use of org.apache.xerces.parsers.DOMParser in project ats-framework by Axway.
the class XmlUtils method getDomParser.
private static DOMParser getDomParser() throws SAXNotRecognizedException, SAXNotSupportedException {
DOMParser parser = new DOMParser();
// Required settings from the DomParser
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
return parser;
}
use of org.apache.xerces.parsers.DOMParser in project ats-framework by Axway.
the class XmlUtils method loadXMLFile.
/**
* Loads an XML file from an InputStream.
* <br>
* Note: the source stream is closed internally
*
* @param configurationFileStream the source stream
* @return the loaded XML document
* @throws IOException for IO error
* @throws SAXException for parsing exception
*/
public static Document loadXMLFile(InputStream configurationFileStream) throws IOException, SAXException {
try {
DOMParser parser = getDomParser();
parser.parse(new InputSource(configurationFileStream));
return parser.getDocument();
} finally {
IoUtils.closeStream(configurationFileStream);
}
}
use of org.apache.xerces.parsers.DOMParser in project gate-core by GateNLP.
the class ControllerMetadataViewer method setTarget.
@Override
public void setTarget(Object target) {
if (target == null)
throw new NullPointerException("received a null target");
if (!(target instanceof Controller))
throw new IllegalArgumentException("not a controller");
Controller controller = (Controller) target;
if (!controller.getFeatures().containsKey("gate.app.MetadataURL"))
throw new IllegalArgumentException("no gate.app.MetadataURL feature");
try {
URL metadata = (URL) controller.getFeatures().get("gate.app.MetadataURL");
URL longDesc = new URL(metadata, "long-desc.html");
URL iconDesc = new URL(metadata, "icon.png");
Document document = builder.parse(metadata.openStream());
Node text = document.getDocumentElement().getElementsByTagName("pipeline-name").item(0).getFirstChild();
Font font = Gate.getUserConfig().getFont(GateConstants.TEXT_COMPONENTS_FONT);
StringBuilder page = new StringBuilder();
page.append("<!DOCTYPE html>");
page.append("<html>");
page.append("<head>");
page.append("<style type='text/css'>body { font-family: ").append(font.getFamily()).append("; font-size: ").append(font.getSize()).append("pt }</style>");
page.append("</head>");
page.append("<body>");
page.append("<h1><img style='vertical-align: middle;' src='").append(StringEscapeUtils.escapeHtml(iconDesc.toString())).append("'/> ").append(StringEscapeUtils.escapeHtml(text.getTextContent())).append("</h1>");
page.append(IOUtils.toString(longDesc, "UTF-8"));
page.append("</body></html>");
// parse using NekoHTML
HTMLConfiguration config = new HTMLConfiguration();
// Force element names to lower case to match XHTML requirements
// as that is what Flying Saucer expects
config.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
DOMParser htmlParser = new DOMParser(config);
htmlParser.parse(new InputSource(new StringReader(page.toString())));
display.setDocument(htmlParser.getDocument(), longDesc.toString());
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
use of org.apache.xerces.parsers.DOMParser in project muikku by otavanopisto.
the class DeusNexMachinaController method determineEmbeddedAssignmentType.
private WorkspaceMaterialAssignmentType determineEmbeddedAssignmentType(HtmlMaterial material) throws DeusNexException {
try {
if (material.getHtml() == null) {
return null;
}
StringReader htmlReader = new StringReader(material.getHtml());
DOMParser parser = new DOMParser();
InputSource inputSource = new InputSource(htmlReader);
parser.parse(inputSource);
org.w3c.dom.Document domDocument = parser.getDocument();
List<Element> elements = DeusNexXmlUtils.getElementsByXPath(domDocument.getDocumentElement(), "//iframe[@data-type=\"embedded-document\"]");
List<WorkspaceMaterialAssignmentType> assignmentTypes = new ArrayList<>();
if (!elements.isEmpty()) {
for (Element element : elements) {
if ("EXERCISE".equals(element.getAttribute("data-assignment-type"))) {
assignmentTypes.add(WorkspaceMaterialAssignmentType.EXERCISE);
}
if ("EVALUATED".equals(element.getAttribute("data-assignment-type"))) {
assignmentTypes.add(WorkspaceMaterialAssignmentType.EVALUATED);
}
}
}
if (assignmentTypes.isEmpty() || (assignmentTypes.contains(WorkspaceMaterialAssignmentType.EXERCISE) && assignmentTypes.contains(WorkspaceMaterialAssignmentType.EVALUATED))) {
return null;
} else {
return assignmentTypes.get(0);
}
} catch (SAXException | IOException | XPathExpressionException e) {
throw new DeusNexInternalException("Embedded assignment type handling failed. ", e);
}
}
use of org.apache.xerces.parsers.DOMParser in project alfresco-repository by Alfresco.
the class ActivitiWorkflowEngine method getProcessKey.
private String getProcessKey(InputStream workflowDefinition) throws Exception {
try {
InputSource inputSource = new InputSource(workflowDefinition);
DOMParser parser = new DOMParser();
parser.parse(inputSource);
Document document = parser.getDocument();
NodeList elemnts = document.getElementsByTagName("process");
if (elemnts.getLength() < 1) {
throw new IllegalArgumentException("The input stream does not contain a process definition!");
}
NamedNodeMap attributes = elemnts.item(0).getAttributes();
Node idAttrib = attributes.getNamedItem("id");
if (idAttrib == null) {
throw new IllegalAccessError("The process definition does not have an id!");
}
if (activitiUtil.isMultiTenantWorkflowDeploymentEnabled()) {
// Workflow-definition is deployed tenant-aware, key should be altered
return factory.getDomainProcessKey(idAttrib.getNodeValue());
} else {
return idAttrib.getNodeValue();
}
} finally {
workflowDefinition.close();
}
}
Aggregations