use of javax.xml.transform.dom.DOMResult in project gocd by gocd.
the class XsltStylesheet method tryXsltTransformation.
private DOMResult tryXsltTransformation(ThreadContext context, IRubyObject[] args, DOMSource domSource, NokogiriXsltErrorListener elistener) throws TransformerException {
Transformer transf = sheet.newTransformer();
transf.reset();
transf.setErrorListener(elistener);
if (args.length > 1) {
addParametersToTransformer(context, transf, args[1]);
}
DOMResult result = new DOMResult();
transf.transform(domSource, result);
return result;
}
use of javax.xml.transform.dom.DOMResult in project midpoint by Evolveum.
the class TestExtraSchema method testUserExtensionSchemaParseUser.
@Test
public void testUserExtensionSchemaParseUser() throws SAXException, IOException, SchemaException {
System.out.println("===[ testUserExtensionSchemaParseUser ]===");
Document dataDoc = DOMUtil.parseFile(USER_JACK_FILE_XML);
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
context.initialize();
// Parsing user
// items from user extension are not correctly defined in the schema
PrismObject<UserType> user = context.parserFor(DOMUtil.getFirstChildElement(dataDoc)).compat().parse();
assertNotNull("No definition for user", user.getDefinition());
System.out.println("Parsed root object:");
System.out.println(user.debugDump());
// TODO: assert user
// Try javax schemas by validating a XML file
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(dataDoc), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.transform.dom.DOMResult in project midpoint by Evolveum.
the class TestSchemaRegistry method testBasic.
/**
* Test whether the midpoint prism context was constructed OK and if it can validate
* ordinary user object.
*/
@Test
public void testBasic() throws SAXException, IOException, SchemaException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry reg = context.getSchemaRegistry();
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
// Try to use the schema to validate Jack
// PrismObject<UserType> user = context.parseObject(new File("src/test/resources/common/user-jack.xml"));
// Element document = context.serializeToDom(user);
Document document = DOMUtil.parseFile("src/test/resources/common/user-jack.xml");
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(document), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.transform.dom.DOMResult in project jdk8u_jdk by JetBrains.
the class BooleanAttributes method test.
public static void test(String mimeType, boolean useStreamMeta, String metaXml, String... boolXpaths) throws Exception {
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
iw.setOutput(ios);
ImageWriteParam param = null;
IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
IIOMetadata imageMeta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
Source src = new StreamSource(new StringReader(metaXml));
DOMResult dst = new DOMResult();
transform(src, dst);
Document doc = (Document) dst.getNode();
Element node = doc.getDocumentElement();
String metaFormat = node.getNodeName();
// Verify that the default metadata gets formatted correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, false);
meta.mergeTree(metaFormat, node);
// Verify that the merged metadata gets formatte correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, true);
iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
iw.dispose();
ios.close();
ImageReader ir = ImageIO.getImageReader(iw);
byte[] bytes = os.toByteArray();
if (bytes.length == 0)
throw new AssertionError("Zero length image file");
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
ir.setInput(iis);
if (useStreamMeta)
meta = ir.getStreamMetadata();
else
meta = ir.getImageMetadata(0);
// Verify again after writing and re-reading the image
verify(meta.getAsTree(metaFormat), boolXpaths, true);
}
use of javax.xml.transform.dom.DOMResult in project jdk8u_jdk by JetBrains.
the class TransformerTest method transformInputStreamToDocument.
private Document transformInputStreamToDocument(Transformer transformer, InputStream sourceStream) throws TransformerException {
DOMResult response = new DOMResult();
transformer.transform(new StreamSource(sourceStream), response);
return (Document) response.getNode();
}
Aggregations