Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


                    SourceResolver resolver,
                    Map objectModel,
                    String source,
                    Parameters par )
    throws Exception {
        Source src = null;
        try {
            // Figure out what script to open.  A missing script name is caught
            // by the resolver/SystemId grouping later on and causes an exception
            String scriptName = source;

            // Locate the appropriate file on the filesytem
            src = resolver.resolve(scriptName);
            String systemID = src.getSystemId();

            if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("script source [" + scriptName + "]");
                getLogger().debug("script resolved to [" + systemID + "]");
            }

            // TODO: why doesn't this work?
            // Reader in = src.getCharacterStream();

            Reader in = new InputStreamReader(src.getInputStream());

            // Set up the BSF manager and register relevant helper "beans"

            BSFManager mgr = new BSFManager();
            HashMap actionMap = new HashMap();

            // parameters to act(...)
            mgr.registerBean("resolver", resolver);
            mgr.registerBean("objectModel", objectModel);
            mgr.registerBean("parameters", par);

            // ScriptAction housekeeping
            mgr.registerBean("actionMap", actionMap);

            // helpers
            // TODO: should we check for a null request object here or let the script handle it?

            mgr.registerBean("logger", getLogger());
            mgr.registerBean("request", ( (Request) objectModel.get(Constants.REQUEST_OBJECT) ) );
            mgr.registerBean("scriptaction", this );
            mgr.registerBean("manager", this.manager );

            getLogger().debug("BSFManager execution begining");

            // Execute the script

            mgr.exec(BSFManager.getLangFromFilename(systemID), systemID, 0, 0,
                    IOUtils.getStringFromReader(in));

            getLogger().debug("BSFManager execution complete");

            // Figure out what to return
            // TODO: decide on a more robust communication method

            if ( actionMap.containsKey( "scriptaction-continue" ) )
            {
                return ( Collections.unmodifiableMap(actionMap) );
            }
            else
            {
                return ( null );
            }
        } catch (ProcessingException e) {
            throw e;
        } catch (Exception e) {
            throw new ProcessingException(
                    "Exception in ScriptAction.act()", e);
        } finally {
            if (src != null) src.recycle();
        } // try/catch
    } // public Map act(...)
View Full Code Here


        if (httpResponse == null || httpRequest == null) {
            throw new ProcessingException("HttpServletRequest or HttpServletResponse object not available");
        }

        // ensure that we are serving a file...
        Source inputSource = null;
        Parser parser = null;
        try {
            inputSource = this.resolver.resolve(this.source);
            String systemId = inputSource.getSystemId();
            if (!systemId.startsWith("file:/"))
                throw new IOException("protocol not supported: " + systemId);

            // construct both ends of the pipe
            PipedInputStream input = new PipedInputStream();

            // start PHP producing results into the pipe
            PhpServlet php = new PhpServlet();
            php.init(new config((ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT)));
            php.setInput(systemId.substring(6));
            php.setOutput(new PipedOutputStream(input));
            php.setRequest(httpRequest);
            php.setResponse(httpResponse);
            new Thread(php).start();

            // pipe the results into the parser
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.setConsumer(this.xmlConsumer);
            parser.parse(new InputSource(input));

            // clean up
            php.destroy();
        } catch (IOException e) {
            getLogger().debug("PhpGenerator.generate()", e);
            throw e;
        } catch (Exception e) {
            getLogger().debug("PhpGenerator.generate()", e);
            throw new IOException(e.toString());
        } finally {
            if (inputSource != null) inputSource.recycle();
            if (parser != null) this.manager.release(parser);
        }
    }
