private static DomLexicalProcessor getDomParser(@NotNull PrismContext prismContext) { return ((PrismContextImpl) prismContext).getParserDom(); }
private XmlAsStringType unmarshalXmlAsStringFromMap(MapXNodeImpl map, Class<XmlAsStringType> beanClass, ParsingContext parsingContext) throws SchemaException { // reading a string represented a XML-style content // used e.g. when reading report templates (embedded XML) // A necessary condition: there may be only one map entry. if (map.size() > 1) { throw new SchemaException("Map with more than one item cannot be parsed as a string: " + map); } else if (map.isEmpty()) { return new XmlAsStringType(); } else { Entry<QName, XNodeImpl> entry = map.entrySet().iterator().next(); DomLexicalProcessor domParser = ((PrismContextImpl) prismContext).getParserDom(); String value = domParser.write(entry.getValue(), entry.getKey(), null); return new XmlAsStringType(value); } }
final DomLexicalProcessor domLexicalProcessor = ((PrismContextImpl) prismContext).getParserDom(); String ok = domLexicalProcessor.write(valOkNode, new QName("ok"), null); System.out.println("correct value serialized to: " + ok);
/** * TODO rewrite this method using Prism API */ @Override public void serializeFaultMessage(Detail detail, Object faultInfo, QName faultMessageElementName, Trace logger) { try { XNodeImpl faultMessageXnode = prismContext.getBeanMarshaller().marshall(faultInfo); RootXNodeImpl xroot = new RootXNodeImpl(faultMessageElementName, faultMessageXnode); xroot.setExplicitTypeDeclaration(true); QName faultType = prismContext.getSchemaRegistry().determineTypeForClass(faultInfo.getClass()); xroot.setTypeQName(faultType); prismContext.getParserDom().serializeUnderElement(xroot, faultMessageElementName, detail); } catch (SchemaException e) { logger.error("Error serializing fault message (SOAP fault detail): {}", e.getMessage(), e); } }
@Test public void testParseResourceDom() throws Exception { if (!"xml".equals(language)) { return; } final String TEST_NAME = "testParseResourceDom"; displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = getPrismContext(); // WHEN DomLexicalProcessor parserDom = ((PrismContextImpl) prismContext).getParserDom(); RootXNode xnode = parserDom.read(new ParserFileSource(getFile(TestConstants.RESOURCE_FILE_BASENAME)), createDefaultParsingContext()); PrismObject<ResourceType> resource = prismContext.parserFor(xnode).parse(); // THEN System.out.println("Parsed resource:"); System.out.println(resource.debugDump()); assertResource(resource, true, true, false); }