Example usage for org.xml.sax ContentHandler endElement

List of usage examples for org.xml.sax ContentHandler endElement

Introduction

In this page you can find the example usage for org.xml.sax ContentHandler endElement.

Prototype

public void endElement(String uri, String localName, String qName) throws SAXException;

Source Link

Document

Receive notification of the end of an element.

Usage

From source file:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java

private String handleSegments(String documentHead, ContentHandler contentHandler, String fieldSeparator,
        String componentSeparator, String subcomponentSeparator, String repetitionSeparator,
        String escapeCharacter, String[] segments) throws SAXException {
    for (int segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {
        String segment = segments[segmentIndex];
        logger.trace("handling segment: " + segment);
        // loop through each segment and pull out the fields
        StringTokenizer fieldTokenizer = new StringTokenizer(segment, fieldSeparator, true);

        if (fieldTokenizer.hasMoreTokens()) {
            // the XML element is named after the first field
            String segmentId = fieldTokenizer.nextToken().trim();

            if (segmentIndex == 0) {
                documentHead = MESSAGE_ROOT_ID;
                contentHandler.startElement("", documentHead, "", null);
            }//from www  . j a v a2  s.c o m

            contentHandler.startElement("", segmentId, "", null);
            handleFieldOrRepetitions(contentHandler, fieldSeparator, componentSeparator, subcomponentSeparator,
                    repetitionSeparator, escapeCharacter, segmentId, fieldTokenizer);
            contentHandler.endElement("", segmentId, "");
        } else {
            throw new SAXException("Could not find fields in segment: " + segment);
        }
    }

    return documentHead;
}

From source file:biz.taoconsulting.oxf.processor.converter.FromPdfConverter.java

/**
 * processBookmark gets called recursively for all nested bookmarks extracts
 * the bookmark and the text/*from w w  w  . java  2s .c  o m*/
        
 */
private void processBookmark(ContentHandler hd, PDDocument doc, PDOutlineItem curItem, String scope,
        int level) {
    // First we check on what page the bookmark is. If we can't retrieve the
    // page the bookmark can't be the outline we are looking for, however we
    // would process children (you never know)
    try {

        int curPageNo = getPageNumber(doc, curItem);

        if (curPageNo > -1) {

            AttributesImpl atts = new AttributesImpl();
            atts.addAttribute("", ATT_LEVEL, ATT_LEVEL, ATT_CDATA, Integer.toString(level));
            atts.addAttribute("", ATT_PAGE, ATT_PAGE, ATT_CDATA, Integer.toString(curPageNo));

            hd.startElement("", TAG_BOOKMARK, TAG_BOOKMARK, atts);

            // Write the properties of interest
            atts.clear();
            hd.startElement("", TAG_TITLE, TAG_TITLE, atts);
            String curTitle = curItem.getTitle();
            hd.characters(curTitle.toCharArray(), 0, curTitle.length());
            hd.endElement("", TAG_TITLE, TAG_TITLE);

            //write out the text associated with this bookmark
            // if the scope allows for that

            if (!scope.toLowerCase().equals(SCOPE_BOOKMARKSONLY)) {

                PDFTextStripper stripper = new PDFTextStripper();
                stripper.setStartBookmark(curItem);
                stripper.setEndBookmark(curItem);
                String textBetweenBookmarks = stripper.getText(doc);
                hd.startElement("", TAG_TEXT, TAG_TEXT, atts);
                textBetweenBookmarks = MassageTextResult(textBetweenBookmarks);
                hd.characters(textBetweenBookmarks.toCharArray(), 0, textBetweenBookmarks.length());
                hd.endElement("", TAG_TEXT, TAG_TEXT);

            }

        }
        // Now check the children
        PDOutlineItem child = curItem.getFirstChild();
        while (child != null) {
            processBookmark(hd, doc, child, scope, level + 1);
            logger.info("Child:" + child.getTitle());
            child = child.getNextSibling();
        }
        // Close the mark
        hd.endElement("", TAG_BOOKMARK, TAG_BOOKMARK);
    } catch (SAXException e) {
        logger.error(e);
        addErrorTagToOutput(hd, e.toString());
    } catch (IOException e) {
        logger.error(e);
        addErrorTagToOutput(hd, e.toString());
    } finally {
        // Nothing concluding to do
    }
}

From source file:nl.architolk.ldt.processors.HttpClientProcessor.java

private void parseJSONObject(ContentHandler contentHandler, JSONObject json) throws SAXException {
    Object[] names = json.names().toArray();
    for (int i = 0; i < names.length; i++) {
        String name = (String) names[i];
        Object value = json.get(name);
        String safeName = name.replace('@', '_');
        contentHandler.startElement("", safeName, safeName, new AttributesImpl());

        if (value instanceof JSONObject) {
            parseJSONObject(contentHandler, (JSONObject) value);
        } else if (value instanceof JSONArray) {
            Iterator<?> jsonit = ((JSONArray) value).iterator();
            while (jsonit.hasNext()) {
                Object arrayValue = jsonit.next();
                if (arrayValue instanceof JSONObject) {
                    parseJSONObject(contentHandler, (JSONObject) arrayValue);
                } else {
                    String textValue = String.valueOf(arrayValue);
                    contentHandler.characters(textValue.toCharArray(), 0, textValue.length());
                }//from w w w  .j a  v  a2s  . co m
                //Array means repeating the XML node, so end the current node, and start a new one
                if (jsonit.hasNext()) {
                    contentHandler.endElement("", safeName, safeName);
                    contentHandler.startElement("", safeName, safeName, new AttributesImpl());
                }
            }
        } else {
            String textValue = String.valueOf(value);
            contentHandler.characters(textValue.toCharArray(), 0, textValue.length());
        }

        contentHandler.endElement("", safeName, safeName);
    }
}

From source file:net.ontopia.persistence.rdbms.DatabaseProjectReader.java

public static void saveProject(Project project, ContentHandler dh) throws SAXException {
    AttributesImpl atts = new AttributesImpl();

    dh.startDocument();//from www .jav a  2 s.  co m

    dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema", EMPTY_ATTR_LIST);

    Iterator<String> platforms = project.getDataTypePlatforms().iterator();
    if (platforms.hasNext()) {
        while (platforms.hasNext()) {
            String platform = platforms.next();

            atts.clear();
            atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PLATFORM, CDATA, platform);
            dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes", atts);

            Iterator<DataType> datatypes = project.getDataTypes(platform).iterator();
            while (datatypes.hasNext()) {
                // Platform datatypes
                DataType datatype = datatypes.next();
                atts.clear();
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, (datatype.getName()));
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, (datatype.getType()));
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA,
                        (datatype.getSize() == null ? "" : datatype.getSize()));
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "class", CDATA,
                        (datatype.isVariable() ? "variable" : "constant"));

                dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype", atts);

                // Datatype properties
                Iterator<String> properties = datatype.getProperties().iterator();
                while (properties.hasNext()) {
                    String name = properties.next();
                    String value = datatype.getProperty(name);
                    if (value != null) {
                        atts.clear();
                        atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name);
                        atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value);
                        dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts);
                        dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY);
                    }
                }

                dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype");

            }
        }
        dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes");
    }

    Iterator<Table> tables = project.getTables().iterator();
    while (tables.hasNext()) {
        Table table = tables.next();

        // Table attributes
        atts.clear();
        atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, table.getName());
        if (table.getShortName() != null)
            atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "short", CDATA, table.getShortName());
        if (table.getPrimaryKeys() != null)
            atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "pks", CDATA,
                    StringUtils.join(table.getPrimaryKeys(), " "));
        dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table", atts);

        // Table properties
        Iterator<String> properties = table.getProperties().iterator();
        while (properties.hasNext()) {
            String name = properties.next();
            String value = table.getProperty(name);
            if (value != null) {
                atts.clear();
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name);
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value);
                dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts);
                dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY);
            }
        }

        Iterator<Column> columns = table.getColumns().iterator();
        while (columns.hasNext()) {
            Column column = columns.next();

            // Column attributes
            atts.clear();
            atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, column.getName());
            atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, column.getType());

            if (column.isReference()) {
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "reftab", CDATA,
                        column.getReferencedTable());
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "refcol", CDATA,
                        column.getReferencedColumn());
            }

            if (column.getSize() != null)
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA, column.getName());
            if (column.isNullable())
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "null", CDATA, "yes");
            if (column.getDefault() != null)
                atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "default", CDATA, column.getDefault());
            dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column", atts);

            // Column properties
            Iterator<String> properties2 = column.getProperties().iterator();
            while (properties2.hasNext()) {
                String name = properties2.next();
                String value = column.getProperty(name);
                if (value != null) {
                    atts.clear();
                    atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name);
                    atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value);
                    dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts);
                    dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY);
                }
            }
            dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column");
        }

        dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table");
    }

    dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema");
    dh.endDocument();
}

