1 11 package org.eclipse.pde.internal.core.text.plugin; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.core.plugin.IPluginExtension; 17 import org.eclipse.pde.core.plugin.ISharedPluginModel; 18 import org.eclipse.pde.internal.core.PDECore; 19 import org.eclipse.pde.internal.core.ischema.ISchema; 20 import org.eclipse.pde.internal.core.schema.SchemaRegistry; 21 import org.eclipse.pde.internal.core.text.IDocumentAttribute; 22 import org.eclipse.pde.internal.core.text.IDocumentNode; 23 24 public class PluginExtensionNode extends PluginParentNode implements 25 IPluginExtension, IDocumentExtension { 26 27 private static final long serialVersionUID = 1L; 28 private transient ISchema fSchema; 29 30 33 public String getPoint() { 34 return getXMLAttributeValue(P_POINT); 35 } 36 39 public void setPoint(String point) throws CoreException { 40 setXMLAttribute(P_POINT, point); 41 } 42 43 46 public void setName(String name) throws CoreException { 47 setXMLAttribute(P_NAME, name); 48 } 49 50 53 public String getName() { 54 return getXMLAttributeValue(P_NAME); 55 } 56 57 60 public String getTranslatedName() { 61 String name = getName(); 62 if (name != null && name.trim().length() > 0) 63 return getResourceString(name); 64 String point = getPoint(); 65 ISchema schema = PDECore.getDefault().getSchemaRegistry().getSchema(point); 66 return schema == null ? "" : schema.getName(); } 68 71 public String getId() { 72 return getXMLAttributeValue(P_ID); 73 } 74 77 public void setId(String id) throws CoreException { 78 setXMLAttribute(P_ID, id); 79 } 80 81 84 public String write(boolean indent) { 85 String sep = getLineDelimiter(); 86 StringBuffer buffer = new StringBuffer (); 87 if (indent) 88 buffer.append(getIndent()); 89 buffer.append(writeShallow(false)); 90 IDocumentNode[] children = getChildNodes(); 91 for (int i = 0; i < children.length; i++) { 92 children[i].setLineIndent(getLineIndent() + 3); 93 buffer.append(sep + children[i].write(true)); 94 } 95 buffer.append(sep + getIndent() + "</extension>"); return buffer.toString(); 97 } 98 99 102 public void write(String indent, PrintWriter writer) { 103 writer.write(write(true)); 105 } 106 107 110 public String writeShallow(boolean terminate) { 111 String sep = getLineDelimiter(); 112 String attrIndent = " "; StringBuffer buffer = new StringBuffer ("<extension"); IDocumentAttribute attr = getDocumentAttribute(P_ID); 115 if (attr != null && attr.getAttributeValue().trim().length() > 0) 116 buffer.append(sep + getIndent() + attrIndent + attr.write()); 117 attr = getDocumentAttribute(P_NAME); 118 if (attr != null && attr.getAttributeValue().trim().length() > 0) 119 buffer.append(sep + getIndent() + attrIndent + attr.write()); 120 attr = getDocumentAttribute(P_POINT); 121 if (attr != null && attr.getAttributeValue().trim().length() > 0) 122 buffer.append(sep + getIndent() + attrIndent + attr.write()); 123 if (terminate) 124 buffer.append("/"); buffer.append(">"); return buffer.toString(); 127 } 128 129 132 public Object getSchema() { 133 if (fSchema == null) { 134 SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry(); 135 fSchema = registry.getSchema(getPoint()); 136 } else if (fSchema.isDisposed()) { 137 fSchema = null; 138 } 139 return fSchema; 140 } 141 142 145 public void reconnect(ISharedPluginModel model, ISchema schema, IDocumentNode parent) { 146 super.reconnect(model, schema, parent); 147 fSchema = schema; 149 } 150 151 } 152 | Popular Tags |