【问题标题】:Alfresco: Fetching data from cmis responseAlfresco:从 cmis 响应中获取数据
【发布时间】:2013-12-17 11:41:29
【问题描述】:

我的意图是基本上使用 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。

【问题讨论】:

    标签: php xml alfresco alfresco-share


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果你的用例和你描述的一样简单,你可以在 PHP 中使用 XPath 来查询你想要的数据。

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

      选择“Title”元素(我建议改为选择 propertyString cmis:name - 尽管 CMIS 规范规定 cmis:name 必须在 atom:title 元素中设置,但我发现存储库确实如此不设置 CMIS 规范中定义的标题元素)

      //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"
      

      【讨论】:

      • 感谢您的回复。我不知道 cmis 和它的处理。如果我现在问一个无意义的问题,请原谅。执行 curl 命令后得到的响应将保存在一个变量中,比如 $response。如何从这个变量中获取值。
      • 鲁米,我已经根据您的评论更新了我的答案。此更新只是一个简单的示例。如果您做的事情超出了我们所讨论的范围,我强烈建议您查看 Apache Chemistry PHP 客户端库。
      猜你喜欢
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 2011-08-22
      相关资源
      最近更新 更多