From source file:com.mirth.connect.model.converters.NCPDPReader.java

@Override
public void parse(InputSource input) throws SAXException, IOException {
    // convert the InputSource to a String and trim the whitespace
    String message = IOUtils.toString(input.getCharacterStream()).trim();

    ContentHandler contentHandler = getContentHandler();
    contentHandler.startDocument();/*ww  w. java  2  s .co m*/

    if ((message == null) || (message.length() < 3)) {
        throw new SAXException("Unable to parse, message is null or too short: " + message);
    }

    // process header
    String header = parseHeader(message, contentHandler);

    // process body
    int groupDelimeterIndex = message.indexOf(groupDelimeter);
    int segmentDelimeterIndex = message.indexOf(segmentDelimeter);
    int bodyIndex = 0;

    if ((groupDelimeterIndex == -1) || (segmentDelimeterIndex < groupDelimeterIndex)) {
        bodyIndex = segmentDelimeterIndex;
    } else {
        bodyIndex = groupDelimeterIndex;
    }

    String body = message.substring(bodyIndex, message.length());

    boolean hasMoreSegments = true;
    boolean inGroup = false;
    boolean firstTransaction = true;
    int groupCounter = 0;

    while (hasMoreSegments) {
        // get next segment or group
        groupDelimeterIndex = body.indexOf(groupDelimeter);
        segmentDelimeterIndex = body.indexOf(segmentDelimeter);

        if ((groupDelimeterIndex > -1) && (groupDelimeterIndex < segmentDelimeterIndex)) { // case: next part is a group
            // process last segment before group
            parseSegment(body.substring(0, groupDelimeterIndex), contentHandler);

            if (inGroup) {
                contentHandler.endElement("", "TRANSACTION", "");
            }

            if (firstTransaction) {
                firstTransaction = false;
                contentHandler.startElement("", "TRANSACTIONS", "", null);
            }

            // process a group
            AttributesImpl attr = new AttributesImpl();
            attr.addAttribute("", "counter", "counter", "", Integer.toString(++groupCounter));
            contentHandler.startElement("", "TRANSACTION", "", attr);
            inGroup = true;
        } else if (groupDelimeterIndex == -1 && segmentDelimeterIndex == -1) { // case: last segment
            parseSegment(body, contentHandler);
            hasMoreSegments = false;
        } else { // case: next part is a segment
            String segment = body.substring(0, segmentDelimeterIndex);
            parseSegment(segment, contentHandler);
        }

        // remove processed segment from message body
        body = body.substring(segmentDelimeterIndex + segmentDelimeter.length());
    }

    // end group if we have started one
    if (inGroup) {
        contentHandler.endElement("", "TRANSACTION", "");
        contentHandler.endElement("", "TRANSACTIONS", "");
    }

    contentHandler.endElement("", header, "");
    contentHandler.endDocument();
}

