首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

alfresco-webservice跟cmis操作alfresco的space

2012-07-04 
alfresco-webservice和cmis操作alfresco的spacealfresco-webservice和cmis操作alfresco的space所需jar包al

alfresco-webservice和cmis操作alfresco的space
alfresco-webservice和cmis操作alfresco的space

所需jar包

alfresco-web-services-client-3.4.d.jar
alfresco-opencmis-extension-0.2.jar
chemistry-opencmis-client-api-0.6.0.jar
chemistry-opencmis-client-bindings-0.6.0.jar
chemistry-opencmis-client-impl-0.6.0.jar
chemistry-opencmis-commons-api-0.6.0.jar
chemistry-opencmis-commons-impl-0.6.0.jar

1、alfresco-webservice
需要创建一个会话,在会话范围内操作space,包括生成子space,最后关闭会话。

/***建立会话***/WebServiceFactory.setEndpointAddress("http://"+ AlfrescoConfig.getProperty(AlfrescoConfig.SERVER_HOST) + ":"+ AlfrescoConfig.getProperty(AlfrescoConfig.SERVER_PORT)+ "/alfresco/api");//开始alfresco-webservice的会话 此处username和password即是 http://localhost:8384/alfresco 登录alfresco的用户名密码AuthenticationUtils.startSession(AlfrescoConfig.getProperty(AlfrescoConfig.SERVER_USERNAME),AlfrescoConfig.getProperty(AlfrescoConfig.SERVER_PASSWORD));String ticket = AuthenticationUtils.getTicket();/***关闭会话***/AuthenticationUtils.endSession();/***创建 根space***/startSession();Reference space = null;//获取space storeStore STORE = new Store(Constants.WORKSPACE_STORE,"SpacesStore");//获取comany home 根spaceParentReference companyHomeParent = new ParentReference(STORE , null, "/app:company_home",Constants.ASSOC_CONTAINS, null);RepositoryServiceSoapBindingStub stub=WebServiceFactory.getRepositoryService();try {                        //初始化要添加的space,为company home 的子spacespace = new Reference(STORE, null, companyHomeParent .getPath()+ "/cm:" + spacename);                        //如果space不存在就抛出异常stub.get(new Predicate(new Reference[] { space },STORE , null));} catch (Exception e) {                        companyHomeParent.setChildName(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL,spacename));NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, spacename) };                        //通过CML(Content Manipulation Language,操作Repository的语句)创建spaceCMLCreate create = new CMLCreate("1", companyHomeParent, null, null,null, Constants.TYPE_FOLDER, properties);CML cml = new CML();cml.setCreate(new CMLCreate[] { create });try {stub.update(cml);} catch (Exception e2) {System.err.println("Can not create the space");throw e2;}}endSession();



2、cmis(我用的是atompub绑定)
//初始化cmis sessionSessionFactoryImpl sessionFactory = SessionFactoryImpl.newInstance();Map<String, String> parameter = new HashMap<String, String>();parameter.put(SessionParameter.USER, "admin");parameter.put(SessionParameter.PASSWORD, "admin");parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8384/alfresco/service/cmis");parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());parameter.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "");parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "en");parameter.put(SessionParameter.LOCALE_VARIANT, "US");parameter.put(SessionParameter.OBJECT_FACTORY_CLASS,"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");List<Repository> repositorys = sessionFactory.getRepositories(parameter);Repository soleRepository = sessionFactory.getRepositories(parameter).get(0);//company homeparameter.put(SessionParameter.REPOSITORY_ID, soleRepository.getId());Session session = sessionFactory.createSession(parameter);/***创建space***/Folder root = session.getRootFolder();ObjectId parentId = session.createObjectId(root.getId());properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value());properties.put(PropertyIds.NAME, fName);session.createFolder(properties, parentId);/***删除space***/Folder root = session.getRootFolder();CmisObject space=null;for (CmisObject childrens : root.getChildren()) {if (childrens.getName().equals(fName)) {space=childrens;}}if(space!=null)space.delete(true);elseSystem.out.println(fName+" 不存在");

热点排行