package org.apache.jasper.compiler;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.StringTokenizer;
import org.apache.jasper.JasperException;
-import org.apache.jasper.util.SystemLogHandler;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
}
+ protected static class SystemLogHandler extends PrintStream {
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Construct the handler to capture the output of the given steam.
+ */
+ public SystemLogHandler(PrintStream wrapped) {
+ super(wrapped);
+ this.wrapped = wrapped;
+ }
+
+
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * Wrapped PrintStream.
+ */
+ protected PrintStream wrapped = null;
+
+
+ /**
+ * Thread <-> PrintStream associations.
+ */
+ protected static ThreadLocal streams = new ThreadLocal();
+
+
+ /**
+ * Thread <-> ByteArrayOutputStream associations.
+ */
+ protected static ThreadLocal data = new ThreadLocal();
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ public PrintStream getWrapped() {
+ return wrapped;
+ }
+
+ /**
+ * Start capturing thread's output.
+ */
+ public static void setThread() {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ data.set(baos);
+ streams.set(new PrintStream(baos));
+ }
+
+
+ /**
+ * Stop capturing thread's output and return captured data as a String.
+ */
+ public static String unsetThread() {
+ ByteArrayOutputStream baos =
+ (ByteArrayOutputStream) data.get();
+ if (baos == null) {
+ return null;
+ }
+ streams.set(null);
+ data.set(null);
+ return baos.toString();
+ }
+
+
+ // ------------------------------------------------------ Protected Methods
+
+
+ /**
+ * Find PrintStream to which the output must be written to.
+ */
+ protected PrintStream findStream() {
+ PrintStream ps = (PrintStream) streams.get();
+ if (ps == null) {
+ ps = wrapped;
+ }
+ return ps;
+ }
+
+
+ // ---------------------------------------------------- PrintStream Methods
+
+
+ public void flush() {
+ findStream().flush();
+ }
+
+ public void close() {
+ findStream().close();
+ }
+
+ public boolean checkError() {
+ return findStream().checkError();
+ }
+
+ protected void setError() {
+ //findStream().setError();
+ }
+
+ public void write(int b) {
+ findStream().write(b);
+ }
+
+ public void write(byte[] b)
+ throws IOException {
+ findStream().write(b);
+ }
+
+ public void write(byte[] buf, int off, int len) {
+ findStream().write(buf, off, len);
+ }
+
+ public void print(boolean b) {
+ findStream().print(b);
+ }
+
+ public void print(char c) {
+ findStream().print(c);
+ }
+
+ public void print(int i) {
+ findStream().print(i);
+ }
+
+ public void print(long l) {
+ findStream().print(l);
+ }
+
+ public void print(float f) {
+ findStream().print(f);
+ }
+
+ public void print(double d) {
+ findStream().print(d);
+ }
+
+ public void print(char[] s) {
+ findStream().print(s);
+ }
+
+ public void print(String s) {
+ findStream().print(s);
+ }
+
+ public void print(Object obj) {
+ findStream().print(obj);
+ }
+
+ public void println() {
+ findStream().println();
+ }
+
+ public void println(boolean x) {
+ findStream().println(x);
+ }
+
+ public void println(char x) {
+ findStream().println(x);
+ }
+
+ public void println(int x) {
+ findStream().println(x);
+ }
+
+ public void println(long x) {
+ findStream().println(x);
+ }
+
+ public void println(float x) {
+ findStream().println(x);
+ }
+
+ public void println(double x) {
+ findStream().println(x);
+ }
+
+ public void println(char[] x) {
+ findStream().println(x);
+ }
+
+ public void println(String x) {
+ findStream().println(x);
+ }
+
+ public void println(Object x) {
+ findStream().println(x);
+ }
+
+ }
+
}
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.jsp.JspApplicationContext;
-import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.JspEngineInfo;
+import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
import org.apache.jasper.Constants;
-import org.apache.jasper.util.SimplePool;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+++ /dev/null
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jasper.util;
-
-import java.util.Date;
-
-import java.text.DateFormat;
-import java.text.FieldPosition;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-
-/**
- * Fast date formatter that caches recently formatted date information
- * and uses it to avoid too-frequent calls to the underlying
- * formatter. Note: breaks fieldPosition param of format(Date,
- * StringBuffer, FieldPosition). If you care about the field
- * position, call the underlying DateFormat directly.
- *
- * @author Stan Bailes
- * @author Alex Chaffee
- */
-public class FastDateFormat extends DateFormat {
-
- private DateFormat df;
- private long lastSec = -1;
- private StringBuffer sb = new StringBuffer();
- private FieldPosition fp = new FieldPosition(DateFormat.MILLISECOND_FIELD);
-
- public FastDateFormat(DateFormat df) {
- this.df = df;
- }
-
- public Date parse(String text, ParsePosition pos) {
- return df.parse(text, pos);
- }
-
- /**
- * Note: breaks functionality of fieldPosition param. Also:
- * there's a bug in SimpleDateFormat with "S" and "SS", use "SSS"
- * instead if you want a msec field.
- */
- public StringBuffer format(Date date, StringBuffer toAppendTo,
- FieldPosition fieldPosition) {
- long dt = date.getTime();
- long ds = dt / 1000;
- if (ds != lastSec) {
- sb.setLength(0);
- df.format(date, sb, fp);
- lastSec = ds;
- } else {
- // munge current msec into existing string
- int ms = (int)(dt % 1000);
- int pos = fp.getEndIndex();
- int begin = fp.getBeginIndex();
- if (pos > 0) {
- if (pos > begin)
- sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
- ms /= 10;
- if (pos > begin)
- sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
- ms /= 10;
- if (pos > begin)
- sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
- }
- }
- toAppendTo.append(sb.toString());
- return toAppendTo;
- }
-
- public static void main(String[] args) {
- String format = "yyyy-MM-dd HH:mm:ss.SSS";
- if (args.length > 0)
- format = args[0];
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- FastDateFormat fdf = new FastDateFormat(sdf);
- Date d = new Date();
-
- d.setTime(1);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(20);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(500);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(543);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(999);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(1050);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(2543);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(12345);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
- d.setTime(12340);
- System.out.println(fdf.format(d) + "\t" + sdf.format(d));
-
- final int reps = 100000;
- {
- long start = System.currentTimeMillis();
- for (int i = 0; i < reps; i++) {
- d.setTime(System.currentTimeMillis());
- fdf.format(d);
- }
- long elap = System.currentTimeMillis() - start;
- System.out.println("fast: " + elap + " elapsed");
- System.out.println(fdf.format(d));
- }
- {
- long start = System.currentTimeMillis();
- for (int i = 0; i < reps; i++) {
- d.setTime(System.currentTimeMillis());
- sdf.format(d);
- }
- long elap = System.currentTimeMillis() - start;
- System.out.println("slow: " + elap + " elapsed");
- System.out.println(sdf.format(d));
- }
- }
-}
+++ /dev/null
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jasper.util;
-
-import java.util.Vector;
-
-/**
- * A simple FIFO queue class which causes the calling thread to wait
- * if the queue is empty and notifies threads that are waiting when it
- * is not empty.
- *
- * @author Anil V (akv@eng.sun.com)
- */
-public class Queue {
- private Vector vector = new Vector();
-
- /**
- * Put the object into the queue.
- *
- * @param object the object to be appended to the
- * queue.
- */
- public synchronized void put(Object object) {
- vector.addElement(object);
- notify();
- }
-
- /**
- * Pull the first object out of the queue. Wait if the queue is
- * empty.
- */
- public synchronized Object pull() {
- while (isEmpty())
- try {
- wait();
- } catch (InterruptedException ex) {
- }
- return get();
- }
-
- /**
- * Get the first object out of the queue. Return null if the queue
- * is empty.
- */
- public synchronized Object get() {
- Object object = peek();
- if (object != null)
- vector.removeElementAt(0);
- return object;
- }
-
- /**
- * Peek to see if something is available.
- */
- public Object peek() {
- if (isEmpty())
- return null;
- return vector.elementAt(0);
- }
-
- /**
- * Is the queue empty?
- */
- public boolean isEmpty() {
- return vector.isEmpty();
- }
-
- /**
- * How many elements are there in this queue?
- */
- public int size() {
- return vector.size();
- }
-}
+++ /dev/null
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jasper.util;
-
-/**
- * Simple object pool. Based on ThreadPool and few other classes
- *
- * The pool will ignore overflow and return null if empty.
- *
- * @author Gal Shachor
- * @author Costin
- */
-public final class SimplePool {
-
- private static final int DEFAULT_SIZE=16;
-
- /*
- * Where the threads are held.
- */
- private Object pool[];
-
- private int max;
- private int current=-1;
-
- private Object lock;
-
- public SimplePool() {
- this.max=DEFAULT_SIZE;
- this.pool=new Object[max];
- this.lock=new Object();
- }
-
- public SimplePool(int max) {
- this.max=max;
- this.pool=new Object[max];
- this.lock=new Object();
- }
-
- /**
- * Adds the given object to the pool, and does nothing if the pool is full
- */
- public void put(Object o) {
- synchronized( lock ) {
- if( current < (max-1) ) {
- current += 1;
- pool[current] = o;
- }
- }
- }
-
- /**
- * Get an object from the pool, null if the pool is empty.
- */
- public Object get() {
- Object item = null;
- synchronized( lock ) {
- if( current >= 0 ) {
- item = pool[current];
- current -= 1;
- }
- }
- return item;
- }
-
- /**
- * Return the size of the pool
- */
- public int getMax() {
- return max;
- }
-}
+++ /dev/null
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jasper.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-
-
-/**
- * This helper class may be used to do sophisticated redirection of
- * System.out and System.err.
- *
- * @author Remy Maucherat
- */
-public class SystemLogHandler extends PrintStream {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct the handler to capture the output of the given steam.
- */
- public SystemLogHandler(PrintStream wrapped) {
- super(wrapped);
- this.wrapped = wrapped;
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * Wrapped PrintStream.
- */
- protected PrintStream wrapped = null;
-
-
- /**
- * Thread <-> PrintStream associations.
- */
- protected static ThreadLocal streams = new ThreadLocal();
-
-
- /**
- * Thread <-> ByteArrayOutputStream associations.
- */
- protected static ThreadLocal data = new ThreadLocal();
-
-
- // --------------------------------------------------------- Public Methods
-
-
- public PrintStream getWrapped() {
- return wrapped;
- }
-
- /**
- * Start capturing thread's output.
- */
- public static void setThread() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- data.set(baos);
- streams.set(new PrintStream(baos));
- }
-
-
- /**
- * Stop capturing thread's output and return captured data as a String.
- */
- public static String unsetThread() {
- ByteArrayOutputStream baos =
- (ByteArrayOutputStream) data.get();
- if (baos == null) {
- return null;
- }
- streams.set(null);
- data.set(null);
- return baos.toString();
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
-
- /**
- * Find PrintStream to which the output must be written to.
- */
- protected PrintStream findStream() {
- PrintStream ps = (PrintStream) streams.get();
- if (ps == null) {
- ps = wrapped;
- }
- return ps;
- }
-
-
- // ---------------------------------------------------- PrintStream Methods
-
-
- public void flush() {
- findStream().flush();
- }
-
- public void close() {
- findStream().close();
- }
-
- public boolean checkError() {
- return findStream().checkError();
- }
-
- protected void setError() {
- //findStream().setError();
- }
-
- public void write(int b) {
- findStream().write(b);
- }
-
- public void write(byte[] b)
- throws IOException {
- findStream().write(b);
- }
-
- public void write(byte[] buf, int off, int len) {
- findStream().write(buf, off, len);
- }
-
- public void print(boolean b) {
- findStream().print(b);
- }
-
- public void print(char c) {
- findStream().print(c);
- }
-
- public void print(int i) {
- findStream().print(i);
- }
-
- public void print(long l) {
- findStream().print(l);
- }
-
- public void print(float f) {
- findStream().print(f);
- }
-
- public void print(double d) {
- findStream().print(d);
- }
-
- public void print(char[] s) {
- findStream().print(s);
- }
-
- public void print(String s) {
- findStream().print(s);
- }
-
- public void print(Object obj) {
- findStream().print(obj);
- }
-
- public void println() {
- findStream().println();
- }
-
- public void println(boolean x) {
- findStream().println(x);
- }
-
- public void println(char x) {
- findStream().println(x);
- }
-
- public void println(int x) {
- findStream().println(x);
- }
-
- public void println(long x) {
- findStream().println(x);
- }
-
- public void println(float x) {
- findStream().println(x);
- }
-
- public void println(double x) {
- findStream().println(x);
- }
-
- public void println(char[] x) {
- findStream().println(x);
- }
-
- public void println(String x) {
- findStream().println(x);
- }
-
- public void println(Object x) {
- findStream().println(x);
- }
-
-}