1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.PrintWriter ; 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement; 19 import org.w3c.dom.Node ; 20 21 public class FeatureURLElement 22 extends FeatureObject 23 implements IFeatureURLElement { 24 private static final long serialVersionUID = 1L; 25 private int fElementType; 26 private int fSiteType = UPDATE_SITE; 27 private URL fUrl; 28 29 public FeatureURLElement(int elementType) { 30 this.fElementType = elementType; 31 } 32 public FeatureURLElement(int elementType, URL url) { 33 this.fElementType = elementType; 34 this.fUrl = url; 35 } 36 public int getElementType() { 37 return fElementType; 38 } 39 public URL getURL() { 40 return fUrl; 41 } 42 public int getSiteType() { 43 return fSiteType; 44 } 45 protected void parse(Node node) { 46 super.parse(node); 47 String urlName = getNodeAttribute(node, "url"); try { 49 if(urlName!=null) 50 fUrl = new URL (urlName); 51 } catch (MalformedURLException e) { 52 } 53 String typeName = getNodeAttribute(node, "type"); if (typeName != null && typeName.equals("web")) fSiteType = WEB_SITE; 56 } 57 58 public void setURL(URL url) throws CoreException { 59 ensureModelEditable(); 60 Object oldValue = this.fUrl; 61 this.fUrl = url; 62 firePropertyChanged(this, P_URL, oldValue, url); 63 } 64 65 public void setSiteType(int type) throws CoreException { 66 ensureModelEditable(); 67 Integer oldValue = new Integer (this.fSiteType); 68 this.fSiteType = type; 69 firePropertyChanged(this, P_URL, oldValue, new Integer (type)); 70 } 71 72 public void restoreProperty(String name, Object oldValue, Object newValue) 73 throws CoreException { 74 if (name.equals(P_URL)) { 75 setURL((URL ) newValue); 76 } else if (name.equals(P_SITE_TYPE)) { 77 setSiteType(((Integer ) newValue).intValue()); 78 } else 79 super.restoreProperty(name, oldValue, newValue); 80 } 81 82 public String toString() { 83 if (label != null) 84 return label; 85 if (fUrl != null) 86 return fUrl.toString(); 87 return super.toString(); 88 } 89 public void write(String indent, PrintWriter writer) { 90 String tag = null; 91 switch (fElementType) { 92 case UPDATE : 93 tag = "update"; break; 95 case DISCOVERY : 96 tag = "discovery"; break; 98 } 99 if (tag == null) 100 return; 101 writer.print(indent + "<" + tag); if (label != null && label.length()>0) { 103 writer.print(" label=\"" + getWritableString(label) + "\""); } 105 if (fUrl != null) { 106 writer.print(" url=\"" + getWritableString(fUrl.toString()) + "\""); } 108 if (fSiteType == WEB_SITE) { 109 writer.print(" type=\"web\""); } 111 writer.println("/>"); } 113 } 114 | Popular Tags |