07-15-2009 04:29 AM
<%
InputStream is= request.getInputStream();
testecriture.ajouter(is, "salut"); // c'est la fonction java qui fait l'upload et salut c'est le titre du fichier
%>
</body>
</html>
voici ma fonction java: public static void ajouter(InputStream is, String title) throws IOException {
AuthenticationUtils.startSession("admin", "admin");
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String folderPath = "/app:company_home/cm:yassine_test";
ParentReference companyHomeParent = new ParentReference(storeRef, null, folderPath, Constants.ASSOC_CONTAINS, null);
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
.getRepositoryService();
ContentServiceSoapBindingStub contentService = WebServiceFactory
.getContentService();
NamedValue[] contentProps = new NamedValue[1];
NamedValue[] titledProps = new NamedValue[2];
// le nom du fichier
companyHomeParent.setChildName("{http://www.alfresco.org/model/content/1.0}yassine.doc");
//String ext= Extension(title);
//title= replace(title);
CMLCreate create = new CMLCreate("1", companyHomeParent,companyHomeParent.getUuid(), Constants.ASSOC_CONTAINS, null,
Constants.PROP_CONTENT, contentProps);
// Construct CML Block
contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, "yassine.doc");
// Propriété du fichier
titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, title);
titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "");
CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED,
titledProps, null, "1");
String contType = "application/msword";
/*if(ext.equals("pdf")){
contType="application/pdf";
} else if(ext.equals("doc")){
contType= "application/msword";
}else if(ext.equals("txt")){
contType= "text/plain";
}*/
CML cml = new CML();
cml.setCreate(new CMLCreate[] { create });
cml.setAddAspect(new CMLAddAspect[] { addAspect });
// Mettre a jour le repositroy
ContentFormat format = new ContentFormat(contType, "UTF-8");
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
Reference content = result[0].getDestination();
byte[] buffer = new byte[1024];
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
int l = 0;
while (l >= 0) {
l = is.read(buffer);
if (l != -1) {
os.write(buffer, 0, l);
}
}
is.close();
os.flush();
//os.close();
contentService.write(content, Constants.PROP_CONTENT, os.toByteArray(), format);
merci d'avance de votre aide 07-21-2009 07:28 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.