Search in sources :

Example 6 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class SCDBasedBindingSet method reportError.

private void reportError(Element errorSource, String formattedMsg, Exception nestedException) {
    SAXParseException e = new SAXParseException2(formattedMsg, forest.locatorTable.getStartLocation(errorSource), nestedException);
    errorReceiver.error(e);
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) SAXParseException(org.xml.sax.SAXParseException)

Example 7 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class AbstractReferenceFinderImpl method startElement.

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    super.startElement(namespaceURI, localName, qName, atts);
    String relativeRef = findExternalResource(namespaceURI, localName, atts);
    if (relativeRef == null) {
        // not found
        return;
    }
    try {
        // absolutize URL.
        String lsi = locator.getSystemId();
        String ref;
        URI relRefURI = new URI(relativeRef);
        if (relRefURI.isAbsolute())
            ref = relativeRef;
        else {
            if (lsi.startsWith("jar:")) {
                int bangIdx = lsi.indexOf('!');
                if (bangIdx > 0) {
                    ref = lsi.substring(0, bangIdx + 1) + new URI(lsi.substring(bangIdx + 1)).resolve(new URI(relativeRef));
                } else {
                    ref = relativeRef;
                }
            } else {
                ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
            }
        }
        // but don't mark this document as a root.
        if (parent != null) {
            // this is there to allow easier testing
            parent.parse(ref, false);
        }
    } catch (URISyntaxException e) {
        String msg = e.getMessage();
        if (new File(relativeRef).exists()) {
            msg = Messages.format(Messages.ERR_FILENAME_IS_NOT_URI) + ' ' + msg;
        }
        SAXParseException spe = new SAXParseException2(Messages.format(Messages.ERR_UNABLE_TO_PARSE, relativeRef, msg), locator, e);
        fatalError(spe);
        throw spe;
    } catch (IOException e) {
        SAXParseException spe = new SAXParseException2(Messages.format(Messages.ERR_UNABLE_TO_PARSE, relativeRef, e.getMessage()), locator, e);
        fatalError(spe);
        throw spe;
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) SAXParseException(org.xml.sax.SAXParseException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 8 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class TDTDReader method parse.

/**
 * Parses DTD grammar and a binding information into BGM.
 *
 * <p>
 * This method is just a utility method that covers 80% of the use
 * cases.
 *
 * @param    bindingInfo
 *        binding information file, if any. Can be null.
 */
public static Model parse(InputSource dtd, InputSource bindingInfo, ErrorReceiver errorReceiver, Options opts) {
    try {
        // set up a ring
        final Ring old = Ring.begin();
        try {
            ErrorReceiverFilter ef = new ErrorReceiverFilter(errorReceiver);
            JCodeModel cm = new JCodeModel();
            Model model = new Model(opts, cm, NameConverter.standard, opts.classNameAllocator, null);
            Ring.add(cm);
            Ring.add(model);
            Ring.add(ErrorReceiver.class, ef);
            TDTDReader reader = new TDTDReader(ef, opts, bindingInfo);
            DTDParser parser = new DTDParser();
            parser.setDtdHandler(reader);
            if (opts.entityResolver != null)
                parser.setEntityResolver(opts.entityResolver);
            try {
                parser.parse(dtd);
            } catch (SAXParseException e) {
                // this error was already handled by GrammarReaderController
                return null;
            }
            Ring.get(ModelChecker.class).check();
            if (ef.hadError())
                return null;
            else
                return model;
        } finally {
            Ring.end(old);
        }
    } catch (IOException | SAXException e) {
        errorReceiver.error(new SAXParseException2(e.getMessage(), null, e));
        return null;
    } catch (AbortException e) {
        // parsing was aborted but the error was already reported
        return null;
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) IOException(java.io.IOException) JCodeModel(com.sun.codemodel.JCodeModel) SAXException(org.xml.sax.SAXException) ModelChecker(com.sun.tools.xjc.reader.ModelChecker) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) Ring(com.sun.tools.xjc.reader.Ring) SAXParseException(org.xml.sax.SAXParseException) Model(com.sun.tools.xjc.model.Model) JCodeModel(com.sun.codemodel.JCodeModel) DTDParser(com.sun.xml.dtdparser.DTDParser) AbortException(com.sun.tools.xjc.AbortException)

Example 9 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class UnmarshallingContext method handleEvent.

// 
// 
// error handling
// 
// 
/**
 * Reports an error to the user, and asks if s/he wants
 * to recover. If the canRecover flag is false, regardless
 * of the client instruction, an exception will be thrown.
 *
 * Only if the flag is true and the user wants to recover from an error,
 * the method returns normally.
 *
 * The thrown exception will be catched by the unmarshaller.
 */
public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
    ValidationEventHandler eventHandler = parent.getEventHandler();
    boolean recover = eventHandler.handleEvent(event);
    // from the unmarshaller.getResult()
    if (!recover)
        aborted = true;
    if (!canRecover || !recover)
        throw new SAXParseException2(event.getMessage(), locator, new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2)

Example 10 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project metro-jax-ws by eclipse-ee4j.

the class Internalizer method reportError.

private void reportError(Element errorSource, String formattedMsg, Exception nestedException) {
    SAXParseException e = new SAXParseException2(formattedMsg, forest.locatorTable.getStartLocation(errorSource), nestedException);
    errorReceiver.error(e);
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

SAXParseException2 (com.sun.istack.SAXParseException2)11 SAXParseException (org.xml.sax.SAXParseException)7 IOException (java.io.IOException)4 SAXException (org.xml.sax.SAXException)3 AbortException (com.sun.tools.xjc.AbortException)2 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JCodeModel (com.sun.codemodel.JCodeModel)1 Model (com.sun.tools.xjc.model.Model)1 ModelChecker (com.sun.tools.xjc.reader.ModelChecker)1 Ring (com.sun.tools.xjc.reader.Ring)1 ForkContentHandler (com.sun.tools.xjc.util.ForkContentHandler)1 DTDParser (com.sun.xml.dtdparser.DTDParser)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 WebApplicationException (javax.ws.rs.WebApplicationException)1