Esempio n. 1
1
File: Macro.java Progetto: bramk/bnd
  public String _range(String args[]) {
    verifyCommand(args, _rangeHelp, _rangePattern, 2, 3);
    Version version = null;
    if (args.length >= 3) version = new Version(args[2]);
    else {
      String v = domain.getProperty("@");
      if (v == null) return null;
      version = new Version(v);
    }
    String spec = args[1];

    Matcher m = RANGE_MASK.matcher(spec);
    m.matches();
    String floor = m.group(1);
    String floorMask = m.group(2);
    String ceilingMask = m.group(3);
    String ceiling = m.group(4);

    String left = version(version, floorMask);
    String right = version(version, ceilingMask);
    StringBuilder sb = new StringBuilder();
    sb.append(floor);
    sb.append(left);
    sb.append(",");
    sb.append(right);
    sb.append(ceiling);

    String s = sb.toString();
    VersionRange vr = new VersionRange(s);
    if (!(vr.includes(vr.getHigh()) || vr.includes(vr.getLow()))) {
      domain.error(
          "${range} macro created an invalid range %s from %s and mask %s", s, version, spec);
    }
    return sb.toString();
  }
Esempio n. 2
0
 @Override
 public void processingInstruction(String target, String data) throws SAXException {
   _logger.fine("Processing Instruction " + target);
   _logger.fine("Processing Instruction data: " + data);
   if (target.equals("assemble")) {
     if (!_stack.isEmpty()) {
       ElementInfo element = _stack.get(_stack.size() - 1);
       Matcher matcher = PROCESSING_INSTRUCTION.matcher(data);
       while (matcher.find()) {
         if (matcher.groupCount() == 2) {
           String name = matcher.group(1);
           if (name.charAt(0) == '@') {
             element.inst.put(name, matcher.group(2));
           } else {
             element.args.add(guessUntypedValue(name, matcher.group(2)));
           }
           _logger.fine(
               "Processing Instruction for "
                   + element.data.getClass()
                   + "\n\ttarget = "
                   + target
                   + "\n\t"
                   + name
                   + "="
                   + matcher.group(2));
         }
       }
     }
   }
 }
  public void testBaseUrlPath() throws Exception {
    sau1 = setupSimAu(simAuConfig(tempDirPath));
    createContent(sau1);
    crawlContent(sau1);
    CachedUrlSet cus1 = sau1.getAuCachedUrlSet();

    tempDirPath2 = getTempDir().getAbsolutePath() + File.separator;
    Configuration config2 = simAuConfig(tempDirPath2);
    config2.put("base_url", "http://anotherhost.org/some/path/");
    SimulatedArchivalUnit sau2 = setupSimAu(config2);
    createContent(sau2);
    crawlContent(sau2);
    CachedUrlSet cus2 = sau1.getAuCachedUrlSet();
    List urls1 = auUrls(sau1);
    List urls2 = auUrls(sau2);

    Pattern pat1 = Pattern.compile("http://www\\.example\\.com(/.*)$");
    Pattern pat2 = Pattern.compile("http://anotherhost\\.org/some/path(/.*)$");
    List<String> l1 = auUrls(sau1);
    List<String> l2 = auUrls(sau2);
    assertEquals(l1.size(), l2.size());
    for (int ix = 0; ix < l1.size(); ix++) {
      Matcher m1 = pat1.matcher(l1.get(ix));
      assertTrue(m1.matches());
      Matcher m2 = pat2.matcher(l2.get(ix));
      assertTrue(m2.matches());
      assertEquals(m1.group(1), m2.group(1));
    }
  }
