Package java.util.regex

Examples of java.util.regex.Matcher


                parentFile = new File(folder);
            }
            parentFile.mkdirs();
            Pattern p = Pattern.compile("class ([a-zA-Z0-9]+)");
            for (String model : models) {
                Matcher m = p.matcher(model);
                if (m.find()) {
                    String className = m.group().substring("class".length()).trim();
                    File classFile = new File(parentFile, className + ".java");
                    Writer o = new FileWriter(classFile, false);
                    PrintWriter writer = new PrintWriter(new BufferedWriter(o));
                    writer.write(model);
                    writer.close();


    IOUtilities.pipeStreams(stream, bytes);

    String version = bytes.toString();

    Pattern p = Pattern.compile("Version:.*git(\\d{8}).*");
    Matcher match = p.matcher(version);

    if (match.find()) {
      if (Integer.parseInt(match.group(1)) >= WEBIF_MINIMUM_VERSION) {
        return true;
      }
    }

    return false;

   * @param type
   *          Collect TV or radio channel
   */
  private void gatherChannels(StringBuffer webPage, TopfieldServiceType type) {
    ArrayList<SatelliteInfo> satellites = new ArrayList<SatelliteInfo>();
    Matcher infoMatcher = Pattern.compile(String.format(INFO_CREATE_FORMAT, type)).matcher(webPage);
    while (infoMatcher.find()) {
      satellites.add(new SatelliteInfo(Integer.parseInt(infoMatcher.group(1)), Integer.parseInt(infoMatcher.group(2)),
          infoMatcher.group(4)));
    }
    for (SatelliteInfo info : satellites) {
      Matcher channelMatcher = Pattern.compile(String.format(INFO_CHANNEL_FORMAT, type, info.getIndex())).matcher(
          webPage);
      while (channelMatcher.find()) {
        int subIndex = Integer.parseInt(channelMatcher.group(1));
        int serviceIndex = Integer.parseInt(channelMatcher.group(2));
        Matcher serviceMatcher = Pattern.compile(String.format(INFO_SERVICE_FORMAT, type, info.getIndex(), subIndex))
            .matcher(webPage);
        Matcher tunerMatcher = Pattern.compile(String.format(INFO_TUNER_FORMAT, type, info.getIndex(), subIndex))
            .matcher(webPage);
        serviceMatcher.find();
        tunerMatcher.find();
        String serviceName = serviceMatcher.group(1);
        serviceName = serviceName.substring(serviceName.indexOf(" ") + 1);
        TopfieldServiceInfo serviceInfo = new TopfieldServiceInfo(serviceIndex, info.getName(), info.getIndex(),
            serviceName, Integer.parseInt(tunerMatcher.group(1)), type == TopfieldServiceType.TV);
        channels.add(serviceInfo);
      }
    }
  }

   *          The content of the new timer form
   * @param recordTime
   *          The time to modify
   */
  private void correctTime(StringBuffer formContent, ProgramTime recordTime) {
    Matcher timeMatcher = RECEIVER_ADD_TIME_PATTERN.matcher(formContent);
    if (timeMatcher.find()) {
      int receiverPreroll = Integer.parseInt(timeMatcher.group(1));
      int receiverPostroll = Integer.parseInt(timeMatcher.group(2));

      recordTime.addMinutesToStart(receiverPreroll);
      recordTime.addMinutesToEnd(receiverPostroll * -1);
    }
  }

   *           If the device could not be contacted
   */
  public void getTimerList() throws TopfieldConnectionException {
    ArrayList<TopfieldTimerEntry> timerList = new ArrayList<TopfieldTimerEntry>();
    StringBuffer content = readDeviceData(TIMER_LIST_PAGE);
    Matcher timerEntryMatcher = TIMER_ENTRY_PATTERN.matcher(content);
    while (timerEntryMatcher.find()) {
      if (timerEntryMatcher.group(2).equals("0")) {
        // This is a P-timer => skip it
        continue;
      }

      int entryNumber = Integer.parseInt(timerEntryMatcher.group(1));
      TopfieldServiceType type = TopfieldServiceType.createFromNumber(Integer.parseInt(timerEntryMatcher.group(3)));
      int serviceNumber = Integer.parseInt(timerEntryMatcher.group(6)) - 1;
      int tuner = Integer.parseInt(timerEntryMatcher.group(8));
      TopfieldTimerMode mode = TopfieldTimerMode.createFromNumber(Integer.parseInt(timerEntryMatcher.group(9)));
      int startDay = Integer.parseInt(timerEntryMatcher.group(10));
      int startMonth = Integer.parseInt(timerEntryMatcher.group(11));
      int startYear = Integer.parseInt(timerEntryMatcher.group(12));
      int startHour = Integer.parseInt(timerEntryMatcher.group(13));
      int startMinute = Integer.parseInt(timerEntryMatcher.group(14));
      int length = Integer.parseInt(timerEntryMatcher.group(15));
      String fileName = timerEntryMatcher.group(16);

      Calendar recordingStart = Calendar.getInstance();
      recordingStart.set(Calendar.DAY_OF_MONTH, startDay);
      recordingStart.set(Calendar.MONTH, startMonth - 1);
      recordingStart.set(Calendar.YEAR, startYear);

        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        InputStream in = con.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        Matcher matcher;
        Pattern pattern = Pattern.compile("<tr><td>(\\d+):(\\d+)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>");

        String line = reader.readLine();
        while (line != null) {

            matcher = pattern.matcher(line);
            if (matcher.find()) {
                // System.out.println("h: "+matcher.group(1)+"; m: "+matcher.group(2)+"; title: "+matcher.group(3)+"; short: "+matcher.group(4)+"; desc: "+matcher.group(5));
                int h = Integer.parseInt(matcher.group(1));
                int m = Integer.parseInt(matcher.group(2));
                String title = matcher.group(3);
                String shortInfo = matcher.group(4);
                String description = matcher.group(5);

                ProgramFrame frame = new ProgramFrame();
                frame.addProgramField(ProgramField.create(ProgramFieldType.START_TIME_TYPE, h * 60 + m));
                frame.addProgramField(ProgramField.create(ProgramFieldType.TITLE_TYPE, title));
                frame.addProgramField(ProgramField.create(ProgramFieldType.SHORT_DESCRIPTION_TYPE, shortInfo));

      if (!this.failSilently) throw new IllegalArgumentException(
          "Block '" + blockName + "' not found." +
              " Matches " + locateBlock(blockName));
    }
    Pattern pattern = Pattern.compile("\\{([\\w\\.]+)\\}");
    Matcher matcher = pattern.matcher(copy);
    pattern = Pattern.compile("_BLOCK_\\.(.+)");
    for (Matcher matcher2; matcher.find();)
    {
      String match = matcher.group(1);
      matcher2 = pattern.matcher(match);
      if (matcher2.find())
      {
        if (parsedBlocks.containsKey(matcher2.group(1)))
        {

      this.implicitMain  = true; // affects parse(block) and out()
      fileText = "<!-- BEGIN: main -->" + fileText + "<!-- END: main -->";
    }
    // END: implicit main
    Pattern pattern = Pattern.compile("<!--\\s*(BEGIN|END)\\s*:\\s*(\\w+)\\s*-->(.*?)(?=(?:<!--\\s*(?:BEGIN|END)\\s*:\\s*\\w+\\s*-->)|(?:\\s*$))", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(fileText);
    ArrayList blockNames = new ArrayList();
    String parentName = "";
    int lastlength = 0; // used in newline trimming to see if one block immediately follows the previous
    while (matcher.find())
    {
      // BEGIN: newline trimming
      String after = matcher.group(3); // contents after tag
      if (lastlength == 0 || fileText.charAt(matcher.start() - 1) == '\n') {
        after = after.replaceFirst("^\\r?\\n", "");
      }
      lastlength = after.length();
      // END: newline trimming
      if (matcher.group(1).toUpperCase().equals("BEGIN"))
      {
        parentName = implode(blockNames);
        blockNames.add(matcher.group(2));
        String currentBlockName = implode(blockNames);
        if (blocks.containsKey(currentBlockName))
        {
          blocks.put(currentBlockName, blocks.get(currentBlockName) + after);
        }
        else
        {
          blocks.put(currentBlockName, after);
        }
        if (blocks.containsKey(parentName))
        {
          blocks.put(parentName, blocks.get(parentName) + "{_BLOCK_." + currentBlockName + "}");
        }
        else
        {
          blocks.put(parentName, "{_BLOCK_." + currentBlockName + "}");
        }
        subBlocks.put(parentName, currentBlockName);
        subBlocks.put(currentBlockName, "");
      }
      else if (matcher.group(1).toUpperCase().equals("END"))
      {
        blockNames.remove(blockNames.size()-1);
        parentName = implode(blockNames);
        if (blocks.containsKey(parentName))
        {

                end = content.indexOf("- Tag type:", start);
            }
            if (end != -1) {
                String resource = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(resource);
                while (matcher.find()) {
                    String group = matcher.group();
                    String[] parts = group.split("\\) \\(");
                    if (parts.length == 2) {
                        warning.setMedium(parts[0].substring(1));
                        String line = parts[1].substring(0, parts[1].length()-1);
                        line = line.substring(line.indexOf(" ")).trim();
                        try {
                            warning.setLine(Integer.parseInt(line));
                        } catch (NumberFormatException e) {
                            warning.setLine(-1);
                        }
                    }
                }
                resource = resource.trim();
                resource = resource.substring(0, resource.indexOf(" "));
                warning.setResource(resource);
            }
           
            start = content.indexOf("- Context");
            end = -1;
            if (start != -1) {
                start += "- Context".length();
                end = content.indexOf("- Message:", start);
            }
            if (end != -1) {
                String temp = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(temp);
                if (matcher.find()) {
                    String group = matcher.group();
                    warning.setDb(group.substring(1, group.length()-1));
                }
            }
           
            start = content.indexOf("- Message:");

                end = content.indexOf("- Tag type:", start);
            }
            if (end != -1) {
                String resource = content.substring(start, end);
                // extract  medium and line
                Matcher matcher =Pattern.compile("\\(.*\\)").matcher(resource);
                while (matcher.find()) {
                    String group = matcher.group();
                    String[] parts = group.split("\\) \\(");
                    if (parts.length == 2) {
                        warning.setMedium(parts[0].substring(1));
                        String line = parts[1].substring(0, parts[1].length()-1);
                        line = line.substring(line.indexOf(" ")).trim();

TOP

Related Classes of java.util.regex.Matcher

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.