Example usage for org.jdom2.output Format getCompactFormat

List of usage examples for org.jdom2.output Format getCompactFormat

Introduction

In this page you can find the example usage for org.jdom2.output Format getCompactFormat.

Prototype

public static Format getCompactFormat() 

Source Link

Document

Returns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

From source file:org.kisst.cordys.caas.util.XmlNode.java

License:Open Source License

public String compact() {
    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    return out.outputString(element);
}

From source file:org.mule.tools.apikit.Helper.java

License:Open Source License

public static String nonSpaceOutput(Element element) {
    XMLOutputter xout = new XMLOutputter(Format.getCompactFormat());
    return xout.outputString(element);
}

From source file:org.mule.tools.apikit.Helper.java

License:Open Source License

public static String nonSpaceOutput(Document doc) {
    XMLOutputter xout = new XMLOutputter(Format.getCompactFormat());
    return xout.outputString(doc.getRootElement().getChildren());
}

From source file:org.mycore.common.xml.MCRXMLHelper.java

License:Open Source License

private static Element canonicalElement(Parent e) throws IOException, SAXParseException {
    XMLOutputter xout = new XMLOutputter(Format.getCompactFormat());
    MCRByteArrayOutputStream bout = new MCRByteArrayOutputStream();
    if (e instanceof Element) {
        xout.output((Element) e, bout);
    } else {//from   w  ww . j a va  2 s. com
        xout.output((Document) e, bout);
    }
    Document xml = MCRXMLParserFactory.getNonValidatingParser()
            .parseXML(new MCRByteContent(bout.getBuffer(), 0, bout.size()));
    return xml.getRootElement();
}

From source file:org.mycore.frontend.editor.MCREditorSubmission.java

License:Open Source License

private void validate(MCRRequestParameters parms, Element editor) {
    LOGGER.info("Validating editor input... ");

    for (Enumeration e = parms.getParameterNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();

        if (!name.startsWith("_sortnr-")) {
            continue;
        }// ww  w.j a v  a  2s.  c  om

        name = name.substring(8);

        String ID = parms.getParameter("_id@" + name);

        if (ID == null || ID.trim().length() == 0) {
            continue;
        }

        String[] values = { "" };

        if (parms.getParameterValues(name) != null) {
            values = parms.getParameterValues(name);
        }

        Element component = MCREditorDefReader.findElementByID(ID, editor);

        if (component == null) {
            continue;
        }

        List conditions = component.getChildren("condition");

        if (conditions == null) {
            continue;
        }

        // Skip variables with values equal to autofill text
        String attrib = component.getAttributeValue("autofill");
        String elem = component.getChildTextTrim("autofill");
        String autofill = null;

        if (attrib != null && attrib.trim().length() > 0) {
            autofill = attrib.trim();
        } else if (attrib != null && attrib.trim().length() > 0) {
            autofill = elem.trim();
        }

        if (values[0].trim().equals(autofill)) {
            values[0] = "";
        }

        for (Object condition1 : conditions) {
            Element condition = (Element) condition1;

            boolean ok = true;
            for (int j = 0; j < values.length && ok; j++) {
                String nname = j == 0 ? name : name + "[" + (j + 1) + "]";
                ok = checkCondition(condition, nname, values[j]);

                if (!ok) {
                    String sortNr = parms.getParameter("_sortnr-" + name);
                    failed.put(sortNr, condition);

                    if (LOGGER.isDebugEnabled()) {
                        String cond = new XMLOutputter(Format.getCompactFormat()).outputString(condition);
                        LOGGER.debug("Validation condition failed:");
                        LOGGER.debug(nname + " = \"" + values[j] + "\"");
                        LOGGER.debug(cond);
                    }
                }
            }
        }
    }

    for (Enumeration e = parms.getParameterNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();

        if (!name.startsWith("_cond-")) {
            continue;
        }

        String path = name.substring(6);
        String[] ids = parms.getParameterValues(name);

        if (ids != null) {
            for (String id : ids) {
                Element condition = MCREditorDefReader.findElementByID(id, editor);

                if (condition == null) {
                    continue;
                }

                String field1 = condition.getAttributeValue("field1", "");
                String field2 = condition.getAttributeValue("field2", "");

                if (!field1.isEmpty() || !field2.isEmpty()) {
                    String pathA = path + ((!field1.isEmpty() && !field1.equals(".")) ? "/" + field1 : "");
                    String pathB = path + ((!field2.isEmpty() && !field2.equals(".")) ? "/" + field2 : "");

                    String valueA = parms.getParameter(pathA);
                    String valueB = parms.getParameter(pathB);

                    String sortNrA = parms.getParameter("_sortnr-" + pathA);
                    String sortNrB = parms.getParameter("_sortnr-" + pathB);

                    boolean pairValuesAlreadyInvalid = (failed.containsKey(sortNrA)
                            || failed.containsKey(sortNrB));

                    if (!pairValuesAlreadyInvalid) {
                        MCRValidator validator = MCRValidatorBuilder.buildPredefinedCombinedPairValidator();
                        setValidatorProperties(validator, condition);
                        if (!validator.isValid(valueA, valueB)) {
                            failed.put(sortNrA, condition);
                            failed.put(sortNrB, condition);
                        }
                    }
                } else {
                    XPathExpression<Element> xpath = XPathFactory.instance().compile(path, Filters.element(),
                            null, getNamespaceMap().values());
                    Element current = xpath.evaluateFirst(getXML());
                    if (current == null) {
                        LOGGER.debug("Could not validate, because no element found at xpath " + path);
                        continue;
                    }

                    MCRValidator validator = MCRValidatorBuilder.buildPredefinedCombinedElementValidator();
                    setValidatorProperties(validator, condition);
                    if (!validator.isValid(current)) {
                        String sortNr = parms.getParameter("_sortnr-" + path);
                        failed.put(sortNr, condition);
                    }
                }
            }
        }
    }
}

