1,alfresco的SDK中有对应的取文件的API吗?
2,可以用alfresco的remote file server sync方法同步所有文件到指定文件夹,省去这个程序
2,可以用alfresco的remote file server sync方法同步所有文件到指定文件夹,省去这个程序
解决方案 »
- build.xml文件BUILD FAILED
- list和数组哪个存储空间更大?
- 是不是所有的servlet都可以用jsp来写?
- java com.opensymphony.webwork.views.jasperreports.CompileReport 如何编译报表模板
- 有关于系统资源释放的问题
- spring技术手册中一问题不解,望高手指教!
- 系统经常报An attempt by a client to checkout a Connection has timed out
- ◆◇一个纯java程序,连接数据库的◆◇ 编译通过,但执行的时候提示:No suitable driver!!
- 菜鸟求助HIBERNATE的问题!!困扰很多天,一直没解决,拜托了!
- 帮忙看看我的xml操作有什么问题?
- session 不失效
- JSF 的<h:datatable>的用法求救
下面类完成从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;
}}