Esempio n. 4
0
  /**
   * Get dependencies of a source file.
   *
   * @param path The canonical path of source file.
   * @return Path of dependencies.
   */
  private ArrayList<String> getDependencies(String path) {
    if (!dependenceMap.containsKey(path)) {
      ArrayList<String> dependencies = new ArrayList<String>();
      Matcher m = PATTERN_REQUIRE.matcher(read(path, charset));

      while (m.find()) {
        // Decide which root path to use.
        // Path wrapped in <> is related to root path.
        // Path wrapped in "" is related to parent folder of the source file.
        String root = null;

        if (m.group(1).equals("<")) {
          root = this.root;
        } else {
          root = new File(path).getParent();
        }

        // Get path of required file.
        String required = m.group(2);

        File f = new File(root, required);

        if (f.exists()) {
          dependencies.add(canonize(f));
        } else {
          App.exit("Cannot find required file " + required + " in " + path);
        }
      }

      dependenceMap.put(path, dependencies);
    }

    return dependenceMap.get(path);
  }
Esempio n. 5
0
  /**
   * Leave only the value for RCS keywords.
   *
   * <p>For example, <code>$Revision: 1.1 $</code> becomes <code>1.0</code>.
   */
  public String replaceRcsKeywords(String text) {
    if (matcher == null) {
      matcher =
          Pattern.compile(
                  "\\$(Author|Date|Header|Id|Locker|Log|Name|RCSFile|Revision|Source|State): (.+?) \\$")
              .matcher(text);
    } else {
      matcher.reset(text);
    }

    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
      String string = matcher.group(2);

      // For the Date: keyword, have a shot at reformatting string
      if ("Date".equals(matcher.group(1))) {
        try {
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = dateFormat.parse(string);
          string = date.toString();
        } catch (ParseException e) {
        } // if we can't parse, return unchanged
      }

      matcher.appendReplacement(buffer, string);
    }
    matcher.appendTail(buffer);
    return buffer.toString();
  }
  protected Map<String, String> getAttributes() {
    if (attributes != null) {
      return attributes;
    }

    attributes = new HashMap<String, String>();

    matcher = ADDITIONAL_ATTRIBUTES_PATTERN.matcher(firstLine);
    if (matcher.find()) {
      String s;
      Matcher attributeMatcher;

      s = matcher.group(2);
      attributeMatcher = ADDITIONAL_ATTRIBUTE_PATTERN.matcher(s);
      while (attributeMatcher.find()) {
        String key;
        String value;

        key = attributeMatcher.group(1);
        value = attributeMatcher.group(2);
        attributes.put(key.toLowerCase(Locale.ENGLISH), value);
      }
    }
    return attributes;
  }
 public boolean checkCondition(String format, ScoreBoardEvent event) {
   boolean triggerCondition = true;
   Matcher m = conditionPattern.matcher(format);
   if (!m.find()) throw new IllegalArgumentException("No conditions in format : " + format);
   do {
     String specifier = m.group(1);
     String comparator = m.group(2);
     String targetValue = m.group(3);
     if (null == comparator || null == targetValue) continue;
     String value = scoreBoardValues.get(specifier).getValue();
     if (triggerCondition) {
       triggerCondition = false;
       // If current trigger event value == previous value after processing
       // (e.g. conversion to min:sec) then ignore, to prevent multiple consecutive
       // identical triggers
       if (value.equals(
           scoreBoardValues.get(specifier).getPreviousValue(event.getPreviousValue())))
         return false;
     }
     try {
       if (!checkConditionValue(value, comparator, targetValue)) return false;
     } catch (IllegalArgumentException iaE) {
       return false;
     }
   } while (m.find());
   return true;
 }
