You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/03/07 13:12:12 UTC
svn commit: r1453799 - in
/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src:
main/java/org/apache/chemistry/opencmis/commons/impl/
main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/
test/java/org/ap...
Author: fmui
Date: Thu Mar 7 12:12:12 2013
New Revision: 1453799
URL: http://svn.apache.org/r1453799
Log:
CMIS 1.1: more XML code
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/DateTimeHelper.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/CmisExtensionElementImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/DateTimeHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/DateTimeHelper.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/DateTimeHelper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/DateTimeHelper.java Thu Mar 7 12:12:12 2013
@@ -192,6 +192,13 @@ public class DateTimeHelper {
return getFormatter(0).format(cal.getTimeInMillis());
}
+ /**
+ * Clears out cached formatters.
+ */
+ public static void clear() {
+ THREADLOCAL_HTTP_FORMATS.remove();
+ }
+
private static SimpleDateFormat getFormatter(int x) {
SoftReference<SimpleDateFormat[]> ref = THREADLOCAL_HTTP_FORMATS.get();
SimpleDateFormat[] sdfs = ref.get();
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLUtils.java Thu Mar 7 12:12:12 2013
@@ -40,6 +40,25 @@ public class XMLUtils {
public static final String PREFIX_RESTATOM = "cmisra";
public static final String PREFIX_APACHE_CHEMISTY = "chemistry";
+ public static final ThreadLocal<XMLInputFactory> THREADLOCAL_XML_INPUT_FACTORY = new ThreadLocal<XMLInputFactory>() {
+ @Override
+ protected XMLInputFactory initialValue() {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+ factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+ return factory;
+ }
+ };
+
+ public static final ThreadLocal<XMLOutputFactory> THREADLOCAL_XML_OUTPUT_FACTORY = new ThreadLocal<XMLOutputFactory>() {
+ @Override
+ protected XMLOutputFactory initialValue() {
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ return factory;
+ }
+ };
+
// --------------
// --- writer ---
// --------------
@@ -48,9 +67,7 @@ public class XMLUtils {
* Creates a new XML writer.
*/
public static XMLStreamWriter createWriter(OutputStream out) throws XMLStreamException {
- XMLOutputFactory factory = XMLOutputFactory.newInstance();
- factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
- return factory.createXMLStreamWriter(out, "UTF-8");
+ return THREADLOCAL_XML_OUTPUT_FACTORY.get().createXMLStreamWriter(out, "UTF-8");
}
/**
@@ -196,10 +213,7 @@ public class XMLUtils {
* Creates a new XML parser with OpenCMIS default settings.
*/
public static XMLStreamReader createParser(InputStream stream) throws XMLStreamException {
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
- factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
- return factory.createXMLStreamReader(stream);
+ return THREADLOCAL_XML_INPUT_FACTORY.get().createXMLStreamReader(stream);
}
/**
@@ -273,4 +287,12 @@ public class XMLUtils {
return sb == null ? null : sb.toString();
}
+
+ /**
+ * Clears out cached XML factories.
+ */
+ public static void clear() {
+ THREADLOCAL_XML_INPUT_FACTORY.remove();
+ THREADLOCAL_XML_OUTPUT_FACTORY.remove();
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLWalker.java Thu Mar 7 12:12:12 2013
@@ -138,6 +138,8 @@ public abstract class XMLWalker<T> {
}
children.add(handleExtensionLevel(parser, level + 1));
+
+ continue;
}
if (!next(parser)) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/CmisExtensionElementImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/CmisExtensionElementImpl.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/CmisExtensionElementImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/CmisExtensionElementImpl.java Thu Mar 7 12:12:12 2013
@@ -119,6 +119,39 @@ public class CmisExtensionElementImpl im
return attributes;
}
+ public String toTreeString(int level) {
+ StringBuilder sb = new StringBuilder();
+ nextTreelevel(sb, level);
+ return sb.toString();
+ }
+
+ private void nextTreelevel(StringBuilder sb, int level) {
+ for (int i = 0; i < level; i++) {
+ sb.append(" ");
+ }
+
+ sb.append((namespace == null ? "" : "{" + namespace + "}") + name + " " + attributes + ": ");
+
+ if (children.isEmpty()) {
+ sb.append(value);
+ sb.append('\n');
+ } else {
+ sb.append('\n');
+
+ for (CmisExtensionElement element : children) {
+ if (element instanceof CmisExtensionElementImpl) {
+ sb.append(((CmisExtensionElementImpl) element).toTreeString(level + 1));
+ } else if (element != null) {
+ for (int i = 0; i < level + 1; i++) {
+ sb.append(" ");
+ }
+ sb.append(element.toString());
+ sb.append('\n');
+ }
+ }
+ }
+ }
+
@Override
public String toString() {
return (namespace == null ? "" : "{" + namespace + "}") + name + " " + attributes + ": "
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java Thu Mar 7 12:12:12 2013
@@ -290,6 +290,17 @@ public abstract class AbstractXMLConvert
return values[rnd.nextInt(values.length)];
}
+ protected String randomTag() {
+ StringBuilder sb = new StringBuilder();
+
+ int length = rnd.nextInt(7) + 3;
+ for (int i = 0; i < length; i++) {
+ sb.append((char) (rnd.nextInt(26) + 'a'));
+ }
+
+ return sb.toString();
+ }
+
/**
* Compares two data objects.
*/
@@ -308,11 +319,11 @@ public abstract class AbstractXMLConvert
// handle simple types
if ((expected instanceof String) || (expected instanceof Boolean) || (expected instanceof BigInteger)
|| (expected instanceof BigDecimal) || (expected instanceof Enum<?>)) {
- assertEquals(expected, actual);
+ assertEquals(name, expected, actual);
return;
} else if (expected instanceof GregorianCalendar) {
- assertEquals(((GregorianCalendar) expected).getTimeInMillis(),
+ assertEquals(name, ((GregorianCalendar) expected).getTimeInMillis(),
((GregorianCalendar) actual).getTimeInMillis());
return;
@@ -320,7 +331,7 @@ public abstract class AbstractXMLConvert
List<?> expectedList = (List<?>) expected;
List<?> actualList = (List<?>) actual;
- assertEquals(expectedList.size(), actualList.size());
+ assertEquals(name + ".length", expectedList.size(), actualList.size());
for (int i = 0; i < expectedList.size(); i++) {
assertDataObjectsEquals(name + "[" + i + "]", expectedList.get(i), actualList.get(i), ignoreMethods);
@@ -331,7 +342,7 @@ public abstract class AbstractXMLConvert
Map<?, ?> expectedMap = (Map<?, ?>) expected;
Map<?, ?> actualMap = (Map<?, ?>) actual;
- assertEquals(expectedMap.size(), actualMap.size());
+ assertEquals(name + ".length", expectedMap.size(), actualMap.size());
for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
assertTrue(actualMap.containsKey(entry.getKey()));
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java?rev=1453799&r1=1453798&r2=1453799&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java Thu Mar 7 12:12:12 2013
@@ -19,7 +19,6 @@
package org.apache.chemistry.opencmis.commons.impl.xml;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
@@ -34,6 +33,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
import org.apache.chemistry.opencmis.commons.data.ObjectData;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.data.PropertyId;
@@ -50,6 +50,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AllowableActionsImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChangeEventInfoDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
@@ -109,6 +110,7 @@ public class ObjectConvertTest extends A
properties.addProperty(createPropertyData(PropertyType.URI, 0));
properties.addProperty(createPropertyData(PropertyType.URI, 1));
properties.addProperty(createPropertyData(PropertyType.URI, randomInt(8) + 2));
+ properties.setExtensions(createExtensions(3));
result.setProperties(properties);
// allowable actions
@@ -180,6 +182,9 @@ public class ObjectConvertTest extends A
}
result.setRenditions(renditions);
+ // extensions
+ result.setExtensions(createExtensions(5));
+
return result;
}
@@ -291,6 +296,27 @@ public class ObjectConvertTest extends A
return result;
}
+ protected List<CmisExtensionElement> createExtensions(int depth) {
+ List<CmisExtensionElement> result = new ArrayList<CmisExtensionElement>();
+
+ String[] namespaces = new String[] { "http://ext1.com", "http://ext2.org", "http://ext3.net" };
+
+ for (int i = 0; i < randomInt(4) + 1; i++) {
+ String ns = namespaces[randomInt(namespaces.length)];
+
+ CmisExtensionElementImpl element;
+ if (randomBoolean() || depth < 1) {
+ element = new CmisExtensionElementImpl(ns, randomTag(), null, randomString());
+ } else {
+ element = new CmisExtensionElementImpl(ns, randomTag(), null, createExtensions(depth - 1));
+ }
+
+ result.add(element);
+ }
+
+ return result;
+ }
+
protected void assertObjectData10(ObjectData data, boolean validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -310,7 +336,7 @@ public class ObjectConvertTest extends A
assertNotNull(result);
assertDataObjectsEquals("ObjectData", data, result, null);
- assertNull(result.getExtensions());
+ assertNotNull(result.getExtensions());
}
protected void assertObjectData11(ObjectData data, boolean validate) throws Exception {
@@ -332,6 +358,6 @@ public class ObjectConvertTest extends A
assertNotNull(result);
assertDataObjectsEquals("ObjectData", data, result, null);
- assertNull(result.getExtensions());
+ assertNotNull(result.getExtensions());
}
}