示例#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;
 }
示例#2
0
  public static boolean isAncestor(String parentPath, String ancestorPath) {
    parentPath = parentPath == null ? "" : parentPath;
    ancestorPath = ancestorPath == null ? "" : ancestorPath;

    if (parentPath.length() == 0) {
      return !ancestorPath.startsWith("/");
    }

    if (ancestorPath.startsWith(parentPath)) {
      if (parentPath.length() != ancestorPath.length()
          && !parentPath.endsWith("/")
          && ancestorPath.charAt(parentPath.length()) != '/') {
        if (parentPath.startsWith("file://") && ancestorPath.startsWith("file://")) {
          // HACK: maybe encoded back slashes (UNC path)?
          String encodedSlash = SVNEncodingUtil.uriEncode("\\");
          return parentPath.endsWith(encodedSlash)
              || ancestorPath.substring(parentPath.length()).startsWith(encodedSlash);
        }
        return false;
      }
      return true;
    }

    return false;
  }
示例#3
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;
 }
示例#4
0
 public static StringBuffer openCDataTag(
     String prefix, String tagName, String cdata, Map attributes, StringBuffer target) {
   if (cdata == null) {
     return target;
   }
   target = openXMLTag(prefix, tagName, XML_STYLE_PROTECT_CDATA, attributes, target);
   target.append(SVNEncodingUtil.xmlEncodeCDATA(cdata));
   target = closeXMLTag(prefix, tagName, target);
   return target;
 }
示例#5
0
 public static void checkPathIsValid(String path) throws SVNException {
   for (int i = 0; i < path.length(); i++) {
     char ch = path.charAt(i);
     if (SVNEncodingUtil.isASCIIControlChar(ch)) {
       SVNErrorMessage err =
           SVNErrorMessage.create(
               SVNErrorCode.FS_PATH_SYNTAX,
               "Invalid control character ''{0}'' in path ''{1}''",
               new String[] {"0x" + SVNFormatUtil.getHexNumberFromByte((byte) ch), path});
       SVNErrorManager.error(err, SVNLogType.DEFAULT);
     }
   }
 }