Alfresco:从cmis响应中获取数据

时间:2013-12-17 11:41:29

标签: php xml alfresco alfresco-share

我的意图是基本上使用php脚本列出Alfresco网站中的文件夹,为了实现这一点,我在终端执行curl语句,如下所示,

curl -u admin:admin123 http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children

我得到的答案如下,

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:alf="http://www.alfresco.org" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<author><name>admin</name></author>
<generator version="4.2.0 (4576)">Alfresco (Community)</generator>
<icon>http://localhost:8080/alfresco/images/logo/AlfrescoLogo16.ico</icon>
<id>urn:uuid:02f9530f-a1b1-4d6d-b479-b5355692b8e2-children</id>
<link rel="service" href="http://localhost:8080/alfresco/service/cmis"/>
<link rel="self" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children"/>
<link rel="via" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2"/>
<link rel="up" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/4046a051-6cde-4049-a222-53365ac4fbd4/children" type="application/atom+xml;type=feed"/>
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2/descendants" type="application/cmistree+xml"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2/tree" type="application/atom+xml;type=feed"/>
<link rel="first" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/>
<link rel="last" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/>
<title>mysite Children</title>
<updated>2013-12-11T17:11:32.963+05:30</updated>
<opensearch:totalResults>1</opensearch:totalResults>
<opensearch:startIndex>0</opensearch:startIndex>
<opensearch:itemsPerPage>-1</opensearch:itemsPerPage>
<cmisra:numItems>1</cmisra:numItems>
<entry>
<author><name>admin</name></author>
<content src="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/content"/><id>urn:uuid:863dba18-b564-4042-b9a9-e26d83eee13f</id>
<link rel="self" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f"/>
<link rel="edit" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/allowableactions"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/relationships" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/rels"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/policies" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/pols"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/acl" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/acl"/>
<link rel="up" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2" type="application/atom+xml;type=entry"/>
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/children" type="application/atom+xml;type=feed"/>
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/descendants" type="application/cmistree+xml"/>
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/tree" type="application/atom+xml;type=feed"/>
<link rel="describedby" href="http://localhost:8080/alfresco/service/cmis/type/cmis:folder"/>
<link rel="service" href="http://localhost:8080/alfresco/service/cmis"/>
<published>2013-12-11T17:11:32.522+05:30</published>
<summary>Document Library</summary>
<title>documentLibrary</title>
<updated>2013-12-13T11:50:55.893+05:30</updated>
<app:edited>2013-12-13T11:50:55.893+05:30</app:edited>
<alf:icon>http://localhost:8080/alfresco/images/icons/space-icon-default-16.gif</alf:icon>
<cmisra:object>
<cmis:properties>
<cmis:propertyId propertyDefinitionId="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Object Types Ids" queryName="cmis:allowedChildObjectTypeIds"/>
<cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId>
<cmis:propertyString propertyDefinitionId="cmis:path" displayName="Path" queryName="cmis:path"><cmis:value>/Sites/mysite/documentLibrary</cmis:value></cmis:propertyString>
<cmis:propertyString propertyDefinitionId="cmis:name" displayName="Name" queryName="cmis:name"><cmis:value>documentLibrary</cmis:value></cmis:propertyString>
<cmis:propertyDateTime propertyDefinitionId="cmis:creationDate" displayName="Creation Date" queryName="cmis:creationDate"><cmis:value>2013-12-11T17:11:32.522+05:30</cmis:value></cmis:propertyDateTime>
<cmis:propertyString propertyDefinitionId="cmis:changeToken" displayName="Change token" queryName="cmis:changeToken"/>
<cmis:propertyString propertyDefinitionId="cmis:lastModifiedBy" displayName="Last Modified By" queryName="cmis:lastModifiedBy"><cmis:value>admin</cmis:value></cmis:propertyString>
<cmis:propertyString propertyDefinitionId="cmis:createdBy" displayName="Created by" queryName="cmis:createdBy"><cmis:value>admin</cmis:value></cmis:propertyString>
<cmis:propertyId propertyDefinitionId="cmis:objectId" displayName="Object Id" queryName="cmis:objectId"><cmis:value>workspace://SpacesStore/863dba18-b564-4042-b9a9-e26d83eee13f</cmis:value></cmis:propertyId>
<cmis:propertyId propertyDefinitionId="alfcmis:nodeRef" displayName="Alfresco Node Ref" queryName="alfcmis:nodeRef"/>
<cmis:propertyId propertyDefinitionId="cmis:baseTypeId" displayName="Base Type Id" queryName="cmis:baseTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId>
<cmis:propertyId propertyDefinitionId="cmis:parentId" displayName="Parent Id" queryName="cmis:parentId"><cmis:value>workspace://SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2</cmis:value></cmis:propertyId>
<cmis:propertyDateTime propertyDefinitionId="cmis:lastModificationDate" displayName="Last Modified Date" queryName="cmis:lastModificationDate"><cmis:value>2013-12-13T11:50:55.893+05:30</cmis:value></cmis:propertyDateTime>
<alf:aspects>
<alf:appliedAspects>P:sys:localized</alf:appliedAspects>
<alf:appliedAspects>P:cm:titled</alf:appliedAspects>
<alf:appliedAspects>P:cm:ownable</alf:appliedAspects>
<alf:appliedAspects>P:cm:tagscope</alf:appliedAspects>
<alf:appliedAspects>P:st:siteContainer</alf:appliedAspects>
<alf:properties>
<cmis:propertyString propertyDefinitionId="cm:description" displayName="Description" queryName="cm:description"><cmis:value>Document Library</cmis:value></cmis:propertyString>
<cmis:propertyString propertyDefinitionId="cm:title" displayName="Title" queryName="cm:title"/>
<cmis:propertyString propertyDefinitionId="cm:owner" displayName="Owner" queryName="cm:owner"><cmis:value>admin</cmis:value></cmis:propertyString>
<cmis:propertyString propertyDefinitionId="cm:tagScopeSummary" displayName="Tag Summary" queryName="cm:tagScopeSummary"/>
<cmis:propertyString propertyDefinitionId="st:componentId" displayName="Component Id" queryName="st:componentId"><cmis:value>documentLibrary</cmis:value></cmis:propertyString>
</alf:properties>
</alf:aspects>
</cmis:properties>
</cmisra:object>
<cmisra:pathSegment>documentLibrary</cmisra:pathSegment>
</entry>