View Full Code Here

                               element,
                               (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element),
                               attrs);
        }

        Source source = null;
        try {
            source = this.sourceResolver.resolve(src);
            source.toSAX(consumer);
        } catch (IOException e) {
            getLogger().error("CIncludeTransformer", e);
            throw new SAXException("CIncludeTransformer could not read resource", e);
        } catch (ProcessingException e){
            getLogger().error("Could not stream input", e);
            throw new SAXException("Exception in CIncludeTransformer",e);
        } finally {
            source.recycle();
        }

        if (!"".equals(element)) {
            super.endElement(ns, element, (!ns.equals("") && !prefix.equals("") ? prefix+":"+element : element));
            if (!ns.equals("")) {
View Full Code Here

                getLogger().debug("Base URI: null");
            else
                getLogger().debug("Base URI: " + current_xmlbase_uri.getSystemId());
        }

        Source url = null;
        String suffix;
        try {
            int index = href.indexOf('#');
            if (index < 0) {
                if(current_xmlbase_uri == null)
                    url = this.resolver.resolve(href);
                else
                    url = this.resolver.resolve(current_xmlbase_uri.getSystemId() + href);
                suffix = "";
            } else {
                if(current_xmlbase_uri == null)
                    url = this.resolver.resolve(href.substring(0,index));
                else
                    url = this.resolver.resolve(current_xmlbase_uri.getSystemId() + href.substring(0,index));
                suffix = href.substring(index+1);
            }
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("URL: "+url+"\nSuffix: "+suffix);
            }
       
            if (parse.equals("text")) {
                getLogger().debug("Parse type is text");
                InputStream input = url.getInputStream();
                Reader reader = new BufferedReader(new InputStreamReader(input));
                int read;
                char ary[] = new char[1024];
                if (reader != null) {
                    while ((read = reader.read(ary)) != -1) {
                        super.characters(ary,0,read);
                    }
                    reader.close();
                }
            } else if (parse.equals("xml")) {
                getLogger().debug("Parse type is XML");
                Parser parser = null;
                try {
                    parser = (Parser)manager.lookup(Parser.ROLE);
       
                    InputSource input = url.getInputSource();
       
                    if (suffix.startsWith("xpointer(") && suffix.endsWith(")")) {
                        String xpath = suffix.substring(9,suffix.length()-1);
                        getLogger().debug("XPath is "+xpath);
                        Document document = parser.parseDocument(input);
                        NodeList list = processor.selectNodeList(document,xpath);
                        DOMStreamer streamer = new DOMStreamer(super.contentHandler,super.lexicalHandler);
                        int length = list.getLength();
                        for (int i=0; i<length; i++) {
                            streamer.stream(list.item(i));
                        }
                    } else {
                        IncludeXMLConsumer xinclude_handler = new IncludeXMLConsumer(super.contentHandler,super.lexicalHandler);
                        xinclude_handler.setLogger(getLogger());
                        parser.setConsumer(xinclude_handler);
                        parser.parse(input);
                    }
                } catch(SAXException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(ProcessingException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(MalformedURLException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(IOException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw e;
                } catch(ComponentException e) {
                    getLogger().error("Error in processXIncludeElement", e);
                    throw new SAXException(e);
                } finally {
                    if(parser != null) this.manager.release(parser);
                }
            }
        } finally {
            if (url != null) url.recycle();
        }
    }
View Full Code Here

            } catch (ParserConfigurationException e) {
                log.error("XTTransformer.setup", e);
                new ProcessingException(e.getMessage(),e);
            }
            loaderprocessor.setParser(saxParser.getParser());
            Source source = resolver.resolve(xsluri);
            try {
                InputSource xslsrc = source.getInputSource();
                loaderprocessor.loadStylesheet(xslsrc);
                if (store != null) store.store(xsluri, loaderprocessor);
            } finally {
                source.recycle();
            }
        }

        // Always clone the processor before using it,
        // Indeed 1 instance per thread is allowed
View Full Code Here

                sourceCache = (Map)this.resolverContext.get(CONTEXT_SOURCE_CACHE_KEY);
            } catch (ContextException ignore) {
                throw new org.apache.velocity.exception.ResourceNotFoundException("Runtime Cocoon source cache not specified in resource loader resolver context.");
            }

            Source source = (Source)sourceCache.get(systemId);
            if (source == null) {
                try {
                    SourceResolver resolver = (SourceResolver)this.resolverContext.get(CONTEXT_RESOLVER_KEY);
                    source = resolver.resolve(systemId);
                } catch (ContextException ex) {
View Full Code Here

        this.manager = manager;
    }
   
    public Source getSource(Environment environment, String location)
      throws ProcessingException, MalformedURLException, IOException {
        Source result = new FileSource(location, this.manager);
        setupLogger(result);
        return result;
    }
View Full Code Here

                return sourceFactory.getSource(environment, location);
            }
        }

        // default implementation
        Source result = new URLSource(this.urlFactory.getURL(location), this.manager);
        if (result instanceof LogEnabled) {
            ((LogEnabled)result).enableLogging(getLogger());
        }
        return result;
    }
View Full Code Here

        }
        if (fragment == null) {
            throw new ProcessingException("insertFragment: fragment is required.");
        }

        Source fileSource = null;
        String systemId = null;
        try {
            fileSource = this.resolver.resolve( fileName );
            systemId = fileSource.getSystemId();
            if (systemId.startsWith("file:") == false) {
                throw new ProcessingException("insertFragment: this is not a file: " + systemId);
            }
        } finally {
            if (fileSource != null) fileSource.recycle();
        }
        if (path.startsWith("/") == true) path = path.substring(1);

        File file = new File(systemId.substring(5));
        DocumentFragment resource = null;
View Full Code Here

            long key = HashUtil.hash("CA(" +
                                     this.rootElement.prefix +
                                     ':' +
                                     this.rootElement.name +
                                     '<' + this.rootElement.namespace + ">)");
            Source current;
            for (int i = 0; i < this.parts.size(); i++) {
                final Part part = (Part)this.parts.get(i);
                current = part.source;
                if (current.getLastModified() == 0) {
                        return 0;
                } else {
                    if (part.element == null) {
                        key += HashUtil.hash("P=" +
                                         part.stripRootElement + ':' +
                                         current.getSystemId() + ';');
                    } else {
                        key += HashUtil.hash("P=" +
                                         part.element.prefix +
                                         ':' +
                                         part.element.name +
                                         '<' + part.element.namespace + ">:" +
                                         part.stripRootElement + ':' +
                                         current.getSystemId() + ';');
                    }
                }
            }
            return key;
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.cocoon.environment.Source

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.