Example usage for javax.xml.transform.sax TransformerHandler startCDATA

List of usage examples for javax.xml.transform.sax TransformerHandler startCDATA

Introduction

In this page you can find the example usage for javax.xml.transform.sax TransformerHandler startCDATA.

Prototype

public abstract void startCDATA() throws SAXException;

Source Link

Document

Report the start of a CDATA section.

Usage

From source file:com.smartitengineering.exim.impl.xml.ResourceObjectExporter.java

public void exportElement(AssociationType type, Object object, TransformerHandler handler) throws IOException {
    if (type == null || object == null || handler == null) {
        throw new IOException("All parameters are required!");
    }/*from  w w w .  j  a v a2 s .  com*/
    EximResourceConfig config = ConfigRegistrar.getConfigForClass(object.getClass());
    if (config == null) {
        try {
            handler.startCDATA();
            String value = object == null ? null : object.toString();
            if (StringUtils.isBlank(value)) {
                value = "";
            }
            char[] chars = value.toCharArray();
            handler.characters(chars, 0, chars.length);
            handler.endCDATA();
        } catch (Exception ex) {
            throw new IOException(ex);
        }
    } else {
        //Handle resources
    }
}

From source file:com.smartitengineering.exim.impl.xml.GenericDataTypeExporter.java

public void exportElement(AssociationType type, Object object, TransformerHandler handler) throws IOException {
    if (type == null || object == null || handler == null) {
        throw new IOException("All parameters are required!");
    }//from w  w w. ja v  a  2 s  .  c  o  m
    final String elementName = type.getSimpleName();
    final String value;
    switch (type) {
    case TYPE_DATE:
        value = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format((Date) object);
        break;
    case TYPE_STRING:
    case TYPE_INTEGER:
    case TYPE_LONG:
    case TYPE_FLOAT:
    case TYPE_DOUBLE:
    case TYPE_BOOLEAN:
    default:
        value = object == null ? null : object.toString();
        break;
    }
    try {
        AttributesImpl atts = new AttributesImpl();
        handler.startElement(EXIM_COLLECN_URI, EXIM_COLLECTION_NS, elementName, atts);
        if (AssociationType.TYPE_STRING.equals(type)) {
            handler.startCDATA();
        }
        final char[] chars;
        if (StringUtils.isBlank(value)) {
            chars = "".toCharArray();
        } else {
            chars = value.toCharArray();
        }
        handler.characters(chars, 0, chars.length);
        if (AssociationType.TYPE_STRING.equals(type)) {
            handler.endCDATA();
        }
        handler.endElement(EXIM_COLLECN_URI, EXIM_COLLECTION_NS, elementName);
    } catch (Exception exception) {
        throw new IOException(exception);
    }
}