use of javax.xml.transform.dom.DOMResult in project uPortal by Jasig.
the class XmlUtilitiesImpl method convertToDom.
@Override
public Node convertToDom(XMLEventReader xmlEventReader) throws XMLStreamException {
//Convert the XmlEventReader into a DOM
final XMLOutputFactory xmlOutputFactory = this.getXmlOutputFactory();
final DOMResult sourceDom = new DOMResult(DocumentFactory.getThreadDocument());
final XMLEventWriter sourceWriter = xmlOutputFactory.createXMLEventWriter(sourceDom);
sourceWriter.add(xmlEventReader);
sourceWriter.flush();
sourceWriter.close();
return sourceDom.getNode();
}
use of javax.xml.transform.dom.DOMResult in project midpoint by Evolveum.
the class Validator method validateSchema.
// this was made public to allow validation of pre-parsed non-prism documents
public Node validateSchema(Element objectDoc, OperationResult objectResult) {
OperationResult result = objectResult.createSubresult(Validator.class.getName() + ".validateSchema");
DOMResult validationResult = new DOMResult();
try {
xsdValidator.validate(new DOMSource(objectDoc), validationResult);
} catch (SAXException e) {
result.recordFatalError("Validation error: " + e.getMessage(), e);
objectResult.computeStatus("Validation error: " + e.getMessage());
return null;
} catch (IOException e) {
result.recordFatalError("IO error during validation: " + e.getMessage(), e);
objectResult.computeStatus("IO error during validation: " + e.getMessage());
return null;
}
result.recordSuccess();
return validationResult.getNode();
}
use of javax.xml.transform.dom.DOMResult in project midpoint by Evolveum.
the class TestExtraSchema method testExtraSchema.
/**
* Test is extra schema can be loaded to the schema registry and whether the file compliant to that
* schema can be validated.
*/
@Test
public void testExtraSchema() throws SAXException, IOException, SchemaException {
System.out.println("===[ testExtraSchema ]===");
Document dataDoc = DOMUtil.parseFile(new File(COMMON_DIR_PATH, "root-foo.xml"));
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
Document extraSchemaDoc = DOMUtil.parseFile(new File(EXTRA_SCHEMA_DIR, "root.xsd"));
reg.registerSchema(extraSchemaDoc, "file root.xsd");
reg.initialize();
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 lucene-solr by apache.
the class XMLLoader method load.
@Override
public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream, UpdateRequestProcessor processor) throws Exception {
final String charset = ContentStreamBase.getCharsetFromContentType(stream.getContentType());
InputStream is = null;
XMLStreamReader parser = null;
String tr = req.getParams().get(CommonParams.TR, null);
if (tr != null) {
if (req.getCore().getCoreDescriptor().isConfigSetTrusted() == false) {
throw new SolrException(ErrorCode.UNAUTHORIZED, "The configset for this collection was uploaded without any authentication in place," + " and this operation is not available for collections with untrusted configsets. To use this feature, re-upload the configset" + " after enabling authentication and authorization.");
}
final Transformer t = getTransformer(tr, req);
final DOMResult result = new DOMResult();
// an internal result DOM tree, we just access it directly as input for StAX):
try {
is = stream.getStream();
final InputSource isrc = new InputSource(is);
isrc.setEncoding(charset);
final XMLReader xmlr = saxFactory.newSAXParser().getXMLReader();
xmlr.setErrorHandler(xmllog);
xmlr.setEntityResolver(EmptyEntityResolver.SAX_INSTANCE);
final SAXSource source = new SAXSource(xmlr, isrc);
t.transform(source, result);
} catch (TransformerException te) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, te.getMessage(), te);
} finally {
IOUtils.closeQuietly(is);
}
// second step: feed the intermediate DOM tree into StAX parser:
try {
parser = inputFactory.createXMLStreamReader(new DOMSource(result.getNode()));
this.processUpdate(req, processor, parser);
} catch (XMLStreamException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
} finally {
if (parser != null)
parser.close();
}
} else // Normal XML Loader
{
try {
is = stream.getStream();
if (log.isTraceEnabled()) {
final byte[] body = IOUtils.toByteArray(is);
// TODO: The charset may be wrong, as the real charset is later
// determined by the XML parser, the content-type is only used as a hint!
log.trace("body", new String(body, (charset == null) ? ContentStreamBase.DEFAULT_CHARSET : charset));
IOUtils.closeQuietly(is);
is = new ByteArrayInputStream(body);
}
parser = (charset == null) ? inputFactory.createXMLStreamReader(is) : inputFactory.createXMLStreamReader(is, charset);
this.processUpdate(req, processor, parser);
} catch (XMLStreamException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
} finally {
if (parser != null)
parser.close();
IOUtils.closeQuietly(is);
}
}
}
use of javax.xml.transform.dom.DOMResult in project lucene-solr by apache.
the class QueryTemplateManager method getQueryAsDOM.
/**
* Fast means of constructing query using a cached,precompiled stylesheet
*/
public static Document getQueryAsDOM(Properties formProperties, Templates template) throws ParserConfigurationException, TransformerException {
DOMResult result = new DOMResult();
transformCriteria(formProperties, template, result);
return (Document) result.getNode();
}
Aggregations