Search in sources :

Example 31 with SAXException

use of org.xml.sax.SAXException in project j2objc by google.

the class ToStream method endDTD.

/**
     * Report the end of DTD declarations.
     * @throws org.xml.sax.SAXException The application may raise an exception.
     * @see #startDTD
     */
public void endDTD() throws org.xml.sax.SAXException {
    try {
        if (m_needToOutputDocTypeDecl) {
            outputDocTypeDecl(m_elemContext.m_elementName, false);
            m_needToOutputDocTypeDecl = false;
        }
        final java.io.Writer writer = m_writer;
        if (!m_inDoctype)
            writer.write("]>");
        else {
            writer.write('>');
        }
        writer.write(m_lineSep, 0, m_lineSepLen);
    } catch (IOException e) {
        throw new SAXException(e);
    }
}
Also used : Writer(java.io.Writer) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 32 with SAXException

use of org.xml.sax.SAXException in project j2objc by google.

the class ToStream method charactersRaw.

/**
     * If available, when the disable-output-escaping attribute is used,
     * output raw text without escaping.
     *
     * @param ch The characters from the XML document.
     * @param start The start position in the array.
     * @param length The number of characters to read from the array.
     *
     * @throws org.xml.sax.SAXException
     */
protected void charactersRaw(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (m_inEntityRef)
        return;
    try {
        if (m_elemContext.m_startTagOpen) {
            closeStartTag();
            m_elemContext.m_startTagOpen = false;
        }
        m_ispreserve = true;
        m_writer.write(ch, start, length);
    } catch (IOException e) {
        throw new SAXException(e);
    }
}
Also used : IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 33 with SAXException

use of org.xml.sax.SAXException in project j2objc by google.

the class ToStream method characters.

/**
     * Receive notification of character data.
     *
     * <p>The Parser will call this method to report each chunk of
     * character data.  SAX parsers may return all contiguous character
     * data in a single chunk, or they may split it into several
     * chunks; however, all of the characters in any single event
     * must come from the same external entity, so that the Locator
     * provides useful information.</p>
     *
     * <p>The application must not attempt to read from the array
     * outside of the specified range.</p>
     *
     * <p>Note that some parsers will report whitespace using the
     * ignorableWhitespace() method rather than this one (validating
     * parsers must do so).</p>
     *
     * @param chars The characters from the XML document.
     * @param start The start position in the array.
     * @param length The number of characters to read from the array.
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
     *            wrapping another exception.
     * @see #ignorableWhitespace
     * @see org.xml.sax.Locator
     *
     * @throws org.xml.sax.SAXException
     */
