Search in sources :

Example 56 with Format

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);
}
Also used : Element(org.jdom2.Element)

Example 57 with Format

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());
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 58 with Format

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;
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 59 with Format

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();
}
Also used : Element(org.jdom2.Element)

Example 60 with Format

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;
}
Also used : Element(org.jdom2.Element) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Element (org.jdom2.Element)56 Document (org.jdom2.Document)20 XMLOutputter (org.jdom2.output.XMLOutputter)19 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)9 Attribute (org.jdom2.Attribute)9 Format (org.jdom2.output.Format)7 File (java.io.File)5 ArrayList (java.util.ArrayList)5 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)5 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)5 JsonWriter (com.google.gson.stream.JsonWriter)4 Date (java.util.Date)4 SAXBuilder (org.jdom2.input.SAXBuilder)4 SimpleDateFormat (java.text.SimpleDateFormat)3 JDOMException (org.jdom2.JDOMException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 JComponent (javax.swing.JComponent)2