Package com.volantis.xml.pipeline.sax

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


        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);
                return null;
            }
View Full Code Here


     */
    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

    public Object startElement(DynamicProcess dynamicProcess,
                               ExpandedName elementName,
                               Attributes attributes)
            throws SAXException {

        XMLPipelineException exception = new XMLPipelineException(
                "Deliberately generated exception.",
                dynamicProcess.getPipeline().getPipelineContext().
                getCurrentLocator());

        dynamicProcess.fatalError(exception);
View Full Code Here

        if (config == null ||
                !(config instanceof ProxySessionIdConfiguration)) {
            // cannot get hold of the configuration. As this is fatal
            // deliver a fatal error down the pipeline
            XMLPipelineException error = new XMLPipelineException(
                    "Could not retrieve the Proxy Session Id",
                    context.getCurrentLocator());

            try {
                pipeline.getPipelineProcess().fatalError(error);
View Full Code Here

TOP

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

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.