Example #1
0
 public static String call(PageContext pc, String string, String regExp, String replace)
     throws ExpressionException {
   try {
     return Perl5Util.replace(string, regExp, replace, false, false);
   } catch (MalformedPatternException e) {
     throw new FunctionException(pc, "reReplaceNoCase", 2, "regularExpression", e.getMessage());
   }
 }
 public WildcardFilenameFilter(String regex) {
   try {
     matcher_ = new Perl5Matcher();
     PatternCompiler compiler = new GlobCompiler();
     pattern_ = compiler.compile(regex);
   } catch (MalformedPatternException e) {
     throw (new IllegalArgumentException(e.getMessage()));
   }
 }
 /** Initialize ORO fields from patterns String[]. */
 protected void initPatternRepresentation(String[] patterns) throws IllegalArgumentException {
   this.compiledPatterns = new Pattern[patterns.length];
   Perl5Compiler compiler = new Perl5Compiler();
   for (int i = 0; i < patterns.length; i++) {
     // compile the pattern to be thread-safe
     try {
       this.compiledPatterns[i] = compiler.compile(patterns[i], Perl5Compiler.READ_ONLY_MASK);
     } catch (MalformedPatternException ex) {
       throw new IllegalArgumentException(ex.getMessage());
     }
   }
   this.matcher = new Perl5Matcher();
 }
Example #4
0
    /**
     * Compile regexp parameter.
     *
     * @param name The name of the parameter.
     * @param value The parameter value.
     * @return Pattern[] The compiled patterns, or <code>null</code>.
     * @throws PluginException On malformed patterns.
     */
    private Pattern[] compileGlobs(String name, String value) throws PluginException {

      Pattern[] result = null;

      if (null != value && 0 < value.length() && !STR_GLOBSTAR.equals(value)) {
        try {
          PatternCompiler pc = new GlobCompiler();

          String[] ptrns = StringUtils.split(value, STR_COMMA);

          result = new Pattern[ptrns.length];

          for (int n = 0; n < ptrns.length; n++) {
            result[n] = pc.compile(ptrns[n]);
          }
        } catch (MalformedPatternException e) {
          throw new PluginException(
              "Parameter " + name + " has a malformed pattern: " + e.getMessage());
        }
      }

      return result;
    }
  // FIXME: The compiled pattern strings should really be cached somehow.
  public void initialize(WikiContext context, Map params) throws PluginException {
    m_dateFormat = Preferences.getDateFormat(context, TimeFormat.DATETIME);
    m_engine = context.getEngine();
    m_maxwidth = TextUtil.parseIntParameter((String) params.get(PARAM_MAXWIDTH), Integer.MAX_VALUE);
    if (m_maxwidth < 0) m_maxwidth = 0;

    String s = (String) params.get(PARAM_SEPARATOR);

    if (s != null) {
      m_separator = s;
      // pre-2.1.145 there was a separator at the end of the list
      // if they set the parameters, we use the new format of
      // before Item1 after separator before Item2 after separator before
      // Item3 after
      m_after = "";
    }

    s = (String) params.get(PARAM_BEFORE);

    if (s != null) {
      m_before = s;
    }

    s = (String) params.get(PARAM_AFTER);

    if (s != null) {
      m_after = s;
    }

    s = (String) params.get(PARAM_EXCLUDE);

    if (s != null) {
      try {
        PatternCompiler pc = new GlobCompiler();

        String[] ptrns = StringUtils.split(s, ",");

        m_exclude = new Pattern[ptrns.length];

        for (int i = 0; i < ptrns.length; i++) {
          m_exclude[i] = pc.compile(ptrns[i]);
        }
      } catch (MalformedPatternException e) {
        throw new PluginException("Exclude-parameter has a malformed pattern: " + e.getMessage());
      }
    }

    // TODO: Cut-n-paste, refactor
    s = (String) params.get(PARAM_INCLUDE);

    if (s != null) {
      try {
        PatternCompiler pc = new GlobCompiler();

        String[] ptrns = StringUtils.split(s, ",");

        m_include = new Pattern[ptrns.length];

        for (int i = 0; i < ptrns.length; i++) {
          m_include[i] = pc.compile(ptrns[i]);
        }
      } catch (MalformedPatternException e) {
        throw new PluginException("Include-parameter has a malformed pattern: " + e.getMessage());
      }
    }

    // log.debug( "Requested maximum width is "+m_maxwidth );
    s = (String) params.get(PARAM_SHOW);

    if (s != null) {
      if (s.equalsIgnoreCase("count")) {
        m_show = "count";
      }
    }

    s = (String) params.get(PARAM_LASTMODIFIED);

    if (s != null) {
      if (s.equalsIgnoreCase("true")) {
        if (m_show.equals("count")) {
          m_lastModified = true;
        } else {
          throw new PluginException(
              "showLastModified=true is only valid if show=count is also specified");
        }
      }
    }

    initSorter(context, params);
  }