1 11 package org.eclipse.pde.internal.core.site; 12 13 import java.io.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.pde.core.*; 17 import org.eclipse.pde.internal.core.*; 18 import org.eclipse.pde.internal.core.isite.*; 19 import org.w3c.dom.*; 20 21 public abstract class SiteBuildObject 22 extends PlatformObject 23 implements ISiteBuildObject { 24 transient ISiteBuildModel model; 25 transient ISiteBuildObject parent; 26 boolean inTheModel; 27 28 void setInTheModel(boolean value) { 29 inTheModel = value; 30 } 31 32 public boolean isInTheModel() { 33 return inTheModel; 34 } 35 36 protected void ensureModelEditable() throws CoreException { 37 if (!model.isEditable()) { 38 throwCoreException(PDECore.getResourceString("SiteBuildObject.readOnlyException")); } 40 } 41 protected void firePropertyChanged( 42 String property, 43 Object oldValue, 44 Object newValue) { 45 firePropertyChanged(this, property, oldValue, newValue); 46 } 47 protected void firePropertyChanged( 48 ISiteBuildObject object, 49 String property, 50 Object oldValue, 51 Object newValue) { 52 if (model.isEditable() && model instanceof IModelChangeProvider) { 53 IModelChangeProvider provider = (IModelChangeProvider) model; 54 provider.fireModelObjectChanged(object, property, oldValue, newValue); 55 } 56 } 57 protected void fireStructureChanged(ISiteBuildObject child, int changeType) { 58 fireStructureChanged(new ISiteBuildObject[] { child }, changeType); 59 } 60 protected void fireStructureChanged( 61 ISiteBuildObject[] children, 62 int changeType) { 63 ISiteBuildModel model = getModel(); 64 if (model.isEditable() && model instanceof IModelChangeProvider) { 65 IModelChangeProvider provider = (IModelChangeProvider) model; 66 provider.fireModelChanged(new ModelChangedEvent(provider, changeType, children, null)); 67 } 68 } 69 public ISiteBuild getSiteBuild() { 70 return model.getSiteBuild(); 71 } 72 73 public ISiteBuildModel getModel() { 74 return model; 75 } 76 77 String getNodeAttribute(Node node, String name) { 78 NamedNodeMap atts = node.getAttributes(); 79 Node attribute = null; 80 if (atts != null) 81 attribute = atts.getNamedItem(name); 82 if (attribute != null) 83 return attribute.getNodeValue(); 84 return null; 85 } 86 87 int getIntegerAttribute(Node node, String name) { 88 String value = getNodeAttribute(node, name); 89 if (value != null) { 90 try { 91 return Integer.parseInt(value); 92 } catch (NumberFormatException e) { 93 } 94 } 95 return 0; 96 } 97 98 boolean getBooleanAttribute(Node node, String name) { 99 String value = getNodeAttribute(node, name); 100 if (value != null) { 101 return value.equalsIgnoreCase("true"); } 103 return false; 104 } 105 106 public ISiteBuildObject getParent() { 107 return parent; 108 } 109 110 protected void reset() { 111 } 112 113 protected void throwCoreException(String message) throws CoreException { 114 Status status = 115 new Status(IStatus.ERROR, PDECore.getPluginId(), IStatus.OK, message, null); 116 throw new CoreException(status); 117 } 118 119 public static String getWritableString(String source) { 120 if (source == null) 121 return ""; StringBuffer buf = new StringBuffer (); 123 for (int i = 0; i < source.length(); i++) { 124 char c = source.charAt(i); 125 switch (c) { 126 case '&' : 127 buf.append("&"); break; 129 case '<' : 130 buf.append("<"); break; 132 case '>' : 133 buf.append(">"); break; 135 case '\'' : 136 buf.append("'"); break; 138 case '\"' : 139 buf.append("""); break; 141 default : 142 buf.append(c); 143 break; 144 } 145 } 146 return buf.toString(); 147 } 148 149 public void restoreProperty(String name, Object oldValue, Object newValue) 150 throws CoreException { 151 } 152 153 public void write(String indent, PrintWriter writer) { 154 } 155 156 public void setModel(ISiteBuildModel model) { 157 this.model = model; 158 } 159 160 public void setParent(ISiteBuildObject parent) { 161 this.parent = parent; 162 } 163 } 164 | Popular Tags |