1,alfresco的SDK中有对应的取文件的API吗?
2,可以用alfresco的remote file server sync方法同步所有文件到指定文件夹,省去这个程序

解决方案 »

  1.   

    谢谢,楼上兄台.同步对我来说不需要,我也许只取知识库中的不同文件夹的文件到同一个本地目录下,取哪个文件用户自己定义的,所以不用同步哪个东西.我仔细研究了下alfresco的SDK,目前问题我已经自行解决,耗费2天时间,真累.
      

  2.   

    楼上兄台这分混的容易啊!等了这么多天,没人顶贴,实在没办法,只好结贴了,顺便把代码贴了给大家共享下.发现java高手一般太忙,问贴好象热情不高啊!小弟最近研究下java,基本知识不熟,所以难题很多,请大家照顾下.2小时后结扎这个贴,简称结贴.
    下面类完成从Afresco服务器向本地目录下载文件,仅仅是实验用的,没有好好定义,若你要用就要修改下public class download_test { /**define input*/
    //Url(include port)
        protected static final String Url = "http://localhost:8080/alfresco/api";
        //UserName Key
        protected static final String UserName = "admin";
        //PassWord key
        protected static final String PassWord = "admin";
        //Upload SerVice Folder
        protected static final String ServiceFolderName = "myfoder/childfoder";    /** The store used throughout the samples */
        protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
       
    /**
     * @param args
     */
    public static void main(String[] args)  throws Exception
    {
    // TODO Auto-generated method stub
            /**Set repository location*/
            WebServiceFactory.setEndpointAddress(Url);
            
            /**Start the session*/
            AuthenticationUtils.startSession(UserName, PassWord);
            
            /** Make sure Service Folder has been created,or download files will be failure */
            boolean Success = true;
    String[] ServiceFolderList = ServiceFolderName.split("/");
    String ParentFolder = "/app:company_home";
    String ServiceFolder;
    Reference SAMPLE_FOLDER;
            for(String mServiceFolder :ServiceFolderList)
            {
             ServiceFolder = ParentFolder+"/cm:"+mServiceFolder;
             SAMPLE_FOLDER = new Reference(STORE, null, ServiceFolder);
            
             try
             { 
             WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null));
             }
             catch (Exception exception)
             {
              //jmp to /** End the session*/
              Success=false;
              break;
             }
             ParentFolder = ServiceFolder;
            }
            
            System.out.println(ParentFolder);
            
        /**Download files,if exception then "Success = False" */
            if(Success)
            {
                // Get the content service
                ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
                //Search the content int the ServicrFolder
                Content mcontent = SearchContent(contentService,ParentFolder,"1kkk.jpg");
             DownLoadFileFromAlfresco(mcontent,"d:/1kkk.jpg");
            
            }
            /** End the session*/
            AuthenticationUtils.endSession();
    }

        /**
         * Helper method to download file from Alfresco.
         *  
         * @param content           the content of file which will be downloaded
         * @param destFolder        the local folder
         * @throws Exception        
         */
        public static void DownLoadFileFromAlfresco(Content content,String destFolder) throws Exception
        {    
         InputStream in=ContentUtils.getContentAsInputStream(content); 
         //Output file
         File file=new File(destFolder); 
         if(!file.exists())
         file.createNewFile(); 
         FileOutputStream out=new FileOutputStream(file); 
         int c; 
         byte buffer[]=new byte[1024]; 
         while((c=in.read(buffer))!=-1)
         { 
         for(int i=0;i<c;i++) 
         out.write(buffer[i]); 
         } 
         in.close(); 
         out.close(); 
            System.out.println("download ok!");
        }
        /**
         * modifly Refence Name.
         *  
         * @param FileName          the name of the download file
         * @return                  Refence Name
         * @throws Exception        
         */
        public static String modiflyRefenceName(String FileName)
        {
         if(FileName.charAt(0)>='1'&&FileName.charAt(0)<='9')
         {     String ModifliedName ="_x003"+FileName.substring(0,1)+"_"+FileName.substring(1);
         System.out.println(ModifliedName);
         return ModifliedName;
         }
        
         return FileName;
        }
        
        /**
         * Helper method to SearchContent.
         *  
         * @param contentService    the content web service
         * @param srcFolder         ParentFolder on web service
         * @param FileName          the name of the download file
         * @return                  a Content of the download file
         * @throws Exception        
         */
        public static Content SearchContent(ContentServiceSoapBindingStub contentService, String srcFolder,String FileName) throws Exception
        {
         String FileRefenceName = modiflyRefenceName(FileName);
         Reference contentReference = new Reference(STORE,null,srcFolder+"/cm:"+FileRefenceName);
            Content[] readResult = contentService.read(
                    new Predicate(new Reference[]{contentReference}, STORE, null), 
                    Constants.PROP_CONTENT);
            System.out.println(readResult[0].getUrl());        for(Content content: readResult)
            {
             String[] SplitedUrl = content.getUrl().split("/");
             if(SplitedUrl[SplitedUrl.length-1].equals(FileName))
             {
             return content;
             }
            
            }
         return null;
        }}