initial commit of jsp2php converter

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@10 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2007-06-19 12:22:03 +00:00
parent 78333e44e1
commit e0e456ed9f
9 changed files with 896 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>net.sf.webim.converter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,40 @@
package net.sf.webim.converter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import net.sf.webim.converter.parser.Parser;
public class JspConverter {
public static void main(String[] args) {
String toProcess = getFileContents("C:\\projects\\sf\\webim\\src\\converter\\test.xml");
Parser p = new Parser();
String result = p.parse(toProcess);
System.out.println(">>>\n" + result + "<<<");
}
private static String getFileContents(String file) {
StringBuffer contents = new StringBuffer();
char[] buffer = new char[2048];
int count;
try {
Reader in = new InputStreamReader(new FileInputStream(file));
try {
while ((count = in.read(buffer)) > 0) {
contents.append(buffer, 0, count);
}
} finally {
in.close();
}
} catch (IOException ioe) {
return null;
}
return contents.toString();
}
}

View File

@ -0,0 +1,377 @@
// Parser.java
package net.sf.webim.converter.parser;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.ArrayList;
import net.sf.webim.converter.xml.XmlArgument;
import net.sf.webim.converter.xml.XmlNode;
public class Parser {
public Parser() {
}
private static final boolean DEBUG_SYNTAX = false;
private StringBuffer sb;
int killEnds = -1;
byte[] buff;
int l;
private String rawText(int start, int end) {
if( killEnds == start ) {
while( start < end && (buff[start] == '\t' || buff[start] == ' ') )
start++;
if( start < end && buff[start] == '\r' )
start++;
if( start < end && buff[start] == '\n' )
start++;
}
try {
return new String(buff, start, end-start, "utf-8");
} catch(UnsupportedEncodingException ex) {
return "";
}
}
void error( String s ) {
System.err.println(s);
}
public String parse(String s) {
l = 0;
sb = new StringBuffer();
try {
buff = s.getBytes("utf-8");
} catch( UnsupportedEncodingException ex ) {
return null;
}
if( parse() )
return sb.toString();
return null;
}
private void checkTag(XmlNode node, String endTag) {
if( !node.getTagName().equals(endTag) )
error("Tag " + node.getTagName() + " is closed with " + endTag);
}
public class lapg_place {
public int line, offset;
public lapg_place( int line, int offset ) {
this.line = line;
this.offset = offset;
}
};
public class lapg_symbol {
public Object sym;
public int lexem, state;
public lapg_place pos;
public lapg_place endpos;
};
private static final short[] lapg_char2no = new short[] {
0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5, 6, 7, 1, 1, 8, 1, 9, 1, 1, 1, 1, 1, 10, 1, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 1, 23, 24, 25, 1,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 1, 1, 1, 1, 53,
1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
private static final short[][] lapg_lexem = new short[][] {
{ -2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, },
{ -1, -1, 4, 4, 4, 4, -1, 5, -1, 6, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8, -1, 9, 10, -1, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, },
{ -3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, },
{ -4, -4, -4, -4, -4, -4, 12, -4, 13, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, },
{ -14, -14, 4, 4, 4, 4, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, },
{ -1, 5, 5, -1, 5, 5, 5, 14, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, },
{ -1, 6, 6, -1, 6, 6, 6, 6, 6, 15, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, },
{ -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, },
{ -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, },
{ -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, -11, },
{ -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, },
{ -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, 11, -8, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -8, -8, -8, -8, -8, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, },
{ -1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 18, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, },
{ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, },
{ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, },
{ -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, },
{ -1, 18, 18, 18, 18, 18, 18, 18, 20, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, },
{ -1, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, },
{ -1, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 22, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, },
{ -1, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, },
{ -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, },
{ -1, 19, 19, 19, 19, 19, 19, 19, 24, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, },
{ -1, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 25, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, },
{ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, },
};
private static final int[] lapg_action = new int[] {
-1, 9, -1, 6, 8, 7, -3, 2, -1, 5, -17, -27, 1, -1, -1, 3,
-1, -35, -1, -45, 18, -1, 4, 11, -1, 14, -1, 17, -1, 19, 15, 16,
-1, -2,
};
private static final short[] lapg_lalr = new short[] {
1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 0, 0, -1, -2, 10, -1,
6, 10, 8, 10, 11, 10, -1, -2, 6, -1, 8, 13, 11, 13, -1, -2,
9, -1, 6, 20, 8, 20, 11, 20, -1, -2, 6, -1, 8, 12, 11, 12,
-1, -2,
};
private static final short[] lapg_sym_goto = new short[] {
0, 1, 5, 9, 13, 17, 21, 27, 28, 31, 32, 33, 35, 35, 36, 38,
42, 46, 48, 52, 55, 56, 57, 59,
};
private static final short[] lapg_sym_from = new short[] {
32, 0, 6, 8, 14, 0, 6, 8, 14, 0, 6, 8, 14, 0, 6, 8,
14, 0, 6, 8, 14, 2, 11, 13, 16, 19, 21, 24, 18, 26, 28, 17,
10, 13, 18, 0, 0, 8, 0, 6, 8, 14, 0, 6, 8, 14, 8, 14,
0, 6, 8, 14, 2, 13, 21, 11, 11, 11, 19,
};
private static final short[] lapg_sym_to = new short[] {
33, 1, 1, 1, 1, 2, 2, 13, 13, 3, 3, 3, 3, 4, 4, 4,
4, 5, 5, 5, 5, 10, 17, 10, 23, 17, 10, 29, 25, 30, 31, 24,
16, 21, 26, 32, 6, 14, 7, 12, 7, 12, 8, 8, 8, 8, 15, 22,
9, 9, 9, 9, 11, 11, 28, 18, 19, 20, 27,
};
private static final short[] lapg_rlen = new short[] {
1, 2, 1, 2, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0, 4, 5,
4, 2, 1, 3, 1,
};
private static final short[] lapg_rlex = new short[] {
13, 14, 14, 15, 15, 15, 15, 15, 15, 15, 19, 19, 20, 20, 16, 18,
17, 21, 21, 22, 22,
};
private static final String[] lapg_syms = new String[] {
"eoi",
"any",
"'<'",
"comment",
"doctype",
"taglib",
"identifier",
"ccon",
"'>'",
"'='",
"':'",
"'/'",
"_skip",
"input",
"xml_tags",
"xml_tag_or_space",
"tag_start",
"tag_end",
"no_body_tag",
"tag_name",
"argumentsopt",
"arguments",
"argument",
};
public enum Tokens {
eoi,
any,
LESS,
comment,
doctype,
taglib,
identifier,
ccon,
GREATER,
EQ,
COLON,
DIV,
_skip,
input,
xml_tags,
xml_tag_or_space,
tag_start,
tag_end,
no_body_tag,
tag_name,
argumentsopt,
arguments,
argument,
}
private static int lapg_next( int state, int symbol ) {
int p;
if( lapg_action[state] < -2 ) {
for( p = - lapg_action[state] - 3; lapg_lalr[p] >= 0; p += 2 )
if( lapg_lalr[p] == symbol ) break;
return lapg_lalr[p+1];
}
return lapg_action[state];
}
private static int lapg_state_sym( int state, int symbol ) {
int min = lapg_sym_goto[symbol], max = lapg_sym_goto[symbol+1]-1;
int i, e;
while( min <= max ) {
e = (min + max) >> 1;
i = lapg_sym_from[e];
if( i == state )
return lapg_sym_to[e];
else if( i < state )
min = e + 1;
else
max = e - 1;
}
return -1;
}
public boolean parse() {
byte[] token = new byte[1024];
int lapg_head = 0, group = 0, lapg_i, lapg_size, chr;
lapg_symbol[] lapg_m = new lapg_symbol[1024];
lapg_symbol lapg_n;
int lapg_current_line = 1, lapg_current_offset = 0;
lapg_m[0] = new lapg_symbol();
lapg_m[0].state = 0;
chr = l < buff.length ? buff[l++] : 0;
do {
lapg_n = new lapg_symbol();
lapg_n.pos = new lapg_place( lapg_current_line, lapg_current_offset );
for( lapg_size = 0, lapg_i = group; lapg_i >= 0; ) {
if( lapg_size < 1024-1 ) token[lapg_size++] = (byte)chr;
lapg_i = lapg_lexem[lapg_i][lapg_char2no[(chr+256)%256]];
if( lapg_i >= -1 && chr != 0 ) {
lapg_current_offset++;
if( chr == '\n' ) lapg_current_line++;
chr = l < buff.length ? buff[l++] : 0;
}
}
lapg_n.endpos = new lapg_place( lapg_current_line, lapg_current_offset );
if( lapg_i == -1 ) {
if( chr == 0 ) {
error( "Unexpected end of file reached");
break;
}
error( MessageFormat.format( "invalid lexem at line {0}: `{1}`, skipped", lapg_n.pos.line, new String(token,0,lapg_size) ) );
lapg_n.lexem = -1;
continue;
}
lapg_size--;
lapg_n.lexem = -lapg_i-2;
lapg_n.sym = null;
switch( lapg_n.lexem ) {
case 2:
group = 1; break;
case 6:
lapg_n.sym = new String(token,0,lapg_size); break;
case 7:
lapg_n.sym = new String(token,1,lapg_size-2); break;
case 8:
group = 0; break;
case 12:
continue;
}
do {
lapg_i = lapg_next( lapg_m[lapg_head].state, lapg_n.lexem );
if( lapg_i >= 0 ) {
lapg_symbol lapg_gg = new lapg_symbol();
lapg_gg.sym = (lapg_rlen[lapg_i]!=0)?lapg_m[lapg_head+1-lapg_rlen[lapg_i]].sym:null;
lapg_gg.lexem = lapg_rlex[lapg_i];
lapg_gg.state = 0;
if( DEBUG_SYNTAX )
System.out.println( "reduce to " + lapg_syms[lapg_rlex[lapg_i]] );
lapg_gg.pos = (lapg_rlen[lapg_i]!=0)?lapg_m[lapg_head+1-lapg_rlen[lapg_i]].pos:lapg_n.pos;
lapg_gg.endpos = (lapg_rlen[lapg_i]!=0)?lapg_m[lapg_head].endpos:lapg_n.pos;
switch( lapg_i ) {
case 3:
checkTag(((XmlNode)lapg_m[lapg_head-1].sym),((String)lapg_m[lapg_head-0].sym));
break;
case 4:
checkTag(((XmlNode)lapg_m[lapg_head-2].sym),((String)lapg_m[lapg_head-0].sym));
break;
case 10:
lapg_gg.sym = ((String)lapg_m[lapg_head-0].sym);
break;
case 11:
lapg_gg.sym = ((String)lapg_m[lapg_head-2].sym) + ":" + ((String)lapg_m[lapg_head-0].sym);
break;
case 14:
lapg_gg.sym = new XmlNode(((String)lapg_m[lapg_head-2].sym), ((ArrayList<XmlArgument>)lapg_m[lapg_head-1].sym));
break;
case 15:
lapg_gg.sym = new XmlNode(((String)lapg_m[lapg_head-3].sym), ((ArrayList<XmlArgument>)lapg_m[lapg_head-2].sym));
break;
case 16:
lapg_gg.sym = ((String)lapg_m[lapg_head-1].sym);
break;
case 17:
((ArrayList<XmlArgument>)lapg_gg.sym).add(((XmlArgument)lapg_m[lapg_head-0].sym));
break;
case 18:
lapg_gg.sym = new ArrayList<XmlArgument>(); ((ArrayList<XmlArgument>)lapg_gg.sym).add(((XmlArgument)lapg_m[lapg_head-0].sym));
break;
case 19:
lapg_gg.sym = new XmlArgument();
break;
case 20:
lapg_gg.sym = new XmlArgument();
break;
}
for( int e = lapg_rlen[lapg_i]; e > 0; e-- )
lapg_m[lapg_head--] = null;
lapg_m[++lapg_head] = lapg_gg;
lapg_m[lapg_head].state = lapg_state_sym( lapg_m[lapg_head-1].state, lapg_gg.lexem );
} else if( lapg_i == -1 ) {
lapg_m[++lapg_head] = lapg_n;
lapg_m[lapg_head].state = lapg_state_sym( lapg_m[lapg_head-1].state, lapg_n.lexem );
if( DEBUG_SYNTAX )
System.out.println( MessageFormat.format( "shift: {0} ({1})", lapg_syms[lapg_n.lexem], new String(token,0,lapg_size) ) );
}
} while( lapg_i >= 0 && lapg_m[lapg_head].state != -1 );
if( (lapg_i == -2 || lapg_m[lapg_head].state == -1) && lapg_n.lexem != 0 ) {
break;
}
} while( lapg_n.lexem != 0 );
if( lapg_m[lapg_head].state != 34-1 ) {
error( MessageFormat.format( "syntax error before line {0}", lapg_n.pos.line ) );
return false;
};
return true;
}
}

View File

@ -0,0 +1,150 @@
# Automatically generated grammar
.lang "java"
.getsym "chr = l < buff.length ? buff[l++] : 0"
.positioning "offset"
.class "Parser"
.namespace "net.sf.webim.converter.parser"
.breaks "on"
.lexemend "on"
# Vocabulary
[0]
any: /[^<]+/
'<': /</ { group = @1; break; }
comment: /<%--([^-]|-[^-]|--[^%]|--%[^>])*--%>/
doctype: /<![^>]*>/
taglib: /<%@([^%]|%[^>])*%>/
[1]
identifier(String): /[a-zA-Z_][A-Za-z_0-9-]*/ -1 { @ = new String(token,0,lapg_size); break; }
ccon(String): /"[^\n"]*"/ { @ = new String(token,1,lapg_size-2); break; }
ccon: /'[^\n']*'/
'>': />/ { group = @0; break; }
'=': /=/
':': /:/
'/': /\//
_skip: /[\t\r\n ]+/ \ continue;
# Attributes
[]
# Grammar
input ::=
xml_tags
;
xml_tags ::=
xml_tags xml_tag_or_space
| xml_tag_or_space
;
xml_tag_or_space ::=
tag_start tag_end { checkTag($tag_start,$tag_end); }
| tag_start xml_tags tag_end { checkTag($tag_start,$tag_end); }
| no_body_tag
| comment
| taglib
| doctype
| any
;
tag_name (String) ::=
identifier { $$ = $identifier; }
| identifier ':' identifier { $$ = $identifier#0 + ":" + $identifier#1; }
;
tag_start (XmlNode) ::=
'<' tag_name argumentsopt '>' { $$ = new XmlNode($tag_name, $argumentsopt); }
;
no_body_tag (XmlNode) ::=
'<' tag_name argumentsopt '/' '>' { $$ = new XmlNode($tag_name, $argumentsopt); }
;
tag_end (String) ::=
'<' '/' tag_name '>' { $$ = $tag_name; }
;
arguments (ArrayList<XmlArgument>) ::=
arguments argument { $arguments.add($argument); }
| argument { $$ = new ArrayList<XmlArgument>(); $arguments.add($argument); }
;
argument (XmlArgument) ::=
identifier '=' ccon { $$ = new XmlArgument(); }
| identifier { $$ = new XmlArgument(); }
;
##################################################################################
%%
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.ArrayList;
import net.sf.webim.converter.xml.XmlArgument;
import net.sf.webim.converter.xml.XmlNode;
%%
public Parser() {
}
private static final boolean DEBUG_SYNTAX = false;
private StringBuffer sb;
int killEnds = -1;
byte[] buff;
int l;
private String rawText(int start, int end) {
if( killEnds == start ) {
while( start < end && (buff[start] == '\t' || buff[start] == ' ') )
start++;
if( start < end && buff[start] == '\r' )
start++;
if( start < end && buff[start] == '\n' )
start++;
}
try {
return new String(buff, start, end-start, "utf-8");
} catch(UnsupportedEncodingException ex) {
return "";
}
}
void error( String s ) {
System.err.println(s);
}
public String parse(String s) {
l = 0;
sb = new StringBuffer();
try {
buff = s.getBytes("utf-8");
} catch( UnsupportedEncodingException ex ) {
return null;
}
if( parse() )
return sb.toString();
return null;
}
private void checkTag(XmlNode node, String endTag) {
if( !node.getTagName().equals(endTag) )
error("Tag " + node.getTagName() + " is closed with " + endTag);
}

View File

@ -0,0 +1,5 @@
package net.sf.webim.converter.xml;
public class XmlArgument {
}

View File

@ -0,0 +1,18 @@
package net.sf.webim.converter.xml;
import java.util.List;
public class XmlNode {
private String tagName;
private List<XmlArgument> arguments;
public XmlNode(String tagName, List<XmlArgument> arguments) {
this.tagName = tagName;
this.arguments = arguments;
}
public String getTagName() {
return tagName;
}
}

273
src/converter/test.xml Normal file
View File

@ -0,0 +1,273 @@
<%@ page contentType="text/html; charset=utf-8" errorPage="/errors/error_page.jsp" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tiles" uri="/tags/struts-tiles"%>
<%@ taglib prefix="html" uri="/tags/struts-html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="is" uri="imcenter.i_services.ru.tags"%>
<%@ taglib prefix="bean" uri="/tags/struts-bean"%>
<tiles:useAttribute id="titleKey" name="titleKey" classname="java.lang.String" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><bean:message key="<%=titleKey%>" /></title>
<link rel="shortcut icon" href="<c:url value='/res/images/favicon.ico'/>" type="image/x-icon"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/res/style/chat.css'/>" />
<script type="text/javascript" language="javascript" src="<c:url value='/res/common.js'/>"></script>
<script type="text/javascript" language="javascript" src="<c:url value='/res/brws.js'/>"></script>
<script language="javascript"><!--
var threadParams = { servl:"<html:rewrite action='/Thread'/>",frequency:2,<c:if test="${user}">user:"true",</c:if>threadid:${ct.chatThreadId},token:${ct.token} };
//--></script>
<script type="text/javascript" language="javascript" src="<c:url value='/res/page_chat.js'/>"></script>
</head>
<body bgcolor="#FFFFFF" background="<c:url value='/res/images/chat/bg.gif'/>" text="#000000" link="#C28400" vlink="#C28400" alink="#C28400" marginwidth="0" marginheight="0" leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td valign="top">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td></td>
<td colspan="2" height="100" background="<c:url value='/res/images/chat/banner.gif'/>" valign="top" class="bgrn">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="50%" valign="top">
<table width="135" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="25"></td>
</tr>
<tr>
<td align="center"><c:if test="${not empty ct.company.chatLogoURL}"><img src="<c:url value='${ct.company.chatLogoURL}'/>" width="85" height="45" border="0" alt=""/></c:if></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td align="center" class="text">${ct.company.name}</td>
</tr>
</table>
</td>
<td width="50%" align="right" valign="top">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="25" align="right">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="text"><bean:message key="chat.window.product_name"/></td>
<td width="5"></td>
<td>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="95" height="13" bgcolor="#D09221" align="center" class="www"><a href="<bean:message key='site.url'/>" title="<bean:message key='company.title'/>" target="_blank"><bean:message key='site.title'/></a></td>
</tr>
</table>
</td>
<td width="5"></td>
<td><a class="closethread" href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.close_title'/>"><html:img page="/res/images/chat/buttons/closewin.gif" width="15" height="15" border="0" altKey="chat.window.close_link_text"/></a></td>
<td width="5"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="60" align="right">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<c:if test="${agent}">
<td class="text" nowrap>
<bean:message key="chat.window.chatting_with"/> <b><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.chatting_with'/> <c:out value='${ct.user.name}'/>"><c:out value='${ct.user.name}'/></a></b><br/>
</td>
</c:if><c:if test="${user}">
<td class="text" nowrap>
<div id="changename1" style="display:${displ1};">
<table cellspacing="0" cellpadding="0" border="0"><tr>
<td class="text" nowrap><bean:message key="chat.client.name"/></td>
<td width="10" valign="top"><html:img page="/res/images/free.gif" width="10" height="1" border="0" alt="" /></td>
<td><input id="uname" type="text" size="12" value="<c:out value='${ct.user.name}'/>" class="username"/></td>
<td width="5" valign="top"><html:img page="/res/images/free.gif" width="5" height="1" border="0" alt="" /></td>
<td><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.client.changename'/>"><html:img page="/res/images/chat/buttons/exec.gif" width="25" height="25" border="0" alt="&gt;&gt;" /></a></td>
</tr></table>
</div>
<div id="changename2" style="display:${displ2};">
<table cellspacing="0" cellpadding="0" border="0"><tr>
<td class="text" nowrap><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.client.changename'/>"><bean:message key="chat.client.changename"/></a></td>
<td width="10" valign="top"><html:img page="/res/images/free.gif" width="10" height="1" border="0" alt="" /></td>
<td><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.client.changename'/>"><html:img page="/res/images/chat/buttons/changeuser.gif" width="25" height="25" border="0" alt="" /></a></td>
</tr></table>
</div>
</td>
</c:if>
<c:if test="${agent}">
<td width="10" valign="top"><html:img page="/res/images/free.gif" width="10" height="1" border="0" alt="" /></td>
<td><a class="closethread" href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.close_title'/>">
<html:img page="/res/images/chat/buttons/close.gif" width="25" height="25" border="0" altKey="chat.window.close_link_text"/></a></td>
</c:if>
<!--
<td><html:img page="/res/images/chat/buttons/changeuser.gif" width="25" height="25" border="0" alt="Change User" /></td>
-->
<td><html:img page="/res/images/chat/buttondiv.gif" width="35" height="45" border="0" alt="" /></td>
<c:if test="${user}">
<td><is:popupLink options="toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,width=603,height=204,resizable=0" name="ForwardMail" href="${selfLink}&page=mailthread">
<jsp:attribute name="title"><bean:message key='chat.window.toolbar.mail_history'/></jsp:attribute>
<jsp:body><html:img page="/res/images/chat/buttons/email.gif" width="25" height="25" border="0" alt="Mail&nbsp;"/></jsp:body>
</is:popupLink></td>
</c:if><%--jsponly--%><c:if test="${agent && canpost}">
<td><a href="${selfLink}&page=redirect" title="<bean:message key='chat.window.toolbar.redirect_user'/>">
<html:img page="/res/images/chat/buttons/send.gif" width="25" height="25" border="0" alt="Redirect&nbsp;" /></a></td>
</c:if>
<c:if test="${agent && not empty requestScope.historyParams}">
<td><is:popupLink options="toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,width=703,height=380,resizable=1" name="UserHistory">
<jsp:attribute name="href"><html:rewrite forward="client_analysis_userhistory" name="historyParams"/></jsp:attribute>
<jsp:attribute name="title"><bean:message key='page.analysis.userhistory.title'/></jsp:attribute>
<jsp:body><html:img page="/res/images/chat/buttons/history.gif" width="25" height="25" border="0" alt="History&nbsp;"/></jsp:body>
</is:popupLink></td>
</c:if><%--end--%>
<td><a id="refresh" href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.toolbar.refresh'/>">
<html:img page="/res/images/chat/buttons/refresh.gif" width="25" height="25" border="0" alt="Refresh&nbsp;" /></a></td>
<%--jsponly--%><c:if test="${not empty requestScope.sslLink}">
<td><a href="${requestScope.sslLink}" title="<bean:message key='chat.window.toolbar.ssl'/>">
<html:img page="/res/images/chat/buttons/lock.gif" width="25" height="25" border="0" alt="Lock" /></a></td>
</c:if><%--end--%>
<td width="20" valign="top"><html:img page="/res/images/free.gif" width="20" height="1" border="0" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
<td valign="top">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="20" valign="top"><html:img pageKey="image.chat.history" width="20" height="80" border="0" alt="" /></td>
<td colspan="2" width="100%" height="100%" valign="top" id="chatwndtd">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3" bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
<td width="100%" height="100%" bgcolor="#FFFFFF" valign="top">
<iframe id="chatwnd" width="100%" height="100%" src="" frameborder="0" style="overflow:auto;">
Sorry, your browser does not support iframes; try a browser that supports W3 standards.
</iframe>
</td>
<td bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="3" bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
</table>
</td>
</tr>
<c:if test="${canpost}">
<tr>
<td colspan="3" height="5" style="cursor:n-resize;" id="spl1"></td>
</tr>
<tr>
<td width="20" valign="top"><html:img pageKey="image.chat.message" width="20" height="85" border="0" alt="" /></td>
<td width="100%" height="100" valign="top" id="msgwndtd">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3" bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
<td width="100%" height="100%" bgcolor="#FFFFFF" valign="top">
<textarea id="msgwnd" class="message" tabindex="0"></textarea>
</td>
<td bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="3" bgcolor="#A1A1A1"><html:img page="/res/images/free.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
</table>
</td>
<td valign="center" id="avatarwnd"></td>
</tr>
</c:if>
</table>
</td>
<td></td>
</tr>
<tr>
<td height="45"></td>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="33%">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="20"></td>
<%-- <c:if test="${user}">
<td style="padding-left:10px;">
Switch to <a href="${linkWoLevel}&level=simple">Level2</a>
</td>
</c:if> --%>
<%--jsponly--%><c:if test="${agent && canpost}">
<td>
<select id="predefined" size="1" class="answer">
<option><bean:message key="chat.window.predefined.select_answer" /></option>
<c:forEach var="it" items="${predefinedList}"><option>${fn:escapeXml(it)}</option></c:forEach>
</select>
</td>
</c:if><%--end--%>
</tr>
</table>
</td>
<td width="33%" align="center" class="copyr"><bean:message key="chat.window.poweredby" /> <a href="<bean:message key='site.url'/>" title="<bean:message key='company.title'/>" target="_blank"><bean:message key="chat.window.poweredreftext"/></a></td>
<td width="33%" align="right">
<c:if test="${canpost}">
<table cellspacing="0" cellpadding="0" border="0" id="postmessage">
<tr>
<td><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.send_message'/>"><html:img page="/res/images/chat/submit.gif" width="40" height="35" border="0" alt="" /></a></td>
<td background="<c:url value='/res/images/chat/submitbg.gif'/>" valign="top" class="submit">
<html:img page="/res/images/free.gif" width="1" height="10" border="0" alt="" /><br/>
<a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.send_message'/>"><bean:message key='chat.window.send_message_short'/></a><br/>
</td>
<td width="10"><a href="javascript:void(0)" onclick="return false;" title="<bean:message key='chat.window.send_message'/>"><html:img page="/res/images/chat/submitrest.gif" width="10" height="35" border="0" alt="" /></a></td>
</tr>
</table>
</c:if>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
<tr>
<td width="10"><html:img page="/res/images/free.gif" width="10" height="1" border="0" alt="" /></td>
<td width="100%"><html:img page="/res/images/free.gif" width="585" height="1" border="0" alt="" /></td>
<td width="5"><html:img page="/res/images/free.gif" width="5" height="1" border="0" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

10
src/converter/test.xml2 Normal file
View File

@ -0,0 +1,10 @@
<root>
<load img="aaa"/>
<img src="www.ya.ru" width="10" height="15">Wow</img>
</root>