[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/deploy/compile RmlErrorHandler.java,NONE,1.1 Rm
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2003-02-06 20:13:48
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile
In directory sc8-pr-cvs1:/tmp/cvs-serv26777/dev/src/net/sourceforge/idrs/deploy/compile
Modified Files:
RmlCompiler.java Compiler.java RMLHandler.java
CompilerState.java
Added Files:
RmlErrorHandler.java
Log Message:
1. Moved controller code into servlet
2. Added the ability for properties to be arrays of strings
3. Moved config file into it's own xml file
4. Added better compile errors for rml pages
5. removed all debug printings
--- NEW FILE: RmlErrorHandler.java ---
package net.sourceforge.idrs.deploy.compile;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* @author mlb
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class RmlErrorHandler implements ErrorHandler {
SAXParseException e;
int lineNumber;
/**
* Constructor for RmlErrorHandler.
*/
public RmlErrorHandler() {
super();
lineNumber = -1;
}
/**
* @see org.xml.sax.ErrorHandler#warning(SAXParseException)
*/
public void warning(SAXParseException exception) throws SAXException {
//this.e = exception;
//throw new SAXException("warning : " + exception.getLineNumber());
}
/**
* @see org.xml.sax.ErrorHandler#error(SAXParseException)
*/
public void error(SAXParseException exception) throws SAXException {
this.lineNumber = exception.getLineNumber();
throw exception;
}
/**
* @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
*/
public void fatalError(SAXParseException exception) throws SAXException {
this.lineNumber = exception.getLineNumber();
throw exception;
}
public SAXParseException getException() {
return e;
}
/**
* Returns the lineNumber.
* @return int
*/
public int getLineNumber() {
return lineNumber;
}
}
Index: RmlCompiler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/RmlCompiler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RmlCompiler.java 23 Mar 2002 04:48:27 -0000 1.2
--- RmlCompiler.java 6 Feb 2003 20:13:45 -0000 1.3
***************
*** 15,19 ****
*/
-
package net.sourceforge.idrs.deploy.compile;
--- 15,18 ----
***************
*** 25,29 ****
import javax.xml.parsers.*;
import net.sourceforge.idrs.deploy.macro.*;
- import net.sourceforge.idrs.deploy.compile.*;
/**
*
--- 24,27 ----
***************
*** 32,100 ****
*/
public class RmlCompiler {
! IDRSRep rep;
!
! /** Creates new RmlCompiler */
! public RmlCompiler(PrintWriter log, String rml, String xmlParser,String schemaSrc, boolean isFile, String rmlNS) throws Exception {
! boolean fail;
! StringWriter transformOut = new StringWriter();
! InputSource in;
! CompilerState comp = new CompilerState();
!
! MacroToXML trans = new MacroToXML(xmlParser,schemaSrc,isFile,rmlNS);
!
! log.println("Transformation : ");
!
! try {
! trans.setRML(rml);
! trans.setWriter(transformOut);
! trans.transformToXML();
! System.out.println("Transformation Complete!");
! fail = false;
! }
! catch (Exception e) {
! fail = true;
! e.printStackTrace(log);
! }
!
!
!
! log.println(transformOut.getBuffer());
! log.flush();
!
!
!
! if (fail) {
! log.println("Translation Failed");
! log.flush();
! return;
! }
!
!
! try {
! StringReader xmlIn = new StringReader(transformOut.getBuffer().toString());
! in = new InputSource(xmlIn);
! XMLReader parser = XMLReaderFactory.createXMLReader(xmlParser);
! RMLHandler rmlHandler = new RMLHandler(comp);
! rmlHandler.setOut(log);
! parser.setContentHandler(rmlHandler);
! parser.parse(in);
! }
! catch (Exception ee) {
! ee.printStackTrace(log);
! }
!
! if (fail) {
! log.println("Compilation Failed");
! return;
! }
! log.flush();
! rep = comp.getReport();
!
! }
!
! public IDRSRep getReport() {
! return rep;
! }
}
--- 30,188 ----
*/
public class RmlCompiler {
! IDRSRep rep;
! String xmlsrc;
! String errorWord;
! String err;
! /** Creates new RmlCompiler */
! public RmlCompiler(
! PrintWriter log,
! String rml,
! String xmlParser,
! String schemaSrc,
! boolean isFile,
! String rmlNS)
! throws Exception {
! err = null;
! errorWord = null;
! boolean fail;
! StringWriter transformOut = new StringWriter();
! InputSource in;
!
! CompilerState comp = new CompilerState();
!
! MacroToXML trans = new MacroToXML(xmlParser, schemaSrc, isFile, rmlNS);
!
! log.println("Transformation : ");
!
! try {
! trans.setRML(rml);
! trans.setWriter(transformOut);
! trans.transformToXML();
! //System.out.println("Transformation Complete!");
! fail = false;
! } catch (Exception e) {
! fail = true;
! e.printStackTrace(log);
! }
!
! log.println(transformOut.getBuffer());
! log.flush();
!
! if (fail) {
! log.println("Translation Failed");
! log.flush();
! return;
! }
!
! LocatorImpl locator = new LocatorImpl();
!
! StringReader xmlIn =
! new StringReader(transformOut.getBuffer().toString());
! in = new InputSource(xmlIn);
! XMLReader parser = XMLReaderFactory.createXMLReader(xmlParser);
! RMLHandler rmlHandler = new RMLHandler(comp);
! rmlHandler.setOut(log);
! rmlHandler.setDocumentLocator(locator);
! RmlErrorHandler err = new RmlErrorHandler();
!
! parser.setErrorHandler(err);
! parser.setContentHandler(rmlHandler);
!
! try {
! parser.parse(in);
! } catch (Exception e) {
! String msg = e.toString();
! msg = msg.substring(msg.indexOf("###") + 3);
! msg = msg.substring(msg.indexOf(":") + 1);
! this.err = msg;
! this.errorWord = comp.getErrorWord();
!
! log.println("ERROR : " + msg
! /*+ " - Line : " +err.getException().getLineNumber()*/
! );
! log.println("Error Word : " + comp.getErrorWord());
! /*if (locator.getLineNumber() != -1 && comp.getErrorWord() != null) {
! String tmp = transformOut.getBuffer().toString();
! StringTokenizer tok = new StringTokenizer(tmp, "\n");
! int i = 1;
!
! while (tok.hasMoreTokens()) {
! if (tok.nextToken().indexOf(comp.getErrorWord()) != -1) {
! log.println("Line : " + i);
! break;
! }
! i = i + 1;
! }
! }
! else {*/
! int lineNum = err.getLineNumber() == -1 ? rmlHandler.getLastLineNum() : err.getLineNumber();
! log.println("Line: " + lineNum) ;
! //}
!
! }
!
! this.xmlsrc = transformOut.getBuffer().toString();
!
! if (fail) {
! log.println("Compilation Failed");
! return;
! }
! log.flush();
! rep = comp.getReport();
!
! }
!
! public IDRSRep getReport() {
! return rep;
! }
!
! /**
! * Returns the err.
! * @return String
! */
! public String getErr() {
! return err;
! }
!
! /**
! * Returns the errorWord.
! * @return String
! */
! public String getErrorWord() {
! return errorWord;
! }
!
! /**
! * Returns the xmlsrc.
! * @return String
! */
! public String getXmlsrc() {
! return xmlsrc;
! }
!
! /**
! * Sets the err.
! * @param err The err to set
! */
! public void setErr(String err) {
! this.err = err;
! }
!
! /**
! * Sets the errorWord.
! * @param errorWord The errorWord to set
! */
! public void setErrorWord(String errorWord) {
! this.errorWord = errorWord;
! }
!
! /**
! * Sets the xmlsrc.
! * @param xmlsrc The xmlsrc to set
! */
! public void setXmlsrc(String xmlsrc) {
! this.xmlsrc = xmlsrc;
! }
}
Index: Compiler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/Compiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Compiler.java 4 Mar 2002 23:05:34 -0000 1.4
--- Compiler.java 6 Feb 2003 20:13:45 -0000 1.5
***************
*** 26,29 ****
--- 26,30 ----
protected Attributes atts;
protected CompilerState state;
+ protected String error;
***************
*** 48,51 ****
--- 49,68 ----
*/
public abstract void seal() throws Exception;
+
+ /**
+ * Returns the error.
+ * @return String
+ */
+ public String getError() {
+ return error;
+ }
+
+ /**
+ * Sets the error.
+ * @param error The error to set
+ */
+ public void setError(String error) {
+ this.error = error;
+ }
}
Index: RMLHandler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/RMLHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RMLHandler.java 8 Jan 2003 06:01:37 -0000 1.6
--- RMLHandler.java 6 Feb 2003 20:13:45 -0000 1.7
***************
*** 36,39 ****
--- 36,42 ----
Stack isMethodState;
PrintWriter out;
+ protected int lastLineNum;
+
+ Locator locator;
public static String BASE_PACKAGE = "net.sourceforge.idrs.deploy.compile.units";
***************
*** 61,66 ****
*/
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {
try {
! out.println("Start Element" + localName);
}
catch (Exception e){}
--- 64,71 ----
*/
public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException {
+ //out.println("Line : " + this.locator.getLineNumber());
+ this.lastLineNum = this.locator.getLineNumber();
try {
! ///out.println("Start Element" + localName);
}
catch (Exception e){}
***************
*** 94,98 ****
compiler.setAttributes(atts);
state.pushNode(compiler);
! out.println("Push Class : " + compiler.getClass());
}
--- 99,103 ----
compiler.setAttributes(atts);
state.pushNode(compiler);
! //out.println("Push Class : " + compiler.getClass());
}
***************
*** 106,110 ****
this.isMethodState.push(new Boolean(isMethod));
try {
! out.println("Push isMethod" + isMethod);
}
catch (Exception ee){}
--- 111,115 ----
this.isMethodState.push(new Boolean(isMethod));
try {
! //out.println("Push isMethod" + isMethod);
}
catch (Exception ee){}
***************
*** 121,126 ****
*/
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
try {
! out.println("End Element " + localName);
}
catch (Exception e){}
--- 126,133 ----
*/
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
+ //out.println("Line : " + this.locator.getLineNumber());
+ this.lastLineNum = this.locator.getLineNumber();
try {
! // out.println("End Element " + localName);
}
catch (Exception e){}
***************
*** 134,142 ****
this.isMethod = ((Boolean) this.isMethodState.pop()).booleanValue();
! out.println("Pop isMethod " + this.isMethod);
if (this.isMethod) {
curr = state.peekNode();
! out.println("Current Class : " + curr.getClass());
//meth = (Method) this.methods.get(methodName);
--- 141,149 ----
this.isMethod = ((Boolean) this.isMethodState.pop()).booleanValue();
! //out.println("Pop isMethod " + this.isMethod);
if (this.isMethod) {
curr = state.peekNode();
! //out.println("Current Class : " + curr.getClass());
//meth = (Method) this.methods.get(methodName);
***************
*** 146,149 ****
--- 153,157 ----
}
catch (Exception e1) {
+
throw new SAXException(e1);
}
***************
*** 153,159 ****
try {
! out.println("Curr :" + curr + "!");
! out.println("Params :" + params[0] + "-" + params[1]);
! out.println("Method : " + meth.getName());
meth.invoke(curr,params);
--- 161,167 ----
try {
! // out.println("Curr :" + curr + "!");
! //out.println("Params :" + params[0] + "-" + params[1]);
! //out.println("Method : " + meth.getName());
meth.invoke(curr,params);
***************
*** 161,165 ****
catch (Exception e2) {
//e2.printStackTrace(System.out);
! throw new SAXException(e2);
}
}
--- 169,175 ----
catch (Exception e2) {
//e2.printStackTrace(System.out);
! //throw new SAXException(e2.getMessage());
!
! throw new SAXException("###" + e2.getCause().toString());
}
}
***************
*** 167,171 ****
if (! state.isNodeEmpty()) {
curr = state.popNode();
! out.println("Pop Class : " + curr.getClass());
try {
curr.seal();
--- 177,181 ----
if (! state.isNodeEmpty()) {
curr = state.popNode();
! //out.println("Pop Class : " + curr.getClass());
try {
curr.seal();
***************
*** 173,177 ****
catch (Exception e) {
e.printStackTrace(System.out);
! throw new SAXException(e);
}
}
--- 183,187 ----
catch (Exception e) {
e.printStackTrace(System.out);
! throw new SAXParseException(e.toString(),this.locator);
}
}
***************
*** 180,183 ****
--- 190,194 ----
public void characters(char[] ch, int start, int end) {
+ //out.println("Line : " + locator.getLineNumber());
for (int i=start;i<start + end;i++) {
currBuff.append(ch[i]);
***************
*** 209,211 ****
--- 220,239 ----
}
+ public void setDocumentLocator(Locator locator) {
+ //out.println("Line : " + locator.getLineNumber());
+ this.locator = locator;
+ }
+
+ public Locator getDocumentLocator() {
+ return this.locator;
+ }
+
+ /**
+ * Returns the lastLineNum.
+ * @return int
+ */
+ public int getLastLineNum() {
+ return lastLineNum;
+ }
+
}
Index: CompilerState.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/compile/CompilerState.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CompilerState.java 5 Apr 2002 14:37:52 -0000 1.5
--- CompilerState.java 6 Feb 2003 20:13:45 -0000 1.6
***************
*** 27,30 ****
--- 27,31 ----
HashMap comp_atts;
Stack lines;
+ String errorWord;
/** Creates new CompilerState */
***************
*** 223,226 ****
--- 224,243 ----
return this.currentLine == null;
}
+
+ /**
+ * Returns the errorWord.
+ * @return String
+ */
+ public String getErrorWord() {
+ return errorWord;
+ }
+
+ /**
+ * Sets the errorWord.
+ * @param errorWord The errorWord to set
+ */
+ public void setErrorWord(String errorWord) {
+ this.errorWord = errorWord;
+ }
}
|