From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java

protected void write(ContentHandler dh) throws SAXException {

    // initialize attributes
    AttributesImpl atts = new AttributesImpl();

    // <db2tm name="...">
    if (name != null)
        addAttribute(atts, "name", "CDATA", name);

    dh.startDocument();// www  . j  ava 2s.c o m
    dh.startElement("", "", "db2tm", atts);
    atts.clear();

    // prefixes
    for (Prefix prefix : iprefixes.values()) {
        addAttribute(atts, "prefix", "CDATA", prefix.getId());

        switch (prefix.getType()) {
        case Prefix.TYPE_SUBJECT_IDENTIFIER:
            addAttribute(atts, "subject-identifier", "CDATA", prefix.getLocator());
            break;
        case Prefix.TYPE_ITEM_IDENTIFIER:
            addAttribute(atts, "item-identifier", "CDATA", prefix.getLocator());
            break;
        case Prefix.TYPE_SUBJECT_LOCATOR:
            addAttribute(atts, "subject-locator", "CDATA", prefix.getLocator());
            break;
        }

        dh.startElement("", "", "using", atts);
        atts.clear();
        dh.endElement("", "", "using");
    }

    // relations
    for (Relation rel : getRelations()) {
        // <relation>
        addAttribute(atts, "name", "CDATA", rel.getName());
        addAttribute(atts, "columns", "CDATA", rel.getColumns());
        dh.startElement("", "", "relation", atts);
        atts.clear();

        outputEntities(rel, dh);

        // </relation>
        dh.endElement("", "", "relation");
    }

    // </db2tm>
    dh.endElement("", "", "db2tm");
    dh.endDocument();
}