public void characters(final char[] chars, final int start, final int length) throws org.xml.sax.SAXException {
    // is created if string is empty.	
    if (length == 0 || (m_inEntityRef && !m_expandDTDEntities))
        return;
    m_docIsEmpty = false;
    if (m_elemContext.m_startTagOpen) {
        closeStartTag();
        m_elemContext.m_startTagOpen = false;
    } else if (m_needToCallStartDocument) {
        startDocumentInternal();
    }
    if (m_cdataStartCalled || m_elemContext.m_isCdataSection) {
        /* either due to startCDATA() being called or due to 
             * cdata-section-elements atribute, we need this as cdata
             */
        cdata(chars, start, length);
        return;
    }
    if (m_cdataTagOpen)
        closeCDATA();
    if (m_disableOutputEscapingStates.peekOrFalse() || (!m_escaping)) {
        charactersRaw(chars, start, length);
        // time to fire off characters generation event
        if (m_tracer != null)
            super.fireCharEvent(chars, start, length);
        return;
    }
    if (m_elemContext.m_startTagOpen) {
        closeStartTag();
        m_elemContext.m_startTagOpen = false;
    }
    try {
        int i;
        int startClean;
        // skip any leading whitspace 
        // don't go off the end and use a hand inlined version
        // of isWhitespace(ch)
        final int end = start + length;
        // last non-clean character that was processed
        int lastDirtyCharProcessed = start - 1;
        // that was processed
        final Writer writer = m_writer;
        boolean isAllWhitespace = true;
        // process any leading whitspace
        i = start;
        while (i < end && isAllWhitespace) {
            char ch1 = chars[i];
            if (m_charInfo.shouldMapTextChar(ch1)) {
                // The character is supposed to be replaced by a String
                // so write out the clean whitespace characters accumulated
                // so far
                // then the String.
                writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                String outputStringForChar = m_charInfo.getOutputStringForChar(ch1);
                writer.write(outputStringForChar);
                // We can't say that everything we are writing out is
                // all whitespace, we just wrote out a String.
                isAllWhitespace = false;
                // mark the last non-clean
                lastDirtyCharProcessed = i;
                // character processed
                i++;
            } else {
                // The character is clean, but is it a whitespace ?
                switch(ch1) {
                    // TODO: Any other whitespace to consider?
                    case CharInfo.S_SPACE:
                        // Just accumulate the clean whitespace
                        i++;
                        break;
                    case CharInfo.S_LINEFEED:
                        lastDirtyCharProcessed = processLineFeed(chars, i, lastDirtyCharProcessed, writer);
                        i++;
                        break;
                    case CharInfo.S_CARRIAGERETURN:
                        writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                        writer.write("&#13;");
                        lastDirtyCharProcessed = i;
                        i++;
                        break;
                    case CharInfo.S_HORIZONAL_TAB:
                        // Just accumulate the clean whitespace
                        i++;
                        break;
                    default:
                        // The character was clean, but not a whitespace
                        // so break the loop to continue with this character
                        // (we don't increment index i !!)
                        isAllWhitespace = false;
                        break;
                }
            }
        }
        /* If there is some non-whitespace, mark that we may need
             * to preserve this. This is only important if we have indentation on.
             */
        if (i < end || !isAllWhitespace)
            m_ispreserve = true;
        for (; i < end; i++) {
            char ch = chars[i];
            if (m_charInfo.shouldMapTextChar(ch)) {
                // The character is supposed to be replaced by a String
                // e.g.   '&'  -->  "&amp;"
                // e.g.   '<'  -->  "&lt;"
                writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                String outputStringForChar = m_charInfo.getOutputStringForChar(ch);
                writer.write(outputStringForChar);
                lastDirtyCharProcessed = i;
            } else {
                if (ch <= 0x1F) {
                    // common TAB, NEW-LINE, CARRIAGE-RETURN
                    switch(ch) {
                        case CharInfo.S_HORIZONAL_TAB:
                            // Leave whitespace TAB as a real character
                            break;
                        case CharInfo.S_LINEFEED:
                            lastDirtyCharProcessed = processLineFeed(chars, i, lastDirtyCharProcessed, writer);
                            break;
                        case CharInfo.S_CARRIAGERETURN:
                            writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                            writer.write("&#13;");
                            lastDirtyCharProcessed = i;
                            // Leave whitespace carriage return as a real character
                            break;
                        default:
                            writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                            writer.write("&#");
                            writer.write(Integer.toString(ch));
                            writer.write(';');
                            lastDirtyCharProcessed = i;
                            break;
                    }
                } else if (ch < 0x7F) {
                // Range 0x20 through 0x7E inclusive
                // Normal ASCII chars, do nothing, just add it to
                // the clean characters
                } else if (ch <= 0x9F) {
                    // Range 0x7F through 0x9F inclusive
                    // More control characters, including NEL (0x85)
                    writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                    writer.write("&#");
                    writer.write(Integer.toString(ch));
                    writer.write(';');
                    lastDirtyCharProcessed = i;
                } else if (ch == CharInfo.S_LINE_SEPARATOR) {
                    // LINE SEPARATOR
                    writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                    writer.write("&#8232;");
                    lastDirtyCharProcessed = i;
                } else if (m_encodingInfo.isInEncoding(ch)) {
                // If the character is in the encoding, and
                // not in the normal ASCII range, we also
                // just leave it get added on to the clean characters
                } else {
                    // This is a fallback plan, we should never get here
                    // but if the character wasn't previously handled
                    // (i.e. isn't in the encoding, etc.) then what
                    // should we do?  We choose to write out an entity
                    writeOutCleanChars(chars, i, lastDirtyCharProcessed);
                    writer.write("&#");
                    writer.write(Integer.toString(ch));
                    writer.write(';');
                    lastDirtyCharProcessed = i;
                }
            }
        }
        // we've reached the end. Any clean characters at the
        // end of the array than need to be written out?
        startClean = lastDirtyCharProcessed + 1;
        if (i > startClean) {
            int lengthClean = i - startClean;
            m_writer.write(chars, startClean, lengthClean);
        }
        // For indentation purposes, mark that we've just writen text out
        m_isprevtext = true;
    } catch (IOException e) {
        throw new SAXException(e);
    }
    // time to fire off characters generation event
    if (m_tracer != null)
        super.fireCharEvent(chars, start, length);
}
Also used : IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) SAXException(org.xml.sax.SAXException)

