1 11 package org.eclipse.pde.internal.ui.correction; 12 13 import java.util.StringTokenizer ; 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.pde.core.IBaseModel; 18 import org.eclipse.pde.core.plugin.IPluginModelBase; 19 import org.eclipse.pde.core.plugin.ISharedExtensionsModel; 20 import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; 21 import org.eclipse.pde.internal.core.builders.XMLErrorReporter; 22 import org.eclipse.pde.internal.core.ibundle.IBundle; 23 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 24 import org.eclipse.pde.internal.core.text.IDocumentNode; 25 26 public abstract class AbstractXMLMarkerResolution extends AbstractPDEMarkerResolution { 27 28 protected String fLocationPath; 29 30 public AbstractXMLMarkerResolution(int resolutionType, IMarker marker) { 31 super(resolutionType); 32 try { 33 fLocationPath = (String )marker.getAttribute(PDEMarkerFactory.MPK_LOCATION_PATH); 34 } catch (CoreException e) { 35 } 36 } 37 38 protected abstract void createChange(IPluginModelBase model); 39 40 protected void createChange(IBaseModel model) { 41 if (model instanceof IPluginModelBase) 42 createChange((IPluginModelBase)model); 43 } 44 45 protected Object findNode(IPluginModelBase base) { 46 if (fLocationPath == null) 47 return null; 48 49 if (fLocationPath.charAt(0) != '(' && 51 base instanceof IBundlePluginModelBase) { 52 IBundle bundle = ((IBundlePluginModelBase)base).getBundleModel().getBundle(); 53 return bundle.getManifestHeader(fLocationPath); 54 } 55 56 IDocumentNode node = null; 57 StringTokenizer strtok = new StringTokenizer ( 58 fLocationPath, 59 Character.toString(XMLErrorReporter.F_CHILD_SEP)); 60 while (strtok.hasMoreTokens()) { 61 String token = strtok.nextToken(); 62 if (node != null) { 63 IDocumentNode[] children = node.getChildNodes(); 64 int childIndex = Integer.parseInt(token.substring(1, token.indexOf(')'))); 65 if ((childIndex >= 0) || 66 (childIndex < children.length)) { 67 node = children[childIndex]; 68 } 69 } else if (base instanceof IBundlePluginModelBase) { 71 ISharedExtensionsModel sharedModel = ((IBundlePluginModelBase)base).getExtensionsModel(); 72 if (sharedModel instanceof IPluginModelBase) 73 node = (IDocumentNode)((IPluginModelBase)sharedModel).getPluginBase(); 74 } else 75 node = (IDocumentNode)base.getPluginBase(); 76 77 int attr = token.indexOf(XMLErrorReporter.F_ATT_PREFIX); 78 if (attr != -1) { 79 int valueIndex = token.indexOf(XMLErrorReporter.F_ATT_VALUE_PREFIX); 80 if (valueIndex == -1) 81 return node.getDocumentAttribute(token.substring(attr + 1)); 82 return node.getDocumentAttribute(token.substring(attr + 1, valueIndex)); 83 } 84 } 85 return node; 86 } 87 88 protected String getNameOfNode() { 89 int lastChild = fLocationPath.lastIndexOf(')'); 90 if (lastChild < 0) 91 return fLocationPath; 92 String item = fLocationPath.substring(lastChild + 1); 93 lastChild = item.indexOf(XMLErrorReporter.F_ATT_PREFIX); 94 if (lastChild == -1) 95 return item; 96 int valueIndex = item.indexOf(XMLErrorReporter.F_ATT_VALUE_PREFIX); 97 if (valueIndex == -1) 98 return item.substring(lastChild + 1); 99 return item.substring(valueIndex + 1); 100 } 101 102 protected boolean isAttrNode() { 103 return fLocationPath.indexOf(XMLErrorReporter.F_ATT_PREFIX) != -1; 104 } 105 } 106 | Popular Tags |