001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.intro.impl.model;
011:
012: import org.eclipse.ui.internal.intro.impl.model.url.IntroURL;
013: import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
014: import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
015: import org.osgi.framework.Bundle;
016: import org.w3c.dom.Element;
017: import org.w3c.dom.NodeList;
018:
019: /**
020: * An intro Link. This model class is responsible for parsing and creating an
021: * IntroURL class instance if the URL happens to be a valid intro url.
022: */
023: public class IntroLink extends AbstractTextElement {
024:
025: protected static final String TAG_LINK = "link"; //$NON-NLS-1$
026:
027: private static final String ATT_LABEL = "label"; //$NON-NLS-1$
028: private static final String ATT_URL = "url"; //$NON-NLS-1$
029: private static final String TAG_IMG = "img"; //$NON-NLS-1$
030:
031: private String label;
032: private String url;
033: private IntroImage img;
034: private IntroURL introURL;
035:
036: /**
037: * @param element
038: */
039: IntroLink(Element element, Bundle bundle, String base) {
040: super (element, bundle);
041: url = getAttribute(element, ATT_URL);
042: label = getAttribute(element, ATT_LABEL);
043:
044: url = ModelUtil.resolveURL(base, url, bundle);
045: if (url != null) {
046: // check the URL.
047: IntroURLParser parser = new IntroURLParser(url);
048: if (parser.hasIntroUrl())
049: introURL = parser.getIntroURL();
050: }
051:
052: // There should be at most one img element.
053: NodeList imgElements = element.getElementsByTagName(TAG_IMG);
054: if (imgElements.getLength() > 0) {
055: img = new IntroImage((Element) imgElements.item(0),
056: getBundle(), base);
057: img.setParent(this );
058: }
059: }
060:
061: /**
062: * @return Returns the label.
063: */
064: public String getLabel() {
065: return label;
066: }
067:
068: /**
069: * @return Returns the url.
070: */
071: public String getUrl() {
072: return url;
073: }
074:
075: /**
076: * Retruns an IntroURL instance if link has a valid intro url. Returns null
077: * otherwise.
078: *
079: * @return Returns the introURL.
080: */
081: public IntroURL getIntroURL() {
082: return introURL;
083: }
084:
085: /*
086: * (non-Javadoc)
087: *
088: * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
089: */
090: public int getType() {
091: return AbstractIntroElement.LINK;
092: }
093:
094: /**
095: * @return Returns the img.
096: */
097: public IntroImage getImg() {
098: return img;
099: }
100:
101: /**
102: * Deep copy since class has mutable objects.
103: */
104: public Object clone() throws CloneNotSupportedException {
105: IntroLink clone = (IntroLink) super .clone();
106: if (img != null) {
107: IntroImage cloneIntroImage = (IntroImage) img.clone();
108: cloneIntroImage.setParent(clone);
109: clone.img = cloneIntroImage;
110: }
111: // no need to clobe IntroURL.
112: return clone;
113: }
114: }
|