View Javadoc

1   package org.csc.phynixx.loggersystem.logger.channellogger;
2   
3   /*
4    * #%L
5    * phynixx-common
6    * %%
7    * Copyright (C) 2014 csc
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  
24  import java.util.regex.Matcher;
25  import java.util.regex.Pattern;
26  
27  class LogFilenameMatcher {
28  
29      static class LogFilenameParts {
30          private String loggerName = null;
31          private String loggerSystemName = null;
32          private int logfileIndex = -1;
33  
34          private LogFilenameParts(String loggerSystemName, String loggerName, int logfileIndex) {
35              super();
36              this.loggerSystemName = loggerSystemName;
37              this.loggerName = loggerName;
38              this.logfileIndex = logfileIndex;
39          }
40  
41          String getLoggerSystemName() {
42              return loggerSystemName;
43          }
44  
45  
46          String getLoggerName() {
47              return loggerName;
48          }
49  
50          int getLogfileIndex() {
51              return logfileIndex;
52          }
53  
54      }
55  
56  
57      private java.util.regex.Pattern regexPattern = null;
58  
59      LogFilenameMatcher(String pattern) {
60          this.regexPattern = Pattern.compile(pattern);
61      }
62  
63  
64      LogFilenameParts matches(String input) {
65  
66          Matcher m = this.regexPattern.matcher(input);
67  
68          if (!m.matches()) {
69              return null;
70          }
71  
72          Matcher result = m; // -- JDK 1.4
73  
74          // JDK 1.5 MatchResult result= m.toMatchResult();
75          String g1 = result.group(1);
76          String g2 = result.group(2);
77          String g3 = result.group(3);
78  
79  
80          return new LogFilenameParts(g1, g2, Integer.parseInt(g3));
81      }
82  
83  }