lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r884411 - /lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java
Date Thu, 26 Nov 2009 06:40:30 GMT
Author: noble
Date: Thu Nov 26 06:40:30 2009
New Revision: 884411

URL: http://svn.apache.org/viewvc?rev=884411&view=rev
Log:
SOLR-1592

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java?rev=884411&r1=884410&r2=884411&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java Thu Nov 26 06:40:30
2009
@@ -188,15 +188,80 @@
 
   /** Writes the XML attribute name/val. A null val means that the attribute is missing.
*/
   public void writeAttr(String name, String val) throws IOException {
+    writeAttr(name, val, true);
+  }
+
+  public void writeAttr(String name, String val, boolean escape) throws IOException{
     if (val != null) {
       writer.write(' ');
       writer.write(name);
       writer.write("=\"");
+      if(escape){
+        XML.escapeAttributeValue(val, writer);
+      } else {
+        writer.write(val);
+      }
       XML.escapeAttributeValue(val, writer);
       writer.write('"');
     }
   }
 
+  /**Writes a tag with attributes
+   *
+   * @param tag
+   * @param attributes
+   * @param closeTag
+   * @param escape
+   * @throws IOException
+   */
+  public void startTag(String tag, Map<String,String> attributes, boolean closeTag,
boolean escape) throws IOException {
+    if (doIndent) indent();
+    writer.write('<');
+    writer.write(tag);
+    if(!attributes.isEmpty()) {
+      for (Map.Entry<String, String> entry : attributes.entrySet()) {
+        writeAttr(entry.getKey(), entry.getValue(), escape);
+      }
+    }
+    if (closeTag) {
+      writer.write("/>");
+    } else {
+      writer.write('>');
+    }
+  }
+
+  /**Write a complete tag w/ attributes and cdata (the cdata is not enclosed in $lt;!CDATA[]!&gt;
+   * @param tag
+   * @param attributes
+   * @param cdata
+   * @param escapeCdata
+   * @param escapeAttr
+   * @throws IOException
+   */
+  public void writeCdataTag(String tag, Map<String,String> attributes, String cdata,
boolean escapeCdata, boolean escapeAttr) throws IOException {
+    if (doIndent) indent();
+    writer.write('<');
+    writer.write(tag);
+    if (!attributes.isEmpty()) {
+      for (Map.Entry<String, String> entry : attributes.entrySet()) {
+        writeAttr(entry.getKey(), entry.getValue(), escapeAttr);
+      }
+    }
+    writer.write('>');
+    if (cdata != null && cdata.length() > 0) {
+      if (escapeCdata) {
+        XML.escapeCharData(cdata, writer);
+      } else {
+        writer.write(cdata, 0, cdata.length());
+      }
+    }
+    writer.write("</");
+    writer.write(tag);
+    writer.write('>');
+  }
+
+
+
   public void startTag(String tag, String name, boolean closeTag) throws IOException {
     if (doIndent) indent();
 



Mime
View raw message