use of org.jdom2.DocType in project pcgen by PCGen.
the class TravelMethodFactory method load.
// ### Factory methods ###
public static Vector<TravelMethod> load(File datadir) {
//Create a new list for the travel methods
Vector<TravelMethod> tms = new Vector<>();
File path = new File(datadir, DIR_TRAVELMETHODS);
if (path.isDirectory()) {
File[] dataFiles = path.listFiles(new XMLFilter());
SAXBuilder builder = new SAXBuilder();
for (int i = 0; i < dataFiles.length; i++) {
try {
Document methodSet = builder.build(dataFiles[i]);
DocType dt = methodSet.getDocType();
if (dt.getElementName().equals(XML_ELEMENT_TRAVEL)) {
//Do work here
TravelMethod tm = TravelMethodFactory.create(methodSet);
tms.add(tm);
}
} catch (Exception e) {
Logging.errorPrint(e.getMessage(), e);
}
}
} else {
//$NON-NLS-1$
Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
}
return tms;
}
use of org.jdom2.DocType in project cas by apereo.
the class AbstractSamlObjectBuilder method toDom.
private static org.w3c.dom.Document toDom(final Document doc) throws Exception {
LOGGER.trace("Creating document from: [{}]", doc);
val xmlOutputter = new XMLOutputter();
val elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
val xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
val dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
}
use of org.jdom2.DocType in project cas by apereo.
the class AbstractSamlObjectBuilder method constructDocumentFromXml.
/**
* Construct document from xml.
*
* @param xmlString the xml string
* @return the document
*/
@SuppressWarnings("java:S2755")
public static Document constructDocumentFromXml(final String xmlString) {
LOGGER.trace("Attempting to construct an instance of Document from xml: [{}]", xmlString);
try {
val builder = new SAXBuilder();
builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
return null;
}
}
use of org.jdom2.DocType in project jena by apache.
the class GMLReader method newSAXBuilder.
// ---- XXE safe SAXBuilder
private static SAXBuilder newSAXBuilder() {
SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
builder.setExpandEntities(false);
return builder;
}
use of org.jdom2.DocType in project mycore by MyCoRe-Org.
the class MCRSimpleFCTDetector method addRule.
/**
* Adds a detection rule from the file content type definition XML file. The
* detector parses the <rules> element provided with each content type
* in the file content types XML definition.
*
* @param type
* the file content type the rule is for
* @param xRules
* the rules XML element containing the rules for detecting that
* type
*/
public void addRule(MCRFileContentType type, Element xRules) {
Vector<MCRDetectionRule> rules = new Vector<>();
rulesTable.put(type, rules);
typesList.add(type);
try {
List extensions = xRules.getChildren("extension");
for (Object extension : extensions) {
Element elem = (Element) extension;
double score = elem.getAttribute("score").getDoubleValue();
String ext = elem.getTextTrim();
rules.addElement(new MCRExtensionRule(ext, score));
}
List patterns = xRules.getChildren("pattern");
for (Object pattern1 : patterns) {
Element elem = (Element) pattern1;
double score = elem.getAttribute("score").getDoubleValue();
int offset = elem.getAttribute("offset").getIntValue();
String format = elem.getAttributeValue("format");
String pattern = elem.getTextTrim();
rules.addElement(new MCRPatternRule(pattern, format, offset, score));
}
List doctypes = xRules.getChildren("doctype");
for (Object doctype1 : doctypes) {
Element elem = (Element) doctype1;
double score = elem.getAttribute("score").getDoubleValue();
String doctype = elem.getTextTrim();
rules.addElement(new MCRDoctypeRule(doctype, score));
}
List strings = xRules.getChildren("string");
for (Object string1 : strings) {
Element elem = (Element) string1;
double score = elem.getAttribute("score").getDoubleValue();
String string = elem.getTextTrim();
rules.addElement(new MCRStringRule(string, score));
}
} catch (Exception exc) {
String msg = "Error parsing detection rules for file content type " + type.getLabel();
throw new MCRConfigurationException(msg, exc);
}
}
Aggregations