Package java.util.regex

Examples of java.util.regex.Pattern$Pos


  protected Map getBeanProperties(Object bean) {
    HashMap values = new HashMap();
    if (bean == null) return values;
    Method[] m = bean.getClass().getMethods();
   
    Pattern p = Pattern.compile("get([A-Z]\\w+)");
   
    for (int i = 0; i < m.length; i++) {
      if (m[i].getName().equals("getClass")) continue;
      if (m[i].getParameterTypes().length > 0) continue;
      Matcher r = p.matcher(m[i].getName());
      if (r.matches()) {
        try {
          values.put(r.group(1).toLowerCase(), m[i].invoke(bean, new Object[0]));
        } catch (IllegalArgumentException e) {
          throw e;
View Full Code Here


   
    // javascript:loadOrAlert('WVOPRHRPFSCLAW7UWHCXCH7QNQIU6TWG')

    // accept raw hash of 32 base-32 chars, with garbage around it
    if (accept_magnets && guess) {
      Pattern pattern = Pattern.compile("[^a-zA-Z2-7][a-zA-Z2-7]{32}[^a-zA-Z2-7]");
      Matcher matcher = pattern.matcher(text);
      if (matcher.find()) {
        String hash = text.substring(matcher.start() + 1, matcher.start() + 33);
        return "magnet:?xt=urn:btih:" + hash;
      }

      pattern = Pattern.compile("[^a-fA-F0-9][a-fA-F0-9]{40}[^a-fA-F0-9]");
      matcher = pattern.matcher(text);
      if (matcher.find()) {
        String hash = text.substring(matcher.start() + 1, matcher.start() + 41);
        // convert from HEX to raw bytes
        byte[] infohash = ByteFormatter.decodeString(hash.toUpperCase());
        // convert to BASE32
View Full Code Here

    // accept raw hash of 32 base-32 chars
    if (text.matches("^[a-zA-Z2-7]{32}$")) {
      return "magnet:?xt=urn:btih:" + text;
    }
   
    Pattern pattern;
    Matcher matcher;

    pattern = Pattern.compile("bc://bt/([a-z0-9=\\+/]+)", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(text.replaceAll(" ", "+"));
    if (matcher.find()) {
      String base64 = matcher.group(1);
      byte[] decode = Base64.decode(base64);
      if (decode != null && decode.length > 0) {
        // Format is AA/<name>/<size>/<hash>/ZZ
        try {
          String decodeString = new String(decode, "utf8");
          pattern = Pattern.compile("AA.*/(.*)/ZZ", Pattern.CASE_INSENSITIVE);
          matcher = pattern.matcher(decodeString);
          if (matcher.find()) {
            String hash = matcher.group(1);
            String magnet = parseTextForMagnets(hash);
            if (magnet != null) {
              pattern = Pattern.compile("AA/(.*)/[0-9]+", Pattern.CASE_INSENSITIVE);
              matcher = pattern.matcher(decodeString);
              if (matcher.find()) {
                String name = matcher.group(1);
                return magnet + "&dn=" + encode(name);
              }
              return magnet;
            }
          }
        } catch (UnsupportedEncodingException e) {
        }
      }
    }

    pattern = Pattern.compile("bctp://task/(.*)", Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(text);
    if (matcher.find()) {
      // Format is <name>/<size>/<hash>
      String decodeString = matcher.group(1);
      String magnet = parseTextForMagnets(decodeString);
      if (magnet != null) {
        pattern = Pattern.compile("(.*)/[0-9]+", Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(decodeString);
        if (matcher.find()) {
          String name = matcher.group(1);
          return magnet + "&dn=" + encode(name);
        }
        return magnet;
      }
    }

    // accept raw hash of 32 base-32 chars, with garbage around it
    if (true) {
      text = "!" + text + "!";
      pattern = Pattern.compile("[^a-zA-Z2-7][a-zA-Z2-7]{32}[^a-zA-Z2-7]");
      matcher = pattern.matcher(text);
      if (matcher.find()) {
        String hash = text.substring(matcher.start() + 1, matcher.start() + 33);
        return "magnet:?xt=urn:btih:" + hash;
      }

      pattern = Pattern.compile("[^a-fA-F0-9][a-fA-F0-9]{40}[^a-fA-F0-9]");
      matcher = pattern.matcher(text);
      if (matcher.find()) {
        String hash = text.substring(matcher.start() + 1, matcher.start() + 41);
        // convert from HEX to raw bytes
        byte[] infohash = ByteFormatter.decodeString(hash.toUpperCase());
        // convert to BASE32
View Full Code Here

        while (thisIndexIterator.hasNext()) {
          int currentIndex = ((Integer) thisIndexIterator.next()).intValue();
          String fieldValue = String.valueOf(rowData.get(currentIndex - 1));

          if (fieldValue != null) {
            Pattern pattern = Pattern.compile("[^a-zA-z_0-9 ]");
            Matcher fieldMatch = pattern.matcher(fieldValue);
            fieldValue = fieldMatch.replaceAll("");
            // fieldValue = fieldValue.replaceAll("'","");
          }

          if (fieldValue == null || fieldValue.equals("null")) {
View Full Code Here

          }
        }

        String s = bRegexSearch ? tmpSearch : "\\Q"
            + tmpSearch.replaceAll("[|;]", "\\\\E|\\\\Q") + "\\E";
        Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);

        if (!pattern.matcher(name).find())
          bOurs = false;
      } catch (Exception e) {
        // Future: report PatternSyntaxException message to user.
      }
    }
View Full Code Here

      "/etc/gre.d/libxul0d.conf"
    };

    log("Auto-scanning for GRE/XULRunner.  You can skip this by appending the GRE path to LD_LIBRARY_PATH and setting MOZILLA_FIVE_HOME.");
    try {
      Pattern pat = Pattern.compile("GRE_PATH=(.*)", Pattern.CASE_INSENSITIVE);
      for (int i = 0; i < confList.length; i++) {
        File file = new File(confList[i]);
        if (file.isFile() && file.canRead()) {
          log("  checking " + file + " for GRE_PATH");
          String fileText = FileUtil.readFileAsString(file, 16384);
          if (fileText != null) {
            Matcher matcher = pat.matcher(fileText);
            if (matcher.find()) {
              String possibleGrePath = matcher.group(1);
              if (isValidGrePath(new File(possibleGrePath))) {
                grePath = possibleGrePath;
                break;
View Full Code Here

   * @param f
   * @return
   */
  public static boolean mkdirs(File f) {
    if (Constants.isOSX) {
      Pattern pat = Pattern.compile("^(/Volumes/[^/]+)");
      Matcher matcher = pat.matcher(f.getParent());
      if (matcher.find()) {
        String sVolume = matcher.group();
        File fVolume = new File(sVolume);
        if (!fVolume.isDirectory()) {
          Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, sVolume
View Full Code Here

   * @param filter wildcard (glob) filter
   * @return list of matched DownloadManager objects
   */
  private List matchWildcard( List torrents, String filter )
  {
    Pattern pattern = Pattern.compile(wildcardToPattern(filter), Pattern.CASE_INSENSITIVE);
    List list = new ArrayList();
    for (Iterator iter = torrents.iterator(); iter.hasNext();) {
      DownloadManager dm = (DownloadManager) iter.next();
      if( pattern.matcher(dm.getDisplayName()).matches() )
        list.add(dm);
    }
    return list;
  }
View Full Code Here

    try {
      version = Integer.parseInt(sVersion);
    } catch (Throwable t) {
    }
   
    Pattern pat = Pattern.compile("SCRIPT_VERSION=([0-9]+)",
        Pattern.CASE_INSENSITIVE);
   
   
    File oldFilePath;
    String sScriptFile = System.getProperty("azureus.script", null);
    if (sScriptFile != null && new File(sScriptFile).exists()) {
      oldFilePath = new File(sScriptFile);
    } else {
      oldFilePath = new File(SystemProperties.getApplicationPath(),
          "azureus");
      if (!oldFilePath.exists()) {
        return;
      }
    }

    final String oldFilePathString = oldFilePath.getAbsolutePath();

    String oldStartupScript;
    try {
      oldStartupScript = FileUtil.readFileAsString(oldFilePath,
          65535, "utf8");
    } catch (IOException e) {
      oldStartupScript = "";
    }

    // Case: Script with no version, we update it, user selects restart.
    //       Restart doesn't include azureus.script.version yet, so we
    //       would normally prompt again.  This fix reads the version
    //       from the file if we don't have a version yet, thus preventing
    //       the second restart message
    if (version == 0) {
      Matcher matcher = pat.matcher(oldStartupScript);
      if (matcher.find()) {
        String sScriptVersion = matcher.group(1);
        try {
          version = Integer.parseInt(sScriptVersion);
        } catch (Throwable t) {
        }
      }
    }
   
    if (version <= lastAskedVersion) {
      return;
    }

    InputStream stream = getClass().getResourceAsStream("startupScript");
    try {
      String startupScript = FileUtil.readInputStreamAsString(stream, 65535,
          "utf8");
      Matcher matcher = pat.matcher(startupScript);
      if (matcher.find()) {
        String sScriptVersion = matcher.group(1);
        int latestVersion = 0;
        try {
          latestVersion = Integer.parseInt(sScriptVersion);
View Full Code Here

    // examples:
    // <A HREF=http://abc.om/moo>test</a>
    // <A style=cow HREF="http://abc.om/moo">test</a>
    // <a href="http://www.gnu.org/licenses/fdl.html" target="_top">moo</a>

    Pattern pat = Pattern.compile("<.*a\\s++.*href=\"?([^\\'\"\\s>]++).*",
        Pattern.CASE_INSENSITIVE);
    Matcher m = pat.matcher(text);
    if (m.find()) {
      String sURL = m.group(1);
      try {
        sURL = URLDecoder.decode(sURL);
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of java.util.regex.Pattern$Pos

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.