sylvain 2002/09/29 13:24:23 Modified: . changes.xml src/java/org/apache/cocoon/components/pipeline/impl CachingPointProcessingPipeline.java src/java/org/apache/cocoon/components/treeprocessor DefaultTreeBuilder.java src/java/org/apache/cocoon/components/treeprocessor/sitemap ComponentsSelector.java GenerateNodeBuilder.java SerializeNodeBuilder.java SitemapLanguage.java TransformNodeBuilder.java src/java/org/apache/cocoon/components/treeprocessor/variables NOPVariableResolver.java PreparedVariableResolver.java VariableResolver.java src/java/org/apache/cocoon/sitemap DefaultSitemapComponentSelector.java SitemapComponentSelector.java Log: Apply patch #12780 : new pipeline hints to allow pipeline-specific parameters on sitemap statements. Submitted by: Michael Melhem <[EMAIL PROTECTED]> Revision Changes Path 1.263 +6 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.262 retrieving revision 1.263 diff -u -r1.262 -r1.263 --- changes.xml 27 Sep 2002 16:29:58 -0000 1.262 +++ changes.xml 29 Sep 2002 20:24:22 -0000 1.263 @@ -40,6 +40,11 @@ </devs> <release version="@version@" date="@date@"> + <action dev="SW" type="add" fixes-bug="12780" due-to="Michael Melhem" due-to-email="[EMAIL PROTECTED]"> + New pipeline hint attribute to allow pipeline components (i.e. map:generate, map:transform + and map:serialize) to hold some pipeline-specific parameters. The first usage of this feature + is to drive manual cache points for the CachingPointProcessingPipeline. + </action> <action dev="GP" type="update"> Removed all references to Loggable in favor of LogEnabled (this includes references to common abstract classes as AbstractLoggable and 1.5 +28 -19 xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java Index: CachingPointProcessingPipeline.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CachingPointProcessingPipeline.java 9 Sep 2002 12:00:41 -0000 1.4 +++ CachingPointProcessingPipeline.java 29 Sep 2002 20:24:22 -0000 1.5 @@ -130,23 +130,27 @@ throws ProcessingException { super.setGenerator(role, source, param, hintParam); - // check the hint param for a "caching-point" hint + // check the hint param for a "caching-point" hint String pipelinehint = null; try { - pipelinehint = hintParam.getParameter("hint"); - getLogger().debug("pipeline-hint is: " + pipelinehint); + pipelinehint = hintParam.getParameter("caching-point", null); + + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("generator caching-point pipeline-hint is set to: " + pipelinehint); + } } catch (Exception ex) { - getLogger().warn("pipeline-hint Exception, pipeline-hint ignored: " + ex); + if (this.getLogger().isWarnEnabled()) { + getLogger().warn("caching-point hint Exception, pipeline-hint ignored: " + ex); + } } - - // if this generator is manually set to "caching-point" (via pipeline-hint) - // then ensure the next component is caching. - if ((pipelinehint != null) && pipelinehint.equals("caching-point")) { - this.nextIsCachePoint=true; - } + // if this generator is manually set to "caching-point" (via pipeline-hint) + // then ensure the next component is caching. + if ( "true".equals(pipelinehint)) { + this.nextIsCachePoint=true; + } } @@ -157,15 +161,20 @@ throws ProcessingException { super.addTransformer(role, source, param, hintParam); - // check the hint param for a "caching-point" hint + // check the hint param for a "caching-point" hint String pipelinehint = null; try { - pipelinehint = hintParam.getParameter("hint"); - getLogger().debug("pipeline-hint is: " + pipelinehint); + pipelinehint = hintParam.getParameter("caching-point", null); + + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("transformer caching-point pipeline-hint is set to: " + pipelinehint); + } } catch (Exception ex) { - getLogger().warn("pipeline-hint Exception, pipeline-hint ignored: " + ex); + if (this.getLogger().isWarnEnabled()) { + getLogger().warn("caching-point hint Exception, pipeline-hint ignored: " + ex); + } } // add caching point flag @@ -173,11 +182,11 @@ this.isCachePoint.add(new Boolean(this.nextIsCachePoint)); this.nextIsCachePoint = false; - // if this transformer is manually set to "caching-point" (via pipeline-hint) - // then ensure the next component is caching. - if ((pipelinehint != null) && pipelinehint.equals("caching-point")) { + // if this transformer is manually set to "caching-point" (via pipeline-hint) + // then ensure the next component is caching. + if ( "true".equals(pipelinehint)) { this.nextIsCachePoint=true; - } + } } 1.15 +1 -46 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java Index: DefaultTreeBuilder.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- DefaultTreeBuilder.java 16 Sep 2002 16:20:53 -0000 1.14 +++ DefaultTreeBuilder.java 29 Sep 2002 20:24:22 -0000 1.15 @@ -472,12 +472,6 @@ ((ParameterizableProcessingNode)node).setParameters(params); } - if (node instanceof PipelineEventComponentProcessingNode) { - Map params = getHintParameters(config); - ((PipelineEventComponentProcessingNode)node).setPipelineHints(params); - } - - if (node instanceof Initializable) { this.initializableNodes.add(node); } @@ -488,45 +482,6 @@ return node; } - - /** - * Method to extract pieline-hint parameters from the hint attribute - */ - protected Map getHintParameters(Configuration config) throws ConfigurationException { - String expression = config.getAttribute("hint",null); - - if (expression == null) - return null; - - Map params = new HashMap(); - - try { - // REVIST: hint needs to be parsed into name value pairs. - // At the moment hint value is simply passed through - // as a whole and not parsed! - // - // Syntax for pipeline hints (as Proposed by Sylvain Wallez): - // A hints attribute has one or more comma separated hints - // hints-attr :: hint [ ',' hint ]* - // A hint is a name and an optional value - // If there is no value, it is considered as a boolean "true" - // hint :: litteral [ '=' litteral ] - // litteral :: <a character string where ',' and '=' must be escaped with '\'> - // - // This allows the following : - // pipeline-hint="caching-point, connector=profiling" - params.put( VariableResolverFactory.getResolver("hint", this.manager), - VariableResolverFactory.getResolver(expression, this.manager)); - } - catch(PatternException pe) { - String msg = "Invalid pattern '" + expression + "' at " + config.getLocation(); - throw new ConfigurationException(msg, pe); - } - - return params; - - } - /** * Get <xxx:parameter> elements as a <code>Map</code> of </code>ListOfMapResolver</code>s, 1.5 +17 -1 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java Index: ComponentsSelector.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ComponentsSelector.java 18 Aug 2002 07:58:15 -0000 1.4 +++ ComponentsSelector.java 29 Sep 2002 20:24:22 -0000 1.5 @@ -123,6 +123,9 @@ /** The labels for hints */ private Map hintLabels; + /** The pipeline-hint Map */ + private Map pipelineHints; + /** The set of known hints, used to add standard components (see ensureExists) */ private Set knownHints = new HashSet(); @@ -177,6 +180,7 @@ } this.hintLabels = new HashMap(); + this.pipelineHints = new HashMap(); super.configure(config); } @@ -210,6 +214,9 @@ } this.hintLabels.put(hint, labels); } + + String pipelineHint = config.getAttribute("hint", null); + this.pipelineHints.put(hint, pipelineHint); } /** @@ -313,6 +320,15 @@ return parentSitemapSelector.getLabels(hint); } return labels; + } + + public String getPipelineHint(Object hint) { + String pipelineHint = (String)this.pipelineHints.get(hint); + // Pipeline-hints can be inherited or completely overrided + if (pipelineHint == null && parentSitemapSelector != null) { + return parentSitemapSelector.getPipelineHint(hint); + } + return pipelineHint; } } 1.3 +4 -1 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/GenerateNodeBuilder.java Index: GenerateNodeBuilder.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/GenerateNodeBuilder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- GenerateNodeBuilder.java 24 Jun 2002 20:32:19 -0000 1.2 +++ GenerateNodeBuilder.java 29 Sep 2002 20:24:22 -0000 1.3 @@ -74,17 +74,20 @@ private GenerateNode node; private Collection views; + private Map pipelineHints; public ProcessingNode buildNode(Configuration config) throws Exception { String type = this.treeBuilder.getTypeForStatement(config, Generator.ROLE + "Selector"); this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Generator.ROLE, type, config); + this.pipelineHints = ((SitemapLanguage)this.treeBuilder).getHintsForStatement(Generator.ROLE, type, config); this.node = new GenerateNode( type, VariableResolverFactory.getResolver(config.getAttribute("src", null), this.manager) ); + this.node.setPipelineHints(this.pipelineHints); return this.treeBuilder.setupNode(this.node, config); } 1.2 +4 -1 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java Index: SerializeNodeBuilder.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SerializeNodeBuilder.java 5 Mar 2002 08:26:23 -0000 1.1 +++ SerializeNodeBuilder.java 29 Sep 2002 20:24:22 -0000 1.2 @@ -74,6 +74,7 @@ private SerializeNode node; private Collection views; + private Map pipelineHints; /** This builder has no parameters -- return <code>false</code> */ protected boolean hasParameters() { @@ -85,12 +86,14 @@ String type = this.treeBuilder.getTypeForStatement(config, Serializer.ROLE + "Selector"); this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Serializer.ROLE, type, config); + this.pipelineHints = ((SitemapLanguage)this.treeBuilder).getHintsForStatement(Serializer.ROLE, type, config); this.node = new SerializeNode( type, config.getAttribute("mime-type", null), config.getAttributeAsInteger("status-code", -1) ); + this.node.setPipelineHints(this.pipelineHints); return this.treeBuilder.setupNode(node, config); } 1.10 +113 -2 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Index: SitemapLanguage.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SitemapLanguage.java 11 Sep 2002 10:08:35 -0000 1.9 +++ SitemapLanguage.java 29 Sep 2002 20:24:22 -0000 1.10 @@ -74,8 +74,15 @@ import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder; import org.apache.cocoon.components.treeprocessor.DefaultTreeBuilder; + +import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; +import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; + +import org.apache.cocoon.sitemap.PatternException; import org.apache.cocoon.util.StringUtils; +import org.apache.regexp.RE; + import java.util.*; /** @@ -89,6 +96,10 @@ private static final String ATTR_PREFIX = "org.apache.cocoon.components.treeprocessor.ViewNodeBuilder"; + // Regexp's for splitting expressions + private static final String COMMA_SPLIT_REGEXP = "[\\s]*,[\\s]*"; + private static final String EQUALS_SPLIT_REGEXP = "[\\s]*=[\\s]*"; + /** * Build a component manager with the contents of the <map:components> element of * the tree. @@ -359,6 +370,106 @@ return result; } + + /** + * Extract pipeline-hints from the given statement (if any exist) + * + * @param role the component role (e.g. <code>Generator.ROLE</code>) + * @param hint the component hint, i.e. the 'type' attribute + * @param statement the sitemap statement + * @return the hint params <code>Map</code> for this statement, or null + * if none exist + */ + public Map getHintsForStatement(String role, String hint, Configuration statement) throws Exception { + // This method implemets the hintParam Syntax as follows: + // A hints attribute has one or more comma separated hints + // hints-attr :: hint [ ',' hint ]* + // A hint is a name and an optional (string) value + // If there is no value, it is considered as boolean string "true" + // hint :: literal [ '=' litteral ] + // literal :: <a character string where the chars ',' and '=' are not permitted> + // + // A ConfigurationException is thrown if there is a problem "parsing" + // the hint. + + String statementHintParams = statement.getAttribute("hint", null); + String componentHintParams = null; + String hintParams = null; + + // firstly, determine if any pipeline-hints are defined at the component level + // if so, inherit these pipeline-hints (these hints can be overriden by local pipeline-hints) + try { + SitemapComponentSelector selector = (SitemapComponentSelector)this.manager.lookup(role + "Selector"); + componentHintParams = (String) selector.getPipelineHint(hint); + } + catch (Exception ex) { + if (this.getLogger().isWarnEnabled()) { + getLogger().warn("pipeline-hints: Component Exception: could not " + + "check for component level hints " + ex); + } + } + + if (componentHintParams != null) { + hintParams = componentHintParams; + + if (statementHintParams != null) { + hintParams = hintParams + "," + statementHintParams; + } + } + else { + hintParams = statementHintParams; + } + + // if there are no pipeline-hints defined then + // it makes no sense to continue so, return null + if (hintParams == null) { + return null; + } + + Map params = new HashMap(); + + RE commaSplit = new RE(COMMA_SPLIT_REGEXP); + RE equalsSplit = new RE(EQUALS_SPLIT_REGEXP); + + String[] expressions = commaSplit.split(hintParams.trim()); + + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("pipeline-hints: (aggregate-hint) " + hintParams); + } + + for (int i=0; i<expressions.length;i++) { + String [] nameValuePair = equalsSplit.split(expressions[i]); + + try { + if (nameValuePair.length < 2) { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("pipeline-hints: (name) " + nameValuePair[0] + + "\npipeline-hints: (value) [implicit] true"); + } + + params.put( VariableResolverFactory.getResolver(nameValuePair[0], this.manager), + VariableResolverFactory.getResolver("true", this.manager)); + } + else + { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("pipeline-hints: (name) " + nameValuePair[0] + + "\npipeline-hints: (value) " + nameValuePair[1]); + } + + params.put( VariableResolverFactory.getResolver(nameValuePair[0], this.manager), + VariableResolverFactory.getResolver(nameValuePair[1], this.manager)); + } + } + catch(PatternException pe) { + String msg = "Invalid pattern '" + hintParams + "' at " + statement.getLocation(); + getLogger().error(msg, pe); + throw new ConfigurationException(msg, pe); + } + } + + return params; + } /** * Split a list of space/comma separated labels into a Collection @@ -371,5 +482,5 @@ } else { return Arrays.asList(StringUtils.split(labels, ", \t\n\r")); } - } + } } 1.3 +5 -1 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/TransformNodeBuilder.java Index: TransformNodeBuilder.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/TransformNodeBuilder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TransformNodeBuilder.java 24 Jun 2002 20:32:19 -0000 1.2 +++ TransformNodeBuilder.java 29 Sep 2002 20:24:22 -0000 1.3 @@ -74,17 +74,21 @@ private TransformNode node; private Collection views; + private Map pipelineHints; public ProcessingNode buildNode(Configuration config) throws Exception { String type = this.treeBuilder.getTypeForStatement(config, Transformer.ROLE + "Selector"); this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement(Transformer.ROLE, type, config); + this.pipelineHints = ((SitemapLanguage)this.treeBuilder).getHintsForStatement(Transformer.ROLE, type, config); this.node = new TransformNode( type, VariableResolverFactory.getResolver(config.getAttribute("src", null), this.manager) ); + + this.node.setPipelineHints(this.pipelineHints); return this.treeBuilder.setupNode(node, config); } 1.2 +1 -2 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/NOPVariableResolver.java Index: NOPVariableResolver.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/NOPVariableResolver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NOPVariableResolver.java 24 Jun 2002 20:32:20 -0000 1.1 +++ NOPVariableResolver.java 29 Sep 2002 20:24:22 -0000 1.2 @@ -59,7 +59,6 @@ public class NOPVariableResolver extends VariableResolver { - private String originalExpr = null; private String expression = null; public NOPVariableResolver(String expression) { @@ -81,4 +80,4 @@ public final void release() { // Nothing to do } -} \ No newline at end of file +} 1.3 +0 -1 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolver.java Index: PreparedVariableResolver.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/PreparedVariableResolver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PreparedVariableResolver.java 25 Jun 2002 07:55:13 -0000 1.2 +++ PreparedVariableResolver.java 29 Sep 2002 20:24:22 -0000 1.3 @@ -70,7 +70,6 @@ public class PreparedVariableResolver extends VariableResolver implements Disposable { - private String originalExpr; private ComponentManager manager; private ComponentSelector selector; 1.2 +29 -2 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/VariableResolver.java Index: VariableResolver.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/variables/VariableResolver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- VariableResolver.java 24 Jun 2002 20:32:20 -0000 1.1 +++ VariableResolver.java 29 Sep 2002 20:24:22 -0000 1.2 @@ -52,6 +52,7 @@ import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.sitemap.PatternException; +import org.apache.cocoon.util.HashUtil; import java.util.Collections; import java.util.Iterator; @@ -70,6 +71,32 @@ public static final Map EMPTY_MAP = Collections.unmodifiableMap(new java.util.HashMap(0)); + protected String originalExpr = null; + + public String getKey() { + return this.originalExpr; + } + + /** + * Compare two VariableResolvers + */ + public boolean equals(Object object) { + if (object instanceof VariableResolver) { + if (((VariableResolver)object).getKey().equals(this.getKey())) { + return true; + } + } + return false; + } + + /** + * generate HashCode + * needed to determine uniqueness within hashtables + */ + public int hashCode() { + return (int) HashUtil.hash(this.getKey()); + } + /** * Resolve all {...} patterns using the values given in the list of maps and the object model. */ @@ -137,4 +164,4 @@ // ((VariableResolver)entry.getValue()).release(); // } // } -} \ No newline at end of file +} 1.5 +16 -2 xml-cocoon2/src/java/org/apache/cocoon/sitemap/DefaultSitemapComponentSelector.java Index: DefaultSitemapComponentSelector.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/DefaultSitemapComponentSelector.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DefaultSitemapComponentSelector.java 26 Apr 2002 07:19:13 -0000 1.4 +++ DefaultSitemapComponentSelector.java 29 Sep 2002 20:24:23 -0000 1.5 @@ -73,6 +73,7 @@ implements SitemapComponentSelector { private Map hintLabels; + private Map pipelineHints; private Map mime_types; private SitemapComponentSelector parentSelector; @@ -85,6 +86,7 @@ super(); this.hintLabels = new HashMap(); this.mime_types = new HashMap(); + this.pipelineHints = new HashMap(); componentMapping = Collections.synchronizedMap(new HashMap()); } @@ -175,6 +177,15 @@ return labels; } + public String getPipelineHint(Object hint) { + String pipelineHint = (String)this.pipelineHints.get(hint); + // Pipeline-hints can be inherited or completely overrided + if (pipelineHint == null && parentSelector != null) { + return parentSelector.getPipelineHint(hint); + } + return pipelineHint; + } + public void addComponent(Object hint, Class component, Configuration conf) throws ComponentException { @@ -194,6 +205,9 @@ this.hintLabels.put(hint, labels); } + String pipelineHint = conf.getAttribute("hint", null); + this.pipelineHints.put(hint, pipelineHint); + super.addComponent(hint, component, conf); } @@ -204,4 +218,4 @@ this.addComponent(hint, component, conf); this.mime_types.put(hint, mimeType); } -} \ No newline at end of file +} 1.9 +3 -2 xml-cocoon2/src/java/org/apache/cocoon/sitemap/SitemapComponentSelector.java Index: SitemapComponentSelector.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/SitemapComponentSelector.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SitemapComponentSelector.java 22 Feb 2002 07:03:55 -0000 1.8 +++ SitemapComponentSelector.java 29 Sep 2002 20:24:23 -0000 1.9 @@ -64,4 +64,5 @@ boolean hasLabel(Object hint, String label); String[] getLabels(Object hint); -} \ No newline at end of file + String getPipelineHint(Object hint); +}
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]