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:
Shalin Shekhar Mangar 2008-12-09 11:18:48 +00:00
parent 2430817fe1
commit 1ffed882a9
1 changed files with 26 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package org.apache.solr.common.util;
import java.io.Writer;
import java.io.IOException;
import java.util.Map;
/**
* @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{
for (int i=offset; i<length; i++) {
char ch = chars[i];