Update of /var/cvs/src/org/mmbase/util/transformers
In directory james.mmbase.org:/tmp/cvs-serv32106
Modified Files:
ListParser.jj XmlField.java
Log Message:
MMB-1658
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util/transformers
See also: http://www.mmbase.org/jira/browse/MMB-1658
Index: ListParser.jj
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/transformers/ListParser.jj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ListParser.jj 16 Jun 2008 16:09:55 -0000 1.1
+++ ListParser.jj 17 Jun 2008 10:00:45 -0000 1.2
@@ -12,14 +12,13 @@
* This file is parsed by <a href="https://javacc.dev.java.net/">javacc</a>.
*
* @author Michiel Meeuwisssen
- * @since MMBase-1-8
+ * @since MMBase-1.8.6
+ * @version $Id: ListParser.jj,v 1.2 2008/06/17 10:00:45 michiel Exp $
*/
options {
- LOOKAHEAD = 2;
STATIC = false;
- FORCE_LA_CHECK = false;
- IGNORE_CASE = true;
+ IGNORE_CASE = false;
}
PARSER_BEGIN(ListParser)
@@ -33,11 +32,12 @@
public class ListParser {
int curDepth = 0;
+ boolean begin = true;
LinkedList<Character> stack = new LinkedList<Character>();
static String transform( String inString ) {
- Reader reader = new StringReader( inString ) ;
- ListParser parser = new ListParser( reader ) ;
+ Reader reader = new StringReader(inString) ;
+ ListParser parser = new ListParser(reader) ;
StringBuffer buffer = new StringBuffer() ;
try {
parser.start(buffer) ; }
@@ -49,20 +49,22 @@
}
int getDepth(Token t) {
- return t.image.length() - 2;
+ return t.image.length() - (begin ? 1 : 2);
}
char getType(Token t) {
- return t.image.charAt(1) == '*' ? 'o' : 'u';
+ return t.image.charAt(begin ? 0 : 1) == '*' ? 'o' : 'u';
}
void open(StringBuffer buf, char type) {
curDepth++;
stack.addFirst(type);
- buf.append("\n<").append(type).append("l>");
+ if (! begin && curDepth == 1) buf.append('\n');
+ buf.append('<').append(type).append("l>");
}
void close(StringBuffer buf) {
curDepth--;
char t = stack.removeFirst();
buf.append("</li></").append(t).append("l>");
+ if (curDepth > 0) buf.append("</li>");
}
void handleList(StringBuffer buf, Token t) {
int depth = getDepth(t);
@@ -74,7 +76,6 @@
} else if (depth == curDepth) {
buf.append("</li>");
}
-
buf.append("<li>");
}
void endLists(StringBuffer buf) {
@@ -92,9 +93,10 @@
PARSER_END(ListParser)
-
-TOKEN : { <OL: ("\n*") ("*")* (" ")> }
-TOKEN : { <UL: ("\n-") ("-")* (" ")> }
+TOKEN : { <BOL: "*" ("*")* (" ")> }
+TOKEN : { <BUL: "-" ("-")* (" ")> }
+TOKEN : { <OL: "\n*" ("*")* (" ")> }
+TOKEN : { <UL: "\n-" ("-")* (" ")> }
TOKEN : { <END: ("\n")> }
TOKEN : { <OTHER : ~[] > }
@@ -105,10 +107,12 @@
{
(
- t = <OL> { handleList(buf, t); }
- | t = <UL> { handleList(buf, t); }
- | <END> { endLists(buf); buf.append("\n");}
- | (t = <OTHER>) { buf.append(t.image); }
+ t = <OL> { begin = false; handleList(buf, t); }
+ | t = <UL> { begin = false; handleList(buf, t); }
+ | t = <BOL> { if (begin) { handleList(buf, t); begin = false; } else {
buf.append(t.image); }}
+ | t = <BUL> { if (begin) { handleList(buf, t); begin = false; } else {
buf.append(t.image); }}
+ | <END> { if (begin) { buf.append("\n"); } else { endLists(buf);
buf.append("\n"); } }
+ | (t = <OTHER>) { begin = false; buf.append(t.image); }
)*
<EOF> { endLists(buf); }
}
Index: XmlField.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/transformers/XmlField.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -b -r1.61 -r1.62
--- XmlField.java 10 Jun 2008 12:26:29 -0000 1.61
+++ XmlField.java 17 Jun 2008 10:00:45 -0000 1.62
@@ -20,7 +20,7 @@
* XMLFields in MMBase. This class can encode such a field to several other
formats.
*
* @author Michiel Meeuwissen
- * @version $Id: XmlField.java,v 1.61 2008/06/10 12:26:29 michiel Exp $
+ * @version $Id: XmlField.java,v 1.62 2008/06/17 10:00:45 michiel Exp $
*/
public class XmlField extends ConfigurableStringTransformer implements
CharTransformer {
@@ -61,6 +61,17 @@
* Takes a string object, finds list structures and changes those to XML
*/
static void handleList(StringObject obj) {
+ String result = ListParser.transform(obj.toString());
+ obj.setLength(0);
+ obj.append(result);
+ }
+
+ /**
+ * This is the original implementation of [EMAIL PROTECTED] #handleList},
but withouth suppport lists in
+ * lists (MMB-1658). Code pretty much incomprehensible as it is, so didn't
add support for this
+ * here, but redid it in ListParser.jj.
+ */
+ private static void handleListLegacy(StringObject obj) {
// handle lists
// make <ul> possible (not yet nested), with -'s on the first char of
line.
int inList = 0; //
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs