Package com.volantis.xml.pipeline.sax.conditioners

Examples of com.volantis.xml.pipeline.sax.conditioners.ContentConditioner


        String method = "createContentConditioner";
        Class paramTypes [] = {String.class, XMLFilter.class};

        Object args [] = {customContentType, xmlFilter};
        ContentConditioner actual = (ContentConditioner)
                PrivateAccessor.invoke(process, method, paramTypes, args);
        assertSame("Unexpected conditioner returned.", xmlConditioner, actual);

        // check that we still get the custom conditioner when the content type
        // has extra attributes.
        args[0] = customContentType + "; charset=\"utf8\"";
        actual = (ContentConditioner)
                PrivateAccessor.invoke(process, method, paramTypes, args);
        assertSame("Unexpected conditioner returned.", xmlConditioner, actual);

        // Check that we get an HTMLResponseConditioner for text/html
        args[0] = "text/html; charset=\"utf8\"";
        actual = (ContentConditioner)
                PrivateAccessor.invoke(process, method, paramTypes, args);
        assertEquals("Unexpected conditioner returned.",
                HTMLResponseConditioner.class, actual.getClass());

        // Check that we get an XMLResponseConditioner for anything else
        args[0] = "text/plain; charset=\"utf8\"";
        actual = (ContentConditioner)
                PrivateAccessor.invoke(process, method, paramTypes, args);
        assertEquals("Unexpected conditioner returned.",
                XMLResponseConditioner.class, actual.getClass());
    }
View Full Code Here


    private void consumeResponse(String redirectURL,
                                 InputStream response,
                                 String contentType)
            throws IOException, SAXException {
        XMLFilter responseFilter = retrieveResponseFilter(contentType);
        ContentConditioner conditioner =
                createContentConditioner(contentType, responseFilter);
        InputSource source = new InputSource(response);

        String charEncoding;

        // Get the charset from the content type first as that has priority
        // over any other setting.
        charEncoding = HeaderUtils.getCharSetFromContentType(contentType);

        // todo If no charset was found and the content type is text/html then
        // todo process the <meta> tags in the content to see whether there is
        // todo a content-type property that has a charset parameter.

        // If no character encoding could be found then use the default
        // configured one.
        if (charEncoding == null) {
            charEncoding = configuration.getCharacterEncoding();
        }

        // Set the character encoding in the input source.
        if (charEncoding != null) {
            source.setEncoding(charEncoding);
        }

        // We aim to have the following process(es) in the pipeline
        // WDProcess -> CUP -> [[URLRewriteProcess] | [Pipeline]] -> next
        // where URLRewriteProcess is chained to its own CUP setup in
        // its setPipeline() method.
        XMLProcess nextProcess = next;

        // If the configuration has the the 'responseContainsPipelineMarkup'
        // flag set, then we need to create a pipeline and insert it before
        // the next process (which could be the URLRewriteProcess or next
        if (configuration.getResponseContainsPipelineMarkup()) {
            XMLPipeline pipeline = getPipelineContext().getPipelineFactory().
                    createDynamicPipeline(getPipelineContext());
            XMLProcess pipelineProcess = pipeline.getPipelineProcess();
            pipelineProcess.setNextProcess(nextProcess);
            nextProcess = pipelineProcess;
        }

        if (redirectURL != null) {
            if (redirectURL.indexOf("://") == -1) {
                // We have been redirected to a relative url. In
                // this case there is no need to rewrite relative urls
                redirectURL = null;
            } else {
                // We need to set redirectURL to its prefex i.e.
                // remove the resource part if there is one.
                if (hasResource(redirectURL)) {
                    int index = redirectURL.lastIndexOf('/');
                    redirectURL = redirectURL.substring(0, index);
                }
            }
        }
        // We want the URLRewrite process to appear immediately after the
        // CUP so that
        XMLProcess urlRewriteProcess = createURLRewriterProcess(redirectURL);
        if (urlRewriteProcess != null) {
            // Only add the url rewriter process to the pipeline if
            // the process returned is not null. This process is chained
            // to the cup process so that its ouput will be returned
            // to the cup.
            urlRewriteProcess.setNextProcess(nextProcess);
            urlRewriteProcess.setPipeline(getPipeline());
            nextProcess = urlRewriteProcess;
        }
        // Always create the cup process. Note that this won't always be
        // the case. See the comments in URLRewriteProcess.
        XMLProcess cup = getPipelineContext().
                getPipelineFactory().createContextUpdatingProcess();
        cup.setPipeline(getPipeline());

        // Chain the cup to the next process (which may be the URLRewrite
        // process OR Pipeline OR next in that order).
        cup.setNextProcess(nextProcess);
        setNextProcess(cup);

        source.setSystemId(getUrlString());
        conditioner.condition(source, cup);
    }
View Full Code Here

     * @param filter The XMLFilter for use by the created conditioner.
     * @return A conditioner that can condition the specified content type.
     */
    private ContentConditioner createContentConditioner(String contentType,
                                                        XMLFilter filter) {
        ContentConditioner conditioner = null;
        if (contentType != null) {
            // ContentConditioners should only ever be mapped against the short
            // form of content type strings.  As such we must extract the
            // content type up to the ';' separator.
            int pos = contentType.indexOf(';');
View Full Code Here

     * @param filter the XMLFilter used by the ContentConditioner
     * @return the appropriate ContentConditioner
     */
    public static ContentConditioner
            createContentTypeConditioner(String contentType, XMLFilter filter) {
        ContentConditioner conditioner;
        if (contentType.startsWith("text/html")) {
            conditioner = new HTMLResponseConditioner(filter);
        } else {
            conditioner = new XMLResponseConditioner(filter);
        }
View Full Code Here

TOP

Related Classes of com.volantis.xml.pipeline.sax.conditioners.ContentConditioner

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.