当前位置: 首页>>代码示例>>Java>>正文


Java DOMUtil.parseDocument方法代码示例

本文整理汇总了Java中com.evolveum.midpoint.util.DOMUtil.parseDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DOMUtil.parseDocument方法的具体用法?Java DOMUtil.parseDocument怎么用?Java DOMUtil.parseDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.evolveum.midpoint.util.DOMUtil的用法示例。


在下文中一共展示了DOMUtil.parseDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: match

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Override
public boolean match(String a, String b) {
	if (a == null && b == null) {
		return true;
	}
	if (a == null || b == null) {
		return false;
	}
	try {
		
		Document docA = DOMUtil.parseDocument(a);
		Document docB = DOMUtil.parseDocument(b);
		return DOMUtil.compareDocument(docA, docB, false, false);
		
	} catch (IllegalStateException | IllegalArgumentException e) {
		LOGGER.warn("Invalid XML in XML matching rule: {}", e.getMessage());
		// Invalid XML. We do not want to throw the exception from matching rule.
		// So fall back to ordinary string comparison.
		return StringUtils.equals(a, b);
	}
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:22,代码来源:XmlMatchingRule.java

示例2: normalize

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Override
public String normalize(String original) {
	if (original == null) {
		return original;
	}
	try {
		
		Document doc = DOMUtil.parseDocument(original);
		DOMUtil.normalize(doc, false);
		String out = DOMUtil.printDom(doc, false, true).toString();
		return out.trim();
		
	} catch (IllegalStateException | IllegalArgumentException e) {
		LOGGER.warn("Invalid XML in XML matching rule: {}", e.getMessage());
		return original.trim();
	}
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:18,代码来源:XmlMatchingRule.java

示例3: testConvertFromProtectedString

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Test(enabled=false)
public void testConvertFromProtectedString() throws SchemaException {
	Document document = DOMUtil.parseDocument(
			"<password xmlns=\""+FOO_NAMESPACE+"\" "+
			"xmlns:c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\" "+
			"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
			"xsi:type=\"c:ProtectedStringType\">"+
			"<c:clearValue>3lizab3th</c:clearValue></password>");
	Element element = DOMUtil.getFirstChildElement(document);
	
	Object value = XmlTypeConverter.toJavaValue(element);
	
	System.out.println("XML -> ProtectedStringType: "+value);
	assertNotNull(value);
	assertTrue(value instanceof ProtectedStringType);
	assertEquals("3lizab3th",((ProtectedStringType)value).getClearValue());
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:18,代码来源:XsdTypeConverterTest.java

示例4: testExtensionClob

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Test
public void testExtensionClob() throws Exception {
    Session session = getFactory().openSession();

    QName valueName = new QName(NS_P, "locations");
    ItemDefinition def = getDefinition(GenericObjectType.class, new ItemPath(ObjectType.F_EXTENSION, valueName));
    AssertJUnit.assertNotNull(def);

    Document document = DOMUtil.getDocument();
    Element value = DOMUtil.createElement(document, valueName);
    Element location = DOMUtil.createElement(document, new QName(NS_P, "location"));
    value.appendChild(location);
    location.setAttribute("key", "heaven");
    location.setTextContent("somewhere above");

    Object realValue = RAnyConverter.getRealRepoValue(def, value);
    //asserting simple dom
    document = DOMUtil.parseDocument((String) realValue);
    Element root = document.getDocumentElement();
    AssertJUnit.assertNotNull(root);
    AssertJUnit.assertEquals("locations", root.getLocalName());
    AssertJUnit.assertEquals(NS_P, root.getNamespaceURI());
    AssertJUnit.assertEquals(1, DOMUtil.listChildElements(root).size());

    location = DOMUtil.listChildElements(root).get(0);
    AssertJUnit.assertNotNull(location);
    AssertJUnit.assertEquals("location", location.getLocalName());
    AssertJUnit.assertEquals(NS_P, location.getNamespaceURI());
    AssertJUnit.assertEquals(0, DOMUtil.listChildElements(location).size());
    AssertJUnit.assertEquals("heaven", location.getAttribute("key"));
    AssertJUnit.assertEquals("somewhere above", location.getTextContent());

    session.close();
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:35,代码来源:RAnyConverterStaticTest.java

示例5: toItemPath

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
private ItemPath toItemPath(String stringPath) {
	String xml = "<path " +
			"xmlns='"+SchemaConstants.NS_C+"' " +
			"xmlns:t='"+SchemaConstants.NS_TYPES+"'>" + 
			stringPath + "</path>";
	Document doc = DOMUtil.parseDocument(xml);
	Element element = DOMUtil.getFirstChildElement(doc);
	return new ItemPathHolder(element).toItemPath();
	
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:11,代码来源:TestExpressionUtil.java

示例6: test200ExportUsers

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Test
   public void test200ExportUsers() throws Exception {
	final String TEST_NAME = "test200ExportUsers";
       displayTestTile(TEST_NAME);

       // GIVEN
       Task task = createTask(TEST_NAME);
       OperationResult result = task.getResult();
  
       // WHEN
       displayWhen(TEST_NAME);
       List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, 
       		SelectorOptions.createCollection(ItemPath.EMPTY_PATH, GetOperationOptions.createRaw()), task, result);
       
       // THEN
       displayThen(TEST_NAME);
       assertSuccess(result);

       assertEquals("Unexpected number of users", 5, users.size());
       for (PrismObject<UserType> user: users) {
       	display("Exporting user", user);
       	assertNotNull("Null definition in "+user, user.getDefinition());
       	display("Definition", user.getDefinition());
       	String xmlString = prismContext.serializerFor(PrismContext.LANG_XML).serialize(user);
       	display("Exported user", xmlString);
       	
       	Document xmlDocument = DOMUtil.parseDocument(xmlString);
   		Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
   		Validator validator = javaxSchema.newValidator();
   		validator.setResourceResolver(prismContext.getEntityResolver());
   		validator.validate(new DOMSource(xmlDocument));
   		
   		PrismObject<Objectable> parsedUser = prismContext.parseObject(xmlString);
   		assertTrue("Re-parsed user is not equal to original: "+user, user.equals(parsedUser));
   		
       }
       
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:39,代码来源:TestMisc.java

示例7: serializeAndValidate

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
private void serializeAndValidate(PrismObject<UserType> user, PrismContext prismContext) throws SchemaException, SAXException, IOException {
	String xmlString = prismContext.serializeObjectToString(user, PrismContext.LANG_XML);
	System.out.println("Serialized XML");
	System.out.println(xmlString);
	Document xmlDocument = DOMUtil.parseDocument(xmlString);
	Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
	Validator validator = javaxSchema.newValidator();
	validator.setResourceResolver(prismContext.getEntityResolver());
	validator.validate(new DOMSource(xmlDocument));
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:11,代码来源:TestPrismObjectConstruction.java

示例8: validateObject

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
public EventResult validateObject(String stringXml, OperationResult objectResult) {
	Document objectDoc = DOMUtil.parseDocument(stringXml);
	Element objectElement = DOMUtil.getFirstChildElement(objectDoc);
	return validateObjectInternal(objectElement, objectResult, objectResult);
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:6,代码来源:Validator.java

示例9: testRoundTripGeneric

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Test
public void testRoundTripGeneric() throws SchemaException {
	// GIVEN
	PrismSchemaImpl schema = new PrismSchemaImpl(SCHEMA_NS, PrismTestUtil.getPrismContext());
	// Ordinary property
	schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
	
	// Property container
	PrismContainerDefinitionImpl containerDefinition = schema.createPropertyContainerDefinition("ContainerType");
	// ... in it ordinary property
	containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
	// ... and local property with a type from another schema
	containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
	// ... property reference
	containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
	// ... read-only int property 
	PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
	((PrismPropertyDefinitionImpl) counterProperty).setReadOnly();

	System.out.println("Generic schema before serializing to XSD: ");
	System.out.println(schema.debugDump());
	System.out.println();

	// WHEN
	
	Document xsd = schema.serializeToXsd();
	
	String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
	
	System.out.println("Generic schema after serializing to XSD: ");
	System.out.println(stringXmlSchema);
	System.out.println();
	
	Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
	
	PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());

	System.out.println("Generic schema after parsing from XSD: ");
	System.out.println(newSchema.debugDump());
	System.out.println();
	
	// THEN

	PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new QName(SCHEMA_NS,"number1"), PrismPropertyDefinition.class);
	assertEquals(new QName(SCHEMA_NS,"number1"),number1def.getName());
	assertEquals(DOMUtil.XSD_INT,number1def.getTypeName());
	
	PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new QName(SCHEMA_NS,"ContainerType"));
	assertEquals(new QName(SCHEMA_NS,"ContainerType"),newContainerDef.getTypeName());
	
	PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS,"login"));
	assertEquals(new QName(SCHEMA_NS,"login"), loginDef.getName());
	assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
	assertTrue("Read flag is wrong",loginDef.canRead());
	assertTrue("Create flag is wrong",loginDef.canAdd());
	assertTrue("Update flag is wrong",loginDef.canModify());

	PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS,"password"));
	assertEquals(new QName(SCHEMA_NS,"password"), passwdDef.getName());
	assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());

	PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new QName(SchemaConstants.NS_C,"credentials"));
	assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
	assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());

	PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS,"counter"));
	assertEquals(new QName(SCHEMA_NS,"counter"), countDef.getName());
	assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
	assertTrue("Read flag is wrong",countDef.canRead());
	assertFalse("Create flag is wrong",countDef.canAdd());
	assertFalse("Update flag is wrong",countDef.canModify());
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:73,代码来源:SchemaProcessorTest.java

