KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > product > AboutInfo


1 /*******************************************************************************
2  * Copyright (c) 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 package org.eclipse.pde.internal.core.product;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.pde.internal.core.iproduct.IAboutInfo;
16 import org.eclipse.pde.internal.core.iproduct.IProductModel;
17 import org.w3c.dom.Element JavaDoc;
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20 import org.w3c.dom.Text JavaDoc;
21
22
23 public class AboutInfo extends ProductObject implements IAboutInfo {
24
25     private static final long serialVersionUID = 1L;
26     private String JavaDoc fImagePath;
27     private String JavaDoc fAboutText;
28
29     public AboutInfo(IProductModel model) {
30         super(model);
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#setText(java.lang.String)
35      */

36     public void setText(String JavaDoc text) {
37         String JavaDoc old = fAboutText;
38         fAboutText = text;
39         if (isEditable())
40             firePropertyChanged(P_TEXT, old, fAboutText);
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#getText()
45      */

46     public String JavaDoc getText() {
47         return fAboutText;
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#setImagePath(java.lang.String)
52      */

53     public void setImagePath(String JavaDoc path) {
54         String JavaDoc old = fImagePath;
55         fImagePath = path;
56         if (isEditable())
57             firePropertyChanged(P_IMAGE, old, fImagePath);
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#getImagePath()
62      */

63     public String JavaDoc getImagePath() {
64         return fImagePath;
65     }
66     
67     /* (non-Javadoc)
68      * @see org.eclipse.pde.internal.core.product.ProductObject#write(java.lang.String, java.io.PrintWriter)
69      */

70     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
71         if (isAboutImageDefined() || isAboutTextDefined()) {
72             writer.println(indent + "<aboutInfo>"); //$NON-NLS-1$
73
if (isAboutImageDefined())
74                 writer.println(indent + " <image path=\"" + getWritableString(fImagePath.trim()) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
75
if (isAboutTextDefined()) {
76                 writer.println(indent + " <text>"); //$NON-NLS-1$
77
writer.println(indent + " " + getWritableString(fAboutText.trim())); //$NON-NLS-1$
78
writer.println(indent + " </text>"); //$NON-NLS-1$
79
}
80             writer.println(indent + "</aboutInfo>"); //$NON-NLS-1$
81
}
82     }
83     
84     private boolean isAboutTextDefined() {
85         return fAboutText != null && fAboutText.length() > 0;
86     }
87     
88     private boolean isAboutImageDefined() {
89         return fImagePath != null && fImagePath.length() > 0;
90     }
91     
92     /* (non-Javadoc)
93      * @see org.eclipse.pde.internal.core.iproduct.IProductObject#parse(org.w3c.dom.Node)
94      */

95     public void parse(Node JavaDoc node) {
96         NodeList JavaDoc children = node.getChildNodes();
97         for (int i = 0; i < children.getLength(); i++) {
98             Node JavaDoc child = children.item(i);
99             if (child.getNodeType() == Node.ELEMENT_NODE) {
100                 if (child.getNodeName().equals("image")) { //$NON-NLS-1$
101
fImagePath = ((Element JavaDoc)child).getAttribute("path"); //$NON-NLS-1$
102
} else if (child.getNodeName().equals("text")) { //$NON-NLS-1$
103
child.normalize();
104                     if (child.getChildNodes().getLength() > 0) {
105                         Node JavaDoc text = child.getFirstChild();
106                         if (text.getNodeType() == Node.TEXT_NODE)
107                             fAboutText = ((Text JavaDoc)text).getData().trim();
108                     }
109                 }
110             }
111         }
112     }
113     
114 }
115
Popular Tags