05-18-2009 03:24 AM
11-24-2010 02:12 AM
11-24-2010 04:45 AM
11-24-2010 05:42 AM
11-24-2010 08:41 AM
11-25-2010 03:43 AM
11-25-2010 05:50 AM
/** Admin user name and password used to connect to the repository */
protected static final String USERNAME = "admin";
protected static final String PASSWORD = "admin";
/** The store used throughout the samples */
protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, "/app:company_home/cm:sample_folder9");
public static void main(String args[]) throws Exception
{
WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/api");
AuthenticationUtils.startSession(USERNAME, PASSWORD);
try
{
// Check to see if the sample folder has already been created or not
WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null));
ParentReference parentRef = new ParentReference();
parentRef.setStore(STORE);
parentRef.setUuid(SAMPLE_FOLDER.getUuid());
parentRef.setPath(SAMPLE_FOLDER.getPath());
parentRef.setAssociationType(Constants.ASSOC_CONTAINS);
parentRef.setChildName(Constants.ASSOC_CONTAINS);
NamedValue[] properties2 = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, "SampleContent1.txt")};
CMLCreate create2 = new CMLCreate();
create2.setParent(parentRef);
create2.setProperty(properties2);
create2.setType(Constants.TYPE_CONTENT);
CML cml2 = new CML();
cml2.setCreate(new CMLCreate[] {create2});
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml2);
Reference contentNode = result[0].getDestination();
ContentFormat format = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8");
byte[] content = "This is some test content provided by the Alfresco development team!".getBytes();
Content content1 = WebServiceFactory.getContentService().write(contentNode,
Constants.PROP_CONTENT, content, format);
}
catch (Exception e){
e.printStackTrace();
}
}
/** Admin user name and password used to connect to the repository */
protected static final String USERNAME = "admin";
protected static final String PASSWORD = "admin";
/** The store used throughout the samples */
protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
static String parentSpace = "/app:company_home/cm:sample_folder6";
protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, parentSpace);
static String fileName= "SampleContext.txt";
static boolean success = true;
protected static void downloadContent() throws Exception
{
try
{
// Check to see if the sample folder has already been created or not
WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null));
}
catch (Exception exception)
{
System.out.println("Error while getting repository service");
exception.printStackTrace();
success=false;
}
}
public static void main(String args[]) {
try{
AuthenticationUtils.startSession("admin", "admin");
downloadContent();
System.out.println("Success Value is "+success);
if(success){
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
System.out.println("ISO9075.encode(fileName)"+ISO9075.encode(fileName));
Reference contentReference = new Reference(STORE,null,parentSpace+"/cm:"+fileName);// Reference contentReference = new Reference(STORE,null,parentSpace);
System.out.println("UUID IS …….."+contentReference.getPath());
System.out.println("3"+fileName);
Content[] readResult = contentService.read(new Predicate(new Reference[]{contentReference}, STORE, null), Constants.PROP_CONTENT);
System.out.println("Before for……."+readResult.length);
System.out.println("URL is "+readResult[0].getUrl());
System.out.println("Node is "+readResult[0].getNode().getUuid());
for(Content content: readResult) {
String[] splitedUrl = content.getUrl().split("/");
if(splitedUrl[splitedUrl.length-1].equals(fileName)){
System.out.println("Inside If");
InputStream in=ContentUtils.getContentAsInputStream(content);
// response.reset();
// response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
// ServletOutputStream sosStream = response.getOutputStream();
int ibit = 256;
while ((ibit) >= 0) {
ibit = in.read();
// sosStream.write(ibit);
}
// sosStream.flush();
// sosStream.close();
in.close();
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
12-05-2010 11:10 AM
12-06-2010 09:23 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.