2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.clay.parser.builder.chain.DefaultBuilderRule
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultBuilderRule
100%
9/9
N/A
3
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 /*
 19  
  * $Id: DefaultBuilderRule.java 464373 2006-10-16 04:21:54Z rahul $
 20  
  */
 21  
 package org.apache.shale.clay.parser.builder.chain;
 22  
 
 23  
 import org.apache.commons.chain.Command;
 24  
 import org.apache.commons.chain.Context;
 25  
 import org.apache.shale.clay.parser.Node;
 26  
 import org.apache.shale.clay.parser.builder.Builder;
 27  
 import org.apache.shale.clay.parser.builder.CommentBuilder;
 28  
 import org.apache.shale.clay.parser.builder.MorphBuilder;
 29  
 import org.apache.shale.clay.parser.builder.VerbatimBuilder;
 30  
 
 31  
 /**
 32  
  * <p>
 33  
  * This is a <code>Command</code> implementation that will
 34  
  * match a HTML {@link Node} with a matching {@link Builder}
 35  
  * implementation. This is the default rule and will always return a
 36  
  * {@link OutputLinkBuilder} and the chain terminated.  The {@link BuilderFactory} runs this
 37  
  * command rule as part of the <code>Globals.BUILDER_CATALOG_NAME</code>
 38  
  * found in the <code>Globals.BUILDER_RESOURCE_NAME</code> and
 39  
  * invoking the <code>Globals.FIND_BUILDER_COMMAND_NAME</code>
 40  
  * </p>
 41  
  */
 42  60
 public class DefaultBuilderRule implements Command {
 43  
 
 44  
     /**
 45  
      * <p>
 46  
      * Default static instance of {@link VerbatimBuilder}.
 47  
      * <p>
 48  
      */
 49  1
     private static final Builder[] BUILDERS = {new CommentBuilder(), new MorphBuilder(), new VerbatimBuilder()};
 50  
 
 51  
     /**
 52  
      * <p>
 53  
      * Uses the {@link BuilderRuleContext} to find the current html
 54  
      * {@link org.apache.shale.clay.parser.Node}. This is the default rule that
 55  
      * will return a {@link VerbatimBuilder} when the node is not a comment or
 56  
      * has a <code>jsfid</code> attribute. When the html node is a
 57  
      * comment, the {@link CommentBuilder} is returned.  If the node is not a comment
 58  
      * but has a <code>jsfid</code> attribute, the {@link MorphBuilder} is returned.
 59  
      * </p>
 60  
      *
 61  
      * @param context commons chians
 62  
      * @return <code>true</code> if final
 63  
      * @exception Exception propagated to the top chain
 64  
      */
 65  
     public boolean execute(Context context) throws Exception {
 66  
 
 67  
 
 68  684
         BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
 69  684
         Node node = builderRuleContext.getNode();
 70  684
         if (node.isComment() || node.isCdata()) {
 71  14
             builderRuleContext.setBuilder(BUILDERS[0]);
 72  14
         } else  if (node.getName() != null && node.getAttributes().containsKey("jsfid")) {
 73  
             builderRuleContext.setBuilder(BUILDERS[1]);
 74  
         } else {
 75  670
             builderRuleContext.setBuilder(BUILDERS[2]);
 76  
         }
 77  
 
 78  684
         return true;
 79  
     }
 80  
 
 81  
 }