Package org.xml.sax

Examples of org.xml.sax.Locator


    // Javadoc inherited
    public void endDocument() throws SAXException {
        eventCount--;
        if (eventCount < 0) {
            Locator locator = getPipelineContext().getCurrentLocator();
            XMLStreamingException e = new XMLStreamingException(
                    "endDocument received without a preceeding startDocument",
                    locator);
            fatalError(e);
        }
View Full Code Here


                    ServletResponse.class);

            // this process cannot execute with either of these two objects so
            // throw an exception if either one or both is missing
            if (request == null || response == null) {
                Locator locator = context.getCurrentLocator();
                XMLProcessingException xmlException =
                        new XMLProcessingException(
                                "Null request and response objects in context",
                                locator);
                fatalError(xmlException);
            }

            // Get valid a RequestDispatcher to dispatch to
            RequestDispatcher dispatcher = getRequestDispatcher(request);
            try {
                dispatcher.include(request, response);
            } catch (Exception e) {
                Locator locator = getPipelineContext().getCurrentLocator();
                XMLProcessingException xmlException =
                        new XMLProcessingException("Failed to include URI ",
                                                   locator, e);
                fatalError(xmlException);
            }
View Full Code Here

            String message = exception.getMessage();
            IMarker marker = file.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.MESSAGE, message);
            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
            marker.setAttribute(DOMValidator.class.getName(), true);
            Locator locator = validationHandler.getDocumentLocator();
            if (locator != null) {
                int lineNumber =
                        validationHandler.getDocumentLocator().getLineNumber();
                marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
            }
