本文整理汇总了Java中org.ofbiz.base.util.UtilXml.fromXml方法的典型用法代码示例。如果您正苦于以下问题:Java UtilXml.fromXml方法的具体用法?Java UtilXml.fromXml怎么用?Java UtilXml.fromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ofbiz.base.util.UtilXml
的用法示例。
在下文中一共展示了UtilXml.fromXml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testXmlSerialization
import org.ofbiz.base.util.UtilXml; //导入方法依赖的package包/类
public void testXmlSerialization() throws Exception {
// Must use the default delegator because the deserialized GenericValue can't
// find the randomized one.
Delegator localDelegator = DelegatorFactory.getDelegator("default");
boolean transBegin = TransactionUtil.begin();
localDelegator.create("TestingType", "testingTypeId", "TEST-5", "description", "Testing Type #5");
GenericValue testValue = EntityQuery.use(localDelegator).from("TestingType").where("testingTypeId", "TEST-5").queryOne();
assertEquals("Retrieved value has the correct description", "Testing Type #5", testValue.getString("description"));
String newValueStr = UtilXml.toXml(testValue);
GenericValue newValue = (GenericValue) UtilXml.fromXml(newValueStr);
assertEquals("Retrieved value has the correct description", "Testing Type #5", newValue.getString("description"));
newValue.put("description", "XML Testing Type #5");
newValue.store();
newValue = EntityQuery.use(localDelegator).from("TestingType").where("testingTypeId", "TEST-5").queryOne();
assertEquals("Retrieved value has the correct description", "XML Testing Type #5", newValue.getString("description"));
TransactionUtil.rollback(transBegin, null, null);
}
示例2: testUnsupportedClassConverter
import org.ofbiz.base.util.UtilXml; //导入方法依赖的package包/类
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) {
}
}
示例3: deserialize
import org.ofbiz.base.util.UtilXml; //导入方法依赖的package包/类
/** Deserialize a Java object from an XML string. <p>This method should be used with caution.
* If the XML string contains a serialized <code>GenericValue</code> or <code>GenericPK</code>
* then it is possible to unintentionally corrupt the database.</p>
*
* @param content the content
* @param delegator the delegator
* @return return a deserialized object from XML string
* @throws SerializeException
* @throws SAXException
* @throws ParserConfigurationException
* @throws IOException
*/
public static Object deserialize(String content, Delegator delegator)
throws SerializeException, SAXException, ParserConfigurationException, IOException {
// readXmlDocument with false second parameter to disable validation
Document document = UtilXml.readXmlDocument(content, false);
if (document != null) {
if (!"ofbiz-ser".equals(document.getDocumentElement().getTagName())) {
return UtilXml.fromXml(content);
}
return deserialize(document, delegator);
} else {
Debug.logWarning("Serialized document came back null", module);
return null;
}
}