2 |
|
|
3 |
package org.nongnu.alph.xml; |
package org.nongnu.alph.xml; |
4 |
import org.nongnu.alph.*; |
import org.nongnu.alph.*; |
5 |
|
import org.nongnu.alph.util.*; |
6 |
import java.util.List; |
import java.util.List; |
7 |
import java.util.Iterator; |
import java.util.Iterator; |
8 |
|
|
11 |
|
|
12 |
public class SpanSerializer { |
public class SpanSerializer { |
13 |
|
|
|
public static String escapeXML(String s) { |
|
|
StringBuffer buf = new StringBuffer(); |
|
|
for(int i=0; i<s.length(); i++) { |
|
|
switch(s.charAt(i)) { |
|
|
case '&': buf.append("&"); break; |
|
|
case '<': buf.append("<"); break; |
|
|
case '>': buf.append(">"); break; |
|
|
case '\'': buf.append("'"); break; |
|
|
case '\"': buf.append("""); break; |
|
|
default: |
|
|
buf.append(s.charAt(i)); break; |
|
|
} |
|
|
} |
|
|
return buf.toString(); |
|
|
} |
|
|
|
|
14 |
public String namespace; |
public String namespace; |
15 |
|
|
16 |
public String span2xml(Span s0) { |
public String span2xml(Span s0) { |
18 |
org.nongnu.alph.impl.URN5TextSpan t = (org.nongnu.alph.impl.URN5TextSpan)s0; |
org.nongnu.alph.impl.URN5TextSpan t = (org.nongnu.alph.impl.URN5TextSpan)s0; |
19 |
return "<uts b=\""+t.getScrollId()+ |
return "<uts b=\""+t.getScrollId()+ |
20 |
"\" o=\""+t.offset()+ |
"\" o=\""+t.offset()+ |
21 |
"\" t=\""+escapeXML(t.getText())+"\"/>"; |
"\" t=\""+XMLUtil.escapeXML(t.getText())+"\"/>"; |
22 |
} else if(s0 instanceof TextSpan) { |
} else if(s0 instanceof TextSpan) { |
23 |
TextSpan s = (TextSpan)s0; |
TextSpan s = (TextSpan)s0; |
24 |
return "<" + (namespace == null ? "" : |
return "<" + (namespace == null ? "" : |