Example usage for org.xml.sax SAXException SAXException

List of usage examples for org.xml.sax SAXException SAXException

Introduction

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

Prototype

public SAXException(Exception e) 

Source Link

Document

Create a new SAXException wrapping an existing exception.

Usage

From source file:gov.nih.nci.cagrid.encoding.AxisContentHandler.java

/**
 * delegates to the serialization context
 *//*from  ww  w . j  a  v a 2  s.c  o  m*/
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    try {
        context.startElement(new QName(uri, localName), attributes);
    } catch (IOException ioe) {
        throw new SAXException(ioe);
    }
}

From source file:com.atlassw.tools.eclipse.checkstyle.builder.PackageNamesLoader.java

/**
 * {@inheritDoc}/*from   w w w. ja  va  2  s. com*/
 */
public void startElement(String aNamespaceURI, String aLocalName, String aQName, Attributes aAtts)
        throws SAXException {
    if (aQName.equals("package")) //$NON-NLS-1$
    {
        // push package name
        final String name = aAtts.getValue("name"); //$NON-NLS-1$
        if (name == null) {
            throw new SAXException("missing package name"); //$NON-NLS-1$
        }
        mPackageStack.push(name);
    }
}

From source file:com.webcohesion.ofx4j.io.OFXV2ContentHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("END ELEMENT: " + qName);
    }/*from  ww w.  j a  v  a  2  s  .  c o m*/

    OFXParseEvent eventToFinish = eventStack.pop();
    if (eventToFinish.getEventType() == OFXParseEvent.Type.CHARACTERS) {
        String chars = eventToFinish.getEventValue().trim();

        if (eventStack.isEmpty()) {
            throw new IllegalStateException(
                    "Illegal character data outside main OFX root element: \"" + chars + "\".");
        } else {
            OFXParseEvent elementEvent = eventStack.pop();
            if (elementEvent.getEventType() != OFXParseEvent.Type.ELEMENT) {
                throw new IllegalStateException("Illegal OFX event before characters \"" + chars + "\" ("
                        + elementEvent.getEventType() + ")!");
            } else {
                String value = elementEvent.getEventValue();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Element " + value + " processed with value " + chars);
                }
                try {
                    this.ofxHandler.onElement(value, chars);
                } catch (OFXParseException e) {
                    throw new SAXException(e);
                }
            }
        }
    } else if (eventToFinish.getEventType() == OFXParseEvent.Type.ELEMENT) {
        //we're ending an aggregate (no character data on the stack).
        if (qName.equals(eventToFinish.getEventValue())) {
            //the last element on the stack is ours; we're ending an OFX aggregate.
            String value = eventToFinish.getEventValue();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Ending aggregate " + value);
            }
            try {
                this.ofxHandler.endAggregate(value);
            } catch (OFXParseException e) {
                throw new SAXException(e);
            }

            this.startedEvents.remove(eventToFinish);
        } else {
            throw new IllegalStateException("Unexpected end tag: " + eventToFinish.getEventValue());
        }
    } else {
        throw new IllegalStateException("Illegal OFX event: " + eventToFinish.getEventType());
    }
}

From source file:com.frameworkset.orm.engine.transform.XmlToData.java

/**
 * Handles opening elements of the xml file.
 *///from  w  ww .  j  a  va  2  s .c o  m
