001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.site;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.internal.core.isite.ISiteDescription;
016: import org.w3c.dom.Node;
017: import org.w3c.dom.NodeList;
018:
019: public class SiteDescription extends SiteObject implements
020: ISiteDescription {
021: private static final long serialVersionUID = 1L;
022: private String url;
023: private String text;
024:
025: /**
026: * @see org.eclipse.pde.internal.core.isite.ISiteDescription#getURL()
027: */
028: public String getURL() {
029: return url;
030: }
031:
032: /**
033: * @see org.eclipse.pde.internal.core.isite.ISiteDescription#getText()
034: */
035: public String getText() {
036: return text;
037: }
038:
039: /**
040: * @see org.eclipse.pde.internal.core.isite.ISiteDescription#setURL(java.net.URL)
041: */
042: public void setURL(String url) throws CoreException {
043: ensureModelEditable();
044: Object oldValue = this .url;
045: this .url = url;
046: firePropertyChanged(P_URL, oldValue, url);
047: }
048:
049: /**
050: * @see org.eclipse.pde.internal.core.isite.ISiteDescription#setText(java.lang.String)
051: */
052: public void setText(String text) throws CoreException {
053: ensureModelEditable();
054: Object oldValue = this .text;
055: this .text = text;
056: firePropertyChanged(P_TEXT, oldValue, text);
057: }
058:
059: protected void reset() {
060: url = null;
061: text = null;
062: }
063:
064: protected void parse(Node node) {
065: url = getNodeAttribute(node, "url"); //$NON-NLS-1$
066: NodeList children = node.getChildNodes();
067: for (int i = 0; i < children.getLength(); i++) {
068: Node child = children.item(i);
069: if (child.getNodeType() == Node.TEXT_NODE) {
070: Node firstChild = node.getFirstChild();
071: if (firstChild != null)
072: text = getNormalizedText(firstChild.getNodeValue());
073: break;
074: }
075: }
076: }
077:
078: public void restoreProperty(String name, Object oldValue,
079: Object newValue) throws CoreException {
080: if (name.equals(P_URL)) {
081: setURL(newValue != null ? newValue.toString() : null);
082: } else if (name.equals(P_TEXT)) {
083: setText(newValue != null ? newValue.toString() : null);
084: } else
085: super .restoreProperty(name, oldValue, newValue);
086: }
087:
088: public void write(String indent, PrintWriter writer) {
089: if ((url == null || url.length() <= 0)
090: && (text == null || text.trim().length() <= 0))
091: return;
092: writer.print(indent);
093: writer.print("<description"); //$NON-NLS-1$
094: if (url != null && url.length() > 0)
095: writer.print(" url=\"" + //$NON-NLS-1$
096: SiteObject.getWritableString(url) + "\""); //$NON-NLS-1$
097: writer.println(">"); //$NON-NLS-1$
098: if (text != null) {
099: writer
100: .println(indent
101: + Site.INDENT
102: + SiteObject
103: .getWritableString(getNormalizedText(text)));
104: }
105: writer.println(indent + "</description>"); //$NON-NLS-1$
106: }
107:
108: public boolean isValid() {
109: return true;
110: }
111:
112: }
|