如何在php中获取子数据?即基本上是标题'documentLibrary'和它的objectId。

2 个答案:

答案 0 :(得分:1)

您可以使用以下PHP库,而不是自己解析Atom提要:http://chemistry.apache.org/php/phpclient.html

答案 1 :(得分:0)

如果您的用例与您所描述的一样简单,您可以在PHP中使用XPath来查询您所追踪的数据。

以下是您可以使用的XPath查询:

选择“Title”元素(我建议选择propertyString cmis:name - 尽管CMIS规范指定必须在atom:title元素中设置cmis:name,我发现了存储库执行的情况不设置CMIS规范中定义的title元素

//cmis:propertyString[contains(@propertyDefinitionId, 'cmis:name')][1]/cmis:value/text()

选择cmis:objectId

//cmis:propertyId[contains(@propertyDefinitionId, 'cmis:objectId')][1]/cmis:value[1]/text()

如果您通过CMIS与Alfresco进行更复杂的用例交互,请查看Apache Chemistry CMIS PHP客户端(http://chemistry.apache.org/php/phpclient.html)以获取强大的客户端库,并查看客户端库是否符合您的需求。

编辑 - 将所有内容组合在一起的简单示例......

// Load the XML String into a SimpleXMLElement
$sxe = new SimpleXMLElement($xmlResponse);

// Optional but good practice - register namespaces
$sxe->registerXPathNamespace('cmis', 'http://docs.oasis-open.org/ns/cmis/core/200908/');

// Execute XPath Query
$result = $sxe->xpath("//cmis:propertyString[contains(@propertyDefinitionId, 'cmis:name')][1]/cmis:value/text()");

// Do something with the result.
echo $result[0]  // For XPath above this will print: "documentLibrary"