How can I get the download URL?
I tried with the following code :
<code>
public static String webService(String dir, String fileName)
throws Exception {
String downloadURL = null;
try {
// Let us say you know the directory and filename For Eg:
// String dir = "app:company_home/sites/my-site/documentLibrary/";
// String fileName = "Stake";
System.out.println("dir ::" + dir);
System.out.println("fileName ::" + fileName);
// Start the session
AuthenticationUtils.startSession("admin", "admin");
String ticket = AuthenticationUtils.getCurrentTicket();
// Create a reference to the parent where we want to create content
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
// Reference reference = new Reference(storeRef, null,
// "/app:company_home/cmsmileyCMCOE/cm:COE1/*[@cm:name=\"" +
// "eProfilerPPT" + "\"]");
// Create a new Reference to the node you want (variable path here).
String path = dir + "*[@cm:name=\"" + fileName + "\"]";
Reference reference = new Reference(storeRef, null, path);
ContentServiceSoapBindingStub contentService = WebServiceFactory
.getContentService();
// Read the content from the respository
Content[] readResult = contentService.read(new Predicate(
new Reference[] { reference }, storeRef, null),
Constants.PROP_CONTENT);
Content contentRef = readResult[0];
// Get the ticket URL as above and the downloadURL here points to
// the url where the content is present.
System.out.println("contentRef.getUrl() : " + contentRef.getUrl());
String ticketURL = "?ticket=" + ticket;
downloadURL = contentRef.getUrl() + ticketURL;
System.out.println("downloadURL in webService(): " + downloadURL);
} catch (Throwable e) {
System.out.println(e.toString());
} finally {
// End the session
// AuthenticationUtils.endSession();
}
return downloadURL;
}
<code>
This is returning null value when calling with a site document library;
String url = webService("app:company_home/sites/my-site/documentLibrary/", "Alfresco Doccument.odt");
While printing path , it displays : app:company_home/sites/my-site/documentLibrary/*[@cm:name="Alfresco Doccument.odt"] .
And exception is throwing when "Content[] readResult" is defined.
But working fine if I called like;
String url = webService("/app:company_home/cm:sample/", "images.jpeg");
So the problem is happening when site document library path is passing.
How to fix it?
Please help me to fix it.