KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > cheatsheet > simple > SimpleCSIntro


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.core.cheatsheet.simple;
13
14 import java.io.IOException JavaDoc;
15 import java.io.PrintWriter JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.pde.internal.core.PDECoreMessages;
20 import org.eclipse.pde.internal.core.XMLPrintHandler;
21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSDescription;
22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro;
23 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel;
24 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModelFactory;
25 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
26 import org.eclipse.pde.internal.core.util.PDETextHelper;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.NodeList JavaDoc;
30
31 /**
32  * SimpleCSIntro
33  *
34  */

35 public class SimpleCSIntro extends SimpleCSObject implements ISimpleCSIntro {
36
37     /**
38      * Element: description
39      */

40     private ISimpleCSDescription fDescription;
41     
42     /**
43      * Attribute: contextId
44      */

45     private String JavaDoc fContextId;
46     
47     /**
48      * Attribute: href
49      */

50     private String JavaDoc fHref;
51     
52     /**
53      *
54      */

55     private static final long serialVersionUID = 1L;
56
57     /**
58      * @param model
59      * @param parent
60      */

61     public SimpleCSIntro(ISimpleCSModel model, ISimpleCSObject parent) {
62         super(model, parent);
63         reset();
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#getContextId()
68      */

69     public String JavaDoc getContextId() {
70         return fContextId;
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#getDescription()
75      */

76     public ISimpleCSDescription getDescription() {
77         return fDescription;
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#getHref()
82      */

83     public String JavaDoc getHref() {
84         return fHref;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#setContextId(java.lang.String)
89      */

90     public void setContextId(String JavaDoc contextId) {
91         String JavaDoc old = fContextId;
92         fContextId = contextId;
93         if (isEditable()) {
94             firePropertyChanged(ATTRIBUTE_CONTEXTID, old, fContextId);
95         }
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#setDescription(java.lang.String)
100      */

101     public void setDescription(ISimpleCSDescription description) {
102         ISimpleCSObject old = fDescription;
103         fDescription = description;
104
105         if (isEditable()) {
106             fireStructureChanged(description, old);
107         }
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#setHref(java.lang.String)
112      */

113     public void setHref(String JavaDoc href) {
114         String JavaDoc old = fHref;
115         fHref = href;
116         if (isEditable()) {
117             firePropertyChanged(ATTRIBUTE_HREF, old, fHref);
118         }
119     }
120
121     /**
122      * @param node
123      */

124     public void parse(Element JavaDoc element) {
125         // Process contextId attribute
126
fContextId = element.getAttribute(ATTRIBUTE_CONTEXTID).trim();
127         // Process href attribute
128
fHref = element.getAttribute(ATTRIBUTE_HREF).trim();
129         // Process children
130
NodeList JavaDoc children = element.getChildNodes();
131         ISimpleCSModelFactory factory = getModel().getFactory();
132         for (int i = 0; i < children.getLength(); i++) {
133             Node JavaDoc child = children.item(i);
134             if (child.getNodeType() == Node.ELEMENT_NODE) {
135                 Element JavaDoc childElement = (Element JavaDoc)child;
136                 String JavaDoc name = child.getNodeName();
137                 if (name.equals(ELEMENT_DESCRIPTION)) {
138                     fDescription = factory.createSimpleCSDescription(this);
139                     fDescription.parse(childElement);
140                 }
141             }
142         }
143     }
144
145     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
146
147         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
148         String JavaDoc newIndent = indent + XMLPrintHandler.XML_INDENT;
149         
150         try {
151             // Print intro element
152
buffer.append(ELEMENT_INTRO); //$NON-NLS-1$
153
// Print contextId attribute
154
// Print href attribute
155
if ((fContextId != null) &&
156                     (fContextId.length() > 0)) {
157                 buffer.append(XMLPrintHandler.wrapAttribute(
158                         ATTRIBUTE_CONTEXTID,
159                         PDETextHelper.translateWriteText(
160                                 fContextId.trim(), SUBSTITUTE_CHARS)));
161             } else if ((fHref != null) &&
162                             (fHref.length() > 0)) {
163                 buffer.append(XMLPrintHandler.wrapAttribute(
164                         ATTRIBUTE_HREF,
165                         PDETextHelper.translateWriteText(
166                                 fHref.trim(), SUBSTITUTE_CHARS)));
167             }
168             // Start element
169
XMLPrintHandler.printBeginElement(writer, buffer.toString(),
170                     indent, false);
171             // Print description element
172
if (fDescription != null) {
173                 fDescription.write(newIndent, writer);
174             }
175             // End element
176
XMLPrintHandler.printEndElement(writer, ELEMENT_INTRO, indent);
177             
178         } catch (IOException JavaDoc e) {
179             // Suppress
180
//e.printStackTrace();
181
}
182     }
183
184     /* (non-Javadoc)
185      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro#reset()
186      */

187     public void reset() {
188         fDescription = null;
189         fContextId = null;
190         fHref = null;
191     }
192
193     /* (non-Javadoc)
194      * @see org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject#getType()
195      */

196     public int getType() {
197         return TYPE_INTRO;
198     }
199
200     /* (non-Javadoc)
201      * @see org.eclipse.pde.internal.core.cheatsheet.simple.SimpleCSObject#getName()
202      */

203     public String JavaDoc getName() {
204         return PDECoreMessages.SimpleCSIntro_0;
205     }
206
207     /* (non-Javadoc)
208      * @see org.eclipse.pde.internal.core.cheatsheet.simple.SimpleCSObject#getChildren()
209      */

210     public List JavaDoc getChildren() {
211         return new ArrayList JavaDoc();
212     }
213
214 }
215
Popular Tags