giacomo 01/08/25 12:40:33
Modified: src/org/apache/cocoon Cocoon.java
src/org/apache/cocoon/acting
AbstractComplementaryConfigurableAction.java
src/org/apache/cocoon/components/language/markup
AbstractMarkupLanguage.java Logicsheet.java
NamedLogicsheet.java
src/org/apache/cocoon/components/language/markup/xsp
XSPFormValidatorHelper.java
src/org/apache/cocoon/components/source SitemapSource.java
URLSource.java
src/org/apache/cocoon/components/xslt XSLTProcessor.java
XSLTProcessorImpl.java
src/org/apache/cocoon/environment Source.java
src/org/apache/cocoon/generation DirectoryGenerator.java
FileGenerator.java
src/org/apache/cocoon/sitemap ContentAggregator.java
Handler.java
src/org/apache/cocoon/transformation
CIncludeTransformer.java
CachingCIncludeTransformer.java
I18nTransformer.java TraxTransformer.java
webapp cocoon.xconf
Log:
Added patch for 'Major changes in Source interface and others'
Submitted by: Ovidiu Predescu <[EMAIL PROTECTED]>
Revision Changes Path
1.21 +3 -2 xml-cocoon2/src/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Cocoon.java 2001/08/22 03:51:05 1.20
+++ Cocoon.java 2001/08/25 19:40:31 1.21
@@ -33,6 +33,7 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.ModifiableSource;
import org.apache.cocoon.sitemap.AbstractSitemap;
import org.apache.cocoon.sitemap.Manager;
import org.apache.cocoon.util.ClassUtils;
@@ -51,14 +52,14 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
(Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.20 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.21 $ $Date: 2001/08/25 19:40:31 $
*/
public class Cocoon extends AbstractLoggable implements ThreadSafe,
Component, Initializable, Disposable, Modifiable, Processor, Contextualizable {
/** The application context */
private Context context;
/** The configuration file */
- private Source configurationFile;
+ private ModifiableSource configurationFile;
/** The sitemap file */
private String sitemapFileName;
1.10 +2 -2
xml-cocoon2/src/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java
Index: AbstractComplementaryConfigurableAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractComplementaryConfigurableAction.java 2001/08/22 03:51:05
1.9
+++ AbstractComplementaryConfigurableAction.java 2001/08/25 19:40:31
1.10
@@ -26,7 +26,7 @@
* effective. The name of the root configuration element is irrelevant.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.9 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.10 $ $Date: 2001/08/25 19:40:31 $
*/
public abstract class AbstractComplementaryConfigurableAction extends
ConfigurableComposerAction {
private static Map configurations = new HashMap();
@@ -76,7 +76,7 @@
conf = new ConfigurationHelper();
SAXConfigurationHandler builder = new
SAXConfigurationHandler();
- resource.stream(builder);
+ resource.toSAX(builder);
conf.lastModified = resource.getLastModified();
conf.configuration = builder.getConfiguration();
1.9 +204 -260
xml-cocoon2/src/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java
Index: AbstractMarkupLanguage.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractMarkupLanguage.java 2001/08/22 03:51:05 1.8
+++ AbstractMarkupLanguage.java 2001/08/25 19:40:31 1.9
@@ -22,6 +22,7 @@
import org.apache.cocoon.components.store.Store;
import org.apache.cocoon.components.url.URLFactory;
import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.components.source.URLSource;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.util.IOUtils;
import org.xml.sax.Attributes;
@@ -47,12 +48,20 @@
/**
* Base implementation of <code>MarkupLanguage</code>. This class uses
- * logicsheets as the only means of code generation. Code generation should
be decoupled from this context!!!
+ * logicsheets as the only means of code generation. Code generation
+ * should be decoupled from this context!!!
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
- * @version CVS $Revision: 1.8 $ $Date: 2001/08/22 03:51:05 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @version CVS $Revision: 1.9 $ $Date: 2001/08/25 19:40:31 $
*/
-public abstract class AbstractMarkupLanguage extends AbstractLoggable
implements MarkupLanguage, Composable, Configurable {
+public abstract class AbstractMarkupLanguage extends AbstractLoggable
+ implements MarkupLanguage, Composable, Configurable
+{
+ /** The 'file' URL protocol. */
+ private static final String FILE = "file:";
+
/** The supported language table */
protected Hashtable languages;
@@ -68,6 +77,11 @@
/** The component manager */
protected ComponentManager manager;
+ /**
+ * The URL factory used to resolve URIs.
+ */
+ URLFactory urlFactory;
+
/**
* Set the global component manager.
* @param manager The sitemap-specified component manager
@@ -77,6 +91,9 @@
// Initialize logicsheet cache
this.logicsheetCache = (Store) manager.lookup(Store.ROLE);
+
+ // Initialize the URL factory
+ urlFactory = (URLFactory)this.manager.lookup(URLFactory.ROLE);
}
/** The default constructor. */
@@ -94,139 +111,131 @@
this.uri = params.getParameter("uri", null);
this.prefix = params.getParameter("prefix", null);
}
-
- /**
- * Process additional configuration. Load supported programming language
definitions
- *
- * @param conf The language configuration
- * @exception ConfigurationException If an error occurs loading
logichseets
- */
- public void configure(Configuration conf) throws ConfigurationException {
- try {
- // Set up each target-language
- Configuration[] l = conf.getChildren("target-language");
- for (int i = 0; i < l.length; i++) {
- LanguageDescriptor language = new LanguageDescriptor();
- language.setName(l[i].getAttribute("name"));
- Parameters lcp = Parameters.fromConfiguration(l[i]);
-
- // Create & Store the core logicsheet
- CachedURL entry = createLogicsheet(lcp, false);
- entry.setLogger(getLogger());
-
- String logicsheetName = entry.getURL().toExternalForm();
-
- this.logicsheetCache.store(logicsheetName, entry);
- language.setLogicsheet(logicsheetName);
-
- // Set up each built-in logicsheet
- Configuration[] n = l[i].getChildren("builtin-logicsheet");
- for (int j = 0; j < n.length; j++) {
- Parameters ncp = Parameters.fromConfiguration(n[j]);
-
- // Create & Store the named logicsheets
- CachedURL namedEntry = createLogicsheet(ncp, true);
-
- String namedLogicsheetName =
namedEntry.getURL().toExternalForm();
- String namedLogicSheetPrefix = ((NamedLogicsheet)
namedEntry.getLogicsheet()).getPrefix();
-
- this.logicsheetCache.store(namedLogicsheetName,
namedEntry);
-
- // FIXME: Logicsheets should be found by uri--not prefix.
- language.addNamedLogicsheet(namedLogicSheetPrefix,
namedLogicsheetName);
- }
- this.languages.put(language.getName(), language);
- }
- } catch (Exception e) {
- getLogger().warn("Configuration Error: " + e.getMessage(), e);
- throw new ConfigurationException("AbstractMarkupLanguage: " +
e.getMessage(), e);
- }
- }
-
- /**
- * Abstract out the Logicsheet creation. Handles both Named and regular
logicsheets.
- */
- private CachedURL createLogicsheet(Parameters params, boolean named)
throws Exception {
- String logicsheetLocation;
- URL logicsheetURL;
- Logicsheet logicsheet;
- CachedURL entry = null;
-
- if (named) {
- logicsheetLocation = params.getParameter("href", null);
-
- NamedLogicsheet namedLogicsheet = new NamedLogicsheet();
- namedLogicsheet.setLogger(getLogger());
- namedLogicsheet.setPrefix(params.getParameter("prefix", null));
- namedLogicsheet.setUri(params.getParameter("href", null));
-
- logicsheet = namedLogicsheet;
- } else {
- logicsheetLocation = params.getParameter("core-logicsheet",
null);
- logicsheet = new Logicsheet();
- logicsheet.setLogger(getLogger());
- }
-
- URLFactory urlFactory = null;
- try {
- urlFactory = (URLFactory) this.manager.lookup(URLFactory.ROLE);
- logicsheetURL = urlFactory.getURL(logicsheetLocation);
- } catch (Exception e){
- getLogger().warn("URL Error: " + e.getMessage(), e);
- throw e;
- } finally {
- if (urlFactory!=null) this.manager.release((Component)
urlFactory);
- }
-
- InputSource is = new InputSource(logicsheetURL.openStream());
- is.setSystemId(logicsheetURL.toString());
- logicsheet.setInputSource(is);
-
- entry = new CachedURL(logicsheetURL, logicsheet);
- entry.setLogger(getLogger());
-
- return entry;
- }
-
- /**
- * Return the source document's encoding. This can be <code>null</code>
for
- * the platform's default encoding. The default implementation returns
- * <code>null, but derived classes may override it if encoding applies to
- * their concrete languages. FIXME: There should be a way to get the
- * XML document's encoding as seen by the parser; unfortunately, this
- * information is not returned by current DOM or SAX parsers...
- * @return The document-specified encoding
- */
- public String getEncoding() {
- return null;
- }
- /**
- * Returns a filter that chains on the fly the requested transformers
for source
- * code generation. This method scans the input SAX events for built-in
logicsheet
- * declared as namespace attribute on the root element. Derived class
should overide this method and the public inner class in
- * order to add more specif action and to build a more specific
transformer chain.
- * @param logicsheetMarkupGenerator the logicsheet markup generator
- * @param resolver the entity resolver
- * @return XMLFilter the filter that build on the fly the transformer
chain
- */
- protected TransformerChainBuilderFilter getTranformerChainBuilder
- (LogicsheetCodeGenerator logicsheetMarkupGenerator, SourceResolver
resolver) {
- return new
TransformerChainBuilderFilter(logicsheetMarkupGenerator, resolver);
- }
-
- /**
- * Prepare the input source for logicsheet processing and code
generation with a preprocess filter.
- * The return <code>XMLFilter</code> object is the first filter on the
transformer chain.
- * The default implementation does nothing by returning a identity
filter, but
- * derived classes should (at least) use the passed programming language
to quote <code>Strings</code>
- * @param filename The source filename
- * @param language The target programming language
- * @return The preprocess filter
- */
- protected XMLFilter getPreprocessFilter(String filename,
ProgrammingLanguage language) {
- return new XMLFilterImpl();
- }
+ /**
+ * Process additional configuration. Load supported programming
+ * language definitions
+ *
+ * @param conf The language configuration
+ * @exception ConfigurationException If an error occurs loading logichseets
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ try {
+ // Set up each target-language
+ Configuration[] l = conf.getChildren("target-language");
+ for (int i = 0; i < l.length; i++) {
+ LanguageDescriptor language = new LanguageDescriptor();
+ language.setName(l[i].getAttribute("name"));
+ Parameters lcp = Parameters.fromConfiguration(l[i]);
+
+ // Create & Store the core logicsheet
+ Logicsheet logicsheet = createLogicsheet(lcp, false);
+ String logicsheetName = logicsheet.getSystemId();
+ logicsheetCache.store(logicsheetName, logicsheet);
+ language.setLogicsheet(logicsheetName);
+
+ // Set up each built-in logicsheet
+ Configuration[] n = l[i].getChildren("builtin-logicsheet");
+ for (int j = 0; j < n.length; j++) {
+ Parameters ncp = Parameters.fromConfiguration(n[j]);
+
+ // Create & Store the named logicsheets
+ NamedLogicsheet namedLogicsheet
+ = (NamedLogicsheet)createLogicsheet(ncp, true);
+ logicsheetName = namedLogicsheet.getSystemId();
+ String logicsheetPrefix = namedLogicsheet.getPrefix();
+ logicsheetCache.store(logicsheetName, namedLogicsheet);
+
+ // FIXME: Logicsheets should be found by uri--not prefix.
+ language.addNamedLogicsheet(logicsheetPrefix, logicsheetName);
+ }
+ this.languages.put(language.getName(), language);
+ }
+ } catch (Exception e) {
+ getLogger().warn("Configuration Error: " + e.getMessage(), e);
+ throw new ConfigurationException("AbstractMarkupLanguage: "
+ + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Abstract out the Logicsheet creation. Handles both Named and regular
logicsheets.
+ */
+ private Logicsheet createLogicsheet(Parameters params, boolean named)
+ throws Exception
+ {
+ String logicsheetLocation;
+ Logicsheet logicsheet;
+
+ if (named) {
+ logicsheetLocation = params.getParameter("href", null);
+
+ NamedLogicsheet namedLogicsheet = new
NamedLogicsheet(logicsheetLocation,
+ urlFactory,
+ manager);
+ namedLogicsheet.setLogger(getLogger());
+ namedLogicsheet.setPrefix(params.getParameter("prefix", null));
+ logicsheet = namedLogicsheet;
+ } else {
+ logicsheetLocation = params.getParameter("core-logicsheet", null);
+ logicsheet = new Logicsheet(logicsheetLocation, urlFactory, manager);
+ logicsheet.setLogger(getLogger());
+ }
+
+ return logicsheet;
+ }
+
+ /**
+ * Return the source document's encoding. This can be <code>null</code> for
+ * the platform's default encoding. The default implementation returns
+ * <code>null, but derived classes may override it if encoding applies to
+ * their concrete languages. FIXME: There should be a way to get the
+ * XML document's encoding as seen by the parser; unfortunately, this
+ * information is not returned by current DOM or SAX parsers...
+ * @return The document-specified encoding
+ */
+ public String getEncoding() {
+ return null;
+ }
+
+ /**
+ * Returns a filter that chains on the fly the requested
+ * transformers for source code generation. This method scans the
+ * input SAX events for built-in logicsheet declared as namespace
+ * attribute on the root element. Derived class should overide
+ * this method and the public inner class in order to add more
+ * specif action and to build a more specific transformer chain.
+ *
+ * @param logicsheetMarkupGenerator the logicsheet markup generator
+ * @param resolver the entity resolver
+ * @return XMLFilter the filter that build on the fly the transformer chain
+ */
+ protected TransformerChainBuilderFilter getTranformerChainBuilder
+ (LogicsheetCodeGenerator logicsheetMarkupGenerator,
+ SourceResolver resolver)
+ {
+ return new TransformerChainBuilderFilter(logicsheetMarkupGenerator,
+ resolver);
+ }
+
+ /**
+ * Prepare the input source for logicsheet processing and code
+ * generation with a preprocess filter. The return
+ * <code>XMLFilter</code> object is the first filter on the
+ * transformer chain. The default implementation does nothing by
+ * returning a identity filter, but derived classes should (at
+ * least) use the passed programming language to quote
+ * <code>Strings</code>
+ *
+ * @param filename The source filename
+ * @param language The target programming language
+ * @return The preprocess filter
+ */
+ protected XMLFilter getPreprocessFilter(String filename,
+ ProgrammingLanguage language)
+ {
+ return new XMLFilterImpl();
+ }
/**
* Add a dependency on an external file to the document for inclusion in
@@ -239,9 +248,16 @@
/**
* Generate source code from the input document for the target
- * <code>ProgrammingLanguage</code>. After preprocessing the input
document,
- * this method applies logicsheets in the following order: <ul>
<li>User-defined logicsheets</li>
- * <li>Namespace-mapped logicsheets</li> <li>Language-specific
logicsheet</li> </ul>
+ * <code>ProgrammingLanguage</code>. After preprocessing the input
+ * document, this method applies logicsheets in the following
+ * order:
+ *
+ * <ul>
+ * <li>User-defined logicsheets</li>
+ * <li>Namespace-mapped logicsheets</li>
+ * <li>Language-specific logicsheet</li>
+ * </ul>
+ *
* @param input The input source
* @param filename The input document's original filename
* @param programmingLanguage The target programming language
@@ -310,55 +326,58 @@
* @exception IOException IO Error
* @exception SAXException Logicsheet parse error
*/
- protected void addLogicsheetToList(LanguageDescriptor language, String
logicsheetLocation, SourceResolver resolver)
- throws MalformedURLException, IOException, SAXException,
ProcessingException
- {
- Source inputSource = resolver.resolve(logicsheetLocation);
- try {
- URL url = new URL(inputSource.getSystemId());
- getLogger().debug("Logicsheet Used:" + url.toExternalForm());
-
- String logicsheetName = inputSource.getSystemId();
- CachedURL entry =
(CachedURL)this.logicsheetCache.get(logicsheetName);
- Logicsheet logicsheet = null;
- if (entry == null) {
- logicsheet = new Logicsheet();
- logicsheet.setLogger(getLogger());
- logicsheet.setInputSource(inputSource.getInputSource());
- entry = new CachedURL(url, logicsheet);
- entry.setLogger(getLogger());
- this.logicsheetCache.store(logicsheetName, entry);
- }
- logicsheet = entry.getLogicsheet();
- if (entry.hasChanged()) {
- logicsheet.setInputSource(inputSource.getInputSource());
- }
- if (entry.isFile()) {
- this.addDependency(IOUtils.getFullFilename(entry.getFile()));
- }
-
- logicSheetList.add(logicsheet);
-
- Map namespaces = logicsheet.getNamespaces();
- if(!logicsheetLocation.equals(language.getLogicsheet()))
- {
- if(namespaces != null && namespaces.size()>0) {
- Iterator iter = namespaces.keySet().iterator();
- while(iter.hasNext()) {
- String namespace = (String) iter.next();
- String namedLogicsheetName =
language.getNamedLogicsheet(namespace);
- if(namedLogicsheetName!= null &&
!logicsheetLocation.equals(namedLogicsheetName)) {
- getLogger().debug("Adding embedded logic sheet
for " + namespace + ":" + namedLogicsheetName);
- // Add embedded logic sheets too.
- addLogicsheetToList(language,
namedLogicsheetName, resolver);
- }
- }
- }
- }
- } finally {
- inputSource.recycle();
+ protected void addLogicsheetToList(LanguageDescriptor language,
+ String logicsheetLocation,
+ SourceResolver resolver)
+ throws MalformedURLException, IOException, SAXException,
ProcessingException
+ {
+ Logicsheet logicsheet =
(Logicsheet)logicsheetCache.get(logicsheetLocation);
+ String logicsheetName;
+
+ getLogger().debug("AbstractMarkupLanguage addLogicsheetToList: "
+ + "logicsheetLocation " + logicsheetLocation
+ + ", logicsheet instance " + logicsheet);
+
+ if (logicsheet == null) {
+ Source inputSource = resolver.resolve(logicsheetLocation);
+ logicsheet = new Logicsheet(inputSource, manager);
+ logicsheetName = logicsheet.getSystemId();
+
+ logicsheetCache.store(logicsheetName, logicsheet);
+ }
+ else
+ logicsheetName = logicsheet.getSystemId();
+
+ getLogger().debug("AbstractMarkupLanguage addLogicsheetToList: "
+ + "logicsheetName " + logicsheetName);
+
+ if (logicsheetName.startsWith(FILE)) {
+ String filename = logicsheetName.substring(FILE.length());
+ addDependency(filename);
+ getLogger().debug("AbstractMarkupLanguage addLogicsheetToList: "
+ + "adding dependency on file " + filename);
+ }
+
+ logicSheetList.add(logicsheet);
+
+ Map namespaces = logicsheet.getNamespaces();
+ if(!logicsheetLocation.equals(language.getLogicsheet())) {
+ if(namespaces != null && namespaces.size()>0) {
+ Iterator iter = namespaces.keySet().iterator();
+ while(iter.hasNext()) {
+ String namespace = (String) iter.next();
+ String namedLogicsheetName =
language.getNamedLogicsheet(namespace);
+ if(namedLogicsheetName!= null
+ && !logicsheetLocation.equals(namedLogicsheetName)) {
+ getLogger().debug("Adding embedded logic sheet for "
+ + namespace + ":" + namedLogicsheetName);
+ // Add embedded logic sheets too.
+ addLogicsheetToList(language, namedLogicsheetName, resolver);
+ }
}
+ }
}
+ }
//
// Inner classes
//
@@ -427,81 +446,6 @@
*/
protected String getNamedLogicsheet(String prefix) {
return (String)this.namedLogicsheets.get(prefix);
- }
- }
-
-
- /** This class holds a cached URL entry associated with a logicsheet */
- protected class CachedURL extends AbstractLoggable {
- /** The logicsheet URL */
- protected URL url;
-
- /**
- * The logicsheet's <code>File</code> if it's actually a file.
- * This is used to provide last modification information not
otherwise available for URL's in Java :-(
- */
- protected File file;
-
- /** The cached logicsheet */
- protected Logicsheet logicsheet;
-
- /** The las time this logicsheet was changed/loaded */
- protected long lastModified;
-
- /** The constructor. */
- protected CachedURL(URL url, Logicsheet logicsheet) throws
IOException {
- this.url = url;
- this.logicsheet = logicsheet;
- if (this.isFile()) {
- this.file = new File(url.getFile());
- }
- this.lastModified = (
- new Date()).getTime();
- }
-
- /**
- * Return this entry's URL
- * @return The cached logicsheet's URL
- */
- protected URL getURL() {
- return this.url;
- }
-
- protected boolean isFile() {
- return this.url.getProtocol().equals("file");
- }
-
- /**
- * Return this entry's <code>File</code>
- * @return The cached logicsheet's <code>File</code>
- */
- protected File getFile() {
- return this.file;
- }
-
- /**
- * Return this entry's cached logicsheet
- * @return The cached logicsheet
- */
- protected Logicsheet getLogicsheet() {
- return this.logicsheet;
- }
-
- /**
- * Assert whether this entry's logicsheet should be reloaded
- * @return Whether the cached logicsheet has changed
- */
- protected boolean hasChanged() {
- boolean hasChanged = false;
- if (this.file == null) {
- return false;
- }
- try {
- hasChanged = this.lastModified < this.file.lastModified();
- } catch (SecurityException se) {
- super.getLogger().warn("SecurityException", se);
- }
- return hasChanged;
}
}
1.5 +158 -119
xml-cocoon2/src/org/apache/cocoon/components/language/markup/Logicsheet.java
Index: Logicsheet.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/Logicsheet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Logicsheet.java 2001/08/20 13:55:11 1.4
+++ Logicsheet.java 2001/08/25 19:40:32 1.5
@@ -9,7 +9,15 @@
package org.apache.cocoon.components.language.markup;
import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.component.ComponentException;
+
+import org.apache.cocoon.environment.Source;
import org.apache.cocoon.util.TraxErrorHandler;
+import org.apache.cocoon.components.url.URLFactory;
+import org.apache.cocoon.components.xslt.XSLTProcessor;
+import org.apache.cocoon.components.source.URLSource;
+
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -25,149 +33,180 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
/**
* A code-generation logicsheet. This class is actually a wrapper for
- * a "standard" XSLT stylesheet stored as <code>trax.Templates</code> object.
- * Though this will change shortly: a new markup language will be used
- * for logicsheet authoring; logicsheets written in this language will be
- * transformed into an equivalent XSLT stylesheet anyway... This class
should probably be based on an interface...
+ * a "standard" XSLT stylesheet stored as <code>trax.Templates</code>
+ * object. Though this will change shortly: a new markup language
+ * will be used for logicsheet authoring; logicsheets written in this
+ * language will be transformed into an equivalent XSLT stylesheet
+ * anyway... This class should probably be based on an interface...
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/08/20 13:55:11 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @version CVS $Revision: 1.5 $ $Date: 2001/08/25 19:40:32 $
*/
-public class Logicsheet extends AbstractLoggable {
- /** The trax TransformerFactory */
- protected SAXTransformerFactory tfactory;
-
- /** The trax templates */
- protected Templates templates;
-
- /**
- * the template namespace's list
- */
- protected Map namespaces = new HashMap();
-
+public class Logicsheet extends AbstractLoggable
+{
+ /**
+ * The Source object for this logicsheet.
+ */
+ Source source;
+
+ /**
+ * the template namespace's list
+ */
+ protected Map namespaces = new HashMap();
+
+ /**
+ * The [EMAIL PROTECTED] org.apache.cocoon.components.xslt.XSLTProcessor}
component.
+ */
+ XSLTProcessor xsltProcessor;
+
+ /**
+ * The ComponentManager of this instance.
+ */
+ ComponentManager manager;
+
+ public Logicsheet(Source source, ComponentManager manager)
+ {
+ this.source = source;
+ this.manager = manager;
+ try {
+ xsltProcessor = (XSLTProcessor)manager.lookup(XSLTProcessor.ROLE);
+ }
+ catch (ComponentException e) {
+ getLogger().error("Cannot obtain XSLTProcessor component: " + e);
+ }
+ }
+
+ /**
+ * Creates a new <code>Logicsheet</code> instance given an URL to
+ * containing the logicsheet, the [EMAIL PROTECTED]
+ * org.apache.cocoon.components.url.URLFactory}, and a
+ * <code>ComponentManager</code>.
+ *
+ * @param url an <code>URL</code> value
+ * @param urlFactory an <code>URLFactory</code> value
+ * @exception MalformedURLException if an error occurs
+ * @exception IOException if an error occurs
+ */
+ public Logicsheet(URL url, URLFactory urlFactory, ComponentManager manager)
+ throws MalformedURLException, IOException
+ {
+ this(url.toString(), urlFactory, manager);
+ }
+
+ public Logicsheet(String systemId, URLFactory urlFactory,
+ ComponentManager manager)
+ throws MalformedURLException, IOException
+ {
+ this.manager = manager;
+ URL url = urlFactory.getURL(systemId);
+ this.source = new URLSource(url, manager);
+ try {
+ xsltProcessor = (XSLTProcessor)manager.lookup(XSLTProcessor.ROLE);
+ }
+ catch (ComponentException e) {
+ getLogger().error("Cannot obtain XSLTProcessor component: " + e);
+ }
+ }
+
+ public String getSystemId()
+ {
+ return source.getSystemId();
+ }
+
+ /**
+ * This will return the list of namespaces in this logicsheet.
+ */
+ public Map getNamespaces()
+ {
+ // Force the parsing of the Source or, if nothing changed,
+ // return the old content of namespaces.
+ getTransformerHandler();
+ return namespaces;
+ }
+
+ /**
+ * Obtain the TransformerHandler object that will perform the
+ * transformation associated with this logicsheet.
+ *
+ * @return a <code>TransformerHandler</code> value
+ */
+ public TransformerHandler getTransformerHandler()
+ {
+ try {
+ // If the Source object is not changed, the
+ // getTransformerHandler() of XSLTProcessor will simply return
+ // the old template object. If the Source is unchanged, the
+ // namespaces are not modified either.
+ XMLFilter saveNSFilter = new SaveNamespaceFilter(namespaces);
+ return xsltProcessor.getTransformerHandler(source, saveNSFilter);
+ } catch (Exception e) {
+ getLogger().error("Logicsheet.getTransformerHandler: Exception ", e);
+ }
+ return null;
+ }
- /**
- * This will return the list of namespaces in this logicsheet.
+ /**
+ * This filter listen for source SAX events, and register the declared
+ * namespaces into a <code>Map</code> object.
+ *
+ */
+ protected class SaveNamespaceFilter extends XMLFilterImpl
+ {
+ private Map originalNamepaces;
+
+ /**
+ * The contructor needs an initialized <code>Map</code> object where it
+ * can store the found namespace declarations.
+ * @param originalNamepaces a initialized <code>Map</code> instance.
*/
- public Map getNamespaces()
+ public SaveNamespaceFilter(Map originalNamepaces)
{
- return namespaces;
+ this.originalNamepaces = originalNamepaces;
}
/**
- * Helper for TransformerFactory.
+ * @param reader the parent reader
+ * @see XMLFilter
*/
- private SAXTransformerFactory getTransformerFactory()
+ public void setParent(XMLReader reader)
{
- if(tfactory == null) {
- tfactory = (SAXTransformerFactory)
TransformerFactory.newInstance();
- tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
- }
- return tfactory;
+ super.setParent(reader);
+ reader.setContentHandler(this);
}
/**
- * The constructor. It does preserve the namespace from the stylesheet.
- * @param inputSource The stylesheet's input source
- * @exception IOException IOError processing input source
- * @exception SAXException Input source parse error
+ * @see ContentHandler
*/
- public void setInputSource(InputSource inputSource) throws SAXException,
IOException {
- try {
- // Create a Templates ContentHandler to handle parsing of the
- // stylesheet.
- javax.xml.transform.sax.TemplatesHandler templatesHandler =
-
getTransformerFactory().newTemplatesHandler();
-
- // Create an XMLReader and set its ContentHandler.
- org.xml.sax.XMLReader reader =
-
org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
-
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
-
- // Create a XMLFilter that save the namespace hold in the
stylesheet
- XMLFilter saveNSFilter = new SaveNamespaceFilter(namespaces);
- saveNSFilter.setParent(reader);
-
- saveNSFilter.setContentHandler(templatesHandler);
- //reader.setContentHandler(templatesHandler);
-
- // Parse the stylesheet.
- reader.parse(inputSource);
-
- // Get the Templates object (generated during the parsing of the
stylesheet)
- // from the TemplatesHandler.
- templates = templatesHandler.getTemplates();
- } catch (TransformerConfigurationException e) {
- getLogger().error("Logicsheet.setInputSource", e);
- }
+ public void startDocument ()
+ throws SAXException
+ {
+ super.startDocument();
}
/**
- * Get the TransformerHandler that performs the stylesheet
transformation.
- * @return The TransformerHandler for the associated stylesheet.
+ * @see ContentHandler
*/
- public TransformerHandler getTransformerHandler() {
- try {
- TransformerHandler handler =
getTransformerFactory().newTransformerHandler(templates);
- handler.getTransformer().setErrorListener(new
TraxErrorHandler(getLogger()));
- return handler;
- } catch (TransformerConfigurationException e) {
-
getLogger().error("Logicsheet.getTransformerHandler:TransformerConfigurationException",
e);
- } catch (Exception e) {
- getLogger().error("Logicsheet.getTransformerHandler:Exception",
e);
- }
- return null;
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException
+ {
+ originalNamepaces.put(prefix,uri);
+ super.startPrefixMapping(prefix, uri);
}
- /**
- * This filter listen for source SAX events, and register the declared
- * namespaces into a <code>Map</code> object.
- *
- */
- protected class SaveNamespaceFilter extends XMLFilterImpl {
-
- private Map originalNamepaces;
-
- /**
- * The contructor needs an initialized <code>Map</code> object where
it
- * can store the found namespace declarations.
- * @param originalNamepaces a initialized <code>Map</code> instance.
- */
- public SaveNamespaceFilter(Map originalNamepaces) {
- this.originalNamepaces = originalNamepaces;
- }
-
- /**
- * @param reader the parent reader
- * @see XMLFilter
- */
- public void setParent(XMLReader reader) {
- super.setParent(reader);
- reader.setContentHandler(this);
- }
-
- /**
- * @see ContentHandler
- */
- public void startDocument () throws SAXException {
- super.startDocument();
- }
-
- /**
- * @see ContentHandler
- */
- public void startPrefixMapping(String prefix, String uri) throws
SAXException {
- originalNamepaces.put(prefix,uri);
- super.startPrefixMapping(prefix, uri);
- }
-
- public void startElement (String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException
{
- super.startElement(namespaceURI, localName, qName, atts);
- }
+ public void startElement (String namespaceURI, String localName,
+ String qName, Attributes atts)
+ throws SAXException
+ {
+ super.startElement(namespaceURI, localName, qName, atts);
}
+ }
}
1.3 +13 -19
xml-cocoon2/src/org/apache/cocoon/components/language/markup/NamedLogicsheet.java
Index: NamedLogicsheet.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/NamedLogicsheet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NamedLogicsheet.java 2001/08/20 13:55:11 1.2
+++ NamedLogicsheet.java 2001/08/25 19:40:32 1.3
@@ -7,7 +7,11 @@
*****************************************************************************/
package org.apache.cocoon.components.language.markup;
+import java.net.MalformedURLException;
+import java.io.IOException;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.cocoon.components.url.URLFactory;
/**
* An extension to <code>Logicsheet</code> that is associated with a
namespace.
@@ -16,7 +20,8 @@
* namespace
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version CVS $Revision: 1.2 $ $Date: 2001/08/20 13:55:11 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @version CVS $Revision: 1.3 $ $Date: 2001/08/25 19:40:32 $
*/
public class NamedLogicsheet extends Logicsheet {
/**
@@ -29,6 +34,13 @@
*/
protected String prefix;
+ public NamedLogicsheet(String systemId, URLFactory urlFactory,
+ ComponentManager manager)
+ throws MalformedURLException, IOException
+ {
+ super(systemId, urlFactory, manager);
+ }
+
/**
* Set the logichseet's namespace prefix
*
@@ -45,23 +57,5 @@
*/
public String getPrefix() {
return this.prefix;
- }
-
- /**
- * Set the logichseet's namespace uri
- *
- * @param prefix The namespace uri
- */
- public void setUri(String uri) {
- this.uri = uri;
- }
-
- /**
- * Return the logicsheet's namespace uri
- *
- * @return The logicsheet's namespace uri
- */
- public String getUri() {
- return this.uri;
}
}
1.12 +2 -2
xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPFormValidatorHelper.java
Index: XSPFormValidatorHelper.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPFormValidatorHelper.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XSPFormValidatorHelper.java 2001/08/22 03:51:05 1.11
+++ XSPFormValidatorHelper.java 2001/08/25 19:40:32 1.12
@@ -27,7 +27,7 @@
* The <code>ValidatorActionResult</code> object helper
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
- * @version CVS $Revision: 1.11 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.12 $ $Date: 2001/08/25 19:40:32 $
*/
public class XSPFormValidatorHelper {
/**
@@ -464,7 +464,7 @@
conf = new ConfigurationHelper();
SAXConfigurationHandler builder = new
SAXConfigurationHandler();
- source.stream(builder);
+ source.toSAX(builder);
conf.lastModified = source.getLastModified();
conf.configuration = builder.getConfiguration();
1.17 +21 -25
xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java
Index: SitemapSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SitemapSource.java 2001/08/22 03:51:05 1.16
+++ SitemapSource.java 2001/08/25 19:40:32 1.17
@@ -20,6 +20,7 @@
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.ModifiableSource;
import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.sitemap.Sitemap;
@@ -33,6 +34,7 @@
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.w3c.dom.Node;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -45,12 +47,12 @@
* Description of a source which is defined by a pipeline.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.16 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.17 $ $Date: 2001/08/25 19:40:32 $
*/
public final class SitemapSource
extends AbstractXMLConsumer
-implements Source {
+implements ModifiableSource {
/** The last modification date or 0 */
private long lastModificationDate;
@@ -82,8 +84,8 @@
/** The redirect <code>Source</code> */
private Source redirectSource;
- /** The <code>ProcessingException</code> if unable to get resource */
- private ProcessingException exception;
+ /** The <code>SAXException</code> if unable to get resource */
+ private SAXException exception;
/**
* Construct a new object
@@ -168,7 +170,7 @@
throws ProcessingException, IOException {
// VG: Why exception is not thrown in constructor?
if (this.exception != null) {
- throw this.exception;
+ throw new ProcessingException(this.exception);
}
SitemapComponentSelector serializerSelector = null;
Serializer serializer = null;
@@ -179,13 +181,11 @@
ByteArrayOutputStream os = new ByteArrayOutputStream();
serializer.setOutputStream(os);
- this.stream(serializer);
+ this.toSAX(serializer);
return new ByteArrayInputStream(os.toByteArray());
} catch (ComponentException cme) {
throw new ProcessingException("could not lookup pipeline
components", cme);
- } catch (ProcessingException e) {
- throw e;
} catch (Exception e) {
throw new ProcessingException("Exception during processing of "
+ this.systemId, e);
} finally {
@@ -259,12 +259,10 @@
this.redirectSource =
this.environment.resolve(redirectURL);
this.lastModificationDate =
this.redirectSource.getLastModified();
}
- } catch (ProcessingException e) {
- reset();
- this.exception = e;
} catch (Exception e) {
reset();
- this.exception = new ProcessingException("Could not get sitemap
source " + this.systemId, e);
+ this.exception = new SAXException("Could not get sitemap source "
+ + this.systemId, e);
}
}
@@ -281,26 +279,24 @@
/**
* Stream content to the consumer
*/
- public void stream(XMLConsumer consumer)
- throws ProcessingException, SAXException, IOException {
+ public void toSAX(XMLConsumer consumer)
+ throws SAXException {
if (this.exception != null) {
throw this.exception;
}
try {
-
if (this.redirectSource != null) {
- this.redirectSource.stream(consumer);
+ this.redirectSource.toSAX(consumer);
} else {
this.environment.setURI(this.prefix, this.uri);
- ((XMLProducer)eventPipeline).setConsumer(consumer);
- eventPipeline.process(this.environment);
+ ((XMLProducer)eventPipeline).setConsumer(consumer);
+ eventPipeline.process(this.environment);
}
} catch (ComponentException cme) {
- throw new ProcessingException("could not lookup pipeline
components", cme);
- } catch (ProcessingException e) {
- throw e;
+ throw new SAXException("could not lookup pipeline components",
cme);
} catch (Exception e) {
- throw new ProcessingException("Exception during processing of "
+ this.systemId, e);
+ throw new SAXException("Exception during processing of "
+ + this.systemId, e);
} finally {
reset();
}
@@ -309,9 +305,9 @@
/**
* Stream content to the content handler
*/
- public void stream(ContentHandler contentHandler)
- throws ProcessingException, SAXException, IOException {
- this.stream(new ContentHandlerWrapper(contentHandler));
+ public void toSAX(ContentHandler contentHandler)
+ throws SAXException {
+ this.toSAX(new ContentHandlerWrapper(contentHandler));
}
private void reset() {
1.10 +29 -61
xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- URLSource.java 2001/08/22 03:51:05 1.9
+++ URLSource.java 2001/08/25 19:40:32 1.10
@@ -12,7 +12,7 @@
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.parser.Parser;
-import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.ModifiableSource;
import org.apache.cocoon.xml.XMLConsumer;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -30,11 +30,10 @@
* Description of a source which is described by an URL.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.9 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.10 $ $Date: 2001/08/25 19:40:32 $
*/
-public final class URLSource
-implements Source {
+public final class URLSource implements ModifiableSource {
/** Identifier for file urls */
private final String FILE = "file:";
@@ -187,25 +186,6 @@
}
/**
- * Is this a file, then the <code>getFile</code> method can
- * return a <code>File</code> object for this source.
- */
- public boolean isFile() {
- return this.isFile;
- }
-
- /**
- * Return a <code>File</code> object if this is a local file
- * (if the <code>isFile</code> method returns true).
- */
- public File getFile() {
- if (this.isFile == true) {
- return new File(this.systemId.substring(FILE.length()));
- }
- return null;
- }
-
- /**
* Refresh this object and update the last modified date
* and content length.
*/
@@ -306,43 +286,31 @@
return new String ( out );
}
- /**
- * Stream content to the consumer
- */
- public void stream(XMLConsumer consumer)
- throws ProcessingException, SAXException, IOException {
- Parser parser = null;
- try {
- parser = (Parser)this.manager.lookup(Parser.ROLE);
-
- parser.setConsumer(consumer);
- parser.parse(this.getInputSource());
- } catch (ComponentException e){
- throw new ProcessingException("Exception in URLSource.stream()",
e);
- } finally {
- if (parser != null) this.manager.release(parser);
- }
- }
-
- /**
- * Stream content to the content handler
- */
- public void stream(ContentHandler contentHandler)
- throws ProcessingException, SAXException, IOException {
- Parser parser = null;
- try {
- parser = (Parser)this.manager.lookup(Parser.ROLE);
-
- parser.setContentHandler(contentHandler);
- parser.parse(this.getInputSource());
- } catch (ComponentException e){
- throw new ProcessingException("Exception in URLSource.stream()",
e);
- } finally {
- if (parser != null) this.manager.release(parser);
- }
- }
-
- public void recycle() {
- }
+ /**
+ * Stream content to a content handler or to an XMLConsumer
+ */
+ public void toSAX(ContentHandler handler)
+ throws SAXException
+ {
+ Parser parser = null;
+ try {
+ parser = (Parser)this.manager.lookup(Parser.ROLE);
+
+ if (handler instanceof XMLConsumer)
+ parser.setConsumer((XMLConsumer)handler);
+ else
+ parser.setContentHandler(handler);
+
+ parser.parse(this.getInputSource());
+ } catch (Exception e){
+ throw new SAXException("Exception in URLSource.stream()", e);
+ } finally {
+ if (parser != null) this.manager.release(parser);
+ }
+ }
+
+ public void recycle()
+ {
+ }
}
1.3 +25 -3
xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessor.java
Index: XSLTProcessor.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSLTProcessor.java 2001/08/20 13:55:13 1.2
+++ XSLTProcessor.java 2001/08/25 19:40:32 1.3
@@ -15,6 +15,8 @@
import javax.xml.transform.Result;
import javax.xml.transform.sax.TransformerHandler;
+import org.xml.sax.XMLFilter;
+
/**
* This is the interface of the XSLT processor in Cocoon.
*
@@ -39,11 +41,31 @@
public void setSourceResolver(SourceResolver resolver);
/**
- * Return a <code>TransformerHandler</code> for a given stylesheet
- * <code>Source</code>. This can be used in a pipeline to handle the
- * transformation of a stream of SAX events. See [EMAIL PROTECTED]
+ * <p>Return a <code>TransformerHandler</code> for a given
+ * stylesheet <code>Source</code>. This can be used in a pipeline to
+ * handle the transformation of a stream of SAX events. See [EMAIL
PROTECTED]
* org.apache.cocoon.transformation.TraxTransformer#setConsumer} for
* an example of how to use this method.
+ *
+ * <p>The additional <code>filter</code> argument, if it's not
+ * <code>null</code>, is inserted in the chain SAX events as an XML
+ * filter during the parsing or the source document.
+ *
+ * <p>This method caches the Source object and performs a reparsing
+ * only if this changes.
+ *
+ * @param stylesheet a <code>Source</code> value
+ * @param filter a <code>XMLFilter</code> value
+ * @return a <code>TransformerHandler</code> value
+ * @exception ProcessingException if an error occurs
+ */
+ public TransformerHandler getTransformerHandler(Source stylesheet,
+ XMLFilter filter)
+ throws ProcessingException;
+
+ /**
+ * Same as [EMAIL PROTECTED] #getTransformerHandler(Source,XMLFilter)},
with
+ * <code>filter</code> set to <code>null</code>.
*
* @param stylesheet a <code>Source</code> value
* @return a <code>TransformerHandler</code> value
1.3 +21 -3
xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
Index: XSLTProcessorImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSLTProcessorImpl.java 2001/08/20 13:55:13 1.2
+++ XSLTProcessorImpl.java 2001/08/25 19:40:32 1.3
@@ -24,6 +24,7 @@
import org.apache.cocoon.util.TraxErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
+import org.xml.sax.XMLFilter;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.transform.Result;
@@ -106,12 +107,21 @@
public TransformerHandler getTransformerHandler(Source stylesheet)
throws ProcessingException
{
+ return getTransformerHandler(stylesheet, null);
+ }
+
+ public TransformerHandler getTransformerHandler(Source stylesheet,
+ XMLFilter filter)
+ throws ProcessingException
+ {
try {
Templates templates = getTemplates(stylesheet);
if(templates == null) {
- getLogger().debug("Creating new Templates in " + this + " for "
- + stylesheet.getInputSource().getSystemId());
InputSource is = stylesheet.getInputSource();
+ getLogger().debug("Creating new Templates in " + this + " for " +
is);
+ if (is.getSystemId() != null)
+ getLogger().debug(" with system id " + is.getSystemId());
+
//templates = getTransformerFactory().newTemplates(new
SAXSource(is));
// Create a Templates ContentHandler to handle parsing of the
@@ -123,7 +133,13 @@
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
- reader.setContentHandler(templatesHandler);
+
+ if (filter != null) {
+ filter.setParent(reader);
+ filter.setContentHandler(templatesHandler);
+ }
+ else
+ reader.setContentHandler(templatesHandler);
getLogger().debug("InputSource = " + is
+ ", templatesHandler = " + templatesHandler
@@ -221,6 +237,8 @@
{
Templates templates = null;
InputSource is = stylesheet.getInputSource();
+ getLogger().debug("XSLTProcessorImpl getTemplates: stylesheet "
+ + is.getSystemId());
if (useStore == false)
return null;
1.11 +38 -64 xml-cocoon2/src/org/apache/cocoon/environment/Source.java
Index: Source.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/environment/Source.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Source.java 2001/08/22 03:51:05 1.10
+++ Source.java 2001/08/25 19:40:32 1.11
@@ -9,83 +9,57 @@
package org.apache.cocoon.environment;
import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.cocoon.xml.XMLizable;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.xml.XMLConsumer;
-import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
+import java.io.IOException;
/**
* Description of a source. This interface provides a simple interface
- * for accessing any resource (URL, local file etc).
+ * for accessing a source of data. The source of data is assumed to
+ * <b>not change</b> during the lifetime of the Source object. If you
+ * have a data source that can change its content and you want it to
+ * reflect in Cocoon, use a [EMAIL PROTECTED] ModifiableSource} object
instead.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.10 $ $Date: 2001/08/22 03:51:05 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @version CVS $Revision: 1.11 $ $Date: 2001/08/25 19:40:32 $
*/
-public interface Source extends Recyclable {
- /**
- * Get the last modification date of the source or 0 if it
- * is not possible to determine the date.
- */
- long getLastModified();
-
- /**
- * Get the content length of the source or -1 if it
- * is not possible to determine the length.
- */
- long getContentLength();
-
- /**
- * Return an <code>InputStream</code> object to read from the source.
- */
- InputStream getInputStream()
+public interface Source extends Recyclable, XMLizable {
+ /**
+ * Get the last modification date of the source or 0 if it
+ * is not possible to determine the date.
+ */
+ public long getLastModified();
+
+ /**
+ * Get the content length of the source or -1 if it
+ * is not possible to determine the length.
+ */
+ public long getContentLength();
+
+ /**
+ * Return an <code>InputStream</code> object to read from the source.
+ */
+ public InputStream getInputStream()
throws ProcessingException, IOException;
- /**
- * Return the unique identifer for this source
- */
- String getSystemId();
-
- /**
- * Is this a file, then the <code>getFile</code> method can
- * return a <code>File</code> object for this source.
- */
- boolean isFile();
-
- /**
- * Return a <code>File</code> object if this is a local file
- * (if the <code>isFile</code> method returns true).
- */
- File getFile();
-
- /**
- * Refresh this object and update the last modified date
- * and content length.
- */
- void refresh();
-
- /**
- * Return a new <code>InputSource</code> object
- */
- InputSource getInputSource()
+ /**
+ * Return an <code>InputSource</code> object to read the XML
+ * content.
+ *
+ * @return an <code>InputSource</code> value
+ * @exception ProcessingException if an error occurs
+ * @exception IOException if an error occurs
+ */
+ public InputSource getInputSource()
throws ProcessingException, IOException;
- /**
- * Stream content to the consumer
- */
- void stream(XMLConsumer consumer)
- throws ProcessingException, SAXException, IOException;
-
- /**
- * Stream content to the content handler
- */
- void stream(ContentHandler contentHandler)
- throws ProcessingException, SAXException, IOException;
-
+ /**
+ * Return the unique identifer for this source
+ */
+ public String getSystemId();
}
-
1.12 +10 -9
xml-cocoon2/src/org/apache/cocoon/generation/DirectoryGenerator.java
Index: DirectoryGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/DirectoryGenerator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DirectoryGenerator.java 2001/08/22 03:51:05 1.11
+++ DirectoryGenerator.java 2001/08/25 19:40:32 1.12
@@ -61,10 +61,11 @@
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Conny Krappatsch</a>
* (SMB GmbH) for Virbus AG
- * @version CVS $Revision: 1.11 $ $Date: 2001/08/22 03:51:05 $ */
+ * @version CVS $Revision: 1.12 $ $Date: 2001/08/25 19:40:32 $ */
public class DirectoryGenerator extends ComposerGenerator implements
Recyclable {
-
+ private static final String FILE = "file:";
+
/** The URI of the namespace of this generator. */
protected static final String URI =
"http://apache.org/cocoon/directory/2.0";
@@ -163,20 +164,20 @@
Source inputSource = null;
try {
inputSource = this.resolver.resolve(directory);
- directory = inputSource.getSystemId();
- if (inputSource.isFile() == false) {
- throw new ResourceNotFoundException(directory + " is not a
directory.");
+ String systemId = inputSource.getSystemId();
+ if (!systemId.startsWith(FILE)) {
+ throw new ResourceNotFoundException(systemId + " does not
denote a directory");
}
- File path = inputSource.getFile();
- if (!path.isDirectory()) {
+ File directoryFile = new File(directory);
+ if (!directoryFile.isDirectory()) {
throw new ResourceNotFoundException(directory + " is not a
directory.");
}
this.contentHandler.startDocument();
this.contentHandler.startPrefixMapping(PREFIX,URI);
- Stack ancestors = getAncestors(path);
- addPathWithAncestors(path, ancestors);
+ Stack ancestors = getAncestors(directoryFile);
+ addPathWithAncestors(directoryFile, ancestors);
this.contentHandler.endPrefixMapping(PREFIX);
this.contentHandler.endDocument();
1.20 +8 -12
xml-cocoon2/src/org/apache/cocoon/generation/FileGenerator.java
Index: FileGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/FileGenerator.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- FileGenerator.java 2001/08/22 03:51:05 1.19
+++ FileGenerator.java 2001/08/25 19:40:32 1.20
@@ -35,7 +35,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.19 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.20 $ $Date: 2001/08/25 19:40:32 $
*/
public class FileGenerator extends ComposerGenerator
implements Cacheable, Recyclable {
@@ -101,21 +101,17 @@
* Generate XML data.
*/
public void generate()
- throws IOException, SAXException, ProcessingException {
+ throws IOException, SAXException {
try {
getLogger().debug("processing file " + super.source);
getLogger().debug("file resolved to " +
this.inputSource.getSystemId());
- this.inputSource.stream(super.xmlConsumer);
-
- } catch (FileNotFoundException e) {
- getLogger().warn("Could not find resource " +
this.inputSource.getSystemId(), e);
- throw new ResourceNotFoundException("Could not find resource "
- + this.inputSource.getSystemId(), e);
- } catch (IOException e) {
- getLogger().error("Could not read resource " +
this.inputSource.getSystemId(), e);
- throw new ResourceNotFoundException("Could not read resource "
- + this.inputSource.getSystemId(), e);
+ this.inputSource.toSAX(super.xmlConsumer);
+ } catch (Exception e) {
+ getLogger().error("Could not read resource "
+ + this.inputSource.getSystemId(), e);
+ throw new SAXException("Could not read resource "
+ + this.inputSource.getSystemId(), e);
}
}
}
1.16 +2 -2
xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java
Index: ContentAggregator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ContentAggregator.java 2001/08/22 03:51:06 1.15
+++ ContentAggregator.java 2001/08/25 19:40:32 1.16
@@ -37,7 +37,7 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: ContentAggregator.java,v 1.15 2001/08/22 03:51:06
vgritsenko Exp $
+ * @version CVS $Id: ContentAggregator.java,v 1.16 2001/08/25 19:40:32
giacomo Exp $
*/
public class ContentAggregator extends ContentHandlerWrapper implements
Generator, Cacheable, Composable {
@@ -142,7 +142,7 @@
}
try {
- part.source.stream(this);
+ part.source.toSAX(this);
} finally {
if (!part.element.equals("")) {
this.endElem(prefix, part.element);
1.19 +4 -3 xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java
Index: Handler.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Handler.java 2001/08/22 03:51:06 1.18
+++ Handler.java 2001/08/25 19:40:32 1.19
@@ -27,6 +27,7 @@
import org.apache.cocoon.components.source.SourceHandler;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.Source;
+import org.apache.cocoon.environment.ModifiableSource;
import org.apache.cocoon.environment.SourceResolver;
import org.xml.sax.SAXException;
@@ -40,7 +41,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.18 $ $Date: 2001/08/22 03:51:06 $
+ * @version CVS $Revision: 1.19 $ $Date: 2001/08/25 19:40:32 $
*/
public class Handler extends AbstractLoggable
implements Runnable, Contextualizable, Composable, Processor, Disposable,
SourceResolver {
@@ -50,7 +51,7 @@
/** the source of this sitemap */
private String sourceFileName;
- private Source source;
+ private ModifiableSource source;
/** the last error */
private Exception exception;
@@ -117,7 +118,7 @@
SourceHandler oldSourceHandler = environment.getSourceHandler();
try {
environment.setSourceHandler(this.sourceHandler);
- this.source = environment.resolve(this.sourceFileName);
+ this.source =
(ModifiableSource)environment.resolve(this.sourceFileName);
this.contextSource = environment.resolve("");
} finally {
environment.setSourceHandler(oldSourceHandler);
1.7 +2 -2
xml-cocoon2/src/org/apache/cocoon/transformation/CIncludeTransformer.java
Index: CIncludeTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/CIncludeTransformer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CIncludeTransformer.java 2001/08/22 03:51:06 1.6
+++ CIncludeTransformer.java 2001/08/25 19:40:32 1.7
@@ -32,7 +32,7 @@
* which surrounds the included content.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.6 $ $Date: 2001/08/22 03:51:06 $ $Author:
vgritsenko $
+ * @version CVS $Revision: 1.7 $ $Date: 2001/08/25 19:40:32 $ $Author:
giacomo $
*/
public class CIncludeTransformer extends AbstractTransformer
implements Recyclable, Composable {
@@ -127,7 +127,7 @@
Source source = null;
try {
source = this.sourceResolver.resolve(src);
- source.stream(consumer);
+ source.toSAX(consumer);
} catch (IOException e) {
getLogger().error("CIncludeTransformer", e);
throw new SAXException("CIncludeTransformer could not read
resource", e);
1.7 +2 -2
xml-cocoon2/src/org/apache/cocoon/transformation/CachingCIncludeTransformer.java
Index: CachingCIncludeTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/CachingCIncludeTransformer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CachingCIncludeTransformer.java 2001/08/20 13:55:17 1.6
+++ CachingCIncludeTransformer.java 2001/08/25 19:40:32 1.7
@@ -45,7 +45,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Maciek Kaminski</a>
- * @version CVS $Revision: 1.6 $ $Date: 2001/08/20 13:55:17 $ $Author: dims $
+ * @version CVS $Revision: 1.7 $ $Date: 2001/08/25 19:40:32 $ $Author:
giacomo $
*/
public class CachingCIncludeTransformer extends AbstractTransformer
implements Recyclable, Composable, Cacheable {
@@ -162,7 +162,7 @@
}
try {
- this.sourceResolver.resolve(src).stream(getConsumer());
+ this.sourceResolver.resolve(src).toSAX(getConsumer());
} catch (Exception e) {
getLogger().error("CachingCIncludeTransformer", e);
throw new SAXException("CachingCIncludeTransformer could not
read resource", e);
1.17 +12 -2
xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java
Index: I18nTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- I18nTransformer.java 2001/08/20 13:55:17 1.16
+++ I18nTransformer.java 2001/08/25 19:40:32 1.17
@@ -17,9 +17,11 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.acting.LocaleAction;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.Source;
import org.apache.cocoon.i18n.XMLResourceBundle;
import org.apache.cocoon.i18n.XMLResourceBundleFactory;
import org.apache.regexp.RE;
@@ -28,6 +30,7 @@
import org.xml.sax.helpers.AttributesImpl;
import java.io.IOException;
+import java.io.File;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.MessageFormat;
@@ -194,6 +197,8 @@
public class I18nTransformer extends AbstractTransformer
implements Composable, Poolable, Configurable {
+ private static final String FILE = "file:";
+
protected ComponentManager manager;
/**
@@ -455,8 +460,13 @@
XMLResourceBundleFactory.ConfigurationKeys.ROOT_DIRECTORY,
"location"
);
- String cR =
- resolver.resolve(catalogueLocation).getFile().getCanonicalPath();
+ Source source = resolver.resolve(catalogueLocation);
+ String systemId = source.getSystemId();
+ if (!systemId.startsWith(FILE)) {
+ throw new ResourceNotFoundException(systemId + " does not denote a
directory");
+ }
+ File file = new File(systemId);
+ String cR = file.getCanonicalPath();
dirConf.setValue(cR);
configuration.addChild(dirConf);
1.31 +5 -3
xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java
Index: TraxTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/TraxTransformer.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- TraxTransformer.java 2001/08/22 03:51:06 1.30
+++ TraxTransformer.java 2001/08/25 19:40:32 1.31
@@ -80,7 +80,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
- * @version CVS $Id: TraxTransformer.java,v 1.30 2001/08/22 03:51:06
vgritsenko Exp $
+ * @version CVS $Id: TraxTransformer.java,v 1.31 2001/08/25 19:40:32 giacomo
Exp $
*/
public class TraxTransformer extends AbstractTransformer
implements Transformer, Composable, Recyclable, Configurable, Cacheable,
Disposable {
@@ -410,8 +410,10 @@
*/
this.transformerHandler = null;
this.objectModel = null;
- this.inputSource.recycle();
- this.inputSource = null;
+ if (this.inputSource != null) {
+ this.inputSource.recycle();
+ this.inputSource = null;
+ }
this.par = null;
this._useParameters = this.useParameters;
this._useCookies = this.useCookies;
1.29 +0 -6 xml-cocoon2/webapp/cocoon.xconf
Index: cocoon.xconf
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- cocoon.xconf 2001/08/14 11:19:54 1.28
+++ cocoon.xconf 2001/08/25 19:40:33 1.29
@@ -175,12 +175,6 @@
<parameter name="href"
value="resource://org/apache/cocoon/components/language/markup/xsp/java/form-validator.xsl"/>
</builtin-logicsheet>
- <builtin-logicsheet>
- <parameter name="prefix" value="soap"/>
- <parameter name="uri" value="http://apache.org/xsp/soap/2.0"/>
- <parameter name="href"
value="context://docs/samples/soap/soap-lib.xsl"/>
- </builtin-logicsheet>
-
<!-- The sel taglib allows to put multiple pages / view into
one xsp. While in general it is good style to put
different views into different xsp because they're more
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]