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

For more information, please explore the Attic.

View Javadoc

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: AnchorBuilderRule.java 464373 2006-10-16 04:21:54Z rahul $
20   */
21  package org.apache.shale.clay.parser.builder.chain;
22  
23  /***
24   * <p>
25   * This is a <code>Command</code> implementation that will
26   * match a HTML {@link Node} with a matching {@link Builder}
27   * implementation.  If the html node is an anchored tag, a
28   * {@link OutputLinkBuilder} will be returned and the
29   * chain terminated.  The {@link BuilderFactory} runs this
30   * command rule as part of the <code>Globals.BUILDER_CATALOG_NAME</code>
31   * found in the <code>Globals.BUILDER_RESOURCE_NAME</code> and
32   * invoking the <code>Globals.FIND_BUILDER_COMMAND_NAME</code>
33   * </p>
34   */
35  import org.apache.commons.chain.Command;
36  import org.apache.commons.chain.Context;
37  import org.apache.shale.clay.parser.Node;
38  import org.apache.shale.clay.parser.builder.Builder;
39  import org.apache.shale.clay.parser.builder.OutputLinkBuilder;
40  
41  /***
42   *
43   *
44   */
45  public class AnchorBuilderRule implements Command {
46  
47      /***
48       * <p>
49       * Static instance of the builder.
50       * </p>
51       */
52      private static final Builder BUILDER = new OutputLinkBuilder();
53  
54      /***
55       * <p>
56       * Uses the {@link BuilderRuleContext} to find the current html {@link Node}.
57       * If the node is an anchored element, return an instance if the builder and
58       * stop the chain.
59       * </p>
60       *
61       * @param context commons chains
62       * @return <code>true</code> if is final
63       * @exception Exception throws back to the top of the chain
64       */
65      public boolean execute(Context context) throws Exception {
66  
67          boolean isFinal = false;
68  
69          BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
70          Node node = builderRuleContext.getNode();
71          if (!node.isComment() && node.getName() != null
72              && node.getName().equalsIgnoreCase("a")) {
73              builderRuleContext.setBuilder(BUILDER);
74              isFinal = true;
75  
76          }
77  
78          return isFinal;
79      }
80  
81  }