0
votes

Hi guys i am doing alfresco using opencmis apache chemistry. I have done many services such as creating folder,subfolder,uploading,downloading with version updates. Now i am trying to generate link of folder/document whatever the link is in dashboard of alfresco. Somebody is there who can help me to genrate the link using openCmis(java)?? Thanks in advance

public  String dowloadingDocument(String docuementID){
	  Session cmisSession=new CreateSession().getSession();
	  Document document=(Document) cmisSession.getObject(docuementID);
     String link=null;
      try {
	        Method loadLink = AbstractAtomPubService.class.getDeclaredMethod("loadLink", 

	            new Class[] { String.class, String.class, String.class, String.class });

		try {
			
			link=(String) loadLink.invoke(cmisSession.getBinding().getObjectService(),cmisSession.getRepositoryInfo().getId(),document.getId(),AtomPubParser.LINK_REL_CONTENT,null);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
	} catch (NoSuchMethodException e) {
		e.printStackTrace();
	} catch (SecurityException e) {
		e.printStackTrace();
	}
      return link;
      
}
1
Do you need the link for directly downloading the file or for displaying the file in the the browser inside share UI? - Younes Regaieg
what do you mean with link I've done the same thing with J2EE and i have a path to get my File or Folder from my app is this what you want ??? - Yagami Light
hi Younes thanks for respond.I want generate the link for my folder,document using java code(open cmis).Can u help me?? - Md Noorshid
Hi yagami i want generate the link of a specific folder, but not by using simply path.I am posting the demo for creating download link for document.Same like i want for folder.Here if i pass folder id link is coming null.I am posting the code in my question - Md Noorshid
just an additionnel question what is the purpose of this link, is it to download a document ??? - Yagami Light

1 Answers

1
votes

This snippet gives you a download link for the document:

Document document= (Document)cmisSession.getObject(docuementID);
String link = document.getContentUrl();

This is not same link you'll find the Alfresco dashboard, but it also lets the user download the document. Please note, that depending on the authentication setup the user has to authenticate again before the download starts.