public void startElement(String uri, String localName, String rawName, Attributes attributes)
        throws SAXException {
    try {
        if (rawName.equals("dataset")) {
            //ignore <dataset> for now.
        }

        else {
            Table table = database.getTableByJavaName(rawName);

            if (table == null) {
                throw new SAXException("Table '" + rawName + "' unknown");
            }
            List columnValues = new ArrayList();
            for (int i = 0; i < attributes.getLength(); i++) {
                Column col = table.getColumnByJavaName(attributes.getQName(i));

                if (col == null) {
                    throw new SAXException(
                            "Column " + attributes.getQName(i) + " in table " + rawName + " unknown.");
                }

                String value = attributes.getValue(i);
                columnValues.add(new ColumnValue(col, value));
            }
            data.add(new DataRow(table, columnValues));
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }
}

From source file:com.amalto.core.load.payload.FlushXMLReader.java

public void parse(InputSource input) throws IOException, SAXException {
    if (contentHandler == null) {
        throw new IllegalStateException("Content handler has not been set.");
    }//from   w  w  w .j  a va  2s . co  m

    contentHandler.startDocument();
    contentHandler.startElement(StringUtils.EMPTY, Constants.WRAPPER_ELEMENT, Constants.WRAPPER_ELEMENT,
            Constants.EMPTY_ATTRIBUTES);

    // Prolog
    Metadata metadata = context.getMetadata();
    writePrologElement(Constants.CONTAINER_ELEMENT, metadata.getContainer());
    writePrologElement(Constants.NAME_ELEMENT, metadata.getName());
    writePrologElement(Constants.DMN_ELEMENT, metadata.getDMN());
    writePrologElement(Constants.DMR_ELEMENT, metadata.getDMR());
    writePrologElement(Constants.SP_ELEMENT, metadata.getSP());
    writePrologElement(Constants.TIMESTAMP_ELEMENT, metadata.getVersion());
    writePrologElement(Constants.TASK_ID_ELEMENT, metadata.getTaskId());
    writePrologElement(Constants.ID_ELEMENT, metadata.getId());

    // Payload
    contentHandler.startElement(StringUtils.EMPTY, Constants.PAYLOAD_ELEMENT, Constants.PAYLOAD_ELEMENT,
            Constants.EMPTY_ATTRIBUTES);
    try {
        context.getWriter().flush(contentHandler);
        context.setWriter(new StateContextSAXWriter(contentHandler));
        while (!context.hasFinishedPayload()) {
            context.parse(reader);
        }
        if (context.getDepth() == 1) {
            context.parse(reader);
        }
    } catch (Exception e) {
        throw new SAXException(e);
    }

    contentHandler.endElement(StringUtils.EMPTY, Constants.PAYLOAD_ELEMENT, Constants.PAYLOAD_ELEMENT);

    // End prolog
    contentHandler.endElement(StringUtils.EMPTY, Constants.WRAPPER_ELEMENT, Constants.WRAPPER_ELEMENT);

    contentHandler.endDocument();
}

From source file:com.sonicle.webtop.mail.SaxHTMLMailParser.java

public void initialize(HTMLMailData mailData, boolean justBody) throws SAXException {
    //if (writer!=null || reader!=null) throw new SAXException("SaxHTMLMailParser yet not released!");
    release();/*from   w w  w . j  a v  a  2  s  . co  m*/

    this.mailData = mailData;

    writer = new PipedWriter();
    try {
        reader = new PipedReader(writer);
    } catch (IOException exc) {
        throw new SAXException(exc);
    }
    pwriter = new PrintWriter(writer);
    breader = new BufferedReader(reader);
    this.justBody = justBody;
}

From source file:gov.nih.nci.cagrid.encoding.AxisContentHandler.java

/**
 * delegates to the serialization context
 *///  w w w  .ja  v  a  2  s .com
public void endElement(String uri, String localName, String qName) throws SAXException {
    try {
        context.endElement();
    } catch (IOException ioe) {
        throw new SAXException(ioe);
    }
}

From source file:cz.muni.fi.japanesejmdictsaxparser.saxholder.SaxDataHolder.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    if (mCanceled) {
        throw new SAXException("SAX terminated due to ParserService end.");
    }/* w  ww  . ja  va2s. c o  m*/
    switch (qName) {
    case "entry":
        mDocument = new Document();
        mEnglishJSONSense = new JSONArray();
        mFrenchJSONSense = new JSONArray();
        mDutchJSONSense = new JSONArray();
        mGermanJSONSense = new JSONArray();
        mRussianJSONSense = new JSONArray();
        mJapaneseRebJSON = new JSONArray();
        mJapaneseKebJSON = new JSONArray();

        mRebFirst = null;
        mKebFirst = null;
        break;
    case "reb":
        mJapaneseReb = true;
        break;
    case "keb":
        mJapaneseKeb = true;
        break;
    case "sense":
        mEnglishJSON = new JSONArray();
        mFrenchJSON = new JSONArray();
        mDutchJSON = new JSONArray();
        mGermanJSON = new JSONArray();
        mRussianJSON = new JSONArray();
        break;
    case "gloss":
        switch (attributes.getValue("xml:lang")) {
        case "eng":
            //english
            mEnglish = true;
            break;
        case "fre":
            mFrench = true;
            break;
        case "dut":
            mDutch = true;
            break;
        case "ger":
            mGerman = true;
            break;
        case "rus":
            mRussian = true;
            break;
        }
        break;
    case "ke_ri":
    case "re_pri":
        mPriorityTag = true;
        break;
    case "pos":
        mPos = true;
        break;
    }
}