From source file:com.mirth.connect.plugins.datatypes.delimited.DelimitedReader.java

public void parse(InputSource input) throws SAXException, IOException {

    // Parsing overview
    ////from   ww w . java2s.  c  o  m
    // The incoming stream is a single message which is a collection of one
    // or more records.
    // Each record is a collection of columns. Columns can be either fixed
    // width, or delimited.
    // Records are delimited.
    // Each record is assumed to contain the same number and type of
    // columns.
    //
    // The following user configurable options affect the behavior of the
    // parser:
    // o columnWidths The array of fixed column widths.
    // o columnDelimiter The characters that delimit (separate) the
    // columns.
    // o recordDelimiter The characters that delimit (separate) each
    // record.
    // o quoteToken The characters that are used to quote a column value.
    // o escapeWithDoubleQuote Iff true, embedded quotes are escaped with
    // two consecutive quotes.
    // Otherwise, the quote escape characters escape embedded quote
    // characters.
    // o quoteEscapeToken The characters used to escape a quote (or itself).
    // o ignoreCR Iff true, all incoming \r characters are ignored and not
    // processed.
    //
    // The following user configurable options affect the behavior of the
    // output:
    // o columnNames A list of column names (taken from either file header,
    // or supplied by user).
    BufferedReader in = new BufferedReader(input.getCharacterStream());

    // Start the document
    String documentHead = "delimited";
    ContentHandler contentHandler = getContentHandler();
    contentHandler.startDocument();

    // Output <delimited>
    contentHandler.startElement("", documentHead, "", null);

    // While the parser gets records from the message
    ArrayList<String> record;
    int recordNo = 1;
    while ((record = getRecord(in, null)) != null) {

        // Output <rowN>
        if (serializationProperties.isNumberedRows()) {
            contentHandler.startElement("", "row" + recordNo, "", null);
        } else {
            contentHandler.startElement("", "row", "", null);
        }

        // For each column
        for (int i = 0; i < record.size(); i++) {

            String columnName;
            if (serializationProperties.getColumnNames() != null
                    && i < serializationProperties.getColumnNames().length) {
                // User specified column name
                columnName = serializationProperties.getColumnNames()[i];
            } else {
                // Default column name
                columnName = "column" + (i + 1);
            }
            // Output <columnN>
            contentHandler.startElement("", columnName, "", null);

            // Output column value
            contentHandler.characters(record.get(i).toCharArray(), 0, record.get(i).length());

            // Output </columnN>
            contentHandler.endElement("", columnName, "");
        }

        // Output </rowN>
        if (serializationProperties.isNumberedRows()) {
            contentHandler.endElement("", "row" + recordNo, "");
        } else {
            contentHandler.endElement("", "row", "");
        }

        recordNo++;
    }

    // Output </delimited>
    contentHandler.endElement("", documentHead, "");

    // End the document
    contentHandler.endDocument();
}

From source file:com.mirth.connect.model.converters.NCPDPReader.java

