From f3cc13f1f3d786a4ea1b10f5fc2d823fd11a630d Mon Sep 17 00:00:00 2001
From: remm dateStamp.
*/
- private synchronized void open() {
+ protected synchronized void open() {
// Create the directory if necessary
File dir = new File(directory);
if (!dir.isAbsolute())
@@ -635,8 +713,11 @@ public class AccessLogValve
}
writer = new PrintWriter(new BufferedWriter(new FileWriter(
pathname, true), 128000), false);
+
+ currentLogFile = new File(pathname);
} catch (IOException e) {
writer = null;
+ currentLogFile = null;
}
}
@@ -755,8 +836,8 @@ public class AccessLogValve
if (fileDateFormat == null || fileDateFormat.length() == 0)
fileDateFormat = "yyyy-MM-dd";
- dateFormatter = new SimpleDateFormat(fileDateFormat);
- dateFormatter.setTimeZone(timezone);
+ fileDateFormatter = new SimpleDateFormat(fileDateFormat);
+ fileDateFormatter.setTimeZone(timezone);
dayFormatter = new SimpleDateFormat("dd");
dayFormatter.setTimeZone(timezone);
monthFormatter = new SimpleDateFormat("MM");
@@ -766,7 +847,7 @@ public class AccessLogValve
timeFormatter = new SimpleDateFormat("HH:mm:ss");
timeFormatter.setTimeZone(timezone);
currentDate = new Date();
- dateStamp = dateFormatter.format(currentDate);
+ dateStamp = fileDateFormatter.format(currentDate);
open();
}
@@ -793,7 +874,7 @@ public class AccessLogValve
/**
* AccessLogElement writes the partial message into the buffer.
*/
- private interface AccessLogElement {
+ protected interface AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time);
@@ -802,14 +883,20 @@ public class AccessLogValve
/**
* write local IP address - %A
*/
- private class LocalAddrElement implements AccessLogElement {
+ protected class LocalAddrElement implements AccessLogElement {
+
+ private String value = null;
+
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
- String value;
- try {
- value = InetAddress.getLocalHost().getHostAddress();
- } catch (Throwable e) {
- value = "127.0.0.1";
+ if (value == null) {
+ synchronized (this) {
+ try {
+ value = InetAddress.getLocalHost().getHostAddress();
+ } catch (Throwable e) {
+ value = "127.0.0.1";
+ }
+ }
}
buf.append(value);
}
@@ -818,7 +905,7 @@ public class AccessLogValve
/**
* write remote IP address - %a
*/
- private class RemoteAddrElement implements AccessLogElement {
+ protected class RemoteAddrElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append(request.getRemoteAddr());
@@ -828,7 +915,7 @@ public class AccessLogValve
/**
* write remote host name - %h
*/
- private class HostElement implements AccessLogElement {
+ protected class HostElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append(request.getRemoteHost());
@@ -838,7 +925,7 @@ public class AccessLogValve
/**
* write remote logical username from identd (always returns '-') - %l
*/
- private class LogicalUserNameElement implements AccessLogElement {
+ protected class LogicalUserNameElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append('-');
@@ -848,7 +935,7 @@ public class AccessLogValve
/**
* write request protocol - %H
*/
- private class ProtocolElement implements AccessLogElement {
+ protected class ProtocolElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append(request.getProtocol());
@@ -858,7 +945,7 @@ public class AccessLogValve
/**
* write remote user that was authenticated (if any), else '-' - %u
*/
- private class UserElement implements AccessLogElement {
+ protected class UserElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (request != null) {
@@ -877,7 +964,7 @@ public class AccessLogValve
/**
* write date and time, in Common Log Format - %t
*/
- private class DateAndTimeElement implements AccessLogElement {
+ protected class DateAndTimeElement implements AccessLogElement {
private Date currentDate = new Date(0);
private String currentDateString = null;
@@ -911,7 +998,7 @@ public class AccessLogValve
/**
* write first line of the request (method and request URI) - %r
*/
- private class RequestElement implements AccessLogElement {
+ protected class RequestElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (request != null) {
@@ -934,7 +1021,7 @@ public class AccessLogValve
/**
* write HTTP status code of the response - %s
*/
- private class HttpStatusCodeElement implements AccessLogElement {
+ protected class HttpStatusCodeElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (response != null) {
@@ -948,7 +1035,7 @@ public class AccessLogValve
/**
* write local port on which this request was received - %p
*/
- private class LocalPortElement implements AccessLogElement {
+ protected class LocalPortElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append(request.getServerPort());
@@ -958,7 +1045,7 @@ public class AccessLogValve
/**
* write bytes sent, excluding HTTP headers - %b, %B
*/
- private class ByteSentElement implements AccessLogElement {
+ protected class ByteSentElement implements AccessLogElement {
private boolean conversion;
/**
@@ -982,7 +1069,7 @@ public class AccessLogValve
/**
* write request method (GET, POST, etc.) - %m
*/
- private class MethodElement implements AccessLogElement {
+ protected class MethodElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (request != null) {
@@ -994,7 +1081,7 @@ public class AccessLogValve
/**
* write time taken to process the request - %D, %T
*/
- private class ElapsedTimeElement implements AccessLogElement {
+ protected class ElapsedTimeElement implements AccessLogElement {
private boolean millis;
/**
@@ -1025,7 +1112,7 @@ public class AccessLogValve
/**
* write Query string (prepended with a '?' if it exists) - %q
*/
- private class QueryElement implements AccessLogElement {
+ protected class QueryElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
String query = null;
@@ -1041,7 +1128,7 @@ public class AccessLogValve
/**
* write user session ID - %S
*/
- private class SessionIdElement implements AccessLogElement {
+ protected class SessionIdElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (request != null) {
@@ -1060,7 +1147,7 @@ public class AccessLogValve
/**
* write requested URL path - %U
*/
- private class RequestURIElement implements AccessLogElement {
+ protected class RequestURIElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
if (request != null) {
@@ -1074,7 +1161,7 @@ public class AccessLogValve
/**
* write local server name - %v
*/
- private class LocalServerNameElement implements AccessLogElement {
+ protected class LocalServerNameElement implements AccessLogElement {
public void addElement(StringBuffer buf, Date date, Request request,
Response response, long time) {
buf.append(request.getServerName());
@@ -1084,7 +1171,7 @@ public class AccessLogValve
/**
* write any string
*/
- private class StringElement implements AccessLogElement {
+ protected class StringElement implements AccessLogElement {
private String str;
public StringElement(String str) {
@@ -1100,7 +1187,7 @@ public class AccessLogValve
/**
* write incoming headers - %{xxx}i
*/
- private class HeaderElement implements AccessLogElement {
+ protected class HeaderElement implements AccessLogElement {
private String header;
public HeaderElement(String header) {
@@ -1116,7 +1203,7 @@ public class AccessLogValve
/**
* write a specific cookie - %{xxx}c
*/
- private class CookieElement implements AccessLogElement {
+ protected class CookieElement implements AccessLogElement {
private String header;
public CookieElement(String header) {
@@ -1142,7 +1229,7 @@ public class AccessLogValve
/**
* write an attribute in the ServletRequest - %{xxx}r
*/
- private class RequestAttributeElement implements AccessLogElement {
+ protected class RequestAttributeElement implements AccessLogElement {
private String header;
public RequestAttributeElement(String header) {
@@ -1172,7 +1259,7 @@ public class AccessLogValve
/**
* write an attribute in the HttpSession - %{xxx}s
*/
- private class SessionAttributeElement implements AccessLogElement {
+ protected class SessionAttributeElement implements AccessLogElement {
private String header;
public SessionAttributeElement(String header) {
@@ -1207,8 +1294,8 @@ public class AccessLogValve
/**
* parse pattern string and create the array of AccessLogElement
*/
- private AccessLogElement[] createLogElements() {
- List list = new ArrayList();
+ protected AccessLogElement[] createLogElements() {
+ List
- * For UNIX users, another field called checkExistsis also
+ * For UvNIX users, another field called checkExistsis also
* available. If set to true, the log file's existence will be checked before
* each logging. This way an external log rotator can move the file
* somewhere and tomcat will start with a new file.
@@ -134,650 +126,37 @@ import org.apache.juli.logging.LogFactory;
*/
public class ExtendedAccessLogValve
- extends ValveBase
+ extends AccessLogValve
implements Lifecycle {
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a new instance of this class with default property values.
- */
- public ExtendedAccessLogValve() {
-
- super();
-
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
private static Log log = LogFactory.getLog(ExtendedAccessLogValve.class);
-
- /**
- * The descriptive information about this implementation.
- */
- protected static final String info =
- "org.apache.catalina.valves.ExtendedAccessLogValve/1.0";
-
-
- /**
- * The lifecycle event support for this component.
- */
- protected LifecycleSupport lifecycle = new LifecycleSupport(this);
-
-
-
- /**
- * The string manager for this package.
- */
- private StringManager sm =
- StringManager.getManager(Constants.Package);
-
-
- /**
- * Has this component been started yet?
- */
- private boolean started = false;
-
-
- /**
- * The as-of date for the currently open log file, or a zero-length
- * string if there is no open log file.
- */
- private String dateStamp = "";
-
-
- /**
- * The PrintWriter to which we are currently logging, if any.
- */
- private PrintWriter writer = null;
-
-
- /**
- * The formatter for the date contained in the file name.
- */
- private SimpleDateFormat fileDateFormatter = null;
-
-
- /**
- * A date formatter to format a Date into a date in the format
- * "yyyy-MM-dd".
- */
- private SimpleDateFormat dateFormatter = null;
-
-
- /**
- * A date formatter to format a Date into a time in the format
- * "kk:mm:ss" (kk is a 24-hour representation of the hour).
- */
- private SimpleDateFormat timeFormatter = null;
-
-
- /**
- * Time taken formatter for 3 decimal places.
- */
- private DecimalFormat timeTakenFormatter = null;
-
-
- /**
- * My ip address. Look it up once and remember it. Dump this if we can
- * determine another reliable way to get server ip address since this
- * server may have many ip's.
- */
- private String myIpAddress = null;
-
-
- /**
- * My dns name. Look it up once and remember it. Dump this if we can
- * determine another reliable way to get server name address since this
- * server may have many ip's.
- */
- private String myDNSName = null;
-
-
- /**
- * Holder for all of the fields to log after the pattern is decoded.
- */
- private FieldInfo[] fieldInfos;
-
-
- /**
- * The current log file we are writing to. Helpful when checkExists
- * is true.
- */
- private File currentLogFile = null;
-
-
-
- /**
- * The system time when we last updated the Date that this valve
- * uses for log lines.
- */
- private Date currentDate = null;
-
-
- /**
- * Instant when the log daily rotation was last checked.
- */
- private long rotationLastChecked = 0L;
-
-
- /**
- * The directory in which log files are created.
- */
- private String directory = "logs";
-
-
- /**
- * The pattern used to format our access log lines.
- */
- private String pattern = null;
-
-
- /**
- * The prefix that is added to log file filenames.
- */
- private String prefix = "access_log.";
-
-
- /**
- * Should we rotate our log file? Default is true (like old behavior)
- */
- private boolean rotatable = true;
-
-
- /**
- * The suffix that is added to log file filenames.
- */
- private String suffix = "";
-
-
- /**
- * Are we doing conditional logging. default false.
- */
- private String condition = null;
-
-
- /**
- * Do we check for log file existence? Helpful if an external
- * agent renames the log file so we can automagically recreate it.
- */
- private boolean checkExists = false;
-
-
- /**
- * Date format to place in log file name. Use at your own risk!
- */
- private String fileDateFormat = null;
-
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Return the directory in which we create log files.
- */
- public String getDirectory() {
-
- return (directory);
-
- }
-
-
- /**
- * Set the directory in which we create log files.
- *
- * @param directory The new log file directory
- */
- public void setDirectory(String directory) {
-
- this.directory = directory;
-
- }
-
-
- /**
- * Return descriptive information about this implementation.
- */
- public String getInfo() {
-
- return (info);
-
- }
-
-
- /**
- * Return the format pattern.
- */
- public String getPattern() {
-
- return (this.pattern);
-
- }
-
-
- /**
- * Set the format pattern, first translating any recognized alias.
- *
- * @param pattern The new pattern pattern
- */
- public void setPattern(String pattern) {
-
- FieldInfo[] f= decodePattern(pattern);
- if (f!=null) {
- this.pattern = pattern;
- this.fieldInfos = f;
- }
- }
-
-
- /**
- * Return the log file prefix.
- */
- public String getPrefix() {
-
- return (prefix);
-
- }
-
-
- /**
- * Set the log file prefix.
- *
- * @param prefix The new log file prefix
- */
- public void setPrefix(String prefix) {
-
- this.prefix = prefix;
-
- }
-
-
- /**
- * Return true if logs are automatically rotated.
- */
- public boolean isRotatable() {
-
- return rotatable;
-
- }
-
-
- /**
- * Set the value is we should we rotate the logs
- *
- * @param rotatable true is we should rotate.
- */
- public void setRotatable(boolean rotatable) {
-
- this.rotatable = rotatable;
-
- }
-
-
- /**
- * Return the log file suffix.
- */
- public String getSuffix() {
-
- return (suffix);
-
- }
-
-
- /**
- * Set the log file suffix.
- *
- * @param suffix The new log file suffix
- */
- public void setSuffix(String suffix) {
-
- this.suffix = suffix;
-
- }
-
-
-
- /**
- * Return whether the attribute name to look for when
- * performing conditional loggging. If null, every
- * request is logged.
- */
- public String getCondition() {
-
- return condition;
-
- }
-
-
- /**
- * Set the ServletRequest.attribute to look for to perform
- * conditional logging. Set to null to log everything.
- *
- * @param condition Set to null to log everything
- */
- public void setCondition(String condition) {
-
- this.condition = condition;
-
- }
-
-
-
- /**
- * Check for file existence before logging.
- */
- public boolean isCheckExists() {
-
- return checkExists;
-
- }
-
-
- /**
- * Set whether to check for log file existence before logging.
- *
- * @param checkExists true meaning to check for file existence.
- */
- public void setCheckExists(boolean checkExists) {
-
- this.checkExists = checkExists;
-
- }
-
-
- /**
- * Return the date format date based log rotation.
- */
- public String getFileDateFormat() {
- return fileDateFormat;
- }
-
-
- /**
- * Set the date format date based log rotation.
- */
- public void setFileDateFormat(String fileDateFormat) {
- this.fileDateFormat = fileDateFormat;
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Log a message summarizing the specified request and response, according
- * to the format specified by the pattern property.
- *
- * @param request Request being processed
- * @param response Response being processed
- *
- * @exception IOException if an input/output error has occurred
- * @exception ServletException if a servlet error has occurred
- */
- public void invoke(Request request, Response response)
- throws IOException, ServletException {
-
- // Pass this request on to the next valve in our pipeline
- long endTime;
- long runTime;
- long startTime=System.currentTimeMillis();
-
- getNext().invoke(request, response);
-
- endTime = System.currentTimeMillis();
- runTime = endTime-startTime;
-
- if (fieldInfos==null || condition!=null &&
- null!=request.getRequest().getAttribute(condition)) {
- return;
- }
-
-
- Date date = getDate(endTime);
- StringBuffer result = new StringBuffer();
-
- for (int i=0; fieldInfos!=null && idateStamp.
- */
- private synchronized void open() {
-
- // Create the directory if necessary
- File dir = new File(directory);
- if (!dir.isAbsolute())
- dir = new File(System.getProperty("catalina.base"), directory);
- dir.mkdirs();
-
- // Open the current log file
- try {
- String pathname;
-
- // If no rotate - no need for dateStamp in fileName
- if (rotatable){
- pathname = dir.getAbsolutePath() + File.separator +
- prefix + dateStamp + suffix;
- } else {
- pathname = dir.getAbsolutePath() + File.separator +
- prefix + suffix;
- }
-
- currentLogFile = new File(pathname);
- writer = new PrintWriter(new FileWriter(pathname, true), true);
- if (currentLogFile.length()==0) {
- writer.println("#Fields: " + pattern);
- writer.println("#Version: 1.0");
- writer.println("#Software: " + ServerInfo.getServerInfo());
- }
-
-
- } catch (IOException e) {
- writer = null;
- currentLogFile = null;
+
+ protected class RequestHeaderElement implements AccessLogElement {
+ private String header;
+
+ public RequestHeaderElement(String header) {
+ this.header = header;
+ }
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ buf.append(wrap(request.getHeader(header)));
}
-
}
-
-
- /**
- * This method returns a Date object that is accurate to within one
- * second. If a thread calls this method to get a Date and it's been
- * less than 1 second since a new Date was created, this method
- * simply gives out the same Date again so that the system doesn't
- * spend time creating Date objects unnecessarily.
- */
- private Date getDate(long systime) {
- /* Avoid extra call to System.currentTimeMillis(); */
- if (0==systime) {
- systime = System.currentTimeMillis();
+
+ protected class ResponseHeaderElement implements AccessLogElement {
+ private String header;
+
+ public ResponseHeaderElement(String header) {
+ this.header = header;
}
-
- // Only create a new Date once per second, max.
- if ((systime - currentDate.getTime()) > 1000) {
- currentDate.setTime(systime);
+
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ buf.append(wrap(response.getHeader(header)));
}
-
- return currentDate;
-
}
-
-
- // ------------------------------------------------------ Lifecycle Methods
-
-
- /**
- * Add a lifecycle event listener to this component.
- *
- * @param listener The listener to add
- */
- public void addLifecycleListener(LifecycleListener listener) {
-
- lifecycle.addLifecycleListener(listener);
-
+
+ protected class ServletContextElement implements AccessLogElement {
+ private String attribute;
+
+ public ServletContextElement(String attribute) {
+ this.attribute = attribute;
+ }
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ buf.append(wrap(request.getContext().getServletContext()
+ .getAttribute(attribute)));
+ }
}
-
-
- /**
- * Get the lifecycle listeners associated with this lifecycle. If this
- * Lifecycle has no listeners registered, a zero-length array is returned.
- */
- public LifecycleListener[] findLifecycleListeners() {
-
- return lifecycle.findLifecycleListeners();
-
+
+ protected class CookieElement implements AccessLogElement {
+ private String name;
+
+ public CookieElement(String name) {
+ this.name = name;
+ }
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ Cookie[] c = request.getCookies();
+ for (int i = 0; c != null && i < c.length; i++) {
+ if (name.equals(c[i].getName())) {
+ buf.append(wrap(c[i].getValue()));
+ }
+ }
+ }
}
-
-
- /**
- * Remove a lifecycle event listener from this component.
- *
- * @param listener The listener to add
- */
- public void removeLifecycleListener(LifecycleListener listener) {
-
- lifecycle.removeLifecycleListener(listener);
-
+
+ protected class RequestAttributeElement implements AccessLogElement {
+ private String attribute;
+
+ public RequestAttributeElement(String attribute) {
+ this.attribute = attribute;
+ }
+
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ buf.append(wrap(request.getAttribute(attribute)));
+ }
+ }
+
+ protected class SessionAttributeElement implements AccessLogElement {
+ private String attribute;
+
+ public SessionAttributeElement(String attribute) {
+ this.attribute = attribute;
+ }
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ HttpSession session = null;
+ if (request != null) {
+ session = request.getSession(false);
+ if (session != null)
+ buf.append(wrap(session.getAttribute(attribute)));
+ }
+ }
}
-
-
- /**
- * Prepare for the beginning of active use of the public methods of this
- * component. This method should be called after configure(),
- * and before any of the public methods of the component are utilized.
- *
- * @exception LifecycleException if this component detects a fatal error
- * that prevents this component from being used
- */
- public void start() throws LifecycleException {
-
- // Validate and update our current component state
- if (started)
- throw new LifecycleException
- (sm.getString("extendedAccessLogValve.alreadyStarted"));
- lifecycle.fireLifecycleEvent(START_EVENT, null);
- started = true;
-
- // Initialize the timeZone, Date formatters, and currentDate
- TimeZone tz = TimeZone.getTimeZone("GMT");
- dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
- dateFormatter.setTimeZone(tz);
- timeFormatter = new SimpleDateFormat("HH:mm:ss");
- timeFormatter.setTimeZone(tz);
- currentDate = new Date(System.currentTimeMillis());
- if (fileDateFormat==null || fileDateFormat.length()==0)
- fileDateFormat = "yyyy-MM-dd";
- fileDateFormatter = new SimpleDateFormat(fileDateFormat);
- dateStamp = fileDateFormatter.format(currentDate);
- timeTakenFormatter = new DecimalFormat("0.000");
-
- /* Everybody say ick ... ick */
- try {
- InetAddress inetAddress = InetAddress.getLocalHost();
- myIpAddress = inetAddress.getHostAddress();
- myDNSName = inetAddress.getHostName();
- } catch(Throwable e){
- myIpAddress="127.0.0.1";
- myDNSName="localhost";
+
+ protected class RequestParameterElement implements AccessLogElement {
+ private String parameter;
+
+ public RequestParameterElement(String parameter) {
+ this.parameter = parameter;
+ }
+ /**
+ * urlEncode the given string. If null or empty, return null.
+ */
+ private String urlEncode(String value) {
+ if (null==value || value.length()==0) {
+ return null;
+ }
+ return URLEncoder.encode(value);
+ }
+
+ public void addElement(StringBuffer buf, Date date, Request request,
+ Response response, long time) {
+ buf.append(wrap(urlEncode(request.getParameter(parameter))));
}
-
- open();
-
}
-
-
- /**
- * Gracefully terminate the active use of the public methods of this
- * component. This method should be the last one called on a given
- * instance of this component.
- *
- * @exception LifecycleException if this component detects a fatal error
- * that needs to be reported
- */
- public void stop() throws LifecycleException {
-
- // Validate and update our current component state
- if (!started)
- throw new LifecycleException
- (sm.getString("extendedAccessLogValve.notStarted"));
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
- started = false;
-
- close();
-
+
+ protected class PatternTokenizer {
+ private StringReader sr = null;
+ private StringBuffer buf = new StringBuffer();
+ private boolean ended = false;
+ private boolean subToken;
+ private boolean parameter;
+
+ public PatternTokenizer(String str) {
+ sr = new StringReader(str);
+ }
+
+ public boolean hasSubToken() {
+ return subToken;
+ }
+
+ public boolean hasParameter() {
+ return parameter;
+ }
+
+ public String getToken() throws IOException {
+ String result = null;
+ subToken = false;
+ parameter = false;
+
+ int c = sr.read();
+ while (c != -1) {
+ switch (c) {
+ case ' ':
+ result = buf.toString();
+ buf = new StringBuffer();
+ buf.append((char) c);
+ return result;
+ case '-':
+ result = buf.toString();
+ buf = new StringBuffer();
+ subToken = true;
+ return result;
+ case '(':
+ result = buf.toString();
+ buf = new StringBuffer();
+ parameter = true;
+ return result;
+ case ')':
+ result = buf.toString();
+ buf = new StringBuffer();
+ break;
+ default:
+ buf.append((char) c);
+ }
+ c = sr.read();
+ }
+ ended = true;
+ if (buf.length() != 0) {
+ return buf.toString();
+ } else {
+ return null;
+ }
+ }
+
+ public String getParameter()throws IOException {
+ String result;
+ if (!parameter) {
+ return null;
+ }
+ parameter = false;
+ int c = sr.read();
+ while (c != -1) {
+ if (c == ')') {
+ result = buf.toString();
+ buf = new StringBuffer();
+ return result;
+ }
+ buf.append((char) c);
+ c = sr.read();
+ }
+ return null;
+ }
+
+ public String getWhiteSpaces() throws IOException {
+ StringBuffer whiteSpaces = new StringBuffer();
+ if (buf.length() > 0) {
+ whiteSpaces.append(buf);
+ buf = new StringBuffer();
+ }
+ int c = sr.read();
+ while (Character.isWhitespace((char) c)) {
+ whiteSpaces.append((char) c);
+ c = sr.read();
+ }
+ if (c == -1) {
+ ended = true;
+ } else {
+ buf.append((char) c);
+ }
+ return whiteSpaces.toString();
+ }
+
+ public boolean isEnded() {
+ return ended;
+ }
+
+ public String getRemains() throws IOException {
+ StringBuffer remains = new StringBuffer();
+ for(int c = sr.read(); c != -1; c = sr.read()) {
+ remains.append((char) c);
+ }
+ return remains.toString();
+ }
+
}
+
+ protected AccessLogElement[] createLogElements() {
+ if (log.isDebugEnabled()) {
+ log.debug("decodePattern, pattern =" + pattern);
+ }
+ List