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