private void parseSegment(String segment, ContentHandler contentHandler) throws SAXException {
    if (StringUtils.isBlank(segment)) {
        return;/*www .  jav a2 s. co  m*/
    }

    boolean inCounter = false;
    boolean inCount = false;
    boolean hasMoreFields = true;
    String segmentId = StringUtils.EMPTY;
    String subSegment = StringUtils.EMPTY;
    Stack<String> fieldStack = new Stack<String>();

    int fieldDelimeterIndex = segment.indexOf(fieldDelimeter);

    if (fieldDelimeterIndex == 0) {
        segment = segment.substring(fieldDelimeterIndex + fieldDelimeter.length());
        fieldDelimeterIndex = segment.indexOf(fieldDelimeter);
    }

    if (fieldDelimeterIndex == -1) {
        logger.warn("Empty segment with no field seperators. Make sure batch file processing is disabled.");
        hasMoreFields = false;
        segmentId = segment;
    } else {
        segmentId = segment.substring(0, fieldDelimeterIndex);
        subSegment = segment.substring(fieldDelimeterIndex + fieldDelimeter.length(), segment.length());
    }

    contentHandler.startElement("", NCPDPReference.getInstance().getSegment(segmentId, version), "", null);

    while (hasMoreFields) {
        fieldDelimeterIndex = subSegment.indexOf(fieldDelimeter);
        // not last field
        String field;

        if (fieldDelimeterIndex != -1) {
            field = subSegment.substring(0, subSegment.indexOf(fieldDelimeter));
            subSegment = subSegment.substring(fieldDelimeterIndex + fieldDelimeter.length());
        } else {
            field = subSegment;
            hasMoreFields = false;
        }

        String fieldId = field.substring(0, 2);
        String fieldDescription = NCPDPReference.getInstance().getDescription(fieldId, version);
        String fieldMessage = field.substring(2);

        if (inCount && !isRepeatingField(fieldDescription) && !fieldDescription.endsWith("Count")) {
            // if we are were in count field then end the element
            contentHandler.endElement("", fieldStack.pop(), "");

            if (fieldStack.size() == 0) {
                inCount = false;
            }
        }

        if (fieldDescription.endsWith("Counter")) {
            if (inCounter) {
                contentHandler.endElement("", fieldStack.pop(), "");
            }

            inCounter = true;
            AttributesImpl attr = new AttributesImpl();
            attr.addAttribute("", "counter", "counter", "", fieldMessage);
            contentHandler.startElement("", fieldDescription, "", attr);
            fieldStack.push(fieldDescription);
        } else if (fieldDescription.endsWith("Count")) {
            // count field, add complex element
            inCount = true;
            AttributesImpl attr = new AttributesImpl();
            attr.addAttribute("", fieldDescription, fieldDescription, "", fieldMessage);
            // start the repeating field element
            contentHandler.startElement("", fieldDescription, "", attr);
            fieldStack.push(fieldDescription);
        } else {
            contentHandler.startElement("", fieldDescription, "", null);
            contentHandler.characters(fieldMessage.toCharArray(), 0, fieldMessage.length());
            contentHandler.endElement("", fieldDescription, "");
        }
    }

    while (fieldStack.size() > 0) {
        // close remaining count and counters
        contentHandler.endElement("", fieldStack.pop(), "");
    }

    contentHandler.endElement("", NCPDPReference.getInstance().getSegment(segmentId, version), "");
}

From source file:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java

public void parse(InputSource source) throws SAXException, IOException {
    String message = getMessageFromSource(source);
    ContentHandler contentHandler = getContentHandler();
    contentHandler.startDocument();//www  .  j  a v a 2  s . com

    // first tokenize the segments
    if ((message == null) || (message.length() < 6)) {
        throw new SAXException("Unable to parse message. It is NULL or too short. " + message);
    }

    // usually |
    String fieldSeparator = DEFAULT_FIELD_SEPARATOR;
    String componentSeparator = DEFAULT_COMPONENT_SEPARATOR;
    String repetitionSeparator = DEFAULT_REPETITION_SEPARATOR;
    String escapeCharacter = DEFAULT_ESCAPE_CHARACTER;
    String subcomponentSeparator = DEFAULT_SUBCOMPONENT_TERMINATOR;

    // if we have a header, grab the actual separators from the message
    String firstSegment = message.substring(0, 3);
    if (firstSegment.equalsIgnoreCase("MSH") || firstSegment.equalsIgnoreCase("FHS")
            || firstSegment.equalsIgnoreCase("BHS")) {
        fieldSeparator = new String(new char[] { message.charAt(3) });

        int nextDelimiter = message.indexOf(message.charAt(3), 4);
        if (nextDelimiter == -1) {
            // If the message is just MSH|^~\&, we still want to extract the encoding characters
            nextDelimiter = message.length();
        }

        if (nextDelimiter > 4) {
            // usually ^
            componentSeparator = new String(new char[] { message.charAt(4) });
        }

        if (nextDelimiter > 5) {
            // usually ~
            repetitionSeparator = new String(new char[] { message.charAt(5) });
        }

        if (nextDelimiter > 6) {
            // usually \
            escapeCharacter = new String(new char[] { message.charAt(6) });
        }

        if (nextDelimiter > 7) {
            // usually &
            subcomponentSeparator = new String(new char[] { message.charAt(7) });
        }
    }

    // replace the special case of ^~& with ^~\& (MIRTH-1544)
    if (message.length() >= 8 && "^~&|".equals(message.substring(4, 8))) {
        escapeCharacter = "\\";
        subcomponentSeparator = "&";
        repetitionSeparator = "~";
        componentSeparator = "^";
    }

    // tokenize the segments first
    String[] segments = StringUtils.split(message, segmentDelimiter);
    String documentHead = handleSegments("", contentHandler, fieldSeparator, componentSeparator,
            subcomponentSeparator, repetitionSeparator, escapeCharacter, segments);
    contentHandler.endElement("", documentHead, "");
    contentHandler.endDocument();
}

