Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Source


                        XMLResourceBundleFactory.ConfigurationKeys.ROOT_DIRECTORY,
                        "location"
                );

        debug( "catalog location:" + catalogueLocation );
        Source source = resolver.resolve( catalogueLocation );
        String systemId = source.getSystemId();
        if ( !systemId.startsWith( FILE ) ) {
            throw new ResourceNotFoundException( systemId + " does not denote a directory" );
        }
        debug( "catalog directory:" + systemId );
        dirConf.setValue( systemId );
View Full Code Here


    protected void processXIncludeElement(String href, String parse) throws SAXException,ProcessingException,IOException {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Processing XInclude element: href="+href+", parse="+parse);
            getLogger().debug("Base URI: " + current_xmlbase_uri.getSystemId());
        }
        Source url;
        String suffix;
        int index = href.indexOf('#');
        if (index < 0) {
            url = this.resolver.resolve(current_xmlbase_uri.getSystemId() + href);
            suffix = "";
        } 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
            {
                getLogger().debug("Looking up " + Parser.ROLE);
                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);
                    try {
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

                               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

   */
  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

            // 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

  public Source readScript(Environment environment, String sourceName)
    throws Exception
  {
    Scriptable thrScope = null;
    Source source = null;

    System.out.println("Reading file " + sourceName);

    try {
      thrScope = enterContext(environment, null);
      source = environment.resolve(sourceName);
      InputStream inputStream = source.getInputStream();
      Reader reader = new BufferedReader(new InputStreamReader(inputStream));
      Context ctx = Context.getCurrentContext();
      ctx.evaluateReader(scope, reader, sourceName, 1, null);
    }
    catch (Exception ex) {
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

        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);
                    if (descriptor.startsWith("file:")) {
                        resource = sourceHandler.getSource((Environment)resolver,((Environment)resolver).getContext(), descriptor.substring(5));
                    } else
                        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();
                    this.manager.release(sourceHandler);
                }
        } else {
        getLogger().debug("Using fixed cached configuration for " + descriptor);
        }
View Full Code Here

        if (this.getLogger().isDebugEnabled()) {
            this.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

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.