Package com.volantis.xml.pipeline.sax

Examples of com.volantis.xml.pipeline.sax.XMLPipeline


    // Javadoc inherited
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        XMLPipeline pipeline = dynamicProcess.getPipeline();

        StringBuffer hrefAttr = new StringBuffer(PICASA_FEED_API_URL);
        StringBuffer queryString = new StringBuffer();

        String userId = attributes.getValue(USER_ID_ATTRIBUTE);

        if (userId != null) {
            hrefAttr.append(MessageFormat.format(
                PICASA_USER_FRAGMENT, userId));   
        }

        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


    public void endElement(
            DynamicProcess dynamicProcess, ExpandedName element, Object object)
            throws SAXException {

        try {
            XMLPipeline pipeline = dynamicProcess.getPipeline();
            context = dynamicProcess.getPipelineContext();
            authData = AuthData.retrieve(context);
            this.id = ((HashMap<String,String>)object).get(ATTRIBUTE_ID);
            if (authData == null) {
                throw new XMLPipelineException(EXCEPTION_LOCALIZER.format("gdocs-authentication-data-missing"),null);
View Full Code Here

     * Test: cache element with both name and cacheKey attributes set.
     * CacheEntry for those attributes does not exist in the cache.
     */
    public void testAttributes() throws Exception {

        XMLPipeline pipeline = new XMLPipelineProcessImpl(contextMock);

        final String cacheName = "cache107";
        final String cacheKeyValue = "key107";

        CacheKey cacheKey = new CacheKey();
View Full Code Here

     * Tests if CacheRule correctly delegates the time to live and expire mode
     * values to the CacheBodyOperationProcess.
     */
    public void testTimeToLiveWithKeyAttr() throws Exception {

        final XMLPipeline pipeline = new XMLPipelineProcessImpl(contextMock);
        dynamicProcessMock.expects.getPipeline().returns(pipeline);

        final CacheBodyOperationProcess[] cacheBodyOperationProcess =
            new CacheBodyOperationProcess[1];

View Full Code Here

    // Javadoc inherited
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        XMLPipeline pipeline = dynamicProcess.getPipeline();

        StringBuffer queryString = new StringBuffer();        

        String photosetId = attributes.getValue(PHOTOSET_ID_ATTRIBUTE);
        String userId = attributes.getValue(USER_ID_ATTRIBUTE);
        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

                pipelineFactory.createPipelineContext(
                        pipelineConfiguration,
                        (EnvironmentInteraction)null);

        // create a dynamic pipeine
        XMLPipeline pipeline = pipelineFactory.createDynamicPipeline(pipelineContext);

        AbsoluteToRelativeURLOperationProcess process =
            new AbsoluteToRelativeURLOperationProcess();
        process.setPipeline(pipeline);
View Full Code Here

                pipelineFactory.createPipelineContext(
                        pipelineConfiguration,
                        (EnvironmentInteraction)null);

        // create a dynamic pipeine
        XMLPipeline pipeline = pipelineFactory.
                createDynamicPipeline(pipelineContext);

        AbsoluteToRelativeURLOperationProcess process =
            new AbsoluteToRelativeURLOperationProcess();
        process.setPipeline(pipeline);
View Full Code Here

                pipelineFactory.createPipelineContext(
                        pipelineConfiguration,
                        (EnvironmentInteraction)null);

        // create a dynamic pipeine
        XMLPipeline pipeline = pipelineFactory.
                createDynamicPipeline(pipelineContext);

        AbsoluteToRelativeURLOperationProcess process =
            new AbsoluteToRelativeURLOperationProcess();
        process.setPipeline(pipeline);
View Full Code Here

            // cache element or cache element has key attribute set, so
            // recording process has been already started.
            CacheBodyOperationProcess operation =
                    new CacheBodyOperationProcess();

            XMLPipeline pipeline = dynamicProcess.getPipeline();

            operation.setCacheName(cacheName);
            operation.setCacheKey(properties.getCacheKey());
            final CacheControl cacheControl = properties.getCacheControl();
            if (cacheControl != null && cacheControl.getTimeToLive() == null) {
View Full Code Here

                operation.setCacheName(cacheName);
                operation.setCache(cache);
                CacheKey cacheKey = new CacheKey();
                cacheKey.addKey(cacheKeyString);
                operation.setCacheKey(cacheKey);
                XMLPipeline pipeline = dynamicProcess.getPipeline();
                operation.setPipeline(pipeline);
                operation.setFixedExpiryMode(fixedExpiryMode);
                operation.setMaxWaitTime(maxWaitTime);

                try {
View Full Code Here

TOP

Related Classes of com.volantis.xml.pipeline.sax.XMLPipeline

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.