From source file:org.syncope.core.report.UserReportlet.java

private void doExtract(final ContentHandler handler, final UserReportletConf conf,
        final List<SyncopeUser> users) throws SAXException, ReportException {

    AttributesImpl atts = new AttributesImpl();
    for (SyncopeUser user : users) {
        atts.clear();//ww w.j a  v a2 s .  c  o  m

        for (Feature feature : conf.getFeatures()) {
            String type = null;
            String value = null;
            switch (feature) {
            case id:
                type = XSD_LONG;
                value = String.valueOf(user.getId());
                break;

            case username:
                type = XSD_STRING;
                value = user.getUsername();
                break;

            case workflowId:
                type = XSD_LONG;
                value = String.valueOf(user.getWorkflowId());
                break;

            case status:
                type = XSD_STRING;
                value = user.getStatus();
                break;

            case creationDate:
                type = XSD_DATETIME;
                value = user.getCreationDate() == null ? "" : DATE_FORMAT.get().format(user.getCreationDate());
                break;

            case lastLoginDate:
                type = XSD_DATETIME;
                value = user.getLastLoginDate() == null ? ""
                        : DATE_FORMAT.get().format(user.getLastLoginDate());
                break;

            case changePwdDate:
                type = XSD_DATETIME;
                value = user.getChangePwdDate() == null ? ""
                        : DATE_FORMAT.get().format(user.getChangePwdDate());
                break;

            case passwordHistorySize:
                type = XSD_INT;
                value = String.valueOf(user.getPasswordHistory().size());
                break;

            case failedLoginCount:
                type = XSD_INT;
                value = String.valueOf(user.getFailedLogins());
                break;

            default:
            }

            if (type != null && value != null) {
                atts.addAttribute("", "", feature.name(), type, value);
            }
        }

        handler.startElement("", "", "user", atts);

        // Using UserTO for attribute values, since the conversion logic of
        // values to String is already encapsulated there
        UserTO userTO = userDataBinder.getUserTO(user);

        doExtractAttributes(handler, userTO, conf.getAttrs(), conf.getDerAttrs(), conf.getVirAttrs());

        if (conf.getFeatures().contains(Feature.memberships)) {
            handler.startElement("", "", "memberships", null);

            for (MembershipTO memb : userTO.getMemberships()) {
                atts.clear();

                atts.addAttribute("", "", "id", XSD_LONG, String.valueOf(memb.getId()));
                atts.addAttribute("", "", "roleId", XSD_LONG, String.valueOf(memb.getRoleId()));
                atts.addAttribute("", "", "roleName", XSD_STRING, String.valueOf(memb.getRoleName()));
                handler.startElement("", "", "membership", atts);

                doExtractAttributes(handler, memb, memb.getAttributeMap().keySet(),
                        memb.getDerivedAttributeMap().keySet(), memb.getVirtualAttributeMap().keySet());

                if (conf.getFeatures().contains(Feature.resources)) {
                    Membership actualMemb = user.getMembership(memb.getRoleId());
                    if (actualMemb == null) {
                        LOG.warn("Unexpected: cannot find membership for " + "role {} for user {}",
                                memb.getRoleId(), user);
                    } else {
                        doExtractResources(handler, roleDataBinder.getRoleTO(actualMemb.getSyncopeRole()));
                    }
                }

                handler.endElement("", "", "membership");
            }

            handler.endElement("", "", "memberships");
        }

        if (conf.getFeatures().contains(Feature.resources)) {
            doExtractResources(handler, userTO);
        }

        handler.endElement("", "", "user");
    }
}