コード例 #1
0
 private static ArrayList parseDNchain(String dnChain) {
   if (dnChain == null) {
     throw new IllegalArgumentException("The DN chain must not be null."); // $NON-NLS-1$
   }
   ArrayList parsed = new ArrayList();
   int startIndex = 0;
   startIndex = skipSpaces(dnChain, startIndex);
   while (startIndex < dnChain.length()) {
     int endIndex = startIndex;
     boolean inQuote = false;
     out:
     while (endIndex < dnChain.length()) {
       char c = dnChain.charAt(endIndex);
       switch (c) {
         case '"':
           inQuote = !inQuote;
           break;
         case '\\':
           endIndex++; // skip the escaped char
           break;
         case ';':
           if (!inQuote) break out;
       }
       endIndex++;
     }
     if (endIndex > dnChain.length()) {
       throw new IllegalArgumentException("unterminated escape");
     }
     parsed.add(dnChain.substring(startIndex, endIndex));
     startIndex = endIndex + 1;
     startIndex = skipSpaces(dnChain, startIndex);
   }
   return parsed;
 }
コード例 #2
0
  private static PermissionInfo[] getPermissionInfos(URL resource, Framework framework) {
    if (resource == null) return null;
    PermissionInfo[] info = EMPTY_PERM_INFO;
    DataInputStream in = null;
    try {
      in = new DataInputStream(resource.openStream());
      ArrayList permissions = new ArrayList();
      BufferedReader reader;
      try {
        reader = new BufferedReader(new InputStreamReader(in, "UTF8")); // $NON-NLS-1$
      } catch (UnsupportedEncodingException e) {
        reader = new BufferedReader(new InputStreamReader(in));
      }

      while (true) {
        String line = reader.readLine();
        if (line == null) /* EOF */ break;
        line = line.trim();
        if ((line.length() == 0)
            || line.startsWith("#")
            || line.startsWith("//")) /* comments */ // $NON-NLS-1$ //$NON-NLS-2$
        continue;

        try {
          permissions.add(new PermissionInfo(line));
        } catch (IllegalArgumentException iae) {
          /* incorrectly encoded permission */
          if (framework != null)
            framework.publishFrameworkEvent(FrameworkEvent.ERROR, framework.getBundle(0), iae);
        }
      }
      int size = permissions.size();
      if (size > 0) info = (PermissionInfo[]) permissions.toArray(new PermissionInfo[size]);
    } catch (IOException e) {
      // do nothing
    } finally {
      try {
        if (in != null) in.close();
      } catch (IOException ee) {
        // do nothing
      }
    }
    return info;
  }