1 11 package org.eclipse.pde.internal.ui.model.plugin; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.pde.core.plugin.*; 15 import org.eclipse.pde.internal.core.ischema.*; 16 import org.eclipse.pde.internal.ui.model.*; 17 18 public class PluginElementNode extends PluginParentNode 19 implements 20 IPluginElement { 21 22 private static final long serialVersionUID = 1L; 23 24 private transient ISchemaElement elementInfo; 25 28 public IPluginElement createCopy() { 29 return null; 30 } 31 34 public IPluginAttribute getAttribute(String name) { 35 return (IPluginAttribute)fAttributes.get(name); 36 } 37 40 public IPluginAttribute[] getAttributes() { 41 return (IPluginAttribute[])fAttributes.values().toArray(new IPluginAttribute[fAttributes.size()]); 42 } 43 46 public int getAttributeCount() { 47 return fAttributes.size(); 48 } 49 52 public String getText() { 53 IDocumentTextNode node = getTextNode(); 54 return node == null ? "" : node.getText(); } 56 59 public void setAttribute(String name, String value) throws CoreException { 60 setXMLAttribute(name, value); 61 } 62 65 public void setText(String text) throws CoreException { 66 IDocumentTextNode node = getTextNode(); 67 if (node == null) { 68 node = new DocumentTextNode(); 69 node.setEnclosingElement(this); 70 addTextNode(node); 71 } 72 node.setText(text); 73 firePropertyChanged(this, P_TEXT, node, node); 74 } 75 76 79 public String write(boolean indent) { 80 String sep = getLineDelimiter(); 81 StringBuffer buffer = new StringBuffer (); 82 if (indent) 83 buffer.append(getIndent()); 84 85 IDocumentNode[] children = getChildNodes(); 86 String text = getText(); 87 if (children.length > 0 || text.length() > 0) { 88 buffer.append(writeShallow(false) + sep); 89 if (text.length() > 0) 90 buffer.append(getIndent() + " " + text + sep); for (int i = 0; i < children.length; i++) { 92 children[i].setLineIndent(getLineIndent() + 3); 93 buffer.append(children[i].write(true) + sep); 94 } 95 buffer.append(getIndent() + "</" + getXMLTagName() + ">"); } else { 97 buffer.append(writeShallow(true)); 98 } 99 100 return buffer.toString(); 101 } 102 103 106 public String writeShallow(boolean terminate) { 107 String sep = getLineDelimiter(); 108 StringBuffer buffer = new StringBuffer ("<" + getXMLTagName()); 110 IDocumentAttribute[] attrs = getNodeAttributes(); 111 if (attrs.length == 1) { 112 if (attrs[0].getAttributeValue().length() > 0) 113 buffer.append(" " + attrs[0].write()); } else { 115 for (int i = 0; i < attrs.length; i++) { 116 if (attrs[i].getAttributeValue().length() > 0) 117 buffer.append(sep + getIndent() + " " + attrs[i].write()); } 119 } 120 if (terminate) 121 buffer.append("/"); buffer.append(">"); return buffer.toString(); 124 } 125 126 129 public String getName() { 130 return getXMLTagName(); 131 } 132 133 136 public void setName(String name) throws CoreException { 137 setXMLTagName(name); 138 } 139 140 143 public Object getElementInfo() { 144 if (elementInfo == null) { 145 IDocumentNode node = getParentNode(); 146 for (;;) { 147 if (node == null || node instanceof IPluginExtension) 148 break; 149 node = node.getParentNode(); 150 } 151 if (node != null) { 152 IPluginExtension extension = (IPluginExtension) node; 153 ISchema schema = (ISchema)extension.getSchema(); 154 if (schema != null) { 155 elementInfo = schema.findElement(getName()); 156 } 157 } 158 } 159 return elementInfo; 160 } 161 162 } 163 | Popular Tags |