Beispiel #1
0
 public static StringBuffer openXMLTag(
     String prefix, String tagName, int style, Map attributes, StringBuffer target) {
   target = target == null ? new StringBuffer() : target;
   target.append("<");
   if (prefix != null) {
     target.append(prefix);
     target.append(":");
   }
   target.append(tagName);
   if (attributes != null && !attributes.isEmpty()) {
     for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext(); ) {
       Map.Entry entry = (Map.Entry) iterator.next();
       String name = (String) entry.getKey();
       String value = (String) entry.getValue();
       if ((style & XML_STYLE_ATTRIBUTE_BREAKS_LINE) != 0) {
         target.append("\n  ");
       }
       target.append(" ");
       target.append(name);
       target.append("=\"");
       target.append(SVNEncodingUtil.xmlEncodeAttr(value));
       target.append("\"");
     }
     attributes.clear();
   }
   if ((style & XML_STYLE_SELF_CLOSING) != 0) {
     target.append("/");
   }
   target.append(">");
   if ((style & XML_STYLE_PROTECT_CDATA) == 0) {
     target.append("\n");
   }
   return target;
 }
Beispiel #2
0
 public static StringBuffer openNamespaceDeclarationTag(
     String prefix,
     String header,
     Collection namespaces,
     Map prefixMap,
     Map attrs,
     StringBuffer target) {
   target = target == null ? new StringBuffer() : target;
   target.append("<");
   if (prefix != null) {
     target.append(prefix);
     target.append(":");
   }
   target.append(header);
   if (namespaces != null && !namespaces.isEmpty()) {
     Collection usedNamespaces = new ArrayList();
     for (Iterator iterator = namespaces.iterator(); iterator.hasNext(); ) {
       Object item = iterator.next();
       String currentNamespace = null;
       if (item instanceof DAVElement) {
         DAVElement currentElement = (DAVElement) item;
         currentNamespace = currentElement.getNamespace();
       } else if (item instanceof String) {
         currentNamespace = (String) item;
       }
       if (currentNamespace != null
           && currentNamespace.length() > 0
           && !usedNamespaces.contains(currentNamespace)) {
         usedNamespaces.add(currentNamespace);
         target.append(" xmlns");
         if (prefixMap != null) {
           target.append(":");
           target.append(prefixMap.get(currentNamespace));
         }
         target.append("=\"");
         target.append(currentNamespace);
         target.append("\"");
       }
     }
     usedNamespaces.clear();
   }
   if (attrs != null && !attrs.isEmpty()) {
     for (Iterator iterator = attrs.entrySet().iterator(); iterator.hasNext(); ) {
       Map.Entry entry = (Map.Entry) iterator.next();
       String name = (String) entry.getKey();
       String value = (String) entry.getValue();
       target.append(" ");
       target.append(name);
       target.append("=\"");
       target.append(SVNEncodingUtil.xmlEncodeAttr(value));
       target.append("\"");
     }
   }
   target.append(">\n");
   return target;
 }