Example usage for org.xml.sax ContentHandler startDocument

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

Introduction

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

Prototype

public void startDocument() throws SAXException;

Source Link

Document

Receive notification of the beginning of a document.

Usage

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();

    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();//  ww  w.j  a  v  a 2  s.c om
            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.aurel.track.util.HTMLDiff.java

public static String makeDiff(String newValue, String oldValue, Locale locale) throws URISyntaxException {
    boolean htmlOut = true;
    if (newValue == null) {
        newValue = "";
    } else {/*from  ww w .ja  v a  2  s. c o m*/
        newValue = newValue.replaceAll("&nbsp;", " ");
    }
    if (oldValue == null || (oldValue != null && oldValue.length() == 0)) {
        return newValue;
    } else {
        oldValue = oldValue.replaceAll("&nbsp;", " ");
    }

    try {
        SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();

        TransformerHandler result = tf.newTransformerHandler();
        StringWriter stringWriter = new StringWriter();
        result.setResult(new StreamResult(stringWriter));

        XslFilter filter = new XslFilter();

        ContentHandler postProcess = htmlOut ? filter.xsl(result, "com/aurel/track/util/htmlheader.xsl")
                : result;

        String prefix = "diff";

        HtmlCleaner cleaner = new HtmlCleaner();

        InputSource oldSource = new InputSource(new StringReader(oldValue));
        InputSource newSource = new InputSource(new StringReader(newValue));

        DomTreeBuilder oldHandler = new DomTreeBuilder();
        cleaner.cleanAndParse(oldSource, oldHandler);
        TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, locale);

        DomTreeBuilder newHandler = new DomTreeBuilder();
        cleaner.cleanAndParse(newSource, newHandler);
        TextNodeComparator rightComparator = new TextNodeComparator(newHandler, locale);

        postProcess.startDocument();
        postProcess.startElement("", "diffreport", "diffreport", new AttributesImpl());
        postProcess.startElement("", "diff", "diff", new AttributesImpl());
        HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix);

        HTMLDiffer differ = new HTMLDiffer(output);
        differ.diff(leftComparator, rightComparator);
        postProcess.endElement("", "diff", "diff");
        postProcess.endElement("", "diffreport", "diffreport");
        postProcess.endDocument();
        return stringWriter.toString();
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        if (e.getCause() != null) {
            LOGGER.error(ExceptionUtils.getStackTrace(e.getCause()));
        }
        if (e instanceof SAXException) {
            LOGGER.error(ExceptionUtils.getStackTrace(((SAXException) e).getException()));
        }
    }
    return null;
}

From source file:csns.web.controller.WikiController.java

private String diff(Revision oldRevision, Revision newRevision) throws Exception {
    StringWriter result = new StringWriter();
    TransformerHandler transformerHandler = ((SAXTransformerFactory) TransformerFactory.newInstance())
            .newTransformerHandler();// w w w .  ja va 2s .c  o m
    transformerHandler.setResult(new StreamResult(result));
    XslFilter xslFilter = new XslFilter();
    ContentHandler contentHandler = xslFilter.xsl(transformerHandler, "xsl/diff2html.xsl");

    contentHandler.startDocument();
    HtmlSaxDiffOutput diffOutput = new HtmlSaxDiffOutput(contentHandler, "diff");
    HTMLDiffer differ = new HTMLDiffer(diffOutput);
    TextNodeComparator leftComparator = createComparator(oldRevision);
    TextNodeComparator rightComparator = createComparator(newRevision);
    differ.diff(leftComparator, rightComparator);
    contentHandler.endDocument();

    return result.toString();
}

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();

    if ((message == null) || (message.length() < 3)) {
        throw new SAXException("Unable to parse, message is null or too short: " + message);
    }//from   w w  w.jav a  2s.  c  o  m

    // 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: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();

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

    // 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.apache.uima.ruta.descriptor.RutaDescriptorBuilder.java

private void toFile(XMLizable desc, File destination) throws SAXException, FileNotFoundException {
    destination.getParentFile().mkdirs();
    OutputStream out = new FileOutputStream(destination);
    XMLSerializer sax = new XMLSerializer(out);
    ContentHandler ch = sax.getContentHandler();
    ch.startDocument();
    desc.toXML(ch);//from w w  w  .  j a  v  a2s.c  o  m
    ch.endDocument();
}

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

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

    // Parsing overview
    ////w  w  w .  j a  v  a2 s  .  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: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();
    dh.startElement("", "", "db2tm", atts);
    atts.clear();/*from   ww w  . j a  v a 2s . com*/

    // 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:CSVXMLReader.java

