List of usage examples for java.util.regex PatternSyntaxException getDescription
public String getDescription()
From source file:pl.otros.logview.parser.log4j.Log4jPatternMultilineLogParser.java
@Override public void init(Properties properties) throws InitializationException { String rePattern = properties.getProperty(PROPERTY_REPATTERN); logFormat = properties.getProperty(PROPERTY_PATTERN); if (!StringUtils.isBlank(logFormat) && rePattern != null) { throw new InitializationException(String.format("Conflicting log patterns set (properties %s and %s)", PROPERTY_PATTERN, PROPERTY_REPATTERN)); }/*from ww w .j av a 2s . com*/ if (StringUtils.isBlank(logFormat) && rePattern == null) { throw new InitializationException( String.format("Log pattern not set (property %s or %s)", PROPERTY_PATTERN, PROPERTY_REPATTERN)); } timestampFormat = properties.getProperty(PROPERTY_DATE_FORMAT); if (StringUtils.isBlank(timestampFormat)) { throw new InitializationException( String.format("Date format not set (property %s)", PROPERTY_DATE_FORMAT)); } customLevelDefinitions = properties.getProperty(PROPERTY_CUSTOM_LEVELS); parserDescription.setDisplayName(properties.getProperty(PROPERTY_NAME, "?")); parserDescription.setDescription(properties.getProperty(PROPERTY_DESCRIPTION, "?")); parserDescription.setCharset(properties.getProperty(PROPERTY_CHARSET, "UTF-8")); if (timestampFormat != null) { // dateFormat = new SimpleDateFormat(quoteTimeStampChars(timestampFormat)); timestampPatternText = convertTimestamp(); } if (rePattern == null) { initializePatterns(); createPattern(); } else { try { regexpPattern = Pattern.compile(rePattern); } catch (PatternSyntaxException pse) { throw new InitializationException(String.format("Malformatted regex pattern for '%s' (%s): %s", PROPERTY_REPATTERN, rePattern, pse.getDescription())); } // if custom level definitions exist, parse them updateCustomLevelDefinitionMap(); Map<Integer, String> groupMap = new HashMap<Integer, String>(); Enumeration<String> e = (Enumeration<String>) properties.propertyNames(); String key = null, val = null; int keyLen, dotGrouplen; int dotGroupLen = ".group".length(); while (e.hasMoreElements()) try { key = e.nextElement(); keyLen = key.length(); if (keyLen <= dotGroupLen || !key.endsWith(".group")) continue; val = properties.getProperty(key); groupMap.put(Integer.valueOf(val), key.substring(0, keyLen - dotGroupLen)); } catch (NumberFormatException ne) { throw new InitializationException( String.format("Group property '%s.group' set to non-integer: %s", key, val)); } if (groupMap.size() < 1) throw new InitializationException(PROPERTY_REPATTERN + " set but no group properties set. " + "Set group indexes like 'TIMESTAMP.group=1', " + "starting with index 1"); for (int i = 1; i <= groupMap.size(); i++) { if (!groupMap.containsKey(Integer.valueOf(i))) throw new InitializationException("Group property numbers not consecutive starting at 1"); matchingKeywords.add(groupMap.get(Integer.valueOf(i))); } if (matchingKeywords.contains(Log4jPatternMultilineLogParser.MESSAGE) && !matchingKeywords .get(matchingKeywords.size() - 1).equals(Log4jPatternMultilineLogParser.MESSAGE)) throw new InitializationException("If MESSAGE group is present, it must be last"); } }
From source file:sorcer.core.provider.logger.RemoteLoggerManager.java
public String getLogComments(String filename) { Pattern p = null;// w w w. j a v a2 s. c o m try { // The following pattern lets this extract multiline comments that // appear on a single line (e.g., /* same line */) and single-line // comments (e.g., // some line). Furthermore, the comment may // appear anywhere on the line. p = Pattern.compile(".*/\\*.*\\*/|.*//.*$"); } catch (PatternSyntaxException e) { System.err.println("Regex syntax error: " + e.getMessage()); System.err.println("Error description: " + e.getDescription()); System.err.println("Error index: " + e.getIndex()); System.err.println("Erroneous pattern: " + e.getPattern()); } BufferedReader br = null; StringBuffer bw = new StringBuffer(); try { FileReader fr = new FileReader(filename); br = new BufferedReader(fr); Matcher m = p.matcher(""); String line; while ((line = br.readLine()) != null) { m.reset(line); if (m.matches()) /* entire line must match */ { bw.append(line + "\n"); } } } catch (IOException e) { System.err.println(e.getMessage()); } finally // Close file. { try { if (br != null) br.close(); } catch (IOException e) { } } return bw.toString(); }