KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.BundleUtil;
15 import org.eclipse.ui.internal.intro.impl.util.Log;
16 import org.osgi.framework.Bundle;
17 import org.w3c.dom.Element JavaDoc;
18 import org.w3c.dom.NodeList JavaDoc;
19
20 /**
21  * An intro HTML element. Can have text and image as fall back. "type" attribute
22  * in markup determines if it is inlined or not. if inlined, value of 'src' will
23  * be treated as a snippet of HTML to emit 'in-place'. If 'embed', a valid
24  * (full) HTML document will be embedded using HTML 'OBJECT' tag. Ecoding can be
25  * specified for inline snippets.
26  */

27 public class IntroHTML extends AbstractTextElement {
28
29     protected static final String JavaDoc TAG_HTML = "html"; //$NON-NLS-1$
30

31     private static final String JavaDoc ATT_SRC = "src"; //$NON-NLS-1$
32
/**
33      * type must be "inline" or "embed".
34      */

35     private static final String JavaDoc ATT_TYPE = "type"; //$NON-NLS-1$
36
// Default is UTF-8.
37
private static final String JavaDoc ATT_ENCODING = "encoding"; //$NON-NLS-1$
38

39     private String JavaDoc src;
40     private String JavaDoc html_type;
41     private String JavaDoc encoding;
42     private IntroImage introImage;
43
44     IntroHTML(Element JavaDoc element, Bundle bundle, String JavaDoc base) {
45         super(element, bundle);
46         src = getAttribute(element, ATT_SRC);
47         html_type = getAttribute(element, ATT_TYPE);
48         encoding = getAttribute(element, ATT_ENCODING);
49         if (encoding == null)
50             encoding = "UTF-8"; //$NON-NLS-1$
51
if (html_type != null && !html_type.equalsIgnoreCase("inline") //$NON-NLS-1$
52
&& !html_type.equalsIgnoreCase("embed")) //$NON-NLS-1$
53
// if type is not correct, null it.
54
html_type = null;
55
56         // description will be null if there is no description element.
57
introImage = getIntroImage(element, base);
58
59         // Resolve.
60
src = BundleUtil.getResolvedResourceLocation(base, src, bundle);
61     }
62
63     /**
64      * Retruns the intro image element embedded in this element.
65      */

66     private IntroImage getIntroImage(Element JavaDoc element, String JavaDoc base) {
67         try {
68             // There should only be one text element. Since elements where
69
// obtained by name, no point validating name.
70
NodeList JavaDoc imageElements = element
71                 .getElementsByTagName(IntroImage.TAG_IMAGE);
72             if (imageElements.getLength() == 0)
73                 // no contributions. done.
74
return null;
75             IntroImage image = new IntroImage((Element JavaDoc) imageElements.item(0),
76                 getBundle(), base);
77             image.setParent(this);
78             return image;
79         } catch (Exception JavaDoc e) {
80             Log.error(e.getMessage(), e);
81             return null;
82         }
83     }
84
85     /**
86      * Returns the html type. Will be either "inline" or "embed". If not, null
87      * will be returned as if the attibute was nto defined.
88      *
89      * @return Returns the html type value.
90      */

91     public boolean isInlined() {
92         return (html_type != null && html_type.equalsIgnoreCase("inline")) ? true //$NON-NLS-1$
93
: false;
94     }
95
96     /**
97      * @return Returns the src.
98      */

99     public String JavaDoc getSrc() {
100         return src;
101     }
102
103     /**
104      * @return Returns the encoding of the inlined file. This is not needed for
105      * embedded files. Default is UTF-8.
106      */

107     public String JavaDoc getInlineEncoding() {
108         return encoding;
109     }
110
111     /**
112      * Returns the intro image used as a replacement if this HTML element fails.
113      * May return null if there is no image child.
114      *
115      * @return Returns the introImage.
116      */

117     public IntroImage getIntroImage() {
118         return introImage;
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
125      */

126     public int getType() {
127         return AbstractIntroElement.HTML;
128     }
129
130     /**
131      * Deep copy since class has mutable objects.
132      */

133     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
134         IntroHTML clone = (IntroHTML) super.clone();
135         if (introImage != null) {
136             IntroImage cloneIntroImage = (IntroImage) introImage.clone();
137             cloneIntroImage.setParent(clone);
138             clone.introImage = cloneIntroImage;
139         }
140         return clone;
141     }
142
143 }
144
Popular Tags