1 11 package org.eclipse.pde.internal.core.site; 12 13 import java.io.*; 14 import java.util.*; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.pde.core.*; 18 import org.eclipse.pde.internal.core.isite.*; 19 import org.w3c.dom.*; 20 21 29 public class SiteBuild extends SiteBuildObject implements ISiteBuild { 30 final static String INDENT = " "; private Vector features = new Vector(); 32 public static final String DEFAULT_PLUGIN_DIR = "plugins"; public static final String DEFAULT_FEATURE_DIR = "features"; private final IPath pluginLocation = new Path(DEFAULT_PLUGIN_DIR); 35 private final IPath featureLocation = new Path(DEFAULT_FEATURE_DIR); 36 private boolean useConsole; 37 private boolean autobuild; 38 private boolean scrubOutput; 39 40 41 44 public IPath getPluginLocation() { 45 return pluginLocation; 46 } 47 48 51 public IPath getFeatureLocation() { 52 return featureLocation; 53 } 54 55 public void setAutobuild(boolean value) throws CoreException { 56 ensureModelEditable(); 57 Object oldValue = new Boolean (this.autobuild); 58 this.autobuild = value; 59 firePropertyChanged(P_AUTOBUILD, oldValue, new Boolean (value)); 60 } 61 62 public boolean isAutobuild() { 63 return autobuild; 64 } 65 66 public void setScrubOutput(boolean value) throws CoreException { 67 ensureModelEditable(); 68 Object oldValue = new Boolean (this.scrubOutput); 69 this.scrubOutput = value; 70 firePropertyChanged(P_AUTOBUILD, oldValue, new Boolean (value)); 71 } 72 73 public boolean getScrubOutput() { 74 return scrubOutput; 75 } 76 77 public void setShowConsole(boolean value) throws CoreException { 78 ensureModelEditable(); 79 Object oldValue = new Boolean (this.useConsole); 80 this.useConsole = value; 81 firePropertyChanged(P_SHOW_CONSOLE, oldValue, new Boolean (value)); 82 } 83 84 public boolean getShowConsole() { 85 return useConsole; 86 } 87 88 91 public void addFeatures(ISiteBuildFeature[] newFeatures) throws CoreException { 92 ensureModelEditable(); 93 for (int i = 0; i < newFeatures.length; i++) { 94 ISiteBuildFeature feature = newFeatures[i]; 95 ((SiteBuildFeature) feature).setInTheModel(true); 96 features.add(newFeatures[i]); 97 } 98 fireStructureChanged(newFeatures, IModelChangedEvent.INSERT); 99 } 100 101 102 105 public void removeFeatures(ISiteBuildFeature[] newFeatures) 106 throws CoreException { 107 ensureModelEditable(); 108 for (int i = 0; i < newFeatures.length; i++) { 109 ISiteBuildFeature feature = newFeatures[i]; 110 ((SiteBuildFeature) feature).setInTheModel(false); 111 features.remove(newFeatures[i]); 112 } 113 fireStructureChanged(newFeatures, IModelChangedEvent.REMOVE); 114 } 115 116 119 public ISiteBuildFeature[] getFeatures() { 120 return (ISiteBuildFeature[]) features.toArray( 121 new ISiteBuildFeature[features.size()]); 122 } 123 124 protected void reset() { 125 features.clear(); 126 useConsole = false; 127 autobuild = false; 128 scrubOutput = false; 129 } 130 131 protected void parse(Node node) { 132 String value = getNodeAttribute(node, "plugin-location"); autobuild = getBooleanAttribute(node, "autobuild"); scrubOutput = getBooleanAttribute(node, "scrub-output"); useConsole = getBooleanAttribute(node, "use-console"); NodeList children = node.getChildNodes(); 137 for (int i = 0; i < children.getLength(); i++) { 138 Node child = children.item(i); 139 if (child.getNodeType() == Node.ELEMENT_NODE) { 140 parseChild(child); 141 } 142 } 143 } 144 145 protected void parseChild(Node child) { 146 String tag = child.getNodeName().toLowerCase(); 147 if (tag.equals("feature")) { ISiteBuildFeature feature = getModel().createFeature(); 149 ((SiteBuildFeature) feature).parse(child); 150 ((SiteBuildFeature) feature).setInTheModel(true); 151 features.add(feature); 152 } 153 } 154 public void restoreProperty(String name, Object oldValue, Object newValue) 155 throws CoreException { 156 if (name.equals(P_AUTOBUILD)) { 157 setAutobuild(newValue!=null?((Boolean )newValue).booleanValue():false); 158 } else if (name.equals(P_SCRUB_OUTPUT)) { 159 setScrubOutput(newValue!=null?((Boolean )newValue).booleanValue():false); 160 } else if (name.equals(P_SHOW_CONSOLE)) { 161 setShowConsole(newValue!=null?((Boolean )newValue).booleanValue():false); 162 } 163 else 164 super.restoreProperty(name, oldValue, newValue); 165 } 166 public void write(String indent, PrintWriter writer) { 167 writer.print(indent + "<site-build"); String indent2 = indent + INDENT; 169 String indenta = indent + INDENT + INDENT; 170 writeIfDefined(indenta, writer, "autobuild", autobuild?"true":"false"); writeIfDefined(indenta, writer, "scrub-output", scrubOutput?"true":"false"); writeIfDefined(indenta, writer, "use-console", useConsole?"true":"false"); writer.println(">"); 175 writeChildren(indent2, features, writer); 176 writer.println(indent + "</site-build>"); } 178 private void writeChildren( 179 String indent, 180 Vector children, 181 PrintWriter writer) { 182 for (int i = 0; i < children.size(); i++) { 183 IWritable writable = (IWritable) children.get(i); 184 writable.write(indent, writer); 185 } 186 } 187 188 public void resetReferences() { 189 for (int i=0; i<features.size(); i++) { 190 ISiteBuildFeature sbfeature = (ISiteBuildFeature)features.get(i); 191 sbfeature.setReferencedFeature(null); 192 } 193 } 194 195 private void writeIfDefined( 196 String indent, 197 PrintWriter writer, 198 String attName, 199 String attValue) { 200 if (attValue == null) 201 return; 202 writer.println(); 203 writer.print(indent + attName + "=\"" + attValue + "\""); } 205 } 206 | Popular Tags |