Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


            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);

            Source redirectSource = null;
            try {
                redirectSource = this.resolve(newURL);
                redirectSource.toSAX(ls);
            } catch (SAXException se) {
                throw new IOException("SAXException: " + se);
            } catch (ProcessingException pe) {
                throw new IOException("ProcessingException: " + pe);
            } finally {
                if (redirectSource != null) redirectSource.recycle();
            }
        } else {
            Source redirectSource = null;
            try {
                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);
                }
            } catch (SAXException se) {
                throw new IOException("SAXException: " + se);
            } catch (ProcessingException pe) {
                throw new IOException("ProcessingException: " + pe);
            } finally {
                if (redirectSource != null) redirectSource.recycle();
            }
        }
    }
View Full Code Here

            SourceResolver otherResolver = ((IncludeCacheValidity) validity).resolver;

            for(Iterator i = sources.iterator(), j = timeStamps.iterator(); i.hasNext();) {
                String src = ((String)i.next());
                long timeStamp = ((Long)j.next()).longValue();
                Source otherSource = null;
                try {
                    otherSource = otherResolver.resolve(src);
                    if(otherSource.getLastModified() != timeStamp ||
                        timeStamp == 0)
                        return false;
                } catch (Exception e) {
                    return false;
                } finally {
                    if (otherSource != null) otherSource.recycle();
                }
            }
            return true;
        }
        return false;
View Full Code Here

                XMLResourceBundleFactory.ConfigurationKeys.ROOT_DIRECTORY,
                "location"
            );

        debug("catalog location:" + location);
        Source source = resolver.resolve(location);
        try {
            String systemId = source.getSystemId();
            if (!systemId.startsWith(FILE)) {
                throw new ResourceNotFoundException(
                    systemId + " does not denote a directory"
                );
            }
            debug("catalog directory:" + systemId);
            dirConf.setValue(systemId);
            configuration.addChild(dirConf);
        } finally {
            source.recycle();
        }

        // Pass created configuration object to the factory
        factory.configure(configuration);
        debug("configured");
View Full Code Here

    if (this.getLogger().isDebugEnabled()) {
      getLogger().debug("resolve(href = " + href
                        + ", base = " + base + "); resolver = " + resolver);
    }

    Source xslSource = null;
    try {
      if (href.indexOf(":") > 1) {
        xslSource = resolver.resolve(href);
      } else {
        // patch for a null pointer passed as base
        if (base == null)
          throw new IllegalArgumentException("Null pointer passed as base");

        // is the base a file or a real url
        if (!base.startsWith("file:")) {
          int lastPathElementPos = base.lastIndexOf('/');
          if (lastPathElementPos == -1) {
            // this should never occur as the base should
            // always be protocol:/....
            return null; // we can't resolve this
          } else {
            xslSource = resolver.resolve(new StringBuffer(base.substring(0, lastPathElementPos))
                                         .append("/").append(href).toString());
          }
        } else {
          File parent = new File(base.substring(5));
          File parent2 = new File(parent.getParentFile(), href);
          xslSource = resolver.resolve(parent2.toURL().toExternalForm());
        }
      }

      InputSource is = xslSource.getInputSource();
      if (this.getLogger().isDebugEnabled()) {
        getLogger().debug("xslSource = " + xslSource
                          + ", system id = " + is.getSystemId());
      }

      return new StreamSource(is.getByteStream(), is.getSystemId());

    } catch (ResourceNotFoundException rnfe) {
        // to obtain the same behaviour as when the resource is
        // transformed by the XSLT Transformer we should return null here.
        return null;
    } catch (java.net.MalformedURLException mue) {
        return null;
    } catch (IOException ioe) {
        return null;
    } catch (SAXException se) {
        throw new TransformerException(se);
    } catch (ProcessingException pe) {
        throw new TransformerException(pe);
    } finally {
      if (xslSource != null) xslSource.recycle();
    }
  }
View Full Code Here

   */
  public Value parse(Value sManager, Value ssource)
    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();
View Full Code Here

        List includes = (List)templateAndTimeAndIncludes[2];
        if (includes != null) {
            for (int i = includes.size() - 1; i >= 0; i--) {
                // Every include stored as pair of source ID and timestamp
                Object[] pair = (Object[])includes.get(i);
                Source included = resolver.resolve((String)pair[0]);
                if (included.getLastModified() != ((Long)pair[1]).longValue()) {
                    store.remove(id);
                    return null;
                }
            }
        }
