KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.osgi.framework.Bundle;
15 import org.w3c.dom.Element JavaDoc;
16 import org.w3c.dom.Node JavaDoc;
17
18 /**
19  * An intro text element.
20  */

21 public class IntroText extends AbstractBaseIntroElement {
22
23     protected static final String JavaDoc TAG_TEXT = "text"; //$NON-NLS-1$
24

25     private String JavaDoc text;
26     /**
27      * boolean flag which is true if the text element contains CData content.
28      * which means we would have to model it as formatted text.
29      */

30     private boolean isFormatted = false;
31
32     IntroText(Element JavaDoc element, Bundle bundle) {
33         super(element, bundle);
34         Node JavaDoc textNode = element.getFirstChild();
35         if (textNode == null)
36             return;
37         if (textNode.getNodeType() == Node.TEXT_NODE
38                 || textNode.getNodeType() == Node.CDATA_SECTION_NODE) {
39             // we may have a text or a CDATA nodes.
40
text = textNode.getNodeValue();
41             isFormatted = checkIfFormatted();
42         }
43     }
44
45     /**
46      * @return Returns the text description.
47      */

48     public String JavaDoc getText() {
49         IntroModelRoot root = getModelRoot();
50         if (root!=null)
51             return root.resolveVariables(text);
52         return text;
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.eclipse.ui.internal.intro.impl.model.IntroElement#getType()
59      */

60     public int getType() {
61         return AbstractIntroElement.TEXT;
62     }
63
64     /**
65      * @return true if the content of this text element has any " <" which makes
66      * it formatted.
67      */

68     public boolean checkIfFormatted() {
69         if (text == null)
70             return false;
71         int i = text.indexOf("<"); //$NON-NLS-1$
72
return i == -1 ? false : true;
73     }
74
75
76     /**
77      * @return Returns the isFormatted.
78      */

79     public boolean isFormatted() {
80         return isFormatted;
81     }
82 }
83
Popular Tags