KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > IntroLink


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.intro.impl.model;
13
14 import org.eclipse.ui.internal.intro.impl.model.url.IntroURL;
15 import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
16 import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
17 import org.osgi.framework.Bundle;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 /**
22  * An intro Link. This model class is responsible for parsing and creating an
23  * IntroURL class instance if the URL happens to be a valid intro url.
24  */

25 public class IntroLink extends AbstractTextElement {
26
27     protected static final String JavaDoc TAG_LINK = "link"; //$NON-NLS-1$
28

29     private static final String JavaDoc ATT_LABEL = "label"; //$NON-NLS-1$
30
private static final String JavaDoc ATT_URL = "url"; //$NON-NLS-1$
31
private static final String JavaDoc TAG_IMG = "img"; //$NON-NLS-1$
32

33     private String JavaDoc label;
34     private String JavaDoc url;
35     private IntroImage img;
36     private IntroURL introURL;
37
38     /**
39      * @param element
40      */

41     IntroLink(Element JavaDoc element, Bundle bundle, String JavaDoc base) {
42         super(element, bundle);
43         url = getAttribute(element, ATT_URL);
44         label = getAttribute(element, ATT_LABEL);
45
46         url = ModelUtil.resolveURL(base, url, bundle);
47         if (url != null) {
48             // check the URL.
49
IntroURLParser parser = new IntroURLParser(url);
50             if (parser.hasIntroUrl())
51                 introURL = parser.getIntroURL();
52         }
53
54         // There should be at most one img element.
55
NodeList JavaDoc imgElements = element.getElementsByTagName(TAG_IMG);
56         if (imgElements.getLength() > 0) {
57             img = new IntroImage((Element JavaDoc) imgElements.item(0), getBundle(),
58                 base);
59             img.setParent(this);
60         }
61     }
62
63     /**
64      * @return Returns the label.
65      */

66     public String JavaDoc getLabel() {
67         return label;
68     }
69
70     /**
71      * @return Returns the url.
72      */

73     public String JavaDoc getUrl() {
74         return url;
75     }
76
77     /**
78      * Retruns an IntroURL instance if link has a valid intro url. Returns null
79      * otherwise.
80      *
81      * @return Returns the introURL.
82      */

83     public IntroURL getIntroURL() {
84         return introURL;
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
91      */

92     public int getType() {
93         return AbstractIntroElement.LINK;
94     }
95
96     /**
97      * @return Returns the img.
98      */

99     public IntroImage getImg() {
100         return img;
101     }
102
103     /**
104      * Deep copy since class has mutable objects.
105      */

106     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
107         IntroLink clone = (IntroLink) super.clone();
108         if (img != null) {
109             IntroImage cloneIntroImage = (IntroImage) img.clone();
110             cloneIntroImage.setParent(clone);
111             clone.img = cloneIntroImage;
112         }
113         // no need to clobe IntroURL.
114
return clone;
115     }
116 }
117
Popular Tags