View Full Code Here

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("resolve(href = " + href +
                              ", base = " + base + "); resolver = " + resolver);
        }

        Source xslSource = null;
        try {
            if (base == null || href.indexOf(":") > 1) {
                // Null base - href must be an absolute URL
                xslSource = resolver.resolve(href);
            } else if (href.length() == 0) {
                // Empty href resolves to base
                xslSource = resolver.resolve(base);
            } else {
                // is the base a file or a real url
                if (!base.startsWith("file:")) {
                    int lastPathElementPos = base.lastIndexOf('/');
                    if (lastPathElementPos == -1) {
                        // this should never occur as the base should
                        // always be protocol:/....
                        return null; // we can't resolve this
                    } else {
                        xslSource = resolver.resolve(
                            base.substring(0, lastPathElementPos) + "/" + href);
                    }
                } else {
                    File parent = new File(base.substring(5));
                    File parent2 = new File(parent.getParentFile(), href);
                    xslSource = resolver.resolve(parent2.toURL().toExternalForm());
                }
            }

            if (getLogger().isDebugEnabled()) {
                getLogger().debug("xslSource = " + xslSource
                    + ", system id = " + xslSource.getSystemId());
            }

            InputSource is = xslSource.getInputSource();
            if (includes != null) {
                includes.add(new Object[]{xslSource.getSystemId(), new Long(xslSource.getLastModified())});
            }
            return new StreamSource(is.getByteStream(), is.getSystemId());
        } catch (ResourceNotFoundException rnfe) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve " + href
                    + "(base = " + base + "), return null", rnfe);
            }

            // CZ: To obtain the same behaviour as when the resource is
            // transformed by the XSLT Transformer we should return null here.
            return null;
        } catch (MalformedURLException mue) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve " + href
                    + "(base = " + base + "), return null", mue);
            }
           
            return null;
        } catch (IOException ioe) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve " + href
                    + "(base = " + base + "), return null", ioe);
            }

            return null;
        } catch (SAXException se) {
            throw new TransformerException(se);
        } catch (ProcessingException pe) {
            throw new TransformerException(pe);
        } finally {
            if (xslSource != null) xslSource.recycle();
        }
    }
View Full Code Here

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

        final Source source = resolver.resolve(fileName);
        final String id = source.getSystemId();

        ProgrammingLanguage programmingLanguage = null;
        MarkupLanguage markupLanguage = null;
        try {
            // Create file name for the program generated from the provided source.
            final String normalizedName = getNormalizedName(id);

            // Ensure no 2 requests for the same file overlap
            Program program = null;
            CompiledComponent programInstance = null;

            // Attempt to load program object from cache
            try {
                programInstance = (CompiledComponent)this.cache.select(normalizedName);
            } catch (Exception e) {
                getLogger().debug("The instance was not accessible from the internal cache. Proceeding.");
            }

            if (programInstance == null && this.preload) {
                // Preloading: Load program if its source/[object file] is available
                try {
                    markupLanguage =
                            (MarkupLanguage)this.markupSelector.select(markupLanguageName);
                    programmingLanguage =
                            (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
                    programmingLanguage.setLanguageName(programmingLanguageName);
                    program = programmingLanguage.preload(normalizedName,
                            this.workDir, markupLanguage.getEncoding());

                    this.cache.addGenerator(newManager, normalizedName, program);
                    programInstance = (CompiledComponent)this.cache.select(normalizedName);
                } catch (Exception e) {
                    getLogger().debug("The program was not preloaded");
                }
            }

            /*
             * FIXME: It's the program (not the instance) that must
             * be queried for changes!!!
             */
            if (programInstance != null && this.autoReload) {
                // Autoreloading: Unload program if its source is modified
                long lastModified = source.getLastModified();
                if (lastModified == 0 || programInstance.modifiedSince(lastModified)) {
                    // Release the component.
                    release(programInstance);
                    programInstance = null;

                    // Unload program
                    if (programmingLanguage == null) {
                        programmingLanguage =
                                (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
                        programmingLanguage.setLanguageName(programmingLanguageName);
                    }

                    programmingLanguage.unload(program, normalizedName, this.workDir);
                    this.cache.removeGenerator(normalizedName);
                    program = null;
                }
            }

            // Not preloaded or just unloaded: (re)create.
            if (programInstance == null) {
                if (programmingLanguage == null) {
                    programmingLanguage =
                            (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
                    programmingLanguage.setLanguageName(programmingLanguageName);
                }
                if (markupLanguage == null) {
                    markupLanguage =
                            (MarkupLanguage)this.markupSelector.select(markupLanguageName);
                }
                programInstance = this.createResource(newManager,
                        source, normalizedName, markupLanguage,
                        programmingLanguage, resolver);
            }

            // Recompose with the new manager if needed
            if (programInstance instanceof Recomposable) {
                ((Recomposable)programInstance).recompose(newManager);
            }
            return programInstance;
        } finally {
            source.recycle();
            this.markupSelector.release(markupLanguage);
            this.languageSelector.release(programmingLanguage);
        }
    }
View Full Code Here

                XMLResourceBundleFactory.ConfigurationKeys.ROOT_DIRECTORY,
                "location"
            );

        debug("catalog location:" + location);
        Source source = resolver.resolve(location);
        try {
            String systemId = source.getSystemId();
            if (!systemId.startsWith(FILE)) {
                throw new ResourceNotFoundException(
                    systemId + " does not denote a directory"
                );
            }
            debug("catalog directory:" + systemId);
            dirConf.setValue(systemId);
            configuration.addChild(dirConf);
        } finally {
            source.recycle();
        }

        // Pass created configuration object to the factory
        factory.configure(configuration);
        debug("configured");
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.