[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/deploy/macro MacroToXML.java,1.13,1.14 MacroToX
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-03-04 23:05:39
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/macro
In directory usw-pr-cvs1:/tmp/cvs-serv28790/src/net/sourceforge/idrs/deploy/macro
Modified Files:
MacroToXML.java MacroToXMLHandler.java
Log Message:
Completed initial xml compilation system
Index: MacroToXML.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/macro/MacroToXML.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** MacroToXML.java 25 Jan 2002 14:49:03 -0000 1.13
--- MacroToXML.java 4 Mar 2002 23:05:35 -0000 1.14
***************
*** 35,43 ****
boolean lastOwnLine;
boolean inTag;
!
Stack writeStack;
!
String currentTagName;
!
/**
*Constructor, loads transoformation xml document
--- 35,43 ----
boolean lastOwnLine;
boolean inTag;
! String rmlNS;
Stack writeStack;
!
String currentTagName;
!
/**
*Constructor, loads transoformation xml document
***************
*** 46,50 ****
*@param isFile Identifies if xmlSrc is the xml as a string or a path to the xml file
*/
! public MacroToXML(String parser, String xmlSrc, boolean isFile) throws Exception {
ownLine = false;
inTag = false;
--- 46,50 ----
*@param isFile Identifies if xmlSrc is the xml as a string or a path to the xml file
*/
! public MacroToXML(String parser, String xmlSrc, boolean isFile,String rmlNS) throws Exception {
ownLine = false;
inTag = false;
***************
*** 56,62 ****
lastOwnLine = false;
writeStack = new Stack();
!
XMLReader xmlParser = XMLReaderFactory.createXMLReader(parser);
!
InputSource in;
info = new MacroToXMLHandler();
--- 56,64 ----
lastOwnLine = false;
writeStack = new Stack();
! this.rmlNS=rmlNS;
!
!
XMLReader xmlParser = XMLReaderFactory.createXMLReader(parser);
!
InputSource in;
info = new MacroToXMLHandler();
***************
*** 67,74 ****
in = new InputSource(new StringReader(xmlSrc));
}
xmlParser.setContentHandler(info);
xmlParser.parse(in);
}
!
/**
*Sets the rml-macro source as a string
--- 69,77 ----
in = new InputSource(new StringReader(xmlSrc));
}
+
xmlParser.setContentHandler(info);
xmlParser.parse(in);
}
!
/**
*Sets the rml-macro source as a string
***************
*** 78,82 ****
this.rmlSrc = rml;
}
!
/**
*Sets the writer where the RML-XML will be written to
--- 81,85 ----
this.rmlSrc = rml;
}
!
/**
*Sets the writer where the RML-XML will be written to
***************
*** 85,90 ****
public void setWriter(Writer out) throws IOException {
this.out = out;
}
!
/**
*Transforms the RML-Macro page into an RML-XML page
--- 88,94 ----
public void setWriter(Writer out) throws IOException {
this.out = out;
+
}
!
/**
*Transforms the RML-Macro page into an RML-XML page
***************
*** 93,109 ****
int begin=0,end=0,tagEnd;
boolean isScript;
!
String curr = "", tag="";
end = rmlSrc.indexOf("<",begin);
!
while (end != -1) {
!
isScript = isScriptTag(end);
curr = rmlSrc.substring(begin,end);
!
//debug
System.out.println("text : " + curr);
!
!
if (isScript) {
outText(curr);
--- 97,113 ----
int begin=0,end=0,tagEnd;
boolean isScript;
! out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
String curr = "", tag="";
end = rmlSrc.indexOf("<",begin);
!
while (end != -1) {
!
isScript = isScriptTag(end);
curr = rmlSrc.substring(begin,end);
!
//debug
System.out.println("text : " + curr);
!
!
if (isScript) {
outText(curr);
***************
*** 112,120 ****
else {
tagEnd = readTag(end);
!
tag = rmlSrc.substring(end, tagEnd);
!
System.out.print("tag : " + tag);
!
if (isRMLTag(tag)) {
outText(curr);
--- 116,124 ----
else {
tagEnd = readTag(end);
!
tag = rmlSrc.substring(end, tagEnd);
!
System.out.print("tag : " + tag);
!
if (isRMLTag(tag)) {
outText(curr);
***************
*** 126,136 ****
}
}
!
begin = tagEnd;
end = rmlSrc.indexOf("<",begin);
}
!
}
!
/**
*Determines if current tag is a script tag
--- 130,140 ----
}
}
!
begin = tagEnd;
end = rmlSrc.indexOf("<",begin);
}
!
}
!
/**
*Determines if current tag is a script tag
***************
*** 140,144 ****
return rmlSrc.charAt(begin + 1) == info.getScriptChar();
}
!
/**
*Writes a fully xml compatable version of a script
--- 144,148 ----
return rmlSrc.charAt(begin + 1) == info.getScriptChar();
}
!
/**
*Writes a fully xml compatable version of a script
***************
*** 154,190 ****
String tmpLine,whiteSpace;
StringTokenizer tok;
!
tag = "<" + info.getNameSpace() + ":" + (isEcho ? info.getEchoScriptTag() : info.getScriptTag()) + ">";
out.write(tag);
! if (isEcho) {
! out.write(script);
! }
! else {
! tmpLine = script.substring(1,script.indexOf('\n'));
! script = script.substring(script.indexOf('\n') + 1);
! taglen = tag.length() + ((String) "</" + info.getNameSpace() + ":" + info.getTextTag() + ">").length();
! spaceBegin = rmlSrc.lastIndexOf('\n',begin);
! //whiteSpace = rmlSrc.substring(spaceBegin + 1,begin);
! whiteSpace = "";
!
! for (int i=0;i<taglen;i++)
! whiteSpace += " ";
!
! tok = new StringTokenizer(script,"\n",false);
!
! out.write(tmpLine + "\n");
! while (tok.hasMoreTokens()) {
! out.write(whiteSpace + tok.nextToken() + "\n");
! }
! }
out.write("</" + info.getNameSpace() + ":");
out.write( isEcho ? info.getEchoScriptTag() : info.getScriptTag());
out.write(">");
!
return end + 2;
}
!
/**
*Writes text apropriatly, either with text tags or without them
--- 158,176 ----
String tmpLine,whiteSpace;
StringTokenizer tok;
!
tag = "<" + info.getNameSpace() + ":" + (isEcho ? info.getEchoScriptTag() : info.getScriptTag()) + ">";
out.write(tag);
+
! out.write(script);
+
out.write("</" + info.getNameSpace() + ":");
out.write( isEcho ? info.getEchoScriptTag() : info.getScriptTag());
out.write(">");
!
return end + 2;
}
!
/**
*Writes text apropriatly, either with text tags or without them
***************
*** 194,210 ****
boolean hasCR = (txt.indexOf("\n") != -1);
String splitText;
!
if (txt.length() == 0) return;
!
!
!
!
if (this.ownLine) {
if (shouldWrite() && hasCR && !lastOwnLine)
out.write("<" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
if (hasCR) {
splitText = xmlEncode(txt.substring(0,txt.lastIndexOf('\n')));
! if (splitText.trim().length() != 0)
out.write(splitText);
}
--- 180,196 ----
boolean hasCR = (txt.indexOf("\n") != -1);
String splitText;
!
if (txt.length() == 0) return;
!
!
!
!
if (this.ownLine) {
if (shouldWrite() && hasCR && !lastOwnLine)
out.write("<" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
if (hasCR) {
splitText = xmlEncode(txt.substring(0,txt.lastIndexOf('\n')));
! if (splitText.trim().length() != 0)
out.write(splitText);
}
***************
*** 212,222 ****
out.write(xmlEncode("\n" + txt));
}
!
if (shouldWrite() && hasCR && !lastOwnLine)
out.write("</" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
if (hasCR)
out.write(xmlEncode(txt.substring(txt.lastIndexOf('\n'))));
!
}
else {
--- 198,208 ----
out.write(xmlEncode("\n" + txt));
}
!
if (shouldWrite() && hasCR && !lastOwnLine)
out.write("</" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
if (hasCR)
out.write(xmlEncode(txt.substring(txt.lastIndexOf('\n'))));
!
}
else {
***************
*** 225,244 ****
this.lastOwnLine = false;
}
!
if (shouldWrite())
out.write("<" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
out.write(xmlEncode(txt));
!
if (shouldWrite())
out.write("</" + info.getNameSpace() + ":" + info.getTextTag() + ">");
}
!
!
lookLastTag = false;
inSimple = false;
}
!
!
/**
*Reads rmlSrc for position of the end of the current tag
--- 211,230 ----
this.lastOwnLine = false;
}
!
if (shouldWrite())
out.write("<" + info.getNameSpace() + ":" + info.getTextTag() + ">");
!
out.write(xmlEncode(txt));
!
if (shouldWrite())
out.write("</" + info.getNameSpace() + ":" + info.getTextTag() + ">");
}
!
!
lookLastTag = false;
inSimple = false;
}
!
!
/**
*Reads rmlSrc for position of the end of the current tag
***************
*** 248,252 ****
return rmlSrc.indexOf(">", begin)+1;
}
!
/**
*Determines if a tag is an RML tag
--- 234,238 ----
return rmlSrc.indexOf(">", begin)+1;
}
!
/**
*Determines if a tag is an RML tag
***************
*** 254,258 ****
*/
protected boolean isRMLTag(String tag) {
!
int begin=0, end=0,tmp;
char c;
--- 240,244 ----
*/
protected boolean isRMLTag(String tag) {
!
int begin=0, end=0,tmp;
char c;
***************
*** 260,266 ****
String tagName;
boolean isTag=false;
!
//writeText = isBody;
!
if (c == '/') {
begin = 2;
--- 246,252 ----
String tagName;
boolean isTag=false;
!
//writeText = isBody;
!
if (c == '/') {
begin = 2;
***************
*** 271,286 ****
inTag = false;
}
!
tmp = tag.indexOf(" ",begin);
if (tmp == -1) {
tmp = tag.indexOf(">",begin);
}
!
tagName = tag.substring(begin,tmp);
!
this.currentTagName=tagName;
!
isTag = info.isRMLTag(tagName.toLowerCase().trim());
!
if (isTag) {
this.ownLine = info.isTagOwnLine(tagName.toLowerCase().trim());
--- 257,272 ----
inTag = false;
}
!
tmp = tag.indexOf(" ",begin);
if (tmp == -1) {
tmp = tag.indexOf(">",begin);
}
!
tagName = tag.substring(begin,tmp);
!
this.currentTagName=tagName;
!
isTag = info.isRMLTag(tagName.toLowerCase().trim());
!
if (isTag) {
this.ownLine = info.isTagOwnLine(tagName.toLowerCase().trim());
***************
*** 290,295 ****
else {
this.inSimple = info.isTagSimple(tagName.toLowerCase().trim());
!
!
if (! writeStack.empty()) {
this.lastTagWrite = ((Boolean) writeStack.peek()).booleanValue();
--- 276,281 ----
else {
this.inSimple = info.isTagSimple(tagName.toLowerCase().trim());
!
!
if (! writeStack.empty()) {
this.lastTagWrite = ((Boolean) writeStack.peek()).booleanValue();
***************
*** 298,313 ****
this.lastTagWrite = false;
}
!
! this.lookLastTag = true;
writeStack.push(new Boolean(this.inSimple));
System.out.println("PUSH " + tagName);
popTag = false;
}
!
!
}
!
/*
!
if (isTag && (tagName.toLowerCase().trim().equalsIgnoreCase("body") || tagName.toLowerCase().trim().equalsIgnoreCase("head")))
if (inTag)
--- 284,299 ----
this.lastTagWrite = false;
}
!
! this.lookLastTag = ! this.inSimple;
writeStack.push(new Boolean(this.inSimple));
System.out.println("PUSH " + tagName);
popTag = false;
}
!
!
}
!
/*
!
if (isTag && (tagName.toLowerCase().trim().equalsIgnoreCase("body") || tagName.toLowerCase().trim().equalsIgnoreCase("head")))
if (inTag)
***************
*** 316,323 ****
isBody = true;
}*/
!
return isTag;
}
!
/**
*Writes the RML tag as full XML 1.0 tag
--- 302,309 ----
isBody = true;
}*/
!
return isTag;
}
!
/**
*Writes the RML tag as full XML 1.0 tag
***************
*** 332,352 ****
StringTokenizer tok;
String token;
!
!
tagName = this.currentTagName;
!
out.write("<" + ((c=='/') ? "/" : "") + info.getNameSpace() + ":");
!
begin = end;
end = tag.indexOf(">");
!
begin = tag.indexOf(tagName) + tagName.length();
atts = tag.substring(begin,end);
!
tok = new StringTokenizer(atts,"\"",false);
!
!
out.write(info.getCorrectRMLTagName(tagName));
!
while (tok.hasMoreTokens() && tok.countTokens() != 1) {
token = tok.nextToken();
--- 318,343 ----
StringTokenizer tok;
String token;
!
!
tagName = this.currentTagName;
!
out.write("<" + ((c=='/') ? "/" : "") + info.getNameSpace() + ":");
!
begin = end;
end = tag.indexOf(">");
!
begin = tag.indexOf(tagName) + tagName.length();
atts = tag.substring(begin,end);
!
tok = new StringTokenizer(atts,"\"",false);
!
!
out.write(info.getCorrectRMLTagName(tagName));
!
! if (tagName.toLowerCase().trim().equals("rml") && c != '/') {
! out.write(" xmlns:" + info.getNameSpace() + "=\"" + rmlNS + "\" ");
! }
!
!
while (tok.hasMoreTokens() && tok.countTokens() != 1) {
token = tok.nextToken();
***************
*** 363,367 ****
if (popTag) {
System.out.println("POP " + tagName);
! writeStack.pop();
popTag = false;
}
--- 354,359 ----
if (popTag) {
System.out.println("POP " + tagName);
! if (! writeStack.empty())
! writeStack.pop();
popTag = false;
}
Index: MacroToXMLHandler.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/deploy/macro/MacroToXMLHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MacroToXMLHandler.java 27 Feb 2002 23:56:31 -0000 1.7
--- MacroToXMLHandler.java 4 Mar 2002 23:05:35 -0000 1.8
***************
*** 40,44 ****
Attributes atts;
StringBuffer currBuff;
!
/**
* Constructor for MacroToXMLHandler
--- 40,44 ----
Attributes atts;
StringBuffer currBuff;
!
/**
* Constructor for MacroToXMLHandler
***************
*** 48,75 ****
rmlTags = new HashMap();
}
!
public void startDocument() throws SAXException {
!
}
!
public void endDocument() throws SAXException {
!
}
!
public void startElement(String namespaceURI, String loaclName, String rawName, Attributes atts) throws SAXException {
currBuff = new StringBuffer();
this.atts=atts;
}
!
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
String name = localName.toLowerCase();
String rep;
!
if (name.equals(RML)) {
System.out.println("Found Tag : " + currBuff.toString().trim().toLowerCase());
! rep = atts.getValue(REPRESENT);
!
rmlTags.put(currBuff.toString().trim().toLowerCase(),new Tag(rep==null ? currBuff.toString().trim() : rep, Boolean.valueOf(atts.getValue(IS_SIMPLE)).booleanValue(), Boolean.valueOf(atts.getValue(OWN_LINE)).booleanValue()));
! }
else if (name.equals(TEXT_TAG)) {
textTag = currBuff.toString();
--- 48,79 ----
rmlTags = new HashMap();
}
!
public void startDocument() throws SAXException {
!
}
!
public void endDocument() throws SAXException {
!
}
!
public void startElement(String namespaceURI, String loaclName, String rawName, Attributes atts) throws SAXException {
currBuff = new StringBuffer();
this.atts=atts;
+ String rep = atts.getValue(REPRESENT);
+
}
!
public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
String name = localName.toLowerCase();
String rep;
!
if (name.equals(RML)) {
System.out.println("Found Tag : " + currBuff.toString().trim().toLowerCase());
! rep = atts.getValue(REPRESENT);
!
!
!
rmlTags.put(currBuff.toString().trim().toLowerCase(),new Tag(rep==null ? currBuff.toString().trim() : rep, Boolean.valueOf(atts.getValue(IS_SIMPLE)).booleanValue(), Boolean.valueOf(atts.getValue(OWN_LINE)).booleanValue()));
! }
else if (name.equals(TEXT_TAG)) {
textTag = currBuff.toString();
***************
*** 97,111 ****
}
}
!
public void characters(char[] ch, int start, int end) {
for (int i=start;i<start + end;i++) {
! currBuff.append(ch[i]);
}
}
!
/**
*Retrieves the character identified by the transformation document as the script character,
*the default is $ for <$ $>, <$= $>
! *@return
*/
public char getScriptChar() {
--- 101,115 ----
}
}
!
public void characters(char[] ch, int start, int end) {
for (int i=start;i<start + end;i++) {
! currBuff.append(ch[i]);
}
}
!
/**
*Retrieves the character identified by the transformation document as the script character,
*the default is $ for <$ $>, <$= $>
! *@return
*/
public char getScriptChar() {
|