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