Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


        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.parse(new InputSource(input), this.xmlConsumer);

            // 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();
            this.manager.release(parser);
        }
    }
View Full Code Here


     *      filesystem
     */
    public void generate()
    throws SAXException, ProcessingException {
        String directory = super.source;
        Source inputSource = null;
        try {
            inputSource = this.resolver.resolve(directory);
            String systemId = inputSource.getSystemId();
            if (!systemId.startsWith(FILE)) {
              throw new ResourceNotFoundException(systemId + " does not denote a directory");
            }
            // This relies on systemId being of the form "file://..."
            File directoryFile = new File(new URL(systemId).getFile());
            if (!directoryFile.isDirectory()) {
                throw new ResourceNotFoundException(directory + " is not a directory.");
            }

            this.contentHandler.startDocument();
            this.contentHandler.startPrefixMapping(PREFIX,URI);

            Stack ancestors = getAncestors(directoryFile);
            addPathWithAncestors(directoryFile, ancestors);

            this.contentHandler.endPrefixMapping(PREFIX);
            this.contentHandler.endDocument();
        } catch (IOException ioe) {
            getLogger().warn("Could not read directory " + directory, ioe);
            throw new ResourceNotFoundException("Could not read directory "
                + directory, ioe);
        } finally {
            if (inputSource != null) inputSource.recycle();
        }
    }
View Full Code Here

        synchronized (AbstractComplementaryConfigurableAction.configurations) {
            conf = (ConfigurationHelper) AbstractComplementaryConfigurableAction.configurations.get(descriptor);

            if (reloadable || conf == null) {
                SourceHandler sourceHandler = null;
                Source resource = null;

                try {
                    sourceHandler = (SourceHandler) this.manager.lookup(SourceHandler.ROLE);
                    resource = sourceHandler.getSource(null, descriptor);

                    if (conf == null || conf.lastModified < resource.getLastModified()) {
                        getLogger().debug("(Re)Loading " + descriptor);
                        if (conf == null)
                            conf = new ConfigurationHelper();
     
                        SAXConfigurationHandler builder = new SAXConfigurationHandler();
                        resource.toSAX(builder);
     
                        conf.lastModified = resource.getLastModified();
                        conf.configuration = builder.getConfiguration();
     
                        this.cacheConfiguration(descriptor, conf);
                    } else {
                        getLogger().debug("Using cached configuration for " + descriptor);
                    }
                } catch (Exception e) {
                    getLogger().error("Could not configure Database mapping environment", e);
                    throw new ConfigurationException("Error trying to load configurations for resource: " + (resource == null ? "null" : resource.getSystemId()));
                } finally {
                    if (resource != null) resource.recycle();
                    if (sourceHandler != null) this.manager.release((Component) sourceHandler);
                }
      } else {
    getLogger().debug("Using fixed cached configuration for " + descriptor);
      }
View Full Code Here

            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);
            ByteArrayInputStream input = new ByteArrayInputStream(bytes);

            // pipe the results into the parser
            parser = (Parser)this.manager.lookup(Parser.ROLE);
            parser.setConsumer(this.xmlConsumer);
            parser.parse(new InputSource(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) {
            getLogger().debug("SAXException JspGenerator.generate()", e);
            getLogger().debug("Embedded SAXException JspGenerator.generate()", e.getException());
            throw new ProcessingException("SAXException JspGenerator.generate()",e.getException());
        } catch (IOException e) {
            getLogger().debug("IOException in JspGenerator.generate()", e);
            throw new ProcessingException("IOException JspGenerator.generate()",e);
        } catch (ProcessingException e) {
            throw e;
        } catch (Exception e) {
            getLogger().debug("Exception in JspGenerator.generate()", e);
            throw new ProcessingException("Exception JspGenerator.generate()",e);
        } finally {
            if (src != null) src.recycle();
            if (parser != null) this.manager.release(parser);
            if (engine != null) this.manager.release(engine);
        }
    }
View Full Code Here

public class ResourceExistsAction extends ComposerAction implements ThreadSafe {

    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
        HashMap results = new HashMap();
        String urlstring = parameters.getParameter("url",null);
        Source src = null;
        try {
            src = resolver.resolve(urlstring);
            src.getInputStream();
        } catch (Exception e) {
            getLogger().debug("ResourceExistsAction: exception: ",e);
            return null;
        } finally {
            if (src != null) src.recycle();
        }
        return Collections.unmodifiableMap(results);
    }
