本文整理汇总了Java中org.apache.chemistry.opencmis.client.api.Folder.createDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.createDocument方法的具体用法?Java Folder.createDocument怎么用?Java Folder.createDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.chemistry.opencmis.client.api.Folder
的用法示例。
在下文中一共展示了Folder.createDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
/**
* Creates a new document with the given name and content under the given
* folder.
*
* @param name
* the name of the document.
* @param rootFolder
* the root folder.
* @param content
* the content of the document.
* @return the created document.
*/
public Document createDocument(Folder rootFolder, String fileName, InputStream inputStream) {
logger.debug(DEBUG_CREATING_NEW_DOCUMENT, fileName, rootFolder);
Document document = null;
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, CMIS_DOCUMENT_TYPE);
properties.put(PropertyIds.NAME, fileName);
ContentStream contentStream = cmisSession.getObjectFactory().createContentStream(fileName, -1,
MIME_TYPE_TEXT_PLAIN_UTF_8, inputStream);
try {
document = rootFolder.createDocument(properties, contentStream, VersioningState.NONE);
} catch (CmisNameConstraintViolationException e) {
String errorMessage = MessageFormat.format(ERROR_FILE_ALREADY_EXISTS, fileName);
logger.error(errorMessage);
throw new CmisNameConstraintViolationException(errorMessage, e);
}
logger.debug(DEBUG_DOCUMENT_CREATED, fileName);
return document;
}
示例2: createDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
private static Document createDocument(Folder target, String newDocName, Session session)
{
Map<String, String> props = new HashMap<String, String>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put(PropertyIds.NAME, newDocName);
String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation.";
byte[] buf = null;
try
{
buf = content.getBytes("ISO-8859-1"); // set the encoding here for the content stream
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
ByteArrayInputStream input = new ByteArrayInputStream(buf);
ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length,
"text/plain; charset=UTF-8", input); // additionally set the charset here
// NOTE that we intentionally specified the wrong charset here (as UTF-8)
// because Alfresco does automatic charset detection, so we will ignore this explicit request
return target.createDocument(props, contentStream, VersioningState.MAJOR);
}
示例3: createUniqueDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
private Document createUniqueDocument(Folder newFolder)
throws UnsupportedEncodingException {
String uniqueName = getUniqueName();
Map<String, Object> uProperties = new HashMap<String, Object>();
uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
uProperties.put(PropertyIds.NAME, uniqueName);
ContentStreamImpl contentStream = new ContentStreamImpl();
contentStream.setFileName("bob");
String shortString = "short";
contentStream.setStream(new ByteArrayInputStream(shortString.getBytes("UTF-8")));
contentStream.setLength(new BigInteger("5"));
contentStream.setMimeType("text/plain");
Document uniqueDocument = newFolder.createDocument(uProperties, contentStream, VersioningState.MAJOR);
return uniqueDocument;
}
示例4: createDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
public String createDocument(Folder parentFolder, String name, byte[] content) {
logger.debug("Prepparing to create document");
Document document = null;
try{
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = new ContentStreamImpl(name,
BigInteger.valueOf(content.length), "text/plain", stream);
logger.info("Creating document in path: " + parentFolder.getPath());
document = parentFolder.createDocument(properties, contentStream, null);
logger.info("Document path: " + document.getPaths().get(0));
}
catch(Exception e){
logger.error("Failed to create document.", e);
}
return document.getPaths().get(0);
}
示例5: doInBackground
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
@Override
protected CmisResult<Document> doInBackground(Void... arg0) {
Document doc = null;
Exception exception = null;
// Try to retrieve the parent folder object and then create an album.
try {
Folder folder = (Folder) session.getObjectByPath(albumParentfolderPath);
// Create the map of properties associated to the future album.
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, CmisBookIds.BOOK_ALBUM);
properties.put(PropertyIds.BASE_TYPE_ID, ObjectType.DOCUMENT_BASETYPE_ID);
properties.put(PropertyIds.NAME, albumTitle);
doc = folder.createDocument(properties, null, null);
} catch (Exception e) {
exception = e;
}
return new CmisResult<Document>(exception, doc);
}
示例6: uploadFile
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
private void uploadFile(String path, File file, Folder destinationFolder) throws FileNotFoundException {
for (int x = 0; x < 3; x++) {
try {
Map<String, Serializable> properties = new HashMap<String, Serializable>();
properties.put(PropertyIds.NAME, file.getName());
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
ContentStream contentStream = new ContentStreamImpl(file.getAbsolutePath(), BigInteger.valueOf(file.length()), _mimetype, new FileInputStream(file));
_session.clear();
Document document = destinationFolder.createDocument(properties, contentStream, VersioningState.MAJOR);
getLog().info("Uploaded '" + file.getName() + "' to '" + path + "' with a document id of '" + document.getId() + "'");
return;
} catch (Exception ex) {
getLog().debug("Upload failed, retrying...");
}
}
}
示例7: DISABLED_testBasicFileOps
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
public void DISABLED_testBasicFileOps()
{
Repository repository = getRepository("admin", "admin");
Session session = repository.createSession();
Folder rootFolder = session.getRootFolder();
// create folder
Map<String,String> folderProps = new HashMap<String, String>();
{
folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate());
}
Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext());
Map<String, String> fileProps = new HashMap<String, String>();
{
fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
}
ContentStreamImpl fileContent = new ContentStreamImpl();
{
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt"));
writer.putContent("Ipsum and so on");
ContentReader reader = writer.getReader();
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
fileContent.setStream(reader.getContentInputStream());
}
folder.createDocument(fileProps, fileContent, VersioningState.MAJOR);
}
示例8: testDownloadEvent
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
public void testDownloadEvent() throws InterruptedException
{
Repository repository = getRepository("admin", "admin");
Session session = repository.createSession();
Folder rootFolder = session.getRootFolder();
String docname = "mydoc-" + GUID.generate() + ".txt";
Map<String, String> props = new HashMap<String, String>();
{
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
props.put(PropertyIds.NAME, docname);
}
// content
byte[] byteContent = "Hello from Download testing class".getBytes();
InputStream stream = new ByteArrayInputStream(byteContent);
ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream);
Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR);
NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
ContentStream content = doc1.getContentStream();
assertNotNull(content);
//range request
content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4));
assertNotNull(content);
}
示例9: createFileFromUpload
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
@Override
public FileCustom createFileFromUpload(ByteArrayInOutStream file, String mimeType, String filename,
long length, String typeFichier, String prefixe, Candidature candidature, Boolean commune) throws FileException{
try{
String name = prefixe+"_"+filename;
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
properties.put(PropertyIds.NAME, name);
ByteArrayInputStream bis = file.getInputStream();
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(length), mimeType, bis);
Folder master;
if (typeFichier.equals(ConstanteUtils.TYPE_FICHIER_GESTIONNAIRE)){
master = getFolderGestionnaire();
}else{
master = getFolderCandidature(candidature, commune);
}
//versioning
VersioningState versioningState = VersioningState.NONE;
if (enableVersioningCmis!=null && enableVersioningCmis){
versioningState = VersioningState.MINOR;
}
Document d = master.createDocument(properties, contentStream, versioningState);
file.close();
bis.close();
return getFileFromDoc(d,filename, prefixe);
}catch(Exception e){
logger.error("Stockage de fichier - CMIS : erreur de creation du fichier ",e);
throw new FileException(applicationContext.getMessage("file.error.create", null, UI.getCurrent().getLocale()),e);
}
}
示例10: createDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
public Document createDocument(String parentId, String name, Map<String, Serializable> properties, ContentStream contentStream, VersioningState versioningState)
{
CmisObject o = getObject(parentId);
if(o instanceof Folder)
{
Folder f = (Folder)o;
if(properties == null)
{
properties = new HashMap<String, Serializable>();
}
String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID);
String type = "cmis:document";
if(objectTypeId == null)
{
objectTypeId = type;
}
if(objectTypeId.indexOf(type) == -1)
{
StringBuilder sb = new StringBuilder(objectTypeId);
if(sb.length() > 0)
{
sb.append(",");
}
sb.append(type);
objectTypeId = sb.toString();
}
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
Document res = f.createDocument(properties, contentStream, versioningState);
return res;
}
else
{
throw new IllegalArgumentException("Parent does not exists or is not a folder");
}
}
示例11: storeDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
private Document storeDocument(Folder parentFolder, Map<String, Object> cmisProperties, ContentStream contentStream) throws Exception {
if (!cmisProperties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
cmisProperties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
}
VersioningState versioningState = VersioningState.NONE;
if (getSessionFacade().isObjectTypeVersionable((String) cmisProperties.get(PropertyIds.OBJECT_TYPE_ID))) {
versioningState = VersioningState.MAJOR;
}
LOG.debug("Creating document with properties: {}", cmisProperties);
return parentFolder.createDocument(cmisProperties, contentStream, versioningState);
}
示例12: createTextDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
protected void createTextDocument(Folder newFolder, String content, String fileName)
throws UnsupportedEncodingException {
byte[] buf = content.getBytes("UTF-8");
ByteArrayInputStream input = new ByteArrayInputStream(buf);
ContentStream contentStream = createSession().getObjectFactory()
.createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
properties.put(PropertyIds.NAME, fileName);
newFolder.createDocument(properties, contentStream, VersioningState.NONE);
}
示例13: createDocument
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
public Document createDocument(String parentId, String name, Map<String, Serializable> properties, ContentStream contentStream, VersioningState versioningState)
{
CmisObject o = getObject(parentId);
if(o instanceof Folder)
{
Folder f = (Folder)o;
if(properties == null)
{
properties = new HashMap<String, Serializable>();
}
String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID);
String type = "cmis:document";
if(objectTypeId == null)
{
objectTypeId = type;
}
if(objectTypeId.indexOf(type) == -1)
{
StringBuilder sb = new StringBuilder(objectTypeId);
if(sb.length() > 0)
{
sb.append(",");
}
sb.append(type);
objectTypeId = sb.toString();
}
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
Document res = f.createDocument(properties, contentStream, versioningState);
return res;
}
else
{
throw new IllegalArgumentException("Parent does not exists or is not a folder");
}
}
示例14: uploadContentToPurgeableFolder
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
@Override
public void uploadContentToPurgeableFolder(CMISFile cmisFile) {
Session session = createSession();
Folder multitenantRootFolder = getMultitenantRootFolder(session, true);
Folder uuidFolder = getPurgableUuidFolder(session, sessionResolver.resolveCurrentSessionIdentifier(), multitenantRootFolder, repoFolderNestingLevels, true);
Folder contentsFolder = getFolderByPath(session, CONTENT_FOLDER_NAME, uuidFolder, true);
Map<String, String> newDocProps = new HashMap<String, String>();
newDocProps.put(PropertyIds.OBJECT_TYPE_ID, CMIS_DOCUMENT);
newDocProps.put(PropertyIds.NAME, cmisFile.getFileName());
ContentStream contentStream = new ContentStreamImpl(cmisFile.getFileName(), null, cmisFile.getMimeType(), cmisFile.getInputStream());
contentsFolder.createDocument(newDocProps, contentStream, VersioningState.NONE, null, null, null, session.getDefaultContext());
}
示例15: uploadDescriptorToPurgeableFolder
import org.apache.chemistry.opencmis.client.api.Folder; //导入方法依赖的package包/类
@Override
public void uploadDescriptorToPurgeableFolder(CMISEvidenceFile cmisFile) {
Session session = createSession();
Folder multitenantRootFolder = getMultitenantRootFolder(session, true);
Folder uuidFolder = getPurgableUuidFolder(session, sessionResolver.resolveCurrentSessionIdentifier(), multitenantRootFolder, repoFolderNestingLevels, true);
Map<String, String> newDocProps = new HashMap<String, String>();
newDocProps.put(PropertyIds.OBJECT_TYPE_ID, CMISEvidenceFile.PROPERTY_DOC_ID);
newDocProps.put(PropertyIds.NAME, cmisFile.getFileName());
if (cmisFile.getTransactionId() != null && !cmisFile.getTransactionId().equals("")) {
newDocProps.put(CMISEvidenceFile.PROPERTY_TRANSACTION_ID, cmisFile.getTransactionId());
}
newDocProps.put(CMISEvidenceFile.PROPERTY_TRANSACTION_STATUS, cmisFile.getTransactionStatus());
ContentStream contentStream = new ContentStreamImpl(cmisFile.getFileName(), null, cmisFile.getMimeType(), cmisFile.getInputStream());
uuidFolder.createDocument(newDocProps, contentStream, VersioningState.NONE, null, null, null, session.getDefaultContext());
}