mirror of https://github.com/apache/lucene.git
Adding a convenience method which passes attributes in a Map
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@724662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2430817fe1
commit
1ffed882a9
|
@ -19,6 +19,7 @@ package org.apache.solr.common.util;
|
||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
@ -153,6 +154,31 @@ public class XML {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** escapes character data in val */
|
||||||
|
public static void writeXML(Writer out, String tag, String val, Map<String, String> attrs) throws IOException {
|
||||||
|
out.write('<');
|
||||||
|
out.write(tag);
|
||||||
|
for (Map.Entry<String, String> entry : attrs.entrySet()) {
|
||||||
|
out.write(' ');
|
||||||
|
out.write(entry.getKey());
|
||||||
|
out.write('=');
|
||||||
|
out.write('"');
|
||||||
|
escapeAttributeValue(entry.getValue(), out);
|
||||||
|
out.write('"');
|
||||||
|
}
|
||||||
|
if (val == null) {
|
||||||
|
out.write('/');
|
||||||
|
out.write('>');
|
||||||
|
} else {
|
||||||
|
out.write('>');
|
||||||
|
escapeCharData(val,out);
|
||||||
|
out.write('<');
|
||||||
|
out.write('/');
|
||||||
|
out.write(tag);
|
||||||
|
out.write('>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void escape(char [] chars, int offset, int length, Writer out, String [] escapes) throws IOException{
|
private static void escape(char [] chars, int offset, int length, Writer out, String [] escapes) throws IOException{
|
||||||
for (int i=offset; i<length; i++) {
|
for (int i=offset; i<length; i++) {
|
||||||
char ch = chars[i];
|
char ch = chars[i];
|
||||||
|
|
Loading…
Reference in New Issue