You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dc...@apache.org on 2011/07/22 17:26:20 UTC
svn commit: r1149632 - in /chemistry/abdera-ext/trunk/src:
main/java/org/apache/chemistry/abdera/ext/CMISValue.java
test/java/org/apache/chemistry/abdera/ext/test/TestDate.java
test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml
Author: dcaruana
Date: Fri Jul 22 15:26:19 2011
New Revision: 1149632
URL: http://svn.apache.org/viewvc?rev=1149632&view=rev
Log:
Fix issue with CMIS Abdera parser for dates without timezone
Added:
chemistry/abdera-ext/trunk/src/test/java/org/apache/chemistry/abdera/ext/test/TestDate.java
chemistry/abdera-ext/trunk/src/test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml
Modified:
chemistry/abdera-ext/trunk/src/main/java/org/apache/chemistry/abdera/ext/CMISValue.java
Modified: chemistry/abdera-ext/trunk/src/main/java/org/apache/chemistry/abdera/ext/CMISValue.java
URL: http://svn.apache.org/viewvc/chemistry/abdera-ext/trunk/src/main/java/org/apache/chemistry/abdera/ext/CMISValue.java?rev=1149632&r1=1149631&r2=1149632&view=diff
==============================================================================
--- chemistry/abdera-ext/trunk/src/main/java/org/apache/chemistry/abdera/ext/CMISValue.java (original)
+++ chemistry/abdera-ext/trunk/src/main/java/org/apache/chemistry/abdera/ext/CMISValue.java Fri Jul 22 15:26:19 2011
@@ -17,11 +17,13 @@
package org.apache.chemistry.abdera.ext;
import java.math.BigDecimal;
+import java.util.Calendar;
import java.util.Date;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
import javax.xml.namespace.QName;
-import org.apache.chemistry.abdera.ext.utils.ISO8601DateFormat;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
@@ -113,8 +115,13 @@ public class CMISValue extends Extensibl
* @return date value
*/
public Date getDateValue() {
- // TODO: Use mechanism not reliant on Alfresco code
- return ISO8601DateFormat.parse(getStringValue());
+ try {
+ DatatypeFactory df = DatatypeFactory.newInstance();
+ Calendar calendar = df.newXMLGregorianCalendar(getStringValue()).toGregorianCalendar();
+ return calendar.getTime();
+ } catch (DatatypeConfigurationException e) {
+ return null;
+ }
}
}
Added: chemistry/abdera-ext/trunk/src/test/java/org/apache/chemistry/abdera/ext/test/TestDate.java
URL: http://svn.apache.org/viewvc/chemistry/abdera-ext/trunk/src/test/java/org/apache/chemistry/abdera/ext/test/TestDate.java?rev=1149632&view=auto
==============================================================================
--- chemistry/abdera-ext/trunk/src/test/java/org/apache/chemistry/abdera/ext/test/TestDate.java (added)
+++ chemistry/abdera-ext/trunk/src/test/java/org/apache/chemistry/abdera/ext/test/TestDate.java Fri Jul 22 15:26:19 2011
@@ -0,0 +1,144 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.abdera.ext.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.model.Entry;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.abdera.ext.CMISObject;
+import org.apache.chemistry.abdera.ext.CMISProperties;
+import org.apache.chemistry.abdera.ext.CMISProperty;
+import org.apache.chemistry.abdera.ext.utils.CMISAppModel;
+
+/**
+ *
+ */
+
+/**
+ * Test for Abdera Extension functionalities. Takes a local CMIS compliant
+ * atompub entries and validates the parsing of those via the CmisAppModel and
+ * Abdera extensions
+ *
+ * @author davidc
+ *
+ */
+public class TestDate extends TestCase {
+
+ CMISAppModel model = null;
+
+ @Override
+ protected void setUp() throws Exception {
+ model = new CMISAppModel();
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Tests constants for the type definition entry parsing
+ */
+ public void testDateWithoutTimezone() {
+ Entry entry = loadEntry("/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml");
+ assertNotNull(entry);
+ CMISObject object = entry.getExtension(CMISConstants.OBJECT);
+ assertNotNull(object);
+ CMISProperties properties = object.getProperties();
+ assertNotNull(properties);
+ CMISProperty property = properties.find("cmis:creationDate");
+ assertNotNull(property);
+ Date date = property.getDateValue();
+ assertNotNull(date);
+
+// assertTrue(type.getCreatable());
+// assertTrue(type.getFileable());
+// assertTrue(type.getQueryable());
+// assertTrue(type.getVersionable());
+// assertTrue(type.getFullTextIndexed());
+// assertTrue(type.getIncludeInSupertypeQuery());
+// assertFalse(type.getControllablePolicy());
+// assertTrue(type.getControllableACL());
+// assertEquals("", type.getDescription());
+// assertEquals("My doc", type.getDisplayName());
+// assertEquals("mycm:doc", type.getQueryName());
+// assertEquals("http://www.alfresco.org/model/mycontent/1.0", type.getLocalNamespace());
+// assertEquals("doc", type.getLocalName());
+// assertEquals("cmis:document", type.getBaseId());
+// assertEquals("cmis:document", type.getParentId());
+// assertEquals("D:mycm:doc", type.getId());
+// assertEquals("allowed", type.getContentStreamAllowed());
+ }
+
+ /*
+ * Utility private methods
+ */
+
+ private Entry loadEntry(String resourcePath) {
+ String entryStr = null;
+ try {
+ entryStr = load(resourcePath);
+ } catch (IOException e) {
+ fail("Test atom entry not found");
+ }
+ Entry entry = model.parseEntry(new StringReader(entryStr), null);
+ return entry;
+ }
+
+
+ /**
+ * Load text from file specified by class path
+ *
+ * @param classPath
+ * XML file
+ * @return XML
+ * @throws IOException
+ */
+ private String load(String path) throws IOException {
+ InputStream input = getClass().getResourceAsStream(path);
+ if (input == null) {
+ throw new IOException(path + " not found.");
+ }
+
+ InputStreamReader reader = new InputStreamReader(input, "UTF-8");
+ StringWriter writer = new StringWriter();
+
+ try {
+ char[] buffer = new char[4096];
+ int bytesRead = -1;
+ while ((bytesRead = reader.read(buffer)) != -1) {
+ writer.write(buffer, 0, bytesRead);
+ }
+ writer.flush();
+ } finally {
+ reader.close();
+ writer.close();
+ }
+
+ return writer.toString();
+ }
+
+}
Added: chemistry/abdera-ext/trunk/src/test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml
URL: http://svn.apache.org/viewvc/chemistry/abdera-ext/trunk/src/test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml?rev=1149632&view=auto
==============================================================================
--- chemistry/abdera-ext/trunk/src/test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml (added)
+++ chemistry/abdera-ext/trunk/src/test/resources/org/apache/chemistry/abdera/ext/test/date-without-timezone.xml Fri Jul 22 15:26:19 2011
@@ -0,0 +1,123 @@
+<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:app="http://www.w3.org/2007/app">
+ <atom:author>
+ <atom:name>System</atom:name>
+ </atom:author>
+ <atom:id>http://opencmis.org/d29ya3NwYWNlOi8vU3BhY2VzU3RvcmUvOTNlZjljZTQtNTgxMS00NDAxLTkxN2QtZjQ4ZmZhOTNkODRk</atom:id>
+ <atom:title>Data Dictionary</atom:title>
+ <app:edited>2010-09-28T11:51:47Z</app:edited>
+ <atom:updated>2010-09-28T11:51:47Z</atom:updated>
+ <cmisra:object xmlns:ns3="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
+ <cmis:properties>
+ <cmis:propertyId queryName="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Object Types Ids"
+ localName="allowedChildObjectTypeIds" propertyDefinitionId="cmis:allowedChildObjectTypeIds" />
+ <cmis:propertyId queryName="cmis:objectTypeId" displayName="Object Type Id" localName="objectTypeId"
+ propertyDefinitionId="cmis:objectTypeId">
+ <cmis:value>cmis:folder</cmis:value>
+ </cmis:propertyId>
+ <cmis:propertyString queryName="cmis:path" displayName="Path" localName="path"
+ propertyDefinitionId="cmis:path">
+ <cmis:value>/Data Dictionary</cmis:value>
+ </cmis:propertyString>
+ <cmis:propertyString queryName="cmis:name" displayName="Name" localName="name"
+ propertyDefinitionId="cmis:name">
+ <cmis:value>Data Dictionary</cmis:value>
+ </cmis:propertyString>
+ <cmis:propertyDateTime queryName="cmis:creationDate" displayName="Creation Date"
+ localName="creationDate" propertyDefinitionId="cmis:creationDate">
+ <cmis:value>2011-01-31T01:01:01</cmis:value>
+ </cmis:propertyDateTime>
+ <cmis:propertyString queryName="cmis:changeToken" displayName="Change token" localName="changeToken"
+ propertyDefinitionId="cmis:changeToken" />
+ <cmis:propertyString queryName="cmis:lastModifiedBy" displayName="Last Modified By"
+ localName="lastModifiedBy" propertyDefinitionId="cmis:lastModifiedBy">
+ <cmis:value>System</cmis:value>
+ </cmis:propertyString>
+ <cmis:propertyString queryName="cmis:createdBy" displayName="Created by" localName="createdBy"
+ propertyDefinitionId="cmis:createdBy">
+ <cmis:value>System</cmis:value>
+ </cmis:propertyString>
+ <cmis:propertyId queryName="cmis:objectId" displayName="Object Id" localName="objectId"
+ propertyDefinitionId="cmis:objectId">
+ <cmis:value>workspace://SpacesStore/93ef9ce4-5811-4401-917d-f48ffa93d84d</cmis:value>
+ </cmis:propertyId>
+ <cmis:propertyId queryName="cmis:baseTypeId" displayName="Base Type Id" localName="baseTypeId"
+ propertyDefinitionId="cmis:baseTypeId">
+ <cmis:value>cmis:folder</cmis:value>
+ </cmis:propertyId>
+ <cmis:propertyId queryName="alfcmis:nodeRef" displayName="Alfresco Node Ref" localName="nodeRef"
+ propertyDefinitionId="alfcmis:nodeRef">
+ <cmis:value>workspace://SpacesStore/93ef9ce4-5811-4401-917d-f48ffa93d84d</cmis:value>
+ </cmis:propertyId>
+ <cmis:propertyDateTime queryName="cmis:lastModificationDate" displayName="Last Modified Date"
+ localName="lastModificationDate" propertyDefinitionId="cmis:lastModificationDate">
+ <cmis:value>2010-09-28T12:51:47.851+01:00</cmis:value>
+ </cmis:propertyDateTime>
+ <cmis:propertyId queryName="cmis:parentId" displayName="Parent Id" localName="parentId"
+ propertyDefinitionId="cmis:parentId">
+ <cmis:value>workspace://SpacesStore/87b2f129-3ad0-4a46-a6ea-05ecbfb54aa1</cmis:value>
+ </cmis:propertyId>
+ <aspects:aspects xmlns="http://www.alfresco.org" xmlns:aspects="http://www.alfresco.org">
+ <appliedAspects>P:app:uifacets</appliedAspects>
+ <properties>
+ <cmis:propertyString xmlns="http://docs.oasis-open.org/ns/cmis/core/200908/"
+ xmlns:ns0="http://docs.oasis-open.org/ns/cmis/core/200908/" propertyDefinitionId="app:icon">
+ <value>space-icon-default</value>
+ </cmis:propertyString>
+ <cmis:propertyString xmlns="http://docs.oasis-open.org/ns/cmis/core/200908/"
+ xmlns:ns0="http://docs.oasis-open.org/ns/cmis/core/200908/" propertyDefinitionId="cm:description">
+ <value>User managed definitions</value>
+ </cmis:propertyString>
+ <cmis:propertyString xmlns="http://docs.oasis-open.org/ns/cmis/core/200908/"
+ xmlns:ns0="http://docs.oasis-open.org/ns/cmis/core/200908/" propertyDefinitionId="cmis:policyText" />
+ <cmis:propertyString xmlns="http://docs.oasis-open.org/ns/cmis/core/200908/"
+ xmlns:ns0="http://docs.oasis-open.org/ns/cmis/core/200908/" propertyDefinitionId="cm:title">
+ <value>Data Dictionary</value>
+ </cmis:propertyString>
+ </properties>
+ <appliedAspects>P:cm:titled</appliedAspects>
+ <appliedAspects>P:sys:localized</appliedAspects>
+ </aspects:aspects>
+ </cmis:properties>
+ </cmisra:object>
+ <atom:link rel="service"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7?repositoryId=371554cd-ac06-40ba-98b8-e6b60275cca7"
+ type="application/atomsvc+xml" />
+ <atom:link rel="self"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/entry?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=entry" cmisra:id="workspace://SpacesStore/93ef9ce4-5811-4401-917d-f48ffa93d84d" />
+ <atom:link rel="enclosure"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/entry?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=entry" />
+ <atom:link rel="edit"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/entry?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=entry" />
+ <atom:link rel="describedby"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/type?id=cmis%3Afolder" type="application/atom+xml;type=entry" />
+ <atom:link rel="http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/allowableactions?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/cmisallowableactions+xml" />
+ <atom:link rel="up"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/parents?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=feed" />
+ <atom:link rel="down"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/children?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=feed" />
+ <atom:link rel="down"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/descendants?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/cmistree+xml" />
+ <atom:link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/foldertree?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/cmistree+xml" />
+ <atom:link rel="edit"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/entry?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d&returnVersion=latest"
+ type="application/atom+xml;type=entry" />
+ <atom:link rel="http://docs.oasis-open.org/ns/cmis/link/200908/acl"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/acl?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/cmisacl+xml" />
+ <atom:link rel="http://docs.oasis-open.org/ns/cmis/link/200908/policies"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/policies?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=feed" />
+ <atom:link rel="http://docs.oasis-open.org/ns/cmis/link/200908/relationships"
+ href="http://cmis.alfresco.com/cmisatom/371554cd-ac06-40ba-98b8-e6b60275cca7/relationships?id=workspace%3A%2F%2FSpacesStore%2F93ef9ce4-5811-4401-917d-f48ffa93d84d"
+ type="application/atom+xml;type=feed" />
+</atom:entry>