示例10: testRoundTripResource

import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
@Test
	public void testRoundTripResource() throws SchemaException {
		// GIVEN
		ResourceSchemaImpl schema = new ResourceSchemaImpl(SCHEMA_NS, PrismTestUtil.getPrismContext());
		
		// Property container
		ObjectClassComplexTypeDefinitionImpl containerDefinition = (ObjectClassComplexTypeDefinitionImpl) schema.createObjectClassDefinition("AccountObjectClass");
		containerDefinition.setKind(ShadowKindType.ACCOUNT);
		containerDefinition.setDefaultInAKind(true);
		containerDefinition.setNativeObjectClass("ACCOUNT");
		// ... in it ordinary attribute - an identifier
		ResourceAttributeDefinitionImpl xloginDef = containerDefinition.createAttributeDefinition("login", DOMUtil.XSD_STRING);
		containerDefinition.addPrimaryIdentifier(xloginDef);
		xloginDef.setNativeAttributeName("LOGIN");
		containerDefinition.setDisplayNameAttribute(xloginDef.getName());
		// ... and local property with a type from another schema
		ResourceAttributeDefinitionImpl xpasswdDef = containerDefinition.createAttributeDefinition("password", ProtectedStringType.COMPLEX_TYPE);
		xpasswdDef.setNativeAttributeName("PASSWORD");
		// ... property reference
		// TODO this is not a ResourceAttributeDefinition, it cannot be placed here!
		//containerDefinition.createAttributeDefinition(SchemaConstants.C_CREDENTIALS, SchemaConstants.C_CREDENTIALS_TYPE);
		// ... ignored attribute
		ResourceAttributeDefinitionImpl xSepDef = containerDefinition.createAttributeDefinition("sep", DOMUtil.XSD_STRING);
		xSepDef.setIgnored(true);

		System.out.println("Resource schema before serializing to XSD: ");
		System.out.println(schema.debugDump());
		System.out.println();

		// WHEN
		
		Document xsd = schema.serializeToXsd();
		
		String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
		
		System.out.println("Resource schema after serializing to XSD: ");
		System.out.println(stringXmlSchema);
		System.out.println();
		
		Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
		
		ResourceSchema newSchema = ResourceSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), "serialized schema", PrismTestUtil.getPrismContext());

		System.out.println("Resource schema after parsing from XSD: ");
		System.out.println(newSchema.debugDump());
		System.out.println();
		
		// THEN
			
		ObjectClassComplexTypeDefinition newObjectClassDef = newSchema.findObjectClassDefinition(new QName(SCHEMA_NS,"AccountObjectClass"));
		assertEquals(new QName(SCHEMA_NS,"AccountObjectClass"),newObjectClassDef.getTypeName());
		assertEquals(ShadowKindType.ACCOUNT, newObjectClassDef.getKind());
		assertTrue(newObjectClassDef.isDefaultInAKind());
		
		PrismPropertyDefinition loginDef = newObjectClassDef.findPropertyDefinition(new QName(SCHEMA_NS,"login"));
		assertEquals(new QName(SCHEMA_NS,"login"), loginDef.getName());
		assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
		assertFalse(loginDef.isIgnored());

		PrismPropertyDefinition passwdDef = newObjectClassDef.findPropertyDefinition(new QName(SCHEMA_NS,"password"));
		assertEquals(new QName(SCHEMA_NS,"password"), passwdDef.getName());
		assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
		assertFalse(passwdDef.isIgnored());

//		PrismContainerDefinition credDef = newObjectClassDef.findContainerDefinition(new QName(SchemaConstants.NS_C,"credentials"));
//		assertEquals(new QName(SchemaConstants.NS_C,"credentials"), credDef.getName());
//		assertEquals(new QName(SchemaConstants.NS_C,"CredentialsType"), credDef.getTypeName());
//		assertFalse(credDef.isIgnored());
		
		PrismPropertyDefinition sepDef = newObjectClassDef.findPropertyDefinition(new QName(SCHEMA_NS,"sep"));
		assertEquals(new QName(SCHEMA_NS,"sep"), sepDef.getName());
		assertEquals(DOMUtil.XSD_STRING, sepDef.getTypeName());
		assertTrue(sepDef.isIgnored());
		
	}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:76,代码来源:SchemaProcessorTest.java


注:本文中的com.evolveum.midpoint.util.DOMUtil.parseDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。