1 11 package org.eclipse.pde.internal.core.text.plugin; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.core.IModelChangedEvent; 17 import org.eclipse.pde.core.plugin.IPluginLibrary; 18 import org.eclipse.pde.internal.core.text.IDocumentAttribute; 19 import org.eclipse.pde.internal.core.text.IDocumentNode; 20 21 public class PluginLibraryNode extends PluginObjectNode implements IPluginLibrary { 22 23 private static final long serialVersionUID = 1L; 24 25 28 public String [] getContentFilters() { 29 IDocumentNode[] children = getChildNodes(); 30 ArrayList result = new ArrayList (); 31 for (int i = 0; i < children.length; i++) { 32 PluginObjectNode node = (PluginObjectNode)children[i]; 33 if (node.getName().equals(P_EXPORTED)) { 34 String name = children[i].getXMLAttributeValue(P_NAME); 35 if (name != null && !name.equals("*")) { int index = name.indexOf(".*"); if (index != -1) 38 name = name.substring(0, index); 39 result.add(name); 40 } 41 } 42 } 43 return (String [])result.toArray(new String [result.size()]); 44 } 45 48 public String [] getPackages() { 49 return new String [0]; 50 } 51 54 public boolean isExported() { 55 IDocumentNode[] children = getChildNodes(); 56 for (int i = 0; i < children.length; i++) { 57 PluginObjectNode node = (PluginObjectNode)children[i]; 58 if (node.getName().equals(P_EXPORTED)) 59 return true; 60 } 61 return false; 62 } 63 66 public boolean isFullyExported() { 67 IDocumentNode[] children = getChildNodes(); 68 for (int i = 0; i < children.length; i++) { 69 PluginObjectNode node = (PluginObjectNode)children[i]; 70 if (node.getName().equals(P_EXPORTED)) { 71 String name = children[i].getXMLAttributeValue(P_NAME); 72 if (name != null && name.equals("*")) return true; 74 } 75 } 76 return false; 77 } 78 79 82 public String getType() { 83 String type = getXMLAttributeValue(P_TYPE); 84 return (type != null && type.equals("resource")) ? IPluginLibrary.RESOURCE : IPluginLibrary.CODE; } 86 89 public void setContentFilters(String [] filters) throws CoreException { 90 } 91 94 public void addContentFilter(String filter) throws CoreException { 95 PluginElementNode node = new PluginElementNode(); 96 node.setXMLTagName(P_EXPORTED); 97 node.setParentNode(this); 98 node.setModel(getModel()); 99 node.setXMLAttribute(P_NAME, "*".equals(filter) || filter.endsWith(".*") ? filter : filter + ".*"); addContentFilter(node); 101 } 102 103 public void addContentFilter(PluginElementNode node) throws CoreException { 104 addChildNode(node); 105 if (isInTheModel()) { 106 node.setInTheModel(true); 107 fireStructureChanged(node, IModelChangedEvent.INSERT); 108 } 109 } 110 111 114 public void removeContentFilter(String filter) throws CoreException { 115 if (!filter.endsWith(".*")) filter += ".*"; IDocumentNode[] children = getChildNodes(); 118 for (int i = 0; i < children.length; i++) { 119 if (children[i].getXMLTagName().equals(P_EXPORTED) 120 && filter.equals(children[i].getXMLAttributeValue(P_NAME))) { 121 removeContentFilter((PluginElementNode)children[i]); 122 } 123 } 124 } 125 126 public void removeContentFilter(PluginElementNode node) { 127 removeChildNode(node); 128 if (isInTheModel()) { 129 node.setInTheModel(false); 130 fireStructureChanged(node, IModelChangedEvent.REMOVE); 131 } 132 } 133 134 137 public void setPackages(String [] packages) throws CoreException { 138 } 139 142 public void setExported(boolean exported) throws CoreException { 143 IDocumentNode[] children = getChildNodes(); 144 boolean alreadyExported = false; 145 for (int i = 0; i < children.length; i++) { 146 if (children[i].getXMLTagName().equals(P_EXPORTED)) { 147 if (!"*".equals(children[i].getXMLAttributeValue(P_NAME))) { removeContentFilter((PluginElementNode)children[i]); 149 } else { 150 alreadyExported = true; 151 if (!exported) { 152 removeContentFilter((PluginElementNode)children[i]); 153 } 154 } 155 } 156 } 157 if (exported && !alreadyExported) { 158 addContentFilter("*"); } 160 } 161 162 165 public void setType(String type) throws CoreException { 166 } 167 168 171 public String getName() { 172 return getXMLAttributeValue(P_NAME); 173 } 174 175 178 public void setName(String name) throws CoreException { 179 setXMLAttribute(P_NAME, name); 180 } 181 182 185 public String write(boolean indent) { 186 String sep = getLineDelimiter(); 187 StringBuffer buffer = new StringBuffer (); 188 if (indent) 189 buffer.append(getIndent()); 190 191 IDocumentNode[] children = getChildNodes(); 192 if (children.length > 0) { 193 buffer.append(writeShallow(false) + sep); 194 for (int i = 0; i < children.length; i++) { 195 children[i].setLineIndent(getLineIndent() + 3); 196 buffer.append(children[i].write(true) + sep); 197 } 198 buffer.append(getIndent() + "</" + getXMLTagName() + ">"); } else { 200 buffer.append(writeShallow(true)); 201 } 202 return buffer.toString(); 203 } 204 205 208 public String writeShallow(boolean terminate) { 209 StringBuffer buffer = new StringBuffer ("<" + getXMLTagName()); 211 IDocumentAttribute[] attrs = getNodeAttributes(); 212 for (int i = 0; i < attrs.length; i++) { 213 appendAttribute(buffer, attrs[i].getAttributeName()); 214 } 215 if (terminate) 216 buffer.append("/"); buffer.append(">"); return buffer.toString(); 219 } 220 221 public String toString() { 222 return getName(); 223 } 224 225 } 226 | Popular Tags |