1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.internal.core.PDECoreMessages; 17 import org.eclipse.pde.internal.core.ifeature.IFeature; 18 import org.eclipse.pde.internal.core.ifeature.IFeatureInfo; 19 import org.w3c.dom.Node ; 20 21 public class FeatureInfo extends FeatureObject implements IFeatureInfo { 22 private static final long serialVersionUID = 1L; 23 private String url; 24 private String description; 25 private int index; 26 27 public FeatureInfo(int index) { 28 this.index = index; 29 } 30 31 public int getIndex() { 32 return index; 33 } 34 35 private String getTag() { 36 return IFeature.INFO_TAGS[index]; 37 } 38 39 42 public String getURL() { 43 return url; 44 } 45 46 49 public String getDescription() { 50 return description; 51 } 52 53 56 public void setURL(String url) throws CoreException { 57 ensureModelEditable(); 58 Object oldValue = this.url; 59 this.url = url; 60 firePropertyChanged(P_URL, oldValue, url); 61 } 62 63 public void restoreProperty(String name, Object oldValue, Object newValue) 64 throws CoreException { 65 if (name.equals(P_DESC)) { 66 setDescription(newValue != null ? newValue.toString() : null); 67 } else if (name.equals(P_URL)) { 68 setURL(newValue != null ? newValue.toString() : null); 69 } else 70 super.restoreProperty(name, oldValue, newValue); 71 } 72 73 76 public void setDescription(String description) throws CoreException { 77 ensureModelEditable(); 78 Object oldValue = this.description; 79 this.description = description; 80 firePropertyChanged(P_DESC, oldValue, description); 81 } 82 protected void parse(Node node) { 83 url = getNodeAttribute(node, "url"); Node firstChild = node.getFirstChild(); 85 if (firstChild!=null) 86 description = getNormalizedText(firstChild.getNodeValue()); 87 } 88 89 public void write(String indent, PrintWriter writer) { 90 String indent2 = indent + Feature.INDENT; 91 String desc = description!=null?getWritableString(description.trim()):null; 92 writer.println(); 93 writer.print(indent + "<" + getTag()); if (url != null) { 95 writer.print(" url=\"" + getWritableString(url) + "\""); } 97 writer.println(">"); if (desc!=null) writer.println(indent2 + desc); 99 writer.println(indent + "</" + getTag() + ">"); } 101 102 public boolean isEmpty() { 103 if (url != null) 104 return false; 105 String desc = description != null ? description.trim() : null; 106 if (desc != null && desc.length() > 0) 107 return false; 108 return true; 109 } 110 111 public String toString() { 112 switch (index) { 113 case IFeature.INFO_DESCRIPTION : 114 return PDECoreMessages.FeatureInfo_description; 115 case IFeature.INFO_LICENSE : 116 return PDECoreMessages.FeatureInfo_license; 117 case IFeature.INFO_COPYRIGHT : 118 return PDECoreMessages.FeatureInfo_copyright; 119 } 120 return super.toString(); 121 } 122 } 123 | Popular Tags |