KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > site > SiteDescription


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.pde.internal.core.site;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.internal.core.isite.ISiteDescription;
17 import org.w3c.dom.Node JavaDoc;
18 import org.w3c.dom.NodeList JavaDoc;
19
20 public class SiteDescription extends SiteObject implements ISiteDescription {
21     private static final long serialVersionUID = 1L;
22     private String JavaDoc url;
23     private String JavaDoc text;
24
25     /**
26      * @see org.eclipse.pde.internal.core.isite.ISiteDescription#getURL()
27      */

28     public String JavaDoc getURL() {
29         return url;
30     }
31
32     /**
33      * @see org.eclipse.pde.internal.core.isite.ISiteDescription#getText()
34      */

35     public String JavaDoc getText() {
36         return text;
37     }
38
39     /**
40      * @see org.eclipse.pde.internal.core.isite.ISiteDescription#setURL(java.net.URL)
41      */

42     public void setURL(String JavaDoc url) throws CoreException {
43         ensureModelEditable();
44         Object JavaDoc oldValue = this.url;
45         this.url = url;
46         firePropertyChanged(P_URL, oldValue, url);
47     }
48
49     /**
50      * @see org.eclipse.pde.internal.core.isite.ISiteDescription#setText(java.lang.String)
51      */

52     public void setText(String JavaDoc text) throws CoreException {
53         ensureModelEditable();
54         Object JavaDoc oldValue = this.text;
55         this.text = text;
56         firePropertyChanged(P_TEXT, oldValue, text);
57     }
58
59     protected void reset() {
60         url = null;
61         text = null;
62     }
63
64     protected void parse(Node JavaDoc node) {
65         url = getNodeAttribute(node, "url"); //$NON-NLS-1$
66
NodeList JavaDoc children = node.getChildNodes();
67         for (int i=0; i<children.getLength(); i++) {
68             Node JavaDoc child = children.item(i);
69             if (child.getNodeType()==Node.TEXT_NODE) {
70                 Node JavaDoc firstChild = node.getFirstChild();
71                 if (firstChild!=null)
72                     text = getNormalizedText(firstChild.getNodeValue());
73                 break;
74             }
75         }
76     }
77
78     public void restoreProperty(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue)
79         throws CoreException {
80         if (name.equals(P_URL)) {
81             setURL(newValue != null ? newValue.toString() : null);
82         } else if (name.equals(P_TEXT)) {
83             setText(newValue != null ? newValue.toString() : null);
84         } else
85             super.restoreProperty(name, oldValue, newValue);
86     }
87     
88     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
89         if ((url == null || url.length() <= 0)
90                 && (text == null || text.trim().length() <= 0))
91             return;
92         writer.print(indent);
93         writer.print("<description"); //$NON-NLS-1$
94
if (url != null && url.length() > 0)
95             writer.print(" url=\"" + //$NON-NLS-1$
96
SiteObject.getWritableString(url) + "\""); //$NON-NLS-1$
97
writer.println(">"); //$NON-NLS-1$
98
if (text!=null) {
99             writer.println(indent + Site.INDENT +
100                     SiteObject.getWritableString(getNormalizedText(text)));
101         }
102         writer.println(indent+"</description>"); //$NON-NLS-1$
103
}
104     public boolean isValid() {
105         return true;
106     }
107
108 }
109
Popular Tags