1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*******************************************************************************
* Copyright (c) 2015 David Green.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* David Green - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.wikitext.commonmark.internal.inlines;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.Objects;
import org.eclipse.mylyn.wikitext.commonmark.internal.Line;
import org.eclipse.mylyn.wikitext.commonmark.internal.ToStringHelper;
import org.eclipse.mylyn.wikitext.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.parser.ImageAttributes;
public class Image extends InlineWithNestedContents {
private final String src;
private final String title;
public Image(Line line, int offset, int length, String src, String title, List<Inline> contents) {
super(line, offset, length, contents);
this.src = checkNotNull(src);
this.title = title;
}
public String getHref() {
return src;
}
@Override
public void emit(DocumentBuilder builder) {
ImageAttributes attributes = new ImageAttributes();
attributes.setTitle(title);
List<Inline> contents = getContents();
if (!contents.isEmpty()) {
attributes.setAlt(InlineParser.toStringContent(contents));
}
builder.image(attributes, src);
}
@Override
public int hashCode() {
return Objects.hash(getOffset(), getLength(), getContents(), src, title);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
Image other = (Image) obj;
return src.equals(other.src) && getContents().equals(other.getContents()) && Objects.equals(title, other.title);
}
@Override
public String toString() {
return com.google.common.base.Objects.toStringHelper(Image.class)
.add("offset", getOffset())
.add("length", getLength())
.add("src", ToStringHelper.toStringValue(src))
.add("title", title)
.add("contents", getContents())
.toString();
}
}
|