1 11 package org.eclipse.pde.internal.core.site; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.internal.core.isite.ISiteDescription; 17 import org.w3c.dom.Node ; 18 import org.w3c.dom.NodeList ; 19 20 public class SiteDescription extends SiteObject implements ISiteDescription { 21 private static final long serialVersionUID = 1L; 22 private String url; 23 private String text; 24 25 28 public String getURL() { 29 return url; 30 } 31 32 35 public String getText() { 36 return text; 37 } 38 39 42 public void setURL(String url) throws CoreException { 43 ensureModelEditable(); 44 Object oldValue = this.url; 45 this.url = url; 46 firePropertyChanged(P_URL, oldValue, url); 47 } 48 49 52 public void setText(String text) throws CoreException { 53 ensureModelEditable(); 54 Object 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 node) { 65 url = getNodeAttribute(node, "url"); NodeList children = node.getChildNodes(); 67 for (int i=0; i<children.getLength(); i++) { 68 Node child = children.item(i); 69 if (child.getNodeType()==Node.TEXT_NODE) { 70 Node firstChild = node.getFirstChild(); 71 if (firstChild!=null) 72 text = getNormalizedText(firstChild.getNodeValue()); 73 break; 74 } 75 } 76 } 77 78 public void restoreProperty(String name, Object oldValue, Object 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 indent, PrintWriter 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"); if (url != null && url.length() > 0) 95 writer.print(" url=\"" + SiteObject.getWritableString(url) + "\""); writer.println(">"); if (text!=null) { 99 writer.println(indent + Site.INDENT + 100 SiteObject.getWritableString(getNormalizedText(text))); 101 } 102 writer.println(indent+"</description>"); } 104 public boolean isValid() { 105 return true; 106 } 107 108 } 109 | Popular Tags |