/**
 * Parse a CSV file. SAX events are delivered to the ContentHandler
 * that was registered via <code>setContentHandler</code>.
 *
 * @param input the comma separated values file to parse.
 *//*  w w w.  j  av a  2s .com*/
public void parse(InputSource input) throws IOException, SAXException {
    // if no handler is registered to receive events, don't bother
    // to parse the CSV file
    ContentHandler ch = getContentHandler();
    if (ch == null) {
        return;
    }

    // convert the InputSource into a BufferedReader
    BufferedReader br = null;
    if (input.getCharacterStream() != null) {
        br = new BufferedReader(input.getCharacterStream());
    } else if (input.getByteStream() != null) {
        br = new BufferedReader(new InputStreamReader(input.getByteStream()));
    } else if (input.getSystemId() != null) {
        java.net.URL url = new URL(input.getSystemId());
        br = new BufferedReader(new InputStreamReader(url.openStream()));
    } else {
        throw new SAXException("Invalid InputSource object");
    }

    ch.startDocument();

    // emit <csvFile>
    ch.startElement("", "", "csvFile", EMPTY_ATTR);

    // read each line of the file until EOF is reached
    String curLine = null;
    while ((curLine = br.readLine()) != null) {
        curLine = curLine.trim();
        if (curLine.length() > 0) {
            // create the <line> element
            ch.startElement("", "", "line", EMPTY_ATTR);
            // output data from this line
            parseLine(curLine, ch);
            // close the </line> element
            ch.endElement("", "", "line");
        }
    }

    // emit </csvFile>
    ch.endElement("", "", "csvFile");
    ch.endDocument();
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.hl7.HL7MapToLexGrid.java

void loadMetaData(CodingScheme csclass, String connectionString, String driver) {

    messages_.info("Loading individual coding scheme metadata");
    Connection c = null;/*w w w . j  ava 2 s .  co  m*/

    // create the filename of the metadata file to be created
    String filename = loaderPrefs.getXMLMetadataFilePath() + "/"
            + PreferenceLoaderConstants.META_HL7_METADATA_FILE_NAME;

    FileOutputStream fos;
    try {
        fos = new FileOutputStream(filename);

        OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
        of.setIndent(1);
        of.setIndenting(true);
        XMLSerializer serializer = new XMLSerializer(fos, of);

        // SAX2.0 ContentHandler.
        ContentHandler hd = serializer.asContentHandler();
        hd.startDocument();

        // Element attributes.
        AttributesImpl atts = new AttributesImpl();

        // CODINGSCHEMES tag.
        hd.startElement("", "", "codingSchemes", atts);

        String defaultLanguage = "en";
        String isNative = "0";
        String codeSystemId;
        String codeSystemType;
        String codeSystemName;
        String fullName;
        String description;
        String releaseId;
        String copyrightNotice;
        Integer approximateNumberofConcepts;

        try {
            c = DBUtility.connectToDatabase(accessConnectionString, driver, null, null);

            PreparedStatement getCodingSchemeMetaData = c
                    .prepareStatement("SELECT b.codeSystemid, b.codeSystemType, b.codeSystemName, "
                            + "b.fullName, b.description, b.releaseId, b.copyrightNotice "
                            + "FROM VCS_code_system AS b");
            ResultSet codingSchemeMetaData = getCodingSchemeMetaData.executeQuery();

            PreparedStatement getCodingSchemeConceptCount = c
                    .prepareStatement("SELECT VCS_concept_code_xref.codeSystemId2, "
                            + "COUNT (VCS_concept_code_xref.codeSystemId2) as conceptcount "
                            + "FROM VCS_concept_code_xref " + "GROUP BY VCS_concept_code_xref.codeSystemId2;");

            ResultSet codingSchemeConceptCount = getCodingSchemeConceptCount.executeQuery();

            Hashtable<String, Integer> conceptCountList = new Hashtable<String, Integer>();

            while (codingSchemeConceptCount.next()) {

                String codingSchemeId = codingSchemeConceptCount.getString("codeSystemId2");
                String codingSchemeCount = codingSchemeConceptCount.getString("conceptcount");

                conceptCountList.put(new String(codingSchemeId), new Integer(codingSchemeCount));
            }

            codingSchemeConceptCount.close();

            int codeSchemeCounter = 0;

            while (codingSchemeMetaData.next()) {
                codeSystemId = codingSchemeMetaData.getString("codeSystemid");
                if (codeSystemId == null) {
                    codeSystemId = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                codeSystemType = codingSchemeMetaData.getString("codeSystemType");
                if (codeSystemType == null) {
                    codeSystemType = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                codeSystemName = codingSchemeMetaData.getString("codeSystemName");
                if (codeSystemName == null) {
                    codeSystemName = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                fullName = codingSchemeMetaData.getString("fullName");
                if (fullName == null) {
                    fullName = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                description = codingSchemeMetaData.getString("description");
                if (description == null) {
                    description = SQLTableConstants.TBLCOLVAL_MISSING;
                }
                // The description contains HTML tags. We try to remove
                // them.
                else {
                    int begin = description.lastIndexOf("<p>");
                    int end = description.lastIndexOf("</p>");
                    if (begin > -1) {
                        if (begin + 3 < end)
                            description = description.substring(begin + 3, end);
                    }
                }

                releaseId = codingSchemeMetaData.getString("releaseId");
                if (releaseId == null) {
                    releaseId = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                copyrightNotice = codingSchemeMetaData.getString("copyrightNotice");
                if (copyrightNotice == null) {
                    copyrightNotice = SQLTableConstants.TBLCOLVAL_MISSING;
                }

                approximateNumberofConcepts = ((Integer) conceptCountList.get(codeSystemId));
                if (approximateNumberofConcepts == null) {
                    approximateNumberofConcepts = new Integer(0);
                }

                // Begin codingScheme element
                atts.clear();
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_CODINGSCHEMENAME, "CDATA", codeSystemName);
                // May want to change to _fullName
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_FORMALNAME, "CDATA", fullName);
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_CODINGSCHEMEURI, "CDATA", codeSystemId);
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_DEFAULTLANGUAGE, "CDATA", defaultLanguage);
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_REPRESENTSVERSION, "CDATA", releaseId);
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_ISNATIVE, "CDATA", isNative);
                atts.addAttribute("", "", SQLTableConstants.TBLCOL_APPROXNUMCONCEPTS, "CDATA",
                        approximateNumberofConcepts.toString());
                hd.startElement("", "", SQLTableConstants.TBLCOL_CODINGSCHEME, atts);

                // localname
                atts.clear();
                hd.startElement("", "", "localName", atts);
                hd.characters(codeSystemName.toCharArray(), 0, codeSystemName.length());
                hd.endElement("", "", SQLTableConstants.TBLCOLVAL_LOCALNAME);

                // entityDescription
                atts.clear();
                hd.startElement("", "", SQLTableConstants.TBLCOL_ENTITYDESCRIPTION, atts);
                hd.characters(description.toCharArray(), 0, description.length());
                hd.endElement("", "", SQLTableConstants.TBLCOL_ENTITYDESCRIPTION);

                // copyright
                atts.clear();
                hd.startElement("", "", SQLTableConstants.TBLCOL_COPYRIGHT, atts);
                hd.characters(copyrightNotice.toCharArray(), 0, copyrightNotice.length());
                hd.endElement("", "", SQLTableConstants.TBLCOL_COPYRIGHT);

                // May need to include as Property
                // // CodingScheme
                // atts.clear();
                // hd.startElement("","","CodingScheme",atts);
                // hd.characters(_codeSystemType.toCharArray(),0,_codeSystemType.length());
                // hd.endElement("","","CodingScheme");

                // End codingScheme element
                hd.endElement("", "", SQLTableConstants.TBLCOL_CODINGSCHEME);

                codeSchemeCounter++;

            } // End while there are result rows to process

            getCodingSchemeConceptCount.close();

            hd.endElement("", "", "codingSchemes");
            hd.endDocument();
            fos.close();

        } catch (Exception e) {
            messages_.error("Failed while preparing HL7 Code System MetaData.", e);
            e.printStackTrace();
        } finally {
            try {
                c.close();
            } catch (SQLException e) {
                messages_.debug("An error occurred while closing the MS Access connection: " + e.getMessage());
                e.printStackTrace();
            }
        }

    } catch (FileNotFoundException fnfe) {
        messages_.debug("Loader Preferences file was not found, file: " + filename);
        fnfe.printStackTrace();
    } catch (IOException ioe) {
        messages_.debug("IOException, file: " + filename);
        ioe.printStackTrace();
    } catch (SAXException saxe) {
        messages_.debug("SAXException, file: " + filename);
        saxe.printStackTrace();
    }

}