use of org.jdom2.Content 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);
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRFile method setContentFrom.
/**
* Sets the content of this file from a JDOM xml document.
*
* @param xml
* the JDOM xml document that should be stored as file content
*/
public void setContentFrom(Document xml) {
Objects.requireNonNull(xml, "jdom xml document is null");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new XMLOutputter().output(xml, baos);
baos.close();
} catch (IOException ignored) {
}
setContentFrom(baos.toByteArray());
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRObject method createXML.
/**
* This method creates a XML stream for all object data.
*
* @exception MCRException
* if the content of this class is not valid
* @return a JDOM Document with the XML data of the object as byte array
*/
@Override
public final Document createXML() throws MCRException {
try {
Document doc = super.createXML();
Element elm = doc.getRootElement();
elm.addContent(mcr_struct.createXML());
elm.addContent(mcr_metadata.createXML());
elm.addContent(mcr_service.createXML());
return doc;
} catch (MCRException exc) {
throw new MCRException("The content of '" + mcr_id + "' is invalid.", exc);
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRWebsiteWriteProtection method getConfiguration.
private static Element getConfiguration() {
// try to get file
File configFolder = new File(CONFIG_FOLDER_PATH);
if (!configFolder.exists()) {
configFolder.mkdirs();
}
// file exist?, return it's content
if (CONFIG_FILE.exists()) {
Element config = null;
// try to get from cache
if (cacheValid()) {
config = configCache;
} else {
SAXBuilder builder = new SAXBuilder();
try {
config = builder.build(CONFIG_FILE).getRootElement();
// update cache
updateCache(config);
} catch (JDOMException | IOException e) {
e.printStackTrace();
return null;
}
}
return config;
} else {
// create XML
Element config = configToJDOM(false, " ");
setConfiguration(config);
return config;
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRMetaAccessRule method createXML.
/**
* This method create a XML stream for all data in this class, defined by
* the MyCoRe XML MCRMetaAccessRule definition for the given subtag.
*
* @exception MCRException
* if the content of this class is not valid
* @return a JDOM Element with the XML MCRMetaAccessRule part
*/
@Override
public org.jdom2.Element createXML() throws MCRException {
Element elm = super.createXML();
elm.setAttribute("permission", permission);
elm.addContent(condition.clone());
return elm;
}
Aggregations