Skip to content

Commit fabf90f

Browse files
author
Xuan Dai
committed
re-implement method to get offset to avoid failure with JDK 6
git-svn-id: https://svn.apache.org/repos/asf/geronimo/devtools/eclipse-plugin/branches/2.1.5@918907 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1da54d6 commit fabf90f

File tree

1 file changed

+33
-52
lines changed

1 file changed

+33
-52
lines changed

plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.List;
88

99
import org.xml.sax.Attributes;
10-
import org.xml.sax.Locator;
1110
import org.xml.sax.SAXException;
1211
import org.xml.sax.helpers.DefaultHandler;
1312

@@ -16,7 +15,6 @@
1615
*/
1716
public class DeploymentPlanHandler extends DefaultHandler {
1817
protected String file;
19-
protected Locator locator;
2018
protected List<DeploymentPlanTextNode> nodeList = new ArrayList<DeploymentPlanTextNode>();
2119

2220
protected static final int START = 0, IN_ROOT_ELEMENT = 1,
@@ -48,48 +46,38 @@ public String getNodeValue(String nodeName) {
4846
}
4947
return null;
5048
}
51-
52-
public void setDocumentLocator(Locator locator) {
53-
this.locator = locator;
54-
}
55-
49+
5650
public void characters(char[] ch, int start, int length)
5751
throws SAXException {
58-
String value = null;
5952
DeploymentPlanTextNode wtn = null;
53+
String name = null;
54+
6055
switch (state) {
61-
case IN_CONTEXT_ROOT:
62-
value = new String(ch, start, length);
63-
wtn = new DeploymentPlanTextNode();
64-
try {
65-
int offset = getOffset(locator.getLineNumber(), locator
66-
.getColumnNumber());
67-
wtn.setName(DeploymentPlanTextNode.CONTEXT_ROOT);
68-
wtn.setValue(value);
69-
wtn.setOffset(offset - length);
70-
nodeList.add(wtn);
71-
} catch (IOException e) {
72-
e.printStackTrace();
73-
}
74-
break;
75-
case IN_ARTIFACTID:
76-
value = new String(ch, start, length);
77-
wtn = new DeploymentPlanTextNode();
78-
try {
79-
int offset = getOffset(locator.getLineNumber(), locator
80-
.getColumnNumber());
81-
wtn.setName(DeploymentPlanTextNode.ARTIFACT_ID);
82-
wtn.setValue(value);
83-
wtn.setOffset(offset - length);
84-
nodeList.add(wtn);
85-
86-
} catch (IOException e) {
87-
e.printStackTrace();
88-
}
89-
break;
90-
default:
91-
break;
56+
case IN_CONTEXT_ROOT:
57+
name = DeploymentPlanTextNode.CONTEXT_ROOT;
58+
break;
59+
case IN_ARTIFACTID:
60+
name = DeploymentPlanTextNode.ARTIFACT_ID;
61+
break;
62+
default:
63+
return;
9264
}
65+
66+
String value = new String(ch, start, length);
67+
wtn = new DeploymentPlanTextNode();
68+
69+
wtn.setName(name);
70+
wtn.setValue(value);
71+
try {
72+
//ch doesn't contains XML declare statement at the beginning of deployment plan
73+
//get the character number of first line
74+
int xmlDeclareLength = getXMLDeclareLength();
75+
wtn.setOffset(xmlDeclareLength + start - 1);
76+
} catch (IOException e) {
77+
e.printStackTrace();
78+
}
79+
nodeList.add(wtn);
80+
9381
}
9482

9583
public void startElement(String uri, String localName, String qName,
@@ -150,25 +138,18 @@ public void endElement(String uri, String localName, String qName)
150138
}
151139
}
152140

153-
// return the offset of the DeploymentPlanTextNode's end
154-
protected int getOffset(int lineNumber, int columnNumber)
141+
// return the character number of first line in deployment plan
142+
protected int getXMLDeclareLength()
155143
throws IOException {
156144
BufferedReader br = new BufferedReader(new FileReader(file));
157145

158-
if (lineNumber < 1 || columnNumber < 1)
159-
return -1;
160-
161146
int current;
162147
int offset = 0;
163148

164-
for (int i = 1; i < lineNumber;) {
165-
do {
166-
current = br.read();
167-
offset++;
168-
} while (current != '\n');
169-
i++;
170-
}
171-
offset += (columnNumber - 1);
149+
do {
150+
current = br.read();
151+
offset++;
152+
} while (current != '\n');
172153

173154
br.close();
174155

0 commit comments

Comments
 (0)