use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRDirectoryXML method addDate.
private void addDate(Element parent, String type, GregorianCalendar date) {
Element xDate = new Element("date");
parent.addContent(xDate);
xDate.setAttribute("type", type);
String time = dateFormatter.format(date.getTime());
xDate.setAttribute("format", dateFormat);
xDate.addContent(time);
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRMetaISO8601DateTest method setFromDOM.
@Test
public void setFromDOM() {
MCRMetaISO8601Date ts = new MCRMetaISO8601Date();
Element datum = new Element("datum");
datum.setAttribute("inherited", "0").setText("2006-01-23");
ts.setFromDOM(datum);
assertEquals("Dates not equal", "2006-01-23", ts.getISOString());
datum.setAttribute("format", MCRISO8601Format.COMPLETE_HH_MM.toString());
ts.setFromDOM(datum);
assertNull("Date should be null", ts.getDate());
assertEquals("Format should be set by jdom", MCRISO8601Format.COMPLETE_HH_MM.toString(), ts.getFormat());
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRAccessCommands method getRuleFromFile.
private static Element getRuleFromFile(String fileName) throws Exception {
if (!checkFilename(fileName)) {
LOGGER.warn("Wrong file format or file doesn't exist");
return null;
}
Document ruleDom = MCRXMLParserFactory.getParser().parseXML(new MCRFileContent(fileName));
Element rule = ruleDom.getRootElement();
if (!rule.getName().equals("condition")) {
LOGGER.warn("ROOT element is not valid, a valid rule would be for example:");
LOGGER.warn("<condition format=\"xml\"><boolean operator=\"true\" /></condition>");
return null;
}
return rule;
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRMetaISO8601Date method createXML.
/*
* (non-Javadoc)
*
* @see org.mycore.datamodel.metadata.MCRMetaDefault#createXML()
*/
@Override
public Element createXML() throws MCRException {
if (!changed) {
return export.clone();
}
Element elm = super.createXML();
if (!(isoDate.getIsoFormat() == null || isoDate.getIsoFormat() == MCRISO8601Format.COMPLETE_HH_MM_SS_SSS)) {
elm.setAttribute("format", isoDate.getIsoFormat().toString());
}
elm.setText(getISOString());
export = elm;
changed = false;
return export.clone();
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRQuery method parseXML.
/**
* Parses a XML representation of a query.
*
* @param doc
* the XML document
* @return the parsed MCRQuery
*/
public static MCRQuery parseXML(Document doc) {
Element xml = doc.getRootElement();
Element conditions = xml.getChild("conditions");
MCRQuery query = null;
if (conditions.getAttributeValue("format", "xml").equals("xml")) {
Element condElem = conditions.getChildren().get(0);
query = new MCRQuery(new MCRQueryParser().parse(condElem));
} else {
String queryString = conditions.getTextTrim();
query = new MCRQuery(new MCRQueryParser().parse(queryString));
}
String max = xml.getAttributeValue("maxResults", "");
if (max.length() > 0) {
query.setMaxResults(Integer.parseInt(max));
}
List<MCRSortBy> sortBy = null;
Element sortByElem = xml.getChild("sortBy");
if (sortByElem != null) {
List children = sortByElem.getChildren();
sortBy = new ArrayList<>(children.size());
for (Object aChildren : children) {
Element sortByChild = (Element) aChildren;
String name = sortByChild.getAttributeValue("name");
String ad = sortByChild.getAttributeValue("order");
boolean direction = "ascending".equals(ad) ? MCRSortBy.ASCENDING : MCRSortBy.DESCENDING;
sortBy.add(new MCRSortBy(name, direction));
}
}
if (sortBy != null) {
query.setSortBy(sortBy);
}
Element returns = xml.getChild("returnFields");
if (returns != null) {
query.setReturnFields(returns.getText());
}
return query;
}
Aggregations