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   * Block that represents a link.
26   *
27   * @author Juan F. Codagnone
28   */
29  class LinkBlock
30      implements Block
31  {
32      /**
33       * link reference
34       */
35      private final String reference;
36  
37      /**
38       * link text
39       */
40      private final Block content;
41  
42      /**
43       * Creates the LinkBlock.
44       *
45       * @param reference reference anchor
46       * @param text text to display
47       * @deprecated
48       */
49      LinkBlock( final String reference, final String text )
50      {
51          this( reference, new TextBlock( text ) );
52      }
53  
54      /**
55       * Creates the LinkBlock.
56       *
57       * @param reference reference anchor, not null.
58       * @param content block with the displayed content, not null.
59       */
60      LinkBlock( final String reference, final Block content )
61      {
62          if ( reference == null || content == null )
63          {
64              throw new IllegalArgumentException( "arguments can't be null" );
65          }
66          this.reference = reference;
67          this.content = content;
68      }
69  
70      /** {@inheritDoc} */
71      public final void traverse( final Sink sink )
72      {
73          sink.link( reference );
74          content.traverse( sink );
75          sink.link_();
76  
77      }
78  
79      /** {@inheritDoc} */
80      public final boolean equals( final Object obj )
81      {
82          boolean ret = false;
83  
84          if ( obj == this )
85          {
86              ret = true;
87          }
88          else if ( obj instanceof LinkBlock )
89          {
90              final LinkBlock l = (LinkBlock) obj;
91              ret = reference.equals( l.reference ) && content.equals( l.content );
92          }
93  
94          return ret;
95      }
96  
97      /**
98       * {@inheritDoc}
99       *
100      * @return a int.
101      */
102     public final int hashCode()
103     {
104         final int magic1 = 17;
105         final int magic2 = 37;
106 
107         return magic1 + magic2 * reference.hashCode() + magic2 * content.hashCode();
108     }
109 }