01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.intro.impl.model;
11:
12: import org.osgi.framework.Bundle;
13: import org.w3c.dom.Element;
14: import org.w3c.dom.Node;
15:
16: /**
17: * An intro text element.
18: */
19: public class IntroText extends AbstractBaseIntroElement {
20:
21: protected static final String TAG_TEXT = "text"; //$NON-NLS-1$
22:
23: private String text;
24: /**
25: * boolean flag which is true if the text element contains CData content.
26: * which means we would have to model it as formatted text.
27: */
28: private boolean isFormatted = false;
29:
30: IntroText(Element element, Bundle bundle) {
31: super (element, bundle);
32: Node textNode = element.getFirstChild();
33: if (textNode == null)
34: return;
35: if (textNode.getNodeType() == Node.TEXT_NODE
36: || textNode.getNodeType() == Node.CDATA_SECTION_NODE) {
37: // we may have a text or a CDATA nodes.
38: text = textNode.getNodeValue();
39: isFormatted = checkIfFormatted();
40: }
41: }
42:
43: /**
44: * @return Returns the text description.
45: */
46: public String getText() {
47: IntroModelRoot root = getModelRoot();
48: if (root != null)
49: return root.resolveVariables(text);
50: return text;
51: }
52:
53: /*
54: * (non-Javadoc)
55: *
56: * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
57: */
58: public int getType() {
59: return AbstractIntroElement.TEXT;
60: }
61:
62: /**
63: * @return true if the content of this text element has any " <" which makes
64: * it formatted.
65: */
66: public boolean checkIfFormatted() {
67: if (text == null)
68: return false;
69: int i = text.indexOf("<"); //$NON-NLS-1$
70: return i == -1 ? false : true;
71: }
72:
73: /**
74: * @return Returns the isFormatted.
75: */
76: public boolean isFormatted() {
77: return isFormatted;
78: }
79: }
|