KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > correction > AbstractXMLMarkerResolution


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.correction;
12
13 import java.util.StringTokenizer JavaDoc;
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 JavaDoc fLocationPath;
29     
30     public AbstractXMLMarkerResolution(int resolutionType, IMarker marker) {
31         super(resolutionType);
32         try {
33             fLocationPath = (String JavaDoc)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 JavaDoc findNode(IPluginModelBase base) {
46         if (fLocationPath == null)
47             return null;
48         
49         // special case for externalizing strings in manifest.mf
50
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 JavaDoc strtok = new StringTokenizer JavaDoc(
58                 fLocationPath,
59                 Character.toString(XMLErrorReporter.F_CHILD_SEP));
60         while (strtok.hasMoreTokens()) {
61             String JavaDoc 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             // when externalizing Strings in plugin.xml, we pass in both Manifest and plug-in file (bug 172080 comment #1)
70
} 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 JavaDoc getNameOfNode() {
89         int lastChild = fLocationPath.lastIndexOf(')');
90         if (lastChild < 0)
91             return fLocationPath;
92         String JavaDoc 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