Esempio n. 8
0
  private InstanceList readFile() throws IOException {

    String NL = System.getProperty("line.separator");
    Scanner scanner = new Scanner(new FileInputStream(fileName), encoding);

    ArrayList<Pipe> pipeList = new ArrayList<Pipe>();
    pipeList.add(new CharSequence2TokenSequence(Pattern.compile("\\p{L}\\p{L}+")));
    pipeList.add(new TokenSequence2FeatureSequence());

    InstanceList testing = new InstanceList(new SerialPipes(pipeList));

    try {
      while (scanner.hasNextLine()) {

        String text = scanner.nextLine();
        text = text.replaceAll("\\x0d", "");

        Pattern patten = Pattern.compile("^(.*?),(.*?),(.*)$");
        Matcher matcher = patten.matcher(text);

        if (matcher.find()) {
          docIds.add(matcher.group(1));
          testing.addThruPipe(new Instance(matcher.group(3), null, "test instance", null));
        }
      }
    } finally {
      scanner.close();
    }

    return testing;
  }
  private static String expand(String str) {
    if (str == null) {
      return null;
    }

    StringBuilder result = new StringBuilder();
    Pattern re = Pattern.compile("^(.*?)\\$\\{([^}]*)\\}(.*)");
    while (true) {
      Matcher matcher = re.matcher(str);
      if (matcher.matches()) {
        result.append(matcher.group(1));
        String property = matcher.group(2);
        if (property.equals("/")) {
          property = "file.separator";
        }
        String value = System.getProperty(property);
        if (value != null) {
          result.append(value);
        }
        str = matcher.group(3);
      } else {
        result.append(str);
        break;
      }
    }
    return result.toString();
  }
 public Coords(String entry) {
   Matcher m = coordsPattern.matcher(entry);
   if (!m.matches()) {
     throw new IllegalArgumentException(entry);
   }
   chrom = m.group(1);
   start = Integer.parseInt(m.group(2));
   end = Integer.parseInt(m.group(3));
   strand = m.group(4).charAt(0);
 }
Esempio n. 11
0
 public static int[] decodePrimerName(String pname) {
   Matcher m = primerNamePattern.matcher(pname);
   if (!m.matches()) {
     throw new IllegalArgumentException(pname);
   }
   int[] a = new int[3];
   a[0] = Integer.parseInt(m.group(1));
   a[1] = Integer.parseInt(m.group(2));
   a[2] = Integer.parseInt(m.group(3));
   return a;
 }
Esempio n. 12
0
  /**
   * Initializes the date format.
   *
   * @param d input
   * @param e example format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void date(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = DATE.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);
    yea = toLong(mt.group(1), false, ii);
    // +1 is added to BC values to simplify computations
    if (yea < 0) yea++;
    mon = (byte) (Strings.toInt(mt.group(3)) - 1);
    day = (byte) (Strings.toInt(mt.group(4)) - 1);

    if (mon < 0 || mon >= 12 || day < 0 || day >= dpm(yea, mon)) throw dateError(d, e, ii);
    if (yea <= MIN_YEAR || yea > MAX_YEAR) throw DATERANGE_X_X.get(ii, type, chop(d, ii));
    zone(mt, 5, d, ii);
  }
Esempio n. 13
0
  /**
   * Initializes the timezone.
   *
   * @param matcher matcher
   * @param pos first matching position
   * @param value value
   * @param ii input info
   * @throws QueryException query exception
   */
  final void zone(final Matcher matcher, final int pos, final byte[] value, final InputInfo ii)
      throws QueryException {

    final String z = matcher.group(pos);
    if (z == null) return;
    if ("Z".equals(z)) {
      tz = 0;
    } else {
      final int th = Strings.toInt(matcher.group(pos + 2));
      final int tm = Strings.toInt(matcher.group(pos + 3));
      if (th > 14 || tm > 59 || th == 14 && tm != 0) throw INVALIDZONE_X.get(ii, value);
      final int mn = th * 60 + tm;
      tz = (short) ("-".equals(matcher.group(pos + 1)) ? -mn : mn);
    }
  }