From source file:org.rascalmpl.library.lang.xml.DOM.java

License:Open Source License

public IString xmlCompact(IConstructor node) throws IOException {
    return xmlToString(node, Format.getCompactFormat());
}

From source file:org.yawlfoundation.yawl.util.JDOMUtil.java

License:Open Source License

/****************************************************************************/

public static String documentToStringDump(Document doc) {
    if (doc == null)
        return null;
    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    return out.outputString(doc);
}

From source file:org.yawlfoundation.yawl.util.JDOMUtil.java

License:Open Source License

/****************************************************************************/

public static String elementToStringDump(Element e) {
    if (e == null)
        return null;
    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    return out.outputString(e);
}

From source file:pt.ua.dicoogle.server.web.dicom.Information.java

License:Open Source License

/**
 * Based on a SOP Instance UID returns a String containing a XML document filled with all name and value tag pairs for the respective .dcm file.
 *
 * @param sopInstanceUID a String containing a valid/indexed SOP Instance UID.
 * @return a String containing a XML document filled with all name and value tag pairs for the respective .dcm file if the SOP Instance UID is valid and indexed, null otherwise.
 *//*from   www .ja v a  2  s. co m*/
public static String getXMLTagListFromFile(String sopInstanceUID) {
    // get all the tags and their values present on the file
    HashMap<String, Object> tags = searchForFileIndexedMetaData(sopInstanceUID);
    if (tags == null) {
        return null;
    }

    // create the XML string builder and open the xml document
    StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
    xml.append("<tags>");

    Element rootElem = new Element("tags");

    // loop through all the tags set and add them and their values to the XML tree
    Iterator<String> it = tags.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        String value = (String) tags.get(key);
        value = value.trim();

        value = CharMatcher.inRange(start, end).and(CharMatcher.noneOf("\t\r\n")).collapseFrom(value, ' ');

        Element tagElem = new Element("tag");
        tagElem.setAttribute("name", key);
        tagElem.setText(value);

        rootElem.addContent(tagElem);
    }

    XMLOutputter outStream = new XMLOutputter(Format.getCompactFormat());
    StringWriter wr = new StringWriter();
    try {
        outStream.output(new Document(rootElem), wr);
    } catch (IOException e) {
        return null;
    }

    return wr.toString();
}

From source file:pt.ua.dicoogle.webservices.RestTagsResource.java

License:Open Source License

@Get
public Representation representXML() {
    StringRepresentation sr;// www. j  av  a2s  .  c  om

    HashMap<String, Integer> tagList = DictionaryAccess.getInstance().getTagList();

    ArrayList<String> list = new ArrayList<String>();
    Element tags = new Element("tags");
    for (String tag : tagList.keySet()) {
        int value = tagList.get(tag);

        Element e = new Element("tag");
        e.setAttribute("id", Integer.toString(value));
        e.setAttribute("name", tag);
        tags.addContent(e);
    }

    tags.setAttribute("count", Integer.toString(tags.getChildren().size()));
    Document xmlDoc = new Document(tags);

    XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
    String str = out.outputString(xmlDoc);

    StringRepresentation rep = new StringRepresentation(str, MediaType.APPLICATION_XML);

    return rep;
}