From source file:com.sshtools.daemon.configuration.ServerConfiguration.java

/**
 *
 *
 * @param uri/*ww w.j a v a 2 s.  co  m*/
 * @param localName
 * @param qname
 * @param attrs
 *
 * @throws SAXException
 */
public void startElement(String uri, String localName, String qname, Attributes attrs) throws SAXException {
    if (currentElement == null) {
        if (!qname.equals("ServerConfiguration")) {
            throw new SAXException("Unexpected root element " + qname);
        }
    } else {
        if (currentElement.equals("ServerConfiguration")) {
            if (qname.equals("ServerHostKey")) {
                //String algorithm = attrs.getValue("AlgorithmName");
                String privateKey = attrs.getValue("PrivateKeyFile");

                if (privateKey == null) {
                    throw new SAXException("Required attributes missing from <ServerHostKey> element");
                }

                log.debug("ServerHostKey PrivateKeyFile=" + privateKey);

                File f = new File(privateKey);

                if (!f.exists()) {
                    privateKey = ConfigurationLoader.getConfigurationDirectory() + privateKey;
                    f = new File(privateKey);
                }

                try {
                    if (f.exists()) {
                        SshPrivateKeyFile pkf = SshPrivateKeyFile.parse(f);
                        SshPrivateKey key = pkf.toPrivateKey(null);
                        serverHostKeys.put(key.getAlgorithmName(), key);
                    } else {
                        log.warn("Private key file '" + privateKey + "' could not be found");
                    }
                } catch (InvalidSshKeyException ex) {
                    log.warn("Failed to load private key '" + privateKey, ex);
                } catch (IOException ioe) {
                    log.warn("Failed to load private key '" + privateKey, ioe);
                }
            } else if (qname.equals("Subsystem")) {
                String type = attrs.getValue("Type");
                String name = attrs.getValue("Name");
                String provider = attrs.getValue("Provider");

                if ((type == null) || (name == null) || (provider == null)) {
                    throw new SAXException("Required attributes missing from <Subsystem> element");
                }

                log.debug("Subsystem Type=" + type + " Name=" + name + " Provider=" + provider);
                allowedSubsystems.put(name, new AllowedSubsystem(type, name, provider));
            } else if (!qname.equals("AuthenticationBanner") && !qname.equals("MaxConnections")
                    && !qname.equals("MaxAuthentications") && !qname.equals("ListenAddress")
                    && !qname.equals("Port") && !qname.equals("CommandPort")
                    && !qname.equals("TerminalProvider") && !qname.equals("AllowedAuthentication")
                    && !qname.equals("RequiredAuthentication") && !qname.equals("AuthorizationFile")
                    && !qname.equals("UserConfigDirectory") && !qname.equals("AllowTcpForwarding")) {
                throw new SAXException("Unexpected <" + qname + "> element after SshAPIConfiguration");
            }
        }
    }

    currentElement = qname;
}

From source file:com.liusoft.sc.util.SchemaResolver.java

/**
 * Resolve the requested external entity.
 *
 * @param publicId The public identifier of the entity being referenced
 * @param systemId The system identifier of the entity being referenced
 *
 * @exception org.xml.sax.SAXException if a parsing exception occurs
 *
 *//*  www.j  a  v  a2 s .  com*/
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {

    if (publicId != null) {
        this.publicId = publicId;
        digester.setPublicId(publicId);
    }

    // Has this system identifier been registered?
    String entityURL = null;
    if (publicId != null) {
        entityURL = (String) entityValidator.get(publicId);
    }

    // Redirect the schema location to a local destination
    String key = null;
    if (entityURL == null && systemId != null) {
        key = systemId.substring(systemId.lastIndexOf('/') + 1);
        entityURL = (String) entityValidator.get(key);
    }

    if (entityURL == null) {
        return (null);
    }

    try {
        return (new InputSource(entityURL));
    } catch (Exception e) {
        throw new SAXException(e);
    }

}