View Full Code Here

            throw new ConfigurationException("The form descriptor is not set!");
        }

        synchronized (XSPFormValidatorHelper.configurations) {
            conf = (ConfigurationHelper) XSPFormValidatorHelper.configurations.get(descriptor);
            Source source = null;
            SourceHandler sourceHandler = null;
            try {
                sourceHandler = (SourceHandler) manager.lookup(SourceHandler.ROLE);
                source = sourceHandler.getSource(null, descriptor);
   
                if (conf == null || ( reloadable && conf.lastModified < source.getLastModified())) {
                    logger.debug("XSPFormValidatorHelper.getConfiguration: (Re)Loading " + descriptor);
       
                    if (conf == null)
                    conf = new ConfigurationHelper();
       
                    SAXConfigurationHandler builder = new SAXConfigurationHandler();
                    source.toSAX(builder);
       
                    conf.lastModified = source.getLastModified();
                    conf.configuration = builder.getConfiguration();
       
                    XSPFormValidatorHelper.cacheConfiguration(descriptor, conf);
                } else {
                    logger.debug("XSPFormValidatorHelper.getConfiguration: Using cached configuration for " + descriptor);
                }
            } catch (Exception e) {
                logger.error("XSPFormValidatorHelper.getConfiguration: Could not configure Database mapping environment", e);
                throw new ConfigurationException("Error trying to load configurations for resource: " + source.getSystemId());
            } finally {
                if (source != null) source.recycle();
               if (sourceHandler != null) manager.release((Component) sourceHandler);
            }
        }

        return conf.configuration;
View Full Code Here

            // so we create one without Avalon...
            org.apache.cocoon.serialization.LinkSerializer ls =
                new org.apache.cocoon.serialization.LinkSerializer();
            ls.setOutputStream(this.stream);
            try {
                final Source redirectSource = this.resolve(newURL);
                redirectSource.toSAX(ls);
            } catch (SAXException se) {
                throw new IOException("SAXException: " + se);
            } catch (ProcessingException pe) {
                throw new IOException("ProcessingException: " + pe);
            }
        } else {
            try {
                final Source redirectSource = this.resolve(newURL);
                InputStream is = redirectSource.getInputStream();
                byte[] buffer = new byte[8192];
                int length = -1;

                while ((length = is.read(buffer)) > -1) {
                    this.stream.write(buffer, 0, length);
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

    getLogger().debug("AbstractMarkupLanguage addLogicsheetToList: "
                      + "logicsheetLocation " + logicsheetLocation
                      + ", logicsheet instance " + logicsheet);

    if (logicsheet == null) {
      Source inputSource = resolver.resolve(logicsheetLocation);
      logicsheet = new Logicsheet(inputSource, manager, resolver);
      logicsheetName = logicsheet.getSystemId();

      logicsheetCache.store(CACHE_PREFIX + logicsheetName, logicsheet);
    }
View Full Code Here

                                  String markupLanguageName,
                                  String programmingLanguageName,
                                  SourceResolver resolver)
        throws Exception {

        Source source = resolver.resolve(fileName);
        try {
            // Set filenames
            StringBuffer contextFilename = new StringBuffer(this.rootPackage.replace('.', File.separatorChar));
            contextFilename.append(File.separator);
            String id = source.getSystemId();
            if(id.startsWith(this.contextDir)) {
                // VG: File is located under contextDir, using relative file name
                contextFilename.append(id.substring(this.contextDir.length()));
            } else {
                // VG: File is located outside of contextDir, using systemId
                getLogger().debug("Loading from external source " + id);
                contextFilename.append(id);
            }
            String normalizedName = IOUtils.normalizedFilename(contextFilename.toString());
   
            // Ensure no 2 requests for the same file overlap
            Class program = null;
            CompiledComponent programInstance = null;
   
            // Attempt to load program object from cache
            try {
                programInstance = (CompiledComponent) select(normalizedName);
            } catch (Exception e) {
                getLogger().debug("The instance was not accessible from the internal cache. Proceeding.");
            }
   
            if ((programInstance == null) && this.preload) {
                String className = normalizedName.replace(File.separatorChar, '.');
   
                try {
                    program = this.classManager.loadClass(className);
                    this.addCompiledComponent(newManager, normalizedName, program);
                    programInstance = (CompiledComponent) select(normalizedName);
                } catch (Exception e) {
                    getLogger().debug("The class was not preloaded");
                }
            }
   
            if (programInstance == null) {
          programInstance =
                    this.createResource(
                        newManager, fileName, normalizedName,
                        markupLanguageName, programmingLanguageName, resolver
                    );
            }
   
            if (this.autoReload == false) {
                return programInstance;
            }
   
            /*
             * FIXME: It's the program (not the instance) that must
             * be queried for changes!!!
             */
   
            if (programInstance != null && programInstance.modifiedSince(source.getLastModified())) {
                // Release the component.
                release(programInstance);
   
                // Unload program
                ProgrammingLanguage programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
                programmingLanguage.setLanguageName(programmingLanguageName);
                programmingLanguage.unload(program, normalizedName, this.workDir);
                this.cache.removeGenerator(normalizedName);
   
                // Invalidate previous program/instance pair
                program = null;
                programInstance = null;
            }
   
            if (programInstance == null) {
                if (program == null) {
                    programInstance =
                        this.createResource(
                            newManager, fileName, normalizedName,
                            markupLanguageName, programmingLanguageName,
                            resolver
                        );
                } else
                    programInstance = (CompiledComponent) select(normalizedName);
            }

            return programInstance;
        } finally {
            source.recycle();
        }
    }
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.