blob: dcafcb0a7f0a6b5e65c96a5f8c4393d1360eed00 (
plain) (
blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.intro.impl.model;
import org.eclipse.ui.internal.intro.impl.model.url.IntroURL;
import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
import org.osgi.framework.Bundle;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* An intro Link. This model class is responsible for parsing and creating an
* IntroURL class instance if the URL happens to be a valid intro url.
*/
public class IntroLink extends AbstractTextElement {
protected static final String TAG_LINK = "link"; //$NON-NLS-1$
private static final String ATT_LABEL = "label"; //$NON-NLS-1$
private static final String ATT_URL = "url"; //$NON-NLS-1$
private static final String TAG_IMG = "img"; //$NON-NLS-1$
private String label;
private String url;
private IntroImage img;
private IntroURL introURL;
/**
* @param element
*/
IntroLink(Element element, Bundle bundle, String base) {
super(element, bundle);
url = getAttribute(element, ATT_URL);
label = getAttribute(element, ATT_LABEL);
url = ModelUtil.resolveURL(base, url, bundle);
if (url != null) {
// check the URL.
IntroURLParser parser = new IntroURLParser(url);
if (parser.hasIntroUrl())
introURL = parser.getIntroURL();
}
// There should be at most one img element.
NodeList imgElements = element.getElementsByTagName(TAG_IMG);
if (imgElements.getLength() > 0) {
img = new IntroImage((Element) imgElements.item(0), getBundle(),
base);
img.setParent(this);
}
}
/**
* @return Returns the label.
*/
public String getLabel() {
return label;
}
/**
* @return Returns the url.
*/
public String getUrl() {
return url;
}
/**
* Retruns an IntroURL instance if link has a valid intro url. Returns null
* otherwise.
*
* @return Returns the introURL.
*/
public IntroURL getIntroURL() {
return introURL;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
*/
public int getType() {
return AbstractIntroElement.LINK;
}
/**
* @return Returns the img.
*/
public IntroImage getImg() {
return img;
}
/**
* Deep copy since class has mutable objects.
*/
public Object clone() throws CloneNotSupportedException {
IntroLink clone = (IntroLink) super.clone();
if (img != null) {
IntroImage cloneIntroImage = (IntroImage) img.clone();
cloneIntroImage.setParent(clone);
clone.img = cloneIntroImage;
}
// no need to clobe IntroURL.
return clone;
}
}
|