Package org.apache.cocoon.components.parser

Examples of org.apache.cocoon.components.parser.Parser


     * @exception Exception
     */
    public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
        throws IOException, ServletException, SAXException, Exception {

        Parser parser = null;
        byte[] bytes = null;

        HttpServletRequest request = httpRequest;
        String inc_servlet_path_was = (String)httpRequest.getAttribute( INC_SERVLET_PATH );
        request.setAttribute( INC_SERVLET_PATH, url );
View Full Code Here


    /**
     * Generate XML data using Velocity template.
     */
    public void generate()
    throws IOException, SAXException, ProcessingException {
        Parser parser = null;
        try
        {
            parser = (Parser)(this.manager.lookup(Parser.ROLE));
            getLogger().debug("Processing File :" + super.source);

            /* first, we init the runtime engine.  Defaults are fine. */
            if(initVelocity == false)
            {
                initVelocity = true;

                String templatePath = ((org.apache.cocoon.environment.http.HttpContext)super.context).getRealPath("/templates");
                getLogger().debug("Templates Directory:" + templatePath);

                Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
                Velocity.init();
            }

            /* lets make a Context and put data into it */
            VelocityContext context = new VelocityContext();

            context.put("name", "Velocity Generator");
            context.put("project", "Cocoon2");
            context.put("request", this.request);
            context.put("response", this.response);
            context.put("context", this.context);

            /* lets render a template */
            StringWriter w = new StringWriter();
            Velocity.mergeTemplate(super.source, context, w );

            InputSource xmlInput =
                    new InputSource(new StringReader(w.toString()));
            parser.setConsumer(this.xmlConsumer);
            parser.parse(xmlInput);
        } catch (IOException e){
            getLogger().warn("VelocityGenerator.generate()", e);
            throw new ResourceNotFoundException("Could not get Resource for VelocityGenerator", e);
        } catch (SAXException e){
            getLogger().error("VelocityGenerator.generate()", e);
View Full Code Here

     * @return a <code>Configuration</code> value
     * @exception ConfigurationException if an error occurs
     * @exception ContextException if an error occurs
     */
    public Configuration configure(ExcaliburComponentManager startupManager) throws ConfigurationException, ContextException {
        Parser p = null;
        Configuration roleConfig = null;

        try {
            this.configurationFile.refresh();
            p = (Parser)startupManager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/cocoon.roles").openStream();
            InputSource is = new InputSource(inputStream);
            is.setSystemId(this.configurationFile.getSystemId());
            p.setContentHandler(b);
            p.parse(is);
            roleConfig = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations", e);
        } finally {
            if (p != null) startupManager.release(p);
        }

        DefaultRoleManager drm = new DefaultRoleManager();
        drm.setLogger(getLogger());
        drm.configure(roleConfig);
        roleConfig = null;

        try {
            p = (Parser)startupManager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputSource is = this.configurationFile.getInputSource();
            p.setContentHandler(b);
            p.parse(is);
            this.configuration = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations",e);
        } finally {
            if (p != null) startupManager.release(p);
        }

        Configuration conf = this.configuration;

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Root configuration: " + conf.getName());
        }
        if (! "cocoon".equals(conf.getName())) {
            throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Configuration version: " + conf.getAttribute("version"));
        }
        if (!Constants.CONF_VERSION.equals(conf.getAttribute("version"))) {
            throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
        }

        String userRoles = conf.getAttribute("user-roles", "");
        if (!"".equals(userRoles)) {
            try {
                p = (Parser)startupManager.lookup(Parser.ROLE);
                SAXConfigurationHandler b = new SAXConfigurationHandler();
                org.apache.cocoon.environment.Context context =
                    (org.apache.cocoon.environment.Context) this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
                URL url = context.getResource(userRoles);
                InputSource is = new InputSource(new BufferedInputStream(url.openStream()));
                is.setSystemId(this.configurationFile.getSystemId());
                p.setContentHandler(b);
                p.parse(is);
                roleConfig = b.getConfiguration();
            } catch (Exception e) {
                getLogger().error("Could not configure Cocoon environment", e);
                throw new ConfigurationException("Error trying to load configurations", e);
            } finally {
View Full Code Here

    throws Exception
  {
    ComponentManager manager = componentManager(sManager);
    Source source = source(ssource);

    Parser parser = (Parser)manager.lookup(Parser.ROLE);
    XMLtoSXML handler = new XMLtoSXML();
    parser.setContentHandler(handler);
    InputSource input = new InputSource(source.getInputStream());
    parser.parse(input);

    SchemeInterpreter interpreters
      = (SchemeInterpreter)manager.lookup(SchemeInterpreter.ROLE);
    Symbol mainFunction = interpreters.getMainFunction();
    Interpreter interp = interpreters.getInterpreter();
View Full Code Here

    }  

    public static void includeInputSource(InputSource source, ComponentManager manager, ContentHandler contentHandler)
        throws RuntimeException {
       
        Parser newParser = null;
       
        try {
            newParser = (Parser) manager.lookup(Parser.ROLE);
            XSPUtil.include(source, contentHandler, newParser);
        } catch (Exception e) {
View Full Code Here

            this.inputSource = null;
        }
    }

    public void generate() throws ProcessingException {
        Parser parser = null;
        try {
            // Figure out what file to open and do so
            getLogger().debug("processing file [" + super.source + "]");
            this.inputSource = this.resolver.resolve(super.source);

            getLogger().debug("file resolved to [" + this.inputSource.getSystemId() + "]");

            // TODO: why doesn't this work?
            // Reader in = src.getCharacterStream();
            Reader in = new java.io.InputStreamReader(this.inputSource.getInputStream());

            // Set up the BSF manager and register relevant helper "beans"
            BSFManager mgr = new BSFManager();

            // add support for additional languages

            if (this.additionalLanguages != null)
            {
                for (int i = 0; i < this.additionalLanguages.length; ++i)
                {
                    getLogger().debug("adding BSF language " + this.additionalLanguages[i].name + " with engine " + this.additionalLanguages[i].engineSrc);

                    mgr.registerScriptingEngine(this.additionalLanguages[i].name,
                                                this.additionalLanguages[i].engineSrc,
                                                this.additionalLanguages[i].extensions);
                }
            }

            StringBuffer output = new StringBuffer();

            mgr.registerBean("resolver", this.resolver);
            mgr.registerBean("source", super.source);
            mgr.registerBean("objectModel", this.objectModel);
            mgr.registerBean("parameters", this.parameters);
            mgr.registerBean("output", output);
            mgr.registerBean("logger", getLogger());

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

            // Execute the script

            mgr.exec(BSFManager.getLangFromFilename(this.inputSource.getSystemId()),
                     this.inputSource.getSystemId(), 0, 0, IOUtils.getStringFromReader(in));

            getLogger().debug("BSFManager execution complete");
            getLogger().debug("output = [" + output.toString() + "]");

            // Extract the XML string from the BSFManager and parse it

            InputSource xmlInput =
                    new InputSource(new StringReader(output.toString()));
            parser = (Parser)(this.manager.lookup(Parser.ROLE));
            parser.setConsumer(this.xmlConsumer);
            parser.parse(xmlInput);
        } catch (ProcessingException e) {
            throw e;
        } catch (FileNotFoundException e) {
            throw new ResourceNotFoundException(
                "Could not load script " + this.inputSource.getSystemId(), e);
View Full Code Here

    /**
     * Generate XML data out of request InputStream.
     */
    public void generate() throws IOException, SAXException, ProcessingException
    {
        Parser parser = null;
        String parameter = parameters.getParameter(StreamGenerator.FORM_NAME, null);
        int len = 0;
    String contentType = null;
        try
        {
            HttpServletRequest request = (HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
            contentType = request.getContentType();
            if (contentType.startsWith("application/x-www-form-urlencoded")) {
                String sXml = request.getParameter(parameter);
                inputSource = new InputSource(new StringReader(sXml));
            } else if (contentType.startsWith("text/plain") ||
                    contentType.startsWith("text/xml") ||
                    contentType.startsWith("application/xml")) {
                len = request.getContentLength();

                if (len > 0) {
                        PostInputStream anStream = new PostInputStream(request.getInputStream(), len);
                        inputSource = new InputSource(anStream);
                } else {
                    throw new IOException("getContentLen() == 0");
                }
            } else {
                throw new IOException("Unexpected getContentType(): " + request.getContentType());
            }

            if (getLogger().isDebugEnabled()) {
                getLogger().debug("processing stream ContentType= " + request.getContentType() + "ContentLen= " + len);
            }
            String charset =  getCharacterEncoding(request, contentType) ;
      if( charset != null)
      {
        this.inputSource.setEncoding(charset);
            }
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.setContentHandler(super.contentHandler);
            parser.setLexicalHandler(super.lexicalHandler);
            parser.parse(this.inputSource);
        } catch (IOException e) {
            getLogger().error("StreamGenerator.generate()", e);
            throw new ResourceNotFoundException("StreamGenerator could not find resource", e);
        } catch (SAXException e) {
            getLogger().error("StreamGenerator.generate()", e);
View Full Code Here

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

        JSPEngine engine = null;
        Parser parser = null;
        Source src = null;
        try {
            src = this.resolver.resolve(this.source);
            String url = src.getSystemId();
            // Guarantee src parameter is a file
            if (!url.startsWith("file:/"))
                throw new IOException("Protocol not supported: " + url);

            url = url.substring(5);
            getLogger().debug("JspGenerator executing JSP:" + url);

            engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
            byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);

            // explicitly specify bytestream encoding
            InputSource input = new InputSource(new ByteArrayInputStream(bytes));
            input.setEncoding("utf-8");

            // pipe the results into the parser
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.setConsumer(this.xmlConsumer);
            parser.parse(input);
        } catch (ServletException e) {
            getLogger().debug("ServletException in JspGenerator.generate()", e);
            getLogger().debug("Embedded ServletException JspGenerator.generate()", e.getRootCause());
            throw new ProcessingException("ServletException in JspGenerator.generate()",e.getRootCause());
        } catch (SAXException e) {
View Full Code Here

        System.err.println("Checking sitemap reload = " + this.checkSitemapReload);
        System.err.println("Reloading sitemap asynchron = " + this.reloadSitemapAsynchron);
        System.err.println("Sitemap check delay = " + checkDelay + " sec");
       
        // Read sitemap roles
        Parser p = null;
        Configuration rolesConfig;
        try {
            p = (Parser)this.manager.lookup(Parser.ROLE);
            SAXConfigurationHandler b = new SAXConfigurationHandler();
            InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/sitemap/sitemap.roles").openStream();
            InputSource is = new InputSource(inputStream);
            is.setSystemId("org/apache/cocoon/sitemap/sitemap.roles");
            p.setContentHandler(b);
            p.parse(is);
            rolesConfig = b.getConfiguration();
        } catch (Exception e) {
            getLogger().error("Could not configure Cocoon environment", e);
            throw new ConfigurationException("Error trying to load configurations", e);
        } finally {
View Full Code Here

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

TOP

Related Classes of org.apache.cocoon.components.parser.Parser

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.