Package org.xml.sax

Examples of org.xml.sax.Locator


                dependencyContext.addDependency(content.getDependency());
            }
        } catch (UnsupportedEncodingException uee) {
            // get hold of the current locator
            Locator currentLocator =
                    context.getCurrentLocator();

            // this is a processing error as it will occur before we start
            // reading in the text
            XMLProcessingException se =
                    new XMLProcessingException(
                            "Inclusion failed due to " +
                            "unsupporteddocument character encoding " +
                            characterEncoding, currentLocator, uee);

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

            // report this fatal a error
            target.fatalError(se);

        } catch (IOException ioe) {
            // 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.
            XMLStreamingException se =
View Full Code Here


    /**
     * Tests the pushLocator method
     * @throws Exception if an error occurs
     */
    public void testPushLocator() throws Exception {
        Locator l1 = createLocator();
        Locator l2 = createLocator();

        context.pushLocator(l1);
        context.pushLocator(l2);
       
        // ensure that l2 is at the top of the stack        
View Full Code Here

    /**
     * Tests the popLocator method
     * @throws Exception if an error occurs
     */
    public void testPopLocator() throws Exception {
        Locator l1 = createLocator();
        Locator l2 = createLocator();

        internalLocatorStack.push(l1);
        internalLocatorStack.push(l2);
       
        // ensure items are popped off in the correct order
View Full Code Here

    /**
     * Tests the getCurrentBaseURI method
     * @throws Exception if an error occurs
     */
    public void testGetCurrentBaseURI() throws Exception {
        Locator l1 = createLocator();
        internalLocatorStack.push(l1);

        assertEquals("getCurrentLocator should return Locator at top of stack",
                     l1, context.getCurrentLocator());
    }
View Full Code Here

     * Tests the getLocators method.
     * @throws Exception if an error occurs
     */
    public void testGetLocators() throws Exception {
        // create some locators
        Locator l1 = createLocator();
        Locator l2 = createLocator();
        // add the locators to the context
        context.pushLocator(l1);
        context.pushLocator(l2);
        // call getLocators to obtain an iterator
        Iterator i = context.getLocators();
View Full Code Here

        String albumName = attributes.getValue(ALBUM_NAME_ATTRIBUTE);
        String albumId = attributes.getValue(ALBUM_ID_ATTRIBUTE);

        if (albumName != null && albumId != null) {
            Locator locator = pipeline.getPipelineContext().getCurrentLocator();
            XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to use both album and album-id attributes",
                                locator);
            getTargetProcess(pipeline).fatalError(e);
            return null;
        }

        if (albumName != null) {
            if (userId == null) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to use album attribute without specifying user-id attribute",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            hrefAttr.append(MessageFormat.format(
                            PICASA_ALBUM_NAME_FRAGMENT, albumName));
        } else if (albumId != null) {
            if (userId == null) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to use album-id attribute without specifying user-id attribute",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            hrefAttr.append(MessageFormat.format(
                            PICASA_ALBUM_ID_FRAGMENT, albumId));
        }

        String photoId = attributes.getValue(PHOTO_ID_ATTRIBUTE);        

        if (photoId != null) {
            if (albumName == null && albumId == null) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to use photo-id attribute without specifying album or album-id attribute",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            hrefAttr.append(MessageFormat.format(
                            PICASA_PHOTO_ID_FRAGMENT, photoId));
        } else {
            queryString.append(PICASA_KIND_PHOTO_FRAGMENT);
        }

        // tags restriction/constraint can be user-, album- or photo-based
        String tags = attributes.getValue(TAGS_ATTRIBUTE);
        if (tags != null) {
            // convert space separated list to comma separated list
            String commaSeparatedTags = tags.trim().replaceAll("\\s+", ",");
            if (!"".equals(queryString)) {
                queryString.append("&");               
            }
            queryString.append(MessageFormat.format(
                            PICASA_TAG_FRAGMENT, commaSeparatedTags));
        } else if (attributes.getValue(QUERY_ATTRIBUTE) != null) {
            if (!"".equals(queryString)) {
                queryString.append("&");
            }
            queryString.append(MessageFormat.format(
                            PICASA_QUERY_FRAGMENT,
                            attributes.getValue(QUERY_ATTRIBUTE)));
        }

        // pagination parameters
        String pageSize = attributes.getValue(PAGE_SIZE_ATTRIBUTE);
        String pageIndex = attributes.getValue(PAGE_INDEX_ATTRIBUTE);   

        if (pageSize != null) {
            Integer pageSizeInt = null;
            try {
                pageSizeInt = Integer.parseInt(pageSize);
            } catch(NumberFormatException nfe) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-size attribute should be of integer value",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
          }

            if (pageSizeInt < 1 || pageSizeInt > 500) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-size attribute value should be in the range of [1,500]",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            pageSize = pageSizeInt.toString();
        } else {
            pageSize = DEFAULT_PAGE_SIZE;
        }

        if (!"".equals(queryString)) {
            queryString.append("&");               
        }

        queryString.append(MessageFormat.format(
                PICASA_MAX_RESULTS_FRAGMENT, pageSize));

        if (pageIndex != null) {
            Integer pageIndexInt = null;
            try {
                pageIndexInt = Integer.parseInt(pageIndex);
            } catch(NumberFormatException nfe) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-index attribute should be of integer value",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }

            if (pageIndexInt < 1) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-index attribute value should be in the range of [1,...]",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
View Full Code Here

    // javadoc inherited
    public void processAttributes(Attributes attributes) throws SAXException {
        variableName = attributes.getValue("name");
        variableValue = attributes.getValue("value");
        if(variableName == null || variableValue == null) {
            Locator l = getPipelineContext().getCurrentLocator();
            fatalError(new ExtendedSAXParseException(
                    "name and value attributes are compulsory", l));                                            
        }
    }
View Full Code Here

        String tags = attributes.getValue(TAGS_ATTRIBUTE);
        String query = attributes.getValue(QUERY_ATTRIBUTE);

        if (photosetId != null) {
            if (userId != null || tags != null || query != null) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to use any of the attributes: 'user-id', 'tags', 'query' " +
                                "when photoset-id is specified",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            queryString.append("?").append(FLICKR_API_PHOTOSETS_METHOD);
            queryString.append("&")
                           .append(MessageFormat.format(
                                FLICKR_PHOTOSET_ID_PARAM, photosetId));
        } else {
            queryString.append("?").append(FLICKR_API_PHOTOS_METHOD);

            if (userId != null) {
                queryString.append("&")
                           .append(MessageFormat.format(
                                FLICKR_USER_ID_PARAM, userId));
            } else if (tags == null && query == null) {
                // parameterless queries are not supported
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "at least one of the attributes: 'user-id', 'tags', 'query' should be specified",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }

            if (tags != null && query != null) {
                // in order not to produce misleading results (as flickr ignores tags param
                // when query/text param is set) it is considered invalid attributes
                // combination
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "not allowed to specify both 'tags' and 'query' attributes",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }

            if (tags != null) {
                // convert space separated list to comma separated list
                String commaSeparatedTags = tags.trim().replaceAll("\\s+", ",");
                queryString.append("&")
                           .append(MessageFormat.format(
                               FLICKR_TAGS_PARAM, commaSeparatedTags))
                           .append("&")
                           .append(FLICKR_TAG_MODE_PARAM);
            }

            if (query != null) {
                queryString.append("&")
                           .append(MessageFormat.format(
                               FLICKR_TEXT_PARAM, query));
            }

        }

        if (attributes.getValue(API_KEY_ATTRIBUTE) != null) {
            queryString.append("&")
                       .append(MessageFormat.format(
                            FLICKR_API_KEY_PARAM,
                            attributes.getValue(API_KEY_ATTRIBUTE)));
        } else {
            Locator locator = pipeline.getPipelineContext().getCurrentLocator();
            XMLPipelineException e =
                    new XMLPipelineException(
                            "api-key attribute should be specified",
                            locator);
            getTargetProcess(pipeline).fatalError(e);
            return null;
        }

        queryString.append("&").append(FLICKR_EXTRAS_PARAM);

        // pagination parameters
        String pageSize = attributes.getValue(PAGE_SIZE_ATTRIBUTE);
        String pageIndex = attributes.getValue(PAGE_INDEX_ATTRIBUTE);

        if (pageSize != null) {
            Integer pageSizeInt = null;
            try {
                pageSizeInt = Integer.parseInt(pageSize);
            } catch(NumberFormatException nfe) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-size attribute should be of integer value",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }

            if (pageSizeInt < 1 || pageSizeInt > 500) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-size attribute value should be in the range of [1,500]",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }
            pageSize = pageSizeInt.toString();
        } else {
            pageSize = DEFAULT_PAGE_SIZE;
        }

        queryString.append("&")
                .append(MessageFormat.format(
                    FLICKR_PER_PAGE_PARAM, pageSize));

        if (pageIndex != null) {
            Integer pageIndexInt;
            try {
                pageIndexInt = Integer.parseInt(pageIndex);
            } catch(NumberFormatException nfe) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-index attribute should be of integer value",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
                return null;
            }

            if (pageIndexInt < 1) {
                Locator locator = pipeline.getPipelineContext().getCurrentLocator();
                XMLPipelineException e =
                        new XMLPipelineException(
                                "page-index attribute value should be in the range of [1,...]",
                                locator);
                getTargetProcess(pipeline).fatalError(e);
View Full Code Here

     * @return The exception to forward.
     */
    private SAXParseException createException(
            DynamicProcess dynamicProcess, final String message) {
        XMLPipelineContext context = dynamicProcess.getPipelineContext();
        Locator locator = context.getCurrentLocator();
        SAXParseException exception = new XMLPipelineException(message,
                locator);
        return exception;
    }
View Full Code Here

            templatesHandler = getTransformerFactory(isCompilable)
                    .newTemplatesHandler();
            setContentHandler(templatesHandler);
            templatesHandler.startDocument();
        } catch (TransformerConfigurationException e) {
            Locator locator = getPipelineContext().getCurrentLocator();
            String message = "Unable to load TemplatesHandler";
            fatalError(new XMLStreamingException(message, locator, e));
        }
    }
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.