Search in sources :

Example 26 with Format

use of org.jdom2.output.Format in project mycore by MyCoRe-Org.

the class MCRAccessControlSystem method getRule.

@Override
public Element getRule(String objID, String permission) {
    MCRAccessRule accessRule = getAccessRule(objID, permission);
    MCRRuleParser parser = new MCRRuleParser();
    Element rule = parser.parse(accessRule.rule).toXML();
    Element condition = new Element("condition");
    condition.setAttribute("format", "xml");
    if (rule != null) {
        condition.addContent(rule);
    }
    return condition;
}
Also used : Element(org.jdom2.Element)

Example 27 with Format

use of org.jdom2.output.Format in project mycore by MyCoRe-Org.

the class MCRAccessManager method getFalseRule.

/**
 * return a rule, that forbids something for all, but superuser
 *
 * @return a rule, that forbids something for all, but superuser
 */
public static Element getFalseRule() {
    Element condition = new Element("condition");
    condition.setAttribute("format", "xml");
    Element booleanOp = new Element("boolean");
    booleanOp.setAttribute("operator", "false");
    condition.addContent(booleanOp);
    return condition;
}
Also used : Element(org.jdom2.Element)

Example 28 with Format

use of org.jdom2.output.Format in project mycore by MyCoRe-Org.

the class MCRDirectoryXML method addTime.

private void addTime(Element parent, String type, int hh, int mm, int ss) {
    Element xTime = new Element(type);
    parent.addContent(xTime);
    GregorianCalendar date = new GregorianCalendar(TimeZone.getDefault(), Locale.ROOT);
    date.set(2002, Calendar.FEBRUARY, 1, hh, mm, ss);
    String time = timeFormatter.format(date.getTime());
    xTime.setAttribute("format", timeFormat);
    xTime.addContent(time);
}
Also used : Element(org.jdom2.Element) GregorianCalendar(java.util.GregorianCalendar)

Example 29 with Format

use of org.jdom2.output.Format in project mycore by MyCoRe-Org.

the class MCRWCMSUtil method convertToOldFormat.

/**
 * Converts the navigation.xml to the old format.
 */
private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new ByteArrayInputStream(xml));
    Element rootElement = doc.getRootElement();
    rootElement.setAttribute("href", rootElement.getName());
    List<org.jdom2.Element> children = rootElement.getChildren();
    for (Element menu : children) {
        String id = menu.getAttributeValue("id");
        menu.setName(id);
        menu.setAttribute("href", id);
        menu.removeAttribute("id");
    }
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length);
    out.output(doc, bout);
    return bout.toByteArray();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jdom2.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom2.Document)

Example 30 with Format

use of org.jdom2.output.Format in project mycore by MyCoRe-Org.

the class MCRXMLFunctions method getISODateFromMCRHistoryDate.

/**
 * The method get a date String in format yyyy-MM-ddThh:mm:ssZ for ancient date values.
 *
 * @param date_value the date string
 * @param field_name the name of field of MCRMetaHistoryDate, it should be 'von' or 'bis'
 * @param calendar_name the name if the calendar defined in MCRCalendar
 * @return the date in format yyyy-MM-ddThh:mm:ssZ
 */
public static String getISODateFromMCRHistoryDate(String date_value, String field_name, String calendar_name) throws ParseException {
    String formatted_date;
    if (field_name == null || field_name.trim().length() == 0) {
        return "";
    }
    boolean use_last_value = false;
    if ("bis".equals(field_name)) {
        use_last_value = true;
    }
    try {
        Calendar calendar = MCRCalendar.getHistoryDateAsCalendar(date_value, use_last_value, calendar_name);
        GregorianCalendar g_calendar = MCRCalendar.getGregorianCalendarOfACalendar(calendar);
        formatted_date = MCRCalendar.getCalendarDateToFormattedString(g_calendar, "yyyy-MM-dd") + "T00:00:00.000Z";
        if (g_calendar.get(GregorianCalendar.ERA) == GregorianCalendar.BC) {
            formatted_date = "-" + formatted_date;
        }
    } catch (Exception e) {
        String errorMsg = "Error while converting date string : " + date_value + " - " + use_last_value + " - " + calendar_name;
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(errorMsg, e);
        }
        LOGGER.warn(errorMsg);
        return "";
    }
    return formatted_date;
}
Also used : GregorianCalendar(com.ibm.icu.util.GregorianCalendar) MCRCalendar(org.mycore.common.MCRCalendar) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom2.JDOMException) ParseException(java.text.ParseException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransformerException(javax.xml.transform.TransformerException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

Element (org.jdom2.Element)57 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