geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From de...@apache.org
Subject svn commit: r918905 - /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java
Date Thu, 04 Mar 2010 09:05:49 GMT
Author: delos
Date: Thu Mar  4 09:05:48 2010
New Revision: 918905

URL: http://svn.apache.org/viewvc?rev=918905&view=rev
Log:
re-implement method to get offset to avoid failure with JDK 6

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java?rev=918905&r1=918904&r2=918905&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.ui/src/main/java/org/apache/geronimo/st/ui/refactoring/DeploymentPlanHandler.java
Thu Mar  4 09:05:48 2010
@@ -7,7 +7,6 @@
 import java.util.List;
 
 import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
@@ -16,7 +15,6 @@
  */
 public class DeploymentPlanHandler extends DefaultHandler {
 	protected String file;
-	protected Locator locator;
 	protected List<DeploymentPlanTextNode> nodeList = new ArrayList<DeploymentPlanTextNode>();
 
 	protected static final int START = 0, IN_ROOT_ELEMENT = 1,
@@ -48,48 +46,38 @@
 		}
 		return null;
 	}
-
-	public void setDocumentLocator(Locator locator) {
-		this.locator = locator;
-	}
-
+	
 	public void characters(char[] ch, int start, int length)
 			throws SAXException {
-		String value = null;
 		DeploymentPlanTextNode wtn = null;
+		String name = null;
+		
 		switch (state) {
-		case IN_CONTEXT_ROOT:
-			value = new String(ch, start, length);
-			wtn = new DeploymentPlanTextNode();
-			try {
-				int offset = getOffset(locator.getLineNumber(), locator
-						.getColumnNumber());
-				wtn.setName(DeploymentPlanTextNode.CONTEXT_ROOT);
-				wtn.setValue(value);
-				wtn.setOffset(offset - length);
-				nodeList.add(wtn);
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-			break;
-		case IN_ARTIFACTID:
-			value = new String(ch, start, length);
-			wtn = new DeploymentPlanTextNode();
-			try {
-				int offset = getOffset(locator.getLineNumber(), locator
-						.getColumnNumber());
-				wtn.setName(DeploymentPlanTextNode.ARTIFACT_ID);
-				wtn.setValue(value);
-				wtn.setOffset(offset - length);
-				nodeList.add(wtn);
-
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-			break;
-		default:
-			break;
+			case IN_CONTEXT_ROOT:
+				name = DeploymentPlanTextNode.CONTEXT_ROOT;
+				break;
+			case IN_ARTIFACTID:
+				name = DeploymentPlanTextNode.ARTIFACT_ID;
+				break;
+			default:
+				return;
+		}
+		
+		String value = new String(ch, start, length);
+		wtn = new DeploymentPlanTextNode();
+		
+		wtn.setName(name);
+		wtn.setValue(value);
+		try {
+			//ch doesn't contains XML declare statement at the beginning of deployment plan
+			//get the character number of first line
+			int xmlDeclareLength = getXMLDeclareLength();
+			wtn.setOffset(xmlDeclareLength + start - 1);
+		} catch (IOException e) {
+			e.printStackTrace();
 		}
+		nodeList.add(wtn);	
+		
 	}
 
 	public void startElement(String uri, String localName, String qName,
@@ -150,25 +138,18 @@
 		}
 	}
 
-	// return the offset of the DeploymentPlanTextNode's end
-	protected int getOffset(int lineNumber, int columnNumber)
+	// return the character number of first line in deployment plan
+	protected int getXMLDeclareLength()
 			throws IOException {
 		BufferedReader br = new BufferedReader(new FileReader(file));
 
-		if (lineNumber < 1 || columnNumber < 1)
-			return -1;
-
 		int current;
 		int offset = 0;
 
-		for (int i = 1; i < lineNumber;) {
-			do {
-				current = br.read();
-				offset++;
-			} while (current != '\n');
-			i++;
-		}
-		offset += (columnNumber - 1);
+		do {
+			current = br.read();
+			offset++;
+		} while (current != '\n');
 
 		br.close();
 



Mime
View raw message