il me semblait qu'on pouvait le faire avec des fichier csv
public Reference GestObject(Reference objTarget, String objType, List<NamedValue> objProperties) {// throws Exception
return GestObject(objTarget.getPath(), objType, objProperties);
}
public Reference GestObject(String objTarget, String objType, List<NamedValue> objProperties) {
String objName = getProperty(getQName("cm:name"), objProperties); //Constants.PROP_NAME
if (objName == null || objName.equals("")) {
System.out.println("ERROR - '" + getQName("cm:name") + "' must be set in object properties");
return null;
}
try {
// Check to see if the object has already been created or not
String Path = objTarget + "/*[@cm:name=\"" + objName + "\"]";
Reference objRef = new Reference(STORE, null, Path);
//System.out.println("Path : " + Path);
Node[] results = WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{objRef}, STORE, null));
System.out.println("Object yet created");
return results[0].getReference();
} catch (Exception e) {
// Create parent reference to company home
ParentReference parentReference = new ParentReference(
STORE,
null,
objTarget,
Constants.ASSOC_CONTAINS,
Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, objName));
// Create object
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, objType, (NamedValue[])objProperties.toArray(new NamedValue[objProperties.size()]));
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
try {
UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);
System.out.println("Object created");
return results[0].getDestination();
} catch (Exception e2) {
System.out.println("ERROR - creating object : objType = '" + objType + "'");
e2.printStackTrace();
return null;
}
}
}
public Reference AddContent(Reference objRef, String docContent) {
try {
char in = 0x19;
char out = 0x20;
docContent = docContent.replace(in, out);
// Define the content format for the content we are adding
ContentFormat contentFormat = new ContentFormat("text/html", "ISO-8859-1");
// Get the content service
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
// Write the content
Content content = contentService.write(objRef, Constants.PROP_CONTENT, docContent.getBytes(), contentFormat);
// Get a reference to the newly created content
return content.getNode();
} catch (Exception e) {
System.out.println("ERROR - add content to node");
return null;
}
}
public Reference AddFile(Reference objRef, String imageName) {
try {
//take the 3 last letter of the imageName to have the extension
StringBuilder sb = new StringBuilder(imageName);
String extension = sb.substring(imageName.length()-3, imageName.length());
// Create the format
//ContentFormat format = new ContentFormat("image/"+extension, "UTF-8");
ContentFormat format = new ContentFormat((extension == "xls" ? "application/excel" : (extension == "doc" ? "application/msword" : "image/"+extension)), "UTF-8");
// Open the file and convert to byte array
File ffile = new File(imageName);
FileInputStream fis = new FileInputStream(ffile);
byte[] bytes = ContentUtils.convertToByteArray(fis);
fis.close();
// Get the content service
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
// Write the content
Content content = contentService.write(objRef, Constants.PROP_CONTENT, bytes, format);
// Get a reference to the newly created content
return content.getNode();
} catch (Exception e) {
System.out.println("ERROR - add file");
e.printStackTrace();
return null;
}
}
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.