2013-06-20 31 views
1

我正在使用Alfresco CMS的本地實例,並使用Apache Chemistry Java CMIS。 一切適用於瀏覽和創建對象,但是我很難在文檔上添加元數據。如何使用Apache Chemistry在對象上創建定製屬性

他們的源頁面代碼上有一個示例,說您需要致電CmisObject上的updateProperties。不幸的是,這是行不通的,我得到的例外是:Property 'my:property' is not valid for this type or one of the secondary types

你知道我該如何添加一個自定義屬性?我是否必須增強現有的方面收集,如果是的話,我該怎麼做?

謝謝。

回答

3

住宅「我:財產」是不適用於此類型或輔助類型

我的一個:物業似乎是一個自定義屬性,然後應該有一個自定義的露天方面進行處理。

如果你想使用露天方面,你將需要Alfresco OpenCMIS Extension

下面的代碼片段允許使用露天擴展與OpenCMIS:

Map<String, String> parameter = new HashMap<String, String>(); 
// user credentials 
parameter.put(SessionParameter.USER, "admin"); 
parameter.put(SessionParameter.PASSWORD, "admin"); 

// connection settings 
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom"); 
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); 

// set the alfresco object factory 
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); 

// create session 
SessionFactory factory = SessionFactoryImpl.newInstance(); 
Session session = factory.getRepositories(parameter).get(0).createSession(); 

下面的代碼允許創建一個新文檔有一個自定義屬性填充:

Map<String, Object> properties = new HashMap<String, Object>(); 
properties.put(PropertyIds.NAME, "doc1"); 
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,my:docProps"); 
properties.put("my:property", "My document"); 

Document doc = session.getRootFolder().createDocument(properties, null, null); 
+0

謝謝,但你如何定義我的:docProps?使用代碼調用createDocument時,出現此異常:輸入'cmis:document,my:docProps'是未知的! –

+0

屬性不會動態分配給Alfresco中的文檔。您需要在Alfresco中添加自定義方面。它完全與cmis無關。 –

+0

我已經更新了我的答案:您需要安裝Alfresco OpenCmis Extension並在與Alfresco創建會話之前聲明AlfrescoObjectFactory實現 –

0

自定義屬性應在庫中定義,那麼你可以嘗試將它們設置在CMIS屬性中。

相關問題