You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2014/01/11 18:39:39 UTC
svn commit: r1557427 - in /ofbiz/trunk/framework/base:
src/org/ofbiz/base/util/UtilXml.java
src/org/ofbiz/base/util/test/UtilXmlTests.java testdef/basetests.xml
Author: adrianc
Date: Sat Jan 11 17:39:38 2014
New Revision: 1557427
URL: http://svn.apache.org/r1557427
Log:
Added the ability to exclude certain classes from XML serialization/deserialization.
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java (with props)
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
ofbiz/trunk/framework/base/testdef/basetests.xml
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java?rev=1557427&r1=1557426&r2=1557427&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java Sat Jan 11 17:39:38 2014
@@ -73,6 +73,11 @@ import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/**
* Utilities methods to simplify dealing with JAXP & DOM XML parsing
@@ -81,7 +86,13 @@ import com.thoughtworks.xstream.XStream;
public class UtilXml {
public static final String module = UtilXml.class.getName();
- protected static final XStream xstream = new XStream();
+ private static final XStream xstream = createXStream();
+
+ private static XStream createXStream() {
+ XStream xstream = new XStream();
+ xstream.registerConverter(new UnsupportedClassConverter());
+ return xstream;
+ }
// ----- DOM Level 3 Load and Save Methods -- //
@@ -1116,4 +1127,26 @@ public class UtilXml {
}
}
}
+
+ private static class UnsupportedClassConverter implements Converter {
+
+ @Override
+ public boolean canConvert(@SuppressWarnings("rawtypes") Class arg0) {
+ if (java.lang.ProcessBuilder.class.equals(arg0)) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void marshal(Object arg0, HierarchicalStreamWriter arg1, MarshallingContext arg2) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object unmarshal(HierarchicalStreamReader arg0, UnmarshallingContext arg1) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
}
Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java?rev=1557427&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java (added)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java Sat Jan 11 17:39:38 2014
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *******************************************************************************/
+package org.ofbiz.base.util.test;
+
+import org.ofbiz.base.test.GenericTestCaseBase;
+import org.ofbiz.base.util.UtilXml;
+
+public class UtilXmlTests extends GenericTestCaseBase {
+
+ public UtilXmlTests(String name) {
+ super(name);
+ }
+
+ public void testUnsupportedClassConverter() throws Exception {
+ String unsupportedClassInXml =
+ "<handler class=\"java.beans.EventHandler\">" +
+ " <target class=\"java.lang.ProcessBuilder\">" +
+ " <command>" +
+ " <string>open</string>" +
+ " <string>.</string>" +
+ " </command>" +
+ " </target>" +
+ " <action>start</action>" +
+ "</handler>";
+ try {
+ @SuppressWarnings("unused")
+ Object unsupportedObject = UtilXml.fromXml(unsupportedClassInXml);
+ fail("Unsupported class in XML");
+ } catch (Exception e) {
+ }
+ }
+}
Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilXmlTests.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Modified: ofbiz/trunk/framework/base/testdef/basetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=1557427&r1=1557426&r2=1557427&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/testdef/basetests.xml (original)
+++ ofbiz/trunk/framework/base/testdef/basetests.xml Sat Jan 11 17:39:38 2014
@@ -37,5 +37,6 @@
<!--junit-test-suite class-name="org.ofbiz.base.util.test.UtilIOTests"/-->
<junit-test-suite class-name="org.ofbiz.base.test.BaseUnitTests"/>
<junit-test-suite class-name="org.ofbiz.base.util.test.UtilPropertiesTests"/>
+ <junit-test-suite class-name="org.ofbiz.base.util.test.UtilXmlTests"/>
</test-group>
</test-suite>