cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [64/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/BufferedOutputStream.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/BufferedOutputStream.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/BufferedOutputStream.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/BufferedOutputStream.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,167 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * This class is like the {@link java.io.BufferedOutputStream} but it
+ * extends it with a logic to count the number of bytes written to
+ * the output stream.
+ * 
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: BufferedOutputStream.java 179240 2005-05-31 17:37:23Z cziegeler $
+ * @since   2.1
+ */
+public final class BufferedOutputStream extends FilterOutputStream {
+    
+    protected byte buf[];
+
+    protected int count;
+    
+    /**
+     * Creates a new buffered output stream to write data to the 
+     * specified underlying output stream with a default 8192-byte
+     * buffer size.
+     *
+     * @param   out   the underlying output stream.
+     */
+    public BufferedOutputStream(OutputStream out) {
+        this(out, 8192);
+    }
+
+    /**
+     * Creates a new buffered output stream to write data to the 
+     * specified underlying output stream with the specified buffer 
+     * size. 
+     *
+     * @param   out    the underlying output stream.
+     * @param   size   the buffer size.
+     * @exception IllegalArgumentException if size <= 0.
+     */
+    public BufferedOutputStream(OutputStream out, int size) {
+        super(out);
+        if (size <= 0) {
+            throw new IllegalArgumentException("Buffer size <= 0");
+        }
+        this.buf = new byte[size];
+    }
+
+    /**
+     * Writes the specified byte to this buffered output stream. 
+     *
+     * @param      b   the byte to be written.
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public void write(int b) throws IOException {
+        if (this.count >= this.buf.length) {
+            this.incBuffer();
+        }
+        this.buf[count++] = (byte)b;
+    }
+
+    /**
+     * Writes <code>len</code> bytes from the specified byte array 
+     * starting at offset <code>off</code> to this buffered output stream.
+     *
+     * <p> Ordinarily this method stores bytes from the given array into this
+     * stream's buffer, flushing the buffer to the underlying output stream as
+     * needed.  If the requested length is at least as large as this stream's
+     * buffer, however, then this method will flush the buffer and write the
+     * bytes directly to the underlying output stream.  Thus redundant
+     * <code>BufferedOutputStream</code>s will not copy data unnecessarily.
+     *
+     * @param      b     the data.
+     * @param      off   the start offset in the data.
+     * @param      len   the number of bytes to write.
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public void write(byte b[], int off, int len) throws IOException {
+        while (len > buf.length - count) {
+            this.incBuffer();
+        }
+        System.arraycopy(b, off, buf, count, len);
+        count += len;
+    }
+
+    /**
+     * Flushes this buffered output stream. 
+     * We don't flush here, flushing is done during closing.
+     *
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public void flush() throws IOException {
+        // nothing
+    }
+
+    /**
+     * Closes this buffered output stream.
+     * Flush before closing.
+     *
+     * @exception  IOException  if an I/O error occurs.
+     */
+    public void close() throws IOException {
+        realFlush();
+        super.close ();
+    }
+
+    /**
+     * Flushes this buffered output stream. 
+     */
+    public void realFlush() throws IOException {
+        this.writeBuffer();
+        this.out.flush();
+    }
+    
+    /**
+     * Write the buffer
+     */
+    private void writeBuffer() 
+    throws IOException {
+        if (this.count > 0) {
+            this.out.write(this.buf, 0, this.count);
+            this.clearBuffer();
+        }
+    }
+
+    /**
+     * Increment the buffer
+     */
+    private void incBuffer() {
+        // currently we double the buffer size
+        // this is not so fast but is a very simple logic
+        byte[] newBuf = new byte[this.buf.length * 2];
+        System.arraycopy(this.buf, 0, newBuf, 0, this.buf.length);
+        this.buf = newBuf;
+    }
+    
+    /**
+     * Clear/reset the buffer
+     */
+    public void clearBuffer() {
+        this.count = 0;
+    }
+
+    /**
+     * Return the size of the current buffer
+     */
+    public int getCount() {
+        return this.count;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/BufferedOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ByteRange.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ByteRange.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ByteRange.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ByteRange.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+/**
+ * @author <a href="mailto:stuart.roebuck@adolos.co.uk">Stuart Roebuck</a>
+ * @version CVS $Id: ByteRange.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+final public class ByteRange {
+
+    
+    private final long start;
+    private final long end;
+
+    
+    public ByteRange(long start, long end) {
+        this.start = start;
+        this.end = end;
+    }
+
+    
+    public ByteRange(String string) throws NumberFormatException {
+        string = string.trim();
+        int dashPos = string.indexOf('-');
+        int length = string.length();
+        if (string.indexOf(',') != -1) {
+            throw new NumberFormatException("Simple ByteRange String contains a comma.");
+        }
+        if (dashPos > 0) {
+            this.start = Integer.parseInt(string.substring(0, dashPos));
+        } else {
+            this.start = Long.MIN_VALUE;
+        }
+        if (dashPos < length - 1) {
+            this.end = Integer.parseInt(string.substring(dashPos + 1, length));
+        } else {
+            this.end = Long.MAX_VALUE;
+        }
+        if (this.start > this.end) {
+            throw new NumberFormatException("Start value is greater than end value.");
+        }
+    }
+
+    
+    public long getStart() {
+        return this.start;
+    }
+
+    
+    public long getEnd() {
+        return this.end;
+    }
+
+    
+    public long length() {
+        return this.end - this.start + 1;
+    }
+
+    
+    public ByteRange intersection(ByteRange range) {
+        if (range.end < this.start || this.end < range.start) {
+            return null;
+        } else {
+            long start = (this.start > range.start) ? this.start : range.start;
+            long end = (this.end < range.end) ? this.end : range.end;
+            return new ByteRange(start, end);
+        }
+    }
+
+
+    public String toString() {
+        return this.start + "-" + this.end;
+    }
+
+    
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ByteRange.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ClassUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ClassUtils.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ClassUtils.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ClassUtils.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * A collection of class management utility methods.
+ *
+ * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: ClassUtils.java 160568 2005-04-08 17:33:05Z sylvain $
+ */
+public class ClassUtils {
+
+    /**
+     * Create a new instance given a class name
+     *
+     * @param className A class name
+     * @return A new instance
+     * @exception Exception If an instantiation error occurs
+     */
+    public static Object newInstance(String className) throws Exception {
+        return ClassUtils.loadClass(className).newInstance();
+    }
+
+    /**
+     * Load a class given its name.
+     * BL: We wan't to use a known ClassLoader--hopefully the heirarchy
+     *     is set correctly.
+     *
+     * @param className A class name
+     * @return The class pointed to by <code>className</code>
+     * @exception ClassNotFoundException If a loading error occurs
+     */
+    public static Class loadClass(String className) throws ClassNotFoundException {
+        return ClassUtils.getClassLoader().loadClass(className);
+    }
+
+    /**
+     * Return a resource URL.
+     * BL: if this is command line operation, the classloading issues
+     *     are more sane.  During servlet execution, we explicitly set
+     *     the ClassLoader.
+     *
+     * @return The context classloader.
+     * @exception MalformedURLException If a loading error occurs
+     */
+    public static URL getResource(String resource) throws MalformedURLException {
+        return ClassUtils.getClassLoader().getResource(resource);
+    }
+
+    /**
+     * Return the context classloader.
+     * BL: if this is command line operation, the classloading issues
+     *     are more sane.  During servlet execution, we explicitly set
+     *     the ClassLoader.
+     *
+     * @return The context classloader.
+     */
+    public static ClassLoader getClassLoader() {
+        return Thread.currentThread().getContextClassLoader();
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ClassUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/Deprecation.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/Deprecation.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/Deprecation.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/Deprecation.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.lang.enums.ValuedEnum;
+
+/**
+ * This class provides a special static "deprecation" logger.
+ * All deprecated code should use this logger to log messages into the 
+ * deprecation logger. This makes it easier for users to find out if they're 
+ * using deprecated stuff.
+ * <p>
+ * Additionally, it is possible to set the forbidden level of deprecation messages (default
+ * is to forbid ERROR, i.e. allow up to WARN). Messages equal to or above the forbidden level
+ * will lead to throwing a {@link DeprecationException}. Setting the forbidden level to
+ * FATAL_ERROR allows running legacy applications using deprecated features (tolerant mode), and
+ * setting the forbidden level to DEBUG will run in strict mode, forbidding all deprecations.
+ * <p>
+ * Note that according to the above, issuing a fatalError log always raises an exception, and
+ * can therefore be used when detecting old features that have been totally removed.
+ *
+ * @version $Id: Deprecation.java 219043 2005-07-14 14:44:06Z cziegeler $
+ */
+public class Deprecation {
+    
+    /**
+     * The deprecation logger.
+     */
+    public static final Logger logger = new LoggerWrapper(new ConsoleLogger());
+    
+    private static final int DEBUG_VALUE = 0;
+    private static final int INFO_VALUE = 1;
+    private static final int WARN_VALUE = 2;
+    private static final int ERROR_VALUE = 3;
+    private static final int FATAL_VALUE = 3;
+    private static final int FATAL_ERROR_VALUE = 4;
+    
+    /**
+     * Debug deprecation messages indicate features that are no more considered "current"
+     * or "best practice", but for which no removal is currently foreseen.
+     */
+    public static final LogLevel DEBUG = new LogLevel("DEBUG", DEBUG_VALUE);
+
+    /**
+     * Info deprecation messages indicate features that are no more considered "current"
+     * or "best practice", and that will probably be removed in future releases.
+     */
+    public static final LogLevel INFO = new LogLevel("INFO", INFO_VALUE);
+
+    /**
+     * Warning deprecation messages indicate features that will be removed in the next major
+     * version (e.g. 2.1.x --> 2.2.0). Such features should not be used if the application is
+     * planned to be migrated to newer Cocoon versions.
+     */
+    public static final LogLevel WARN = new LogLevel("WARN", WARN_VALUE);
+
+    /**
+     * Error deprecation messages indicate features that will be removed in the next minor
+     * version (e.g. 2.1.6 --> 2.1.7). Although still functional, users are stronly invited to
+     * not use them.
+     */
+    public static final LogLevel ERROR = new LogLevel("ERROR", ERROR_VALUE);
+
+    /**
+     * Fatal error deprecation messages indicate features that used to exist but have been removed
+     * in the current version. Logging such a message always throws a {@link DeprecationException}.
+     */
+    public static final LogLevel FATAL_ERROR = new LogLevel("FATAL_ERROR", FATAL_ERROR_VALUE);
+    
+    public static final class LogLevel extends ValuedEnum {
+        private LogLevel(String text, int value) {
+            super(text, value);
+        }
+        
+        public static LogLevel getLevel(String level) {
+            return (LogLevel)ValuedEnum.getEnum(LogLevel.class, level);
+        }
+    }
+
+    public static void setLogger(Logger newLogger) {
+        // Note: the "logger" attribute is not of type LoggerWrapper so that it appears
+        // as a standard Logger in the javadocs.
+        ((LoggerWrapper)logger).setLogger(newLogger);
+    }
+    
+    public static void setForbiddenLevel(LogLevel level) {
+        // If null, reset to the default level
+        if (level == null) {
+            level = ERROR;
+        }
+        ((LoggerWrapper)logger).setForbiddenLevel(level);
+    }
+    
+    /**
+     * Wraps a logger, and throws an DeprecatedException if the message level is
+     * higher than the allowed one.
+     */
+    private static class LoggerWrapper implements Logger {
+        
+        private Logger realLogger;
+        // up to warn is allowed
+        private int forbiddenLevel = ERROR_VALUE;
+        
+        public LoggerWrapper(Logger logger) {
+            this.realLogger = logger;
+        }
+        
+        public void setLogger(Logger logger) {
+            // Unwrap a wrapped logger
+            while(logger instanceof LoggerWrapper) {
+                logger = ((LoggerWrapper)logger).realLogger;
+            }
+            this.realLogger = logger;
+        }
+        
+        public void setForbiddenLevel(LogLevel level) {
+            this.forbiddenLevel = level.getValue();
+        }
+        
+        private void throwException(int level, String message) {
+            if (level >= this.forbiddenLevel) {
+                throw new DeprecationException(message);
+            }
+        }
+        
+        private boolean isThrowingException(int level) {
+            return level >= this.forbiddenLevel;
+        }
+        
+        public void debug(String message) {
+            realLogger.debug(message);
+            throwException(DEBUG_VALUE, message);
+        }
+        public void debug(String message, Throwable thr) {
+            realLogger.debug(message, thr);
+            throwException(DEBUG_VALUE, message);
+        }
+        public void info(String message) {
+            realLogger.info(message);
+            throwException(INFO_VALUE, message);
+        }
+        public void info(String message, Throwable thr) {
+            realLogger.info(message, thr);
+            throwException(INFO_VALUE, message);
+        }
+        public void warn(String message) {
+            realLogger.warn(message);
+            throwException(WARN_VALUE, message);
+        }
+        public void warn(String message, Throwable thr) {
+            realLogger.warn(message, thr);
+            throwException(WARN_VALUE, message);
+        }
+        public void error(String message) {
+            realLogger.error(message);
+            throwException(ERROR_VALUE, message);
+        }
+        public void error(String message, Throwable thr) {
+            realLogger.error(message, thr);
+            throwException(ERROR_VALUE, message);
+        }
+        public void fatalError(String message) {
+            realLogger.fatalError(message);
+            throwException(FATAL_VALUE, message);
+        }
+        public void fatalError(String message, Throwable thr) {
+            realLogger.fatalError(message, thr);
+            throwException(FATAL_VALUE, message);
+        }
+        public boolean isDebugEnabled() {
+            // Enable level also if it is set to throw an exception, so that
+            // logging the message occurs, and then throws it.
+            return isThrowingException(DEBUG_VALUE) || realLogger.isDebugEnabled();
+        }
+        public boolean isInfoEnabled() {
+            return isThrowingException(INFO_VALUE) || realLogger.isInfoEnabled();
+        }
+        public boolean isWarnEnabled() {
+            return isThrowingException(WARN_VALUE) || realLogger.isWarnEnabled();
+        }
+        public boolean isErrorEnabled() {
+            return isThrowingException(ERROR_VALUE) || realLogger.isErrorEnabled();
+        }
+        public boolean isFatalErrorEnabled() {
+            return true;
+        }
+        public Logger getChildLogger(String message) {
+            return realLogger.getChildLogger(message);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/Deprecation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/DeprecationException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/DeprecationException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/DeprecationException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/DeprecationException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+
+/**
+ * An exception that indicates unauthorized use of a deprecated feature, or an
+ * attempt to use a old feature that has been removed.
+ * 
+ * @version $Id: DeprecationException.java 219043 2005-07-14 14:44:06Z cziegeler $
+ */
+public class DeprecationException extends RuntimeException {
+    public DeprecationException(String message) {
+        super(message);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/DeprecationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ElementAttributeMatching.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ElementAttributeMatching.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ElementAttributeMatching.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ElementAttributeMatching.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.cocoon.util;
+
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+
+/**
+ * A helper class for matching element names, and attribute names.
+ * <p/>
+ * For given include-name, exclude-name decide if element-attribute pair
+ * matches. This class defines the precedence and matching algorithm.
+ * </p>
+ * This was originally part of the EncodeURLTransformer, moved
+ * here to make it more reusable.
+ *
+ * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
+ * @version CVS $Id: ElementAttributeMatching.java 292282 2005-09-28 19:54:16Z vgritsenko $
+ */
+public class ElementAttributeMatching {
+    /**
+     * Regular expression of including patterns
+     */
+    protected RE includeNameRE;
+    /**
+     * Regular expression of excluding patterns
+     */
+    protected RE excludeNameRE;
+
+
+    /**
+     * Constructor for the ElementAttributeMatching object
+     *
+     * @param includeName Description of Parameter
+     * @param excludeName Description of Parameter
+     * @throws org.apache.regexp.RESyntaxException
+     *          Description of Exception
+     */
+    public ElementAttributeMatching(String includeName, String excludeName) throws RESyntaxException {
+        includeNameRE = new RE(includeName, RE.MATCH_CASEINDEPENDENT);
+        excludeNameRE = new RE(excludeName, RE.MATCH_CASEINDEPENDENT);
+    }
+
+
+    /**
+     * Return true iff element_name attr_name pair is not matched by exclude-name,
+     * but is matched by include-name
+     *
+     * @param element_name
+     * @param attr_name
+     * @param value used to canonicalize the elemtn/attribute name
+     * @return boolean true iff value of attribute_name should get rewritten, else
+     *         false.
+     */
+    public boolean matchesElementAttribute(String element_name, String attr_name, String value) {
+        final String element_attr_name = canonicalizeElementAttribute(element_name, attr_name, value);
+
+        if (excludeNameRE != null && includeNameRE != null) {
+            return !matchesExcludesElementAttribute(element_attr_name) &&
+                    matchesIncludesElementAttribute(element_attr_name);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Build a single string from element name, attribute and value, for pattern matching.
+     */
+    private String canonicalizeElementAttribute(String element_name, String attr_name, String value) {
+        return element_name + "/@" + attr_name + "=" + value;
+    }
+
+    /**
+     * @return true element_attr_name is matched by exclude-name.
+     */
+    private boolean matchesExcludesElementAttribute(String element_attr_name) {
+        return excludeNameRE.match(element_attr_name);
+    }
+
+    /**
+     * @return true element_attr_name is matched by include-name.
+     */
+    private boolean matchesIncludesElementAttribute(String element_attr_name) {
+        return includeNameRE.match(element_attr_name);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ElementAttributeMatching.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/EnumerationFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/EnumerationFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/EnumerationFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/EnumerationFactory.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,212 @@
+/*
+* Copyright 1999-2005 The Apache Software Foundation
+*
+* Licensed 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.
+*/
+//----------------------------------------------------------------------
+// This software is provided as is in the hope that it might be found
+// useful.
+// You may use and modify it freely provided you keep this copyright
+// notice unchanged and mark modifications appropriately.
+//
+// Bug reports and proposals for improvements are welcome. Please send
+// them to the eMail address below.
+//
+// Christoph Karl Walter Grein
+// Hauptstr. 42
+// D-86926 Greifenberg
+// Germany
+//
+// eMail: Christ-Usch.Grein@T-Online.de
+//
+// Copyright (c) 1998 Christoph Karl Walter Grein
+//----------------------------------------------------------------------
+
+//====================================================================
+// Author    Christoph Grein <Christ-Usch.Grein@T-Online.de>
+// Version   1.1
+// Date      7 February 1998
+//====================================================================
+// A factory for the creation of enumeration types (missing in Java).
+// The same operations are provided as for Ada, only representation
+// specification is missing (which does not seem to make much sense
+// in Java).
+//
+// The idea behind this implementation model is the following:
+//
+// Each enumeration object [or literal as called in Ada] is internally
+// represented by its position number [like in Ada] starting with 0
+// for the first one. For external representation, an image string
+// may also be defined.
+// All operations on enumerations (order relations between objects,
+// iterators [in the Ada sense for getting the successor and predeces-
+// sor of an object]) are implemented on the internal position number.
+//
+// Implementing the Ada 'Pos attribute as a function getPos () is
+// straight forward as is the implementation of 'Image as a function
+// toString () [*], whereas their reverse operations 'Val and 'Value
+// present a bit of a problem.
+// In order to be able to access all objects created for the given
+// class, we define a vector and let the constructors add each object
+// upon creation to this vector. Thus each object's position number
+// is also its vector index. So getVal [Ada's 'Val] simply returns
+// the object stored at the given place; getObject [Ada's 'Value]
+// loops thru the vector until it finds the object with the given
+// string.
+//
+// [*] The name toString has deliberately been chosen because of
+// Java's convention of calling an operation with this name whenever
+// an object's name appears in string context.
+//
+// There is one last point to take care of. An enumeration class has
+// only a fixed number of objects, so we must inhibit the creation of
+// new objects (with the "new" operator) outside of the enumeration
+// class. However, in order to make this EnumerationFactory class
+// work, the constructors need to be public. Therefore we set up the
+// requirement that upon derivation from class EnumerationFactory all
+// objects be created in the derivation class (using all capital
+// letters according to Java's convention) and the constructors be
+// made private.
+//
+// For this class at work, see the example classes EnumerationExample
+// and Test_EnumerationExample, which present a few objects and opera-
+// tions on them.
+//
+// Comments and improvements are welcome, see e-mail address above.
+//====================================================================
+// History:
+// Author Version   Date    Reason for Change
+//  C.G.   1.0  03.02.1998
+//  C.G.   1.1  07.02.1998  getObject returns null if nothing found
+//====================================================================
+
+package org.apache.cocoon.util;
+
+import java.util.Vector;
+
+/**
+ * A factory for the creation of enumeration types (missing in Java).
+ * The same operations are provided as for Ada, only representation
+ * specification is missing (which does not seem to make much sense
+ * in Java).
+ * Enumeration classes are to be derived from this class thereby
+ * making the constructors private to inhibit creation outside of
+ * the derived class.
+ *
+ * @author Christoph Grein
+ * @version CVS $Id: EnumerationFactory.java 156968 2005-03-10 17:33:17Z cziegeler $
+ */
+public class EnumerationFactory {
+
+    private static Vector allObjects =  // must be here JDK 1.1.3
+                    new Vector (0, 1);  // empty, increment by 1
+
+    private int pos;
+    private String image;
+
+    /**
+     * Constructors with and without a string representation (image).
+     * Make constructors private upon derivation.
+     * Be careful: No check is made that the image string is unique!
+     * @param image
+     */
+    public EnumerationFactory(String image) {
+        this.pos = allObjects.size();
+        this.image = image;
+        allObjects.addElement(this);
+    }
+
+    public EnumerationFactory() {
+        this ("");
+    }
+
+    //--------------------------------------------------------------------------
+    // Order relations:
+
+    /**
+     * Order relations Object.op (OtherObject) representing the relation
+     * Object op OtherObject.
+     * @param e the right operand
+     */
+    public boolean lt(EnumerationFactory e) {                   // "<"
+        return this.getPos() < e.getPos();
+    }
+
+    public boolean le(EnumerationFactory e) {                   // "<="
+        return this.getPos() <= e.getPos();
+    }
+
+    public boolean gt(EnumerationFactory e) {                   // ">"
+        return this.getPos() > e.getPos();
+    }
+
+    public boolean ge(EnumerationFactory e) {                   // ">="
+        return this.getPos() >= e.getPos ();
+    }
+
+    // "==" and "equals" are inherited.
+
+    //--------------------------------------------------------------------------
+    // Numeric representation:
+
+    public int getPos() {                                          // Ada'Pos
+        return pos;
+    }
+
+    /**
+     * Access to the numeric representation.
+     * @param value the numeric value
+     */
+    public static EnumerationFactory getVal(int value) {           // Ada'Val
+        return (EnumerationFactory)allObjects.elementAt(value);
+    }
+
+    //--------------------------------------------------------------------------
+    // Iterator:
+
+    public static EnumerationFactory getFirst() {                  // Ada'First
+        return getVal(0);
+    }
+
+    public static EnumerationFactory getLast() {                   // Ada'Last
+        return getVal(allObjects.size() - 1);
+    }
+
+    public EnumerationFactory getNext () {                          // Ada'Succ
+        return getVal(this.getPos() + 1);
+    }
+
+    public EnumerationFactory getPrev () {                          // Ada'Pred
+        return getVal(this.getPos() - 1);
+    }
+
+    //--------------------------------------------------------------------------
+    // String representation:
+
+    public String toString() {                                     // Ada'Image
+        return image;
+    }
+
+    public static EnumerationFactory getObject(String image) {     // Ada'Value
+        EnumerationFactory found;
+        // Linear search seems good enough because there presumably
+        // will not be too many literals.
+        for (int i = 0 ; i < allObjects.size() ; i++) {
+            found = (EnumerationFactory) allObjects.elementAt(i);
+            if (found.toString().equals(image)) {
+                return found;
+            }
+        }
+        return null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/EnumerationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/FileFormatException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/FileFormatException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/FileFormatException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/FileFormatException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,32 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import org.apache.avalon.framework.CascadingException;
+
+/**
+ * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
+ * @version CVS $Id: FileFormatException.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class FileFormatException extends CascadingException {
+    public FileFormatException(String s) {
+        super(s);
+    }
+
+    public FileFormatException(String s, Throwable throwable) {
+        super(s, throwable);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/FileFormatException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashMap.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashMap.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashMap.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashMap.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.cocoon.util;
+
+import java.util.Map;
+
+/**
+ * Extended Version of {@link java.util.HashMap} that provides an extended
+ * get method accpeting a default value. The default value is returned if
+ * the map does not contain a value for the provided key.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: HashMap.java 164222 2005-04-22 11:41:51Z cziegeler $
+ */
+public class HashMap extends java.util.HashMap {
+
+    public HashMap () {
+        super();
+    }
+
+    public HashMap ( int initialCapacity ) {
+        super(initialCapacity);
+    }
+
+    public HashMap ( int initialCapacity, float loadFactor ) {
+        super(initialCapacity, loadFactor);
+    }
+
+    public HashMap ( Map t) {
+        super(t);
+    }
+
+    /**
+     * Get method extended by default object to be returned when key
+     * is not found.
+     *
+     * @param key key to look up
+     * @param _default default value to return if key is not found
+     * @return value that is associated with key
+     */
+    public Object get( Object key, Object _default ) {
+        if (this.containsKey(key)) {
+            return this.get(key);
+        }
+        return _default;
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashUtil.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashUtil.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashUtil.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,186 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+/**
+ * A very efficient java hash algorithm, based on the BuzHash algoritm
+ * by Robert Uzgalis (see http://www.serve.net/buz/hash.adt/java.000.html
+ * for more information).
+ * BuzHash is Copyright (c)1996 Robert Uzgalis, All Rights Reserved.
+ * Used with kind permission of the author
+ *
+ * @author <a href="mailto:buz@zis.com">Robert Uzgalis</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: HashUtil.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public final class HashUtil {
+
+    private static long initial_hash = 0xe12398c6d9ae3b8aL; // initial values
+
+    private static long mix_master[/* 0:255 */] = {
+/* 000 */ 0x4476081a7043a46fL, 0x45768b8a6e7eac19L, 0xebd556c1cf055952L,
+/* */ 0x72ed2da1bf010101L, 0x3ff2030b128e8a64L,
+/* 005 */ 0xcbc330238adcfef2L, 0x737807fe42e20c6cL, 0x74dabaedb1095c58L,
+/* */ 0x968f065c65361d67L, 0xd3f4018ac7a4b199L,
+/* 010 */ 0x954b389b52f24df2L, 0x2f97a9d8d0549327L, 0xb9bea2b49a3b180fL,
+/* */ 0xaf2f42536b21f2ebL, 0x85d991663cff1325L,
+/* 015 */ 0xb9e1260207b575b9L, 0xf3ea88398a23b7e2L, 0xfaf8c83ffbd9091dL,
+/* */ 0x4274fe90834dbdf9L, 0x3f20b157b68d6313L,
+/* 020 */ 0x68b48972b6d06b93L, 0x694837b6eba548afL, 0xeecb51d1acc917c9L,
+/* */ 0xf1c633f02dffbcfaL, 0xa6549ec9d301f3b5L,
+/* 025 */ 0x451dc944f1663592L, 0x446d6acef6ce9e4fL, 0x1c8a5b3013206f02L,
+/* */ 0x5908ca36f2dc50f7L, 0x4fd55d3f3e880a87L,
+/* 030 */ 0xa03a8dbeabbf065dL, 0x3ccbbe078fabcb6dL, 0x1da53a259116f2d0L,
+/* */ 0xfb27a96fcb9af152L, 0x50aba242e85aec09L,
+/* 035 */ 0x24d4e414fc4fc987L, 0x83971844a9ce535eL, 0xc26a3fdeb849398eL,
+/* */ 0xc2380d044d2e70d8L, 0xab418aa8ae19b18fL,
+/* 040 */ 0xd95b6b9247d5ebeaL, 0x8b3b2171fdc60511L, 0xe15cd0ae3fcc44afL,
+/* */ 0x5a4e27f914a68f17L, 0x377bd28ca09aafdcL,
+/* 045 */ 0xbbeb9828594a3294L, 0x7c8df263ae1de1b9L, 0xba0a48a5fd1c1dd0L,
+/* */ 0x57cc1b8818b98ee6L, 0x8c570975d357dabcL,
+/* 050 */ 0x76bdcd6f2e8826aaL, 0x529b15b6ec4055f1L, 0x9147c7a54c34f8a9L,
+/* */ 0x2f96a7728170e402L, 0xe46602f455eca72eL,
+/* 055 */ 0x22834c4dd1bde03fL, 0x2644cf5a25e368ffL, 0x907c6de90b120f4aL,
+/* */ 0xadfe8ba99028f728L, 0xa85199ae14df0433L,
+/* 060 */ 0x2d749b946dd3601eL, 0x76e35457aa052772L, 0x90410bf6e427f736L,
+/* */ 0x536ad04d13e35041L, 0x8cc0d76769b76914L,
+/* 065 */ 0xae0249f6e3b3c01cL, 0x1bdfd075307d6fafL, 0xd8e04f70c221deccL,
+/* */ 0x4ab23622a4281a5dL, 0x37a5613da2fcaba7L,
+/* 070 */ 0x19a56203666d4a9fL, 0x158ffab502c4be93L, 0x0bee714e332ecb2fL,
+/* */ 0x69b71a59f6f74ab0L, 0x0fc7fc622f1dfe8fL,
+/* 075 */ 0x513966de7152a6f9L, 0xc16fae9cc2ea9be7L, 0xb66f0ac586c1899eL,
+/* */ 0x11e124aee3bdefd7L, 0x86cf5a577512901bL,
+/* 080 */ 0x33f33ba6994a1fbdL, 0xde6c4d1d3d47ff0dL, 0x6a99220dc6f78e66L,
+/* */ 0x2dc06ca93e2d25d2L, 0x96413b520134d573L,
+/* 085 */ 0xb4715ce8e1023afaL, 0xe6a75900c8c66c0aL, 0x6448f13ad54c12edL,
+/* */ 0xb9057c28cf6689f0L, 0xf4023daf67f7677aL,
+/* 090 */ 0x877c2650767b9867L, 0xb7ea587dcd5b2341L, 0xc048cf111733f9bcL,
+/* */ 0x112012c15bc867bfL, 0xc95f52b1d9418811L,
+/* 095 */ 0xa47e624ee7499083L, 0x26928606df9b12e8L, 0x5d020462ec3e0928L,
+/* */ 0x8bbde651f6d08914L, 0xd5db83db758e524aL,
+/* 100 */ 0x3105e355c000f455L, 0xdd7fe1b81a786c79L, 0x1f3a818c8e012db1L,
+/* */ 0xd902de819d7b42faL, 0x4200e63325cda5f0L,
+/* 105 */ 0x0e919cdc5fba9220L, 0x5360dd54605a11e1L, 0xa3182d0e6cb23e6cL,
+/* */ 0x13ee462c1b483b87L, 0x1b1b6087b997ee22L,
+/* 110 */ 0x81c36d0b877f7362L, 0xc24879932c1768d4L, 0x1faa756e1673f9adL,
+/* */ 0x61651b24d11fe93dL, 0x30fe3d9304e1cde4L,
+/* 115 */ 0x7be867c750747250L, 0x973e52c7005b5db6L, 0x75d6b699bbaf4817L,
+/* */ 0x25d2a9e97379e196L, 0xe65fb599aca98701L,
+/* 120 */ 0x6ac27960d24bde84L, 0xdfacc04c9fabbcb6L, 0xa46cd07f4a97882bL,
+/* */ 0x652031d8e59a1fd8L, 0x1185bd967ec7ce10L,
+/* 125 */ 0xfc9bd84c6780f244L, 0x0a0c59872f61b3ffL, 0x63885727a1c71c95L,
+/* */ 0x5e88b4390b2d765cL, 0xf0005ccaf988514dL,
+/* 130 */ 0x474e44280a98e840L, 0x32de151c1411bc42L, 0x2c4b86d5aa4482c2L,
+/* */ 0xccd93deb2d9d47daL, 0x3743236ff128a622L,
+/* 135 */ 0x42ed2f2635ba5647L, 0x99c74afd18962dbdL, 0x2d663bb870f6d242L,
+/* */ 0x7912033bc7635d81L, 0xb442862f43753680L,
+/* 140 */ 0x94b1a5400aeaab4cL, 0x5ce285fe810f2220L, 0xe8a7dbe565d9c0b1L,
+/* */ 0x219131af78356c94L, 0x7b3a80d130f27e2fL,
+/* 145 */ 0xbaa5d2859d16b440L, 0x821cfb6935771070L, 0xf68cfb6ee9bc2336L,
+/* */ 0x18244132e935d2fdL, 0x2ed0bda1f4720cffL,
+/* 150 */ 0x4ed48cdf6975173cL, 0xfd37a7a2520e2405L, 0x82c102b2a9e73ce2L,
+/* */ 0xadac6517062623a7L, 0x5a1294d318e26104L,
+/* 155 */ 0xea84fe65c0e4f061L, 0x4f96f8a9464cfee9L, 0x9831dff8ccdc534aL,
+/* */ 0x4ca927cd0f192a14L, 0x030900b294b71649L,
+/* 160 */ 0x644b263b9aeb0675L, 0xa601d4e34647e040L, 0x34d897eb397f1004L,
+/* */ 0xa6101c37f4ec8dfcL, 0xc29d2a8bbfd0006bL,
+/* 165 */ 0xc6b07df8c5b4ed0fL, 0xce1b7d92ba6bccbeL, 0xfa2f99442e03fe1bL,
+/* */ 0xd8863e4c16f0b363L, 0x033b2cccc3392942L,
+/* 170 */ 0x757dc33522d6cf9cL, 0xf07b1ff6ce55fec5L, 0x1569e75f09b40463L,
+/* */ 0xfa33fa08f14a310bL, 0x6eb79aa27bbcf76bL,
+/* 175 */ 0x157061207c249602L, 0x25e5a71fc4e99555L, 0x5df1fe93de625355L,
+/* */ 0x235b56090c1aa55dL, 0xe51068613eaced91L,
+/* 180 */ 0x45bd47b893b9ff1eL, 0x6595e1798d381f2dL, 0xc9b5848cbcdb5ba8L,
+/* */ 0x65985146ff7792bcL, 0x4ab4a17bf05a19a0L,
+/* 185 */ 0xfd94f4ca560ffb0cL, 0xcf9bad581a68fa68L, 0x92b4f0b502b1ce1aL,
+/* */ 0xbcbec0769a610474L, 0x8dbd31ded1a0fecbL,
+/* 190 */ 0xdd1f5ed9f90e8533L, 0x61c1e6a523f84d95L, 0xf24475f383c110c4L,
+/* */ 0xdb2dffa66f90588dL, 0xac06d88e9ee04455L,
+/* 195 */ 0xa215fc47c40504baL, 0x86d7caebfee93369L, 0x9eaec31985804099L,
+/* */ 0x0fba2214abe5d01bL, 0x5a32975a4b3865d6L,
+/* 200 */ 0x8cceebc98a5c108fL, 0x7e12c4589654f2dcL, 0xa49ad49fb0d19772L,
+/* */ 0x3d142dd9c406152bL, 0x9f13589e7be2b8a5L,
+/* 205 */ 0x5e8dbac1892967adL, 0xcc23b93a6308e597L, 0x1ef35f5fe874e16aL,
+/* */ 0x63ae9cc08d2e274fL, 0x5bbabee56007fc05L,
+/* 210 */ 0xabfd72994230fc39L, 0x9d71a13a99144de1L, 0xd9daf5aa8dcc89b3L,
+/* */ 0xe145ec0514161bfdL, 0x143befc2498cd270L,
+/* 215 */ 0xa8e192557dbbd9f8L, 0xcbeda2445628d7d0L, 0x997f0a93205d9ea4L,
+/* */ 0x01014a97f214ebfaL, 0x70c026ffd1ebedafL,
+/* 220 */ 0xf8737b1b3237002fL, 0x8afcbef3147e6e5eL, 0x0e1bb0684483ebd3L,
+/* */ 0x4cbad70ae9b05aa6L, 0xd4a31f523517c363L,
+/* 225 */ 0xdb0f057ae8e9e8a2L, 0x400894a919d89df6L, 0x6a626a9b62defab3L,
+/* */ 0xf907fd7e14f4e201L, 0xe10e4a5657c48f3fL,
+/* 230 */ 0xb17f9f54b8e6e5dcL, 0x6b9e69045fa6d27aL, 0x8b74b6a41dc3078eL,
+/* */ 0x027954d45ca367f9L, 0xd07207b8fdcbb7ccL,
+/* 235 */ 0xf397c47d2f36414bL, 0x05e4e8b11d3a034fL, 0x36adb3f7122d654fL,
+/* */ 0x607d9540eb336078L, 0xb639118e3a8b9600L,
+/* 240 */ 0xd0a406770b5f1484L, 0x3cbee8213ccfb7c6L, 0x467967bb2ff89cf1L,
+/* */ 0xb115fe29609919a6L, 0xba740e6ffa83287eL,
+/* 245 */ 0xb4e51be9b694b7cdL, 0xc9a081c677df5aeaL, 0x2e1fbcd8944508ccL,
+/* */ 0xf626e7895581fbb8L, 0x3ce6e9b5728a05cbL,
+/* 250 */ 0x46e87f2664a31712L, 0x8c1dc526c2f6acfaL, 0x7b4826726e560b10L,
+/* */ 0x2966e0099d8d7ce1L, 0xbb0dd5240d2b2adeL, 0x0d527cc60bbaa936L
+};
+
+    /**
+     * This is buzhash the hash function on which most other Hash methods
+     * are built.
+     */
+    private static long buzhash (StringBuffer arg) {
+        /* Hash StringBuffer */
+        long h = initial_hash;
+        for ( int i=0; i<arg.length(); ++i )
+            h = (h<<1) ^ (h>>>63) ^
+                mix_master[ ( arg.charAt(i) ^ (arg.charAt(i)>>>8) ) & 0xff ];
+        return h;
+    }
+
+    /**
+     * This is buzhash the hash function on which most other Hash methods
+     * are built.
+     */
+    private static long buzhash (String arg) {
+        /* Hash StringBuffer */
+        long h = initial_hash;
+        for ( int i=0; i<arg.length(); ++i )
+            h = (h<<1) ^ (h>>>63) ^
+                mix_master[ ( arg.charAt(i) ^ (arg.charAt(i)>>>8) ) & 0xff ];
+        return h;
+    }
+
+    /**
+     * Hash a String.
+     *
+     * @param arg The String to be hashed
+     * @return The hash for the input.
+     */
+    public static long hash(String arg) {
+        // Make Hash from String
+        return buzhash( arg );
+    }
+
+    /**
+     * Hash a String.
+     *
+     * @param arg The String represented by the StringBuffer to be hashed
+     * @return The hash for the input.
+     */
+    public static long hash(StringBuffer arg) {
+        // Make Hash from StringBuffer
+        return buzhash( arg );
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/HashUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/IOUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/IOUtils.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/IOUtils.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/IOUtils.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,390 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.text.Collator;
+import java.util.Arrays;
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log.Hierarchy;
+
+/**
+ * A collection of <code>File</code>, <code>URL</code> and filename
+ * utility methods
+ *
+ * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: IOUtils.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class IOUtils {
+
+    // **********************
+    // Serialize Methods
+    // **********************
+
+    /**
+     * Dump a <code>String</code> to a text file.
+     *
+     * @param file The output file
+     * @param string The string to be dumped
+     * @exception IOException IO Error
+     * @deprecated To be removed in cocoon 2.3
+     */
+    public static void serializeString(File file, String string)
+    throws IOException {
+        serializeString(file, string, null);
+    }
+
+    /**
+     * Dump a <code>String</code> to a text file.
+     *
+     * @param file The output file
+     * @param string The string to be dumped
+     * @param encoding The encoding for the output file or null for default platform encoding
+     * @exception IOException IO Error
+     * @deprecated To be removed in cocoon 2.3
+     */
+    public static void serializeString(File file, String string, String encoding)
+    throws IOException {
+        final Writer fw =
+                (encoding == null)?
+                new FileWriter(file):
+                new OutputStreamWriter(new FileOutputStream(file), encoding);
+        try {
+            fw.write(string);
+            fw.flush();
+        } finally {
+            if (fw != null) fw.close();
+        }
+    }
+
+    /**
+     * Load a text file contents as a <code>String<code>.
+     * This method does not perform enconding conversions
+     *
+     * @param file The input file
+     * @return The file contents as a <code>String</code>
+     * @exception IOException IO Error
+     */
+    public static String deserializeString(File file)
+    throws IOException {
+        int len;
+        char[] chr = new char[4096];
+        final StringBuffer buffer = new StringBuffer();
+        final FileReader reader = new FileReader(file);
+        try {
+            while ((len = reader.read(chr)) > 0) {
+                buffer.append(chr, 0, len);
+            }
+        } finally {
+            if (reader != null) reader.close();
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * This method serializes an object to an output stream.
+     *
+     * @param file The output file
+     * @param object The object to be serialized
+     * @exception IOException IOError
+     * @deprecated To be removed in cocoon 2.3
+     */
+    public static void serializeObject(File file, Object object)
+    throws IOException {
+        FileOutputStream fos = new FileOutputStream(file);
+        try {
+            ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos));
+            oos.writeObject(object);
+            oos.flush();
+        } finally {
+            if (fos != null) fos.close();
+        }
+    }
+
+    /**
+     * This method deserializes an object from an input stream.
+     *
+     * @param file The input file
+     * @return The deserialized object
+     * @exception IOException IOError
+     * @deprecated To be removed in cocoon 2.3
+     */
+    public static Object deserializeObject(File file)
+    throws IOException, ClassNotFoundException {
+        FileInputStream fis = new FileInputStream(file);
+        Object object = null;
+        try {
+            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
+            object = ois.readObject();
+        } finally {
+            if (fis != null) fis.close();
+        }
+        return object;
+    }
+
+  /**
+   * These are java keywords as specified at the following URL (sorted alphabetically).
+   * http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
+   */
+  static final String keywords[] =
+  {
+      "abstract",  "boolean",     "break",    "byte",         "case",
+      "catch",     "char",        "class",    "const",        "continue",
+      "default",   "do",          "double",   "else",         "extends",
+      "final",     "finally",     "float",    "for",          "goto",
+      "if",        "implements",  "import",   "instanceof",   "int",
+      "interface", "long",        "native",   "new",          "package",
+      "private",   "protected",   "public",   "return",       "short",
+      "static",    "strictfp",    "super",    "switch",       "synchronized",
+      "this",      "throw",       "throws",   "transient",    "try",
+      "void",      "volatile",    "while"
+  };
+
+  /** Collator for comparing the strings */
+  static final Collator englishCollator = Collator.getInstance(Locale.ENGLISH);
+
+  /** Use this character as suffix */
+  static final char keywordSuffix = '_';
+
+  /**
+   * checks if the input string is a valid java keyword.
+   * @return boolean true/false
+   */
+  private static boolean isJavaKeyword(String keyword) {
+    return (Arrays.binarySearch(keywords, keyword, englishCollator) >= 0);
+  }
+
+  // **********************
+  // File Methods
+  // **********************
+
+  /**
+   * Return a modified filename suitable for replicating directory
+   * structures below the store's base directory. The following
+   * conversions are performed:
+   * <ul>
+   * <li>Path separators are converted to regular directory names</li>
+   * <li>File path components are transliterated to make them valid (?)
+   *     programming language identifiers. This transformation may well
+   *     generate collisions for unusual filenames.</li>
+   * </ul>
+   * @return The transformed filename
+   */
+  public static String normalizedFilename(String filename) {
+    if ("".equals(filename)) {
+        return "";
+    }
+    filename = (File.separatorChar == '\\') ? filename.replace('/','\\') : filename.replace('\\','/');
+    String[] path = StringUtils.split(filename, File.separator);
+    int start = (path[0].length() == 0) ? 1 : 0;
+
+    StringBuffer buffer = new StringBuffer();
+    for (int i = start; i < path.length; i++) {
+
+      if (i > start) {
+        buffer.append(File.separator);
+      }
+
+      if (path[i].equals("..")) {
+        int lio;
+        for (lio = buffer.length() - 2; lio >= 0; lio--) {
+          if (buffer.substring(lio).startsWith(File.separator)) {
+            break;
+          }
+        }
+        if (lio >= 0) {
+          buffer.setLength(lio);
+        }
+      } else {
+        char[] chars = path[i].toCharArray();
+
+        if (chars.length < 1 || !Character.isLetter(chars[0])) {
+          buffer.append('_');
+        }
+
+        for (int j = 0; j < chars.length; j++) {
+          if (org.apache.cocoon.util.StringUtils.isAlphaNumeric(chars[j])) {
+            buffer.append(chars[j]);
+          } else {
+            buffer.append('_');
+          }
+        }
+
+        // Append the suffix if necessary.
+        if(isJavaKeyword(path[i]))
+          buffer.append(keywordSuffix);
+      }
+
+    }
+    return buffer.toString();
+  }
+
+  /**
+   * Remove file information from a filename returning only its path
+   * component
+   *
+   * @param filename The filename
+   * @return The path information
+   * @deprecated To be removed in cocoon 2.3
+   */
+  public static String pathComponent(String filename) {
+    int i = filename.lastIndexOf(File.separator);
+    return (i > -1) ? filename.substring(0, i) : filename;
+  }
+
+  /**
+   * Remove path information from a filename returning only its file
+   * component
+   *
+   * @param filename The filename
+   * @return The filename sans path information
+   * @deprecated To be removed in cocoon 2.3
+   */
+  public static String fileComponent(String filename) {
+    int i = filename.lastIndexOf(File.separator);
+    return (i > -1) ? filename.substring(i + 1) : filename;
+  }
+
+  /**
+   * Strip a filename of its <i>last</i> extension (the portion
+   * immediately following the last dot character, if any)
+   *
+   * @param filename The filename
+   * @return The filename sans extension
+   * @deprecated To be removed in cocoon 2.3
+   */
+  public static String baseName(String filename) {
+    int i = filename.lastIndexOf('.');
+    return (i > -1) ? filename.substring(0, i) : filename;
+  }
+
+  /**
+   * Get the complete filename corresponding to a (typically relative)
+   * <code>File</code>.
+   * This method accounts for the possibility of an error in getting
+   * the filename's <i>canonical</i> path, returning the io/error-safe
+   * <i>absolute</i> form instead
+   *
+   * @param file The file
+   * @return The file's absolute filename
+   */
+  public static String getFullFilename(File file) {
+    try {
+      return file.getCanonicalPath();
+    } catch (Exception e) {
+      Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").debug("IOUtils.getFullFilename", e);
+      return file.getAbsolutePath();
+    }
+  }
+
+  /**
+   * Return the path within a base directory
+   */
+  public static String getContextFilePath(String directoryPath, String filePath) {
+      try
+      {
+          File directory = new File(directoryPath);
+          File file = new File(filePath);
+
+          directoryPath = directory.getCanonicalPath();
+          filePath = file.getCanonicalPath();
+
+          // If the context directory does not have a File.separator
+          // at the end then add one explicitly
+          if(!directoryPath.endsWith(File.separator)){
+            directoryPath += File.separator;
+          }
+
+          // If the context dir contains both kinds of separator
+          // then standardize on using the File.separator
+          if ((directoryPath.indexOf('/') !=-1) && (directoryPath.indexOf('\\') !=-1)) {
+            directoryPath = directoryPath.replace('\\', File.separator.charAt(0));
+            directoryPath = directoryPath.replace('/', File.separator.charAt(0));
+          }
+
+          // If the file path contains both kinds of separator
+          // then standardize on using the File.separator
+          if ((filePath.indexOf('/') !=-1) && (filePath.indexOf('\\') !=-1)) {
+            filePath = filePath.replace('\\', File.separator.charAt(0));
+            filePath = filePath.replace('/', File.separator.charAt(0));
+          }
+
+          if (filePath.startsWith(directoryPath)) {
+              filePath = filePath.substring(directoryPath.length());
+          }
+      } catch (Exception e){
+          Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").debug("IOUtils.getContextFilePath", e);
+      }
+
+      return filePath;
+  }
+
+  /**
+   * Return a file with the given filename creating the necessary
+   * directories if not present.
+   *
+   * @param filename The file
+   * @return The created File instance
+   */
+  public static File createFile(File destDir, String filename) {
+    File file = new File(destDir, filename);
+    File parent = file.getParentFile();
+    if (parent != null) parent.mkdirs();
+    return file;
+  }
+
+  /**
+   * Returns a byte array from the given object.
+   *
+   * @param object to convert
+   * @return byte array from the object
+   * @deprecated To be removed in cocoon 2.3
+   */
+  public static byte[] objectToBytes(Object object) throws IOException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    ObjectOutputStream os = new ObjectOutputStream(baos);
+    os.writeObject(object);
+    return baos.toByteArray();
+  }
+
+  /**
+   * Returns a object from the given byte array.
+   *
+   * @param bytes array to convert
+   * @return object
+   * @deprecated To be removed in cocoon 2.3
+   */
+  public static Object bytesToObject(byte[] bytes) throws IOException, ClassNotFoundException {
+    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+    ObjectInputStream is = new ObjectInputStream(bais);
+    return is.readObject();
+  }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/IOUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageProperties.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageProperties.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageProperties.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageProperties.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+/**
+ * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
+ * @version CVS $Id: ImageProperties.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+final public class ImageProperties {
+    final public int width;
+    final public int height;
+    final public char[] comment;
+    final public String type;
+
+    public ImageProperties(int width, int height, char[] comment, String type) {
+        this.width = width;
+        this.height = height;
+        this.comment = comment;
+        this.type = type;
+    }
+
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append(type).append(" ").append(width).append("x").append(height);
+        if (comment != null) {
+            sb.append(" (").append(comment).append(")");
+        }
+        return (sb.toString());
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageUtils.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageUtils.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageUtils.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,159 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+
+/**
+ * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
+ * @author <a href="mailto:balld@webslingerZ.com">Donald A. Ball Jr.</a>
+ * @version CVS $Id: ImageUtils.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+final public class ImageUtils {
+
+    final public static ImageProperties getImageProperties(File file) throws FileNotFoundException, IOException, FileFormatException {
+        String type = MIMEUtils.getMIMEType(file);
+
+        if ("image/gif".equals(type)) {
+             return (getGifProperties(file));
+        }
+        else if ("image/jpeg".equals(type)) {
+            return (getJpegProperties(file));
+        }
+        else {
+            return (null);
+        }
+    }
+
+    final public static ImageProperties getJpegProperties(File file) throws FileNotFoundException, IOException, FileFormatException {
+        BufferedInputStream in = null;
+        try {
+            in = new BufferedInputStream(new FileInputStream(file));
+
+            // check for "magic" header
+            byte[] buf = new byte[2];
+            int count = in.read(buf, 0, 2);
+            if (count < 2) {
+                throw new FileFormatException("Not a valid Jpeg file!");
+            }
+            if ((buf[0]) != (byte) 0xFF || (buf[1]) != (byte) 0xD8) {
+                throw new FileFormatException("Not a valid Jpeg file!");
+            }
+
+            int width = 0;
+            int height = 0;
+            char[] comment = null;
+
+            boolean hasDims = false;
+            boolean hasComment = false;
+            int ch = 0;
+
+            while (ch != 0xDA && !(hasDims && hasComment)) {
+                /* Find next marker (JPEG markers begin with 0xFF) */
+                while (ch != 0xFF) {
+                    ch = in.read();
+                }
+                /* JPEG markers can be padded with unlimited 0xFF's */
+                while (ch == 0xFF) {
+                    ch = in.read();
+                }
+                /* Now, ch contains the value of the marker. */
+
+                int length = 256 * in.read();
+                length += in.read();
+                if (length < 2) {
+                    throw new FileFormatException("Not a valid Jpeg file!");
+                }
+                /* Now, length contains the length of the marker. */
+
+                if (ch >= 0xC0 && ch <= 0xC3) {
+                    in.read();
+                    height = 256 * in.read();
+                    height += in.read();
+                    width = 256 * in.read();
+                    width += in.read();
+                    for (int foo = 0; foo < length - 2 - 5; foo++) {
+                        in.read();
+                    }
+                    hasDims = true;
+                }
+                else if (ch == 0xFE) {
+                    // that's the comment marker
+                    comment = new char[length-2];
+                    for (int foo = 0; foo < length - 2; foo++)
+                        comment[foo] = (char) in.read();
+                    hasComment = true;
+                }
+                else {
+                    // just skip marker
+                    for (int foo = 0; foo < length - 2; foo++) {
+                        in.read();
+                    }
+                }
+            }
+            return (new ImageProperties(width, height, comment, "jpeg"));
+
+        }
+        finally {
+            if (in != null) {
+                try {
+                    in.close();
+                }
+                catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    final public static ImageProperties getGifProperties(File file) throws FileNotFoundException, IOException, FileFormatException {
+        BufferedInputStream in = null;
+        try {
+            in = new BufferedInputStream(new FileInputStream(file));
+            byte[] buf = new byte[10];
+            int count = in.read(buf, 0, 10);
+            if (count < 10) {
+                throw new FileFormatException("Not a valid Gif file!");
+            }
+            if ((buf[0]) != (byte) 'G' || (buf[1]) != (byte) 'I' || (buf[2]) != (byte) 'F') {
+                throw new FileFormatException("Not a valid Gif file!");
+            }
+
+            int w1 = (buf[6] & 0xff) | (buf[6] & 0x80);
+            int w2 = (buf[7] & 0xff) | (buf[7] & 0x80);
+            int h1 = (buf[8] & 0xff) | (buf[8] & 0x80);
+            int h2 = (buf[9] & 0xff) | (buf[9] & 0x80);
+
+            int width = w1 + (w2 << 8);
+            int height = h1 + (h2 << 8);
+
+            return (new ImageProperties(width, height, null,"gif"));
+
+        }
+        finally {
+            if (in != null) {
+                try {
+                    in.close();
+                }
+                catch (IOException e) {
+                }
+            }
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/ImageUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/MIMEUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/MIMEUtils.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/MIMEUtils.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/MIMEUtils.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,175 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.cocoon.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * A collection of <code>File</code>, <code>URL</code> and filename
+ * utility methods.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:tk-cocoon@datas-world.de">Torsten Knodt</a>
+ * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
+ * @version CVS $Id: MIMEUtils.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class MIMEUtils {
+
+    private static final String MIME_MAPPING_FILE = "org/apache/cocoon/util/mime.types";
+
+    /** Default extensions for MIME types. */
+    final private static Map extMap = new HashMap();
+    /** MIME types for extensions. */
+    final private static Map mimeMap = new HashMap();
+
+    /**
+     * Load the MIME type mapping
+     */
+    static {
+        try {
+            final InputStream is = MIMEUtils.class.getClassLoader().getResourceAsStream(MIME_MAPPING_FILE);
+            if (null == is) {
+                throw new RuntimeException("Cocoon cannot load MIME type mappings from " + MIME_MAPPING_FILE);
+            }
+            loadMimeTypes(new InputStreamReader(is), extMap, mimeMap);
+        } catch (IOException ioe) {
+            throw new RuntimeException("Cocoon cannot load MIME type mappings from " + MIME_MAPPING_FILE);
+        }
+    }
+
+    /**
+     * Return the MIME type for a given file.
+     *
+     * @param file File.
+     * @return MIME type.
+     */
+    public static String getMIMEType(final File file)
+            throws FileNotFoundException, IOException {
+        BufferedInputStream in = null;
+
+        try {
+            in = new BufferedInputStream(new FileInputStream(file));
+            byte[] buf = new byte[3];
+            int count = in.read(buf, 0, 3);
+
+            if (count < 3) {
+                return (null);
+            }
+
+            if ((buf[0]) == (byte)'G' && (buf[1]) == (byte)'I' && (buf[2]) == (byte)'F') {
+                return ("image/gif");
+            }
+
+            if ((buf[0]) == (byte)0xFF && (buf[1]) == (byte)0xD8) {
+                return ("image/jpeg");
+            }
+
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        final String name = file.getName();
+        int index = name.lastIndexOf(".");
+        String fileExt = ".";
+        if (index != -1) {
+            fileExt = name.substring(index);
+        }
+        return getMIMEType(fileExt);
+    }
+
+    /**
+     * Return the MIME type for a given filename extension.
+     *
+     * @param ext Filename extension.
+     *
+     * @return MIME type.
+     */
+    public static String getMIMEType(final String ext) {
+        return (String)mimeMap.get(ext);
+    }
+
+    /**
+     * Return the default filename extension for a given MIME type.
+     *
+     * @param type MIME type.
+     *
+     * @return Filename extension.
+     */
+    public static String getDefaultExtension(final String type) {
+        return (String)extMap.get(type);
+    }
+
+    /**
+     * Parses a <code>mime.types</code> file, and generates mappings between
+     * MIME types and extensions.
+     * For example, if a line contains:
+     * <pre>text/html   html htm</pre>
+     * Then 'html' will be the default extension for text/html, and both 'html'
+     * and 'htm' will have MIME type 'text/html'.
+     * Lines starting with '#' are treated as comments and ignored.  If an
+     * extension is listed for two MIME types, the first will be chosen.
+     *
+     * @param in Reader of bytes from <code>mime.types</code> file content
+     * @param extMap Empty map of default extensions, keyed by MIME type. Will
+     * be filled in by this method.
+     * @param mimeMap Empty map of MIME types, keyed by extension.  Will be
+     * filled in by this method.
+     */
+    public static void loadMimeTypes(Reader in, Map extMap, Map mimeMap) throws IOException {
+        BufferedReader br = new BufferedReader(in);
+        String line;
+        while ((line = br.readLine()) != null) {
+            if (line.startsWith("#")) {
+                continue;
+            }
+            if (line.trim().equals("")) {
+                continue;
+            }
+            StringTokenizer tok = new StringTokenizer(line, " \t");
+            String mimeType = tok.nextToken();
+            if (tok.hasMoreTokens()) {
+                String defaultExt = tok.nextToken();
+                if (!extMap.containsKey(mimeType)) {
+                    extMap.put(mimeType, "." + defaultExt);
+                }
+                if (!mimeMap.containsKey("." + defaultExt)) {
+                    mimeMap.put("." + defaultExt, mimeType);
+                }
+                while (tok.hasMoreTokens()) {
+                    String ext = tok.nextToken();
+                    if (!mimeMap.containsKey("." + ext)) {
+                        mimeMap.put("." + ext, mimeType);
+                    }
+                }
+            }
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/util/MIMEUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message