Example usage for com.google.common.base CharMatcher noneOf

List of usage examples for com.google.common.base CharMatcher noneOf

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher noneOf.

Prototype

public static CharMatcher noneOf(CharSequence sequence) 

Source Link

Document

Returns a char matcher that matches any character not present in the given character sequence.

Usage

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

/**
 * 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.
 *//* w ww. j av  a  2s . c  om*/
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();
}