View Javadoc
1   package org.apache.maven.doxia.module.twiki.parser;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.doxia.sink.Sink;
23  
24  /**
25   * Represent a WikiWord
26   *
27   * @author Juan F. Codagnone
28   */
29  class WikiWordBlock
30      implements Block
31  {
32      /**
33       * the wiki word
34       */
35      private final String wikiword;
36  
37      /**
38       * content to show in the wiki word link
39       */
40      private final Block content;
41  
42      /**
43       * Resolves WikiWord links
44       */
45      private final WikiWordLinkResolver wikiWordLinkResolver;
46  
47      /**
48       * @see WikiWordBlock(String, String)
49       * @param aWikiword the wikiWord
50       * @param resolver responsible of resolving the link to the wikiWord
51       */
52      WikiWordBlock( final String aWikiword, final WikiWordLinkResolver resolver )
53      {
54          this( aWikiword, aWikiword, resolver );
55      }
56  
57      /**
58       * Creates the WikiWordBlock.
59       *
60       * @param aWikiword the wiki word
61       * @param aText text to show in the wiki link
62       * @param resolver responsible of resolving the link to the wikiWord
63       * @throws IllegalArgumentException if the wikiword is <code>null</code>
64       * @deprecated
65       */
66      WikiWordBlock( final String aWikiword, final String aText, final WikiWordLinkResolver resolver )
67      {
68          this( aWikiword, new TextBlock( aText ), resolver );
69      }
70  
71      /**
72       * Creates the WikiWordBlock.
73       *
74       * @param aWikiword the wiki word
75       * @param content content to show in the wiki link
76       * @param resolver responsible of resolving the link to the wikiWord
77       * @throws IllegalArgumentException if the wikiword is <code>null</code>
78       */
79      WikiWordBlock( final String aWikiword, final Block content, final WikiWordLinkResolver resolver )
80      {
81          if ( aWikiword == null || content == null || resolver == null )
82          {
83              throw new IllegalArgumentException( "arguments can't be null" );
84          }
85          this.wikiword = aWikiword;
86          this.content = content;
87          this.wikiWordLinkResolver = resolver;
88      }
89  
90      /** {@inheritDoc} */
91      public final void traverse( final Sink sink )
92      {
93          sink.link( wikiWordLinkResolver.resolveLink( wikiword ) );
94          content.traverse( sink );
95          sink.link_();
96      }
97  
98      /** {@inheritDoc} */
99      public final boolean equals( final Object obj )
100     {
101         boolean ret = false;
102 
103         if ( obj == this )
104         {
105             ret = true;
106         }
107         else if ( obj instanceof WikiWordBlock )
108         {
109             final WikiWordBlock w = (WikiWordBlock) obj;
110             ret = wikiword.equals( w.wikiword ) && content.equals( w.content );
111         }
112 
113         return ret;
114     }
115 
116     /**
117      * {@inheritDoc}
118      *
119      * @return a int.
120      */
121     public final int hashCode()
122     {
123         final int magic1 = 17;
124         final int magic2 = 37;
125 
126         return magic1 + magic2 * wikiword.hashCode() + magic2 * content.hashCode();
127     }
128 }