From: vincent@cubedesigners.com
Date: Tue, 16 Aug 2011 16:32:01 +0000 (+0000)
Subject: (no commit message)
X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=12847df5a182303c15817f171bdf58d746c4dc5c;p=cubeextranet.git
---
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/Log.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/Log.java
deleted file mode 100644
index bf80bad2e..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/Log.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * 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.commons.logging;
-
-/**
- *
A simple logging interface abstracting logging APIs. In order to be
- * instantiated successfully by {@link LogFactory}, classes that implement
- * this interface must have a constructor that takes a single String
- * parameter representing the "name" of this Log.
- *
- *
The six logging levels used by Log are (in order):
- *
- *
trace (the least serious)
- *
debug
- *
info
- *
warn
- *
error
- *
fatal (the most serious)
- *
- * The mapping of these log levels to the concepts used by the underlying
- * logging system is implementation dependent.
- * The implemention should ensure, though, that this ordering behaves
- * as expected.
- *
- *
Performance is often a logging concern.
- * By examining the appropriate property,
- * a component can avoid expensive operations (producing information
- * to be logged).
- *
- *
For example,
- *
- * if (log.isDebugEnabled()) {
- * ... do something expensive ...
- * log.debug(theResult);
- * }
- *
- *
- *
- *
Configuration of the underlying logging system will generally be done
- * external to the Logging APIs, through whatever mechanism is supported by
- * that system.
- *
- * @param message log this message
- * @param t log this cause
- */
- public void fatal(Object message, Throwable t);
-
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogConfigurationException.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogConfigurationException.java
deleted file mode 100644
index 0598a4c33..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogConfigurationException.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.commons.logging;
-
-
-/**
- *
An exception that is thrown only if a suitable LogFactory
- * or Log instance cannot be created by the corresponding
- * factory methods.
- *
- * @author Craig R. McClanahan
- * @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (ven., 21 juil. 2006) $
- */
-
-public class LogConfigurationException extends RuntimeException {
-
-
- /**
- * Construct a new exception with null as its detail message.
- */
- public LogConfigurationException() {
-
- super();
-
- }
-
-
- /**
- * Construct a new exception with the specified detail message.
- *
- * @param message The detail message
- */
- public LogConfigurationException(String message) {
-
- super(message);
-
- }
-
-
- /**
- * Construct a new exception with the specified cause and a derived
- * detail message.
- *
- * @param cause The underlying cause
- */
- public LogConfigurationException(Throwable cause) {
-
- this((cause == null) ? null : cause.toString(), cause);
-
- }
-
-
- /**
- * Construct a new exception with the specified detail message and cause.
- *
- * @param message The detail message
- * @param cause The underlying cause
- */
- public LogConfigurationException(String message, Throwable cause) {
-
- super(message + " (Caused by " + cause + ")");
- this.cause = cause; // Two-argument version requires JDK 1.4 or later
-
- }
-
-
- /**
- * The underlying cause of this exception.
- */
- protected Throwable cause = null;
-
-
- /**
- * Return the underlying cause of this exception (if any).
- */
- public Throwable getCause() {
-
- return (this.cause);
-
- }
-
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogFactory.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogFactory.java
deleted file mode 100644
index b573a440e..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogFactory.java
+++ /dev/null
@@ -1,1843 +0,0 @@
-/*
- * 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.commons.logging;
-
-
-import java.io.BufferedReader;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Properties;
-
-
-/**
- *
Factory for creating {@link Log} instances, with discovery and
- * configuration features similar to that employed by standard Java APIs
- * such as JAXP.
- *
- *
IMPLEMENTATION NOTE - This implementation is heavily
- * based on the SAXParserFactory and DocumentBuilderFactory implementations
- * (corresponding to the JAXP pluggability APIs) found in Apache Xerces.
- *
- * @author Craig R. McClanahan
- * @author Costin Manolache
- * @author Richard A. Sitze
- * @version $Revision: 697387 $ $Date: 2008-09-20 18:33:51 +0200 (sam., 20 sept. 2008) $
- */
-
-public abstract class LogFactory {
- // Implementation note re AccessController usage
- //
- // It is important to keep code invoked via an AccessController to small
- // auditable blocks. Such code must carefully evaluate all user input
- // (parameters, system properties, config file contents, etc). As an
- // example, a Log implementation should not write to its logfile
- // with an AccessController anywhere in the call stack, otherwise an
- // insecure application could configure the log implementation to write
- // to a protected file using the privileges granted to JCL rather than
- // to the calling application.
- //
- // Under no circumstance should a non-private method return data that is
- // retrieved via an AccessController. That would allow an insecure app
- // to invoke that method and obtain data that it is not permitted to have.
- //
- // Invoking user-supplied code with an AccessController set is not a major
- // issue (eg invoking the constructor of the class specified by
- // HASHTABLE_IMPLEMENTATION_PROPERTY). That class will be in a different
- // trust domain, and therefore must have permissions to do whatever it
- // is trying to do regardless of the permissions granted to JCL. There is
- // a slight issue in that untrusted code may point that environment var
- // to another trusted library, in which case the code runs if both that
- // lib and JCL have the necessary permissions even when the untrusted
- // caller does not. That's a pretty hard route to exploit though.
-
-
- // ----------------------------------------------------- Manifest Constants
-
- /**
- * The name (priority) of the key in the config file used to
- * specify the priority of that particular config file. The associated value
- * is a floating-point number; higher values take priority over lower values.
- */
- public static final String PRIORITY_KEY = "priority";
-
- /**
- * The name (use_tccl) of the key in the config file used
- * to specify whether logging classes should be loaded via the thread
- * context class loader (TCCL), or not. By default, the TCCL is used.
- */
- public static final String TCCL_KEY = "use_tccl";
-
- /**
- * The name (org.apache.commons.logging.LogFactory) of the property
- * used to identify the LogFactory implementation
- * class name. This can be used as a system property, or as an entry in a
- * configuration properties file.
- */
- public static final String FACTORY_PROPERTY =
- "org.apache.commons.logging.LogFactory";
-
- /**
- * The fully qualified class name of the fallback LogFactory
- * implementation class to use, if no other can be found.
- */
- public static final String FACTORY_DEFAULT =
- "org.apache.commons.logging.impl.LogFactoryImpl";
-
- /**
- * The name (commons-logging.properties) of the properties file to search for.
- */
- public static final String FACTORY_PROPERTIES =
- "commons-logging.properties";
-
- /**
- * JDK1.3+
- * 'Service Provider' specification.
- *
- */
- protected static final String SERVICE_ID =
- "META-INF/services/org.apache.commons.logging.LogFactory";
-
- /**
- * The name (org.apache.commons.logging.diagnostics.dest)
- * of the property used to enable internal commons-logging
- * diagnostic output, in order to get information on what logging
- * implementations are being discovered, what classloaders they
- * are loaded through, etc.
- *
- * If a system property of this name is set then the value is
- * assumed to be the name of a file. The special strings
- * STDOUT or STDERR (case-sensitive) indicate output to
- * System.out and System.err respectively.
- *
- * Diagnostic logging should be used only to debug problematic
- * configurations and should not be set in normal production use.
- */
- public static final String DIAGNOSTICS_DEST_PROPERTY =
- "org.apache.commons.logging.diagnostics.dest";
-
- /**
- * When null (the usual case), no diagnostic output will be
- * generated by LogFactory or LogFactoryImpl. When non-null,
- * interesting events will be written to the specified object.
- */
- private static PrintStream diagnosticsStream = null;
-
- /**
- * A string that gets prefixed to every message output by the
- * logDiagnostic method, so that users can clearly see which
- * LogFactory class is generating the output.
- */
- private static String diagnosticPrefix;
-
- /**
- *
Setting this system property
- * (org.apache.commons.logging.LogFactory.HashtableImpl)
- * value allows the Hashtable used to store
- * classloaders to be substituted by an alternative implementation.
- *
- * to system error and then continue using a standard Hashtable.
- *
- *
- * Usage: Set this property when Java is invoked
- * and LogFactory will attempt to load a new instance
- * of the given implementation class.
- * For example, running the following ant scriplet:
- *
- * will mean that LogFactory will load an instance of
- * org.apache.commons.logging.AltHashtable.
- *
- *
- * A typical use case is to allow a custom
- * Hashtable implementation using weak references to be substituted.
- * This will allow classloaders to be garbage collected without
- * the need to release them (on 1.3+ JVMs only, of course ;)
- *
- */
- public static final String HASHTABLE_IMPLEMENTATION_PROPERTY =
- "org.apache.commons.logging.LogFactory.HashtableImpl";
- /** Name used to load the weak hashtable implementation by names */
- private static final String WEAK_HASHTABLE_CLASSNAME =
- "org.apache.commons.logging.impl.WeakHashtable";
-
- /**
- * A reference to the classloader that loaded this class. This is the
- * same as LogFactory.class.getClassLoader(). However computing this
- * value isn't quite as simple as that, as we potentially need to use
- * AccessControllers etc. It's more efficient to compute it once and
- * cache it here.
- */
- private static ClassLoader thisClassLoader;
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Protected constructor that is not available for public use.
- */
- protected LogFactory() {
- }
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Return the configuration attribute with the specified name (if any),
- * or null if there is no such attribute.
- *
- * @param name Name of the attribute to return
- */
- public abstract Object getAttribute(String name);
-
-
- /**
- * Return an array containing the names of all currently defined
- * configuration attributes. If there are no such attributes, a zero
- * length array is returned.
- */
- public abstract String[] getAttributeNames();
-
-
- /**
- * Convenience method to derive a name from the specified class and
- * call getInstance(String) with it.
- *
- * @param clazz Class for which a suitable Log name will be derived
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public abstract Log getInstance(Class clazz)
- throws LogConfigurationException;
-
-
- /**
- *
Construct (if necessary) and return a Log instance,
- * using the factory's current set of configuration attributes.
- *
- *
NOTE - Depending upon the implementation of
- * the LogFactory you are using, the Log
- * instance you are returned may or may not be local to the current
- * application, and may or may not be returned again on a subsequent
- * call with the same name argument.
- *
- * @param name Logical name of the Log instance to be
- * returned (the meaning of this name is only known to the underlying
- * logging implementation that is being wrapped)
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public abstract Log getInstance(String name)
- throws LogConfigurationException;
-
-
- /**
- * Release any internal references to previously created {@link Log}
- * instances returned by this factory. This is useful in environments
- * like servlet containers, which implement application reloading by
- * throwing away a ClassLoader. Dangling references to objects in that
- * class loader would prevent garbage collection.
- */
- public abstract void release();
-
-
- /**
- * Remove any configuration attribute associated with the specified name.
- * If there is no such attribute, no action is taken.
- *
- * @param name Name of the attribute to remove
- */
- public abstract void removeAttribute(String name);
-
-
- /**
- * Set the configuration attribute with the specified name. Calling
- * this with a null value is equivalent to calling
- * removeAttribute(name).
- *
- * @param name Name of the attribute to set
- * @param value Value of the attribute to set, or null
- * to remove any setting for this attribute
- */
- public abstract void setAttribute(String name, Object value);
-
-
- // ------------------------------------------------------- Static Variables
-
-
- /**
- * The previously constructed LogFactory instances, keyed by
- * the ClassLoader with which it was created.
- */
- protected static Hashtable factories = null;
-
- /**
- * Prevously constructed LogFactory instance as in the
- * factories map, but for the case where
- * getClassLoader returns null.
- * This can happen when:
- *
- *
using JDK1.1 and the calling code is loaded via the system
- * classloader (very common)
- *
using JDK1.2+ and the calling code is loaded via the boot
- * classloader (only likely for embedded systems work).
- *
- * Note that factories is a Hashtable (not a HashMap),
- * and hashtables don't allow null as a key.
- */
- protected static LogFactory nullClassLoaderFactory = null;
-
- /**
- * Create the hashtable which will be used to store a map of
- * (context-classloader -> logfactory-object). Version 1.2+ of Java
- * supports "weak references", allowing a custom Hashtable class
- * to be used which uses only weak references to its keys. Using weak
- * references can fix memory leaks on webapp unload in some cases (though
- * not all). Version 1.1 of Java does not support weak references, so we
- * must dynamically determine which we are using. And just for fun, this
- * code also supports the ability for a system property to specify an
- * arbitrary Hashtable implementation name.
- *
- * Note that the correct way to ensure no memory leaks occur is to ensure
- * that LogFactory.release(contextClassLoader) is called whenever a
- * webapp is undeployed.
- */
- private static final Hashtable createFactoryStore() {
- Hashtable result = null;
- String storeImplementationClass;
- try {
- storeImplementationClass = getSystemProperty(HASHTABLE_IMPLEMENTATION_PROPERTY, null);
- } catch(SecurityException ex) {
- // Permissions don't allow this to be accessed. Default to the "modern"
- // weak hashtable implementation if it is available.
- storeImplementationClass = null;
- }
-
- if (storeImplementationClass == null) {
- storeImplementationClass = WEAK_HASHTABLE_CLASSNAME;
- }
- try {
- Class implementationClass = Class.forName(storeImplementationClass);
- result = (Hashtable) implementationClass.newInstance();
-
- } catch (Throwable t) {
- // ignore
- if (!WEAK_HASHTABLE_CLASSNAME.equals(storeImplementationClass)) {
- // if the user's trying to set up a custom implementation, give a clue
- if (isDiagnosticsEnabled()) {
- // use internal logging to issue the warning
- logDiagnostic("[ERROR] LogFactory: Load of custom hashtable failed");
- } else {
- // we *really* want this output, even if diagnostics weren't
- // explicitly enabled by the user.
- System.err.println("[ERROR] LogFactory: Load of custom hashtable failed");
- }
- }
- }
- if (result == null) {
- result = new Hashtable();
- }
- return result;
- }
-
-
- // --------------------------------------------------------- Static Methods
-
- /** Utility method to safely trim a string. */
- private static String trim(String src) {
- if (src == null) {
- return null;
- }
- return src.trim();
- }
-
- /**
- *
Construct (if necessary) and return a LogFactory
- * instance, using the following ordered lookup procedure to determine
- * the name of the implementation class to be loaded.
- *
- *
The org.apache.commons.logging.LogFactory system
- * property.
- *
The JDK 1.3 Service Discovery mechanism
- *
Use the properties file commons-logging.properties
- * file, if found in the class path of this class. The configuration
- * file is in standard java.util.Properties format and
- * contains the fully qualified name of the implementation class
- * with the key being the system property defined above.
- *
Fall back to a default implementation class
- * (org.apache.commons.logging.impl.LogFactoryImpl).
- *
- *
- *
NOTE - If the properties file method of identifying the
- * LogFactory implementation class is utilized, all of the
- * properties defined in this file will be set as configuration attributes
- * on the corresponding LogFactory instance.
- *
- *
NOTE - In a multithreaded environment it is possible
- * that two different instances will be returned for the same
- * classloader environment.
- *
- *
- * @exception LogConfigurationException if the implementation class is not
- * available or cannot be instantiated.
- */
- public static LogFactory getFactory() throws LogConfigurationException {
- // Identify the class loader we will be using
- ClassLoader contextClassLoader = getContextClassLoaderInternal();
-
- if (contextClassLoader == null) {
- // This is an odd enough situation to report about. This
- // output will be a nuisance on JDK1.1, as the system
- // classloader is null in that environment.
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Context classloader is null.");
- }
- }
-
- // Return any previously registered factory for this class loader
- LogFactory factory = getCachedFactory(contextClassLoader);
- if (factory != null) {
- return factory;
- }
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] LogFactory implementation requested for the first time for context classloader "
- + objectId(contextClassLoader));
- logHierarchy("[LOOKUP] ", contextClassLoader);
- }
-
- // Load properties file.
- //
- // If the properties file exists, then its contents are used as
- // "attributes" on the LogFactory implementation class. One particular
- // property may also control which LogFactory concrete subclass is
- // used, but only if other discovery mechanisms fail..
- //
- // As the properties file (if it exists) will be used one way or
- // another in the end we may as well look for it first.
-
- Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES);
-
- // Determine whether we will be using the thread context class loader to
- // load logging classes or not by checking the loaded properties file (if any).
- ClassLoader baseClassLoader = contextClassLoader;
- if (props != null) {
- String useTCCLStr = props.getProperty(TCCL_KEY);
- if (useTCCLStr != null) {
- // The Boolean.valueOf(useTCCLStr).booleanValue() formulation
- // is required for Java 1.2 compatability.
- if (Boolean.valueOf(useTCCLStr).booleanValue() == false) {
- // Don't use current context classloader when locating any
- // LogFactory or Log classes, just use the class that loaded
- // this abstract class. When this class is deployed in a shared
- // classpath of a container, it means webapps cannot deploy their
- // own logging implementations. It also means that it is up to the
- // implementation whether to load library-specific config files
- // from the TCCL or not.
- baseClassLoader = thisClassLoader;
- }
- }
- }
-
- // Determine which concrete LogFactory subclass to use.
- // First, try a global system property
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Looking for system property [" + FACTORY_PROPERTY
- + "] to define the LogFactory subclass to use...");
- }
-
- try {
- String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
- if (factoryClass != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Creating an instance of LogFactory class '" + factoryClass
- + "' as specified by system property " + FACTORY_PROPERTY);
- }
-
- factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
- } else {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] No system property [" + FACTORY_PROPERTY
- + "] defined.");
- }
- }
- } catch (SecurityException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] A security exception occurred while trying to create an"
- + " instance of the custom factory class"
- + ": [" + trim(e.getMessage())
- + "]. Trying alternative implementations...");
- }
- ; // ignore
- } catch(RuntimeException e) {
- // This is not consistent with the behaviour when a bad LogFactory class is
- // specified in a services file.
- //
- // One possible exception that can occur here is a ClassCastException when
- // the specified class wasn't castable to this LogFactory type.
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] An exception occurred while trying to create an"
- + " instance of the custom factory class"
- + ": [" + trim(e.getMessage())
- + "] as specified by a system property.");
- }
- throw e;
- }
-
-
- // Second, try to find a service by using the JDK1.3 class
- // discovery mechanism, which involves putting a file with the name
- // of an interface class in the META-INF/services directory, where the
- // contents of the file is a single line specifying a concrete class
- // that implements the desired interface.
-
- if (factory == null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Looking for a resource file of name [" + SERVICE_ID
- + "] to define the LogFactory subclass to use...");
- }
- try {
- InputStream is = getResourceAsStream(contextClassLoader,
- SERVICE_ID);
-
- if( is != null ) {
- // This code is needed by EBCDIC and other strange systems.
- // It's a fix for bugs reported in xerces
- BufferedReader rd;
- try {
- rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- } catch (java.io.UnsupportedEncodingException e) {
- rd = new BufferedReader(new InputStreamReader(is));
- }
-
- String factoryClassName = rd.readLine();
- rd.close();
-
- if (factoryClassName != null &&
- ! "".equals(factoryClassName)) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Creating an instance of LogFactory class " + factoryClassName
- + " as specified by file '" + SERVICE_ID
- + "' which was present in the path of the context"
- + " classloader.");
- }
- factory = newFactory(factoryClassName, baseClassLoader, contextClassLoader );
- }
- } else {
- // is == null
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] No resource file with name '" + SERVICE_ID
- + "' found.");
- }
- }
- } catch( Exception ex ) {
- // note: if the specified LogFactory class wasn't compatible with LogFactory
- // for some reason, a ClassCastException will be caught here, and attempts will
- // continue to find a compatible class.
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] A security exception occurred while trying to create an"
- + " instance of the custom factory class"
- + ": [" + trim(ex.getMessage())
- + "]. Trying alternative implementations...");
- }
- ; // ignore
- }
- }
-
-
- // Third try looking into the properties file read earlier (if found)
-
- if (factory == null) {
- if (props != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Looking in properties file for entry with key '"
- + FACTORY_PROPERTY
- + "' to define the LogFactory subclass to use...");
- }
- String factoryClass = props.getProperty(FACTORY_PROPERTY);
- if (factoryClass != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Properties file specifies LogFactory subclass '"
- + factoryClass + "'");
- }
- factory = newFactory(factoryClass, baseClassLoader, contextClassLoader);
-
- // TODO: think about whether we need to handle exceptions from newFactory
- } else {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Properties file has no entry specifying LogFactory subclass.");
- }
- }
- } else {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] No properties file available to determine"
- + " LogFactory subclass from..");
- }
- }
- }
-
-
- // Fourth, try the fallback implementation class
-
- if (factory == null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Loading the default LogFactory implementation '" + FACTORY_DEFAULT
- + "' via the same classloader that loaded this LogFactory"
- + " class (ie not looking in the context classloader).");
- }
-
- // Note: unlike the above code which can try to load custom LogFactory
- // implementations via the TCCL, we don't try to load the default LogFactory
- // implementation via the context classloader because:
- // * that can cause problems (see comments in newFactory method)
- // * no-one should be customising the code of the default class
- // Yes, we do give up the ability for the child to ship a newer
- // version of the LogFactoryImpl class and have it used dynamically
- // by an old LogFactory class in the parent, but that isn't
- // necessarily a good idea anyway.
- factory = newFactory(FACTORY_DEFAULT, thisClassLoader, contextClassLoader);
- }
-
- if (factory != null) {
- /**
- * Always cache using context class loader.
- */
- cacheFactory(contextClassLoader, factory);
-
- if( props!=null ) {
- Enumeration names = props.propertyNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- String value = props.getProperty(name);
- factory.setAttribute(name, value);
- }
- }
- }
-
- return factory;
- }
-
-
- /**
- * Convenience method to return a named logger, without the application
- * having to care about factories.
- *
- * @param clazz Class from which a log name will be derived
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public static Log getLog(Class clazz)
- throws LogConfigurationException {
-
- return (getFactory().getInstance(clazz));
-
- }
-
-
- /**
- * Convenience method to return a named logger, without the application
- * having to care about factories.
- *
- * @param name Logical name of the Log instance to be
- * returned (the meaning of this name is only known to the underlying
- * logging implementation that is being wrapped)
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public static Log getLog(String name)
- throws LogConfigurationException {
-
- return (getFactory().getInstance(name));
-
- }
-
-
- /**
- * Release any internal references to previously created {@link LogFactory}
- * instances that have been associated with the specified class loader
- * (if any), after calling the instance method release() on
- * each of them.
- *
- * @param classLoader ClassLoader for which to release the LogFactory
- */
- public static void release(ClassLoader classLoader) {
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
- }
- synchronized (factories) {
- if (classLoader == null) {
- if (nullClassLoaderFactory != null) {
- nullClassLoaderFactory.release();
- nullClassLoaderFactory = null;
- }
- } else {
- LogFactory factory = (LogFactory) factories.get(classLoader);
- if (factory != null) {
- factory.release();
- factories.remove(classLoader);
- }
- }
- }
-
- }
-
-
- /**
- * Release any internal references to previously created {@link LogFactory}
- * instances, after calling the instance method release() on
- * each of them. This is useful in environments like servlet containers,
- * which implement application reloading by throwing away a ClassLoader.
- * Dangling references to objects in that class loader would prevent
- * garbage collection.
- */
- public static void releaseAll() {
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Releasing factory for all classloaders.");
- }
- synchronized (factories) {
- Enumeration elements = factories.elements();
- while (elements.hasMoreElements()) {
- LogFactory element = (LogFactory) elements.nextElement();
- element.release();
- }
- factories.clear();
-
- if (nullClassLoaderFactory != null) {
- nullClassLoaderFactory.release();
- nullClassLoaderFactory = null;
- }
- }
-
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Safely get access to the classloader for the specified class.
- *
- * Theoretically, calling getClassLoader can throw a security exception,
- * and so should be done under an AccessController in order to provide
- * maximum flexibility. However in practice people don't appear to use
- * security policies that forbid getClassLoader calls. So for the moment
- * all code is written to call this method rather than Class.getClassLoader,
- * so that we could put AccessController stuff in this method without any
- * disruption later if we need to.
- *
- * Even when using an AccessController, however, this method can still
- * throw SecurityException. Commons-logging basically relies on the
- * ability to access classloaders, ie a policy that forbids all
- * classloader access will also prevent commons-logging from working:
- * currently this method will throw an exception preventing the entire app
- * from starting up. Maybe it would be good to detect this situation and
- * just disable all commons-logging? Not high priority though - as stated
- * above, security policies that prevent classloader access aren't common.
- *
- * Note that returning an object fetched via an AccessController would
- * technically be a security flaw anyway; untrusted code that has access
- * to a trusted JCL library could use it to fetch the classloader for
- * a class even when forbidden to do so directly.
- *
- * @since 1.1
- */
- protected static ClassLoader getClassLoader(Class clazz) {
- try {
- return clazz.getClassLoader();
- } catch(SecurityException ex) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Unable to get classloader for class '" + clazz
- + "' due to security restrictions - " + ex.getMessage());
- }
- throw ex;
- }
- }
-
- /**
- * Returns the current context classloader.
- *
- * In versions prior to 1.1, this method did not use an AccessController.
- * In version 1.1, an AccessController wrapper was incorrectly added to
- * this method, causing a minor security flaw.
- *
- * In version 1.1.1 this change was reverted; this method no longer uses
- * an AccessController. User code wishing to obtain the context classloader
- * must invoke this method via AccessController.doPrivileged if it needs
- * support for that.
- *
- * @return the context classloader associated with the current thread,
- * or null if security doesn't allow it.
- *
- * @throws LogConfigurationException if there was some weird error while
- * attempting to get the context classloader.
- *
- * @throws SecurityException if the current java security policy doesn't
- * allow this class to access the context classloader.
- */
- protected static ClassLoader getContextClassLoader()
- throws LogConfigurationException {
-
- return directGetContextClassLoader();
- }
-
- /**
- * Calls LogFactory.directGetContextClassLoader under the control of an
- * AccessController class. This means that java code running under a
- * security manager that forbids access to ClassLoaders will still work
- * if this class is given appropriate privileges, even when the caller
- * doesn't have such privileges. Without using an AccessController, the
- * the entire call stack must have the privilege before the call is
- * allowed.
- *
- * @return the context classloader associated with the current thread,
- * or null if security doesn't allow it.
- *
- * @throws LogConfigurationException if there was some weird error while
- * attempting to get the context classloader.
- *
- * @throws SecurityException if the current java security policy doesn't
- * allow this class to access the context classloader.
- */
- private static ClassLoader getContextClassLoaderInternal()
- throws LogConfigurationException {
- return (ClassLoader)AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return directGetContextClassLoader();
- }
- });
- }
-
- /**
- * Return the thread context class loader if available; otherwise return
- * null.
- *
- * Most/all code should call getContextClassLoaderInternal rather than
- * calling this method directly.
- *
- * The thread context class loader is available for JDK 1.2
- * or later, if certain security conditions are met.
- *
- * Note that no internal logging is done within this method because
- * this method is called every time LogFactory.getLogger() is called,
- * and we don't want too much output generated here.
- *
- * @exception LogConfigurationException if a suitable class loader
- * cannot be identified.
- *
- * @exception SecurityException if the java security policy forbids
- * access to the context classloader from one of the classes in the
- * current call stack.
- * @since 1.1
- */
- protected static ClassLoader directGetContextClassLoader()
- throws LogConfigurationException
- {
- ClassLoader classLoader = null;
-
- try {
- // Are we running on a JDK 1.2 or later system?
- Method method = Thread.class.getMethod("getContextClassLoader",
- (Class[]) null);
-
- // Get the thread context class loader (if there is one)
- try {
- classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
- (Object[]) null);
- } catch (IllegalAccessException e) {
- throw new LogConfigurationException
- ("Unexpected IllegalAccessException", e);
- } catch (InvocationTargetException e) {
- /**
- * InvocationTargetException is thrown by 'invoke' when
- * the method being invoked (getContextClassLoader) throws
- * an exception.
- *
- * getContextClassLoader() throws SecurityException when
- * the context class loader isn't an ancestor of the
- * calling class's class loader, or if security
- * permissions are restricted.
- *
- * In the first case (not related), we want to ignore and
- * keep going. We cannot help but also ignore the second
- * with the logic below, but other calls elsewhere (to
- * obtain a class loader) will trigger this exception where
- * we can make a distinction.
- */
- if (e.getTargetException() instanceof SecurityException) {
- ; // ignore
- } else {
- // Capture 'e.getTargetException()' exception for details
- // alternate: log 'e.getTargetException()', and pass back 'e'.
- throw new LogConfigurationException
- ("Unexpected InvocationTargetException", e.getTargetException());
- }
- }
- } catch (NoSuchMethodException e) {
- // Assume we are running on JDK 1.1
- classLoader = getClassLoader(LogFactory.class);
-
- // We deliberately don't log a message here to outputStream;
- // this message would be output for every call to LogFactory.getLog()
- // when running on JDK1.1
- //
- // if (outputStream != null) {
- // outputStream.println(
- // "Method Thread.getContextClassLoader does not exist;"
- // + " assuming this is JDK 1.1, and that the context"
- // + " classloader is the same as the class that loaded"
- // + " the concrete LogFactory class.");
- // }
-
- }
-
- // Return the selected class loader
- return classLoader;
- }
-
- /**
- * Check cached factories (keyed by contextClassLoader)
- *
- * @param contextClassLoader is the context classloader associated
- * with the current thread. This allows separate LogFactory objects
- * per component within a container, provided each component has
- * a distinct context classloader set. This parameter may be null
- * in JDK1.1, and in embedded systems where jcl-using code is
- * placed in the bootclasspath.
- *
- * @return the factory associated with the specified classloader if
- * one has previously been created, or null if this is the first time
- * we have seen this particular classloader.
- */
- private static LogFactory getCachedFactory(ClassLoader contextClassLoader)
- {
- LogFactory factory = null;
-
- if (contextClassLoader == null) {
- // We have to handle this specially, as factories is a Hashtable
- // and those don't accept null as a key value.
- //
- // nb: nullClassLoaderFactory might be null. That's ok.
- factory = nullClassLoaderFactory;
- } else {
- factory = (LogFactory) factories.get(contextClassLoader);
- }
-
- return factory;
- }
-
- /**
- * Remember this factory, so later calls to LogFactory.getCachedFactory
- * can return the previously created object (together with all its
- * cached Log objects).
- *
- * @param classLoader should be the current context classloader. Note that
- * this can be null under some circumstances; this is ok.
- *
- * @param factory should be the factory to cache. This should never be null.
- */
- private static void cacheFactory(ClassLoader classLoader, LogFactory factory)
- {
- // Ideally we would assert(factory != null) here. However reporting
- // errors from within a logging implementation is a little tricky!
-
- if (factory != null) {
- if (classLoader == null) {
- nullClassLoaderFactory = factory;
- } else {
- factories.put(classLoader, factory);
- }
- }
- }
-
- /**
- * Return a new instance of the specified LogFactory
- * implementation class, loaded by the specified class loader.
- * If that fails, try the class loader used to load this
- * (abstract) LogFactory.
- *
- *
ClassLoader conflicts
- * Note that there can be problems if the specified ClassLoader is not the
- * same as the classloader that loaded this class, ie when loading a
- * concrete LogFactory subclass via a context classloader.
- *
- * The problem is the same one that can occur when loading a concrete Log
- * subclass via a context classloader.
- *
- * The problem occurs when code running in the context classloader calls
- * class X which was loaded via a parent classloader, and class X then calls
- * LogFactory.getFactory (either directly or via LogFactory.getLog). Because
- * class X was loaded via the parent, it binds to LogFactory loaded via
- * the parent. When the code in this method finds some LogFactoryYYYY
- * class in the child (context) classloader, and there also happens to be a
- * LogFactory class defined in the child classloader, then LogFactoryYYYY
- * will be bound to LogFactory@childloader. It cannot be cast to
- * LogFactory@parentloader, ie this method cannot return the object as
- * the desired type. Note that it doesn't matter if the LogFactory class
- * in the child classloader is identical to the LogFactory class in the
- * parent classloader, they are not compatible.
- *
- * The solution taken here is to simply print out an error message when
- * this occurs then throw an exception. The deployer of the application
- * must ensure they remove all occurrences of the LogFactory class from
- * the child classloader in order to resolve the issue. Note that they
- * do not have to move the custom LogFactory subclass; that is ok as
- * long as the only LogFactory class it can find to bind to is in the
- * parent classloader.
- *
- * @param factoryClass Fully qualified name of the LogFactory
- * implementation class
- * @param classLoader ClassLoader from which to load this class
- * @param contextClassLoader is the context that this new factory will
- * manage logging for.
- *
- * @exception LogConfigurationException if a suitable instance
- * cannot be created
- * @since 1.1
- */
- protected static LogFactory newFactory(final String factoryClass,
- final ClassLoader classLoader,
- final ClassLoader contextClassLoader)
- throws LogConfigurationException
- {
- // Note that any unchecked exceptions thrown by the createFactory
- // method will propagate out of this method; in particular a
- // ClassCastException can be thrown.
- Object result = AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return createFactory(factoryClass, classLoader);
- }
- });
-
- if (result instanceof LogConfigurationException) {
- LogConfigurationException ex = (LogConfigurationException) result;
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "An error occurred while loading the factory class:"
- + ex.getMessage());
- }
- throw ex;
- }
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Created object " + objectId(result)
- + " to manage classloader " + objectId(contextClassLoader));
- }
- return (LogFactory)result;
- }
-
- /**
- * Method provided for backwards compatibility; see newFactory version that
- * takes 3 parameters.
- *
- * This method would only ever be called in some rather odd situation.
- * Note that this method is static, so overriding in a subclass doesn't
- * have any effect unless this method is called from a method in that
- * subclass. However this method only makes sense to use from the
- * getFactory method, and as that is almost always invoked via
- * LogFactory.getFactory, any custom definition in a subclass would be
- * pointless. Only a class with a custom getFactory method, then invoked
- * directly via CustomFactoryImpl.getFactory or similar would ever call
- * this. Anyway, it's here just in case, though the "managed class loader"
- * value output to the diagnostics will not report the correct value.
- */
- protected static LogFactory newFactory(final String factoryClass,
- final ClassLoader classLoader) {
- return newFactory(factoryClass, classLoader, null);
- }
-
- /**
- * Implements the operations described in the javadoc for newFactory.
- *
- * @param factoryClass
- *
- * @param classLoader used to load the specified factory class. This is
- * expected to be either the TCCL or the classloader which loaded this
- * class. Note that the classloader which loaded this class might be
- * "null" (ie the bootloader) for embedded systems.
- *
- * @return either a LogFactory object or a LogConfigurationException object.
- * @since 1.1
- */
- protected static Object createFactory(String factoryClass, ClassLoader classLoader) {
-
- // This will be used to diagnose bad configurations
- // and allow a useful message to be sent to the user
- Class logFactoryClass = null;
- try {
- if (classLoader != null) {
- try {
- // First the given class loader param (thread class loader)
-
- // Warning: must typecast here & allow exception
- // to be generated/caught & recast properly.
- logFactoryClass = classLoader.loadClass(factoryClass);
- if (LogFactory.class.isAssignableFrom(logFactoryClass)) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Loaded class " + logFactoryClass.getName()
- + " from classloader " + objectId(classLoader));
- }
- } else {
- //
- // This indicates a problem with the ClassLoader tree.
- // An incompatible ClassLoader was used to load the
- // implementation.
- // As the same classes
- // must be available in multiple class loaders,
- // it is very likely that multiple JCL jars are present.
- // The most likely fix for this
- // problem is to remove the extra JCL jars from the
- // ClassLoader hierarchy.
- //
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Factory class " + logFactoryClass.getName()
- + " loaded from classloader " + objectId(logFactoryClass.getClassLoader())
- + " does not extend '" + LogFactory.class.getName()
- + "' as loaded by this classloader.");
- logHierarchy("[BAD CL TREE] ", classLoader);
- }
- }
-
- return (LogFactory) logFactoryClass.newInstance();
-
- } catch (ClassNotFoundException ex) {
- if (classLoader == thisClassLoader) {
- // Nothing more to try, onwards.
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Unable to locate any class called '" + factoryClass
- + "' via classloader " + objectId(classLoader));
- }
- throw ex;
- }
- // ignore exception, continue
- } catch (NoClassDefFoundError e) {
- if (classLoader == thisClassLoader) {
- // Nothing more to try, onwards.
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Class '" + factoryClass + "' cannot be loaded"
- + " via classloader " + objectId(classLoader)
- + " - it depends on some other class that cannot"
- + " be found.");
- }
- throw e;
- }
- // ignore exception, continue
- } catch(ClassCastException e) {
- if (classLoader == thisClassLoader) {
- // There's no point in falling through to the code below that
- // tries again with thisClassLoader, because we've just tried
- // loading with that loader (not the TCCL). Just throw an
- // appropriate exception here.
-
- final boolean implementsLogFactory = implementsLogFactory(logFactoryClass);
-
- //
- // Construct a good message: users may not actual expect that a custom implementation
- // has been specified. Several well known containers use this mechanism to adapt JCL
- // to their native logging system.
- //
- String msg =
- "The application has specified that a custom LogFactory implementation should be used but " +
- "Class '" + factoryClass + "' cannot be converted to '"
- + LogFactory.class.getName() + "'. ";
- if (implementsLogFactory) {
- msg = msg + "The conflict is caused by the presence of multiple LogFactory classes in incompatible classloaders. " +
- "Background can be found in http://commons.apache.org/logging/tech.html. " +
- "If you have not explicitly specified a custom LogFactory then it is likely that " +
- "the container has set one without your knowledge. " +
- "In this case, consider using the commons-logging-adapters.jar file or " +
- "specifying the standard LogFactory from the command line. ";
- } else {
- msg = msg + "Please check the custom implementation. ";
- }
- msg = msg + "Help can be found @http://commons.apache.org/logging/troubleshooting.html.";
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic(msg);
- }
-
- ClassCastException ex = new ClassCastException(msg);
- throw ex;
- }
-
- // Ignore exception, continue. Presumably the classloader was the
- // TCCL; the code below will try to load the class via thisClassLoader.
- // This will handle the case where the original calling class is in
- // a shared classpath but the TCCL has a copy of LogFactory and the
- // specified LogFactory implementation; we will fall back to using the
- // LogFactory implementation from the same classloader as this class.
- //
- // Issue: this doesn't handle the reverse case, where this LogFactory
- // is in the webapp, and the specified LogFactory implementation is
- // in a shared classpath. In that case:
- // (a) the class really does implement LogFactory (bad log msg above)
- // (b) the fallback code will result in exactly the same problem.
- }
- }
-
- /* At this point, either classLoader == null, OR
- * classLoader was unable to load factoryClass.
- *
- * In either case, we call Class.forName, which is equivalent
- * to LogFactory.class.getClassLoader().load(name), ie we ignore
- * the classloader parameter the caller passed, and fall back
- * to trying the classloader associated with this class. See the
- * javadoc for the newFactory method for more info on the
- * consequences of this.
- *
- * Notes:
- * * LogFactory.class.getClassLoader() may return 'null'
- * if LogFactory is loaded by the bootstrap classloader.
- */
- // Warning: must typecast here & allow exception
- // to be generated/caught & recast properly.
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Unable to load factory class via classloader "
- + objectId(classLoader)
- + " - trying the classloader associated with this LogFactory.");
- }
- logFactoryClass = Class.forName(factoryClass);
- return (LogFactory) logFactoryClass.newInstance();
- } catch (Exception e) {
- // Check to see if we've got a bad configuration
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Unable to create LogFactory instance.");
- }
- if (logFactoryClass != null
- && !LogFactory.class.isAssignableFrom(logFactoryClass)) {
-
- return new LogConfigurationException(
- "The chosen LogFactory implementation does not extend LogFactory."
- + " Please check your configuration.",
- e);
- }
- return new LogConfigurationException(e);
- }
- }
-
- /**
- * Determines whether the given class actually implements LogFactory.
- * Diagnostic information is also logged.
- *
- * Usage: to diagnose whether a classloader conflict is the cause
- * of incompatibility. The test used is whether the class is assignable from
- * the LogFactory class loaded by the class's classloader.
- * @param logFactoryClass Class which may implement LogFactory
- * @return true if the logFactoryClass does extend
- * LogFactory when that class is loaded via the same
- * classloader that loaded the logFactoryClass.
- */
- private static boolean implementsLogFactory(Class logFactoryClass) {
- boolean implementsLogFactory = false;
- if (logFactoryClass != null) {
- try {
- ClassLoader logFactoryClassLoader = logFactoryClass.getClassLoader();
- if (logFactoryClassLoader == null) {
- logDiagnostic("[CUSTOM LOG FACTORY] was loaded by the boot classloader");
- } else {
- logHierarchy("[CUSTOM LOG FACTORY] ", logFactoryClassLoader);
- Class factoryFromCustomLoader
- = Class.forName("org.apache.commons.logging.LogFactory", false, logFactoryClassLoader);
- implementsLogFactory = factoryFromCustomLoader.isAssignableFrom(logFactoryClass);
- if (implementsLogFactory) {
- logDiagnostic("[CUSTOM LOG FACTORY] " + logFactoryClass.getName()
- + " implements LogFactory but was loaded by an incompatible classloader.");
- } else {
- logDiagnostic("[CUSTOM LOG FACTORY] " + logFactoryClass.getName()
- + " does not implement LogFactory.");
- }
- }
- } catch (SecurityException e) {
- //
- // The application is running within a hostile security environment.
- // This will make it very hard to diagnose issues with JCL.
- // Consider running less securely whilst debugging this issue.
- //
- logDiagnostic("[CUSTOM LOG FACTORY] SecurityException thrown whilst trying to determine whether " +
- "the compatibility was caused by a classloader conflict: "
- + e.getMessage());
- } catch (LinkageError e) {
- //
- // This should be an unusual circumstance.
- // LinkageError's usually indicate that a dependent class has incompatibly changed.
- // Another possibility may be an exception thrown by an initializer.
- // Time for a clean rebuild?
- //
- logDiagnostic("[CUSTOM LOG FACTORY] LinkageError thrown whilst trying to determine whether " +
- "the compatibility was caused by a classloader conflict: "
- + e.getMessage());
- } catch (ClassNotFoundException e) {
- //
- // LogFactory cannot be loaded by the classloader which loaded the custom factory implementation.
- // The custom implementation is not viable until this is corrected.
- // Ensure that the JCL jar and the custom class are available from the same classloader.
- // Running with diagnostics on should give information about the classloaders used
- // to load the custom factory.
- //
- logDiagnostic("[CUSTOM LOG FACTORY] LogFactory class cannot be loaded by classloader which loaded the " +
- "custom LogFactory implementation. Is the custom factory in the right classloader?");
- }
- }
- return implementsLogFactory;
- }
-
- /**
- * Applets may run in an environment where accessing resources of a loader is
- * a secure operation, but where the commons-logging library has explicitly
- * been granted permission for that operation. In this case, we need to
- * run the operation using an AccessController.
- */
- private static InputStream getResourceAsStream(final ClassLoader loader,
- final String name)
- {
- return (InputStream)AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- if (loader != null) {
- return loader.getResourceAsStream(name);
- } else {
- return ClassLoader.getSystemResourceAsStream(name);
- }
- }
- });
- }
-
- /**
- * Given a filename, return an enumeration of URLs pointing to
- * all the occurrences of that filename in the classpath.
- *
- * This is just like ClassLoader.getResources except that the
- * operation is done under an AccessController so that this method will
- * succeed when this jarfile is privileged but the caller is not.
- * This method must therefore remain private to avoid security issues.
- *
- * If no instances are found, an Enumeration is returned whose
- * hasMoreElements method returns false (ie an "empty" enumeration).
- * If resources could not be listed for some reason, null is returned.
- */
- private static Enumeration getResources(final ClassLoader loader,
- final String name)
- {
- PrivilegedAction action =
- new PrivilegedAction() {
- public Object run() {
- try {
- if (loader != null) {
- return loader.getResources(name);
- } else {
- return ClassLoader.getSystemResources(name);
- }
- } catch(IOException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Exception while trying to find configuration file "
- + name + ":" + e.getMessage());
- }
- return null;
- } catch(NoSuchMethodError e) {
- // we must be running on a 1.1 JVM which doesn't support
- // ClassLoader.getSystemResources; just return null in
- // this case.
- return null;
- }
- }
- };
- Object result = AccessController.doPrivileged(action);
- return (Enumeration) result;
- }
-
- /**
- * Given a URL that refers to a .properties file, load that file.
- * This is done under an AccessController so that this method will
- * succeed when this jarfile is privileged but the caller is not.
- * This method must therefore remain private to avoid security issues.
- *
- * Null is returned if the URL cannot be opened.
- */
- private static Properties getProperties(final URL url) {
- PrivilegedAction action =
- new PrivilegedAction() {
- public Object run() {
- InputStream stream = null;
- try {
- // We must ensure that useCaches is set to false, as the
- // default behaviour of java is to cache file handles, and
- // this "locks" files, preventing hot-redeploy on windows.
- URLConnection connection = url.openConnection();
- connection.setUseCaches(false);
- stream = connection.getInputStream();
- if (stream != null) {
- Properties props = new Properties();
- props.load(stream);
- stream.close();
- stream = null;
- return props;
- }
- } catch(IOException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Unable to read URL " + url);
- }
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch(Throwable t) {
- // ignore exception; this should not happen
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Unable to close stream for URL " + url);
- }
- }
- }
- }
-
- return null;
- }
- };
- return (Properties) AccessController.doPrivileged(action);
- }
-
- /**
- * Locate a user-provided configuration file.
- *
- * The classpath of the specified classLoader (usually the context classloader)
- * is searched for properties files of the specified name. If none is found,
- * null is returned. If more than one is found, then the file with the greatest
- * value for its PRIORITY property is returned. If multiple files have the
- * same PRIORITY value then the first in the classpath is returned.
- *
- * This differs from the 1.0.x releases; those always use the first one found.
- * However as the priority is a new field, this change is backwards compatible.
- *
- * The purpose of the priority field is to allow a webserver administrator to
- * override logging settings in all webapps by placing a commons-logging.properties
- * file in a shared classpath location with a priority > 0; this overrides any
- * commons-logging.properties files without priorities which are in the
- * webapps. Webapps can also use explicit priorities to override a configuration
- * file in the shared classpath if needed.
- */
- private static final Properties getConfigurationFile(
- ClassLoader classLoader, String fileName) {
-
- Properties props = null;
- double priority = 0.0;
- URL propsUrl = null;
- try {
- Enumeration urls = getResources(classLoader, fileName);
-
- if (urls == null) {
- return null;
- }
-
- while (urls.hasMoreElements()) {
- URL url = (URL) urls.nextElement();
-
- Properties newProps = getProperties(url);
- if (newProps != null) {
- if (props == null) {
- propsUrl = url;
- props = newProps;
- String priorityStr = props.getProperty(PRIORITY_KEY);
- priority = 0.0;
- if (priorityStr != null) {
- priority = Double.parseDouble(priorityStr);
- }
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Properties file found at '" + url + "'"
- + " with priority " + priority);
- }
- } else {
- String newPriorityStr = newProps.getProperty(PRIORITY_KEY);
- double newPriority = 0.0;
- if (newPriorityStr != null) {
- newPriority = Double.parseDouble(newPriorityStr);
- }
-
- if (newPriority > priority) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Properties file at '" + url + "'"
- + " with priority " + newPriority
- + " overrides file at '" + propsUrl + "'"
- + " with priority " + priority);
- }
-
- propsUrl = url;
- props = newProps;
- priority = newPriority;
- } else {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[LOOKUP] Properties file at '" + url + "'"
- + " with priority " + newPriority
- + " does not override file at '" + propsUrl + "'"
- + " with priority " + priority);
- }
- }
- }
-
- }
- }
- } catch (SecurityException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("SecurityException thrown while trying to find/read config files.");
- }
- }
-
- if (isDiagnosticsEnabled()) {
- if (props == null) {
- logDiagnostic(
- "[LOOKUP] No properties file of name '" + fileName
- + "' found.");
- } else {
- logDiagnostic(
- "[LOOKUP] Properties file of name '" + fileName
- + "' found at '" + propsUrl + '"');
- }
- }
-
- return props;
- }
-
- /**
- * Read the specified system property, using an AccessController so that
- * the property can be read if JCL has been granted the appropriate
- * security rights even if the calling code has not.
- *
- * Take care not to expose the value returned by this method to the
- * calling application in any way; otherwise the calling app can use that
- * info to access data that should not be available to it.
- */
- private static String getSystemProperty(final String key, final String def)
- throws SecurityException {
- return (String) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return System.getProperty(key, def);
- }
- });
- }
-
- /**
- * Determines whether the user wants internal diagnostic output. If so,
- * returns an appropriate writer object. Users can enable diagnostic
- * output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to
- * a filename, or the special values STDOUT or STDERR.
- */
- private static void initDiagnostics() {
- String dest;
- try {
- dest = getSystemProperty(DIAGNOSTICS_DEST_PROPERTY, null);
- if (dest == null) {
- return;
- }
- } catch(SecurityException ex) {
- // We must be running in some very secure environment.
- // We just have to assume output is not wanted..
- return;
- }
-
- if (dest.equals("STDOUT")) {
- diagnosticsStream = System.out;
- } else if (dest.equals("STDERR")) {
- diagnosticsStream = System.err;
- } else {
- try {
- // open the file in append mode
- FileOutputStream fos = new FileOutputStream(dest, true);
- diagnosticsStream = new PrintStream(fos);
- } catch(IOException ex) {
- // We should report this to the user - but how?
- return;
- }
- }
-
- // In order to avoid confusion where multiple instances of JCL are
- // being used via different classloaders within the same app, we
- // ensure each logged message has a prefix of form
- // [LogFactory from classloader OID]
- //
- // Note that this prefix should be kept consistent with that
- // in LogFactoryImpl. However here we don't need to output info
- // about the actual *instance* of LogFactory, as all methods that
- // output diagnostics from this class are static.
- String classLoaderName;
- try {
- ClassLoader classLoader = thisClassLoader;
- if (thisClassLoader == null) {
- classLoaderName = "BOOTLOADER";
- } else {
- classLoaderName = objectId(classLoader);
- }
- } catch(SecurityException e) {
- classLoaderName = "UNKNOWN";
- }
- diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
- }
-
- /**
- * Indicates true if the user has enabled internal logging.
- *
- * By the way, sorry for the incorrect grammar, but calling this method
- * areDiagnosticsEnabled just isn't java beans style.
- *
- * @return true if calls to logDiagnostic will have any effect.
- * @since 1.1
- */
- protected static boolean isDiagnosticsEnabled() {
- return diagnosticsStream != null;
- }
-
- /**
- * Write the specified message to the internal logging destination.
- *
- * Note that this method is private; concrete subclasses of this class
- * should not call it because the diagnosticPrefix string this
- * method puts in front of all its messages is LogFactory@....,
- * while subclasses should put SomeSubClass@...
- *
- * Subclasses should instead compute their own prefix, then call
- * logRawDiagnostic. Note that calling isDiagnosticsEnabled is
- * fine for subclasses.
- *
- * Note that it is safe to call this method before initDiagnostics
- * is called; any output will just be ignored (as isDiagnosticsEnabled
- * will return false).
- *
- * @param msg is the diagnostic message to be output.
- */
- private static final void logDiagnostic(String msg) {
- if (diagnosticsStream != null) {
- diagnosticsStream.print(diagnosticPrefix);
- diagnosticsStream.println(msg);
- diagnosticsStream.flush();
- }
- }
-
- /**
- * Write the specified message to the internal logging destination.
- *
- * @param msg is the diagnostic message to be output.
- * @since 1.1
- */
- protected static final void logRawDiagnostic(String msg) {
- if (diagnosticsStream != null) {
- diagnosticsStream.println(msg);
- diagnosticsStream.flush();
- }
- }
-
- /**
- * Generate useful diagnostics regarding the classloader tree for
- * the specified class.
- *
- * As an example, if the specified class was loaded via a webapp's
- * classloader, then you may get the following output:
- *
- * Class com.acme.Foo was loaded via classloader 11111
- * ClassLoader tree: 11111 -> 22222 (SYSTEM) -> 33333 -> BOOT
- *
- *
- * This method returns immediately if isDiagnosticsEnabled()
- * returns false.
- *
- * @param clazz is the class whose classloader + tree are to be
- * output.
- */
- private static void logClassLoaderEnvironment(Class clazz) {
- if (!isDiagnosticsEnabled()) {
- return;
- }
-
- try {
- // Deliberately use System.getProperty here instead of getSystemProperty; if
- // the overall security policy for the calling application forbids access to
- // these variables then we do not want to output them to the diagnostic stream.
- logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir"));
- logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
- } catch(SecurityException ex) {
- logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
- }
-
- String className = clazz.getName();
- ClassLoader classLoader;
-
- try {
- classLoader = getClassLoader(clazz);
- } catch(SecurityException ex) {
- // not much useful diagnostics we can print here!
- logDiagnostic(
- "[ENV] Security forbids determining the classloader for " + className);
- return;
- }
-
- logDiagnostic(
- "[ENV] Class " + className + " was loaded via classloader "
- + objectId(classLoader));
- logHierarchy("[ENV] Ancestry of classloader which loaded " + className + " is ", classLoader);
- }
-
- /**
- * Logs diagnostic messages about the given classloader
- * and it's hierarchy. The prefix is prepended to the message
- * and is intended to make it easier to understand the logs.
- * @param prefix
- * @param classLoader
- */
- private static void logHierarchy(String prefix, ClassLoader classLoader) {
- if (!isDiagnosticsEnabled()) {
- return;
- }
- ClassLoader systemClassLoader;
- if (classLoader != null) {
- final String classLoaderString = classLoader.toString();
- logDiagnostic(prefix + objectId(classLoader) + " == '" + classLoaderString + "'");
- }
-
- try {
- systemClassLoader = ClassLoader.getSystemClassLoader();
- } catch(SecurityException ex) {
- logDiagnostic(
- prefix + "Security forbids determining the system classloader.");
- return;
- }
- if (classLoader != null) {
- StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
- for(;;) {
- buf.append(objectId(classLoader));
- if (classLoader == systemClassLoader) {
- buf.append(" (SYSTEM) ");
- }
-
- try {
- classLoader = classLoader.getParent();
- } catch(SecurityException ex) {
- buf.append(" --> SECRET");
- break;
- }
-
- buf.append(" --> ");
- if (classLoader == null) {
- buf.append("BOOT");
- break;
- }
- }
- logDiagnostic(buf.toString());
- }
- }
-
- /**
- * Returns a string that uniquely identifies the specified object, including
- * its class.
- *
- * The returned string is of form "classname@hashcode", ie is the same as
- * the return value of the Object.toString() method, but works even when
- * the specified object's class has overidden the toString method.
- *
- * @param o may be null.
- * @return a string of form classname@hashcode, or "null" if param o is null.
- * @since 1.1
- */
- public static String objectId(Object o) {
- if (o == null) {
- return "null";
- } else {
- return o.getClass().getName() + "@" + System.identityHashCode(o);
- }
- }
-
- // ----------------------------------------------------------------------
- // Static initialiser block to perform initialisation at class load time.
- //
- // We can't do this in the class constructor, as there are many
- // static methods on this class that can be called before any
- // LogFactory instances are created, and they depend upon this
- // stuff having been set up.
- //
- // Note that this block must come after any variable declarations used
- // by any methods called from this block, as we want any static initialiser
- // associated with the variable to run first. If static initialisers for
- // variables run after this code, then (a) their value might be needed
- // by methods called from here, and (b) they might *override* any value
- // computed here!
- //
- // So the wisest thing to do is just to place this code at the very end
- // of the class file.
- // ----------------------------------------------------------------------
-
- static {
- // note: it's safe to call methods before initDiagnostics (though
- // diagnostic output gets discarded).
- thisClassLoader = getClassLoader(LogFactory.class);
- initDiagnostics();
- logClassLoaderEnvironment(LogFactory.class);
- factories = createFactoryStore();
- if (isDiagnosticsEnabled()) {
- logDiagnostic("BOOTSTRAP COMPLETED");
- }
- }
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogSource.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogSource.java
deleted file mode 100644
index 9cb5f1184..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/LogSource.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * 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.commons.logging;
-
-
-import java.lang.reflect.Constructor;
-import java.util.Hashtable;
-
-import org.apache.commons.logging.impl.NoOpLog;
-
-
-/**
- *
Factory for creating {@link Log} instances. Applications should call
- * the makeNewLogInstance() method to instantiate new instances
- * of the configured {@link Log} implementation class.
- *
- *
By default, calling getInstance() will use the following
- * algorithm:
- *
- *
If Log4J is available, return an instance of
- * org.apache.commons.logging.impl.Log4JLogger.
- *
If JDK 1.4 or later is available, return an instance of
- * org.apache.commons.logging.impl.Jdk14Logger.
- *
Otherwise, return an instance of
- * org.apache.commons.logging.impl.NoOpLog.
- *
- *
- *
You can change the default behavior in one of two ways:
- *
- *
On the startup command line, set the system property
- * org.apache.commons.logging.log to the name of the
- * org.apache.commons.logging.Log implementation class
- * you want to use.
- *
At runtime, call LogSource.setLogImplementation().
- *
- *
- * @deprecated Use {@link LogFactory} instead - The default factory
- * implementation performs exactly the same algorithm as this class did
- *
- * @author Rod Waldhoff
- * @version $Id: LogSource.java 424107 2006-07-20 23:15:42Z skitching $
- */
-public class LogSource {
-
- // ------------------------------------------------------- Class Attributes
-
- static protected Hashtable logs = new Hashtable();
-
- /** Is log4j available (in the current classpath) */
- static protected boolean log4jIsAvailable = false;
-
- /** Is JDK 1.4 logging available */
- static protected boolean jdk14IsAvailable = false;
-
- /** Constructor for current log class */
- static protected Constructor logImplctor = null;
-
-
- // ----------------------------------------------------- Class Initializers
-
- static {
-
- // Is Log4J Available?
- try {
- if (null != Class.forName("org.apache.log4j.Logger")) {
- log4jIsAvailable = true;
- } else {
- log4jIsAvailable = false;
- }
- } catch (Throwable t) {
- log4jIsAvailable = false;
- }
-
- // Is JDK 1.4 Logging Available?
- try {
- if ((null != Class.forName("java.util.logging.Logger")) &&
- (null != Class.forName("org.apache.commons.logging.impl.Jdk14Logger"))) {
- jdk14IsAvailable = true;
- } else {
- jdk14IsAvailable = false;
- }
- } catch (Throwable t) {
- jdk14IsAvailable = false;
- }
-
- // Set the default Log implementation
- String name = null;
- try {
- name = System.getProperty("org.apache.commons.logging.log");
- if (name == null) {
- name = System.getProperty("org.apache.commons.logging.Log");
- }
- } catch (Throwable t) {
- }
- if (name != null) {
- try {
- setLogImplementation(name);
- } catch (Throwable t) {
- try {
- setLogImplementation
- ("org.apache.commons.logging.impl.NoOpLog");
- } catch (Throwable u) {
- ;
- }
- }
- } else {
- try {
- if (log4jIsAvailable) {
- setLogImplementation
- ("org.apache.commons.logging.impl.Log4JLogger");
- } else if (jdk14IsAvailable) {
- setLogImplementation
- ("org.apache.commons.logging.impl.Jdk14Logger");
- } else {
- setLogImplementation
- ("org.apache.commons.logging.impl.NoOpLog");
- }
- } catch (Throwable t) {
- try {
- setLogImplementation
- ("org.apache.commons.logging.impl.NoOpLog");
- } catch (Throwable u) {
- ;
- }
- }
- }
-
- }
-
-
- // ------------------------------------------------------------ Constructor
-
-
- /** Don't allow others to create instances */
- private LogSource() {
- }
-
-
- // ---------------------------------------------------------- Class Methods
-
-
- /**
- * Set the log implementation/log implementation factory
- * by the name of the class. The given class
- * must implement {@link Log}, and provide a constructor that
- * takes a single {@link String} argument (containing the name
- * of the log).
- */
- static public void setLogImplementation(String classname) throws
- LinkageError, ExceptionInInitializerError,
- NoSuchMethodException, SecurityException,
- ClassNotFoundException {
- try {
- Class logclass = Class.forName(classname);
- Class[] argtypes = new Class[1];
- argtypes[0] = "".getClass();
- logImplctor = logclass.getConstructor(argtypes);
- } catch (Throwable t) {
- logImplctor = null;
- }
- }
-
-
- /**
- * Set the log implementation/log implementation factory
- * by class. The given class must implement {@link Log},
- * and provide a constructor that takes a single {@link String}
- * argument (containing the name of the log).
- */
- static public void setLogImplementation(Class logclass) throws
- LinkageError, ExceptionInInitializerError,
- NoSuchMethodException, SecurityException {
- Class[] argtypes = new Class[1];
- argtypes[0] = "".getClass();
- logImplctor = logclass.getConstructor(argtypes);
- }
-
-
- /** Get a Log instance by class name */
- static public Log getInstance(String name) {
- Log log = (Log) (logs.get(name));
- if (null == log) {
- log = makeNewLogInstance(name);
- logs.put(name, log);
- }
- return log;
- }
-
-
- /** Get a Log instance by class */
- static public Log getInstance(Class clazz) {
- return getInstance(clazz.getName());
- }
-
-
- /**
- * Create a new {@link Log} implementation, based
- * on the given name.
- *
- * The specific {@link Log} implementation returned
- * is determined by the value of the
- * org.apache.commons.logging.log property.
- * The value of org.apache.commons.logging.log may be set to
- * the fully specified name of a class that implements
- * the {@link Log} interface. This class must also
- * have a public constructor that takes a single
- * {@link String} argument (containing the name
- * of the {@link Log} to be constructed.
- *
- * When org.apache.commons.logging.log is not set,
- * or when no corresponding class can be found,
- * this method will return a Log4JLogger
- * if the log4j Logger class is
- * available in the {@link LogSource}'s classpath, or a
- * Jdk14Logger if we are on a JDK 1.4 or later system, or
- * NoOpLog if neither of the above conditions is true.
- *
- * @param name the log name (or category)
- */
- static public Log makeNewLogInstance(String name) {
-
- Log log = null;
- try {
- Object[] args = new Object[1];
- args[0] = name;
- log = (Log) (logImplctor.newInstance(args));
- } catch (Throwable t) {
- log = null;
- }
- if (null == log) {
- log = new NoOpLog(name);
- }
- return log;
-
- }
-
-
- /**
- * Returns a {@link String} array containing the names of
- * all logs known to me.
- */
- static public String[] getLogNames() {
- return (String[]) (logs.keySet().toArray(new String[logs.size()]));
- }
-
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/AvalonLogger.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/AvalonLogger.java
deleted file mode 100644
index bcf699788..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/AvalonLogger.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.commons.logging.Log;
-
-/**
- *
Implementation of commons-logging Log interface that delegates all
- * logging calls to the Avalon logging abstraction: the Logger interface.
- *
- *
- * There are two ways in which this class can be used:
- *
- *
- *
the instance can be constructed with an Avalon logger
- * (by calling {@link #AvalonLogger(Logger)}). In this case, it acts
- * as a simple thin wrapping implementation over the logger. This is
- * particularly useful when using a property setter.
- *
- *
the {@link #setDefaultLogger} class property can be called which
- * sets the ancesteral Avalon logger for this class. Any AvalonLogger
- * instances created through the LogFactory mechanisms will output
- * to child loggers of this Logger.
- *
- *
- *
- * Note:AvalonLogger does not implement Serializable
- * because the constructors available for it make this impossible to achieve in all
- * circumstances; there is no way to "reconnect" to an underlying Logger object on
- * deserialization if one was just passed in to the constructor of the original
- * object. This class was marked Serializable in the 1.0.4 release of
- * commons-logging, but this never actually worked (a NullPointerException would
- * be thrown as soon as the deserialized object was used), so removing this marker
- * is not considered to be an incompatible change.
- *
- * @author Neeme Praks
- * @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (ven., 21 juil. 2006) $
- */
-public class AvalonLogger implements Log {
-
- /** Ancesteral avalon logger */
- private static Logger defaultLogger = null;
- /** Avalon logger used to perform log */
- private transient Logger logger = null;
-
- /**
- * Constructs an AvalonLogger that outputs to the given
- * Logger instance.
- * @param logger the avalon logger implementation to delegate to
- */
- public AvalonLogger(Logger logger) {
- this.logger = logger;
- }
-
- /**
- * Constructs an AvalonLogger that will log to a child
- * of the Logger set by calling {@link #setDefaultLogger}.
- * @param name the name of the avalon logger implementation to delegate to
- */
- public AvalonLogger(String name) {
- if (defaultLogger == null)
- throw new NullPointerException("default logger has to be specified if this constructor is used!");
- this.logger = defaultLogger.getChildLogger(name);
- }
-
- /**
- * Gets the Avalon logger implementation used to perform logging.
- * @return avalon logger implementation
- */
- public Logger getLogger() {
- return logger;
- }
-
- /**
- * Sets the ancesteral Avalon logger from which the delegating loggers
- * will descend.
- * @param logger the default avalon logger,
- * in case there is no logger instance supplied in constructor
- */
- public static void setDefaultLogger(Logger logger) {
- defaultLogger = logger;
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.debug.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#debug(Object, Throwable)
- */
- public void debug(Object message, Throwable t) {
- if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.debug.
- *
- * @param message to log.
- * @see org.apache.commons.logging.Log#debug(Object)
- */
- public void debug(Object message) {
- if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message));
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.error.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#error(Object, Throwable)
- */
- public void error(Object message, Throwable t) {
- if (getLogger().isErrorEnabled()) getLogger().error(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.error.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#error(Object)
- */
- public void error(Object message) {
- if (getLogger().isErrorEnabled()) getLogger().error(String.valueOf(message));
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.fatalError.
- *
- * @param message to log.
- * @param t log this cause.
- * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
- */
- public void fatal(Object message, Throwable t) {
- if (getLogger().isFatalErrorEnabled()) getLogger().fatalError(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.fatalError.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#fatal(Object)
- */
- public void fatal(Object message) {
- if (getLogger().isFatalErrorEnabled()) getLogger().fatalError(String.valueOf(message));
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.info.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#info(Object, Throwable)
- */
- public void info(Object message, Throwable t) {
- if (getLogger().isInfoEnabled()) getLogger().info(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.info.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#info(Object)
- */
- public void info(Object message) {
- if (getLogger().isInfoEnabled()) getLogger().info(String.valueOf(message));
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.debug enabled?
- * @see org.apache.commons.logging.Log#isDebugEnabled()
- */
- public boolean isDebugEnabled() {
- return getLogger().isDebugEnabled();
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.error enabled?
- * @see org.apache.commons.logging.Log#isErrorEnabled()
- */
- public boolean isErrorEnabled() {
- return getLogger().isErrorEnabled();
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.fatalError enabled?
- * @see org.apache.commons.logging.Log#isFatalEnabled()
- */
- public boolean isFatalEnabled() {
- return getLogger().isFatalErrorEnabled();
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.info enabled?
- * @see org.apache.commons.logging.Log#isInfoEnabled()
- */
- public boolean isInfoEnabled() {
- return getLogger().isInfoEnabled();
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.debug enabled?
- * @see org.apache.commons.logging.Log#isTraceEnabled()
- */
- public boolean isTraceEnabled() {
- return getLogger().isDebugEnabled();
- }
-
- /**
- * Is logging to
- * org.apache.avalon.framework.logger.Logger.warn enabled?
- * @see org.apache.commons.logging.Log#isWarnEnabled()
- */
- public boolean isWarnEnabled() {
- return getLogger().isWarnEnabled();
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.debug.
- *
- * @param message to log.
- * @param t log this cause.
- * @see org.apache.commons.logging.Log#trace(Object, Throwable)
- */
- public void trace(Object message, Throwable t) {
- if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.debug.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#trace(Object)
- */
- public void trace(Object message) {
- if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message));
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.warn.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#warn(Object, Throwable)
- */
- public void warn(Object message, Throwable t) {
- if (getLogger().isWarnEnabled()) getLogger().warn(String.valueOf(message), t);
- }
-
- /**
- * Logs a message with
- * org.apache.avalon.framework.logger.Logger.warn.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#warn(Object)
- */
- public void warn(Object message) {
- if (getLogger().isWarnEnabled()) getLogger().warn(String.valueOf(message));
- }
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java
deleted file mode 100644
index c64b86846..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.logging.LogRecord;
-import java.util.StringTokenizer;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.apache.commons.logging.Log;
-
-
-/**
- *
Implementation of the org.apache.commons.logging.Log
- * interface that wraps the standard JDK logging mechanisms that are
- * available in SourceForge's Lumberjack for JDKs prior to 1.4.
- *
- * @author Scott Sanders
- * @author Berin Loritsch
- * @author Peter Donald
- * @author Vince Eagen
- * @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (ven., 21 juil. 2006) $
- * @since 1.1
- */
-
-public class Jdk13LumberjackLogger implements Log, Serializable {
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The underlying Logger implementation we are using.
- */
- protected transient Logger logger = null;
- protected String name = null;
- private String sourceClassName = "unknown";
- private String sourceMethodName = "unknown";
- private boolean classAndMethodFound = false;
-
-
- /**
- * This member variable simply ensures that any attempt to initialise
- * this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
- * It must not be private, as an optimising compiler could detect that it
- * is not used and optimise it away.
- */
- protected static final Level dummyLevel = Level.FINE;
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a named instance of this Logger.
- *
- * @param name Name of the logger to be constructed
- */
- public Jdk13LumberjackLogger(String name) {
-
- this.name = name;
- logger = getLogger();
-
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- private void log( Level level, String msg, Throwable ex ) {
- if( getLogger().isLoggable(level) ) {
- LogRecord record = new LogRecord(level, msg);
- if( !classAndMethodFound ) {
- getClassAndMethod();
- }
- record.setSourceClassName(sourceClassName);
- record.setSourceMethodName(sourceMethodName);
- if( ex != null ) {
- record.setThrown(ex);
- }
- getLogger().log(record);
- }
- }
-
- /**
- *
Gets the class and method by looking at the stack trace for the
- * first entry that is not this class.
- */
- private void getClassAndMethod() {
- try {
- Throwable throwable = new Throwable();
- throwable.fillInStackTrace();
- StringWriter stringWriter = new StringWriter();
- PrintWriter printWriter = new PrintWriter( stringWriter );
- throwable.printStackTrace( printWriter );
- String traceString = stringWriter.getBuffer().toString();
- StringTokenizer tokenizer =
- new StringTokenizer( traceString, "\n" );
- tokenizer.nextToken();
- String line = tokenizer.nextToken();
- while ( line.indexOf( this.getClass().getName() ) == -1 ) {
- line = tokenizer.nextToken();
- }
- while ( line.indexOf( this.getClass().getName() ) >= 0 ) {
- line = tokenizer.nextToken();
- }
- int start = line.indexOf( "at " ) + 3;
- int end = line.indexOf( '(' );
- String temp = line.substring( start, end );
- int lastPeriod = temp.lastIndexOf( '.' );
- sourceClassName = temp.substring( 0, lastPeriod );
- sourceMethodName = temp.substring( lastPeriod + 1 );
- } catch ( Exception ex ) {
- // ignore - leave class and methodname unknown
- }
- classAndMethodFound = true;
- }
-
- /**
- * Logs a message with java.util.logging.Level.FINE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#debug(Object)
- */
- public void debug(Object message) {
- log(Level.FINE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#debug(Object, Throwable)
- */
- public void debug(Object message, Throwable exception) {
- log(Level.FINE, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#error(Object)
- */
- public void error(Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#error(Object, Throwable)
- */
- public void error(Object message, Throwable exception) {
- log(Level.SEVERE, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#fatal(Object)
- */
- public void fatal(Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
- */
- public void fatal(Object message, Throwable exception) {
- log(Level.SEVERE, String.valueOf(message), exception);
- }
-
-
- /**
- * Return the native Logger instance we are using.
- */
- public Logger getLogger() {
- if (logger == null) {
- logger = Logger.getLogger(name);
- }
- return (logger);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.INFO.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#info(Object)
- */
- public void info(Object message) {
- log(Level.INFO, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.INFO.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#info(Object, Throwable)
- */
- public void info(Object message, Throwable exception) {
- log(Level.INFO, String.valueOf(message), exception);
- }
-
-
- /**
- * Is debug logging currently enabled?
- */
- public boolean isDebugEnabled() {
- return (getLogger().isLoggable(Level.FINE));
- }
-
-
- /**
- * Is error logging currently enabled?
- */
- public boolean isErrorEnabled() {
- return (getLogger().isLoggable(Level.SEVERE));
- }
-
-
- /**
- * Is fatal logging currently enabled?
- */
- public boolean isFatalEnabled() {
- return (getLogger().isLoggable(Level.SEVERE));
- }
-
-
- /**
- * Is info logging currently enabled?
- */
- public boolean isInfoEnabled() {
- return (getLogger().isLoggable(Level.INFO));
- }
-
-
- /**
- * Is trace logging currently enabled?
- */
- public boolean isTraceEnabled() {
- return (getLogger().isLoggable(Level.FINEST));
- }
-
-
- /**
- * Is warn logging currently enabled?
- */
- public boolean isWarnEnabled() {
- return (getLogger().isLoggable(Level.WARNING));
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINEST.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#trace(Object)
- */
- public void trace(Object message) {
- log(Level.FINEST, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINEST.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#trace(Object, Throwable)
- */
- public void trace(Object message, Throwable exception) {
- log(Level.FINEST, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.WARNING.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#warn(Object)
- */
- public void warn(Object message) {
- log(Level.WARNING, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.WARNING.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#warn(Object, Throwable)
- */
- public void warn(Object message, Throwable exception) {
- log(Level.WARNING, String.valueOf(message), exception);
- }
-
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk14Logger.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk14Logger.java
deleted file mode 100644
index 0de81f43c..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/Jdk14Logger.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.commons.logging.Log;
-
-
-/**
- *
Implementation of the org.apache.commons.logging.Log
- * interface that wraps the standard JDK logging mechanisms that were
- * introduced in the Merlin release (JDK 1.4).
- *
- * @author Scott Sanders
- * @author Berin Loritsch
- * @author Peter Donald
- * @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (ven., 21 juil. 2006) $
- */
-
-public class Jdk14Logger implements Log, Serializable {
-
- /**
- * This member variable simply ensures that any attempt to initialise
- * this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
- * It must not be private, as an optimising compiler could detect that it
- * is not used and optimise it away.
- */
- protected static final Level dummyLevel = Level.FINE;
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a named instance of this Logger.
- *
- * @param name Name of the logger to be constructed
- */
- public Jdk14Logger(String name) {
-
- this.name = name;
- logger = getLogger();
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The underlying Logger implementation we are using.
- */
- protected transient Logger logger = null;
-
-
- /**
- * The name of the logger we are wrapping.
- */
- protected String name = null;
-
-
- // --------------------------------------------------------- Public Methods
-
- private void log( Level level, String msg, Throwable ex ) {
-
- Logger logger = getLogger();
- if (logger.isLoggable(level)) {
- // Hack (?) to get the stack trace.
- Throwable dummyException=new Throwable();
- StackTraceElement locations[]=dummyException.getStackTrace();
- // Caller will be the third element
- String cname="unknown";
- String method="unknown";
- if( locations!=null && locations.length >2 ) {
- StackTraceElement caller=locations[2];
- cname=caller.getClassName();
- method=caller.getMethodName();
- }
- if( ex==null ) {
- logger.logp( level, cname, method, msg );
- } else {
- logger.logp( level, cname, method, msg, ex );
- }
- }
-
- }
-
- /**
- * Logs a message with java.util.logging.Level.FINE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#debug(Object)
- */
- public void debug(Object message) {
- log(Level.FINE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#debug(Object, Throwable)
- */
- public void debug(Object message, Throwable exception) {
- log(Level.FINE, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#error(Object)
- */
- public void error(Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#error(Object, Throwable)
- */
- public void error(Object message, Throwable exception) {
- log(Level.SEVERE, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#fatal(Object)
- */
- public void fatal(Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.SEVERE.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
- */
- public void fatal(Object message, Throwable exception) {
- log(Level.SEVERE, String.valueOf(message), exception);
- }
-
-
- /**
- * Return the native Logger instance we are using.
- */
- public Logger getLogger() {
- if (logger == null) {
- logger = Logger.getLogger(name);
- }
- return (logger);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.INFO.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#info(Object)
- */
- public void info(Object message) {
- log(Level.INFO, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.INFO.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#info(Object, Throwable)
- */
- public void info(Object message, Throwable exception) {
- log(Level.INFO, String.valueOf(message), exception);
- }
-
-
- /**
- * Is debug logging currently enabled?
- */
- public boolean isDebugEnabled() {
- return (getLogger().isLoggable(Level.FINE));
- }
-
-
- /**
- * Is error logging currently enabled?
- */
- public boolean isErrorEnabled() {
- return (getLogger().isLoggable(Level.SEVERE));
- }
-
-
- /**
- * Is fatal logging currently enabled?
- */
- public boolean isFatalEnabled() {
- return (getLogger().isLoggable(Level.SEVERE));
- }
-
-
- /**
- * Is info logging currently enabled?
- */
- public boolean isInfoEnabled() {
- return (getLogger().isLoggable(Level.INFO));
- }
-
-
- /**
- * Is trace logging currently enabled?
- */
- public boolean isTraceEnabled() {
- return (getLogger().isLoggable(Level.FINEST));
- }
-
-
- /**
- * Is warn logging currently enabled?
- */
- public boolean isWarnEnabled() {
- return (getLogger().isLoggable(Level.WARNING));
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINEST.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#trace(Object)
- */
- public void trace(Object message) {
- log(Level.FINEST, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.FINEST.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#trace(Object, Throwable)
- */
- public void trace(Object message, Throwable exception) {
- log(Level.FINEST, String.valueOf(message), exception);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.WARNING.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#warn(Object)
- */
- public void warn(Object message) {
- log(Level.WARNING, String.valueOf(message), null);
- }
-
-
- /**
- * Logs a message with java.util.logging.Level.WARNING.
- *
- * @param message to log
- * @param exception log this cause
- * @see org.apache.commons.logging.Log#warn(Object, Throwable)
- */
- public void warn(Object message, Throwable exception) {
- log(Level.WARNING, String.valueOf(message), exception);
- }
-
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/LogFactoryImpl.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/LogFactoryImpl.java
deleted file mode 100644
index b4fa8db97..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/LogFactoryImpl.java
+++ /dev/null
@@ -1,1500 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogConfigurationException;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- *
Concrete subclass of {@link LogFactory} that implements the
- * following algorithm to dynamically select a logging implementation
- * class to instantiate a wrapper for.
- *
- *
Use a factory configuration attribute named
- * org.apache.commons.logging.Log to identify the
- * requested implementation class.
- *
Use the org.apache.commons.logging.Log system property
- * to identify the requested implementation class.
- *
If Log4J is available, return an instance of
- * org.apache.commons.logging.impl.Log4JLogger.
- *
If JDK 1.4 or later is available, return an instance of
- * org.apache.commons.logging.impl.Jdk14Logger.
- *
Otherwise, return an instance of
- * org.apache.commons.logging.impl.SimpleLog.
- *
- *
- *
If the selected {@link Log} implementation class has a
- * setLogFactory() method that accepts a {@link LogFactory}
- * parameter, this method will be called on each newly created instance
- * to identify the associated factory. This makes factory configuration
- * attributes available to the Log instance, if it so desires.
- *
- *
This factory will remember previously created Log instances
- * for the same name, and will return them on repeated requests to the
- * getInstance() method.
- *
- * @author Rod Waldhoff
- * @author Craig R. McClanahan
- * @author Richard A. Sitze
- * @author Brian Stansberry
- * @version $Revision: 581090 $ $Date: 2007-10-02 00:01:06 +0200 (mar., 02 oct. 2007) $
- */
-
-public class LogFactoryImpl extends LogFactory {
-
-
- /** Log4JLogger class name */
- private static final String LOGGING_IMPL_LOG4J_LOGGER = "org.apache.commons.logging.impl.Log4JLogger";
- /** Jdk14Logger class name */
- private static final String LOGGING_IMPL_JDK14_LOGGER = "org.apache.commons.logging.impl.Jdk14Logger";
- /** Jdk13LumberjackLogger class name */
- private static final String LOGGING_IMPL_LUMBERJACK_LOGGER = "org.apache.commons.logging.impl.Jdk13LumberjackLogger";
- /** SimpleLog class name */
- private static final String LOGGING_IMPL_SIMPLE_LOGGER = "org.apache.commons.logging.impl.SimpleLog";
-
- private static final String PKG_IMPL="org.apache.commons.logging.impl.";
- private static final int PKG_LEN = PKG_IMPL.length();
-
- // ----------------------------------------------------------- Constructors
-
-
-
- /**
- * Public no-arguments constructor required by the lookup mechanism.
- */
- public LogFactoryImpl() {
- super();
- initDiagnostics(); // method on this object
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Instance created.");
- }
- }
-
-
- // ----------------------------------------------------- Manifest Constants
-
-
- /**
- * The name (org.apache.commons.logging.Log) of the system
- * property identifying our {@link Log} implementation class.
- */
- public static final String LOG_PROPERTY =
- "org.apache.commons.logging.Log";
-
-
- /**
- * The deprecated system property used for backwards compatibility with
- * old versions of JCL.
- */
- protected static final String LOG_PROPERTY_OLD =
- "org.apache.commons.logging.log";
-
- /**
- * The name (org.apache.commons.logging.Log.allowFlawedContext)
- * of the system property which can be set true/false to
- * determine system behaviour when a bad context-classloader is encountered.
- * When set to false, a LogConfigurationException is thrown if
- * LogFactoryImpl is loaded via a child classloader of the TCCL (this
- * should never happen in sane systems).
- *
- * Default behaviour: true (tolerates bad context classloaders)
- *
- * See also method setAttribute.
- */
- public static final String ALLOW_FLAWED_CONTEXT_PROPERTY =
- "org.apache.commons.logging.Log.allowFlawedContext";
-
- /**
- * The name (org.apache.commons.logging.Log.allowFlawedDiscovery)
- * of the system property which can be set true/false to
- * determine system behaviour when a bad logging adapter class is
- * encountered during logging discovery. When set to false, an
- * exception will be thrown and the app will fail to start. When set
- * to true, discovery will continue (though the user might end up
- * with a different logging implementation than they expected).
- *
- * Default behaviour: true (tolerates bad logging adapters)
- *
- * See also method setAttribute.
- */
- public static final String ALLOW_FLAWED_DISCOVERY_PROPERTY =
- "org.apache.commons.logging.Log.allowFlawedDiscovery";
-
- /**
- * The name (org.apache.commons.logging.Log.allowFlawedHierarchy)
- * of the system property which can be set true/false to
- * determine system behaviour when a logging adapter class is
- * encountered which has bound to the wrong Log class implementation.
- * When set to false, an exception will be thrown and the app will fail
- * to start. When set to true, discovery will continue (though the user
- * might end up with a different logging implementation than they expected).
- *
- * Default behaviour: true (tolerates bad Log class hierarchy)
- *
- * See also method setAttribute.
- */
- public static final String ALLOW_FLAWED_HIERARCHY_PROPERTY =
- "org.apache.commons.logging.Log.allowFlawedHierarchy";
-
-
- /**
- * The names of classes that will be tried (in order) as logging
- * adapters. Each class is expected to implement the Log interface,
- * and to throw NoClassDefFound or ExceptionInInitializerError when
- * loaded if the underlying logging library is not available. Any
- * other error indicates that the underlying logging library is available
- * but broken/unusable for some reason.
- */
- private static final String[] classesToDiscover = {
- LOGGING_IMPL_LOG4J_LOGGER,
- "org.apache.commons.logging.impl.Jdk14Logger",
- "org.apache.commons.logging.impl.Jdk13LumberjackLogger",
- "org.apache.commons.logging.impl.SimpleLog"
- };
-
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * Determines whether logging classes should be loaded using the thread-context
- * classloader, or via the classloader that loaded this LogFactoryImpl class.
- */
- private boolean useTCCL = true;
-
- /**
- * The string prefixed to every message output by the logDiagnostic method.
- */
- private String diagnosticPrefix;
-
-
- /**
- * Configuration attributes.
- */
- protected Hashtable attributes = new Hashtable();
-
-
- /**
- * The {@link org.apache.commons.logging.Log} instances that have
- * already been created, keyed by logger name.
- */
- protected Hashtable instances = new Hashtable();
-
-
- /**
- * Name of the class implementing the Log interface.
- */
- private String logClassName;
-
-
- /**
- * The one-argument constructor of the
- * {@link org.apache.commons.logging.Log}
- * implementation class that will be used to create new instances.
- * This value is initialized by getLogConstructor(),
- * and then returned repeatedly.
- */
- protected Constructor logConstructor = null;
-
-
- /**
- * The signature of the Constructor to be used.
- */
- protected Class logConstructorSignature[] =
- { java.lang.String.class };
-
-
- /**
- * The one-argument setLogFactory method of the selected
- * {@link org.apache.commons.logging.Log} method, if it exists.
- */
- protected Method logMethod = null;
-
-
- /**
- * The signature of the setLogFactory method to be used.
- */
- protected Class logMethodSignature[] =
- { LogFactory.class };
-
- /**
- * See getBaseClassLoader and initConfiguration.
- */
- private boolean allowFlawedContext;
-
- /**
- * See handleFlawedDiscovery and initConfiguration.
- */
- private boolean allowFlawedDiscovery;
-
- /**
- * See handleFlawedHierarchy and initConfiguration.
- */
- private boolean allowFlawedHierarchy;
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Return the configuration attribute with the specified name (if any),
- * or null if there is no such attribute.
- *
- * @param name Name of the attribute to return
- */
- public Object getAttribute(String name) {
-
- return (attributes.get(name));
-
- }
-
-
- /**
- * Return an array containing the names of all currently defined
- * configuration attributes. If there are no such attributes, a zero
- * length array is returned.
- */
- public String[] getAttributeNames() {
-
- Vector names = new Vector();
- Enumeration keys = attributes.keys();
- while (keys.hasMoreElements()) {
- names.addElement((String) keys.nextElement());
- }
- String results[] = new String[names.size()];
- for (int i = 0; i < results.length; i++) {
- results[i] = (String) names.elementAt(i);
- }
- return (results);
-
- }
-
-
- /**
- * Convenience method to derive a name from the specified class and
- * call getInstance(String) with it.
- *
- * @param clazz Class for which a suitable Log name will be derived
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public Log getInstance(Class clazz) throws LogConfigurationException {
-
- return (getInstance(clazz.getName()));
-
- }
-
-
- /**
- *
Construct (if necessary) and return a Log instance,
- * using the factory's current set of configuration attributes.
- *
- *
NOTE - Depending upon the implementation of
- * the LogFactory you are using, the Log
- * instance you are returned may or may not be local to the current
- * application, and may or may not be returned again on a subsequent
- * call with the same name argument.
- *
- * @param name Logical name of the Log instance to be
- * returned (the meaning of this name is only known to the underlying
- * logging implementation that is being wrapped)
- *
- * @exception LogConfigurationException if a suitable Log
- * instance cannot be returned
- */
- public Log getInstance(String name) throws LogConfigurationException {
-
- Log instance = (Log) instances.get(name);
- if (instance == null) {
- instance = newInstance(name);
- instances.put(name, instance);
- }
- return (instance);
-
- }
-
-
- /**
- * Release any internal references to previously created
- * {@link org.apache.commons.logging.Log}
- * instances returned by this factory. This is useful in environments
- * like servlet containers, which implement application reloading by
- * throwing away a ClassLoader. Dangling references to objects in that
- * class loader would prevent garbage collection.
- */
- public void release() {
-
- logDiagnostic("Releasing all known loggers");
- instances.clear();
- }
-
-
- /**
- * Remove any configuration attribute associated with the specified name.
- * If there is no such attribute, no action is taken.
- *
- * @param name Name of the attribute to remove
- */
- public void removeAttribute(String name) {
-
- attributes.remove(name);
-
- }
-
-
- /**
- * Set the configuration attribute with the specified name. Calling
- * this with a null value is equivalent to calling
- * removeAttribute(name).
- *
- * This method can be used to set logging configuration programmatically
- * rather than via system properties. It can also be used in code running
- * within a container (such as a webapp) to configure behaviour on a
- * per-component level instead of globally as system properties would do.
- * To use this method instead of a system property, call
- *
- * LogFactory.getFactory().setAttribute(...)
- *
- * This must be done before the first Log object is created; configuration
- * changes after that point will be ignored.
- *
- * This method is also called automatically if LogFactory detects a
- * commons-logging.properties file; every entry in that file is set
- * automatically as an attribute here.
- *
- * @param name Name of the attribute to set
- * @param value Value of the attribute to set, or null
- * to remove any setting for this attribute
- */
- public void setAttribute(String name, Object value) {
-
- if (logConstructor != null) {
- logDiagnostic("setAttribute: call too late; configuration already performed.");
- }
-
- if (value == null) {
- attributes.remove(name);
- } else {
- attributes.put(name, value);
- }
-
- if (name.equals(TCCL_KEY)) {
- useTCCL = Boolean.valueOf(value.toString()).booleanValue();
- }
-
- }
-
-
- // ------------------------------------------------------
- // Static Methods
- //
- // These methods only defined as workarounds for a java 1.2 bug;
- // theoretically none of these are needed.
- // ------------------------------------------------------
-
- /**
- * Gets the context classloader.
- * This method is a workaround for a java 1.2 compiler bug.
- * @since 1.1
- */
- protected static ClassLoader getContextClassLoader() throws LogConfigurationException {
- return LogFactory.getContextClassLoader();
- }
-
-
- /**
- * Workaround for bug in Java1.2; in theory this method is not needed.
- * See LogFactory.isDiagnosticsEnabled.
- */
- protected static boolean isDiagnosticsEnabled() {
- return LogFactory.isDiagnosticsEnabled();
- }
-
-
- /**
- * Workaround for bug in Java1.2; in theory this method is not needed.
- * See LogFactory.getClassLoader.
- * @since 1.1
- */
- protected static ClassLoader getClassLoader(Class clazz) {
- return LogFactory.getClassLoader(clazz);
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Calculate and cache a string that uniquely identifies this instance,
- * including which classloader the object was loaded from.
- *
- * This string will later be prefixed to each "internal logging" message
- * emitted, so that users can clearly see any unexpected behaviour.
- *
- * Note that this method does not detect whether internal logging is
- * enabled or not, nor where to output stuff if it is; that is all
- * handled by the parent LogFactory class. This method just computes
- * its own unique prefix for log messages.
- */
- private void initDiagnostics() {
- // It would be nice to include an identifier of the context classloader
- // that this LogFactoryImpl object is responsible for. However that
- // isn't possible as that information isn't available. It is possible
- // to figure this out by looking at the logging from LogFactory to
- // see the context & impl ids from when this object was instantiated,
- // in order to link the impl id output as this object's prefix back to
- // the context it is intended to manage.
- // Note that this prefix should be kept consistent with that
- // in LogFactory.
- Class clazz = this.getClass();
- ClassLoader classLoader = getClassLoader(clazz);
- String classLoaderName;
- try {
- if (classLoader == null) {
- classLoaderName = "BOOTLOADER";
- } else {
- classLoaderName = objectId(classLoader);
- }
- } catch(SecurityException e) {
- classLoaderName = "UNKNOWN";
- }
- diagnosticPrefix = "[LogFactoryImpl@" + System.identityHashCode(this) + " from " + classLoaderName + "] ";
- }
-
-
- /**
- * Output a diagnostic message to a user-specified destination (if the
- * user has enabled diagnostic logging).
- *
- * @param msg diagnostic message
- * @since 1.1
- */
- protected void logDiagnostic(String msg) {
- if (isDiagnosticsEnabled()) {
- logRawDiagnostic(diagnosticPrefix + msg);
- }
- }
-
- /**
- * Return the fully qualified Java classname of the {@link Log}
- * implementation we will be using.
- *
- * @deprecated Never invoked by this class; subclasses should not assume
- * it will be.
- */
- protected String getLogClassName() {
-
- if (logClassName == null) {
- discoverLogImplementation(getClass().getName());
- }
-
- return logClassName;
- }
-
-
- /**
- *
Return the Constructor that can be called to instantiate
- * new {@link org.apache.commons.logging.Log} instances.
- *
- *
IMPLEMENTATION NOTE - Race conditions caused by
- * calling this method from more than one thread are ignored, because
- * the same Constructor instance will ultimately be derived
- * in all circumstances.
- *
- * @exception LogConfigurationException if a suitable constructor
- * cannot be returned
- *
- * @deprecated Never invoked by this class; subclasses should not assume
- * it will be.
- */
- protected Constructor getLogConstructor()
- throws LogConfigurationException {
-
- // Return the previously identified Constructor (if any)
- if (logConstructor == null) {
- discoverLogImplementation(getClass().getName());
- }
-
- return logConstructor;
- }
-
-
- /**
- * Is JDK 1.3 with Lumberjack logging available?
- *
- * @deprecated Never invoked by this class; subclasses should not assume
- * it will be.
- */
- protected boolean isJdk13LumberjackAvailable() {
- return isLogLibraryAvailable(
- "Jdk13Lumberjack",
- "org.apache.commons.logging.impl.Jdk13LumberjackLogger");
- }
-
-
- /**
- *
Return true if JDK 1.4 or later logging
- * is available. Also checks that the Throwable class
- * supports getStackTrace(), which is required by
- * Jdk14Logger.
- *
- * @deprecated Never invoked by this class; subclasses should not assume
- * it will be.
- */
- protected boolean isJdk14Available() {
- return isLogLibraryAvailable(
- "Jdk14",
- "org.apache.commons.logging.impl.Jdk14Logger");
- }
-
-
- /**
- * Is a Log4J implementation available?
- *
- * @deprecated Never invoked by this class; subclasses should not assume
- * it will be.
- */
- protected boolean isLog4JAvailable() {
- return isLogLibraryAvailable(
- "Log4J",
- LOGGING_IMPL_LOG4J_LOGGER);
- }
-
-
- /**
- * Create and return a new {@link org.apache.commons.logging.Log}
- * instance for the specified name.
- *
- * @param name Name of the new logger
- *
- * @exception LogConfigurationException if a new instance cannot
- * be created
- */
- protected Log newInstance(String name) throws LogConfigurationException {
-
- Log instance = null;
- try {
- if (logConstructor == null) {
- instance = discoverLogImplementation(name);
- }
- else {
- Object params[] = { name };
- instance = (Log) logConstructor.newInstance(params);
- }
-
- if (logMethod != null) {
- Object params[] = { this };
- logMethod.invoke(instance, params);
- }
-
- return (instance);
-
- } catch (LogConfigurationException lce) {
-
- // this type of exception means there was a problem in discovery
- // and we've already output diagnostics about the issue, etc.;
- // just pass it on
- throw (LogConfigurationException) lce;
-
- } catch (InvocationTargetException e) {
- // A problem occurred invoking the Constructor or Method
- // previously discovered
- Throwable c = e.getTargetException();
- if (c != null) {
- throw new LogConfigurationException(c);
- } else {
- throw new LogConfigurationException(e);
- }
- } catch (Throwable t) {
- // A problem occurred invoking the Constructor or Method
- // previously discovered
- throw new LogConfigurationException(t);
- }
- }
-
-
- // ------------------------------------------------------ Private Methods
-
- /**
- * Calls LogFactory.directGetContextClassLoader under the control of an
- * AccessController class. This means that java code running under a
- * security manager that forbids access to ClassLoaders will still work
- * if this class is given appropriate privileges, even when the caller
- * doesn't have such privileges. Without using an AccessController, the
- * the entire call stack must have the privilege before the call is
- * allowed.
- *
- * @return the context classloader associated with the current thread,
- * or null if security doesn't allow it.
- *
- * @throws LogConfigurationException if there was some weird error while
- * attempting to get the context classloader.
- *
- * @throws SecurityException if the current java security policy doesn't
- * allow this class to access the context classloader.
- */
- private static ClassLoader getContextClassLoaderInternal()
- throws LogConfigurationException {
- return (ClassLoader)AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return LogFactory.directGetContextClassLoader();
- }
- });
- }
-
- /**
- * Read the specified system property, using an AccessController so that
- * the property can be read if JCL has been granted the appropriate
- * security rights even if the calling code has not.
- *
- * Take care not to expose the value returned by this method to the
- * calling application in any way; otherwise the calling app can use that
- * info to access data that should not be available to it.
- */
- private static String getSystemProperty(final String key, final String def)
- throws SecurityException {
- return (String) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return System.getProperty(key, def);
- }
- });
- }
-
- /**
- * Fetch the parent classloader of a specified classloader.
- *
- * If a SecurityException occurs, null is returned.
- *
- * Note that this method is non-static merely so logDiagnostic is available.
- */
- private ClassLoader getParentClassLoader(final ClassLoader cl) {
- try {
- return (ClassLoader)AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return cl.getParent();
- }
- });
- } catch(SecurityException ex) {
- logDiagnostic("[SECURITY] Unable to obtain parent classloader");
- return null;
- }
-
- }
-
- /**
- * Utility method to check whether a particular logging library is
- * present and available for use. Note that this does not
- * affect the future behaviour of this class.
- */
- private boolean isLogLibraryAvailable(String name, String classname) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Checking for '" + name + "'.");
- }
- try {
- Log log = createLogFromClass(
- classname,
- this.getClass().getName(), // dummy category
- false);
-
- if (log == null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Did not find '" + name + "'.");
- }
- return false;
- } else {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Found '" + name + "'.");
- }
- return true;
- }
- } catch(LogConfigurationException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Logging system '" + name + "' is available but not useable.");
- }
- return false;
- }
- }
-
- /**
- * Attempt to find an attribute (see method setAttribute) or a
- * system property with the provided name and return its value.
- *
- * The attributes associated with this object are checked before
- * system properties in case someone has explicitly called setAttribute,
- * or a configuration property has been set in a commons-logging.properties
- * file.
- *
- * @return the value associated with the property, or null.
- */
- private String getConfigurationValue(String property) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] Trying to get configuration for item " + property);
- }
-
- Object valueObj = getAttribute(property);
- if (valueObj != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property);
- }
- return valueObj.toString();
- }
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] No LogFactory attribute found for " + property);
- }
-
- try {
- // warning: minor security hole here, in that we potentially read a system
- // property that the caller cannot, then output it in readable form as a
- // diagnostic message. However it's only ever JCL-specific properties
- // involved here, so the harm is truly trivial.
- String value = getSystemProperty(property, null);
- if (value != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] Found system property [" + value + "] for " + property);
- }
- return value;
- }
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] No system property found for property " + property);
- }
- } catch (SecurityException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] Security prevented reading system property " + property);
- }
- }
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("[ENV] No configuration defined for item " + property);
- }
-
- return null;
- }
-
- /**
- * Get the setting for the user-configurable behaviour specified by key.
- * If nothing has explicitly been set, then return dflt.
- */
- private boolean getBooleanConfiguration(String key, boolean dflt) {
- String val = getConfigurationValue(key);
- if (val == null)
- return dflt;
- return Boolean.valueOf(val).booleanValue();
- }
-
- /**
- * Initialize a number of variables that control the behaviour of this
- * class and that can be tweaked by the user. This is done when the first
- * logger is created, not in the constructor of this class, because we
- * need to give the user a chance to call method setAttribute in order to
- * configure this object.
- */
- private void initConfiguration() {
- allowFlawedContext = getBooleanConfiguration(ALLOW_FLAWED_CONTEXT_PROPERTY, true);
- allowFlawedDiscovery = getBooleanConfiguration(ALLOW_FLAWED_DISCOVERY_PROPERTY, true);
- allowFlawedHierarchy = getBooleanConfiguration(ALLOW_FLAWED_HIERARCHY_PROPERTY, true);
- }
-
-
- /**
- * Attempts to create a Log instance for the given category name.
- * Follows the discovery process described in the class javadoc.
- *
- * @param logCategory the name of the log category
- *
- * @throws LogConfigurationException if an error in discovery occurs,
- * or if no adapter at all can be instantiated
- */
- private Log discoverLogImplementation(String logCategory)
- throws LogConfigurationException
- {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Discovering a Log implementation...");
- }
-
- initConfiguration();
-
- Log result = null;
-
- // See if the user specified the Log implementation to use
- String specifiedLogClassName = findUserSpecifiedLogClassName();
-
- if (specifiedLogClassName != null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Attempting to load user-specified log class '" +
- specifiedLogClassName + "'...");
- }
-
- result = createLogFromClass(specifiedLogClassName,
- logCategory,
- true);
- if (result == null) {
- StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
- messageBuffer.append(specifiedLogClassName);
- messageBuffer.append("' cannot be found or is not useable.");
-
- // Mistyping or misspelling names is a common fault.
- // Construct a good error message, if we can
- if (specifiedLogClassName != null) {
- informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_LOG4J_LOGGER);
- informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_JDK14_LOGGER);
- informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_LUMBERJACK_LOGGER);
- informUponSimilarName(messageBuffer, specifiedLogClassName, LOGGING_IMPL_SIMPLE_LOGGER);
- }
- throw new LogConfigurationException(messageBuffer.toString());
- }
-
- return result;
- }
-
- // No user specified log; try to discover what's on the classpath
- //
- // Note that we deliberately loop here over classesToDiscover and
- // expect method createLogFromClass to loop over the possible source
- // classloaders. The effect is:
- // for each discoverable log adapter
- // for each possible classloader
- // see if it works
- //
- // It appears reasonable at first glance to do the opposite:
- // for each possible classloader
- // for each discoverable log adapter
- // see if it works
- //
- // The latter certainly has advantages for user-installable logging
- // libraries such as log4j; in a webapp for example this code should
- // first check whether the user has provided any of the possible
- // logging libraries before looking in the parent classloader.
- // Unfortunately, however, Jdk14Logger will always work in jvm>=1.4,
- // and SimpleLog will always work in any JVM. So the loop would never
- // ever look for logging libraries in the parent classpath. Yet many
- // users would expect that putting log4j there would cause it to be
- // detected (and this is the historical JCL behaviour). So we go with
- // the first approach. A user that has bundled a specific logging lib
- // in a webapp should use a commons-logging.properties file or a
- // service file in META-INF to force use of that logging lib anyway,
- // rather than relying on discovery.
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "No user-specified Log implementation; performing discovery" +
- " using the standard supported logging implementations...");
- }
- for(int i=0; (iStringBuffer the message should be appended to,
- * not null
- * @param name the (trimmed) name to be test against the candidate, not null
- * @param candidate the candidate name (not null)
- */
- private void informUponSimilarName(final StringBuffer messageBuffer, final String name,
- final String candidate) {
- if (name.equals(candidate)) {
- // Don't suggest a name that is exactly the same as the one the
- // user tried...
- return;
- }
-
- // If the user provides a name that is in the right package, and gets
- // the first 5 characters of the adapter class right (ignoring case),
- // then suggest the candidate adapter class name.
- if (name.regionMatches(true, 0, candidate, 0, PKG_LEN + 5)) {
- messageBuffer.append(" Did you mean '");
- messageBuffer.append(candidate);
- messageBuffer.append("'?");
- }
- }
-
-
- /**
- * Checks system properties and the attribute map for
- * a Log implementation specified by the user under the
- * property names {@link #LOG_PROPERTY} or {@link #LOG_PROPERTY_OLD}.
- *
- * @return classname specified by the user, or null
- */
- private String findUserSpecifiedLogClassName()
- {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY + "'");
- }
- String specifiedClass = (String) getAttribute(LOG_PROPERTY);
-
- if (specifiedClass == null) { // @deprecated
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Trying to get log class from attribute '" +
- LOG_PROPERTY_OLD + "'");
- }
- specifiedClass = (String) getAttribute(LOG_PROPERTY_OLD);
- }
-
- if (specifiedClass == null) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Trying to get log class from system property '" +
- LOG_PROPERTY + "'");
- }
- try {
- specifiedClass = getSystemProperty(LOG_PROPERTY, null);
- } catch (SecurityException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("No access allowed to system property '" +
- LOG_PROPERTY + "' - " + e.getMessage());
- }
- }
- }
-
- if (specifiedClass == null) { // @deprecated
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Trying to get log class from system property '" +
- LOG_PROPERTY_OLD + "'");
- }
- try {
- specifiedClass = getSystemProperty(LOG_PROPERTY_OLD, null);
- } catch (SecurityException e) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic("No access allowed to system property '" +
- LOG_PROPERTY_OLD + "' - " + e.getMessage());
- }
- }
- }
-
- // Remove any whitespace; it's never valid in a classname so its
- // presence just means a user mistake. As we know what they meant,
- // we may as well strip the spaces.
- if (specifiedClass != null) {
- specifiedClass = specifiedClass.trim();
- }
-
- return specifiedClass;
- }
-
-
- /**
- * Attempts to load the given class, find a suitable constructor,
- * and instantiate an instance of Log.
- *
- * @param logAdapterClassName classname of the Log implementation
- *
- * @param logCategory argument to pass to the Log implementation's
- * constructor
- *
- * @param affectState true if this object's state should
- * be affected by this method call, false otherwise.
- *
- * @return an instance of the given class, or null if the logging
- * library associated with the specified adapter is not available.
- *
- * @throws LogConfigurationException if there was a serious error with
- * configuration and the handleFlawedDiscovery method decided this
- * problem was fatal.
- */
- private Log createLogFromClass(String logAdapterClassName,
- String logCategory,
- boolean affectState)
- throws LogConfigurationException {
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'");
- }
-
- Object[] params = { logCategory };
- Log logAdapter = null;
- Constructor constructor = null;
-
- Class logAdapterClass = null;
- ClassLoader currentCL = getBaseClassLoader();
-
- for(;;) {
- // Loop through the classloader hierarchy trying to find
- // a viable classloader.
- logDiagnostic(
- "Trying to load '"
- + logAdapterClassName
- + "' from classloader "
- + objectId(currentCL));
- try {
- if (isDiagnosticsEnabled()) {
- // Show the location of the first occurrence of the .class file
- // in the classpath. This is the location that ClassLoader.loadClass
- // will load the class from -- unless the classloader is doing
- // something weird.
- URL url;
- String resourceName = logAdapterClassName.replace('.', '/') + ".class";
- if (currentCL != null) {
- url = currentCL.getResource(resourceName );
- } else {
- url = ClassLoader.getSystemResource(resourceName + ".class");
- }
-
- if (url == null) {
- logDiagnostic("Class '" + logAdapterClassName + "' [" + resourceName + "] cannot be found.");
- } else {
- logDiagnostic("Class '" + logAdapterClassName + "' was found at '" + url + "'");
- }
- }
-
- Class c = null;
- try {
- c = Class.forName(logAdapterClassName, true, currentCL);
- } catch (ClassNotFoundException originalClassNotFoundException) {
- // The current classloader was unable to find the log adapter
- // in this or any ancestor classloader. There's no point in
- // trying higher up in the hierarchy in this case..
- String msg = "" + originalClassNotFoundException.getMessage();
- logDiagnostic(
- "The log adapter '"
- + logAdapterClassName
- + "' is not available via classloader "
- + objectId(currentCL)
- + ": "
- + msg.trim());
- try {
- // Try the class classloader.
- // This may work in cases where the TCCL
- // does not contain the code executed or JCL.
- // This behaviour indicates that the application
- // classloading strategy is not consistent with the
- // Java 1.2 classloading guidelines but JCL can
- // and so should handle this case.
- c = Class.forName(logAdapterClassName);
- } catch (ClassNotFoundException secondaryClassNotFoundException) {
- // no point continuing: this adapter isn't available
- msg = "" + secondaryClassNotFoundException.getMessage();
- logDiagnostic(
- "The log adapter '"
- + logAdapterClassName
- + "' is not available via the LogFactoryImpl class classloader: "
- + msg.trim());
- break;
- }
- }
-
- constructor = c.getConstructor(logConstructorSignature);
- Object o = constructor.newInstance(params);
-
- // Note that we do this test after trying to create an instance
- // [rather than testing Log.class.isAssignableFrom(c)] so that
- // we don't complain about Log hierarchy problems when the
- // adapter couldn't be instantiated anyway.
- if (o instanceof Log) {
- logAdapterClass = c;
- logAdapter = (Log) o;
- break;
- }
-
- // Oops, we have a potential problem here. An adapter class
- // has been found and its underlying lib is present too, but
- // there are multiple Log interface classes available making it
- // impossible to cast to the type the caller wanted. We
- // certainly can't use this logger, but we need to know whether
- // to keep on discovering or terminate now.
- //
- // The handleFlawedHierarchy method will throw
- // LogConfigurationException if it regards this problem as
- // fatal, and just return if not.
- handleFlawedHierarchy(currentCL, c);
- } catch (NoClassDefFoundError e) {
- // We were able to load the adapter but it had references to
- // other classes that could not be found. This simply means that
- // the underlying logger library is not present in this or any
- // ancestor classloader. There's no point in trying higher up
- // in the hierarchy in this case..
- String msg = "" + e.getMessage();
- logDiagnostic(
- "The log adapter '"
- + logAdapterClassName
- + "' is missing dependencies when loaded via classloader "
- + objectId(currentCL)
- + ": "
- + msg.trim());
- break;
- } catch (ExceptionInInitializerError e) {
- // A static initializer block or the initializer code associated
- // with a static variable on the log adapter class has thrown
- // an exception.
- //
- // We treat this as meaning the adapter's underlying logging
- // library could not be found.
- String msg = "" + e.getMessage();
- logDiagnostic(
- "The log adapter '"
- + logAdapterClassName
- + "' is unable to initialize itself when loaded via classloader "
- + objectId(currentCL)
- + ": "
- + msg.trim());
- break;
- } catch(LogConfigurationException e) {
- // call to handleFlawedHierarchy above must have thrown
- // a LogConfigurationException, so just throw it on
- throw e;
- } catch(Throwable t) {
- // handleFlawedDiscovery will determine whether this is a fatal
- // problem or not. If it is fatal, then a LogConfigurationException
- // will be thrown.
- handleFlawedDiscovery(logAdapterClassName, currentCL, t);
- }
-
- if (currentCL == null) {
- break;
- }
-
- // try the parent classloader
- // currentCL = currentCL.getParent();
- currentCL = getParentClassLoader(currentCL);
- }
-
- if ((logAdapter != null) && affectState) {
- // We've succeeded, so set instance fields
- this.logClassName = logAdapterClassName;
- this.logConstructor = constructor;
-
- // Identify the setLogFactory method (if there is one)
- try {
- this.logMethod = logAdapterClass.getMethod("setLogFactory",
- logMethodSignature);
- logDiagnostic("Found method setLogFactory(LogFactory) in '"
- + logAdapterClassName + "'");
- } catch (Throwable t) {
- this.logMethod = null;
- logDiagnostic(
- "[INFO] '" + logAdapterClassName
- + "' from classloader " + objectId(currentCL)
- + " does not declare optional method "
- + "setLogFactory(LogFactory)");
- }
-
- logDiagnostic(
- "Log adapter '" + logAdapterClassName
- + "' from classloader " + objectId(logAdapterClass.getClassLoader())
- + " has been selected for use.");
- }
-
- return logAdapter;
- }
-
-
- /**
- * Return the classloader from which we should try to load the logging
- * adapter classes.
- *
- * This method usually returns the context classloader. However if it
- * is discovered that the classloader which loaded this class is a child
- * of the context classloader and the allowFlawedContext option
- * has been set then the classloader which loaded this class is returned
- * instead.
- *
- * The only time when the classloader which loaded this class is a
- * descendant (rather than the same as or an ancestor of the context
- * classloader) is when an app has created custom classloaders but
- * failed to correctly set the context classloader. This is a bug in
- * the calling application; however we provide the option for JCL to
- * simply generate a warning rather than fail outright.
- *
- */
- private ClassLoader getBaseClassLoader() throws LogConfigurationException {
- ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class);
-
- if (useTCCL == false) {
- return thisClassLoader;
- }
-
- ClassLoader contextClassLoader = getContextClassLoaderInternal();
-
- ClassLoader baseClassLoader = getLowestClassLoader(
- contextClassLoader, thisClassLoader);
-
- if (baseClassLoader == null) {
- // The two classloaders are not part of a parent child relationship.
- // In some classloading setups (e.g. JBoss with its
- // UnifiedLoaderRepository) this can still work, so if user hasn't
- // forbidden it, just return the contextClassLoader.
- if (allowFlawedContext) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "[WARNING] the context classloader is not part of a"
- + " parent-child relationship with the classloader that"
- + " loaded LogFactoryImpl.");
- }
- // If contextClassLoader were null, getLowestClassLoader() would
- // have returned thisClassLoader. The fact we are here means
- // contextClassLoader is not null, so we can just return it.
- return contextClassLoader;
- }
- else {
- throw new LogConfigurationException(
- "Bad classloader hierarchy; LogFactoryImpl was loaded via"
- + " a classloader that is not related to the current context"
- + " classloader.");
- }
- }
-
- if (baseClassLoader != contextClassLoader) {
- // We really should just use the contextClassLoader as the starting
- // point for scanning for log adapter classes. However it is expected
- // that there are a number of broken systems out there which create
- // custom classloaders but fail to set the context classloader so
- // we handle those flawed systems anyway.
- if (allowFlawedContext) {
- if (isDiagnosticsEnabled()) {
- logDiagnostic(
- "Warning: the context classloader is an ancestor of the"
- + " classloader that loaded LogFactoryImpl; it should be"
- + " the same or a descendant. The application using"
- + " commons-logging should ensure the context classloader"
- + " is used correctly.");
- }
- } else {
- throw new LogConfigurationException(
- "Bad classloader hierarchy; LogFactoryImpl was loaded via"
- + " a classloader that is not related to the current context"
- + " classloader.");
- }
- }
-
- return baseClassLoader;
- }
-
- /**
- * Given two related classloaders, return the one which is a child of
- * the other.
- *
- * @param c1 is a classloader (including the null classloader)
- * @param c2 is a classloader (including the null classloader)
- *
- * @return c1 if it has c2 as an ancestor, c2 if it has c1 as an ancestor,
- * and null if neither is an ancestor of the other.
- */
- private ClassLoader getLowestClassLoader(ClassLoader c1, ClassLoader c2) {
- // TODO: use AccessController when dealing with classloaders here
-
- if (c1 == null)
- return c2;
-
- if (c2 == null)
- return c1;
-
- ClassLoader current;
-
- // scan c1's ancestors to find c2
- current = c1;
- while (current != null) {
- if (current == c2)
- return c1;
- current = current.getParent();
- }
-
- // scan c2's ancestors to find c1
- current = c2;
- while (current != null) {
- if (current == c1)
- return c2;
- current = current.getParent();
- }
-
- return null;
- }
-
- /**
- * Generates an internal diagnostic logging of the discovery failure and
- * then throws a LogConfigurationException that wraps
- * the passed Throwable.
- *
- * @param logAdapterClassName is the class name of the Log implementation
- * that could not be instantiated. Cannot be null.
- *
- * @param classLoader is the classloader that we were trying to load the
- * logAdapterClassName from when the exception occurred.
- *
- * @param discoveryFlaw is the Throwable created by the classloader
- *
- * @throws LogConfigurationException ALWAYS
- */
- private void handleFlawedDiscovery(String logAdapterClassName,
- ClassLoader classLoader,
- Throwable discoveryFlaw) {
-
- if (isDiagnosticsEnabled()) {
- logDiagnostic("Could not instantiate Log '"
- + logAdapterClassName + "' -- "
- + discoveryFlaw.getClass().getName() + ": "
- + discoveryFlaw.getLocalizedMessage());
-
- if (discoveryFlaw instanceof InvocationTargetException ) {
- // Ok, the lib is there but while trying to create a real underlying
- // logger something failed in the underlying lib; display info about
- // that if possible.
- InvocationTargetException ite = (InvocationTargetException)discoveryFlaw;
- Throwable cause = ite.getTargetException();
- if (cause != null) {
- logDiagnostic("... InvocationTargetException: " +
- cause.getClass().getName() + ": " +
- cause.getLocalizedMessage());
-
- if (cause instanceof ExceptionInInitializerError) {
- ExceptionInInitializerError eiie = (ExceptionInInitializerError)cause;
- Throwable cause2 = eiie.getException();
- if (cause2 != null) {
- logDiagnostic("... ExceptionInInitializerError: " +
- cause2.getClass().getName() + ": " +
- cause2.getLocalizedMessage());
- }
- }
- }
- }
- }
-
- if (!allowFlawedDiscovery) {
- throw new LogConfigurationException(discoveryFlaw);
- }
- }
-
-
- /**
- * Report a problem loading the log adapter, then either return
- * (if the situation is considered recoverable) or throw a
- * LogConfigurationException.
- *
- * There are two possible reasons why we successfully loaded the
- * specified log adapter class then failed to cast it to a Log object:
- *
- *
the specific class just doesn't implement the Log interface
- * (user screwed up), or
- *
the specified class has bound to a Log class loaded by some other
- * classloader; Log@classloaderX cannot be cast to Log@classloaderY.
- *
- *
- * Here we try to figure out which case has occurred so we can give the
- * user some reasonable feedback.
- *
- * @param badClassLoader is the classloader we loaded the problem class from,
- * ie it is equivalent to badClass.getClassLoader().
- *
- * @param badClass is a Class object with the desired name, but which
- * does not implement Log correctly.
- *
- * @throws LogConfigurationException when the situation
- * should not be recovered from.
- */
- private void handleFlawedHierarchy(ClassLoader badClassLoader, Class badClass)
- throws LogConfigurationException {
-
- boolean implementsLog = false;
- String logInterfaceName = Log.class.getName();
- Class interfaces[] = badClass.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if (logInterfaceName.equals(interfaces[i].getName())) {
- implementsLog = true;
- break;
- }
- }
-
- if (implementsLog) {
- // the class does implement an interface called Log, but
- // it is in the wrong classloader
- if (isDiagnosticsEnabled()) {
- try {
- ClassLoader logInterfaceClassLoader = getClassLoader(Log.class);
- logDiagnostic(
- "Class '" + badClass.getName()
- + "' was found in classloader "
- + objectId(badClassLoader)
- + ". It is bound to a Log interface which is not"
- + " the one loaded from classloader "
- + objectId(logInterfaceClassLoader));
- } catch (Throwable t) {
- logDiagnostic(
- "Error while trying to output diagnostics about"
- + " bad class '" + badClass + "'");
- }
- }
-
- if (!allowFlawedHierarchy) {
- StringBuffer msg = new StringBuffer();
- msg.append("Terminating logging for this context ");
- msg.append("due to bad log hierarchy. ");
- msg.append("You have more than one version of '");
- msg.append(Log.class.getName());
- msg.append("' visible.");
- if (isDiagnosticsEnabled()) {
- logDiagnostic(msg.toString());
- }
- throw new LogConfigurationException(msg.toString());
- }
-
- if (isDiagnosticsEnabled()) {
- StringBuffer msg = new StringBuffer();
- msg.append("Warning: bad log hierarchy. ");
- msg.append("You have more than one version of '");
- msg.append(Log.class.getName());
- msg.append("' visible.");
- logDiagnostic(msg.toString());
- }
- } else {
- // this is just a bad adapter class
- if (!allowFlawedDiscovery) {
- StringBuffer msg = new StringBuffer();
- msg.append("Terminating logging for this context. ");
- msg.append("Log class '");
- msg.append(badClass.getName());
- msg.append("' does not implement the Log interface.");
- if (isDiagnosticsEnabled()) {
- logDiagnostic(msg.toString());
- }
-
- throw new LogConfigurationException(msg.toString());
- }
-
- if (isDiagnosticsEnabled()) {
- StringBuffer msg = new StringBuffer();
- msg.append("[WARNING] Log class '");
- msg.append(badClass.getName());
- msg.append("' does not implement the Log interface.");
- logDiagnostic(msg.toString());
- }
- }
- }
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/NoOpLog.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/NoOpLog.java
deleted file mode 100644
index a66bd1037..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/NoOpLog.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-
-import java.io.Serializable;
-import org.apache.commons.logging.Log;
-
-
-/**
- *
Trivial implementation of Log that throws away all messages. No
- * configurable system properties are supported.
- *
- * @author Scott Sanders
- * @author Rod Waldhoff
- * @version $Id: NoOpLog.java 424107 2006-07-20 23:15:42Z skitching $
- */
-public class NoOpLog implements Log, Serializable {
-
- /** Convenience constructor */
- public NoOpLog() { }
- /** Base constructor */
- public NoOpLog(String name) { }
- /** Do nothing */
- public void trace(Object message) { }
- /** Do nothing */
- public void trace(Object message, Throwable t) { }
- /** Do nothing */
- public void debug(Object message) { }
- /** Do nothing */
- public void debug(Object message, Throwable t) { }
- /** Do nothing */
- public void info(Object message) { }
- /** Do nothing */
- public void info(Object message, Throwable t) { }
- /** Do nothing */
- public void warn(Object message) { }
- /** Do nothing */
- public void warn(Object message, Throwable t) { }
- /** Do nothing */
- public void error(Object message) { }
- /** Do nothing */
- public void error(Object message, Throwable t) { }
- /** Do nothing */
- public void fatal(Object message) { }
- /** Do nothing */
- public void fatal(Object message, Throwable t) { }
-
- /**
- * Debug is never enabled.
- *
- * @return false
- */
- public final boolean isDebugEnabled() { return false; }
-
- /**
- * Error is never enabled.
- *
- * @return false
- */
- public final boolean isErrorEnabled() { return false; }
-
- /**
- * Fatal is never enabled.
- *
- * @return false
- */
- public final boolean isFatalEnabled() { return false; }
-
- /**
- * Info is never enabled.
- *
- * @return false
- */
- public final boolean isInfoEnabled() { return false; }
-
- /**
- * Trace is never enabled.
- *
- * @return false
- */
- public final boolean isTraceEnabled() { return false; }
-
- /**
- * Warn is never enabled.
- *
- * @return false
- */
- public final boolean isWarnEnabled() { return false; }
-
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/SimpleLog.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/SimpleLog.java
deleted file mode 100644
index fe1a7c59d..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/SimpleLog.java
+++ /dev/null
@@ -1,721 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-import java.io.InputStream;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogConfigurationException;
-
-/**
- *
Simple implementation of Log that sends all enabled log messages,
- * for all defined loggers, to System.err. The following system properties
- * are supported to configure the behavior of this logger:
- *
- *
org.apache.commons.logging.simplelog.defaultlog -
- * Default logging detail level for all instances of SimpleLog.
- * Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
- * If not specified, defaults to "info".
- *
org.apache.commons.logging.simplelog.log.xxxxx -
- * Logging detail level for a SimpleLog instance named "xxxxx".
- * Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
- * If not specified, the default logging detail level is used.
- *
org.apache.commons.logging.simplelog.showlogname -
- * Set to true if you want the Log instance name to be
- * included in output messages. Defaults to false.
- *
org.apache.commons.logging.simplelog.showShortLogname -
- * Set to true if you want the last component of the name to be
- * included in output messages. Defaults to true.
- *
org.apache.commons.logging.simplelog.showdatetime -
- * Set to true if you want the current date and time
- * to be included in output messages. Default is false.
- *
org.apache.commons.logging.simplelog.dateTimeFormat -
- * The date and time format to be used in the output messages.
- * The pattern describing the date and time format is the same that is
- * used in java.text.SimpleDateFormat. If the format is not
- * specified or is invalid, the default format is used.
- * The default format is yyyy/MM/dd HH:mm:ss:SSS zzz.
- *
- *
- *
In addition to looking for system properties with the names specified
- * above, this implementation also checks for a class loader resource named
- * "simplelog.properties", and includes any matching definitions
- * from this resource (if it exists).
- *
- * @author Scott Sanders
- * @author Rod Waldhoff
- * @author Robert Burrell Donkin
- *
- * @version $Id: SimpleLog.java 581090 2007-10-01 22:01:06Z dennisl $
- */
-public class SimpleLog implements Log, Serializable {
-
-
- // ------------------------------------------------------- Class Attributes
-
- /** All system properties used by SimpleLog start with this */
- static protected final String systemPrefix =
- "org.apache.commons.logging.simplelog.";
-
- /** Properties loaded from simplelog.properties */
- static protected final Properties simpleLogProps = new Properties();
-
- /** The default format to use when formating dates */
- static protected final String DEFAULT_DATE_TIME_FORMAT =
- "yyyy/MM/dd HH:mm:ss:SSS zzz";
-
- /** Include the instance name in the log message? */
- static protected boolean showLogName = false;
- /** Include the short name ( last component ) of the logger in the log
- * message. Defaults to true - otherwise we'll be lost in a flood of
- * messages without knowing who sends them.
- */
- static protected boolean showShortName = true;
- /** Include the current time in the log message */
- static protected boolean showDateTime = false;
- /** The date and time format to use in the log message */
- static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
-
- /**
- * Used to format times.
- *
- * Any code that accesses this object should first obtain a lock on it,
- * ie use synchronized(dateFormatter); this requirement was introduced
- * in 1.1.1 to fix an existing thread safety bug (SimpleDateFormat.format
- * is not thread-safe).
- */
- static protected DateFormat dateFormatter = null;
-
- // ---------------------------------------------------- Log Level Constants
-
-
- /** "Trace" level logging. */
- public static final int LOG_LEVEL_TRACE = 1;
- /** "Debug" level logging. */
- public static final int LOG_LEVEL_DEBUG = 2;
- /** "Info" level logging. */
- public static final int LOG_LEVEL_INFO = 3;
- /** "Warn" level logging. */
- public static final int LOG_LEVEL_WARN = 4;
- /** "Error" level logging. */
- public static final int LOG_LEVEL_ERROR = 5;
- /** "Fatal" level logging. */
- public static final int LOG_LEVEL_FATAL = 6;
-
- /** Enable all logging levels */
- public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1);
-
- /** Enable no logging levels */
- public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1);
-
- // ------------------------------------------------------------ Initializer
-
- private static String getStringProperty(String name) {
- String prop = null;
- try {
- prop = System.getProperty(name);
- } catch (SecurityException e) {
- ; // Ignore
- }
- return (prop == null) ? simpleLogProps.getProperty(name) : prop;
- }
-
- private static String getStringProperty(String name, String dephault) {
- String prop = getStringProperty(name);
- return (prop == null) ? dephault : prop;
- }
-
- private static boolean getBooleanProperty(String name, boolean dephault) {
- String prop = getStringProperty(name);
- return (prop == null) ? dephault : "true".equalsIgnoreCase(prop);
- }
-
- // Initialize class attributes.
- // Load properties file, if found.
- // Override with system properties.
- static {
- // Add props from the resource simplelog.properties
- InputStream in = getResourceAsStream("simplelog.properties");
- if(null != in) {
- try {
- simpleLogProps.load(in);
- in.close();
- } catch(java.io.IOException e) {
- // ignored
- }
- }
-
- showLogName = getBooleanProperty( systemPrefix + "showlogname", showLogName);
- showShortName = getBooleanProperty( systemPrefix + "showShortLogname", showShortName);
- showDateTime = getBooleanProperty( systemPrefix + "showdatetime", showDateTime);
-
- if(showDateTime) {
- dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat",
- dateTimeFormat);
- try {
- dateFormatter = new SimpleDateFormat(dateTimeFormat);
- } catch(IllegalArgumentException e) {
- // If the format pattern is invalid - use the default format
- dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
- dateFormatter = new SimpleDateFormat(dateTimeFormat);
- }
- }
- }
-
- // ------------------------------------------------------------- Attributes
-
- /** The name of this simple log instance */
- protected String logName = null;
- /** The current log level */
- protected int currentLogLevel;
- /** The short name of this simple log instance */
- private String shortLogName = null;
-
-
- // ------------------------------------------------------------ Constructor
-
- /**
- * Construct a simple log with given name.
- *
- * @param name log name
- */
- public SimpleLog(String name) {
-
- logName = name;
-
- // Set initial log level
- // Used to be: set default log level to ERROR
- // IMHO it should be lower, but at least info ( costin ).
- setLevel(SimpleLog.LOG_LEVEL_INFO);
-
- // Set log level from properties
- String lvl = getStringProperty(systemPrefix + "log." + logName);
- int i = String.valueOf(name).lastIndexOf(".");
- while(null == lvl && i > -1) {
- name = name.substring(0,i);
- lvl = getStringProperty(systemPrefix + "log." + name);
- i = String.valueOf(name).lastIndexOf(".");
- }
-
- if(null == lvl) {
- lvl = getStringProperty(systemPrefix + "defaultlog");
- }
-
- if("all".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_ALL);
- } else if("trace".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_TRACE);
- } else if("debug".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_DEBUG);
- } else if("info".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_INFO);
- } else if("warn".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_WARN);
- } else if("error".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_ERROR);
- } else if("fatal".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_FATAL);
- } else if("off".equalsIgnoreCase(lvl)) {
- setLevel(SimpleLog.LOG_LEVEL_OFF);
- }
-
- }
-
-
- // -------------------------------------------------------- Properties
-
- /**
- *
Do the actual logging.
- * This method assembles the message
- * and then calls write() to cause it to be written.
- *
- * @param type One of the LOG_LEVEL_XXX constants defining the log level
- * @param message The message itself (typically a String)
- * @param t The exception whose stack trace should be logged
- */
- protected void log(int type, Object message, Throwable t) {
- // Use a string buffer for better performance
- StringBuffer buf = new StringBuffer();
-
- // Append date-time if so configured
- if(showDateTime) {
- Date now = new Date();
- String dateText;
- synchronized(dateFormatter) {
- dateText = dateFormatter.format(now);
- }
- buf.append(dateText);
- buf.append(" ");
- }
-
- // Append a readable representation of the log level
- switch(type) {
- case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
- case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
- case SimpleLog.LOG_LEVEL_INFO: buf.append("[INFO] "); break;
- case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break;
- case SimpleLog.LOG_LEVEL_ERROR: buf.append("[ERROR] "); break;
- case SimpleLog.LOG_LEVEL_FATAL: buf.append("[FATAL] "); break;
- }
-
- // Append the name of the log instance if so configured
- if( showShortName) {
- if( shortLogName==null ) {
- // Cut all but the last component of the name for both styles
- shortLogName = logName.substring(logName.lastIndexOf(".") + 1);
- shortLogName =
- shortLogName.substring(shortLogName.lastIndexOf("/") + 1);
- }
- buf.append(String.valueOf(shortLogName)).append(" - ");
- } else if(showLogName) {
- buf.append(String.valueOf(logName)).append(" - ");
- }
-
- // Append the message
- buf.append(String.valueOf(message));
-
- // Append stack trace if not null
- if(t != null) {
- buf.append(" <");
- buf.append(t.toString());
- buf.append(">");
-
- java.io.StringWriter sw= new java.io.StringWriter(1024);
- java.io.PrintWriter pw= new java.io.PrintWriter(sw);
- t.printStackTrace(pw);
- pw.close();
- buf.append(sw.toString());
- }
-
- // Print to the appropriate destination
- write(buf);
-
- }
-
-
- /**
- *
Write the content of the message accumulated in the specified
- * StringBuffer to the appropriate output destination. The
- * default implementation writes to System.err.
- *
- * @param buffer A StringBuffer containing the accumulated
- * text to be logged
- */
- protected void write(StringBuffer buffer) {
-
- System.err.println(buffer.toString());
-
- }
-
-
- /**
- * Is the given log level currently enabled?
- *
- * @param logLevel is this level enabled?
- */
- protected boolean isLevelEnabled(int logLevel) {
- // log level are numerically ordered so can use simple numeric
- // comparison
- return (logLevel >= currentLogLevel);
- }
-
-
- // -------------------------------------------------------- Log Implementation
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#debug(Object)
- */
- public final void debug(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
- log(SimpleLog.LOG_LEVEL_DEBUG, message, null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#debug(Object, Throwable)
- */
- public final void debug(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
- log(SimpleLog.LOG_LEVEL_DEBUG, message, t);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#trace(Object)
- */
- public final void trace(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
- log(SimpleLog.LOG_LEVEL_TRACE, message, null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#trace(Object, Throwable)
- */
- public final void trace(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
- log(SimpleLog.LOG_LEVEL_TRACE, message, t);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#info(Object)
- */
- public final void info(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
- log(SimpleLog.LOG_LEVEL_INFO,message,null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#info(Object, Throwable)
- */
- public final void info(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
- log(SimpleLog.LOG_LEVEL_INFO, message, t);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#warn(Object)
- */
- public final void warn(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
- log(SimpleLog.LOG_LEVEL_WARN, message, null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#warn(Object, Throwable)
- */
- public final void warn(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
- log(SimpleLog.LOG_LEVEL_WARN, message, t);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#error(Object)
- */
- public final void error(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
- log(SimpleLog.LOG_LEVEL_ERROR, message, null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#error(Object, Throwable)
- */
- public final void error(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
- log(SimpleLog.LOG_LEVEL_ERROR, message, t);
- }
- }
-
-
- /**
- * Log a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL.
- *
- * @param message to log
- * @see org.apache.commons.logging.Log#fatal(Object)
- */
- public final void fatal(Object message) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
- log(SimpleLog.LOG_LEVEL_FATAL, message, null);
- }
- }
-
-
- /**
- * Logs a message with
- * org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL.
- *
- * @param message to log
- * @param t log this cause
- * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
- */
- public final void fatal(Object message, Throwable t) {
-
- if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
- log(SimpleLog.LOG_LEVEL_FATAL, message, t);
- }
- }
-
-
- /**
- *
Are debug messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isDebugEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG);
- }
-
-
- /**
- *
Are error messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isErrorEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR);
- }
-
-
- /**
- *
Are fatal messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isFatalEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL);
- }
-
-
- /**
- *
Are info messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isInfoEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_INFO);
- }
-
-
- /**
- *
Are trace messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isTraceEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE);
- }
-
-
- /**
- *
Are warn messages currently enabled?
- *
- *
This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
- */
- public final boolean isWarnEnabled() {
-
- return isLevelEnabled(SimpleLog.LOG_LEVEL_WARN);
- }
-
-
- /**
- * Return the thread context class loader if available.
- * Otherwise return null.
- *
- * The thread context class loader is available for JDK 1.2
- * or later, if certain security conditions are met.
- *
- * @exception LogConfigurationException if a suitable class loader
- * cannot be identified.
- */
- private static ClassLoader getContextClassLoader()
- {
- ClassLoader classLoader = null;
-
- if (classLoader == null) {
- try {
- // Are we running on a JDK 1.2 or later system?
- Method method = Thread.class.getMethod("getContextClassLoader",
- (Class[]) null);
-
- // Get the thread context class loader (if there is one)
- try {
- classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
- (Class[]) null);
- } catch (IllegalAccessException e) {
- ; // ignore
- } catch (InvocationTargetException e) {
- /**
- * InvocationTargetException is thrown by 'invoke' when
- * the method being invoked (getContextClassLoader) throws
- * an exception.
- *
- * getContextClassLoader() throws SecurityException when
- * the context class loader isn't an ancestor of the
- * calling class's class loader, or if security
- * permissions are restricted.
- *
- * In the first case (not related), we want to ignore and
- * keep going. We cannot help but also ignore the second
- * with the logic below, but other calls elsewhere (to
- * obtain a class loader) will trigger this exception where
- * we can make a distinction.
- */
- if (e.getTargetException() instanceof SecurityException) {
- ; // ignore
- } else {
- // Capture 'e.getTargetException()' exception for details
- // alternate: log 'e.getTargetException()', and pass back 'e'.
- throw new LogConfigurationException
- ("Unexpected InvocationTargetException", e.getTargetException());
- }
- }
- } catch (NoSuchMethodException e) {
- // Assume we are running on JDK 1.1
- ; // ignore
- }
- }
-
- if (classLoader == null) {
- classLoader = SimpleLog.class.getClassLoader();
- }
-
- // Return the selected class loader
- return classLoader;
- }
-
- private static InputStream getResourceAsStream(final String name)
- {
- return (InputStream)AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- ClassLoader threadCL = getContextClassLoader();
-
- if (threadCL != null) {
- return threadCL.getResourceAsStream(name);
- } else {
- return ClassLoader.getSystemResourceAsStream(name);
- }
- }
- });
- }
-}
-
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/WeakHashtable.java b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/WeakHashtable.java
deleted file mode 100644
index 3748cebf9..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/WeakHashtable.java
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- * 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.commons.logging.impl;
-
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.util.*;
-
-/**
- *
Implementation of Hashtable that uses WeakReference's
- * to hold its keys thus allowing them to be reclaimed by the garbage collector.
- * The associated values are retained using strong references.
- *
- *
This class follows the symantics of Hashtable as closely as
- * possible. It therefore does not accept null values or keys.
- *
- *
Note:
- * This is not intended to be a general purpose hash table replacement.
- * This implementation is also tuned towards a particular purpose: for use as a replacement
- * for Hashtable in LogFactory. This application requires
- * good liveliness for get and put. Various tradeoffs
- * have been made with this in mind.
- *
- *
- * Usage: typical use case is as a drop-in replacement
- * for the Hashtable used in LogFactory for J2EE enviroments
- * running 1.3+ JVMs. Use of this class in most cases (see below) will
- * allow classloaders to be collected by the garbage collector without the need
- * to call {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release(ClassLoader)}.
- *
- *
- *
org.apache.commons.logging.LogFactory checks whether this class
- * can be supported by the current JVM, and if so then uses it to store
- * references to the LogFactory implementationd it loads
- * (rather than using a standard Hashtable instance).
- * Having this class used instead of Hashtable solves
- * certain issues related to dynamic reloading of applications in J2EE-style
- * environments. However this class requires java 1.3 or later (due to its use
- * of java.lang.ref.WeakReference and associates).
- * And by the way, this extends Hashtable rather than HashMap
- * for backwards compatibility reasons. See the documentation
- * for method LogFactory.createFactoryStore for more details.
- *
- *
The reason all this is necessary is due to a issue which
- * arises during hot deploy in a J2EE-like containers.
- * Each component running in the container owns one or more classloaders; when
- * the component loads a LogFactory instance via the component classloader
- * a reference to it gets stored in the static LogFactory.factories member,
- * keyed by the component's classloader so different components don't
- * stomp on each other. When the component is later unloaded, the container
- * sets the component's classloader to null with the intent that all the
- * component's classes get garbage-collected. However there's still a
- * reference to the component's classloader from a key in the "global"
- * LogFactory's factories member! If LogFactory.release()
- * is called whenever component is unloaded, the classloaders will be correctly
- * garbage collected; this should be done by any container that
- * bundles commons-logging by default. However, holding the classloader
- * references weakly ensures that the classloader will be garbage collected
- * without the container performing this step.
- *
- *
- * Limitations:
- * There is still one (unusual) scenario in which a component will not
- * be correctly unloaded without an explicit release. Though weak references
- * are used for its keys, it is necessary to use strong references for its values.
- *
- *
- *
If the abstract class LogFactory is
- * loaded by the container classloader but a subclass of
- * LogFactory [LogFactory1] is loaded by the component's
- * classloader and an instance stored in the static map associated with the
- * base LogFactory class, then there is a strong reference from the LogFactory
- * class to the LogFactory1 instance (as normal) and a strong reference from
- * the LogFactory1 instance to the component classloader via
- * getClass().getClassLoader(). This chain of references will prevent
- * collection of the child classloader.
- *
- *
- * Such a situation occurs when the commons-logging.jar is
- * loaded by a parent classloader (e.g. a server level classloader in a
- * servlet container) and a custom LogFactory implementation is
- * loaded by a child classloader (e.g. a web app classloader).
- *
- *
To avoid this scenario, ensure
- * that any custom LogFactory subclass is loaded by the same classloader as
- * the base LogFactory. Creating custom LogFactory subclasses is,
- * however, rare. The standard LogFactoryImpl class should be sufficient
- * for most or all users.
- *
- *
- * @author Brian Stansberry
- *
- * @since 1.1
- */
-public final class WeakHashtable extends Hashtable {
-
- /**
- * The maximum number of times put() or remove() can be called before
- * the map will be purged of all cleared entries.
- */
- private static final int MAX_CHANGES_BEFORE_PURGE = 100;
-
- /**
- * The maximum number of times put() or remove() can be called before
- * the map will be purged of one cleared entry.
- */
- private static final int PARTIAL_PURGE_COUNT = 10;
-
- /* ReferenceQueue we check for gc'd keys */
- private ReferenceQueue queue = new ReferenceQueue();
- /* Counter used to control how often we purge gc'd entries */
- private int changeCount = 0;
-
- /**
- * Constructs a WeakHashtable with the Hashtable default
- * capacity and load factor.
- */
- public WeakHashtable() {}
-
-
- /**
- *@see Hashtable
- */
- public boolean containsKey(Object key) {
- // purge should not be required
- Referenced referenced = new Referenced(key);
- return super.containsKey(referenced);
- }
-
- /**
- *@see Hashtable
- */
- public Enumeration elements() {
- purge();
- return super.elements();
- }
-
- /**
- *@see Hashtable
- */
- public Set entrySet() {
- purge();
- Set referencedEntries = super.entrySet();
- Set unreferencedEntries = new HashSet();
- for (Iterator it=referencedEntries.iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- Referenced referencedKey = (Referenced) entry.getKey();
- Object key = referencedKey.getValue();
- Object value = entry.getValue();
- if (key != null) {
- Entry dereferencedEntry = new Entry(key, value);
- unreferencedEntries.add(dereferencedEntry);
- }
- }
- return unreferencedEntries;
- }
-
- /**
- *@see Hashtable
- */
- public Object get(Object key) {
- // for performance reasons, no purge
- Referenced referenceKey = new Referenced(key);
- return super.get(referenceKey);
- }
-
- /**
- *@see Hashtable
- */
- public Enumeration keys() {
- purge();
- final Enumeration enumer = super.keys();
- return new Enumeration() {
- public boolean hasMoreElements() {
- return enumer.hasMoreElements();
- }
- public Object nextElement() {
- Referenced nextReference = (Referenced) enumer.nextElement();
- return nextReference.getValue();
- }
- };
- }
-
-
- /**
- *@see Hashtable
- */
- public Set keySet() {
- purge();
- Set referencedKeys = super.keySet();
- Set unreferencedKeys = new HashSet();
- for (Iterator it=referencedKeys.iterator(); it.hasNext();) {
- Referenced referenceKey = (Referenced) it.next();
- Object keyValue = referenceKey.getValue();
- if (keyValue != null) {
- unreferencedKeys.add(keyValue);
- }
- }
- return unreferencedKeys;
- }
-
- /**
- *@see Hashtable
- */
- public Object put(Object key, Object value) {
- // check for nulls, ensuring symantics match superclass
- if (key == null) {
- throw new NullPointerException("Null keys are not allowed");
- }
- if (value == null) {
- throw new NullPointerException("Null values are not allowed");
- }
-
- // for performance reasons, only purge every
- // MAX_CHANGES_BEFORE_PURGE times
- if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
- purge();
- changeCount = 0;
- }
- // do a partial purge more often
- else if ((changeCount % PARTIAL_PURGE_COUNT) == 0) {
- purgeOne();
- }
-
- Referenced keyRef = new Referenced(key, queue);
- return super.put(keyRef, value);
- }
-
- /**
- *@see Hashtable
- */
- public void putAll(Map t) {
- if (t != null) {
- Set entrySet = t.entrySet();
- for (Iterator it=entrySet.iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- put(entry.getKey(), entry.getValue());
- }
- }
- }
-
- /**
- *@see Hashtable
- */
- public Collection values() {
- purge();
- return super.values();
- }
-
- /**
- *@see Hashtable
- */
- public Object remove(Object key) {
- // for performance reasons, only purge every
- // MAX_CHANGES_BEFORE_PURGE times
- if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
- purge();
- changeCount = 0;
- }
- // do a partial purge more often
- else if ((changeCount % PARTIAL_PURGE_COUNT) == 0) {
- purgeOne();
- }
- return super.remove(new Referenced(key));
- }
-
- /**
- *@see Hashtable
- */
- public boolean isEmpty() {
- purge();
- return super.isEmpty();
- }
-
- /**
- *@see Hashtable
- */
- public int size() {
- purge();
- return super.size();
- }
-
- /**
- *@see Hashtable
- */
- public String toString() {
- purge();
- return super.toString();
- }
-
- /**
- * @see Hashtable
- */
- protected void rehash() {
- // purge here to save the effort of rehashing dead entries
- purge();
- super.rehash();
- }
-
- /**
- * Purges all entries whose wrapped keys
- * have been garbage collected.
- */
- private void purge() {
- synchronized (queue) {
- WeakKey key;
- while ((key = (WeakKey) queue.poll()) != null) {
- super.remove(key.getReferenced());
- }
- }
- }
-
- /**
- * Purges one entry whose wrapped key
- * has been garbage collected.
- */
- private void purgeOne() {
-
- synchronized (queue) {
- WeakKey key = (WeakKey) queue.poll();
- if (key != null) {
- super.remove(key.getReferenced());
- }
- }
- }
-
- /** Entry implementation */
- private final static class Entry implements Map.Entry {
-
- private final Object key;
- private final Object value;
-
- private Entry(Object key, Object value) {
- this.key = key;
- this.value = value;
- }
-
- public boolean equals(Object o) {
- boolean result = false;
- if (o != null && o instanceof Map.Entry) {
- Map.Entry entry = (Map.Entry) o;
- result = (getKey()==null ?
- entry.getKey() == null :
- getKey().equals(entry.getKey()))
- &&
- (getValue()==null ?
- entry.getValue() == null :
- getValue().equals(entry.getValue()));
- }
- return result;
- }
-
- public int hashCode() {
-
- return (getKey()==null ? 0 : getKey().hashCode()) ^
- (getValue()==null ? 0 : getValue().hashCode());
- }
-
- public Object setValue(Object value) {
- throw new UnsupportedOperationException("Entry.setValue is not supported.");
- }
-
- public Object getValue() {
- return value;
- }
-
- public Object getKey() {
- return key;
- }
- }
-
-
- /** Wrapper giving correct symantics for equals and hashcode */
- private final static class Referenced {
-
- private final WeakReference reference;
- private final int hashCode;
-
- /**
- *
- * @throws NullPointerException if referant is null
- */
- private Referenced(Object referant) {
- reference = new WeakReference(referant);
- // Calc a permanent hashCode so calls to Hashtable.remove()
- // work if the WeakReference has been cleared
- hashCode = referant.hashCode();
- }
-
- /**
- *
- * @throws NullPointerException if key is null
- */
- private Referenced(Object key, ReferenceQueue queue) {
- reference = new WeakKey(key, queue, this);
- // Calc a permanent hashCode so calls to Hashtable.remove()
- // work if the WeakReference has been cleared
- hashCode = key.hashCode();
-
- }
-
- public int hashCode() {
- return hashCode;
- }
-
- private Object getValue() {
- return reference.get();
- }
-
- public boolean equals(Object o) {
- boolean result = false;
- if (o instanceof Referenced) {
- Referenced otherKey = (Referenced) o;
- Object thisKeyValue = getValue();
- Object otherKeyValue = otherKey.getValue();
- if (thisKeyValue == null) {
- result = (otherKeyValue == null);
-
- // Since our hashcode was calculated from the original
- // non-null referant, the above check breaks the
- // hashcode/equals contract, as two cleared Referenced
- // objects could test equal but have different hashcodes.
- // We can reduce (not eliminate) the chance of this
- // happening by comparing hashcodes.
- if (result == true) {
- result = (this.hashCode() == otherKey.hashCode());
- }
- // In any case, as our c'tor does not allow null referants
- // and Hashtable does not do equality checks between
- // existing keys, normal hashtable operations should never
- // result in an equals comparison between null referants
- }
- else
- {
- result = thisKeyValue.equals(otherKeyValue);
- }
- }
- return result;
- }
- }
-
- /**
- * WeakReference subclass that holds a hard reference to an
- * associated value and also makes accessible
- * the Referenced object holding it.
- */
- private final static class WeakKey extends WeakReference {
-
- private final Referenced referenced;
-
- private WeakKey(Object key,
- ReferenceQueue queue,
- Referenced referenced) {
- super(key, queue);
- this.referenced = referenced;
- }
-
- private Referenced getReferenced() {
- return referenced;
- }
- }
-}
diff --git a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/package.html b/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/package.html
deleted file mode 100644
index 0d370715c..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/commons/logging/impl/package.html
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
Concrete implementations of commons-logging wrapper APIs.
This package provides an API for logging in server-based applications that
-can be used around a variety of different logging implementations, including
-prebuilt support for the following:
-
-
Log4J (version 1.2 or later)
- from Apache's Logging project. Each named Log
- instance is connected to a corresponding Log4J Logger.
-
- JDK Logging API, included in JDK 1.4 or later systems. Each named
- Log instance is connected to a corresponding
- java.util.logging.Logger instance.
-
LogKit from Apache's
- Avalon project. Each named Log instance is
- connected to a corresponding LogKit Logger.
-
NoOpLog implementation that simply swallows
- all log output, for all named Log instances.
-
SimpleLog implementation that writes all
- log output, for all named Log instances, to
- System.err.
-
-
-
-
Quick Start Guide
-
-
For those impatient to just get on with it, the following example
-illustrates the typical declaration and use of a logger that is named (by
-convention) after the calling class:
-
-
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
-
- public class Foo {
-
- private Log log = LogFactory.getLog(Foo.class);
-
- public void foo() {
- ...
- try {
- if (log.isDebugEnabled()) {
- log.debug("About to do something to object " + name);
- }
- name.bar();
- } catch (IllegalStateException e) {
- log.error("Something bad happened to " + name, e);
- }
- ...
- }
-
-
-
Unless you configure things differently, all log output will be written
-to System.err. Therefore, you really will want to review the remainder of
-this page in order to understand how to configure logging for your
-application.
-
-
-
Configuring the Commons Logging Package
-
-
-
Choosing a LogFactory Implementation
-
-
From an application perspective, the first requirement is to retrieve an
-object reference to the LogFactory instance that will be used
-to create Log instances for this
-application. This is normally accomplished by calling the static
-getFactory() method. This method implements the following
-discovery algorithm to select the name of the LogFactory
-implementation class this application wants to use:
-
-
Check for a system property named
- org.apache.commons.logging.LogFactory.
-
Use the JDK 1.3 JAR Services Discovery mechanism (see
-
- http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html for
- more information) to look for a resource named
- META-INF/services/org.apache.commons.logging.LogFactory
- whose first line is assumed to contain the desired class name.
-
Look for a properties file named commons-logging.properties
- visible in the application class path, with a property named
- org.apache.commons.logging.LogFactory defining the
- desired implementation class name.
-
Fall back to a default implementation, which is described
- further below.
-
-
-
If a commons-logging.properties file is found, all of the
-properties defined there are also used to set configuration attributes on
-the instantiated LogFactory instance.
-
-
Once an implementation class name is selected, the corresponding class is
-loaded from the current Thread context class loader (if there is one), or
-from the class loader that loaded the LogFactory class itself
-otherwise. This allows a copy of commons-logging.jar to be
-shared in a multiple class loader environment (such as a servlet container),
-but still allow each web application to provide its own LogFactory
-implementation, if it so desires. An instance of this class will then be
-created, and cached per class loader.
-
-
-
The Default LogFactory Implementation
-
-
The Logging Package APIs include a default LogFactory
-implementation class (
-org.apache.commons.logging.impl.LogFactoryImpl) that is selected if no
-other implementation class name can be discovered. Its primary purpose is
-to create (as necessary) and return Log instances
-in response to calls to the getInstance() method. The default
-implementation uses the following rules:
-
-
At most one Log instance of the same name will be created.
- Subsequent getInstance() calls to the same
- LogFactory instance, with the same name or Class
- parameter, will return the same Log instance.
-
When a new Log instance must be created, the default
- LogFactory implementation uses the following discovery
- process:
-
-
Look for a configuration attribute of this factory named
- org.apache.commons.logging.Log (for backwards
- compatibility to pre-1.0 versions of this API, an attribute
- org.apache.commons.logging.log is also consulted).
-
Look for a system property named
- org.apache.commons.logging.Log (for backwards
- compatibility to pre-1.0 versions of this API, a system property
- org.apache.commons.logging.log is also consulted).
-
If the Log4J logging system is available in the application
- class path, use the corresponding wrapper class
- (Log4JLogger).
-
If the application is executing on a JDK 1.4 system, use
- the corresponding wrapper class
- (Jdk14Logger).
-
Fall back to the default simple logging implementation
- (SimpleLog).
-
-
Load the class of the specified name from the thread context class
- loader (if any), or from the class loader that loaded the
- LogFactory class otherwise.
-
Instantiate an instance of the selected Log
- implementation class, passing the specified name as the single
- argument to its constructor.
-
-
-
See the SimpleLog JavaDocs for detailed
-configuration information for this default implementation.
-
-
-
Configuring the Underlying Logging System
-
-
The basic principle is that the user is totally responsible for the
-configuration of the underlying logging system.
-Commons-logging should not change the existing configuration.
-
-
Each individual Log implementation may
-support its own configuration properties. These will be documented in the
-class descriptions for the corresponding implementation class.
-
-
Finally, some Log implementations (such as the one for Log4J)
-require an external configuration file for the entire logging environment.
-This file should be prepared in a manner that is specific to the actual logging
-technology being used.
-
-
-
Using the Logging Package APIs
-
-
Use of the Logging Package APIs, from the perspective of an application
-component, consists of the following steps:
-
-
Acquire a reference to an instance of
- org.apache.commons.logging.Log, by calling the
- factory method
-
- LogFactory.getInstance(String name). Your application can contain
- references to multiple loggers that are used for different
- purposes. A typical scenario for a server application is to have each
- major component of the server use its own Log instance.
-
Cause messages to be logged (if the corresponding detail level is enabled)
- by calling appropriate methods (trace(), debug(),
- info(), warn(), error, and
- fatal()).
-
-
-
For convenience, LogFactory also offers a static method
-getLog() that combines the typical two-step pattern:
For example, you might use the following technique to initialize and
-use a Log instance in an application component:
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class MyComponent {
-
- protected Log log =
- LogFactory.getLog(MyComponent.class);
-
- // Called once at startup time
- public void start() {
- ...
- log.info("MyComponent started");
- ...
- }
-
- // Called once at shutdown time
- public void stop() {
- ...
- log.info("MyComponent stopped");
- ...
- }
-
- // Called repeatedly to process a particular argument value
- // which you want logged if debugging is enabled
- public void process(String value) {
- ...
- // Do the string concatenation only if logging is enabled
- if (log.isDebugEnabled())
- log.debug("MyComponent processing " + value);
- ...
- }
-
-}
-
-
-
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/AFMParser.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/AFMParser.java
deleted file mode 100644
index cb0e52f81..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/AFMParser.java
+++ /dev/null
@@ -1,1062 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-import java.util.StringTokenizer;
-
-import org.apache.fontbox.util.BoundingBox;
-
-/**
- * This class is used to parse AFM(Adobe Font Metrics) documents.
- *
- * @see AFM Documentation
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class AFMParser
-{
- /**
- * This is a comment in a AFM file.
- */
- public static final String COMMENT = "Comment";
- /**
- * This is the constant used in the AFM file to start a font metrics item.
- */
- public static final String START_FONT_METRICS = "StartFontMetrics";
- /**
- * This is the constant used in the AFM file to end a font metrics item.
- */
- public static final String END_FONT_METRICS = "EndFontMetrics";
- /**
- * This is the font name.
- */
- public static final String FONT_NAME = "FontName";
- /**
- * This is the full name.
- */
- public static final String FULL_NAME = "FullName";
- /**
- * This is the Family name.
- */
- public static final String FAMILY_NAME = "FamilyName";
- /**
- * This is the weight.
- */
- public static final String WEIGHT = "Weight";
- /**
- * This is the font bounding box.
- */
- public static final String FONT_BBOX = "FontBBox";
- /**
- * This is the version of the font.
- */
- public static final String VERSION = "Version";
- /**
- * This is the notice.
- */
- public static final String NOTICE = "Notice";
- /**
- * This is the encoding scheme.
- */
- public static final String ENCODING_SCHEME = "EncodingScheme";
- /**
- * This is the mapping scheme.
- */
- public static final String MAPPING_SCHEME = "MappingScheme";
- /**
- * This is the escape character.
- */
- public static final String ESC_CHAR = "EscChar";
- /**
- * This is the character set.
- */
- public static final String CHARACTER_SET = "CharacterSet";
- /**
- * This is the characters attribute.
- */
- public static final String CHARACTERS = "Characters";
- /**
- * This will determine if this is a base font.
- */
- public static final String IS_BASE_FONT = "IsBaseFont";
- /**
- * This is the V Vector attribute.
- */
- public static final String V_VECTOR = "VVector";
- /**
- * This will tell if the V is fixed.
- */
- public static final String IS_FIXED_V = "IsFixedV";
- /**
- * This is the cap height attribute.
- */
- public static final String CAP_HEIGHT = "CapHeight";
- /**
- * This is the X height.
- */
- public static final String X_HEIGHT = "XHeight";
- /**
- * This is ascender attribute.
- */
- public static final String ASCENDER = "Ascender";
- /**
- * This is the descender attribute.
- */
- public static final String DESCENDER = "Descender";
-
- /**
- * The underline position.
- */
- public static final String UNDERLINE_POSITION = "UnderlinePosition";
- /**
- * This is the Underline thickness.
- */
- public static final String UNDERLINE_THICKNESS = "UnderlineThickness";
- /**
- * This is the italic angle.
- */
- public static final String ITALIC_ANGLE = "ItalicAngle";
- /**
- * This is the char width.
- */
- public static final String CHAR_WIDTH = "CharWidth";
- /**
- * This will determine if this is fixed pitch.
- */
- public static final String IS_FIXED_PITCH = "IsFixedPitch";
- /**
- * This is the start of character metrics.
- */
- public static final String START_CHAR_METRICS = "StartCharMetrics";
- /**
- * This is the end of character metrics.
- */
- public static final String END_CHAR_METRICS = "EndCharMetrics";
- /**
- * The character metrics c value.
- */
- public static final String CHARMETRICS_C = "C";
- /**
- * The character metrics c value.
- */
- public static final String CHARMETRICS_CH = "CH";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_WX = "WX";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W0X = "W0X";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W1X = "W1X";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_WY = "WY";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W0Y = "W0Y";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W1Y = "W1Y";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W = "W";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W0 = "W0";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_W1 = "W1";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_VV = "VV";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_N = "N";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_B = "B";
- /**
- * The character metrics value.
- */
- public static final String CHARMETRICS_L = "L";
- /**
- * The character metrics value.
- */
- public static final String STD_HW = "StdHW";
- /**
- * The character metrics value.
- */
- public static final String STD_VW = "StdVW";
- /**
- * This is the start of track kern data.
- */
- public static final String START_TRACK_KERN = "StartTrackKern";
- /**
- * This is the end of track kern data.
- */
- public static final String END_TRACK_KERN = "EndTrackKern";
- /**
- * This is the start of kern data.
- */
- public static final String START_KERN_DATA = "StartKernData";
- /**
- * This is the end of kern data.
- */
- public static final String END_KERN_DATA = "EndKernData";
- /**
- * This is the start of kern pairs data.
- */
- public static final String START_KERN_PAIRS = "StartKernPairs";
- /**
- * This is the end of kern pairs data.
- */
- public static final String END_KERN_PAIRS = "EndKernPairs";
- /**
- * This is the start of kern pairs data.
- */
- public static final String START_KERN_PAIRS0 = "StartKernPairs0";
- /**
- * This is the start of kern pairs data.
- */
- public static final String START_KERN_PAIRS1 = "StartKernPairs1";
- /**
- * This is the start compisites data section.
- */
- public static final String START_COMPOSITES = "StartComposites";
- /**
- * This is the end compisites data section.
- */
- public static final String END_COMPOSITES = "EndComposites";
- /**
- * This is a composite character.
- */
- public static final String CC = "CC";
- /**
- * This is a composite charater part.
- */
- public static final String PCC = "PCC";
- /**
- * This is a kern pair.
- */
- public static final String KERN_PAIR_KP = "KP";
- /**
- * This is a kern pair.
- */
- public static final String KERN_PAIR_KPH = "KPH";
- /**
- * This is a kern pair.
- */
- public static final String KERN_PAIR_KPX = "KPX";
- /**
- * This is a kern pair.
- */
- public static final String KERN_PAIR_KPY = "KPY";
-
- private static final int BITS_IN_HEX = 16;
-
-
- private InputStream input;
- private FontMetric result;
-
- /**
- * A method to test parsing of all AFM documents in the resources
- * directory.
- *
- * @param args Ignored.
- *
- * @throws IOException If there is an error parsing one of the documents.
- */
- public static void main( String[] args ) throws IOException
- {
- java.io.File afmDir = new java.io.File( "Resources/afm" );
- java.io.File[] files = afmDir.listFiles();
- for( int i=0; i< files.length; i++ )
- {
- if( files[i].getPath().toUpperCase().endsWith( ".AFM" ) )
- {
- long start = System.currentTimeMillis();
- java.io.FileInputStream input = new java.io.FileInputStream( files[i] );
- AFMParser parser = new AFMParser( input );
- parser.parse();
- long stop = System.currentTimeMillis();
- System.out.println( "Parsing:" + files[i].getPath() + " " + (stop-start) );
- }
- }
- }
-
- /**
- * Constructor.
- *
- * @param in The input stream to read the AFM document from.
- */
- public AFMParser( InputStream in )
- {
- input = in;
- }
-
- /**
- * This will parse the AFM document. This will close the Input stream
- * when the parsing is finished.
- *
- * @throws IOException If there is an IO error reading the document.
- */
- public void parse() throws IOException
- {
- result = parseFontMetric();
- }
-
- /**
- * This will get the result of the parsing.
- *
- * @return The parsed java object.
- */
- public FontMetric getResult()
- {
- return result;
- }
-
- /**
- * This will parse a font metrics item.
- *
- * @return The parse font metrics item.
- *
- * @throws IOException If there is an error reading the AFM file.
- */
- private FontMetric parseFontMetric() throws IOException
- {
- FontMetric fontMetrics = new FontMetric();
- String startFontMetrics = readString();
- if( !START_FONT_METRICS.equals( startFontMetrics ) )
- {
- throw new IOException( "Error: The AFM file should start with " + START_FONT_METRICS +
- " and not '" + startFontMetrics + "'" );
- }
- fontMetrics.setAFMVersion( readFloat() );
- String nextCommand = null;
- while( !END_FONT_METRICS.equals( (nextCommand = readString() ) ) )
- {
- if( FONT_NAME.equals( nextCommand ) )
- {
- fontMetrics.setFontName( readLine() );
- }
- else if( FULL_NAME.equals( nextCommand ) )
- {
- fontMetrics.setFullName( readLine() );
- }
- else if( FAMILY_NAME.equals( nextCommand ) )
- {
- fontMetrics.setFamilyName( readLine() );
- }
- else if( WEIGHT.equals( nextCommand ) )
- {
- fontMetrics.setWeight( readLine() );
- }
- else if( FONT_BBOX.equals( nextCommand ) )
- {
- BoundingBox bBox = new BoundingBox();
- bBox.setLowerLeftX( readFloat() );
- bBox.setLowerLeftY( readFloat() );
- bBox.setUpperRightX( readFloat() );
- bBox.setUpperRightY( readFloat() );
- fontMetrics.setFontBBox( bBox );
- }
- else if( VERSION.equals( nextCommand ) )
- {
- fontMetrics.setFontVersion( readLine() );
- }
- else if( NOTICE.equals( nextCommand ) )
- {
- fontMetrics.setNotice( readLine() );
- }
- else if( ENCODING_SCHEME.equals( nextCommand ) )
- {
- fontMetrics.setEncodingScheme( readLine() );
- }
- else if( MAPPING_SCHEME.equals( nextCommand ) )
- {
- fontMetrics.setMappingScheme( readInt() );
- }
- else if( ESC_CHAR.equals( nextCommand ) )
- {
- fontMetrics.setEscChar( readInt() );
- }
- else if( CHARACTER_SET.equals( nextCommand ) )
- {
- fontMetrics.setCharacterSet( readLine() );
- }
- else if( CHARACTERS.equals( nextCommand ) )
- {
- fontMetrics.setCharacters( readInt() );
- }
- else if( IS_BASE_FONT.equals( nextCommand ) )
- {
- fontMetrics.setIsBaseFont( readBoolean() );
- }
- else if( V_VECTOR.equals( nextCommand ) )
- {
- float[] vector = new float[2];
- vector[0] = readFloat();
- vector[1] = readFloat();
- fontMetrics.setVVector( vector );
- }
- else if( IS_FIXED_V.equals( nextCommand ) )
- {
- fontMetrics.setIsFixedV( readBoolean() );
- }
- else if( CAP_HEIGHT.equals( nextCommand ) )
- {
- fontMetrics.setCapHeight( readFloat() );
- }
- else if( X_HEIGHT.equals( nextCommand ) )
- {
- fontMetrics.setXHeight( readFloat() );
- }
- else if( ASCENDER.equals( nextCommand ) )
- {
- fontMetrics.setAscender( readFloat() );
- }
- else if( DESCENDER.equals( nextCommand ) )
- {
- fontMetrics.setDescender( readFloat() );
- }
- else if( STD_HW.equals( nextCommand ) )
- {
- fontMetrics.setStandardHorizontalWidth( readFloat() );
- }
- else if( STD_VW.equals( nextCommand ) )
- {
- fontMetrics.setStandardVerticalWidth( readFloat() );
- }
- else if( COMMENT.equals( nextCommand ) )
- {
- fontMetrics.addComment( readLine() );
- }
- else if( UNDERLINE_POSITION.equals( nextCommand ) )
- {
- fontMetrics.setUnderlinePosition( readFloat() );
- }
- else if( UNDERLINE_THICKNESS.equals( nextCommand ) )
- {
- fontMetrics.setUnderlineThickness( readFloat() );
- }
- else if( ITALIC_ANGLE.equals( nextCommand ) )
- {
- fontMetrics.setItalicAngle( readFloat() );
- }
- else if( CHAR_WIDTH.equals( nextCommand ) )
- {
- float[] widths = new float[2];
- widths[0] = readFloat();
- widths[1] = readFloat();
- fontMetrics.setCharWidth( widths );
- }
- else if( IS_FIXED_PITCH.equals( nextCommand ) )
- {
- fontMetrics.setFixedPitch( readBoolean() );
- }
- else if( START_CHAR_METRICS.equals( nextCommand ) )
- {
- int count = readInt();
- for( int i=0; i= 2 not='" + hexString );
- }
- if( hexString.charAt( 0 ) != '<' ||
- hexString.charAt( hexString.length() -1 ) != '>' )
- {
- throw new IOException( "String should be enclosed by angle brackets '" + hexString+ "'" );
- }
- hexString = hexString.substring( 1, hexString.length() -1 );
- byte[] data = new byte[ (hexString.length() / 2) ];
- for( int i=0; i or FF, the spec is a little
- //unclear, wait and see if it breaks anything.
- String charCode = metricsTokenizer.nextToken();
- charMetric.setCharacterCode( Integer.parseInt( charCode, BITS_IN_HEX ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_WX ) )
- {
- String wx = metricsTokenizer.nextToken();
- charMetric.setWx( Float.parseFloat( wx ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W0X ) )
- {
- String w0x = metricsTokenizer.nextToken();
- charMetric.setW0x( Float.parseFloat( w0x ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W1X ) )
- {
- String w1x = metricsTokenizer.nextToken();
- charMetric.setW0x( Float.parseFloat( w1x ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_WY ) )
- {
- String wy = metricsTokenizer.nextToken();
- charMetric.setWy( Float.parseFloat( wy ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W0Y ) )
- {
- String w0y = metricsTokenizer.nextToken();
- charMetric.setW0y( Float.parseFloat( w0y ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W1Y ) )
- {
- String w1y = metricsTokenizer.nextToken();
- charMetric.setW0y( Float.parseFloat( w1y ) );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W ) )
- {
- String w0 = metricsTokenizer.nextToken();
- String w1 = metricsTokenizer.nextToken();
- float[] w = new float[2];
- w[0] = Float.parseFloat( w0 );
- w[1] = Float.parseFloat( w1 );
- charMetric.setW( w );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W0 ) )
- {
- String w00 = metricsTokenizer.nextToken();
- String w01 = metricsTokenizer.nextToken();
- float[] w0 = new float[2];
- w0[0] = Float.parseFloat( w00 );
- w0[1] = Float.parseFloat( w01 );
- charMetric.setW0( w0 );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_W1 ) )
- {
- String w10 = metricsTokenizer.nextToken();
- String w11 = metricsTokenizer.nextToken();
- float[] w1 = new float[2];
- w1[0] = Float.parseFloat( w10 );
- w1[1] = Float.parseFloat( w11 );
- charMetric.setW1( w1 );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_VV ) )
- {
- String vv0 = metricsTokenizer.nextToken();
- String vv1 = metricsTokenizer.nextToken();
- float[] vv = new float[2];
- vv[0] = Float.parseFloat( vv0 );
- vv[1] = Float.parseFloat( vv1 );
- charMetric.setVv( vv );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_N ) )
- {
- String name = metricsTokenizer.nextToken();
- charMetric.setName( name );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_B ) )
- {
- String llx = metricsTokenizer.nextToken();
- String lly = metricsTokenizer.nextToken();
- String urx = metricsTokenizer.nextToken();
- String ury = metricsTokenizer.nextToken();
- BoundingBox box = new BoundingBox();
- box.setLowerLeftX( Float.parseFloat( llx ) );
- box.setLowerLeftY( Float.parseFloat( lly ) );
- box.setUpperRightX( Float.parseFloat( urx ) );
- box.setUpperRightY( Float.parseFloat( ury ) );
- charMetric.setBoundingBox( box );
- verifySemicolon( metricsTokenizer );
- }
- else if( nextCommand.equals( CHARMETRICS_L ) )
- {
- String successor = metricsTokenizer.nextToken();
- String ligature = metricsTokenizer.nextToken();
- Ligature lig = new Ligature();
- lig.setSuccessor( successor );
- lig.setLigature( ligature );
- charMetric.addLigature( lig );
- verifySemicolon( metricsTokenizer );
- }
- else
- {
- throw new IOException( "Unknown CharMetrics command '" + nextCommand + "'" );
- }
- }
- }
- catch( NumberFormatException e )
- {
- throw new IOException( "Error: Corrupt AFM document:" + e );
- }
- return charMetric;
- }
-
- /**
- * This is used to verify that a semicolon is the next token in the stream.
- *
- * @param tokenizer The tokenizer to read from.
- *
- * @throws IOException If the semicolon is missing.
- */
- private void verifySemicolon( StringTokenizer tokenizer ) throws IOException
- {
- if( tokenizer.hasMoreTokens() )
- {
- String semicolon = tokenizer.nextToken();
- if( !semicolon.equals( ";" ) )
- {
- throw new IOException( "Error: Expected semicolon in stream actual='" +
- semicolon + "'" );
- }
- }
- else
- {
- throw new IOException( "CharMetrics is missing a semicolon after a command" );
- }
- }
-
- /**
- * This will read a boolean from the stream.
- *
- * @return The boolean in the stream.
- */
- private boolean readBoolean() throws IOException
- {
- String theBoolean = readString();
- return Boolean.valueOf( theBoolean ).booleanValue();
- }
-
- /**
- * This will read an integer from the stream.
- *
- * @return The integer in the stream.
- */
- private int readInt() throws IOException
- {
- String theInt = readString();
- try
- {
- return Integer.parseInt( theInt );
- }
- catch( NumberFormatException e )
- {
- throw new IOException( "Error parsing AFM document:" + e );
- }
- }
-
- /**
- * This will read a float from the stream.
- *
- * @return The float in the stream.
- */
- private float readFloat() throws IOException
- {
- String theFloat = readString();
- return Float.parseFloat( theFloat );
- }
-
- /**
- * This will read until the end of a line.
- *
- * @return The string that is read.
- */
- private String readLine() throws IOException
- {
- //First skip the whitespace
- StringBuffer buf = new StringBuffer();
- int nextByte = input.read();
- while( isWhitespace( nextByte ) )
- {
- nextByte = input.read();
- //do nothing just skip the whitespace.
- }
- buf.append( (char)nextByte );
-
- //now read the data
- while( !isEOL(nextByte = input.read()) )
- {
- buf.append( (char)nextByte );
- }
- return buf.toString();
- }
-
- /**
- * This will read a string from the input stream and stop at any whitespace.
- *
- * @return The string read from the stream.
- *
- * @throws IOException If an IO error occurs when reading from the stream.
- */
- private String readString() throws IOException
- {
- //First skip the whitespace
- StringBuffer buf = new StringBuffer();
- int nextByte = input.read();
- while( isWhitespace( nextByte ) )
- {
- nextByte = input.read();
- //do nothing just skip the whitespace.
- }
- buf.append( (char)nextByte );
-
- //now read the data
- while( !isWhitespace(nextByte = input.read()) )
- {
- buf.append( (char)nextByte );
- }
- return buf.toString();
- }
-
- /**
- * This will determine if the byte is a whitespace character or not.
- *
- * @param character The character to test for whitespace.
- *
- * @return true If the character is whitespace as defined by the AFM spec.
- */
- private boolean isEOL( int character )
- {
- return character == 0x0D ||
- character == 0x0A;
- }
-
- /**
- * This will determine if the byte is a whitespace character or not.
- *
- * @param character The character to test for whitespace.
- *
- * @return true If the character is whitespace as defined by the AFM spec.
- */
- private boolean isWhitespace( int character )
- {
- return character == ' ' ||
- character == '\t' ||
- character == 0x0D ||
- character == 0x0A;
- }
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CharMetric.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CharMetric.java
deleted file mode 100644
index 096eaa8aa..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CharMetric.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.fontbox.util.BoundingBox;
-
-/**
- * This class represents a single character metric.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class CharMetric
-{
- private int characterCode;
-
- private float wx;
- private float w0x;
- private float w1x;
-
- private float wy;
- private float w0y;
- private float w1y;
-
- private float[] w;
- private float[] w0;
- private float[] w1;
- private float[] vv;
-
- private String name;
- private BoundingBox boundingBox;
- private List ligatures = new ArrayList();
-
- /** Getter for property boundingBox.
- * @return Value of property boundingBox.
- */
- public BoundingBox getBoundingBox()
- {
- return boundingBox;
- }
-
- /** Setter for property boundingBox.
- * @param bBox New value of property boundingBox.
- */
- public void setBoundingBox(BoundingBox bBox)
- {
- boundingBox = bBox;
- }
-
- /** Getter for property characterCode.
- * @return Value of property characterCode.
- */
- public int getCharacterCode()
- {
- return characterCode;
- }
-
- /** Setter for property characterCode.
- * @param cCode New value of property characterCode.
- */
- public void setCharacterCode(int cCode)
- {
- characterCode = cCode;
- }
-
- /**
- * This will add an entry to the list of ligatures.
- *
- * @param ligature The ligature to add.
- */
- public void addLigature( Ligature ligature )
- {
- ligatures.add( ligature );
- }
-
- /** Getter for property ligatures.
- * @return Value of property ligatures.
- */
- public List getLigatures()
- {
- return ligatures;
- }
-
- /** Setter for property ligatures.
- * @param lig New value of property ligatures.
- */
- public void setLigatures(List lig)
- {
- this.ligatures = lig;
- }
-
- /** Getter for property name.
- * @return Value of property name.
- */
- public String getName()
- {
- return name;
- }
-
- /** Setter for property name.
- * @param n New value of property name.
- */
- public void setName(String n)
- {
- this.name = n;
- }
-
- /** Getter for property vv.
- * @return Value of property vv.
- */
- public float[] getVv()
- {
- return this.vv;
- }
-
- /** Setter for property vv.
- * @param vvValue New value of property vv.
- */
- public void setVv(float[] vvValue)
- {
- this.vv = vvValue;
- }
-
- /** Getter for property w.
- * @return Value of property w.
- */
- public float[] getW()
- {
- return this.w;
- }
-
- /** Setter for property w.
- * @param wValue New value of property w.
- */
- public void setW(float[] wValue)
- {
- this.w = wValue;
- }
-
- /** Getter for property w0.
- * @return Value of property w0.
- */
- public float[] getW0()
- {
- return this.w0;
- }
-
- /** Setter for property w0.
- * @param w0Value New value of property w0.
- */
- public void setW0(float[] w0Value)
- {
- w0 = w0Value;
- }
-
- /** Getter for property w0x.
- * @return Value of property w0x.
- */
- public float getW0x()
- {
- return w0x;
- }
-
- /** Setter for property w0x.
- * @param w0xValue New value of property w0x.
- */
- public void setW0x(float w0xValue)
- {
- w0x = w0xValue;
- }
-
- /** Getter for property w0y.
- * @return Value of property w0y.
- */
- public float getW0y()
- {
- return w0y;
- }
-
- /** Setter for property w0y.
- * @param w0yValue New value of property w0y.
- */
- public void setW0y(float w0yValue)
- {
- w0y = w0yValue;
- }
-
- /** Getter for property w1.
- * @return Value of property w1.
- */
- public float[] getW1()
- {
- return this.w1;
- }
-
- /** Setter for property w1.
- * @param w1Value New value of property w1.
- */
- public void setW1(float[] w1Value)
- {
- w1 = w1Value;
- }
-
- /** Getter for property w1x.
- * @return Value of property w1x.
- */
- public float getW1x()
- {
- return w1x;
- }
-
- /** Setter for property w1x.
- * @param w1xValue New value of property w1x.
- */
- public void setW1x(float w1xValue)
- {
- w1x = w1xValue;
- }
-
- /** Getter for property w1y.
- * @return Value of property w1y.
- */
- public float getW1y()
- {
- return w1y;
- }
-
- /** Setter for property w1y.
- * @param w1yValue New value of property w1y.
- */
- public void setW1y(float w1yValue)
- {
- w1y = w1yValue;
- }
-
- /** Getter for property wx.
- * @return Value of property wx.
- */
- public float getWx()
- {
- return wx;
- }
-
- /** Setter for property wx.
- * @param wxValue New value of property wx.
- */
- public void setWx(float wxValue)
- {
- wx = wxValue;
- }
-
- /** Getter for property wy.
- * @return Value of property wy.
- */
- public float getWy()
- {
- return wy;
- }
-
- /** Setter for property wy.
- * @param wyValue New value of property wy.
- */
- public void setWy(float wyValue)
- {
- this.wy = wyValue;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Composite.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Composite.java
deleted file mode 100644
index eb178330a..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Composite.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This class represents composite character data.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class Composite
-{
- private String name;
- private List parts = new ArrayList();
-
- /** Getter for property name.
- * @return Value of property name.
- */
- public String getName()
- {
- return name;
- }
-
- /** Setter for property name.
- * @param nameValue New value of property name.
- */
- public void setName(String nameValue)
- {
- this.name = nameValue;
- }
-
- /**
- * This will add a composite part.
- *
- * @param part The composite part to add.
- */
- public void addPart( CompositePart part )
- {
- parts.add( part );
- }
-
- /** Getter for property parts.
- * @return Value of property parts.
- */
- public List getParts()
- {
- return parts;
- }
-
- /** Setter for property parts.
- * @param partsList New value of property parts.
- */
- public void setParts(List partsList)
- {
- this.parts = partsList;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CompositePart.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CompositePart.java
deleted file mode 100644
index c9a4ea724..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/CompositePart.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-/**
- * This class represents a part of composite character data.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class CompositePart
-{
- private String name;
- private int xDisplacement;
- private int yDisplacement;
-
- /** Getter for property name.
- * @return Value of property name.
- */
- public java.lang.String getName()
- {
- return name;
- }
-
- /** Setter for property name.
- * @param nameValue New value of property name.
- */
- public void setName(String nameValue)
- {
- name = nameValue;
- }
-
- /** Getter for property xDisplacement.
- * @return Value of property xDisplacement.
- */
- public int getXDisplacement()
- {
- return xDisplacement;
- }
-
- /** Setter for property xDisplacement.
- * @param xDisp New value of property xDisplacement.
- */
- public void setXDisplacement(int xDisp)
- {
- xDisplacement = xDisp;
- }
-
- /** Getter for property yDisplacement.
- * @return Value of property yDisplacement.
- */
- public int getYDisplacement()
- {
- return yDisplacement;
- }
-
- /** Setter for property yDisplacement.
- * @param yDisp New value of property yDisplacement.
- */
- public void setYDisplacement(int yDisp)
- {
- yDisplacement = yDisp;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/FontMetric.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/FontMetric.java
deleted file mode 100644
index ca0d75c5c..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/FontMetric.java
+++ /dev/null
@@ -1,911 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-import java.io.IOException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.fontbox.util.BoundingBox;
-
-/**
- * This is the outermost AFM type. This can be created by the afmparser with a valid
- * AFM document.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.3 $
- */
-public class FontMetric
-{
- /**
- * This is the version of the FontMetrics.
- */
- private float afmVersion;
- private int metricSets = 0;
- private String fontName;
- private String fullName;
- private String familyName;
- private String weight;
- private BoundingBox fontBBox;
- private String fontVersion;
- private String notice;
- private String encodingScheme;
- private int mappingScheme;
- private int escChar;
- private String characterSet;
- private int characters;
- private boolean isBaseFont;
- private float[] vVector;
- private boolean isFixedV;
- private float capHeight;
- private float xHeight;
- private float ascender;
- private float descender;
- private List comments = new ArrayList();
-
- private float underlinePosition;
- private float underlineThickness;
- private float italicAngle;
- private float[] charWidth;
- private boolean isFixedPitch;
- private float standardHorizontalWidth;
- private float standardVerticalWidth;
-
- private List charMetrics = new ArrayList();
- private Map charMetricsMap = new HashMap();
- private List trackKern = new ArrayList();
- private List composites = new ArrayList();
- private List kernPairs = new ArrayList();
- private List kernPairs0 = new ArrayList();
- private List kernPairs1 = new ArrayList();
-
- /**
- * Constructor.
- */
- public FontMetric()
- {
- }
-
- /**
- * This will get the width of a character.
- *
- * @param name The character to get the width for.
- *
- * @return The width of the character.
- *
- * @throws IOException If this AFM file does not handle the character.
- */
- public float getCharacterWidth( String name ) throws IOException
- {
- float result = 0;
- CharMetric metric = charMetricsMap.get( name );
- if( metric == null )
- {
- result=0;
- //don't throw an exception right away.
- //throw new IOException( "Unknown AFM(" + getFullName() + ") characer '" + name + "'" );
- }
- else
- {
- result = metric.getWx();
- }
- return result;
- }
-
- /**
- * This will get the width of a character.
- *
- * @param name The character to get the width for.
- *
- * @return The width of the character.
- *
- * @throws IOException If this AFM file does not handle the character.
- */
- public float getCharacterHeight( String name ) throws IOException
- {
- float result = 0;
- CharMetric metric = charMetricsMap.get( name );
- if( metric == null )
- {
- result=0;
- //don't throw an exception right away.
- //throw new IOException( "Unknown AFM(" + getFullName() + ") characer '" + name + "'" );
- }
- else
- {
- if( metric.getWy() == 0 )
- {
- result = metric.getBoundingBox().getHeight();
- }
- else
- {
- result = metric.getWy();
- }
- }
- return result;
- }
-
-
- /**
- * This will get the average width of a character.
- *
- * @return The width of the character.
- *
- * @throws IOException If this AFM file does not handle the character.
- */
- public float getAverageCharacterWidth() throws IOException
- {
- float average = 0;
- float totalWidths = 0;
- float characterCount = 0;
- Iterator iter = charMetricsMap.values().iterator();
- while( iter.hasNext() )
- {
- CharMetric metric = iter.next();
- if( metric.getWx() > 0 )
- {
- totalWidths += metric.getWx();
- characterCount += 1;
- }
- }
- if( totalWidths > 0 )
- {
- average = totalWidths / characterCount;
- }
-
- return average;
- }
-
- /**
- * This will add a new comment.
- *
- * @param comment The comment to add to this metric.
- */
- public void addComment( String comment )
- {
- comments.add( comment );
- }
-
- /**
- * This will get all comments.
- *
- * @return The list of all comments.
- */
- public List getComments()
- {
- return comments;
- }
-
- /**
- * This will get the version of the AFM document.
- *
- * @return The version of the document.
- */
- public float getAFMVersion()
- {
- return afmVersion;
- }
-
- /**
- * This will get the metricSets attribute.
- *
- * @return The value of the metric sets.
- */
- public int getMetricSets()
- {
- return metricSets;
- }
-
- /**
- * This will set the version of the AFM document.
- *
- * @param afmVersionValue The version of the document.
- */
- public void setAFMVersion( float afmVersionValue )
- {
- afmVersion = afmVersionValue;
- }
-
- /**
- * This will set the metricSets attribute. This value must be 0,1, or 2.
- *
- * @param metricSetsValue The new metric sets attribute.
- */
- public void setMetricSets( int metricSetsValue )
- {
- if( metricSetsValue < 0 || metricSetsValue > 2 )
- {
- throw new RuntimeException( "The metricSets attribute must be in the " +
- "set {0,1,2} and not '" + metricSetsValue + "'" );
- }
- metricSets = metricSetsValue;
- }
-
- /**
- * Getter for property fontName.
- *
- * @return Value of property fontName.
- */
- public String getFontName()
- {
- return fontName;
- }
-
- /**
- * Setter for property fontName.
- *
- * @param name New value of property fontName.
- */
- public void setFontName(String name)
- {
- fontName = name;
- }
-
- /**
- * Getter for property fullName.
- *
- * @return Value of property fullName.
- */
- public String getFullName()
- {
- return fullName;
- }
-
- /**
- * Setter for property fullName.
- *
- * @param fullNameValue New value of property fullName.
- */
- public void setFullName(String fullNameValue)
- {
- fullName = fullNameValue;
- }
-
- /**
- * Getter for property familyName.
- *
- * @return Value of property familyName.
- */
- public String getFamilyName()
- {
- return familyName;
- }
-
- /**
- * Setter for property familyName.
- *
- * @param familyNameValue New value of property familyName.
- */
- public void setFamilyName(String familyNameValue)
- {
- familyName = familyNameValue;
- }
-
- /**
- * Getter for property weight.
- *
- * @return Value of property weight.
- */
- public String getWeight()
- {
- return weight;
- }
-
- /**
- * Setter for property weight.
- *
- * @param weightValue New value of property weight.
- */
- public void setWeight(String weightValue)
- {
- weight = weightValue;
- }
-
- /**
- * Getter for property fontBBox.
- *
- * @return Value of property fontBBox.
- */
- public BoundingBox getFontBBox()
- {
- return fontBBox;
- }
-
- /**
- * Setter for property fontBBox.
- *
- * @param bBox New value of property fontBBox.
- */
- public void setFontBBox(BoundingBox bBox)
- {
- this.fontBBox = bBox;
- }
-
- /**
- * Getter for property notice.
- *
- * @return Value of property notice.
- */
- public String getNotice()
- {
- return notice;
- }
-
- /**
- * Setter for property notice.
- *
- * @param noticeValue New value of property notice.
- */
- public void setNotice(String noticeValue)
- {
- notice = noticeValue;
- }
-
- /**
- * Getter for property encodingScheme.
- *
- * @return Value of property encodingScheme.
- */
- public String getEncodingScheme()
- {
- return encodingScheme;
- }
-
- /**
- * Setter for property encodingScheme.
- *
- * @param encodingSchemeValue New value of property encodingScheme.
- */
- public void setEncodingScheme(String encodingSchemeValue)
- {
- encodingScheme = encodingSchemeValue;
- }
-
- /**
- * Getter for property mappingScheme.
- *
- * @return Value of property mappingScheme.
- */
- public int getMappingScheme()
- {
- return mappingScheme;
- }
-
- /**
- * Setter for property mappingScheme.
- *
- * @param mappingSchemeValue New value of property mappingScheme.
- */
- public void setMappingScheme(int mappingSchemeValue)
- {
- mappingScheme = mappingSchemeValue;
- }
-
- /**
- * Getter for property escChar.
- *
- * @return Value of property escChar.
- */
- public int getEscChar()
- {
- return escChar;
- }
-
- /**
- * Setter for property escChar.
- *
- * @param escCharValue New value of property escChar.
- */
- public void setEscChar(int escCharValue)
- {
- escChar = escCharValue;
- }
-
- /**
- * Getter for property characterSet.
- *
- * @return Value of property characterSet.
- */
- public String getCharacterSet()
- {
- return characterSet;
- }
-
- /**
- * Setter for property characterSet.
- *
- * @param characterSetValue New value of property characterSet.
- */
- public void setCharacterSet(String characterSetValue)
- {
- characterSet = characterSetValue;
- }
-
- /**
- * Getter for property characters.
- *
- * @return Value of property characters.
- */
- public int getCharacters()
- {
- return characters;
- }
-
- /**
- * Setter for property characters.
- *
- * @param charactersValue New value of property characters.
- */
- public void setCharacters(int charactersValue)
- {
- characters = charactersValue;
- }
-
- /**
- * Getter for property isBaseFont.
- *
- * @return Value of property isBaseFont.
- */
- public boolean isBaseFont()
- {
- return isBaseFont;
- }
-
- /**
- * Setter for property isBaseFont.
- *
- * @param isBaseFontValue New value of property isBaseFont.
- */
- public void setIsBaseFont(boolean isBaseFontValue)
- {
- isBaseFont = isBaseFontValue;
- }
-
- /**
- * Getter for property vVector.
- *
- * @return Value of property vVector.
- */
- public float[] getVVector()
- {
- return this.vVector;
- }
-
- /**
- * Setter for property vVector.
- *
- * @param vVectorValue New value of property vVector.
- */
- public void setVVector(float[] vVectorValue)
- {
- vVector = vVectorValue;
- }
-
- /**
- * Getter for property isFixedV.
- *
- * @return Value of property isFixedV.
- */
- public boolean isFixedV()
- {
- return isFixedV;
- }
-
- /**
- * Setter for property isFixedV.
- *
- * @param isFixedVValue New value of property isFixedV.
- */
- public void setIsFixedV(boolean isFixedVValue)
- {
- isFixedV = isFixedVValue;
- }
-
- /**
- * Getter for property capHeight.
- *
- * @return Value of property capHeight.
- */
- public float getCapHeight()
- {
- return capHeight;
- }
-
- /**
- * Setter for property capHeight.
- *
- * @param capHeightValue New value of property capHeight.
- */
- public void setCapHeight(float capHeightValue)
- {
- capHeight = capHeightValue;
- }
-
- /**
- * Getter for property xHeight.
- *
- * @return Value of property xHeight.
- */
- public float getXHeight()
- {
- return xHeight;
- }
-
- /**
- * Setter for property xHeight.
- *
- * @param xHeightValue New value of property xHeight.
- */
- public void setXHeight( float xHeightValue )
- {
- xHeight = xHeightValue;
- }
-
- /**
- * Getter for property ascender.
- *
- * @return Value of property ascender.
- */
- public float getAscender()
- {
- return ascender;
- }
-
- /**
- * Setter for property ascender.
- *
- * @param ascenderValue New value of property ascender.
- */
- public void setAscender( float ascenderValue )
- {
- ascender = ascenderValue;
- }
-
- /**
- * Getter for property descender.
- *
- * @return Value of property descender.
- */
- public float getDescender()
- {
- return descender;
- }
-
- /**
- * Setter for property descender.
- *
- * @param descenderValue New value of property descender.
- */
- public void setDescender( float descenderValue )
- {
- descender = descenderValue;
- }
-
- /**
- * Getter for property fontVersion.
- *
- * @return Value of property fontVersion.
- */
- public String getFontVersion()
- {
- return fontVersion;
- }
-
- /**
- * Setter for property fontVersion.
- *
- * @param fontVersionValue New value of property fontVersion.
- */
- public void setFontVersion(String fontVersionValue)
- {
- fontVersion = fontVersionValue;
- }
-
- /**
- * Getter for property underlinePosition.
- *
- * @return Value of property underlinePosition.
- */
- public float getUnderlinePosition()
- {
- return underlinePosition;
- }
-
- /**
- * Setter for property underlinePosition.
- *
- * @param underlinePositionValue New value of property underlinePosition.
- */
- public void setUnderlinePosition(float underlinePositionValue)
- {
- underlinePosition = underlinePositionValue;
- }
-
- /**
- * Getter for property underlineThickness.
- *
- * @return Value of property underlineThickness.
- */
- public float getUnderlineThickness()
- {
- return underlineThickness;
- }
-
- /**
- * Setter for property underlineThickness.
- *
- * @param underlineThicknessValue New value of property underlineThickness.
- */
- public void setUnderlineThickness(float underlineThicknessValue)
- {
- underlineThickness = underlineThicknessValue;
- }
-
- /**
- * Getter for property italicAngle.
- *
- * @return Value of property italicAngle.
- */
- public float getItalicAngle()
- {
- return italicAngle;
- }
-
- /**
- * Setter for property italicAngle.
- *
- * @param italicAngleValue New value of property italicAngle.
- */
- public void setItalicAngle(float italicAngleValue)
- {
- italicAngle = italicAngleValue;
- }
-
- /**
- * Getter for property charWidth.
- *
- * @return Value of property charWidth.
- */
- public float[] getCharWidth()
- {
- return this.charWidth;
- }
-
- /**
- * Setter for property charWidth.
- *
- * @param charWidthValue New value of property charWidth.
- */
- public void setCharWidth(float[] charWidthValue)
- {
- charWidth = charWidthValue;
- }
-
- /**
- * Getter for property isFixedPitch.
- *
- * @return Value of property isFixedPitch.
- */
- public boolean isFixedPitch()
- {
- return isFixedPitch;
- }
-
- /**
- * Setter for property isFixedPitch.
- *
- * @param isFixedPitchValue New value of property isFixedPitch.
- */
- public void setFixedPitch(boolean isFixedPitchValue)
- {
- isFixedPitch = isFixedPitchValue;
- }
-
- /** Getter for property charMetrics.
- * @return Value of property charMetrics.
- */
- public List getCharMetrics()
- {
- return charMetrics;
- }
-
- /** Setter for property charMetrics.
- * @param charMetricsValue New value of property charMetrics.
- */
- public void setCharMetrics(List charMetricsValue)
- {
- charMetrics = charMetricsValue;
- }
-
- /**
- * This will add another character metric.
- *
- * @param metric The character metric to add.
- */
- public void addCharMetric( CharMetric metric )
- {
- charMetrics.add( metric );
- charMetricsMap.put( metric.getName(), metric );
- }
-
- /** Getter for property trackKern.
- * @return Value of property trackKern.
- */
- public List getTrackKern()
- {
- return trackKern;
- }
-
- /** Setter for property trackKern.
- * @param trackKernValue New value of property trackKern.
- */
- public void setTrackKern(List trackKernValue)
- {
- trackKern = trackKernValue;
- }
-
- /**
- * This will add another track kern.
- *
- * @param kern The track kerning data.
- */
- public void addTrackKern( TrackKern kern )
- {
- trackKern.add( kern );
- }
-
- /** Getter for property composites.
- * @return Value of property composites.
- */
- public List getComposites()
- {
- return composites;
- }
-
- /** Setter for property composites.
- * @param compositesList New value of property composites.
- */
- public void setComposites(List compositesList)
- {
- composites = compositesList;
- }
-
- /**
- * This will add a single composite part to the picture.
- *
- * @param composite The composite info to add.
- */
- public void addComposite( Composite composite )
- {
- composites.add( composite );
- }
-
- /** Getter for property kernPairs.
- * @return Value of property kernPairs.
- */
- public List getKernPairs()
- {
- return kernPairs;
- }
-
- /**
- * This will add a kern pair.
- *
- * @param kernPair The kern pair to add.
- */
- public void addKernPair( KernPair kernPair )
- {
- kernPairs.add( kernPair );
- }
-
- /** Setter for property kernPairs.
- * @param kernPairsList New value of property kernPairs.
- */
- public void setKernPairs(List kernPairsList)
- {
- kernPairs = kernPairsList;
- }
-
- /** Getter for property kernPairs0.
- * @return Value of property kernPairs0.
- */
- public List getKernPairs0()
- {
- return kernPairs0;
- }
-
- /**
- * This will add a kern pair.
- *
- * @param kernPair The kern pair to add.
- */
- public void addKernPair0( KernPair kernPair )
- {
- kernPairs0.add( kernPair );
- }
-
- /** Setter for property kernPairs0.
- * @param kernPairs0List New value of property kernPairs0.
- */
- public void setKernPairs0(List kernPairs0List)
- {
- kernPairs0 = kernPairs0List;
- }
-
- /** Getter for property kernPairs1.
- * @return Value of property kernPairs1.
- */
- public List getKernPairs1()
- {
- return kernPairs1;
- }
-
- /**
- * This will add a kern pair.
- *
- * @param kernPair The kern pair to add.
- */
- public void addKernPair1( KernPair kernPair )
- {
- kernPairs1.add( kernPair );
- }
-
- /** Setter for property kernPairs1.
- * @param kernPairs1List New value of property kernPairs1.
- */
- public void setKernPairs1(List kernPairs1List)
- {
- kernPairs1 = kernPairs1List;
- }
-
- /** Getter for property standardHorizontalWidth.
- * @return Value of property standardHorizontalWidth.
- */
- public float getStandardHorizontalWidth()
- {
- return standardHorizontalWidth;
- }
-
- /** Setter for property standardHorizontalWidth.
- * @param standardHorizontalWidthValue New value of property standardHorizontalWidth.
- */
- public void setStandardHorizontalWidth(float standardHorizontalWidthValue)
- {
- standardHorizontalWidth = standardHorizontalWidthValue;
- }
-
- /** Getter for property standardVerticalWidth.
- * @return Value of property standardVerticalWidth.
- */
- public float getStandardVerticalWidth()
- {
- return standardVerticalWidth;
- }
-
- /** Setter for property standardVerticalWidth.
- * @param standardVerticalWidthValue New value of property standardVerticalWidth.
- */
- public void setStandardVerticalWidth(float standardVerticalWidthValue)
- {
- standardVerticalWidth = standardVerticalWidthValue;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/KernPair.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/KernPair.java
deleted file mode 100644
index 38103bdec..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/KernPair.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-/**
- * This represents some kern pair data.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class KernPair
-{
- private String firstKernCharacter;
- private String secondKernCharacter;
- private float x;
- private float y;
-
- /** Getter for property firstKernCharacter.
- * @return Value of property firstKernCharacter.
- */
- public java.lang.String getFirstKernCharacter()
- {
- return firstKernCharacter;
- }
-
- /** Setter for property firstKernCharacter.
- * @param firstKernCharacterValue New value of property firstKernCharacter.
- */
- public void setFirstKernCharacter(String firstKernCharacterValue)
- {
- firstKernCharacter = firstKernCharacterValue;
- }
-
- /** Getter for property secondKernCharacter.
- * @return Value of property secondKernCharacter.
- */
- public java.lang.String getSecondKernCharacter()
- {
- return secondKernCharacter;
- }
-
- /** Setter for property secondKernCharacter.
- * @param secondKernCharacterValue New value of property secondKernCharacter.
- */
- public void setSecondKernCharacter(String secondKernCharacterValue)
- {
- secondKernCharacter = secondKernCharacterValue;
- }
-
- /** Getter for property x.
- * @return Value of property x.
- */
- public float getX()
- {
- return x;
- }
-
- /** Setter for property x.
- * @param xValue New value of property x.
- */
- public void setX(float xValue)
- {
- x = xValue;
- }
-
- /** Getter for property y.
- * @return Value of property y.
- */
- public float getY()
- {
- return y;
- }
-
- /** Setter for property y.
- * @param yValue New value of property y.
- */
- public void setY(float yValue)
- {
- y = yValue;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Ligature.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Ligature.java
deleted file mode 100644
index 3fbcad31f..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/Ligature.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-/**
- * This class represents a ligature, which is an entry of the CharMetrics.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class Ligature
-{
- private String successor;
- private String ligature;
-
- /** Getter for property ligature.
- * @return Value of property ligature.
- */
- public String getLigature()
- {
- return ligature;
- }
-
- /** Setter for property ligature.
- * @param lig New value of property ligature.
- */
- public void setLigature(String lig)
- {
- ligature = lig;
- }
-
- /** Getter for property successor.
- * @return Value of property successor.
- */
- public String getSuccessor()
- {
- return successor;
- }
-
- /** Setter for property successor.
- * @param successorValue New value of property successor.
- */
- public void setSuccessor(String successorValue)
- {
- successor = successorValue;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/TrackKern.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/TrackKern.java
deleted file mode 100644
index 26672a4f3..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/TrackKern.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.fontbox.afm;
-
-/**
- * This class represents a piece of track kerning data.
- *
- * @author Ben Litchfield (ben@benlitchfield.com)
- * @version $Revision: 1.1 $
- */
-public class TrackKern
-{
- private int degree;
- private float minPointSize;
- private float minKern;
- private float maxPointSize;
- private float maxKern;
-
- /** Getter for property degree.
- * @return Value of property degree.
- */
- public int getDegree()
- {
- return degree;
- }
-
- /** Setter for property degree.
- * @param degreeValue New value of property degree.
- */
- public void setDegree(int degreeValue)
- {
- degree = degreeValue;
- }
-
- /** Getter for property maxKern.
- * @return Value of property maxKern.
- */
- public float getMaxKern()
- {
- return maxKern;
- }
-
- /** Setter for property maxKern.
- * @param maxKernValue New value of property maxKern.
- */
- public void setMaxKern(float maxKernValue)
- {
- maxKern = maxKernValue;
- }
-
- /** Getter for property maxPointSize.
- * @return Value of property maxPointSize.
- */
- public float getMaxPointSize()
- {
- return maxPointSize;
- }
-
- /** Setter for property maxPointSize.
- * @param maxPointSizeValue New value of property maxPointSize.
- */
- public void setMaxPointSize(float maxPointSizeValue)
- {
- maxPointSize = maxPointSizeValue;
- }
-
- /** Getter for property minKern.
- * @return Value of property minKern.
- */
- public float getMinKern()
- {
- return minKern;
- }
-
- /** Setter for property minKern.
- * @param minKernValue New value of property minKern.
- */
- public void setMinKern(float minKernValue)
- {
- minKern = minKernValue;
- }
-
- /** Getter for property minPointSize.
- * @return Value of property minPointSize.
- */
- public float getMinPointSize()
- {
- return minPointSize;
- }
-
- /** Setter for property minPointSize.
- * @param minPointSizeValue New value of property minPointSize.
- */
- public void setMinPointSize(float minPointSizeValue)
- {
- minPointSize = minPointSizeValue;
- }
-
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/package.html b/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/package.html
deleted file mode 100644
index 223f7ccc0..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/afm/package.html
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-This package holds classes used to parse AFM(Adobe Font Metrics) files.
-
-More information about AFM files can be found at
-http://partners.adobe.com/asn/developer/type/
-
-
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/AFMFormatter.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/AFMFormatter.java
deleted file mode 100644
index c681923c0..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/AFMFormatter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.fontbox.cff;
-
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.fontbox.cff.encoding.CFFEncoding;
-
-/**
- * This class creates all needed AFM font metric data from a CFFFont ready to be read from a AFMPaser.
- *
- * @author Villu Ruusmann
- * @version $Revision$
- */
-public class AFMFormatter
-{
-
- private AFMFormatter()
- {
- }
-
- /**
- * Create font metric data for the given CFFFont.
- * @param font the CFFFont
- * @return the created font metric data
- * @throws IOException if an error occurs during reading
- */
- public static byte[] format(CFFFont font) throws IOException
- {
- DataOutput output = new DataOutput();
- printFont(font, output);
- return output.getBytes();
- }
-
- private static void printFont(CFFFont font, DataOutput output)
- throws IOException
- {
- printFontMetrics(font, output);
- }
-
- @SuppressWarnings(value = { "unchecked" })
- private static void printFontMetrics(CFFFont font, DataOutput output)
- throws IOException
- {
- List metrics = renderFont(font);
- output.println("StartFontMetrics 2.0");
- output.println("FontName " + font.getName());
- output.println("FullName " + font.getProperty("FullName"));
- output.println("FamilyName " + font.getProperty("FamilyName"));
- output.println("Weight " + font.getProperty("Weight"));
- CFFEncoding encoding = font.getEncoding();
- if (encoding.isFontSpecific())
- {
- output.println("EncodingScheme FontSpecific");
- }
- Rectangle2D bounds = getBounds(metrics);
- output.println("FontBBox " + (int)bounds.getX() + " " + (int)bounds.getY()
- + " " + (int)bounds.getMaxX() + " " + (int)bounds.getMaxY());
- printDirectionMetrics(font, output);
- printCharMetrics(font, metrics, output);
- output.println("EndFontMetrics");
- }
-
- private static void printDirectionMetrics(CFFFont font, DataOutput output)
- throws IOException
- {
- output.println("UnderlinePosition "
- + font.getProperty("UnderlinePosition"));
- output.println("UnderlineThickness "
- + font.getProperty("UnderlineThickness"));
- output.println("ItalicAngle " + font.getProperty("ItalicAngle"));
- output.println("IsFixedPitch " + font.getProperty("isFixedPitch"));
- }
-
- private static void printCharMetrics(CFFFont font, List metrics, DataOutput output)
- throws IOException
- {
- output.println("StartCharMetrics " + metrics.size());
- Collections.sort(metrics);
- for (CharMetric metric : metrics)
- {
- output.print("C " + metric.code + " ;");
- output.print(" ");
- output.print("WX " + metric.width + " ;");
- output.print(" ");
- output.print("N " + metric.name + " ;");
- output.print(" ");
- output.print("B " + (int) metric.bounds.getX() + " "
- + (int) metric.bounds.getY() + " "
- + (int) metric.bounds.getMaxX() + " "
- + (int) metric.bounds.getMaxY() + " ;");
- output.println();
- }
- output.println("EndCharMetrics");
- }
-
- private static List renderFont(CFFFont font) throws IOException
- {
- List metrics = new ArrayList();
- CharStringRenderer renderer = font.createRenderer();
- Collection mappings = font.getMappings();
- for (CFFFont.Mapping mapping : mappings)
- {
- CharMetric metric = new CharMetric();
- metric.code = mapping.getCode();
- metric.name = mapping.getName();
- renderer.render(mapping.toType1Sequence());
- metric.width = renderer.getWidth();
- metric.bounds = renderer.getBounds();
- metrics.add(metric);
- }
- return metrics;
- }
-
- private static Rectangle2D getBounds(List metrics)
- {
- Rectangle2D bounds = null;
- for(CharMetric metric : metrics)
- {
- if(bounds == null)
- {
- bounds = new Rectangle2D.Double();
- bounds.setFrame(metric.bounds);
- }
- else
- {
- Rectangle2D.union(bounds, metric.bounds, bounds);
- }
- }
- return bounds;
- }
-
- /**
- * This class represents the metric of one single character.
- *
- */
- private static class CharMetric implements Comparable
- {
- private int code;
- private String name;
- private int width;
- private Rectangle2D bounds;
-
- public int compareTo(CharMetric that)
- {
- return code - that.code;
- }
- }
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFDataInput.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFDataInput.java
deleted file mode 100644
index 358c221a8..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFDataInput.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.fontbox.cff;
-
-import java.io.IOException;
-
-/**
- * This is specialized DataInput. It's used to parse a CFFFont.
- *
- * @author Villu Ruusmann
- * @version $Revision$
- */
-public class CFFDataInput extends DataInput
-{
-
- /**
- * Constructor.
- * @param buffer the buffer to be read
- */
- public CFFDataInput(byte[] buffer)
- {
- super(buffer);
- }
-
- /**
- * Read one single Card8 value from the buffer.
- * @return the card8 value
- * @throws IOException if an error occurs during reading
- */
- public int readCard8() throws IOException
- {
- return readUnsignedByte();
- }
-
- /**
- * Read one single Card16 value from the buffer.
- * @return the card16 value
- * @throws IOException if an error occurs during reading
- */
- public int readCard16() throws IOException
- {
- return readUnsignedShort();
- }
-
- /**
- * Read the offset from the buffer.
- * @param offSize the given offsize
- * @return the offset
- * @throws IOException if an error occurs during reading
- */
- public int readOffset(int offSize) throws IOException
- {
- int value = 0;
- for (int i = 0; i < offSize; i++)
- {
- value = value << 8 | readUnsignedByte();
- }
- return value;
- }
-
- /**
- * Read the offsize from the buffer.
- * @return the offsize
- * @throws IOException if an error occurs during reading
- */
- public int readOffSize() throws IOException
- {
- return readUnsignedByte();
- }
-
- /**
- * Read a SID from the buffer.
- * @return the SID
- * @throws IOException if an error occurs during reading
- */
- public int readSID() throws IOException
- {
- return readUnsignedShort();
- }
-}
\ No newline at end of file
diff --git a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFFont.java b/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFFont.java
deleted file mode 100644
index 0434328fd..000000000
--- a/fluidbook/tools/fwstk/src/org/apache/fontbox/cff/CFFFont.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * 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.fontbox.cff;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.fontbox.cff.IndexData;
-import org.apache.fontbox.cff.charset.CFFCharset;
-import org.apache.fontbox.cff.encoding.CFFEncoding;
-
-/**
- * This class represents a CFF/Type2 Font.
- *
- * @author Villu Ruusmann
- * @version $Revision$
- */
-public class CFFFont
-{
-
- private String fontname = null;
- private Map topDict = new LinkedHashMap();
- private Map privateDict = new LinkedHashMap();
- private CFFEncoding fontEncoding = null;
- private CFFCharset fontCharset = null;
- private Map charStringsDict = new LinkedHashMap();
- private IndexData globalSubrIndex = null;
- private IndexData localSubrIndex = null;
-
- /**
- * The name of the font.
- * @return the name of the font
- */
- public String getName()
- {
- return fontname;
- }
-
- /**
- * Sets the name of the font.
- * @param name the name of the font
- */
- public void setName(String name)
- {
- fontname = name;
- }
-
- /**
- * Returns the value for the given name from the dictionary.
- * @param name the name of the value
- * @return the value of the name if available
- */
- public Object getProperty(String name)
- {
- Object topDictValue = topDict.get(name);
- if (topDictValue != null)
- {
- return topDictValue;
- }
- Object privateDictValue = privateDict.get(name);
- if (privateDictValue != null)
- {
- return privateDictValue;
- }
- return null;
- }
-
- /**
- * Adds the given key/value pair to the top dictionary.
- * @param name the given key
- * @param value the given value
- */
- public void addValueToTopDict(String name, Object value)
- {
- if (value != null)
- {
- topDict.put(name, value);
- }
- }
- /**
- * Returns the top dictionary.
- * @return the dictionary
- */
- public Map getTopDict()
- {
- return topDict;
- }
-
- /**
- * Adds the given key/value pair to the private dictionary.
- * @param name the given key
- * @param value the given value
- */
- public void addValueToPrivateDict(String name, Object value)
- {
- if (value != null)
- {
- privateDict.put(name, value);
- }
- }
- /**
- * Returns the private dictionary.
- * @return the dictionary
- */
- public Map getPrivateDict()
- {
- return privateDict;
- }
-
- /**
- * Get the mapping (code/SID/charname/bytes) for this font.
- * @return mappings for codes < 256 and for codes > = 256
- */
- public Collection getMappings()
- {
- List mappings = new ArrayList();
- Set mappedNames = new HashSet();
- for (CFFEncoding.Entry entry : fontEncoding.getEntries())
- {
- String charName = fontCharset.getName(entry.getSID());
- // Predefined encoding
- if (charName == null)
- {
- continue;
- }
- byte[] bytes = charStringsDict.get(charName);
- if (bytes == null)
- {
- continue;
- }
- Mapping mapping = new Mapping();
- mapping.setCode(entry.getCode());
- mapping.setSID(entry.getSID());
- mapping.setName(charName);
- mapping.setBytes(bytes);
- mappings.add(mapping);
- mappedNames.add(charName);
- }
- if (fontEncoding instanceof CFFParser.EmbeddedEncoding)
- {
- CFFParser.EmbeddedEncoding embeddedEncoding = (CFFParser.EmbeddedEncoding)fontEncoding;
-
- for (CFFParser.EmbeddedEncoding.Supplement supplement : embeddedEncoding.getSupplements())
- {
- String charName = fontCharset.getName(supplement.getGlyph());
- if (charName == null)
- {
- continue;
- }
- byte[] bytes = charStringsDict.get(charName);
- if (bytes == null)
- {
- continue;
- }
- Mapping mapping = new Mapping();
- mapping.setCode(supplement.getCode());
- mapping.setSID(supplement.getGlyph());
- mapping.setName(charName);
- mapping.setBytes(bytes);
- mappings.add(mapping);
- mappedNames.add(charName);
- }
- }
- // XXX
- int code = 256;
- for (CFFCharset.Entry entry : fontCharset.getEntries())
- {
- String name = entry.getName();
- if (mappedNames.contains(name))
- {
- continue;
- }
- byte[] bytes = this.charStringsDict.get(name);
- if (bytes == null)
- {
- continue;
- }
- Mapping mapping = new Mapping();
- mapping.setCode(code++);
- mapping.setSID(entry.getSID());
- mapping.setName(name);
- mapping.setBytes(bytes);
-
- mappings.add(mapping);
-
- mappedNames.add(name);
- }
- return mappings;
- }
-
- /**
- * Return the Width value of the given Glyph identifier
- *
- * @param SID
- * @return -1 if the SID is missing from the Font.
- * @throws IOException
- */
- public int getWidth(int SID) throws IOException {
- int nominalWidth = privateDict.containsKey("nominalWidthX") ? ((Number)privateDict.get("nominalWidthX")).intValue() : 0;
- int defaultWidth = privateDict.containsKey("defaultWidthX") ? ((Number)privateDict.get("defaultWidthX")).intValue() : 1000 ;
- for (Mapping m : getMappings() ){
- if (m.getSID() == SID) {
-
- CharStringRenderer csr = null;
- if (((Number)getProperty("CharstringType")).intValue() == 2 ) {
- List