use of org.apache.oro.text.GlobCompiler in project jspwiki by apache.
the class AbstractReferralPlugin method initialize.
/**
* @param context the wiki context
* @param params parameters for initializing the plugin
* @throws PluginException if any of the plugin parameters are malformed
*/
// FIXME: The compiled pattern strings should really be cached somehow.
public void initialize(WikiContext context, Map<String, String> params) throws PluginException {
m_dateFormat = Preferences.getDateFormat(context, TimeFormat.DATETIME);
m_engine = context.getEngine();
m_maxwidth = TextUtil.parseIntParameter(params.get(PARAM_MAXWIDTH), Integer.MAX_VALUE);
if (m_maxwidth < 0)
m_maxwidth = 0;
String s = 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 = params.get(PARAM_BEFORE);
if (s != null) {
m_before = s;
}
s = params.get(PARAM_AFTER);
if (s != null) {
m_after = s;
}
s = 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 = 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 = params.get(PARAM_SHOW);
if (s != null) {
if (s.equalsIgnoreCase("count")) {
m_show = "count";
}
}
s = 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);
}
use of org.apache.oro.text.GlobCompiler in project jspwiki by apache.
the class MarkupParser method initInlineImagePatterns.
@SuppressWarnings("unchecked")
protected final void initInlineImagePatterns() {
PatternCompiler compiler = new GlobCompiler();
//
// We cache compiled patterns in the engine, since their creation is really expensive
//
List<Pattern> compiledpatterns = (List<Pattern>) m_engine.getAttribute(INLINE_IMAGE_PATTERNS);
if (compiledpatterns == null) {
compiledpatterns = new ArrayList<Pattern>(20);
Collection<String> ptrns = m_engine.getAllInlinedImagePatterns();
//
for (Iterator<String> i = ptrns.iterator(); i.hasNext(); ) {
String pattern = i.next();
try {
compiledpatterns.add(compiler.compile(pattern, GlobCompiler.DEFAULT_MASK | GlobCompiler.READ_ONLY_MASK));
} catch (MalformedPatternException e) {
log.error("Malformed pattern [" + pattern + "] in properties: ", e);
}
}
m_engine.setAttribute(INLINE_IMAGE_PATTERNS, compiledpatterns);
}
m_inlineImagePatterns = Collections.unmodifiableList(compiledpatterns);
}
Aggregations