Example 34 with SAXException

use of org.xml.sax.SAXException in project j2objc by google.

the class ToStream method closeStartTag.

/**
     * For the enclosing elements starting tag write out
     * out any attributes followed by ">"
     *
     * @throws org.xml.sax.SAXException
     */
protected void closeStartTag() throws SAXException {
    if (m_elemContext.m_startTagOpen) {
        try {
            if (m_tracer != null)
                super.fireStartElem(m_elemContext.m_elementName);
            int nAttrs = m_attributes.getLength();
            if (nAttrs > 0) {
                processAttributes(m_writer, nAttrs);
                // clear attributes object for re-use with next element
                m_attributes.clear();
            }
            m_writer.write('>');
        } catch (IOException e) {
            throw new SAXException(e);
        }
        /* whether Xalan or XSLTC, we have the prefix mappings now, so
             * lets determine if the current element is specified in the cdata-
             * section-elements list.
             */
        if (m_CdataElems != null)
            m_elemContext.m_isCdataSection = isCdataSection();
        if (m_doIndent) {
            m_isprevtext = false;
            m_preserves.push(m_ispreserve);
        }
    }
}
Also used : IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 35 with SAXException

use of org.xml.sax.SAXException in project j2objc by google.

the class ToStream method internalEntityDecl.

/**
     * Report an internal entity declaration.
     *
     * <p>Only the effective (first) declaration for each entity
     * will be reported.</p>
     *
     * @param name The name of the entity.  If it is a parameter
     *        entity, the name will begin with '%'.
     * @param value The replacement text of the entity.
     * @exception SAXException The application may raise an exception.
     * @see #externalEntityDecl
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl
     */
public void internalEntityDecl(String name, String value) throws SAXException {
    // Do not inline external DTD
    if (m_inExternalDTD)
        return;
    try {
        DTDprolog();
        outputEntityDecl(name, value);
    } catch (IOException e) {
        throw new SAXException(e);
    }
}
Also used : IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)1248 IOException (java.io.IOException)754 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)466 Document (org.w3c.dom.Document)316 DocumentBuilder (javax.xml.parsers.DocumentBuilder)265 InputSource (org.xml.sax.InputSource)249 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)203 InputStream (java.io.InputStream)160 Element (org.w3c.dom.Element)143 NodeList (org.w3c.dom.NodeList)131 File (java.io.File)129 SAXParseException (org.xml.sax.SAXParseException)119 Node (org.w3c.dom.Node)106 ByteArrayInputStream (java.io.ByteArrayInputStream)99 StringReader (java.io.StringReader)92 TransformerException (javax.xml.transform.TransformerException)91 SAXParser (javax.xml.parsers.SAXParser)83 FileInputStream (java.io.FileInputStream)78 ArrayList (java.util.ArrayList)78 XMLReader (org.xml.sax.XMLReader)70