View Full Code Here

     * @param e
     */
    private void handleException(Exception e,String absoluteURI)throws SAXException {
        StringBuffer errorMessages = this.getCollatingErrorListener().getErrorBuffer();
        this.getCollatingErrorListener().resetErrorBuffer();
        Locator locator = getPipelineContext().getCurrentLocator();
        SAXParseException error =
                new XMLProcessingException("Error while attempting to process: "+
                        absoluteURI + "\ndue to following errors: "+
                        errorMessages,locator, e);
        fatalError(error);
View Full Code Here

            }
            addTemplates(templates, Boolean.valueOf(isCompilable));
        } catch (MalformedURLException e) {
            StringBuffer errorMessages = this.getCollatingErrorListener().getErrorBuffer();
            this.getCollatingErrorListener().resetErrorBuffer();
            Locator locator = getPipelineContext().getCurrentLocator();
            SAXParseException error =
                    new ResourceNotFoundException("Error while attempting to process: "+
                            absoluteURI + "\ndue to following errors: "+
                            errorMessages, locator, e);
            fatalError(error);
View Full Code Here

                "XMLPipelineContext should have had its base uri updated",
                baseURI,
                currentBase);
       
        // get hold of the current locator from the pipeline context
        Locator currentLocator =
                process.getPipeline().getPipelineContext().getCurrentLocator();
       
        // ensure that the XMLPipelineContexts stack of locators is updated
        assertSame(
                "XMLPipelineContext should have the current locator updated",
View Full Code Here

        boolean isValid = true;

        // The href attribute is required
        if (null == href) {
            // need to send an error down the pipeline
            Locator locator = context.getCurrentLocator();
            ResourceNotFoundException rnfe =
                    new ResourceNotFoundException("URLConnector requires the " +
                                                  "href attribute to be set",
                                                  locator);
            isValid = false;
            target.fatalError(rnfe);
        }

        if (null != parse &&
                !(XML_VALUE.equals(parse) || TEXT_VALUE.equals(parse))) {
            // need to send an error down the pipeline
            Locator locator = context.getCurrentLocator();
            XMLProcessingException e =
                    new XMLProcessingException("parse attribute must either " +
                                               TEXT_VALUE + " or " + XML_VALUE,
                                               locator);
            isValid = false;
View Full Code Here

        } catch (MalformedURLException e) {
            uridFetchTransaction.stop(
                MonitoredTransaction.FAILED, urlAsString);
            // need to generate an error event.
            Locator locator = context.getCurrentLocator();
            ResourceNotFoundException error = new ResourceNotFoundException(
                "The URI " + href + " could not be included", locator, e);
            error.initErrorInfo(id, null, null,null);
            target.fatalError(error);
        } catch (RuntimeHttpException e) {
            uridFetchTransaction.stop(
                MonitoredTransaction.FAILED, urlAsString);
            // need to generate an error event.
            Locator locator = context.getCurrentLocator();
            ResourceNotFoundException error = new ResourceNotFoundException(
                "The URI " + href + " could not be included", locator, e);
            error.initErrorInfo(id, null, null,null);
            target.fatalError(error);
        }
View Full Code Here

        String inclusionSystemId = url.toExternalForm();
        // check to see if the document that is about to be processed has
        // already been included. If it has then
        if (isCyclicInclusion(url)) {
            // cannot enter a cyclic inclusion
            Locator locator = context.getCurrentLocator();
            CyclicInclusionException ce =
                    new CyclicInclusionException("Cyclic Inclusion encountered " +
                                                 inclusionSystemId, locator);
            target.fatalError(ce);
            return;
        }

        // As this XML Document can contain pipeline mark-up we need
        // to ensure that the parsed document enters a pipeline so that
        // it is processed correctly.
        XMLPipelineFactory factory = context.getPipelineFactory();

        // create a new pipeline.
        XMLPipeline pipeline = factory.createDynamicPipeline(context);

        XMLProcess cup = factory.createContextUpdatingProcess();
        cup.setPipeline(target.getPipeline());
        XMLProcess pipelineProcess = pipeline.getPipelineProcess();
        cup.setNextProcess(pipelineProcess);

        // set up the XMLReader so that the inclusion can be read.
        XMLReader reader = createXMLReader();
        reader.setErrorHandler(cup);
        reader.setContentHandler(cup);

        // Chain the new pipeline process to the target process
        pipelineProcess.setNextProcess(target);

        URLContentManager manager = PipelineURLContentManager.retrieve(
                context);

        try {
            final URLConfiguration urlConfiguration =
                URLConfigurationFactory.getURLConfiguration(url, context);
            URLContent content =
                manager.getURLContent(url, timeout, urlConfiguration);

            // InputSource for content that we are trying to include.
            InputSource source = new InputSource(content.getInputStream());

            // Ensure that the systemID property is set for the
            // InputSource. The XMLReader will need this in order to
            // resolve relative URIs
            source.setSystemId(inclusionSystemId);

            // add dependency to the dependency context
            final DependencyContext dependencyContext =
                context.getDependencyContext();
            if (dependencyContext != null &&
                dependencyContext.isTrackingDependencies()) {

                dependencyContext.addDependency(content.getDependency());
            }

            // perform the inclusion
            reader.parse(source);

        } catch (SAXException e) {

            // If the parser encounters a truly fatal error (e.g. an entity it
            // does not understand), it will throw an exception even if the
            // pipeline try operation prevents the error handler from doing so.
            // This basically defeats our currently useless try operation and
            // allows the entire pipeline to crash. So we must catch any
            // exceptions here manually and deal with them ourselves. Sigh.
            //
            // If we fixed VBM:2004030305 then this code would hopefully not be
            // required.

            uridFetchTransaction.stop(MonitoredTransaction.FAILED,
                    url.toExternalForm());

            // If the pipeline is already handling this error,
            if (context.inErrorRecoveryMode()) {
                // Then we assume that there is a containing try operation that
                // needs help to avoid the pipeline crashing, so we need to
                // mask the exception. So just continue on and hope the
                // pipeline error handling will save us. Note that we cannot
                // re-report it via fatalError or the flow control manager
                // objects.
                if (logger.isDebugEnabled()) {
                    logger.debug("Fetch encountered XML parsing exception " +
                            "while error recovery is in progress, ignoring", e);
                }
            } else {
                // Else we assume that there is no containing try operation.
                // In this case just let the exception propogate up and cause
                // the pipeline to die.
                if (logger.isDebugEnabled()) {
                    logger.debug("Fetch encountered XML parsing exception " +
                            "while no error recovery is in progress, rethrowing",
                            e);
                }
                throw e;
            }

        } catch (IOException ioe) {
             uridFetchTransaction.stop(MonitoredTransaction.FAILED, url.toExternalForm());
            // get hold of the current locator
            Locator currentLocator = context.getCurrentLocator();

            // this is a streaming error as the part of the document might
            // have been included.
            ResourceNotFoundException se =
                    new ResourceNotFoundException(
View Full Code Here

     */
    private boolean isCyclicInclusion(URL inclusion) {
        String inclusionSystemId = inclusion.toExternalForm();
        boolean isCyclic = false;
        Iterator iter = context.getLocators();
        Locator locator;
        while (iter.hasNext() && !isCyclic) {
            locator = (Locator)iter.next();
            isCyclic = inclusionSystemId.equals(locator.getSystemId());
        }
        return isCyclic;
    }
View Full Code Here

TOP

Related Classes of org.xml.sax.Locator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.