Esempio n. 14
0
  public void _sendString(String text) {
    if (writeCommand == null) return;

    /* intercept sessions -i and deliver it to a listener within armitage */
    if (sessionListener != null) {
      Matcher m = interact.matcher(text);
      if (m.matches()) {
        sessionListener.actionPerformed(new ActionEvent(this, 0, m.group(1)));
        return;
      }
    }

    Map read = null;

    try {
      synchronized (this) {
        if (window != null && echo) {
          window.append(window.getPromptText() + text);
        }
      }

      if ("armitage.push".equals(writeCommand)) {
        read = (Map) connection.execute(writeCommand, new Object[] {session, text});
      } else {
        connection.execute(writeCommand, new Object[] {session, text});
        read = readResponse();
      }
      processRead(read);

      fireSessionWroteEvent(text);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Esempio n. 15
0
 public static String getChrom(String chromName) {
   Matcher m = chromPattern.matcher(chromName);
   if (!m.matches()) {
     return chromName;
   }
   return m.group(1);
 }
Esempio n. 16
0
 /**
  * Import an XQuery library module from the given document. The namespace and preferred prefix of
  * the module are extracted from the module itself. The MIME type of the document is set to
  * "application/xquery" as a side-effect.
  *
  * @param module the non-XML document that holds the library module's source
  * @return this service, to chain calls
  * @throws DatabaseException if the module is an XML document, or the module declaration cannot be
  *     found at the top of the document
  */
 public QueryService importModule(Document module) {
   if (module instanceof XMLDocument)
     throw new DatabaseException("module cannot be an XML document: " + module);
   Matcher matcher = MODULE_DECLARATION_DQUOTE.matcher(module.contentsAsString());
   if (!matcher.find()) {
     matcher = MODULE_DECLARATION_SQUOTE.matcher(module.contentsAsString());
     if (!matcher.find())
       throw new DatabaseException("couldn't find a module declaration at the top of " + module);
   }
   module.metadata().setMimeType("application/xquery");
   String moduleNamespace = matcher.group(1);
   // TODO: should do URILiteral processing here to replace entity and character references and
   // normalize
   // whitespace, but since it seems that eXist doesn't do it either (bug?) there's no reason to
   // rush.
   Document prevModule = moduleMap.get(moduleNamespace);
   if (prevModule != null && !prevModule.equals(module))
     throw new DatabaseException(
         "module "
             + moduleNamespace
             + " already bound to "
             + prevModule
             + ", can't rebind to "
             + module);
   moduleMap.put(moduleNamespace, module);
   return this;
 }
Esempio n. 17
0
 /**
  * Takes a line and looks for an archive request tag. If one is found, the information from the
  * tag is returned as an <CODE>ArchiveRequest</CODE>. If a tag is found, the data in the tag is
  * stored in the <CODE>HashMap</CODE> provided.
  *
  * @param currentLine The line in which to look for the archive tag.
  * @param group The <CODE>ArchiveGroup</CODE> to which to add the <CODE>ArchiveRequest</CODE>. Can
  *     be <CODE>null</CODE>.
  * @param template The <CODE>Template</CODE> to which the <CODE>ArchiveRequest</CODE> belongs.
  * @return The archive request tag data as an instance of <CODE>ArchiveRequest</CODE>, <CODE>null
  *     </CODE> if the line passed in does not contain an arFile tag.
  */
 private ArchiveRequest parseArchiveRequestTag(
     String currentLine, ArchiveGroup group, Template template) {
   ArchiveRequest archiveTag;
   Matcher currentMatcher = archiveRequestPattern.matcher(currentLine);
   if (currentMatcher.find()) {
     String fileName = currentMatcher.group(1);
     archiveTag = template.getArchiveRequest(fileName);
     if (archiveTag == null) {
       archiveTag = new ArchiveRequest(fileName);
       template.addArchiveRequest(archiveTag);
     }
     if (group != null) {
       // Creating a new request object because the requests
       // in the groups flagged as not in database will mean the
       // group - request association is not in database. Requests
       // in the archiveRequests map flagged as not in database
       // means the request record is not there.
       String requestFileName = archiveTag.getFileName();
       String requestFileLocation = archiveTag.getFileLocation();
       ArchiveRequest groupRequest = new ArchiveRequest(requestFileLocation, requestFileName);
       group.addArchiveRequest(groupRequest);
     }
   } else archiveTag = null;
   return archiveTag;
 }
Esempio n. 18
0
 public static String removePrimerLR(String pname) {
   Matcher m = primerLRPattern.matcher(pname);
   if (!m.matches()) {
     throw new IllegalArgumentException(pname);
   }
   return m.group(1);
 }
 public String parse(String format) {
   StringBuffer buffer = new StringBuffer();
   Matcher m = formatPattern.matcher(format);
   while (m.find()) m.appendReplacement(buffer, getFormatSpecifierValue(m.group()));
   m.appendTail(buffer);
   return buffer.toString();
 }
Esempio n. 20
0
 /**
  * Takes a line and looks for an archive tag. If one is found, the information from the tag is
  * returned as a <CODE>Signal</CODE>. If a signal ID is given in the tag, the data in the tag is
  * stored in the <CODE>HashMap</CODE> provided.
  *
  * @param currentLine The line in which to look for the archive tag.
  * @return The archive tag data as an instance of <CODE>Signal</CODE>, <CODE>null</CODE> if the
  *     line passed in does not contain an arReq tag.
  */
 private Signal parseArchiveTag(String currentLine) {
   Signal archiveTag;
   Matcher currentMatcher = archivePattern.matcher(currentLine);
   if (currentMatcher.find()) {
     archiveTag = new Signal(currentMatcher.group(1));
     String frequency = currentMatcher.group(2);
     BigDecimal frequencyValue;
     if (frequency == null) frequencyValue = null;
     else frequencyValue = new BigDecimal(frequency);
     archiveTag.setArchiveFrequency(frequencyValue);
     String type = currentMatcher.group(3);
     if (type == null) type = "Monitor";
     archiveTag.setArchiveType(type);
     archiveTag.setArchiveIndicator("Y");
   } else archiveTag = null;
   return archiveTag;
 }
Esempio n. 21
0
  /**
   * Initializes the time format.
   *
   * @param d input format
   * @param e expected format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void time(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = TIME.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);

    hou = (byte) Strings.toInt(mt.group(1));
    min = (byte) Strings.toInt(mt.group(2));
    sec = toDecimal(mt.group(3), false, ii);
    if (min >= 60
        || sec.compareTo(BD60) >= 0
        || hou > 24
        || hou == 24 && (min > 0 || sec.compareTo(BigDecimal.ZERO) > 0)) throw dateError(d, e, ii);
    zone(mt, 5, d, ii);
    if (hou == 24) {
      hou = 0;
      add(DAYSECONDS);
    }
  }
Esempio n. 22
0
  private void addNonTerminal(String EBNF) {
    String p = "<([\\w-]+)>[\\s]*::=(" + "([\\s]*(<[\\w-]+>|(\"[^\"]*\")|[|\\[\\]{}])" + ")+)";
    Matcher m = Pattern.compile(p).matcher(EBNF);

    m.find();

    NonTerminal nt = new NonTerminal(m.group(1));
    List<? extends EBNFBranch> branches = EBNFBranch.getBranches(m.group(2));

    assert (branches.size() > 0);

    if (nonTerminals.size() == 0) {
      startSymbol = nt;
    }

    nonTerminals.put(nt, branches);
  }
Esempio n. 23
0
 public String getArtifactIdFromCoord(String coord) {
   Matcher m = COORD_P.matcher(coord);
   if (m.matches()) {
     return m.group(2);
   } else {
     return null;
   }
 }
 /**
  * Replaces instances of Java reserved words that could not appear in a valid Java condition or
  * Java variable name that are being used as variable names in string.
  *
  * @param string the string in which the Java reserved words should be replaced.
  * @return string with the Java reserved words replaced with a substitute names.
  */
 private static String replaceReservedWords(String string) {
   // cheap hack so that pattern never need to look for a key word at
   // the beginning or end of string.  That way one may simplify the pattern
   // to looking for a reserved word that is not prefixed or suffix with a
   // letter or number.
   string = "(" + string + ")";
   for (int i = 0; i < reservedWords.length; i++) {
     String reservedWord = reservedWords[i];
     Pattern p = Pattern.compile("([\\W])(" + reservedWord + ")([\\W])");
     Matcher m = p.matcher(string);
     while (m.find()) {
       string = m.replaceFirst(m.group(1) + "daikon" + reservedWord + m.group(3));
       m = p.matcher(string);
     }
   }
   return string.substring(1, string.length() - 1);
 }
Esempio n. 25
0
 public synchronized String format(String message) {
   Matcher matcher = variablePattern.matcher(message);
   while (matcher.find()) {
     String variable = matcher.group();
     variable = variable.substring(1);
     if (variable.startsWith("{") && variable.endsWith("}"))
       variable = variable.substring(1, variable.length() - 1);
     String value = variables.get(variable);
     if (value == null) value = "";
     message =
         message.replaceFirst(Pattern.quote(matcher.group()), Matcher.quoteReplacement(value));
   }
   matcher = colorPattern.matcher(message);
   while (matcher.find())
     message =
         message.substring(0, matcher.start()) + "\247" + message.substring(matcher.end() - 1);
   return message;
 }
Esempio n. 26
0
  public URLFinder(String text) {
    Matcher matcher = dfPattern.matcher(text);
    urls = new ArrayList<String>();
    locations = new ArrayList<Integer[]>();

    while (matcher.find()) {
      urls.add(matcher.group(1));
      locations.add(new Integer[] {matcher.start(1), matcher.end(1)});
    }
  }
 public BasicSpellChecker(String file) throws IOException {
   BufferedReader in = new BufferedReader(new FileReader(file));
   Pattern p = Pattern.compile("\\w+");
   for (String temp = ""; temp != null; temp = in.readLine()) {
     Matcher m = p.matcher(temp.toLowerCase());
     while (m.find())
       nWords.put((temp = m.group()), nWords.containsKey(temp) ? nWords.get(temp) + 1 : 1);
   }
   in.close();
 }
  /**
   * Removes anything at the start of the markup that is indented. Normally this indicates notes
   * that the author should have used a template for, such as a "For other uses, see ****" note.
   *
   * @param markup the text to be stripped
   * @return the stripped markup
   */
  public static String stripIndentedStart(String markup) {

    Pattern p = Pattern.compile("(.*?)\n", Pattern.DOTALL);
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int newStart = 0;

    while (m.find()) {
      // System.out.println(" - \"" + m.group() + "\"\n\n") ;

      if (m.group().matches("(?s)([\\s\\W]*)([\\:\\*]+)(.*)") || m.group().matches("\\W*"))
        newStart = m.end();
      else break;
    }

    sb.append(markup.substring(newStart));
    return sb.toString();
  }
  private List<String> convertFollowupPatientIds(List<String> patientIds) {
    List<String> convertedPatientIds = new ArrayList<String>();

    for (String patientId : patientIds) {
      Matcher patientIdMatcher = FOLLOW_UP_PATIENT_ID_REGEX.matcher(patientId);
      convertedPatientIds.add(patientIdMatcher.find() ? patientIdMatcher.group(1) : patientId);
    }

    return convertedPatientIds;
  }
  private void buildXmlPropertiesFile() {
    System.out.println(
        "\nBuilding and checking your pipeline properties file -> " + truncPipePropFile);
    StringBuilder toPrint = new StringBuilder();

    // walk through the prop file
    String[] prop = IO.loadFileIntoStringArray(truncPipePropFile);
    Pattern val = Pattern.compile("(<entry key.+>)([D|A|B].*)</entry>");
    boolean missingFile = false;
    for (String s : prop) {
      // does it match a file needing prepending? Data/, Apps/, Bed/
      Matcher mat = val.matcher(s);
      if (mat.matches()) {
        File test = new File(referenceDir, mat.group(2));
        if (test.exists()) {
          System.out.println("Found\t" + test);
          toPrint.append(mat.group(1));
          toPrint.append(test.toString());
          toPrint.append("</entry>");
        } else {
          System.out.println("Misssing\t" + test);
          missingFile = true;
        }
      }
      // threads?
      else if (s.contains("threads"))
        toPrint.append("<entry key=\"threads\">" + threads + "</entry>");

      // nope just save it and add a line return
      else toPrint.append(s);
      toPrint.append("\n");
    }
    // anything missing? if so exit
    if (missingFile)
      Misc.printErrAndExit(
          "\nFailed to find all of the files in your properties file, see above.\n");

    // OK, write it out
    completePipelinePropFile = new File(outputDirectory, "pipelineProperties.xml");
    if (IO.writeString(toPrint.toString(), completePipelinePropFile) == false)
      Misc.printErrAndExit("Problem writing -> " + truncPipePropFile);
  }