Search in sources :

Example 51 with Format

use of org.jdom2.output.Format in project jspwiki by apache.

the class IndexPlugin method execute.

/**
 * {@inheritDoc}
 */
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
    String include = params.get(PARAM_INCLUDE);
    String exclude = params.get(PARAM_EXCLUDE);
    Element masterDiv = getElement("div", "index");
    Element indexDiv = getElement("div", "header");
    masterDiv.addContent(indexDiv);
    try {
        List<String> pages = listPages(context, include, exclude);
        context.getEngine().getPageSorter().sort(pages);
        char initialChar = ' ';
        Element currentDiv = new Element("div", xmlns_XHTML);
        for (String name : pages) {
            if (name.charAt(0) != initialChar) {
                if (initialChar != ' ') {
                    indexDiv.addContent(" - ");
                }
                initialChar = name.charAt(0);
                masterDiv.addContent(makeHeader(String.valueOf(initialChar)));
                currentDiv = getElement("div", "body");
                masterDiv.addContent(currentDiv);
                indexDiv.addContent(getLink("#" + initialChar, String.valueOf(initialChar)));
            } else {
                currentDiv.addContent(", ");
            }
            currentDiv.addContent(getLink(context.getURL(WikiContext.VIEW, name), name));
        }
    } catch (ProviderException e) {
        log.warn("could not load page index", e);
        throw new PluginException(e.getMessage());
    }
    // serialize to raw format string (no changes to whitespace)
    XMLOutputter out = new XMLOutputter(Format.getRawFormat());
    return out.outputString(masterDiv);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Element(org.jdom2.Element) PluginException(org.apache.wiki.api.exceptions.PluginException)

Example 52 with Format

use of org.jdom2.output.Format in project ldapchai by ldapchai.

the class ChaiResponseSet method rsToChaiXML.

static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
    final Element rootElement = new Element(XML_NODE_ROOT);
    rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED, String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
    rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
    rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
    rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);
    if (rs.caseInsensitive) {
        rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
    }
    if (rs.csIdentifier != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
    }
    if (rs.timestamp != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, getDateFormat().format(rs.timestamp));
    }
    if (rs.crMap != null) {
        for (final Challenge loopChallenge : rs.crMap.keySet()) {
            final Answer answer = rs.crMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }
    if (rs.helpdeskCrMap != null) {
        for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
            final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }
    final Document doc = new Document(rootElement);
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(doc);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Format(org.jdom2.output.Format) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 53 with Format

use of org.jdom2.output.Format in project ldapchai by ldapchai.

the class NmasResponseSet method csToNmasXML.

static String csToNmasXML(final ChallengeSet cs, final String guidValue) {
    final Element rootElement = new Element(NMAS_XML_ROOTNODE);
    rootElement.setAttribute(NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf(cs.getMinRandomRequired()));
    if (guidValue != null) {
        rootElement.setAttribute("GUID", guidValue);
    } else {
        rootElement.setAttribute("GUID", "0");
    }
    for (final Challenge challenge : cs.getChallenges()) {
        final Element loopElement = new Element(NMAS_XML_NODE_CHALLENGE);
        if (challenge.getChallengeText() != null) {
            loopElement.setText(challenge.getChallengeText());
        }
        if (challenge.isAdminDefined()) {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "Admin");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "User");
        }
        if (challenge.isRequired()) {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Required");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Random");
        }
        loopElement.setAttribute(NMAS_XML_ATTR_MIN_LENGTH, String.valueOf(challenge.getMinLength()));
        loopElement.setAttribute(NMAS_XML_ATTR_MAX_LENGTH, String.valueOf(challenge.getMaxLength()));
        rootElement.addContent(loopElement);
    }
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(rootElement);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) Element(org.jdom2.Element) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Example 54 with Format

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

the class MCRAccessManager method getTrueRule.

/**
 * return a rule, that allows something for everybody
 *
 * @return a rule, that allows something for everybody
 */
public static Element getTrueRule() {
    Element condition = new Element("condition");
    condition.setAttribute("format", "xml");
    Element booleanOp = new Element("boolean");
    booleanOp.setAttribute("operator", "true");
    condition.addContent(booleanOp);
    return condition;
}
Also used : Element(org.jdom2.Element)

Example 55 with Format

use of org.jdom2.output.Format 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 &lt;rules&gt; 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);
    }
}
Also used : Element(org.jdom2.Element) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) List(java.util.List) Vector(java.util.Vector)

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