diff options
Diffstat (limited to 'libjava/gnu')
640 files changed, 0 insertions, 138184 deletions
diff --git a/libjava/gnu/classpath/Configuration.java.in b/libjava/gnu/classpath/Configuration.java.in deleted file mode 100644 index f1c6bc5680d..00000000000 --- a/libjava/gnu/classpath/Configuration.java.in +++ /dev/null @@ -1,62 +0,0 @@ -/* gnu.classpath.Configuration - Copyright (C) 1998, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.classpath; - -/** - * This file defines compile-time constants that can be accessed by - * java code. It is pre-processed by configure. - */ -public interface Configuration -{ - // The value of DEBUG is substituted according to whether the - // "--enable-libgcj-debug" argument was passed to configure. Code - // which is made conditional based on the value of this flag will - // be removed by the optimizer in a non-debug build. - boolean DEBUG = @LIBGCJDEBUG@; - - // For libgcj we never load the JNI libraries. - boolean INIT_LOAD_LIBRARY = false; - - // For libgcj we have native methods for dynamic proxy support.... - boolean HAVE_NATIVE_GET_PROXY_DATA = false; - boolean HAVE_NATIVE_GET_PROXY_CLASS = false; - boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = false; - - // Name of default AWT peer library. - String default_awt_peer_toolkit = "@TOOLKIT@"; -} diff --git a/libjava/gnu/classpath/ServiceFactory.java b/libjava/gnu/classpath/ServiceFactory.java deleted file mode 100644 index 711a9042cbf..00000000000 --- a/libjava/gnu/classpath/ServiceFactory.java +++ /dev/null @@ -1,573 +0,0 @@ -/* ServiceFactory.java -- Factory for plug-in services. - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - - -/** - * A factory for plug-ins that conform to a service provider - * interface. This is a general mechanism that gets used by a number - * of packages in the Java API. For instance, {@link - * java.nio.charset.spi.CharsetProvider} allows to write custom - * encoders and decoders for character sets, {@link - * javax.imageio.spi.ImageReaderSpi} allows to support custom image - * formats, and {@link javax.print.PrintService} makes it possible to - * write custom printer drivers. - * - * <p>The plug-ins are concrete implementations of the service - * provider interface, which is defined as an interface or an abstract - * class. The implementation classes must be public and have a public - * constructor that takes no arguments. - * - * <p>Plug-ins are usually deployed in JAR files. A JAR that provides - * an implementation of a service must declare this in a resource file - * whose name is the fully qualified service name and whose location - * is the directory <code>META-INF/services</code>. This UTF-8 encoded - * text file lists, on separate lines, the fully qualified names of - * the concrete implementations. Thus, one JAR file can provide an - * arbitrary number of implementations for an arbitrary count of - * service provider interfaces. - * - * <p><b>Example</b> - * - * <p>For example, a JAR might provide two implementations of the - * service provider interface <code>org.foo.ThinkService</code>, - * namely <code>com.acme.QuickThinker</code> and - * <code>com.acme.DeepThinker</code>. The code for <code>QuickThinker</code> - * woud look as follows: - * - * <pre> - * package com.acme; - * - * /** - * * Provices a super-quick, but not very deep implementation of ThinkService. - * */ - * public class QuickThinker - * implements org.foo.ThinkService - * { - * /** - * * Constructs a new QuickThinker. The service factory (which is - * * part of the Java environment) calls this no-argument constructor - * * when it looks up the available implementations of ThinkService. - * * - * * <p>Note that an application might query all available - * * ThinkService providers, but use just one of them. Therefore, - * * constructing an instance should be very inexpensive. For example, - * * large data structures should only be allocated when the service - * * actually gets used. - * */ - * public QuickThinker() - * { - * } - * - * /** - * * Returns the speed of this ThinkService in thoughts per second. - * * Applications can choose among the available service providers - * * based on this value. - * */ - * public double getSpeed() - * { - * return 314159.2654; - * } - * - * /** - * * Produces a thought. While the returned thoughts are not very - * * deep, they are generated in very short time. - * */ - * public Thought think() - * { - * return null; - * } - * } - * </pre> - * - * <p>The code for <code>com.acme.DeepThinker</code> is left as an - * exercise to the reader. - * - * <p>Acme’s <code>ThinkService</code> plug-in gets deployed as - * a JAR file. Besides the bytecode and resources for - * <code>QuickThinker</code> and <code>DeepThinker</code>, it also - * contains the text file - * <code>META-INF/services/org.foo.ThinkService</code>: - * - * <pre> - * # Available implementations of org.foo.ThinkService - * com.acme.QuickThinker - * com.acme.DeepThinker - * </pre> - * - * <p><b>Thread Safety</b> - * - * <p>It is safe to use <code>ServiceFactory</code> from multiple - * concurrent threads without external synchronization. - * - * <p><b>Note for User Applications</b> - * - * <p>User applications that want to load plug-ins should not directly - * use <code>gnu.classpath.ServiceFactory</code>, because this class - * is only available in Java environments that are based on GNU - * Classpath. Instead, it is recommended that user applications call - * {@link - * javax.imageio.spi.ServiceRegistry#lookupProviders(Class)}. This API - * is actually independent of image I/O, and it is available on every - * environment. - * - * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> - */ -public final class ServiceFactory -{ - /** - * A logger that gets informed when a service gets loaded, or - * when there is a problem with loading a service. - * - * <p>Because {@link java.util.logging.Logger#getLogger(String)} - * is thread-safe, we do not need to worry about synchronization - * here. - */ - private static final Logger LOGGER = Logger.getLogger("gnu.classpath"); - - - /** - * Declared private in order to prevent constructing instances of - * this utility class. - */ - private ServiceFactory() - { - } - - - /** - * Finds service providers that are implementing the specified - * Service Provider Interface. - * - * <p><b>On-demand loading:</b> Loading and initializing service - * providers is delayed as much as possible. The rationale is that - * typical clients will iterate through the set of installed service - * providers until one is found that matches some criteria (like - * supported formats, or quality of service). In such scenarios, it - * might make sense to install only the frequently needed service - * providers on the local machine. More exotic providers can be put - * onto a server; the server will only be contacted when no suitable - * service could be found locally. - * - * <p><b>Security considerations:</b> Any loaded service providers - * are loaded through the specified ClassLoader, or the system - * ClassLoader if <code>classLoader</code> is - * <code>null</code>. When <code>lookupProviders</code> is called, - * the current {@link AccessControlContext} gets recorded. This - * captured security context will determine the permissions when - * services get loaded via the <code>next()</code> method of the - * returned <code>Iterator</code>. - * - * @param spi the service provider interface which must be - * implemented by any loaded service providers. - * - * @param loader the class loader that will be used to load the - * service providers, or <code>null</code> for the system class - * loader. For using the context class loader, see {@link - * #lookupProviders(Class)}. - * - * @return an iterator over instances of <code>spi</code>. - * - * @throws IllegalArgumentException if <code>spi</code> is - * <code>null</code>. - */ - public static Iterator lookupProviders(Class spi, - ClassLoader loader) - { - String resourceName; - Enumeration urls; - - if (spi == null) - throw new IllegalArgumentException(); - - if (loader == null) - loader = ClassLoader.getSystemClassLoader(); - - resourceName = "META-INF/services/" + spi.getName(); - try - { - urls = loader.getResources(resourceName); - } - catch (IOException ioex) - { - /* If an I/O error occurs here, we cannot provide any service - * providers. In this case, we simply return an iterator that - * does not return anything (no providers installed). - */ - log(Level.WARNING, "cannot access {0}", resourceName, ioex); - return Collections.EMPTY_LIST.iterator(); - } - - return new ServiceIterator(spi, urls, loader, - AccessController.getContext()); - } - - - /** - * Finds service providers that are implementing the specified - * Service Provider Interface, using the context class loader - * for loading providers. - * - * @param spi the service provider interface which must be - * implemented by any loaded service providers. - * - * @return an iterator over instances of <code>spi</code>. - * - * @throws IllegalArgumentException if <code>spi</code> is - * <code>null</code>. - * - * @see #lookupProviders(Class, ClassLoader) - */ - public static Iterator lookupProviders(Class spi) - { - ClassLoader ctxLoader; - - ctxLoader = Thread.currentThread().getContextClassLoader(); - return lookupProviders(spi, ctxLoader); - } - - - /** - * An iterator over service providers that are listed in service - * provider configuration files, which get passed as an Enumeration - * of URLs. This is a helper class for {@link - * ServiceFactory#lookupProviders}. - * - * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> - */ - private static final class ServiceIterator - implements Iterator - { - /** - * The service provider interface (usually an interface, sometimes - * an abstract class) which the services must implement. - */ - private final Class spi; - - - /** - * An Enumeration<URL> over the URLs that contain a resource - * <code>META-INF/services/<org.foo.SomeService></code>, - * as returned by {@link ClassLoader#getResources(String)}. - */ - private final Enumeration urls; - - - /** - * The class loader used for loading service providers. - */ - private final ClassLoader loader; - - - /** - * The security context used when loading and initializing service - * providers. We want to load and initialize all plug-in service - * providers under the same security context, namely the one that - * was active when {@link #lookupProviders} has been called. - */ - private final AccessControlContext securityContext; - - - /** - * A reader for the current file listing class names of service - * implementors, or <code>null</code> when the last reader has - * been fetched. - */ - private BufferedReader reader; - - - /** - * The URL currently being processed. This is only used for - * emitting error messages. - */ - private URL currentURL; - - - /** - * The service provider that will be returned by the next call to - * {@link #next()}, or <code>null</code> if the iterator has - * already returned all service providers. - */ - private Object nextProvider; - - - /** - * Constructs an Iterator that loads and initializes services on - * demand. - * - * @param spi the service provider interface which the services - * must implement. Usually, this is a Java interface type, but it - * might also be an abstract class or even a concrete superclass. - * - * @param urls an Enumeration<URL> over the URLs that contain a - * resource - * <code>META-INF/services/<org.foo.SomeService></code>, as - * determined by {@link ClassLoader#getResources(String)}. - * - * @param loader the ClassLoader that gets used for loading - * service providers. - * - * @param securityContext the security context to use when loading - * and initializing service providers. - */ - ServiceIterator(Class spi, Enumeration urls, ClassLoader loader, - AccessControlContext securityContext) - { - this.spi = spi; - this.urls = urls; - this.loader = loader; - this.securityContext = securityContext; - this.nextProvider = loadNextServiceProvider(); - } - - - /** - * @throws NoSuchElementException if {@link #hasNext} returns - * <code>false</code>. - */ - public Object next() - { - Object result; - - if (!hasNext()) - throw new NoSuchElementException(); - - result = nextProvider; - nextProvider = loadNextServiceProvider(); - return result; - } - - - public boolean hasNext() - { - return nextProvider != null; - } - - - public void remove() - { - throw new UnsupportedOperationException(); - } - - - private Object loadNextServiceProvider() - { - String line; - - if (reader == null) - advanceReader(); - - for (;;) - { - /* If we have reached the last provider list, we cannot - * retrieve any further lines. - */ - if (reader == null) - return null; - - try - { - line = reader.readLine(); - } - catch (IOException readProblem) - { - log(Level.WARNING, "IOException upon reading {0}", currentURL, - readProblem); - line = null; - } - - /* When we are at the end of one list of services, - * switch over to the next one. - */ - if (line == null) - { - advanceReader(); - continue; - } - - - // Skip whitespace at the beginning and end of each line. - line = line.trim(); - - // Skip empty lines. - if (line.length() == 0) - continue; - - // Skip comment lines. - if (line.charAt(0) == '#') - continue; - - try - { - log(Level.FINE, - "Loading service provider \"{0}\", specified" - + " by \"META-INF/services/{1}\" in {2}.", - new Object[] { line, spi.getName(), currentURL }, - null); - - /* Load the class in the security context that was - * active when calling lookupProviders. - */ - return AccessController.doPrivileged( - new ServiceProviderLoadingAction(spi, line, loader), - securityContext); - } - catch (Exception ex) - { - String msg = "Cannot load service provider class \"{0}\"," - + " specified by \"META-INF/services/{1}\" in {2}"; - if (ex instanceof PrivilegedActionException - && ex.getCause() instanceof ClassCastException) - msg = "Service provider class \"{0}\" is not an instance" - + " of \"{1}\". Specified" - + " by \"META-INF/services/{1}\" in {2}."; - - log(Level.WARNING, msg, - new Object[] { line, spi.getName(), currentURL }, - ex); - continue; - } - } - } - - - private void advanceReader() - { - do - { - if (reader != null) - { - try - { - reader.close(); - log(Level.FINE, "closed {0}", currentURL, null); - } - catch (Exception ex) - { - log(Level.WARNING, "cannot close {0}", currentURL, ex); - } - reader = null; - currentURL = null; - } - - if (!urls.hasMoreElements()) - return; - - currentURL = (URL) urls.nextElement(); - try - { - reader = new BufferedReader(new InputStreamReader( - currentURL.openStream(), "UTF-8")); - log(Level.FINE, "opened {0}", currentURL, null); - } - catch (Exception ex) - { - log(Level.WARNING, "cannot open {0}", currentURL, ex); - } - } - while (reader == null); - } - } - - - // Package-private to avoid a trampoline. - /** - * Passes a log message to the <code>java.util.logging</code> - * framework. This call returns very quickly if no log message will - * be produced, so there is not much overhead in the standard case. - * - * @param the severity of the message, for instance {@link - * Level#WARNING}. - * - * @param msg the log message, for instance <code>“Could not - * load {0}.”</code> - * - * @param param the parameter(s) for the log message, or - * <code>null</code> if <code>msg</code> does not specify any - * parameters. If <code>param</code> is not an array, an array with - * <code>param</code> as its single element gets passed to the - * logging framework. - * - * @param t a Throwable that is associated with the log record, or - * <code>null</code> if the log message is not associated with a - * Throwable. - */ - static void log(Level level, String msg, Object param, Throwable t) - { - LogRecord rec; - - // Return quickly if no log message will be produced. - if (!LOGGER.isLoggable(level)) - return; - - rec = new LogRecord(level, msg); - if (param != null && param.getClass().isArray()) - rec.setParameters((Object[]) param); - else - rec.setParameters(new Object[] { param }); - - rec.setThrown(t); - - // While java.util.logging can sometimes infer the class and - // method of the caller, this automatic inference is not reliable - // on highly optimizing VMs. Also, log messages make more sense to - // developers when they display a public method in a public class; - // otherwise, they might feel tempted to figure out the internals - // of ServiceFactory in order to understand the problem. - rec.setSourceClassName(ServiceFactory.class.getName()); - rec.setSourceMethodName("lookupProviders"); - - LOGGER.log(rec); - } -} diff --git a/libjava/gnu/classpath/ServiceProviderLoadingAction.java b/libjava/gnu/classpath/ServiceProviderLoadingAction.java deleted file mode 100644 index b5e59cb4b6f..00000000000 --- a/libjava/gnu/classpath/ServiceProviderLoadingAction.java +++ /dev/null @@ -1,149 +0,0 @@ -/* ServiceProviderLoadingAction.java -- Action for loading plug-in services. - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath; - -import java.security.PrivilegedExceptionAction; - -/** - * A privileged action for creating a new instance of a service - * provider. - * - * <p>Class loading and instantiation is encapsulated in a - * <code>PriviledgedAction</code> in order to restrict the loaded - * service providers to the {@link java.security.AccessControlContext} - * that was active when {@link - * gnu.classpath.ServiceFactory#lookupProviders} was called, even - * though the actual loading is delayed to the time when the provider - * is actually needed. - * - * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> - */ -final class ServiceProviderLoadingAction - implements PrivilegedExceptionAction -{ - /** - * The interface to which the loaded service provider implementation - * must conform. Usually, this is a Java interface type, but it - * might also be an abstract class or even a concrete class. - */ - private final Class spi; - - - /** - * The fully qualified name of the class that gets loaded when - * this action is executed. - */ - private final String providerName; - - - /** - * The ClassLoader that gets used for loading the service provider - * class. - */ - private final ClassLoader loader; - - - /** - * Constructs a privileged action for loading a service provider. - * - * @param spi the interface to which the loaded service provider - * implementation must conform. Usually, this is a Java interface - * type, but it might also be an abstract class or even a concrete - * superclass. - * - * @param providerName the fully qualified name of the class that - * gets loaded when this action is executed. - * - * @param loader the ClassLoader that gets used for loading the - * service provider class. - * - * @throws IllegalArgumentException if <code>spi</code>, - * <code>providerName</code> or <code>loader</code> is - * <code>null</code>. - */ - ServiceProviderLoadingAction(Class spi, String providerName, - ClassLoader loader) - { - if (spi == null || providerName == null || loader == null) - throw new IllegalArgumentException(); - - this.spi = spi; - this.providerName = providerName; - this.loader = loader; - } - - - /** - * Loads an implementation class for a service provider, and creates - * a new instance of the loaded class by invoking its public - * no-argument constructor. - * - * @return a new instance of the class whose name was passed as - * <code>providerName</code> to the constructor. - * - * @throws ClassCastException if the service provider does not - * implement the <code>spi</code> interface that was passed to the - * constructor. - * - * @throws IllegalAccessException if the service provider class or - * its no-argument constructor are not <code>public</code>. - * - * @throws InstantiationException if the service provider class is - * <code>abstract</code>, an interface, a primitive type, an array - * class, or void; or if service provider class does not have a - * no-argument constructor; or if there some other problem with - * creating a new instance of the service provider. - */ - public Object run() - throws Exception - { - Class loadedClass; - Object serviceProvider; - - loadedClass = loader.loadClass(providerName); - serviceProvider = loadedClass.newInstance(); - - // Ensure that the loaded provider is actually implementing - // the service provider interface. - if (!spi.isInstance(serviceProvider)) - throw new ClassCastException(spi.getName()); - - return serviceProvider; - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidClassException.java b/libjava/gnu/classpath/jdwp/exception/InvalidClassException.java deleted file mode 100644 index 2e9b7246818..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidClassException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidClassException.java -- invalid/unknown class reference id exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown by the JDWP back-end when an invalid reference - * type id is used by the debugger. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidClassException - extends JdwpException -{ - public InvalidClassException (long id) - { - super (JdwpConstants.Error.INVALID_CLASS, - "invalid class id (" + id + ")"); - } - - public InvalidClassException (Throwable t) - { - super (JdwpConstants.Error.INVALID_CLASS, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidCountException.java b/libjava/gnu/classpath/jdwp/exception/InvalidCountException.java deleted file mode 100644 index 668db042d6b..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidCountException.java +++ /dev/null @@ -1,61 +0,0 @@ -/* InvalidCountException -- an invalid count exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when a count filter is given an invalid count. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidCountException - extends JdwpException -{ - public InvalidCountException (int id) - { - super (JdwpConstants.Error.INVALID_COUNT, "invalid count (" + id + ")"); - } - - public InvalidCountException (Throwable t) - { - super (JdwpConstants.Error.INVALID_COUNT, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidEventTypeException.java b/libjava/gnu/classpath/jdwp/exception/InvalidEventTypeException.java deleted file mode 100644 index 6463325804c..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidEventTypeException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidEventTypeException.java -- an invalid event kind exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when the debugger asks for an event request - * for a non-existant event - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidEventTypeException - extends JdwpException -{ - public InvalidEventTypeException (byte kind) - { - super (JdwpConstants.Error.INVALID_EVENT_TYPE, - "invalid event type (" + kind + ")"); - } - - public InvalidEventTypeException (Throwable t) - { - super (JdwpConstants.Error.INVALID_EVENT_TYPE, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidObjectException.java b/libjava/gnu/classpath/jdwp/exception/InvalidObjectException.java deleted file mode 100644 index 587f4609e8f..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidObjectException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidObjectException.java -- an invalid object id exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when an invalid object id is used by - * the debugger - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidObjectException - extends JdwpException -{ - public InvalidObjectException (long id) - { - super (JdwpConstants.Error.INVALID_OBJECT, - "invalid object id (" + id + ")"); - } - - public InvalidObjectException (Throwable t) - { - super (JdwpConstants.Error.INVALID_OBJECT, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidStringException.java b/libjava/gnu/classpath/jdwp/exception/InvalidStringException.java deleted file mode 100644 index c689d5f1678..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidStringException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidStringException.java -- an invalid string id exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when the debugger uses an invalid String - * id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidStringException - extends JdwpException -{ - public InvalidStringException (String str) - { - super (JdwpConstants.Error.INVALID_STRING, - "invalid string (" + str + ")"); - } - - public InvalidStringException (Throwable t) - { - super (JdwpConstants.Error.INVALID_STRING, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidThreadException.java b/libjava/gnu/classpath/jdwp/exception/InvalidThreadException.java deleted file mode 100644 index bcbaf4902ed..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidThreadException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidThreadException.java -- an invalid thread id exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when an invalid thread id is used - * by the debugger - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidThreadException - extends JdwpException -{ - public InvalidThreadException (long id) - { - super (JdwpConstants.Error.INVALID_THREAD, - "invalid thread id (" + id + ")"); - } - - public InvalidThreadException (Throwable t) - { - super (JdwpConstants.Error.INVALID_THREAD, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java b/libjava/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java deleted file mode 100644 index 92b214f4696..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/InvalidThreadGroupException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* InvalidThreadGroupException.java -- an invalid thread group id exception - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when an invalid thread group id is used - * by the debugger - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InvalidThreadGroupException - extends JdwpException -{ - public InvalidThreadGroupException (long id) - { - super (JdwpConstants.Error.INVALID_THREAD_GROUP, - "invalid thread id (" + id + ")"); - } - - public InvalidThreadException (Throwable t) - { - super (JdwpConstants.Error.INVALID_THREAD_GROUP, t); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/JdwpException.java b/libjava/gnu/classpath/jdwp/exception/JdwpException.java deleted file mode 100644 index 6d4887cdad2..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/JdwpException.java +++ /dev/null @@ -1,86 +0,0 @@ -/* JdwpException.java -- an exception base class for all JDWP exceptions - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -/** - * A base class exception for all JDWP back-end exceptions - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class JdwpException - extends Exception -{ - // The integer error code defined by JDWP - private short _errorCode; - - /** - * Constructs a new <code>JdwpException</code> with the - * given error code and given cause - * - * @param code the JDWP error code - * @param t the cause of the exception - */ - public JdwpException (short code, Throwable t) - { - super (t); - _errorCode = code; - } - - /** - * Constructs a new <code>JdwpException</code> with the - * given error code and string error message - * - * @param code the JDWP error code - * @param str an error message - */ - public JdwpException (short code, String str) - { - super (str); - _errorCode = code; - } - - /** - * Returns the JDWP error code represented by this exception - */ - public short getErrorCode () - { - return _errorCode; - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java b/libjava/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java deleted file mode 100644 index d76ad8ca837..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java +++ /dev/null @@ -1,58 +0,0 @@ -/* JdwpInternalErrorException.java -- an internal error exception - features or functions - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown by the JDWP back-end when an unusual runtime - * error occurs internally - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class JdwpInternalErrorException - extends JdwpException -{ - public JdwpInternalErrorException (Throwable cause) - { - super (JdwpConstants.Error.INTERNAL, cause); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/NotImplementedException.java b/libjava/gnu/classpath/jdwp/exception/NotImplementedException.java deleted file mode 100644 index 8f5feabe9b8..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/NotImplementedException.java +++ /dev/null @@ -1,59 +0,0 @@ -/* NotImplementedException.java -- an exception for unimplemented JDWP - features or functions - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown by virtual machines when functionality - * or features are not implemented - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class NotImplementedException - extends JdwpException -{ - public NotImplementedException (String feature) - { - super (JdwpConstants.Error.NOT_IMPLEMENTED, - feature + " is not yet implemented"); - } -} diff --git a/libjava/gnu/classpath/jdwp/exception/VmDeadException.java b/libjava/gnu/classpath/jdwp/exception/VmDeadException.java deleted file mode 100644 index 6164018db64..00000000000 --- a/libjava/gnu/classpath/jdwp/exception/VmDeadException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Jdwp.java -- Virtual machine to JDWP back-end programming interface - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.classpath.jdwp.exception; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * An exception thrown when the virtual machine is dead - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class VmDeadException - extends JdwpException -{ - public VmDeadException () - { - super (JdwpConstants.Error.VM_DEAD, "Virtual machine is dead"); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ArrayId.java b/libjava/gnu/classpath/jdwp/id/ArrayId.java deleted file mode 100644 index cd428a172b3..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ArrayId.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ArrayId.java -- array object IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP array id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ArrayId - extends ObjectId -{ - // Arrays are handled a little differently than other IDs - //public static final Class typeClass = UNDEFINED - - /** - * Constructs a new <code>ArrayId</code> - */ - public ArrayId () - { - super (JdwpConstants.Tag.ARRAY); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java b/libjava/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java deleted file mode 100644 index 14a73dc5b24..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ArrayReferenceTypeId.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ArrayReferenceTypeId.java -- array reference type ids - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A reference type ID representing java arrays - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ArrayReferenceTypeId - extends ReferenceTypeId -{ - /** - * Constructs a new <code>ArrayReferenceTypeId</code> - */ - public ArrayReferenceTypeId () - { - super (JdwpConstants.TypeTag.ARRAY); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ClassLoaderId.java b/libjava/gnu/classpath/jdwp/id/ClassLoaderId.java deleted file mode 100644 index 133872566fd..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ClassLoaderId.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ClassLoaderId.java -- class loader IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP thread id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ClassLoaderId - extends ObjectId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = ClassLoader.class; - - /** - * Constructs a new <code>ClassLoaderId</code> - */ - public ClassLoaderId () - { - super (JdwpConstants.Tag.CLASS_LOADER); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ClassObjectId.java b/libjava/gnu/classpath/jdwp/id/ClassObjectId.java deleted file mode 100644 index e5559ce10f3..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ClassObjectId.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ClassObjectId.java -- class object IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP class object id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ClassObjectId - extends ObjectId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = Class.class; - - /** - * Constructs a new <code>ClassObjectId</code> - */ - public ClassObjectId () - { - super (JdwpConstants.Tag.CLASS_OBJECT); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ClassReferenceTypeId.java b/libjava/gnu/classpath/jdwp/id/ClassReferenceTypeId.java deleted file mode 100644 index 6b57673f827..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ClassReferenceTypeId.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ClassReferenceTypeId.java -- class reference type ids - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A reference type ID representing java classes - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ClassReferenceTypeId - extends ReferenceTypeId -{ - /** - * Constructs a new <code>ClassReferenceTypeId</code> - */ - public ClassReferenceTypeId () - { - super (JdwpConstants.TypeTag.CLASS); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java b/libjava/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java deleted file mode 100644 index bdbd6b6ebff..00000000000 --- a/libjava/gnu/classpath/jdwp/id/InterfaceReferenceTypeId.java +++ /dev/null @@ -1,59 +0,0 @@ -/* InterfaceReferenceTypeId.java -- interface reference type ids - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A reference type ID representing java interfaces - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class InterfaceReferenceTypeId - extends ReferenceTypeId -{ - /** - * Constructs a new <code>InterfaceReferenceTypeId</code> - */ - public InterfaceReferenceTypeId () - { - super (JdwpConstants.TypeTag.INTERFACE); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/JdwpId.java b/libjava/gnu/classpath/jdwp/id/JdwpId.java deleted file mode 100644 index 37f82e208c5..00000000000 --- a/libjava/gnu/classpath/jdwp/id/JdwpId.java +++ /dev/null @@ -1,127 +0,0 @@ -/* JdwpId.java -- base class for all object ID types - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * A baseclass for all object types reported to the debugger - * - * @author Keith Seitz <keiths@redhat.com> - */ -public abstract class JdwpId -{ - /** - * ID assigned to this object - */ - protected long _id; - - /** - * Tag of ID's type (see {@link gnu.classpath.jdwp.JdwpConstants.Tag}) - * for object-like IDs or the type tag (see {@link - * gnu.classpath.JdwpConstants.TypeTag}) for reference type IDs. - */ - private byte _tag; - - /** - * Constructs an empty <code>JdwpId</code> - */ - public JdwpId (byte tag) - { - _tag = tag; - } - - /** - * Sets the id for this object reference - */ - void setId (long id) - { - _id = id; - } - - /** - * Returns the id for this object reference - */ - public long getId () - { - return _id; - } - - /** - * Compares two object ids for equality. Two object ids - * are equal if they point to the same type and contain to - * the same id number. (NOTE: This is a much stricter check - * than is necessary: all <code>JdwpId</code>s have unique - * ids.) - */ - public boolean equals (JdwpId id) - { - return ((id.getClass () == getClass ()) && (id.getId () == getId ())); - } - - /** - * Returns size of this type (used by IDSizes) - */ - public abstract int size (); - - /** - * Writes the contents of this type to the <code>DataOutputStream</code> - * @param outStream the <code>DataOutputStream</code> to use - * @throws IOException when an error occurs on the <code>OutputStream</code> - */ - public abstract void write (DataOutputStream outStream) - throws IOException; - - /** - * Writes the contents of this type to the output stream, preceded - * by a one-byte tag for tagged object IDs or type tag for - * reference type IDs. - * - * @param outStream the <code>DataOutputStream</code> to use - * @throws IOException when an error occurs on the <code>OutputStream</code> - */ - public void writeTagged (DataOutputStream outStream) - throws IOException - { - outStream.writeByte (_tag); - write (outStream); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/JdwpIdFactory.java b/libjava/gnu/classpath/jdwp/id/JdwpIdFactory.java deleted file mode 100644 index 06ec3c7681f..00000000000 --- a/libjava/gnu/classpath/jdwp/id/JdwpIdFactory.java +++ /dev/null @@ -1,165 +0,0 @@ -/* JdwpIdFactory.java -- factory for generating type and object IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import java.util.HashMap; - -/** - * This factory generates ids for objects and types that may - * be sent to a debugger. - * - * @author Keith Seitz (keiths@redhat.com) - */ -public class JdwpIdFactory -{ - // ID of last object / referencetype - private static Object _idLock = new Object (); - private static Object _ridLock = new Object (); - private static long _lastId = 0; - private static long _lastRid = 0; - - // A list of all ID types - private static HashMap _idList = new HashMap (); - - // Initialize the id list with known types - static - { - // ObjectId and ArrayId are special cases. See newId. - _idList.put (ClassLoaderId.typeClass, ClassLoaderId.class); - _idList.put (ClassObjectId.typeClass, ClassObjectId.class); - //_idList.put (FieldId.typeClass, FieldId.class); - //_idList.put (FrameId.typeClass, FrameId.class); - //_idList.put (MethodId.typeClass, MethodId.class); - _idList.put (StringId.typeClass, StringId.class); - _idList.put (ThreadId.typeClass, ThreadId.class); - _idList.put (ThreadGroupId.typeClass, ThreadGroupId.class); - } - - /** - * Returns a new id for the given object - * - * @param object the object for which an id is desired - * @returns a suitable object id - */ - public static JdwpId newId (Object object) - { - JdwpId id = null; - - // Special case: arrays - if (object.getClass ().isArray ()) - id = new ArrayId (); - else - { - // Loop through all classes until we hit baseclass - Class myClass; - for (myClass = object.getClass (); myClass != null; - myClass = myClass.getSuperclass ()) - { - Class clz = (Class) _idList.get (myClass); - if (clz != null) - { - try - { - id = (JdwpId) clz.newInstance (); - synchronized (_idLock) - { - id.setId (++_lastId); - } - return id; - } - catch (InstantiationException ie) - { - // This really should not happen - throw new RuntimeException ("cannot create new ID", ie); - } - catch (IllegalAccessException iae) - { - // This really should not happen - throw new RuntimeException ("illegal access of ID", iae); - } - } - } - - /* getSuperclass returned null and no matching ID type found. - So it must derive from Object. */ - id = new ObjectId (); - } - - synchronized (_idLock) - { - id.setId (++_lastId); - } - - return id; - } - - /** - * Returns a new reference type id for the given class - * - * @param clazz the <code>Class</code> for which an id is desired - * @returns a suitable reference type id or <code>null</code> - */ - public static ReferenceTypeId newReferenceTypeId (Class clazz) - { - ReferenceTypeId id = null; - try - { - if (clazz.isArray ()) - id = new ArrayReferenceTypeId (); - else if (clazz.isInterface ()) - id = new InterfaceReferenceTypeId (); - else - id = new ClassReferenceTypeId (); - synchronized (_ridLock) - { - id.setId (++_lastRid); - } - return id; - } - catch (InstantiationException ie) - { - return null; - } - catch (IllegalAccessException iae) - { - return null; - } - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ObjectId.java b/libjava/gnu/classpath/jdwp/id/ObjectId.java deleted file mode 100644 index e34a3b59ebf..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ObjectId.java +++ /dev/null @@ -1,99 +0,0 @@ -/* ObjectId.java -- object IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * A class which represents a JDWP object id for an object - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ObjectId - extends JdwpId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = Object.class; - - /** - * Constructs a new <code>ObjectId</code> - */ - public ObjectId () - { - super (JdwpConstants.Tag.OBJECT); - } - - /** - * Constructs a new <code>ObjectId</code> of the - * given type. - * - * @param tag the tag of this type of object ID - */ - public ObjectId (byte tag) - { - super (tag); - } - - /** - * Returns the size of this id type - */ - public int size () - { - return 8; - } - - /** - * Writes the id to the stream - * - * @param outStream the stream to which to write - * @throws IOException when an error occurs on the <code>OutputStream</code> - */ - public void write (DataOutputStream outStream) - throws IOException - { - // All we need to do is write out our id as an 8-byte integer - outStream.writeLong (_id); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ReferenceTypeId.java b/libjava/gnu/classpath/jdwp/id/ReferenceTypeId.java deleted file mode 100644 index cdb78040a41..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ReferenceTypeId.java +++ /dev/null @@ -1,81 +0,0 @@ -/* ReferenceTypeId.java -- a base class for all reference type IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * Base class for reference type IDs. This class usurps - * <code>JdwpId</code>'s tag member for its own use (type tag). - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ReferenceTypeId - extends JdwpId -{ - /** - * Constructor used by {Array,Interface,Class}ReferenceTypeId - */ - public ReferenceTypeId (byte tag) - { - super (tag); - } - - /** - * Returns the size of this ID type - */ - public int size () - { - return 8; - } - - /** - * Outputs the reference type ID to the given output stream - * - * @param outStream the stream to which to write the data - * @throws IOException for errors writing to the stream - */ - public void write (DataOutputStream outStream) - throws IOException - { - outStream.writeLong (_id); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/StringId.java b/libjava/gnu/classpath/jdwp/id/StringId.java deleted file mode 100644 index ea1a83a56a2..00000000000 --- a/libjava/gnu/classpath/jdwp/id/StringId.java +++ /dev/null @@ -1,64 +0,0 @@ -/* StringId.java -- string IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP string id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class StringId - extends ObjectId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = String.class; - - /** - * Constructs a new <code>StringId</code> - */ - public StringId () - { - super (JdwpConstants.Tag.STRING); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ThreadGroupId.java b/libjava/gnu/classpath/jdwp/id/ThreadGroupId.java deleted file mode 100644 index aef7d5b5421..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ThreadGroupId.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ThreadGroupId.java -- thread group IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP thread group id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ThreadGroupId - extends ObjectId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = ThreadGroup.class; - - /** - * Constructs a new <code>ThreadGroupId</code> - */ - public ThreadGroupId () - { - super (JdwpConstants.Tag.THREAD_GROUP); - } -} diff --git a/libjava/gnu/classpath/jdwp/id/ThreadId.java b/libjava/gnu/classpath/jdwp/id/ThreadId.java deleted file mode 100644 index 733bf55102b..00000000000 --- a/libjava/gnu/classpath/jdwp/id/ThreadId.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ThreadId.java -- thread IDs - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.id; - -import gnu.classpath.jdwp.JdwpConstants; - -/** - * A class which represents a JDWP thread id - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class ThreadId - extends ObjectId -{ - /** - * The object class that this id represents - */ - public static final Class typeClass = Thread.class; - - /** - * Constructs a new <code>ThreadId</code> - */ - public ThreadId () - { - super (JdwpConstants.Tag.THREAD); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/CommandSet.java b/libjava/gnu/classpath/jdwp/processor/CommandSet.java deleted file mode 100644 index 17b956ceadc..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/CommandSet.java +++ /dev/null @@ -1,68 +0,0 @@ -/* CommandSet.java -- An interface defining JDWP Command Sets - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.exception.JdwpException; - -import java.io.DataOutputStream; -import java.nio.ByteBuffer; - -/** - * A class representing a JDWP Command Set. This class serves as a generic - * interface for all Command Sets types used by JDWP. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public interface CommandSet -{ - /** - * Runs the given command with the data in distr and writes the data for the - * reply packet to ostr. - * - * @param bb holds the data portion of the Command Packet - * @param os data portion of the Reply Packet will be written here - * @param command the command field of the Command Packet - * @return true if the JDWP layer should shut down in response to this packet - * @throws JdwpException command wasn't carried out successfully - */ - public boolean runCommand(ByteBuffer bb, DataOutputStream os, - byte command) - throws JdwpException; -} diff --git a/libjava/gnu/classpath/jdwp/processor/FieldCommandSet.java b/libjava/gnu/classpath/jdwp/processor/FieldCommandSet.java deleted file mode 100644 index f14635b9188..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/FieldCommandSet.java +++ /dev/null @@ -1,66 +0,0 @@ -/* FieldCommandSet.java -- class to implement the Field Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.NotImplementedException; - -import java.io.DataOutputStream; -import java.nio.ByteBuffer; - -/** - * A class representing the Field Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class FieldCommandSet implements CommandSet -{ - /** - * There are no commands for this CommandSet at this time so we just throw a - * NotImplementedException whenever it's called. - * - * @throws JdwpException An exception will always be thrown - */ - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - throw new NotImplementedException( - "No commands for command set Field implemented."); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java b/libjava/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java deleted file mode 100644 index a32da38b324..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/InterfaceTypeCommandSet.java +++ /dev/null @@ -1,67 +0,0 @@ -/* InterfaceTypeCommandSet.java -- class to implement the InterfaceType - Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.NotImplementedException; - -import java.io.DataOutputStream; -import java.nio.ByteBuffer; - -/** - * A class representing the InterfaceType Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class InterfaceTypeCommandSet implements CommandSet -{ - /** - * There are no commands for this CommandSet at this time so we just throw a - * NotImplementedException whenever it's called. - * - * @throws JdwpException An exception will always be thrown - */ - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - throw new NotImplementedException( - "No commands for command set InterfaceType implemented."); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/libjava/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java deleted file mode 100644 index 38bb0cdbf96..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java +++ /dev/null @@ -1,249 +0,0 @@ -/* ObjectReferenceCommandSet.java -- lass to implement the ObjectReference - Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.IVirtualMachine; -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.exception.InvalidFieldException; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; -import gnu.classpath.jdwp.exception.NotImplementedException; -import gnu.classpath.jdwp.id.IdManager; -import gnu.classpath.jdwp.id.ObjectId; -import gnu.classpath.jdwp.id.ReferenceTypeId; -import gnu.classpath.jdwp.util.Value; -import gnu.classpath.jdwp.util.MethodInvoker; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.nio.ByteBuffer; - -/** - * A class representing the ObjectReference Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class ObjectReferenceCommandSet implements CommandSet -{ - // Our hook into the jvm - private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); - - // Manages all the different ids that are assigned by jdwp - private final IdManager idMan = Jdwp.getIdManager(); - - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - try - { - switch (command) - { - case JdwpConstants.CommandSet.ObjectReference.REFERENCE_TYPE: - executeReferenceType(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.GET_VALUES: - executeGetValues(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.SET_VALUES: - executeSetValues(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.MONITOR_INFO: - executeMonitorInfo(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.INVOKE_METHOD: - executeInvokeMethod(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.DISABLE_COLLECTION: - executeDisableCollection(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.ENABLE_COLLECTION: - executeEnableCollection(bb, os); - break; - case JdwpConstants.CommandSet.ObjectReference.IS_COLLECTED: - executeIsCollected(bb, os); - break; - default: - throw new NotImplementedException("Command " + command + - " not found in String Reference Command Set."); - } - } - catch (IOException ex) - { - // The DataOutputStream we're using isn't talking to a socket at all - // So if we throw an IOException we're in serious trouble - throw new JdwpInternalErrorException(ex); - } - return true; - } - - private void executeReferenceType(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - Object obj = oid.getObject(); - Class clazz = obj.getClass(); - ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); - refId.writeTagged(os); - } - - private void executeGetValues(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - Object obj = oid.getObject(); - - int numFields = bb.getInt(); - - os.writeInt(numFields); // Looks pointless but this is the protocol - - for (int i = 0; i < numFields; i++) - { - Field field = (Field) idMan.readId(bb).getObject(); - Value.writeValueFromField(os, field, obj); - } - } - - private void executeSetValues(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - Object obj = oid.getObject(); - - int numFields = bb.getInt(); - - for (int i = 0; i < numFields; i++) - { - Field field = (Field) idMan.readId(bb).getObject(); - Object value = Value.getObj(bb, field); - try - { - field.set(obj, value); - } - catch (IllegalArgumentException ex) - { - // I suppose this would best qualify as an invalid field then - throw new InvalidFieldException(ex); - } - catch (IllegalAccessException ex) - { - // We should be able to access any field - throw new JdwpInternalErrorException(ex); - } - } - } - - private void executeMonitorInfo(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // This command is optional, determined by VirtualMachines CapabilitiesNew - // so we'll leave it till later to implement - throw new NotImplementedException( - "Command ExecuteMonitorInfo not implemented."); - - } - - private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - Object obj = oid.getObject(); - - ObjectId tid = idMan.readId(bb); - Thread thread = (Thread) tid.getObject(); - - ReferenceTypeId rid = idMan.readReferenceTypeId(bb); - Class clazz = rid.getType(); - - ObjectId mid = idMan.readId(bb); - Method method = (Method) mid.getObject(); - - int args = bb.getInt(); - Object[] values = new Object[args]; - - for (int i = 0; i < args; i++) - { - values[i] = Value.getObj(bb); - } - - int invokeOptions = bb.getInt(); - - if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) != 0) - { // We must suspend all other running threads first - vm.suspendAllThreads(); - } - boolean nonVirtual; - if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_NONVIRTUAL) != 0) - nonVirtual = true; - else - nonVirtual = false; - MethodInvoker vmi = new MethodInvoker(vm); - - vmi.executeMethod(obj, thread, clazz, method, values, nonVirtual); - Object value = vmi.getReturnedValue(); - ObjectId exceptionId = vmi.getExceptionId(); - - Value.writeValue(os, value); - exceptionId.writeTagged(os); - } - - private void executeDisableCollection(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - oid.disableCollection(); - } - - private void executeEnableCollection(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - oid.enableCollection(); - } - - private void executeIsCollected(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = idMan.readId(bb); - boolean collected = oid.isCollected(); - os.writeBoolean(collected); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/PacketProcessor.java b/libjava/gnu/classpath/jdwp/processor/PacketProcessor.java deleted file mode 100644 index 914494c249f..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/PacketProcessor.java +++ /dev/null @@ -1,216 +0,0 @@ -/* PacketProcessor.java -- a thread which processes command packets - from the debugger - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.transport.JdwpCommandPacket; -import gnu.classpath.jdwp.transport.JdwpConnection; -import gnu.classpath.jdwp.transport.JdwpPacket; -import gnu.classpath.jdwp.transport.JdwpReplyPacket; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * This class is responsible for processing packets from the - * debugger. It waits for an available packet from the connection - * ({@link gnu.classpath.jdwp.transport.JdwpConnection}) and then - * processes the packet and any reply. - * - * @author Keith Seitz (keiths@redhat.com) - */ -public class PacketProcessor - extends Thread -{ - // The connection to the debugger - private JdwpConnection _connection; - - // Shutdown this thread? - private boolean _shutdown; - - // A Mapping of the command set (Byte) to the specific CommandSet - private CommandSet[] _sets; - - // Contents of the ReplyPackets data field - private ByteArrayOutputStream _outputBytes; - - // Output stream around _outputBytes - private DataOutputStream _os; - - /** - * Constructs a new <code>PacketProcessor</code> object - * Connection must be validated before getting here! - * - * @param con the connection - */ - public PacketProcessor (JdwpConnection con) - { - _connection = con; - _shutdown = false; - - // MAXIMUM is the value of the largest command set we may receive - _sets = new CommandSet[JdwpConstants.CommandSet.MAXIMUM + 1]; - _outputBytes = new ByteArrayOutputStream(); - _os = new DataOutputStream (_outputBytes); - - // Create all the Command Sets and add them to our array - _sets[JdwpConstants.CommandSet.VirtualMachine.CS_VALUE] = - new VirtualMachineCommandSet(); - _sets[JdwpConstants.CommandSet.ReferenceType.CS_VALUE] = - new ReferenceTypeCommandSet(); - _sets[JdwpConstants.CommandSet.ClassType.CS_VALUE] = - new ClassTypeCommandSet(); - _sets[JdwpConstants.CommandSet.ArrayType.CS_VALUE] = - new ArrayTypeCommandSet(); - _sets[JdwpConstants.CommandSet.InterfaceType.CS_VALUE] = - new InterfaceTypeCommandSet(); - _sets[JdwpConstants.CommandSet.Method.CS_VALUE] = - new MethodCommandSet(); - _sets[JdwpConstants.CommandSet.Field.CS_VALUE] = - new FieldCommandSet(); - _sets[JdwpConstants.CommandSet.ObjectReference.CS_VALUE] = - new ObjectReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.StringReference.CS_VALUE] = - new StringReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.ThreadReference.CS_VALUE] = - new ThreadReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.ThreadGroupReference.CS_VALUE] = - new ThreadGroupReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.ArrayReference.CS_VALUE] = - new ArrayReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.ClassLoaderReference.CS_VALUE] = - new ClassLoaderReferenceCommandSet(); - _sets[JdwpConstants.CommandSet.EventRequest.CS_VALUE] = - new EventRequestCommandSet(); - _sets[JdwpConstants.CommandSet.StackFrame.CS_VALUE] = - new StackFrameCommandSet(); - _sets[JdwpConstants.CommandSet.ClassObjectReference.CS_VALUE] = - new ClassObjectReferenceCommandSet(); - } - - /** - * Main run routine for this thread. Will loop getting packets - * from the connection and processing them. - */ - public void run () - { - try - { - while (!_shutdown) - { - _processOnePacket (); - } - } - catch (IOException ex) - { - ex.printStackTrace(); - } - // Time to shutdown, tell Jdwp to shutdown - Jdwp.getDefault().shutdown(); - } - - /** - * Shutdown the packet processor - */ - public void shutdown () - { - _shutdown = true; - interrupt (); - } - - // Helper function which actually does all the work of waiting - // for a packet and getting it processed. - private void _processOnePacket () - throws IOException - { - JdwpPacket pkt = _connection.getPacket (); - - if (!(pkt instanceof JdwpCommandPacket)) - { - // We're not supposed to get these from the debugger! - // Drop it on the floor - return; - } - - if (pkt != null) - { - JdwpCommandPacket commandPkt = (JdwpCommandPacket) pkt; - JdwpReplyPacket reply = new JdwpReplyPacket(commandPkt); - - // Reset our output stream - _outputBytes.reset(); - - // Create a ByteBuffer around the command packet - ByteBuffer bb = ByteBuffer.wrap(commandPkt.getData()); - byte command = commandPkt.getCommand(); - byte commandSet = commandPkt.getCommandSet(); - - CommandSet set = null; - try - { - // There is no command set with value 0 - if (commandSet > 0 && commandSet < _sets.length) - { - set = _sets[commandPkt.getCommandSet()]; - } - if (set != null) - { - _shutdown = set.runCommand(bb, _os, command); - reply.setData(_outputBytes.toByteArray()); - } - else - { - // This command set wasn't in our tree - reply.setErrorCode(JdwpConstants.Error.NOT_IMPLEMENTED); - } - } - catch (JdwpException ex) - { - reply.setErrorCode(ex.getErrorCode ()); - } - _connection.sendPacket (reply); - } - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java b/libjava/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java deleted file mode 100644 index 34def9f2d07..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java +++ /dev/null @@ -1,321 +0,0 @@ -/* ReferenceTypeCommandSet.java -- lass to implement the ReferenceType - Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.IVirtualMachine; -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.exception.InvalidFieldException; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; -import gnu.classpath.jdwp.exception.NotImplementedException; -import gnu.classpath.jdwp.id.IdManager; -import gnu.classpath.jdwp.id.ObjectId; -import gnu.classpath.jdwp.id.ReferenceTypeId; -import gnu.classpath.jdwp.util.JdwpString; -import gnu.classpath.jdwp.util.Signature; -import gnu.classpath.jdwp.util.Value; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.nio.ByteBuffer; - -/** - * A class representing the ReferenceType Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class ReferenceTypeCommandSet implements CommandSet -{ - // Our hook into the jvm - private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); - - // Manages all the different ids that are assigned by jdwp - private final IdManager idMan = Jdwp.getIdManager(); - - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - try - { - switch (command) - { - case JdwpConstants.CommandSet.ReferenceType.SIGNATURE: - executeSignature(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.CLASS_LOADER: - executeClassLoader(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.MODIFIERS: - executeModifiers(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.FIELDS: - executeFields(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.METHODS: - executeMethods(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.GET_VALUES: - executeGetValues(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.SOURCE_FILE: - executeSourceFile(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.NESTED_TYPES: - executeNestedTypes(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.STATUS: - executeStatus(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.INTERFACES: - executeInterfaces(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.CLASS_OBJECT: - executeClassObject(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.SOURCE_DEBUG_EXTENSION: - executeSourceDebugExtension(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.SIGNATURE_WITH_GENERIC: - executeSignatureWithGeneric(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.FIELDS_WITH_GENERIC: - executeFieldWithGeneric(bb, os); - break; - case JdwpConstants.CommandSet.ReferenceType.METHODS_WITH_GENERIC: - executeMethodsWithGeneric(bb, os); - break; - default: - throw new NotImplementedException("Command " + command + - " not found in String Reference Command Set."); - } - } - catch (IOException ex) - { - // The DataOutputStream we're using isn't talking to a socket at all - // So if we throw an IOException we're in serious trouble - throw new JdwpInternalErrorException(ex); - } - return true; - } - - private void executeSignature(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - String sig = Signature.computeClassSignature(refId.getType()); - JdwpString.writeString(os, sig); - } - - private void executeClassLoader(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - - Class clazz = refId.getType(); - ClassLoader loader = clazz.getClassLoader(); - ObjectId oid = idMan.getId(loader); - oid.write(os); - } - - private void executeModifiers(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - - Class clazz = refId.getType(); - os.writeInt(clazz.getModifiers()); - } - - private void executeFields(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - - Field[] fields = clazz.getFields(); - os.writeInt(fields.length); - for (int i = 0; i < fields.length; i++) - { - Field field = fields[i]; - idMan.getId(field).write(os); - JdwpString.writeString(os, field.getName()); - JdwpString.writeString(os, Signature.computeFieldSignature(field)); - os.writeInt(field.getModifiers()); - } - } - - private void executeMethods(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - - Method[] methods = clazz.getMethods(); - os.writeInt(methods.length); - for (int i = 0; i < methods.length; i++) - { - Method method = methods[i]; - idMan.getId(method).write(os); - JdwpString.writeString(os, method.getName()); - JdwpString.writeString(os, Signature.computeMethodSignature(method)); - os.writeInt(method.getModifiers()); - } - } - - private void executeGetValues(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - - int numFields = bb.getInt(); - os.writeInt(numFields); // Looks pointless but this is the protocol - for (int i = 0; i < numFields; i++) - { - ObjectId fieldId = idMan.readId(bb); - Field field = (Field) (fieldId.getObject()); - Class fieldClazz = field.getDeclaringClass(); - - // We don't actually need the clazz to get the field but we might as - // well check that the debugger got it right - if (fieldClazz.isAssignableFrom(clazz)) - Value.writeStaticValueFromField(os, field); - else - throw new InvalidFieldException(fieldId.getId()); - } - } - - private void executeSourceFile(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - - // We'll need to go into the jvm for this unless there's an easier way - String sourceFileName = vm.getSourceFile(clazz); - JdwpString.writeString(os, sourceFileName); - // clazz.getProtectionDomain().getCodeSource().getLocation(); - } - - private void executeNestedTypes(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - Class[] declaredClazzes = clazz.getDeclaredClasses(); - os.writeInt(declaredClazzes.length); - for (int i = 0; i < declaredClazzes.length; i++) - { - Class decClazz = declaredClazzes[i]; - ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz); - clazzId.writeTagged(os); - } - } - - private void executeStatus(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - - // I don't think there's any other way to get this - int status = vm.getStatus(clazz); - os.writeInt(status); - } - - private void executeInterfaces(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - Class[] interfaces = clazz.getInterfaces(); - os.writeInt(interfaces.length); - for (int i = 0; i < interfaces.length; i++) - { - Class interfaceClass = interfaces[i]; - ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass); - intId.write(os); - } - } - - private void executeClassObject(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ReferenceTypeId refId = idMan.readReferenceTypeId(bb); - Class clazz = refId.getType(); - ObjectId clazzObjectId = idMan.getId(clazz); - clazzObjectId.write(os); - } - - private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // This command is optional, determined by VirtualMachines CapabilitiesNew - // so we'll leave it till later to implement - throw new NotImplementedException( - "Command SourceDebugExtension not implemented."); - } - - private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // We don't have generics yet - throw new NotImplementedException( - "Command SourceDebugExtension not implemented."); - } - - private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // We don't have generics yet - throw new NotImplementedException( - "Command SourceDebugExtension not implemented."); - } - - private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // We don't have generics yet - throw new NotImplementedException( - "Command SourceDebugExtension not implemented."); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java b/libjava/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java deleted file mode 100644 index 1f1b04cb0cc..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java +++ /dev/null @@ -1,98 +0,0 @@ -/* StringReferenceCommandSet.java -- class to implement the StringReference - Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; -import gnu.classpath.jdwp.exception.NotImplementedException; -import gnu.classpath.jdwp.id.ObjectId; -import gnu.classpath.jdwp.util.JdwpString; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * A class representing the StringReference Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class StringReferenceCommandSet implements CommandSet -{ - - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - try - { - - // Although there's only a single command to choose from we still use - // a switch to maintain consistency with the rest of the CommandSets - switch (command) - { - case JdwpConstants.CommandSet.StringReference.VALUE: - executeValue(bb, os); - break; - default: - throw new NotImplementedException("Command " + command + - " not found in String Reference Command Set."); - } - } - catch (IOException ex) - { - // The DataOutputStream we're using isn't talking to a socket at all - // So if we throw an IOException we're in serious trouble - throw new JdwpInternalErrorException(ex); - } - return true; - } - - private void executeValue(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = Jdwp.getIdManager().readId(bb); - - String str = (String) oid.getObject(); - JdwpString.writeString(os, str); - } -} diff --git a/libjava/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java b/libjava/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java deleted file mode 100644 index 32b98781727..00000000000 --- a/libjava/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java +++ /dev/null @@ -1,474 +0,0 @@ -/* VirtualMachineCommandSet.java -- class to implement the VirtualMachine - Command Set - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.processor; - -import gnu.classpath.jdwp.IVirtualMachine; -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.JdwpConstants; -import gnu.classpath.jdwp.exception.JdwpException; -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; -import gnu.classpath.jdwp.exception.NotImplementedException; -import gnu.classpath.jdwp.id.IdManager; -import gnu.classpath.jdwp.id.ObjectId; -import gnu.classpath.jdwp.id.ReferenceTypeId; -import gnu.classpath.jdwp.util.JdwpString; -import gnu.classpath.jdwp.util.Signature; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Properties; - -/** - * A class representing the VirtualMachine Command Set. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class VirtualMachineCommandSet implements CommandSet -{ - // Our hook into the jvm - private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); - - // Manages all the different ids that are assigned by jdwp - private final IdManager idMan = Jdwp.getIdManager(); - - // The Jdwp object - private final Jdwp jdwp = Jdwp.getDefault(); - - public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) - throws JdwpException - { - boolean keepRunning = true; - try - { - switch (command) - { - case JdwpConstants.CommandSet.VirtualMachine.VERSION: - executeVersion(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.CLASSES_BY_SIGNATURE: - executeClassesBySignature(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES: - executeAllClasses(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.ALL_THREADS: - executeAllThreads(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.TOP_LEVEL_THREAD_GROUPS: - executeTopLevelThreadGroups(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.IDSIZES: - executeIDsizes(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.DISPOSE: - keepRunning = false; - executeDispose(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.SUSPEND: - executeSuspend(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.RESUME: - executeResume(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.EXIT: - keepRunning = false; - executeExit(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING: - executeCreateString(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES: - executeCapabilities(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.CLASS_PATHS: - executeClassPaths(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.DISPOSE_OBJECTS: - executeDisposeObjects(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.HOLD_EVENTS: - executeHoldEvents(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.RELEASE_EVENTS: - executeReleaseEvents(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES_NEW: - executeCapabilitiesNew(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.REDEFINE_CLASSES: - executeRedefineClasses(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.SET_DEFAULT_STRATUM: - executeSetDefaultStratum(bb, os); - break; - case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES_WITH_GENERIC: - executeAllClassesWithGeneric(bb, os); - break; - - default: - break; - } - } - catch (IOException ex) - { - // The DataOutputStream we're using isn't talking to a socket at all - // So if we throw an IOException we're in serious trouble - throw new JdwpInternalErrorException(ex); - } - return keepRunning; - } - - private void executeVersion(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - - Properties props = System.getProperties(); - - int jdwpMajor = JdwpConstants.Version.MAJOR; - int jdwpMinor = JdwpConstants.Version.MINOR; - // The description field is pretty loosely defined - String description = "JDWP version " + jdwpMajor + "." + jdwpMinor - + ", JVM version " + props.getProperty("java.vm.name") - + " " + props.getProperty("java.vm.version") + " " - + props.getProperty("java.version"); - String vmVersion = props.getProperty("java.version"); - String vmName = props.getProperty("java.vm.name"); - JdwpString.writeString(os, description); - os.write(jdwpMajor); - os.write(jdwpMinor); - JdwpString.writeString(os, vmName); - JdwpString.writeString(os, vmVersion); - } - - private void executeClassesBySignature(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - String sig = JdwpString.readString(bb); - ArrayList allMatchingClasses = new ArrayList(); - - // This will be an Iterator over all loaded Classes - Iterator iter = vm.getAllLoadedClasses(); - - while (iter.hasNext()) - { - Class clazz = (Class) iter.next(); - String clazzSig = Signature.computeClassSignature(clazz); - if (clazzSig.equals(sig)) - allMatchingClasses.add(clazz); - } - - os.writeInt(allMatchingClasses.size()); - for (int i = 0; i < allMatchingClasses.size(); i++) - { - Class clazz = (Class) allMatchingClasses.get(i); - ReferenceTypeId id = idMan.getReferenceTypeId(clazz); - id.writeTagged(os); - int status = vm.getStatus(clazz); - os.writeInt(status); - } - } - - private void executeAllClasses(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // Disable garbage collection while we're collecting the info on loaded - // classes so we some classes don't get collected between the time we get - // the count and the time we get the list - vm.disableGarbageCollection(); - - int classCount = vm.getAllLoadedClassesCount(); - os.writeInt(classCount); - - // This will be an Iterator over all loaded Classes - Iterator iter = vm.getAllLoadedClasses(); - vm.enableGarbageCollection(); - int count = 0; - - // Note it's possible classes were created since out classCount so make - // sure we don't write more classes than we told the debugger - while (iter.hasNext() && count++ < classCount) - { - Class clazz = (Class) iter.next(); - ReferenceTypeId id = idMan.getReferenceTypeId(clazz); - id.writeTagged(os); - String sig = Signature.computeClassSignature(clazz); - JdwpString.writeString(os, sig); - int status = vm.getStatus(clazz); - os.writeInt(status); - } - } - - private void executeAllThreads(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup(); - ThreadGroup root = getRootThreadGroup(jdwpGroup); - - int numThreads = root.activeCount(); - Thread allThreads[] = new Thread[numThreads]; - root.enumerate(allThreads, true); - - // We need to loop through for the true count since some threads may have - // been destroyed since we got - // activeCount so those spots in the array will be null. As well we must - // ignore any threads that belong to jdwp - numThreads = 0; - for (int i = 0; i < allThreads.length; i++) - { - Thread thread = allThreads[i]; - if (thread == null) - break; // No threads after this point - if (!thread.getThreadGroup().equals(jdwpGroup)) - numThreads++; - } - - os.writeInt(numThreads); - - for (int i = 0; i < allThreads.length; i++) - { - Thread thread = allThreads[i]; - if (thread == null) - break; // No threads after this point - if (!thread.getThreadGroup().equals(jdwpGroup)) - idMan.getId(thread).write(os); - } - } - - private void executeTopLevelThreadGroups(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ThreadGroup jdwpGroup = jdwp.getJdwpThreadGroup(); - ThreadGroup root = getRootThreadGroup(jdwpGroup); - - os.writeInt(1); // Just one top level group allowed? - idMan.getId(root); - } - - private void executeDispose(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // resumeAllThreads isn't sufficient as a thread may have been - // suspended multiple times, we likely need a way to keep track of how many - // times a thread has been suspended or else a stronger resume method for - // this purpose - // vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup()); - - // Simply shutting down the jdwp layer will take care of the rest of the - // shutdown other than disabling debugging in the VM - // vm.disableDebugging(); - - // Don't implement this until we're sure how to remove all the debugging - // effects from the VM. - throw new NotImplementedException( - "Command VirtualMachine.Dispose not implemented"); - - } - - private void executeIDsizes(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - ObjectId oid = new ObjectId(); - os.writeInt(oid.size()); // fieldId - os.writeInt(oid.size()); // methodId - os.writeInt(oid.size()); // objectId - os.writeInt(new ReferenceTypeId((byte) 0x00).size()); // referenceTypeId - os.writeInt(oid.size()); // frameId - } - - private void executeSuspend(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - vm.suspendAllThreadsExcept(jdwp.getJdwpThreadGroup()); - } - - private void executeResume(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup()); - } - - private void executeExit(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - int exitCode = bb.getInt(); - jdwp.setExit(exitCode); - } - - private void executeCreateString(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - String string = JdwpString.readString(bb); - ObjectId stringId = Jdwp.getIdManager().getId(string); - - // Since this string isn't referenced anywhere we'll disable garbage - // collection on it so it's still around when the debugger gets back to it. - stringId.disableCollection(); - stringId.write(os); - } - - private void executeCapabilities(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // Store these somewhere? - os.writeBoolean(false); // canWatchFieldModification - os.writeBoolean(false); // canWatchFieldAccess - os.writeBoolean(false); // canGetBytecodes - os.writeBoolean(false); // canGetSyntheticAttribute - os.writeBoolean(false); // canGetOwnedMonitorInfo - os.writeBoolean(false); // canGetCurrentContendedMonitor - os.writeBoolean(false); // canGetMonitorInfo - } - - private void executeClassPaths(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - String baseDir = System.getProperty("user.dir"); - JdwpString.writeString(os, baseDir); - - // Find and write the classpath - String classPath = System.getProperty("java.class.path"); - String[] paths = classPath.split(":"); - - os.writeInt(paths.length); - for (int i = 0; i < paths.length; i++) - JdwpString.writeString(os, paths[i]); - - // Now the bootpath - String bootPath = System.getProperty("sun.boot.class.path"); - paths = bootPath.split(":"); - os.writeInt(paths.length); - for (int i = 0; i < paths.length; i++) - JdwpString.writeString(os, paths[i]); - } - - private void executeDisposeObjects(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // Instead of going through the list of objects they give us it's probably - // better just to find the garbage collected objects ourselves - idMan.update(); - } - - private void executeHoldEvents(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // Going to have to implement a send queue somewhere and do this without - // triggering events - // Until then just don't implement - throw new NotImplementedException( - "Command VirtualMachine.HoldEvents not implemented"); - } - - // Opposite of executeHoldEvents - private void executeReleaseEvents(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - throw new NotImplementedException( - "Command VirtualMachine.ReleaseEvents not implemented"); - } - - private void executeCapabilitiesNew(ByteBuffer bb, DataOutputStream os) - throws JdwpException, IOException - { - // Store these somewhere? - final int CAPABILITIES_NEW_SIZE = 32; - os.writeBoolean(false); // canWatchFieldModification - os.writeBoolean(false); // canWatchFieldAccess - os.writeBoolean(false); // canGetBytecodes - os.writeBoolean(false); // canGetSyntheticAttribute - os.writeBoolean(false); // canGetOwnedMonitorInfo - os.writeBoolean(false); // canGetCurrentContendedMonitor - os.writeBoolean(false); // canGetMonitorInfo - os.writeBoolean(false); // canRedefineClasses - os.writeBoolean(false); // canAddMethod - os.writeBoolean(false); // canUnrestrictedlyRedefineClasses - os.writeBoolean(false); // canPopFrames - os.writeBoolean(false); // canUseInstanceFilters - os.writeBoolean(false); // canGetSourceDebugExtension - os.writeBoolean(false); // canRequestVMDeathEvent - os.writeBoolean(false); // canSetDefaultStratum - for (int i = 15; i < CAPABILITIES_NEW_SIZE; i++) - // Future capabilities - // currently unused - os.writeBoolean(false); // Set to false - } - - private void executeRedefineClasses(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // Optional command, don't implement - throw new NotImplementedException( - "Command VirtualMachine.RedefineClasses not implemented"); - } - - private void executeSetDefaultStratum(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // Optional command, don't implement - throw new NotImplementedException( - "Command VirtualMachine.SetDefaultStratum not implemented"); - } - - private void executeAllClassesWithGeneric(ByteBuffer bb, DataOutputStream os) - throws JdwpException - { - // We don't handle generics - throw new NotImplementedException( - "Command VirtualMachine.AllClassesWithGeneric not implemented"); - } - - /** - * Find the root ThreadGroup of this ThreadGroup - */ - private ThreadGroup getRootThreadGroup(ThreadGroup group) - { - ThreadGroup parent = group.getParent(); - - while (parent != null) - { - group = parent; - parent = group.getParent(); - } - return group; // This group was the root - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/ITransport.java b/libjava/gnu/classpath/jdwp/transport/ITransport.java deleted file mode 100644 index 371cf8f06af..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/ITransport.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ITransport.java -- An interface defining JDWP transports - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.IllegalArgumentException; -import java.util.HashMap; - -/** - * A class representing a transport layer. This class serves as a generic - * interface for all transport types used in the JDWP back-end. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public interface ITransport -{ - /** - * Configure the transport with the given properties - * - * @param properties properties of the transport configuration - * @throws TransportException on configury error - */ - public void configure (HashMap properties) - throws TransportException; - - /** - * Initialize the transport - * - * @throws TransportException on initialization error - */ - public void initialize () - throws TransportException; - - /** - * Get the input stream for the transport - */ - public InputStream getInputStream () - throws IOException; - - /** - * Get the output stream for the transport - */ - public OutputStream getOutputStream () - throws IOException; -} diff --git a/libjava/gnu/classpath/jdwp/transport/JdwpCommandPacket.java b/libjava/gnu/classpath/jdwp/transport/JdwpCommandPacket.java deleted file mode 100644 index e99159aad9b..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/JdwpCommandPacket.java +++ /dev/null @@ -1,149 +0,0 @@ -/* JdwpCommandPacket.java -- JDWP command packet - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * A class representing a JDWP command packet. - * This class adds command set and command to the packet header - * information in {@link gnu.classpath.jdwp.transport.JdwpPacket} - * and adds additional command packet-specific processing. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class JdwpCommandPacket extends JdwpPacket -{ - /** - * Command set - */ - protected byte _commandSet; - - /** - * Command - */ - protected byte _command; - - // Minimum packet size [excluding super class] - // ( commandSet (1) + command (1) ) - private static final int MINIMUM_LENGTH = 2; - - /** - * Constructs a new <code>JdwpCommandPacket</code> - */ - public JdwpCommandPacket () - { - // Don't assign an id. This constructor is called by - // JdwpPacket.fromBytes, and that will assign a packet id. - } - - /** - * Constructs a new <code>JdwpCommandPacket</code> - * with the given command set and command - * - * @param set the command set - * @param command the command - */ - public JdwpCommandPacket (byte set, byte command) - { - _id = ++_last_id; - _commandSet = set; - _command = command; - } - - /** - * Retuns the length of this packet - */ - public int getLength () - { - return MINIMUM_LENGTH + super.getLength (); - } - - /** - * Returns the command set - */ - public byte getCommandSet () - { - return _commandSet; - } - - /** - * Sets the command set - */ - public void setCommandSet (byte cs) - { - _commandSet = cs; - } - - /** - * Returns the command - */ - public byte getCommand () - { - return _command; - } - - /** - * Sets the command - */ - public void setCommand (byte cmd) - { - _command = cmd; - } - - // Reads command packet data from the given buffer, starting - // at the given offset - protected int myFromBytes (byte[] bytes, int index) - { - int i = 0; - setCommandSet (bytes[index + i++]); - setCommand (bytes[index + i++]); - return i; - } - - // Writes the command packet data into the given buffer - protected void myWrite (DataOutputStream dos) - throws IOException - { - dos.writeByte (getCommandSet ()); - dos.writeByte (getCommand ()); - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/JdwpConnection.java b/libjava/gnu/classpath/jdwp/transport/JdwpConnection.java deleted file mode 100644 index 18250d3209b..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/JdwpConnection.java +++ /dev/null @@ -1,298 +0,0 @@ -/* JdwpConnection.java -- A JDWP-speaking connection - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import gnu.classpath.jdwp.Jdwp; -import gnu.classpath.jdwp.event.Event; -import gnu.classpath.jdwp.event.EventRequest; - -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -/** - * A connection via some transport to some JDWP-speaking entity. - * This is also a thread which handles all communications to/from - * the debugger. While access to the transport layer may be accessed by - * several threads, start-up and initialization should not be allowed - * to occur more than once. - * - * <p>This class is also a thread that is responsible for pulling - * packets off the wire and sticking them in a queue for packet - * processing threads. - * - * @author Keith Seitz (keiths@redhat.com) - */ -public class JdwpConnection - extends Thread -{ - // The JDWP handshake - private static final byte[] _HANDSHAKE = {'J', 'D', 'W', 'P', '-', 'H', 'a', - 'n', 'd', 's', 'h', 'a', 'k', 'e'}; - - // Transport method - private ITransport _transport; - - // Command queue - private ArrayList _commandQueue; - - // Shutdown flag - private boolean _shutdown; - - // Input stream from transport - private DataInputStream _inStream; - - // Output stream from transprot - private DataOutputStream _outStream; - - // A buffer used to construct the packet data - private ByteArrayOutputStream _bytes; - - // A DataOutputStream for the byte buffer - private DataOutputStream _doStream; - - /** - * Creates a new <code>JdwpConnection</code> instance - * - * @param transport the transport to use for communications - */ - public JdwpConnection (ITransport transport) - { - _transport = transport; - _commandQueue = new ArrayList (); - _shutdown = false; - _bytes = new ByteArrayOutputStream (); - _doStream = new DataOutputStream (_bytes); - } - - /** - * Initializes the connection, including connecting - * to socket or shared memory endpoint - * - * @throws TransportException if initialization fails - */ - public void initialize () - throws TransportException - { - // Initialize transport (connect socket, e.g.) - _transport.initialize (); - - // Do handshake - try - { - _inStream = new DataInputStream (_transport.getInputStream ()); - _outStream = new DataOutputStream (_transport.getOutputStream ()); - _doHandshake (); - } - catch (IOException ioe) - { - throw new TransportException (ioe); - } - } - - /* Does the JDWP handshake -- this should not need synchronization - because this is called by VM startup code, i.e., no packet - processing threads have started yet. */ - private void _doHandshake () - throws IOException - { - // According to the spec, the handshake is always initiated by - // the debugger, regardless of whether the JVM is in client mode or - // server mode. - - // Wait for handshake from debugger - byte[] hshake = new byte[_HANDSHAKE.length]; - _inStream.readFully (hshake, 0, _HANDSHAKE.length); - - if (Arrays.equals (hshake, _HANDSHAKE)) - { - // Send reply handshake - _outStream.write (_HANDSHAKE, 0, _HANDSHAKE.length); - return; - } - else - { - throw new IOException ("invalid JDWP handshake (\"" + hshake + "\")"); - } - } - - /** - * Main run method for the thread. This thread loops waiting for - * packets to be read via the connection. When a packet is complete - * and ready for processing, it places the packet in a queue that can - * be accessed via <code>getPacket</code> - */ - public void run () - { - while (!_shutdown) - { - try - { - _readOnePacket (); - } - catch (IOException ioe) - { - /* IOException can occur for two reasons: - 1. Lost connection with the other side - 2. Transport was shutdown - In either case, we make sure that all of the - back-end gets shutdown. */ - Jdwp.getInstance().shutdown (); - } - catch (Throwable t) - { - System.out.println ("JdwpConnection.run: caught an exception: " - + t); - // Just keep going - } - } - } - - // Reads a single packet from the connection, adding it to the packet - // queue when a complete packet is ready. - private void _readOnePacket () - throws IOException - { - byte[] data = null; - - // Read in the packet - int length = _inStream.readInt (); - if (length < 11) - { - throw new IOException ("JDWP packet length < 11 (" - + length + ")"); - } - - data = new byte[length]; - data[0] = (byte) (length >>> 24); - data[1] = (byte) (length >>> 16); - data[2] = (byte) (length >>> 8); - data[3] = (byte) length; - _inStream.readFully (data, 4, length - 4); - - JdwpPacket packet = JdwpPacket.fromBytes (data); - if (packet != null) - { - synchronized (_commandQueue) - { - _commandQueue.add (packet); - _commandQueue.notifyAll (); - } - } - } - - /** - * Returns a packet from the queue of ready packets - * - * @returns a <code>JdwpPacket</code> ready for processing - * <code>null</code> when shutting down - */ - public JdwpPacket getPacket () - { - synchronized (_commandQueue) - { - while (_commandQueue.isEmpty ()) - { - try - { - _commandQueue.wait (); - } - catch (InterruptedException ie) - { - /* PacketProcessor is interrupted - when shutting down */ - return null; - } - } - - return (JdwpPacket) _commandQueue.remove (0); - } - } - - /** - * Send a packet to the debugger - * - * @param pkt a <code>JdwpPacket</code> to send - * @throws IOException - */ - public void sendPacket (JdwpPacket pkt) - throws IOException - { - pkt.write (_outStream); - } - - /** - * Send an event notification to the debugger - * - * @param request the debugger request that wanted this event - * @param event the event - * @throws IOException - */ - public void sendEvent (EventRequest request, Event event) - throws IOException - { - JdwpPacket pkt; - - synchronized (_bytes) - { - _bytes.reset (); - pkt = event.toPacket (_doStream, request); - pkt.setData (_bytes.toByteArray ()); - } - - sendPacket (pkt); - } - - /** - * Shutdown the connection - */ - public void shutdown () - { - if (!_shutdown) - { - _transport.shutdown (); - _shutdown = true; - interrupt (); - } - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/JdwpPacket.java b/libjava/gnu/classpath/jdwp/transport/JdwpPacket.java deleted file mode 100644 index 7fa93e2de1b..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/JdwpPacket.java +++ /dev/null @@ -1,278 +0,0 @@ -/* JdwpPacket.java -- Base class for JDWP command and reply packets - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * All command and reply packets in JDWP share - * common header type information: - * - * length (4 bytes) : size of entire packet, including length - * id (4 bytes) : unique packet id - * flags (1 byte) : flag byte - * [command packet stuff | reply packet stuff] - * data (variable) : unique command-/reply-specific data - * - * This class deal with everything except the command- and reply-specific - * data, which get handled in {@link - * gnu.classpath.jdwp.transport.JdwpCommandPacket} and {@link - * gnu.classpath.jdwp.transprot.JdwpReplyPacket}. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public abstract class JdwpPacket -{ - // Last id of packet constructed - protected static int _last_id = 0; - - // JDWP reply packet flag - protected static final int JDWP_FLAG_REPLY = 0x80; - - /** - * Minimum packet size excluding sub-class data - * ( length (4) + id (4) + flags (1) ) - */ - protected static final int MINIMUM_SIZE = 9; - - /** - * Id of command/reply - */ - protected int _id; - - /** - * Packet flags - */ - protected byte _flags; - - /** - * Packet-specific data - */ - protected byte[] _data; - - /** - * Constructor - */ - public JdwpPacket () - { - // By default, DON'T assign an id. This way when a packet - // is constructed from fromBytes, _last_id won't increment (i.e., - // it won't leave holes in the outgoing packet ids). - } - - /** - * Constructs a <code>JdwpPacket</code> with the id - * from the given packet. - * - * @param pkt a packet whose id will be used in this new packet - */ - public JdwpPacket (JdwpPacket pkt) - { - _id = pkt.getId (); - } - - /** - * Returns the packet id - */ - public int getId () - { - return _id; - } - - /** - * Sets the packet id - */ - public void setId (int id) - { - _id = id; - } - - /** - * Returns the packet flags - */ - public byte getFlags () - { - return _flags; - } - - /** - * Sets the packet flags - */ - public void setFlags (byte flags) - { - _flags = flags; - } - - /** - * Gets the command/reply-specific data in this packet - */ - public byte[] getData () - { - return _data; - } - - /** - * Sets the command/reply-specific data in this packet - */ - public void setData (byte[] data) - { - _data = data; - } - - /** - * Returns the length of this entire packet - */ - public int getLength () - { - return MINIMUM_SIZE + (_data == null ? 0 : _data.length); - } - - /** - * Allow subclasses to initialize from data - * - * @param bytes packet data from the wire - * @param index index into <code>bytes</code> to start processing - * @return number of bytes in <code>bytes</code> processed - */ - protected abstract int myFromBytes (byte[] bytes, int index); - - /** - * Convert the given bytes into a <code>JdwpPacket</code>. Uses the - * abstract method <code>myFromBytes</code> to allow subclasses to - * process data. - * - * If the given data does not represent a valid JDWP packet, it returns - * <code>null</code>. - * - * @param bytes packet data from the wire - * @param index index into <code>bytes</code> to start processing - * @return number of bytes in <code>bytes</code> processed - */ - public static JdwpPacket fromBytes (byte[] bytes) - { - int i = 0; - int length = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16 - | (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff)); - int id = 0; - byte flags = 0; - - if (bytes.length == length) - { - id = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16 - | (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff)); - flags = bytes[i++]; - - Class clazz = null; - if (flags == 0) - clazz = JdwpCommandPacket.class; - else if ((flags & JDWP_FLAG_REPLY) != 0) - clazz = JdwpReplyPacket.class; - else - { - // Malformed packet. Discard it. - return null; - } - - JdwpPacket pkt = null; - try - { - pkt = (JdwpPacket) clazz.newInstance (); - } - catch (InstantiationException ie) - { - // Discard packet - return null; - } - catch (IllegalAccessException iae) - { - // Discard packet - return null; - } - - pkt.setId (id); - pkt.setFlags (flags); - - i += pkt.myFromBytes (bytes, i); - byte[] data = new byte[length - i]; - System.arraycopy (bytes, i, data, 0, data.length); - pkt.setData (data); - - return pkt; - } - - return null; - } - - /** - * Put subclass information onto the stream - * - * @param dos the output stream to which to write - */ - protected abstract void myWrite (DataOutputStream dos) - throws IOException; - - /** - * Writes the packet to the output stream - * - * @param dos the output stream to which to write the packet - */ - public void write (DataOutputStream dos) - throws IOException - { - // length - int length = getLength (); - dos.writeInt (length); - - // ID - dos.writeInt (getId ()); - - // flag - dos.writeByte (getFlags ()); - - // packet-specific stuff - myWrite (dos); - - // data (if any) - byte[] data = getData (); - if (data != null && data.length > 0) - dos.write (data, 0, data.length); - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/JdwpReplyPacket.java b/libjava/gnu/classpath/jdwp/transport/JdwpReplyPacket.java deleted file mode 100644 index de32ecf995b..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/JdwpReplyPacket.java +++ /dev/null @@ -1,137 +0,0 @@ -/* JdwpReplyPacket.java -- JDWP reply packet - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * A class represents a JDWP reply packet. - * This class adds an error code to the packet header information - * in {@link gnu.classpath.transport.JdwpPacket} and adds additional - * reply packet-specific processing. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class JdwpReplyPacket extends JdwpPacket -{ - /** - * Error code - */ - protected short _errorCode; - - // Minimum packet size [excluding super class] ( errorCode (2) ) - private static final int MINIMUM_LENGTH = 2; - - /** - * Constructs a <code>JdwpReplyPacket</code>. - */ - public JdwpReplyPacket () - { - // Don't assign a packet id. This is called by JdwpPacket.fromBytes - // which assigns a packet id. (Not that a VM would do that...) - } - - /** - * Constructs a <code>JdwpReplyPacket</code> with the - * id from the given packet and error code - * - * @param pkt the packet whose id this packet will use - * @param errorCode the error code - */ - public JdwpReplyPacket (JdwpPacket pkt, short errorCode) - { - this(pkt); - _errorCode = errorCode; - } - - /** - * Constructs a <code>JdwpReplyPacket</code> with the - * id from the given packet and an empty error code - * - * @param pkt the packet whose id this packet will use - */ - public JdwpReplyPacket (JdwpPacket pkt) - { - super (pkt); - _flags = (byte) JDWP_FLAG_REPLY; - } - - /** - * Returns the length of this packet - */ - public int getLength () - { - return MINIMUM_LENGTH + super.getLength (); - } - - /** - * Returns the error code - */ - public short getErrorCode () - { - return _errorCode; - } - - /** - * Sets the error code - */ - public void setErrorCode (short ec) - { - _errorCode = ec; - } - - // Reads command packet data from the given buffer, starting - // at the given offset - protected int myFromBytes (byte[] bytes, int index) - { - int i = 0; - setErrorCode ((short) ((bytes[index + i++] & 0xff) << 8 - | (bytes[index + i++] & 0xff))); - return i; - } - - // Writes the command packet data into the given buffer - protected void myWrite (DataOutputStream dos) - throws IOException - { - dos.writeShort (getErrorCode ()); - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/SocketTransport.java b/libjava/gnu/classpath/jdwp/transport/SocketTransport.java deleted file mode 100644 index 0ad7357e183..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/SocketTransport.java +++ /dev/null @@ -1,171 +0,0 @@ -/* SocketTransport.java -- a socket transport - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import gnu.classpath.jdwp.transport.ITransport; -import gnu.classpath.jdwp.transport.TransportException; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.HashMap; - -import javax.net.ServerSocketFactory; -import javax.net.SocketFactory; - -/** - * A socket-based transport. This transport uses - * configury string that looks like "name=dt_socket, - * address=localhost:1234,server=y". - * - * @author Keith Seitz <keiths@redhat.com> - */ -class SocketTransport - implements ITransport -{ - /** - * Name of this transport - */ - public static final String NAME = "dt_socket"; - - // Configure properties - private static final String _PROPERTY_ADDRESS = "address"; - private static final String _PROPERTY_SERVER = "server"; - - // Port number - private int _port; - - // Host name - private String _host; - - // Are we acting as a server? - private boolean _server = false; - - // Socket - private Socket _socket; - - /** - * Setup the connection configuration from the given properties - * - * @param properties the properties of the JDWP session - * @throws TransportException for any configury errors - */ - public void configure (HashMap properties) - throws TransportException - { - // Get address [form: "hostname:port"] - String p = (String) properties.get (_PROPERTY_ADDRESS); - if (p != null) - { - String[] s = p.split (":"); - if (s.length == 2) - { - _host = s[0]; - _port = Integer.parseInt (s[1]); - } - } - - // Get server [form: "y" or "n"] - p = (String) properties.get (_PROPERTY_SERVER); - if (p != null) - { - if (p.toLowerCase().equals ("y")) - _server = true; - } - } - - /** - * Initialize this socket connection. This includes - * connecting to the host (or listening for it). - * - * @throws TransportException if a transport-related error occurs - */ - public void initialize () - throws TransportException - { - try - { - if (_server) - { - // Get a server socket - ServerSocketFactory ssf = ServerSocketFactory.getDefault (); - ServerSocket ss = ssf.createServerSocket (_port, 1); - _socket = ss.accept (); - } - else - { - // Get a client socket (the factory will connect it) - SocketFactory sf = SocketFactory.getDefault (); - _socket = sf.createSocket (_host, _port); - } - } - catch (IOException ioe) - { - // This will grab UnknownHostException, too. - throw new TransportException (ioe); - } - } - - /** - * Returns an <code>InputStream</code> for the transport - * - * @throws IOException if an I/O error occurs creating the stream - * or the socket is not connected - */ - public InputStream getInputStream () - throws IOException - { - return _socket.getInputStream (); - } - - /** - * Returns an <code>OutputStream</code> for the transport - * - * @throws IOException if an I/O error occurs creating the stream - * or the socket is not connected - */ - public OutputStream getOutputStream () - throws IOException - { - return _socket.getOutputStream (); - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/TransportException.java b/libjava/gnu/classpath/jdwp/transport/TransportException.java deleted file mode 100644 index 057422a879e..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/TransportException.java +++ /dev/null @@ -1,75 +0,0 @@ -/* TransportException.java -- Exception for transport configury errors - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -/** - * A transport configury or initialization exception thrown by - * JDWP transports. This class is a generic exception class - * that the different transport layers use to report transport-specific - * exceptions that may occur (which could be very different from - * one transport to the next.). - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class TransportException - extends Exception -{ - /** - * Constructs a <code>TransportException</code> with the - * given message - * - * @param message a message describing the exception - */ - public TransportException (String message) - { - super (message); - } - - /** - * Constructs a <code>TransportException</code> with the - * given <code>Throwable</code> root cause - * - * @param t the cause of the exception - */ - public TransportException (Throwable t) - { - super (t); - } -} diff --git a/libjava/gnu/classpath/jdwp/transport/TransportFactory.java b/libjava/gnu/classpath/jdwp/transport/TransportFactory.java deleted file mode 100644 index 480fb362939..00000000000 --- a/libjava/gnu/classpath/jdwp/transport/TransportFactory.java +++ /dev/null @@ -1,115 +0,0 @@ -/* TransportFactory.java -- Factory for transports - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.transport; - -import java.util.HashMap; - -/** - * A factory class that constructs transports for use by - * the JDWP back-end. - * - * @author Keith Seitz <keiths@redhat.com> - */ -public class TransportFactory -{ - // Keyword in configspec that specifies transport method - private static final String _TRANSPORT_PROPERTY = "transport"; - - // A single transport method mapping - private static class TransportMethod - { - String name; - Class clazz; - public TransportMethod (String name, Class clazz) - { - this.name = name; - this.clazz = clazz; - } - } - - // List of all supported transport methods - private static TransportMethod[] _transportMethods = new TransportMethod[] - { - new TransportMethod (SocketTransport.NAME, SocketTransport.class) - //new TransportMethod (ShmemTransport.NAME, ShmemTransport.class) - }; - - /** - * Get a transport configured as specified in the properties - * - * @param properties a <code>HashMap</code> specifying the JDWP - * configuration properties - * @returns the created and configured transport - * @throws TransportException for invalid configurations - */ - public static ITransport newInstance (HashMap properties) - throws TransportException - { - String name = null; - if (properties != null) - name = (String) properties.get (_TRANSPORT_PROPERTY); - if (name == null) - throw new TransportException ("no transport specified"); - - for (int i = 0; i < _transportMethods.length; ++i) - { - if (_transportMethods[i].name.equals (name)) - { - try - { - ITransport t; - t = (ITransport) _transportMethods[i].clazz.newInstance (); - t.configure (properties); - return t; - } - catch (TransportException te) - { - throw te; - } - catch (Exception e) - { - throw new TransportException (e); - } - } - } - - throw new TransportException ("transport \"" + name + "\" not found"); - } -} diff --git a/libjava/gnu/classpath/jdwp/util/JdwpString.java b/libjava/gnu/classpath/jdwp/util/JdwpString.java deleted file mode 100644 index 592249fccb2..00000000000 --- a/libjava/gnu/classpath/jdwp/util/JdwpString.java +++ /dev/null @@ -1,95 +0,0 @@ -/* JdwpString.java -- utility class to read and write jdwp strings - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.classpath.jdwp.util; - -import gnu.classpath.jdwp.exception.JdwpInternalErrorException; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; - -/** - * A class to compute the JDWP representation of Strings. - * - * @author Aaron Luchko <aluchko@redhat.com> - */ -public class JdwpString -{ - - /** - * Write this String to the outStream as a string understood by jdwp. - * - * @param os write the String here - * @param string the String to write - * @throws IOException - */ - public static void writeString(DataOutputStream os, String string) - throws IOException - { - // Get the bytes of the string as a string in UTF-8 - byte[] strBytes = string.getBytes("UTF-8"); - os.writeInt(strBytes.length); - os.write(strBytes); - } - - /** - * Read a jdwp style string from the ByteBuffer. - * - * @param bb contains the string - * @return the String that was read - * @throws JdwpInternalErrorException bb didn't contain a value UTF-8 string - */ - public static String readString(ByteBuffer bb) - throws JdwpInternalErrorException - { - int length = bb.getInt(); - byte[] strBytes = new byte[length]; - bb.get(strBytes); - try - { - return new String(strBytes, "UTF-8"); - } - catch (UnsupportedEncodingException ex) - { - // Any string from the VM should be in UTF-8 so an encoding error - // shouldn't be possible - throw new JdwpInternalErrorException(ex); - } - } -} diff --git a/libjava/gnu/classpath/jdwp/util/Signature.java b/libjava/gnu/classpath/jdwp/util/Signature.java deleted file mode 100644 index 36445c31841..00000000000 --- a/libjava/gnu/classpath/jdwp/util/Signature.java +++ /dev/null @@ -1,149 +0,0 @@ -/* Signature.java -- utility class to compute class and method signatures - Copyright (C) 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.classpath.jdwp.util; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * A class to compute class and method signatures. - * - * @author Tom Tromey (tromey@redhat.com) - * @author Keith Seitz (keiths@redhat.com) - */ -public class Signature -{ - /** - * Computes the class signature, i.e., java.lang.String.class - * returns "Ljava/lang/String;". - * - * @param theClass the class for which to compute the signature - * @return the class's type signature - */ - public static String computeClassSignature (Class theClass) - { - StringBuffer sb = new StringBuffer (); - _addToSignature (sb, theClass); - return sb.toString (); - } - - /** - * Computes the field signature which is just the class signature of the - * field's type, ie a Field of type java.lang.String this will return - * "Ljava/lang/String;". - * - * @param field the field for which to compute the signature - * @return the field's type signature - */ - public static String computeFieldSignature (Field field) - { - return computeClassSignature (field.getType()); - } - - /** - * Computes the method signature, i.e., java.lang.String.split (String, int) - * returns "(Ljava/lang/String;I)[Ljava/lang/String;" - * - * @param method the method for which to compute the signature - * @return the method's type signature - */ - public static String computeMethodSignature (Method method) - { - return _computeSignature (method.getReturnType (), - method.getParameterTypes ()); - } - - private static String _computeSignature (Class returnType, - Class[] paramTypes) - { - StringBuffer sb = new StringBuffer ("("); - if (paramTypes != null) - { - for (int i = 0; i < paramTypes.length; ++i) - _addToSignature (sb, paramTypes[i]); - } - sb.append (")"); - _addToSignature (sb, returnType); - return sb.toString(); - } - - private static void _addToSignature (StringBuffer sb, Class k) - { - // For some reason there's no easy way to get the signature of a - // class. - if (k.isPrimitive ()) - { - if (k == void.class) - sb.append('V'); - else if (k == boolean.class) - sb.append('Z'); - else if (k == byte.class) - sb.append('B'); - else if (k == char.class) - sb.append('C'); - else if (k == short.class) - sb.append('S'); - else if (k == int.class) - sb.append('I'); - else if (k == float.class) - sb.append('F'); - else if (k == double.class) - sb.append('D'); - else if (k == long.class) - sb.append('J'); - return; - } - - String name = k.getName (); - int len = name.length (); - sb.ensureCapacity (len); - if (! k.isArray ()) - sb.append('L'); - for (int i = 0; i < len; ++i) - { - char c = name.charAt (i); - if (c == '.') - c = '/'; - sb.append (c); - } - if (! k.isArray ()) - sb.append(';'); - } -} diff --git a/libjava/gnu/java/awt/BitMaskExtent.java b/libjava/gnu/java/awt/BitMaskExtent.java deleted file mode 100644 index 28134991099..00000000000 --- a/libjava/gnu/java/awt/BitMaskExtent.java +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt; - -/** - * Simple transparent utility class that can be used to perform bit - * mask extent calculations. - */ -public final class BitMaskExtent -{ - /** The number of the least significant bit of the bit mask extent. */ - public byte leastSignificantBit; - - /** The number of bits in the bit mask extent. */ - public byte bitWidth; - - /** - * Set the bit mask. This will calculate and set the leastSignificantBit - * and bitWidth fields. - * - * @see #leastSignificantBit - * @see #bitWidth - */ - public void setMask(long mask) - { - leastSignificantBit = 0; - bitWidth = 0; - if (mask == 0) return; - long shiftMask = mask; - for (; (shiftMask&1) == 0; shiftMask >>>=1) leastSignificantBit++; - for (; (shiftMask&1) != 0; shiftMask >>>=1) bitWidth++; - - if (shiftMask != 0) - throw new IllegalArgumentException("mask must be continuous"); - } - - /** - * Calculate the bit mask based on the values of the - * leastSignificantBit and bitWidth fields. - */ - public long toMask() - { - return ((1<<bitWidth)-1) << leastSignificantBit; - } -} diff --git a/libjava/gnu/java/awt/BitwiseXORComposite.java b/libjava/gnu/java/awt/BitwiseXORComposite.java deleted file mode 100644 index b568e1108c1..00000000000 --- a/libjava/gnu/java/awt/BitwiseXORComposite.java +++ /dev/null @@ -1,295 +0,0 @@ -/* BitwiseXORComposite.java -- Composite for emulating old-style XOR. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import java.awt.Color; -import java.awt.Composite; -import java.awt.CompositeContext; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.image.ColorModel; -import java.awt.image.DataBuffer; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; - - -/** - * A composite for emulating traditional bitwise XOR of pixel values. - * Please note that this composite does <i>not</i> implement the Porter-Duff - * XOR operator, but an exclusive or of overlapping subpixel regions. - * - * <p><img src="doc-files/BitwiseXORComposite-1.png" width="545" - * height="138" alt="A screen shot of BitwiseXORComposite in action" - * /> - * - * <p>The above screen shot shows the result of applying six different - * BitwiseXORComposites. They were constructed with the colors colors - * white, blue, black, orange, green, and brown, respectively. Each - * composite was used to paint a fully white rectangle on top of the - * blue bar in the background. - * - * <p>The purpose of this composite is to support the {@link - * Graphics#setXORMode(Color)} method in composite-aware graphics - * implementations. Applications typically would use - * <code>setXORMode</code> for drawing “highlights” such - * as text selections or cursors by inverting colors temporarily and - * then inverting them back. - * - * <p>A concrete <code>Graphics</code> implementation may contain - * the following code: - * - * <p><pre> public void setXORMode(Color xorColor) - * { - * setComposite(new gnu.java.awt.BitwiseXORComposite(xorColor)); - * } - * - * public void setPaintMode() - * { - * setComposite(java.awt.AlphaComposite.SrcOver); - * }</pre> - * - * @author Graydon Hoare (graydon@redhat.com) - * @author Sascha Brawer (brawer@dandelis.ch) - */ -public class BitwiseXORComposite - implements Composite -{ - /** - * The color whose RGB value is xor-ed with the values of each - * pixel. - */ - protected Color xorColor; - - - /** - * Constructs a new composite for xor-ing the pixel value. - * - * @param xorColor the color whose pixel value will be bitwise - * xor-ed with the source and destination pixels. - */ - public BitwiseXORComposite(Color xorColor) - { - this.xorColor = xorColor; - } - - - /** - * Creates a context object for performing the compositing - * operation. Several contexts may co-exist for one composite; each - * context may simultaneously be called from concurrent threads. - * - * @param srcColorModel the color model of the source. - * @param dstColorModel the color model of the destination. - * @param hints hints for choosing between rendering alternatives. - */ - public CompositeContext createContext(ColorModel srcColorModel, - ColorModel dstColorModel, - RenderingHints hints) - { - if (IntContext.isSupported(srcColorModel, dstColorModel, hints)) - return new IntContext(srcColorModel, xorColor); - - return new GeneralContext(srcColorModel, dstColorModel, xorColor); - } - - - /** - * A fallback CompositeContext that performs bitwise XOR of pixel - * values with the pixel value of the specified <code>xorColor</code>. - * - * <p>Applying this CompositeContext on a 1024x1024 BufferedImage of - * <code>TYPE_INT_RGB</code> took 611 ms on a lightly loaded 2.4 GHz - * Intel Pentium 4 CPU running Sun J2SE 1.4.1_01 on GNU/Linux - * 2.4.20. The timing is the average of ten runs on the same - * BufferedImage. Since the measurements were taken with {@link - * System#currentTimeMillis()}, they are rather inaccurate. - * - * @author Graydon Hoare (graydon@redhat.com) - */ - private static class GeneralContext - implements CompositeContext - { - ColorModel srcColorModel; - ColorModel dstColorModel; - Color xorColor; - - public GeneralContext(ColorModel srcColorModel, - ColorModel dstColorModel, - Color xorColor) - { - this.srcColorModel = srcColorModel; - this.dstColorModel = dstColorModel; - this.xorColor = xorColor; - } - - - public void compose(Raster src, Raster dstIn, WritableRaster dstOut) - { - Rectangle srcRect = src.getBounds(); - Rectangle dstInRect = dstIn.getBounds(); - Rectangle dstOutRect = dstOut.getBounds(); - - int xp = xorColor.getRGB(); - int w = Math.min(Math.min(srcRect.width, dstOutRect.width), - dstInRect.width); - int h = Math.min(Math.min(srcRect.height, dstOutRect.height), - dstInRect.height); - - Object srcPix = null, dstPix = null, rpPix = null; - - // Re-using the rpPix object saved 1-2% of execution time in - // the 1024x1024 pixel benchmark. - - for (int y = 0; y < h; y++) - { - for (int x = 0; x < w; x++) - { - srcPix = src.getDataElements(x + srcRect.x, y + srcRect.y, srcPix); - dstPix = dstIn.getDataElements(x + dstInRect.x, y + dstInRect.y, - dstPix); - int sp = srcColorModel.getRGB(srcPix); - int dp = dstColorModel.getRGB(dstPix); - int rp = sp ^ xp ^ dp; - dstOut.setDataElements(x + dstOutRect.x, y + dstOutRect.y, - dstColorModel.getDataElements(rp, rpPix)); - } - } - } - - - /** - * Disposes any cached resources. The default implementation does - * nothing because no resources are cached. - */ - public void dispose() - { - } - } - - - /** - * An optimized CompositeContext that performs bitwise XOR of - * <code>int</code> pixel values with the pixel value of a specified - * <code>xorColor</code>. This CompositeContext working only for - * rasters whose transfer format is {@link DataBuffer#TYPE_INT}. - * - * <p>Applying this CompositeContext on a 1024x1024 BufferedImage of - * <code>TYPE_INT_RGB</code> took 69 ms on a lightly loaded 2.4 GHz - * Intel Pentium 4 CPU running Sun J2SE 1.4.1_01 on GNU/Linux - * 2.4.20. The timing is the average of ten runs on the same - * BufferedImage. Since the measurements were taken with {@link - * System#currentTimeMillis()}, they are rather inaccurate. - * - * @author Sascha Brawer (brawer@dandelis.ch) - */ - private static class IntContext - extends GeneralContext - { - public IntContext(ColorModel colorModel, Color xorColor) - { - super(colorModel, colorModel, xorColor); - } - - - public void compose(Raster src, Raster dstIn, - WritableRaster dstOut) - { - int aX, bX, dstX, aY, bY, dstY, width, height; - int xorPixel; - int[] srcLine, dstLine; - - aX = src.getMinX(); - aY = src.getMinY(); - bX = dstIn.getMinX(); - bY = dstIn.getMinY(); - dstX = dstOut.getMinX(); - dstY = dstOut.getMinY(); - width = Math.min(Math.min(src.getWidth(), dstIn.getWidth()), - dstOut.getWidth()); - height = Math.min(Math.min(src.getHeight(), dstIn.getHeight()), - dstOut.getHeight()); - if ((width < 1) || (height < 1)) - return; - - srcLine = new int[width]; - dstLine = new int[width]; - - /* We need an int[] array with at least one element here; - * srcLine is as good as any other. - */ - srcColorModel.getDataElements(this.xorColor.getRGB(), srcLine); - xorPixel = srcLine[0]; - - for (int y = 0; y < height; y++) - { - src.getDataElements(aX, y + aY, width, 1, srcLine); - dstIn.getDataElements(bX, y + bY, width, 1, dstLine); - - for (int x = 0; x < width; x++) - dstLine[x] ^= srcLine[x] ^ xorPixel; - - dstOut.setDataElements(dstX, y + dstY, width, 1, dstLine); - } - } - - - /** - * Determines whether an instance of this CompositeContext would - * be able to process the specified color models. - */ - public static boolean isSupported(ColorModel srcColorModel, - ColorModel dstColorModel, - RenderingHints hints) - { - // FIXME: It would be good if someone could review these checks. - // They probably need to be more restrictive. - - int transferType; - - transferType = srcColorModel.getTransferType(); - if (transferType != dstColorModel.getTransferType()) - return false; - - if (transferType != DataBuffer.TYPE_INT) - return false; - - return true; - } - } -} diff --git a/libjava/gnu/java/awt/Buffers.java b/libjava/gnu/java/awt/Buffers.java deleted file mode 100644 index c6ccf919145..00000000000 --- a/libjava/gnu/java/awt/Buffers.java +++ /dev/null @@ -1,243 +0,0 @@ -/* Buffers.java -- - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferByte; -import java.awt.image.DataBufferDouble; -import java.awt.image.DataBufferFloat; -import java.awt.image.DataBufferInt; -import java.awt.image.DataBufferShort; -import java.awt.image.DataBufferUShort; - -/** - * Utility class for creating and accessing data buffers of arbitrary - * data types. - */ -public final class Buffers -{ - /** - * Create a data buffer of a particular type. - * - * @param dataType the desired data type of the buffer. - * @param data an array containing data, or null - * @param size the size of the data buffer bank - */ - public static DataBuffer createBuffer(int dataType, Object data, - int size) - { - if (data == null) return createBuffer(dataType, size, 1); - - return createBufferFromData(dataType, data, size); - } - - - /** - * Create a data buffer of a particular type. - * - * @param dataType the desired data type of the buffer. - * @param size the size of the data buffer bank - */ - public static DataBuffer createBuffer(int dataType, int size) { - return createBuffer(dataType, size, 1); - } - - /** - * Create a data buffer of a particular type. - * - * @param dataType the desired data type of the buffer. - * @param size the size of the data buffer bank - * @param numBanks the number of banks the buffer should have - */ - public static DataBuffer createBuffer(int dataType, int size, int numBanks) - { - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - return new DataBufferByte(size, numBanks); - case DataBuffer.TYPE_SHORT: - return new DataBufferShort(size, numBanks); - case DataBuffer.TYPE_USHORT: - return new DataBufferUShort(size, numBanks); - case DataBuffer.TYPE_INT: - return new DataBufferInt(size, numBanks); - case DataBuffer.TYPE_FLOAT: - return new DataBufferFloat(size, numBanks); - case DataBuffer.TYPE_DOUBLE: - return new DataBufferDouble(size, numBanks); - default: - throw new UnsupportedOperationException(); - } - } - - /** - * Create a data buffer of a particular type. - * - * @param dataType the desired data type of the buffer - * @param data an array containing the data - * @param size the size of the data buffer bank - */ - public static DataBuffer createBufferFromData(int dataType, Object data, - int size) - { - switch (dataType) - { - case DataBuffer.TYPE_BYTE: - return new DataBufferByte((byte[]) data, size); - case DataBuffer.TYPE_SHORT: - return new DataBufferShort((short[]) data, size); - case DataBuffer.TYPE_USHORT: - return new DataBufferUShort((short[]) data, size); - case DataBuffer.TYPE_INT: - return new DataBufferInt((int[]) data, size); - case DataBuffer.TYPE_FLOAT: - return new DataBufferFloat((float[]) data, size); - case DataBuffer.TYPE_DOUBLE: - return new DataBufferDouble((double[]) data, size); - default: - throw new UnsupportedOperationException(); - } - } - - /** - * Return the data array of a data buffer, regardless of the data - * type. - * - * @return an array of primitive values. The actual array type - * depends on the data type of the buffer. - */ - public static Object getData(DataBuffer buffer) - { - if (buffer instanceof DataBufferByte) - return ((DataBufferByte) buffer).getData(); - - if (buffer instanceof DataBufferShort) - return ((DataBufferShort) buffer).getData(); - - if (buffer instanceof DataBufferUShort) - return ((DataBufferUShort) buffer).getData(); - - if (buffer instanceof DataBufferInt) - return ((DataBufferInt) buffer).getData(); - - if (buffer instanceof DataBufferFloat) - return ((DataBufferFloat) buffer).getData(); - - if (buffer instanceof DataBufferDouble) - return ((DataBufferDouble) buffer).getData(); - - throw new ClassCastException("Unknown data buffer type"); - } - - - /** - * Copy data from array contained in data buffer, much like - * System.arraycopy. Create a suitable destination array if the - * given destination array is null. - */ - public static Object getData(DataBuffer src, int srcOffset, - Object dest, int destOffset, - int length) - { - Object from; - if (src instanceof DataBufferByte) - { - from = ((DataBufferByte) src).getData(); - if (dest == null) dest = new byte[length+destOffset]; - } - else if (src instanceof DataBufferShort) - { - from = ((DataBufferShort) src).getData(); - if (dest == null) dest = new short[length+destOffset]; - } - else if (src instanceof DataBufferUShort) - { - from = ((DataBufferUShort) src).getData(); - if (dest == null) dest = new short[length+destOffset]; - } - else if (src instanceof DataBufferInt) - { - from = ((DataBufferInt) src).getData(); - if (dest == null) dest = new int[length+destOffset]; - } - else if (src instanceof DataBufferFloat) - { - from = ((DataBufferFloat) src).getData(); - if (dest == null) dest = new float[length+destOffset]; - } - else if (src instanceof DataBufferDouble) - { - from = ((DataBufferDouble) src).getData(); - if (dest == null) dest = new double[length+destOffset]; - } - else - { - throw new ClassCastException("Unknown data buffer type"); - } - - System.arraycopy(from, srcOffset, dest, destOffset, length); - return dest; - } - - /** - * @param bits the width of a data element measured in bits - * - * @return the smallest data type that can store data elements of - * the given number of bits, without any truncation. - */ - public static int smallestAppropriateTransferType(int bits) - { - if (bits <= 8) - { - return DataBuffer.TYPE_BYTE; - } - else if (bits <= 16) - { - return DataBuffer.TYPE_USHORT; - } - else if (bits <= 32) - { - return DataBuffer.TYPE_INT; - } - else - { - return DataBuffer.TYPE_UNDEFINED; - } - } -} diff --git a/libjava/gnu/java/awt/ClasspathToolkit.java b/libjava/gnu/java/awt/ClasspathToolkit.java deleted file mode 100644 index d42bfc08221..00000000000 --- a/libjava/gnu/java/awt/ClasspathToolkit.java +++ /dev/null @@ -1,369 +0,0 @@ -/* ClasspathToolkit.java -- Abstract superclass for Classpath toolkits. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import gnu.java.awt.peer.ClasspathFontPeer; -import gnu.java.awt.peer.ClasspathTextLayoutPeer; - -import java.awt.AWTException; -import java.awt.Dimension; -import java.awt.DisplayMode; -import java.awt.EventQueue; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.Image; -import java.awt.Toolkit; -import java.awt.font.FontRenderContext; -import java.awt.image.ColorModel; -import java.awt.image.ImageProducer; -import java.awt.peer.RobotPeer; -import java.io.File; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.AttributedString; -import java.util.HashMap; -import java.util.Map; - -import javax.imageio.spi.IIORegistry; - -/** - * An abstract superclass for Classpath toolkits. - * - * <p>There exist some parts of AWT and Java2D that are specific to - * the underlying platform, but for which the {@link Toolkit} class - * does not provide suitable abstractions. Examples include some - * methods of {@link Font} or {@link GraphicsEnvironment}. Those - * methods use ClasspathToolkit as a central place for obtaining - * platform-specific functionality. - * - * <p>In addition, ClasspathToolkit implements some abstract methods - * of {@link java.awt.Toolkit} that are not really platform-specific, - * such as the maintenance of a cache of loaded images. - * - * <p><b>Thread Safety:</b> The methods of this class may safely be - * called without external synchronization. This also hold for any - * inherited {@link Toolkit} methods. Subclasses are responsible for - * the necessary synchronization. - * - * @author Sascha Brawer (brawer@dandelis.ch) - */ -public abstract class ClasspathToolkit - extends Toolkit -{ - /** - * A map from URLs to previously loaded images, used by {@link - * #getImage(java.net.URL)}. For images that were loaded via a path - * to an image file, the map contains a key with a file URL. - */ - private HashMap imageCache; - - - /** - * Returns a shared instance of the local, platform-specific - * graphics environment. - * - * <p>This method is specific to GNU Classpath. It gets called by - * the Classpath implementation of {@link - * GraphicsEnvironment.getLocalGraphcisEnvironment()}. - */ - public abstract GraphicsEnvironment getLocalGraphicsEnvironment(); - - - /** - * Determines the current size of the default, primary screen. - * - * @throws HeadlessException if the local graphics environment is - * headless, which means that no screen is attached and no user - * interaction is allowed. - */ - public Dimension getScreenSize() - { - DisplayMode mode; - - // getDefaultScreenDevice throws HeadlessException if the - // local graphics environment is headless. - mode = GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDisplayMode(); - - return new Dimension(mode.getWidth(), mode.getHeight()); - } - - - /** - * Determines the current color model of the default, primary - * screen. - * - * @see GraphicsEnvironment#getDefaultScreenDevice() - * @see java.awt.GraphicsDevice#getDefaultConfiguration() - * @see java.awt.GraphicsConfiguration#getColorModel() - * - * @throws HeadlessException if the local graphics environment is - * headless, which means that no screen is attached and no user - * interaction is allowed. - */ - public ColorModel getColorModel() - { - // getDefaultScreenDevice throws HeadlessException if the - // local graphics environment is headless. - return GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration() - .getColorModel(); - } - - /** - * Retrieves the metrics for rendering a font on the screen. - * - * @param font the font whose metrics are requested. - */ - public FontMetrics getFontMetrics(Font font) - { - return ((ClasspathFontPeer) font.getPeer ()).getFontMetrics (font); - } - - - /** - * Acquires an appropriate {@link ClasspathFontPeer}, for use in - * classpath's implementation of {@link java.awt.Font}. - * - * @param name The logical name of the font. This may be either a face - * name or a logical font name, or may even be null. A default - * implementation of name decoding is provided in - * {@link ClasspathFontPeer}, but may be overridden in other toolkits. - * - * @param attrs Any extra {@link java.awt.font.TextAttribute} attributes - * this font peer should have, such as size, weight, family name, or - * transformation. - */ - public abstract ClasspathFontPeer getClasspathFontPeer (String name, Map attrs); - - public abstract ClasspathTextLayoutPeer - getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc); - - - /** - * Creates a {@link Font}, in a platform-specific manner. - * - * The default implementation simply constructs a {@link Font}, but some - * toolkits may wish to override this, to return {@link Font} subclasses which - * implement {@link java.awt.font.OpenType} or - * {@link java.awt.font.MultipleMaster}. - */ - public Font getFont (String name, Map attrs) - { - return new Font (name, attrs); - } - - - /** - * Creates a font, reading the glyph definitions from a stream. - * - * <p>This method provides the platform-specific implementation for - * the static factory method {@link Font#createFont(int, - * java.io.InputStream)}. - * - * @param format the format of the font data, such as {@link - * Font#TRUETYPE_FONT}. An implementation may ignore this argument - * if it is able to automatically recognize the font format from the - * provided data. - * - * @param stream an input stream from where the font data is read - * in. The stream will be advanced to the position after the font - * data, but not closed. - * - * @throws IllegalArgumentException if <code>format</code> is - * not supported. - * - * @throws FontFormatException if <code>stream</code> does not - * contain data in the expected format, or if required tables are - * missing from a font. - * - * @throws IOException if a problem occurs while reading in the - * contents of <code>stream</code>. - */ - public abstract Font createFont(int format, InputStream stream); - - - /** - * Returns an image from the specified file, which must be in a - * recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>This method maintains a cache for images. If an image has been - * loaded from the same path before, the cached copy will be - * returned. The implementation may hold cached copies for an - * indefinite time, which can consume substantial resources with - * large images. Users are therefore advised to use {@link - * #createImage(java.lang.String)} instead. - * - * <p>The default implementation creates a file URL for the - * specified path and invokes {@link #getImage(URL)}. - * - * @param path A path to the image file. - * - * @return IllegalArgumentException if <code>path</code> does not - * designate a valid path. - */ - public Image getImage(String path) - { - try - { - return getImage(new File(path).toURL()); - } - catch (MalformedURLException muex) - { - throw (IllegalArgumentException) new IllegalArgumentException(path) - .initCause(muex); - } - } - - - /** - * Loads an image from the specified URL. The image data must be in - * a recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>This method maintains a cache for images. If an image has been - * loaded from the same URL before, the cached copy will be - * returned. The implementation may hold cached copies for an - * indefinite time, which can consume substantial resources with - * large images. Users are therefore advised to use {@link - * #createImage(java.net.URL)} instead. - * - * @param url the URL from where the image is read. - */ - public Image getImage(URL url) - { - Image result; - - synchronized (this) - { - // Many applications never call getImage. Therefore, we lazily - // create the image cache when it is actually needed. - if (imageCache == null) - imageCache = new HashMap(); - else - { - result = (Image) imageCache.get(url); - if (result != null) - return result; - } - - // The createImage(URL) method, which is specified by - // java.awt.Toolkit, is not implemented by this abstract class - // because it is platform-dependent. Once Classpath has support - // for the javax.imageio package, it might be worth considering - // that toolkits provide native stream readers. Then, the class - // ClasspathToolkit could provide a general implementation that - // delegates the image format parsing to javax.imageio. - result = createImage(url); - - // It is not clear whether it would be a good idea to use weak - // references here. The advantage would be reduced memory - // consumption, since loaded images would not be kept - // forever. But on VMs that frequently perform garbage - // collection (which includes VMs with a parallel or incremental - // collector), the image might frequently need to be re-loaded, - // possibly over a slow network connection. - imageCache.put(url, result); - - return result; - } - } - - - /** - * Returns an image from the specified file, which must be in a - * recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>A new image is created every time this method gets called, - * even if the same path has been passed before. - * - * <p>The default implementation creates a file URL for the - * specified path and invokes {@link #createImage(URL)}. - * - * @param path A path to the file to be read in. - */ - public Image createImage(String path) - { - try - { - // The abstract method createImage(URL) is defined by - // java.awt.Toolkit, but intentionally not implemented by - // ClasspathToolkit because it is platform specific. - return createImage(new File(path).toURL()); - } - catch (MalformedURLException muex) - { - throw (IllegalArgumentException) new IllegalArgumentException(path) - .initCause(muex); - } - } - - /** - * Creates an ImageProducer from the specified URL. The image is assumed - * to be in a recognised format. If the toolkit does not implement the - * image format or the image format is not recognised, null is returned. - * This default implementation is overriden by the Toolkit implementations. - * - * @param url URL to read image data from. - */ - public ImageProducer createImageProducer(URL url) - { - return null; - } - - public abstract RobotPeer createRobot (GraphicsDevice screen) - throws AWTException; - - /** - * Used to register ImageIO SPIs provided by the toolkit. - */ - - public void registerImageIOSpis(IIORegistry reg) - { - } - - public abstract boolean nativeQueueEmpty(); - public abstract void wakeNativeQueue(); - public abstract void iterateNativeQueue(EventQueue locked, boolean block); -} diff --git a/libjava/gnu/java/awt/ComponentDataBlitOp.java b/libjava/gnu/java/awt/ComponentDataBlitOp.java deleted file mode 100644 index 545427ea767..00000000000 --- a/libjava/gnu/java/awt/ComponentDataBlitOp.java +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt; - -import java.awt.RenderingHints; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.ComponentSampleModel; -import java.awt.image.DataBuffer; -import java.awt.image.Raster; -import java.awt.image.RasterOp; -import java.awt.image.WritableRaster; - -/** - * This raster copy operation assumes that both source and destination - * sample models are tightly pixel packed and contain the same number - * of bands. - * - * @throws java.lang.ClassCastException if the sample models of the - * rasters are not of type ComponentSampleModel. - * - * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) - */ -public class ComponentDataBlitOp implements RasterOp -{ - public static final ComponentDataBlitOp INSTANCE = new ComponentDataBlitOp(); - - public WritableRaster filter(Raster src, WritableRaster dest) - { - if (dest == null) - dest = createCompatibleDestRaster(src); - - DataBuffer srcDB = src.getDataBuffer(); - DataBuffer destDB = dest.getDataBuffer(); - - ComponentSampleModel srcSM = (ComponentSampleModel) src.getSampleModel(); - ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel(); - - - // Calculate offset to data in the underlying arrays: - - int srcScanlineStride = srcSM.getScanlineStride(); - int destScanlineStride = destSM.getScanlineStride(); - int srcX = src.getMinX() - src.getSampleModelTranslateX(); - int srcY = src.getMinY() - src.getSampleModelTranslateY(); - int destX = dest.getMinX() - dest.getSampleModelTranslateX(); - int destY = dest.getMinY() - dest.getSampleModelTranslateY(); - - int numBands = srcSM.getNumBands(); - - /* We can't use getOffset(x, y) from the sample model since we - don't want the band offset added in. */ - - int srcOffset = - numBands*srcX + srcScanlineStride*srcY + // from sample model - srcDB.getOffset(); // from data buffer - - int destOffset = - numBands*destX + destScanlineStride*destY + // from sample model - destDB.getOffset(); // from data buffer - - // Determine how much, and how many times to blit. - - int rowSize = src.getWidth()*numBands; - int h = src.getHeight(); - - if ((rowSize == srcScanlineStride) && - (rowSize == destScanlineStride)) - { - // collapse scan line blits to one large blit. - rowSize *= h; - h = 1; - } - - - // Do blitting - - Object srcArray = Buffers.getData(srcDB); - Object destArray = Buffers.getData(destDB); - - for (int yd = 0; yd<h; yd++) - { - System.arraycopy(srcArray, srcOffset, - destArray, destOffset, - rowSize); - srcOffset += srcScanlineStride; - destOffset += destScanlineStride; - } - - - return dest; - } - - public Rectangle2D getBounds2D(Raster src) - { - return src.getBounds(); - } - - public WritableRaster createCompatibleDestRaster(Raster src) { - - /* FIXME: Maybe we should explicitly create a raster with a - tightly pixel packed sample model, rather than assuming - that the createCompatibleWritableRaster() method in Raster - will create one. */ - - return src.createCompatibleWritableRaster(); - } - - public Point2D getPoint2D(Point2D srcPoint, Point2D destPoint) - { - if (destPoint == null) - return (Point2D) srcPoint.clone(); - - destPoint.setLocation(srcPoint); - return destPoint; - } - - public RenderingHints getRenderingHints() - { - throw new UnsupportedOperationException("not implemented"); - } -} diff --git a/libjava/gnu/java/awt/EmbeddedWindow.java b/libjava/gnu/java/awt/EmbeddedWindow.java deleted file mode 100644 index 2cf4316a42d..00000000000 --- a/libjava/gnu/java/awt/EmbeddedWindow.java +++ /dev/null @@ -1,143 +0,0 @@ -/* EmbeddedWindow.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import gnu.java.awt.peer.EmbeddedWindowPeer; -import gnu.java.security.action.SetAccessibleAction; - -import java.awt.Component; -import java.awt.Frame; -import java.awt.Toolkit; -import java.lang.reflect.Field; -import java.security.AccessController; - -/** - * Represents an AWT window that can be embedded into another - * application. - * - * @author Michael Koch (konqueror@gmx.de) - */ -public class EmbeddedWindow extends Frame -{ - private long handle; - - /** - * Creates a window to be embedded into another application. The - * window will only be embedded after its setHandle method has been - * called. - */ - public EmbeddedWindow () - { - super(); - this.handle = 0; - } - - /** - * Creates a window to be embedded into another application. - * - * @param handle the native handle to the screen area where the AWT - * window should be embedded - */ - public EmbeddedWindow (long handle) - { - super(); - this.handle = handle; - } - - /** - * Creates the native peer for this embedded window. - */ - public void addNotify() - { - Toolkit tk = getToolkit(); - - if (! (tk instanceof EmbeddedWindowSupport)) - throw new UnsupportedOperationException - ("Embedded windows are not supported by the current peers: " - + tk.getClass()); - - // Circumvent the package-privateness of the AWT internal - // java.awt.Component.peer member variable. - try - { - Field peerField = Component.class.getDeclaredField("peer"); - AccessController.doPrivileged(new SetAccessibleAction(peerField)); - peerField.set(this, ((EmbeddedWindowSupport) tk).createEmbeddedWindow (this)); - } - catch (IllegalAccessException e) - { - // This should never happen. - } - catch (NoSuchFieldException e) - { - // This should never happen. - } - - super.addNotify(); - } - - /** - * If the native peer for this embedded window has been created, - * then setHandle will embed the window. If not, setHandle tells - * us where to embed ourselves when our peer is created. - * - * @param handle the native handle to the screen area where the AWT - * window should be embedded - */ - public void setHandle(long handle) - { - if (this.handle != 0) - throw new RuntimeException ("EmbeddedWindow is already embedded"); - - this.handle = handle; - if (getPeer() != null) - ((EmbeddedWindowPeer) getPeer()).embed (this.handle); - } - - /** - * Gets the native handle of the screen area where the window will - * be embedded. - * - * @return The native handle that was passed to the constructor. - */ - public long getHandle() - { - return handle; - } -} diff --git a/libjava/gnu/java/awt/EmbeddedWindowSupport.java b/libjava/gnu/java/awt/EmbeddedWindowSupport.java deleted file mode 100644 index 566f0949eb2..00000000000 --- a/libjava/gnu/java/awt/EmbeddedWindowSupport.java +++ /dev/null @@ -1,65 +0,0 @@ -/* EmbeddedWindowSupport.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import gnu.java.awt.peer.EmbeddedWindowPeer; - -/** - * Declares a method for creating native embedded window peers. - * - * All classes inherited from java.awt.Toolkit that implement this - * interface are assumed to support the creation of embedded window - * peers. To create an embedded window, use - * gnu.java.awt.EmbeddedWindow. - * - * @see gnu.java.awt.EmbeddedWindow - * @see java.awt.Toolkit - * - * @author Michael Koch (konqueror@gmx.de) - */ -public interface EmbeddedWindowSupport -{ - /** - * Creates an embedded window peer, and associates it with an - * EmbeddedWindow object. - * - * @param w The embedded window with which to associate a peer. - */ - EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w); -} diff --git a/libjava/gnu/java/awt/EventModifier.java b/libjava/gnu/java/awt/EventModifier.java deleted file mode 100644 index 565fcbc3297..00000000000 --- a/libjava/gnu/java/awt/EventModifier.java +++ /dev/null @@ -1,107 +0,0 @@ -/* EventModifier.java -- tool for converting modifier bits to 1.4 syle - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt; - -import java.awt.event.InputEvent; - -public class EventModifier -{ - /** The mask for old events. */ - public static final int OLD_MASK = 0x3f; - - /** The mask for new events. */ - public static final int NEW_MASK = 0x3fc0; - - /** - * Non-instantiable. - */ - private EventModifier() - { - throw new InternalError(); - } - - /** - * Converts the old style modifiers (0x3f) to the new style (0xffffffc0). - * - * @param mod the modifiers to convert - * @return the adjusted modifiers - */ - public static int extend(int mod) - { - // Favor what we hope will be the common case. - if ((mod & OLD_MASK) == 0) - return mod; - if ((mod & InputEvent.SHIFT_MASK) != 0) - mod |= InputEvent.SHIFT_DOWN_MASK; - if ((mod & InputEvent.CTRL_MASK) != 0) - mod |= InputEvent.CTRL_DOWN_MASK; - if ((mod & InputEvent.META_MASK) != 0) - mod |= InputEvent.META_DOWN_MASK; - if ((mod & InputEvent.ALT_MASK) != 0) - mod |= InputEvent.ALT_DOWN_MASK; - if ((mod & InputEvent.BUTTON1_MASK) != 0) - mod |= InputEvent.BUTTON1_DOWN_MASK; - if ((mod & InputEvent.ALT_GRAPH_MASK) != 0) - mod |= InputEvent.ALT_GRAPH_DOWN_MASK; - return mod & ~OLD_MASK; - } - - /** - * Converts the new style modifiers (0xffffffc0) to the old style (0x3f). - * - * @param mod the modifiers to convert - * @return the adjusted modifiers - */ - public static int revert(int mod) - { - if ((mod & InputEvent.SHIFT_DOWN_MASK) != 0) - mod |= InputEvent.SHIFT_MASK; - if ((mod & InputEvent.CTRL_DOWN_MASK) != 0) - mod |= InputEvent.CTRL_MASK; - if ((mod & InputEvent.META_DOWN_MASK) != 0) - mod |= InputEvent.META_MASK; - if ((mod & InputEvent.ALT_DOWN_MASK) != 0) - mod |= InputEvent.ALT_MASK; - if ((mod & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) - mod |= InputEvent.ALT_GRAPH_MASK; - if ((mod & InputEvent.BUTTON1_DOWN_MASK) != 0) - mod |= InputEvent.BUTTON1_MASK; - return mod & OLD_MASK; - } -} // class EventModifier diff --git a/libjava/gnu/java/awt/color/CieXyzConverter.java b/libjava/gnu/java/awt/color/CieXyzConverter.java deleted file mode 100644 index 1742805854d..00000000000 --- a/libjava/gnu/java/awt/color/CieXyzConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* CieXyzConverter.java -- CieXyz conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * CieXyzConverter - converts to/from a D50-relative CIE XYZ color space. - * - * The sRGB<->CIE XYZ conversions in SrgbConverter are used. - * - * @author Sven de Marothy - */ -public class CieXyzConverter implements ColorSpaceConverter -{ - public float[] toCIEXYZ(float[] in) - { - float[] out = new float[3]; - System.arraycopy(in, 0, out, 0, 3); - return out; - } - - public float[] fromCIEXYZ(float[] in) - { - float[] out = new float[3]; - System.arraycopy(in, 0, out, 0, 3); - return out; - } - - public float[] toRGB(float[] in) - { - return SrgbConverter.XYZtoRGB(in); - } - - public float[] fromRGB(float[] in) - { - return SrgbConverter.RGBtoXYZ(in); - } -} diff --git a/libjava/gnu/java/awt/color/ClutProfileConverter.java b/libjava/gnu/java/awt/color/ClutProfileConverter.java deleted file mode 100644 index bff97cc9b87..00000000000 --- a/libjava/gnu/java/awt/color/ClutProfileConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* ClutProfileConverter.java -- Conversion routines for CLUT-Based profiles - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - -import java.awt.color.ICC_Profile; - - -/** - * ClutProfileConverter - conversions through a CLUT-based profile - * - * @author Sven de Marothy - */ -public class ClutProfileConverter implements ColorSpaceConverter -{ - private ColorLookUpTable toPCS; - private ColorLookUpTable fromPCS; - private int nChannels; - - public ClutProfileConverter(ICC_Profile profile) - { - nChannels = profile.getNumComponents(); - - // Sun does not specifiy which rendering intent should be used, - // neither does the ICC v2 spec really. - // Try intent 0 - try - { - toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag); - } - catch (Exception e) - { - toPCS = null; - } - - try - { - fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag); - } - catch (Exception e) - { - fromPCS = null; - } - - if (toPCS != null || fromPCS != null) - return; - - // If no intent 0 clut is available, look for a intent 1 clut. - try - { - toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB1Tag); - } - catch (Exception e) - { - toPCS = null; - } - - try - { - fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA1Tag); - } - catch (Exception e) - { - fromPCS = null; - } - - if (toPCS != null || fromPCS != null) - return; - - // Last shot.. intent 2 CLUT. - try - { - toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB2Tag); - } - catch (Exception e) - { - toPCS = null; - } - - try - { - fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA2Tag); - } - catch (Exception e) - { - fromPCS = null; - } - - if (toPCS == null && fromPCS == null) - throw new IllegalArgumentException("No CLUTs in profile!"); - } - - public float[] toCIEXYZ(float[] in) - { - if (toPCS != null) - return toPCS.lookup(in); - else - return new float[3]; - } - - public float[] toRGB(float[] in) - { - return SrgbConverter.XYZtoRGB(toCIEXYZ(in)); - } - - public float[] fromCIEXYZ(float[] in) - { - if (fromPCS != null) - return fromPCS.lookup(in); - else - return new float[nChannels]; - } - - public float[] fromRGB(float[] in) - { - return fromCIEXYZ(SrgbConverter.RGBtoXYZ(in)); - } -} diff --git a/libjava/gnu/java/awt/color/ColorLookUpTable.java b/libjava/gnu/java/awt/color/ColorLookUpTable.java deleted file mode 100644 index 6b6418bc284..00000000000 --- a/libjava/gnu/java/awt/color/ColorLookUpTable.java +++ /dev/null @@ -1,429 +0,0 @@ -/* ColorLookUpTable.java -- ICC v2 CLUT - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - -import java.awt.color.ColorSpace; -import java.awt.color.ICC_Profile; -import java.nio.ByteBuffer; - - -/** - * ColorLookUpTable handles color lookups through a color lookup table, - * as defined in the ICC specification. - * Both 'mft2' and 'mft1' (8 and 16-bit) type CLUTs are handled. - * - * This will have to be updated later for ICC 4.0.0 - * - * @author Sven de Marothy - */ -public class ColorLookUpTable -{ - /** - * CIE 1931 D50 white point (in Lab coordinates) - */ - private static float[] D50 = { 0.96422f, 1.00f, 0.82521f }; - - /** - * Number of input/output channels - */ - int nIn; - - /** - * Number of input/output channels - */ - int nOut; - int nInTableEntries; // Number of input table entries - int nOutTableEntries; // Number of output table entries - int gridpoints; // Number of gridpoints - int nClut; // This is nOut*(gridpoints**nIn) - double[][] inTable; // 1D input table ([channel][table]) - short[][] outTable; // 1D input table ([channel][table]) - double[] clut; // The color lookup table - float[][] inMatrix; // input matrix (XYZ only) - boolean useMatrix; // Whether to use the matrix or not. - int[] multiplier; - int[] offsets; // Hypercube offsets - boolean inputLab; // Set if the CLUT input CS is Lab - boolean outputLab; // Set if the CLUT output CS is Lab - - /** - * Constructor - * Requires a profile file to get the CLUT from and the tag of the - * CLUT to create. (icSigXToYZTag where X,Y = [A | B], Z = [0,1,2]) - */ - public ColorLookUpTable(ICC_Profile profile, int tag) - { - useMatrix = false; - - switch (tag) - { - case ICC_Profile.icSigAToB0Tag: - case ICC_Profile.icSigAToB1Tag: - case ICC_Profile.icSigAToB2Tag: - if (profile.getColorSpaceType() == ColorSpace.TYPE_XYZ) - useMatrix = true; - inputLab = false; - outputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab); - break; - case ICC_Profile.icSigBToA0Tag: - case ICC_Profile.icSigBToA1Tag: - case ICC_Profile.icSigBToA2Tag: - if (profile.getPCSType() == ColorSpace.TYPE_XYZ) - useMatrix = true; - inputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab); - outputLab = false; - break; - default: - throw new IllegalArgumentException("Not a clut-type tag."); - } - - byte[] data = profile.getData(tag); - if (data == null) - throw new IllegalArgumentException("Unsuitable profile, does not contain a CLUT."); - - // check 'mft' - if (data[0] != 0x6d || data[1] != 0x66 || data[2] != 0x74) - throw new IllegalArgumentException("Unsuitable profile, invalid CLUT data."); - - if (data[3] == 0x32) - readClut16(data); - else if (data[3] == 0x31) - readClut8(data); - else - throw new IllegalArgumentException("Unknown/invalid CLUT type."); - } - - /** - * Loads a 16-bit CLUT into our data structures - */ - private void readClut16(byte[] data) - { - ByteBuffer buf = ByteBuffer.wrap(data); - - nIn = data[8] & (0xFF); - nOut = data[9] & (0xFF); - nInTableEntries = buf.getShort(48); - nOutTableEntries = buf.getShort(50); - gridpoints = data[10] & (0xFF); - - inMatrix = new float[3][3]; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f; - - inTable = new double[nIn][nInTableEntries]; - for (int channel = 0; channel < nIn; channel++) - for (int i = 0; i < nInTableEntries; i++) - inTable[channel][i] = (double) ((int) buf.getShort(52 - + (channel * nInTableEntries - + i) * 2) - & (0xFFFF)) / 65536.0; - - nClut = nOut; - multiplier = new int[nIn]; - multiplier[nIn - 1] = nOut; - for (int i = 0; i < nIn; i++) - { - nClut *= gridpoints; - if (i > 0) - multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints; - } - - int clutOffset = 52 + nIn * nInTableEntries * 2; - clut = new double[nClut]; - for (int i = 0; i < nClut; i++) - clut[i] = (double) ((int) buf.getShort(clutOffset + i * 2) & (0xFFFF)) / 65536.0; - - outTable = new short[nOut][nOutTableEntries]; - for (int channel = 0; channel < nOut; channel++) - for (int i = 0; i < nOutTableEntries; i++) - outTable[channel][i] = buf.getShort(clutOffset - + (nClut - + channel * nOutTableEntries + i) * 2); - - // calculate the hypercube corner offsets - offsets = new int[(1 << nIn)]; - offsets[0] = 0; - for (int j = 0; j < nIn; j++) - { - int factor = 1 << j; - for (int i = 0; i < factor; i++) - offsets[factor + i] = offsets[i] + multiplier[j]; - } - } - - /** - * Loads a 8-bit CLUT into our data structures. - */ - private void readClut8(byte[] data) - { - ByteBuffer buf = ByteBuffer.wrap(data); - - nIn = (data[8] & (0xFF)); - nOut = (data[9] & (0xFF)); - nInTableEntries = 256; // always 256 - nOutTableEntries = 256; // always 256 - gridpoints = (data[10] & (0xFF)); - - inMatrix = new float[3][3]; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f; - - inTable = new double[nIn][nInTableEntries]; - for (int channel = 0; channel < nIn; channel++) - for (int i = 0; i < nInTableEntries; i++) - inTable[channel][i] = (double) ((int) buf.get(48 - + (channel * nInTableEntries - + i)) & (0xFF)) / 255.0; - - nClut = nOut; - multiplier = new int[nIn]; - multiplier[nIn - 1] = nOut; - for (int i = 0; i < nIn; i++) - { - nClut *= gridpoints; - if (i > 0) - multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints; - } - - int clutOffset = 48 + nIn * nInTableEntries; - clut = new double[nClut]; - for (int i = 0; i < nClut; i++) - clut[i] = (double) ((int) buf.get(clutOffset + i) & (0xFF)) / 255.0; - - outTable = new short[nOut][nOutTableEntries]; - for (int channel = 0; channel < nOut; channel++) - for (int i = 0; i < nOutTableEntries; i++) - outTable[channel][i] = (short) (buf.get(clutOffset + nClut - + channel * nOutTableEntries - + i) * 257); - - // calculate the hypercube corner offsets - offsets = new int[(1 << nIn)]; - offsets[0] = 0; - for (int j = 0; j < nIn; j++) - { - int factor = 1 << j; - for (int i = 0; i < factor; i++) - offsets[factor + i] = offsets[i] + multiplier[j]; - } - } - - /** - * Performs a lookup through the Color LookUp Table. - * If the CLUT tag type is AtoB the conversion will be from the device - * color space to the PCS, BtoA type goes in the opposite direction. - * - * For convenience, the PCS values for input or output will always be - * CIE XYZ (D50), if the actual PCS is Lab, the values will be converted. - * - * N-dimensional linear interpolation is used. - */ - float[] lookup(float[] in) - { - float[] in2 = new float[in.length]; - if (useMatrix) - { - for (int i = 0; i < 3; i++) - in2[i] = in[0] * inMatrix[i][0] + in[1] * inMatrix[i][1] - + in[2] * inMatrix[i][2]; - } - else if (inputLab) - in2 = XYZtoLab(in); - else - System.arraycopy(in, 0, in2, 0, in.length); - - // input table - for (int i = 0; i < nIn; i++) - { - int index = (int) Math.floor(in2[i] * (double) (nInTableEntries - 1)); // floor in - - // clip values. - if (index >= nInTableEntries - 1) - in2[i] = (float) inTable[i][nInTableEntries - 1]; - else if (index < 0) - in2[i] = (float) inTable[i][0]; - else - { - // linear interpolation - double alpha = in2[i] * ((double) nInTableEntries - 1.0) - index; - in2[i] = (float) (inTable[i][index] * (1 - alpha) - + inTable[i][index + 1] * alpha); - } - } - - // CLUT lookup - double[] output2 = new double[nOut]; - double[] weights = new double[(1 << nIn)]; - double[] clutalpha = new double[nIn]; // interpolation values - int offset = 0; // = gp - for (int i = 0; i < nIn; i++) - { - int index = (int) Math.floor(in2[i] * ((double) gridpoints - 1.0)); - double alpha = in2[i] * ((double) gridpoints - 1.0) - (double) index; - - // clip values. - if (index >= gridpoints - 1) - { - index = gridpoints - 1; - alpha = 1.0; - } - else if (index < 0) - index = 0; - clutalpha[i] = alpha; - offset += index * multiplier[i]; - } - - // Calculate interpolation weights - weights[0] = 1.0; - for (int j = 0; j < nIn; j++) - { - int factor = 1 << j; - for (int i = 0; i < factor; i++) - { - weights[factor + i] = weights[i] * clutalpha[j]; - weights[i] *= (1.0 - clutalpha[j]); - } - } - - for (int i = 0; i < nOut; i++) - output2[i] = weights[0] * clut[offset + i]; - - for (int i = 1; i < (1 << nIn); i++) - { - int offset2 = offset + offsets[i]; - for (int f = 0; f < nOut; f++) - output2[f] += weights[i] * clut[offset2 + f]; - } - - // output table - float[] output = new float[nOut]; - for (int i = 0; i < nOut; i++) - { - int index = (int) Math.floor(output2[i] * ((double) nOutTableEntries - - 1.0)); - - // clip values. - if (index >= nOutTableEntries - 1) - output[i] = outTable[i][nOutTableEntries - 1]; - else if (index < 0) - output[i] = outTable[i][0]; - else - { - // linear interpolation - double a = output2[i] * ((double) nOutTableEntries - 1.0) - - (double) index; - output[i] = (float) ((double) ((int) outTable[i][index] & (0xFFFF)) * (1 - - a) - + (double) ((int) outTable[i][index + 1] & (0xFFFF)) * a) / 65536f; - } - } - - if (outputLab) - return LabtoXYZ(output); - return output; - } - - /** - * Converts CIE Lab coordinates to (D50) XYZ ones. - */ - private float[] LabtoXYZ(float[] in) - { - // Convert from byte-packed format to a - // more convenient one (actual Lab values) - // (See ICC spec for details) - // factor is 100 * 65536 / 65280 - in[0] = (float) (100.392156862745 * in[0]); - in[1] = (in[1] * 256.0f) - 128.0f; - in[2] = (in[2] * 256.0f) - 128.0f; - - float[] out = new float[3]; - - out[1] = (in[0] + 16.0f) / 116.0f; - out[0] = in[1] / 500.0f + out[1]; - out[2] = out[1] - in[2] / 200.0f; - - for (int i = 0; i < 3; i++) - { - double exp = out[i] * out[i] * out[i]; - if (exp <= 0.008856) - out[i] = (out[i] - 16.0f / 116.0f) / 7.787f; - else - out[i] = (float) exp; - out[i] = D50[i] * out[i]; - } - return out; - } - - /** - * Converts CIE XYZ coordinates to Lab ones. - */ - private float[] XYZtoLab(float[] in) - { - float[] temp = new float[3]; - - for (int i = 0; i < 3; i++) - { - temp[i] = in[i] / D50[i]; - - if (temp[i] <= 0.008856f) - temp[i] = (7.7870689f * temp[i]) + (16f / 116.0f); - else - temp[i] = (float) Math.exp((1.0 / 3.0) * Math.log(temp[i])); - } - - float[] out = new float[3]; - out[0] = (116.0f * temp[1]) - 16f; - out[1] = 500.0f * (temp[0] - temp[1]); - out[2] = 200.0f * (temp[1] - temp[2]); - - // Normalize to packed format - out[0] = (float) (out[0] / 100.392156862745); - out[1] = (out[1] + 128f) / 256f; - out[2] = (out[2] + 128f) / 256f; - for (int i = 0; i < 3; i++) - { - if (out[i] < 0f) - out[i] = 0f; - if (out[i] > 1f) - out[i] = 1f; - } - return out; - } -} diff --git a/libjava/gnu/java/awt/color/ColorSpaceConverter.java b/libjava/gnu/java/awt/color/ColorSpaceConverter.java deleted file mode 100644 index 63ba08a4ff5..00000000000 --- a/libjava/gnu/java/awt/color/ColorSpaceConverter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* ColorSpaceConverter.java -- an interface for colorspace conversion - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * ColorSpaceConverter - used by java.awt.color.ICC_ColorSpace - * - * Color space conversion can occur in several ways: - * - * -Directly (for the built in spaces sRGB, linear RGB, gray, CIE XYZ and PYCC - * -ICC_ProfileRGB works through TRC curves and a matrix - * -ICC_ProfileGray works through a single TRC - * -Everything else is done through Color lookup tables. - * - * The different conversion methods are implemented through - * an interface. The built-in colorspaces are implemented directly - * with the relevant conversion equations. - * - * In this way, we hopefully will always use the fastest and most - * accurate method available. - * - * @author Sven de Marothy - */ -public interface ColorSpaceConverter -{ - float[] toCIEXYZ(float[] in); - - float[] fromCIEXYZ(float[] in); - - float[] toRGB(float[] in); - - float[] fromRGB(float[] in); -} diff --git a/libjava/gnu/java/awt/color/GrayProfileConverter.java b/libjava/gnu/java/awt/color/GrayProfileConverter.java deleted file mode 100644 index 3c725138a66..00000000000 --- a/libjava/gnu/java/awt/color/GrayProfileConverter.java +++ /dev/null @@ -1,137 +0,0 @@ -/* GrayProfileConverter.java -- Gray profile conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.color; - -import java.awt.color.ICC_Profile; -import java.awt.color.ICC_ProfileGray; -import java.awt.color.ProfileDataException; - -/** - * GrayProfileConverter - converts Grayscale profiles (ICC_ProfileGray) - * - * This type of profile contains a single tone reproduction curve (TRC). - * Conversion consists of simple TRC lookup. - * - * This implementation is very lazy and does everything applying the TRC and - * utilizing the built-in linear grayscale color space. - * - * @author Sven de Marothy - */ -public class GrayProfileConverter implements ColorSpaceConverter -{ - private GrayScaleConverter gc; - private ToneReproductionCurve trc; - private ColorLookUpTable toPCS; - private ColorLookUpTable fromPCS; - - /** - * Constructs the converter described by an ICC_ProfileGray object - */ - public GrayProfileConverter(ICC_ProfileGray profile) - { - try - { - trc = new ToneReproductionCurve(profile.getGamma()); - } - catch (ProfileDataException e) - { - trc = new ToneReproductionCurve(profile.getTRC()); - } - - // linear grayscale converter - gc = new GrayScaleConverter(); - - // If a CLUT is available, it should be used, and the TRCs ignored. - // Note: A valid profile may only have CLUTs in one direction, and - // TRC:s without useful info, making reverse-transforms impossible. - // In this case the TRC will be used for the reverse-transform with - // unpredictable results. This is in line with the Java specification, - try - { - toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag); - } - catch (Exception e) - { - toPCS = null; - } - - try - { - fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag); - } - catch (Exception e) - { - fromPCS = null; - } - } - - public float[] toCIEXYZ(float[] in) - { - if (toPCS != null) - return toPCS.lookup(in); - float[] gray = new float[1]; - gray[0] = trc.lookup(in[0]); - return gc.toCIEXYZ(gray); - } - - public float[] toRGB(float[] in) - { - float[] gray = new float[1]; - gray[0] = trc.lookup(in[0]); - return gc.toRGB(gray); - } - - public float[] fromRGB(float[] in) - { - // get linear grayscale value - float[] gray = gc.fromRGB(in); - gray[0] = trc.reverseLookup(gray[0]); - return gray; - } - - public float[] fromCIEXYZ(float[] in) - { - if (fromPCS != null) - return fromPCS.lookup(in); - - float[] gray = gc.fromCIEXYZ(in); - gray[0] = trc.reverseLookup(gray[0]); - return gray; - } -} diff --git a/libjava/gnu/java/awt/color/GrayScaleConverter.java b/libjava/gnu/java/awt/color/GrayScaleConverter.java deleted file mode 100644 index 7a27ddba828..00000000000 --- a/libjava/gnu/java/awt/color/GrayScaleConverter.java +++ /dev/null @@ -1,110 +0,0 @@ -/* GrayScaleConverter.java -- Linear grayscale conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * Linear Grayscale converter - * - * @author Sven de Marothy - */ -public class GrayScaleConverter implements ColorSpaceConverter -{ - // intensity factors (ITU Rec. BT.709) - double[] coeff = { 0.2125f, 0.7154f, 0.0721f }; - - /** - * CIE 1931 D50 white point (in Lab coordinates) - */ - private static float[] D50 = { 0.96422f, 1.00f, 0.82521f }; - - public float[] toCIEXYZ(float[] in) - { - float g = in[0]; - if (g < 0) - g = 1 + g; - float[] out = { g * D50[0], g * D50[1], g * D50[2] }; // White spot - return out; - } - - public float[] toRGB(float[] in) - { - float[] out = new float[3]; - if (in[0] <= 0.00304f) - out[0] = in[0] * 12.92f; - else - out[0] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(in[0]))) - - 0.055f; - out[1] = out[2] = out[0]; - return out; - } - - public float[] fromCIEXYZ(float[] in) - { - float[] temp = new float[3]; - temp[0] = 3.1338f * in[0] - 1.6171f * in[1] - 0.4907f * in[2]; - temp[1] = -0.9785f * in[0] + 1.9160f * in[1] + 0.0334f * in[2]; - temp[2] = 0.0720f * in[0] - 0.2290f * in[1] + 1.4056f * in[2]; - float[] out = new float[1]; - for (int i = 0; i < 3; i++) - out[0] = (float) (temp[i] * coeff[i]); - return out; - } - - public float[] fromRGB(float[] in) - { - float[] out = new float[1]; - - // Convert non-linear RGB coordinates to linear ones, - // numbers from the w3 spec. - out[0] = 0; - for (int i = 0; i < 3; i++) - { - float n = in[i]; - if (n < 0) - n = 0f; - if (n > 1) - n = 1f; - if (n <= 0.03928f) - out[0] += (float) (coeff[i] * n / 12.92); - else - out[0] += (float) (coeff[i] * Math.exp(2.4 * Math.log((n + 0.055) / 1.055))); - } - return out; - } -} diff --git a/libjava/gnu/java/awt/color/LinearRGBConverter.java b/libjava/gnu/java/awt/color/LinearRGBConverter.java deleted file mode 100644 index 13a4e2c04f4..00000000000 --- a/libjava/gnu/java/awt/color/LinearRGBConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* LinearRGBConverter.java -- conversion to a linear RGB color space - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * LinearRGBConverter - conversion routines for a linear sRGB colorspace - * sRGB is a standard for RGB colorspaces, adopted by the w3c. - * - * The specification is available at: - * http://www.w3.org/Graphics/Color/sRGB.html - * - * @author Sven de Marothy - */ -public class LinearRGBConverter implements ColorSpaceConverter -{ - /** - * linear RGB --> sRGB - * Use the inverse gamma curve - */ - public float[] toRGB(float[] in) - { - float[] out = new float[3]; - for (int i = 0; i < 3; i++) - { - float n = in[i]; - if (n < 0) - n = 0f; - if (n > 1) - n = 1f; - if (n <= 0.00304f) - out[i] = in[0] * 12.92f; - else - out[i] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(n))) - - 0.055f; - } - return out; - } - - /** - * sRGB --> linear RGB - * Use the gamma curve (gamma=2.4 in sRGB) - */ - public float[] fromRGB(float[] in) - { - float[] out = new float[3]; - - // Convert non-linear RGB coordinates to linear ones, - // numbers from the w3 spec. - for (int i = 0; i < 3; i++) - { - float n = in[i]; - if (n < 0) - n = 0f; - if (n > 1) - n = 1f; - if (n <= 0.03928f) - out[i] = (float) (n / 12.92); - else - out[i] = (float) (Math.exp(2.4 * Math.log((n + 0.055) / 1.055))); - } - return out; - } - - /** - * Linear RGB --> CIE XYZ (D50 relative) - * This is a simple matrix transform, the matrix (relative D65) - * is given in the sRGB spec. This has been combined with a - * linear Bradford transform for the D65-->D50 mapping, resulting - * in a single matrix which does the whole thing. - * - */ - public float[] fromCIEXYZ(float[] in) - { - /* - * Note: The numbers which were used to calculate this only had four - * digits of accuracy. So don't be fooled by the number of digits here. - * If someone has more accurate source, feel free to update this. - */ - float[] out = new float[3]; - out[0] = (float) (3.13383065124221 * in[0] - 1.61711949411313 * in[1] - - 0.49071914111101 * in[2]); - out[1] = (float) (-0.97847026691142 * in[0] + 1.91597856031996 * in[1] - + 0.03340430640699 * in[2]); - out[2] = (float) (0.07203679486279 * in[0] - 0.22903073553113 * in[1] - + 1.40557835776234 * in[2]); - if (out[0] < 0) - out[0] = 0f; - if (out[1] < 0) - out[1] = 0f; - if (out[2] < 0) - out[2] = 0f; - if (out[0] > 1.0f) - out[0] = 1.0f; - if (out[1] > 1.0f) - out[1] = 1.0f; - if (out[2] > 1.0f) - out[2] = 1.0f; - return out; - } - - /** - * Linear RGB --> CIE XYZ (D50 relative) - * Uses the inverse of the above matrix. - */ - public float[] toCIEXYZ(float[] in) - { - float[] out = new float[3]; - out[0] = (float) (0.43606375022190 * in[0] + 0.38514960146481 * in[1] - + 0.14308641888799 * in[2]); - out[1] = (float) (0.22245089403542 * in[0] + 0.71692584775182 * in[1] - + 0.06062451125578 * in[2]); - out[2] = (float) (0.01389851860679 * in[0] + 0.09707969011198 * in[1] - + 0.71399604572506 * in[2]); - return out; - } -} diff --git a/libjava/gnu/java/awt/color/ProfileHeader.java b/libjava/gnu/java/awt/color/ProfileHeader.java deleted file mode 100644 index 4fdef560a42..00000000000 --- a/libjava/gnu/java/awt/color/ProfileHeader.java +++ /dev/null @@ -1,398 +0,0 @@ -/* ProfileHeader.java -- Encapsules ICC Profile header data - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - -import java.awt.color.ColorSpace; -import java.awt.color.ICC_Profile; -import java.nio.ByteBuffer; - - -/** - * Header, abstracts and validates the header data. - * - * @author Sven de Marothy - */ -public class ProfileHeader -{ - /** - * Magic identifier (ASCII 'acsp') - */ - private static final int icMagicNumber = 0x61637370; - - /** - * Mapping from ICC Profile signatures to ColorSpace types - */ - private static final int[] csTypeMap = - { - ICC_Profile.icSigXYZData, - ColorSpace.TYPE_XYZ, - ICC_Profile.icSigLabData, - ColorSpace.TYPE_Lab, - ICC_Profile.icSigLuvData, - ColorSpace.TYPE_Luv, - ICC_Profile.icSigYCbCrData, - ColorSpace.TYPE_YCbCr, - ICC_Profile.icSigYxyData, - ColorSpace.TYPE_Yxy, - ICC_Profile.icSigRgbData, - ColorSpace.TYPE_RGB, - ICC_Profile.icSigGrayData, - ColorSpace.TYPE_GRAY, - ICC_Profile.icSigHsvData, - ColorSpace.TYPE_HSV, - ICC_Profile.icSigHlsData, - ColorSpace.TYPE_HLS, - ICC_Profile.icSigCmykData, - ColorSpace.TYPE_CMYK, - ICC_Profile.icSigCmyData, - ColorSpace.TYPE_CMY, - ICC_Profile.icSigSpace2CLR, - ColorSpace.TYPE_2CLR, - ICC_Profile.icSigSpace3CLR, - ColorSpace.TYPE_3CLR, - ICC_Profile.icSigSpace4CLR, - ColorSpace.TYPE_4CLR, - ICC_Profile.icSigSpace5CLR, - ColorSpace.TYPE_5CLR, - ICC_Profile.icSigSpace6CLR, - ColorSpace.TYPE_6CLR, - ICC_Profile.icSigSpace7CLR, - ColorSpace.TYPE_7CLR, - ICC_Profile.icSigSpace8CLR, - ColorSpace.TYPE_8CLR, - ICC_Profile.icSigSpace9CLR, - ColorSpace.TYPE_9CLR, - ICC_Profile.icSigSpaceACLR, - ColorSpace.TYPE_ACLR, - ICC_Profile.icSigSpaceBCLR, - ColorSpace.TYPE_BCLR, - ICC_Profile.icSigSpaceCCLR, - ColorSpace.TYPE_CCLR, - ICC_Profile.icSigSpaceDCLR, - ColorSpace.TYPE_DCLR, - ICC_Profile.icSigSpaceECLR, - ColorSpace.TYPE_ECLR, - ICC_Profile.icSigSpaceFCLR, - ColorSpace.TYPE_FCLR - }; - - /** - * Size of an ICC header (128 bytes) - */ - public static final int HEADERSIZE = 128; - - /** - * Mapping of ICC class signatures to profile class constants - */ - private static final int[] classMap = - { - ICC_Profile.icSigInputClass, - ICC_Profile.CLASS_INPUT, - ICC_Profile.icSigDisplayClass, - ICC_Profile.CLASS_DISPLAY, - ICC_Profile.icSigOutputClass, - ICC_Profile.CLASS_OUTPUT, - ICC_Profile.icSigLinkClass, - ICC_Profile.CLASS_DEVICELINK, - ICC_Profile.icSigColorSpaceClass, - ICC_Profile.CLASS_COLORSPACECONVERSION, - ICC_Profile.icSigAbstractClass, - ICC_Profile.CLASS_ABSTRACT, - ICC_Profile.icSigNamedColorClass, - ICC_Profile.CLASS_NAMEDCOLOR - }; - private int size; - private int cmmId; - - // Major/Minor version, The ICC-1998 spec is major v2 - private int majorVersion; - - // Major/Minor version, The ICC-1998 spec is major v2 - private int minorVersion; - private int profileClass; // profile device class - private int colorSpace; // data color space type - private int profileColorSpace; // profile connection space (PCS) type - private byte[] timestamp; // original creation timestamp - private int platform; // platform signature - private int flags; // flags - private int magic; // magic number. - private int manufacturerSig; // manufacturer sig - private int modelSig; // model sig - private byte[] attributes; // Attributes - private int intent; // rendering intent - private byte[] illuminant; // illuminant info (Coordinates of D50 in the PCS) - private int creatorSig; // Creator sig (same type as manufacturer) - - /** - * Creates a 'default' header for use with our predefined profiles. - * Note the device and profile color spaces are not set. - */ - public ProfileHeader() - { - creatorSig = 0; - intent = 0; - modelSig = manufacturerSig = (int) 0x6E6f6E65; // 'none' - magic = icMagicNumber; - cmmId = 0; - platform = 0; // no preferred platform - timestamp = new byte[8]; - majorVersion = 2; - minorVersion = 0x10; - flags = 0; - - // D50 in XYZ format (encoded) - illuminant = new byte[] - { - (byte) 0x00, (byte) 0x00, (byte) 0xf6, (byte) 0xd6, - (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0xd3, (byte) 0x2d - }; - attributes = new byte[8]; - profileClass = ICC_Profile.CLASS_DISPLAY; - } - - /** - * Creates a header from profile data. Only the header portion (128 bytes) - * is read, so the array passed need not be the full profile. - */ - public ProfileHeader(byte[] data) - { - ByteBuffer buf = ByteBuffer.wrap(data); - - // Get size (the sign bit shouldn't matter. - // A valid profile can never be +2Gb) - size = buf.getInt(ICC_Profile.icHdrSize); - - // CMM ID - cmmId = buf.getInt(ICC_Profile.icHdrCmmId); - - // Version number - majorVersion = (int) (data[ICC_Profile.icHdrVersion]); - minorVersion = (int) (data[ICC_Profile.icHdrVersion + 1]); - - // Profile/Device class - int classSig = buf.getInt(ICC_Profile.icHdrDeviceClass); - profileClass = -1; - for (int i = 0; i < classMap.length; i += 2) - if (classMap[i] == classSig) - { - profileClass = classMap[i + 1]; - break; - } - - // get the data color space - int csSig = buf.getInt(ICC_Profile.icHdrColorSpace); - colorSpace = -1; - for (int i = 0; i < csTypeMap.length; i += 2) - if (csTypeMap[i] == csSig) - { - colorSpace = csTypeMap[i + 1]; - break; - } - - // get the profile color space (PCS), must be xyz or lab except - // for device-link-class profiles - int pcsSig = buf.getInt(ICC_Profile.icHdrPcs); - profileColorSpace = -1; - if (profileClass != ICC_Profile.CLASS_DEVICELINK) - { - if (pcsSig == ICC_Profile.icSigXYZData) - profileColorSpace = ColorSpace.TYPE_XYZ; - if (pcsSig == ICC_Profile.icSigLabData) - profileColorSpace = ColorSpace.TYPE_Lab; - } - else - { - for (int i = 0; i < csTypeMap.length; i += 2) - if (csTypeMap[i] == pcsSig) - { - profileColorSpace = csTypeMap[i + 1]; - break; - } - } - - // creation timestamp - timestamp = new byte[8]; - System.arraycopy(data, ICC_Profile.icHdrDate, timestamp, 0, 8); - - // magic number - magic = buf.getInt(ICC_Profile.icHdrMagic); - - // platform info - platform = buf.getInt(ICC_Profile.icHdrPlatform); - // get flags - flags = buf.getInt(ICC_Profile.icHdrFlags); - // get manufacturer sign - manufacturerSig = buf.getInt(ICC_Profile.icHdrManufacturer); - // get header model - modelSig = buf.getInt(ICC_Profile.icHdrModel); - // attributes - attributes = new byte[8]; - System.arraycopy(data, ICC_Profile.icHdrAttributes, attributes, 0, 8); - // rendering intent - intent = buf.getInt(ICC_Profile.icHdrRenderingIntent); - // illuminant info - illuminant = new byte[12]; - System.arraycopy(data, ICC_Profile.icHdrIlluminant, illuminant, 0, 12); - // Creator signature - creatorSig = buf.getInt(ICC_Profile.icHdrCreator); - // The rest of the header (Total size: 128 bytes) is unused.. - } - - /** - * Verify that the header is valid - * @param size equals the file size if it is to be verified, -1 otherwise - * @throws IllegalArgumentException if the header is found to be invalid. - */ - public void verifyHeader(int size) throws IllegalArgumentException - { - // verify size - if (size != -1 && this.size != size) - throw new IllegalArgumentException("Invalid profile length:" + size); - - // Check version number - if (majorVersion != 2) - throw new IllegalArgumentException("Wrong major version number:" - + majorVersion); - - // Profile/Device class - if (profileClass == -1) - throw new IllegalArgumentException("Invalid profile/device class"); - - // get the data color space - if (colorSpace == -1) - throw new IllegalArgumentException("Invalid colorspace"); - - // profile color space - if (profileColorSpace == -1) - throw new IllegalArgumentException("Invalid PCS."); - - // check magic number - if (magic != icMagicNumber) - throw new IllegalArgumentException("Invalid magic number!"); - } - - /** - * Creates a header, setting the header file size at the same time. - * @param size the profile file size. - */ - public byte[] getData(int size) - { - byte[] data = new byte[HEADERSIZE]; - ByteBuffer buf = ByteBuffer.wrap(data); - buf.putInt(ICC_Profile.icHdrSize, size); - buf.putInt(ICC_Profile.icHdrCmmId, cmmId); - buf.putShort(ICC_Profile.icHdrVersion, - (short) (majorVersion << 8 | minorVersion)); - for (int i = 1; i < classMap.length; i += 2) - if (profileClass == classMap[i]) - buf.putInt(ICC_Profile.icHdrDeviceClass, classMap[i - 1]); - for (int i = 1; i < csTypeMap.length; i += 2) - if (csTypeMap[i] == colorSpace) - buf.putInt(ICC_Profile.icHdrColorSpace, csTypeMap[i - 1]); - for (int i = 1; i < csTypeMap.length; i += 2) - if (csTypeMap[i] == profileColorSpace) - buf.putInt(ICC_Profile.icHdrPcs, csTypeMap[i - 1]); - - System.arraycopy(timestamp, 0, data, ICC_Profile.icHdrDate, - timestamp.length); - buf.putInt(ICC_Profile.icHdrMagic, icMagicNumber); - buf.putInt(ICC_Profile.icHdrPlatform, platform); - buf.putInt(ICC_Profile.icHdrFlags, flags); - buf.putInt(ICC_Profile.icHdrManufacturer, manufacturerSig); - buf.putInt(ICC_Profile.icHdrModel, modelSig); - System.arraycopy(attributes, 0, data, ICC_Profile.icHdrAttributes, - attributes.length); - buf.putInt(ICC_Profile.icHdrRenderingIntent, intent); - System.arraycopy(illuminant, 0, data, ICC_Profile.icHdrIlluminant, - illuminant.length); - buf.putInt(ICC_Profile.icHdrCreator, creatorSig); - return buf.array(); - } - - public int getSize() - { - return size; - } - - public void setSize(int s) - { - size = s; - } - - public int getMajorVersion() - { - return majorVersion; - } - - public int getMinorVersion() - { - return minorVersion; - } - - public int getProfileClass() - { - return profileClass; - } - - public void setProfileClass(int pc) - { - profileClass = pc; - } - - public int getColorSpace() - { - return colorSpace; - } - - public int getProfileColorSpace() - { - return profileColorSpace; - } - - public void setColorSpace(int cs) - { - colorSpace = cs; - } - - public void setProfileColorSpace(int pcs) - { - profileColorSpace = pcs; - } - -} diff --git a/libjava/gnu/java/awt/color/PyccConverter.java b/libjava/gnu/java/awt/color/PyccConverter.java deleted file mode 100644 index cd50d8776cd..00000000000 --- a/libjava/gnu/java/awt/color/PyccConverter.java +++ /dev/null @@ -1,72 +0,0 @@ -/* PyccConverter.java -- PhotoYCC conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * PyccConverter - conversion routines for the PhotoYCC colorspace - * - * Also known as PhotoCD YCC, it is an expansion of the conventional - * YCC color space to also include colors with over 100% white. - * - * XXX FIXME: Not yet implemented, implementation pending. - * - * @author Sven de Marothy - */ -public class PyccConverter implements ColorSpaceConverter -{ - public float[] toRGB(float[] in) - { - return null; - } - - public float[] fromRGB(float[] in) - { - return null; - } - - public float[] toCIEXYZ(float[] in) - { - return null; - } - - public float[] fromCIEXYZ(float[] in) - { - return null; - } -} diff --git a/libjava/gnu/java/awt/color/RgbProfileConverter.java b/libjava/gnu/java/awt/color/RgbProfileConverter.java deleted file mode 100644 index 0cbd28f6cca..00000000000 --- a/libjava/gnu/java/awt/color/RgbProfileConverter.java +++ /dev/null @@ -1,244 +0,0 @@ -/* RgbProfileConverter.java -- RGB Profile conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.color; - -import java.awt.color.ICC_Profile; -import java.awt.color.ICC_ProfileRGB; -import java.awt.color.ProfileDataException; - -/** - * RgbProfileConverter - converts RGB profiles (ICC_ProfileRGB) - * - * This type of profile contains a matrix and three - * tone reproduction curves (TRCs). - * - * Device RGB --> CIE XYZ is done through first multiplying with - * a matrix, then each component is looked-up against it's TRC. - * - * The opposite transform is done using the inverse of the matrix, - * and TRC:s. - * - * @author Sven de Marothy - */ -public class RgbProfileConverter implements ColorSpaceConverter -{ - private float[][] matrix; - private float[][] inv_matrix; - private ToneReproductionCurve rTRC; - private ToneReproductionCurve gTRC; - private ToneReproductionCurve bTRC; - private ColorLookUpTable toPCS; - private ColorLookUpTable fromPCS; - - /** - * CIE 1931 D50 white point (in Lab coordinates) - */ - private static float[] D50 = { 0.96422f, 1.00f, 0.82521f }; - - /** - * Constructs an RgbProfileConverter from a given ICC_ProfileRGB - */ - public RgbProfileConverter(ICC_ProfileRGB profile) - { - toPCS = fromPCS = null; - matrix = profile.getMatrix(); - - // get TRCs - try - { - rTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.REDCOMPONENT)); - } - catch (ProfileDataException e) - { - rTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.REDCOMPONENT)); - } - try - { - gTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.GREENCOMPONENT)); - } - catch (ProfileDataException e) - { - gTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.GREENCOMPONENT)); - } - try - { - bTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.BLUECOMPONENT)); - } - catch (ProfileDataException e) - { - bTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.BLUECOMPONENT)); - } - - // If a CLUT is available, it should be used, and the TRCs ignored. - // Note: A valid profile may only have CLUTs in one direction, and - // TRC:s without useful info, making reverse-transforms impossible. - // In this case the TRC will be used for the reverse-transform with - // unpredictable results. This is in line with the Java specification, - try - { - toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag); - } - catch (Exception e) - { - toPCS = null; - } - - try - { - fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag); - } - catch (Exception e) - { - fromPCS = null; - } - - // Calculate the inverse matrix if no reverse CLUT is available - if(fromPCS == null) - inv_matrix = invertMatrix(matrix); - else - { - // otherwise just set it to an identity matrix - inv_matrix = new float[3][3]; - inv_matrix[0][0] = inv_matrix[1][1] = inv_matrix[2][2] = 1.0f; - } - } - - public float[] toCIEXYZ(float[] in) - { - // CLUT takes precedence - if (toPCS != null) - return toPCS.lookup(in); - - float[] temp = new float[3]; - float[] out = new float[3]; - - // device space --> linear gamma - temp[0] = rTRC.lookup(in[0]); - temp[1] = gTRC.lookup(in[1]); - temp[2] = bTRC.lookup(in[2]); - - // matrix multiplication - out[0] = matrix[0][0] * temp[0] + matrix[0][1] * temp[1] - + matrix[0][2] * temp[2]; - out[1] = matrix[1][0] * temp[0] + matrix[1][1] * temp[1] - + matrix[1][2] * temp[2]; - out[2] = matrix[2][0] * temp[0] + matrix[2][1] * temp[1] - + matrix[2][2] * temp[2]; - - return out; - } - - public float[] toRGB(float[] in) - { - return SrgbConverter.XYZtoRGB(toCIEXYZ(in)); - } - - public float[] fromCIEXYZ(float[] in) - { - if (fromPCS != null) - return fromPCS.lookup(in); - - float[] temp = new float[3]; - float[] out = new float[3]; - - // matrix multiplication - temp[0] = inv_matrix[0][0] * in[0] + inv_matrix[0][1] * in[1] - + inv_matrix[0][2] * in[2]; - temp[1] = inv_matrix[1][0] * in[0] + inv_matrix[1][1] * in[1] - + inv_matrix[1][2] * in[2]; - temp[2] = inv_matrix[2][0] * in[0] + inv_matrix[2][1] * in[1] - + inv_matrix[2][2] * in[2]; - - // device space --> linear gamma - out[0] = rTRC.reverseLookup(temp[0]); - out[1] = gTRC.reverseLookup(temp[1]); - out[2] = bTRC.reverseLookup(temp[2]); - - // FIXME: Sun appears to clip the return values to [0,1] - // I don't believe that is a Good Thing, - // (some colorspaces may allow values outside that range.) - // So we return the actual values here. - return out; - } - - public float[] fromRGB(float[] in) - { - return fromCIEXYZ(SrgbConverter.RGBtoXYZ(in)); - } - - /** - * Inverts a 3x3 matrix, returns the inverse, - * throws an IllegalArgumentException if the matrix is not - * invertible (this shouldn't happen for a valid profile) - */ - private float[][] invertMatrix(float[][] matrix) - { - float[][] out = new float[3][3]; - double determinant = matrix[0][0] * (matrix[1][1] * matrix[2][2] - - matrix[2][1] * matrix[1][2]) - - matrix[0][1] * (matrix[1][0] * matrix[2][2] - - matrix[2][0] * matrix[1][2]) - + matrix[0][2] * (matrix[1][0] * matrix[2][1] - - matrix[2][0] * matrix[1][1]); - - if (determinant == 0.0) - throw new IllegalArgumentException("Can't invert conversion matrix."); - float invdet = (float) (1.0 / determinant); - - out[0][0] = invdet * (matrix[1][1] * matrix[2][2] - - matrix[1][2] * matrix[2][1]); - out[0][1] = invdet * (matrix[0][2] * matrix[2][1] - - matrix[0][1] * matrix[2][2]); - out[0][2] = invdet * (matrix[0][1] * matrix[1][2] - - matrix[0][2] * matrix[1][1]); - out[1][0] = invdet * (matrix[1][2] * matrix[2][0] - - matrix[1][0] * matrix[2][2]); - out[1][1] = invdet * (matrix[0][0] * matrix[2][2] - - matrix[0][2] * matrix[2][0]); - out[1][2] = invdet * (matrix[0][2] * matrix[1][0] - - matrix[0][0] * matrix[1][2]); - out[2][0] = invdet * (matrix[1][0] * matrix[2][1] - - matrix[1][1] * matrix[2][0]); - out[2][1] = invdet * (matrix[0][1] * matrix[2][0] - - matrix[0][0] * matrix[2][1]); - out[2][2] = invdet * (matrix[0][0] * matrix[1][1] - - matrix[0][1] * matrix[1][0]); - return out; - } -} diff --git a/libjava/gnu/java/awt/color/SrgbConverter.java b/libjava/gnu/java/awt/color/SrgbConverter.java deleted file mode 100644 index a30a0db906c..00000000000 --- a/libjava/gnu/java/awt/color/SrgbConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* SrgbConverter.java -- sRGB conversion class - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * SrgbConverter - conversion routines for the sRGB colorspace - * sRGB is a standard for RGB colorspaces, adopted by the w3c. - * - * The specification is available at: - * http://www.w3.org/Graphics/Color/sRGB.html - * - * @author Sven de Marothy - */ -/** - * - * Note the matrix numbers used here are NOT identical to those in the - * w3 spec, as those numbers are CIE XYZ relative a D65 white point. - * The CIE XYZ we use is relative a D50 white point, so therefore a - * linear Bradford transform matrix for D65->D50 mapping has been applied. - * (The ICC documents describe this transform) - * - * Linearized Bradford transform: - * 0.8951 0.2664 -0.1614 - * -0.7502 1.7135 0.0367 - * 0.0389 -0.0685 1.0296 - * - * Inverse: - * 0.9870 -0.1471 0.1600 - * 0.4323 0.5184 0.0493 - * -0.00853 0.0400 0.9685 - */ -public class SrgbConverter implements ColorSpaceConverter -{ - public float[] fromCIEXYZ(float[] in) - { - return XYZtoRGB(in); - } - - public float[] toCIEXYZ(float[] in) - { - return RGBtoXYZ(in); - } - - public float[] toRGB(float[] in) - { - float[] out = new float[3]; - System.arraycopy(in, 0, out, 0, 3); - return out; - } - - public float[] fromRGB(float[] in) - { - float[] out = new float[3]; - System.arraycopy(in, 0, out, 0, 3); - return out; - } - - /** - * CIE XYZ (D50 relative) --> sRGB - * - * Static as it's used by other ColorSpaceConverters to - * convert to sRGB if the color space is defined in XYZ. - */ - public static float[] XYZtoRGB(float[] in) - { - float[] temp = new float[3]; - temp[0] = 3.1338f * in[0] - 1.6171f * in[1] - 0.4907f * in[2]; - temp[1] = -0.9785f * in[0] + 1.9160f * in[1] + 0.0334f * in[2]; - temp[2] = 0.0720f * in[0] - 0.2290f * in[1] + 1.4056f * in[2]; - - float[] out = new float[3]; - for (int i = 0; i < 3; i++) - { - if (temp[i] < 0) - temp[i] = 0.0f; - if (temp[i] > 1) - temp[i] = 1.0f; - if (temp[i] <= 0.00304f) - out[i] = temp[i] * 12.92f; - else - out[i] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(temp[i]))) - - 0.055f; - } - return out; - } - - /** - * sRGB --> CIE XYZ (D50 relative) - * - * Static as it's used by other ColorSpaceConverters to - * convert to XYZ if the color space is defined in RGB. - */ - public static float[] RGBtoXYZ(float[] in) - { - float[] temp = new float[3]; - float[] out = new float[3]; - for (int i = 0; i < 3; i++) - if (in[i] <= 0.03928f) - temp[i] = in[i] / 12.92f; - else - temp[i] = (float) Math.exp(2.4 * Math.log((in[i] + 0.055) / 1.055)); - - /* - * Note: The numbers which were used to calculate this only had four - * digits of accuracy. So don't be fooled by the number of digits here. - * If someone has more accurate source, feel free to update this. - */ - out[0] = (float) (0.436063750222 * temp[0] + 0.385149601465 * temp[1] - + 0.143086418888 * temp[2]); - out[1] = (float) (0.222450894035 * temp[0] + 0.71692584775 * temp[1] - + 0.060624511256 * temp[2]); - out[2] = (float) (0.0138985186 * temp[0] + 0.097079690112 * temp[1] - + 0.713996045725 * temp[2]); - return out; - } -} diff --git a/libjava/gnu/java/awt/color/TagEntry.java b/libjava/gnu/java/awt/color/TagEntry.java deleted file mode 100644 index a9786468384..00000000000 --- a/libjava/gnu/java/awt/color/TagEntry.java +++ /dev/null @@ -1,121 +0,0 @@ -/* TagEntry.java -- A utility class used for storing the tags in ICC_Profile - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * TagEntry - stores a profile tag. - * These are conveniently stored in a hashtable with the tag signature - * as a key. A legal profile can only have one tag with a given sig, - * so we can conveniently ignore collisions. - * - * @author Sven de Marothy - */ -public class TagEntry -{ - // tag table entry size - public static final int entrySize = 12; - private int signature; - private int size; - private int offset; - private byte[] data; - - public TagEntry(int sig, int offset, int size, byte[] data) - { - this.signature = sig; - this.offset = offset; - this.size = size; - this.data = new byte[size]; - System.arraycopy(data, offset, this.data, 0, size); - } - - public TagEntry(int sig, byte[] data) - { - this.signature = sig; - this.size = data.length; - this.data = new byte[size]; - System.arraycopy(data, offset, this.data, 0, size); - } - - public byte[] getData() - { - byte[] d = new byte[size]; - System.arraycopy(this.data, 0, d, 0, size); - return d; - } - - public String hashKey() - { - return tagHashKey(signature); - } - - public String toString() - { - String s = ""; - s = s + (char) ((byte) ((signature >> 24) & 0xFF)); - s = s + (char) ((byte) ((signature >> 16) & 0xFF)); - s = s + (char) ((byte) ((signature >> 8) & 0xFF)); - s = s + (char) ((byte) (signature & 0xFF)); - return s; - } - - public int getSignature() - { - return signature; - } - - public int getSize() - { - return size; - } - - public int getOffset() - { - return offset; - } - - public void setOffset(int offset) - { - this.offset = offset; - } - - public static String tagHashKey(int sig) - { - return "" + sig; - } -} diff --git a/libjava/gnu/java/awt/color/ToneReproductionCurve.java b/libjava/gnu/java/awt/color/ToneReproductionCurve.java deleted file mode 100644 index a1bccbd4068..00000000000 --- a/libjava/gnu/java/awt/color/ToneReproductionCurve.java +++ /dev/null @@ -1,177 +0,0 @@ -/* ToneReproductionCurve.java -- Representation of an ICC 'curv' type TRC - Copyright (C) 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.color; - - -/** - * ToneReproductionCurve - TRCs are used to describe RGB - * and Grayscale profiles. The TRC is essentially the gamma - * function of the color space. - * - * For example, Apple RGB has a gamma of 1.8, most monitors are ~2.2, - * sRGB is 2.4 with a small linear part near 0. - * Linear spaces are of course 1.0. - * (The exact function is implemented in SrgbConverter) - * - * The ICC specification allows the TRC to be described as a single - * Gamma value, where the function is thus out = in**gamma. - * Alternatively, the gamma function may be represented by a lookup table - * of values, in which case linear interpolation is used. - * - * @author Sven de Marothy - */ -public class ToneReproductionCurve -{ - private float[] trc; - private float gamma; - private float[] reverseTrc; - - /** - * Constructs a TRC from a gamma values - */ - public ToneReproductionCurve(float gamma) - { - trc = null; - reverseTrc = null; - this.gamma = gamma; - } - - /** - * Constructs a TRC from a set of float values - */ - public ToneReproductionCurve(float[] trcValues) - { - trc = new float[trcValues.length]; - System.arraycopy(trcValues, 0, trc, 0, trcValues.length); - setupReverseTrc(); - } - - /** - * Constructs a TRC from a set of short values normalized to - * the 0-65535 range (as in the ICC profile file). - * (Note the values are treated as unsigned) - */ - public ToneReproductionCurve(short[] trcValues) - { - trc = new float[trcValues.length]; - for (int i = 0; i < trcValues.length; i++) - trc[i] = (float) ((int) trcValues[i] & (0xFFFF)) / 65535.0f; - setupReverseTrc(); - } - - /** - * Performs a TRC lookup - */ - public float lookup(float in) - { - float out; - - if (trc == null) - { - if (in == 0f) - return 0.0f; - return (float) Math.exp(gamma * Math.log(in)); - } - else - { - double alpha = in * (trc.length - 1); - int index = (int) Math.floor(alpha); - alpha = alpha - (double) index; - if (index >= trc.length - 1) - return trc[trc.length - 1]; - if (index <= 0) - return trc[0]; - out = (float) (trc[index] * (1.0 - alpha) + trc[index + 1] * alpha); - } - return out; - } - - /** - * Performs an reverse lookup - */ - public float reverseLookup(float in) - { - float out; - - if (trc == null) - { - if (in == 0f) - return 0.0f; - return (float) Math.exp((1.0 / gamma) * Math.log(in)); - } - else - { - double alpha = in * (reverseTrc.length - 1); - int index = (int) Math.floor(alpha); - alpha = alpha - (double) index; - if (index >= reverseTrc.length - 1) - return reverseTrc[reverseTrc.length - 1]; - if (index <= 0) - return reverseTrc[0]; - out = (float) (reverseTrc[index] * (1.0 - alpha) - + reverseTrc[index + 1] * alpha); - } - return out; - } - - /** - * Calculates a reverse-lookup table. - * We use a whopping 10,000 entries.. This is should be more than any - * real-life TRC table (typically around 256-1024) so we won't be losing - * any precision. - * - * This will of course generate completely invalid results if the curve - * is not monotonic and invertable. But what's the alternative? - */ - public void setupReverseTrc() - { - reverseTrc = new float[10000]; - int j = 0; - for (int i = 0; i < 10000; i++) - { - float n = ((float) i) / 10000f; - while (trc[j + 1] < n && j < trc.length - 2) - j++; - - if (j == trc.length - 2) - reverseTrc[i] = trc[trc.length - 1]; - else - reverseTrc[i] = (j + (n - trc[j]) / (trc[j + 1] - trc[j])) / ((float) trc.length); - } - } -} diff --git a/libjava/gnu/java/awt/doc-files/BitwiseXORComposite-1.png b/libjava/gnu/java/awt/doc-files/BitwiseXORComposite-1.png Binary files differdeleted file mode 100644 index 588c910dd75..00000000000 --- a/libjava/gnu/java/awt/doc-files/BitwiseXORComposite-1.png +++ /dev/null diff --git a/libjava/gnu/java/awt/image/ImageDecoder.java b/libjava/gnu/java/awt/image/ImageDecoder.java deleted file mode 100644 index 141c8541794..00000000000 --- a/libjava/gnu/java/awt/image/ImageDecoder.java +++ /dev/null @@ -1,156 +0,0 @@ -/* ImageDecoder.java -- - Copyright (C) 1999, 2000, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.image; - -import java.awt.image.ImageConsumer; -import java.awt.image.ImageProducer; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Vector; - -public abstract class ImageDecoder implements ImageProducer -{ - Vector consumers = new Vector (); - String filename; - URL url; - byte[] data; - int offset; - int length; - InputStream input; - - static - { - // FIXME: there was some broken code here that looked like - // it wanted to rely on this property. I don't have any idea - // what it was intended to do. - // String endian = System.getProperties ().getProperty ("gnu.cpu.endian"); - } - - public ImageDecoder (String filename) - { - this.filename = filename; - } - - public ImageDecoder (URL url) - { - this.url = url; - } - - public ImageDecoder (InputStream is) - { - this.input = is; - } - - public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength) - { - data = imagedata; - offset = imageoffset; - length = imagelength; - } - - public void addConsumer (ImageConsumer ic) - { - consumers.addElement (ic); - } - - public boolean isConsumer (ImageConsumer ic) - { - return consumers.contains (ic); - } - - public void removeConsumer (ImageConsumer ic) - { - consumers.removeElement (ic); - } - - public void startProduction (ImageConsumer ic) - { - if (!isConsumer(ic)) - addConsumer(ic); - - Vector list = (Vector) consumers.clone (); - try - { - // Create the input stream here rather than in the - // ImageDecoder constructors so that exceptions cause - // imageComplete to be called with an appropriate error - // status. - if (input == null) - { - try - { - if (url != null) - input = url.openStream(); - else - { - if (filename != null) - input = new FileInputStream (filename); - else - input = new ByteArrayInputStream (data, offset, length); - } - produce (list, input); - } - finally - { - input = null; - } - } - else - { - produce (list, input); - } - } - catch (Exception e) - { - for (int i = 0; i < list.size (); i++) - { - ImageConsumer ic2 = (ImageConsumer) list.elementAt (i); - ic2.imageComplete (ImageConsumer.IMAGEERROR); - } - } - } - - public void requestTopDownLeftRightResend (ImageConsumer ic) - { - } - - public abstract void produce (Vector v, InputStream is) throws IOException; -} diff --git a/libjava/gnu/java/awt/image/XBMDecoder.java b/libjava/gnu/java/awt/image/XBMDecoder.java deleted file mode 100644 index 0793d8ee749..00000000000 --- a/libjava/gnu/java/awt/image/XBMDecoder.java +++ /dev/null @@ -1,155 +0,0 @@ -/* XBMDecoder.java -- Decodes X-bitmaps - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.image; - -import java.awt.image.ColorModel; -import java.awt.image.ImageConsumer; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.util.StringTokenizer; -import java.util.Vector; - -public class XBMDecoder extends ImageDecoder -{ - BufferedReader reader; - static final ColorModel cm = ColorModel.getRGBdefault (); - static final int black = 0xff000000; - static final int transparent = 0x00000000; - static final int masktable[] = { 0x01, 0x02, 0x04, 0x08, - 0x10, 0x20, 0x40, 0x80 }; - - public XBMDecoder (String filename) - { - super (filename); - } - - public XBMDecoder (URL url) - { - super (url); - } - - public void produce (Vector v, InputStream is) throws IOException - { - reader = new BufferedReader (new InputStreamReader (is)); - int width = -1, height = -1; - - for (int i = 0; i < 2; i++) - { - String line = reader.readLine (); - StringTokenizer st = new StringTokenizer (line); - - st.nextToken (); // #define - st.nextToken (); // name_[width|height] - if (i == 0) - width = Integer.parseInt (st.nextToken (), 10); - else - height = Integer.parseInt (st.nextToken (), 10); - } - - for (int i = 0; i < v.size (); i++) - { - ImageConsumer ic = (ImageConsumer) v.elementAt (i); - - ic.setDimensions (width, height); - ic.setColorModel (cm); - ic.setHints (ImageConsumer.COMPLETESCANLINES - | ImageConsumer.SINGLEFRAME - | ImageConsumer.SINGLEPASS - | ImageConsumer.TOPDOWNLEFTRIGHT); - } - - /* skip to the byte array */ - while (reader.read () != '{') { } - - /* loop through each scanline */ - for (int line = 0; line < height; line++) - { - int scanline[] = getScanline (reader, width); - - for (int i = 0; i < v.size (); i++) - { - ImageConsumer ic = (ImageConsumer) v.elementAt (i); - ic.setPixels (0, 0 + line, width, 1, cm, scanline, 0, width); - } - } - - /* tell each ImageConsumer that we're finished */ - for (int i = 0; i < v.size (); i++) - { - ImageConsumer ic = (ImageConsumer) v.elementAt (i); - ic.imageComplete (ImageConsumer.STATICIMAGEDONE); - } - } - - public static int[] getScanline (Reader in, int len) throws IOException - { - char byteStr[] = new char[2]; - int scanline[] = new int[len]; - int x = 0; - - while (x < len) - { - int ch = in.read (); - if (ch == '0') - { - in.read (); // 'x' - - byteStr[0] = (char) in.read (); - byteStr[1] = (char) in.read (); - - int byteVal = Integer.parseInt (new String (byteStr), 16); - - for (int i = 0; i < 8; i++, x++) - { - if (x == len) // condition occurs if bitmap is padded - return scanline; - - scanline[x] = ((byteVal & masktable[i]) != 0) ? - black : transparent; - } - } - } - - return scanline; - } -} diff --git a/libjava/gnu/java/awt/peer/ClasspathFontPeer.java b/libjava/gnu/java/awt/peer/ClasspathFontPeer.java deleted file mode 100644 index 78ab3a9de21..00000000000 --- a/libjava/gnu/java/awt/peer/ClasspathFontPeer.java +++ /dev/null @@ -1,846 +0,0 @@ -/* ClasspathFontPeer.java -- Font peer used by GNU Classpath. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer; - -import gnu.java.awt.ClasspathToolkit; - -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Toolkit; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.font.LineMetrics; -import java.awt.font.TextAttribute; -import java.awt.font.TransformAttribute; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; -import java.awt.peer.FontPeer; -import java.text.AttributedCharacterIterator; -import java.text.CharacterIterator; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -/** - * A peer for fonts that are used inside Classpath. The purpose of - * this interface is to abstract from platform-specific font handling - * in the Classpath implementation of java.awt.Font and related - * classes. - * - * <p><b>State kept by the peer:</b> a peer is generated for each Font - * object in the default implementation. If you wish to share peers between - * fonts, you will need to subclass both ClasspathFontPeer and - * {@link ClasspathToolKit}.</p> - * - * <p><b>Thread Safety:</b> Methods of this interface may be called - * from arbitrary threads at any time. Implementations of the - * <code>ClasspathFontPeer</code> interface are required to perform - * the necessary synchronization.</p> - * - * @see java.awt.Font#getPeer - * @see java.awt.Toolkit#getFontPeer - * - * @author Sascha Brawer (brawer@dandelis.ch) - * @author Graydon Hoare (graydon@redhat.com) - */ -public abstract class ClasspathFontPeer - implements FontPeer -{ - - /*************************************************************************/ - - /* - * Instance Variables - */ - - /** - * The 3 names of this font. all fonts have 3 names, some of which - * may be equal: - * - * logical -- name the font was constructed from - * family -- a designer or brand name (Helvetica) - * face -- specific instance of a design (Helvetica Regular) - * - * @see isLogicalFontName - */ - - protected String logicalName; - protected String familyName; - protected String faceName; - - /** - * The font style, which is a combination (by OR-ing) of the font style - * constants PLAIN, BOLD and ITALIC, in this class. - */ - protected int style; - - /** - * The font point size. A point is 1/72 of an inch. - */ - protected float size; - - /** - * The affine transformation the font is currently subject to. - */ - protected AffineTransform transform; - - protected static ClasspathToolkit tk() - { - return (ClasspathToolkit)(Toolkit.getDefaultToolkit ()); - } - - /* - * Confusingly, a Logical Font is a concept unrelated to - * a Font's Logical Name. - * - * A Logical Font is one of 6 built-in, abstract font types - * which must be supported by any java environment: SansSerif, - * Serif, Monospaced, Dialog, and DialogInput. - * - * A Font's Logical Name is the name the font was constructed - * from. This might be the name of a Logical Font, or it might - * be the name of a Font Face. - */ - - protected static boolean isLogicalFontName(String name) - { - String uname = name.toUpperCase (); - return (uname.equals ("SANSSERIF") || - uname.equals ("SERIF") || - uname.equals ("MONOSPACED") || - uname.equals ("DIALOG") || - uname.equals ("DIALOGINPUT")); - } - - protected static String logicalFontNameToFaceName (String name) - { - String uname = name.toUpperCase (); - if (uname.equals("SANSSERIF")) - return "Helvetica"; - else if (uname.equals ("SERIF")) - return "Times"; - else if (uname.equals ("MONOSPACED")) - return "Courier"; - else if (uname.equals ("DIALOG")) - return "Helvetica"; - else if (uname.equals ("DIALOGINPUT")) - return "Helvetica"; - else - return "Helvetica"; - } - - protected static String faceNameToFamilyName (String name) - { - return name; - } - - public static void copyStyleToAttrs (int style, Map attrs) - { - if ((style & Font.BOLD) == Font.BOLD) - attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); - else - attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR); - - if ((style & Font.ITALIC) == Font.ITALIC) - attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); - else - attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); - } - - protected static void copyFamilyToAttrs (String fam, Map attrs) - { - if (fam != null) - attrs.put (TextAttribute.FAMILY, fam); - } - - public static void copySizeToAttrs (float size, Map attrs) - { - attrs.put (TextAttribute.SIZE, new Float (size)); - } - - protected static void copyTransformToAttrs (AffineTransform trans, Map attrs) - { - if (trans != null) - attrs.put(TextAttribute.TRANSFORM, new TransformAttribute (trans)); - } - - - protected void setStandardAttributes (String name, String family, int style, - float size, AffineTransform trans) - { - this.logicalName = name; - - if (isLogicalFontName (name)) - this.faceName = logicalFontNameToFaceName (name); - else - this.faceName = name; - - if (family != null) - this.familyName = family; - else - this.familyName = faceNameToFamilyName (faceName); - - this.style = style; - this.size = size; - this.transform = trans; - } - - - protected void setStandardAttributes (String name, Map attribs) - { - String family = this.familyName; - AffineTransform trans = this.transform; - float size = this.size; - int style = this.style; - - if (attribs.containsKey (TextAttribute.FAMILY)) - family = (String) attribs.get (TextAttribute.FAMILY); - - if (name == null) - name = "SansSerif"; - - if (attribs.containsKey (TextAttribute.WEIGHT)) - { - Float weight = (Float) attribs.get (TextAttribute.WEIGHT); - if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ()) - style += Font.BOLD; - } - - if (attribs.containsKey (TextAttribute.POSTURE)) - { - Float posture = (Float) attribs.get (TextAttribute.POSTURE); - if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ()) - style += Font.ITALIC; - } - - if (attribs.containsKey (TextAttribute.SIZE)) - { - Float sz = (Float) attribs.get (TextAttribute.SIZE); - size = sz.floatValue (); - - // Pango doesn't accept 0 as a font size. - if (size < 1) - size = 1; - } - else - size = 12; - - if (attribs.containsKey (TextAttribute.TRANSFORM)) - { - TransformAttribute ta = (TransformAttribute) - attribs.get(TextAttribute.TRANSFORM); - trans = ta.getTransform (); - } - - setStandardAttributes (name, family, style, size, trans); - } - - protected void getStandardAttributes (Map attrs) - { - copyFamilyToAttrs (this.familyName, attrs); - copySizeToAttrs (this.size, attrs); - copyStyleToAttrs (this.style, attrs); - copyTransformToAttrs (this.transform, attrs); - } - - - /* Begin public API */ - - public ClasspathFontPeer (String name, Map attrs) - { - setStandardAttributes (name, attrs); - } - - public ClasspathFontPeer (String name, int style, int size) - { - setStandardAttributes (name, (String)null, style, - (float)size, (AffineTransform)null); - } - - /** - * Implementation of {@link Font#getName} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public String getName (Font font) - { - return logicalName; - } - - /** - * Implementation of {@link Font#getFamily()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public String getFamily (Font font) - { - return familyName; - } - - /** - * Implementation of {@link Font#getFamily(Locale)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public String getFamily (Font font, Locale lc) - { - return familyName; - } - - /** - * Implementation of {@link Font#getFontName()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public String getFontName (Font font) - { - return faceName; - } - - /** - * Implementation of {@link Font#getFontName(Locale)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public String getFontName (Font font, Locale lc) - { - return faceName; - } - - /** - * Implementation of {@link Font#getSize} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public float getSize (Font font) - { - return size; - } - - /** - * Implementation of {@link Font#isPlain} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public boolean isPlain (Font font) - { - return style == Font.PLAIN; - } - - /** - * Implementation of {@link Font#isBold} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public boolean isBold (Font font) - { - return ((style & Font.BOLD) == Font.BOLD); - } - - /** - * Implementation of {@link Font#isItalic} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public boolean isItalic (Font font) - { - return ((style & Font.ITALIC) == Font.ITALIC); - } - - /** - * Implementation of {@link Font#deriveFont(int, float)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, int style, float size) - { - Map attrs = new HashMap (); - getStandardAttributes (attrs); - copyStyleToAttrs (style, attrs); - copySizeToAttrs (size, attrs); - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#deriveFont(float)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, float size) - { - Map attrs = new HashMap (); - getStandardAttributes (attrs); - copySizeToAttrs (size, attrs); - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#deriveFont(int)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, int style) - { - Map attrs = new HashMap (); - getStandardAttributes (attrs); - copyStyleToAttrs (style, attrs); - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#deriveFont(int, AffineTransform)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, int style, AffineTransform t) - { - Map attrs = new HashMap (); - getStandardAttributes (attrs); - copyStyleToAttrs (style, attrs); - copyTransformToAttrs (t, attrs); - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#deriveFont(AffineTransform)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, AffineTransform t) - { - Map attrs = new HashMap (); - getStandardAttributes (attrs); - copyTransformToAttrs (t, attrs); - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#deriveFont(Map)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Font deriveFont (Font font, Map attrs) - { - return tk().getFont (logicalName, attrs); - } - - /** - * Implementation of {@link Font#getAttributes()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public Map getAttributes (Font font) - { - HashMap h = new HashMap (); - getStandardAttributes (h); - return h; - } - - /** - * Implementation of {@link Font#getAvailableAttributes()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public AttributedCharacterIterator.Attribute[] getAvailableAttributes(Font font) - { - AttributedCharacterIterator.Attribute a[] = - new AttributedCharacterIterator.Attribute[5]; - a[0] = TextAttribute.FAMILY; - a[1] = TextAttribute.SIZE; - a[2] = TextAttribute.POSTURE; - a[3] = TextAttribute.WEIGHT; - a[4] = TextAttribute.TRANSFORM; - return a; - } - - /** - * Implementation of {@link Font#getTransform()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public AffineTransform getTransform (Font font) - { - if (transform == null) - transform = new AffineTransform (); - return transform; - } - - /** - * Implementation of {@link Font#isTransformed()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public boolean isTransformed (Font font) - { - return ! transform.isIdentity (); - } - - /** - * Implementation of {@link Font#getItalicAngle()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public float getItalicAngle (Font font) - { - if ((style & Font.ITALIC) == Font.ITALIC) - return TextAttribute.POSTURE_OBLIQUE.floatValue (); - else - return TextAttribute.POSTURE_REGULAR.floatValue (); - } - - - /** - * Implementation of {@link Font#getStyle()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public int getStyle (Font font) - { - return style; - } - - - - - /* Remaining methods are abstract */ - - /** - * Implementation of {@link Font#canDisplay(char)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract boolean canDisplay (Font font, char c); - - /** - * Implementation of {@link Font#canDisplay(String)}, - * {@link Font#canDisplay(char [], int, int)}, and - * {@link Font#canDisplay(CharacterIterator, int, int)}. - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit); - - - /** - * Returns the name of this font face inside the family, for example - * <i>“Light”</i>. - * - * <p>This method is currently not used by {@link Font}. However, - * this name would be needed by any serious desktop publishing - * application. - * - * @param font the font whose sub-family name is requested. - * - * @param locale the locale for which to localize the name. If - * <code>locale</code> is <code>null</code>, the returned name is - * localized to the user’s default locale. - * - * @return the name of the face inside its family, or - * <code>null</code> if the font does not provide a sub-family name. - */ - - public abstract String getSubFamilyName (Font font, Locale locale); - - - /** - * Implementation of {@link Font#getPSName()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract String getPostScriptName (Font font); - - - /** - * Implementation of {@link Font#getNumGlyphs()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract int getNumGlyphs (Font font); - - - /** - * Implementation of {@link Font#getMissingGlyphCode()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract int getMissingGlyphCode (Font font); - - - /** - * Implementation of {@link Font#getBaselineFor(char)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract byte getBaselineFor (Font font, char c); - - - /** - * Returns a name for the specified glyph. This is useful for - * generating PostScript or PDF files that embed some glyphs of a - * font. If the implementation follows glyph naming conventions - * specified by Adobe, search engines can extract the original text - * from the generated PostScript and PDF files. - * - * <p>This method is currently not used by GNU Classpath. However, - * it would be very useful for someone wishing to write a good - * PostScript or PDF stream provider for the - * <code>javax.print</code> package. - * - * <p><b>Names are not unique:</b> Under some rare circumstances, - * the same name can be returned for different glyphs. It is - * therefore recommended that printer drivers check whether the same - * name has already been returned for antoher glyph, and make the - * name unique by adding the string ".alt" followed by the glyph - * index.</p> - * - * <p>This situation would occur for an OpenType or TrueType font - * that has a <code>post</code> table of format 3 and provides a - * mapping from glyph IDs to Unicode sequences through a - * <code>Zapf</code> table. If the same sequence of Unicode - * codepoints leads to different glyphs (depending on contextual - * position, for example, or on typographic sophistication level), - * the same name would get synthesized for those glyphs. To avoid - * this, the font peer would have to go through the names of all - * glyphs, which would make this operation very inefficient with - * large fonts. - * - * @param font the font containing the glyph whose name is - * requested. - * - * @param glyphIndex the glyph whose name the caller wants to - * retrieve. - * - * @return the glyph name, or <code>null</code> if a font does not - * provide glyph names. - */ - - public abstract String getGlyphName (Font font, int glyphIndex); - - - /** - * Implementation of {@link - * Font#createGlyphVector(FontRenderContext, String)}, {@link - * Font#createGlyphVector(FontRenderContext, char[])}, and {@link - * Font#createGlyphVector(FontRenderContext, CharacterIterator)}. - * - * @param font the font object that the created GlyphVector will return - * when it gets asked for its font. This argument is needed because the - * public API of {@link GlyphVector} works with {@link java.awt.Font}, - * not with font peers. - */ - - public abstract GlyphVector createGlyphVector (Font font, - FontRenderContext frc, - CharacterIterator ci); - - - /** - * Implementation of {@link Font#createGlyphVector(FontRenderContext, - * int[])}. - * - * @param font the font object that the created GlyphVector will return - * when it gets asked for its font. This argument is needed because the - * public API of {@link GlyphVector} works with {@link java.awt.Font}, - * not with font peers. - */ - - public abstract GlyphVector createGlyphVector (Font font, - FontRenderContext ctx, - int[] glyphCodes); - - - /** - * Implementation of {@link Font#layoutGlyphVector(FontRenderContext, - * char[], int, int, int)}. - * - * @param font the font object that the created GlyphVector will return - * when it gets asked for its font. This argument is needed because the - * public API of {@link GlyphVector} works with {@link java.awt.Font}, - * not with font peers. - */ - - public abstract GlyphVector layoutGlyphVector (Font font, - FontRenderContext frc, - char[] chars, int start, - int limit, int flags); - - - /** - * Implementation of {@link Font#getFontMetrics()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract FontMetrics getFontMetrics (Font font); - - - /** - * Implementation of {@link Font#hasUniformLineMetrics()} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract boolean hasUniformLineMetrics (Font font); - - - /** - * Implementation of {@link Font#getLineMetrics(CharacterIterator, int, - * int, FontRenderContext)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract LineMetrics getLineMetrics (Font font, - CharacterIterator ci, - int begin, int limit, - FontRenderContext rc); - - /** - * Implementation of {@link Font#getMaxCharBounds(FontRenderContext)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract Rectangle2D getMaxCharBounds (Font font, - FontRenderContext rc); - - /** - * Implementation of {@link Font#getStringBounds(CharacterIterator, int, - * int, FontRenderContext)} - * - * @param font the font this peer is being called from. This may be - * useful if you are sharing peers between Font objects. Otherwise it may - * be ignored. - */ - - public abstract Rectangle2D getStringBounds (Font font, - CharacterIterator ci, - int begin, int limit, - FontRenderContext frc); - -} diff --git a/libjava/gnu/java/awt/peer/ClasspathTextLayoutPeer.java b/libjava/gnu/java/awt/peer/ClasspathTextLayoutPeer.java deleted file mode 100644 index 70df2ef74ef..00000000000 --- a/libjava/gnu/java/awt/peer/ClasspathTextLayoutPeer.java +++ /dev/null @@ -1,104 +0,0 @@ -/* ClasspathTextLayoutPeer.java - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer; - -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.font.TextHitInfo; -import java.awt.font.TextLayout; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; - -/** - * @author Graydon Hoare - */ - -public interface ClasspathTextLayoutPeer -{ - TextHitInfo getStrongCaret (TextHitInfo hit1, - TextHitInfo hit2); - - void draw (Graphics2D g2, float x, float y); - - byte getBaseline (); - - boolean isLeftToRight (); - boolean isVertical (); - - float getAdvance (); - float getAscent (); - float getDescent (); - float getLeading (); - - int getCharacterCount (); - byte getCharacterLevel (int index); - - float[] getBaselineOffsets (); - Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint); - Rectangle2D getBounds (); - - float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds); - Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds); - Shape[] getCaretShapes (int offset, Rectangle2D bounds, - TextLayout.CaretPolicy policy); - - Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint, - Rectangle2D bounds); - int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint); - - TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy); - TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy); - TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds); - TextHitInfo getVisualOtherHit (TextHitInfo hit); - - float getVisibleAdvance (); - Shape getOutline (AffineTransform tx); - Shape getVisualHighlightShape (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint, - Rectangle2D bounds); - - TextLayout getJustifiedLayout (float justificationWidth); - void handleJustify (float justificationWidth); - - Object clone (); - int hashCode (); - boolean equals (ClasspathTextLayoutPeer tl); - String toString (); -} diff --git a/libjava/gnu/java/awt/peer/EmbeddedWindowPeer.java b/libjava/gnu/java/awt/peer/EmbeddedWindowPeer.java deleted file mode 100644 index 4c64a1d2d18..00000000000 --- a/libjava/gnu/java/awt/peer/EmbeddedWindowPeer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* EmbeddedWindowPeer.java -- Interface for window peers that may be - embedded into other applications - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer; - -import java.awt.peer.FramePeer; - -public interface EmbeddedWindowPeer extends FramePeer -{ - void embed (long handle); -} diff --git a/libjava/gnu/java/awt/peer/GLightweightPeer.java b/libjava/gnu/java/awt/peer/GLightweightPeer.java deleted file mode 100644 index 3bcaebcea62..00000000000 --- a/libjava/gnu/java/awt/peer/GLightweightPeer.java +++ /dev/null @@ -1,298 +0,0 @@ -/* GLightweightPeer.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer; - -import java.awt.AWTEvent; -import java.awt.AWTException; -import java.awt.BufferCapabilities; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Insets; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.event.PaintEvent; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; -import java.awt.peer.ContainerPeer; -import java.awt.peer.LightweightPeer; - -/* - * Another possible implementation strategy for lightweight peers is - * to make GLightweightPeer a placeholder class that implements - * LightweightPeer. Then the Component and Container classes could - * identify a peer as lightweight and handle it specially. The - * current approach is probably more clear but less efficient. - */ - -/** - * A stub class that implements the ComponentPeer and ContainerPeer - * interfaces using callbacks into the Component and Container - * classes. GLightweightPeer allows the Component and Container - * classes to treat lightweight and heavyweight peers in the same way. - * - * Lightweight components are painted directly onto their parent - * containers through an Image object provided by the toolkit. - */ -public class GLightweightPeer - implements LightweightPeer, ContainerPeer -{ - private Component comp; - - private Insets containerInsets; - - public GLightweightPeer(Component comp) - { - this.comp = comp; - } - - // -------- java.awt.peer.ContainerPeer implementation: - - public Insets insets() - { - return getInsets (); - } - - public Insets getInsets() - { - if (containerInsets == null) - containerInsets = new Insets (0,0,0,0); - return containerInsets; - } - - public void beginValidate() - { - } - - public void endValidate() - { - } - - public void beginLayout() - { - } - - public void endLayout() - { - } - - public boolean isPaintPending() - { - return false; - } - - // -------- java.awt.peer.ComponentPeer implementation: - - public int checkImage(Image img, int width, int height, ImageObserver o) - { - return comp.getToolkit().checkImage(img, width, height, o); - } - - public Image createImage(ImageProducer prod) - { - return comp.getToolkit().createImage(prod); - } - - /* This method is not called. */ - public Image createImage(int width, int height) - { - return null; - } - - public void disable() {} - - public void dispose() {} - - public void enable() {} - - public GraphicsConfiguration getGraphicsConfiguration() - { - return null; - } - - public FontMetrics getFontMetrics(Font f) - { - return comp.getToolkit().getFontMetrics(f); - } - - /* Returning null here tells the Component object that called us to - * use its parent's Graphics. */ - public Graphics getGraphics() - { - return null; - } - - public Point getLocationOnScreen() - { - Point parentLocation = comp.getParent().getLocationOnScreen(); - return new Point (parentLocation.x + comp.getX(), - parentLocation.y + comp.getY()); - } - - public Dimension getMinimumSize() - { - return new Dimension(comp.getWidth(), comp.getHeight()); - } - - /* A lightweight component's preferred size is equivalent to its - * Component width and height values. */ - public Dimension getPreferredSize() - { - return new Dimension(comp.getWidth(), comp.getHeight()); - } - - /* Returning null here tells the Component object that called us to - * use its parent's Toolkit. */ - public Toolkit getToolkit() - { - return null; - } - - public void handleEvent(AWTEvent e) {} - - public void hide() {} - - public boolean isFocusable() - { - return false; - } - - public boolean isFocusTraversable() - { - return false; - } - - public Dimension minimumSize() - { - return getMinimumSize(); - } - - public Dimension preferredSize() - { - return getPreferredSize(); - } - - public void paint(Graphics graphics) {} - - public boolean prepareImage(Image img, int width, int height, - ImageObserver o) - { - return comp.getToolkit().prepareImage(img, width, height, o); - } - - public void print(Graphics graphics) {} - - public void repaint(long tm, int x, int y, int width, int height) {} - - public void requestFocus() {} - - public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x) - { - return false; - } - - public void reshape(int x, int y, int width, int height) {} - - public void setBackground(Color color) {} - - public void setBounds(int x, int y, int width, int height) {} - - public void setCursor(Cursor cursor) {} - - public void setEnabled(boolean enabled) {} - - public void setEventMask(long eventMask) {} - - public void setFont(Font font) {} - - public void setForeground(Color color) {} - - public void setVisible(boolean visible) {} - - public void show() {} - - public ColorModel getColorModel () - { - return comp.getColorModel (); - } - - public boolean isObscured() - { - return false; - } - - public boolean canDetermineObscurity() - { - return false; - } - - public void coalescePaintEvent(PaintEvent e) { } - - public void updateCursorImmediately() { } - - public VolatileImage createVolatileImage(int width, int height) - { - return null; - } - - public boolean handlesWheelScrolling() - { - return false; - } - - public void createBuffers(int x, BufferCapabilities capabilities) - throws AWTException { } - - public Image getBackBuffer() - { - return null; - } - - public void flip(BufferCapabilities.FlipContents contents) { } - - public void destroyBuffers() { } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GThreadMutex.java b/libjava/gnu/java/awt/peer/gtk/GThreadMutex.java deleted file mode 100644 index e73df9e5509..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GThreadMutex.java +++ /dev/null @@ -1,109 +0,0 @@ -/* GThreadMutex.java -- Implements a mutex object for glib's gthread - abstraction, for use with GNU Classpath's --portable-native-sync option. - This is used in gthread-jni.c - - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.peer.gtk; - -/** Implements a mutex object for glib's gthread - abstraction, for use with GNU Classpath's --portable-native-sync option. - This is used in gthread-jni.c. - - We use this object to implement the POSIX semantics for Mutexes. They are - needed are needed for the function vector that is passed to glib's - g_thread subpackage's initialization function. - - The GThreadMutex object itself serves as the Real Lock; if code has - entered the monitor for this GThreadMutex object (in Java language, if - it's synchronized on this object) then it holds the lock that this object - represents. - - @author Steven Augart - May, 2004 - - -*/ - -class GThreadMutex -{ - /** Might "lock" be locked? Is anyone waiting - to get that lock? How long is the queue? - - If zero, nobody holds a lock on this GThreadMutex object, and nobody is - trying to get one. Before someone attempts to acquire a lock on this - object, they must increment potentialLockers. After they release their - lock on this object, they must decrement potentialLockers. - - Access to this field is guarded by synchronizing on the object - <code>lockForPotentialLockers</code>. - - After construction, we only access this field via JNI. - */ - volatile int potentialLockers; - - /** An object to synchronize to if you want to examine or modify the - <code>potentialLockers</code> field. Only hold this lock for brief - moments, just long enough to check or set the value of - <code>lockForPotentialLockers</code>. - - We use this representation so that g_thread_mutex_trylock() will work - with the POSIX semantics. This is the only case in which you ever hold a - lock on <code>lockForPotentialLockers</code> while trying to get another - lock -- if you are the mutex_trylock() implementation, and you have just - checked that <code>potentialLockers</code> has the value zero. In that - case, mutex_trylock() holds the lock on lockForPotentialLockers so that - another thread calling mutex_trylock() or mutex_lock() won't increment - potentialLockers after we've checked it and before we've gained the lock - on the POSIX mutex. Of course, in that case the operation of gaining - the POSIX lock itself will succeed immediately, and once it has - succeeded, trylock releases lockForPotentialLockers right away, - incremented to 1 (one). - - After construction, we only access this field via JNI. - */ - Object lockForPotentialLockers; - - GThreadMutex() - { - potentialLockers = 0; - lockForPotentialLockers = new Object(); - } -} -// Local Variables: -// c-file-style: "gnu" -// End: diff --git a/libjava/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java b/libjava/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java deleted file mode 100644 index 9a1b8e3a30a..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java +++ /dev/null @@ -1,303 +0,0 @@ -/* GThreadNativeMethodRunner.java -- Implements pthread_create(), under - glib's gthread abstraction, for use with GNU Classpath's - --portable-native-sync option. - This is used by gthread-jni.c - - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.peer.gtk; - -import java.lang.ref.WeakReference; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** Implements pthread_create(), under glib's gthread abstraction, for use - with GNU Classpath's --portable-native-sync option. This is used in - gthread-jni.c - - Also implements a registry for threads, mapping Thread objects to small - integers. The registry uses weak references for threads that aren't - joinable, so that they will be garbage collected. - - There are a number of possible alternative implementations. - - - The rest of this comment consists of an answer to a question that was - raised on the commit-classpath mailing list: - - Mark Wielaard wrote: - - > Can't we assume that jobject and gpointer are both (void *) so we don't - > need the int <-> Thread (global jobject ref) mapping? - > Maybe there are platforms where jobject and gpointer aren't the same, - > but I guess that is pretty unlikely. - - - I agree with you on the pointer size issues. A gpointer is a void *, so - it's certainly guaranteed to be at least as large as any other - pointer. And a jobject is implicitly an opaque pointer (in Jikes RVM, we - use small integers, but we coerce them into the representation of a - pointer). - - The int <==> Thread mapping addresses a different issue. I realize that I - did not document this properly (two and a half lines in thread_create), - and the point is subtle (at least to me; took me a while to figure out). - - The int => Thread mapping always returns jobjects that are local - references, not global ones. This is because Thread objects need to be - able to go away and be garbage collected after the thread they refer to - has died. - - If we keep a global object reference to a thread, then when do we delete - that global object reference? We have an answer in the case of GThread - objects that were explicitly created with the joinable attribute. It is - safe for us to maintain a global reference to any joinable thread, since - the joinable thread must linger (even if only in a zombie state) - until it's explicitly joined via a g_thread_join() call. The global ref - could be cleaned up at that point too. - - However, in the case of GThreads that were created non-joinable by - g_thread_create(), and in the case of Java threads that were created - within pure Java code (not via g_thread_create()), we don't want them to - linger forever, and there is no way to tell when the last reference - to such threads needs to expire. In the case of this application -- AWT - with GTK peers -- it would probably be safe anyway, since there are not - very many threads we create, but I was going for correctness even in the - case of long-running programs that might set up and tear down AWT - interfaces many times. - - So, I duplicated the POSIX thread-ID semantics. The thread ID of a - non-joinable thread remains valid as long as that thread is still alive. - Once that thread dies, the old thread ID may be reused at any moment. And - that's why the array indexed by thread ID numbers is an array of weak - references. - - That's also why the int => Thread jobject mapping function always returns - local references, since global references would lock the Thread in memory - forever. - - I would dearly love there to be a cleaner solution. I dislike the - repeated dips from C code into Java that are necessary to look up thread - ID numbers. If anyone can think of one, I'm all ears. -*/ - -class GThreadNativeMethodRunner - extends Thread -{ - /** The C function pointer that was passed to g_thread_create(). - Specifically, this the numeric address of an object of - C type "void *(*funcPtr)(void *funcArg)". - */ - private final long funcPtr; - - /** The argument for the function "funcPtr(funcArg)". */ - private final long funcArg; - - GThreadNativeMethodRunner(long funcPtr, long funcArg, boolean joinable) - { - this.funcPtr = funcPtr; - this.funcArg = funcArg; - - if (joinable) - registerSelfJoinable(); - } - - public void run() - { - nativeRun(funcPtr, funcArg); - } - - private native void nativeRun(long funcPtr, long funcArg); - - /** THREADS is an array of threads, indexed by thread ID codes. Not sure - whether this is the "best" approach but it does make it O(1) to look up a - thread by its ID. - - Zero is a valid thread ID code. Any negative number is invalid. - - Possible future fixes (TODO?) - - - The THREADS array will only grow. probably not a problem. - But we could keep count when nulling entries and shrink when we have - lots of nulls at the end. Probably not worth it. --mjw - - - Could make this a set of Object; see the comment on "joinable" below. - - The initial size of 17 is just a starting point. Any number will do, - including zero. - */ - private static WeakReference[] threads = new WeakReference[17]; - - /** Used by threadToThreadID, below. Returns the registration number of - the newly-registered thread. - */ - private static synchronized int registerThread(Thread t) - { - int i; - - for (i = 0; i < threads.length; ++i) - { - WeakReference ref = threads[i]; - if (ref == null) - break; // found an empty spot. - } - - if (i == threads.length) - { - /* expand the array */ - WeakReference[] bigger = new WeakReference[threads.length * 2]; - System.arraycopy(threads, 0, bigger, 0, threads.length); - threads = bigger; - } - - threads[i] = new WeakReference(t); - - return i; - } - - /** Look up the Thread ID # for a Thread. Assign a Thread ID # if none - exists. This is a general routine for handling all threads, including - the VM's main thread, if appropriate. - - - Runs in O(n/2) time. - - We can't just issue a threadID upon thread creation. If we were to do - that, not all threads would have a threadID, because not all threads - are launched by GThreadNativeMethodRunner. - */ - static synchronized int threadToThreadID(Thread t) - { - for (int i = 0; i < threads.length; ++i ) - { - if (threads[i] == null) - continue; - Thread referent = (Thread) threads[i].get(); - if (referent == null) - { - threads[i] = null; // Purge the dead WeakReference. - continue; - } - if (referent.equals(t)) - return i; - } // for() - - /* No match found. */ - return registerThread(t); - } - - /** @param threadID Must be a non-negative integer. - - Used to return null if the thread number was out of range or if - the thread was unregistered. Now we throw an exception. - - Possible Alternative Interface: We could go back to returning null in - some sort of check-free mode, so code that calls this function must - be prepared to get null. - */ - static Thread threadIDToThread(int threadID) - throws IllegalArgumentException - { - if (threadID < 0) - throw new IllegalArgumentException("Received a negative threadID, " - + threadID); - if (threadID >= threads.length) - throw new IllegalArgumentException("Received a threadID (" + threadID - + ") higher than was" - + " ever issued"); - - /* Note: if the user is using a stale reference, things will just - break. We might end up getting a different thread than the one - expected. - - TODO: Add an error-checking mode where the user's problems with threads - are announced. For instance, if the user asks for the thread - associated with a threadID that was never issued, we could print a - warning or even abort. - - TODO: Consider optionally disabling all of the error-checking we - already have; it probably slows down the implementation. We could - just return NULL. This is just the reverse of the above TODO item. - */ - - WeakReference threadRef = threads[threadID]; - - if (threadRef == null) - throw new IllegalArgumentException("Asked to look up a stale or unissued" - + "threadID (" + threadID + ")" ); - - - Thread referent = (Thread) threadRef.get(); - if (referent == null) - throw new IllegalArgumentException ("Asked to look up a stale threadID (" - + threadID + ")"); - return referent; - } - - /** Joinable threads need a hard reference, so that they won't go away when - they die. That is because their thread IDs need to stay valid until the - thread is joined via thread_join(threadID). Joinable threads have to be - explicitly joined before they are allowed to go away completely. - - Possible Alternative Implementation: Eliminate the Joinable set. When - calling getThreadIDFromThread() you know whether or not the thread - is joinable. So just store the Thread itself in the threads array? - Make that array an Object array and check with instanceof. This - looks cleaner and more robust to me and it saves a native -> Java - call. But instanceof might be expensive. --mjw - */ - private static final Set joinable = - Collections.synchronizedSet(new HashSet()); - - /** Only called from the constructor. */ - private void registerSelfJoinable() - { - joinable.add(this); - } - - /** This method is only called from JNI, and only after we have succeeded in - a thread_join() operation. */ - static void deRegisterJoinable(Thread thread) - { - joinable.remove(thread); - } -} - -// Local Variables: -// c-file-style: "gnu" -// End: diff --git a/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java b/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java deleted file mode 100644 index 7a439e83a9d..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java +++ /dev/null @@ -1,134 +0,0 @@ -/* GdkFontMetrics.java - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.java.awt.ClasspathToolkit; - -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Toolkit; - -public class GdkFontMetrics extends FontMetrics -{ - - private int[] font_metrics; - GdkFontPeer peer; - - static final int FONT_METRICS_ASCENT = 0; - static final int FONT_METRICS_MAX_ASCENT = 1; - static final int FONT_METRICS_DESCENT = 2; - static final int FONT_METRICS_MAX_DESCENT = 3; - static final int FONT_METRICS_MAX_ADVANCE = 4; - - static final int TEXT_METRICS_X_BEARING = 0; - static final int TEXT_METRICS_Y_BEARING = 1; - static final int TEXT_METRICS_WIDTH = 2; - static final int TEXT_METRICS_HEIGHT = 3; - static final int TEXT_METRICS_X_ADVANCE = 4; - static final int TEXT_METRICS_Y_ADVANCE = 5; - - - public GdkFontMetrics (Font font) - { - super (font.getPeer() instanceof GdkFontPeer - ? font - : ((ClasspathToolkit)(Toolkit.getDefaultToolkit ())) - .getFont (font.getName(), font.getAttributes ())); - - peer = (GdkFontPeer) this.font.getPeer(); - - font_metrics = new int[5]; - double [] hires = new double[5]; - peer.getFontMetrics (hires); - for (int i = 0; i < 5; ++i) - font_metrics[i] = (int) hires[i]; - } - - public int stringWidth (String str) - { - double [] hires = new double[6]; - peer.getTextMetrics(str, hires); - return (int) hires [TEXT_METRICS_WIDTH]; - } - - public int charWidth (char ch) - { - return stringWidth (new String (new char[] { ch })); - } - - public int charsWidth (char data[], int off, int len) - { - return stringWidth (new String (data, off, len)); - } - - /* - Sun's Motif implementation always returns 0 or 1 here (???), but - going by the X11 man pages, it seems as though we should return - font.ascent + font.descent. - */ - public int getLeading () - { - return 1; - } - - public int getAscent () - { - return font_metrics[FONT_METRICS_ASCENT]; - } - - public int getMaxAscent () - { - return font_metrics[FONT_METRICS_MAX_ASCENT]; - } - - public int getDescent () - { - return font_metrics[FONT_METRICS_DESCENT]; - } - - public int getMaxDescent () - { - return font_metrics[FONT_METRICS_MAX_DESCENT]; - } - - public int getMaxAdvance () - { - return font_metrics[FONT_METRICS_MAX_ADVANCE]; - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkFontPeer.java b/libjava/gnu/java/awt/peer/gtk/GdkFontPeer.java deleted file mode 100644 index c6d42b37276..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkFontPeer.java +++ /dev/null @@ -1,307 +0,0 @@ -/* GdkFontPeer.java -- Implements FontPeer with GTK+ - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.classpath.Configuration; -import gnu.java.awt.peer.ClasspathFontPeer; - -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.font.LineMetrics; -import java.awt.geom.Rectangle2D; -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -public class GdkFontPeer extends ClasspathFontPeer -{ - static native void initStaticState(); - private final int native_state = GtkGenericPeer.getUniqueInteger (); - private static ResourceBundle bundle; - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("gtkpeer"); - } - - initStaticState (); - - try - { - bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font"); - } - catch (Throwable ignored) - { - bundle = null; - } - } - - private native void initState (); - private native void dispose (); - private native void setFont (String family, int style, int size, boolean useGraphics2D); - - native void getFontMetrics(double [] metrics); - native void getTextMetrics(String str, double [] metrics); - - protected void finalize () - { - if (GtkToolkit.useGraphics2D ()) - GdkGraphics2D.releasePeerGraphicsResource(this); - dispose (); - } - - /* - * Helpers for the 3-way overloading that this class seems to suffer - * from. Remove them if you feel like they're a performance bottleneck, - * for the time being I prefer my code not be written and debugged in - * triplicate. - */ - - private String buildString(CharacterIterator iter) - { - StringBuffer sb = new StringBuffer(); - for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) - sb.append(c); - return sb.toString(); - } - - private String buildString(CharacterIterator iter, int begin, int limit) - { - StringBuffer sb = new StringBuffer(); - int i = 0; - for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++) - { - if (begin <= i) - sb.append(c); - if (limit <= i) - break; - } - return sb.toString(); - } - - private String buildString(char[] chars, int begin, int limit) - { - return new String(chars, begin, limit - begin); - } - - /* Public API */ - - public GdkFontPeer (String name, int style) - { - // All fonts get a default size of 12 if size is not specified. - this(name, style, 12); - } - - public GdkFontPeer (String name, int style, int size) - { - super(name, style, size); - initState (); - setFont (this.familyName, this.style, (int)this.size, - GtkToolkit.useGraphics2D()); - } - - public GdkFontPeer (String name, Map attributes) - { - super(name, attributes); - initState (); - setFont (this.familyName, this.style, (int)this.size, - GtkToolkit.useGraphics2D()); - } - - public String getSubFamilyName(Font font, Locale locale) - { - return null; - } - - public String getPostScriptName(Font font) - { - return null; - } - - public boolean canDisplay (Font font, char c) - { - // FIXME: inquire with pango - return true; - } - - public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit) - { - // FIXME: inquire with pango - return -1; - } - - private native GdkGlyphVector getGlyphVector(String txt, - Font f, - FontRenderContext ctx); - - public GlyphVector createGlyphVector (Font font, - FontRenderContext ctx, - CharacterIterator i) - { - return getGlyphVector(buildString (i), font, ctx); - } - - public GlyphVector createGlyphVector (Font font, - FontRenderContext ctx, - int[] glyphCodes) - { - return null; - // return new GdkGlyphVector (font, this, ctx, glyphCodes); - } - - public byte getBaselineFor (Font font, char c) - { - throw new UnsupportedOperationException (); - } - - protected class GdkFontLineMetrics extends LineMetrics - { - FontMetrics fm; - int nchars; - - public GdkFontLineMetrics (FontMetrics m, int n) - { - fm = m; - nchars = n; - } - - public float getAscent() - { - return (float) fm.getAscent (); - } - - public int getBaselineIndex() - { - return Font.ROMAN_BASELINE; - } - - public float[] getBaselineOffsets() - { - return new float[3]; - } - - public float getDescent() - { - return (float) fm.getDescent (); - } - - public float getHeight() - { - return (float) fm.getHeight (); - } - - public float getLeading() { return 0.f; } - public int getNumChars() { return nchars; } - public float getStrikethroughOffset() { return 0.f; } - public float getStrikethroughThickness() { return 0.f; } - public float getUnderlineOffset() { return 0.f; } - public float getUnderlineThickness() { return 0.f; } - - } - - public LineMetrics getLineMetrics (Font font, CharacterIterator ci, - int begin, int limit, FontRenderContext rc) - { - return new GdkFontLineMetrics (getFontMetrics (font), limit - begin); - } - - public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc) - { - throw new UnsupportedOperationException (); - } - - public int getMissingGlyphCode (Font font) - { - throw new UnsupportedOperationException (); - } - - public String getGlyphName (Font font, int glyphIndex) - { - throw new UnsupportedOperationException (); - } - - public int getNumGlyphs (Font font) - { - throw new UnsupportedOperationException (); - } - - public Rectangle2D getStringBounds (Font font, CharacterIterator ci, - int begin, int limit, FontRenderContext frc) - { - GdkGlyphVector gv = getGlyphVector(buildString (ci, begin, limit), font, frc); - return gv.getVisualBounds(); - } - - public boolean hasUniformLineMetrics (Font font) - { - return true; - } - - public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc, - char[] chars, int start, int limit, - int flags) - { - int nchars = (limit - start) + 1; - char[] nc = new char[nchars]; - - for (int i = 0; i < nchars; ++i) - nc[i] = chars[start + i]; - - return createGlyphVector (font, frc, - new StringCharacterIterator (new String (nc))); - } - - public LineMetrics getLineMetrics (Font font, String str, - FontRenderContext frc) - { - return new GdkFontLineMetrics (getFontMetrics (font), str.length ()); - } - - public FontMetrics getFontMetrics (Font font) - { - return new GdkFontMetrics (font); - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGlyphVector.java b/libjava/gnu/java/awt/peer/gtk/GdkGlyphVector.java deleted file mode 100644 index f0ddea43a12..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkGlyphVector.java +++ /dev/null @@ -1,359 +0,0 @@ -/* GdkGlyphVector.java -- Glyph vector object - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphJustificationInfo; -import java.awt.font.GlyphMetrics; -import java.awt.font.GlyphVector; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -public class GdkGlyphVector extends GlyphVector -{ - - /* We use a simple representation for glyph vectors here. Glyph i - * consumes 8 doubles: - * - * logical x: extents[ 10*i ] - * logical y: extents[ 10*i + 1 ] - * logical width: extents[ 10*i + 2 ] - * logical height: extents[ 10*i + 3 ] - * - * visual x: extents[ 10*i + 4 ] - * visual y: extents[ 10*i + 5 ] - * visual width: extents[ 10*i + 6 ] - * visual height: extents[ 10*i + 7 ] - * - * origin pos x: extents[ 10*i + 8 ] - * origin pos y: extents[ 10*i + 9 ] - * - * as well as one int, code[i], representing the glyph code in the font. - */ - - double [] extents; - int [] codes; - - Font font; - FontRenderContext fontRenderContext; - - Rectangle2D allLogical; - Rectangle2D allVisual; - - public GdkGlyphVector(double[] extents, int[] codes, Font font, FontRenderContext frc) - { - this.extents = extents; - this.codes = codes; - this.font = font; - this.fontRenderContext = frc; - - allLogical = new Rectangle2D.Double(); - allVisual = new Rectangle2D.Double(); - - for (int i = 0; i < codes.length; ++i) - { - allLogical.add (new Rectangle2D.Double(extents[10*i ] + extents[10*i + 8], - extents[10*i + 1] + extents[10*i + 9], - extents[10*i + 2], - extents[10*i + 3])); - - allVisual.add (new Rectangle2D.Double(extents[10*i + 4] + extents[10*i + 8], - extents[10*i + 5] + extents[10*i + 9], - extents[10*i + 6], - extents[10*i + 7])); - } - } - - /* - geometric notes: - - the FRC contains a mapping from points -> pixels. - - typographics points are typically 1/72 of an inch. - - pixel displays are often around 72 dpi. - - so the FRC can get away with using an identity transform on a screen, - often. behavior is documented by sun to fall back to an identity - transform if the internal transformation is null. - - coordinates coming up from pango are expressed as floats -- in device - space, so basically pixels-with-fractional-bits -- derived from their - storage format in pango (1024ths of pixels). - - it is not clear from the javadocs whether the results of methods like - getGlyphPositions ought to return coordinates in device space, or - "point" space, or what. for now I'm returning them in device space. - - */ - - public double[] getExtents() - { - return extents; - } - - public int[] getCodes() - { - return codes; - } - - public Font getFont () - { - return font; - } - - public FontRenderContext getFontRenderContext () - { - return fontRenderContext; - } - - public int getGlyphCharIndex (int glyphIndex) - { - // FIXME: currently pango does not provide glyph-by-glyph - // reverse mapping information, so we assume a broken 1:1 - // glyph model here. This is plainly wrong. - return glyphIndex; - } - - public int[] getGlyphCharIndices (int beginGlyphIndex, - int numEntries, - int[] codeReturn) - { - int ix[] = codeReturn; - if (ix == null) - ix = new int[numEntries]; - - for (int i = 0; i < numEntries; i++) - ix[i] = getGlyphCharIndex (beginGlyphIndex + i); - return ix; - } - - public int getGlyphCode (int glyphIndex) - { - return codes[glyphIndex]; - } - - public int[] getGlyphCodes (int beginGlyphIndex, int numEntries, - int[] codeReturn) - { - if (codeReturn == null) - codeReturn = new int[numEntries]; - - System.arraycopy(codes, beginGlyphIndex, codeReturn, 0, numEntries); - return codeReturn; - } - - public Shape getGlyphLogicalBounds (int i) - { - return new Rectangle2D.Double (extents[8*i], extents[8*i + 1], - extents[8*i + 2], extents[8*i + 3]); - } - - public GlyphMetrics getGlyphMetrics (int i) - { - // FIXME: pango does not yield vertical layout information at the - // moment. - - boolean is_horizontal = true; - double advanceX = extents[8*i + 2]; // "logical width" == advanceX - double advanceY = 0; - - return new GlyphMetrics (is_horizontal, - (float) advanceX, (float) advanceY, - (Rectangle2D) getGlyphVisualBounds(i), - GlyphMetrics.STANDARD); - } - - public Shape getGlyphOutline (int glyphIndex) - { - throw new UnsupportedOperationException (); - } - - public Shape getGlyphOutline (int glyphIndex, float x, float y) - { - throw new UnsupportedOperationException (); - } - - public Rectangle getGlyphPixelBounds (int i, - FontRenderContext renderFRC, - float x, float y) - { - return new Rectangle((int) x, (int) y, - (int) extents[8*i + 6], (int) extents[8*i + 7]); - } - - public Point2D getGlyphPosition (int i) - { - return new Point2D.Double (extents[10*i + 8], - extents[10*i + 9]); - } - - public float[] getGlyphPositions (int beginGlyphIndex, - int numEntries, - float[] positionReturn) - { - float fx[] = positionReturn; - if (fx == null) - fx = new float[numEntries * 2]; - - for (int i = 0; i < numEntries; ++i) - { - fx[2*i ] = (float) extents[10*i + 8]; - fx[2*i + 1] = (float) extents[10*i + 9]; - } - return fx; - } - - public AffineTransform getGlyphTransform (int glyphIndex) - { - // Glyphs don't have independent transforms in these simple glyph - // vectors; docs specify null is an ok return here. - return null; - } - - public Shape getGlyphVisualBounds (int i) - { - return new Rectangle2D.Double(extents[8*i + 4], extents[8*i + 5], - extents[8*i + 6], extents[8*i + 7]); - } - - public int getLayoutFlags () - { - return 0; - } - - public Rectangle2D getLogicalBounds () - { - return allLogical; - } - - public int getNumGlyphs () - { - return codes.length; - } - - public Shape getOutline () - { - throw new UnsupportedOperationException (); - } - - public Rectangle getPixelBounds (FontRenderContext renderFRC, - float x, float y) - { - return new Rectangle((int)x, - (int)y, - (int) allVisual.getWidth(), - (int) allVisual.getHeight()); - } - - public Rectangle2D getVisualBounds () - { - return allVisual; - } - - public void performDefaultLayout () - { - } - - public void setGlyphPosition (int i, Point2D newPos) - { - extents[8*i ] = newPos.getX(); - extents[8*i + 1] = newPos.getY(); - - extents[8*i + 4] = newPos.getX(); - extents[8*i + 5] = newPos.getY(); - } - - public void setGlyphTransform (int glyphIndex, - AffineTransform newTX) - { - // not yet.. maybe not ever? - throw new UnsupportedOperationException (); - } - - public boolean equals(GlyphVector gv) - { - if (gv == null) - return false; - - if (! (gv instanceof GdkGlyphVector)) - return false; - - GdkGlyphVector ggv = (GdkGlyphVector) gv; - - if ((ggv.codes.length != this.codes.length) - || (ggv.extents.length != this.extents.length)) - return false; - - if ((ggv.font == null && this.font != null) - || (ggv.font != null && this.font == null) - || (!ggv.font.equals(this.font))) - return false; - - if ((ggv.fontRenderContext == null && this.fontRenderContext != null) - || (ggv.fontRenderContext != null && this.fontRenderContext == null) - || (!ggv.fontRenderContext.equals(this.fontRenderContext))) - return false; - - for (int i = 0; i < ggv.codes.length; ++i) - if (ggv.codes[i] != this.codes[i]) - return false; - - for (int i = 0; i < ggv.extents.length; ++i) - if (ggv.extents[i] != this.extents[i]) - return false; - - return true; - } - - public GlyphJustificationInfo getGlyphJustificationInfo(int idx) - { - throw new UnsupportedOperationException (); - } - - public Shape getOutline(float x, float y) - { - throw new UnsupportedOperationException (); - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java deleted file mode 100644 index cc3a1009d86..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java +++ /dev/null @@ -1,487 +0,0 @@ -/* GdkGraphics.java - Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.SystemColor; -import java.awt.image.ImageObserver; -import java.text.AttributedCharacterIterator; - -public class GdkGraphics extends Graphics -{ - private final int native_state = GtkGenericPeer.getUniqueInteger(); - - Color color, xorColor; - GtkComponentPeer component; - Font font; - Rectangle clip; - - int xOffset = 0; - int yOffset = 0; - - static final int GDK_COPY = 0, GDK_XOR = 2; - - native void initState (GtkComponentPeer component); - native void initState (int width, int height); - native void copyState (GdkGraphics g); - - GdkGraphics (GdkGraphics g) - { - color = g.color; - xorColor = g.xorColor; - font = g.font; - clip = new Rectangle (g.clip); - component = g.component; - - copyState (g); - } - - GdkGraphics (int width, int height) - { - initState (width, height); - color = Color.black; - clip = new Rectangle (0, 0, width, height); - font = new Font ("Dialog", Font.PLAIN, 12); - } - - GdkGraphics (GtkComponentPeer component) - { - this.component = component; - font = component.awtComponent.getFont (); - - if (component.isRealized ()) - initComponentGraphics (); - else - connectSignals (component); - } - - void initComponentGraphics () - { - initState (component); - color = component.awtComponent.getForeground (); - Dimension d = component.awtComponent.getSize (); - clip = new Rectangle (0, 0, d.width, d.height); - } - - native void connectSignals (GtkComponentPeer component); - - public native void clearRect(int x, int y, int width, int height); - - public void clipRect (int x, int y, int width, int height) - { - if (component != null && ! component.isRealized ()) - return; - - clip = clip.intersection (new Rectangle (x, y, width, height)); - setClipRectangle (clip.x, clip.y, clip.width, clip.height); - } - - public native void copyArea(int x, int y, int width, int height, - int dx, int dy); - - public Graphics create () - { - return new GdkGraphics (this); - } - - public native void dispose(); - - native void copyPixmap (Graphics g, int x, int y, int width, int height); - native void copyAndScalePixmap (Graphics g, boolean flip_x, boolean flip_y, - int src_x, int src_y, - int src_width, int src_height, - int dest_x, int dest_y, - int dest_width, int dest_height); - public boolean drawImage (Image img, int x, int y, - Color bgcolor, ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (img instanceof GtkOffScreenImage) - { - int width = img.getWidth (null); - int height = img.getHeight (null); - copyPixmap (img.getGraphics (), - x, y, width, height); - return true; - } - - GtkImage image = (GtkImage) img; - new GtkImagePainter (image, this, x, y, -1, -1, bgcolor, observer); - return image.isLoaded (); - } - - public boolean drawImage (Image img, int x, int y, ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (img instanceof GtkOffScreenImage) - { - int width = img.getWidth (null); - int height = img.getHeight (null); - copyPixmap (img.getGraphics (), - x, y, width, height); - return true; - } - - if (component != null) - return drawImage (img, x, y, component.getBackground (), observer); - else - return drawImage (img, x, y, SystemColor.window, observer); - } - - public boolean drawImage (Image img, int x, int y, int width, int height, - Color bgcolor, ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (img instanceof GtkOffScreenImage) - { - copyAndScalePixmap (img.getGraphics (), false, false, - 0, 0, img.getWidth (null), img.getHeight (null), - x, y, width, height); - return true; - } - - GtkImage image = (GtkImage) img; - new GtkImagePainter (image, this, x, y, width, height, bgcolor, observer); - return image.isLoaded (); - } - - public boolean drawImage (Image img, int x, int y, int width, int height, - ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (component != null) - return drawImage (img, x, y, width, height, component.getBackground (), - observer); - else - return drawImage (img, x, y, width, height, SystemColor.window, - observer); - } - - public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, - int sx1, int sy1, int sx2, int sy2, - Color bgcolor, ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (img instanceof GtkOffScreenImage) - { - int dx_start, dy_start, d_width, d_height; - int sx_start, sy_start, s_width, s_height; - boolean x_flip = false; - boolean y_flip = false; - - if (dx1 < dx2) - { - dx_start = dx1; - d_width = dx2 - dx1; - } - else - { - dx_start = dx2; - d_width = dx1 - dx2; - x_flip ^= true; - } - if (dy1 < dy2) - { - dy_start = dy1; - d_height = dy2 - dy1; - } - else - { - dy_start = dy2; - d_height = dy1 - dy2; - y_flip ^= true; - } - if (sx1 < sx2) - { - sx_start = sx1; - s_width = sx2 - sx1; - } - else - { - sx_start = sx2; - s_width = sx1 - sx2; - x_flip ^= true; - } - if (sy1 < sy2) - { - sy_start = sy1; - s_height = sy2 - sy1; - } - else - { - sy_start = sy2; - s_height = sy1 - sy2; - y_flip ^= true; - } - - copyAndScalePixmap (img.getGraphics (), x_flip, y_flip, - sx_start, sy_start, s_width, s_height, - dx_start, dy_start, d_width, d_height); - return true; - } - - GtkImage image = (GtkImage) img; - new GtkImagePainter (image, this, dx1, dy1, dx2, dy2, - sx1, sy1, sx2, sy2, bgcolor, observer); - return image.isLoaded (); - } - - public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, - int sx1, int sy1, int sx2, int sy2, - ImageObserver observer) - { - if (component != null && ! component.isRealized ()) - return false; - - if (component != null) - return drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, - component.getBackground (), observer); - else - return drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, - SystemColor.window, observer); - } - - public native void drawLine(int x1, int y1, int x2, int y2); - - public native void drawArc(int x, int y, int width, int height, - int startAngle, int arcAngle); - public native void fillArc(int x, int y, int width, int height, - int startAngle, int arcAngle); - public native void drawOval(int x, int y, int width, int height); - public native void fillOval(int x, int y, int width, int height); - - public native void drawPolygon(int[] xPoints, int[] yPoints, int nPoints); - public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints); - - public native void drawPolyline(int[] xPoints, int[] yPoints, int nPoints); - - public native void drawRect(int x, int y, int width, int height); - public native void fillRect(int x, int y, int width, int height); - - GdkFontPeer getFontPeer() - { - return (GdkFontPeer) getFont().getPeer(); - } - - native void drawString (GdkFontPeer f, String str, int x, int y); - public void drawString (String str, int x, int y) - { - drawString(getFontPeer(), str, x, y); - } - - - public void drawString (AttributedCharacterIterator ci, int x, int y) - { - throw new Error ("not implemented"); - } - - public void drawRoundRect(int x, int y, int width, int height, - int arcWidth, int arcHeight) - { - if (arcWidth > width) - arcWidth = width; - if (arcHeight > height) - arcHeight = height; - - int xx = x + width - arcWidth; - int yy = y + height - arcHeight; - - drawArc (x, y, arcWidth, arcHeight, 90, 90); - drawArc (xx, y, arcWidth, arcHeight, 0, 90); - drawArc (xx, yy, arcWidth, arcHeight, 270, 90); - drawArc (x, yy, arcWidth, arcHeight, 180, 90); - - int y1 = y + arcHeight / 2; - int y2 = y + height - arcHeight / 2; - drawLine (x, y1, x, y2); - drawLine (x + width, y1, x + width, y2); - - int x1 = x + arcWidth / 2; - int x2 = x + width - arcWidth / 2; - drawLine (x1, y, x2, y); - drawLine (x1, y + height, x2, y + height); - } - - public void fillRoundRect (int x, int y, int width, int height, - int arcWidth, int arcHeight) - { - if (arcWidth > width) - arcWidth = width; - if (arcHeight > height) - arcHeight = height; - - int xx = x + width - arcWidth; - int yy = y + height - arcHeight; - - fillArc (x, y, arcWidth, arcHeight, 90, 90); - fillArc (xx, y, arcWidth, arcHeight, 0, 90); - fillArc (xx, yy, arcWidth, arcHeight, 270, 90); - fillArc (x, yy, arcWidth, arcHeight, 180, 90); - - fillRect (x, y + arcHeight / 2, width, height - arcHeight + 1); - fillRect (x + arcWidth / 2, y, width - arcWidth + 1, height); - } - - public Shape getClip () - { - return getClipBounds (); - } - - public Rectangle getClipBounds () - { - if (clip == null) - return null; - else - return clip.getBounds(); - } - - public Color getColor () - { - return color; - } - - public Font getFont () - { - return font; - } - - public FontMetrics getFontMetrics (Font font) - { - return new GdkFontMetrics (font); - } - - native void setClipRectangle (int x, int y, int width, int height); - - public void setClip (int x, int y, int width, int height) - { - if ((component != null && ! component.isRealized ()) - || clip == null) - return; - - clip.x = x; - clip.y = y; - clip.width = width; - clip.height = height; - - setClipRectangle (x, y, width, height); - } - - public void setClip (Rectangle clip) - { - setClip (clip.x, clip.y, clip.width, clip.height); - } - - public void setClip (Shape clip) - { - if (clip != null) - setClip(clip.getBounds()); - } - - private native void setFGColor(int red, int green, int blue); - - public void setColor (Color c) - { - if (c == null) - color = Color.BLACK; - else - color = c; - - if (xorColor == null) /* paint mode */ - setFGColor (color.getRed (), color.getGreen (), color.getBlue ()); - else /* xor mode */ - setFGColor (color.getRed () ^ xorColor.getRed (), - color.getGreen () ^ xorColor.getGreen (), - color.getBlue () ^ xorColor.getBlue ()); - } - - public void setFont (Font font) - { - this.font = font; - } - - native void setFunction (int gdk_func); - - public void setPaintMode () - { - xorColor = null; - - setFunction (GDK_COPY); - setFGColor (color.getRed (), color.getGreen (), color.getBlue ()); - } - - public void setXORMode (Color c) - { - xorColor = c; - - setFunction (GDK_XOR); - setFGColor (color.getRed () ^ xorColor.getRed (), - color.getGreen () ^ xorColor.getGreen (), - color.getBlue () ^ xorColor.getBlue ()); - } - - public native void translateNative(int x, int y); - - public void translate (int x, int y) - { - if (component != null && ! component.isRealized ()) - return; - - clip.x -= x; - clip.y -= y; - - translateNative (x, y); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java deleted file mode 100644 index 65c4ca2a224..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ /dev/null @@ -1,1449 +0,0 @@ -/* GdkGraphics2D.java -- - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.classpath.Configuration; -import gnu.java.awt.ClasspathToolkit; - -import java.awt.AlphaComposite; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Composite; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.GradientPaint; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Paint; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.TexturePaint; -import java.awt.Toolkit; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.geom.AffineTransform; -import java.awt.geom.Arc2D; -import java.awt.geom.GeneralPath; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.awt.image.ColorModel; -import java.awt.image.CropImageFilter; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferInt; -import java.awt.image.DirectColorModel; -import java.awt.image.FilteredImageSource; -import java.awt.image.ImageObserver; -import java.awt.image.ImagingOpException; -import java.awt.image.MultiPixelPackedSampleModel; -import java.awt.image.Raster; -import java.awt.image.RenderedImage; -import java.awt.image.SampleModel; -import java.awt.image.WritableRaster; -import java.awt.image.renderable.RenderContext; -import java.awt.image.renderable.RenderableImage; -import java.text.AttributedCharacterIterator; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -public class GdkGraphics2D extends Graphics2D -{ - ////////////////////////////////////// - ////// State Management Methods ////// - ////////////////////////////////////// - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - System.loadLibrary("gtkpeer"); - - if (GtkToolkit.useGraphics2D()) - initStaticState(); - } - - static native void initStaticState(); - - private final int native_state = GtkGenericPeer.getUniqueInteger(); - - // These are package-private to avoid accessor methods. - Paint paint; - Stroke stroke; - Color fg; - Color bg; - Shape clip; - AffineTransform transform; - private GtkComponentPeer component; - // This is package-private to avoid an accessor method. - Font font; - private RenderingHints hints; - private BufferedImage bimage; - private boolean pixelConversionRequired; - private int[] pixelBuffer; - // This is package-private to avoid an accessor method. - Composite comp; - private Stack stateStack; - - private native void initState(GtkComponentPeer component); - private native void initState(int width, int height); - private native void initState(int[] pixes, int width, int height); - private native void copyState(GdkGraphics2D g); - public native void dispose(); - private native void cairoSurfaceSetFilter(int filter); - native void connectSignals(GtkComponentPeer component); - - public void finalize() - { - dispose(); - } - - public Graphics create() - { - return new GdkGraphics2D(this); - } - - public Graphics create(int x, int y, int width, int height) - { - return new GdkGraphics2D(width, height); - } - - GdkGraphics2D(GdkGraphics2D g) - { - paint = g.paint; - stroke = g.stroke; - setRenderingHints(g.hints); - - if (g.fg.getAlpha() != -1) - fg = new Color(g.fg.getRed(), g.fg.getGreen(), g.fg.getBlue(), - g.fg.getAlpha()); - else - fg = new Color(g.fg.getRGB()); - - if (g.bg.getAlpha() != -1) - bg = new Color(g.bg.getRed(), g.bg.getGreen(), g.bg.getBlue(), - g.bg.getAlpha()); - else - bg = new Color(g.bg.getRGB()); - - if (g.clip == null) - clip = null; - else - clip = new Rectangle(g.getClipBounds()); - - if (g.transform == null) - transform = new AffineTransform(); - else - transform = new AffineTransform(g.transform); - - font = g.font; - component = g.component; - copyState(g); - - setColor(fg); - setBackground(bg); - setPaint(paint); - setStroke(stroke); - setTransform(transform); - setClip(clip); - stateStack = new Stack(); - } - - GdkGraphics2D(int width, int height) - { - initState(width, height); - - setColor(Color.black); - setBackground(Color.black); - setPaint(getColor()); - setFont(new Font("SansSerif", Font.PLAIN, 12)); - setTransform(new AffineTransform()); - setStroke(new BasicStroke()); - setRenderingHints(getDefaultHints()); - - stateStack = new Stack(); - } - - GdkGraphics2D(GtkComponentPeer component) - { - this.component = component; - - if (component.isRealized()) - initComponentGraphics2D(); - else - connectSignals(component); - } - - void initComponentGraphics2D() - { - initState(component); - - setColor(component.awtComponent.getForeground()); - setBackground(component.awtComponent.getBackground()); - setPaint(getColor()); - setTransform(new AffineTransform()); - setStroke(new BasicStroke()); - setRenderingHints(getDefaultHints()); - setFont(new Font("SansSerif", Font.PLAIN, 12)); - - stateStack = new Stack(); - } - - GdkGraphics2D(BufferedImage bimage) - { - this.bimage = bimage; - this.pixelBuffer = findSimpleIntegerArray(bimage.getColorModel(), - bimage.getRaster()); - if (this.pixelBuffer == null) - { - this.pixelBuffer = new int[bimage.getRaster().getWidth() * bimage.getRaster() - .getHeight()]; - this.pixelConversionRequired = true; - } - else - { - this.pixelConversionRequired = false; - } - - initState(this.pixelBuffer, bimage.getWidth(), bimage.getHeight()); - - setColor(Color.black); - setBackground(Color.black); - setPaint(getColor()); - setFont(new Font("SansSerif", Font.PLAIN, 12)); - setTransform(new AffineTransform()); - setStroke(new BasicStroke()); - setRenderingHints(getDefaultHints()); - - stateStack = new Stack(); - - // draw current buffered image to the pixmap associated - // with it, if the image is not equal to our paint buffer. - if (pixelConversionRequired) - drawImage(bimage, new AffineTransform(1, 0, 0, 1, 0, 0), bg, null); - } - - //////////////////////////////////// - ////// Native Drawing Methods ////// - //////////////////////////////////// - - // GDK drawing methods - private native void gdkDrawDrawable(GdkGraphics2D other, int x, int y); - - // drawing utility methods - private native void drawPixels(int[] pixels, int w, int h, int stride, - double[] i2u); - private native void setTexturePixels(int[] pixels, int w, int h, int stride); - private native void setGradient(double x1, double y1, double x2, double y2, - int r1, int g1, int b1, int a1, int r2, - int g2, int b2, int a2, boolean cyclic); - - // simple passthroughs to cairo - private native void cairoSave(); - private native void cairoRestore(); - private native void cairoSetMatrix(double[] m); - private native void cairoSetOperator(int cairoOperator); - private native void cairoSetRGBColor(double red, double green, double blue); - private native void cairoSetAlpha(double alpha); - private native void cairoSetFillRule(int cairoFillRule); - private native void cairoSetLineWidth(double width); - private native void cairoSetLineCap(int cairoLineCap); - private native void cairoSetLineJoin(int cairoLineJoin); - private native void cairoSetDash(double[] dashes, int ndash, double offset); - - private native void cairoSetMiterLimit(double limit); - private native void cairoNewPath(); - private native void cairoMoveTo(double x, double y); - private native void cairoLineTo(double x, double y); - private native void cairoCurveTo(double x1, double y1, double x2, double y2, - double x3, double y3); - private native void cairoRelMoveTo(double dx, double dy); - private native void cairoRelLineTo(double dx, double dy); - private native void cairoRelCurveTo(double dx1, double dy1, double dx2, - double dy2, double dx3, double dy3); - private native void cairoRectangle(double x, double y, double width, - double height); - private native void cairoClosePath(); - private native void cairoStroke(); - private native void cairoFill(); - private native void cairoClip(); - - ///////////////////////////////////////////// - ////// General Drawing Support Methods ////// - ///////////////////////////////////////////// - - private class DrawState - { - private Paint paint; - private Stroke stroke; - private Color fg; - private Color bg; - private Shape clip; - private AffineTransform transform; - private Font font; - private Composite comp; - - DrawState(GdkGraphics2D g) - { - this.paint = g.paint; - this.stroke = g.stroke; - this.fg = g.fg; - this.bg = g.bg; - this.clip = g.clip; - if (g.transform != null) - this.transform = (AffineTransform) g.transform.clone(); - this.font = g.font; - this.comp = g.comp; - } - - public void restore(GdkGraphics2D g) - { - g.paint = this.paint; - g.stroke = this.stroke; - g.fg = this.fg; - g.bg = this.bg; - g.clip = this.clip; - g.transform = this.transform; - g.font = this.font; - g.comp = this.comp; - } - } - - private void stateSave() - { - stateStack.push(new DrawState(this)); - cairoSave(); - } - - private void stateRestore() - { - ((DrawState) (stateStack.pop())).restore(this); - cairoRestore(); - } - - // Some operations (drawing rather than filling) require that their - // coords be shifted to land on 0.5-pixel boundaries, in order to land on - // "middle of pixel" coordinates and light up complete pixels. - private boolean shiftDrawCalls = false; - - private double shifted(double coord, boolean doShift) - { - if (doShift) - return Math.floor(coord) + 0.5; - else - return coord; - } - - private void walkPath(PathIterator p, boolean doShift) - { - double x = 0; - double y = 0; - double[] coords = new double[6]; - - cairoSetFillRule(p.getWindingRule()); - for (; ! p.isDone(); p.next()) - { - int seg = p.currentSegment(coords); - switch (seg) - { - case PathIterator.SEG_MOVETO: - x = shifted(coords[0], doShift); - y = shifted(coords[1], doShift); - cairoMoveTo(x, y); - break; - case PathIterator.SEG_LINETO: - x = shifted(coords[0], doShift); - y = shifted(coords[1], doShift); - cairoLineTo(x, y); - break; - case PathIterator.SEG_QUADTO: - // splitting a quadratic bezier into a cubic: - // see: http://pfaedit.sourceforge.net/bezier.html - double x1 = x + (2.0 / 3.0) * (shifted(coords[0], doShift) - x); - double y1 = y + (2.0 / 3.0) * (shifted(coords[1], doShift) - y); - - double x2 = x1 + (1.0 / 3.0) * (shifted(coords[2], doShift) - x); - double y2 = y1 + (1.0 / 3.0) * (shifted(coords[3], doShift) - y); - - x = shifted(coords[2], doShift); - y = shifted(coords[3], doShift); - cairoCurveTo(x1, y1, x2, y2, x, y); - break; - case PathIterator.SEG_CUBICTO: - x = shifted(coords[4], doShift); - y = shifted(coords[5], doShift); - cairoCurveTo(shifted(coords[0], doShift), - shifted(coords[1], doShift), - shifted(coords[2], doShift), - shifted(coords[3], doShift), x, y); - break; - case PathIterator.SEG_CLOSE: - cairoClosePath(); - break; - } - } - } - - private Map getDefaultHints() - { - HashMap defaultHints = new HashMap(); - - defaultHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); - - defaultHints.put(RenderingHints.KEY_STROKE_CONTROL, - RenderingHints.VALUE_STROKE_DEFAULT); - - defaultHints.put(RenderingHints.KEY_FRACTIONALMETRICS, - RenderingHints.VALUE_FRACTIONALMETRICS_OFF); - - defaultHints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_OFF); - - defaultHints.put(RenderingHints.KEY_RENDERING, - RenderingHints.VALUE_RENDER_DEFAULT); - - return defaultHints; - } - - public static int[] findSimpleIntegerArray (ColorModel cm, Raster raster) - { - if (cm == null || raster == null) - return null; - - if (! cm.getColorSpace().isCS_sRGB()) - return null; - - if (! (cm instanceof DirectColorModel)) - return null; - - DirectColorModel dcm = (DirectColorModel) cm; - - if (dcm.getRedMask() != 0x00FF0000 || dcm.getGreenMask() != 0x0000FF00 - || dcm.getBlueMask() != 0x000000FF) - return null; - - if (! (raster instanceof WritableRaster)) - return null; - - if (raster.getSampleModel().getDataType() != DataBuffer.TYPE_INT) - return null; - - if (! (raster.getDataBuffer() instanceof DataBufferInt)) - return null; - - DataBufferInt db = (DataBufferInt) raster.getDataBuffer(); - - if (db.getNumBanks() != 1) - return null; - - // Finally, we have determined that this is a single bank, [A]RGB-int - // buffer in sRGB space. It's worth checking all this, because it means - // that cairo can paint directly into the data buffer, which is very - // fast compared to all the normal copying and converting. - - return db.getData(); - } - - private void updateBufferedImage() - { - if (bimage != null && pixelConversionRequired) - { - int height = bimage.getHeight(); - int width = bimage.getWidth(); - for (int y = 0; y < height; ++y) - for (int x = 0; x < width; ++x) - bimage.setRGB(x, y, pixelBuffer[y*width+height]); - } - } - - private boolean drawImage(Image img, AffineTransform xform, - Color bgcolor, ImageObserver obs) - { - if (img == null) - return false; - - if (img instanceof GtkOffScreenImage - && img.getGraphics() instanceof GdkGraphics2D - && (xform == null || xform.getType() == AffineTransform.TYPE_IDENTITY - || xform.getType() == AffineTransform.TYPE_TRANSLATION)) - { - // we are being asked to flush a double buffer from Gdk - GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics(); - gdkDrawDrawable(g2, (int) xform.getTranslateX(), - (int) xform.getTranslateY()); - - updateBufferedImage(); - - return true; - } - else - { - // In this case, xform is an AffineTransform that transforms bounding - // box of the specified image from image space to user space. However - // when we pass this transform to cairo, cairo will use this transform - // to map "user coordinates" to "pixel" coordinates, which is the - // other way around. Therefore to get the "user -> pixel" transform - // that cairo wants from "image -> user" transform that we currently - // have, we will need to invert the transformation matrix. - AffineTransform invertedXform = new AffineTransform(); - - try - { - invertedXform = xform.createInverse(); - if (img instanceof BufferedImage) - { - // draw an image which has actually been loaded - // into memory fully - BufferedImage b = (BufferedImage) img; - return drawRaster(b.getColorModel(), b.getData(), - invertedXform, bgcolor); - } - else - return this.drawImage(GdkPixbufDecoder.createBufferedImage(img - .getSource()), - xform, bgcolor, obs); - } - catch (NoninvertibleTransformException e) - { - throw new ImagingOpException("Unable to invert transform " - + xform.toString()); - } - } - } - - ////////////////////////////////////////////////// - ////// Implementation of Graphics2D Methods ////// - ////////////////////////////////////////////////// - - public void draw(Shape s) - { - if (stroke != null && ! (stroke instanceof BasicStroke)) - { - fill(stroke.createStrokedShape(s)); - return; - } - - cairoNewPath(); - - if (s instanceof Rectangle2D) - { - Rectangle2D r = (Rectangle2D) s; - cairoRectangle(shifted(r.getX(), shiftDrawCalls), - shifted(r.getY(), shiftDrawCalls), r.getWidth(), - r.getHeight()); - } - else - walkPath(s.getPathIterator(null), shiftDrawCalls); - cairoStroke(); - - updateBufferedImage(); - } - - public void fill(Shape s) - { - cairoNewPath(); - if (s instanceof Rectangle2D) - { - Rectangle2D r = (Rectangle2D) s; - cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - else - walkPath(s.getPathIterator(null), false); - - cairoFill(); - - updateBufferedImage(); - } - - public void clip(Shape s) - { - // update it - if (clip == null || s == null) - clip = s; - else if (s instanceof Rectangle2D && clip instanceof Rectangle2D) - { - Rectangle2D r = (Rectangle2D) s; - Rectangle2D curr = (Rectangle2D) clip; - clip = curr.createIntersection(r); - } - else - throw new UnsupportedOperationException(); - - // draw it - if (clip != null) - { - cairoNewPath(); - if (clip instanceof Rectangle2D) - { - Rectangle2D r = (Rectangle2D) clip; - cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - else - walkPath(clip.getPathIterator(null), false); - - // cairoClosePath (); - cairoClip(); - } - } - - public Paint getPaint() - { - return paint; - } - - public AffineTransform getTransform() - { - return (AffineTransform) transform.clone(); - } - - public void setPaint(Paint p) - { - if (paint == null) - return; - - paint = p; - if (paint instanceof Color) - { - setColor((Color) paint); - } - else if (paint instanceof TexturePaint) - { - TexturePaint tp = (TexturePaint) paint; - BufferedImage img = tp.getImage(); - - // map the image to the anchor rectangle - int width = (int) tp.getAnchorRect().getWidth(); - int height = (int) tp.getAnchorRect().getHeight(); - - double scaleX = width / (double) img.getWidth(); - double scaleY = width / (double) img.getHeight(); - - AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0); - AffineTransformOp op = new AffineTransformOp(at, getRenderingHints()); - BufferedImage texture = op.filter(img, null); - int[] pixels = texture.getRGB(0, 0, width, height, null, 0, width); - setTexturePixels(pixels, width, height, width); - } - else if (paint instanceof GradientPaint) - { - GradientPaint gp = (GradientPaint) paint; - Point2D p1 = gp.getPoint1(); - Point2D p2 = gp.getPoint2(); - Color c1 = gp.getColor1(); - Color c2 = gp.getColor2(); - setGradient(p1.getX(), p1.getY(), p2.getX(), p2.getY(), c1.getRed(), - c1.getGreen(), c1.getBlue(), c1.getAlpha(), c2.getRed(), - c2.getGreen(), c2.getBlue(), c2.getAlpha(), gp.isCyclic()); - } - else - throw new java.lang.UnsupportedOperationException(); - } - - public void setTransform(AffineTransform tx) - { - transform = tx; - if (transform != null) - { - double[] m = new double[6]; - transform.getMatrix(m); - cairoSetMatrix(m); - } - } - - public void transform(AffineTransform tx) - { - if (transform == null) - transform = new AffineTransform(tx); - else - transform.concatenate(tx); - setTransform(transform); - if (clip != null) - { - // FIXME: this should actuall try to transform the shape - // rather than degrade to bounds. - Rectangle2D r = clip.getBounds2D(); - double[] coords = new double[] - { - r.getX(), r.getY(), r.getX() + r.getWidth(), - r.getY() + r.getHeight() - }; - try - { - tx.createInverse().transform(coords, 0, coords, 0, 2); - r.setRect(coords[0], coords[1], coords[2] - coords[0], - coords[3] - coords[1]); - clip = r; - } - catch (java.awt.geom.NoninvertibleTransformException e) - { - } - } - } - - public void rotate(double theta) - { - transform(AffineTransform.getRotateInstance(theta)); - } - - public void rotate(double theta, double x, double y) - { - transform(AffineTransform.getRotateInstance(theta, x, y)); - } - - public void scale(double sx, double sy) - { - transform(AffineTransform.getScaleInstance(sx, sy)); - } - - public void translate(double tx, double ty) - { - transform(AffineTransform.getTranslateInstance(tx, ty)); - } - - public void translate(int x, int y) - { - translate((double) x, (double) y); - } - - public void shear(double shearX, double shearY) - { - transform(AffineTransform.getShearInstance(shearX, shearY)); - } - - public Stroke getStroke() - { - return stroke; - } - - public void setStroke(Stroke st) - { - stroke = st; - if (stroke instanceof BasicStroke) - { - BasicStroke bs = (BasicStroke) stroke; - cairoSetLineCap(bs.getEndCap()); - cairoSetLineWidth(bs.getLineWidth()); - cairoSetLineJoin(bs.getLineJoin()); - cairoSetMiterLimit(bs.getMiterLimit()); - float[] dashes = bs.getDashArray(); - if (dashes != null) - { - double[] double_dashes = new double[dashes.length]; - for (int i = 0; i < dashes.length; i++) - double_dashes[i] = dashes[i]; - cairoSetDash(double_dashes, double_dashes.length, - (double) bs.getDashPhase()); - } - } - } - - //////////////////////////////////////////////// - ////// Implementation of Graphics Methods ////// - //////////////////////////////////////////////// - - public void setPaintMode() - { - setComposite(java.awt.AlphaComposite.SrcOver); - } - - public void setXORMode(Color c) - { - setComposite(new gnu.java.awt.BitwiseXORComposite(c)); - } - - public void setColor(Color c) - { - if (c == null) - c = Color.BLACK; - - fg = c; - paint = c; - cairoSetRGBColor(fg.getRed() / 255.0, fg.getGreen() / 255.0, - fg.getBlue() / 255.0); - cairoSetAlpha((fg.getAlpha() & 255) / 255.0); - } - - public Color getColor() - { - return fg; - } - - public void clipRect(int x, int y, int width, int height) - { - clip(new Rectangle(x, y, width, height)); - } - - public Shape getClip() - { - return clip.getBounds2D(); //getClipInDevSpace(); - } - - public Rectangle getClipBounds() - { - if (clip == null) - return null; - else - return clip.getBounds(); - } - - protected Rectangle2D getClipInDevSpace() - { - Rectangle2D uclip = clip.getBounds2D(); - if (transform == null) - return uclip; - else - { - Point2D pos = transform.transform(new Point2D.Double(uclip.getX(), - uclip.getY()), - (Point2D) null); - Point2D extent = transform.deltaTransform(new Point2D.Double(uclip - .getWidth(), - uclip - .getHeight()), - (Point2D) null); - return new Rectangle2D.Double(pos.getX(), pos.getY(), extent.getX(), - extent.getY()); - } - } - - public void setClip(int x, int y, int width, int height) - { - setClip(new Rectangle2D.Double((double) x, (double) y, (double) width, - (double) height)); - } - - public void setClip(Shape s) - { - clip = s; - if (s != null) - { - cairoNewPath(); - if (s instanceof Rectangle2D) - { - Rectangle2D r = (Rectangle2D) s; - cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - else - walkPath(s.getPathIterator(null), false); - - // cairoClosePath (); - cairoClip(); - } - } - - private static BasicStroke draw3DRectStroke = new BasicStroke(); - - public void draw3DRect(int x, int y, int width, int height, boolean raised) - { - Stroke tmp = stroke; - setStroke(draw3DRectStroke); - super.draw3DRect(x, y, width, height, raised); - setStroke(tmp); - updateBufferedImage(); - } - - public void fill3DRect(int x, int y, int width, int height, boolean raised) - { - Stroke tmp = stroke; - setStroke(draw3DRectStroke); - super.fill3DRect(x, y, width, height, raised); - setStroke(tmp); - updateBufferedImage(); - } - - public void drawRect(int x, int y, int width, int height) - { - draw(new Rectangle(x, y, width, height)); - } - - public void fillRect(int x, int y, int width, int height) - { - cairoNewPath(); - cairoRectangle(x, y, width, height); - cairoFill(); - } - - public void clearRect(int x, int y, int width, int height) - { - cairoSetRGBColor(bg.getRed() / 255.0, bg.getGreen() / 255.0, - bg.getBlue() / 255.0); - cairoSetAlpha(1.0); - cairoNewPath(); - cairoRectangle(x, y, width, height); - cairoFill(); - setColor(fg); - - updateBufferedImage(); - } - - public void setBackground(Color c) - { - bg = c; - } - - public Color getBackground() - { - return bg; - } - - private void doPolygon(int[] xPoints, int[] yPoints, int nPoints, - boolean close, boolean fill) - { - if (nPoints < 1) - return; - GeneralPath gp = new GeneralPath(PathIterator.WIND_EVEN_ODD); - gp.moveTo((float) xPoints[0], (float) yPoints[0]); - for (int i = 1; i < nPoints; i++) - gp.lineTo((float) xPoints[i], (float) yPoints[i]); - - if (close) - gp.closePath(); - - Shape sh = gp; - if (fill == false && stroke != null && ! (stroke instanceof BasicStroke)) - { - sh = stroke.createStrokedShape(gp); - fill = true; - } - - if (fill) - fill(sh); - else - draw(sh); - } - - public void drawLine(int x1, int y1, int x2, int y2) - { - int[] xp = new int[2]; - int[] yp = new int[2]; - - xp[0] = x1; - xp[1] = x2; - yp[0] = y1; - yp[1] = y2; - - doPolygon(xp, yp, 2, false, false); - } - - public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) - { - doPolygon(xPoints, yPoints, nPoints, true, true); - } - - public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) - { - doPolygon(xPoints, yPoints, nPoints, true, false); - } - - public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) - { - doPolygon(xPoints, yPoints, nPoints, false, false); - } - - private boolean drawRaster(ColorModel cm, Raster r, - AffineTransform imageToUser, Color bgcolor) - { - if (r == null) - return false; - - SampleModel sm = r.getSampleModel(); - DataBuffer db = r.getDataBuffer(); - - if (db == null || sm == null) - return false; - - if (cm == null) - cm = ColorModel.getRGBdefault(); - - double[] i2u = new double[6]; - if (imageToUser != null) - imageToUser.getMatrix(i2u); - else - { - i2u[0] = 1; - i2u[1] = 0; - i2u[2] = 0; - i2u[3] = 1; - i2u[4] = 0; - i2u[5] = 0; - } - - int[] pixels = findSimpleIntegerArray(cm, r); - - if (pixels == null) - { - // FIXME: I don't think this code will work correctly with a non-RGB - // MultiPixelPackedSampleModel. Although this entire method should - // probably be rewritten to better utilize Cairo's different supported - // data formats. - if (sm instanceof MultiPixelPackedSampleModel) - { - pixels = r.getPixels(0, 0, r.getWidth(), r.getHeight(), pixels); - for (int i = 0; i < pixels.length; i++) - pixels[i] = cm.getRGB(pixels[i]); - } - else - { - pixels = new int[r.getWidth() * r.getHeight()]; - for (int i = 0; i < pixels.length; i++) - pixels[i] = cm.getRGB(db.getElem(i)); - } - } - - // Change all transparent pixels in the image to the specified bgcolor, - // or (if there's no alpha) fill in an alpha channel so that it paints - // correctly. - if (cm.hasAlpha()) - { - if (bgcolor != null && cm.hasAlpha()) - for (int i = 0; i < pixels.length; i++) - { - if (cm.getAlpha(pixels[i]) == 0) - pixels[i] = bgcolor.getRGB(); - } - } - else - for (int i = 0; i < pixels.length; i++) - pixels[i] |= 0xFF000000; - - drawPixels(pixels, r.getWidth(), r.getHeight(), r.getWidth(), i2u); - - updateBufferedImage(); - - return true; - } - - public void drawRenderedImage(RenderedImage image, AffineTransform xform) - { - drawRaster(image.getColorModel(), image.getData(), xform, bg); - } - - public void drawRenderableImage(RenderableImage image, AffineTransform xform) - { - drawRenderedImage(image.createRendering(new RenderContext(xform)), xform); - } - - public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) - { - return drawImage(img, xform, bg, obs); - } - - public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y) - { - Image filtered = op.filter(image, null); - drawImage(filtered, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, null); - } - - public boolean drawImage(Image img, int x, int y, ImageObserver observer) - { - return drawImage(img, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, - observer); - } - - /////////////////////////////////////////////// - ////// Unimplemented Stubs and Overloads ////// - /////////////////////////////////////////////// - - public boolean hit(Rectangle rect, Shape text, boolean onStroke) - { - throw new java.lang.UnsupportedOperationException(); - } - - public GraphicsConfiguration getDeviceConfiguration() - { - throw new java.lang.UnsupportedOperationException(); - } - - public void setComposite(Composite comp) - { - this.comp = comp; - - if (comp instanceof AlphaComposite) - { - AlphaComposite a = (AlphaComposite) comp; - cairoSetOperator(a.getRule()); - Color c = getColor(); - setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), - (int) (a.getAlpha() * ((float) c.getAlpha())))); - } - else - throw new java.lang.UnsupportedOperationException(); - } - - public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) - { - hints.put(hintKey, hintValue); - - if (hintKey.equals(RenderingHints.KEY_INTERPOLATION) - || hintKey.equals(RenderingHints.KEY_ALPHA_INTERPOLATION)) - { - if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) - cairoSurfaceSetFilter(0); - - else if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) - cairoSurfaceSetFilter(1); - - else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) - cairoSurfaceSetFilter(2); - - else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) - cairoSurfaceSetFilter(3); - - else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) - cairoSurfaceSetFilter(4); - } - - shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) - || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); - } - - public Object getRenderingHint(RenderingHints.Key hintKey) - { - return hints.get(hintKey); - } - - public void setRenderingHints(Map hints) - { - this.hints = new RenderingHints(getDefaultHints()); - this.hints.add(new RenderingHints(hints)); - - if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) - { - if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) - cairoSurfaceSetFilter(0); - - else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) - cairoSurfaceSetFilter(1); - } - - if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) - { - if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) - cairoSurfaceSetFilter(2); - - else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) - cairoSurfaceSetFilter(3); - - else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) - cairoSurfaceSetFilter(4); - } - - shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) - || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); - } - - public void addRenderingHints(Map hints) - { - this.hints.add(new RenderingHints(hints)); - } - - public RenderingHints getRenderingHints() - { - return hints; - } - - public Composite getComposite() - { - if (comp == null) - return AlphaComposite.SrcOver; - else - return comp; - } - - public FontRenderContext getFontRenderContext() - { - return new FontRenderContext(transform, true, true); - } - - public void copyArea(int x, int y, int width, int height, int dx, int dy) - { - throw new java.lang.UnsupportedOperationException(); - } - - public void drawArc(int x, int y, int width, int height, int startAngle, - int arcAngle) - { - draw(new Arc2D.Double((double) x, (double) y, (double) width, - (double) height, (double) startAngle, - (double) arcAngle, Arc2D.OPEN)); - } - - public boolean drawImage(Image img, int x, int y, Color bgcolor, - ImageObserver observer) - { - return drawImage(img, x, y, img.getWidth(observer), - img.getHeight(observer), bgcolor, observer); - } - - public boolean drawImage(Image img, int x, int y, int width, int height, - Color bgcolor, ImageObserver observer) - { - double scaleX = width / (double) img.getWidth(observer); - double scaleY = height / (double) img.getHeight(observer); - - return drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), - bgcolor, observer); - } - - public boolean drawImage(Image img, int x, int y, int width, int height, - ImageObserver observer) - { - return drawImage(img, x, y, width, height, bg, observer); - } - - public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, - int sx1, int sy1, int sx2, int sy2, Color bgcolor, - ImageObserver observer) - { - if (img == null) - return false; - - Image subImage; - - int sourceWidth = sx2 - sx1; - int sourceHeight = sy2 - sy1; - - int destWidth = dx2 - dx1; - int destHeight = dy2 - dy1; - - double scaleX = destWidth / (double) sourceWidth; - double scaleY = destHeight / (double) sourceHeight; - - // Get the subimage of the source enclosed in the - // rectangle specified by sx1, sy1, sx2, sy2 - - if (img instanceof BufferedImage) - { - BufferedImage b = (BufferedImage) img; - subImage = b.getSubimage(sx1, sy1, sx2, sy2); - } - else - { - // FIXME: This code currently doesn't work. Null Pointer - // exception is thrown in this case. This happens - // because img.getSource() always returns null, since source gets - // never initialized when it is created with the help of - // createImage(int width, int height). - CropImageFilter filter = new CropImageFilter(sx1, sx2, sx2, sy2); - FilteredImageSource src = new FilteredImageSource(img.getSource(), - filter); - - subImage = Toolkit.getDefaultToolkit().createImage(src); - } - - return drawImage(subImage, - new AffineTransform(scaleX, 0, 0, scaleY, dx1, dy1), - bgcolor, observer); - } - - public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, - int sx1, int sy1, int sx2, int sy2, - ImageObserver observer) - { - return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bg, observer); - } - - public void drawOval(int x, int y, int width, int height) - { - drawArc(x, y, width, height, 0, 360); - } - - public void drawRoundRect(int x, int y, int width, int height, int arcWidth, - int arcHeight) - { - if (arcWidth > width) - arcWidth = width; - if (arcHeight > height) - arcHeight = height; - - int xx = x + width - arcWidth; - int yy = y + height - arcHeight; - - drawArc(x, y, arcWidth, arcHeight, 90, 90); - drawArc(xx, y, arcWidth, arcHeight, 0, 90); - drawArc(xx, yy, arcWidth, arcHeight, 270, 90); - drawArc(x, yy, arcWidth, arcHeight, 180, 90); - - int y1 = y + arcHeight / 2; - int y2 = y + height - arcHeight / 2; - drawLine(x, y1, x, y2); - drawLine(x + width, y1, x + width, y2); - - int x1 = x + arcWidth / 2; - int x2 = x + width - arcWidth / 2; - drawLine(x1, y, x2, y); - drawLine(x1, y + height, x2, y + height); - } - - // these are the most accelerated painting paths - native void cairoDrawGlyphVector(GdkFontPeer font, - float x, float y, int n, - int[] codes, float[] positions); - - native void cairoDrawGdkTextLayout(GdkTextLayout gl, - float x, float y); - - GdkFontPeer getFontPeer() - { - return (GdkFontPeer) getFont().getPeer(); - } - - public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) - { - cairoDrawGdkTextLayout (gl, x, y); - updateBufferedImage (); - } - - public void drawString(String str, float x, float y) - { - drawGlyphVector(getFont().createGlyphVector(null, str), x, y); - updateBufferedImage (); - } - - public void drawString(String str, int x, int y) - { - drawString (str, (float) x, (float) y); - } - - public void drawString(AttributedCharacterIterator ci, int x, int y) - { - drawString (ci, (float) x, (float) y); - } - - public void drawGlyphVector(GlyphVector gv, float x, float y) - { - int n = gv.getNumGlyphs (); - int[] codes = gv.getGlyphCodes (0, n, null); - float[] positions = gv.getGlyphPositions (0, n, null); - - setFont (gv.getFont ()); - cairoDrawGlyphVector (getFontPeer(), x, y, n, codes, positions); - updateBufferedImage (); - } - - public void drawString(AttributedCharacterIterator ci, float x, float y) - { - GlyphVector gv = getFont().createGlyphVector(getFontRenderContext(), ci); - drawGlyphVector(gv, x, y); - } - - public void fillArc(int x, int y, int width, int height, int startAngle, - int arcAngle) - { - fill(new Arc2D.Double((double) x, (double) y, (double) width, - (double) height, (double) startAngle, - (double) arcAngle, Arc2D.OPEN)); - } - - public void fillOval(int x, int y, int width, int height) - { - fillArc(x, y, width, height, 0, 360); - } - - public void fillRoundRect(int x, int y, int width, int height, int arcWidth, - int arcHeight) - { - if (arcWidth > width) - arcWidth = width; - if (arcHeight > height) - arcHeight = height; - - int xx = x + width - arcWidth; - int yy = y + height - arcHeight; - - fillArc(x, y, arcWidth, arcHeight, 90, 90); - fillArc(xx, y, arcWidth, arcHeight, 0, 90); - fillArc(xx, yy, arcWidth, arcHeight, 270, 90); - fillArc(x, yy, arcWidth, arcHeight, 180, 90); - - fillRect(x, y + arcHeight / 2, width, height - arcHeight + 1); - fillRect(x + arcWidth / 2, y, width - arcWidth + 1, height); - } - - public Font getFont() - { - if (font == null) - return new Font("SansSerif", Font.PLAIN, 12); - return font; - } - - // Until such time as pango is happy to talk directly to cairo, we - // actually need to redirect some calls from the GtkFontPeer and - // GtkFontMetrics into the drawing kit and ask cairo ourselves. - - static native void releasePeerGraphicsResource(GdkFontPeer f); - - public FontMetrics getFontMetrics() - { - return getFontMetrics(getFont()); - } - - public FontMetrics getFontMetrics(Font f) - { - // the reason we go via the toolkit here is to try to get - // a cached object. the toolkit keeps such a cache. - return Toolkit.getDefaultToolkit().getFontMetrics(f); - } - - public void setFont(Font f) - { - if (f.getPeer() instanceof GdkFontPeer) - font = f; - else - font = - ((ClasspathToolkit)(Toolkit.getDefaultToolkit())) - .getFont(f.getName(), f.getAttributes()); - } - - public String toString() - { - return (getClass().getName() - + "[font=" + getFont().toString() - + ",color=" + fg.toString() - + "]"); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java deleted file mode 100644 index bfad87acac0..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java +++ /dev/null @@ -1,138 +0,0 @@ -/* GdkGraphicsConfiguration.java -- describes characteristics of graphics - Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.peer.gtk; - -import java.awt.BufferCapabilities; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.ImageCapabilities; -import java.awt.Rectangle; - -import java.awt.geom.AffineTransform; - -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.VolatileImage; - -public class GdkGraphicsConfiguration - extends GraphicsConfiguration -{ - GdkScreenGraphicsDevice gdkScreenGraphicsDevice; - ColorModel cm; - Rectangle bounds; - - public GtkToolkit getToolkit() - { - return gdkScreenGraphicsDevice.getToolkit(); - } - - public GdkGraphicsConfiguration(GdkScreenGraphicsDevice dev) - { - this.gdkScreenGraphicsDevice = dev; - cm = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getColorModel(); - bounds = getToolkit().getBounds(); - } - - public GraphicsDevice getDevice() - { - return gdkScreenGraphicsDevice; - } - - public BufferedImage createCompatibleImage(int w, int h) - { - return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - } - - public BufferedImage createCompatibleImage(int w, int h, - int transparency) - { - return createCompatibleImage(w, h); - } - - public VolatileImage createCompatibleVolatileImage(int w, int h) - { - return new GtkVolatileImage(w, h); - } - - public VolatileImage createCompatibleVolatileImage(int w, int h, - ImageCapabilities caps) - throws java.awt.AWTException - { - return new GtkVolatileImage(w, h, caps); - } - - public ColorModel getColorModel() - { - return cm; - } - - public ColorModel getColorModel(int transparency) - { - return getColorModel(); - } - - public AffineTransform getDefaultTransform() - { - // FIXME: extract the GDK DPI information here. - return new AffineTransform(); - } - - public AffineTransform getNormalizingTransform() - { - // FIXME: extract the GDK DPI information here. - return new AffineTransform(); - } - - public Rectangle getBounds() - { - return bounds; - } - - public BufferCapabilities getBufferCapabilities() - { - return new BufferCapabilities(getImageCapabilities(), - getImageCapabilities(), - BufferCapabilities.FlipContents.UNDEFINED); - } - - public ImageCapabilities getImageCapabilities() - { - return new ImageCapabilities(false); - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java deleted file mode 100644 index 4f9d1c27af6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java +++ /dev/null @@ -1,107 +0,0 @@ -/* GdkGraphicsEnvironment.java -- information about the graphics environment - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; -import java.awt.image.BufferedImage; -import java.util.Locale; - -public class GdkGraphicsEnvironment extends GraphicsEnvironment -{ - GtkToolkit gtkToolkit; - - public GtkToolkit getToolkit() - { - return gtkToolkit; - } - - public GdkGraphicsEnvironment (GtkToolkit tk) - { - super(); - gtkToolkit = tk; - } - - public GraphicsDevice[] getScreenDevices () - { - // FIXME: Support multiple screens, since GDK can. - return new GraphicsDevice[] { new GdkScreenGraphicsDevice (this) }; - } - - public GraphicsDevice getDefaultScreenDevice () - { - if (GraphicsEnvironment.isHeadless ()) - throw new HeadlessException (); - - return new GdkScreenGraphicsDevice (this); - } - - public Graphics2D createGraphics (BufferedImage image) - { - return new GdkGraphics2D (image); - } - - private native int nativeGetNumFontFamilies(); - private native void nativeGetFontFamilies(String[] family_names); - - public Font[] getAllFonts () - { - throw new java.lang.UnsupportedOperationException (); - } - - public String[] getAvailableFontFamilyNames () - { - String[] family_names; - int array_size; - - array_size = nativeGetNumFontFamilies(); - family_names = new String[array_size]; - - nativeGetFontFamilies(family_names); - return family_names; - } - - public String[] getAvailableFontFamilyNames (Locale l) - { - throw new java.lang.UnsupportedOperationException (); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java b/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java deleted file mode 100644 index a3d82f62f87..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java +++ /dev/null @@ -1,675 +0,0 @@ -/* GdkPixbufDecoder.java -- Image data decoding object - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.classpath.Configuration; - -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.DirectColorModel; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageProducer; -import java.awt.image.Raster; -import java.awt.image.RenderedImage; -import java.io.DataOutput; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Locale; -import java.util.Vector; - -import javax.imageio.IIOImage; -import javax.imageio.ImageReadParam; -import javax.imageio.ImageReader; -import javax.imageio.ImageTypeSpecifier; -import javax.imageio.ImageWriteParam; -import javax.imageio.ImageWriter; -import javax.imageio.metadata.IIOMetadata; -import javax.imageio.spi.IIORegistry; -import javax.imageio.spi.ImageReaderSpi; -import javax.imageio.spi.ImageWriterSpi; -import javax.imageio.stream.ImageInputStream; -import javax.imageio.stream.ImageOutputStream; - -public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder -{ - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("gtkpeer"); - } - initStaticState (); - } - - static native void initStaticState(); - private final int native_state = GtkGenericPeer.getUniqueInteger (); - private boolean initialized = false; - - // the current set of ImageConsumers for this decoder - Vector curr; - - // interface to GdkPixbuf - native void initState (); - native void pumpBytes (byte[] bytes, int len); - native void finish (); - static native void streamImage(int[] bytes, String format, int width, int height, boolean hasAlpha, DataOutput sink); - - // gdk-pixbuf provids data in RGBA format - static final ColorModel cm = new DirectColorModel (32, 0xff000000, - 0x00ff0000, - 0x0000ff00, - 0x000000ff); - public GdkPixbufDecoder (InputStream in) - { - super (in); - } - - public GdkPixbufDecoder (String filename) - { - super (filename); - } - - public GdkPixbufDecoder (URL url) - { - super (url); - } - - public GdkPixbufDecoder (byte[] imagedata, int imageoffset, int imagelength) - { - super (imagedata, imageoffset, imagelength); - } - - // called back by native side - void areaPrepared (int width, int height) - { - - if (curr == null) - return; - - for (int i = 0; i < curr.size (); i++) - { - ImageConsumer ic = (ImageConsumer) curr.elementAt (i); - ic.setDimensions (width, height); - ic.setColorModel (cm); - ic.setHints (ImageConsumer.RANDOMPIXELORDER); - } - } - - // called back by native side - void areaUpdated (int x, int y, int width, int height, - int pixels[], int scansize) - { - if (curr == null) - return; - - for (int i = 0; i < curr.size (); i++) - { - ImageConsumer ic = (ImageConsumer) curr.elementAt (i); - ic.setPixels (x, y, width, height, cm, pixels, 0, scansize); - } - } - - // called from an async image loader of one sort or another, this method - // repeatedly reads bytes from the input stream and passes them through a - // GdkPixbufLoader using the native method pumpBytes. pumpBytes in turn - // decodes the image data and calls back areaPrepared and areaUpdated on - // this object, feeding back decoded pixel blocks, which we pass to each - // of the ImageConsumers in the provided Vector. - - public void produce (Vector v, InputStream is) throws IOException - { - curr = v; - - byte bytes[] = new byte[4096]; - int len = 0; - initState(); - while ((len = is.read (bytes)) != -1) - pumpBytes (bytes, len); - - for (int i = 0; i < curr.size (); i++) - { - ImageConsumer ic = (ImageConsumer) curr.elementAt (i); - ic.imageComplete (ImageConsumer.STATICIMAGEDONE); - } - - curr = null; - } - - public void finalize() - { - finish(); - } - - - public static class ImageFormatSpec - { - public String name; - public boolean writable = false; - public ArrayList mimeTypes = new ArrayList(); - public ArrayList extensions = new ArrayList(); - - public ImageFormatSpec(String name, boolean writable) - { - this.name = name; - this.writable = writable; - } - - public synchronized void addMimeType(String m) - { - mimeTypes.add(m); - } - - public synchronized void addExtension(String e) - { - extensions.add(e); - } - } - - static ArrayList imageFormatSpecs; - - public static ImageFormatSpec registerFormat(String name, boolean writable) - { - ImageFormatSpec ifs = new ImageFormatSpec(name, writable); - synchronized(GdkPixbufDecoder.class) - { - if (imageFormatSpecs == null) - imageFormatSpecs = new ArrayList(); - imageFormatSpecs.add(ifs); - } - return ifs; - } - - static String[] getFormatNames(boolean writable) - { - ArrayList names = new ArrayList(); - synchronized (imageFormatSpecs) - { - Iterator i = imageFormatSpecs.iterator(); - while (i.hasNext()) - { - ImageFormatSpec ifs = (ImageFormatSpec) i.next(); - if (writable && !ifs.writable) - continue; - names.add(ifs.name); - - /* - * In order to make the filtering code work, we need to register - * this type under every "format name" likely to be used as a synonym. - * This generally means "all the extensions people might use". - */ - - Iterator j = ifs.extensions.iterator(); - while (j.hasNext()) - names.add((String) j.next()); - } - } - Object[] objs = names.toArray(); - String[] strings = new String[objs.length]; - for (int i = 0; i < objs.length; ++i) - strings[i] = (String) objs[i]; - return strings; - } - - static String[] getFormatExtensions(boolean writable) - { - ArrayList extensions = new ArrayList(); - synchronized (imageFormatSpecs) - { - Iterator i = imageFormatSpecs.iterator(); - while (i.hasNext()) - { - ImageFormatSpec ifs = (ImageFormatSpec) i.next(); - if (writable && !ifs.writable) - continue; - Iterator j = ifs.extensions.iterator(); - while (j.hasNext()) - extensions.add((String) j.next()); - } - } - Object[] objs = extensions.toArray(); - String[] strings = new String[objs.length]; - for (int i = 0; i < objs.length; ++i) - strings[i] = (String) objs[i]; - return strings; - } - - static String[] getFormatMimeTypes(boolean writable) - { - ArrayList mimeTypes = new ArrayList(); - synchronized (imageFormatSpecs) - { - Iterator i = imageFormatSpecs.iterator(); - while (i.hasNext()) - { - ImageFormatSpec ifs = (ImageFormatSpec) i.next(); - if (writable && !ifs.writable) - continue; - Iterator j = ifs.mimeTypes.iterator(); - while (j.hasNext()) - mimeTypes.add((String) j.next()); - } - } - Object[] objs = mimeTypes.toArray(); - String[] strings = new String[objs.length]; - for (int i = 0; i < objs.length; ++i) - strings[i] = (String) objs[i]; - return strings; - } - - - static String findFormatName(Object ext, boolean needWritable) - { - if (ext == null) - throw new IllegalArgumentException("extension is null"); - - if (!(ext instanceof String)) - throw new IllegalArgumentException("extension is not a string"); - - String str = (String) ext; - - Iterator i = imageFormatSpecs.iterator(); - while (i.hasNext()) - { - ImageFormatSpec ifs = (ImageFormatSpec) i.next(); - - if (needWritable && !ifs.writable) - continue; - - if (ifs.name.equals(str)) - return str; - - Iterator j = ifs.extensions.iterator(); - while (j.hasNext()) - { - String extension = (String)j.next(); - if (extension.equals(str)) - return ifs.name; - } - - j = ifs.mimeTypes.iterator(); - while (j.hasNext()) - { - String mimeType = (String)j.next(); - if (mimeType.equals(str)) - return ifs.name; - } - } - throw new IllegalArgumentException("unknown extension '" + str + "'"); - } - - private static GdkPixbufReaderSpi readerSpi; - private static GdkPixbufWriterSpi writerSpi; - - public static synchronized GdkPixbufReaderSpi getReaderSpi() - { - if (readerSpi == null) - readerSpi = new GdkPixbufReaderSpi(); - return readerSpi; - } - - public static synchronized GdkPixbufWriterSpi getWriterSpi() - { - if (writerSpi == null) - writerSpi = new GdkPixbufWriterSpi(); - return writerSpi; - } - - public static void registerSpis(IIORegistry reg) - { - reg.registerServiceProvider(getReaderSpi(), ImageReaderSpi.class); - reg.registerServiceProvider(getWriterSpi(), ImageWriterSpi.class); - } - - public static class GdkPixbufWriterSpi extends ImageWriterSpi - { - public GdkPixbufWriterSpi() - { - super("GdkPixbuf", "2.x", - GdkPixbufDecoder.getFormatNames(true), - GdkPixbufDecoder.getFormatExtensions(true), - GdkPixbufDecoder.getFormatMimeTypes(true), - "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufWriter", - new Class[] { ImageOutputStream.class }, - new String[] { "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufReaderSpi" }, - false, null, null, null, null, - false, null, null, null, null); - } - - public boolean canEncodeImage(ImageTypeSpecifier ts) - { - return true; - } - - public ImageWriter createWriterInstance(Object ext) - { - return new GdkPixbufWriter(this, ext); - } - - public String getDescription(java.util.Locale loc) - { - return "GdkPixbuf Writer SPI"; - } - - } - - public static class GdkPixbufReaderSpi extends ImageReaderSpi - { - public GdkPixbufReaderSpi() - { - super("GdkPixbuf", "2.x", - GdkPixbufDecoder.getFormatNames(false), - GdkPixbufDecoder.getFormatExtensions(false), - GdkPixbufDecoder.getFormatMimeTypes(false), - "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufReader", - new Class[] { ImageInputStream.class }, - new String[] { "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufWriterSpi" }, - false, null, null, null, null, - false, null, null, null, null); - } - - public boolean canDecodeInput(Object obj) - { - return true; - } - - public ImageReader createReaderInstance(Object ext) - { - return new GdkPixbufReader(this, ext); - } - - public String getDescription(Locale loc) - { - return "GdkPixbuf Reader SPI"; - } - } - - private static class GdkPixbufWriter - extends ImageWriter - { - String ext; - public GdkPixbufWriter(GdkPixbufWriterSpi ownerSpi, Object ext) - { - super(ownerSpi); - this.ext = findFormatName(ext, true); - } - - public IIOMetadata convertImageMetadata (IIOMetadata inData, - ImageTypeSpecifier imageType, - ImageWriteParam param) - { - return null; - } - - public IIOMetadata convertStreamMetadata (IIOMetadata inData, - ImageWriteParam param) - { - return null; - } - - public IIOMetadata getDefaultImageMetadata (ImageTypeSpecifier imageType, - ImageWriteParam param) - { - return null; - } - - public IIOMetadata getDefaultStreamMetadata (ImageWriteParam param) - { - return null; - } - - public void write (IIOMetadata streamMetadata, IIOImage i, ImageWriteParam param) - throws IOException - { - RenderedImage image = i.getRenderedImage(); - Raster ras = image.getData(); - int width = ras.getWidth(); - int height = ras.getHeight(); - ColorModel model = image.getColorModel(); - int[] pixels = GdkGraphics2D.findSimpleIntegerArray (image.getColorModel(), ras); - - if (pixels == null) - { - BufferedImage img = new BufferedImage(width, height, - (model != null && model.hasAlpha() ? - BufferedImage.TYPE_INT_ARGB - : BufferedImage.TYPE_INT_RGB)); - int[] pix = new int[4]; - for (int y = 0; y < height; ++y) - for (int x = 0; x < width; ++x) - img.setRGB(x, y, model.getRGB(ras.getPixel(x, y, pix))); - pixels = GdkGraphics2D.findSimpleIntegerArray (img.getColorModel(), - img.getRaster()); - model = img.getColorModel(); - } - - processImageStarted(1); - streamImage(pixels, this.ext, width, height, model.hasAlpha(), - (DataOutput) this.getOutput()); - processImageComplete(); - } - } - - private static class GdkPixbufReader - extends ImageReader - implements ImageConsumer - { - // ImageConsumer parts - GdkPixbufDecoder dec; - BufferedImage bufferedImage; - ColorModel defaultModel; - int width; - int height; - String ext; - - public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext) - { - super(ownerSpi); - this.ext = findFormatName(ext, false); - } - - public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext, GdkPixbufDecoder d) - { - this(ownerSpi, ext); - dec = d; - } - - public void setDimensions(int w, int h) - { - processImageStarted(1); - width = w; - height = h; - } - - public void setProperties(Hashtable props) {} - - public void setColorModel(ColorModel model) - { - defaultModel = model; - } - - public void setHints(int flags) {} - - public void setPixels(int x, int y, int w, int h, - ColorModel model, byte[] pixels, - int offset, int scansize) - { - } - - public void setPixels(int x, int y, int w, int h, - ColorModel model, int[] pixels, - int offset, int scansize) - { - if (model == null) - model = defaultModel; - - if (bufferedImage == null) - { - bufferedImage = new BufferedImage (width, height, (model != null && model.hasAlpha() ? - BufferedImage.TYPE_INT_ARGB - : BufferedImage.TYPE_INT_RGB)); - } - - int pixels2[]; - if (model != null) - { - pixels2 = new int[pixels.length]; - for (int yy = 0; yy < h; yy++) - for (int xx = 0; xx < w; xx++) - { - int i = yy * scansize + xx; - pixels2[i] = model.getRGB (pixels[i]); - } - } - else - pixels2 = pixels; - - bufferedImage.setRGB (x, y, w, h, pixels2, offset, scansize); - processImageProgress(y / (height == 0 ? 1 : height)); - } - - public void imageComplete(int status) - { - processImageComplete(); - } - - public BufferedImage getBufferedImage() - { - if (bufferedImage == null && dec != null) - dec.startProduction (this); - return bufferedImage; - } - - // ImageReader parts - - public int getNumImages(boolean allowSearch) - throws IOException - { - return 1; - } - - public IIOMetadata getImageMetadata(int i) - { - return null; - } - - public IIOMetadata getStreamMetadata() - throws IOException - { - return null; - } - - public Iterator getImageTypes(int imageIndex) - throws IOException - { - BufferedImage img = getBufferedImage(); - Vector vec = new Vector(); - vec.add(new ImageTypeSpecifier(img)); - return vec.iterator(); - } - - public int getHeight(int imageIndex) - throws IOException - { - return getBufferedImage().getHeight(); - } - - public int getWidth(int imageIndex) - throws IOException - { - return getBufferedImage().getWidth(); - } - - public void setInput(Object input, - boolean seekForwardOnly, - boolean ignoreMetadata) - { - super.setInput(input, seekForwardOnly, ignoreMetadata); - dec = new GdkPixbufDecoder((InputStream) getInput()); - } - - public BufferedImage read(int imageIndex, ImageReadParam param) - throws IOException - { - return getBufferedImage (); - } - } - - // remaining helper class and static method is a convenience for the Gtk - // peers, for loading a BufferedImage in off a disk file without going - // through the whole imageio system. - - public static BufferedImage createBufferedImage (String filename) - { - GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(), - "png", // reader auto-detects, doesn't matter - new GdkPixbufDecoder (filename)); - return r.getBufferedImage (); - } - - public static BufferedImage createBufferedImage (URL u) - { - GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(), - "png", // reader auto-detects, doesn't matter - new GdkPixbufDecoder (u)); - return r.getBufferedImage (); - } - - public static BufferedImage createBufferedImage (byte[] imagedata, int imageoffset, - int imagelength) - { - GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(), - "png", // reader auto-detects, doesn't matter - new GdkPixbufDecoder (imagedata, - imageoffset, - imagelength)); - return r.getBufferedImage (); - } - - public static BufferedImage createBufferedImage (ImageProducer producer) - { - GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(), "png" /* ignored */, null); - producer.startProduction(r); - return r.getBufferedImage (); - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkRobotPeer.java b/libjava/gnu/java/awt/peer/gtk/GdkRobotPeer.java deleted file mode 100644 index 6d0218d057a..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkRobotPeer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* GdkRobot.java -- an XTest implementation of RobotPeer - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTException; -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.awt.image.ColorModel; -import java.awt.image.DirectColorModel; -import java.awt.peer.RobotPeer; - -/** - * Implements the RobotPeer interface using the XTest extension. - * - * @author Thomas Fitzsimmons - */ -public class GdkRobotPeer implements RobotPeer -{ - // gdk-pixbuf provides data in RGBA format - static final ColorModel cm = new DirectColorModel (32, 0xff000000, - 0x00ff0000, - 0x0000ff00, - 0x000000ff); - - public GdkRobotPeer (GraphicsDevice screen) throws AWTException - { - // FIXME: make use of screen parameter when GraphicsDevice is - // implemented. - if (!initXTest ()) - throw new AWTException ("XTest extension not supported"); - } - - native boolean initXTest (); - - // RobotPeer methods - public native void mouseMove (int x, int y); - public native void mousePress (int buttons); - public native void mouseRelease (int buttons); - public native void mouseWheel (int wheelAmt); - public native void keyPress (int keycode); - public native void keyRelease (int keycode); - native int[] nativeGetRGBPixels (int x, int y, int width, int height); - - public int getRGBPixel (int x, int y) - { - return cm.getRGB (nativeGetRGBPixels (x, y, 1, 1)[0]); - } - - public int[] getRGBPixels (Rectangle r) - { - int[] gdk_pixels = nativeGetRGBPixels (r.x, r.y, r.width, r.height); - int[] pixels = new int[r.width * r.height]; - - for (int i = 0; i < r.width * r.height; i++) - pixels[i] = cm.getRGB (gdk_pixels[i]); - - return pixels; - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java b/libjava/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java deleted file mode 100644 index 2bf9d23db94..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java +++ /dev/null @@ -1,115 +0,0 @@ -/* GdkScreenGraphicsDevice.java -- information about a screen device - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Dimension; -import java.awt.DisplayMode; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; - -public class GdkScreenGraphicsDevice extends GraphicsDevice -{ - GdkGraphicsEnvironment env; - - public GtkToolkit getToolkit() - { - return env.getToolkit(); - } - - public GdkScreenGraphicsDevice (GdkGraphicsEnvironment e) - { - super (); - env = e; - } - - public int getType () - { - return GraphicsDevice.TYPE_RASTER_SCREEN; - } - - public String getIDstring () - { - // FIXME: query X for this string - return "default GDK device ID string"; - } - - public GraphicsConfiguration[] getConfigurations () - { - // FIXME: query X for the list of possible configurations - return new GraphicsConfiguration [] { new GdkGraphicsConfiguration(this) }; - } - - public GraphicsConfiguration getDefaultConfiguration () - { - - // FIXME: query X for default configuration - return new GdkGraphicsConfiguration(this); - } - - - /** - * Returns the current display mode of this device, or null if unknown. - * - * @return the current display mode - * @see #setDisplayMode(DisplayMode) - * @see #getDisplayModes() - * @since 1.4 - */ - public DisplayMode getDisplayMode() - { - // determine display mode - Dimension dim = getToolkit().getScreenSize(); - DisplayMode mode = new DisplayMode(dim.width, dim.height, 0, - DisplayMode.REFRESH_RATE_UNKNOWN); - return mode; - } - - /** - * This device does not yet support fullscreen exclusive mode, so this - * returns <code>false</code>. - * - * @return <code>false</code> - * @since 1.4 - */ - public boolean isFullScreenSupported() - { - return false; - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GdkTextLayout.java b/libjava/gnu/java/awt/peer/gtk/GdkTextLayout.java deleted file mode 100644 index ff51745f26c..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GdkTextLayout.java +++ /dev/null @@ -1,434 +0,0 @@ -/* GdkTextLayout.java - Copyright (C) 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.classpath.Configuration; -import gnu.java.awt.peer.ClasspathTextLayoutPeer; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphMetrics; -import java.awt.font.GlyphVector; -import java.awt.font.TextAttribute; -import java.awt.font.TextHitInfo; -import java.awt.font.TextLayout; -import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; -import java.awt.geom.Rectangle2D; -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; -import java.text.CharacterIterator; - -/** - * This is an implementation of the text layout peer interface which - * delegates all the hard work to pango. - * - * @author Graydon Hoare - */ - -public class GdkTextLayout - implements ClasspathTextLayoutPeer -{ - // native side, plumbing, etc. - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("gtkpeer"); - } - initStaticState (); - } - private native void setText(String str); - private native void getExtents(double[] inkExtents, - double[] logExtents); - private native void indexToPos(int idx, double[] pos); - private native void initState (); - private native void dispose (); - static native void initStaticState(); - private final int native_state = GtkGenericPeer.getUniqueInteger (); - protected void finalize () - { - dispose (); - } - - // we hold on to these to make sure we can render when presented - // with non-GdkGraphics2D paint targets - private AttributedString attributedString; - private FontRenderContext fontRenderContext; - - public GdkTextLayout(AttributedString str, FontRenderContext frc) - { - initState(); - attributedString = str; - fontRenderContext = frc; - } - - protected class CharacterIteratorProxy - implements CharacterIterator - { - public CharacterIterator target; - public int begin; - public int limit; - public int index; - - public CharacterIteratorProxy (CharacterIterator ci) - { - target = ci; - } - - public int getBeginIndex () - { - return begin; - } - - public int getEndIndex () - { - return limit; - } - - public int getIndex () - { - return index; - } - - public char setIndex (int idx) - throws IllegalArgumentException - { - if (idx < begin || idx >= limit) - throw new IllegalArgumentException (); - char ch = target.setIndex (idx); - index = idx; - return ch; - } - - public char first () - { - int save = target.getIndex (); - char ch = target.setIndex (begin); - target.setIndex (save); - return ch; - } - - public char last () - { - if (begin == limit) - return this.first (); - - int save = target.getIndex (); - char ch = target.setIndex (limit - 1); - target.setIndex (save); - return ch; - } - - public char current () - { - return target.current(); - } - - public char next () - { - if (index >= limit - 1) - return CharacterIterator.DONE; - else - { - index++; - return target.next(); - } - } - - public char previous () - { - if (index <= begin) - return CharacterIterator.DONE; - else - { - index--; - return target.previous (); - } - } - - public Object clone () - { - CharacterIteratorProxy cip = new CharacterIteratorProxy (this.target); - cip.begin = this.begin; - cip.limit = this.limit; - cip.index = this.index; - return cip; - } - - } - - - // public side - - public void draw (Graphics2D g2, float x, float y) - { - if (g2 instanceof GdkGraphics2D) - { - // we share pango structures directly with GdkGraphics2D - // when legal - GdkGraphics2D gg2 = (GdkGraphics2D) g2; - gg2.drawGdkTextLayout(this, x, y); - } - else - { - // falling back to a rather tedious layout algorithm when - // not legal - AttributedCharacterIterator ci = attributedString.getIterator (); - CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci); - Font defFont = g2.getFont (); - - /* Note: this implementation currently only interprets FONT text - * attributes. There is a reasonable argument to be made for some - * attributes being interpreted out here, where we have control of the - * Graphics2D and can construct or derive new fonts, and some - * attributes being interpreted by the GlyphVector itself. So far, for - * all attributes except FONT we do neither. - */ - - for (char c = ci.first (); - c != CharacterIterator.DONE; - c = ci.next ()) - { - proxy.begin = ci.getIndex (); - proxy.limit = ci.getRunLimit(TextAttribute.FONT); - if (proxy.limit <= proxy.begin) - continue; - - proxy.index = proxy.begin; - - Object fnt = ci.getAttribute(TextAttribute.FONT); - GlyphVector gv; - if (fnt instanceof Font) - gv = ((Font)fnt).createGlyphVector (fontRenderContext, proxy); - else - gv = defFont.createGlyphVector (fontRenderContext, proxy); - - g2.drawGlyphVector (gv, x, y); - - int n = gv.getNumGlyphs (); - for (int i = 0; i < n; ++i) - { - GlyphMetrics gm = gv.getGlyphMetrics (i); - if (gm.getAdvanceX() == gm.getAdvance ()) - x += gm.getAdvanceX (); - else - y += gm.getAdvanceY (); - } - } - } - } - - public TextHitInfo getStrongCaret (TextHitInfo hit1, - TextHitInfo hit2) - { - throw new Error("not implemented"); - } - - public byte getBaseline () - { - throw new Error("not implemented"); - } - - public boolean isLeftToRight () - { - throw new Error("not implemented"); - } - - public boolean isVertical () - { - throw new Error("not implemented"); - } - - public float getAdvance () - { - throw new Error("not implemented"); - } - - public float getAscent () - { - throw new Error("not implemented"); - } - - public float getDescent () - { - throw new Error("not implemented"); - } - - public float getLeading () - { - throw new Error("not implemented"); - } - - public int getCharacterCount () - { - throw new Error("not implemented"); - } - - public byte getCharacterLevel (int index) - { - throw new Error("not implemented"); - } - - public float[] getBaselineOffsets () - { - throw new Error("not implemented"); - } - - public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint) - { - throw new Error("not implemented"); - } - - public Rectangle2D getBounds () - { - double[] inkExtents = new double[4]; - double[] logExtents = new double[4]; - getExtents(inkExtents, logExtents); - return new Rectangle2D.Double(logExtents[0], logExtents[1], - logExtents[2], logExtents[3]); - } - - public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds) - { - throw new Error("not implemented"); - } - - public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds) - { - throw new Error("not implemented"); - } - - public Shape[] getCaretShapes (int offset, Rectangle2D bounds, - TextLayout.CaretPolicy policy) - { - throw new Error("not implemented"); - } - - public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint, - Rectangle2D bounds) - { - AffineTransform at = new AffineTransform(); - GeneralPath gp = new GeneralPath(); - double [] rect = new double[4]; - Rectangle2D tmp = new Rectangle2D.Double(); - for (int i = firstEndpoint; i <= secondEndpoint; ++i) - { - indexToPos(i, rect); - tmp.setRect(rect[0], rect[1], rect[2], rect[3]); - Rectangle2D.intersect(tmp, bounds, tmp); - gp.append(tmp.getPathIterator(at), false); - } - return gp; - } - - public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint) - { - throw new Error("not implemented"); - } - - public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy) - { - throw new Error("not implemented"); - } - public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy) - { - throw new Error("not implemented"); - } - public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds) - { - throw new Error("not implemented"); - } - public TextHitInfo getVisualOtherHit (TextHitInfo hit) - { - throw new Error("not implemented"); - } - - public float getVisibleAdvance () - { - throw new Error("not implemented"); - } - - public Shape getOutline (AffineTransform tx) - { - throw new Error("not implemented"); - } - - public Shape getVisualHighlightShape (TextHitInfo firstEndpoint, - TextHitInfo secondEndpoint, - Rectangle2D bounds) - { - throw new Error("not implemented"); - } - - - public TextLayout getJustifiedLayout (float justificationWidth) - { - throw new Error("not implemented"); - } - - public void handleJustify (float justificationWidth) - { - throw new Error("not implemented"); - } - - public Object clone () - { - throw new Error("not implemented"); - } - - public int hashCode () - { - throw new Error("not implemented"); - } - - public boolean equals (ClasspathTextLayoutPeer tl) - { - throw new Error("not implemented"); - } - - public String toString () - { - throw new Error("not implemented"); - } - -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java deleted file mode 100644 index ab5df9f463f..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java +++ /dev/null @@ -1,107 +0,0 @@ -/* GtkButtonPeer.java -- Implements ButtonPeer with GTK - Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.Button; -import java.awt.Component; -import java.awt.Point; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.peer.ButtonPeer; - -public class GtkButtonPeer extends GtkComponentPeer - implements ButtonPeer -{ - native void create (String label); - - public native void connectSignals (); - - native void gtkWidgetModifyFont (String name, int style, int size); - native void gtkSetLabel (String label); - native void gtkWidgetSetForeground (int red, int green, int blue); - native void gtkWidgetSetBackground (int red, int green, int blue); - native void gtkActivate (); - native void gtkWidgetRequestFocus (); - native void setNativeBounds (int x, int y, int width, int height); - - public GtkButtonPeer (Button b) - { - super (b); - } - - void create () - { - create (((Button) awtComponent).getLabel ()); - } - - public void setLabel (String label) - { - gtkSetLabel(label); - } - - public void handleEvent (AWTEvent e) - { - if (e.getID () == MouseEvent.MOUSE_RELEASED && isEnabled ()) - { - MouseEvent me = (MouseEvent) e; - Point p = me.getPoint(); - p.translate(((Component) me.getSource()).getX(), - ((Component) me.getSource()).getY()); - if (!me.isConsumed () - && (me.getModifiersEx () & MouseEvent.BUTTON1_DOWN_MASK) != 0 - && awtComponent.getBounds().contains(p)) - postActionEvent (((Button) awtComponent).getActionCommand (), - me.getModifiersEx ()); - } - - if (e.getID () == KeyEvent.KEY_PRESSED) - { - KeyEvent ke = (KeyEvent) e; - if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_SPACE) - { - postActionEvent (((Button) awtComponent).getActionCommand (), - ke.getModifiersEx ()); - gtkActivate (); - } - } - - super.handleEvent (e); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java deleted file mode 100644 index dc21761209e..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkCanvasPeer.java +++ /dev/null @@ -1,100 +0,0 @@ -/* GtkCanvasPeer.java - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.Canvas; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.event.PaintEvent; -import java.awt.peer.CanvasPeer; - -public class GtkCanvasPeer extends GtkComponentPeer implements CanvasPeer -{ - native void create (); - - public GtkCanvasPeer (Canvas c) - { - super (c); - } - - public Graphics getGraphics () - { - if (GtkToolkit.useGraphics2D ()) - return new GdkGraphics2D (this); - else - return new GdkGraphics (this); - } - - public void handleEvent (AWTEvent event) - { - int id = event.getID(); - - switch (id) - { - case PaintEvent.PAINT: - case PaintEvent.UPDATE: - { - try - { - Graphics g = getGraphics (); - g.setClip (((PaintEvent)event).getUpdateRect()); - - if (id == PaintEvent.PAINT) - awtComponent.paint (g); - else - awtComponent.update (g); - - g.dispose (); - } - catch (InternalError e) - { - System.err.println (e); - } - } - break; - } - } - - /* Preferred size for a drawing widget is always what the user requested */ - public Dimension getPreferredSize () - { - return awtComponent.getSize (); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java deleted file mode 100644 index 46b0733d363..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* GtkCheckboxGroupPeer.java - Wrap a CheckboxGroup - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.CheckboxGroup; -import java.util.WeakHashMap; - -// Note that there is no peer interface for a CheckboxGroup. We -// introduce our own in order to make it easier to keep a piece of -// native state for each one. -public class GtkCheckboxGroupPeer extends GtkGenericPeer -{ - // This maps from a CheckboxGroup to the native peer. - private static WeakHashMap map = new WeakHashMap (); - - // Find the native peer corresponding to a CheckboxGroup. - public static synchronized GtkCheckboxGroupPeer - getCheckboxGroupPeer (CheckboxGroup group) - { - if (group == null) - return null; - GtkCheckboxGroupPeer nat = (GtkCheckboxGroupPeer) map.get (group); - if (nat == null) - { - nat = new GtkCheckboxGroupPeer (); - map.put (group, nat); - } - return nat; - } - - private GtkCheckboxGroupPeer () - { - // We don't need any special state here. Note that we can't store - // a reference to the java-side CheckboxGroup. That would mean - // they could never be collected. - super (null); - } - - // Dispose of our native resources. - public native void dispose (); - - // Remove a given checkbox from this group. - public native void remove (GtkCheckboxPeer box); - - // When collected, clean up the native state. - protected void finalize () - { - dispose (); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java deleted file mode 100644 index 01a6e3102d9..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxMenuItemPeer.java +++ /dev/null @@ -1,69 +0,0 @@ -/* GtkCheckboxMenuItemPeer.java -- Implements CheckboxMenuItemPeer with GTK+ - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.CheckboxMenuItem; -import java.awt.ItemSelectable; -import java.awt.event.ItemEvent; -import java.awt.peer.CheckboxMenuItemPeer; - -public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer - implements CheckboxMenuItemPeer -{ - native void create (String label); - - public GtkCheckboxMenuItemPeer (CheckboxMenuItem menu) - { - super (menu); - setState (menu.getState ()); - } - - public native void setState(boolean t); - - protected void postMenuActionEvent () - { - CheckboxMenuItem item = (CheckboxMenuItem)awtWidget; - q().postEvent (new ItemEvent ((ItemSelectable)awtWidget, - ItemEvent.ITEM_STATE_CHANGED, - item.getActionCommand(), - item.getState() ? ItemEvent.DESELECTED : ItemEvent.SELECTED)); - - super.postMenuActionEvent(); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java deleted file mode 100644 index 851757245aa..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java +++ /dev/null @@ -1,128 +0,0 @@ -/* GtkCheckboxPeer.java -- Implements CheckboxPeer with GTK - Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Checkbox; -import java.awt.CheckboxGroup; -import java.awt.peer.CheckboxPeer; - -public class GtkCheckboxPeer extends GtkComponentPeer - implements CheckboxPeer -{ - // Group from last time it was set. - public GtkCheckboxGroupPeer old_group; - // The current state of the GTK checkbox. - private boolean currentState; - - public native void create (GtkCheckboxGroupPeer group); - public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group); - public native void connectSignals (); - native void gtkWidgetModifyFont (String name, int style, int size); - native void gtkButtonSetLabel (String label); - native void gtkToggleButtonSetActive (boolean is_active); - - public GtkCheckboxPeer (Checkbox c) - { - super (c); - } - - // FIXME: we must be able to switch between a checkbutton and a - // radiobutton dynamically. - public void create () - { - Checkbox checkbox = (Checkbox) awtComponent; - CheckboxGroup g = checkbox.getCheckboxGroup (); - old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g); - create (old_group); - gtkToggleButtonSetActive (checkbox.getState ()); - gtkButtonSetLabel (checkbox.getLabel ()); - } - - public void setState (boolean state) - { - if (currentState != state) - gtkToggleButtonSetActive (state); - } - - public void setLabel (String label) - { - gtkButtonSetLabel (label); - } - - public void setCheckboxGroup (CheckboxGroup group) - { - GtkCheckboxGroupPeer gp - = GtkCheckboxGroupPeer.getCheckboxGroupPeer (group); - if (gp != old_group) - { - if (old_group != null) - old_group.remove (this); - nativeSetCheckboxGroup (gp); - old_group = gp; - } - } - - // Override the superclass postItemEvent so that the peer doesn't - // need information that we have. - public void postItemEvent (Object item, int stateChange) - { - Checkbox currentCheckBox = ((Checkbox)awtComponent); - // A firing of the event is only desired if the state has changed due to a - // button press. The currentCheckBox's state must be different from the - // one that the stateChange is changing to. - // stateChange = 1 if it goes from false -> true - // stateChange = 2 if it goes from true -> false - if (( !currentCheckBox.getState() && stateChange == 1) - || (currentCheckBox.getState() && stateChange == 2)) - { - super.postItemEvent (awtComponent, stateChange); - currentState = !currentCheckBox.getState(); - currentCheckBox.setState(currentState); - } - } - - public void dispose () - { - // Notify the group so that the native state can be cleaned up - // appropriately. - if (old_group != null) - old_group.remove (this); - super.dispose (); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/libjava/gnu/java/awt/peer/gtk/GtkChoicePeer.java deleted file mode 100644 index 6260b58e0e6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkChoicePeer.java +++ /dev/null @@ -1,128 +0,0 @@ -/* GtkChoicePeer.java -- Implements ChoicePeer with GTK - Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Choice; -import java.awt.event.ItemEvent; -import java.awt.peer.ChoicePeer; - -public class GtkChoicePeer extends GtkComponentPeer - implements ChoicePeer -{ - public GtkChoicePeer (Choice c) - { - super (c); - - int count = c.getItemCount (); - if (count > 0) - { - String items[] = new String[count]; - for (int i = 0; i < count; i++) - items[i] = c.getItem (i); - - append (items); - } - - int selected = c.getSelectedIndex(); - if (selected >= 0) - select(selected); - } - - native void create (); - - native void append (String items[]); - native int nativeGetSelected (); - native void nativeAdd (String item, int index); - native void nativeRemove (int index); - native void nativeRemoveAll (); - - public native void select (int position); - - public void add (String item, int index) - { - int before = nativeGetSelected(); - - nativeAdd (item, index); - - /* Generate an ItemEvent if we added the first one or - if we inserted at or before the currently selected item. */ - if ((before < 0) || (before >= index)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } - } - - public void remove (int index) - { - int before = nativeGetSelected(); - int after; - - nativeRemove (index); - after = nativeGetSelected(); - - /* Generate an ItemEvent if we are removing the currently selected item - and there are at least one item left. */ - if ((before == index) && (after >= 0)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } - } - - public void removeAll () - { - nativeRemoveAll(); - } - - public void addItem (String item, int position) - { - add (item, position); - } - - protected void choicePostItemEvent (String label, int stateChange) - { - // Must set our state before notifying listeners - if (stateChange == ItemEvent.SELECTED) - ((Choice) awtComponent).select (label); - postItemEvent (label, stateChange); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkClipboard.java b/libjava/gnu/java/awt/peer/gtk/GtkClipboard.java deleted file mode 100644 index c719cddb575..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkClipboard.java +++ /dev/null @@ -1,170 +0,0 @@ -/* GtkClipboard.java - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.ClipboardOwner; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class GtkClipboard extends Clipboard -{ - /* the number of milliseconds that we'll wait around for the - owner of the GDK_SELECTION_PRIMARY selection to convert - the requested data */ - static final int SELECTION_RECEIVED_TIMEOUT = 5000; - - /* We currently only support transferring of text between applications */ - static String selection; - static Object selectionLock = new Object (); - - static boolean hasSelection = false; - - protected GtkClipboard() - { - super("System Clipboard"); - initNativeState(); - } - - public Transferable getContents(Object requestor) - { - synchronized (this) - { - if (hasSelection) - return contents; - } - - /* Java doesn't own the selection, so we need to ask X11 */ - // XXX: Does this hold with Swing too ? - synchronized (selectionLock) - { - requestStringConversion(); - - try - { - selectionLock.wait(SELECTION_RECEIVED_TIMEOUT); - } - catch (InterruptedException e) - { - return null; - } - - return selection == null ? null : new StringSelection(selection); - } - } - - void stringSelectionReceived(String newSelection) - { - synchronized (selectionLock) - { - selection = newSelection; - selectionLock.notify(); - } - } - - /* convert Java clipboard data into a String suitable for sending - to another application */ - synchronized String stringSelectionHandler() throws IOException - { - String selection = null; - - try - { - if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) - selection = (String)contents.getTransferData(DataFlavor.stringFlavor); - else if (contents.isDataFlavorSupported(DataFlavor.plainTextFlavor)) - { - StringBuffer sbuf = new StringBuffer(); - InputStreamReader reader; - char readBuf[] = new char[512]; - int numChars; - - reader = new InputStreamReader - ((InputStream) - contents.getTransferData(DataFlavor.plainTextFlavor), "UNICODE"); - - while (true) - { - numChars = reader.read(readBuf); - if (numChars == -1) - break; - sbuf.append(readBuf, 0, numChars); - } - - selection = new String(sbuf); - } - } - catch (Exception e) - { - } - - return selection; - } - - public synchronized void setContents(Transferable contents, - ClipboardOwner owner) - { - selectionGet(); - - this.contents = contents; - this.owner = owner; - - hasSelection = true; - } - - synchronized void selectionClear() - { - hasSelection = false; - - if (owner != null) - { - owner.lostOwnership(this, contents); - owner = null; - contents = null; - } - } - - native void initNativeState(); - static native void requestStringConversion(); - static native void selectionGet(); -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java deleted file mode 100644 index 61dbaadf054..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ /dev/null @@ -1,662 +0,0 @@ -/* GtkComponentPeer.java -- Implements ComponentPeer with GTK - Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.AWTException; -import java.awt.BufferCapabilities; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.Image; -import java.awt.Insets; -import java.awt.ItemSelectable; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.Window; -import java.awt.event.FocusEvent; -import java.awt.event.ItemEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.PaintEvent; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; -import java.awt.peer.ComponentPeer; - -public class GtkComponentPeer extends GtkGenericPeer - implements ComponentPeer -{ - VolatileImage backBuffer; - BufferCapabilities caps; - - Component awtComponent; - - Insets insets; - - boolean isInRepaint; - - /* this isEnabled differs from Component.isEnabled, in that it - knows if a parent is disabled. In that case Component.isEnabled - may return true, but our isEnabled will always return false */ - native boolean isEnabled (); - static native boolean modalHasGrab(); - - native int[] gtkWidgetGetForeground (); - native int[] gtkWidgetGetBackground (); - native void gtkWidgetGetDimensions (int[] dim); - native void gtkWidgetGetPreferredDimensions (int[] dim); - native void gtkWidgetGetLocationOnScreen (int[] point); - native void gtkWidgetSetCursor (int type); - native void gtkWidgetSetBackground (int red, int green, int blue); - native void gtkWidgetSetForeground (int red, int green, int blue); - native void gtkWidgetSetSensitive (boolean sensitive); - native void gtkWidgetSetParent (ComponentPeer parent); - native void gtkWidgetRequestFocus (); - native void gtkWidgetDispatchKeyEvent (int id, long when, int mods, - int keyCode, int keyLocation); - - native boolean isRealized (); - - void create () - { - throw new RuntimeException (); - } - - native void connectSignals (); - - protected GtkComponentPeer (Component awtComponent) - { - super (awtComponent); - this.awtComponent = awtComponent; - insets = new Insets (0, 0, 0, 0); - - create (); - - connectSignals (); - - if (awtComponent.getForeground () != null) - setForeground (awtComponent.getForeground ()); - if (awtComponent.getBackground () != null) - setBackground (awtComponent.getBackground ()); - if (awtComponent.getFont() != null) - setFont(awtComponent.getFont()); - - Component parent = awtComponent.getParent (); - - // Only set our parent on the GTK side if our parent on the AWT - // side is not showing. Otherwise the gtk peer will be shown - // before we've had a chance to position and size it properly. - if (awtComponent instanceof Window - || (parent != null && ! parent.isShowing ())) - setParentAndBounds (); - } - - void setParentAndBounds () - { - setParent (); - - setComponentBounds (); - - setVisibleAndEnabled (); - } - - void setParent () - { - ComponentPeer p; - Component component = awtComponent; - do - { - component = component.getParent (); - p = component.getPeer (); - } - while (p instanceof java.awt.peer.LightweightPeer); - - if (p != null) - gtkWidgetSetParent (p); - } - - void beginNativeRepaint () - { - isInRepaint = true; - } - - void endNativeRepaint () - { - isInRepaint = false; - } - - /* - * Set the bounds of this peer's AWT Component based on dimensions - * returned by the native windowing system. Most Components impose - * their dimensions on the peers which is what the default - * implementation does. However some peers, like GtkFileDialogPeer, - * need to pass their size back to the AWT Component. - */ - void setComponentBounds () - { - Rectangle bounds = awtComponent.getBounds (); - - if (bounds.x == 0 && bounds.y == 0 - && bounds.width == 0 && bounds.height == 0) - return; - - setBounds (bounds.x, bounds.y, bounds.width, bounds.height); - } - - void setVisibleAndEnabled () - { - setVisible (awtComponent.isVisible ()); - setEnabled (awtComponent.isEnabled ()); - } - - public int checkImage (Image image, int width, int height, - ImageObserver observer) - { - GtkImage i = (GtkImage) image; - return i.checkImage (); - } - - public Image createImage (ImageProducer producer) - { - GtkImage image = new GtkImage (producer, null); - producer.startProduction (image); - return image; - } - - public Image createImage (int width, int height) - { - Graphics g; - if (GtkToolkit.useGraphics2D ()) - { - Graphics2D g2 = new GdkGraphics2D (width, height); - g2.setBackground (getBackground ()); - g = g2; - } - else - g = new GdkGraphics (width, height); - - g.setColor(getBackground()); - g.fillRect(0, 0, width, height); - - return new GtkOffScreenImage (null, g, width, height); - } - - public void disable () - { - setEnabled (false); - } - - public void enable () - { - setEnabled (true); - } - - public ColorModel getColorModel () - { - return ColorModel.getRGBdefault (); - } - - public FontMetrics getFontMetrics (Font font) - { - return getToolkit().getFontMetrics(font); - } - - public Graphics getGraphics () - { - if (GtkToolkit.useGraphics2D ()) - return new GdkGraphics2D (this); - else - return new GdkGraphics (this); - } - - public Point getLocationOnScreen () - { - int point[] = new int[2]; - gtkWidgetGetLocationOnScreen (point); - return new Point (point[0], point[1]); - } - - public Dimension getMinimumSize () - { - return minimumSize (); - } - - public Dimension getPreferredSize () - { - return preferredSize (); - } - - public Toolkit getToolkit () - { - return Toolkit.getDefaultToolkit(); - } - - public void handleEvent (AWTEvent event) - { - int id = event.getID(); - KeyEvent ke = null; - - switch (id) - { - case PaintEvent.PAINT: - case PaintEvent.UPDATE: - { - try - { - Graphics g = getGraphics (); - - // Some peers like GtkFileDialogPeer are repainted by Gtk itself - if (g == null) - break; - - g.setClip (((PaintEvent) event).getUpdateRect()); - - if (id == PaintEvent.PAINT) - awtComponent.paint (g); - else - awtComponent.update (g); - - g.dispose (); - } - catch (InternalError e) - { - System.err.println (e); - } - } - break; - case KeyEvent.KEY_PRESSED: - ke = (KeyEvent) event; - gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (), - ke.getKeyCode (), ke.getKeyLocation ()); - break; - case KeyEvent.KEY_RELEASED: - ke = (KeyEvent) event; - gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (), - ke.getKeyCode (), ke.getKeyLocation ()); - break; - } - } - - public boolean isFocusTraversable () - { - return true; - } - - public Dimension minimumSize () - { - int dim[] = new int[2]; - - gtkWidgetGetPreferredDimensions (dim); - - return new Dimension (dim[0], dim[1]); - } - - public void paint (Graphics g) - { - } - - public Dimension preferredSize () - { - int dim[] = new int[2]; - - gtkWidgetGetPreferredDimensions (dim); - - return new Dimension (dim[0], dim[1]); - } - - public boolean prepareImage (Image image, int width, int height, - ImageObserver observer) - { - GtkImage i = (GtkImage) image; - - if (i.isLoaded ()) return true; - - class PrepareImage extends Thread - { - GtkImage image; - ImageObserver observer; - - PrepareImage (GtkImage image, ImageObserver observer) - { - this.image = image; - image.setObserver (observer); - } - - public void run () - { - image.source.startProduction (image); - } - } - - new PrepareImage (i, observer).start (); - return false; - } - - public void print (Graphics g) - { - throw new RuntimeException (); - } - - public void repaint (long tm, int x, int y, int width, int height) - { - if (x == 0 && y == 0 && width == 0 && height == 0) - return; - - q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE, - new Rectangle (x, y, width, height))); - } - - public void requestFocus () - { - gtkWidgetRequestFocus(); - postFocusEvent(FocusEvent.FOCUS_GAINED, false); - } - - public void reshape (int x, int y, int width, int height) - { - setBounds (x, y, width, height); - } - - public void setBackground (Color c) - { - gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue()); - } - - native void setNativeBounds (int x, int y, int width, int height); - - public void setBounds (int x, int y, int width, int height) - { - Component parent = awtComponent.getParent (); - - // Heavyweight components that are children of one or more - // lightweight containers have to be handled specially. Because - // calls to GLightweightPeer.setBounds do nothing, GTK has no - // knowledge of the lightweight containers' positions. So we have - // to add the offsets manually when placing a heavyweight - // component within a lightweight container. The lightweight - // container may itself be in a lightweight container and so on, - // so we need to continue adding offsets until we reach a - // container whose position GTK knows -- that is, the first - // non-lightweight. - boolean lightweightChild = false; - Insets i; - while (parent.isLightweight ()) - { - lightweightChild = true; - - i = ((Container) parent).getInsets (); - - x += parent.getX () + i.left; - y += parent.getY () + i.top; - - parent = parent.getParent (); - } - - // We only need to convert from Java to GTK coordinates if we're - // placing a heavyweight component in a Window. - if (parent instanceof Window && !lightweightChild) - { - Insets insets = ((Window) parent).getInsets (); - GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer (); - int menuBarHeight = 0; - if (peer instanceof GtkFramePeer) - menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight (); - - // Convert from Java coordinates to GTK coordinates. - setNativeBounds (x - insets.left, y - insets.top + menuBarHeight, - width, height); - } - else - setNativeBounds (x, y, width, height); - } - - void setCursor () - { - setCursor (awtComponent.getCursor ()); - } - - public void setCursor (Cursor cursor) - { - gtkWidgetSetCursor (cursor.getType ()); - } - - public void setEnabled (boolean b) - { - gtkWidgetSetSensitive (b); - } - - public void setFont (Font f) - { - // FIXME: This should really affect the widget tree below me. - // Currently this is only handled if the call is made directly on - // a text widget, which implements setFont() itself. - gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize()); - } - - public void setForeground (Color c) - { - gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue()); - } - - public Color getForeground () - { - int rgb[] = gtkWidgetGetForeground (); - return new Color (rgb[0], rgb[1], rgb[2]); - } - - public Color getBackground () - { - int rgb[] = gtkWidgetGetBackground (); - return new Color (rgb[0], rgb[1], rgb[2]); - } - - public void setVisible (boolean b) - { - if (b) - show (); - else - hide (); - } - - public native void hide (); - public native void show (); - - protected void postMouseEvent(int id, long when, int mods, int x, int y, - int clickCount, boolean popupTrigger) - { - q().postEvent(new MouseEvent(awtComponent, id, when, mods, x, y, - clickCount, popupTrigger)); - } - - protected void postExposeEvent (int x, int y, int width, int height) - { - if (!isInRepaint) - q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, - new Rectangle (x, y, width, height))); - } - - protected void postKeyEvent (int id, long when, int mods, - int keyCode, char keyChar, int keyLocation) - { - KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods, - keyCode, keyChar, keyLocation); - - // Also post a KEY_TYPED event if keyEvent is a key press that - // doesn't represent an action or modifier key. - if (keyEvent.getID () == KeyEvent.KEY_PRESSED - && (!keyEvent.isActionKey () - && keyCode != KeyEvent.VK_SHIFT - && keyCode != KeyEvent.VK_CONTROL - && keyCode != KeyEvent.VK_ALT)) - { - synchronized (q) - { - q().postEvent (keyEvent); - q().postEvent (new KeyEvent (awtComponent, KeyEvent.KEY_TYPED, when, mods, - KeyEvent.VK_UNDEFINED, keyChar, keyLocation)); - } - } - else - q().postEvent (keyEvent); - } - - protected void postFocusEvent (int id, boolean temporary) - { - q().postEvent (new FocusEvent (awtComponent, id, temporary)); - } - - protected void postItemEvent (Object item, int stateChange) - { - q().postEvent (new ItemEvent ((ItemSelectable)awtComponent, - ItemEvent.ITEM_STATE_CHANGED, - item, stateChange)); - } - - public GraphicsConfiguration getGraphicsConfiguration () - { - // FIXME: just a stub for now. - return null; - } - - public void setEventMask (long mask) - { - // FIXME: just a stub for now. - } - - public boolean isFocusable () - { - return false; - } - - public boolean requestFocus (Component source, boolean b1, - boolean b2, long x) - { - return false; - } - - public boolean isObscured () - { - return false; - } - - public boolean canDetermineObscurity () - { - return false; - } - - public void coalescePaintEvent (PaintEvent e) - { - - } - - public void updateCursorImmediately () - { - - } - - public boolean handlesWheelScrolling () - { - return false; - } - - // Convenience method to create a new volatile image on the screen - // on which this component is displayed. - public VolatileImage createVolatileImage (int width, int height) - { - return new GtkVolatileImage (width, height); - } - - // Creates buffers used in a buffering strategy. - public void createBuffers (int numBuffers, BufferCapabilities caps) - throws AWTException - { - // numBuffers == 2 implies double-buffering, meaning one back - // buffer and one front buffer. - if (numBuffers == 2) - backBuffer = new GtkVolatileImage(awtComponent.getWidth(), - awtComponent.getHeight(), - caps.getBackBufferCapabilities()); - else - throw new AWTException("GtkComponentPeer.createBuffers:" - + " multi-buffering not supported"); - this.caps = caps; - } - - // Return the back buffer. - public Image getBackBuffer () - { - return backBuffer; - } - - // FIXME: flip should be implemented as a fast native operation - public void flip (BufferCapabilities.FlipContents contents) - { - getGraphics().drawImage(backBuffer, - awtComponent.getWidth(), - awtComponent.getHeight(), - null); - - // create new back buffer and clear it to the background color. - if (contents == BufferCapabilities.FlipContents.BACKGROUND) - { - backBuffer = createVolatileImage(awtComponent.getWidth(), - awtComponent.getHeight()); - backBuffer.getGraphics().clearRect(0, 0, - awtComponent.getWidth(), - awtComponent.getHeight()); - } - // FIXME: support BufferCapabilities.FlipContents.PRIOR - } - - // Release the resources allocated to back buffers. - public void destroyBuffers () - { - backBuffer.flush(); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java deleted file mode 100644 index e4d033fc2f6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java +++ /dev/null @@ -1,151 +0,0 @@ -/* GtkContainerPeer.java -- Implements ContainerPeer with GTK - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Insets; -import java.awt.Window; -import java.awt.peer.ComponentPeer; -import java.awt.peer.ContainerPeer; - -public class GtkContainerPeer extends GtkComponentPeer - implements ContainerPeer -{ - Container c; - boolean isValidating; - - public GtkContainerPeer(Container c) - { - super (c); - this.c = c; - } - - public void beginValidate () - { - isValidating = true; - } - - public void endValidate () - { - Component parent = awtComponent.getParent (); - - // Only set our parent on the GTK side if our parent on the AWT - // side is not showing. Otherwise the gtk peer will be shown - // before we've had a chance to position and size it properly. - if (parent != null && parent.isShowing ()) - { - Component[] components = ((Container) awtComponent).getComponents (); - int ncomponents = components.length; - - for (int i = 0; i < ncomponents; i++) - { - ComponentPeer peer = components[i].getPeer (); - - // Skip lightweight peers. - if (peer instanceof GtkComponentPeer) - ((GtkComponentPeer) peer).setParentAndBounds (); - } - - // GTK windows don't have parents. - if (!(awtComponent instanceof Window)) - setParentAndBounds (); - } - - isValidating = false; - } - - public Insets getInsets() - { - return insets; - } - - public Insets insets() - { - return getInsets (); - } - - public void setBounds (int x, int y, int width, int height) - { - super.setBounds (x, y, width, height); - } - - public void setFont(Font f) - { - super.setFont(f); - Component[] components = ((Container) awtComponent).getComponents(); - for (int i = 0; i < components.length; i++) - { - GtkComponentPeer peer = (GtkComponentPeer) components[i].getPeer(); - if (peer != null && ! peer.awtComponent.isFontSet()) - peer.setFont(f); - } - } - - public Graphics getGraphics () - { - return super.getGraphics(); - } - - public void beginLayout () { } - public void endLayout () { } - public boolean isPaintPending () { return false; } - - public void setBackground (Color c) - { - super.setBackground(c); - - Object components[] = ((Container) awtComponent).getComponents(); - for (int i = 0; i < components.length; i++) - { - Component comp = (Component) components[i]; - - // If the child's background has not been explicitly set yet, - // it should inherit this container's background. This makes the - // child component appear as if it has a transparent background. - // Note that we do not alter the background property of the child, - // but only repaint the child with the parent's background color. - if (!comp.isBackgroundSet() && comp.getPeer() != null) - comp.getPeer().setBackground(c); - } - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkDialogPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkDialogPeer.java deleted file mode 100644 index c2cbc37dce9..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkDialogPeer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* GtkDialogPeer.java -- Implements DialogPeer with GTK - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Dialog; -import java.awt.Graphics; -import java.awt.Rectangle; -import java.awt.event.PaintEvent; -import java.awt.peer.DialogPeer; - -public class GtkDialogPeer extends GtkWindowPeer - implements DialogPeer -{ - public GtkDialogPeer (Dialog dialog) - { - super (dialog); - } - - public Graphics getGraphics () - { - Graphics g; - if (GtkToolkit.useGraphics2D ()) - g = new GdkGraphics2D (this); - else - g = new GdkGraphics (this); - g.translate (-insets.left, -insets.top); - return g; - } - - protected void postMouseEvent(int id, long when, int mods, int x, int y, - int clickCount, boolean popupTrigger) - { - super.postMouseEvent (id, when, mods, - x + insets.left, y + insets.top, - clickCount, popupTrigger); - } - - protected void postExposeEvent (int x, int y, int width, int height) - { - if (!isInRepaint) - q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, - new Rectangle (x + insets.left, - y + insets.top, - width, height))); - } - - void create () - { - // Create a decorated dialog window. - create (GDK_WINDOW_TYPE_HINT_DIALOG, true); - - Dialog dialog = (Dialog) awtComponent; - - gtkWindowSetModal (dialog.isModal ()); - setTitle (dialog.getTitle ()); - setResizable (dialog.isResizable ()); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java deleted file mode 100644 index 0533d2759c2..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkEmbeddedWindowPeer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* GtkEmbeddedWindowPeer.java -- Implements EmbeddedWindowPeer using a - GtkPlug - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.java.awt.EmbeddedWindow; -import gnu.java.awt.peer.EmbeddedWindowPeer; - -public class GtkEmbeddedWindowPeer extends GtkFramePeer - implements EmbeddedWindowPeer -{ - native void create (long socket_id); - - void create () - { - create (((EmbeddedWindow) awtComponent).getHandle ()); - } - - native void construct (long socket_id); - - // FIXME: embed doesn't work right now, though I believe it should. - // This means that you can't call setVisible (true) on an - // EmbeddedWindow before calling setHandle with a valid handle. The - // problem is that somewhere after the call to - // GtkEmbeddedWindow.create and before the call to - // GtkEmbeddedWindow.construct, the GtkPlug peer is being realized. - // GtkSocket silently fails to embed an already-realized GtkPlug. - public void embed (long handle) - { - construct (handle); - } - - public GtkEmbeddedWindowPeer (EmbeddedWindow w) - { - super (w); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java deleted file mode 100644 index bd1f0775a92..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkFileDialogPeer.java +++ /dev/null @@ -1,219 +0,0 @@ -/* GtkFileDialogPeer.java -- Implements FileDialogPeer with GTK - Copyright (C) 1998, 1999, 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Dialog; -import java.awt.FileDialog; -import java.awt.Graphics; -import java.awt.Window; -import java.awt.peer.FileDialogPeer; -import java.io.File; -import java.io.FilenameFilter; - -public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer -{ - static final String FS = System.getProperty("file.separator"); - - private String currentFile = null; - private String currentDirectory = null; - private FilenameFilter filter; - - native void create (GtkContainerPeer parent); - native void connectSignals (); - native void nativeSetFile (String file); - public native String nativeGetDirectory(); - public native void nativeSetDirectory(String directory); - native void nativeSetFilenameFilter (FilenameFilter filter); - - public void create() - { - create((GtkContainerPeer) awtComponent.getParent().getPeer()); - - FileDialog fd = (FileDialog) awtComponent; - - setDirectory(fd.getDirectory()); - setFile(fd.getFile()); - - FilenameFilter filter = fd.getFilenameFilter(); - if (filter != null) - setFilenameFilter(filter); - } - - public GtkFileDialogPeer (FileDialog fd) - { - super (fd); - } - - void setComponentBounds () - { - if (awtComponent.getHeight () == 0 - && awtComponent.getWidth () == 0) - { - int[] dims = new int[2]; - gtkWidgetGetPreferredDimensions (dims); - ((GtkFileDialogPeer) this).setBoundsCallback ((Window) awtComponent, - awtComponent.getX (), - awtComponent.getY (), - dims[0], dims[1]); - } - super.setComponentBounds (); - } - - public void setFile (String fileName) - { - /* If nothing changed do nothing. This usually happens because - the only way we have to set the file name in FileDialog is by - calling its SetFile which will call us back. */ - if ((fileName == null && currentFile == null) - || (fileName != null && fileName.equals (currentFile))) - return; - - if (fileName == null || fileName.equals ("")) - { - currentFile = ""; - nativeSetFile (""); - return; - } - - // GtkFileChooser requires absolute filenames. If the given filename - // is not absolute, let's construct it based on current directory. - currentFile = fileName; - if (fileName.indexOf(FS) == 0) - { - nativeSetFile (fileName); - } - else - { - nativeSetFile (nativeGetDirectory() + FS + fileName); - } - } - - public void setDirectory (String directory) - { - /* If nothing changed so nothing. This usually happens because - the only way we have to set the directory in FileDialog is by - calling its setDirectory which will call us back. */ - if ((directory == null && currentDirectory == null) - || (directory != null && directory.equals (currentDirectory))) - return; - - if (directory == null || directory.equals ("")) - { - currentDirectory = FS; - nativeSetFile (FS); - return; - } - - currentDirectory = directory; - nativeSetDirectory (directory); - } - - public void setFilenameFilter (FilenameFilter filter) - { - this.filter = filter; - nativeSetFilenameFilter(filter); - } - - /* This method interacts with the native callback function of the - same name. The native function will extract the filename from the - GtkFileFilterInfo object and send it to this method, which will - in turn call the filter's accept() method and give back the return - value. */ - boolean filenameFilterCallback (String fullname) { - String filename = fullname.substring(fullname.lastIndexOf(FS) + 1); - String dirname = fullname.substring(0, fullname.lastIndexOf(FS)); - File dir = new File(dirname); - return filter.accept(dir, filename); - } - - public Graphics getGraphics () - { - // GtkFileDialog will repaint by itself - return null; - } - - void gtkHideFileDialog () - { - ((Dialog) awtComponent).hide(); - } - - void gtkDisposeFileDialog () - { - ((Dialog) awtComponent).dispose(); - } - - /* Callback to set the file and directory values when the user is finished - * with the dialog. - */ - void gtkSetFilename (String fileName) - { - FileDialog fd = (FileDialog) awtWidget; - if (fileName == null) - { - currentFile = null; - fd.setFile(null); - return; - } - - int sepIndex = fileName.lastIndexOf (FS); - if (sepIndex < 0) - { - /* This should never happen on Unix (all paths start with '/') */ - currentFile = fileName; - } - else - { - if (fileName.length() > (sepIndex + 1)) - { - String fn = fileName.substring (sepIndex + 1); - currentFile = fn; - } - else - { - currentFile = null; - } - - String dn = fileName.substring (0, sepIndex + 1); - currentDirectory = dn; - fd.setDirectory(dn); - } - - fd.setFile (currentFile); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java deleted file mode 100644 index 80ad1580362..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkFontPeer.java +++ /dev/null @@ -1,225 +0,0 @@ -/* GtkFontPeer.java -- Implements FontPeer with GTK+ - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.java.awt.peer.ClasspathFontPeer; - -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.font.LineMetrics; -import java.awt.geom.Rectangle2D; -import java.text.CharacterIterator; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class GtkFontPeer extends ClasspathFontPeer -{ - private static ResourceBundle bundle; - - static - { - try - { - bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font"); - } - catch (Throwable ignored) - { - bundle = null; - } - } - - private final String Xname; - - public GtkFontPeer (String name, int style) - { - // All fonts get a default size of 12 if size is not specified. - this(name, style, 12); - } - - public GtkFontPeer (String name, int style, int size) - { - super(name, style, size); - - String Xname = null; - if (bundle != null) - { - try - { - Xname = bundle.getString (name.toLowerCase () + "." + style); - } - catch (MissingResourceException mre) - { - // ignored - } - } - - if (Xname == null) - { - String weight; - String slant; - String spacing; - - if (style == Font.ITALIC || (style == (Font.BOLD+Font.ITALIC))) - slant = "i"; - else - slant = "r"; - if (style == Font.BOLD || (style == (Font.BOLD+Font.ITALIC))) - weight = "bold"; - else - weight = "medium"; - if (name.equals("Serif") || name.equals("SansSerif") - || name.equals("Helvetica") || name.equals("Times")) - spacing = "p"; - else - spacing = "c"; - - Xname = "-*-*-" + weight + "-" + slant + "-normal-*-*-" + size + "-*-*-" + spacing + "-*-*-*"; - } - - this.Xname = Xname; - } - - public String getXLFD () - { - return Xname; - } - - - /* remaining methods are for static compatibility with the newer - ClasspathFontPeer superclass; none of these methods ever existed or - worked on the older FontPeer interface, but we need to pretend to - support them anyways. */ - - public boolean canDisplay (Font font, char c) - { - throw new UnsupportedOperationException(); - } - - public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit) - { - throw new UnsupportedOperationException(); - } - - public String getSubFamilyName (Font font, Locale locale) - { - throw new UnsupportedOperationException(); - } - - public String getPostScriptName (Font font) - { - throw new UnsupportedOperationException(); - } - - public int getNumGlyphs (Font font) - { - throw new UnsupportedOperationException(); - } - - public int getMissingGlyphCode (Font font) - { - throw new UnsupportedOperationException(); - } - - public byte getBaselineFor (Font font, char c) - { - throw new UnsupportedOperationException(); - } - - public String getGlyphName (Font font, int glyphIndex) - { - throw new UnsupportedOperationException(); - } - - public GlyphVector createGlyphVector (Font font, - FontRenderContext frc, - CharacterIterator ci) - { - throw new UnsupportedOperationException(); - } - - public GlyphVector createGlyphVector (Font font, - FontRenderContext ctx, - int[] glyphCodes) - { - throw new UnsupportedOperationException(); - } - - public GlyphVector layoutGlyphVector (Font font, - FontRenderContext frc, - char[] chars, int start, - int limit, int flags) - { - throw new UnsupportedOperationException(); - } - - public FontMetrics getFontMetrics (Font font) - { - throw new UnsupportedOperationException(); - } - - public boolean hasUniformLineMetrics (Font font) - { - throw new UnsupportedOperationException(); - } - - public LineMetrics getLineMetrics (Font font, - CharacterIterator ci, - int begin, int limit, - FontRenderContext rc) - { - throw new UnsupportedOperationException(); - } - - public Rectangle2D getMaxCharBounds (Font font, - FontRenderContext rc) - { - throw new UnsupportedOperationException(); - } - - public Rectangle2D getStringBounds (Font font, - CharacterIterator ci, - int begin, int limit, - FontRenderContext frc) - { - throw new UnsupportedOperationException(); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java b/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java deleted file mode 100644 index 77b7a81786a..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java +++ /dev/null @@ -1,275 +0,0 @@ -/* GtkFramePeer.java -- Implements FramePeer with GTK - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.MenuBar; -import java.awt.Rectangle; -import java.awt.Window; -import java.awt.event.PaintEvent; -import java.awt.image.ColorModel; -import java.awt.peer.FramePeer; -import java.awt.peer.MenuBarPeer; - -public class GtkFramePeer extends GtkWindowPeer - implements FramePeer -{ - private int menuBarHeight; - private MenuBarPeer menuBar; - native int getMenuBarHeight (MenuBarPeer bar); - native void setMenuBarWidth (MenuBarPeer bar, int width); - native void setMenuBarPeer (MenuBarPeer bar); - native void removeMenuBarPeer (); - native void gtkFixedSetVisible (boolean visible); - - int getMenuBarHeight () - { - return menuBar == null ? 0 : getMenuBarHeight (menuBar); - } - - public void setMenuBar (MenuBar bar) - { - if (bar == null && menuBar != null) - { - // We're removing the menubar. - gtkFixedSetVisible (false); - menuBar = null; - removeMenuBarPeer (); - insets.top -= menuBarHeight; - menuBarHeight = 0; - awtComponent.validate (); - gtkFixedSetVisible (true); - } - else if (bar != null && menuBar == null) - { - // We're adding a menubar where there was no menubar before. - gtkFixedSetVisible (false); - menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer(); - setMenuBarPeer (menuBar); - int menuBarWidth = - awtComponent.getWidth () - insets.left - insets.right; - if (menuBarWidth > 0) - setMenuBarWidth (menuBar, menuBarWidth); - menuBarHeight = getMenuBarHeight (); - insets.top += menuBarHeight; - awtComponent.validate (); - gtkFixedSetVisible (true); - } - else if (bar != null && menuBar != null) - { - // We're swapping the menubar. - gtkFixedSetVisible (false); - removeMenuBarPeer(); - int oldHeight = menuBarHeight; - int menuBarWidth = - awtComponent.getWidth () - insets.left - insets.right; - menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer (); - setMenuBarPeer (menuBar); - if (menuBarWidth > 0) - setMenuBarWidth (menuBar, menuBarWidth); - menuBarHeight = getMenuBarHeight (); - if (oldHeight != menuBarHeight) - { - insets.top += (menuBarHeight - oldHeight); - awtComponent.validate (); - } - gtkFixedSetVisible (true); - } - } - - public void setBounds (int x, int y, int width, int height) - { - int menuBarWidth = width - insets.left - insets.right; - if (menuBar != null && menuBarWidth > 0) - setMenuBarWidth (menuBar, menuBarWidth); - - nativeSetBounds (x, y, - width - insets.left - insets.right, - height - insets.top - insets.bottom - + menuBarHeight); - } - - public void setResizable (boolean resizable) - { - // Call setSize; otherwise when resizable is changed from true to - // false the frame will shrink to the dimensions it had before it - // was resizable. - setSize (awtComponent.getWidth() - insets.left - insets.right, - awtComponent.getHeight() - insets.top - insets.bottom - + menuBarHeight); - gtkWindowSetResizable (resizable); - } - - protected void postInsetsChangedEvent (int top, int left, - int bottom, int right) - { - insets.top = top + menuBarHeight; - insets.left = left; - insets.bottom = bottom; - insets.right = right; - } - - public GtkFramePeer (Frame frame) - { - super (frame); - } - - void create () - { - // Create a normal decorated window. - create (GDK_WINDOW_TYPE_HINT_NORMAL, true); - - Frame frame = (Frame) awtComponent; - - setMenuBar (frame.getMenuBar ()); - - setTitle (frame.getTitle ()); - gtkWindowSetResizable (frame.isResizable ()); - setIconImage(frame.getIconImage()); - } - - native void nativeSetIconImageFromDecoder (GdkPixbufDecoder decoder); - native void nativeSetIconImageFromData (int[] pixels, int width, int height); - public void setIconImage (Image image) - { - if (image != null && image instanceof GtkImage) - { - GtkImage img = (GtkImage) image; - // FIXME: Image should be loaded, but if not, do image loading here. - if (img.isLoaded()) - { - if (img.getSource() instanceof GdkPixbufDecoder) - { - nativeSetIconImageFromDecoder((GdkPixbufDecoder) img.getSource()); - } - else - { - int[] pixels = img.getPixelCache(); - ColorModel model = img.getColorModel(); - int[] data = new int[pixels.length * 4]; - for (int i = 0; i < pixels.length; i++) - { - data[i * 4] = model.getRed(pixels[i]); - data[i * 4 + 1] = model.getGreen(pixels[i]); - data[i * 4 + 2] = model.getBlue(pixels[i]); - data[i * 4 + 3] = model.getAlpha(pixels[i]); - } - nativeSetIconImageFromData(data, img.getWidth(null), img.getHeight(null)); - } - } - } - } - - public Graphics getGraphics () - { - Graphics g; - if (GtkToolkit.useGraphics2D ()) - g = new GdkGraphics2D (this); - else - g = new GdkGraphics (this); - g.translate (-insets.left, -insets.top); - return g; - } - - protected void postConfigureEvent (int x, int y, int width, int height) - { - int frame_x = x - insets.left; - // Since insets.top includes the MenuBar height, we need to add back - // the MenuBar height to the frame's y position. - // If no MenuBar exists in this frame, the MenuBar height will be 0. - int frame_y = y - insets.top + menuBarHeight; - int frame_width = width + insets.left + insets.right; - // Ditto as above. Since insets.top already includes the MenuBar's height, - // we need to subtract the MenuBar's height from the top inset. - int frame_height = height + insets.top + insets.bottom - menuBarHeight; - if (frame_x != awtComponent.getX() - || frame_y != awtComponent.getY() - || frame_width != awtComponent.getWidth() - || frame_height != awtComponent.getHeight()) - { - if (frame_width != awtComponent.getWidth() && menuBar != null - && width > 0) - setMenuBarWidth (menuBar, width); - - setBoundsCallback ((Window) awtComponent, - frame_x, - frame_y, - frame_width, - frame_height); - - awtComponent.validate(); - } - } - - protected void postMouseEvent(int id, long when, int mods, int x, int y, - int clickCount, boolean popupTrigger) - { - super.postMouseEvent (id, when, mods, - x + insets.left, y + insets.top, - clickCount, popupTrigger); - } - - protected void postExposeEvent (int x, int y, int width, int height) - { - if (!isInRepaint) - q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, - new Rectangle (x + insets.left, - y + insets.top, - width, height))); - } - - public int getState () - { - return 0; - } - - public void setState (int state) - { - - } - - public void setMaximizedBounds (Rectangle r) - { - - } -} - - diff --git a/libjava/gnu/java/awt/peer/gtk/GtkGenericPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkGenericPeer.java deleted file mode 100644 index 669268e92d8..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkGenericPeer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* GtkGenericPeer.java - Has a hashcode. Yuck. - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.EventQueue; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; - -public class GtkGenericPeer -{ - final int native_state = getUniqueInteger (); - - // Next native state value we will assign. - private static int next_native_state = 0; - - // The widget or other java-side object we wrap. - protected Object awtWidget; - - // Global event queue. - protected static EventQueue q = null; - - // Dispose of our native state. - public native void dispose (); - - static EventQueue q () - { - return Toolkit.getDefaultToolkit ().getSystemEventQueue (); - } - - protected GtkGenericPeer (Object awtWidget) - { - this.awtWidget = awtWidget; - } - - public static void enableQueue (EventQueue sq) - { - if (q == null) - q = sq; - } - - protected void postActionEvent (String command, int mods) - { - q().postEvent (new ActionEvent (awtWidget, ActionEvent.ACTION_PERFORMED, - command, mods)); - } - - // Return a unique integer for use in the native state mapping - // code. We can't use a hash code since that is not guaranteed to - // be unique. - static synchronized int getUniqueInteger () - { - // Let's assume this will never wrap. - return next_native_state++; - } - - native void gtkWidgetModifyFont (String name, int style, int size); -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkImage.java b/libjava/gnu/java/awt/peer/gtk/GtkImage.java deleted file mode 100644 index a9f8e9075b6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkImage.java +++ /dev/null @@ -1,344 +0,0 @@ -/* GtkImage.java - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Graphics; -import java.awt.Image; -import java.awt.image.ColorModel; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.util.Hashtable; -import java.util.Vector; - -public class GtkImage extends Image implements ImageConsumer -{ - int width = -1, height = -1; - Hashtable props = null; - boolean isLoaded = false; - boolean isCacheable = true; - boolean loading = false; - - Vector widthObservers = new Vector (); - Vector heightObservers = new Vector (); - Vector propertyObservers = new Vector (); - - ImageProducer source; - ImageObserver observer; - Graphics g; - - /* Variables in which we stored cached data, if possible. - - An image is cached if the following properties are true: - 1. The ColorModel passed into setColorModel is the same ColorModel - passed to all invocations of setPixels. - 2. The image contains a single frame. - - */ - int[] pixelCache; - ColorModel model; - - public - GtkImage (ImageProducer producer, Graphics g) - { - source = producer; - this.g = g; - - if (source != null) - source.addConsumer (this); - } - - public void setObserver (ImageObserver observer) - { - this.observer = observer; - } - - public synchronized int[] - getPixelCache () - { - return pixelCache; - } - - public synchronized ColorModel - getColorModel () - { - return model; - } - - public synchronized int - getWidth (ImageObserver observer) - { - if (width == -1) - widthObservers.addElement (observer); - - return width; - } - - public synchronized int - getHeight (ImageObserver observer) - { - if (height == -1) - heightObservers.addElement (observer); - - return height; - } - - public ImageProducer - getSource () - { - return source; - } - - public Graphics - getGraphics () - { - return g; - } - - public synchronized Object - getProperty (String name, ImageObserver observer) - { - if (props == null) - { - propertyObservers.addElement (observer); - return null; - } - - Object value = props.get (name); - return (value == null) ? UndefinedProperty : value; - } - - public synchronized void - flush () - { - isLoaded = false; - isCacheable = true; - width = height = -1; - props = null; - pixelCache = null; - model = null; - - if (source != null) - { - source.removeConsumer (this); - source.addConsumer (this); - } - } - - public boolean - isLoaded () - { - return isLoaded; - } - - /* ImageConsumer methods */ - - public synchronized void - setDimensions (int width, int height) - { - pixelCache = new int[width*height]; - - this.width = width; - this.height = height; - - for (int i = 0; i < widthObservers.size (); i++) - { - ImageObserver io = (ImageObserver) widthObservers.elementAt (i); - if (io != null) - io.imageUpdate (this, ImageObserver.WIDTH, -1, -1, width, height); - } - - for (int i = 0; i < heightObservers.size (); i++) - { - ImageObserver io = (ImageObserver) heightObservers.elementAt (i); - if (io != null) - io.imageUpdate (this, ImageObserver.HEIGHT, -1, -1, width, height); - } - - if (observer != null) - observer.imageUpdate (this, - (ImageObserver.WIDTH - | ImageObserver.HEIGHT), - -1, -1, width, height); - } - - public synchronized void - setProperties (Hashtable props) - { - this.props = props; - - for (int i = 0; i < propertyObservers.size (); i++) - { - ImageObserver io = (ImageObserver) propertyObservers.elementAt (i); - if (io != null) - io.imageUpdate (this, ImageObserver.PROPERTIES, -1, -1, width, height); - } - } - - public synchronized void - setColorModel (ColorModel model) - { - if (this.model == null || this.model.equals(model)) - this.model = model; - else - isCacheable = false; - } - - public synchronized void - setHints (int flags) - { - } - - public synchronized void - setPixels (int x, int y, int width, int height, ColorModel cm, byte[] pixels, - int offset, int scansize) - { - setPixels (x, y, width, height, cm, convertPixels (pixels), offset, - scansize); - - if (observer != null) - observer.imageUpdate (this, - ImageObserver.SOMEBITS, - x, y, width, height); - } - - public synchronized void - setPixels (int x, int y, int width, int height, ColorModel cm, int[] pixels, - int offset, int scansize) - { - loading = true; - - if (!isCacheable) - return; - - if (!cm.equals(model) || pixelCache == null) - { - isCacheable = false; - return; - } - - if (scansize == width && height == 1) - { - // Copy contents of pixels array into pixel cache. - System.arraycopy (pixels, offset, - pixelCache, y * this.width + x, - pixels.length - offset); - } - else // skip over scansize-width for each row - { - for (int i = 0; i < height; i++) - System.arraycopy (pixels, offset + (i * scansize), - pixelCache, (y + i) * this.width + x, - width); - } - } - - public synchronized void - imageComplete (int status) - { - if (status == ImageConsumer.STATICIMAGEDONE && isCacheable) - isLoaded = true; - - if (status == ImageConsumer.SINGLEFRAME) - isCacheable = false; - - if (observer != null) - { - if (status == ImageConsumer.IMAGEERROR) - observer.imageUpdate (null, - ImageObserver.ERROR, - -1, -1, -1, -1); - else - observer.imageUpdate (null, - ImageObserver.ALLBITS, - -1, -1, -1, -1); - } - - if (source != null && status != ImageConsumer.SINGLEFRAME) - source.removeConsumer (this); - } - - public synchronized void - startProduction (GtkImagePainter painter) - { - if (isLoaded) - { - painter.setDimensions (width, height); - painter.setPixels (0, 0, width, height, model, pixelCache, 0, width); - } - else - { - if (source != null) - { - source.startProduction (painter); - source.removeConsumer (painter); - } - } - } - - private int[] - convertPixels (byte[] pixels) - { - int ret[] = new int[pixels.length]; - - for (int i = 0; i < pixels.length; i++) - ret[i] = pixels[i]; - - return ret; - } - - synchronized int - checkImage () - { - int bits = 0; - - if (width != -1) - bits |= ImageObserver.WIDTH; - if (height != -1) - bits |= ImageObserver.HEIGHT; - if (props != null) - bits |= ImageObserver.PROPERTIES; - if (loading) - bits |= ImageObserver.SOMEBITS; - if (isLoaded) - bits |= ImageObserver.ALLBITS; - - return bits; - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java b/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java deleted file mode 100644 index 9efa0ae7137..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java +++ /dev/null @@ -1,267 +0,0 @@ -/* GtkImagePainter.java - Copyright (C) 1999, 2000 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Color; -import java.awt.Rectangle; -import java.awt.image.ColorModel; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageObserver; -import java.util.Hashtable; - -public class GtkImagePainter implements Runnable, ImageConsumer -{ - GtkImage image; - GdkGraphics gc; - int startX, startY; - int redBG; - int greenBG; - int blueBG; - double affine[]; - int width, height; - boolean flipX, flipY; - Rectangle clip; - int s_width, s_height; - ImageObserver observer; - - public - GtkImagePainter (GtkImage image, GdkGraphics gc, int x, int y, - int width, int height, Color bgcolor, ImageObserver o) - { - this.image = image; - this.gc = (GdkGraphics) gc.create (); - startX = x; - startY = y; - redBG = bgcolor.getRed (); - greenBG = bgcolor.getGreen (); - blueBG = bgcolor.getBlue (); - this.width = width; - this.height = height; - flipX = flipY = false; - s_width = s_height = 0; - clip = null; - observer = o; - - run (); - } - - public - GtkImagePainter (GtkImage image, GdkGraphics gc, - int dx1, int dy1, int dx2, int dy2, - int sx1, int sy1, int sx2, int sy2, - Color bgcolor, ImageObserver o) - { - this.image = image; - this.gc = (GdkGraphics) gc.create (); - startX = (dx1 < dx2) ? dx1 : dx2; - startY = dy1; - redBG = bgcolor.getRed (); - greenBG = bgcolor.getGreen (); - blueBG = bgcolor.getBlue (); - observer = o; - - this.width = Math.abs (dx2 - dx1); - this.height = Math.abs (dy2 - dy1); - - flipX = ((dx1 > dx2 && sx2 > sx1) - || (dx1 < dx2 && sx2 < sx1)); - - flipY = ((dy1 > dy2 && sy2 > sy1) - || (dy1 < dy2 && sy2 < sy1)); - - s_width = Math.abs (sx2 - sx1); - s_height = Math.abs (sy2 - sy1); - clip = new Rectangle (sx1, sy1, s_width, s_height); - - run (); - } - - public void - run () - { - image.startProduction (this); - gc.dispose (); - } - - /* Convert pixel data into a format that gdkrgb can understand */ - static int[] - convertPixels (int[] pixels, ColorModel model) - { - if (pixels == null || model == null) - { - return null; - } - - if (model.equals (ColorModel.getRGBdefault ())) - return pixels; - - int ret[] = new int[pixels.length]; - - for (int i = 0; i < pixels.length; i++) - ret[i] = model.getRGB (pixels[i]); - - return ret; - } - - static int[] - convertPixels (byte[] pixels, ColorModel model) - { - if (pixels == null || model == null) - { - return null; - } - - int ret[] = new int[pixels.length]; - - for (int i = 0; i < pixels.length; i++) - ret[i] = model.getRGB (pixels[i]); - - return ret; - } - - native void - drawPixels (GdkGraphics gc, int bg_red, int bg_green, int bg_blue, - int x, int y, int width, int height, int[] pixels, int offset, - int scansize, double affine[]); - - - public void - setPixels (int x, int y, int width, int height, ColorModel model, - int[] pixels, int offset, int scansize) - { - if (clip != null) - { - Rectangle r; - r = clip.intersection (new Rectangle (x, y, width, height)); - if (r.width == 0 && r.height == 0) - return; - - offset += r.y * scansize + r.x; - - width = r.width; - height = r.height; - x = r.x; - y = r.y; - } - - drawPixels (gc, redBG, greenBG, blueBG, - startX + x, startY + y, - width, height, convertPixels (pixels, model), offset, - scansize, affine); - } - - public void - setPixels (int x, int y, int width, int height, ColorModel model, - byte[] pixels, int offset, int scansize) - { - setPixels (x, y, width, height, ColorModel.getRGBdefault(), - convertPixels (pixels, model), offset, scansize); - } - - public void - setDimensions (int width, int height) - { - if (!flipX && !flipY && - ((this.width == -1 && this.height == -1) - || (this.width == width && this.height == height))) - return; - - affine = new double[6]; - affine[1] = affine[2] = affine[4] = affine[5] = 0; - - if (clip != null) - { - affine[0] = this.width / (double) s_width; - affine[3] = this.height / (double) s_height; - } - else - { - affine[0] = this.width / (double) width; - affine[3] = this.height / (double) height; - } - - if (flipX) - { - affine[0] = -affine[0]; - affine[4] = this.width; - } - - if (flipY) - { - affine[3] = -affine[3]; - affine[5] = this.height; - } - - if (affine[0] == 1 && affine[3] == 1) - affine = null; - } - - public void - setProperties (Hashtable props) - { - } - - public void - setColorModel (ColorModel model) - { - } - - public void - setHints (int flags) - { - } - - public void - imageComplete (int status) - { - image.imageComplete(status); - - if (observer != null) - { - if (status == ImageConsumer.IMAGEERROR) - observer.imageUpdate (null, - ImageObserver.ERROR, - -1, -1, -1, -1); - else - observer.imageUpdate (null, - ImageObserver.ALLBITS, - -1, -1, -1, -1); - } - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java deleted file mode 100644 index fdd5fd15f63..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* GtkLabelPeer.java -- Implements LabelPeer with GTK - Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Label; -import java.awt.peer.LabelPeer; - -public class GtkLabelPeer extends GtkComponentPeer - implements LabelPeer -{ - native void create (String text, float alignment); - native void gtkWidgetModifyFont (String name, int style, int size); - native void nativeSetAlignment (float alignment); - - public native void setText(String text); - native void setNativeBounds (int x, int y, int width, int height); - - void create () - { - Label label = (Label) awtComponent; - create (label.getText (), getGtkAlignment (label.getAlignment ())); - } - - public GtkLabelPeer (Label l) - { - super (l); - } - - public void setAlignment (int alignment) - { - nativeSetAlignment (getGtkAlignment (alignment)); - } - - float getGtkAlignment (int alignment) - { - switch (alignment) - { - case Label.LEFT: - return 0.0f; - case Label.CENTER: - return 0.5f; - case Label.RIGHT: - return 1.0f; - } - - return 0.0f; - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkListPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkListPeer.java deleted file mode 100644 index ff12fe34bba..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkListPeer.java +++ /dev/null @@ -1,180 +0,0 @@ -/* GtkListPeer.java -- Implements ListPeer with GTK - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.Dimension; -import java.awt.List; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.peer.ListPeer; - -public class GtkListPeer extends GtkComponentPeer - implements ListPeer -{ - void create () - { - List list = (List) awtComponent; - - create (list.getRows ()); - - setMultipleMode (list.isMultipleMode ()); - } - - native void create (int rows); - native void connectSignals (); - native void gtkWidgetModifyFont (String name, int style, int size); - native void gtkWidgetRequestFocus (); - - native void getSize (int rows, int visibleRows, int dims[]); - - public GtkListPeer (List list) - { - super (list); - - setMultipleMode (list.isMultipleMode ()); - - if (list.getItemCount () > 0) - append (list.getItems ()); - } - - native void append (String items[]); - - public native void add (String item, int index); - - public void addItem (String item, int index) - { - add (item, index); - } - - public void clear () - { - removeAll (); - } - - public native void delItems (int start, int end); - public native void deselect (int index); - - public Dimension getMinimumSize (int rows) - { - return minimumSize (rows); - } - - public Dimension getPreferredSize (int rows) - { - return preferredSize (rows); - } - - public native int[] getSelectedIndexes (); - public native void makeVisible (int index); - - public Dimension minimumSize (int rows) - { - int dims[] = new int[2]; - - int visibleRows = ((List) awtComponent).getRows(); - getSize (rows, visibleRows, dims); - return new Dimension (dims[0], dims[1]); - } - - public Dimension preferredSize (int rows) - { - int dims[] = new int[2]; - - int visibleRows = ((List) awtComponent).getRows(); - getSize (rows, visibleRows, dims); - return new Dimension (dims[0], dims[1]); - } - - public void removeAll () - { - delItems (0, -1); - } - - public native void select (int index); - public native void setMultipleMode (boolean b); - - public void setMultipleSelections (boolean b) - { - setMultipleMode (b); - } - - public void handleEvent (AWTEvent e) - { - if (e.getID () == MouseEvent.MOUSE_CLICKED && isEnabled ()) - { - // Only generate the ActionEvent on the second click of a - // multiple click. - MouseEvent me = (MouseEvent) e; - if (!me.isConsumed () - && (me.getModifiersEx () & MouseEvent.BUTTON1_DOWN_MASK) != 0 - && me.getClickCount() == 2) - { - String selectedItem = ((List) awtComponent).getSelectedItem (); - - // Double-click only generates an Action event if - // something is selected. - if (selectedItem != null) - postActionEvent (((List) awtComponent).getSelectedItem (), - me.getModifiersEx ()); - } - } - - if (e.getID () == KeyEvent.KEY_PRESSED) - { - KeyEvent ke = (KeyEvent) e; - if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_ENTER) - { - String selectedItem = ((List) awtComponent).getSelectedItem (); - - // Enter only generates an Action event if something is - // selected. - if (selectedItem != null) - postActionEvent (selectedItem, ke.getModifiersEx ()); - } - } - - super.handleEvent (e); - } - - protected void postItemEvent (int item, int stateChange) - { - postItemEvent (new Integer (item), stateChange); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java deleted file mode 100644 index 79eeaf9ba6a..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* GtkMenuBarPeer.java -- Implements MenuBarPeer with GTK+ - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Font; -import java.awt.Menu; -import java.awt.MenuBar; -import java.awt.MenuComponent; -import java.awt.peer.MenuBarPeer; -import java.awt.peer.MenuPeer; - -public class GtkMenuBarPeer extends GtkMenuComponentPeer - implements MenuBarPeer -{ - - native void create (); - native void addMenu (MenuPeer menu); - - public GtkMenuBarPeer (MenuBar target) - { - super (target); - } - - void setFont () - { - MenuComponent mc = (MenuComponent) awtWidget; - Font f = mc.getFont (); - - if (f == null) - mc.setFont (new Font ("Dialog", Font.PLAIN, 12)); - } - - // FIXME: remove this method or replace it with one that does - // something useful. - /* In Gnome, help menus are no longer right flushed. */ - native void nativeSetHelpMenu(MenuPeer menuPeer); - - public void addHelpMenu (Menu menu) - { - // nativeSetHelpMenu((MenuPeer) menu.getPeer()); - } - - public native void delMenu(int index); -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java deleted file mode 100644 index 8d9d1ca04a0..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkMenuComponentPeer.java +++ /dev/null @@ -1,63 +0,0 @@ -/* GtkMenuComponentPeer.java -- Implements MenuComponentPeer with GTK+ - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.peer.MenuComponentPeer; - -public class GtkMenuComponentPeer extends GtkGenericPeer - implements MenuComponentPeer -{ - void create () - { - throw new RuntimeException (); - } - - void setFont () - { - } - - public GtkMenuComponentPeer (Object awtWidget) - { - super (awtWidget); - create (); - setFont (); - } - - public native void dispose(); -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java deleted file mode 100644 index 5728f262b13..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkMenuItemPeer.java +++ /dev/null @@ -1,120 +0,0 @@ -/* GtkMenuItemPeer.java -- Implements MenuItemPeer with GTK+ - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Font; -import java.awt.Menu; -import java.awt.MenuBar; -import java.awt.MenuComponent; -import java.awt.MenuItem; -import java.awt.peer.MenuItemPeer; -import java.awt.peer.MenuPeer; - -public class GtkMenuItemPeer extends GtkMenuComponentPeer - implements MenuItemPeer -{ - native void create (String label); - native void connectSignals (); - native void gtkWidgetModifyFont (String name, int style, int size); - - void create () - { - create (((MenuItem) awtWidget).getLabel()); - } - - public GtkMenuItemPeer (MenuItem item) - { - super (item); - setEnabled (item.isEnabled ()); - setParent (item); - - if (item.getParent() instanceof Menu && ! (item instanceof Menu)) - connectSignals(); - } - - void setFont () - { - MenuComponent mc = ((MenuComponent) awtWidget); - Font f = mc.getFont (); - - if (f == null) - { - MenuComponent parent = (MenuComponent) mc.getParent (); - Font pf = parent.getFont (); - gtkWidgetModifyFont (pf.getName (), pf.getStyle (), pf.getSize ()); - } - else - gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize()); - } - - void setParent (MenuItem item) - { - // add ourself differently, based on what type of parent we have - // yes, the typecasting here is nasty. - Object parent = item.getParent (); - if (parent instanceof MenuBar) - { - ((GtkMenuBarPeer)((MenuBar)parent).getPeer ()).addMenu ((MenuPeer) this); - } - else // parent instanceof Menu - { - ((GtkMenuPeer)((Menu)parent).getPeer ()).addItem (this, - item.getShortcut ()); - } - } - - public void disable () - { - setEnabled (false); - } - - public void enable () - { - setEnabled (true); - } - - public native void setEnabled(boolean b); - - public native void setLabel(String label); - - protected void postMenuActionEvent () - { - postActionEvent (((MenuItem)awtWidget).getActionCommand (), 0); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkMenuPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkMenuPeer.java deleted file mode 100644 index 80332dd6a72..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkMenuPeer.java +++ /dev/null @@ -1,103 +0,0 @@ -/* GtkMenuPeer.java -- Implements MenuPeer with GTK+ - Copyright (C) 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Component; -import java.awt.Menu; -import java.awt.MenuContainer; -import java.awt.MenuItem; -import java.awt.MenuShortcut; -import java.awt.peer.MenuItemPeer; -import java.awt.peer.MenuPeer; - -public class GtkMenuPeer extends GtkMenuItemPeer - implements MenuPeer -{ - native void create (String label); - native void addItem (MenuItemPeer item, int key, boolean shiftModifier); - native void setupAccelGroup (GtkGenericPeer container); - native void addTearOff (); - - public GtkMenuPeer (Menu menu) - { - super (menu); - - if (menu.isTearOff()) - addTearOff(); - - MenuContainer parent = menu.getParent (); - if (parent instanceof Menu) - setupAccelGroup ((GtkGenericPeer)((Menu)parent).getPeer ()); - else if (parent instanceof Component) - setupAccelGroup ((GtkGenericPeer)((Component)parent).getPeer ()); - else - setupAccelGroup (null); - } - - public void addItem (MenuItem item) - { - int key = 0; - boolean shiftModifier = false; - - MenuShortcut ms = item.getShortcut (); - if (ms != null) - { - key = ms.getKey (); - shiftModifier = ms.usesShiftModifier (); - } - - addItem ((MenuItemPeer) item.getPeer (), key, shiftModifier); - } - - public void addItem (MenuItemPeer item, MenuShortcut ms) - { - int key = 0; - boolean shiftModifier = false; - - if (ms != null) - { - key = ms.getKey (); - shiftModifier = ms.usesShiftModifier (); - } - - addItem (item, key, shiftModifier); - } - - public native void delItem(int index); -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkOffScreenImage.java b/libjava/gnu/java/awt/peer/gtk/GtkOffScreenImage.java deleted file mode 100644 index 48cea2d7231..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkOffScreenImage.java +++ /dev/null @@ -1,93 +0,0 @@ -/* GtkOffScreenImage.java - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Graphics; -import java.awt.Image; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; - -public class GtkOffScreenImage extends Image -{ - int width, height; - ImageProducer source; - Graphics g; - - public GtkOffScreenImage (ImageProducer source, Graphics g, - int width, int height) - { - this.width = width; - this.height = height; - - this.source = source; - this.g = g; - } - - public int getWidth (ImageObserver observer) - { - return width; - } - - public int getHeight (ImageObserver observer) - { - return height; - } - - public ImageProducer getSource () - { - return source; - } - - public Graphics getGraphics () - { - if (g instanceof GdkGraphics2D) - return new GdkGraphics2D ((GdkGraphics2D) this.g); - else - return new GdkGraphics ((GdkGraphics) this.g); - } - - public Object getProperty (String name, ImageObserver observer) - { - return Image.UndefinedProperty; - } - - public void flush () - { - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkPanelPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkPanelPeer.java deleted file mode 100644 index fbddb302a76..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkPanelPeer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* GtkPanelPeer.java -- Implements PanelPeer with GTK - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.Panel; -import java.awt.event.MouseEvent; -import java.awt.peer.PanelPeer; - -public class GtkPanelPeer extends GtkContainerPeer - implements PanelPeer -{ - native void create (); - - public GtkPanelPeer (Panel p) - { - super (p); - } - - public void handleEvent (AWTEvent event) - { - int id = event.getID(); - - switch (id) - { - case MouseEvent.MOUSE_PRESSED: - awtComponent.requestFocusInWindow (); - break; - } - super.handleEvent (event); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java deleted file mode 100644 index d14c16dd79d..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkPopupMenuPeer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* GtkPopupMenuPeer.java -- Implements PopupMenuPeer with GTK+ - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Component; -import java.awt.Event; -import java.awt.MenuItem; -import java.awt.Point; -import java.awt.PopupMenu; -import java.awt.peer.PopupMenuPeer; - -public class GtkPopupMenuPeer extends GtkMenuPeer - implements PopupMenuPeer -{ - public GtkPopupMenuPeer (PopupMenu menu) - { - super (menu); - } - - native void setupAccelGroup (GtkGenericPeer container); - - void setParent (MenuItem item) - { - // we don't need to "add" ourselves to our parent - } - - native void show (int x, int y, long time); - public void show (Component origin, int x, int y) - { - Point abs = origin.getLocationOnScreen (); - show (abs.x + x, abs.y + y, 0); - } - - public void show (Event e) - { - - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java b/libjava/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java deleted file mode 100644 index 69f8b494625..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkScrollPanePeer.java +++ /dev/null @@ -1,113 +0,0 @@ -/* GtkScrollPanePeer.java -- Implements ScrollPanePeer with GTK - Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Adjustable; -import java.awt.Dimension; -import java.awt.ScrollPane; -import java.awt.peer.ScrollPanePeer; - -public class GtkScrollPanePeer extends GtkContainerPeer - implements ScrollPanePeer -{ - native void create (int width, int height); - - void create () - { - create (awtComponent.getWidth (), awtComponent.getHeight ()); - } - - // native void gtkScrolledWindowSetScrollPosition(int x, int y); - native void gtkScrolledWindowSetHScrollIncrement (int u); - native void gtkScrolledWindowSetVScrollIncrement (int u); - - public GtkScrollPanePeer (ScrollPane sp) - { - super (sp); - - setPolicy (sp.getScrollbarDisplayPolicy ()); - } - - native void setPolicy (int policy); - public void childResized (int width, int height) - { - int dim[] = new int[2]; - - gtkWidgetGetDimensions (dim); - - // If the child is in this range, GTK adds both scrollbars, but - // the AWT doesn't. So set the peer's scroll policy to - // GTK_POLICY_NEVER. - if ((width > dim[0] - getVScrollbarWidth () - && width <= dim[0]) - && (height > dim[1] - getHScrollbarHeight () - && height <= dim[1])) - setPolicy (ScrollPane.SCROLLBARS_NEVER); - else - setPolicy (((ScrollPane) awtComponent).getScrollbarDisplayPolicy ()); - } - - public native int getHScrollbarHeight(); - public native int getVScrollbarWidth(); - public native void setScrollPosition(int x, int y); - - public Dimension getPreferredSize () - { - return awtComponent.getSize(); - } - - public void setUnitIncrement (Adjustable adj, int u) - { - if (adj.getOrientation()==Adjustable.HORIZONTAL) - gtkScrolledWindowSetHScrollIncrement (u); - else - gtkScrolledWindowSetVScrollIncrement (u); - } - - public void setValue (Adjustable adj, int v) - { -// System.out.println("SPP: setVal: "+adj+":"+v); -// Point p=myScrollPane.getScrollPosition (); -// if (adj.getOrientation()==Adjustable.HORIZONTAL) -// gtkScrolledWindowSetScrollPosition (v,p.y); -// else -// gtkScrolledWindowSetScrollPosition (p.x,v); -// adj.setValue(v); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java deleted file mode 100644 index aa3a26e34ad..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkScrollbarPeer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* GtkScrollbarPeer.java -- Implements ScrollbarPeer with GTK+ - Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Adjustable; -import java.awt.Scrollbar; -import java.awt.event.AdjustmentEvent; -import java.awt.peer.ScrollbarPeer; - -public class GtkScrollbarPeer extends GtkComponentPeer - implements ScrollbarPeer -{ - void create () - { - Scrollbar sb = (Scrollbar) awtComponent; - - create (sb.getOrientation (), sb.getValue (), - sb.getMinimum (), sb.getMaximum (), - sb.getUnitIncrement (), sb.getBlockIncrement (), - sb.getVisibleAmount ()); - } - - native void create (int orientation, int value, - int min, int max, int stepIncr, int pageIncr, - int visibleAmount); - - native void connectSignals (); - - public GtkScrollbarPeer (Scrollbar s) - { - super (s); - } - - public native void setLineIncrement(int amount); - public native void setPageIncrement(int amount); - public native void setValues(int value, int visible, int min, int max); - - protected void postAdjustmentEvent (int type, int value) - { - q().postEvent (new AdjustmentEvent ((Adjustable)awtComponent, - AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, - type, value)); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java deleted file mode 100644 index fb0e2ced508..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java +++ /dev/null @@ -1,178 +0,0 @@ -/* GtkTextAreaPeer.java -- Implements TextAreaPeer with GTK - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.TextArea; -import java.awt.peer.TextAreaPeer; - -public class GtkTextAreaPeer extends GtkTextComponentPeer - implements TextAreaPeer -{ - private static transient int DEFAULT_ROWS = 10; - private static transient int DEFAULT_COLS = 80; - - native void create (int width, int height, int scrollbarVisibility); - - native void gtkWidgetModifyFont (String name, int style, int size); - native void gtkWidgetRequestFocus (); - - void create () - { - Font f = awtComponent.getFont (); - - // By default, Sun sets a TextArea's font when its peer is - // created. If f != null then the peer's font is set by - // GtkComponent.create. - if (f == null) - { - f = new Font ("Dialog", Font.PLAIN, 12); - awtComponent.setFont (f); - } - - FontMetrics fm = getFontMetrics (f); - - TextArea ta = ((TextArea) awtComponent); - int sizeRows = ta.getRows (); - int sizeCols = ta.getColumns (); - - sizeRows = sizeRows == 0 ? DEFAULT_ROWS : sizeRows; - sizeCols = sizeCols == 0 ? DEFAULT_COLS : sizeCols; - - int width = sizeCols * fm.getMaxAdvance (); - int height = sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); - - create (width, height, ta.getScrollbarVisibility ()); - setEditable (ta.isEditable ()); - } - - public GtkTextAreaPeer (TextArea ta) - { - super (ta); - } - - public native void insert (String str, int pos); - public native void replaceRange (String str, int start, int end); - - public Dimension getMinimumSize (int rows, int cols) - { - return minimumSize (rows == 0 ? DEFAULT_ROWS : rows, - cols == 0 ? DEFAULT_COLS : cols); - } - - public Dimension getPreferredSize (int rows, int cols) - { - return preferredSize (rows == 0 ? DEFAULT_ROWS : rows, - cols == 0 ? DEFAULT_COLS : cols); - } - - native int getHScrollbarHeight (); - native int getVScrollbarWidth (); - - // Deprecated - public Dimension minimumSize (int rows, int cols) - { - TextArea ta = ((TextArea) awtComponent); - int height = 0; - int width = 0; - - if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH - || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY) - height = getHScrollbarHeight (); - - if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH - || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY) - width = getVScrollbarWidth (); - - Font f = awtComponent.getFont (); - if (f == null) - return new Dimension (width, height); - - FontMetrics fm = getFontMetrics (f); - - int sizeRows = rows == 0 ? DEFAULT_ROWS : rows; - int sizeCols = cols == 0 ? DEFAULT_COLS : cols; - - width += sizeCols * fm.getMaxAdvance (); - height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); - - return new Dimension (width, height); - } - - public Dimension preferredSize (int rows, int cols) - { - TextArea ta = ((TextArea) awtComponent); - int height = 0; - int width = 0; - - if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH - || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY) - height = getHScrollbarHeight (); - - if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH - || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY) - width = getVScrollbarWidth (); - - Font f = awtComponent.getFont (); - if (f == null) - return new Dimension (width, height); - - FontMetrics fm = getFontMetrics (f); - - int sizeRows = rows == 0 ? DEFAULT_ROWS : rows; - int sizeCols = cols == 0 ? DEFAULT_COLS : cols; - - width += sizeCols * fm.getMaxAdvance (); - height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); - - return new Dimension (width, height); - } - - public void replaceText (String str, int start, int end) - { - replaceRange (str, start, end); - } - - public void insertText (String str, int pos) - { - insert (str, pos); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java deleted file mode 100644 index c1f1cf0e1ae..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java +++ /dev/null @@ -1,87 +0,0 @@ -/* GtkTextComponentPeer.java -- Implements TextComponentPeer with GTK - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Rectangle; -import java.awt.TextComponent; -import java.awt.event.TextEvent; -import java.awt.peer.TextComponentPeer; - -public class GtkTextComponentPeer extends GtkComponentPeer - implements TextComponentPeer -{ - GtkTextComponentPeer (TextComponent tc) - { - super (tc); - - setText (tc.getText ()); - setCaretPosition(0); - } - - public native void connectSignals (); - - public native int getCaretPosition (); - public native void setCaretPosition (int pos); - public native int getSelectionStart (); - public native int getSelectionEnd (); - public native String getText (); - public native void select (int start, int end); - public native void setEditable (boolean state); - public native void setText (String text); - - public int getIndexAtPoint(int x, int y) - { - return 0; // FIXME - } - - public Rectangle getCharacterBounds (int pos) - { - return null; - } - - public long filterEvents (long filter) - { - return filter; // FIXME - } - - protected void postTextEvent () - { - q().postEvent (new TextEvent (awtComponent, TextEvent.TEXT_VALUE_CHANGED)); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java deleted file mode 100644 index 1031f7cc9e6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java +++ /dev/null @@ -1,162 +0,0 @@ -/* GtkTextFieldPeer.java -- Implements TextFieldPeer with GTK - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.AWTEvent; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.TextField; -import java.awt.event.KeyEvent; -import java.awt.peer.TextFieldPeer; - -public class GtkTextFieldPeer extends GtkTextComponentPeer - implements TextFieldPeer -{ - native void create (int width); - native void gtkWidgetSetBackground (int red, int green, int blue); - native void gtkWidgetSetForeground (int red, int green, int blue); - - void create () - { - Font f = awtComponent.getFont (); - - // By default, Sun sets a TextField's font when its peer is - // created. If f != null then the peer's font is set by - // GtkComponent.create. - if (f == null) - { - f = new Font ("Dialog", Font.PLAIN, 12); - awtComponent.setFont (f); - } - - FontMetrics fm = getFontMetrics (f); - - TextField tf = ((TextField) awtComponent); - int cols = tf.getColumns (); - - int text_width = cols * fm.getMaxAdvance (); - - create (text_width); - - setEditable (tf.isEditable ()); - } - - native int gtkEntryGetBorderWidth (); - - native void gtkWidgetModifyFont (String name, int style, int size); - - public GtkTextFieldPeer (TextField tf) - { - super (tf); - - if (tf.echoCharIsSet ()) - setEchoChar (tf.getEchoChar ()); - } - - public Dimension getMinimumSize (int cols) - { - return minimumSize (cols); - } - - public Dimension getPreferredSize (int cols) - { - return preferredSize (cols); - } - - public native void setEchoChar (char c); - - // Deprecated - public Dimension minimumSize (int cols) - { - int dim[] = new int[2]; - - gtkWidgetGetPreferredDimensions (dim); - - Font f = awtComponent.getFont (); - if (f == null) - return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]); - - FontMetrics fm = getFontMetrics (f); - - int text_width = cols * fm.getMaxAdvance (); - - int width = text_width + 2 * gtkEntryGetBorderWidth (); - - return new Dimension (width, dim[1]); - } - - public Dimension preferredSize (int cols) - { - int dim[] = new int[2]; - - gtkWidgetGetPreferredDimensions (dim); - - Font f = awtComponent.getFont (); - if (f == null) - return new Dimension (2 * gtkEntryGetBorderWidth (), dim[1]); - - FontMetrics fm = getFontMetrics (f); - - int text_width = cols * fm.getMaxAdvance (); - - int width = text_width + 2 * gtkEntryGetBorderWidth (); - - return new Dimension (width, dim[1]); - } - - public void setEchoCharacter (char c) - { - setEchoChar (c); - } - - public void handleEvent (AWTEvent e) - { - if (e.getID () == KeyEvent.KEY_PRESSED) - { - KeyEvent ke = (KeyEvent) e; - - if (!ke.isConsumed () - && ke.getKeyCode () == KeyEvent.VK_ENTER) - postActionEvent (getText (), ke.getModifiersEx ()); - } - - super.handleEvent (e); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java deleted file mode 100644 index 10afde77c74..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java +++ /dev/null @@ -1,670 +0,0 @@ -/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers - Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import gnu.classpath.Configuration; -import gnu.java.awt.EmbeddedWindow; -import gnu.java.awt.EmbeddedWindowSupport; -import gnu.java.awt.peer.ClasspathFontPeer; -import gnu.java.awt.peer.ClasspathTextLayoutPeer; -import gnu.java.awt.peer.EmbeddedWindowPeer; - -import java.awt.*; -import java.awt.datatransfer.Clipboard; -import java.awt.dnd.DragGestureEvent; -import java.awt.dnd.peer.DragSourceContextPeer; -import java.awt.font.FontRenderContext; -import java.awt.im.InputMethodHighlight; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.ImageConsumer; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.peer.*; -import java.io.InputStream; -import java.net.URL; -import java.text.AttributedString; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; - -import javax.imageio.spi.IIORegistry; - -/* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer(). - This merits comment. We are basically calling Sun's bluff on this one. - We think Sun has deprecated it simply to discourage its use as it is - bad programming style. However, we need to get at a component's peer in - this class. If getPeer() ever goes away, we can implement a hash table - that will keep up with every window's peer, but for now this is faster. */ - -/** - * This class accesses a system property called - * <tt>gnu.java.awt.peer.gtk.Graphics</tt>. If the property is defined and - * equal to "Graphics2D", the cairo-based GdkGraphics2D will be used in - * drawing contexts. Any other value will cause the older GdkGraphics - * object to be used. - */ -public class GtkToolkit extends gnu.java.awt.ClasspathToolkit - implements EmbeddedWindowSupport -{ - Hashtable containers = new Hashtable(); - static EventQueue q; - static Clipboard systemClipboard; - static boolean useGraphics2dSet; - static boolean useGraphics2d; - - public static boolean useGraphics2D() - { - if (useGraphics2dSet) - return useGraphics2d; - useGraphics2d = System.getProperty("gnu.java.awt.peer.gtk.Graphics", - "Graphics").equals("Graphics2D"); - useGraphics2dSet = true; - return useGraphics2d; - } - - static native void gtkInit(int portableNativeSync); - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - System.loadLibrary("gtkpeer"); - - int portableNativeSync; - String portNatSyncProp = - System.getProperty("gnu.classpath.awt.gtk.portable.native.sync"); - - if (portNatSyncProp == null) - portableNativeSync = -1; // unset - else if (Boolean.valueOf(portNatSyncProp).booleanValue()) - portableNativeSync = 1; // true - else - portableNativeSync = 0; // false - - gtkInit(portableNativeSync); - } - - public GtkToolkit () - { - systemClipboard = new GtkClipboard (); - } - - public native void beep(); - private native void getScreenSizeDimensions(int[] xy); - - public int checkImage (Image image, int width, int height, - ImageObserver observer) - { - int status = ImageObserver.ALLBITS - | ImageObserver.WIDTH - | ImageObserver.HEIGHT; - - if (image instanceof GtkImage) - { - status = ((GtkImage) image).checkImage (); - } - - if (observer != null) - observer.imageUpdate (image, status, - -1, -1, - image.getWidth (observer), - image.getHeight (observer)); - - return status; - } - - /** - * A helper class to return to clients in cases where a BufferedImage is - * desired but its construction fails. - */ - private class GtkErrorImage extends Image - { - public GtkErrorImage() - { - } - - public int getWidth(ImageObserver observer) - { - return -1; - } - - public int getHeight(ImageObserver observer) - { - return -1; - } - - public ImageProducer getSource() - { - - return new ImageProducer() - { - HashSet consumers = new HashSet(); - public void addConsumer(ImageConsumer ic) - { - consumers.add(ic); - } - - public boolean isConsumer(ImageConsumer ic) - { - return consumers.contains(ic); - } - - public void removeConsumer(ImageConsumer ic) - { - consumers.remove(ic); - } - - public void startProduction(ImageConsumer ic) - { - consumers.add(ic); - Iterator i = consumers.iterator(); - while(i.hasNext()) - { - ImageConsumer c = (ImageConsumer) i.next(); - c.imageComplete(ImageConsumer.IMAGEERROR); - } - } - public void requestTopDownLeftRightResend(ImageConsumer ic) - { - startProduction(ic); - } - }; - } - - public Graphics getGraphics() - { - return null; - } - - public Object getProperty(String name, ImageObserver observer) - { - return null; - } - public Image getScaledInstance(int width, int height, int flags) - { - return new GtkErrorImage(); - } - - public void flush() - { - } - } - - - /** - * Helper to return either a BufferedImage -- the argument -- or a - * GtkErrorImage if the argument is null. - */ - - private Image bufferedImageOrError(BufferedImage b) - { - if (b == null) - return new GtkErrorImage(); - else - return b; - } - - - public Image createImage (String filename) - { - if (useGraphics2D()) - return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename)); - else - { - GdkPixbufDecoder d = new GdkPixbufDecoder (filename); - GtkImage image = new GtkImage (d, null); - d.startProduction (image); - return image; - } - } - - public Image createImage (URL url) - { - if (useGraphics2D()) - return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url)); - else - { - GdkPixbufDecoder d = new GdkPixbufDecoder (url); - GtkImage image = new GtkImage (d, null); - d.startProduction (image); - return image; - } - } - - public Image createImage (ImageProducer producer) - { - if (useGraphics2D()) - return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer)); - else - { - GtkImage image = new GtkImage (producer, null); - producer.startProduction (image); - return image; - } - } - - public Image createImage (byte[] imagedata, int imageoffset, - int imagelength) - { - if (useGraphics2D()) - return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata, - imageoffset, - imagelength)); - else - { - GdkPixbufDecoder d = new GdkPixbufDecoder (imagedata, - imageoffset, - imagelength); - GtkImage image = new GtkImage (d, null); - d.startProduction (image); - return image; - } - } - - /** - * Creates an ImageProducer from the specified URL. The image is assumed - * to be in a recognised format. - * - * @param url URL to read image data from. - */ - public ImageProducer createImageProducer(URL url) - { - return new GdkPixbufDecoder(url); - } - - public ColorModel getColorModel () - { - return ColorModel.getRGBdefault (); - } - - public String[] getFontList () - { - return (new String[] { "Dialog", - "DialogInput", - "Monospaced", - "Serif", - "SansSerif" }); - } - - private class LRUCache extends LinkedHashMap - { - int max_entries; - public LRUCache(int max) - { - super(max, 0.75f, true); - max_entries = max; - } - protected boolean removeEldestEntry(Map.Entry eldest) - { - return size() > max_entries; - } - } - - private LRUCache fontCache = new LRUCache(50); - private LRUCache metricsCache = new LRUCache(50); - private LRUCache imageCache = new LRUCache(50); - - public FontMetrics getFontMetrics (Font font) - { - synchronized (metricsCache) - { - if (metricsCache.containsKey(font)) - return (FontMetrics) metricsCache.get(font); - } - - FontMetrics m = new GdkFontMetrics (font); - synchronized (metricsCache) - { - metricsCache.put(font, m); - } - return m; - } - - public Image getImage (String filename) - { - if (imageCache.containsKey(filename)) - return (Image) imageCache.get(filename); - else - { - Image im = createImage(filename); - imageCache.put(filename, im); - return im; - } - } - - public Image getImage (URL url) - { - if (imageCache.containsKey(url)) - return (Image) imageCache.get(url); - else - { - Image im = createImage(url); - imageCache.put(url, im); - return im; - } - } - - public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props) - { - return null; - } - - public native int getScreenResolution(); - - public Dimension getScreenSize () - { - int dim[] = new int[2]; - getScreenSizeDimensions(dim); - return new Dimension(dim[0], dim[1]); - } - - public Clipboard getSystemClipboard() - { - return systemClipboard; - } - - public boolean prepareImage (Image image, int width, int height, - ImageObserver observer) - { - GtkImage i = (GtkImage) image; - - if (i.isLoaded ()) return true; - - class PrepareImage extends Thread - { - GtkImage image; - ImageObserver observer; - - PrepareImage (GtkImage image, ImageObserver observer) - { - this.image = image; - image.setObserver (observer); - } - - public void run () - { - image.source.startProduction (image); - } - } - - new PrepareImage (i, observer).start (); - return false; - } - - public native void sync(); - - protected void setComponentState (Component c, GtkComponentPeer cp) - { - /* Make the Component reflect Peer defaults */ - if (c.getForeground () == null) - c.setForeground (cp.getForeground ()); - if (c.getBackground () == null) - c.setBackground (cp.getBackground ()); - // if (c.getFont () == null) - // c.setFont (cp.getFont ()); - - /* Make the Peer reflect the state of the Component */ - if (! (c instanceof Window)) - { - cp.setCursor (c.getCursor ()); - - Rectangle bounds = c.getBounds (); - cp.setBounds (bounds.x, bounds.y, bounds.width, bounds.height); - cp.setVisible (c.isVisible ()); - } - } - - protected ButtonPeer createButton (Button b) - { - return new GtkButtonPeer (b); - } - - protected CanvasPeer createCanvas (Canvas c) - { - return new GtkCanvasPeer (c); - } - - protected CheckboxPeer createCheckbox (Checkbox cb) - { - return new GtkCheckboxPeer (cb); - } - - protected CheckboxMenuItemPeer createCheckboxMenuItem (CheckboxMenuItem cmi) - { - return new GtkCheckboxMenuItemPeer (cmi); - } - - protected ChoicePeer createChoice (Choice c) - { - return new GtkChoicePeer (c); - } - - protected DialogPeer createDialog (Dialog d) - { - return new GtkDialogPeer (d); - } - - protected FileDialogPeer createFileDialog (FileDialog fd) - { - return new GtkFileDialogPeer (fd); - } - - protected FramePeer createFrame (Frame f) - { - return new GtkFramePeer (f); - } - - protected LabelPeer createLabel (Label label) - { - return new GtkLabelPeer (label); - } - - protected ListPeer createList (List list) - { - return new GtkListPeer (list); - } - - protected MenuPeer createMenu (Menu m) - { - return new GtkMenuPeer (m); - } - - protected MenuBarPeer createMenuBar (MenuBar mb) - { - return new GtkMenuBarPeer (mb); - } - - protected MenuItemPeer createMenuItem (MenuItem mi) - { - return new GtkMenuItemPeer (mi); - } - - protected PanelPeer createPanel (Panel p) - { - return new GtkPanelPeer (p); - } - - protected PopupMenuPeer createPopupMenu (PopupMenu target) - { - return new GtkPopupMenuPeer (target); - } - - protected ScrollPanePeer createScrollPane (ScrollPane sp) - { - return new GtkScrollPanePeer (sp); - } - - protected ScrollbarPeer createScrollbar (Scrollbar sb) - { - return new GtkScrollbarPeer (sb); - } - - protected TextAreaPeer createTextArea (TextArea ta) - { - return new GtkTextAreaPeer (ta); - } - - protected TextFieldPeer createTextField (TextField tf) - { - return new GtkTextFieldPeer (tf); - } - - protected WindowPeer createWindow (Window w) - { - return new GtkWindowPeer (w); - } - - public EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w) - { - return new GtkEmbeddedWindowPeer (w); - } - - /** - * @deprecated part of the older "logical font" system in earlier AWT - * implementations. Our newer Font class uses getClasspathFontPeer. - */ - protected FontPeer getFontPeer (String name, int style) { - // All fonts get a default size of 12 if size is not specified. - return getFontPeer(name, style, 12); - } - - /** - * Private method that allows size to be set at initialization time. - */ - private FontPeer getFontPeer (String name, int style, int size) - { - Map attrs = new HashMap (); - ClasspathFontPeer.copyStyleToAttrs (style, attrs); - ClasspathFontPeer.copySizeToAttrs (size, attrs); - return getClasspathFontPeer (name, attrs); - } - - /** - * Newer method to produce a peer for a Font object, even though Sun's - * design claims Font should now be peerless, we do not agree with this - * model, hence "ClasspathFontPeer". - */ - - public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs) - { - Map keyMap = new HashMap (attrs); - // We don't know what kind of "name" the user requested (logical, face, - // family), and we don't actually *need* to know here. The worst case - // involves failure to consolidate fonts with the same backend in our - // cache. This is harmless. - keyMap.put ("GtkToolkit.RequestedFontName", name); - if (fontCache.containsKey (keyMap)) - return (ClasspathFontPeer) fontCache.get (keyMap); - else - { - ClasspathFontPeer newPeer = new GdkFontPeer (name, attrs); - fontCache.put (keyMap, newPeer); - return newPeer; - } - } - - public ClasspathTextLayoutPeer getClasspathTextLayoutPeer (AttributedString str, - FontRenderContext frc) - { - return new GdkTextLayout(str, frc); - } - - protected EventQueue getSystemEventQueueImpl() - { - synchronized (GtkToolkit.class) - { - if (q == null) - { - q = new EventQueue(); - GtkGenericPeer.enableQueue (q); - } - } - return q; - } - - protected native void loadSystemColors (int[] systemColors); - - public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e) - { - throw new Error("not implemented"); - } - - public Map mapInputMethodHighlight(InputMethodHighlight highlight) - { - throw new Error("not implemented"); - } - - public Rectangle getBounds() - { - int[] dims = new int[2]; - getScreenSizeDimensions(dims); - return new Rectangle(0, 0, dims[0], dims[1]); - } - - // ClasspathToolkit methods - - public GraphicsEnvironment getLocalGraphicsEnvironment() - { - return new GdkGraphicsEnvironment(this); - } - - public Font createFont(int format, InputStream stream) - { - throw new UnsupportedOperationException(); - } - - public RobotPeer createRobot (GraphicsDevice screen) throws AWTException - { - return new GdkRobotPeer (screen); - } - - public void registerImageIOSpis(IIORegistry reg) - { - GdkPixbufDecoder.registerSpis(reg); - } - - public native boolean nativeQueueEmpty(); - public native void wakeNativeQueue(); - public native void iterateNativeQueue(EventQueue locked, boolean block); - -} // class GtkToolkit diff --git a/libjava/gnu/java/awt/peer/gtk/GtkVolatileImage.java b/libjava/gnu/java/awt/peer/gtk/GtkVolatileImage.java deleted file mode 100644 index 496090a0940..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkVolatileImage.java +++ /dev/null @@ -1,118 +0,0 @@ -/* GtkVolatileImage.java -- a hardware-accelerated image buffer - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.awt.peer.gtk; - -import java.awt.ImageCapabilities; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.image.BufferedImage; -import java.awt.image.ImageObserver; -import java.awt.image.VolatileImage; - -public class GtkVolatileImage extends VolatileImage -{ - private int width; - private int height; - private ImageCapabilities caps; - - public GtkVolatileImage(int width, int height) - { - this(width, height, null); - } - - public GtkVolatileImage(int width, int height, ImageCapabilities caps) - { - this.width = width; - this.height = height; - this.caps = caps; - } - - // FIXME: should return a buffered image snapshot of the accelerated - // visual - public BufferedImage getSnapshot() - { - return null; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - // FIXME: should return a graphics wrapper around this image's - // visual - public Graphics2D createGraphics() - { - return null; - } - - public int validate(GraphicsConfiguration gc) - { - return VolatileImage.IMAGE_OK; - } - - public boolean contentsLost() - { - return false; - } - - public ImageCapabilities getCapabilities() - { - return caps; - } - - public synchronized Object getProperty (String name, ImageObserver observer) - { - return null; - } - - public synchronized int getWidth (ImageObserver observer) - { - return width; - } - - public synchronized int getHeight (ImageObserver observer) - { - return height; - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkWindowPeer.java deleted file mode 100644 index bd16f3c7695..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ /dev/null @@ -1,210 +0,0 @@ -/* GtkWindowPeer.java -- Implements WindowPeer with GTK - Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.awt.peer.gtk; - -import java.awt.Component; -import java.awt.Frame; -import java.awt.Window; -import java.awt.event.WindowEvent; -import java.awt.peer.WindowPeer; - -public class GtkWindowPeer extends GtkContainerPeer - implements WindowPeer -{ - protected static final int GDK_WINDOW_TYPE_HINT_NORMAL = 0; - protected static final int GDK_WINDOW_TYPE_HINT_DIALOG = 1; - protected static final int GDK_WINDOW_TYPE_HINT_MENU = 2; - protected static final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3; - protected static final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4; - protected static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5; - protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6; - protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7; - - private boolean hasBeenShown = false; - private int oldState = Frame.NORMAL; - - native void gtkWindowSetTitle (String title); - native void gtkWindowSetResizable (boolean resizable); - native void gtkWindowSetModal (boolean modal); - - int getWidth () - { - return awtComponent.getWidth(); - } - - int getHeight () - { - return awtComponent.getHeight(); - } - - native void create (int type, boolean decorated, GtkWindowPeer parent); - - void create (int type, boolean decorated) - { - GtkWindowPeer parent_peer = null; - Component parent = awtComponent.getParent(); - - if (parent != null) - parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer(); - - create (type, decorated, parent_peer); - } - - void create () - { - // Create a normal undecorated window. - create (GDK_WINDOW_TYPE_HINT_NORMAL, false); - } - - void setParent () - { - setVisible (awtComponent.isVisible ()); - setEnabled (awtComponent.isEnabled ()); - } - - void setVisibleAndEnabled () - { - } - - native void connectSignals (); - - public GtkWindowPeer (Window window) - { - super (window); - } - - public native void toBack(); - public native void toFront(); - - native void nativeSetBounds (int x, int y, int width, int height); - - public void setBounds (int x, int y, int width, int height) - { - nativeSetBounds (x, y, - width - insets.left - insets.right, - height - insets.top - insets.bottom); - } - - public void setTitle (String title) - { - gtkWindowSetTitle (title); - } - - native void setSize (int width, int height); - - public void setResizable (boolean resizable) - { - // Call setSize; otherwise when resizable is changed from true to - // false the window will shrink to the dimensions it had before it - // was resizable. - setSize (awtComponent.getWidth() - insets.left - insets.right, - awtComponent.getHeight() - insets.top - insets.bottom); - gtkWindowSetResizable (resizable); - } - - native void setBoundsCallback (Window window, - int x, int y, - int width, int height); - - protected void postInsetsChangedEvent (int top, int left, - int bottom, int right) - { - insets.top = top; - insets.left = left; - insets.bottom = bottom; - insets.right = right; - } - - protected void postConfigureEvent (int x, int y, int width, int height) - { - int frame_x = x - insets.left; - int frame_y = y - insets.top; - int frame_width = width + insets.left + insets.right; - int frame_height = height + insets.top + insets.bottom; - - if (frame_x != awtComponent.getX() - || frame_y != awtComponent.getY() - || frame_width != awtComponent.getWidth() - || frame_height != awtComponent.getHeight()) - { - setBoundsCallback ((Window) awtComponent, - frame_x, frame_y, frame_width, frame_height); - - awtComponent.validate(); - } - } - - native void nativeSetVisible (boolean b); - public void setVisible (boolean b) - { - // Prevent the window manager from automatically placing this - // window when it is shown. - if (b) - setBounds (awtComponent.getX(), - awtComponent.getY(), - awtComponent.getWidth(), - awtComponent.getHeight()); - nativeSetVisible (b); - } - - void postWindowEvent (int id, Window opposite, int newState) - { - if (id == WindowEvent.WINDOW_OPENED) - { - // Post a WINDOW_OPENED event the first time this window is shown. - if (!hasBeenShown) - { - q().postEvent (new WindowEvent ((Window) awtComponent, id, - opposite)); - hasBeenShown = true; - } - } - else if (id == WindowEvent.WINDOW_STATE_CHANGED) - { - if (oldState != newState) - { - q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite, - oldState, newState)); - oldState = newState; - } - } - else - q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite)); - } -} diff --git a/libjava/gnu/java/awt/peer/gtk/Test.java b/libjava/gnu/java/awt/peer/gtk/Test.java deleted file mode 100644 index 66f37d814bd..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/Test.java +++ /dev/null @@ -1,299 +0,0 @@ -/* Test.java -- Tests the GTK Toolkit - Copyright (C) 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -import java.util.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.peer.*; -import java.awt.datatransfer.*; -import gnu.java.awt.image.*; -import java.io.*; - -class Test -{ - static int xs = 5, ys = 5; - - public static void main(String args[]) - { - if (args.length == 0) - { - Properties prop=System.getProperties (); - prop.put ("awt.toolkit","gnu.java.awt.peer.gtk.GtkToolkit"); - } - - final Frame f=new Frame(); - f.setTitle ("Red Hat Classpath"); - -// f.addComponentListener (new ComponentAdapter() { -// public void componentMoved (ComponentEvent e) { -// System.out.println("component moved"); -// } -// public void componentResized (ComponentEvent e) { -// System.out.println("component resized"); -// } -// }); - f.setSize(200,200); - - Panel pan=new Panel(); - - final Label l = new Label ("Pithy Message:"); - l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR)); - pan.add (l); - - TextField tf = new TextField("Hello world!"); - pan.add(tf); - - final Image img; - img = Toolkit.getDefaultToolkit ().createImage (new XBMDecoder ("fvwm.xbm")); - - - final Canvas ch = new Canvas () { - - public void update (Graphics g) - { - System.out.println ("update called"); - super.update (g); - } - public void paint (Graphics g) { - g.drawString("Hello world!", xs+5, ys+10); - g.setColor (Color.blue); - g.drawLine (xs,ys,xs+20,ys+20); - -// System.out.println (TextArea.SCROLLBARS_BOTH); -// System.out.println (TextArea.SCROLLBARS_HORIZONTAL_ONLY); -// System.out.println (TextArea.SCROLLBARS_VERTICAL_ONLY); - -// Font f1 = new Font ("TimesRoman", Font.PLAIN, 10); -// System.out.println (f1.getName ()); -// System.out.println (f1.getFamily ()); - -// Font font = new Font ("Serif", Font.PLAIN, 18); -// g.setFont (font); -// g.setXORMode (Color.red); - - -// System.out.println (g.getFontMetrics (font).stringWidth ("foobar")); - -// System.out.println (g.drawImage (img, 0, 0, this)); - } - }; - - ch.setSize(60, 60); -// List ch=new List(); -// ch.add("Ding"); -// ch.add("September"); -// ch.add("Red"); -// ch.add("Quassia"); -// ch.add("Pterodactyl"); - -// ch.addMouseListener(new MouseAdapter() { -// public void mousePressed(MouseEvent e) { -// System.out.println("mouse pressed ch"); -// System.out.println("shift = " + e.isShiftDown()); -// System.out.println("meta = " + e.isMetaDown()); -// System.out.println("alt = " + e.isAltDown()); -// System.out.println("ctrl = " + e.isControlDown()); -// System.out.println("x = " + e.getX()); -// System.out.println("y = " + e.getY()); -// System.out.println("clickcount = " + e.getClickCount()); -// System.out.println("when = " + e.getWhen()); -// System.out.println(); -// } -// public void mouseReleased(MouseEvent e) { -// System.out.println("mouse released ch"); -// } -// public void mouseClicked(MouseEvent e) { -// System.out.println("mouse clicked ch"); -// } -// }); - - pan.add(ch); - f.add(pan,"North"); - - final ScrollPane sp=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); - System.out.println ("ALWAYS HERE: " + ScrollPane.SCROLLBARS_ALWAYS); - System.out.println ("ALWAYS" + ScrollPane.SCROLLBARS_ALWAYS); - System.out.println ("NEEDED" + ScrollPane.SCROLLBARS_AS_NEEDED); - System.out.println ("NEVER " + ScrollPane.SCROLLBARS_NEVER); - - - final Panel p=new Panel(); - System.out.println ("PREFERED: " + p.getPreferredSize ()); - p.add(new Button("Stop")); - System.out.println ("PREFERED: " + p.getPreferredSize ()); - p.add(new Button("evil")); - System.out.println ("PREFERED: " + p.getPreferredSize ()); - p.add(new Button("hoarders")); - p.add(new Button("use")); - p.add(new Button("GNU")); - p.add(new Scrollbar(Scrollbar.HORIZONTAL)); - System.out.println ("PREFERED: " + p.getPreferredSize ()); - - sp.add(p); - f.add(sp,"South"); - - Panel east_panel = new Panel(); - east_panel.setLayout(new GridLayout (0,1)); - -// CheckboxGroup group = new CheckboxGroup(); - -// Checkbox cb=new Checkbox("one", group, true); -// east_panel.add(cb); -// cb=new Checkbox("two", group, false); -// east_panel.add(cb); - -// cb.addMouseListener(new MouseAdapter() { -// public void mousePressed(MouseEvent e) { -// System.out.println("mouse pressed cb"); -// System.out.println("shift = " + e.isShiftDown()); -// System.out.println("meta = " + e.isMetaDown()); -// System.out.println("alt = " + e.isAltDown()); -// System.out.println("ctrl = " + e.isControlDown()); -// System.out.println("x = " + e.getX()); -// System.out.println("y = " + e.getY()); -// System.out.println("clickcount = " + e.getClickCount()); -// System.out.println("when = " + e.getWhen()); -// System.out.println(); -// } -// public void mouseReleased(MouseEvent e) { -// System.out.println("mouse released cb"); -// } -// public void mouseClicked(MouseEvent e) { -// System.out.println("mouse clicked cb"); -// } -// public void mouseEntered(MouseEvent e) { -// System.out.println("mouse entered cb"); -// } -// public void mouseExited(MouseEvent e) { -// System.out.println("mouse exited cb"); -// } -// }); - - f.add(east_panel,"East"); - - final Button wb=new Button(); - wb.setLabel("Destroy Frame on Click"); - wb.addActionListener (new ActionListener () { - public void actionPerformed (ActionEvent e) { - ScrollPanePeer peer = (ScrollPanePeer)sp.getPeer (); - if (peer != null) - { - System.out.println (peer.getHScrollbarHeight ()); - System.out.println (peer.getVScrollbarWidth ()); - } - - l.setText ("Hello World!"); - System.out.println ("PREFERED: " + p.getPreferredSize ()); - - final Dialog d = new Dialog (f); - d.setModal (true); - Button b = new Button ("foobar"); - b.addMouseListener (new MouseAdapter () { - public void mousePressed (MouseEvent me) { - System.out.println ("I got called"); - d.hide (); - -// System.out.println (ScrollPane.SCROLLBARS_ALWAYS); -// System.out.println (ScrollPane.SCROLLBARS_AS_NEEDED); -// System.out.println (ScrollPane.SCROLLBARS_NEVER); - } - }); - d.add (b); - d.pack (); - d.show (); - System.out.println ("hello world"); -// System.out.println ("action listener on wb called"); -// Clipboard clip = Toolkit.getDefaultToolkit ().getSystemClipboard (); -// StringSelection ss = new StringSelection("123456789"); -// clip.setContents (ss, ss); -// Transferable t = clip.getContents (this); -// try { -// System.out.println (t.getTransferData (DataFlavor.stringFlavor)); -// } catch (Exception ex) { -// ex.printStackTrace (); -// } -// System.exit (0); - } - }); - - wb.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - System.out.println("mouse pressed wb"); - xs++; - ys++; - ch.repaint (); - } - public void mouseReleased(MouseEvent e) { - System.out.println("mouse released wb"); - } - public void mouseClicked(MouseEvent e) { - System.out.println("mouse clicked wb"); - } - public void mouseEntered(MouseEvent e) { - System.out.println("mouse entered wb"); - } - public void mouseExited(MouseEvent e) { - System.out.println("mouse exited wb"); - } - }); - - f.add(wb,"West"); - - f.pack(); - f.show(); - - sp.setScrollPosition (10,0); - - Toolkit t = Toolkit.getDefaultToolkit(); - /* t.beep(); */ - System.out.println("screen size: " + t.getScreenSize()); - System.out.println("resolution : " + t.getScreenResolution()); -// try { -// Thread.sleep (5000); -// } catch (InterruptedException e) {} -// f.setSize(500,500); - - System.out.println ("background of canvas: " + ch.getBackground ()); - System.out.println ("foreground of canvas: " + ch.getForeground ()); - - System.out.println("done"); - } -} - - - diff --git a/libjava/gnu/java/awt/peer/gtk/TestAWT.java b/libjava/gnu/java/awt/peer/gtk/TestAWT.java deleted file mode 100644 index 3fb00a4f2d6..00000000000 --- a/libjava/gnu/java/awt/peer/gtk/TestAWT.java +++ /dev/null @@ -1,613 +0,0 @@ -/* TestAWT.java -- Tests the AWT like testgtk - Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -import java.awt.List; -import java.util.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.peer.*; - -class TestAWT -{ - public static void main(String args[]) - { - if (args.length==0) - { - Properties prop = System.getProperties (); - prop.put ("awt.toolkit", "gnu.java.awt.peer.gtk.GtkToolkit"); - } - MainWindow f = new MainWindow(); - System.out.println(f.isDisplayable()); - f.show(); - System.out.println(f.isDisplayable()); - } -} - -interface SubWindow -{ - public void init (); -} - -class PrettyPanel extends Panel -{ - Insets myInsets; - - public PrettyPanel () - { - myInsets = new Insets (10, 10, 10, 10); - } - public Insets getInsets () - { - return myInsets; - } -} - -abstract class PrettyFrame extends Frame -{ - public PrettyFrame () - { - ((BorderLayout) getLayout ()).setHgap (5); - ((BorderLayout) getLayout ()).setVgap (5); - } - -// public Insets getInsets() -// { -// Insets oldInsets = super.getInsets (); -// return new Insets (oldInsets.top+10, -// oldInsets.left+10, -// oldInsets.bottom+10, -// oldInsets.right+10); -// } -} - -abstract class SubFrame extends PrettyFrame implements SubWindow -{ - boolean initted = false; - - public void setVisible (boolean visible) - { - if (!initted && visible) - init(); - super.setVisible (visible); - } -} - -class MainWindow extends PrettyFrame implements ActionListener -{ - Button closeButton; - - Hashtable windows; - Vector buttons; - - void addSubWindow (String name, SubWindow w) - { - Button b = new Button (name); - b.addActionListener (this); - - buttons.addElement (b); - windows.put (b, w); - } - - MainWindow () - { - MenuBar mb = new MenuBar (); - Menu menu = new Menu ("File"); - Menu submenu = new Menu ("Testing"); - submenu.add (new CheckboxMenuItem ("Foobar")); - menu.add (submenu); - mb.add (menu); - - setMenuBar (mb); - - add (new Label ("Classpath v0.0.0"), "North"); - - closeButton = new Button ("Close"); - closeButton.addActionListener (this); - closeButton.setFont (new Font ("Serif", Font.BOLD | Font.ITALIC, 18)); - add (closeButton, "South"); - - windows = new Hashtable (); - buttons = new Vector (); - - addSubWindow ("Buttons", new ButtonsWindow ()); - addSubWindow ("Cursors", new CursorsWindow ()); - addSubWindow ("Dialog", new DialogWindow (this)); - addSubWindow ("File", new FileWindow (this)); - addSubWindow ("Labels", new LabelWindow ()); - addSubWindow ("List", new ListWindow ()); - addSubWindow ("Radio Buttons", new RadioWindow ()); - addSubWindow ("TextField", new TextFieldWindow ()); - - Panel sp = new Panel(); - PrettyPanel p = new PrettyPanel(); - p.setLayout (new GridLayout (windows.size(), 1)); - - for (Enumeration e = buttons.elements (); e.hasMoreElements (); ) - { - p.add ((Button) e.nextElement ()); - } - - sp.add (p); - add (sp, "Center"); - - setSize (200, 86 + (windows.size ()*22)); - setTitle ("TestAWT"); - } - - public void actionPerformed (ActionEvent evt) - { - Button source = (Button) evt.getSource (); - - if (source==closeButton) - { - System.getProperties ().list (System.out); - dispose(); - System.exit (0); - } - - Window w = (Window) windows.get (source); - if (w.isVisible ()) - w.dispose (); - else - { - if (w instanceof Dialog) - { - System.out.println ("Will 'show'"); - w.show(); - System.out.println ("Has shown"); - } - else - { - w.setVisible (true); - } - } - } -} - -class ButtonsWindow extends SubFrame implements ActionListener -{ - Button b[] = new Button [9]; - - public void init () - { - initted = true; - Panel p = new Panel (); - p.setLayout (new GridLayout (0, 3, 5, 5)); - - for (int i=0; i<9; i++) - { - b[i]=new Button ("button" + (i+1)); - b[i].addActionListener (this); - } - - p.add (b[0]); - p.add (b[6]); - p.add (b[4]); - p.add (b[8]); - p.add (b[1]); - p.add (b[7]); - p.add (b[3]); - p.add (b[5]); - p.add (b[2]); - - add (p, "North"); - - Button cb = new Button ("close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - add (cb, "South"); - setTitle ("Buttons"); - } - - public void actionPerformed (ActionEvent evt) - { - Button source = (Button) evt.getSource (); - - for (int i=0; i<9; i++) - { - if (source == b[i]) - { - int i2=((i+1)==9)?0:(i+1); - if (b[i2].isVisible()) - b[i2].setVisible(false); - else - b[i2].setVisible(true); - } - } - } -} - - -class DialogWindow extends Dialog implements SubWindow -{ - Label text; - Frame parent; - boolean initted = false; - - public DialogWindow (Frame f) - { - super (f, true); - - this.parent = f; - - addWindowListener (new WindowAdapter () - { - public void windowClosing (WindowEvent e) - { - System.out.println ("Window Closing"); - text.setVisible (false); - hide (); - } - }); - } - - public void setVisible (boolean visible) - { - if (!initted && visible) - init(); - super.setVisible (visible); - } - - public void show () - { - if (!initted) - init(); - super.show (); - } - - public void init () - { - text = new Label ("Dialog Test"); - text.setAlignment (Label.CENTER); - - add (text, "North"); - text.setVisible (false); - - Panel p = new PrettyPanel(); - - Button cb = new Button ("OK"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) - { - text.setVisible (false); - hide(); - } - }); - - p.setLayout (new GridLayout (1, 3)); - ((GridLayout) p.getLayout ()).setHgap (5); - ((GridLayout) p.getLayout ()).setVgap (5); - p.add (cb); - - Button toggle = new Button ("Toggle"); - p.add (toggle); - - toggle.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) - { - if (text.isVisible ()) - text.setVisible (false); - else - text.setVisible (true); - doLayout(); - } - }); - - Button subdlg = new Button ("SubDialog"); - p.add (subdlg); - - subdlg.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) - { - DialogWindow sw = new DialogWindow (parent); - System.out.println ("Will show modal sub dialog"); - sw.show (); - System.out.println ("Has shown modal sub dialog"); - } - }); - - add (p, "South"); - setTitle ("Dialog"); - setSize (240, 120); - } -} - -class CursorsWindow extends SubFrame implements ItemListener -{ - Choice cursorChoice; - Canvas cursorCanvas; - - public void init () - { - cursorChoice = new Choice(); - cursorChoice.add ("Default"); - cursorChoice.add ("Crosshair"); - cursorChoice.add ("Text"); - cursorChoice.add ("Wait"); - cursorChoice.add ("Southwest Resize"); - cursorChoice.add ("Southeast Resize"); - cursorChoice.add ("Northwest Resize"); - cursorChoice.add ("Northeast Resize"); - cursorChoice.add ("North Resize"); - cursorChoice.add ("South Resize"); - cursorChoice.add ("West Resize"); - cursorChoice.add ("East Resize"); - cursorChoice.add ("Hand"); - cursorChoice.add ("Move"); - - cursorChoice.addItemListener(this); - - add (cursorChoice, "North"); - - cursorCanvas = new Canvas () - { - public void paint (Graphics g) - { - Dimension d = this.getSize(); - g.setColor (Color.white); - g.fillRect (0, 0, d.width, d.height/2); - g.setColor (Color.black); - g.fillRect (0, d.height/2, d.width, d.height/2); - g.setColor (this.getBackground()); - g.fillRect (d.width/3, d.height/3, d.width/3, - d.height/3); - } - }; - - cursorCanvas.setSize (80,80); - - add (cursorCanvas, "Center"); - - Button cb = new Button ("Close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - - add (cb, "South"); - setTitle ("Cursors"); - setSize (160, 180); - } - - public void itemStateChanged (ItemEvent e) - { - cursorCanvas.setCursor (Cursor.getPredefinedCursor (cursorChoice.getSelectedIndex())); - } -} - -class TextFieldWindow extends SubFrame implements ItemListener -{ - Checkbox editable, visible, sensitive; - TextField text; - - public void init () - { - initted = true; - text = new TextField ("hello world"); - add (text, "North"); - - Panel p = new Panel(); - p.setLayout (new GridLayout (3, 1)); - ((GridLayout) p.getLayout ()).setHgap (5); - ((GridLayout) p.getLayout ()).setVgap (5); - - editable = new Checkbox("Editable", true); - p.add (editable); - editable.addItemListener (this); - - visible = new Checkbox("Visible", true); - p.add (visible); - visible.addItemListener (this); - - sensitive = new Checkbox("Sensitive", true); - p.add (sensitive); - sensitive.addItemListener (this); - - add (p, "Center"); - - Button cb = new Button ("Close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - - add (cb, "South"); - setTitle ("TextField"); - setSize (160, 180); - } - - public void itemStateChanged (ItemEvent e) - { - boolean on=true; - - if (e.getStateChange () == ItemEvent.DESELECTED) - on=false; - if (e.getSource() == editable) - text.setEditable (on); - if (e.getSource() == visible) - if (on) - text.setEchoChar ((char) 0); - else - text.setEchoChar ('*'); - if (e.getSource() == sensitive) - text.setEnabled (on); - - } -} - -class FileWindow extends FileDialog implements SubWindow -{ - boolean initted = false; - - public FileWindow (MainWindow mw) - { - super (mw); - } - - public void setVisible (boolean visible) - { - if (!initted && visible) - init(); - super.setVisible (visible); - } - - public void init() - { - initted = true; - } -} - -class LabelWindow extends SubFrame -{ - public void init () - { - initted = true; - - Panel p = new Panel(); - p.setLayout (new GridLayout (3, 1)); - ((GridLayout) p.getLayout ()).setHgap (5); - ((GridLayout) p.getLayout ()).setVgap (5); - - p.add (new Label ("left justified label", Label.LEFT)); - p.add (new Label ("center justified label", Label.CENTER)); - p.add (new Label ("right justified label", Label.RIGHT)); - - add (p, "Center"); - - Button cb = new Button ("Close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - - add (cb, "South"); - setTitle ("Labels"); - setSize (160, 180); - } -} - -class ListWindow extends SubFrame -{ - public void init () - { - initted = true; - - Panel p = new Panel (); - p.setLayout (new GridLayout (3, 1)); - - List l = new List (5, true); - for (int i = 0; i < 10; i++) - l.add ("added item " + i); - - p.add (l); - - add (p, "Center"); - - Button cb = new Button ("Close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - - add (cb, "South"); - setTitle ("List"); - setSize (85, 167); - } -} - - -class RadioWindow extends SubFrame -{ - public void init () - { - initted = true; - - Panel p = new Panel(); - p.setLayout (new GridLayout (3, 1)); - ((GridLayout) p.getLayout ()).setHgap (5); - ((GridLayout) p.getLayout ()).setVgap (5); - - final CheckboxGroup cg = new CheckboxGroup(); - final Checkbox[] boxes = new Checkbox[3]; - for (int i = 0; i < 3; ++i) - { - boxes[i] = new Checkbox("button" + i, cg, i == 0); - p.add(boxes[i]); - } - - add (p, "North"); - - p = new Panel(); - p.setLayout (new GridLayout (1, 3)); - ((GridLayout) p.getLayout ()).setHgap (5); - ((GridLayout) p.getLayout ()).setVgap (5); - - for (int i = 0; i < 3; ++i) - { - final int val = i; - Button tweak = new Button ("Set " + i); - tweak.addActionListener(new ActionListener () - { - public void actionPerformed (ActionEvent e) - { - cg.setSelectedCheckbox(boxes[val]); - } - }); - p.add(tweak); - } - - add (p, "Center"); - - Button cb = new Button ("Close"); - cb.addActionListener(new ActionListener () { - public void actionPerformed (ActionEvent e) { - dispose(); - } - }); - - add (cb, "South"); - setTitle ("Radio Buttons"); - setSize (85, 167); - } -} diff --git a/libjava/gnu/java/beans/BeanInfoEmbryo.java b/libjava/gnu/java/beans/BeanInfoEmbryo.java deleted file mode 100644 index 0cf73e5b9ae..00000000000 --- a/libjava/gnu/java/beans/BeanInfoEmbryo.java +++ /dev/null @@ -1,171 +0,0 @@ -/* gnu.java.beans.BeanInfoEmbryo - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans; - -import java.beans.BeanDescriptor; -import java.beans.BeanInfo; -import java.beans.EventSetDescriptor; -import java.beans.IndexedPropertyDescriptor; -import java.beans.MethodDescriptor; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; -import java.util.Vector; - -/** - ** A BeanInfoEmbryo accumulates information about a Bean - ** while it is in the process of being created, and then - ** when you are done accumulating the information, the - ** getBeanInfo() method may be called to create a BeanInfo - ** object based on the information.<P> - ** - ** This class is not well-synchronized. (It can be, it - ** just isn't yet.) - ** - ** @author John Keiser - ** @version 1.1.0, 30 Jul 1998 - ** @see java.beans.BeanInfo - **/ - -public class BeanInfoEmbryo { - - // by using a TreeMap the properties will be sorted alphabetically by name - // which matches the (undocumented) behavior of jdk - TreeMap properties = new TreeMap(); - Hashtable events = new Hashtable(); - Vector methods = new Vector(); - - BeanDescriptor beanDescriptor; - BeanInfo[] additionalBeanInfo; - java.awt.Image[] im; - String defaultPropertyName; - String defaultEventName; - - public BeanInfoEmbryo() { - } - - public BeanInfo getBeanInfo() { - int defaultProperty = -1; - int defaultEvent = -1; - - PropertyDescriptor[] Aproperties = new PropertyDescriptor[properties.size()]; - int i = 0; - Iterator it = properties.entrySet().iterator(); - while (it.hasNext()) { - Aproperties[i] = (PropertyDescriptor) (((Map.Entry)it.next()).getValue()); - if(defaultPropertyName != null && Aproperties[i].getName().equals(defaultPropertyName)) { - defaultProperty = i; - } - i++; - } - - EventSetDescriptor[] Aevents = new EventSetDescriptor[events.size()]; - i = 0; - Enumeration e = events.elements(); - while (e.hasMoreElements()) { - Aevents[i] = (EventSetDescriptor) e.nextElement(); - if(defaultEventName != null && Aevents[i].getName().equals(defaultEventName)) { - defaultEvent = i; - } - i++; - } - - MethodDescriptor[] Amethods = new MethodDescriptor[methods.size()]; - methods.copyInto(Amethods); - - return new ExplicitBeanInfo(beanDescriptor,additionalBeanInfo,Aproperties,defaultProperty,Aevents,defaultEvent,Amethods,im); - } - - public void setBeanDescriptor(BeanDescriptor b) { - beanDescriptor = b; - } - - public void setAdditionalBeanInfo(BeanInfo[] b) { - additionalBeanInfo = b; - } - - public boolean hasProperty(PropertyDescriptor p) { - return properties.get(p.getName()) != null; - } - public void addProperty(PropertyDescriptor p) { - properties.put(p.getName(),p); - } - public void addIndexedProperty(IndexedPropertyDescriptor p) { - properties.put(p.getName(),p); - } - - public boolean hasEvent(EventSetDescriptor e) { - return events.get(e.getName()) != null; - } - public void addEvent(EventSetDescriptor e) { - events.put(e.getName(),e); - } - - public boolean hasMethod(MethodDescriptor m) { - for(int i=0;i<methods.size();i++) { - Method thisMethod = ((MethodDescriptor)methods.elementAt(i)).getMethod(); - if(m.getMethod().getName().equals(thisMethod.getName()) - && Arrays.equals(m.getMethod().getParameterTypes(), - thisMethod.getParameterTypes())) { - return true; - } - } - return false; - } - public void addMethod(MethodDescriptor m) { - methods.addElement(m); - } - - public void setDefaultPropertyName(String defaultPropertyName) { - this.defaultPropertyName = defaultPropertyName; - } - - public void setDefaultEventName(String defaultEventName) { - this.defaultEventName = defaultEventName; - } - - public void setIcons(java.awt.Image[] im) { - this.im = im; - } -} diff --git a/libjava/gnu/java/beans/DummyAppletContext.java b/libjava/gnu/java/beans/DummyAppletContext.java deleted file mode 100644 index 4facb470d95..00000000000 --- a/libjava/gnu/java/beans/DummyAppletContext.java +++ /dev/null @@ -1,200 +0,0 @@ -/* gnu.java.beans.DummyAppletContext - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans; - -import java.applet.Applet; -import java.applet.AppletContext; -import java.applet.AudioClip; -import java.awt.Image; -import java.awt.Toolkit; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; - -/** A placeholder <code>AppletContext</code> implementation that does nothing. - * - * <p>This is the default implementation for GNU Classpath and is used for <code>Applet</code> - * beans being created with {@link java.beans.Beans.instantiate}.</p> - * - * <p>It has no functionality in order to allow it to be used without any dependencies - * (e.g. sound, network access, ...).</p> - * - * @author Robert Schuster - */ -class DummyAppletContext implements AppletContext -{ - private static final Enumeration EMPTY_ENUMERATION = Collections.enumeration(Collections.EMPTY_SET); - private static final AudioClip DUMMY_CLIP = new DummyAudioClip(); - - DummyAppletContext() - { - } - - /** Implementation is VM neutral and returns a dummy {@link AudioClip} instance - * for every URL that returns a non-<code>null</code> object on - * <code>URL.openConnection()</code>. - * - * @see java.applet.AppletContext#getAudioClip(java.net.URL) - * - * FIXME: When Java Sound API (javax.sound) is included in Classpath or URL is able to handle - * sampled sound this should be adjusted. - */ - public AudioClip getAudioClip(URL url) - { - try - { - return (url.openConnection() != null ? DUMMY_CLIP : null); - } - catch (IOException ioe) - { - return null; - } - } - - /** Loads the <code>Image</code> instance by delegating to - * {@link java.awt.Toolkit.createImage(URL) }. - * - * @see java.applet.AppletContext#getImage(java.net.URL) - * @see java.awt.Toolkit#createImage(java.net.URL) - */ - public Image getImage(URL url) - { - return Toolkit.getDefaultToolkit().createImage(url); - } - - /** Returns <code>null</code> for every argument. - * - * @see java.applet.AppletContext#getApplet(java.lang.String) - */ - public Applet getApplet(String name) - { - return null; - } - - /** Returns always an empty <code>Enumeration</code>. - * - * @see java.applet.AppletContext#getApplets() - */ - public Enumeration getApplets() - { - return EMPTY_ENUMERATION; - } - - /** Does nothing. - * - * @see java.applet.AppletContext#showDocument(java.net.URL) - */ - public void showDocument(URL url) - { - } - - /** Does nothing. - * - * @see java.applet.AppletContext#showDocument(java.net.URL, java.lang.String) - */ - public void showDocument(URL url, String target) - { - } - - /** Does nothing. - * - * @see java.applet.AppletContext#showStatus(java.lang.String) - */ - public void showStatus(String message) - { - } - - /** Does nothing. - * - * @see java.applet.AppletContext#setStream(java.lang.String, java.io.InputStream) - */ - public void setStream(String key, InputStream stream) - throws IOException - { - throw new IOException("Dummy implementation imposes zero InputStream associations."); - } - - /** Returns <code>null</code> for every argument. - * - * @see java.applet.AppletContext#getStream(java.lang.String) - */ - public InputStream getStream(String key) - { - return null; - } - - /** Returns always an empty iterator. - * - * @see java.applet.AppletContext#getStreamKeys() - */ - public Iterator getStreamKeys() - { - return Collections.EMPTY_SET.iterator(); - } - - /** Dummy <code>AudioClip</code> implementation that does nothing but - * preventing <code>NullPointerException</code>S being thrown in programs - * that expect a valid <code>AudioClip</code> instance to be returned by - * their Applet. - * - * @author Robert Schuster - */ - static class DummyAudioClip implements AudioClip - { - public void play() - { - } - - public void stop() - { - } - - public void loop() - { - } - - public String toString() - { - return "DummyAudioClip never plays anything - implement javax.sound and make us happy :)"; - } - } -} diff --git a/libjava/gnu/java/beans/DummyAppletStub.java b/libjava/gnu/java/beans/DummyAppletStub.java deleted file mode 100644 index 3bcb43534cf..00000000000 --- a/libjava/gnu/java/beans/DummyAppletStub.java +++ /dev/null @@ -1,115 +0,0 @@ -/* gnu.java.beans.DummyAppletStub - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans; - -import java.applet.AppletContext; -import java.applet.AppletStub; -import java.net.URL; - -/** Placeholder implementation of <code>AppletStub</code> providing no functionality. - * <p>This class is used for <code>Applet</code> being created with - * {@link java.beans.Bean.instantiate}.</p> - * - * @author Robert Schuster - */ -public class DummyAppletStub implements AppletStub -{ - private URL documentBase; - private URL codeBase; - private DummyAppletContext context; - - public DummyAppletStub(URL newCodeBase, URL newDocumentBase) - { - codeBase = newCodeBase; - documentBase = newDocumentBase; - - context = new DummyAppletContext(); - } - - /** Returns always <code>true</code>. - * - * @see java.applet.AppletStub#isActive() - */ - public boolean isActive() - { - return true; - } - - /** - * @see java.applet.AppletStub#getDocumentBase() - */ - public URL getDocumentBase() - { - return documentBase; - } - - /** - * @see java.applet.AppletStub#getCodeBase() - */ - public URL getCodeBase() - { - return codeBase; - } - - /** Implementation returns <code>null</code> for every parameter name. - * - * @see java.applet.AppletStub#getParameter(java.lang.String) - */ - public String getParameter(String name) - { - return null; - } - - /** Returns a non-functional context instance. - * - * @see java.applet.AppletStub#getAppletContext() - */ - public AppletContext getAppletContext() - { - return context; - } - - /** Does nothing. - * - * @see java.applet.AppletStub#appletResize(int, int) - */ - public void appletResize(int width, int height) - { - } -} diff --git a/libjava/gnu/java/beans/ExplicitBeanInfo.java b/libjava/gnu/java/beans/ExplicitBeanInfo.java deleted file mode 100644 index 6da5e869695..00000000000 --- a/libjava/gnu/java/beans/ExplicitBeanInfo.java +++ /dev/null @@ -1,149 +0,0 @@ -/* ExplicitBeanInfo.java -- - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans; - -import java.awt.Image; -import java.beans.BeanDescriptor; -import java.beans.BeanInfo; -import java.beans.EventSetDescriptor; -import java.beans.MethodDescriptor; -import java.beans.PropertyDescriptor; - -/** - ** ExplicitBeanInfo lets you specify in the constructor - ** all the various parts of the BeanInfo. - ** - ** @author John Keiser - ** @version 1.1.0, 30 Jul 1998 - ** @see java.beans.BeanInfo - **/ - -public class ExplicitBeanInfo implements BeanInfo { - /** The BeanDescriptor returned by getBeanDescriptor. **/ - protected BeanDescriptor beanDescriptor; - - /** The EventSetDescriptor array returned by - ** getEventSetDescriptors(). - **/ - protected EventSetDescriptor[] eventSetDescriptors = new EventSetDescriptor[0]; - - /** The PropertyDescriptor array returned by - ** getPropertyDescriptors(). - **/ - protected PropertyDescriptor[] propertyDescriptors = new PropertyDescriptor[0]; - - /** The MethodDescriptor array returned by - ** getMethodDescriptors(). - **/ - protected MethodDescriptor[] methodDescriptors; - - /** The default property index. **/ - protected int defaultPropertyIndex; - - /** The default event index. **/ - protected int defaultEventIndex; - - /** The BeanInfo array returned by - ** getAdditionalBeanInfo(). - **/ - protected BeanInfo[] additionalBeanInfo; - - /** The set of icons. **/ - protected Image[] icons; - - public ExplicitBeanInfo(BeanDescriptor beanDescriptor, - BeanInfo[] additionalBeanInfo, - PropertyDescriptor[] propertyDescriptors, - int defaultPropertyIndex, - EventSetDescriptor[] eventSetDescriptors, - int defaultEventIndex, - MethodDescriptor[] methodDescriptors, - Image[] icons) { - this.beanDescriptor = beanDescriptor; - this.additionalBeanInfo = additionalBeanInfo; - this.propertyDescriptors = propertyDescriptors; - this.defaultPropertyIndex = defaultPropertyIndex; - this.eventSetDescriptors = eventSetDescriptors; - this.defaultEventIndex = defaultEventIndex; - this.methodDescriptors = methodDescriptors; - this.icons = icons; - } - - /** Get Bean descriptor. **/ - public BeanDescriptor getBeanDescriptor() { - return beanDescriptor; - } - - /** Get Bean events. **/ - public EventSetDescriptor[] getEventSetDescriptors() { - return eventSetDescriptors; - } - - /** Get default event set. **/ - public int getDefaultEventIndex() { - return defaultEventIndex; - } - - /** Get Bean properties. **/ - public PropertyDescriptor[] getPropertyDescriptors() { - return propertyDescriptors; - } - - /** Get "default" property. **/ - public int getDefaultPropertyIndex() { - return defaultPropertyIndex; - } - - /** Get Bean methods. **/ - public MethodDescriptor[] getMethodDescriptors() { - return methodDescriptors; - } - - /** Get additional Bean info. **/ - public BeanInfo[] getAdditionalBeanInfo() { - return additionalBeanInfo; - } - - /** Get Bean icons. - ** @param iconType the type of icon - **/ - public Image getIcon(int iconType) { - return icons != null ? icons[iconType - 1] : null; - } -} diff --git a/libjava/gnu/java/beans/IntrospectionIncubator.java b/libjava/gnu/java/beans/IntrospectionIncubator.java deleted file mode 100644 index e0d9480e327..00000000000 --- a/libjava/gnu/java/beans/IntrospectionIncubator.java +++ /dev/null @@ -1,441 +0,0 @@ -/* gnu.java.beans.IntrospectionIncubator - Copyright (C) 1998, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans; - -import gnu.java.lang.ArrayHelper; -import gnu.java.lang.ClassHelper; - -import java.beans.BeanInfo; -import java.beans.EventSetDescriptor; -import java.beans.IndexedPropertyDescriptor; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.MethodDescriptor; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Array; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -/** - ** IntrospectionIncubator takes in a bunch of Methods, and - ** Introspects only those Methods you give it.<br/> - ** - ** See {@link addMethod(Method)} for details which rules apply to - ** the methods. - ** - ** @author John Keiser - ** @author Robert Schuster - ** @see gnu.java.beans.ExplicitBeanInfo - ** @see java.beans.BeanInfo - **/ - -public class IntrospectionIncubator { - Hashtable propertyMethods = new Hashtable(); - Hashtable listenerMethods = new Hashtable(); - Vector otherMethods = new Vector(); - - Class propertyStopClass; - Class eventStopClass; - Class methodStopClass; - - public IntrospectionIncubator() { - } - - /** Examines the given method and files it in a suitable collection. - * It files the method as a property method if it finds: - * <ul> - * <li>boolean "is" getter</li> - * <li>"get" style getter</li> - * <li>single argument setter</li> - * <li>indiced setter and getter</li> - * </ul> - * It files the method as a listener method if all of these rules apply: - * <ul> - * <li>the method name starts with "add" or "remove"</li> - * <li>there is only a single argument</li> - * <li>the argument type is a subclass of <code>java.util.EventListener</code></li> - * </ul> - * All public methods are filed as such. - * - * @param method The method instance to examine. - */ - public void addMethod(Method method) { - if(Modifier.isPublic(method.getModifiers())) { - String name = ClassHelper.getTruncatedName(method.getName()); - Class retType = method.getReturnType(); - Class[] params = method.getParameterTypes(); - boolean isVoid = retType.equals(java.lang.Void.TYPE); - Class methodClass = method.getDeclaringClass(); - - /* Accepts the method for examination if no stop class is given or the method is declared in a subclass of the stop class. - * The rules for this are described in {@link java.beans.Introspector.getBeanInfo(Class, Class)}. - * This block finds out whether the method is a suitable getter or setter method (or read/write method). - */ - if(isReachable(propertyStopClass, methodClass)) { - /* At this point a method may regarded as a property's read or write method if its name - * starts with "is", "get" or "set". However, if a method is static it cannot be part - * of a property. - */ - if(Modifier.isStatic(method.getModifiers())) { - // files method as other because it is static - otherMethods.addElement(method); - } else if(name.startsWith("is") - && retType.equals(java.lang.Boolean.TYPE) - && params.length == 0) { - // files method as boolean "is" style getter - addToPropertyHash(name,method,IS); - } else if(name.startsWith("get") && !isVoid) { - if(params.length == 0) { - // files as legal non-argument getter - addToPropertyHash(name,method,GET); - } else if(params.length == 1 && params[0].equals(java.lang.Integer.TYPE)) { - // files as legal indiced getter - addToPropertyHash(name,method,GET_I); - } else { - // files as other because the method's signature is not Bean-like - otherMethods.addElement(method); - } - } else if(name.startsWith("set") && isVoid) { - if(params.length == 1) { - // files as legal single-argument setter method - addToPropertyHash(name,method,SET); - } else if(params.length == 2 && params[0].equals(java.lang.Integer.TYPE)) { - // files as legal indiced setter method - addToPropertyHash(name,method,SET_I); - } else { - // files as other because the method's signature is not Bean-like - otherMethods.addElement(method); - } - } - } - - if(isReachable(eventStopClass, methodClass)) { - if(name.startsWith("add") - && isVoid - && params.length == 1 - && java.util.EventListener.class.isAssignableFrom(params[0])) { - addToListenerHash(name,method,ADD); - } else if(name.startsWith("remove") - && isVoid - && params.length == 1 - && java.util.EventListener.class.isAssignableFrom(params[0])) { - addToListenerHash(name,method,REMOVE); - } - } - - if(isReachable(methodStopClass, methodClass)) { - // files as reachable public method - otherMethods.addElement(method); - } - - } - } - - public void addMethods(Method[] m) { - for(int i=0;i<m.length;i++) { - addMethod(m[i]); - } - } - - public void setPropertyStopClass(Class c) { - propertyStopClass = c; - } - - public void setEventStopClass(Class c) { - eventStopClass = c; - } - - public void setMethodStopClass(Class c) { - methodStopClass = c; - } - - - public BeanInfoEmbryo getBeanInfoEmbryo() throws IntrospectionException { - BeanInfoEmbryo b = new BeanInfoEmbryo(); - findXXX(b,IS); - findXXXInt(b,GET_I); - findXXXInt(b,SET_I); - findXXX(b,GET); - findXXX(b,SET); - findAddRemovePairs(b); - for(int i=0;i<otherMethods.size();i++) { - MethodDescriptor newMethod = new MethodDescriptor((Method)otherMethods.elementAt(i)); - if(!b.hasMethod(newMethod)) { - b.addMethod(new MethodDescriptor((Method)otherMethods.elementAt(i))); - } - } - return b; - } - - public BeanInfo getBeanInfo() throws IntrospectionException { - return getBeanInfoEmbryo().getBeanInfo(); - } - - - void findAddRemovePairs(BeanInfoEmbryo b) throws IntrospectionException { - Enumeration listenerEnum = listenerMethods.keys(); - while(listenerEnum.hasMoreElements()) { - DoubleKey k = (DoubleKey)listenerEnum.nextElement(); - Method[] m = (Method[])listenerMethods.get(k); - if(m[ADD] != null && m[REMOVE] != null) { - EventSetDescriptor e = new EventSetDescriptor(Introspector.decapitalize(k.getName()), - k.getType(), k.getType().getMethods(), - m[ADD],m[REMOVE]); - e.setUnicast(ArrayHelper.contains(m[ADD].getExceptionTypes(),java.util.TooManyListenersException.class)); - if(!b.hasEvent(e)) { - b.addEvent(e); - } - } - } - } - - void findXXX(BeanInfoEmbryo b, int funcType) throws IntrospectionException { - Enumeration keys = propertyMethods.keys(); - while(keys.hasMoreElements()) { - DoubleKey k = (DoubleKey)keys.nextElement(); - Method[] m = (Method[])propertyMethods.get(k); - if(m[funcType] != null) { - PropertyDescriptor p = new PropertyDescriptor(Introspector.decapitalize(k.getName()), - m[IS] != null ? m[IS] : m[GET], - m[SET]); - if(m[SET] != null) { - p.setConstrained(ArrayHelper.contains(m[SET].getExceptionTypes(),java.beans.PropertyVetoException.class)); - } - if(!b.hasProperty(p)) { - b.addProperty(p); - } - } - } - } - - void findXXXInt(BeanInfoEmbryo b, int funcType) throws IntrospectionException { - Enumeration keys = propertyMethods.keys(); - while(keys.hasMoreElements()) { - DoubleKey k = (DoubleKey)keys.nextElement(); - Method[] m = (Method[])propertyMethods.get(k); - if(m[funcType] != null) { - boolean constrained; - if(m[SET_I] != null) { - constrained = ArrayHelper.contains(m[SET_I].getExceptionTypes(),java.beans.PropertyVetoException.class); - } else { - constrained = false; - } - - /** Find out if there is an array type get or set **/ - Class arrayType = Array.newInstance(k.getType(),0).getClass(); - DoubleKey findSetArray = new DoubleKey(arrayType,k.getName()); - Method[] m2 = (Method[])propertyMethods.get(findSetArray); - IndexedPropertyDescriptor p; - if(m2 == null) { - p = new IndexedPropertyDescriptor(Introspector.decapitalize(k.getName()), - null,null, - m[GET_I],m[SET_I]); - } else { - if(constrained && m2[SET] != null) { - constrained = ArrayHelper.contains(m2[SET].getExceptionTypes(),java.beans.PropertyVetoException.class); - } - p = new IndexedPropertyDescriptor(Introspector.decapitalize(k.getName()), - m2[GET],m2[SET], - m[GET_I],m[SET_I]); - } - p.setConstrained(constrained); - if(!b.hasProperty(p)) { - b.addProperty(p); - } - } - } - } - - static final int IS=0; - static final int GET_I=1; - static final int SET_I=2; - static final int GET=3; - static final int SET=4; - - static final int ADD=0; - static final int REMOVE=1; - - void addToPropertyHash(String name, Method method, int funcType) { - String newName; - Class type; - - switch(funcType) { - case IS: - type = java.lang.Boolean.TYPE; - newName = name.substring(2); - break; - case GET_I: - type = method.getReturnType(); - newName = name.substring(3); - break; - case SET_I: - type = method.getParameterTypes()[1]; - newName = name.substring(3); - break; - case GET: - type = method.getReturnType(); - newName = name.substring(3); - break; - case SET: - type = method.getParameterTypes()[0]; - newName = name.substring(3); - break; - default: - return; - } - newName = capitalize(newName); - if (newName.length() == 0) - return; - - DoubleKey k = new DoubleKey(type,newName); - Method[] methods = (Method[])propertyMethods.get(k); - if(methods == null) { - methods = new Method[5]; - propertyMethods.put(k,methods); - } - methods[funcType] = method; - } - - void addToListenerHash(String name, Method method, int funcType) { - String newName; - Class type; - - switch(funcType) { - case ADD: - type = method.getParameterTypes()[0]; - newName = name.substring(3,name.length()-8); - break; - case REMOVE: - type = method.getParameterTypes()[0]; - newName = name.substring(6,name.length()-8); - break; - default: - return; - } - newName = capitalize(newName); - if (newName.length() == 0) - return; - - DoubleKey k = new DoubleKey(type,newName); - Method[] methods = (Method[])listenerMethods.get(k); - if(methods == null) { - methods = new Method[2]; - listenerMethods.put(k,methods); - } - methods[funcType] = method; - } - - /* Determines whether <code>stopClass</code> is <code>null</code> - * or <code>declaringClass<code> is a true subclass of <code>stopClass</code>. - * This expression is useful to detect whether a method should be introspected or not. - * The rules for this are described in {@link java.beans.Introspector.getBeanInfo(Class, Class)}. - */ - static boolean isReachable(Class stopClass, Class declaringClass) { - return stopClass == null || (stopClass.isAssignableFrom(declaringClass) && !stopClass.equals(declaringClass)); - } - - /** Transforms a property name into a part of a method name. - * E.g. "value" becomes "Value" which can then concatenated with - * "set", "get" or "is" to form a valid method name. - * - * Implementation notes: - * If "" is the argument, it is returned without changes. - * If <code>null</code> is the argument, <code>null</code> is returned. - * - * @param name Name of a property. - * @return Part of a method name of a property. - */ - static String capitalize(String name) { - try { - if(Character.isUpperCase(name.charAt(0))) { - return name; - } else { - char[] c = name.toCharArray(); - c[0] = Character.toLowerCase(c[0]); - return new String(c); - } - } catch(StringIndexOutOfBoundsException E) { - return name; - } catch(NullPointerException E) { - return null; - } - } -} - -/** This class is a hashmap key that consists of a <code>Class</code> and a - * <code>String</code> element. - * - * It is used for XXX: find out what this is used for - * - * @author John Keiser - * @author Robert Schuster - */ -class DoubleKey { - Class type; - String name; - - DoubleKey(Class type, String name) { - this.type = type; - this.name = name; - } - - Class getType() { - return type; - } - - String getName() { - return name; - } - - public boolean equals(Object o) { - if(o instanceof DoubleKey) { - DoubleKey d = (DoubleKey)o; - return d.type.equals(type) && d.name.equals(name); - } else { - return false; - } - } - - public int hashCode() { - return type.hashCode() ^ name.hashCode(); - } -} diff --git a/libjava/gnu/java/beans/decoder/AbstractContext.java b/libjava/gnu/java/beans/decoder/AbstractContext.java deleted file mode 100644 index 0e95d432986..00000000000 --- a/libjava/gnu/java/beans/decoder/AbstractContext.java +++ /dev/null @@ -1,70 +0,0 @@ -/* gnu.java.beans.decoder.AbstractContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** AbstractContext implements some basic functionality of the Context - * interface and is therefore the base of all Context implementations. - * - * @author Robert Schuster - */ -abstract class AbstractContext implements Context -{ - private boolean isStatement; - private String id; - - public String getId() - { - return id; - } - - public void setId(String newId) - { - id = newId; - } - - public boolean isStatement() - { - return isStatement; - } - - public void setStatement(boolean b) - { - isStatement = b; - } -} diff --git a/libjava/gnu/java/beans/decoder/AbstractCreatableObjectContext.java b/libjava/gnu/java/beans/decoder/AbstractCreatableObjectContext.java deleted file mode 100644 index 47f04fa1cbe..00000000000 --- a/libjava/gnu/java/beans/decoder/AbstractCreatableObjectContext.java +++ /dev/null @@ -1,113 +0,0 @@ -/* gnu.java.beans.decoder.AbstractCreatableContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.beans.decoder; - - -/** AbstractCreatableObjectContext is the base class for all Context implementations - * which create a result object in their lifetime. It provides means for preventing - * to create the object twice. - * - * @author Robert Schuster - * - */ -abstract class AbstractCreatableObjectContext extends AbstractObjectContext -{ - AbstractCreatableObjectContext() - { - } - - /** Adds a parameter object to this Context if the result object has not been - * created yet. Otherwise an AssemblyException is thrown that indicates a wrong - * behavior of the decoder. - */ - public final void addParameterObject(Object o) throws AssemblyException - { - if (object == null) - addParameterObjectImpl(o); - else - throw new AssemblyException(new IllegalStateException("No more parameter objects are allowed when the object as already been created.")); - } - - /** Adds a parameter object to this Context. Implement this without caring - * for illegal states because this has been done already. - * - * @param obj The parameter object to be added. - */ - protected abstract void addParameterObjectImpl(Object obj); - - /** Creates the result object if it does not exist already. - */ - public final void notifyStatement(Context outerContext) - throws AssemblyException - { - if (object != null) - return; - - object = createObject(outerContext); - } - - /** Creates the result object. This method is called only once. Implement this - * without checking for double invocations as this is already being prevented. - * - * @param outerContext The Context that exists around this one. - * @return The result object. - * @throws AssemblerException if the object creation fails somehow. - */ - protected abstract Object createObject(Context outerContext) - throws AssemblyException; - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public final Object endContext(Context outerContext) - throws AssemblyException - { - notifyStatement(outerContext); - return object; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - /* Returns true when the AbstractCreatableObjectContext has not created the result object yet - * (A failed subcontext automatically lets this context fail too.) - */ - return object == null; - } -} diff --git a/libjava/gnu/java/beans/decoder/AbstractElementHandler.java b/libjava/gnu/java/beans/decoder/AbstractElementHandler.java deleted file mode 100644 index e5578a990bc..00000000000 --- a/libjava/gnu/java/beans/decoder/AbstractElementHandler.java +++ /dev/null @@ -1,316 +0,0 @@ -/* gnu.java.beans.decoder.AbstractElementHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -/** ElementHandler manages a Context instance and interacts with - * its parent and child handlers. - * - * @author Robert Schuster - */ -abstract class AbstractElementHandler implements ElementHandler -{ - /** The Context instance of this handler. The instance is available after the startElement() - * method was called. Otherwise the handler is marked as failed. - */ - private Context context; - - /** The parent handler. */ - private ElementHandler parent; - - /** Stores whether this handler is marked as failed. */ - private boolean hasFailed; - - /** Stores the character data which is contained in the body of the XML tag. */ - private StringBuffer buffer = new StringBuffer(); - - /** Stores whether this ElementHandler can have subelements. The information for this is taken from - * javabeans.dtd which can be found here: - * <a href="http://java.sun.com/products/jfc/tsc/articles/persistence3/">Java Persistence Article</a> - */ - private boolean allowsSubelements; - - /** Creates a new ElementHandler with the given ElementHandler instance - * as parent. - * - * @param parentHandler The parent handler. - */ - protected AbstractElementHandler(ElementHandler parentHandler, - boolean allowsSubs) - { - parent = parentHandler; - allowsSubelements = allowsSubs; - } - - /** Evaluates the attributes and creates a Context instance. - * If the creation of the Context instance fails the ElementHandler - * is marked as failed which may affect the parent handler other. - * - * @param attributes Attributes of the XML tag. - */ - public final void start(Attributes attributes, - ExceptionListener exceptionListener) - { - try - { - // lets the subclass create the appropriate Context instance - context = startElement(attributes, exceptionListener); - } - catch (AssemblyException pe) - { - Throwable t = pe.getCause(); - - if (t instanceof Exception) - exceptionListener.exceptionThrown((Exception) t); - else - throw new InternalError("Unexpected Throwable type in AssemblerException. Please file a bug report."); - - notifyContextFailed(); - - return; - } - } - - /** Analyses the content of the Attributes instance and creates a Context - * object accordingly. - * An AssemblerException is thrown when the Context instance could not - * be created. - * - * @param attributes Attributes of the XML tag. - * @return A Context instance. - * @throws AssemblerException when Context instance could not be created. - */ - protected abstract Context startElement(Attributes attributes, ExceptionListener exceptionListener) - throws AssemblyException; - - /** Post-processes the Context. - */ - public final void end(ExceptionListener exceptionListener) - { - // skips processing if the handler is marked as failed (because the Context - // is then invalid or may not exist at all) - if (!hasFailed) - { - try - { - // note: the order of operations is very important here - // sends the stored character data to the Context - endElement(buffer.toString()); - - // reports to the parent handler if this handler's Context is a - // statement (returning no value BACK to the parent's Context) - if (context.isStatement()) - { - // This may create a valid result in the parent's Context - // or let it fail - parent.notifyStatement(exceptionListener); - - // skips any further processing if the parent handler is now marked - // as failed - if (parent.hasFailed()) - return; - } - - // processes the Context and stores the result - putObject(context.getId(), context.endContext(parent.getContext())); - - // transfers the Context's results to the parent's Context - // if it is an expression (rather than a statement) - if (! context.isStatement()) - parent.getContext().addParameterObject(context.getResult()); - } - catch (AssemblyException pe) - { - // notifies that an exception was thrown in this handler's Context - Throwable t = pe.getCause(); - - if (t instanceof Exception) - exceptionListener.exceptionThrown((Exception) t); - else - throw (InternalError) new InternalError("Severe problem while decoding XML data.") - .initCause(t); - - // marks the handler as failed - notifyContextFailed(); - } - } - } - - /** Notifies the handler's Context that its child Context will not return - * a value back. Some Context variants need this information to know when - * a method or a constructor call can be made. - * - * This method is called by a child handler. - */ - public void notifyStatement(ExceptionListener exceptionListener) - { - try - { - - // propagates to parent handler first to generate objects - // needed by this Context instance - if(context.isStatement()) - { - parent.notifyStatement(exceptionListener); - } - - // Some Context instances do stuff which can fail now. If that - // happens this handler is marked as failed. - context.notifyStatement(parent.getContext()); - } - catch (AssemblyException ae) - { - // notifies that an exception was thrown in this handler's Context - Throwable t = ae.getCause(); - - if (t instanceof Exception) - exceptionListener.exceptionThrown((Exception) t); - else - throw (InternalError) new InternalError("Severe problem while decoding XML data.") - .initCause(t); - - // marks the handler as failed - notifyContextFailed(); - } - } - - /** Marks this and any depending parent handlers as failed. Which means that on their end - * no result is calculated. - * - * When a handler has failed no more handlers are accepted within it. - */ - public final void notifyContextFailed() - { - hasFailed = true; - - // marks the parent handler as failed if its Context - // is affected by the failure of this handler's Context - if (parent.getContext().subContextFailed()) - parent.notifyContextFailed(); - } - - /** Returns whether this handler has failed. - * - * This is used to skip child elements. - * - * @return Whether this handler has failed. - */ - public final boolean hasFailed() - { - return hasFailed; - } - - /** Processes the character data when the element ends. - * - * The default implementation does nothing for convenience. - * - * @param characters - * @throws AssemblerException - */ - protected void endElement(String characters) throws AssemblyException - { - // XXX: throw an exception when unexpected character data is available? - } - - /** Adds characters from the body of the XML tag to the buffer. - * - * @param ch - * @param start - * @param length - * @throws SAXException - */ - public final void characters(char[] ch, int start, int length) - { - // simply appends character data - buffer.append(ch, start, length); - } - - /** Stores an object globally under a unique id. If the id is - * null the object is not stored. - * - * @param objectId - * @param o - */ - public void putObject(String objectId, Object o) - { - if (objectId != null) - parent.putObject(objectId, o); - } - - /** Returns a previously stored object. If the id is null the - * result is null, too. - * - * @param objectId - * @return Returns a previously stored object or null. - */ - public Object getObject(String objectId) throws AssemblyException - { - return objectId == null ? null : parent.getObject(objectId); - } - - /** Returns the Class instance as if called Class.forName() but - * uses a ClassLoader given by the user. - * - * @param className - * @return - * @throws ClassNotFoundException - */ - public Class instantiateClass(String className) - throws ClassNotFoundException - { - return parent.instantiateClass(className); - } - - public final boolean isSubelementAllowed(String subElementName) - { - return allowsSubelements && ! subElementName.equals("java"); - } - - public final Context getContext() - { - return context; - } - - public final ElementHandler getParent() - { - return parent; - } -} diff --git a/libjava/gnu/java/beans/decoder/AbstractObjectContext.java b/libjava/gnu/java/beans/decoder/AbstractObjectContext.java deleted file mode 100644 index 202c33b3413..00000000000 --- a/libjava/gnu/java/beans/decoder/AbstractObjectContext.java +++ /dev/null @@ -1,127 +0,0 @@ -/* gnu.java.beans.decoder.AbstractObjectContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.beans.decoder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** AbstractObjectContext is the base for all Context implementations which - * create or provide a result object during their lifetime. - * - * <p>This class provides the implementation for an indexed get and set method. - * But this does not mean that the result object supports these operation.</p> - * - * @author Robert Schuster - * - */ -abstract class AbstractObjectContext extends AbstractContext -{ - protected Object object; - - AbstractObjectContext() - {} - - /** Sets the result object of the Context. - * - * @param obj The result object to be set. - */ - protected final void setObject(Object obj) - { - object = obj; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#set(int, java.lang.Object) - */ - public final void set(int index, Object o) throws AssemblyException - { - try - { - Method method = - object.getClass().getMethod( - "set", - new Class[] { Integer.TYPE, Object.class }); - - method.invoke(object, new Object[] { new Integer(index), o }); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#get(int) - */ - public final Object get(int index) throws AssemblyException - { - try - { - Method method = - object.getClass().getMethod( - "get", - new Class[] { Integer.TYPE }); - - return method.invoke(object, new Object[] { new Integer(index)}); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } - - public final Object getResult() - { - return object; - } -} diff --git a/libjava/gnu/java/beans/decoder/ArrayContext.java b/libjava/gnu/java/beans/decoder/ArrayContext.java deleted file mode 100644 index cf4267f2779..00000000000 --- a/libjava/gnu/java/beans/decoder/ArrayContext.java +++ /dev/null @@ -1,122 +0,0 @@ -/* gnu.java.beans.decoder.ArrayContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.lang.reflect.Array; - -/** A Context implementation for a fixed size array. The array - * elements have to be set using IndexContext instances. - * - * @author Robert Schuster - */ -class ArrayContext extends AbstractContext -{ - private Object array; - - ArrayContext(String id, Class klass, int length) - { - setId(id); - array = Array.newInstance(klass, length); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - throw new AssemblyException(new IllegalStateException("Adding objects without an index to a fixed array is not possible.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) - { - // method call intentionally ignored because there is not any useful effect - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - return array; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - // returns false to indicate that assembling the array does not fail only because - // a subelement failed. - return false; - } - - public void set(int index, Object o) throws AssemblyException - { - try - { - Array.set(array, index, o); - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - throw new AssemblyException(aioobe); - } - } - - public Object get(int index) throws AssemblyException - { - try - { - return Array.get(array, index); - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - throw new AssemblyException(aioobe); - } - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#getResult() - */ - public Object getResult() - { - return array; - } -} diff --git a/libjava/gnu/java/beans/decoder/ArrayHandler.java b/libjava/gnu/java/beans/decoder/ArrayHandler.java deleted file mode 100644 index 23f0285192b..00000000000 --- a/libjava/gnu/java/beans/decoder/ArrayHandler.java +++ /dev/null @@ -1,118 +0,0 @@ -/* gnu.java.beans.decoder.ArrayHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; -import java.util.HashMap; - -import org.xml.sax.Attributes; - -/** ArrayHandler processes the <array> tag. Depending on the existance of the 'length' attribute a Context for - * a fixed-size or growable array is created. - * - * @author Robert Schuster - */ -class ArrayHandler extends AbstractElementHandler -{ - /** Contains a mapping between a textual description of a primitive type (like "byte") and - * its corresponding wrapper class. This allows it to easily construct Array objects for - * primitive data types. - */ - private static HashMap typeMap = new HashMap(); - - static - { - typeMap.put("byte", Byte.TYPE); - typeMap.put("short", Short.TYPE); - typeMap.put("int", Integer.TYPE); - typeMap.put("long", Long.TYPE); - - typeMap.put("float", Float.TYPE); - typeMap.put("double", Double.TYPE); - - typeMap.put("boolean", Boolean.TYPE); - - typeMap.put("char", Character.TYPE); - } - - /** - * @param PersistenceParser - */ - ArrayHandler(ElementHandler parent) - { - super(parent, true); - } - - protected Context startElement(Attributes attributes, ExceptionListener exceptionListener) - throws AssemblyException, AssemblyException - { - String id = attributes.getValue("id"); - String className = attributes.getValue("class"); - - if (className != null) - { - try - { - Class klass; - - if (typeMap.containsKey(className)) - klass = (Class) typeMap.get(className); - else - klass = instantiateClass(className); - - String length = attributes.getValue("length"); - if (length != null) - // creates Array with predefined length - return new ArrayContext(id, klass, Integer.parseInt(length)); - else - // creates Array without length restriction - return new GrowableArrayContext(id, klass); - } - catch (ClassNotFoundException cnfe) - { - throw new AssemblyException(cnfe); - } - catch (NumberFormatException nfe) - { - throw new AssemblyException(nfe); - } - } - - throw new AssemblyException(new IllegalArgumentException("Missing 'class' attribute in <array> tag.")); - } -} diff --git a/libjava/gnu/java/beans/decoder/AssemblyException.java b/libjava/gnu/java/beans/decoder/AssemblyException.java deleted file mode 100644 index 29dfa65ac7c..00000000000 --- a/libjava/gnu/java/beans/decoder/AssemblyException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* gnu.java.beans.decoder.AssemblyException - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** The AssemblyException is used to wrap the cause of problems when assembling objects. - * In all cases only the wrapped exception is given to the PersistenceParser's - * ExceptionListener instance (never the AssemblyException itself). - * - * <p>Note: Often multiple steps are needed to construct a fully usuable object instance. - * Such a construction can be called assembly and thats why this exception was - * named AssemblyException.</p> - * - * @author Robert Schuster - */ -class AssemblyException extends Exception -{ - AssemblyException(Throwable cause) - { - super(cause); - } -} diff --git a/libjava/gnu/java/beans/decoder/BooleanHandler.java b/libjava/gnu/java/beans/decoder/BooleanHandler.java deleted file mode 100644 index a34fe346e0f..00000000000 --- a/libjava/gnu/java/beans/decoder/BooleanHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -/* gnu.java.beans.decoder.BooleanHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Boolean instance from the character data in a <boolean> tag. - * - * @author Robert Schuster - */ -class BooleanHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - BooleanHandler(ElementHandler parent) - { - super(parent); - - // TODO Auto-generated constructor stub - } - - protected Object parse(String number) throws AssemblyException - { - if (number.equals("true")) - return new Boolean(true); - - if (number.equals("false")) - return new Boolean(false); - - throw new AssemblyException(new IllegalArgumentException("Element contained no valid boolean value.")); - } -} diff --git a/libjava/gnu/java/beans/decoder/ByteHandler.java b/libjava/gnu/java/beans/decoder/ByteHandler.java deleted file mode 100644 index d6c33d14d21..00000000000 --- a/libjava/gnu/java/beans/decoder/ByteHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* gnu.java.beans.decoder.ByteHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Byte instance from the character data in a <byte> tag. - * - * @author Robert Schuster - */ -class ByteHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - ByteHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Byte.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/CharHandler.java b/libjava/gnu/java/beans/decoder/CharHandler.java deleted file mode 100644 index 1b31e5b0559..00000000000 --- a/libjava/gnu/java/beans/decoder/CharHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* gnu.java.beans.decoder.CharHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Character instance from the character data in a <char> tag. - * - * @author Robert Schuster - */ -class CharHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - CharHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws AssemblyException - { - if (number.length() > 1) - throw new AssemblyException(new IllegalArgumentException("Element contained no valid character.")); - - return new Character(number.charAt(0)); - } -} diff --git a/libjava/gnu/java/beans/decoder/ClassHandler.java b/libjava/gnu/java/beans/decoder/ClassHandler.java deleted file mode 100644 index 1dbdd63e79a..00000000000 --- a/libjava/gnu/java/beans/decoder/ClassHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* gnu.java.beans.decoder.ClassHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Class instance from the character data in a <class> tag. - * - * @author Robert Schuster - */ -class ClassHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - ClassHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String characters) throws AssemblyException - { - try - { - return instantiateClass(characters); - } - catch (ClassNotFoundException cnfe) - { - throw new AssemblyException(cnfe); - } - } -} diff --git a/libjava/gnu/java/beans/decoder/ConstructorContext.java b/libjava/gnu/java/beans/decoder/ConstructorContext.java deleted file mode 100644 index 7838fb7e263..00000000000 --- a/libjava/gnu/java/beans/decoder/ConstructorContext.java +++ /dev/null @@ -1,102 +0,0 @@ -/* gnu.java.beans.decoder.ConstructorContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; - -/** A ConstructorContext is a {@link Context} implementation which collects the parameters for a constructor - * call and instantiates the result object using that constructor. After that sub-contexts can invoke - * methods on the result object. - * - * <p>The constructor is invoked when a sub-context is a statement or the Context ends.</p> - * - * @author Robert Schuster - */ -class ConstructorContext extends AbstractCreatableObjectContext -{ - private ArrayList arguments = new ArrayList(); - private Class klass; - - ConstructorContext(String id, Class newClass) - { - setId(id); - // sets superclass field - klass = newClass; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - protected void addParameterObjectImpl(Object o) - { - arguments.add(o); - } - - protected Object createObject(Context outerContext) - throws AssemblyException - { - Object[] args = arguments.toArray(); - - try - { - Constructor constructor = MethodFinder.getConstructor(klass, args); - - // instantiates object (klass field gets re-set by superclass) - return constructor.newInstance(args); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - catch (InstantiationException ie) - { - throw new AssemblyException(ie); - } - } - -} diff --git a/libjava/gnu/java/beans/decoder/Context.java b/libjava/gnu/java/beans/decoder/Context.java deleted file mode 100644 index a2db09732d1..00000000000 --- a/libjava/gnu/java/beans/decoder/Context.java +++ /dev/null @@ -1,137 +0,0 @@ -/* gnu.java.beans.decoder.Context - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -/** A Context is the environment for an object which is being assembler. If there - * are no errors each handler creates one Context. - * <p>Depending on the result of isStatement() a Context can be statement or an - * expression. An expression returns a value to the Context of its parent handler, - * a statement does not. Whenever a Context is a statement the parent handler's - * Context is informed about that through the {@link notifyStatement}-method.</p> - * - * @author Robert Schuster - */ -interface Context -{ - /** Adds a parameter object to the context. This method is used when - * sub-Contexts return their result. - * - * Some Contexts do not accept more than a certain amount of objects - * and throw an AssemblerException if the amount is exceeded. - * - * @param o The object added to this context. - */ - void addParameterObject(Object o) throws AssemblyException; - - /** Notifies that the next element is a statement. This can mean - * that an argument list is complete to be called. - * - */ - void notifyStatement(Context outerContext) throws AssemblyException; - - /** Notifies that the context ends and the returns the appropriate result - * object. - * - * @param outerContext - * @return - */ - Object endContext(Context outerContext) throws AssemblyException; - - /** Notifies that the assembly of a subcontext failed and returns - * whether this Context is affected in a way that it fails too. - * - * @return Whether the failure of a subcontext lets this context fail, too. - */ - boolean subContextFailed(); - - /** Calls an appropriate indexed set method if it is available or - * throws an AssemblerException if that is not allowed on this Context. - * - * The behaviour of this method is equal to List.set(int, Object). - * - * @param index Index position to be set. - * @param o Object to be set at the given index position. - * @throws AssemblerException Indexed set is not allowed or otherwise failed. - */ - void set(int index, Object o) throws AssemblyException; - - /** Calls an appropriate indexed get method if it is available or - * throws an AssemblerException if that is not allowed on this Context. - * - * The behaviour of this method is equal to List.get(int). - * - * @param index Index position of the object return. - * @throws AssemblerException Indexed get is not allowed or otherwise failed. - */ - Object get(int index) throws AssemblyException; - - /** Returns the result which was calculated by calling endContext() or reportStatement(). - * Its the handler's responsibility to care that any of these two methods was called. - * - * This is used by sub-Contexts to access this Context's result. - * - * @return - */ - Object getResult(); - - /** Gives this Context a unique id. For convenience the id may be null which means - * that no id exists at all. - * - * @param id - */ - void setId(String id); - - /** Returns this Context's unique id or null if does not have such an id. - * - * @return This Context's id or null. - */ - String getId(); - - /** Returns whether this Context is a statement (not returning result back - * to parent handler's Context) or not (= expression). - * - * @return - */ - boolean isStatement(); - - /** Sets whether this Context is a statement or not. - * - * @param b - */ - void setStatement(boolean b); -} diff --git a/libjava/gnu/java/beans/decoder/DecoderContext.java b/libjava/gnu/java/beans/decoder/DecoderContext.java deleted file mode 100644 index 69d84e57656..00000000000 --- a/libjava/gnu/java/beans/decoder/DecoderContext.java +++ /dev/null @@ -1,124 +0,0 @@ -/* gnu.java.beans.decoder.DecoderContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.XMLDecoder; -import java.util.ArrayList; -import java.util.Iterator; - -/** DecoderContext is a Context implementation which allows access to - * the XMLDecoder instance itself. This is used for the <java> tag. - * - * @author Robert Schuster - */ -public class DecoderContext extends AbstractContext -{ - private XMLDecoder decoder; - - public DecoderContext(XMLDecoder xmlDecoder) - { - decoder = xmlDecoder; - } - - private ArrayList objects = new ArrayList(); - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - objects.add(o); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - return decoder; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - return false; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#set(int, java.lang.Object) - */ - public void set(int index, Object o) throws AssemblyException - { - throw new AssemblyException(new IllegalArgumentException("Set method is not allowed in decoder context.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#get(int) - */ - public Object get(int index) throws AssemblyException - { - throw new AssemblyException(new IllegalArgumentException("Get method is not allowed in decoder context.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#getResult() - */ - public Object getResult() - { - return decoder; - } - - /** Returns an Iterator that retrieves the assembled objects. - * - * @return An Iterator retrieving assembled objects. - */ - public Iterator iterator() - { - return objects.iterator(); - } - -} diff --git a/libjava/gnu/java/beans/decoder/DefaultExceptionListener.java b/libjava/gnu/java/beans/decoder/DefaultExceptionListener.java deleted file mode 100644 index 71e7158e7d2..00000000000 --- a/libjava/gnu/java/beans/decoder/DefaultExceptionListener.java +++ /dev/null @@ -1,57 +0,0 @@ -/* gnu.java.beans.DefaultExceptionListener - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -/** The DefaultExceptionListener is the default implementation of the ExceptionListener - * interface. An instance of this class is used whenever the user provided no - * ExceptionListener instance on its own. - * - * <p>The implementation just writes the exception's message to <code>System.err</code>.</p> - * - * @author Robert Schuster - */ -public class DefaultExceptionListener implements ExceptionListener -{ - public void exceptionThrown(Exception e) - { - System.err.println("non-critical exception: " + e + " - message: " - + e.getMessage()); - } -} diff --git a/libjava/gnu/java/beans/decoder/DoubleHandler.java b/libjava/gnu/java/beans/decoder/DoubleHandler.java deleted file mode 100644 index 8f6be7ec092..00000000000 --- a/libjava/gnu/java/beans/decoder/DoubleHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* gnu.java.beans.decoder.DoubleHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Double instance from the character data in a <double> tag. - * - * @author Robert Schuster - */ -class DoubleHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - DoubleHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Double.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/DummyContext.java b/libjava/gnu/java/beans/decoder/DummyContext.java deleted file mode 100644 index f3b24549de2..00000000000 --- a/libjava/gnu/java/beans/decoder/DummyContext.java +++ /dev/null @@ -1,116 +0,0 @@ -/* gnu.java.beans.decoder.DummyContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -/** The DummyContext is used as the Context implementation for the DummyHandler. It - * just prevents having a null-reference. - * - * <p>When the implementation is correct none of this class' methods - * (except <code>notifyStatement()</code>) is called.</p> - * - * @author Robert Schuster - */ -public class DummyContext extends AbstractContext -{ - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - // intentionally ignored - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - fail(); - return null; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - fail(); - return false; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#set(int, java.lang.Object) - */ - public void set(int index, Object o) throws AssemblyException - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#get(int) - */ - public Object get(int index) throws AssemblyException - { - fail(); - return null; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#getResult() - */ - public Object getResult() - { - fail(); - return null; - } - - private void fail() - { - throw new InternalError("Invoking the DummyContext is not expected" - + " - Please file a bug report at" - + " http://www/gnu.org/software/classpath/."); - } -} diff --git a/libjava/gnu/java/beans/decoder/DummyHandler.java b/libjava/gnu/java/beans/decoder/DummyHandler.java deleted file mode 100644 index 880d76adc0e..00000000000 --- a/libjava/gnu/java/beans/decoder/DummyHandler.java +++ /dev/null @@ -1,156 +0,0 @@ -/* gnu.java.beans.decoder.DummyHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -/** An ElementHandler implementation that is used as an artificial root - * element. This avoids having to check for a null element. - * - * @author Robert Schuster - */ -class DummyHandler implements ElementHandler -{ - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#start(org.xml.sax.Attributes, java.beans.ExceptionListener) - */ - public void start( - Attributes attributes, - ExceptionListener exceptionListener) - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#end(java.beans.ExceptionListener) - */ - public void end(ExceptionListener exceptionListener) - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#characters(char[], int, int) - */ - public void characters(char[] ch, int start, int length) - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#isSubelementAllowed(java.lang.String) - */ - public boolean isSubelementAllowed(String subElementName) - { - return true; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#instantiateClass(java.lang.String) - */ - public Class instantiateClass(String className) - throws ClassNotFoundException - { - fail(); - return null; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#reportStatement(java.beans.ExceptionListener) - */ - public void notifyStatement(ExceptionListener exceptionListener) - { - // ignore - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#hasFailed() - */ - public boolean hasFailed() - { - return false; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#getContext() - */ - public Context getContext() - { - return new DummyContext(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#contextFailed() - */ - public void notifyContextFailed() - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#putObject(java.lang.String, java.lang.Object) - */ - public void putObject(String objectId, Object o) - { - fail(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.ElementHandler#getObject(java.lang.String) - */ - public Object getObject(String objectId) - { - fail(); - return null; - } - - public ElementHandler getParent() - { - fail(); - return null; - } - - private void fail() - { - throw new InternalError("Invoking the DummyHandler is not expected" - + " - Please file a bug report at " - + " http://www.gnu.org/software/classpath/."); - } -} diff --git a/libjava/gnu/java/beans/decoder/ElementHandler.java b/libjava/gnu/java/beans/decoder/ElementHandler.java deleted file mode 100644 index e6ae60af886..00000000000 --- a/libjava/gnu/java/beans/decoder/ElementHandler.java +++ /dev/null @@ -1,130 +0,0 @@ -/* gnu.java.beans.decoder.ElementHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -/** ElementHandler manages a Context instance and interacts with - * its parent and child handlers. - * - * @author Robert Schuster - */ -interface ElementHandler -{ - /** Evaluates the attributes and creates a Context instance. - * If the creation of the Context instance fails the ElementHandler - * is marked as failed which may affect the parent handler other. - * - * @param attributes Attributes of the XML tag. - */ - void start(Attributes attributes, ExceptionListener exceptionListener); - - /** Post-processes the Context. - */ - void end(ExceptionListener exceptionListener); - - /** Adds characters from the body of the XML tag to the buffer. - * - * @param ch - * @param start - * @param length - * @throws SAXException - */ - void characters(char[] ch, int start, int length); - - /** Returns whether a subelement of the given name is allowed. The rules - * for evaluating this are derived from the javabeans.dtd which can be found - * here: <a href="http://java.sun.com/products/jfc/tsc/articles/persistence3">Java Persistence Article</a>. - * - * @param subElementName - * @return - */ - boolean isSubelementAllowed(String subElementName); - - /** Provides the same functionality as Class.forName() but allows the decoder - * to use a different class loader. - * - * @param className - * @return - * @throws ClassNotFoundException - */ - Class instantiateClass(String className) throws ClassNotFoundException; - - /** Notifies the handler's Context that its child Context will not return - * a value back. Some Context variants need this information to know when - * a method or a constructor call can be made. - * - * This method is called by a child handler. - */ - void notifyStatement(ExceptionListener exceptionListener); - - /** Returns whether this handler has failed. - * - * This is used to skip child elements. - * - * @return Whether this handler has failed. - */ - boolean hasFailed(); - - /** Returns the Context instance this handler is working on. - * - * @return The handler's Context instance. - */ - Context getContext(); - - /** Notifies the handler that its Context failed and starts a recursive - * invocation of the parent handler if it is affected by that failure. - * - * Although the method is a public API member it is only used internally. - */ - void notifyContextFailed(); - - /** Stores the object under the given id. The object is not stored if the - * id is null. - * - * @param objectId - * @param o - */ - void putObject(String objectId, Object o); - - Object getObject(String objectId) throws AssemblyException; - - ElementHandler getParent(); -} diff --git a/libjava/gnu/java/beans/decoder/FloatHandler.java b/libjava/gnu/java/beans/decoder/FloatHandler.java deleted file mode 100644 index 5f0e15cefed..00000000000 --- a/libjava/gnu/java/beans/decoder/FloatHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* gnu.java.beans.decoder.FloatHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Float instance from the character data in a <float> tag. - * - * @author Robert Schuster - */ -class FloatHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - FloatHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Float.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/GrowableArrayContext.java b/libjava/gnu/java/beans/decoder/GrowableArrayContext.java deleted file mode 100644 index f24a60b4a4b..00000000000 --- a/libjava/gnu/java/beans/decoder/GrowableArrayContext.java +++ /dev/null @@ -1,138 +0,0 @@ -/* gnu.java.beans.decoder.GrowableArrayContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.beans.decoder; - -import java.lang.reflect.Array; - -/** A Context implementation for a growable array. The array - * elements have to be set using expressions. - * - * @author Robert Schuster - */ -class GrowableArrayContext extends AbstractContext -{ - private static final int INITIAL_SIZE = 16; - - private Class klass; - private Object array; - private int length; - - GrowableArrayContext(String id, Class newClass) - { - setId(id); - klass = newClass; - array = Array.newInstance(klass, INITIAL_SIZE); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - if (length == Array.getLength(array)) - { - Object tmp = Array.newInstance(klass, length * 2); - System.arraycopy(array, 0, tmp, 0, length); - array = tmp; - } - - try { - Array.set(array, length++, o); - } catch(IllegalArgumentException iae) { - throw new AssemblyException(iae); - } - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - throw new AssemblyException( - new IllegalArgumentException("Statements inside a growable array are not allowed.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - if (length != Array.getLength(array)) - { - Object tmp = Array.newInstance(klass, length); - System.arraycopy(array, 0, tmp, 0, length); - array = tmp; - } - - return array; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - // returns false to indicate that assembling the array does not fail only because - // a subelement failed - return false; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#set(int, java.lang.Object) - */ - public void set(int index, Object o) throws AssemblyException - { - try { - Array.set(array, index, o); - } catch(IllegalArgumentException iae) { - throw new AssemblyException(iae); - } - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#get(int) - */ - public Object get(int index) throws AssemblyException - { - return Array.get(array, index); - } - - public Object getResult() - { - return array; - } -} diff --git a/libjava/gnu/java/beans/decoder/IndexContext.java b/libjava/gnu/java/beans/decoder/IndexContext.java deleted file mode 100644 index 11f840caeec..00000000000 --- a/libjava/gnu/java/beans/decoder/IndexContext.java +++ /dev/null @@ -1,130 +0,0 @@ -/* gnu.java.beans.decoder.IndexContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -/** IndexContext is Context implementation that senses whether it is an indexed get or set - * operation and invokes this operation. - * - * <p>An IndexContent is a get operation when no argument is provided and a set operation if one - * argument is provided.</p> - * - * @author Robert Schuster - */ -class IndexContext extends AbstractContext -{ - private Object result; - private Object argument; - private int index; - private boolean isSetter; - - IndexContext(String id, int newIndex) - { - setId(id); - index = newIndex; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - if (! isSetter) - { - argument = o; - isSetter = true; - } - else - throw new AssemblyException(new IllegalStateException("More than one argument for indiced access is not possible.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - throw new AssemblyException(new IllegalStateException("Statements inside indiced access are not allowed.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - if (isSetter) - { - // setter - outerContext.set(index, argument); - - return null; - } - else - // getter - return result = outerContext.get(index); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - // returns true to indicate that indiced access assembly fails when one of its - // argument could not be assembled - return true; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#set(int, java.lang.Object) - */ - public void set(int index, Object o) throws AssemblyException - { - throw new AssemblyException(new IllegalStateException("Setter is not allowed inside indiced access.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#get(int) - */ - public Object get(int index) throws AssemblyException - { - throw new AssemblyException(new IllegalStateException("getter is not allowed insided indiced access.")); - } - - public Object getResult() - { - return result; - } -} diff --git a/libjava/gnu/java/beans/decoder/IntHandler.java b/libjava/gnu/java/beans/decoder/IntHandler.java deleted file mode 100644 index a96f4a0315b..00000000000 --- a/libjava/gnu/java/beans/decoder/IntHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* gnu.java.beans.decoder.IntHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Integer instance from the character data in a <int> tag. - * - * @author Robert Schuster - */ -class IntHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - IntHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Integer.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/JavaHandler.java b/libjava/gnu/java/beans/decoder/JavaHandler.java deleted file mode 100644 index 3bc8c60288c..00000000000 --- a/libjava/gnu/java/beans/decoder/JavaHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* gnu.java.beans.decoder.JavaHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; -import java.util.HashMap; - -import org.xml.sax.Attributes; - -/** Wraps a DecoderContext instance. - * - * @author Robert Schuster - */ -public class JavaHandler extends AbstractElementHandler -{ - private Context context; - private HashMap objectMap = new HashMap(); - private ClassLoader classLoader; - - /** - * @param PersistenceParser - */ - JavaHandler(DummyHandler parent, Context decoderContext, - ClassLoader cl) - { - super(parent, true); - - classLoader = cl; - - context = decoderContext; - - } - - protected Context startElement(Attributes attributes, ExceptionListener exceptionListener) - throws AssemblyException - { - // may expect version and class attribute but it not used in JDK - // so we do either - return context; - } - - public Object getObject(String objectId) - { - return objectMap.get(objectId); - } - - public void putObject(String objectId, Object o) - { - if (objectId != null) - objectMap.put(objectId, o); - } - - public Class instantiateClass(String className) - throws ClassNotFoundException - { - return Class.forName(className, false, classLoader); - } -} diff --git a/libjava/gnu/java/beans/decoder/LongHandler.java b/libjava/gnu/java/beans/decoder/LongHandler.java deleted file mode 100644 index d7bfa54e54e..00000000000 --- a/libjava/gnu/java/beans/decoder/LongHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* gnu.java.beans.decoder.LongHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Creates a Long instance from the character data in a <long> tag. - * - * @author Robert Schuster - */ -class LongHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - LongHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Long.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/MethodContext.java b/libjava/gnu/java/beans/decoder/MethodContext.java deleted file mode 100644 index bad0a213f7f..00000000000 --- a/libjava/gnu/java/beans/decoder/MethodContext.java +++ /dev/null @@ -1,107 +0,0 @@ -/* gnu.java.beans.decoder.MethodContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.beans.decoder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; - -/** MethodContext collects arguments for a method call and creates the result object - * using it. The method is called using the result object of the parent Context. - * - * <p>When the result object is available methods can be called on it using sub-Contexts.</p> - * - * @author Robert Schuster - */ -class MethodContext extends AbstractCreatableObjectContext -{ - private ArrayList arguments = new ArrayList(); - private String methodName; - - MethodContext(String id, String newMethodName) - { - setId(id); - setStatement(true); - methodName = newMethodName; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObjectImpl(Object o) - { - arguments.add(o); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - protected Object createObject(Context outerContext) - throws AssemblyException - { - Object outerObject = outerContext.getResult(); - - if (outerObject == null) - throw new AssemblyException( - new NullPointerException( - "No object to invoke method " + methodName)); - - Object[] args = arguments.toArray(); - - try - { - Method method = - MethodFinder.getMethod( - outerObject.getClass(), - methodName, - args); - return method.invoke(outerObject, args); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } -} diff --git a/libjava/gnu/java/beans/decoder/MethodFinder.java b/libjava/gnu/java/beans/decoder/MethodFinder.java deleted file mode 100644 index 3968b173adb..00000000000 --- a/libjava/gnu/java/beans/decoder/MethodFinder.java +++ /dev/null @@ -1,177 +0,0 @@ -/* gnu.java.beans.decoder.MethodFinder - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.HashMap; - -class MethodFinder -{ - /** Provides a mapping between a wrapper class and its corresponding primitive's type. */ - private static HashMap typeMapping = new HashMap(); - - static { - typeMapping.put(Byte.class, Byte.TYPE); - typeMapping.put(Short.class, Short.TYPE); - typeMapping.put(Integer.class, Integer.TYPE); - typeMapping.put(Long.class, Long.TYPE); - typeMapping.put(Float.class, Float.TYPE); - typeMapping.put(Double.class, Double.TYPE); - - typeMapping.put(Character.class, Character.TYPE); - typeMapping.put(Boolean.class, Boolean.TYPE); - } - - private MethodFinder() - { - } - - /** Searches a Method which can accept the given arguments. - * - * @param klass - * @param name - * @param arguments - * @return - * @throws NoSuchMethodException - */ - static Method getMethod(Class klass, String name, Object[] arguments) - throws NoSuchMethodException - { - // prepares array containing the types of the arguments - Class[] argumentTypes = getArgumentTypes(arguments); - - Method[] methods = klass.getMethods(); - - // iterates over all public methods - for (int i = 0; i < methods.length; i++) - { - if (methods[i].getName().equals(name)) - { - if (matchingArgumentTypes(methods[i].getParameterTypes(), - argumentTypes)) - return methods[i]; - } - } - - throw new NoSuchMethodException( - "Could not find a matching method named " - + name - + "() in class " - + klass); - } - - static Constructor getConstructor(Class klass, Object[] arguments) - throws NoSuchMethodException - { - Class[] argumentTypes = getArgumentTypes(arguments); - Constructor[] constructors = klass.getConstructors(); - - // iterates over all public methods - for (int i = 0; i < constructors.length; i++) - { - if (matchingArgumentTypes(constructors[i].getParameterTypes(), - argumentTypes)) - return constructors[i]; - } - - throw new NoSuchMethodException( - "Could not find a matching constructor in class " + klass); - } - - /** Transforms an array of argument objects into an array of argument types. - * For each argument being null the argument is null, too. An argument type - * being null means: Accepts everything (although this can be ambigous). - * - * @param arguments - * @return - */ - private static Class[] getArgumentTypes(Object[] arguments) - { - if (arguments == null) - return new Class[0]; - - // prepares array containing the types of the arguments - Class[] argumentTypes = new Class[arguments.length]; - for (int i = 0; i < arguments.length; i++) - argumentTypes[i] = - (arguments[i] == null) ? null : arguments[i].getClass(); - return argumentTypes; - } - - /** Tests whether the argument types supplied to the method argument types - * are assignable. In addition to the assignment specifications this method - * handles the primitive's wrapper classes as if they were of their - * primitive type (e.g Boolean.class equals Boolean.TYPE). - * When a supplied argument type is null it is assumed that no argument - * object was supplied for it and the test for this particular parameter will - * pass. - * - * @param methodArgTypes - * @param suppliedArgTypes - * @return - */ - private static boolean matchingArgumentTypes( - Class[] methodArgTypes, - Class[] suppliedArgTypes) - { - if (methodArgTypes.length != suppliedArgTypes.length) - return false; - - for (int i = 0; i < methodArgTypes.length; i++) - { - if (suppliedArgTypes[i] == null) - { - // by definition a non-existant argument type (null) can be converted to everything - continue; - } - else if (typeMapping.containsKey(suppliedArgTypes[i])) - { - Class primitiveType = - (Class) typeMapping.get(suppliedArgTypes[i]); - if (!(methodArgTypes[i].isAssignableFrom(suppliedArgTypes[i]) - || methodArgTypes[i].isAssignableFrom(primitiveType))) - return false; - } - else if (!methodArgTypes[i].isAssignableFrom(suppliedArgTypes[i])) - return false; - } - - return true; - } -} diff --git a/libjava/gnu/java/beans/decoder/NullHandler.java b/libjava/gnu/java/beans/decoder/NullHandler.java deleted file mode 100644 index 549617db3cb..00000000000 --- a/libjava/gnu/java/beans/decoder/NullHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/* gnu.java.beans.decoder.NullHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - - -/** Just provides the 'null' object. - * - * @author Robert Schuster - */ -class NullHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - NullHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String characters) throws AssemblyException - { - if (! characters.equals("")) - throw new AssemblyException(new IllegalArgumentException("No characters inside <void> tag allowed.")); - - return null; - } -} diff --git a/libjava/gnu/java/beans/decoder/ObjectContext.java b/libjava/gnu/java/beans/decoder/ObjectContext.java deleted file mode 100644 index cf88a2c2c5c..00000000000 --- a/libjava/gnu/java/beans/decoder/ObjectContext.java +++ /dev/null @@ -1,100 +0,0 @@ -/* gnu.java.beans.decoder.ObjectHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -/** ObjectContext is a {@link Context} implementation that wraps a simple Object instance. - * The instance can be provided when the Context is created (due to an 'idref' - * attribute) or later (eg. <int> tag) - * - * <p>The ObjectContext does not accept any parameter object and ignores notifications - * about sub-contexts being statements.</p> - * - * @author Robert Schuster - */ -final class ObjectContext extends AbstractObjectContext -{ - ObjectContext(Object newObject) - { - setObject(newObject); - } - - ObjectContext(String id, Object newObject) - { - setId(id); - setObject(newObject); - } - - ObjectContext() - { - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - throw new AssemblyException(new IllegalArgumentException("Adding objects to an ObjectContext is not allowed.")); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#reportStatement() - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - // can ignore that - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public Object endContext(Context outerContext) throws AssemblyException - { - // just returns the object which is encapsuled (may be null) - return getResult(); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#subContextFailed() - */ - public boolean subContextFailed() - { - // this context will not fail when a subcontext fails because the result is - // already available when the context is created. - return false; - } -} diff --git a/libjava/gnu/java/beans/decoder/ObjectHandler.java b/libjava/gnu/java/beans/decoder/ObjectHandler.java deleted file mode 100644 index dc5b3290bb1..00000000000 --- a/libjava/gnu/java/beans/decoder/ObjectHandler.java +++ /dev/null @@ -1,169 +0,0 @@ -/* gnu.java.beans.decoder.ObjectHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -/** An ObjectHandler parses the <object> tag and thereby creates various - * Context implementations. - * - * @author Robert Schuster - * - */ -public class ObjectHandler extends AbstractElementHandler -{ - /** - * XXX: Can all results be stored with an object id? - * - * - * @param PersistenceParser - */ - ObjectHandler(ElementHandler parent) - { - super(parent, true); - } - - protected Context startElement(Attributes attributes, ExceptionListener exceptionListener) - throws AssemblyException - { - String className = attributes.getValue("class"); - String methodName = attributes.getValue("method"); - String fieldName = attributes.getValue("field"); - String index = attributes.getValue("index"); - String propertyName = attributes.getValue("property"); - String id = attributes.getValue("id"); - String idRef = attributes.getValue("idref"); - - /* first check if we just want to access an existing object (idref present) - * - * note: <object idref="foo" method="bar"/> is not valid to call method "bar" - * on the object with id "foo". Instead this should return the object "foo" - * itself. The right way to this is: - * <object idref="foo"> - * <object method="bar"/> - * </object> - * - * This means that if idref is present class, method, field, index and - * property are obsolete. - */ - if (idRef != null) - // reactivates an existing object and giving it another name if id exists - return new ObjectContext(id, getObject(idRef)); - - // decides whether we are in a static (className present) or dynamic context - if (className != null) - { - try - { - Class klass = instantiateClass(className); - - // class name exists which means that we are in a static context. - // so we may want to ... - // access a static field if the fieldName exists - if (fieldName != null) - { - try - { - return new ObjectContext(id, - klass.getField(fieldName).get(null)); - } - catch (NoSuchFieldException nsfe) - { - throw new AssemblyException(nsfe); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } - - // (falling through is important!) - // run a constructor if methodName is "new" or null - if (methodName == null || methodName.equals("new")) - return new ConstructorContext(id, klass); - - // (falling through is important!) - // run a static method on the given class (if methodName exists, which is implied already) - return new StaticMethodContext(id, klass, methodName); - // XXX: should fail if unexpected attributes are present? - } - catch (ClassNotFoundException cnfe) - { - throw new AssemblyException(cnfe); - } - } - else - { - // className does not exist which means we are in the context of - // some object and want to ... - // access the get(int index) method if index != null - if (index != null) - { - try - { - // Note: http://java.sun.com/products/jfc/tsc/articles/persistence3/ says - // that <void index="4"/> will make up a get()-call. But this is wrong because - // <void/> tags never return values (to the surrounding context) - return new IndexContext(id, Integer.parseInt(index)); - } - catch (NumberFormatException nfe) - { - throw new AssemblyException(nfe); - } - } - - // access a method if methodName exists - if (methodName != null) - return new MethodContext(id, methodName); - - // (falling through is important!) - // access a property if a propertyName exists - if (propertyName != null && propertyName.length() > 0) - // this is reported as an ordinary method access where the propertyName is - // converted into a 'getter'-method name: convert first character of property name - // to upper case and prepend 'get' - // Note: This will be a getter-method because the <object> tag implies that a return - // value is expected. - return new PropertyContext(id, propertyName); - } - - throw new AssemblyException(new IllegalArgumentException("Wrong or missing attributes for <object> tag.")); - } -} diff --git a/libjava/gnu/java/beans/decoder/PersistenceParser.java b/libjava/gnu/java/beans/decoder/PersistenceParser.java deleted file mode 100644 index 4eb37abef97..00000000000 --- a/libjava/gnu/java/beans/decoder/PersistenceParser.java +++ /dev/null @@ -1,485 +0,0 @@ -/* gnu.java.beans.PersistenceParser - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; -import java.beans.XMLDecoder; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** The PersistenceParser parses an XML data stream and delegates actions to ElementHandler - * instances. The parser catches and recovers from all exception which reside from wrong usage - * of attributes and tags. - * - * @author Robert Schuster - */ -public class PersistenceParser extends DefaultHandler implements Context -{ - /** The ExceptionListener instance which is informed of non-critical parsing exceptions. - */ - private ExceptionListener exceptionListener; - - /** When an element was not usable all elements inside it should be skipped. - * This is done by skipping startElement() and endElement() invocations whenever - * this value is above 0. - */ - private int skipElement; - - /** Stores the Creator instances which can instantiate the appropriate handler implementation - * for a given element. - */ - private HashMap handlerCreators = new HashMap(); - - /** Denotes the current ElementHandler. To avoid checking for null-values it is pre-assigned - * with a DummyHandler instance which must not be used but acts as a root element. - */ - private ElementHandler currentHandler; - - /** The real root element that stores all objects created during parsing. - * Package-private to avoid an accessor method. - */ - JavaHandler javaHandler; - - /** Stores the decoded objects. */ - private List objects = new LinkedList(); - - /** The XMLDecoder instance that started this PersistenceParser */ - private XMLDecoder decoder; - - /** Creates a PersistenceParser which reads XML data from the given InputStream, reports - * exceptions to ExceptionListener instance, stores resulting object in the DecoderContext - * and uses the given ClassLoader to resolve classes. - * - * @param inputStream - * @param exceptionListener - * @param decoderContext - * @param cl - */ - public PersistenceParser( - InputStream inputStream, - ExceptionListener exceptionListener, - ClassLoader cl, - XMLDecoder decoder) - { - - this.exceptionListener = exceptionListener; - this.decoder = decoder; - - DummyHandler dummyHandler = new DummyHandler(); - currentHandler = dummyHandler; - javaHandler = new JavaHandler(dummyHandler, this, cl); - - SAXParserFactory factory = SAXParserFactory.newInstance(); - - SAXParser parser; - try - { - parser = factory.newSAXParser(); - } - catch (ParserConfigurationException pce) - { - // should not happen when a parser is available because we did - // not request any requirements on the XML parser - throw (InternalError) new InternalError( - "No SAX Parser available.").initCause( - pce); - } - catch (SAXException saxe) - { - // should not happen when a parser is available because we did - // not request any requirements on the XML parser - throw (InternalError) new InternalError( - "No SAX Parser available.").initCause( - saxe); - } - - // prepares a map of Creator instances which can instantiate a handler which is - // appropriate for the tag that is used as a key for the Creator - handlerCreators.put("java", new JavaHandlerCreator()); - - // calls methods (properties), constructors, access fields - handlerCreators.put("object", new ObjectHandlerCreator()); - handlerCreators.put("void", new VoidHandlerCreator()); - - handlerCreators.put("array", new ArrayHandlerCreator()); - - // these handler directly create an Object (or null) - handlerCreators.put("class", new ClassHandlerCreator()); - handlerCreators.put("null", new NullHandlerCreator()); - - handlerCreators.put("char", new CharHandlerCreator()); - handlerCreators.put("string", new StringHandlerCreator()); - handlerCreators.put("boolean", new BooleanHandlerCreator()); - handlerCreators.put("byte", new ByteHandlerCreator()); - handlerCreators.put("short", new ShortHandlerCreator()); - handlerCreators.put("int", new IntHandlerCreator()); - handlerCreators.put("long", new LongHandlerCreator()); - handlerCreators.put("float", new FloatHandlerCreator()); - handlerCreators.put("double", new DoubleHandlerCreator()); - - // parses the data and sends all exceptions to the ExceptionListener - try - { - parser.parse(inputStream, this); - } - catch (SAXException saxe) - { - exceptionListener.exceptionThrown( - new IllegalArgumentException("XML data not well-formed.")); - } - catch (IOException ioe) - { - exceptionListener.exceptionThrown(ioe); - } - } - - public void startElement( - String uri, - String localName, - String qName, - Attributes attributes) - throws SAXException - { - /* The element is skipped if - * a) the current handler has already failed or a previous error occured - * which makes all children obsolete - */ - if (currentHandler.hasFailed() || skipElement > 0) - { - exceptionListener.exceptionThrown( - new IllegalArgumentException( - "Element unusable due to previous error: " + qName)); - - skipElement++; - - return; - } - - /* b) Subelements are not allowed within the current ElementHandler. - */ - if (!currentHandler.isSubelementAllowed(qName)) - { - exceptionListener.exceptionThrown( - new IllegalArgumentException( - "Element is not allowed here: " + qName)); - - skipElement++; - - return; - } - - /* c) The tag name is not a key in the map of Creator instances. This means that - * either the XML data is of a newer version or simply contains a miss-spelled element. - */ - if (!handlerCreators.containsKey(qName)) - { - exceptionListener.exceptionThrown( - new IllegalArgumentException( - "Element unusable because tag is unknown: " + qName)); - - skipElement++; - - return; - } - - // creates a new handler for the new element - AbstractElementHandler handler = - ((Creator) handlerCreators.get(qName)).createHandler( - currentHandler); - - // makes it the current handler to receive character data - currentHandler = handler; - - // starts the handler - currentHandler.start(attributes, exceptionListener); - } - - public void endElement(String uri, String localName, String qName) - throws SAXException - { - // skips processing the current handler if we are parsing an element - // which was marked invalid (in startElement() ) - if (skipElement > 0) - { - skipElement--; - return; - } - - // invokes the handler's finishing method - currentHandler.end(exceptionListener); - - // removes the current handler and reactivates its parent - currentHandler = currentHandler.getParent(); - } - - /** Transfers character data to the current handler - */ - public void characters(char[] ch, int start, int length) - throws SAXException - { - // prevents sending character data of invalid elements - if (skipElement > 0) - return; - - currentHandler.characters(ch, start, length); - } - - /** Creator interface provided a mechanism to instantiate ElementHandler instances - * for the appropriate tag. - * - * @author Robert Schuster - */ - interface Creator - { - /** Creates an ElementHandler instance using the given ElementHandler as its parent. - * - * @param parent The parent ElementHandler of the result. - * @return A new ElementHandler instance. - */ - AbstractElementHandler createHandler(ElementHandler parent); - } - - class BooleanHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new BooleanHandler(parent); - } - } - - class ByteHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new ByteHandler(parent); - } - } - - class ShortHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new ShortHandler(parent); - } - } - - class IntHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new IntHandler(parent); - } - } - - class LongHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new LongHandler(parent); - } - } - - class FloatHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new FloatHandler(parent); - } - } - - class DoubleHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new DoubleHandler(parent); - } - } - - class CharHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new CharHandler(parent); - } - } - - class StringHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new StringHandler(parent); - } - } - - class JavaHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return javaHandler; - } - } - - class ObjectHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new ObjectHandler(parent); - } - } - - class VoidHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new VoidHandler(parent); - } - } - - class ClassHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new ClassHandler(parent); - } - } - - class NullHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new NullHandler(parent); - } - } - - class ArrayHandlerCreator implements Creator - { - public AbstractElementHandler createHandler(ElementHandler parent) - { - return new ArrayHandler(parent); - } - } - - /** Adds a decoded object to the Context. */ - public void addParameterObject(Object o) throws AssemblyException - { - objects.add(o); - } - - public void notifyStatement(Context outerContext) throws AssemblyException - { - // can be ignored because theis Context does not react to statement and expressions - // differently - } - - public Object endContext(Context outerContext) throws AssemblyException - { - return null; - } - - public boolean subContextFailed() - { - // failing of subcontexts is no problem for the mother of all contexts - return false; - } - - public void set(int index, Object o) throws AssemblyException - { - // not supported - throw new AssemblyException( - new IllegalArgumentException("Set method is not allowed in decoder context.")); - } - - public Object get(int index) throws AssemblyException - { - // not supported - throw new AssemblyException( - new IllegalArgumentException("Get method is not allowed in decoder context.")); - } - - public Object getResult() - { - // returns the XMLDecoder instance which is requested by child contexts this way. - // That is needed to invoke methods on the decoder. - return decoder; - } - - public void setId(String id) - { - exceptionListener.exceptionThrown(new IllegalArgumentException("id attribute is not allowed for <java> tag.")); - } - - public String getId() - { - // appears to have no id - return null; - } - - public boolean isStatement() - { - // this context is a statement by definition because it never returns anything to a parent because - // there is no such parent (DummyContext does not count!) - return true; - } - - public void setStatement(boolean b) - { - // ignores that because this Context is always a statement - } - - /** Returns an Iterator instance which returns the decoded objects. - * - * This method is used by the XMLDecoder directly. - */ - public Iterator iterator() - { - return objects.iterator(); - } - -} diff --git a/libjava/gnu/java/beans/decoder/PropertyContext.java b/libjava/gnu/java/beans/decoder/PropertyContext.java deleted file mode 100644 index 838ef814b01..00000000000 --- a/libjava/gnu/java/beans/decoder/PropertyContext.java +++ /dev/null @@ -1,137 +0,0 @@ -/* gnu.java.beans.decoder.PropertyContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** PropertyContext is a Context implementation that is very similar to MethodContext - * and IndexContext. The sole purpose of PropertyContext to find out whether it should - * 'set' or 'get' a certain property. This decision is made using the number of - * arguments. - * <p>When the method call has to be made and there is no argument we 'get' the property. - * With one argument it is 'set'.</p> - * - * @author Robert Schuster - */ -class PropertyContext extends AbstractObjectContext -{ - private Object argument; - private String propertyName; - private String prefix = "get"; - private boolean methodCalled; - - PropertyContext(String id, String newPropertyName) - { - setId(id); - propertyName = newPropertyName; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObject(Object o) throws AssemblyException - { - if (methodCalled) - throw new AssemblyException(new IllegalArgumentException("Cannot add parameter object when method was already called.")); - - if (argument != null) - throw new AssemblyException(new IllegalArgumentException("Property attribut allows zero or one argument only.")); - - argument = o; - setStatement(true); - prefix = "set"; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - public void notifyStatement(Context outerContext) throws AssemblyException - { - if (methodCalled) - return; - methodCalled = true; - - Object outerObject = outerContext.getResult(); - - if (outerObject == null) - throw new AssemblyException(new NullPointerException("No object to access property " - + propertyName)); - - - // converts property name into a method name - String methodName = prefix + propertyName.substring(0, 1).toUpperCase() - + propertyName.substring(1); - - // prepares the argument - Object[] args = (argument != null) ? new Object[] { argument } : null; - - try - { - Method method = MethodFinder.getMethod(outerObject.getClass(), - methodName, args); - - // stores the result whether it is available or not - setObject(method.invoke(outerObject, args)); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } - - public Object endContext(Context outerContext) throws AssemblyException - { - notifyStatement(outerContext); - - return getResult(); - } - - public boolean subContextFailed() - { - return ! methodCalled; - } -} diff --git a/libjava/gnu/java/beans/decoder/ShortHandler.java b/libjava/gnu/java/beans/decoder/ShortHandler.java deleted file mode 100644 index ab6ddbece26..00000000000 --- a/libjava/gnu/java/beans/decoder/ShortHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* gnu.java.beans.decoder.ShortHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -/** Creates a Short instance from the character data in a <short> tag. - * - * @author Robert Schuster - */ -class ShortHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - ShortHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String number) throws NumberFormatException - { - return Short.valueOf(number); - } -} diff --git a/libjava/gnu/java/beans/decoder/SimpleHandler.java b/libjava/gnu/java/beans/decoder/SimpleHandler.java deleted file mode 100644 index bc187e8a052..00000000000 --- a/libjava/gnu/java/beans/decoder/SimpleHandler.java +++ /dev/null @@ -1,111 +0,0 @@ -/* gnu.java.beans.decoder.SimpleHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -/** XML element handler that is specialized on tags that contains a simple string in their - * body which has to be parsed in a specific way. - * <p>All of these tags have in common that they do not accept attributes. A warning is - * send to the parser's ExceptionListener when one or more attributes exist.</p> - * - * @author Robert Schuster - */ -abstract class SimpleHandler extends AbstractElementHandler -{ - private ObjectContext context; - - /** - * @param PersistenceParser - */ - SimpleHandler(ElementHandler parent) - { - super(parent, false); - - // SimpleHandler do not accept any subelements - } - - protected final Context startElement(Attributes attributes, ExceptionListener exceptionListener) - throws AssemblyException - { - - // note: simple elements should not have any attributes. We inform - // the user of this syntactical but uncritical problem by sending - // an IllegalArgumentException for each unneccessary attribute - int size = attributes.getLength(); - for (int i = 0; i < size; i++) { - String attributeName = attributes.getQName(i); - Exception e = - new IllegalArgumentException( - "Unneccessary attribute '" - + attributeName - + "' discarded."); - exceptionListener.exceptionThrown(e); - } - - return context = new ObjectContext(); - } - - public void endElement(String characters) - throws AssemblyException, AssemblyException - { - // reports the number when the character data can be parsed - try - { - context.setObject(parse(characters)); - } - catch (NumberFormatException nfe) - { - throw new AssemblyException(nfe); - } - } - - /** Returns an object that is created from the given characters. If the string is - * converted into a number a NumberFormatException is cathed and reported - * appropriately. - * - * @param characters A string of characters that has to be processed in some way. - * @return An Object instance generated from the given data. - * @throws AssemblerException When the string was invalid. - * @throws NumberFormatException When the string could not be parsed into a number. - */ - protected abstract Object parse(String characters) - throws AssemblyException, NumberFormatException; -} diff --git a/libjava/gnu/java/beans/decoder/StaticMethodContext.java b/libjava/gnu/java/beans/decoder/StaticMethodContext.java deleted file mode 100644 index 959c949f77b..00000000000 --- a/libjava/gnu/java/beans/decoder/StaticMethodContext.java +++ /dev/null @@ -1,95 +0,0 @@ -/* gnu.java.beans.decoder.StaticMethodContext - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; - -/** - * @author Robert Schuster - */ -class StaticMethodContext extends AbstractCreatableObjectContext -{ - private ArrayList arguments = new ArrayList(); - private Class klass; - private String methodName; - - StaticMethodContext(String id, Class newClass, String newMethodName) - { - setId(id); - klass = newClass; - methodName = newMethodName; - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#addObject(java.lang.Object) - */ - public void addParameterObjectImpl(Object o) - { - arguments.add(o); - } - - /* (non-Javadoc) - * @see gnu.java.beans.decoder.Context#endContext(gnu.java.beans.decoder.Context) - */ - protected Object createObject(Context outerContext) - throws AssemblyException - { - Object[] args = arguments.toArray(); - - try - { - Method method = MethodFinder.getMethod(klass, methodName, args); - return method.invoke(null, args); - } - catch (NoSuchMethodException nsme) - { - throw new AssemblyException(nsme); - } - catch (InvocationTargetException ite) - { - // rethrows the reason for the InvocationTargetsException (ie. the exception in the called code) - throw new AssemblyException(ite.getCause()); - } - catch (IllegalAccessException iae) - { - throw new AssemblyException(iae); - } - } -} diff --git a/libjava/gnu/java/beans/decoder/StringHandler.java b/libjava/gnu/java/beans/decoder/StringHandler.java deleted file mode 100644 index 6f2311a9e62..00000000000 --- a/libjava/gnu/java/beans/decoder/StringHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* gnu.java.beans.decoder.StringHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -class StringHandler extends SimpleHandler -{ - /** - * @param PersistenceParser - */ - StringHandler(ElementHandler parent) - { - super(parent); - } - - protected Object parse(String characters) - { - return characters; - } -} diff --git a/libjava/gnu/java/beans/decoder/VoidHandler.java b/libjava/gnu/java/beans/decoder/VoidHandler.java deleted file mode 100644 index ca3664bbed1..00000000000 --- a/libjava/gnu/java/beans/decoder/VoidHandler.java +++ /dev/null @@ -1,140 +0,0 @@ -/* gnu.java.beans.decoder.VoidHandler - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.beans.decoder; - -import java.beans.ExceptionListener; - -import org.xml.sax.Attributes; - -public class VoidHandler extends AbstractElementHandler -{ - /** - * @param PersistenceParser - */ - VoidHandler(ElementHandler parent) - { - super(parent, true); - } - - protected Context startElement( - Attributes attributes, - ExceptionListener exceptionListener) - throws AssemblyException - { - Context ctx = startElementImpl(attributes); - ctx.setStatement(true); - - return ctx; - } - - private Context startElementImpl(Attributes attributes) - throws AssemblyException - { - String id = attributes.getValue("id"); - String className = attributes.getValue("class"); - String methodName = attributes.getValue("method"); - String propertyName = attributes.getValue("property"); - String index = attributes.getValue("index"); - - if (className != null) - { - try - { - Class klass = instantiateClass(className); - - // class name exists which means that we are in a static context. - // so we may want to ... - // run a constructor if methodName is "new" or null - if (methodName == null || methodName.equals("new")) - // if the id is null the result cannot be by the decoder accessed but the - // constructor may have side effects (e.g. registering itself in a global registry) - return new ConstructorContext(id, klass); - - // (falling through is important!) - // run a static method on the given class (if methodName exists, which is implied already) - return new StaticMethodContext(id, klass, methodName); - } - catch (ClassNotFoundException cnfe) - { - throw new AssemblyException(cnfe); - } - } - else - { - // className does not exist which means we are in the context of - // some object and want to ... - // access an element by index - if (index != null) - { - // note: whether this resolves into get(i) or set(i, o) depends on the - // number of arguments and is decided by the ObjectAssembler - try - { - return new IndexContext(id, Integer.parseInt(index)); - } - catch (NumberFormatException nfe) - { - throw new AssemblyException(nfe); - } - } - - // access a method if methodName exists - if (methodName != null) - return new MethodContext(id, methodName); - - // (falling through is important!) - // access a property if a propertyName exists - if (propertyName != null && propertyName.length() > 0) - // this is reported as an ordinary method invocation where the propertyName is - // converted into a 'setter'-method name: convert first character of property name - // to upper case and prepend 'set' - // Note: This will be a setter-method because the <void> tag implies that no return - // value is expected (but a side effect) - return new PropertyContext(id, propertyName); - } - - // if code reaches this point the tag has wrong attributes. The following test - // does not make it better but can provide are more specific error message for - // a common mistake: <void> tags are not allowed to have an idref attribute - throw new AssemblyException( - new IllegalArgumentException( - (attributes.getValue("idref") == null) - ? "Missing attributes for <void> tag" - : "<void> does not support 'idref' attribute.")); - } -} diff --git a/libjava/gnu/java/beans/editors/ColorEditor.java b/libjava/gnu/java/beans/editors/ColorEditor.java deleted file mode 100644 index b099eb2f0e9..00000000000 --- a/libjava/gnu/java/beans/editors/ColorEditor.java +++ /dev/null @@ -1,100 +0,0 @@ -/* gnu.java.beans.editors.ColorEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.awt.Color; -import java.beans.PropertyEditorSupport; - -/** - ** NativeByteEditor is a property editor for the - ** byte type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class ColorEditor extends PropertyEditorSupport { - Color[] stdColors = {Color.black,Color.blue,Color.cyan, - Color.darkGray,Color.gray,Color.green, - Color.lightGray,Color.magenta,Color.orange, - Color.pink,Color.red,Color.white, - Color.yellow}; - String[] stdColorNames = {"black","blue","cyan", - "dark gray","gray","green", - "light gray","magenta","orange", - "pink","red","white", - "yellow"}; - - /** setAsText for Color checks for standard color names - ** and then checks for a #RRGGBB value or just RRGGBB, - ** both in hex. - **/ - public void setAsText(String val) throws IllegalArgumentException { - if(val.length() == 0) { - throw new IllegalArgumentException("Tried to set empty value!"); - } - for(int i=0;i<stdColorNames.length;i++) { - if(stdColorNames[i].equalsIgnoreCase(val)) { - setValue(stdColors[i]); - return; - } - } - if(val.charAt(0) == '#') { - setValue(new Color(Integer.parseInt(val.substring(1),16))); - } else { - setValue(new Color(Integer.parseInt(val,16))); - } - } - - /** getAsText for Color turns the color into either one of the standard - ** colors or into an RGB hex value with # prepended. **/ - public String getAsText() { - for(int i=0;i<stdColors.length;i++) { - if(stdColors[i].equals(getValue())) { - return stdColorNames[i]; - } - } - return "#" + Integer.toHexString(((Color)getValue()).getRGB() & 0x00FFFFFF); - } - - /** getTags for Color returns a list of standard colors. **/ - public String[] getTags() { - return stdColorNames; - } -} diff --git a/libjava/gnu/java/beans/editors/FontEditor.java b/libjava/gnu/java/beans/editors/FontEditor.java deleted file mode 100644 index 904f7bebfbe..00000000000 --- a/libjava/gnu/java/beans/editors/FontEditor.java +++ /dev/null @@ -1,77 +0,0 @@ -/* gnu.java.beans.editors.FontEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.awt.Font; -import java.beans.PropertyEditorSupport; - -/** - ** FontEditor is a property editor for java.awt.Font. - ** - ** <STRONG>To Do:</STRONG> Add custom font chooser - ** component. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class FontEditor extends PropertyEditorSupport { - /** setAsText for Font calls Font.decode(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Font.decode(val)); - } - - /** getAsText for Font returns a value in the format - ** expected by Font.decode(). - **/ - public String getAsText() { - Font f = (Font)getValue(); - if(f.isBold()) { - if(f.isItalic()) { - return f.getName()+"-bolditalic-"+f.getSize(); - } else { - return f.getName()+"-bold-"+f.getSize(); - } - } else if(f.isItalic()) { - return f.getName()+"-italic-"+f.getSize(); - } else { - return f.getName()+"-"+f.getSize(); - } - } -} diff --git a/libjava/gnu/java/beans/editors/NativeBooleanEditor.java b/libjava/gnu/java/beans/editors/NativeBooleanEditor.java deleted file mode 100644 index 3620cc1747a..00000000000 --- a/libjava/gnu/java/beans/editors/NativeBooleanEditor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* gnu.java.beans.editors.NativeBooleanEditor - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeBooleanEditor is a property editor for the - ** boolean type.<P> - ** - ** <STRONG>To Do:</STRONG> add support for a checkbox - ** as the custom editor. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeBooleanEditor extends PropertyEditorSupport { - String[] tags = {"true","false"}; - - /** - * setAsText for boolean checks for true or false or t or f. - * "" also means false. - **/ - public void setAsText(String val) throws IllegalArgumentException { - if(val.equalsIgnoreCase("true") || val.equalsIgnoreCase("t")) { - setValue(Boolean.TRUE); - } else if(val.equalsIgnoreCase("false") || val.equalsIgnoreCase("f") || val.equals("")) { - setValue(Boolean.FALSE); - } else { - throw new IllegalArgumentException("Value must be true, false, t, f or empty."); - } - } - - - /** getAsText for boolean calls Boolean.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeByteEditor.java b/libjava/gnu/java/beans/editors/NativeByteEditor.java deleted file mode 100644 index f3ec5fa1945..00000000000 --- a/libjava/gnu/java/beans/editors/NativeByteEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeByteEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeByteEditor is a property editor for the - ** byte type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeByteEditor extends PropertyEditorSupport { - /** setAsText for byte calls Byte.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Byte.valueOf(val)); - } - - /** getAsText for byte calls Byte.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeDoubleEditor.java b/libjava/gnu/java/beans/editors/NativeDoubleEditor.java deleted file mode 100644 index 8d8aae15337..00000000000 --- a/libjava/gnu/java/beans/editors/NativeDoubleEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeDoubleEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeDoubleEditor is a property editor for the - ** double type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeDoubleEditor extends PropertyEditorSupport { - /** setAsText for double calls Double.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Double.valueOf(val)); - } - - /** getAsText for double calls Double.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeFloatEditor.java b/libjava/gnu/java/beans/editors/NativeFloatEditor.java deleted file mode 100644 index 801377e7df9..00000000000 --- a/libjava/gnu/java/beans/editors/NativeFloatEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeFloatEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeFloatEditor is a property editor for the - ** float type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeFloatEditor extends PropertyEditorSupport { - /** setAsText for float calls Float.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Float.valueOf(val)); - } - - /** getAsText for float calls Float.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeIntEditor.java b/libjava/gnu/java/beans/editors/NativeIntEditor.java deleted file mode 100644 index a6148841c46..00000000000 --- a/libjava/gnu/java/beans/editors/NativeIntEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeIntEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeIntEditor is a property editor for the - ** int type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeIntEditor extends PropertyEditorSupport { - /** setAsText for int calls Integer.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Integer.valueOf(val)); - } - - /** getAsText for int calls Integer.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeLongEditor.java b/libjava/gnu/java/beans/editors/NativeLongEditor.java deleted file mode 100644 index 95e9dc87028..00000000000 --- a/libjava/gnu/java/beans/editors/NativeLongEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeLongEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeLongEditor is a property editor for the - ** long type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeLongEditor extends PropertyEditorSupport { - /** setAsText for long calls Long.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Long.valueOf(val)); - } - - /** getAsText for long calls Long.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/NativeShortEditor.java b/libjava/gnu/java/beans/editors/NativeShortEditor.java deleted file mode 100644 index ffaa266492e..00000000000 --- a/libjava/gnu/java/beans/editors/NativeShortEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.NativeShortEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeShortEditor is a property editor for the - ** short type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class NativeShortEditor extends PropertyEditorSupport { - /** setAsText for short calls Short.valueOf(). **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(Short.valueOf(val)); - } - - /** getAsText for short calls Short.toString(). **/ - public String getAsText() { - return getValue().toString(); - } -} diff --git a/libjava/gnu/java/beans/editors/StringEditor.java b/libjava/gnu/java/beans/editors/StringEditor.java deleted file mode 100644 index 8242d5475a5..00000000000 --- a/libjava/gnu/java/beans/editors/StringEditor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* gnu.java.beans.editors.StringEditor - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.beans.editors; - -import java.beans.PropertyEditorSupport; - -/** - ** NativeByteEditor is a property editor for the - ** byte type. - ** - ** @author John Keiser - ** @version 1.1.0, 29 Jul 1998 - **/ - -public class StringEditor extends PropertyEditorSupport { - /** setAsText just sets the value. **/ - public void setAsText(String val) throws IllegalArgumentException { - setValue(val); - } - - /** getAsText just returns the value. **/ - public String getAsText() { - return (String)getValue(); - } -} diff --git a/libjava/gnu/java/io/ASN1ParsingException.java b/libjava/gnu/java/io/ASN1ParsingException.java deleted file mode 100644 index 5d2c64ab54f..00000000000 --- a/libjava/gnu/java/io/ASN1ParsingException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* ASN1ParsingException.java -- ASN.1 parsing exception. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.io; - -/** - * Signals a malformed ASN.1 sequence. - */ -public class ASN1ParsingException extends java.io.IOException -{ - - public ASN1ParsingException() - { - super(); - } - - public ASN1ParsingException(String msg) - { - super(msg); - } -} diff --git a/libjava/gnu/java/io/Base64InputStream.java b/libjava/gnu/java/io/Base64InputStream.java deleted file mode 100644 index b0824ab6935..00000000000 --- a/libjava/gnu/java/io/Base64InputStream.java +++ /dev/null @@ -1,216 +0,0 @@ -/* Base64InputStream.java -- base-64 input stream. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.io; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * A filter input stream that decodes data encoded in the Base-64 - * encoding scheme. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class Base64InputStream extends FilterInputStream -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - /** Base-64 digits. */ - private static final String BASE_64 = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - /** Base-64 padding character. */ - private static final char BASE_64_PAD = '='; - - /** Decoding state. */ - private int state; - - /** Intermediate decoded value. */ - private int temp; - - /** EOF flag. */ - private boolean eof; - - private final byte[] one = new byte[1]; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new Base-64 input stream. The input bytes must be the - * ASCII characters A-Z, a-z, 0-9, + and /, with optional whitespace, - * and will be decoded into a byte stream. - * - * @param in The source of Base-64 input. - */ - public Base64InputStream(InputStream in) - { - super(in); - state = 0; - temp = 0; - eof = false; - } - - // Class method. - // ------------------------------------------------------------------------ - - /** - * Decode a single Base-64 string to a byte array. - * - * @param base64 The Base-64 encoded data. - * @return The decoded bytes. - * @throws IOException If the given data do not compose a valid Base-64 - * sequence. - */ - public static byte[] decode(String base64) throws IOException - { - Base64InputStream in = - new Base64InputStream(new ByteArrayInputStream(base64.getBytes())); - ByteArrayOutputStream out = - new ByteArrayOutputStream((int) (base64.length() / 0.666)); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) != -1) - out.write(buf, 0, len); - return out.toByteArray(); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public int available() - { - return 0; - } - - public int read() throws IOException - { - if (read(one) == 1) - return one[0]; - return -1; - } - - public int read(byte[] buf, int off, int len) throws IOException - { - if (eof) - return -1; - int count = 0; - while (count < len) - { - int i; - while (Character.isWhitespace((char) (i = in.read()))); - int pos = BASE_64.indexOf((char) i); - if (pos >= 0) - { - switch (state) - { - case 0: - temp = pos << 2; - state = 1; - break; - case 1: - buf[count++] = (byte) (temp | (pos >>> 4)); - temp = (pos & 0x0F) << 4; - state = 2; - break; - case 2: - buf[count++] = (byte) (temp | (pos >>> 2)); - temp = (pos & 0x03) << 6; - state = 3; - break; - case 3: - buf[count++] = (byte) (temp | pos); - state = 0; - break; - } - } - else if (i == BASE_64_PAD) - { - switch (state) - { - case 0: - case 1: - throw new IOException("malformed Base-64 input"); - case 2: - while (Character.isWhitespace((char) (i = in.read()))); - if (i != BASE_64_PAD) - throw new IOException("malformed Base-64 input"); - case 3: - while (Character.isWhitespace((char) (i = in.read()))); - } - eof = true; - break; - } - else // First non-Base-64 character, consider it end-of-stream. - { - if (state != 0) - throw new IOException("malformed Base-64 input"); - eof = true; - break; - } - } - return count; - } - - public boolean markSupported() - { - return false; - } - - public void mark(int markLimit) { } - - public void reset() throws IOException - { - throw new IOException("reset not supported"); - } - - public long skip(long n) throws IOException - { - long skipped; - for (skipped = 0; skipped < n; skipped++) - if (read() == -1) - break; - return skipped; - } -} diff --git a/libjava/gnu/java/io/ClassLoaderObjectInputStream.java b/libjava/gnu/java/io/ClassLoaderObjectInputStream.java deleted file mode 100644 index 238ab26b1b9..00000000000 --- a/libjava/gnu/java/io/ClassLoaderObjectInputStream.java +++ /dev/null @@ -1,73 +0,0 @@ -/* gnu.java.io.ClassLoaderObjectInputStream - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.io; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.StreamCorruptedException; - -/** - * ClassLoaderObjectInputStream is ObjectInputStream, with - * the ability to use a specific ClassLoader. - * - * @author Geoff Berry - * @version 1.1.0, 29 Jul 1998 - */ - -public class ClassLoaderObjectInputStream extends ObjectInputStream { - ClassLoader myClassLoader; - - /** Create the new ClassLoaderObjectInputStream. - * @param in the InputStream to read the Objects from. - * @param myClassLoader the ClassLoader to load classes - * with. - */ - public ClassLoaderObjectInputStream(InputStream in, ClassLoader myClassLoader) throws IOException,StreamCorruptedException { - super(in); - this.myClassLoader = myClassLoader; - } - - /** Overriden method to use the loadClass() method from - * the ClassLoader. - */ - public Class resolveClass(String name) throws IOException, ClassNotFoundException { - return myClassLoader.loadClass(name); - } -} diff --git a/libjava/gnu/java/io/NullOutputStream.java b/libjava/gnu/java/io/NullOutputStream.java deleted file mode 100644 index 526bd26e830..00000000000 --- a/libjava/gnu/java/io/NullOutputStream.java +++ /dev/null @@ -1,56 +0,0 @@ -/* NullOutputStream.java -- OutputStream that does absolutely nothing - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.io; - -import java.io.OutputStream; - -/** - This is a placeholder OutputStream that does absolutley nothing - when written to. It is intended to be used in the same manner as - /dev/null. None of this class's methods do anything at all. -*/ -public class NullOutputStream extends OutputStream -{ - public NullOutputStream() {} - public void write( int b ) {} - public void write( byte b[] ) {} - public void write( byte b[], int off, int len ) {} - public void flush() {} - public void close() {} -} diff --git a/libjava/gnu/java/io/ObjectIdentityWrapper.java b/libjava/gnu/java/io/ObjectIdentityWrapper.java deleted file mode 100644 index 6db2e3a52a6..00000000000 --- a/libjava/gnu/java/io/ObjectIdentityWrapper.java +++ /dev/null @@ -1,100 +0,0 @@ -/* ObjectIdentityWrapper.java -- Wrapper class used to override equals() - and hashCode() to be as discriminating as possible - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.io; - -/** - This class is a thin wrapper around <code>Object</code> that makes - the methods <code>hashCode()</code> and <code>equals(Object)</code> - as discriminating as possible. -*/ -public class ObjectIdentityWrapper -{ - - /** - Constructs a <code>ObjectIdentityWrapper</code> that is wrapped - around o. - */ - public ObjectIdentityWrapper( Object o ) - { - object = o; - } - - /** - Uses <code>System.identityHashCode(Object)</code> to compute a - hash code for the object wrapped by this - <code>ObjectIdentityWrapper</code>. - - @see java.lang.System#identityHashCode(java.lang.Object) - @see java.util.Hashtable - @see java.lang.Object#hashCode() - */ - public int hashCode() - { - return System.identityHashCode( object ); - } - - /** - Uses the <code>==</code> operator to test for equality between - the object wrapped by this <code>ObjectIdentityWrapper</code> and - the object wrapped by the <code>ObjectIdentityWrapper</code> o. - Returns false if o is not a <code>ObjectIdentityWrapper</code>. - - @see java.util.Hashtable - @see java.lang.Object#equals() - */ - public boolean equals( Object o ) - { - if( o instanceof ObjectIdentityWrapper ) - return object == ((ObjectIdentityWrapper)o).object; - else - return false; - } - - public String toString() - { - return "ObjectIdentityWrapper< " + object + ", " + hashCode() + " >"; - } - - /** - The <code>Object</code> wrapped by this - <code>ObjectIdentityWrapper</code>. - */ - public Object object; -} diff --git a/libjava/gnu/java/lang/ArrayHelper.java b/libjava/gnu/java/lang/ArrayHelper.java deleted file mode 100644 index 5f675831e9f..00000000000 --- a/libjava/gnu/java/lang/ArrayHelper.java +++ /dev/null @@ -1,78 +0,0 @@ -/* ArrayHelper.java -- Helper methods for handling array operations - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.lang; - -/** - * ArrayHelper helps you do things with arrays. - * - * @author John Keiser - */ -public class ArrayHelper -{ - /** - * Counterpart to java.util.Collection.contains. - * - * @param array the array to search - * @param searchFor the object to locate - * @return true if some array element <code>equals(searchFor)</code> - */ - public static boolean contains(Object[] array, Object searchFor) - { - return indexOf(array, searchFor) != -1; - } - - /** - * Counterpart to java.util.Collection.indexOf. - * - * @param array the array to search - * @param searchFor the object to locate - * @return the index of the first equal object, or -1 - */ - public static int indexOf(Object[] array, Object searchFor) - { - for (int i = 0; i < array.length; i++) - { - if(array[i].equals(searchFor)) - { - return i; - } - } - return -1; - } -} diff --git a/libjava/gnu/java/lang/CharData.java b/libjava/gnu/java/lang/CharData.java deleted file mode 100644 index 7631522c810..00000000000 --- a/libjava/gnu/java/lang/CharData.java +++ /dev/null @@ -1,1001 +0,0 @@ -/* gnu/java/lang/CharData -- Database for java.lang.Character Unicode info - Copyright (C) 2002 Free Software Foundation, Inc. - *** This file is generated by scripts/unicode-muncher.pl *** - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.lang; - -/** - * This contains the info about the unicode characters, that - * java.lang.Character needs. It is generated automatically from - * <code>gnu/gcj/convert/UnicodeData-3.0.0.txt</code> and - * <code>gnu/gcj/convert/SpecialCasing-2.txt</code>, by some - * perl scripts. These Unicode definition files can be found on the - * <a href="http://www.unicode.org">http://www.unicode.org</a> website. - * JDK 1.4 uses Unicode version 3.0.0. - * - * The data is stored as string constants, but Character will convert these - * Strings to their respective <code>char[]</code> components. The field - * <code>BLOCKS</code> stores the offset of a block of 2<sup>SHIFT</sup> - * characters within <code>DATA</code>. The DATA field, in turn, stores - * information about each character in the low order bits, and an offset - * into the attribute tables <code>UPPER</code>, <code>LOWER</code>, - * <code>NUM_VALUE</code>, and <code>DIRECTION</code>. Notice that the - * attribute tables are much smaller than 0xffff entries; as many characters - * in Unicode share common attributes. The DIRECTION table also contains - * a field for detecting characters with multi-character uppercase expansions. - * Next, there is a listing for <code>TITLE</code> exceptions (most characters - * just have the same title case as upper case). Finally, there are two - * tables for multi-character capitalization, <code>UPPER_SPECIAL</code> - * which lists the characters which are special cased, and - * <code>UPPER_EXPAND</code>, which lists their expansion. - * - * @author scripts/unicode-muncher.pl (written by Jochen Hoenicke, - * Eric Blake) - * @see Character - * @see String - */ -public interface CharData -{ - /** - * The Unicode definition file that was parsed to build this database. - */ - String SOURCE = "gnu/gcj/convert/UnicodeData-3.0.0.txt"; - - /** - * The character shift amount to look up the block offset. In other words, - * <code>(char) (BLOCKS.value[ch >> SHIFT] + ch)</code> is the index where - * <code>ch</code> is described in <code>DATA</code>. - */ - int SHIFT = 5; - - /** - * The mapping of character blocks to their location in <code>DATA</code>. - * Each entry has been adjusted so that the 16-bit sum with the desired - * character gives the actual index into <code>DATA</code>. - */ - String BLOCKS - = "\u01c2\u01c2\u01c1\u012c\u012b\u01a0\u01f8\u02dc\u025f\u02ee\u0215" - + "\u0346\u02dc\u0326\u02bc\u0216\u015f\u02d4\u0376\u0376\u0376\u0369" - + "\ufe8f\u0344\uff85\uff65\ufdb5\ufda1\033\u02c4\034G\ufea8" - + "\uff8c\u0235\ufeff\032\ufebf&\ufb20\ufe28\u0113\u0104\ufb61" - + "\ufb5a\u010b\u0109\u00fe\uff08\u0229\u025e\u01c7\u01fc\u01dc\ufc46" - + "\u0229\ufe27\ufb55\u0169\ufbc8\u00fc\u0103\ufb68\ufb48\ufb28\ufb08" - + "\ufae8\ufac8\ufaa8\ufa88\ufa68\ufa48eP\u00ab\u0139\ufe0e" - + "c\u0155\u01a8\uf669\u0129\u0128\uf91f\ufe56\u0108\u0107\ufac0" - + "\ufc8e\ufead\u00c6\ufca7\ufb95\uf47d\u009f\ufb17\ufe20\ufd28\ufb2f" - + ";\uf3b9\ufe57\ufcce\uffbb\uf339\ufa98\uff8b\uff3b\ufa54\uf7e3" - + "\uff2b\ufad7\ufb69\ufc3a\ufee5\uf4c8\ufcb0\ufa88\ufdbf\uf448\ufe45" - + "\ufcc7\ufe4f\uf7f1\uf715\uf2e8\ufd9f\uf348\uf96a\ufc02\ufd97\uf2c8" - + "\uf2a8\uf4b9\uf4b3\uef6b\uf86a\uf84a\ufc58\uf80a\uf7ea\ufc0f\uf7aa" - + "\uee9c\ufb90\uf74a\uf7fa\uf70a\uf7ca\uf792\uf471\uf4d2\uf732\uf64a" - + "\uf401\uf64d\uefa8\uf5ca\uf5aa\ueca1\uf569\uf54a\uf52a\uf50a\uf4ea" - + "\uf4ca\uf4aa\uf48a\uf46a\uf44a\uf42a\uf40a\uf3ea\uf3ca\uf3aa\uf38a" - + "\uf36a\uf34a\uf32a\uf289\uf777\uf2ca\uf2aa\uf737\uec28\uec08\uebe8" - + "\uebc8\uf1ea\uf4a2\uf545\uedc6\uf2d7\uf14a\ue8ed\ue81e\uf0ea\uf597" - + "\uea68\uea48\uea28\uea08\ue9e8\ue9c8\ue9a8\ue988\ue968\ue948\ue928" - + "\ue908\ue8e8\ue8c8\ue8a8\ue888\ue868\ue848\ue828\ue808\ue7e8\ue7c8" - + "\ue7a8\ue788\ue768\ue748\ue728\ue708\ue6e8\ue6c8\ue6a8\ue688\ue668" - + "\ue648\ue628\ue608\ue5e8\ue5c8\ue5a8\ue588\ue568\ue548\ue55f\ue53f" - + "\ue51f\ue4ff\uefd7\ue4bf\ue49f\ue485\uef87\uef57\uef57\uef57\uef57" - + "\uef47\ue1ad\uef46\uef46\uef46\ue1e0\ue3dd\uef06\ue9d9\uebeb\ue244" - + "\ueed4\uef65\ue1f5\uef45\ueee9\uef7c\uee74\uef70\uef7d\uef78\uee91" - + "\uefd3\uee7d\uee25\uee27\uef65\uefdd\uee96\uefd3\uefe1\uef69\udf88" - + "\udf68\udf48\ued2b\ued3d\ued19\uef1c\uef08\ued47\ued3d\ued33\uec2b" - + "\uec0b\uebeb\uebcb\uebce\uea7c\ueb69\ueb6c\ue9b6\ueb0b\ueaeb\ue9e9" - + "\udca8\udc88\udc68\udc48\ue910\uea23\ueb58\ueb4f\ueb45\ueae5\udb68" - + "\udb48\ue92b\ue90b\ue8eb\ue8cb\ue8ab\ue88b\ue86b\ue84b\uda28\uda08" - + "\ud9e8\ud9c8\ud9a8\ud988\ud968\ud948\ud928\ud908\ud8e8\ud8c8\ud8a8" - + "\ud888\ud868\ud848\ud828\ud808\ud7e8\ud7c8\ud7a8\ud788\ud768\ud748" - + "\ud728\ud708\ud6e8\ud6c8\ud6a8\ud688\ud668\ud648\ud628\ud608\ud5e8" - + "\ud5c8\ud5a8\ud588\ud568\ud548\ud528\ud508\ud4e8\ud4c8\ue2b1\ue28b" - + "\ue26b\ue270\ue22b\ue20b\ue1eb\ue1cb\ue1ab\ue18b\ue18e\udd8f\ue3a8" - + "\udfd3\ud929\ud90a\ue348\ud8c9\ud8aa\udcd7\udcb2\ud681\ud82a\ud80a" - + "\ue268\ucede\ud168\ud148\ue116\ue0e9\ue1cb\ue0b7\ue0b7\ue15e\udf17" - + "\ue034\ue013\udff3\udfd3\ude6c\udf93\udf73\udf55\udf34\ud56a\ud54a" - + "\ud52a\ud50a\ud4ea\ud4ca\ud4aa\ud48a\ud46a\ud44a\ud42a\ud40a\ud3ea" - + "\ud3ca\ud3aa\ud38a\ud36a\ud34a\ud32a\ud30a\ud2ea\ud2ca\ud2aa\ud28a" - + "\ud26a\ud24a\ud22a\ud20a\ud1ea\ud1ca\ud1aa\ud18a\ud16a\ud14a\ud12a" - + "\ud10a\ud0ea\ud0ca\ud0aa\ud08a\ud06a\ud04a\ud02a\ud00a\ucfea\ucfca" - + "\ucfaa\ucf8a\ucf6a\ucf4a\ucf2a\ucf0a\uceea\uceca\uceaa\uce8a\uce6a" - + "\uce4a\uce2a\uce0a\ucdea\ucdca\ucdaa\ucd8a\ucd6a\ucd4a\ucd2a\ucd0a" - + "\uccea\uccca\uccaa\ucc8a\ucc6a\ucc4a\ucc2a\ucc0a\ucbea\ucbca\ucbaa" - + "\ucb8a\ucb6a\ucb4a\ucb2a\ucb0a\ucaea\ucaca\ucaaa\uca8a\uca6a\uca4a" - + "\uca2a\uca0a\uc9ea\uc9ca\uc9aa\uc98a\uc96a\uc94a\uc92a\uc90a\uc8ea" - + "\uc8ca\uc8aa\uc88a\uc86a\uc84a\uc82a\uc80a\uc7ea\uc7ca\uc7aa\uc78a" - + "\uc76a\uc74a\uc72a\uc70a\uc6ea\uc6ca\uc6aa\uc68a\uc66a\uc64a\uc62a" - + "\uc60a\uc5ea\uc5ca\uc5aa\uc58a\uc56a\uc54a\uc52a\uc50a\uc4ea\uc4ca" - + "\uc4aa\uc48a\uc46a\uc44a\uc42a\uc40a\uc3ea\uc3ca\uc3aa\uc38a\uc36a" - + "\uc34a\uc32a\uc30a\uc2ea\uc2ca\uc2aa\uc28a\uc26a\uc24a\uc22a\uc20a" - + "\uc1ea\uc1ca\uc1aa\uc18a\uc16a\uc14a\uc12a\uc10a\uc0ea\uc0ca\uc0aa" - + "\uc08a\uc06a\uc04a\uc02a\uc00a\ubfea\ubfca\ubfaa\ubf8a\ubf6a\ubf4a" - + "\ubf2a\ubf0a\ubeea\ubeca\ubeaa\ube8a\ube6a\ube4a\ube2a\ube0a\ubdea" - + "\ubdca\ubdaa\ubd8a\ubd6a\ubd4a\ubd2a\ubd0a\ubcea\ubcca\ubcaa\ubc8a" - + "\ubc6a\ubc4a\ubc2a\ubc0a\ubbea\ub2e0\ub568\ub548\ubb6a\ubb4a\ubb2a" - + "\ubb0a\ubaea\ubaca\ubaaa\uba8a\uba6a\uba4a\uba2a\uba0a\ub9ea\ub9ca" - + "\ub9aa\ub98a\ub96a\ub94a\ub92a\ub90a\ub8ea\ub8ca\ub8aa\ub88a\ub86a" - + "\ub84a\ub82a\ub80a\ub7ea\ub7ca\ub7aa\ub78a\ub76a\ub74a\ub72a\ub70a" - + "\ub6ea\ub6ca\ub6aa\ub68a\ub66a\ub64a\ub62a\ub60a\ub5ea\ub5ca\ub5aa" - + "\ub58a\ub56a\ub54a\ub52a\ub50a\ub4ea\ub4ca\ub4aa\ub48a\ub46a\ub44a" - + "\ub42a\ub40a\ub3ea\ub3ca\ub3aa\ub38a\ub36a\ub34a\ub32a\ub30a\ub2ea" - + "\ub2ca\ub2aa\ub28a\ub26a\ub24a\ub22a\ub20a\ub1ea\ub1ca\ub1aa\ub18a" - + "\ub16a\ub14a\ub12a\ub10a\ub0ea\ub0ca\ub0aa\ub08a\ub06a\ub04a\ub02a" - + "\ub00a\uafea\uafca\uafaa\uaf8a\uaf6a\uaf4a\uaf2a\uaf0a\uaeea\uaeca" - + "\uaeaa\uae8a\uae6a\uae4a\uae2a\uae0a\uadea\uadca\uadaa\uad8a\uad6a" - + "\uad4a\uad2a\uad0a\uacea\uacca\uacaa\uac8a\uac6a\uac4a\uac2a\uac0a" - + "\uabea\uabca\uabaa\uab8a\uab6a\uab4a\uab2a\uab0a\uaaea\uaaca\uaaaa" - + "\uaa8a\uaa6a\uaa4a\uaa2a\uaa0a\ua9ea\ua9ca\ua9aa\ua98a\ua96a\ua94a" - + "\ua92a\ua90a\ua8ea\ua8ca\ua8aa\ua88a\ua86a\ua84a\ua82a\ua80a\ua7ea" - + "\ua7ca\ua7aa\ua78a\ua76a\ua74a\ua72a\ua70a\ua6ea\ua6ca\ua6aa\ua68a" - + "\ua66a\ua64a\ua62a\ua60a\ua5ea\ua5ca\ua5aa\ua58a\ua56a\ua54a\ua52a" - + "\ua50a\ua4ea\ua4ca\ua4aa\ua48a\ua46a\ua44a\ua42a\ua40a\ua3ea\ua3ca" - + "\ua3aa\ua38a\ua36a\ua34a\ua32a\ua30a\ua2ea\ua2ca\ua2aa\ua28a\ua26a" - + "\ua24a\ua22a\ua20a\ua1ea\ua1ca\ua1aa\ua18a\ua16a\ua14a\ua12a\ua10a" - + "\ua0ea\ua0ca\ua0aa\ua08a\ua06a\ua04a\ua02a\ua00a\u9fea\u9fca\u9faa" - + "\u9f8a\u9f6a\u9f4a\u9f2a\u9f0a\u9eea\u9eca\u9eaa\u9e8a\u9e6a\u9e4a" - + "\u9e2a\u9e0a\u9dea\u9dca\u9daa\u9d8a\u9d6a\u9d4a\u9d2a\u9d0a\u9cea" - + "\u9cca\u9caa\u9c8a\u9c6a\u9c4a\u9c2a\u9c0a\u9bea\u9bca\u9baa\u9b8a" - + "\u9b6a\u9b4a\u9b2a\u9b0a\u9aea\u9aca\u9aaa\u9a8a\u9a6a\u9a4a\u9a2a" - + "\u9a0a\u99ea\u99ca\u99aa\u998a\u996a\u994a\u992a\u990a\u98ea\u98ca" - + "\u98aa\u988a\u986a\u984a\u982a\u980a\u97ea\u97ca\u97aa\u978a\u976a" - + "\u974a\u972a\u970a\u96ea\u96ca\u96aa\u968a\u966a\u964a\u962a\u960a" - + "\u95ea\u95ca\u95aa\u958a\u956a\u954a\u952a\u950a\u94ea\u94ca\u94aa" - + "\u948a\u946a\u944a\u942a\u940a\u93ea\u93ca\u93aa\u938a\u936a\u934a" - + "\u932a\u930a\u92ea\u92ca\u92aa\u928a\u926a\u924a\u922a\u920a\u91ea" - + "\u91ca\u91aa\u918a\u916a\u914a\u912a\u910a\u90ea\u90ca\u90aa\u908a" - + "\u906a\u904a\u902a\u900a\u8fea\u8fca\u8faa\u8f8a\u8f6a\u8f4a\u8f2a" - + "\u8f0a\u8eea\u8eca\u8eaa\u8e8a\u8e6a\u8e4a\u8e2a\u8e0a\u8dea\u8dca" - + "\u8daa\u8d8a\u8d6a\u8d4a\u8d2a\u8d0a\u8cea\u8cca\u8caa\u8c8a\u8c6a" - + "\u8c4a\u8c2a\u8c0a\u8bea\u8bca\u8baa\u8b8a\u8b6a\u8b4a\u8b2a\u8b0a" - + "\u8aea\u8aca\u8aaa\u8a8a\u8a6a\u8a4a\u8a2a\u8a0a\u89ea\u89ca\u89aa" - + "\u898a\u896a\u894a\u892a\u890a\u88ea\u88ca\u88aa\u888a\u886a\u884a" - + "\u882a\u880a\u87ea\u87ca\u87aa\u878a\u876a\u874a\u872a\u870a\u86ea" - + "\u86ca\u86aa\u868a\u866a\u864a\u862a\u860a\u85ea\u85ca\u85aa\u858a" - + "\u856a\u854a\u852a\u850a\u84ea\u84ca\u84aa\u848a\u846a\u844a\u842a" - + "\u840a\u83ea\u83ca\u83aa\u838a\u836a\u834a\u832a\u830a\u82ea\u82ca" - + "\u82aa\u828a\u826a\u824a\u822a\u820a\u81ea\u81ca\u81aa\u818a\u816a" - + "\u814a\u812a\u810a\u80ea\u80ca\u80aa\u808a\u806a\u804a\u802a\u800a" - + "\u7fea\u7fca\u7faa\u7f8a\u7f6a\u7f4a\u7f2a\u7f0a\u7eea\u7eca\u7eaa" - + "\u7e8a\u7e6a\u7e4a\u7e2a\u7e0a\u7dea\u7dca\u7daa\u7d8a\u7d6a\u7d4a" - + "\u7d2a\u7d0a\u7cea\u7cca\u7caa\u7c8a\u7c6a\u7c4a\u7c2a\u7c0a\u7bea" - + "\u7bca\u7baa\u7b8a\u7b6a\u7b4a\u7b2a\u7b0a\u7aea\u7aca\u7aaa\u7a8a" - + "\u7a6a\u7a4a\u7a2a\u7a0a\u79ea\u79ca\u79aa\u798a\u796a\u794a\u792a" - + "\u790a\u78ea\u78ca\u78aa\u788a\u786a\u784a\u782a\u780a\u77ea\u77ca" - + "\u77aa\u778a\u776a\u774a\u772a\u770a\u76ea\u76ca\u76aa\u768a\u766a" - + "\u764a\u762a\u760a\u75ea\u75ca\u75aa\u758a\u756a\u754a\u752a\u750a" - + "\u74ea\u74ca\u74aa\u748a\u746a\u744a\u742a\u740a\u73ea\u73ca\u73aa" - + "\u738a\u736a\u734a\u732a\u730a\u72ea\u72ca\u72aa\u728a\u726a\u724a" - + "\u722a\u720a\u71ea\u71ca\u71aa\u718a\u716a\u714a\u712a\u710a\u70ea" - + "\u70ca\u70aa\u708a\u706a\u704a\u702a\u700a\u6fea\u6fca\u6faa\u6f8a" - + "\u6f6a\u6f4a\u6f2a\u6f0a\u6eea\u6eca\u6eaa\u6e8a\u6e6a\u6e4a\u6e2a" - + "\u6e0a\u6dea\u6dca\u6daa\u6d8a\u6d6a\u6d4a\u6d2a\u6d0a\u6cea\u6cca" - + "\u6caa\u6c8a\u6c6a\u6c4a\u6c2a\u6c0a\u6bea\u6bca\u6baa\u6b8a\u6b6a" - + "\u6b4a\u6b2a\u6b0a\u6aea\u6aca\u6aaa\u6a8a\u6a6a\u6a4a\u6a2a\u6a0a" - + "\u69ea\u60f0\u6368\u6348\u696a\u694a\u692a\u690a\u68ea\u68ca\u68aa" - + "\u688a\u686a\u684a\u682a\u680a\u67ea\u67ca\u67aa\u678a\u676a\u674a" - + "\u672a\u670a\u66ea\u66ca\u66aa\u668a\u666a\u664a\u662a\u660a\u65ea" - + "\u65ca\u65aa\u658a\u656a\u654a\u652a\u650a\u6b26\u6de1\u6e9c\u5e48" - + "\u5e28\u5e08\u5de8\u5dc8\u5da8\u5d88\u5d68\u5d48\u5d28\u5d08\u5ce8" - + "\u5cc8\u5ca8\u5c88\u5c68\u5c48\u5c28\u5c08\u5be8\u5bc8\u5ba8\u5b88" - + "\u5b68\u5b48\u5b28\u5b08\u5ae8\u5ac8\u5aa8\u5a88\u5a68\u5a48\u5a28" - + "\u5a08\u59e8\u59c8\u59a8\u5988\u5968\u5948\u5928\u5908\u58e8\u58c8" - + "\u58a8\u5888\u5868\u5848\u5828\u5808\u57e8\u57c8\u57a8\u5788\u5768" - + "\u5748\u5d6a\u5d4a\u5d2a\u5d0a\u5cea\u5cca\u5caa\u5c8a\u5c6a\u5c4a" - + "\u5c2a\u5c0a\u5bea\u5bca\u5baa\u5b8a\u5b6a\u5b4a\u5b2a\u5b0a\u5aea" - + "\u5aca\u5aaa\u5a8a\u5a6a\u5a4a\u5a2a\u5a0a\u59ea\u59ca\u59aa\u598a" - + "\u596a\u594a\u592a\u590a\u58ea\u58ca\u58aa\u588a\u586a\u584a\u582a" - + "\u580a\u57ea\u57ca\u57aa\u578a\u576a\u574a\u572a\u570a\u56ea\u56ca" - + "\u56aa\u568a\u566a\u564a\u562a\u560a\u55ea\u55ca\u55aa\u558a\u556a" - + "\u554a\u552a\u550a\u54ea\u54ca\u54aa\u548a\u546a\u544a\u542a\u540a" - + "\u53ea\u53ca\u53aa\u538a\u536a\u534a\u532a\u530a\u52ea\u52ca\u52aa" - + "\u528a\u526a\u524a\u522a\u520a\u51ea\u51ca\u51aa\u518a\u516a\u514a" - + "\u512a\u510a\u50ea\u50ca\u50aa\u508a\u506a\u504a\u502a\u500a\u4fea" - + "\u4fca\u4faa\u4f8a\u4f6a\u4f4a\u4f2a\u4f0a\u4eea\u4eca\u4eaa\u4e8a" - + "\u4e6a\u4e4a\u4e2a\u4e0a\u4dea\u4dca\u4daa\u4d8a\u4d6a\u4d4a\u4d2a" - + "\u4d0a\u4cea\u4cca\u4caa\u4c8a\u4c6a\u4c4a\u4c2a\u4c0a\u4bea\u4bca" - + "\u4baa\u4b8a\u4b6a\u4b4a\u4b2a\u4b0a\u4aea\u4aca\u4aaa\u4a8a\u4a6a" - + "\u4a4a\u4a2a\u4a0a\u49ea\u49ca\u49aa\u498a\u496a\u494a\u492a\u490a" - + "\u48ea\u48ca\u48aa\u488a\u486a\u484a\u482a\u480a\u47ea\u47ca\u47aa" - + "\u478a\u476a\u474a\u472a\u470a\u46ea\u46ca\u46aa\u468a\u466a\u464a" - + "\u462a\u460a\u45ea\u45ca\u45aa\u458a\u456a\u454a\u452a\u450a\u44ea" - + "\u44ca\u44aa\u448a\u446a\u444a\u442a\u440a\u43ea\u43ca\u43aa\u438a" - + "\u436a\u434a\u432a\u430a\u42ea\u42ca\u42aa\u428a\u426a\u424a\u422a" - + "\u420a\u41ea\u41ca\u41aa\u418a\u416a\u414a\u412a\u410a\u40ea\u40ca" - + "\u40aa\u408a\u406a\u404a\u402a\u400a\u3fea\u3fca\u3faa\u3f8a\u3f6a" - + "\u3f4a\u3f2a\u3f0a\u3eea\u3eca\u3eaa\u3e8a\u3e6a\u3e4a\u3e2a\u3e0a" - + "\u3dea\u3dca\u3daa\u3d8a\u3d6a\u3d4a\u3d2a\u3d0a\u3cea\u3cca\u3caa" - + "\u3c8a\u3c6a\u3c4a\u3c2a\u3c0a\u3bea\u3bca\u3baa\u3b8a\u3b6a\u3b4a" - + "\u3b2a\u3b0a\u3aea\u3aca\u3aaa\u3a8a\u3a6a\u3a4a\u3a2a\u3a0a\u39ea" - + "\u39ca\u39aa\u398a\u396a\u394a\u392a\u390a\u38ea\u38ca\u38aa\u388a" - + "\u386a\u384a\u382a\u380a\u37ea\u37ca\u37aa\u378a\u376a\u374a\u372a" - + "\u370a\u36ea\u36ca\u36aa\u368a\u366a\u364a\u362a\u360a\u35ea\u35ca" - + "\u35aa\u358a\u356a\u354a\u352a\u350a\u34ea\u34ca\u34aa\u348a\u346a" - + "\u344a\u342a\u340a\u33ea\u33ca\u33aa\u338a\u336a\u334a\u332a\u330a" - + "\u32ea\u32ca\u32aa\u328a\u326a\u324a\u322a\u320a\u31ea\u28f2\u2b68" - + "\u2b48\u3c2b\u3c0b\u3beb\u3bcb\u3bab\u3b8b\u3b6b\u3b4b\u3b2b\u3b0b" - + "\u3aeb\u3acb\u3aab\u3a8b\u3a6b\u3a4b\u3a2b\u3a0b\u39eb\u39cb\u39ab" - + "\u398b\u396b\u394b\u392b\u390b\u38eb\u38cb\u38ab\u388b\u386b\u384b" - + "\u382b\u380b\u37eb\u37cb\u37ab\u378b\u376b\u374b\u372b\u370b\u36eb" - + "\u36cb\u36ab\u368b\u366b\u364b\u362b\u360b\u35eb\u35cb\u35ab\u358b" - + "\u356b\u354b\u352b\u350b\u34eb\u34cb\u34ab\u348b\u346b\u344b\u344b" - + "\u342b\u340b\u33eb\u33cb\u33ab\u338b\u336b\u334b\u332b\u330b\u32eb" - + "\u32cb\u32ab\u328b\u326b\u324b\u322b\u320b\u31eb\u31cb\u31ab\u318b" - + "\u316b\u314b\u312b\u310b\u30eb\u30cb\u30ab\u308b\u306b\u304b\u302b" - + "\u300b\u2feb\u2fcb\u2fab\u2f8b\u2f6b\u2f4b\u2f2b\u2f0b\u2eeb\u2ecb" - + "\u2eab\u2e8b\u2e6b\u2e4b\u2e2b\u2e0b\u2deb\u2dcb\u2dab\u2d8b\u2d6b" - + "\u2d4b\u2d2b\u2d0b\u2ceb\u2ccb\u2cab\u2c8b\u2c6b\u2c4b\u2c2b\u2c0b" - + "\u2beb\u2bcb\u2bab\u2b8b\u2b6b\u2b4b\u2b2b\u2b0b\u2aeb\u2acb\u2aab" - + "\u2a8b\u2a6b\u2a4b\u2a2b\u2a0b\u29eb\u29cb\u29ab\u298b\u296b\u294b" - + "\u292b\u290b\u28eb\u28cb\u28ab\u288b\u286b\u284b\u282b\u280b\u27eb" - + "\u27cb\u27ab\u278b\u276b\u274b\u272b\u270b\u26eb\u26cb\u26ab\u268b" - + "\u266b\u264b\u262b\u260b\u25eb\u25cb\u25ab\u258b\u256b\u254b\u252b" - + "\u250b\u24eb\u24cb\u24ab\u248b\u246b\u244b\u242b\u240b\u23eb\u23cb" - + "\u23ab\u238b\u236b\u234b\u232b\u230b\u22eb\u22cb\u22ab\u228b\u226b" - + "\u224b\u222b\u220b\u21eb\u21cb\u21ab\u218b\u216b\u214b\u212b\u210b" - + "\u20eb\u20cb\u20ab\u208b\u206b\u204b\u202b\u200b\u1feb\u1fcb\u1fab" - + "\u1f8b\u1f6b\u1f4b\u1f2b\u1f0b\u1eeb\u1ecb\u1eab\u1e8b\u1e6b\u1e4b" - + "\u1e2b\u1e0b\u1deb\u1dcb\u1dab\u1d8b\u1d6b\u1d4b\u1d2b\u1d0b\u1ceb" - + "\u1ccb\u1cab\u1c8b\u1c6b\u1c4b\u1c2b\u1c0b\u1beb\u1bcb\u1bab\u1b8b" - + "\u1b6b\u106a\u104a\u102a\u100a\u0fea\u0fca\u0faa\u0f8a\u0f6a\u0668" - + "\u08e8\u08c8\u08a8\u0888\u0868\u0848\u07d7\u194b\u07b6\u0d1c\u0cfc" - + "\u0cb2\u0ca9\u0c9c\u0c7c\u0c5c\u0c3c\u0c1c\u0bfc\u0bdc\u0bbc\u0b9c" - + "\u0b7c\u0b5e\u0b2c\u0b1c\u0ab8\u0adc\u0a9c\u02c2\u0528\u166b\u1667" - + "\u03ff\u09fc\u09dc\u09bc\u0659\u0bb8\u15a7\u0fc6\u01c0\u01b1\u09cb" - + "\u082c\u1285"; - - /** - * Information about each character. The low order 5 bits form the - * character type, the next bit is a flag for non-breaking spaces, and the - * next bit is a flag for mirrored directionality. The high order 9 bits - * form the offset into the attribute tables. Note that this limits the - * number of unique character attributes to 512, which is not a problem - * as of Unicode version 3.2.0, but may soon become one. - */ - String DATA - = "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3e80\u3e80\u3001\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85" - + "\u3a85\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85" - + "\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80" - + "\u3e80\u3e80\u3e80\u5198\u3e80\u3e80\u3e80\u3e80\u4606\u3e80\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3a85" - + "\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u3e80\u3e80\u3e80\u3e80\u5202\u5202\u5202\u5202" - + "\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202" - + "\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202\u5202" - + "\u5202\u5202\u5202\u5202\u5202\u2e82\u3e80\u5198\u2a14\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4686\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u1a1b\u1a1b\u3e80\u3e80\u3e80\u3e80\u4584\u3e80\u3e80" - + "\u3e80\u0298\u3e80\u0298\u6615\u6696\u0298\u1a97\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u4584\u1a1b\u1a1b\u1a1b\u1a1b" - + "\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u4584" - + "\u4584\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b" - + "\u1a1b\u1a1b\u1a1b\u1a1b\u2e82\u7282\u2e82\u3e80\u2e82\u4902\u7481" - + "\u7481\u7481\u7481\u7383\u1a1b\u1a1b\u1a1b\u6d82\u6d82\u4902\u4902" - + "\u3e80\u3e80\u2e82\u4902\u6e01\u6e01\u7501\u7501\u3e80\u1a1b\u1a1b" - + "\u1a1b\u1b02\u1b82\u1c02\u1c82\u1d02\u1d82\u1e02\u1e82\u1f02\u1f82" - + "\u2002\u2082\u2102\u2182\u2202\u2282\u2302\u2382\u2402\u2482\u2502" - + "\u2582\u2602\u2682\u2702\u2782\u0455\u0c99\u04d6\u0c99\017\017" - + "\017\017\017\u010f\017\017\017\017\017\017\017" - + "\017\017\017\017\017\017\017\017\017\017\017" - + "\017\017\017\017\017\017\017\017\u008f\u010f\u008f" - + "\u018f\u010f\017\017\017\017\017\017\017\017\017" - + "\017\017\017\017\017\u010f\u010f\u010f\u008f\u020c\u0298" - + "\u0298\u0318\u039a\u0318\u0298\u0298\u0455\u04d6\u0298\u0519\u0598" - + "\u0614\u0598\u0698\u0709\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89" - + "\u0b09\u0b89\u0598\u0298\u0c59\u0c99\u0c59\u0298\u0d01\u0d81\u0e01" - + "\u0e81\u0f01\u0f81\u1001\u1081\u1101\u1181\u1201\u1281\u1301\u1381" - + "\u1401\u1481\u1501\u1581\u1601\u1681\u1701\u1781\u1801\u1881\u1901" - + "\u1981\u0455\u0298\u04d6\u1a1b\u1a97\u0298\u0298\u0298\u0c99\u0455" - + "\u04d6\u3e80\u0298\u0298\u0298\u0298\u0298\u0298\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u282c\u0298\u039a\u039a\u039a\u039a\u289c" - + "\u289c\u1a1b\u289c\u2902\u29dd\u0c99\u2a14\u289c\u1a1b\u2a9c\u0519" - + "\u2b0b\u2b8b\u1a1b\u2c02\u289c\u0298\u1a1b\u2c8b\u2902\u2d5e\u2d8b" - + "\u2d8b\u2d8b\u0298\u0298\u0519\u0614\u0c99\u0c99\u0c99\u3e80\u0298" - + "\u039a\u0318\u0298\u3e80\u3e80\u3e80\u3e80\u5405\u5405\u5405\u3e80" - + "\u5405\u3e80\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u501c\u501c\u4f81\u4f81" - + "\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81\u4f81" - + "\u4f81\u4f81\u4f81\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01" - + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01" - + "\u2e01\u2e01\u2e01\u2e01\u0c99\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01" - + "\u2e01\u2e82\u2e82\u2e82\u4902\u4902\u2e82\u2e82\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u2e82\u2e82" - + "\u2e82\u2e82\u2e82\u3e80\u3e80\u3e80\u3e80\u3e80\u5305\u4606\u5305" - + "\u5305\u3e80\u5305\u5305\u3e80\u5305\u5305\u5305\u5305\u5305\u5305" - + "\u5305\u5305\u5305\u5305\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5398\u5405\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u5087\u5087\u4606\u5087\u5087\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b" - + "\u2d8b\u2d8b\u2d8b\u2d8b\u2d8b\u840b\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u2e82\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5c09" - + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u4606\u4606" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u1a1b\u1a1b\u4701\u0298\u4781\u4781\u4781\u3e80" - + "\u4801\u3e80\u4881\u4881\u4902\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01" - + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2f02" - + "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02" - + "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02" - + "\u0c99\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f82\u2f02\u2f02" - + "\u4a82\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u4b02" - + "\u4b82\u4b82\u3e80\u4c02\u4c82\u4d01\u4d01\u4d01\u4d82\u4e02\u2902" - + "\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u2e82\u3b81\u3c03\u3c82" - + "\u3001\u3082\u3d81\u3e01\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3101\u3182" - + "\u3001\u3082\u3001\u3082\u3001\u3082\u2902\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u4e82\u4f02\u3d02\u2902\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5b10\u5b10\u5b10\u5b10\u5b10" - + "\u5b10\u7f0b\u3e80\u3e80\u3e80\u7f8b\u800b\u808b\u810b\u818b\u820b" - + "\u0519\u0519\u0c99\u0455\u04d6\u2902\u3301\u3001\u3082\u3001\u3082" - + "\u3381\u3001\u3082\u3401\u3401\u3001\u3082\u2902\u3481\u3501\u3581" - + "\u3001\u3082\u3401\u3601\u3682\u3701\u3781\u3001\u3082\u2902\u2902" - + "\u3701\u3801\u2902\u3881\u3a85\u3a85\u3a85\u3a85\u3b81\u3c03\u3c82" - + "\u3b81\u3c03\u3c82\u3b81\u3c03\u3c82\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3d02\u3001\u3082\u501c\u4606\u4606\u4606\u4606\u3e80\u5087\u5087" - + "\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3201\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3282\u3001\u3082\u3001\u3082\u3001\u3082\u3901\u3001\u3082\u3901" - + "\u2902\u2902\u3001\u3082\u3901\u3001\u3082\u3981\u3981\u3001\u3082" - + "\u3001\u3082\u3a01\u3001\u3082\u2902\u3a85\u3001\u3082\u2902\u3b02" - + "\u4d01\u3001\u3082\u3001\u3082\u3e80\u3e80\u3001\u3082\u3e80\u3e80" - + "\u3001\u3082\u3e80\u3e80\u3e80\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001" - + "\u3082\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u0598\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5398\u3e80\u3e80\u3e80\u5398" - + "\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398\u5398" - + "\u5398\u5398\u3e80\u5b10\u5405\u4606\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u3e80\u3e80\u5b10\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01" - + "\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01" - + "\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01\u4d01" - + "\u4d01\u4d01\u4d01\u4d01\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89" - + "\u5f09\u5f89\u6009\u6089\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u2902\u2902\u2902\u3f02\u3f82\u2902\u4002" - + "\u4002\u2902\u4082\u2902\u4102\u2902\u2902\u2902\u2902\u4002\u2902" - + "\u2902\u4182\u2902\u2902\u2902\u2902\u4202\u4282\u2902\u2902\u2902" - + "\u2902\u2902\u4282\u2902\u2902\u4302\u2902\u2902\u4382\u2902\u2902" - + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u4402\u2902\u2902" - + "\u4402\u2902\u2902\u2902\u2902\u4402\u2902\u4482\u4482\u2902\u2902" - + "\u2902\u2902\u2902\u2902\u4502\u2902\u2902\u2902\u2902\u2902\u2902" - + "\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u2902\u3e80\u3e80\u4584" - + "\u4584\u4584\u4584\u4584\u4584\u4584\u4584\u4584\u1a1b\u1a1b\u4584" - + "\u4584\u4584\u4584\u4584\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b\u1a1b" - + "\u1a1b\u1a1b\u4584\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5101\u5101" - + "\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101" - + "\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u5101\u3e80" - + "\u3e80\u4584\u5198\u5198\u5198\u5198\u5198\u5198\u2e01\u2e01\u3e80" - + "\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u2e01\u4982\u4a02" - + "\u4a02\u4a02\u4902\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02" - + "\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u2f02\u4f02\u4f02\u4f02" - + "\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02\u4f02" - + "\u4f02\u4f02\u4606\u4606\u4606\u4606\u4606\u5198\u4606\u4606\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u4606\u5298" - + "\u4606\u4606\u5298\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u5305\u5305\u5305\u5305\u5305\u5305\u5305" - + "\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u5305\u5305\u5305\u5298\u5298\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5c89\u5d09\u5d89" - + "\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u640b\u648b\u650b\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u4606\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80" - + "\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80" - + "\u3e80\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u5b88\u5b88\u5b88\u5b88\u3e80\u4606\u4606\u4606\u3e80\u4606" - + "\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606" - + "\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606" - + "\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3e80\u3e80\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85" - + "\u3e80\u3e80\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09" - + "\u5f89\u6009\u6089\u501c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5509\u5589\u5609" - + "\u5689\u5709\u5789\u5809\u5889\u5909\u5989\u0318\u5a18\u5a18\u5398" - + "\u3e80\u3e80\u4606\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u3e80\u3e80\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u6615\u6696\u5484\u5405\u5405\u5405\u5405" - + "\u5405\u5405\u5405\u5405\u5405\u5405\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u5b88\u5b88\u5198\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u5b88" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80" - + "\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u5198\u5198\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u5484\u5484\u4606" - + "\u4606\u289c\u4606\u4606\u4606\u4606\u3e80\u3e80\u0709\u0789\u0809" - + "\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u5405\u5405\u5405\u5a9c" - + "\u5a9c\u3e80\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85\u3e80\u3e80" - + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u4606\u3a85\u3a85\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u3a85\u3e80\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u5b88" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3e80\u3e80\u4606\u3a85\u5b88\u5b88\u5b88\u5b88\u5b88\u3e80\u4606" - + "\u5b88\u5b88\u3e80\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3a85\u3e80\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u5198" - + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u640b\u670b" - + "\u678b\u680b\u688b\u690b\u698b\u6a0b\u6a8b\u648b\u6b0b\u3e80\u3e80" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3a85\u5b88\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u5b88\u5b88\u5b88\u5b88" - + "\u4606\u3e80\u3e80\u3a85\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80\u3e80" - + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3e80\u5b88\u5b88\u5b88" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4606\u3a85\u3a85\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u039a\u039a\u039a" - + "\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a\u039a" - + "\u039a\u039a\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u4606\u4606" - + "\u5198\u5198\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009" - + "\u6089\u5198\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0298\u0298\u0318\u039a\u0318" - + "\u0298\u0298\u6615\u6696\u0298\u0519\u0598\u0614\u0598\u0698\u0709" - + "\u0789\u0809\u0889\u0909\u0989\u0a09\u0a89\u0b09\u0b89\u0598\u0298" - + "\u0c99\u0c99\u0c99\u0298\u0298\u0298\u0298\u0298\u0298\u2a14\u0298" - + "\u0298\u0298\u0298\u5b10\u5b10\u5b10\u5b10\u3e80\u5c09\u5c89\u5d09" - + "\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u5b88" - + "\u4606\u4606\u4606\u4606\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u5b88" - + "\u5b88\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u5b88\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80" - + "\u3a85\u3a85\u3e80\u3a85\u3e80\u3e80\u3a85\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85" - + "\u3e80\u3e80\u4606\u3e80\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80" - + "\u3e80\u4606\u4606\u3e80\u3e80\u4606\u4606\u4606\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85" - + "\u3a85\u3e80\u3a85\u3e80\u3a85\u3a85\u4606\u4606\u3e80\u3e80\u5c09" - + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3a85\u3a85" - + "\u039a\u039a\u610b\u618b\u620b\u628b\u630b\u638b\u501c\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3a85" - + "\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u4606\u3a85" - + "\u5b88\u5b88\u4606\u4606\u4606\u4606\u4606\u3e80\u4606\u4606\u5b88" - + "\u3e80\u5b88\u5b88\u4606\u3e80\u3e80\u3a85\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u630b" - + "\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u501c\u4606" - + "\u501c\u4606\u501c\u4606\u6615\u6696\u6615\u6696\u5b88\u5b88\u4606" - + "\u4606\u4606\u3e80\u3e80\u3e80\u5b88\u5b88\u3e80\u3e80\u5b88\u5b88" - + "\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u4606\u5b88" - + "\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3e80\u3a85\u3a85\u3e80\u5b88\u4606\u4606\u4606\u4606\u5b88" - + "\u4606\u3e80\u3e80\u3e80\u4606\u4606\u5b88\u4606\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u5b88\u5b88\u5b88\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u5b88\u5b88\u3e80\u3e80\u3e80\u5b88\u5b88\u5b88\u3e80\u5b88\u5b88" - + "\u5b88\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u5b88\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u4584\u3e80\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u3e80\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89" - + "\u6009\u6089\u3e80\u3e80\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u5c09" - + "\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u5087\u5087\u5087\u5b88\u4606\u4606" - + "\u4606\u3e80\u3e80\u5b88\u5b88\u5b88\u3e80\u5b88\u5b88\u5b88\u4606" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u5b88\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u4606\u3e80\u3e80\u3e80\u3e80" - + "\u5b88\u5b88\u5b88\u4606\u4606\u4606\u3e80\u4606\u3e80\u5b88\u5b88" - + "\u5b88\u5b88\u5b88\u5b88\u5b88\u5b88\u4606\u5b88\u5b88\u4606\u4606" - + "\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u4606\u5198\u5198" - + "\u5198\u5198\u5198\u5198\u5198\u039a\u5198\u3e80\u3e80\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u4584\u4606\u4606\u4606\u4606\u4606" - + "\u4606\u4606\u4606\u5198\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09" - + "\u5f89\u6009\u6089\u5198\u5198\u3e80\u3e80\u3e80\u3e80\u3a85\u501c" - + "\u501c\u501c\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u5198\u65b8" - + "\u5198\u5198\u5198\u5198\u5198\u5198\u501c\u501c\u501c\u501c\u501c" - + "\u4606\u4606\u501c\u501c\u501c\u501c\u501c\u501c\u4606\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u3e80\u3e80\u501c\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u1a97\u4584\u4584\u4584" - + "\u3e80\u5c09\u5c89\u5d09\u5d89\u5e09\u5e89\u5f09\u5f89\u6009\u6089" - + "\u5198\u5198\u5198\u5198\u5198\u5198\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u5b88\u5b88\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u020c\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u6615\u6696\u3e80\u3e80\u3e80\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u5198" - + "\u5198\u5198\u6b8b\u6c0b\u6c8b\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u4606\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3001\u3082\u3001" - + "\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082" - + "\u3001\u3082\u3001\u3082\u3001\u3082\u3001\u3082\u2e82\u2e82\u2e82" - + "\u2e82\u2e82\u6d02\u3e80\u3e80\u3e80\u3e80\u6d82\u6d82\u6d82\u6d82" - + "\u6d82\u6d82\u6d82\u6d82\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01" - + "\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82\u6e01\u6e01" - + "\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82" - + "\u6d82\u3e80\u3e80\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u3e80\u3e80" - + "\u2e82\u6d82\u4902\u6d82\u4902\u6d82\u4902\u6d82\u3e80\u6e01\u3e80" - + "\u6e01\u3e80\u6e01\u3e80\u6e01\u6d82\u6d82\u6d82\u6d82\u6d82\u6d82" - + "\u6d82\u6d82\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e01\u6e82" - + "\u6e82\u6f02\u6f02\u6f02\u6f02\u6f82\u6f82\u7002\u7002\u7082\u7082" - + "\u7102\u7102\u3e80\u3e80\u7182\u7182\u7182\u7182\u7182\u7182\u7182" - + "\u7182\u7203\u7203\u7203\u7203\u7203\u7203\u7203\u7203\u7182\u7182" - + "\u7182\u7182\u7182\u7182\u7182\u7182\u7203\u7203\u7203\u7203\u7203" - + "\u7203\u7203\u7203\u6d82\u6d82\u2e82\u7282\u2e82\u3e80\u2e82\u4902" - + "\u6e01\u6e01\u7301\u7301\u7383\u1a1b\u7402\u1a1b\u1b02\u1b82\u1c02" - + "\u1c82\u1d02\u1d82\u1e02\u1e82\u1f02\u1f82\u2002\u2082\u2102\u2182" - + "\u2202\u2282\u2302\u2382\u2402\u2482\u2502\u2582\u2602\u2682\u2702" - + "\u2782\u6615\u0c99\u6696\u0c99\u3e80\u6d82\u6d82\u4902\u4902\u2e82" - + "\u7582\u2e82\u4902\u6e01\u6e01\u7601\u7601\u7681\u1a1b\u1a1b\u1a1b" - + "\u3e80\u3e80\u2e82\u7282\u2e82\u3e80\u2e82\u4902\u7701\u7701\u7781" - + "\u7781\u7383\u1a1b\u1a1b\u3e80\u020c\u020c\u020c\u020c\u020c\u020c" - + "\u020c\u782c\u020c\u020c\u020c\u788c\u5b10\u5b10\u7910\u7990\u2a14" - + "\u7a34\u2a14\u2a14\u2a14\u2a14\u0298\u0298\u7a9d\u7b1e\u6615\u7a9d" - + "\u7a9d\u7b1e\u6615\u7a9d\u0298\u0298\u0298\u0298\u0298\u0298\u0298" - + "\u0298\u7b8d\u7c0e\u7c90\u7d10\u7d90\u7e10\u7e90\u782c\u0318\u0318" - + "\u0318\u0318\u0318\u0298\u0298\u0298\u0298\u29dd\u2d5e\u0298\u0298" - + "\u0298\u0298\u1a97\u7f0b\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b\u810b" - + "\u818b\u820b\u0519\u0519\u0c99\u0455\u04d6\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u4d01\u289c\u289c\u289c\u289c" - + "\u4d01\u289c\u289c\u2902\u4d01\u4d01\u4d01\u2902\u2902\u4d01\u4d01" - + "\u4d01\u2902\u289c\u4d01\u289c\u289c\u289c\u4d01\u4d01\u4d01\u4d01" - + "\u4d01\u289c\u289c\ua20a\ua28a\ua30a\ua38a\ua40a\ua48a\ua50a\ua58a" - + "\ua60a\u4606\u4606\u4606\u4606\u4606\u4606\u2a14\u4584\u4584\u4584" - + "\u4584\u4584\u289c\u289c\ua68a\ua70a\ua78a\u3e80\u3e80\u3e80\u289c" - + "\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u3e80\u3e80\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u0c99\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u0c99\u0c99\u289c\u289c\u0c99\u289c\u0c99" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u0c99\u289c\u289c\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u948a" - + "\u950a\u958a\u960a\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u0c99\u0c99\u0c99\u0c99\u0c99\u289c\u289c" - + "\u289c\u289c\u289c\u0c99\u0c99\u289c\u289c\u289c\u289c\u4d01\u289c" - + "\u8281\u289c\u4d01\u289c\u8301\u8381\u4d01\u4d01\u2a9c\u2902\u4d01" - + "\u4d01\u289c\u4d01\u2902\u3a85\u3a85\u3a85\u3a85\u2902\u289c\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u848a\u850a\u858a\u860a\u868a\u870a\u878a" - + "\u880a\u888a\u890a\u898a\u8a0a\u8a8a\u8b0a\u8b8a\u8c0a\u8c8a\u8d0a" - + "\u8d8a\u8e0a\u8e8a\u8f0a\u8f8a\u900a\u908a\u910a\u918a\u920a\u928a" - + "\u930a\u938a\u940a\u0c99\u0c99\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99" - + "\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99\u0c99" - + "\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59" - + "\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u0c59" - + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c99\u0c99\u0c99" - + "\u0c99\u0c99\u0c99\u289c\u289c\u0c99\u289c\u289c\u0c99\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u0c99\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c59\u0519\u0519\u0c99\u0c59" - + "\u0c59\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c99\u0c59\u0c99" - + "\u0c59\u0c99\u0c99\u0c99\u0c99\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c99\u0c99\u0c99\u0c99\u0c99\u0c59\u0c99\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u0455\u04d6\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u3e80\u3e80\u3e80\u3e80\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u9c1c\u9c1c\u9c1c\u9c1c" - + "\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c\u9c1c" - + "\u9c1c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c" - + "\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u9c9c\u7f0b\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0c59\u0c99\u0c59\u0c99\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59\u0c59" - + "\u0c59\u0c59\u0c59\u0c59\u0c59\u0c99\u0c99\u0c59\u0c59\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u039a\u039a\u0c99\u1a1b\u289c\u039a\u039a\u3e80\u289c\u0c99" - + "\u0c99\u0c99\u0c99\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u5b10\u5b10\u5b10\u289c\u289c\u3e80\u3e80" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u3e80\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u289c" - + "\u3e80\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u289c\u3e80\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u840b\u9d0b" - + "\u9d8b\u9e0b\u9e8b\u9f0b\u9f8b\ua00b\ua08b\ua10b\u840b\u9d0b\u9d8b" - + "\u9e0b\u9e8b\u9f0b\u9f8b\ua00b\ua08b\ua10b\u289c\u3e80\u3e80\u3e80" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u0c59\u0c59\u0c59" - + "\u0c59\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c\u289c" - + "\u501c\u289c\u289c\u289c\u289c\u289c\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u630b\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u3e80\u3e80" - + "\u3e80\u501c\u610b\u618b\u620b\u628b\ua80b\ua88b\ua90b\ua98b\uaa0b" - + "\u640b\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u289c\u3e80\u289c\u289c\u289c" - + "\u3e80\u289c\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b" - + "\u810b\u818b\u820b\u968b\u970b\u978b\u980b\u988b\u990b\u998b\u9a0b" - + "\u9a8b\u9b0b\u9b8b\u2c8b\u2b0b\u2b8b\u7f8b\u800b\u808b\u810b\u818b" - + "\u820b\u968b\u970b\u978b\u980b\u988b\u990b\u998b\u9a0b\u9a8b\u9b0b" - + "\u9b8b\u501c\u501c\u501c\u501c\u020c\u0298\u0298\u0298\u289c\u4584" - + "\u3a85\ua18a\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455" - + "\u04d6\u289c\u289c\u0455\u04d6\u0455\u04d6\u0455\u04d6\u0455\u04d6" - + "\u2a14\u6615\u6696\u6696\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3e80\u3e80\u3e80\u3e80\u4606\u4606\u1a1b\u1a1b" - + "\u4584\u4584\u3e80\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85" - + "\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3a85\u3e80\u501c\u501c\u630b" - + "\u630b\u630b\u630b\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c" - + "\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u501c\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93" - + "\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93" - + "\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93\uaa93" - + "\uaa93\uaa93\uaa93\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12" - + "\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12" - + "\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12\uab12" - + "\uab12\uab12\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305" - + "\u0519\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305\u5305" - + "\u5305\u5305\u5305\u3e80\u5305\u5305\u5305\u5305\u5305\u3e80\u5305" - + "\u3e80\u4606\u4606\u4606\u4606\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80" - + "\u3e80\u3e80\u3e80\u3e80\u3e80\u3e80\u0298\u2a14\u2a14\u1a97\u1a97" - + "\u6615\u6696\u6615\u6696\u6615\u6696\u6615\u6696\u6615\u6696\u6615" - + "\u6696\u3e80\u3e80\u3e80\u3e80\u0298\u0298\u0298\u0298\u1a97\u1a97" - + "\u1a97\u0598\u0298\u0598\u3e80\u0298\u0598\u0298\u0298\u2a14\u6615" - + "\u6696\u6615\u6696\u6615\u6696\u0318\u0298\u0d01\u0d81\u0e01\u0e81" - + "\u0f01\u0f81\u1001\u1081\u1101\u1181\u1201\u1281\u1301\u1381\u1401" - + "\u1481\u1501\u1581\u1601\u1681\u1701\u1781\u1801\u1881\u1901\u1981" - + "\u6615\u0298\u6696\u1a1b\u1a97"; - - /** - * This is the attribute table for computing the numeric value of a - * character. The value is -1 if Unicode does not define a value, -2 - * if the value is not a positive integer, otherwise it is the value. - * Note that this is a signed value, but stored as an unsigned char - * since this is a String literal. - */ - String NUM_VALUE - = "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\000\001\002\003\004\005\006\007" - + "\010\011\uffff\uffff\012\013\014\015\016\017\020" - + "\021\022\023\024\025\026\027\030\031\032\033" - + "\034\035\036\037 !\"#\uffff\uffff\012" - + "\013\014\015\016\017\020\021\022\023\024\025" - + "\026\027\030\031\032\033\034\035\036\037 " - + "!\"#\uffff\uffff\uffff\uffff\uffff\uffff\002\003" - + "\uffff\001\uffff\ufffe\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\000\001\002\003\004\005" - + "\006\007\010\011\uffff\uffff\uffff\uffff\000\001\002" - + "\003\004\005\006\007\010\011\001\002\003\004" - + "\uffff\020\012d\u03e8\uffff\uffff\uffff\024\036(" - + "2<FPZ\u2710\021\022\023\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff" - + "\uffff\000\004\005\006\007\010\011\uffff\uffff\uffff" - + "\001\001\002\003\004\005\006\007\010\011\012" - + "\013\0142d\u01f4\u03e8\001\002\003\004\005" - + "\006\007\010\011\012\013\0142d\u01f4\u03e8" - + "\u03e8\u1388\u2710\uffff\012\013\014\015\016\017\020" - + "\021\022\023\024\uffff\uffff\002\003\004\005\006" - + "\007\010\011\012\000\001\002\003\004\005\006" - + "\007\010\011\012\024\036\005\006\007\010\011" - + "\uffff\uffff"; - - /** - * This is the attribute table for computing the single-character uppercase - * representation of a character. The value is the signed difference - * between the character and its uppercase version. Note that this is - * stored as an unsigned char since this is a String literal. When - * capitalizing a String, you must first check if a multi-character uppercase - * sequence exists before using this character. - */ - String UPPER - = "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\uffe0" - + "\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0" - + "\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0\uffe0" - + "\uffe0\uffe0\uffe0\000\000\000\000\000\000\000\000" - + "\u02e7\000\000\000\000\000\uffe0y\000\uffff\000" - + "\uff18\000\ufed4\000\000\000\000\000\000\000a" - + "\000\000\000\000\000\000\000\0008\000\uffff" - + "\ufffe\uffb1\000\000\000\uff2e\uff32\uff33\uff36\uff35\uff31" - + "\uff2f\uff2d\uff2b\uff2a\uff26\uff27\uff25\000\000T\000" - + "\000\000\000\000\uffda\uffdb\uffe1\uffc0\uffc1\uffc2\uffc7" - + "\000\uffd1\uffca\uffaa\uffb0\000\000\000\000\000\uffd0" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\uffc5\010" - + "\000JVd\u0080p~\010\000\011\000" - + "\000\ue3db\000\000\007\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\ufff0\ufff0\ufff0\ufff0\ufff0" - + "\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0\ufff0" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\uffe6\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000"; - - /** - * This is the attribute table for computing the lowercase representation - * of a character. The value is the signed difference between the - * character and its lowercase version. Note that this is stored as an - * unsigned char since this is a String literal. - */ - String LOWER - = "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + " " - + " " - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000 \000\000\000\001\000\uff39\000\uff87\000\u00d2\u00ce" - + "\u00cdO\u00ca\u00cb\u00cf\000\u00d3\u00d1\u00d5\u00d6\u00da\u00d9\u00db" - + "\000\000\002\001\000\000\uff9f\uffc8\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000&" - + "%@?\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000P\000\0000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\ufff8" - + "\000\000\000\000\000\000\000\ufff8\000\uffb6\ufff7\000\uffaa" - + "\uff9c\000\uff90\ufff9\uff80\uff82\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\ue2a3\udf41\udfba\000\020\020\020\020\020\020\020\020" - + "\020\020\020\020\020\020\020\020\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\032\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000"; - - /** - * This is the attribute table for computing the directionality class - * of a character, as well as a marker of characters with a multi-character - * capitalization. The direction is taken by performing a signed shift - * right by 2 (where a result of -1 means an unknown direction, such as - * for undefined characters). The lower 2 bits form a count of the - * additional characters that will be added to a String when performing - * multi-character uppercase expansion. This count is also used, along with - * the offset in UPPER_SPECIAL, to determine how much of UPPER_EXPAND to use - * when performing the case conversion. Note that this information is stored - * as an unsigned char since this is a String literal. - */ - String DIRECTION - = "$,(004\024\02444\024\034\024\020\014\014\014" - + "\014\014\014\014\014\014\01444\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\00044\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\0344\00044" - + "\024\014\014\000\01444\000\001\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\ufffc\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000 \000\000\000\000\002\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000 \000\000\000\004\004\010\010\010" - + "\030\030\030\030\030\030\030\030\030\030\030\010$\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "44\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\001\001\001\000\001\000\000\000\000\000\000" - + "\000\0000$\000\0044440(8@H<D\014" - + "\014\014\014\014\014\014\000\000\0004\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000\000\000\000\000\000\000\000\000\000\014\014\014\014\014" - + "\014\014\014\014\014\014\000\000444444444" - + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" - + "\000\000\000"; - - /** - * This is the listing of titlecase special cases (all other characters - * can use <code>UPPER</code> to determine their titlecase). The listing - * is a sorted sequence of character pairs; converting the first character - * of the pair to titlecase produces the second character. - */ - String TITLE - = "\u01c4\u01c5\u01c5\u01c5\u01c6\u01c5\u01c7\u01c8\u01c8\u01c8\u01c9" - + "\u01c8\u01ca\u01cb\u01cb\u01cb\u01cc\u01cb\u01f1\u01f2\u01f2\u01f2" - + "\u01f3\u01f2"; - - /** - * This is a listing of characters with multi-character uppercase sequences. - * A character appears in this list exactly when it has a non-zero entry - * in the low-order 2-bit field of DIRECTION. The listing is a sorted - * sequence of pairs (hence a binary search on the even elements is an - * efficient way to lookup a character). The first element of a pair is the - * character with the expansion, and the second is the index into - * UPPER_EXPAND where the expansion begins. Use the 2-bit field of - * DIRECTION to determine where the expansion ends. - */ - String UPPER_SPECIAL - = "\u00df\000\u0149\002\u01f0\004\u0390\006\u03b0\011" - + "\u0587\014\u1e96\016\u1e97\020\u1e98\022\u1e99\024" - + "\u1e9a\026\u1f50\030\u1f52\032\u1f54\035\u1f56 " - + "\u1f80#\u1f81%\u1f82'\u1f83)\u1f84+" - + "\u1f85-\u1f86/\u1f871\u1f883\u1f895" - + "\u1f8a7\u1f8b9\u1f8c;\u1f8d=\u1f8e?" - + "\u1f8fA\u1f90C\u1f91E\u1f92G\u1f93I" - + "\u1f94K\u1f95M\u1f96O\u1f97Q\u1f98S" - + "\u1f99U\u1f9aW\u1f9bY\u1f9c[\u1f9d]" - + "\u1f9e_\u1f9fa\u1fa0c\u1fa1e\u1fa2g" - + "\u1fa3i\u1fa4k\u1fa5m\u1fa6o\u1fa7q" - + "\u1fa8s\u1fa9u\u1faaw\u1faby\u1fac{" - + "\u1fad}\u1fae\u007f\u1faf\u0081\u1fb2\u0083\u1fb3\u0085" - + "\u1fb4\u0087\u1fb6\u0089\u1fb7\u008b\u1fbc\u008e\u1fc2\u0090" - + "\u1fc3\u0092\u1fc4\u0094\u1fc6\u0096\u1fc7\u0098\u1fcc\u009b" - + "\u1fd2\u009d\u1fd3\u00a0\u1fd6\u00a3\u1fd7\u00a5\u1fe2\u00a8" - + "\u1fe3\u00ab\u1fe4\u00ae\u1fe6\u00b0\u1fe7\u00b2\u1ff2\u00b5" - + "\u1ff3\u00b7\u1ff4\u00b9\u1ff6\u00bb\u1ff7\u00bd\u1ffc\u00c0" - + "\ufb00\u00c2\ufb01\u00c4\ufb02\u00c6\ufb03\u00c8\ufb04\u00cb" - + "\ufb05\u00ce\ufb06\u00d0\ufb13\u00d2\ufb14\u00d4\ufb15\u00d6" - + "\ufb16\u00d8\ufb17\u00da"; - - /** - * This is the listing of special case multi-character uppercase sequences. - * Characters listed in UPPER_SPECIAL index into this table to find their - * uppercase expansion. Remember that you must also perform special-casing - * on two single-character sequences in the Turkish locale, which are not - * covered here in CharData. - */ - String UPPER_EXPAND - = "SS\u02bcNJ\u030c\u0399\u0308\u0301\u03a5\u0308" - + "\u0301\u0535\u0552H\u0331T\u0308W\u030aY\u030a" - + "A\u02be\u03a5\u0313\u03a5\u0313\u0300\u03a5\u0313\u0301\u03a5" - + "\u0313\u0342\u1f08\u0399\u1f09\u0399\u1f0a\u0399\u1f0b\u0399\u1f0c" - + "\u0399\u1f0d\u0399\u1f0e\u0399\u1f0f\u0399\u1f08\u0399\u1f09\u0399" - + "\u1f0a\u0399\u1f0b\u0399\u1f0c\u0399\u1f0d\u0399\u1f0e\u0399\u1f0f" - + "\u0399\u1f28\u0399\u1f29\u0399\u1f2a\u0399\u1f2b\u0399\u1f2c\u0399" - + "\u1f2d\u0399\u1f2e\u0399\u1f2f\u0399\u1f28\u0399\u1f29\u0399\u1f2a" - + "\u0399\u1f2b\u0399\u1f2c\u0399\u1f2d\u0399\u1f2e\u0399\u1f2f\u0399" - + "\u1f68\u0399\u1f69\u0399\u1f6a\u0399\u1f6b\u0399\u1f6c\u0399\u1f6d" - + "\u0399\u1f6e\u0399\u1f6f\u0399\u1f68\u0399\u1f69\u0399\u1f6a\u0399" - + "\u1f6b\u0399\u1f6c\u0399\u1f6d\u0399\u1f6e\u0399\u1f6f\u0399\u1fba" - + "\u0399\u0391\u0399\u0386\u0399\u0391\u0342\u0391\u0342\u0399\u0391" - + "\u0399\u1fca\u0399\u0397\u0399\u0389\u0399\u0397\u0342\u0397\u0342" - + "\u0399\u0397\u0399\u0399\u0308\u0300\u0399\u0308\u0301\u0399\u0342" - + "\u0399\u0308\u0342\u03a5\u0308\u0300\u03a5\u0308\u0301\u03a1\u0313" - + "\u03a5\u0342\u03a5\u0308\u0342\u1ffa\u0399\u03a9\u0399\u038f\u0399" - + "\u03a9\u0342\u03a9\u0342\u0399\u03a9\u0399FFFI" - + "FLFFIFFLSTS" - + "T\u0544\u0546\u0544\u0535\u0544\u053b\u054e\u0546\u0544\u053d"; -} diff --git a/libjava/gnu/java/lang/ClassHelper.java b/libjava/gnu/java/lang/ClassHelper.java deleted file mode 100644 index 14c8a39c478..00000000000 --- a/libjava/gnu/java/lang/ClassHelper.java +++ /dev/null @@ -1,177 +0,0 @@ -/* ClassHelper.java -- Utility methods to augment java.lang.Class - Copyright (C) 1998, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.lang; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * ClassHelper has various methods that ought to have been in Class. - * - * @author John Keiser - * @author Eric Blake (ebb9@email.byu.edu) - */ -public class ClassHelper -{ - /** - * Strip the package part from the class name. - * - * @param clazz the class to get the truncated name from - * @return the truncated class name - */ - public static String getTruncatedClassName(Class clazz) - { - return getTruncatedName(clazz.getName()); - } - - /** - * Strip the package part from the class name, or the class part from - * the method or field name. - * - * @param name the name to truncate - * @return the truncated name - */ - public static String getTruncatedName(String name) - { - int lastInd = name.lastIndexOf('.'); - if (lastInd == -1) - return name; - return name.substring(lastInd + 1); - } - - /** Cache of methods found in getAllMethods(). */ - private static Map allMethods = new HashMap(); - - /** - * Get all the methods, public, private and otherwise, from the class, - * getting them from the most recent class to find them. This may not - * be quite the correct approach, as this includes methods that are not - * inherited or accessible from clazz, so beware. - * - * @param clazz the class to start at - * @return all methods declared or inherited in clazz - */ - public static Method[] getAllMethods(Class clazz) - { - Method[] retval = (Method[]) allMethods.get(clazz); - if (retval == null) - { - Set methods = new HashSet(); - Class c = clazz; - while (c != null) - { - Method[] currentMethods = c.getDeclaredMethods(); - loop: - for (int i = 0; i < currentMethods.length; i++) - { - Method current = currentMethods[i]; - int size = methods.size(); - Iterator iter = methods.iterator(); - while (--size >= 0) - { - Method override = (Method) iter.next(); - if (current.getName().equals(override.getName()) - && Arrays.equals(current.getParameterTypes(), - override.getParameterTypes()) - && current.getReturnType() == override.getReturnType()) - continue loop; - } - methods.add(current); - } - c = c.getSuperclass(); - } - retval = new Method[methods.size()]; - methods.toArray(retval); - allMethods.put(clazz, retval); - } - return retval; - } - - /** Cache of fields found in getAllFields(). */ - private static Map allFields = new HashMap(); - - /** - * Get all the fields, public, private and otherwise, from the class, - * getting them from the most recent class to find them. This may not - * be quite the correct approach, as this includes fields that are not - * inherited or accessible from clazz, so beware. - * - * @param clazz the class to start at - * @return all fields declared or inherited in clazz - */ - public static Field[] getAllFields(Class clazz) - { - Field[] retval = (Field[]) allFields.get(clazz); - if (retval == null) - { - Set fields = new HashSet(); - Class c = clazz; - while (c != null) - { - Field[] currentFields = c.getDeclaredFields(); - loop: - for (int i = 0; i < currentFields.length; i++) - { - Field current = currentFields[i]; - int size = fields.size(); - Iterator iter = fields.iterator(); - while (--size >= 0) - { - Field override = (Field) iter.next(); - if (current.getName().equals(override.getName()) - && current.getType() == override.getType()) - continue loop; - } - fields.add(current); - } - c = c.getSuperclass(); - } - retval = new Field[fields.size()]; - fields.toArray(retval); - allFields.put(clazz, retval); - } - return retval; - } -} diff --git a/libjava/gnu/java/lang/reflect/TypeSignature.java b/libjava/gnu/java/lang/reflect/TypeSignature.java deleted file mode 100644 index 842e5bdf0f0..00000000000 --- a/libjava/gnu/java/lang/reflect/TypeSignature.java +++ /dev/null @@ -1,288 +0,0 @@ -/* TypeSignature.java -- Class used to compute type signatures - Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.lang.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - -/** - * This class provides static methods that can be used to compute - * type-signatures of <code>Class</code>s or <code>Member</code>s. - * More specific methods are also provided for computing the - * type-signature of <code>Constructor</code>s and - * <code>Method</code>s. Methods are also provided to go in the - * reverse direction. - * - * @author Eric Blake (ebb9@email.byu.edu) - */ -public class TypeSignature -{ - /** - * Returns a <code>String</code> representing the type-encoding of a class. - * The .class file format has different encodings for classes, depending - * on whether it must be disambiguated from primitive types or not; hence - * the descriptor parameter to choose between them. If you are planning - * on decoding primitive types along with classes, then descriptor should - * be true for correct results. Type-encodings are computed as follows: - * - * <pre> - * boolean -> "Z" - * byte -> "B" - * char -> "C" - * double -> "D" - * float -> "F" - * int -> "I" - * long -> "J" - * short -> "S" - * void -> "V" - * arrays -> "[" + descriptor format of component type - * object -> class format: fully qualified name with '.' replaced by '/' - * descriptor format: "L" + class format + ";" - * </pre> - * - * @param type the class name to encode - * @param descriptor true to return objects in descriptor format - * @return the class name, as it appears in bytecode constant pools - * @see #getClassForEncoding(String) - */ - public static String getEncodingOfClass(String type, boolean descriptor) - { - if (! descriptor || type.charAt(0) == '[') - return type.replace('.', '/'); - if (type.equals("boolean")) - return "Z"; - if (type.equals("byte")) - return "B"; - if (type.equals("short")) - return "S"; - if (type.equals("char")) - return "C"; - if (type.equals("int")) - return "I"; - if (type.equals("long")) - return "J"; - if (type.equals("float")) - return "F"; - if (type.equals("double")) - return "D"; - if (type.equals("void")) - return "V"; - return 'L' + type.replace('.', '/') + ';'; - } - - /** - * Gets the descriptor encoding for a class. - * - * @param clazz the class to encode - * @param descriptor true to return objects in descriptor format - * @return the class name, as it appears in bytecode constant pools - * @see #getEncodingOfClass(String, boolean) - */ - public static String getEncodingOfClass(Class clazz, boolean descriptor) - { - return getEncodingOfClass(clazz.getName(), descriptor); - } - - /** - * Gets the descriptor encoding for a class. - * - * @param clazz the class to encode - * @return the class name, as it appears in bytecode constant pools - * @see #getEncodingOfClass(String, boolean) - */ - public static String getEncodingOfClass(Class clazz) - { - return getEncodingOfClass(clazz.getName(), true); - } - - - /** - * This function is the inverse of <code>getEncodingOfClass</code>. This - * accepts both object and descriptor formats, but must know which style - * of string is being passed in (usually, descriptor should be true). In - * descriptor format, "I" is treated as int.class, in object format, it - * is treated as a class named I in the unnamed package. This method is - * strictly equivalent to {@link #getClassForEncoding(java.lang.String, boolean, java.lang.ClassLoader)} - * with a class loader equal to <code>null</code>. In that case, it - * uses the default class loader on the calling stack. - * - * @param type_code the class name to decode - * @param descriptor if the string is in descriptor format - * @return the corresponding Class object - * @throws ClassNotFoundException if the class cannot be located - * @see #getEncodingOfClass(Class, boolean) - */ - public static Class getClassForEncoding(String type_code, boolean descriptor) - throws ClassNotFoundException - { - return getClassForEncoding(type_code, descriptor, null); - } - - /** - * This function is the inverse of <code>getEncodingOfClass</code>. This - * accepts both object and descriptor formats, but must know which style - * of string is being passed in (usually, descriptor should be true). In - * descriptor format, "I" is treated as int.class, in object format, it - * is treated as a class named I in the unnamed package. - * - * @param type_code The class name to decode. - * @param descriptor If the string is in descriptor format. - * @param loader The class loader when resolving generic object name. If - * <code>loader</code> is null then it uses the default class loader on the - * calling stack. - * @return the corresponding Class object. - * @throws ClassNotFoundException if the class cannot be located. - * @see #getEncodingOfClass(Class, boolean) - * @see #getClassForEncoding(String, boolean) - */ - public static Class getClassForEncoding(String type_code, boolean descriptor, - ClassLoader loader) - throws ClassNotFoundException - { - if (descriptor) - { - switch (type_code.charAt(0)) - { - case 'B': - return byte.class; - case 'C': - return char.class; - case 'D': - return double.class; - case 'F': - return float.class; - case 'I': - return int.class; - case 'J': - return long.class; - case 'S': - return short.class; - case 'V': - return void.class; - case 'Z': - return boolean.class; - default: - throw new ClassNotFoundException("Invalid class name: " - + type_code); - case 'L': - type_code = type_code.substring(1, type_code.length() - 1); - // Fallthrough. - case '[': - } - } - return Class.forName(type_code.replace('/', '.'), true, loader); - } - - /** - * Gets the Class object for a type name. - * - * @param type_code the class name to decode - * @return the corresponding Class object - * @throws ClassNotFoundException if the class cannot be located - * @see #getClassForEncoding(String, boolean) - */ - public static Class getClassForEncoding(String type_code) - throws ClassNotFoundException - { - return getClassForEncoding(type_code, true); - } - - /** - * Returns a <code>String</code> representing the type-encoding of a - * method. The type-encoding of a method is: - * - * "(" + parameter type descriptors + ")" + return type descriptor - * - * XXX This could be faster if it were implemented natively. - * - * @param m the method to encode - * @return the encoding - */ - public static String getEncodingOfMethod(Method m) - { - Class[] paramTypes = m.getParameterTypes(); - StringBuffer buf = new StringBuffer().append('('); - for (int i = 0; i < paramTypes.length; i++) - buf.append(getEncodingOfClass(paramTypes[i].getName(), true)); - buf.append(')').append(getEncodingOfClass(m.getReturnType().getName(), - true)); - return buf.toString(); - } - - /** - * Returns a <code>String</code> representing the type-encoding of a - * constructor. The type-encoding of a method is: - * - * "(" + parameter type descriptors + ")V" - * - * XXX This could be faster if it were implemented natively. - * - * @param c the constructor to encode - * @return the encoding - */ - public static String getEncodingOfConstructor(Constructor c) - { - Class[] paramTypes = c.getParameterTypes(); - StringBuffer buf = new StringBuffer().append('('); - for (int i = 0; i < paramTypes.length; i++) - buf.append(getEncodingOfClass(paramTypes[i].getName(), true)); - buf.append(")V"); - return buf.toString(); - } - - /** - * Returns a <code>String</code> representing the type-encoding of a - * class member. This appropriately handles Constructors, Methods, and - * Fields. - * - * @param mem the member to encode - * @return the encoding - */ - public static String getEncodingOfMember(Member mem) - { - if (mem instanceof Constructor) - return getEncodingOfConstructor((Constructor) mem); - if (mem instanceof Method) - return getEncodingOfMethod((Method) mem); - else // Field - return getEncodingOfClass(((Field) mem).getType().getName(), true); - } -} // class TypeSignature diff --git a/libjava/gnu/java/math/MPN.java b/libjava/gnu/java/math/MPN.java deleted file mode 100644 index 05491bb7e84..00000000000 --- a/libjava/gnu/java/math/MPN.java +++ /dev/null @@ -1,771 +0,0 @@ -/* gnu.java.math.MPN - Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -// Included from Kawa 1.6.62 with permission of the author, -// Per Bothner <per@bothner.com>. - -package gnu.java.math; - -/** This contains various low-level routines for unsigned bigints. - * The interfaces match the mpn interfaces in gmp, - * so it should be easy to replace them with fast native functions - * that are trivial wrappers around the mpn_ functions in gmp - * (at least on platforms that use 32-bit "limbs"). - */ - -public class MPN -{ - /** Add x[0:size-1] and y, and write the size least - * significant words of the result to dest. - * Return carry, either 0 or 1. - * All values are unsigned. - * This is basically the same as gmp's mpn_add_1. */ - public static int add_1 (int[] dest, int[] x, int size, int y) - { - long carry = (long) y & 0xffffffffL; - for (int i = 0; i < size; i++) - { - carry += ((long) x[i] & 0xffffffffL); - dest[i] = (int) carry; - carry >>= 32; - } - return (int) carry; - } - - /** Add x[0:len-1] and y[0:len-1] and write the len least - * significant words of the result to dest[0:len-1]. - * All words are treated as unsigned. - * @return the carry, either 0 or 1 - * This function is basically the same as gmp's mpn_add_n. - */ - public static int add_n (int dest[], int[] x, int[] y, int len) - { - long carry = 0; - for (int i = 0; i < len; i++) - { - carry += ((long) x[i] & 0xffffffffL) - + ((long) y[i] & 0xffffffffL); - dest[i] = (int) carry; - carry >>>= 32; - } - return (int) carry; - } - - /** Subtract Y[0:size-1] from X[0:size-1], and write - * the size least significant words of the result to dest[0:size-1]. - * Return borrow, either 0 or 1. - * This is basically the same as gmp's mpn_sub_n function. - */ - - public static int sub_n (int[] dest, int[] X, int[] Y, int size) - { - int cy = 0; - for (int i = 0; i < size; i++) - { - int y = Y[i]; - int x = X[i]; - y += cy; /* add previous carry to subtrahend */ - // Invert the high-order bit, because: (unsigned) X > (unsigned) Y - // iff: (int) (X^0x80000000) > (int) (Y^0x80000000). - cy = (y^0x80000000) < (cy^0x80000000) ? 1 : 0; - y = x - y; - cy += (y^0x80000000) > (x ^ 0x80000000) ? 1 : 0; - dest[i] = y; - } - return cy; - } - - /** Multiply x[0:len-1] by y, and write the len least - * significant words of the product to dest[0:len-1]. - * Return the most significant word of the product. - * All values are treated as if they were unsigned - * (i.e. masked with 0xffffffffL). - * OK if dest==x (not sure if this is guaranteed for mpn_mul_1). - * This function is basically the same as gmp's mpn_mul_1. - */ - - public static int mul_1 (int[] dest, int[] x, int len, int y) - { - long yword = (long) y & 0xffffffffL; - long carry = 0; - for (int j = 0; j < len; j++) - { - carry += ((long) x[j] & 0xffffffffL) * yword; - dest[j] = (int) carry; - carry >>>= 32; - } - return (int) carry; - } - - /** - * Multiply x[0:xlen-1] and y[0:ylen-1], and - * write the result to dest[0:xlen+ylen-1]. - * The destination has to have space for xlen+ylen words, - * even if the result might be one limb smaller. - * This function requires that xlen >= ylen. - * The destination must be distinct from either input operands. - * All operands are unsigned. - * This function is basically the same gmp's mpn_mul. */ - - public static void mul (int[] dest, - int[] x, int xlen, - int[] y, int ylen) - { - dest[xlen] = MPN.mul_1 (dest, x, xlen, y[0]); - - for (int i = 1; i < ylen; i++) - { - long yword = (long) y[i] & 0xffffffffL; - long carry = 0; - for (int j = 0; j < xlen; j++) - { - carry += ((long) x[j] & 0xffffffffL) * yword - + ((long) dest[i+j] & 0xffffffffL); - dest[i+j] = (int) carry; - carry >>>= 32; - } - dest[i+xlen] = (int) carry; - } - } - - /* Divide (unsigned long) N by (unsigned int) D. - * Returns (remainder << 32)+(unsigned int)(quotient). - * Assumes (unsigned int)(N>>32) < (unsigned int)D. - * Code transcribed from gmp-2.0's mpn_udiv_w_sdiv function. - */ - public static long udiv_qrnnd (long N, int D) - { - long q, r; - long a1 = N >>> 32; - long a0 = N & 0xffffffffL; - if (D >= 0) - { - if (a1 < ((D - a1 - (a0 >>> 31)) & 0xffffffffL)) - { - /* dividend, divisor, and quotient are nonnegative */ - q = N / D; - r = N % D; - } - else - { - /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */ - long c = N - ((long) D << 31); - /* Divide (c1*2^32 + c0) by d */ - q = c / D; - r = c % D; - /* Add 2^31 to quotient */ - q += 1 << 31; - } - } - else - { - long b1 = D >>> 1; /* d/2, between 2^30 and 2^31 - 1 */ - //long c1 = (a1 >> 1); /* A/2 */ - //int c0 = (a1 << 31) + (a0 >> 1); - long c = N >>> 1; - if (a1 < b1 || (a1 >> 1) < b1) - { - if (a1 < b1) - { - q = c / b1; - r = c % b1; - } - else /* c1 < b1, so 2^31 <= (A/2)/b1 < 2^32 */ - { - c = ~(c - (b1 << 32)); - q = c / b1; /* (A/2) / (d/2) */ - r = c % b1; - q = (~q) & 0xffffffffL; /* (A/2)/b1 */ - r = (b1 - 1) - r; /* r < b1 => new r >= 0 */ - } - r = 2 * r + (a0 & 1); - if ((D & 1) != 0) - { - if (r >= q) { - r = r - q; - } else if (q - r <= ((long) D & 0xffffffffL)) { - r = r - q + D; - q -= 1; - } else { - r = r - q + D + D; - q -= 2; - } - } - } - else /* Implies c1 = b1 */ - { /* Hence a1 = d - 1 = 2*b1 - 1 */ - if (a0 >= ((long)(-D) & 0xffffffffL)) - { - q = -1; - r = a0 + D; - } - else - { - q = -2; - r = a0 + D + D; - } - } - } - - return (r << 32) | (q & 0xFFFFFFFFl); - } - - /** Divide divident[0:len-1] by (unsigned int)divisor. - * Write result into quotient[0:len-1. - * Return the one-word (unsigned) remainder. - * OK for quotient==dividend. - */ - - public static int divmod_1 (int[] quotient, int[] dividend, - int len, int divisor) - { - int i = len - 1; - long r = dividend[i]; - if ((r & 0xffffffffL) >= ((long)divisor & 0xffffffffL)) - r = 0; - else - { - quotient[i--] = 0; - r <<= 32; - } - - for (; i >= 0; i--) - { - int n0 = dividend[i]; - r = (r & ~0xffffffffL) | (n0 & 0xffffffffL); - r = udiv_qrnnd (r, divisor); - quotient[i] = (int) r; - } - return (int)(r >> 32); - } - - /* Subtract x[0:len-1]*y from dest[offset:offset+len-1]. - * All values are treated as if unsigned. - * @return the most significant word of - * the product, minus borrow-out from the subtraction. - */ - public static int submul_1 (int[] dest, int offset, int[] x, int len, int y) - { - long yl = (long) y & 0xffffffffL; - int carry = 0; - int j = 0; - do - { - long prod = ((long) x[j] & 0xffffffffL) * yl; - int prod_low = (int) prod; - int prod_high = (int) (prod >> 32); - prod_low += carry; - // Invert the high-order bit, because: (unsigned) X > (unsigned) Y - // iff: (int) (X^0x80000000) > (int) (Y^0x80000000). - carry = ((prod_low ^ 0x80000000) < (carry ^ 0x80000000) ? 1 : 0) - + prod_high; - int x_j = dest[offset+j]; - prod_low = x_j - prod_low; - if ((prod_low ^ 0x80000000) > (x_j ^ 0x80000000)) - carry++; - dest[offset+j] = prod_low; - } - while (++j < len); - return carry; - } - - /** Divide zds[0:nx] by y[0:ny-1]. - * The remainder ends up in zds[0:ny-1]. - * The quotient ends up in zds[ny:nx]. - * Assumes: nx>ny. - * (int)y[ny-1] < 0 (i.e. most significant bit set) - */ - - public static void divide (int[] zds, int nx, int[] y, int ny) - { - // This is basically Knuth's formulation of the classical algorithm, - // but translated from in scm_divbigbig in Jaffar's SCM implementation. - - // Correspondance with Knuth's notation: - // Knuth's u[0:m+n] == zds[nx:0]. - // Knuth's v[1:n] == y[ny-1:0] - // Knuth's n == ny. - // Knuth's m == nx-ny. - // Our nx == Knuth's m+n. - - // Could be re-implemented using gmp's mpn_divrem: - // zds[nx] = mpn_divrem (&zds[ny], 0, zds, nx, y, ny). - - int j = nx; - do - { // loop over digits of quotient - // Knuth's j == our nx-j. - // Knuth's u[j:j+n] == our zds[j:j-ny]. - int qhat; // treated as unsigned - if (zds[j]==y[ny-1]) - qhat = -1; // 0xffffffff - else - { - long w = (((long)(zds[j])) << 32) + ((long)zds[j-1] & 0xffffffffL); - qhat = (int) udiv_qrnnd (w, y[ny-1]); - } - if (qhat != 0) - { - int borrow = submul_1 (zds, j - ny, y, ny, qhat); - int save = zds[j]; - long num = ((long)save&0xffffffffL) - ((long)borrow&0xffffffffL); - while (num != 0) - { - qhat--; - long carry = 0; - for (int i = 0; i < ny; i++) - { - carry += ((long) zds[j-ny+i] & 0xffffffffL) - + ((long) y[i] & 0xffffffffL); - zds[j-ny+i] = (int) carry; - carry >>>= 32; - } - zds[j] += carry; - num = carry - 1; - } - } - zds[j] = qhat; - } while (--j >= ny); - } - - /** Number of digits in the conversion base that always fits in a word. - * For example, for base 10 this is 9, since 10**9 is the - * largest number that fits into a words (assuming 32-bit words). - * This is the same as gmp's __mp_bases[radix].chars_per_limb. - * @param radix the base - * @return number of digits */ - public static int chars_per_word (int radix) - { - if (radix < 10) - { - if (radix < 8) - { - if (radix <= 2) - return 32; - else if (radix == 3) - return 20; - else if (radix == 4) - return 16; - else - return 18 - radix; - } - else - return 10; - } - else if (radix < 12) - return 9; - else if (radix <= 16) - return 8; - else if (radix <= 23) - return 7; - else if (radix <= 40) - return 6; - // The following are conservative, but we don't care. - else if (radix <= 256) - return 4; - else - return 1; - } - - /** Count the number of leading zero bits in an int. */ - public static int count_leading_zeros (int i) - { - if (i == 0) - return 32; - int count = 0; - for (int k = 16; k > 0; k = k >> 1) { - int j = i >>> k; - if (j == 0) - count += k; - else - i = j; - } - return count; - } - - public static int set_str (int dest[], byte[] str, int str_len, int base) - { - int size = 0; - if ((base & (base - 1)) == 0) - { - // The base is a power of 2. Read the input string from - // least to most significant character/digit. */ - - int next_bitpos = 0; - int bits_per_indigit = 0; - for (int i = base; (i >>= 1) != 0; ) bits_per_indigit++; - int res_digit = 0; - - for (int i = str_len; --i >= 0; ) - { - int inp_digit = str[i]; - res_digit |= inp_digit << next_bitpos; - next_bitpos += bits_per_indigit; - if (next_bitpos >= 32) - { - dest[size++] = res_digit; - next_bitpos -= 32; - res_digit = inp_digit >> (bits_per_indigit - next_bitpos); - } - } - - if (res_digit != 0) - dest[size++] = res_digit; - } - else - { - // General case. The base is not a power of 2. - int indigits_per_limb = MPN.chars_per_word (base); - int str_pos = 0; - - while (str_pos < str_len) - { - int chunk = str_len - str_pos; - if (chunk > indigits_per_limb) - chunk = indigits_per_limb; - int res_digit = str[str_pos++]; - int big_base = base; - - while (--chunk > 0) - { - res_digit = res_digit * base + str[str_pos++]; - big_base *= base; - } - - int cy_limb; - if (size == 0) - cy_limb = res_digit; - else - { - cy_limb = MPN.mul_1 (dest, dest, size, big_base); - cy_limb += MPN.add_1 (dest, dest, size, res_digit); - } - if (cy_limb != 0) - dest[size++] = cy_limb; - } - } - return size; - } - - /** Compare x[0:size-1] with y[0:size-1], treating them as unsigned integers. - * @result -1, 0, or 1 depending on if x<y, x==y, or x>y. - * This is basically the same as gmp's mpn_cmp function. - */ - public static int cmp (int[] x, int[] y, int size) - { - while (--size >= 0) - { - int x_word = x[size]; - int y_word = y[size]; - if (x_word != y_word) - { - // Invert the high-order bit, because: - // (unsigned) X > (unsigned) Y iff - // (int) (X^0x80000000) > (int) (Y^0x80000000). - return (x_word ^ 0x80000000) > (y_word ^0x80000000) ? 1 : -1; - } - } - return 0; - } - - /** - * Compare x[0:xlen-1] with y[0:ylen-1], treating them as unsigned integers. - * - * @return -1, 0, or 1 depending on if x<y, x==y, or x>y. - */ - public static int cmp (int[] x, int xlen, int[] y, int ylen) - { - return xlen > ylen ? 1 : xlen < ylen ? -1 : cmp (x, y, xlen); - } - - /** - * Shift x[x_start:x_start+len-1] count bits to the "right" - * (i.e. divide by 2**count). - * Store the len least significant words of the result at dest. - * The bits shifted out to the right are returned. - * OK if dest==x. - * Assumes: 0 < count < 32 - */ - public static int rshift (int[] dest, int[] x, int x_start, - int len, int count) - { - int count_2 = 32 - count; - int low_word = x[x_start]; - int retval = low_word << count_2; - int i = 1; - for (; i < len; i++) - { - int high_word = x[x_start+i]; - dest[i-1] = (low_word >>> count) | (high_word << count_2); - low_word = high_word; - } - dest[i-1] = low_word >>> count; - return retval; - } - - /** - * Shift x[x_start:x_start+len-1] count bits to the "right" - * (i.e. divide by 2**count). - * Store the len least significant words of the result at dest. - * OK if dest==x. - * Assumes: 0 <= count < 32 - * Same as rshift, but handles count==0 (and has no return value). - */ - public static void rshift0 (int[] dest, int[] x, int x_start, - int len, int count) - { - if (count > 0) - rshift(dest, x, x_start, len, count); - else - for (int i = 0; i < len; i++) - dest[i] = x[i + x_start]; - } - - /** Return the long-truncated value of right shifting. - * @param x a two's-complement "bignum" - * @param len the number of significant words in x - * @param count the shift count - * @return (long)(x[0..len-1] >> count). - */ - public static long rshift_long (int[] x, int len, int count) - { - int wordno = count >> 5; - count &= 31; - int sign = x[len-1] < 0 ? -1 : 0; - int w0 = wordno >= len ? sign : x[wordno]; - wordno++; - int w1 = wordno >= len ? sign : x[wordno]; - if (count != 0) - { - wordno++; - int w2 = wordno >= len ? sign : x[wordno]; - w0 = (w0 >>> count) | (w1 << (32-count)); - w1 = (w1 >>> count) | (w2 << (32-count)); - } - return ((long)w1 << 32) | ((long)w0 & 0xffffffffL); - } - - /* Shift x[0:len-1] left by count bits, and store the len least - * significant words of the result in dest[d_offset:d_offset+len-1]. - * Return the bits shifted out from the most significant digit. - * Assumes 0 < count < 32. - * OK if dest==x. - */ - - public static int lshift (int[] dest, int d_offset, - int[] x, int len, int count) - { - int count_2 = 32 - count; - int i = len - 1; - int high_word = x[i]; - int retval = high_word >>> count_2; - d_offset++; - while (--i >= 0) - { - int low_word = x[i]; - dest[d_offset+i] = (high_word << count) | (low_word >>> count_2); - high_word = low_word; - } - dest[d_offset+i] = high_word << count; - return retval; - } - - /** Return least i such that word & (1<<i). Assumes word!=0. */ - - public static int findLowestBit (int word) - { - int i = 0; - while ((word & 0xF) == 0) - { - word >>= 4; - i += 4; - } - if ((word & 3) == 0) - { - word >>= 2; - i += 2; - } - if ((word & 1) == 0) - i += 1; - return i; - } - - /** Return least i such that words & (1<<i). Assumes there is such an i. */ - - public static int findLowestBit (int[] words) - { - for (int i = 0; ; i++) - { - if (words[i] != 0) - return 32 * i + findLowestBit (words[i]); - } - } - - /** Calculate Greatest Common Divisior of x[0:len-1] and y[0:len-1]. - * Assumes both arguments are non-zero. - * Leaves result in x, and returns len of result. - * Also destroys y (actually sets it to a copy of the result). */ - - public static int gcd (int[] x, int[] y, int len) - { - int i, word; - // Find sh such that both x and y are divisible by 2**sh. - for (i = 0; ; i++) - { - word = x[i] | y[i]; - if (word != 0) - { - // Must terminate, since x and y are non-zero. - break; - } - } - int initShiftWords = i; - int initShiftBits = findLowestBit (word); - // Logically: sh = initShiftWords * 32 + initShiftBits - - // Temporarily devide both x and y by 2**sh. - len -= initShiftWords; - MPN.rshift0 (x, x, initShiftWords, len, initShiftBits); - MPN.rshift0 (y, y, initShiftWords, len, initShiftBits); - - int[] odd_arg; /* One of x or y which is odd. */ - int[] other_arg; /* The other one can be even or odd. */ - if ((x[0] & 1) != 0) - { - odd_arg = x; - other_arg = y; - } - else - { - odd_arg = y; - other_arg = x; - } - - for (;;) - { - // Shift other_arg until it is odd; this doesn't - // affect the gcd, since we divide by 2**k, which does not - // divide odd_arg. - for (i = 0; other_arg[i] == 0; ) i++; - if (i > 0) - { - int j; - for (j = 0; j < len-i; j++) - other_arg[j] = other_arg[j+i]; - for ( ; j < len; j++) - other_arg[j] = 0; - } - i = findLowestBit(other_arg[0]); - if (i > 0) - MPN.rshift (other_arg, other_arg, 0, len, i); - - // Now both odd_arg and other_arg are odd. - - // Subtract the smaller from the larger. - // This does not change the result, since gcd(a-b,b)==gcd(a,b). - i = MPN.cmp(odd_arg, other_arg, len); - if (i == 0) - break; - if (i > 0) - { // odd_arg > other_arg - MPN.sub_n (odd_arg, odd_arg, other_arg, len); - // Now odd_arg is even, so swap with other_arg; - int[] tmp = odd_arg; odd_arg = other_arg; other_arg = tmp; - } - else - { // other_arg > odd_arg - MPN.sub_n (other_arg, other_arg, odd_arg, len); - } - while (odd_arg[len-1] == 0 && other_arg[len-1] == 0) - len--; - } - if (initShiftWords + initShiftBits > 0) - { - if (initShiftBits > 0) - { - int sh_out = MPN.lshift (x, initShiftWords, x, len, initShiftBits); - if (sh_out != 0) - x[(len++)+initShiftWords] = sh_out; - } - else - { - for (i = len; --i >= 0;) - x[i+initShiftWords] = x[i]; - } - for (i = initShiftWords; --i >= 0; ) - x[i] = 0; - len += initShiftWords; - } - return len; - } - - public static int intLength (int i) - { - return 32 - count_leading_zeros (i < 0 ? ~i : i); - } - - /** Calcaulte the Common Lisp "integer-length" function. - * Assumes input is canonicalized: len==BigInteger.wordsNeeded(words,len) */ - public static int intLength (int[] words, int len) - { - len--; - return intLength (words[len]) + 32 * len; - } - - /* DEBUGGING: - public static void dprint (BigInteger x) - { - if (x.words == null) - System.err.print(Long.toString((long) x.ival & 0xffffffffL, 16)); - else - dprint (System.err, x.words, x.ival); - } - public static void dprint (int[] x) { dprint (System.err, x, x.length); } - public static void dprint (int[] x, int len) { dprint (System.err, x, len); } - public static void dprint (java.io.PrintStream ps, int[] x, int len) - { - ps.print('('); - for (int i = 0; i < len; i++) - { - if (i > 0) - ps.print (' '); - ps.print ("#x" + Long.toString ((long) x[i] & 0xffffffffL, 16)); - } - ps.print(')'); - } - */ -} diff --git a/libjava/gnu/java/net/BASE64.java b/libjava/gnu/java/net/BASE64.java deleted file mode 100644 index 901aa0c35fc..00000000000 --- a/libjava/gnu/java/net/BASE64.java +++ /dev/null @@ -1,190 +0,0 @@ -/* BASE.java -- - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -/** - * Encodes and decodes text according to the BASE64 encoding. - * - * @author Chris Burdess (dog@gnu.org) - */ -public final class BASE64 -{ - private static final byte[] src = { - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, - 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, - 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, - 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, - 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x2b, 0x2f - }; - - private static final byte[] dst; - static - { - dst = new byte[0x100]; - for (int i = 0x0; i < 0xff; i++) - { - dst[i] = -1; - } - for (int i = 0; i < src.length; i++) - { - dst[src[i]] = (byte) i; - } - } - - private BASE64() - { - } - - /** - * Encode the specified byte array using the BASE64 algorithm. - * - * @param bs the source byte array - */ - public static byte[] encode(byte[] bs) - { - int si = 0, ti = 0; // source/target array indices - byte[] bt = new byte[((bs.length + 2) * 4) / 3]; // target byte array - for (; si < bs.length; si += 3) - { - int buflen = bs.length - si; - if (buflen == 1) - { - byte b = bs[si]; - int i = 0; - bt[ti++] = src[b >>> 2 & 0x3f]; - bt[ti++] = src[(b << 4 & 0x30) + (i >>> 4 & 0xf)]; - } - else if (buflen == 2) - { - byte b1 = bs[si], b2 = bs[si + 1]; - int i = 0; - bt[ti++] = src[b1 >>> 2 & 0x3f]; - bt[ti++] = src[(b1 << 4 & 0x30) + (b2 >>> 4 & 0xf)]; - bt[ti++] = src[(b2 << 2 & 0x3c) + (i >>> 6 & 0x3)]; - } - else - { - byte b1 = bs[si], b2 = bs[si + 1], b3 = bs[si + 2]; - bt[ti++] = src[b1 >>> 2 & 0x3f]; - bt[ti++] = src[(b1 << 4 & 0x30) + (b2 >>> 4 & 0xf)]; - bt[ti++] = src[(b2 << 2 & 0x3c) + (b3 >>> 6 & 0x3)]; - bt[ti++] = src[b3 & 0x3f]; - } - } - if (ti < bt.length) - { - byte[] tmp = new byte[ti]; - System.arraycopy(bt, 0, tmp, 0, ti); - bt = tmp; - } - /*while (ti < bt.length) - { - bt[ti++] = 0x3d; - }*/ - return bt; - } - - /** - * Decode the specified byte array using the BASE64 algorithm. - * - * @param bs the source byte array - */ - public static byte[] decode(byte[] bs) - { - int srclen = bs.length; - while (srclen > 0 && bs[srclen - 1] == 0x3d) - { - srclen--; /* strip padding character */ - } - byte[] buffer = new byte[srclen]; - int buflen = 0; - int si = 0; - int len = srclen - si; - while (len > 0) - { - byte b0 = dst[bs[si++] & 0xff]; - byte b2 = dst[bs[si++] & 0xff]; - buffer[buflen++] = (byte) (b0 << 2 & 0xfc | b2 >>> 4 & 0x3); - if (len > 2) - { - b0 = b2; - b2 = dst[bs[si++] & 0xff]; - buffer[buflen++] = (byte) (b0 << 4 & 0xf0 | b2 >>> 2 & 0xf); - if (len > 3) - { - b0 = b2; - b2 = dst[bs[si++] & 0xff]; - buffer[buflen++] = (byte) (b0 << 6 & 0xc0 | b2 & 0x3f); - } - } - len = srclen - si; - } - byte[] bt = new byte[buflen]; - System.arraycopy(buffer, 0, bt, 0, buflen); - return bt; - } - - public static void main(String[] args) - { - boolean decode = false; - for (int i = 0; i < args.length; i++) - { - if (args[i].equals("-d")) - { - decode = true; - } - else - { - try - { - byte[] in = args[i].getBytes("US-ASCII"); - byte[] out = decode ? decode(in) : encode(in); - System.out.println(args[i] + " = " + - new String(out, "US-ASCII")); - } - catch (java.io.UnsupportedEncodingException e) - { - e.printStackTrace(System.err); - } - } - } - } -} diff --git a/libjava/gnu/java/net/CRLFInputStream.java b/libjava/gnu/java/net/CRLFInputStream.java deleted file mode 100644 index d0f9e8c4130..00000000000 --- a/libjava/gnu/java/net/CRLFInputStream.java +++ /dev/null @@ -1,174 +0,0 @@ -/* CRLFInputStream.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.io.BufferedInputStream; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * An input stream that filters out CR/LF pairs into LFs. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class CRLFInputStream - extends FilterInputStream -{ - /** - * The CR octet. - */ - public static final int CR = 13; - - /** - * The LF octet. - */ - public static final int LF = 10; - - private boolean doReset; - - /** - * Constructs a CR/LF input stream connected to the specified input - * stream. - */ - public CRLFInputStream(InputStream in) - { - super(in.markSupported() ? in : new BufferedInputStream(in)); - } - - /** - * Reads the next byte of data from this input stream. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read() - throws IOException - { - int c = in.read(); - if (c == CR) - { - in.mark(1); - int d = in.read(); - if (d == LF) - { - c = d; - } - else - { - in.reset(); - } - } - return c; - } - - /** - * Reads up to b.length bytes of data from this input stream into - * an array of bytes. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b) - throws IOException - { - return read(b, 0, b.length); - } - - /** - * Reads up to len bytes of data from this input stream into an - * array of bytes, starting at the specified offset. - * Returns -1 if the end of the stream has been reached. - * @exception IOException if an I/O error occurs - */ - public int read(byte[] b, int off, int len) - throws IOException - { - in.mark(len + 1); - int l = in.read(b, off, len); - if (l > 0) - { - int i = indexOfCRLF(b, off, l); - if (doReset) - { - in.reset(); - if (i != -1) - { - l = in.read(b, off, i + 1); // read to CR - in.read(); // skip LF - b[i] = LF; // fix CR as LF - } - else - { - l = in.read(b, off, len); // CR(s) but no LF - } - } - } - return l; - } - - private int indexOfCRLF(byte[] b, int off, int len) - throws IOException - { - doReset = false; - int lm1 = len - 1; - for (int i = off; i < len; i++) - { - if (b[i] == CR) - { - int d; - if (i == lm1) - { - d = in.read(); - doReset = true; - } - else - { - d = b[i + 1]; - } - if (d == LF) - { - doReset = true; - return i; - } - } - } - return -1; - } - -} - diff --git a/libjava/gnu/java/net/CRLFOutputStream.java b/libjava/gnu/java/net/CRLFOutputStream.java deleted file mode 100644 index f27e0f218ad..00000000000 --- a/libjava/gnu/java/net/CRLFOutputStream.java +++ /dev/null @@ -1,183 +0,0 @@ -/* CRLFOutputStream.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -/** - * An output stream that filters LFs into CR/LF pairs. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class CRLFOutputStream - extends FilterOutputStream -{ - static final String US_ASCII = "US-ASCII"; - - /** - * The CR octet. - */ - public static final int CR = 13; - - /** - * The LF octet. - */ - public static final int LF = 10; - - /** - * The CR/LF pair. - */ - public static final byte[] CRLF = { CR, LF }; - - /** - * The last byte read. - */ - protected int last; - - /** - * Constructs a CR/LF output stream connected to the specified output stream. - */ - public CRLFOutputStream(OutputStream out) - { - super(out); - last = -1; - } - - /** - * Writes a character to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(int ch) throws IOException - { - if (ch == CR) - { - out.write(CRLF); - } - else if (ch == LF) - { - if (last != CR) - { - out.write(CRLF); - } - } - else - { - out.write(ch); - } - last = ch; - } - - /** - * Writes a byte array to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(byte[] b) - throws IOException - { - write(b, 0, b.length); - } - - /** - * Writes a portion of a byte array to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(byte[] b, int off, int len) - throws IOException - { - int d = off; - len += off; - for (int i = off; i < len; i++) - { - switch (b[i]) - { - case CR: - out.write (b, d, i - d); - out.write (CRLF, 0, 2); - d = i + 1; - break; - case LF: - if (last != CR) - { - out.write (b, d, i - d); - out.write (CRLF, 0, 2); - } - d = i + 1; - break; - } - last = b[i]; - } - if (len - d > 0) - { - out.write (b, d, len - d); - } - } - - /** - * Writes the specified ASCII string to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void write(String text) - throws IOException - { - try - { - byte[] bytes = text.getBytes(US_ASCII); - write(bytes, 0, bytes.length); - } - catch (UnsupportedEncodingException e) - { - throw new IOException("The US-ASCII encoding is not supported " + - "on this system"); - } - } - - /** - * Writes a newline to the underlying stream. - * @exception IOException if an I/O error occurred - */ - public void writeln() - throws IOException - { - out.write(CRLF, 0, 2); - } -} - diff --git a/libjava/gnu/java/net/EmptyX509TrustManager.java b/libjava/gnu/java/net/EmptyX509TrustManager.java deleted file mode 100644 index b8faf41add7..00000000000 --- a/libjava/gnu/java/net/EmptyX509TrustManager.java +++ /dev/null @@ -1,70 +0,0 @@ -/* EmptyX509TrustManager.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -import javax.net.ssl.X509TrustManager; - -/** - * Empty implementation of an X509 trust manager. - * This implementation does not check any certificates in the chain. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class EmptyX509TrustManager - implements X509TrustManager -{ - public void checkClientTrusted(X509Certificate[] chain, String authType) - throws CertificateException - { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) - throws CertificateException - { - } - - public X509Certificate[] getAcceptedIssuers() - { - return new X509Certificate[0]; - } -} - diff --git a/libjava/gnu/java/net/GetLocalHostAction.java b/libjava/gnu/java/net/GetLocalHostAction.java deleted file mode 100644 index 7483b025773..00000000000 --- a/libjava/gnu/java/net/GetLocalHostAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* GetLocalHostAction.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.security.PrivilegedAction; - -/** - * Privileged action to retrieve the local host InetAddress. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class GetLocalHostAction - implements PrivilegedAction -{ - public Object run() - { - try - { - return InetAddress.getLocalHost(); - } - catch (UnknownHostException e) - { - return null; - } - } -} - diff --git a/libjava/gnu/java/net/HeaderFieldHelper.java b/libjava/gnu/java/net/HeaderFieldHelper.java deleted file mode 100644 index 0fb8d953d21..00000000000 --- a/libjava/gnu/java/net/HeaderFieldHelper.java +++ /dev/null @@ -1,138 +0,0 @@ -/* HeaderFieldHelper.java -- Helps manage headers fields - Copyright (C) 1998, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -/** - * This class manages header field keys and values. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class HeaderFieldHelper -{ - private Vector headerFieldKeys; - private Vector headerFieldValues; - - public HeaderFieldHelper() - { - this (10); - } - - public HeaderFieldHelper (int size) - { - headerFieldKeys = new Vector (size); - headerFieldValues = new Vector (size); - } - - public void addHeaderField (String key, String value) - { - headerFieldKeys.addElement (key); - headerFieldValues.addElement (value); - } - - public String getHeaderFieldKeyByIndex (int index) - { - String key = null; - - try - { - key = (String) headerFieldKeys.elementAt (index); - } - catch (ArrayIndexOutOfBoundsException e) - { - } - - return key; - } - - public String getHeaderFieldValueByIndex(int index) - { - String value = null; - - try - { - value = (String) headerFieldValues.elementAt (index); - } - catch (ArrayIndexOutOfBoundsException e) - { - } - - return value; - } - - public String getHeaderFieldValueByKey(String key) - { - String value = null; - - try - { - value = (String) headerFieldValues.elementAt - (headerFieldKeys.indexOf(key)); - } - catch (ArrayIndexOutOfBoundsException e) - { - } - - return value; - } - - public Map getHeaderFields() - { - HashMap headers = new HashMap(); - int max = headerFieldKeys.size(); - - for (int index = 0; index < max; index++) - { - headers.put(headerFieldKeys.elementAt(index), - headerFieldValues.elementAt(index)); - } - - return headers; - } - - public int getNumberOfEntries() - { - return headerFieldKeys.size(); - } - -} // class HeaderFieldHelper - diff --git a/libjava/gnu/java/net/LineInputStream.java b/libjava/gnu/java/net/LineInputStream.java deleted file mode 100644 index 5ca068618da..00000000000 --- a/libjava/gnu/java/net/LineInputStream.java +++ /dev/null @@ -1,198 +0,0 @@ -/* LineInputStream.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net; - -import java.io.ByteArrayOutputStream; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * An input stream that can read lines of input. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class LineInputStream - extends FilterInputStream -{ - /* - * Line buffer. - */ - private ByteArrayOutputStream buf; - - /* - * Encoding to use when translating bytes to characters. - */ - private String encoding; - - /* - * End-of-stream flag. - */ - private boolean eof; - - /** - * Whether we can use block reads. - */ - private final boolean blockReads; - - /** - * Constructor using the US-ASCII character encoding. - * @param in the underlying input stream - */ - public LineInputStream(InputStream in) - { - this(in, "US-ASCII"); - } - - /** - * Constructor. - * @param in the underlying input stream - * @param encoding the character encoding to use - */ - public LineInputStream(InputStream in, String encoding) - { - super(in); - buf = new ByteArrayOutputStream(); - this.encoding = encoding; - eof = false; - blockReads = in.markSupported(); - } - - /** - * Read a line of input. - */ - public String readLine() - throws IOException - { - if (eof) - { - return null; - } - do - { - if (blockReads) - { - // Use mark and reset to read chunks of bytes - final int MIN_LENGTH = 1024; - int len, pos; - - len = in.available(); - len = (len < MIN_LENGTH) ? MIN_LENGTH : len; - byte[] b = new byte[len]; - in.mark(len); - // Read into buffer b - len = in.read(b, 0, len); - // Handle EOF - if (len == -1) - { - eof = true; - if (buf.size() == 0) - { - return null; - } - else - { - // We don't care about resetting buf - return buf.toString(encoding); - } - } - // Get index of LF in b - pos = indexOf(b, len, (byte) 0x0a); - if (pos != -1) - { - // Write pos bytes to buf - buf.write(b, 0, pos); - // Reset stream, and read pos + 1 bytes - in.reset(); - pos += 1; - while (pos > 0) - { - len = in.read(b, 0, pos); - pos = (len == -1) ? -1 : pos - len; - } - // Return line - String ret = buf.toString(encoding); - buf.reset(); - return ret; - } - else - { - // Append everything to buf and fall through to re-read. - buf.write(b, 0, len); - } - } - else - { - // We must use character reads in order not to read too much - // from the underlying stream. - int c = in.read(); - switch (c) - { - case -1: - eof = true; - if (buf.size() == 0) - { - return null; - } - // Fall through and return contents of buffer. - case 0x0a: // LF - String ret = buf.toString(encoding); - buf.reset(); - return ret; - default: - buf.write(c); - } - } - } - while (true); - } - - private int indexOf(byte[] b, int len, byte c) - { - for (int pos = 0; pos < len; pos++) - { - if (b[pos] == c) - { - return pos; - } - } - return -1; - } -} - diff --git a/libjava/gnu/java/net/URLParseError.java b/libjava/gnu/java/net/URLParseError.java deleted file mode 100644 index 90907480f11..00000000000 --- a/libjava/gnu/java/net/URLParseError.java +++ /dev/null @@ -1,57 +0,0 @@ -/* URLParseError.java -- Helps bypassing the exception limitation for - URLStreamHandler.parseURL(). - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.net; - -/** - * This class helps the people writing protocols to report URL parse - * errors in parseUrl as this method cannot report other exceptions - * than Errors. - * - * The main drawback is that it uses the Error mechanism which should not - * be used for that type of error reporting. - * - * @author Guilhem Lavaux (guilhem@kaffe.org) - */ -public class URLParseError extends Error -{ - public URLParseError(String msg) - { - super(msg); - } -} diff --git a/libjava/gnu/java/net/protocol/ftp/ActiveModeDTP.java b/libjava/gnu/java/net/protocol/ftp/ActiveModeDTP.java deleted file mode 100644 index 3755e8beb8d..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/ActiveModeDTP.java +++ /dev/null @@ -1,251 +0,0 @@ -/* ActiveModeDTP.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - -/** - * An active mode FTP data transfer process. - * This starts a server on the specified port listening for a data - * connection. It converts the socket input into a file stream for reading. - * - * @author Chris Burdess (dog@gnu.org) - */ -final class ActiveModeDTP - implements DTP, Runnable -{ - - ServerSocket server; - Socket socket; - DTPInputStream in; - DTPOutputStream out; - boolean completed; - boolean inProgress; - int transferMode; - IOException exception; - Thread acceptThread; - int connectionTimeout; - - ActiveModeDTP(InetAddress localhost, int port, - int connectionTimeout, int timeout) - throws IOException - { - completed = false; - inProgress = false; - server = new ServerSocket(port, 1, localhost); - if (timeout > 0) - { - server.setSoTimeout(timeout); - } - if (connectionTimeout <= 0) - { - connectionTimeout = 20000; - } - this.connectionTimeout = connectionTimeout; - acceptThread = new Thread(this, "ActiveModeDTP"); - acceptThread.start(); - } - - /** - * Start listening. - */ - public void run() - { - try - { - socket = server.accept(); - //System.err.println("Accepted connection from "+socket.getInetAddress()+":"+socket.getPort()); - } - catch (IOException e) - { - exception = e; - } - } - - /** - * Waits until a client has connected. - */ - public void waitFor() - throws IOException - { - try - { - acceptThread.join(connectionTimeout); - } - catch (InterruptedException e) - { - } - if (exception != null) - { - throw exception; - } - if (socket == null) - { - server.close(); - throw new IOException("client did not connect before timeout"); - } - acceptThread = null; - } - - /** - * Returns an input stream from which a remote file can be read. - */ - public InputStream getInputStream() - throws IOException - { - if (inProgress) - { - throw new IOException("Transfer in progress"); - } - if (acceptThread != null) - { - waitFor(); - } - switch (transferMode) - { - case FTPConnection.MODE_STREAM: - in = new StreamInputStream(this, socket.getInputStream()); - break; - case FTPConnection.MODE_BLOCK: - in = new BlockInputStream(this, socket.getInputStream()); - break; - case FTPConnection.MODE_COMPRESSED: - in = new CompressedInputStream(this, socket.getInputStream()); - break; - default: - throw new IllegalStateException("invalid transfer mode"); - } - in.setTransferComplete(false); - return in; - } - - /** - * Returns an output stream to which a local file can be written for - * upload. - */ - public OutputStream getOutputStream() throws IOException - { - if (inProgress) - { - throw new IOException("Transfer in progress"); - } - if (acceptThread != null) - { - waitFor(); - } - switch (transferMode) - { - case FTPConnection.MODE_STREAM: - out = new StreamOutputStream(this, socket.getOutputStream()); - break; - case FTPConnection.MODE_BLOCK: - out = new BlockOutputStream(this, socket.getOutputStream()); - break; - case FTPConnection.MODE_COMPRESSED: - out = new CompressedOutputStream(this, socket.getOutputStream()); - break; - default: - throw new IllegalStateException("invalid transfer mode"); - } - out.setTransferComplete(false); - return out; - } - - public void setTransferMode(int mode) - { - transferMode = mode; - } - - public void complete() - { - completed = true; - if (!inProgress) - { - transferComplete(); - } - } - - public boolean abort() - { - completed = true; - transferComplete(); - return inProgress; - } - - public void transferComplete() - { - if (socket == null) - { - return; - } - if (in != null) - { - in.setTransferComplete(true); - } - if (out != null) - { - out.setTransferComplete(true); - } - completed = completed || (transferMode == FTPConnection.MODE_STREAM); - if (completed && socket != null) - { - try - { - socket.close(); - } - catch (IOException e) - { - } - try - { - server.close(); - } - catch (IOException e) - { - } - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/BlockInputStream.java b/libjava/gnu/java/net/protocol/ftp/BlockInputStream.java deleted file mode 100644 index 63897f1d6db..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/BlockInputStream.java +++ /dev/null @@ -1,150 +0,0 @@ -/* BlockInputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; - -/** - * A DTP input stream that implements the FTP block transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class BlockInputStream - extends DTPInputStream -{ - - static final int EOF = 64; - - int descriptor; - int max = -1; - int count = -1; - - BlockInputStream(DTP dtp, InputStream in) - { - super(dtp, in); - } - - public int read() - throws IOException - { - if (transferComplete) - { - return -1; - } - if (count == -1) - { - readHeader(); - } - if (max < 1) - { - close(); - return -1; - } - int c = in.read(); - if (c == -1) - { - dtp.transferComplete(); - } - count++; - if (count >= max) - { - count = -1; - if (descriptor == EOF) - { - close(); - } - } - return c; - } - - public int read(byte[] buf) - throws IOException - { - return read(buf, 0, buf.length); - } - - public int read(byte[] buf, int off, int len) - throws IOException - { - if (transferComplete) - { - return -1; - } - if (count == -1) - { - readHeader(); - } - if (max < 1) - { - close(); - return -1; - } - int l = in.read(buf, off, len); - if (l == -1) - { - dtp.transferComplete(); - } - count += l; - if (count >= max) - { - count = -1; - if (descriptor == EOF) - { - close(); - } - } - return l; - } - - /** - * Reads the block header. - */ - void readHeader() - throws IOException - { - descriptor = in.read(); - int max_hi = in.read(); - int max_lo = in.read(); - max = (max_hi << 8) | max_lo; - count = 0; - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/BlockOutputStream.java b/libjava/gnu/java/net/protocol/ftp/BlockOutputStream.java deleted file mode 100644 index 85481c95bd5..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/BlockOutputStream.java +++ /dev/null @@ -1,111 +0,0 @@ -/* BlockOutputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A DTP output stream that implements the FTP block transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class BlockOutputStream - extends DTPOutputStream -{ - - static final byte RECORD = -128; // 0x80 - static final byte EOF = 64; // 0x40 - - BlockOutputStream(DTP dtp, OutputStream out) - { - super(dtp, out); - } - - public void write(int c) - throws IOException - { - if (transferComplete) - { - return; - } - byte[] buf = new byte[] - { - RECORD, /* record descriptor */ - 0x00, 0x01, /* one byte */ - (byte) c /* the byte */ - }; - out.write(buf, 0, 4); - } - - public void write(byte[] b) - throws IOException - { - write(b, 0, b.length); - } - - public void write(byte[] b, int off, int len) - throws IOException - { - if (transferComplete) - { - return; - } - byte[] buf = new byte[len + 3]; - buf[0] = RECORD; /* record descriptor */ - buf[1] = (byte) ((len & 0x00ff) >> 8); /* high byte of bytecount */ - buf[2] = (byte) (len & 0xff00); /* low byte of bytecount */ - System.arraycopy(b, off, buf, 3, len); - out.write(buf, 0, len); - } - - public void close() - throws IOException - { - byte[] buf = new byte[] - { - EOF, /* eof descriptor */ - 0x00, 0x00 /* no bytes */ - }; - out.write(buf, 0, 3); - super.close(); - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/CompressedInputStream.java b/libjava/gnu/java/net/protocol/ftp/CompressedInputStream.java deleted file mode 100644 index f2e65b7d37e..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/CompressedInputStream.java +++ /dev/null @@ -1,215 +0,0 @@ -/* CompressedInputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; -import java.net.ProtocolException; - -/** - * A DTP input stream that implements the FTP compressed transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class CompressedInputStream - extends DTPInputStream -{ - - static final int EOF = 64; - - static final int RAW = 0x00; - static final int COMPRESSED = 0x80; - static final int FILLER = 0xc0; - - int descriptor; - int max = -1; - int count = -1; - - int state = RAW; // RAW | STATE | FILLER - int rep; // the compressed byte - int n = 0; // the number of compressed or raw bytes - - CompressedInputStream(DTP dtp, InputStream in) - { - super(dtp, in); - } - - public int read() - throws IOException - { - if (transferComplete) - { - return -1; - } - if (count == -1) - { - readHeader(); - } - if (max < 1) - { - close(); - return -1; - } - if (n > 0 && (state == COMPRESSED || state == FILLER)) - { - n--; - return rep; - } - int c = in.read(); - if (c == -1) - { - close(); - } - count++; - if (count >= max) - { - count = -1; - if (descriptor == EOF) - { - close(); - } - } - if (c == -1) - { - return c; - } - while (n == 0) // read code header - { - state = (c & 0xc0); - n = (c & 0x3f); - c = in.read(); - if (c == -1) - { - return -1; - } - } - switch (state) - { - case RAW: - break; - case COMPRESSED: - case FILLER: - rep = c; - break; - default: - throw new ProtocolException("Illegal state: " + state); - } - n--; - return c; - } - - public int read(byte[] buf) - throws IOException - { - return read(buf, 0, buf.length); - } - - public int read(byte[] buf, int off, int len) - throws IOException - { - if (transferComplete) - { - return -1; - } - if (count == -1) - { - readHeader(); - } - if (max < 1) - { - close(); - return -1; - } - // TODO improve performance - for (int i = off; i < len; i++) - { - int c = read(); - if (c == -1) - { - close(); - return i; - } - buf[i] = (byte) c; - } - return len; - /* - int l = in.read (buf, off, len); - if (l==-1) - { - close (); - } - count += l; - if (count>=max) - { - count = -1; - if (descriptor==EOF) - { - close (); - } - } - return l; - */ - } - - /** - * Reads the block header. - */ - void readHeader() - throws IOException - { - descriptor = in.read(); - int max_hi = in.read(); - int max_lo = in.read(); - max = (max_hi << 8) | max_lo; - count = 0; - } - - /** - * Reads the code header. - */ - void readCodeHeader() - throws IOException - { - int code = in.read(); - state = (code & 0xc0); - n = (code & 0x3f); - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/CompressedOutputStream.java b/libjava/gnu/java/net/protocol/ftp/CompressedOutputStream.java deleted file mode 100644 index b960fb3afe8..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/CompressedOutputStream.java +++ /dev/null @@ -1,228 +0,0 @@ -/* CompressedOutputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A DTP output stream that implements the FTP compressed transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class CompressedOutputStream - extends DTPOutputStream -{ - - static final byte RECORD = -128; // 0x80 - static final byte EOF = 64; // 0x40 - - CompressedOutputStream(DTP dtp, OutputStream out) - { - super(dtp, out); - } - - /** - * Just one byte cannot be compressed. - * It takes 5 bytes to transmit - hardly very compressed! - */ - public void write(int c) - throws IOException - { - if (transferComplete) - { - return; - } - byte[] buf = new byte[] - { - RECORD, /* record descriptor */ - 0x00, 0x01, /* one byte */ - 0x01, /* one uncompressed byte */ - (byte) c /* the byte */ - }; - out.write(buf, 0, 5); - } - - public void write(byte[] b) - throws IOException - { - write(b, 0, b.length); - } - - /** - * The larger len is, the better. - */ - public void write(byte[] b, int off, int len) - throws IOException - { - if (transferComplete) - { - return; - } - byte[] buf = compress(b, off, len); - len = buf.length; - buf[0] = RECORD; /* record descriptor */ - buf[1] = (byte) ((len & 0x00ff) >> 8); /* high byte of bytecount */ - buf[2] = (byte) (len & 0xff00); /* low byte of bytecount */ - out.write(buf, 0, len); - } - - /** - * Returns the compressed form of the given byte array. - * The first 3 bytes are left free for header information. - */ - byte[] compress(byte[] b, int off, int len) - { - byte[] buf = new byte[len]; - byte last = 0; - int pos = 0, raw_count = 0, rep_count = 1; - for (int i = off; i < len; i++) - { - byte c = b[i]; - if (i > off && c == last) // compress - { - if (raw_count > 0) // flush raw bytes to buf - { - // need to add raw_count+1 bytes - if (pos + (raw_count + 1) > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_raw(buf, pos, b, (i - raw_count) - 1, - raw_count); - raw_count = 0; - } - rep_count++; // keep looking for same byte - } - else - { - if (rep_count > 1) // flush compressed bytes to buf - { - // need to add 2 bytes - if (pos + 2 > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_compressed(buf, pos, rep_count, last); - rep_count = 1; - } - raw_count++; // keep looking for raw bytes - } - if (rep_count == 127) // flush compressed bytes - { - // need to add 2 bytes - if (pos + 2 > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_compressed(buf, pos, rep_count, last); - rep_count = 1; - } - if (raw_count == 127) // flush raw bytes - { - // need to add raw_count+1 bytes - if (pos + (raw_count + 1) > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_raw(buf, pos, b, (i - raw_count), raw_count); - raw_count = 0; - } - last = c; - } - if (rep_count > 1) // flush compressed bytes - { - // need to add 2 bytes - if (pos + 2 > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_compressed(buf, pos, rep_count, last); - rep_count = 1; - } - if (raw_count > 0) // flush raw bytes - { - // need to add raw_count+1 bytes - if (pos + (raw_count + 1) > buf.length) - { - buf = realloc(buf, len); - } - pos = flush_raw(buf, pos, b, (len - raw_count), raw_count); - raw_count = 0; - } - byte[] ret = new byte[pos + 3]; - System.arraycopy(buf, 0, ret, 3, pos); - return ret; - } - - int flush_compressed(byte[] buf, int pos, int count, byte c) - { - buf[pos++] = (byte) (0x80 | count); - buf[pos++] = c; - return pos; - } - - int flush_raw(byte[] buf, int pos, byte[] src, int off, int len) - { - buf[pos++] = (byte) len; - System.arraycopy(src, off, buf, pos, len); - return pos + len; - } - - byte[] realloc(byte[] buf, int len) - { - byte[] ret = new byte[buf.length + len]; - System.arraycopy(buf, 0, ret, 0, buf.length); - return ret; - } - - public void close() - throws IOException - { - byte[] buf = new byte[] - { - EOF, /* eof descriptor */ - 0x00, 0x00 /* no bytes */ - }; - out.write(buf, 0, 3); - out.close(); - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/DTP.java b/libjava/gnu/java/net/protocol/ftp/DTP.java deleted file mode 100644 index 25580af403a..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/DTP.java +++ /dev/null @@ -1,92 +0,0 @@ -/* DTP.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * An FTP data transfer process. - * - * @author Chris Burdess (dog@gnu.org) - */ -interface DTP -{ - - /** - * Returns an input stream from which a remote file can be read. - */ - InputStream getInputStream() - throws IOException; - - /** - * Returns an output stream to which a local file can be written for - * upload. - */ - OutputStream getOutputStream() - throws IOException; - - /** - * Sets the transfer mode to be used with this DTP. - */ - void setTransferMode(int mode); - - /** - * Marks this DTP completed. - * When the current transfer has finished, any resources will be released. - */ - void complete(); - - /** - * Aborts any current transfer and releases all resources held by this - * DTP. - * @return true if a transfer was interrupted, false otherwise - */ - boolean abort(); - - /** - * Used to notify the DTP that its current transfer is complete. - * This occurs either when end-of-stream is reached or a 226 response is - * received. - */ - void transferComplete(); - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/DTPInputStream.java b/libjava/gnu/java/net/protocol/ftp/DTPInputStream.java deleted file mode 100644 index 363a5590fbb..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/DTPInputStream.java +++ /dev/null @@ -1,88 +0,0 @@ -/* DTPInputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * An input stream that notifies a DTP on completion. - * - * @author Chris Burdess (dog@gnu.org) - */ -abstract class DTPInputStream - extends FilterInputStream -{ - - DTP dtp; - boolean transferComplete; - - /** - * Constructor. - * @param dtp the controlling data transfer process - * @param in the underlying socket stream - */ - DTPInputStream (DTP dtp, InputStream in) - { - super(in); - this.dtp = dtp; - transferComplete = false; - } - - /** - * Marks this input stream complete. - * This is called by the DTP. - */ - void setTransferComplete(boolean flag) - { - transferComplete = flag; - } - - /** - * Notifies the controlling DTP that this stream has completed transfer. - */ - public void close() - throws IOException - { - dtp.transferComplete(); - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/DTPOutputStream.java b/libjava/gnu/java/net/protocol/ftp/DTPOutputStream.java deleted file mode 100644 index 83f0be1e30d..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/DTPOutputStream.java +++ /dev/null @@ -1,85 +0,0 @@ -/* DTPOutputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * An output stream that notifies a DTP on end of stream. - * - * @author Chris Burdess (dog@gnu.org) - */ -abstract class DTPOutputStream extends FilterOutputStream -{ - - DTP dtp; - boolean transferComplete; - - /** - * Constructor. - * @param dtp the controlling data transfer process - * @param out the socket output stream - */ - DTPOutputStream (DTP dtp, OutputStream out) - { - super (out); - this.dtp = dtp; - transferComplete = false; - } - - /** - * Tells this stream whether transfer has completed or not. - * @param flag true if the process has completed, false otherwise - */ - void setTransferComplete (boolean flag) - { - transferComplete = flag; - } - - /** - * Notifies the controlling DTP that this stream has been terminated. - */ - public void close () throws IOException - { - dtp.transferComplete (); - } - -} diff --git a/libjava/gnu/java/net/protocol/ftp/FTPConnection.java b/libjava/gnu/java/net/protocol/ftp/FTPConnection.java deleted file mode 100644 index d0f48727cfa..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/FTPConnection.java +++ /dev/null @@ -1,1348 +0,0 @@ -/* FTPConnection.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import gnu.java.net.CRLFInputStream; -import gnu.java.net.CRLFOutputStream; -import gnu.java.net.EmptyX509TrustManager; -import gnu.java.net.LineInputStream; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.BindException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ProtocolException; -import java.net.Socket; -import java.net.UnknownHostException; -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.List; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; - -/** - * An FTP client connection, or PI. - * This implements RFC 959, with the following exceptions: - * <ul> - * <li>STAT, HELP, SITE, SMNT, and ACCT commands are not supported.</li> - * <li>the TYPE command does not allow alternatives to the default bytesize - * (Non-print), and local bytesize is not supported.</li> - * </ul> - * - * @author Chris Burdess (dog@gnu.org) - */ -public class FTPConnection -{ - - /** - * The default FTP transmission control port. - */ - public static final int FTP_PORT = 21; - - /** - * The FTP data port. - */ - public static final int FTP_DATA_PORT = 20; - - // -- FTP vocabulary -- - protected static final String USER = "USER"; - protected static final String PASS = "PASS"; - protected static final String ACCT = "ACCT"; - protected static final String CWD = "CWD"; - protected static final String CDUP = "CDUP"; - protected static final String SMNT = "SMNT"; - protected static final String REIN = "REIN"; - protected static final String QUIT = "QUIT"; - - protected static final String PORT = "PORT"; - protected static final String PASV = "PASV"; - protected static final String TYPE = "TYPE"; - protected static final String STRU = "STRU"; - protected static final String MODE = "MODE"; - - protected static final String RETR = "RETR"; - protected static final String STOR = "STOR"; - protected static final String STOU = "STOU"; - protected static final String APPE = "APPE"; - protected static final String ALLO = "ALLO"; - protected static final String REST = "REST"; - protected static final String RNFR = "RNFR"; - protected static final String RNTO = "RNTO"; - protected static final String ABOR = "ABOR"; - protected static final String DELE = "DELE"; - protected static final String RMD = "RMD"; - protected static final String MKD = "MKD"; - protected static final String PWD = "PWD"; - protected static final String LIST = "LIST"; - protected static final String NLST = "NLST"; - protected static final String SITE = "SITE"; - protected static final String SYST = "SYST"; - protected static final String STAT = "STAT"; - protected static final String HELP = "HELP"; - protected static final String NOOP = "NOOP"; - - protected static final String AUTH = "AUTH"; - protected static final String PBSZ = "PBSZ"; - protected static final String PROT = "PROT"; - protected static final String CCC = "CCC"; - protected static final String TLS = "TLS"; - - public static final int TYPE_ASCII = 1; - public static final int TYPE_EBCDIC = 2; - public static final int TYPE_BINARY = 3; - - public static final int STRUCTURE_FILE = 1; - public static final int STRUCTURE_RECORD = 2; - public static final int STRUCTURE_PAGE = 3; - - public static final int MODE_STREAM = 1; - public static final int MODE_BLOCK = 2; - public static final int MODE_COMPRESSED = 3; - - // -- Telnet constants -- - private static final String US_ASCII = "US-ASCII"; - - /** - * The socket used to communicate with the server. - */ - protected Socket socket; - - /** - * The socket input stream. - */ - protected LineInputStream in; - - /** - * The socket output stream. - */ - protected CRLFOutputStream out; - - /** - * The timeout when attempting to connect a socket. - */ - protected int connectionTimeout; - - /** - * The read timeout on sockets. - */ - protected int timeout; - - /** - * If true, print debugging information. - */ - protected boolean debug; - - /** - * The current data transfer process in use by this connection. - */ - protected DTP dtp; - - /** - * The current representation type. - */ - protected int representationType = TYPE_ASCII; - - /** - * The current file structure type. - */ - protected int fileStructure = STRUCTURE_FILE; - - /** - * The current transfer mode. - */ - protected int transferMode = MODE_STREAM; - - /** - * If true, use passive mode. - */ - protected boolean passive = false; - - /** - * Creates a new connection to the server using the default port. - * @param hostname the hostname of the server to connect to - */ - public FTPConnection(String hostname) - throws UnknownHostException, IOException - { - this(hostname, -1, 0, 0, false); - } - - /** - * Creates a new connection to the server. - * @param hostname the hostname of the server to connect to - * @param port the port to connect to(if <=0, use default port) - */ - public FTPConnection(String hostname, int port) - throws UnknownHostException, IOException - { - this(hostname, port, 0, 0, false); - } - - /** - * Creates a new connection to the server. - * @param hostname the hostname of the server to connect to - * @param port the port to connect to(if <=0, use default port) - * @param connectionTimeout the connection timeout, in milliseconds - * @param timeout the I/O timeout, in milliseconds - * @param debug print debugging information - */ - public FTPConnection(String hostname, int port, - int connectionTimeout, int timeout, boolean debug) - throws UnknownHostException, IOException - { - this.connectionTimeout = connectionTimeout; - this.timeout = timeout; - this.debug = debug; - if (port <= 0) - { - port = FTP_PORT; - } - - // Set up socket - socket = new Socket(); - InetSocketAddress address = new InetSocketAddress(hostname, port); - if (connectionTimeout > 0) - { - socket.connect(address, connectionTimeout); - } - else - { - socket.connect(address); - } - if (timeout > 0) - { - socket.setSoTimeout(timeout); - } - - InputStream in = socket.getInputStream(); - in = new BufferedInputStream(in); - in = new CRLFInputStream(in); - this.in = new LineInputStream(in); - OutputStream out = socket.getOutputStream(); - out = new BufferedOutputStream(out); - this.out = new CRLFOutputStream(out); - - // Read greeting - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 220: // hello - break; - default: - throw new FTPException(response); - } - } - - /** - * Authenticate using the specified username and password. - * If the username suffices for the server, the password will not be used - * and may be null. - * @param username the username - * @param password the optional password - * @return true on success, false otherwise - */ - public boolean authenticate(String username, String password) - throws IOException - { - String cmd = USER + ' ' + username; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 230: // User logged in - return true; - case 331: // User name okay, need password - break; - case 332: // Need account for login - case 530: // No such user - return false; - default: - throw new FTPException(response); - } - cmd = PASS + ' ' + password; - send(cmd); - response = getResponse(); - switch (response.getCode()) - { - case 230: // User logged in - case 202: // Superfluous - return true; - case 332: // Need account for login - case 530: // Bad password - return false; - default: - throw new FTPException(response); - } - } - - /** - * Negotiates TLS over the current connection. - * See IETF draft-murray-auth-ftp-ssl-15.txt for details. - * @param confidential whether to provide confidentiality for the - * connection - */ - public boolean starttls(boolean confidential) - throws IOException - { - return starttls(confidential, new EmptyX509TrustManager()); - } - - /** - * Negotiates TLS over the current connection. - * See IETF draft-murray-auth-ftp-ssl-15.txt for details. - * @param confidential whether to provide confidentiality for the - * connection - * @param tm the trust manager used to validate the server certificate. - */ - public boolean starttls(boolean confidential, TrustManager tm) - throws IOException - { - try - { - // Use SSLSocketFactory to negotiate a TLS session and wrap the - // current socket. - SSLContext context = SSLContext.getInstance("TLS"); - // We don't require strong validation of the server certificate - TrustManager[] trust = new TrustManager[] { tm }; - context.init(null, trust, null); - SSLSocketFactory factory = context.getSocketFactory(); - - send(AUTH + ' ' + TLS); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 500: - case 502: - case 504: - case 534: - case 431: - return false; - case 234: - break; - default: - throw new FTPException(response); - } - - String hostname = socket.getInetAddress().getHostName(); - int port = socket.getPort(); - SSLSocket ss = - (SSLSocket) factory.createSocket(socket, hostname, port, true); - String[] protocols = { "TLSv1", "SSLv3" }; - ss.setEnabledProtocols(protocols); - ss.setUseClientMode(true); - ss.startHandshake(); - - // PBSZ:PROT sequence - send(PBSZ + ' ' + Integer.MAX_VALUE); - response = getResponse(); - switch (response.getCode()) - { - case 501: // syntax error - case 503: // not authenticated - return false; - case 200: - break; - default: - throw new FTPException(response); - } - send(PROT + ' ' +(confidential ? 'P' : 'C')); - response = getResponse(); - switch (response.getCode()) - { - case 503: // not authenticated - case 504: // invalid level - case 536: // level not supported - return false; - case 200: - break; - default: - throw new FTPException(response); - } - - if (confidential) - { - // Set up streams - InputStream in = ss.getInputStream(); - in = new BufferedInputStream(in); - in = new CRLFInputStream(in); - this.in = new LineInputStream(in); - OutputStream out = ss.getOutputStream(); - out = new BufferedOutputStream(out); - this.out = new CRLFOutputStream(out); - } - return true; - } - catch (GeneralSecurityException e) - { - return false; - } - } - - /** - * Changes directory to the specified path. - * @param path an absolute or relative pathname - * @return true on success, false if the specified path does not exist - */ - public boolean changeWorkingDirectory(String path) - throws IOException - { - String cmd = CWD + ' ' + path; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 250: - return true; - case 550: - return false; - default: - throw new FTPException(response); - } - } - - /** - * Changes directory to the parent of the current working directory. - * @return true on success, false otherwise - */ - public boolean changeToParentDirectory() - throws IOException - { - send(CDUP); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 250: - return true; - case 550: - return false; - default: - throw new FTPException(response); - } - } - - /** - * Terminates an authenticated login. - * If file transfer is in progress, it remains active for result response - * only. - */ - public void reinitialize() - throws IOException - { - send(REIN); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 220: - if (dtp != null) - { - dtp.complete(); - dtp = null; - } - break; - default: - throw new FTPException(response); - } - } - - /** - * Terminates the control connection. - * The file transfer connection remains open for result response only. - * This connection is invalid and no further commands may be issued. - */ - public void logout() - throws IOException - { - send(QUIT); - try - { - getResponse(); // not required - } - catch (IOException e) - { - } - if (dtp != null) - { - dtp.complete(); - dtp = null; - } - try - { - socket.close(); - } - catch (IOException e) - { - } - } - - /** - * Initialise the data transfer process. - */ - protected void initialiseDTP() - throws IOException - { - if (dtp != null) - { - dtp.complete(); - dtp = null; - } - - InetAddress localhost = socket.getLocalAddress(); - if (passive) - { - send(PASV); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 227: - String message = response.getMessage(); - try - { - int start = message.indexOf(','); - char c = message.charAt(start - 1); - while (c >= 0x30 && c <= 0x39) - { - c = message.charAt((--start) - 1); - } - int mid1 = start; - for (int i = 0; i < 4; i++) - { - mid1 = message.indexOf(',', mid1 + 1); - } - int mid2 = message.indexOf(',', mid1 + 1); - if (mid1 == -1 || mid2 < mid1) - { - throw new ProtocolException("Malformed 227: " + - message); - } - int end = mid2; - c = message.charAt(end + 1); - while (c >= 0x30 && c <= 0x39) - { - c = message.charAt((++end) + 1); - } - - String address = - message.substring(start, mid1).replace(',', '.'); - int port_hi = - Integer.parseInt(message.substring(mid1 + 1, mid2)); - int port_lo = - Integer.parseInt(message.substring(mid2 + 1, end + 1)); - int port = (port_hi << 8) | port_lo; - - /*System.out.println("Entering passive mode: " + address + - ":" + port);*/ - dtp = new PassiveModeDTP(address, port, localhost, - connectionTimeout, timeout); - break; - } - catch (ArrayIndexOutOfBoundsException e) - { - throw new ProtocolException(e.getMessage() + ": " + - message); - } - catch (NumberFormatException e) - { - throw new ProtocolException(e.getMessage() + ": " + - message); - } - default: - throw new FTPException(response); - } - } - else - { - // Get the local port - int port = socket.getLocalPort() + 1; - int tries = 0; - // Bind the active mode DTP - while (dtp == null) - { - try - { - dtp = new ActiveModeDTP(localhost, port, - connectionTimeout, timeout); - /*System.out.println("Listening on: " + port);*/ - } - catch (BindException e) - { - port++; - tries++; - if (tries > 9) - { - throw e; - } - } - } - - // Send PORT command - StringBuffer buf = new StringBuffer(PORT); - buf.append(' '); - // Construct the address/port string form - byte[] address = localhost.getAddress(); - for (int i = 0; i < address.length; i++) - { - int a =(int) address[i]; - if (a < 0) - { - a += 0x100; - } - buf.append(a); - buf.append(','); - } - int port_hi =(port & 0xff00) >> 8; - int port_lo =(port & 0x00ff); - buf.append(port_hi); - buf.append(','); - buf.append(port_lo); - send(buf.toString()); - // Get response - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: // OK - break; - default: - dtp.abort(); - dtp = null; - throw new FTPException(response); - } - } - dtp.setTransferMode(transferMode); - } - - /** - * Set passive mode. - * @param flag true if we should use passive mode, false otherwise - */ - public void setPassive(boolean flag) - throws IOException - { - if (passive != flag) - { - passive = flag; - initialiseDTP(); - } - } - - /** - * Returns the current representation type of the transfer data. - * @return TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY - */ - public int getRepresentationType() - { - return representationType; - } - - /** - * Sets the desired representation type of the transfer data. - * @param type TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY - */ - public void setRepresentationType(int type) - throws IOException - { - StringBuffer buf = new StringBuffer(TYPE); - buf.append(' '); - switch (type) - { - case TYPE_ASCII: - buf.append('A'); - break; - case TYPE_EBCDIC: - buf.append('E'); - break; - case TYPE_BINARY: - buf.append('I'); - break; - default: - throw new IllegalArgumentException(Integer.toString(type)); - } - //buf.append(' '); - //buf.append('N'); - send(buf.toString()); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: - representationType = type; - break; - default: - throw new FTPException(response); - } - } - - /** - * Returns the current file structure type. - * @return STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE - */ - public int getFileStructure() - { - return fileStructure; - } - - /** - * Sets the desired file structure type. - * @param structure STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE - */ - public void setFileStructure(int structure) - throws IOException - { - StringBuffer buf = new StringBuffer(STRU); - buf.append(' '); - switch (structure) - { - case STRUCTURE_FILE: - buf.append('F'); - break; - case STRUCTURE_RECORD: - buf.append('R'); - break; - case STRUCTURE_PAGE: - buf.append('P'); - break; - default: - throw new IllegalArgumentException(Integer.toString(structure)); - } - send(buf.toString()); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: - fileStructure = structure; - break; - default: - throw new FTPException(response); - } - } - - /** - * Returns the current transfer mode. - * @return MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED - */ - public int getTransferMode() - { - return transferMode; - } - - /** - * Sets the desired transfer mode. - * @param mode MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED - */ - public void setTransferMode(int mode) - throws IOException - { - StringBuffer buf = new StringBuffer(MODE); - buf.append(' '); - switch (mode) - { - case MODE_STREAM: - buf.append('S'); - break; - case MODE_BLOCK: - buf.append('B'); - break; - case MODE_COMPRESSED: - buf.append('C'); - break; - default: - throw new IllegalArgumentException(Integer.toString(mode)); - } - send(buf.toString()); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: - transferMode = mode; - if (dtp != null) - { - dtp.setTransferMode(mode); - } - break; - default: - throw new FTPException(response); - } - } - - /** - * Retrieves the specified file. - * @param filename the filename of the file to retrieve - * @return an InputStream containing the file content - */ - public InputStream retrieve(String filename) - throws IOException - { - if (dtp == null || transferMode == MODE_STREAM) - { - initialiseDTP(); - } - /* - int size = -1; - String cmd = SIZE + ' ' + filename; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 213: - size = Integer.parseInt(response.getMessage()); - break; - case 550: // File not found - default: - throw new FTPException(response); - } - */ - String cmd = RETR + ' ' + filename; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 125: // Data connection already open; transfer starting - case 150: // File status okay; about to open data connection - return dtp.getInputStream(); - default: - throw new FTPException(response); - } - } - - /** - * Returns a stream for uploading a file. - * If a file with the same filename already exists on the server, it will - * be overwritten. - * @param filename the name of the file to save the content as - * @return an OutputStream to write the file data to - */ - public OutputStream store(String filename) - throws IOException - { - if (dtp == null || transferMode == MODE_STREAM) - { - initialiseDTP(); - } - String cmd = STOR + ' ' + filename; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 125: // Data connection already open; transfer starting - case 150: // File status okay; about to open data connection - return dtp.getOutputStream(); - default: - throw new FTPException(response); - } - } - - /** - * Returns a stream for uploading a file. - * If a file with the same filename already exists on the server, the - * content specified will be appended to the existing file. - * @param filename the name of the file to save the content as - * @return an OutputStream to write the file data to - */ - public OutputStream append(String filename) - throws IOException - { - if (dtp == null || transferMode == MODE_STREAM) - { - initialiseDTP(); - } - String cmd = APPE + ' ' + filename; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 125: // Data connection already open; transfer starting - case 150: // File status okay; about to open data connection - return dtp.getOutputStream(); - default: - throw new FTPException(response); - } - } - - /** - * This command may be required by some servers to reserve sufficient - * storage to accommodate the new file to be transferred. - * It should be immediately followed by a <code>store</code> or - * <code>append</code>. - * @param size the number of bytes of storage to allocate - */ - public void allocate(long size) - throws IOException - { - String cmd = ALLO + ' ' + size; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: // OK - case 202: // Superfluous - break; - default: - throw new FTPException(response); - } - } - - /** - * Renames a file. - * @param oldName the current name of the file - * @param newName the new name - * @return true if successful, false otherwise - */ - public boolean rename(String oldName, String newName) - throws IOException - { - String cmd = RNFR + ' ' + oldName; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 450: // File unavailable - case 550: // File not found - return false; - case 350: // Pending - break; - default: - throw new FTPException(response); - } - cmd = RNTO + ' ' + newName; - send(cmd); - response = getResponse(); - switch (response.getCode()) - { - case 250: // OK - return true; - case 450: - case 550: - return false; - default: - throw new FTPException(response); - } - } - - /** - * Aborts the transfer in progress. - * @return true if a transfer was in progress, false otherwise - */ - public boolean abort() - throws IOException - { - send(ABOR); - FTPResponse response = getResponse(); - // Abort client DTP - if (dtp != null) - { - dtp.abort(); - } - switch (response.getCode()) - { - case 226: // successful abort - return false; - case 426: // interrupted - response = getResponse(); - if (response.getCode() == 226) - { - return true; - } - // Otherwise fall through to throw exception - default: - throw new FTPException(response); - } - } - - /** - * Causes the file specified to be deleted at the server site. - * @param filename the file to delete - */ - public boolean delete(String filename) - throws IOException - { - String cmd = DELE + ' ' + filename; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 250: // OK - return true; - case 450: // File unavailable - case 550: // File not found - return false; - default: - throw new FTPException(response); - } - } - - /** - * Causes the directory specified to be deleted. - * This may be an absolute or relative pathname. - * @param pathname the directory to delete - */ - public boolean removeDirectory(String pathname) - throws IOException - { - String cmd = RMD + ' ' + pathname; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 250: // OK - return true; - case 550: // File not found - return false; - default: - throw new FTPException(response); - } - } - - /** - * Causes the directory specified to be created at the server site. - * This may be an absolute or relative pathname. - * @param pathname the directory to create - */ - public boolean makeDirectory(String pathname) - throws IOException - { - String cmd = MKD + ' ' + pathname; - send(cmd); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 257: // Directory created - return true; - case 550: // File not found - return false; - default: - throw new FTPException(response); - } - } - - /** - * Returns the current working directory. - */ - public String getWorkingDirectory() - throws IOException - { - send(PWD); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 257: - String message = response.getMessage(); - if (message.charAt(0) == '"') - { - int end = message.indexOf('"', 1); - if (end == -1) - { - throw new ProtocolException(message); - } - return message.substring(1, end); - } - else - { - int end = message.indexOf(' '); - if (end == -1) - { - return message; - } - else - { - return message.substring(0, end); - } - } - default: - throw new FTPException(response); - } - } - - /** - * Returns a listing of information about the specified pathname. - * If the pathname specifies a directory or other group of files, the - * server should transfer a list of files in the specified directory. - * If the pathname specifies a file then the server should send current - * information on the file. A null argument implies the user's - * current working or default directory. - * @param pathname the context pathname, or null - */ - public InputStream list(String pathname) - throws IOException - { - if (dtp == null || transferMode == MODE_STREAM) - { - initialiseDTP(); - } - if (pathname == null) - { - send(LIST); - } - else - { - String cmd = LIST + ' ' + pathname; - send(cmd); - } - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 125: // Data connection already open; transfer starting - case 150: // File status okay; about to open data connection - return dtp.getInputStream(); - default: - throw new FTPException(response); - } - } - - /** - * Returns a directory listing. The pathname should specify a - * directory or other system-specific file group descriptor; a null - * argument implies the user's current working or default directory. - * @param pathname the directory pathname, or null - * @return a list of filenames(strings) - */ - public List nameList(String pathname) - throws IOException - { - if (dtp == null || transferMode == MODE_STREAM) - { - initialiseDTP(); - } - if (pathname == null) - { - send(NLST); - } - else - { - String cmd = NLST + ' ' + pathname; - send(cmd); - } - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 125: // Data connection already open; transfer starting - case 150: // File status okay; about to open data connection - InputStream in = dtp.getInputStream(); - in = new BufferedInputStream(in); - in = new CRLFInputStream(in); // TODO ensure that TYPE is correct - LineInputStream li = new LineInputStream(in); - List ret = new ArrayList(); - for (String line = li.readLine(); - line != null; - line = li.readLine()) - { - ret.add(line); - } - li.close(); - return ret; - default: - throw new FTPException(response); - } - } - - /** - * Returns the type of operating system at the server. - */ - public String system() - throws IOException - { - send(SYST); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 215: - String message = response.getMessage(); - int end = message.indexOf(' '); - if (end == -1) - { - return message; - } - else - { - return message.substring(0, end); - } - default: - throw new FTPException(response); - } - } - - /** - * Does nothing. - * This method can be used to ensure that the connection does not time - * out. - */ - public void noop() - throws IOException - { - send(NOOP); - FTPResponse response = getResponse(); - switch (response.getCode()) - { - case 200: - break; - default: - throw new FTPException(response); - } - } - - // -- I/O -- - - /** - * Sends the specified command line to the server. - * The CRLF sequence is automatically appended. - * @param cmd the command line to send - */ - protected void send(String cmd) - throws IOException - { - byte[] data = cmd.getBytes(US_ASCII); - out.write(data); - out.writeln(); - out.flush(); - } - - /** - * Reads the next response from the server. - * If the server sends the "transfer complete" code, this is handled here, - * and the next response is passed to the caller. - */ - protected FTPResponse getResponse() - throws IOException - { - FTPResponse response = readResponse(); - if (response.getCode() == 226) - { - if (dtp != null) - { - dtp.transferComplete(); - } - response = readResponse(); - } - return response; - } - - /** - * Reads and parses the next response from the server. - */ - protected FTPResponse readResponse() - throws IOException - { - String line = in.readLine(); - if (line == null) - { - throw new ProtocolException( "EOF"); - } - if (line.length() < 4) - { - throw new ProtocolException(line); - } - int code = parseCode(line); - if (code == -1) - { - throw new ProtocolException(line); - } - char c = line.charAt(3); - if (c == ' ') - { - return new FTPResponse(code, line.substring(4)); - } - else if (c == '-') - { - StringBuffer buf = new StringBuffer(line.substring(4)); - buf.append('\n'); - while(true) - { - line = in.readLine(); - if (line == null) - { - throw new ProtocolException("EOF"); - } - if (line.length() >= 4 && - line.charAt(3) == ' ' && - parseCode(line) == code) - { - return new FTPResponse(code, line.substring(4), - buf.toString()); - } - else - { - buf.append(line); - buf.append('\n'); - } - } - } - else - { - throw new ProtocolException(line); - } - } - - /* - * Parses the 3-digit numeric code at the beginning of the given line. - * Returns -1 on failure. - */ - static final int parseCode(String line) - { - char[] c = { line.charAt(0), line.charAt(1), line.charAt(2) }; - int ret = 0; - for (int i = 0; i < 3; i++) - { - int digit =((int) c[i]) - 0x30; - if (digit < 0 || digit > 9) - { - return -1; - } - // Computing integer powers is way too expensive in Java! - switch (i) - { - case 0: - ret +=(100 * digit); - break; - case 1: - ret +=(10 * digit); - break; - case 2: - ret += digit; - break; - } - } - return ret; - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/FTPException.java b/libjava/gnu/java/net/protocol/ftp/FTPException.java deleted file mode 100644 index 14ad3813f85..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/FTPException.java +++ /dev/null @@ -1,76 +0,0 @@ -/* FTPException.java -- - Copyright (C) 2003. 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; - -/** - * An FTP control exception. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class FTPException - extends IOException -{ - - /** - * The response that provoked this exception. - */ - protected final FTPResponse response; - - /** - * Constructs a new FTP exception. - * @param response the response that provoked this exception - */ - public FTPException(FTPResponse response) - { - super(response.getMessage()); - this.response = response; - } - - /** - * Returns the response that provoked this exception. - */ - public FTPResponse getResponse() - { - return response; - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/FTPResponse.java b/libjava/gnu/java/net/protocol/ftp/FTPResponse.java deleted file mode 100644 index ec72c732c1c..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/FTPResponse.java +++ /dev/null @@ -1,112 +0,0 @@ -/* FTPResponse.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -/** - * An FTP control response. - * - * @author Chris Burdess (dog@gnu.org) - */ -public final class FTPResponse -{ - - /** - * The 3-digit status code. - */ - protected final int code; - - /** - * The human-readable message. - */ - protected final String message; - - /** - * Multiline data, if present. - */ - protected final String data; - - /** - * Constructs a new FTP response. - * @param code the status code - * @param message the message - */ - public FTPResponse(int code, String message) - { - this(code, message, null); - } - - /** - * Constructs a new multiline FTP response. - * @param code the status code - * @param message the message - * @param data multiline data - */ - public FTPResponse(int code, String message, String data) - { - this.code = code; - this.message = message; - this.data = data; - } - - /** - * Returns the 3-digit status code. - */ - public int getCode() - { - return code; - } - - /** - * Returns the human-readable message. - */ - public String getMessage() - { - return message; - } - - /** - * Returns the multiline data, or null if there was no such data. - */ - public String getData() - { - return data; - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/FTPURLConnection.java b/libjava/gnu/java/net/protocol/ftp/FTPURLConnection.java deleted file mode 100644 index 62c40f19e04..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/FTPURLConnection.java +++ /dev/null @@ -1,398 +0,0 @@ -/* FTPURLConnection.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import gnu.java.net.GetLocalHostAction; -import gnu.java.security.action.GetPropertyAction; - -import java.io.FileNotFoundException; -import java.io.FilterInputStream; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.URL; -import java.net.URLConnection; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.Map; - -/** - * An FTP URL connection. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class FTPURLConnection - extends URLConnection -{ - - /** - * The connection managing the protocol exchange. - */ - protected FTPConnection connection; - - protected boolean passive; - protected int representationType; - protected int fileStructure; - protected int transferMode; - - /** - * Constructs an FTP connection to the specified URL. - * @param url the URL - */ - public FTPURLConnection(URL url) - { - super(url); - passive = true; - representationType = FTPConnection.TYPE_BINARY; - fileStructure = -1; - transferMode = -1; - } - - /** - * Establishes the connection. - */ - public void connect() - throws IOException - { - if (connected) - { - return; - } - String host = url.getHost(); - int port = url.getPort(); - String username = url.getUserInfo(); - String password = null; - if (username != null) - { - int ci = username.indexOf(':'); - if (ci != -1) - { - password = username.substring(ci + 1); - username = username.substring(0, ci); - } - } - else - { - username = "anonymous"; - PrivilegedAction a = new GetPropertyAction("user.name"); - String systemUsername =(String) AccessController.doPrivileged(a); - a = new GetLocalHostAction(); - InetAddress localhost =(InetAddress) AccessController.doPrivileged(a); - password = systemUsername + "@" + - ((localhost == null) ? "localhost" : localhost.getHostName()); - } - connection = new FTPConnection(host, port); - if (!connection.authenticate(username, password)) - { - throw new SecurityException("Authentication failed"); - } - connection.setPassive(passive); - if (representationType != -1) - { - connection.setRepresentationType(representationType); - } - if (fileStructure != -1) - { - connection.setFileStructure(fileStructure); - } - if (transferMode != -1) - { - connection.setTransferMode(transferMode); - } - } - - /** - * This connection supports doInput. - */ - public void setDoInput(boolean doinput) - { - doInput = doinput; - } - - /** - * This connection supports doOutput. - */ - public void setDoOutput(boolean dooutput) - { - doOutput = dooutput; - } - - /** - * Returns an input stream that reads from this open connection. - */ - public InputStream getInputStream() - throws IOException - { - if (!connected) - { - connect(); - } - String path = url.getPath(); - String filename = null; - int lsi = path.lastIndexOf('/'); - if (lsi != -1) - { - filename = path.substring(lsi + 1); - path = path.substring(0, lsi); - if (!connection.changeWorkingDirectory(path)) - { - throw new FileNotFoundException(path); - } - } - if (filename != null && filename.length() > 0) - { - return this.new ClosingInputStream(connection.retrieve(filename)); - } - else - { - return this.new ClosingInputStream(connection.list(null)); - } - } - - /** - * Returns an output stream that writes to this connection. - */ - public OutputStream getOutputStream() - throws IOException - { - if (!connected) - { - connect(); - } - String dir = url.getPath(); - String filename = url.getFile(); - if (!connection.changeWorkingDirectory(dir)) - { - throw new FileNotFoundException(dir); - } - if (filename != null) - { - return this.new ClosingOutputStream(connection.store(filename)); - } - else - { - throw new FileNotFoundException(filename); - } - } - - public String getRequestProperty(String key) - { - if ("passive".equals(key)) - { - return Boolean.toString(passive); - } - else if ("representationType".equals(key)) - { - switch (representationType) - { - case FTPConnection.TYPE_ASCII: - return "ASCII"; - case FTPConnection.TYPE_EBCDIC: - return "EBCDIC"; - case FTPConnection.TYPE_BINARY: - return "BINARY"; - } - } - else if ("fileStructure".equals(key)) - { - switch (fileStructure) - { - case FTPConnection.STRUCTURE_FILE: - return "FILE"; - case FTPConnection.STRUCTURE_RECORD: - return "RECORD"; - case FTPConnection.STRUCTURE_PAGE: - return "PAGE"; - } - } - else if ("transferMode".equals(key)) - { - switch (transferMode) - { - case FTPConnection.MODE_STREAM: - return "STREAM"; - case FTPConnection.MODE_BLOCK: - return "BLOCK"; - case FTPConnection.MODE_COMPRESSED: - return "COMPRESSED"; - } - } - return null; - } - - public Map getRequestProperties() - { - Map map = new HashMap(); - addRequestPropertyValue(map, "passive"); - addRequestPropertyValue(map, "representationType"); - addRequestPropertyValue(map, "fileStructure"); - addRequestPropertyValue(map, "transferMode"); - return map; - } - - private void addRequestPropertyValue(Map map, String key) - { - String value = getRequestProperty(key); - map.put(key, value); - } - - public void setRequestProperty(String key, String value) - { - if (connected) - { - throw new IllegalStateException(); - } - if ("passive".equals(key)) - { - passive = Boolean.valueOf(value).booleanValue(); - } - else if ("representationType".equals(key)) - { - if ("A".equalsIgnoreCase(value) || - "ASCII".equalsIgnoreCase(value)) - { - representationType = FTPConnection.TYPE_ASCII; - } - else if ("E".equalsIgnoreCase(value) || - "EBCDIC".equalsIgnoreCase(value)) - { - representationType = FTPConnection.TYPE_EBCDIC; - } - else if ("I".equalsIgnoreCase(value) || - "BINARY".equalsIgnoreCase(value)) - { - representationType = FTPConnection.TYPE_BINARY; - } - else - { - throw new IllegalArgumentException(value); - } - } - else if ("fileStructure".equals(key)) - { - if ("F".equalsIgnoreCase(value) || - "FILE".equalsIgnoreCase(value)) - { - fileStructure = FTPConnection.STRUCTURE_FILE; - } - else if ("R".equalsIgnoreCase(value) || - "RECORD".equalsIgnoreCase(value)) - { - fileStructure = FTPConnection.STRUCTURE_RECORD; - } - else if ("P".equalsIgnoreCase(value) || - "PAGE".equalsIgnoreCase(value)) - { - fileStructure = FTPConnection.STRUCTURE_PAGE; - } - else - { - throw new IllegalArgumentException(value); - } - } - else if ("transferMode".equals(key)) - { - if ("S".equalsIgnoreCase(value) || - "STREAM".equalsIgnoreCase(value)) - { - transferMode = FTPConnection.MODE_STREAM; - } - else if ("B".equalsIgnoreCase(value) || - "BLOCK".equalsIgnoreCase(value)) - { - transferMode = FTPConnection.MODE_BLOCK; - } - else if ("C".equalsIgnoreCase(value) || - "COMPRESSED".equalsIgnoreCase(value)) - { - transferMode = FTPConnection.MODE_COMPRESSED; - } - else - { - throw new IllegalArgumentException(value); - } - } - } - - public void addRequestProperty(String key, String value) - { - setRequestProperty(key, value); - } - - class ClosingInputStream - extends FilterInputStream - { - - ClosingInputStream(InputStream in) - { - super(in); - } - - public void close() - throws IOException - { - super.close(); - connection.logout(); - } - - } - - class ClosingOutputStream - extends FilterOutputStream - { - - ClosingOutputStream(OutputStream out) - { - super(out); - } - - public void close() - throws IOException - { - super.close(); - connection.logout(); - } - - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/Handler.java b/libjava/gnu/java/net/protocol/ftp/Handler.java deleted file mode 100644 index 88491b3c15a..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/Handler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* Handler.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * An FTP URL stream handler. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Handler - extends URLStreamHandler -{ - - protected int getDefaultPort() - { - return FTPConnection.FTP_PORT; - } - - /** - * Returns an FTPURLConnection for the given URL. - */ - public URLConnection openConnection(URL url) - throws IOException - { - return new FTPURLConnection(url); - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/PassiveModeDTP.java b/libjava/gnu/java/net/protocol/ftp/PassiveModeDTP.java deleted file mode 100644 index 6f4fd634168..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/PassiveModeDTP.java +++ /dev/null @@ -1,201 +0,0 @@ -/* PassiveModeDTP.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; - -/** - * A passive mode FTP data transfer process. - * This connects to the host specified and proxies the resulting socket's - * input and output streams. - * - * @author Chris Burdess (dog@gnu.org) - */ -final class PassiveModeDTP - implements DTP -{ - - final String address; - final int port; - Socket socket; - DTPInputStream in; - DTPOutputStream out; - boolean completed; - boolean inProgress; - int transferMode; - - PassiveModeDTP(String address, int port, InetAddress localhost, - int connectionTimeout, int timeout) - throws IOException - { - this.address = address; - this.port = port; - completed = false; - inProgress = false; - socket = new Socket(); - InetSocketAddress remote = new InetSocketAddress(address, port); - InetSocketAddress local = new InetSocketAddress(localhost, port + 1); - socket.bind(local); - if (connectionTimeout > 0) - { - socket.connect(remote, connectionTimeout); - } - else - { - socket.connect(remote); - } - if (timeout > 0) - { - socket.setSoTimeout(timeout); - } - } - - /** - * Returns an input stream from which a remote file can be read. - */ - public InputStream getInputStream() - throws IOException - { - if (inProgress) - { - throw new IOException("Transfer in progress"); - } - switch (transferMode) - { - case FTPConnection.MODE_STREAM: - in = new StreamInputStream(this, socket.getInputStream()); - break; - case FTPConnection.MODE_BLOCK: - in = new BlockInputStream(this, socket.getInputStream()); - break; - case FTPConnection.MODE_COMPRESSED: - in = new CompressedInputStream(this, socket.getInputStream()); - break; - default: - throw new IllegalStateException("Invalid transfer mode"); - } - in.setTransferComplete(false); - return in; - } - - /** - * Returns an output stream to which a local file can be written for - * upload. - */ - public OutputStream getOutputStream() - throws IOException - { - if (inProgress) - { - throw new IOException("Transfer in progress"); - } - switch (transferMode) - { - case FTPConnection.MODE_STREAM: - out = new StreamOutputStream(this, socket.getOutputStream()); - break; - case FTPConnection.MODE_BLOCK: - out = new BlockOutputStream(this, socket.getOutputStream()); - break; - case FTPConnection.MODE_COMPRESSED: - out = new CompressedOutputStream(this, socket.getOutputStream()); - break; - default: - throw new IllegalStateException("Invalid transfer mode"); - } - out.setTransferComplete(false); - return out; - } - - public void setTransferMode(int mode) - { - transferMode = mode; - } - - public void complete() - { - completed = true; - if (!inProgress) - { - transferComplete(); - } - } - - public boolean abort() - { - completed = true; - transferComplete(); - return inProgress; - } - - /* - * Called by DTPInputStream or DTPOutputStream when end of - * stream is reached. - */ - public void transferComplete() - { - if (in != null) - { - in.setTransferComplete(true); - } - if (out != null) - { - out.setTransferComplete(true); - } - inProgress = false; - completed = completed ||(transferMode == FTPConnection.MODE_STREAM); - if (completed && socket != null) - { - try - { - socket.close(); - } - catch (IOException e) - { - } - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/StreamInputStream.java b/libjava/gnu/java/net/protocol/ftp/StreamInputStream.java deleted file mode 100644 index 93eee4e1924..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/StreamInputStream.java +++ /dev/null @@ -1,95 +0,0 @@ -/* StreamInputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.InputStream; - -/** - * A DTP input stream that implements the FTP stream data transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class StreamInputStream - extends DTPInputStream -{ - - StreamInputStream(DTP dtp, InputStream in) - { - super(dtp, in); - } - - public int read() - throws IOException - { - if (transferComplete) - { - return -1; - } - int c = in.read(); - if (c == -1) - { - close(); - } - return c; - } - - public int read(byte[] buf) - throws IOException - { - return read(buf, 0, buf.length); - } - - public int read(byte[] buf, int off, int len) - throws IOException - { - if (transferComplete) - { - return -1; - } - int l = in.read(buf, off, len); - if (l == -1) - { - close(); - } - return l; - } - -} - diff --git a/libjava/gnu/java/net/protocol/ftp/StreamOutputStream.java b/libjava/gnu/java/net/protocol/ftp/StreamOutputStream.java deleted file mode 100644 index a6e28ece3d4..00000000000 --- a/libjava/gnu/java/net/protocol/ftp/StreamOutputStream.java +++ /dev/null @@ -1,85 +0,0 @@ -/* StreamOutputStream.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.ftp; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * A DTP output stream that implements the FTP stream transfer mode. - * - * @author Chris Burdess (dog@gnu.org) - */ -class StreamOutputStream - extends DTPOutputStream -{ - - StreamOutputStream(DTP dtp, OutputStream out) - { - super(dtp, out); - } - - public void write(int c) - throws IOException - { - if (transferComplete) - { - return; - } - out.write(c); - } - - public void write(byte[] b) - throws IOException - { - write(b, 0, b.length); - } - - public void write(byte[] b, int off, int len) - throws IOException - { - if (transferComplete) - { - return; - } - out.write(b, off, len); - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/Authenticator.java b/libjava/gnu/java/net/protocol/http/Authenticator.java deleted file mode 100644 index 0d7c9881956..00000000000 --- a/libjava/gnu/java/net/protocol/http/Authenticator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* Authenticator.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Callback interface for managing authentication. - * @see Request#setAuthenticator - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface Authenticator -{ - - /** - * Returns the credentials to supply for the given realm. - * @param realm the authentication realm - * @param attempt zero on first authentication attempt, increments on each - * unsuccessful attempt - */ - Credentials getCredentials(String realm, int attempt); - -} - diff --git a/libjava/gnu/java/net/protocol/http/ByteArrayRequestBodyWriter.java b/libjava/gnu/java/net/protocol/http/ByteArrayRequestBodyWriter.java deleted file mode 100644 index 35ad2bccf45..00000000000 --- a/libjava/gnu/java/net/protocol/http/ByteArrayRequestBodyWriter.java +++ /dev/null @@ -1,107 +0,0 @@ -/* ByteArrayRequestBodyWriter.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * A simple request body writer using a byte array. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ByteArrayRequestBodyWriter - implements RequestBodyWriter -{ - - /** - * The content. - */ - protected byte[] content; - - /** - * The position within the content at which the next read will occur. - */ - protected int pos; - - /** - * Constructs a new byte array request body writer with the specified - * content. - * @param content the content buffer - */ - public ByteArrayRequestBodyWriter(byte[] content) - { - this.content = content; - pos = 0; - } - - /** - * Returns the total number of bytes that will be written in a single pass - * by this writer. - */ - public int getContentLength() - { - return content.length; - } - - /** - * Initialises the writer. - * This will be called before each pass. - */ - public void reset() - { - pos = 0; - } - - /** - * Writes body content to the supplied buffer. - * @param buffer the content buffer - * @return the number of bytes written - */ - public int write(byte[] buffer) - { - int len = content.length - pos; - len = (buffer.length < len) ? buffer.length : len; - if (len > -1) - { - System.arraycopy(content, pos, buffer, 0, len); - pos += len; - } - return len; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java b/libjava/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java deleted file mode 100644 index 680e45d3e49..00000000000 --- a/libjava/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java +++ /dev/null @@ -1,123 +0,0 @@ -/* Authenticator.java --ByteArrayResponseBodyReader.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Simple response body reader that stores content in a byte array. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ByteArrayResponseBodyReader - implements ResponseBodyReader -{ - - /** - * The content. - */ - protected byte[] content; - - /** - * The position in the content at which the next write will occur. - */ - protected int pos; - - /** - * The length of the buffer. - */ - protected int len; - - /** - * Constructs a new byte array response body reader. - */ - public ByteArrayResponseBodyReader() - { - this(4096); - } - - /** - * Constructs a new byte array response body reader with the specified - * initial buffer size. - * @param size the initial buffer size - */ - public ByteArrayResponseBodyReader(int size) - { - content = new byte[size]; - pos = len = 0; - } - - /** - * This reader accepts all responses. - */ - public boolean accept(Request request, Response response) - { - return true; - } - - public void read(byte[] buffer, int offset, int length) - { - int l = length - offset; - if (pos + l > content.length) - { - byte[] tmp = new byte[content.length * 2]; - System.arraycopy(content, 0, tmp, 0, pos); - content = tmp; - } - System.arraycopy(buffer, offset, content, pos, l); - pos += l; - len = pos; - } - - public void close() - { - pos = 0; - } - - /** - * Retrieves the content of this reader as a byte array. - * The size of the returned array is the number of bytes read. - */ - public byte[] toByteArray() - { - byte[] ret = new byte[len]; - System.arraycopy(content, 0, ret, 0, len); - return ret; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/ChunkedInputStream.java b/libjava/gnu/java/net/protocol/http/ChunkedInputStream.java deleted file mode 100644 index c0706b70840..00000000000 --- a/libjava/gnu/java/net/protocol/http/ChunkedInputStream.java +++ /dev/null @@ -1,172 +0,0 @@ -/* ChunkedInputStream.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.ProtocolException; - -/** - * Input stream wrapper for the "chunked" transfer-coding. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ChunkedInputStream - extends FilterInputStream -{ - - private static final byte CR = 0x0d; - private static final byte LF = 0x0a; - - int size; - int count; - boolean meta; - boolean eof; - Headers headers; - - /** - * Constructor. - * @param in the response socket input stream - * @param headers the headers to receive additional header lines - */ - public ChunkedInputStream(InputStream in, Headers headers) - { - super(in); - this.headers = headers; - size = -1; - count = 0; - meta = true; - } - - public int read() - throws IOException - { - byte[] buf = new byte[1]; - int len = read(buf, 0, 1); - if (len == -1) - { - return -1; - } - int ret = (int) buf[0]; - if (ret < 0) - { - ret += 0x100; - } - return ret; - } - - public int read(byte[] buffer) - throws IOException - { - return read(buffer, 0, buffer.length); - } - - public int read(byte[] buffer, int offset, int length) - throws IOException - { - if (eof) - { - return -1; - } - if (meta) - { - // Read chunk header - int c, last = 0; - boolean seenSemi = false; - StringBuffer buf = new StringBuffer(); - do - { - c = in.read(); - if (c == 0x3b) // ; - { - seenSemi = true; - } - else if (c == 0x0a && last == 0x0d) // CRLF - { - size = Integer.parseInt(buf.toString(), 16); - break; - } - else if (!seenSemi && c >= 0x30) - { - buf.append ((char) c); - } - last = c; - } - while(c != -1); - count = 0; - meta = false; - } - if (size == 0) - { - // Read trailer - headers.parse(in); - eof = true; - return -1; - } - else - { - int diff = length - offset; - int max = size - count; - max = (diff < max) ? diff : max; - int len = (max > 0) ? in.read(buffer, offset, max) : 0; - count += len; - if (count == size) - { - // Read CRLF - int c1 = in.read(); - int c2 = in.read(); - if (c1 == -1 && c2 == -1) - { - // EOF before CRLF: bad, but ignore - eof = true; - return -1; - } - if (c1 != 0x0d || c2 != 0x0a) - { - throw new ProtocolException("expecting CRLF: " + c1 + "," + c2); - } - meta = true; - } - return len; - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/Cookie.java b/libjava/gnu/java/net/protocol/http/Cookie.java deleted file mode 100644 index 45e2f733ff3..00000000000 --- a/libjava/gnu/java/net/protocol/http/Cookie.java +++ /dev/null @@ -1,160 +0,0 @@ -/* Cookie.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.util.Date; - -/** - * An HTTP cookie, as specified in RFC 2109. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Cookie -{ - - /** - * The name of the cookie. - */ - protected final String name; - - /** - * The value of the cookie. - */ - protected final String value; - - /** - * Optional documentation of the intended use of the cookie. - */ - protected final String comment; - - /** - * The domain for which the cookie is valid. - */ - protected final String domain; - - /** - * Optional subset of URL paths within the domain for which the cookie is - * valid. - */ - protected final String path; - - /** - * Indicates that the user-agent should only use secure means to transmit - * this cookie to the server. - */ - protected final boolean secure; - - /** - * The date at which this cookie expires. - */ - protected final Date expires; - - public Cookie(String name, String value, String comment, String domain, - String path, boolean secure, Date expires) - { - this.name = name; - this.value = value; - this.comment = comment; - this.domain = domain; - this.path = path; - this.secure = secure; - this.expires = expires; - } - - public String getName() - { - return name; - } - - public String getValue() - { - return value; - } - - public String getComment() - { - return comment; - } - - public String getDomain() - { - return domain; - } - - public String getPath() - { - return path; - } - - public boolean isSecure() - { - return secure; - } - - public Date getExpiryDate() - { - return expires; - } - - public String toString() - { - return toString(true, true); - } - - public String toString(boolean showPath, boolean showDomain) - { - StringBuffer buf = new StringBuffer(); - buf.append(name); - buf.append('='); - buf.append(value); - if (showPath) - { - buf.append("; $Path="); - buf.append(path); - } - if (showDomain) - { - buf.append("; $Domain="); - buf.append(domain); - } - return buf.toString(); - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/CookieManager.java b/libjava/gnu/java/net/protocol/http/CookieManager.java deleted file mode 100644 index cc1225c497d..00000000000 --- a/libjava/gnu/java/net/protocol/http/CookieManager.java +++ /dev/null @@ -1,65 +0,0 @@ -/* CookieManager.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Cookie manager interface. - * If an application wants to handle cookies, they should implement this - * interface and register the instance with each HTTPConnection they use. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface CookieManager -{ - - /** - * Stores a cookie in the cookie manager. - * @param cookie the cookie to store - */ - void setCookie(Cookie cookie); - - /** - * Retrieves the cookies matching the specified criteria. - * @param host the host name - * @param secure whether the connection is secure - * @param path the path to access - */ - Cookie[] getCookies(String host, boolean secure, String path); - -} diff --git a/libjava/gnu/java/net/protocol/http/Credentials.java b/libjava/gnu/java/net/protocol/http/Credentials.java deleted file mode 100644 index 9e5fcd172f5..00000000000 --- a/libjava/gnu/java/net/protocol/http/Credentials.java +++ /dev/null @@ -1,88 +0,0 @@ -/* Credentials.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Represents a username/password combination that can be used to - * authenticate to an HTTP server. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Credentials -{ - - /** - * The username. - */ - private String username; - - /** - * The password. - */ - private String password; - - /** - * Constructor. - * @param username the username - * @param password the password - */ - public Credentials(String username, String password) - { - this.username = username; - this.password = password; - } - - /** - * Returns the username. - */ - public String getUsername() - { - return username; - } - - /** - * Returns the password. - */ - public String getPassword() - { - return password; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/HTTPConnection.java b/libjava/gnu/java/net/protocol/http/HTTPConnection.java deleted file mode 100644 index 221733dba05..00000000000 --- a/libjava/gnu/java/net/protocol/http/HTTPConnection.java +++ /dev/null @@ -1,681 +0,0 @@ -/* HTTPConnection.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import gnu.classpath.Configuration; -import gnu.classpath.SystemProperties; -import gnu.java.net.EmptyX509TrustManager; -import gnu.java.net.protocol.http.event.ConnectionEvent; -import gnu.java.net.protocol.http.event.ConnectionListener; -import gnu.java.net.protocol.http.event.RequestEvent; -import gnu.java.net.protocol.http.event.RequestListener; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.net.ssl.HandshakeCompletedListener; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; - -/** - * A connection to an HTTP server. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class HTTPConnection -{ - - /** - * The default HTTP port. - */ - public static final int HTTP_PORT = 80; - - /** - * The default HTTPS port. - */ - public static final int HTTPS_PORT = 443; - - private static final String userAgent = SystemProperties.getProperty("http.agent"); - - /** - * The host name of the server to connect to. - */ - protected final String hostname; - - /** - * The port to connect to. - */ - protected final int port; - - /** - * Whether the connection should use transport level security (HTTPS). - */ - protected final boolean secure; - - /** - * The connection timeout for connecting the underlying socket. - */ - protected final int connectionTimeout; - - /** - * The read timeout for reads on the underlying socket. - */ - protected final int timeout; - - /** - * The host name of the proxy to connect to. - */ - protected String proxyHostname; - - /** - * The port on the proxy to connect to. - */ - protected int proxyPort; - - /** - * The major version of HTTP supported by this client. - */ - protected int majorVersion; - - /** - * The minor version of HTTP supported by this client. - */ - protected int minorVersion; - - private final List connectionListeners; - private final List requestListeners; - private final List handshakeCompletedListeners; - - /** - * The socket this connection communicates on. - */ - protected Socket socket; - - /** - * The SSL socket factory to use. - */ - private SSLSocketFactory sslSocketFactory; - - /** - * The socket input stream. - */ - protected InputStream in; - - /** - * The socket output stream. - */ - protected OutputStream out; - - /** - * Nonce values seen by this connection. - */ - private Map nonceCounts; - - /** - * The cookie manager for this connection. - */ - protected CookieManager cookieManager; - - /** - * Creates a new HTTP connection. - * @param hostname the name of the host to connect to - */ - public HTTPConnection(String hostname) - { - this(hostname, HTTP_PORT, false, 0, 0); - } - - /** - * Creates a new HTTP or HTTPS connection. - * @param hostname the name of the host to connect to - * @param secure whether to use a secure connection - */ - public HTTPConnection(String hostname, boolean secure) - { - this(hostname, secure ? HTTPS_PORT : HTTP_PORT, secure, 0, 0); - } - - /** - * Creates a new HTTP or HTTPS connection on the specified port. - * @param hostname the name of the host to connect to - * @param secure whether to use a secure connection - * @param connectionTimeout the connection timeout - * @param timeout the socket read timeout - */ - public HTTPConnection(String hostname, boolean secure, - int connectionTimeout, int timeout) - { - this(hostname, secure ? HTTPS_PORT : HTTP_PORT, secure, - connectionTimeout, timeout); - } - - /** - * Creates a new HTTP connection on the specified port. - * @param hostname the name of the host to connect to - * @param port the port on the host to connect to - */ - public HTTPConnection(String hostname, int port) - { - this(hostname, port, false, 0, 0); - } - - /** - * Creates a new HTTP or HTTPS connection on the specified port. - * @param hostname the name of the host to connect to - * @param port the port on the host to connect to - * @param secure whether to use a secure connection - */ - public HTTPConnection(String hostname, int port, boolean secure) - { - this(hostname, port, secure, 0, 0); - } - - /** - * Creates a new HTTP or HTTPS connection on the specified port. - * @param hostname the name of the host to connect to - * @param port the port on the host to connect to - * @param secure whether to use a secure connection - * @param connectionTimeout the connection timeout - * @param timeout the socket read timeout - */ - public HTTPConnection(String hostname, int port, boolean secure, - int connectionTimeout, int timeout) - { - this.hostname = hostname; - this.port = port; - this.secure = secure; - this.connectionTimeout = connectionTimeout; - this.timeout = timeout; - majorVersion = minorVersion = 1; - connectionListeners = new ArrayList(4); - requestListeners = new ArrayList(4); - handshakeCompletedListeners = new ArrayList(2); - } - - /** - * Returns the name of the host to connect to. - */ - public String getHostName() - { - return hostname; - } - - /** - * Returns the port on the host to connect to. - */ - public int getPort() - { - return port; - } - - /** - * Indicates whether to use a secure connection or not. - */ - public boolean isSecure() - { - return secure; - } - - /** - * Returns the HTTP version string supported by this connection. - * @see #version - */ - public String getVersion() - { - return "HTTP/" + majorVersion + '.' + minorVersion; - } - - /** - * Sets the HTTP version supported by this connection. - * @param majorVersion the major version - * @param minorVersion the minor version - */ - public void setVersion(int majorVersion, int minorVersion) - { - if (majorVersion != 1) - { - throw new IllegalArgumentException("major version not supported: " + - majorVersion); - } - if (minorVersion < 0 || minorVersion > 1) - { - throw new IllegalArgumentException("minor version not supported: " + - minorVersion); - } - this.majorVersion = majorVersion; - this.minorVersion = minorVersion; - } - - /** - * Directs this connection to use the specified proxy. - * @param hostname the proxy host name - * @param port the port on the proxy to connect to - */ - public void setProxy(String hostname, int port) - { - proxyHostname = hostname; - proxyPort = port; - } - - /** - * Indicates whether this connection is using an HTTP proxy. - */ - public boolean isUsingProxy() - { - return (proxyHostname != null && proxyPort > 0); - } - - /** - * Sets the cookie manager to use for this connection. - * @param cookieManager the cookie manager - */ - public void setCookieManager(CookieManager cookieManager) - { - this.cookieManager = cookieManager; - } - - /** - * Returns the cookie manager in use for this connection. - */ - public CookieManager getCookieManager() - { - return cookieManager; - } - - /** - * Creates a new request using this connection. - * @param method the HTTP method to invoke - * @param path the URI-escaped RFC2396 <code>abs_path</code> with - * optional query part - */ - public Request newRequest(String method, String path) - { - if (method == null || method.length() == 0) - { - throw new IllegalArgumentException("method must have non-zero length"); - } - if (path == null || path.length() == 0) - { - path = "/"; - } - Request ret = new Request(this, method, path); - if ((secure && port != HTTPS_PORT) || - (!secure && port != HTTP_PORT)) - { - ret.setHeader("Host", hostname + ":" + port); - } - else - { - ret.setHeader("Host", hostname); - } - ret.setHeader("User-Agent", userAgent); - ret.setHeader("Connection", "keep-alive"); - ret.setHeader("Accept-Encoding", - "chunked;q=1.0, gzip;q=0.9, deflate;q=0.8, " + - "identity;q=0.6, *;q=0"); - if (cookieManager != null) - { - Cookie[] cookies = cookieManager.getCookies(hostname, secure, path); - if (cookies != null && cookies.length > 0) - { - StringBuffer buf = new StringBuffer(); - buf.append("$Version=1"); - for (int i = 0; i < cookies.length; i++) - { - buf.append(','); - buf.append(' '); - buf.append(cookies[i].toString()); - } - ret.setHeader("Cookie", buf.toString()); - } - } - fireRequestEvent(RequestEvent.REQUEST_CREATED, ret); - return ret; - } - - /** - * Closes this connection. - */ - public void close() - throws IOException - { - try - { - closeConnection(); - } - finally - { - fireConnectionEvent(ConnectionEvent.CONNECTION_CLOSED); - } - } - - /** - * Retrieves the socket associated with this connection. - * This creates the socket if necessary. - */ - protected Socket getSocket() - throws IOException - { - if (socket == null) - { - String connectHostname = hostname; - int connectPort = port; - if (isUsingProxy()) - { - connectHostname = proxyHostname; - connectPort = proxyPort; - } - socket = new Socket(); - InetSocketAddress address = - new InetSocketAddress(connectHostname, connectPort); - if (connectionTimeout > 0) - { - socket.connect(address, connectionTimeout); - } - else - { - socket.connect(address); - } - if (timeout > 0) - { - socket.setSoTimeout(timeout); - } - if (secure) - { - try - { - SSLSocketFactory factory = getSSLSocketFactory(); - SSLSocket ss = - (SSLSocket) factory.createSocket(socket, connectHostname, - connectPort, true); - String[] protocols = { "TLSv1", "SSLv3" }; - ss.setEnabledProtocols(protocols); - ss.setUseClientMode(true); - synchronized (handshakeCompletedListeners) - { - if (!handshakeCompletedListeners.isEmpty()) - { - for (Iterator i = - handshakeCompletedListeners.iterator(); - i.hasNext(); ) - { - HandshakeCompletedListener l = - (HandshakeCompletedListener) i.next(); - ss.addHandshakeCompletedListener(l); - } - } - } - ss.startHandshake(); - socket = ss; - } - catch (GeneralSecurityException e) - { - throw new IOException(e.getMessage()); - } - } - in = socket.getInputStream(); - in = new BufferedInputStream(in); - out = socket.getOutputStream(); - out = new BufferedOutputStream(out); - } - return socket; - } - - SSLSocketFactory getSSLSocketFactory() - throws GeneralSecurityException - { - if (sslSocketFactory == null) - { - TrustManager tm = new EmptyX509TrustManager(); - SSLContext context = SSLContext.getInstance("SSL"); - TrustManager[] trust = new TrustManager[] { tm }; - context.init(null, trust, null); - sslSocketFactory = context.getSocketFactory(); - } - return sslSocketFactory; - } - - void setSSLSocketFactory(SSLSocketFactory factory) - { - sslSocketFactory = factory; - } - - protected InputStream getInputStream() - throws IOException - { - if (socket == null) - { - getSocket(); - } - return in; - } - - protected OutputStream getOutputStream() - throws IOException - { - if (socket == null) - { - getSocket(); - } - return out; - } - - /** - * Closes the underlying socket, if any. - */ - protected void closeConnection() - throws IOException - { - if (socket != null) - { - try - { - socket.close(); - } - finally - { - socket = null; - } - } - } - - /** - * Returns a URI representing the connection. - * This does not include any request path component. - */ - protected String getURI() - { - StringBuffer buf = new StringBuffer(); - buf.append(secure ? "https://" : "http://"); - buf.append(hostname); - if (secure) - { - if (port != HTTPConnection.HTTPS_PORT) - { - buf.append(':'); - buf.append(port); - } - } - else - { - if (port != HTTPConnection.HTTP_PORT) - { - buf.append(':'); - buf.append(port); - } - } - return buf.toString(); - } - - /** - * Get the number of times the specified nonce has been seen by this - * connection. - */ - int getNonceCount(String nonce) - { - if (nonceCounts == null) - { - return 0; - } - return((Integer) nonceCounts.get(nonce)).intValue(); - } - - /** - * Increment the number of times the specified nonce has been seen. - */ - void incrementNonce(String nonce) - { - int current = getNonceCount(nonce); - if (nonceCounts == null) - { - nonceCounts = new HashMap(); - } - nonceCounts.put(nonce, new Integer(current + 1)); - } - - // -- Events -- - - public void addConnectionListener(ConnectionListener l) - { - synchronized (connectionListeners) - { - connectionListeners.add(l); - } - } - - public void removeConnectionListener(ConnectionListener l) - { - synchronized (connectionListeners) - { - connectionListeners.remove(l); - } - } - - protected void fireConnectionEvent(int type) - { - ConnectionEvent event = new ConnectionEvent(this, type); - ConnectionListener[] l = null; - synchronized (connectionListeners) - { - l = new ConnectionListener[connectionListeners.size()]; - connectionListeners.toArray(l); - } - for (int i = 0; i < l.length; i++) - { - switch (type) - { - case ConnectionEvent.CONNECTION_CLOSED: - l[i].connectionClosed(event); - break; - } - } - } - - public void addRequestListener(RequestListener l) - { - synchronized (requestListeners) - { - requestListeners.add(l); - } - } - - public void removeRequestListener(RequestListener l) - { - synchronized (requestListeners) - { - requestListeners.remove(l); - } - } - - protected void fireRequestEvent(int type, Request request) - { - RequestEvent event = new RequestEvent(this, type, request); - RequestListener[] l = null; - synchronized (requestListeners) - { - l = new RequestListener[requestListeners.size()]; - requestListeners.toArray(l); - } - for (int i = 0; i < l.length; i++) - { - switch (type) - { - case RequestEvent.REQUEST_CREATED: - l[i].requestCreated(event); - break; - case RequestEvent.REQUEST_SENDING: - l[i].requestSent(event); - break; - case RequestEvent.REQUEST_SENT: - l[i].requestSent(event); - break; - } - } - } - - void addHandshakeCompletedListener(HandshakeCompletedListener l) - { - synchronized (handshakeCompletedListeners) - { - handshakeCompletedListeners.add(l); - } - } - void removeHandshakeCompletedListener(HandshakeCompletedListener l) - { - synchronized (handshakeCompletedListeners) - { - handshakeCompletedListeners.remove(l); - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/HTTPDateFormat.java b/libjava/gnu/java/net/protocol/http/HTTPDateFormat.java deleted file mode 100644 index 2f59e43181c..00000000000 --- a/libjava/gnu/java/net/protocol/http/HTTPDateFormat.java +++ /dev/null @@ -1,441 +0,0 @@ -/* HTTPDateFormat.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.FieldPosition; -import java.text.NumberFormat; -import java.text.ParsePosition; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -/** - * HTTP date formatter and parser. - * Formats dates according to RFC 822 (updated by RFC 1123). - * Parses dates according to the above, <i>or</i> RFC 1036, <i>or</i> the - * ANSI C <code>asctime()</code> format. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class HTTPDateFormat - extends DateFormat -{ - - static final String[] DAYS_OF_WEEK = { - null, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - - static final String[] MONTHS = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - - public HTTPDateFormat() - { - calendar = new GregorianCalendar(TimeZone.getTimeZone ("GMT")); - numberFormat = new DecimalFormat(); - } - - /** - * Appends the textual value for the specified field to the given string - * buffer. This method should be avoided, use <code>format(Date)</code> - * instead. - * @param date the Date object - * @param buf the buffer to append to - * @param field the current field position - * @return the modified buffer - */ - public StringBuffer format(Date date, StringBuffer buf, - FieldPosition field) - { - calendar.clear(); - calendar.setTime(date); - buf.setLength(0); - - // Day of week - buf.append(DAYS_OF_WEEK[calendar.get(Calendar.DAY_OF_WEEK)]); - buf.append(','); - buf.append(' '); - - // Day of month - int day = calendar.get(Calendar.DAY_OF_MONTH); - buf.append(Character.forDigit(day / 10, 10)); - buf.append(Character.forDigit(day % 10, 10)); - buf.append(' '); - - // Month - buf.append(MONTHS[calendar.get(Calendar.MONTH)]); - buf.append(' '); - - // Year - int year = calendar.get(Calendar.YEAR); - if (year < 1000) - { - buf.append('0'); - if (year < 100) - { - buf.append('0'); - if (year < 10) - { - buf.append('0'); - } - } - } - buf.append(Integer.toString(year)); - buf.append(' '); - - // Hour - int hour = calendar.get(Calendar.HOUR_OF_DAY); - buf.append(Character.forDigit(hour / 10, 10)); - buf.append(Character.forDigit(hour % 10, 10)); - buf.append(':'); - - // Minute - int minute = calendar.get(Calendar.MINUTE); - buf.append(Character.forDigit(minute / 10, 10)); - buf.append(Character.forDigit(minute % 10, 10)); - buf.append(':'); - - // Second - int second = calendar.get(Calendar.SECOND); - buf.append(Character.forDigit(second / 10, 10)); - buf.append(Character.forDigit(second % 10, 10)); - buf.append(' '); - - // Timezone - // Get time offset in minutes - int zoneOffset =(calendar.get(Calendar.ZONE_OFFSET) + - calendar.get(Calendar.DST_OFFSET)) / 60000; - - // Apply + or - appropriately - if (zoneOffset < 0) - { - zoneOffset = -zoneOffset; - buf.append('-'); - } - else - { - buf.append('+'); - } - - // Set the 2 2-char fields as specified above - int tzhours = zoneOffset / 60; - buf.append(Character.forDigit(tzhours / 10, 10)); - buf.append(Character.forDigit(tzhours % 10, 10)); - int tzminutes = zoneOffset % 60; - buf.append(Character.forDigit(tzminutes / 10, 10)); - buf.append(Character.forDigit(tzminutes % 10, 10)); - - field.setBeginIndex(0); - field.setEndIndex(buf.length()); - return buf; - } - - /** - * Parses the given date in the current TimeZone. - * @param text the formatted date to be parsed - * @param pos the current parse position - */ - public Date parse(String text, ParsePosition pos) - { - int date, month, year, hour, minute, second; - String monthText; - int start = 0, end = -1; - int len = text.length(); - calendar.clear(); - pos.setIndex(start); - try - { - // Advance to date - if (Character.isLetter(text.charAt(start))) - { - start = skipNonWhitespace(text, start); - } - // Determine mode - switch(start) - { - case 3: - // asctime - start = skipWhitespace(text, start); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - monthText = text.substring(start, end); - month = -1; - for (int i = 0; i < 12; i++) - { - if (MONTHS[i].equals(monthText)) - { - month = i; - break; - } - } - if (month == -1) - { - pos.setErrorIndex(end); - return null; - } - // Advance to date - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - date = Integer.parseInt(text.substring(start, end)); - // Advance to hour - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - hour = Integer.parseInt(text.substring(start, end)); - // Advance to minute - start = end + 1; - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - minute = Integer.parseInt(text.substring(start, end)); - // Advance to second - start = end + 1; - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - second = Integer.parseInt(text.substring(start, end)); - // Advance to year - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - year = Integer.parseInt(text.substring(start, end)); - break; - case 0: - case 4: - // rfc822 - start = skipWhitespace(text, start); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - date = Integer.parseInt(text.substring(start, end)); - // Advance to month - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - monthText = text.substring(start, end); - month = -1; - for (int i = 0; i < 12; i++) - { - if (MONTHS[i].equals(monthText)) - { - month = i; - break; - } - } - if (month == -1) - { - pos.setErrorIndex(end); - return null; - } - // Advance to year - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - year = Integer.parseInt(text.substring(start, end)); - // Advance to hour - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - hour = Integer.parseInt(text.substring(start, end)); - // Advance to minute - start = end + 1; - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - minute = Integer.parseInt(text.substring(start, end)); - // Advance to second - start = end + 1; - pos.setIndex(start); - end = start + 1; - while (end < len && !Character.isWhitespace(text.charAt(end))) - { - end++; - } - second = Integer.parseInt(text.substring(start, end)); - break; - default: - // rfc850(obsolete) - start = skipWhitespace(text, start); - pos.setIndex(start); - end = skipTo(text, start + 1, '-'); - date = Integer.parseInt(text.substring(start, end)); - // Advance to month - start = end + 1; - pos.setIndex(start); - end = skipTo(text, start + 1, '-'); - monthText = text.substring(start, end); - month = -1; - for (int i = 0; i < 12; i++) - { - if (MONTHS[i].equals(monthText)) - { - month = i; - break; - } - } - if (month == -1) - { - pos.setErrorIndex(end); - return null; - } - // Advance to year - start = end + 1; - pos.setIndex(start); - end = skipNonWhitespace(text, start + 1); - year = 1900 + Integer.parseInt(text.substring(start, end)); - // Advance to hour - start = skipWhitespace(text, end + 1); - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - hour = Integer.parseInt(text.substring(start, end)); - // Advance to minute - start = end + 1; - pos.setIndex(start); - end = skipTo(text, start + 1, ':'); - minute = Integer.parseInt(text.substring(start, end)); - // Advance to second - start = end + 1; - pos.setIndex(start); - end = start + 1; - while (end < len && !Character.isWhitespace(text.charAt(end))) - { - end++; - } - second = Integer.parseInt(text.substring(start, end)); - } - - calendar.set(Calendar.YEAR, year); - calendar.set(Calendar.MONTH, month); - calendar.set(Calendar.DAY_OF_MONTH, date); - calendar.set(Calendar.HOUR, hour); - calendar.set(Calendar.MINUTE, minute); - calendar.set(Calendar.SECOND, second); - - if (end != len) - { - // Timezone - start = skipWhitespace(text, end + 1); - end = start + 1; - while (end < len && !Character.isWhitespace(text.charAt(end))) - { - end++; - } - char pm = text.charAt(start); - if (Character.isLetter(pm)) - { - TimeZone tz = - TimeZone.getTimeZone(text.substring(start, end)); - calendar.set(Calendar.ZONE_OFFSET, tz.getRawOffset()); - } - else - { - int zoneOffset = 0; - zoneOffset += 600 * Character.digit(text.charAt(++start), 10); - zoneOffset += 60 * Character.digit(text.charAt(++start), 10); - zoneOffset += 10 * Character.digit(text.charAt(++start), 10); - zoneOffset += Character.digit(text.charAt(++start), 10); - zoneOffset *= 60000; // minutes -> ms - if ('-' == pm) - { - zoneOffset = -zoneOffset; - } - calendar.set(Calendar.ZONE_OFFSET, zoneOffset); - } - } - pos.setIndex(end); - - return calendar.getTime(); - } - catch (NumberFormatException e) - { - pos.setErrorIndex(Math.max(start, end)); - } - catch (StringIndexOutOfBoundsException e) - { - pos.setErrorIndex(Math.max(start, end)); - } - return null; - } - - private int skipWhitespace(String text, int pos) - { - while(Character.isWhitespace(text.charAt(pos))) - { - pos++; - } - return pos; - } - - private int skipNonWhitespace(String text, int pos) - { - while(!Character.isWhitespace(text.charAt(pos))) - { - pos++; - } - return pos; - } - - private int skipTo(String text, int pos, char c) - { - while(text.charAt(pos) != c) - { - pos++; - } - return pos; - } - - /** - * Don't allow setting the calendar. - */ - public void setCalendar(Calendar newCalendar) - { - throw new UnsupportedOperationException(); - } - - /** - * Don't allow setting the NumberFormat. - */ - public void setNumberFormat(NumberFormat newNumberFormat) - { - throw new UnsupportedOperationException(); - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java b/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java deleted file mode 100644 index 1745a34abff..00000000000 --- a/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java +++ /dev/null @@ -1,682 +0,0 @@ -/* HTTPURLConnection.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.ProtocolException; -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.cert.Certificate; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.net.ssl.HandshakeCompletedEvent; -import javax.net.ssl.HandshakeCompletedListener; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLPeerUnverifiedException; -import javax.net.ssl.SSLSocketFactory; - -/** - * A URLConnection that uses the HTTPConnection class. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class HTTPURLConnection - extends HttpsURLConnection - implements HandshakeCompletedListener -{ - - /** - * Pool of reusable connections, used if keepAlive is true. - */ - private static final Map connectionPool = new LinkedHashMap(); - - /* - * The underlying connection. - */ - private HTTPConnection connection; - - private String proxyHostname; - private int proxyPort; - private String agent; - private boolean keepAlive; - private int maxConnections; - - private Request request; - private Headers requestHeaders; - private ByteArrayOutputStream requestSink; - private boolean requestMethodSetExplicitly; - - private Response response; - private ByteArrayInputStream responseSink; - private ByteArrayInputStream errorSink; - - private HandshakeCompletedEvent handshakeEvent; - - /** - * Constructor. - * @param url the URL - */ - public HTTPURLConnection(URL url) - throws IOException - { - super(url); - requestHeaders = new Headers(); - AccessController.doPrivileged(this.new GetHTTPPropertiesAction()); - } - - class GetHTTPPropertiesAction - implements PrivilegedAction - { - - public Object run() - { - proxyHostname = System.getProperty("http.proxyHost"); - if (proxyHostname != null && proxyHostname.length() > 0) - { - String port = System.getProperty("http.proxyPort"); - if (port != null && port.length() > 0) - { - proxyPort = Integer.parseInt(port); - } - else - { - proxyHostname = null; - proxyPort = -1; - } - } - agent = System.getProperty("http.agent"); - String ka = System.getProperty("http.keepAlive"); - keepAlive = !(ka != null && "false".equals(ka)); - String mc = System.getProperty("http.maxConnections"); - maxConnections = (mc != null && mc.length() > 0) ? - Math.max(Integer.parseInt(mc), 1) : 5; - return null; - } - - } - - public void connect() - throws IOException - { - if (connected) - { - return; - } - String protocol = url.getProtocol(); - boolean secure = "https".equals(protocol); - String host = url.getHost(); - int port = url.getPort(); - if (port < 0) - { - port = secure ? HTTPConnection.HTTPS_PORT : - HTTPConnection.HTTP_PORT; - } - String file = url.getFile(); - String username = url.getUserInfo(); - String password = null; - if (username != null) - { - int ci = username.indexOf(':'); - if (ci != -1) - { - password = username.substring(ci + 1); - username = username.substring(0, ci); - } - } - final Credentials creds = (username == null) ? null : - new Credentials (username, password); - - boolean retry; - do - { - retry = false; - if (connection == null) - { - connection = getConnection(host, port, secure); - if (secure) - { - SSLSocketFactory factory = getSSLSocketFactory(); - HostnameVerifier verifier = getHostnameVerifier(); - if (factory != null) - { - connection.setSSLSocketFactory(factory); - } - connection.addHandshakeCompletedListener(this); - // TODO verifier - } - } - if (proxyHostname != null) - { - if (proxyPort < 0) - { - proxyPort = secure ? HTTPConnection.HTTPS_PORT : - HTTPConnection.HTTP_PORT; - } - connection.setProxy(proxyHostname, proxyPort); - } - request = connection.newRequest(method, file); - if (!keepAlive) - { - request.setHeader("Connection", "close"); - } - if (agent != null) - { - request.setHeader("User-Agent", agent); - } - request.getHeaders().putAll(requestHeaders); - if (requestSink != null) - { - byte[] content = requestSink.toByteArray(); - RequestBodyWriter writer = new ByteArrayRequestBodyWriter(content); - request.setRequestBodyWriter(writer); - } - ByteArrayResponseBodyReader reader = new ByteArrayResponseBodyReader(); - request.setResponseBodyReader(reader); - if (creds != null) - { - request.setAuthenticator(new Authenticator() { - public Credentials getCredentials(String realm, int attempts) - { - return (attempts < 2) ? creds : null; - } - }); - } - response = request.dispatch(); - if (response.getCodeClass() == 3 && getInstanceFollowRedirects()) - { - // Follow redirect - String location = response.getHeader("Location"); - String connectionUri = connection.getURI(); - int start = connectionUri.length(); - if (location.startsWith(connectionUri) && - location.charAt(start) == '/') - { - file = location.substring(start); - retry = true; - } - else if (location.startsWith("http:")) - { - connection.close(); - connection = null; - secure = false; - start = 7; - int end = location.indexOf('/', start); - host = location.substring(start, end); - int ci = host.lastIndexOf(':'); - if (ci != -1) - { - port = Integer.parseInt(host.substring (ci + 1)); - host = host.substring(0, ci); - } - else - { - port = HTTPConnection.HTTP_PORT; - } - file = location.substring(end); - retry = true; - } - else if (location.startsWith("https:")) - { - connection.close(); - connection = null; - secure = true; - start = 8; - int end = location.indexOf('/', start); - host = location.substring(start, end); - int ci = host.lastIndexOf(':'); - if (ci != -1) - { - port = Integer.parseInt(host.substring (ci + 1)); - host = host.substring(0, ci); - } - else - { - port = HTTPConnection.HTTPS_PORT; - } - file = location.substring(end); - retry = true; - } - else if (location.length() > 0) - { - // Malformed absolute URI, treat as file part of URI - if (location.charAt(0) == '/') - { - // Absolute path - file = location; - } - else - { - // Relative path - int lsi = file.lastIndexOf('/'); - file = (lsi == -1) ? "/" : file.substring(0, lsi + 1); - file += location; - } - retry = true; - } - } - else - { - responseSink = new ByteArrayInputStream(reader.toByteArray ()); - if (response.getCode() == 404) - { - errorSink = responseSink; - throw new FileNotFoundException(url.toString()); - } - } - } - while (retry); - connected = true; - } - - /** - * Returns a connection, from the pool if necessary. - */ - HTTPConnection getConnection(String host, int port, boolean secure) - throws IOException - { - HTTPConnection connection; - if (keepAlive) - { - StringBuffer buf = new StringBuffer(secure ? "https://" : "http://"); - buf.append(host); - buf.append(':'); - buf.append(port); - String key = buf.toString(); - synchronized (connectionPool) - { - connection = (HTTPConnection) connectionPool.get(key); - if (connection == null) - { - connection = new HTTPConnection(host, port, secure); - // Good housekeeping - if (connectionPool.size() == maxConnections) - { - // maxConnections must always be >= 1 - Object lru = connectionPool.keySet().iterator().next(); - connectionPool.remove(lru); - } - connectionPool.put(key, connection); - } - } - } - else - { - connection = new HTTPConnection(host, port, secure); - } - return connection; - } - - public void disconnect() - { - if (connection != null) - { - try - { - connection.close(); - } - catch (IOException e) - { - } - } - } - - public boolean usingProxy() - { - return (proxyHostname != null); - } - - /** - * Overrides the corresponding method in HttpURLConnection to permit - * arbitrary methods, as long as they're valid ASCII alphabetic - * characters. This is to permit WebDAV and other HTTP extensions to - * function. - * @param method the method - */ - public void setRequestMethod(String method) - throws ProtocolException - { - if (connected) - { - throw new ProtocolException("Already connected"); - } - // Validate - method = method.toUpperCase(); - int len = method.length(); - if (len == 0) - { - throw new ProtocolException("Empty method name"); - } - for (int i = 0; i < len; i++) - { - char c = method.charAt(i); - if (c < 0x41 || c > 0x5a) - { - throw new ProtocolException("Illegal character '" + c + - "' at index " + i); - } - } - // OK - this.method = method; - requestMethodSetExplicitly = true; - } - - public String getRequestProperty(String key) - { - return requestHeaders.getValue(key); - } - - public Map getRequestProperties() - { - return requestHeaders; - } - - public void setRequestProperty(String key, String value) - { - requestHeaders.put(key, value); - } - - public void addRequestProperty(String key, String value) - { - String old = requestHeaders.getValue(key); - if (old == null) - { - requestHeaders.put(key, value); - } - else - { - requestHeaders.put(key, old + "," + value); - } - } - - public OutputStream getOutputStream() - throws IOException - { - if (connected) - { - throw new ProtocolException("Already connected"); - } - if (!doOutput) - { - throw new ProtocolException("doOutput is false"); - } - else if (!requestMethodSetExplicitly) - { - /* - * Silently change the method to POST if no method was set - * explicitly. This is due to broken applications depending on this - * behaviour (Apache XMLRPC for one). - */ - method = "POST"; - } - if (requestSink == null) - { - requestSink = new ByteArrayOutputStream(); - } - return requestSink; - } - - // -- Response -- - - public InputStream getInputStream() - throws IOException - { - if (!connected) - { - connect(); - } - if (!doInput) - { - throw new ProtocolException("doInput is false"); - } - return responseSink; - } - - public InputStream getErrorStream() - { - return errorSink; - } - - public Map getHeaderFields() - { - if (!connected) - { - try - { - connect(); - } - catch (IOException e) - { - return null; - } - } - Map headers = response.getHeaders(); - Map ret = new LinkedHashMap(); - ret.put("", Collections.singletonList(getStatusLine(response))); - for (Iterator i = headers.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry) i.next(); - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - ret.put(key, Collections.singletonList(value)); - } - return ret; - } - - String getStatusLine(Response response) - { - return "HTTP/" + response.getMajorVersion() + - "." + response.getMinorVersion() + - " " + response.getCode() + - " " + response.getMessage(); - } - - public String getHeaderField(int index) - { - if (!connected) - { - try - { - connect(); - } - catch (IOException e) - { - return null; - } - } - if (index == 0) - { - return getStatusLine(response); - } - Iterator i = response.getHeaders().entrySet().iterator(); - Map.Entry entry; - int count = 1; - do - { - if (!i.hasNext()) - { - return null; - } - entry = (Map.Entry) i.next(); - count++; - } - while (count <= index); - return (String) entry.getValue(); - } - - public String getHeaderFieldKey(int index) - { - if (!connected) - { - try - { - connect(); - } - catch (IOException e) - { - return null; - } - } - if (index == 0) - { - return null; - } - Iterator i = response.getHeaders().entrySet().iterator(); - Map.Entry entry; - int count = 1; - do - { - if (!i.hasNext()) - { - return null; - } - entry = (Map.Entry) i.next(); - count++; - } - while (count <= index); - return (String) entry.getKey(); - } - - public String getHeaderField(String name) - { - if (!connected) - { - try - { - connect(); - } - catch (IOException e) - { - return null; - } - } - return (String) response.getHeader(name); - } - - public long getHeaderFieldDate(String name, long def) - { - if (!connected) - { - try - { - connect(); - } - catch (IOException e) - { - return def; - } - } - Date date = response.getDateHeader(name); - return (date == null) ? def : date.getTime(); - } - - public String getContentType() - { - return getHeaderField("Content-Type"); - } - - public int getResponseCode() - throws IOException - { - if (!connected) - { - connect(); - } - return response.getCode(); - } - - public String getResponseMessage() - throws IOException - { - if (!connected) - { - connect(); - } - return response.getMessage(); - } - - // -- HTTPS specific -- - - public String getCipherSuite() - { - if (!connected) - { - throw new IllegalStateException("not connected"); - } - return handshakeEvent.getCipherSuite(); - } - - public Certificate[] getLocalCertificates() - { - if (!connected) - { - throw new IllegalStateException("not connected"); - } - return handshakeEvent.getLocalCertificates(); - } - - public Certificate[] getServerCertificates() - throws SSLPeerUnverifiedException - { - if (!connected) - { - throw new IllegalStateException("not connected"); - } - return handshakeEvent.getPeerCertificates(); - } - - // HandshakeCompletedListener - - public void handshakeCompleted(HandshakeCompletedEvent event) - { - handshakeEvent = event; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/Handler.java b/libjava/gnu/java/net/protocol/http/Handler.java deleted file mode 100644 index 64054251331..00000000000 --- a/libjava/gnu/java/net/protocol/http/Handler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* Handler.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * An HTTP URL stream handler. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Handler - extends URLStreamHandler -{ - - /** - * Returns the default HTTP port (80). - */ - protected int getDefaultPort() - { - return HTTPConnection.HTTP_PORT; - } - - /** - * Returns an HTTPURLConnection for the given URL. - */ - public URLConnection openConnection(URL url) - throws IOException - { - return new HTTPURLConnection(url); - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/Headers.java b/libjava/gnu/java/net/protocol/http/Headers.java deleted file mode 100644 index 847ebefc1f6..00000000000 --- a/libjava/gnu/java/net/protocol/http/Headers.java +++ /dev/null @@ -1,369 +0,0 @@ -/* Headers.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import gnu.java.net.LineInputStream; - -import java.io.IOException; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -/** - * A collection of HTTP header names and associated values. - * Retrieval of values is case insensitive. An iteration over the keys - * returns the header names in the order they were received. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Headers - implements Map -{ - - static final DateFormat dateFormat = new HTTPDateFormat(); - - static class Header - { - - final String name; - - Header(String name) - { - if (name == null || name.length() == 0) - { - throw new IllegalArgumentException(name); - } - this.name = name; - } - - public int hashCode() - { - return name.toLowerCase().hashCode(); - } - - public boolean equals(Object other) - { - if (other instanceof Header) - { - return ((Header) other).name.equalsIgnoreCase(name); - } - return false; - } - - public String toString() - { - return name; - } - - } - - static class HeaderEntry - implements Map.Entry - { - - final Map.Entry entry; - - HeaderEntry(Map.Entry entry) - { - this.entry = entry; - } - - public Object getKey() - { - return ((Header) entry.getKey()).name; - } - - public Object getValue() - { - return entry.getValue(); - } - - public Object setValue(Object value) - { - return entry.setValue(value); - } - - public int hashCode() - { - return entry.hashCode(); - } - - public boolean equals(Object other) - { - return entry.equals(other); - } - - public String toString() - { - return getKey().toString() + "=" + getValue(); - } - - } - - private LinkedHashMap headers; - - public Headers() - { - headers = new LinkedHashMap(); - } - - public int size() - { - return headers.size(); - } - - public boolean isEmpty() - { - return headers.isEmpty(); - } - - public boolean containsKey(Object key) - { - return headers.containsKey(new Header((String) key)); - } - - public boolean containsValue(Object value) - { - return headers.containsValue(value); - } - - public Object get(Object key) - { - return headers.get(new Header((String) key)); - } - - /** - * Returns the value of the specified header as a string. - */ - public String getValue(String header) - { - return (String) headers.get(new Header(header)); - } - - /** - * Returns the value of the specified header as an integer, - * or -1 if the header is not present or not an integer. - */ - public int getIntValue(String header) - { - String val = getValue(header); - if (val == null) - { - return -1; - } - try - { - return Integer.parseInt(val); - } - catch (NumberFormatException e) - { - } - return -1; - } - - /** - * Returns the value of the specified header as a date, - * or <code>null</code> if the header is not present or not a date. - */ - public Date getDateValue(String header) - { - String val = getValue(header); - if (val == null) - { - return null; - } - try - { - return dateFormat.parse(val); - } - catch (ParseException e) - { - return null; - } - } - - public Object put(Object key, Object value) - { - return headers.put(new Header((String) key), value); - } - - public Object remove(Object key) - { - return headers.remove(new Header((String) key)); - } - - public void putAll(Map t) - { - for (Iterator i = t.keySet().iterator(); i.hasNext(); ) - { - String key = (String) i.next(); - String value = (String) t.get(key); - headers.put(new Header(key), value); - } - } - - public void clear() - { - headers.clear(); - } - - public Set keySet() - { - Set keys = headers.keySet(); - Set ret = new LinkedHashSet(); - for (Iterator i = keys.iterator(); i.hasNext(); ) - { - ret.add(((Header) i.next()).name); - } - return ret; - } - - public Collection values() - { - return headers.values(); - } - - public Set entrySet() - { - Set entries = headers.entrySet(); - Set ret = new LinkedHashSet(); - for (Iterator i = entries.iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry) i.next(); - ret.add(new HeaderEntry(entry)); - } - return ret; - } - - public boolean equals(Object other) - { - return headers.equals(other); - } - - public int hashCode() - { - return headers.hashCode(); - } - - /** - * Parse the specified input stream, adding headers to this collection. - */ - public void parse(InputStream in) - throws IOException - { - LineInputStream lin = (in instanceof LineInputStream) ? - (LineInputStream) in : new LineInputStream(in); - - String name = null; - StringBuffer value = new StringBuffer(); - while (true) - { - String line = lin.readLine(); - if (line == null) - { - if (name != null) - { - addValue(name, value.toString()); - } - break; - } - int len = line.length(); - if (len < 2) - { - if (name != null) - { - addValue(name, value.toString()); - } - break; - } - char c1 = line.charAt(0); - if (c1 == ' ' || c1 == '\t') - { - // Continuation - int last = len - 1; - if (line.charAt(last) != '\r') - ++last; - value.append(line.substring(0, last)); - } - else - { - if (name != null) - { - addValue(name, value.toString()); - } - - int di = line.indexOf(':'); - name = line.substring(0, di); - value.setLength(0); - do - { - di++; - } - while (di < len && line.charAt(di) == ' '); - int last = len - 1; - if (line.charAt(last) != '\r') - ++last; - value.append(line.substring(di, last)); - } - } - } - - private void addValue(String name, String value) - { - Header key = new Header(name); - String old = (String) headers.get(key); - if (old == null) - { - headers.put(key, value); - } - else - { - headers.put(key, old + ", " + value); - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/Request.java b/libjava/gnu/java/net/protocol/http/Request.java deleted file mode 100644 index 15a459e3eac..00000000000 --- a/libjava/gnu/java/net/protocol/http/Request.java +++ /dev/null @@ -1,914 +0,0 @@ -/* Request.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import gnu.java.net.BASE64; -import gnu.java.net.LineInputStream; -import gnu.java.net.protocol.http.event.RequestEvent; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.ProtocolException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.zip.GZIPInputStream; -import java.util.zip.InflaterInputStream; - -/** - * A single HTTP request. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Request -{ - - /** - * The connection context in which this request is invoked. - */ - protected final HTTPConnection connection; - - /** - * The HTTP method to invoke. - */ - protected final String method; - - /** - * The path identifying the resource. - * This string must conform to the abs_path definition given in RFC2396, - * with an optional "?query" part, and must be URI-escaped by the caller. - */ - protected final String path; - - /** - * The headers in this request. - */ - protected final Headers requestHeaders; - - /** - * The request body provider. - */ - protected RequestBodyWriter requestBodyWriter; - - /** - * Request body negotiation threshold for 100-continue expectations. - */ - protected int requestBodyNegotiationThreshold; - - /** - * The response body reader. - */ - protected ResponseBodyReader responseBodyReader; - - /** - * Map of response header handlers. - */ - protected Map responseHeaderHandlers; - - /** - * The authenticator. - */ - protected Authenticator authenticator; - - /** - * Whether this request has been dispatched yet. - */ - private boolean dispatched; - - /** - * Constructor for a new request. - * @param connection the connection context - * @param method the HTTP method - * @param path the resource path including query part - */ - protected Request(HTTPConnection connection, String method, - String path) - { - this.connection = connection; - this.method = method; - this.path = path; - requestHeaders = new Headers(); - responseHeaderHandlers = new HashMap(); - requestBodyNegotiationThreshold = 4096; - } - - /** - * Returns the connection associated with this request. - * @see #connection - */ - public HTTPConnection getConnection() - { - return connection; - } - - /** - * Returns the HTTP method to invoke. - * @see #method - */ - public String getMethod() - { - return method; - } - - /** - * Returns the resource path. - * @see #path - */ - public String getPath() - { - return path; - } - - /** - * Returns the full request-URI represented by this request, as specified - * by HTTP/1.1. - */ - public String getRequestURI() - { - return connection.getURI() + path; - } - - /** - * Returns the headers in this request. - */ - public Headers getHeaders() - { - return requestHeaders; - } - - /** - * Returns the value of the specified header in this request. - * @param name the header name - */ - public String getHeader(String name) - { - return requestHeaders.getValue(name); - } - - /** - * Returns the value of the specified header in this request as an integer. - * @param name the header name - */ - public int getIntHeader(String name) - { - return requestHeaders.getIntValue(name); - } - - /** - * Returns the value of the specified header in this request as a date. - * @param name the header name - */ - public Date getDateHeader(String name) - { - return requestHeaders.getDateValue(name); - } - - /** - * Sets the specified header in this request. - * @param name the header name - * @param value the header value - */ - public void setHeader(String name, String value) - { - requestHeaders.put(name, value); - } - - /** - * Convenience method to set the entire request body. - * @param requestBody the request body content - */ - public void setRequestBody(byte[] requestBody) - { - setRequestBodyWriter(new ByteArrayRequestBodyWriter(requestBody)); - } - - /** - * Sets the request body provider. - * @param requestBodyWriter the handler used to obtain the request body - */ - public void setRequestBodyWriter(RequestBodyWriter requestBodyWriter) - { - this.requestBodyWriter = requestBodyWriter; - } - - /** - * Sets the response body reader. - * @param responseBodyReader the handler to receive notifications of - * response body content - */ - public void setResponseBodyReader(ResponseBodyReader responseBodyReader) - { - this.responseBodyReader = responseBodyReader; - } - - /** - * Sets a callback handler to be invoked for the specified header name. - * @param name the header name - * @param handler the handler to receive the value for the header - */ - public void setResponseHeaderHandler(String name, - ResponseHeaderHandler handler) - { - responseHeaderHandlers.put(name, handler); - } - - /** - * Sets an authenticator that can be used to handle authentication - * automatically. - * @param authenticator the authenticator - */ - public void setAuthenticator(Authenticator authenticator) - { - this.authenticator = authenticator; - } - - /** - * Sets the request body negotiation threshold. - * If this is set, it determines the maximum size that the request body - * may be before body negotiation occurs(via the - * <code>100-continue</code> expectation). This ensures that a large - * request body is not sent when the server wouldn't have accepted it - * anyway. - * @param threshold the body negotiation threshold, or <=0 to disable - * request body negotation entirely - */ - public void setRequestBodyNegotiationThreshold(int threshold) - { - requestBodyNegotiationThreshold = threshold; - } - - /** - * Dispatches this request. - * A request can only be dispatched once; calling this method a second - * time results in a protocol exception. - * @exception IOException if an I/O error occurred - * @return an HTTP response object representing the result of the operation - */ - public Response dispatch() - throws IOException - { - if (dispatched) - { - throw new ProtocolException("request already dispatched"); - } - final String CRLF = "\r\n"; - final String HEADER_SEP = ": "; - final String US_ASCII = "US-ASCII"; - final String version = connection.getVersion(); - Response response; - int contentLength = -1; - boolean retry = false; - int attempts = 0; - boolean expectingContinue = false; - if (requestBodyWriter != null) - { - contentLength = requestBodyWriter.getContentLength(); - if (contentLength > requestBodyNegotiationThreshold) - { - expectingContinue = true; - setHeader("Expect", "100-continue"); - } - else - { - setHeader("Content-Length", Integer.toString(contentLength)); - } - } - - try - { - // Loop while authentication fails or continue - do - { - retry = false; - // Send request - connection.fireRequestEvent(RequestEvent.REQUEST_SENDING, this); - - // Get socket output and input streams - OutputStream out = connection.getOutputStream(); - LineInputStream in = - new LineInputStream(connection.getInputStream()); - // Request line - String requestUri = path; - if (connection.isUsingProxy() && - !"*".equals(requestUri) && - !"CONNECT".equals(method)) - { - requestUri = getRequestURI(); - } - String line = method + ' ' + requestUri + ' ' + version + CRLF; - out.write(line.getBytes(US_ASCII)); - // Request headers - for (Iterator i = requestHeaders.keySet().iterator(); - i.hasNext(); ) - { - String name =(String) i.next(); - String value =(String) requestHeaders.get(name); - line = name + HEADER_SEP + value + CRLF; - out.write(line.getBytes(US_ASCII)); - } - out.write(CRLF.getBytes(US_ASCII)); - // Request body - if (requestBodyWriter != null && !expectingContinue) - { - byte[] buffer = new byte[4096]; - int len; - int count = 0; - - requestBodyWriter.reset(); - do - { - len = requestBodyWriter.write(buffer); - if (len > 0) - { - out.write(buffer, 0, len); - } - count += len; - } - while (len > -1 && count < contentLength); - out.write(CRLF.getBytes(US_ASCII)); - } - out.flush(); - // Sent event - connection.fireRequestEvent(RequestEvent.REQUEST_SENT, this); - // Get response - response = readResponse(in); - int sc = response.getCode(); - if (sc == 401 && authenticator != null) - { - if (authenticate(response, attempts++)) - { - retry = true; - } - } - else if (sc == 100 && expectingContinue) - { - requestHeaders.remove("Expect"); - setHeader("Content-Length", Integer.toString(contentLength)); - expectingContinue = false; - retry = true; - } - } - while (retry); - } - catch (IOException e) - { - connection.close(); - throw e; - } - return response; - } - - Response readResponse(LineInputStream in) - throws IOException - { - String line; - int len; - - // Read response status line - line = in.readLine(); - if (line == null) - { - throw new ProtocolException("Peer closed connection"); - } - if (!line.startsWith("HTTP/")) - { - throw new ProtocolException(line); - } - len = line.length(); - int start = 5, end = 6; - while (line.charAt(end) != '.') - { - end++; - } - int majorVersion = Integer.parseInt(line.substring(start, end)); - start = end + 1; - end = start + 1; - while (line.charAt(end) != ' ') - { - end++; - } - int minorVersion = Integer.parseInt(line.substring(start, end)); - start = end + 1; - end = start + 3; - int code = Integer.parseInt(line.substring(start, end)); - String message = line.substring(end + 1, len - 1); - // Read response headers - Headers responseHeaders = new Headers(); - responseHeaders.parse(in); - notifyHeaderHandlers(responseHeaders); - // Construct response - int codeClass = code / 100; - Response ret = new Response(majorVersion, minorVersion, code, - codeClass, message, responseHeaders); - switch (code) - { - case 204: - case 205: - break; - default: - // Does response body reader want body? - boolean notify = (responseBodyReader != null); - if (notify) - { - if (!responseBodyReader.accept(this, ret)) - { - notify = false; - } - } - readResponseBody(ret, in, notify); - } - return ret; - } - - void notifyHeaderHandlers(Headers headers) - { - for (Iterator i = headers.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry) i.next(); - String name =(String) entry.getKey(); - // Handle Set-Cookie - if ("Set-Cookie".equalsIgnoreCase(name)) - { - String value = (String) entry.getValue(); - handleSetCookie(value); - } - ResponseHeaderHandler handler = - (ResponseHeaderHandler) responseHeaderHandlers.get(name); - if (handler != null) - { - String value = (String) entry.getValue(); - handler.setValue(value); - } - } - } - - void readResponseBody(Response response, InputStream in, - boolean notify) - throws IOException - { - byte[] buffer = new byte[4096]; - int contentLength = -1; - Headers trailer = null; - - String transferCoding = response.getHeader("Transfer-Encoding"); - if ("chunked".equalsIgnoreCase(transferCoding)) - { - trailer = new Headers(); - in = new ChunkedInputStream(in, trailer); - } - else - { - contentLength = response.getIntHeader("Content-Length"); - } - String contentCoding = response.getHeader("Content-Encoding"); - if (contentCoding != null && !"identity".equals(contentCoding)) - { - if ("gzip".equals(contentCoding)) - { - in = new GZIPInputStream(in); - } - else if ("deflate".equals(contentCoding)) - { - in = new InflaterInputStream(in); - } - else - { - throw new ProtocolException("Unsupported Content-Encoding: " + - contentCoding); - } - } - - // Persistent connections are the default in HTTP/1.1 - boolean doClose = "close".equalsIgnoreCase(getHeader("Connection")) || - "close".equalsIgnoreCase(response.getHeader("Connection")) || - (connection.majorVersion == 1 && connection.minorVersion == 0) || - (response.majorVersion == 1 && response.minorVersion == 0); - - int count = contentLength; - int len = (count > -1) ? count : buffer.length; - len = (len > buffer.length) ? buffer.length : len; - while (len > -1) - { - len = in.read(buffer, 0, len); - if (len < 0) - { - // EOF - connection.closeConnection(); - break; - } - if (notify) - { - responseBodyReader.read(buffer, 0, len); - } - if (count > -1) - { - count -= len; - if (count < 1) - { - if (doClose) - { - connection.closeConnection(); - } - break; - } - } - } - if (notify) - { - responseBodyReader.close(); - } - if (trailer != null) - { - response.getHeaders().putAll(trailer); - notifyHeaderHandlers(trailer); - } - } - - boolean authenticate(Response response, int attempts) - throws IOException - { - String challenge = response.getHeader("WWW-Authenticate"); - if (challenge == null) - { - challenge = response.getHeader("Proxy-Authenticate"); - } - int si = challenge.indexOf(' '); - String scheme = (si == -1) ? challenge : challenge.substring(0, si); - if ("Basic".equalsIgnoreCase(scheme)) - { - Properties params = parseAuthParams(challenge.substring(si + 1)); - String realm = params.getProperty("realm"); - Credentials creds = authenticator.getCredentials(realm, attempts); - String userPass = creds.getUsername() + ':' + creds.getPassword(); - byte[] b_userPass = userPass.getBytes("US-ASCII"); - byte[] b_encoded = BASE64.encode(b_userPass); - String authorization = - scheme + " " + new String(b_encoded, "US-ASCII"); - setHeader("Authorization", authorization); - return true; - } - else if ("Digest".equalsIgnoreCase(scheme)) - { - Properties params = parseAuthParams(challenge.substring(si + 1)); - String realm = params.getProperty("realm"); - String nonce = params.getProperty("nonce"); - String qop = params.getProperty("qop"); - String algorithm = params.getProperty("algorithm"); - String digestUri = getRequestURI(); - Credentials creds = authenticator.getCredentials(realm, attempts); - String username = creds.getUsername(); - String password = creds.getPassword(); - connection.incrementNonce(nonce); - try - { - MessageDigest md5 = MessageDigest.getInstance("MD5"); - final byte[] COLON = { 0x3a }; - - // Calculate H(A1) - md5.reset(); - md5.update(username.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(realm.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(password.getBytes("US-ASCII")); - byte[] ha1 = md5.digest(); - if ("md5-sess".equals(algorithm)) - { - byte[] cnonce = generateNonce(); - md5.reset(); - md5.update(ha1); - md5.update(COLON); - md5.update(nonce.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(cnonce); - ha1 = md5.digest(); - } - String ha1Hex = toHexString(ha1); - - // Calculate H(A2) - md5.reset(); - md5.update(method.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(digestUri.getBytes("US-ASCII")); - if ("auth-int".equals(qop)) - { - byte[] hEntity = null; // TODO hash of entity body - md5.update(COLON); - md5.update(hEntity); - } - byte[] ha2 = md5.digest(); - String ha2Hex = toHexString(ha2); - - // Calculate response - md5.reset(); - md5.update(ha1Hex.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(nonce.getBytes("US-ASCII")); - if ("auth".equals(qop) || "auth-int".equals(qop)) - { - String nc = getNonceCount(nonce); - byte[] cnonce = generateNonce(); - md5.update(COLON); - md5.update(nc.getBytes("US-ASCII")); - md5.update(COLON); - md5.update(cnonce); - md5.update(COLON); - md5.update(qop.getBytes("US-ASCII")); - } - md5.update(COLON); - md5.update(ha2Hex.getBytes("US-ASCII")); - String digestResponse = toHexString(md5.digest()); - - String authorization = scheme + - " username=\"" + username + "\"" + - " realm=\"" + realm + "\"" + - " nonce=\"" + nonce + "\"" + - " uri=\"" + digestUri + "\"" + - " response=\"" + digestResponse + "\""; - setHeader("Authorization", authorization); - return true; - } - catch (NoSuchAlgorithmException e) - { - return false; - } - } - // Scheme not recognised - return false; - } - - Properties parseAuthParams(String text) - { - int len = text.length(); - String key = null; - StringBuffer buf = new StringBuffer(); - Properties ret = new Properties(); - boolean inQuote = false; - for (int i = 0; i < len; i++) - { - char c = text.charAt(i); - if (c == '"') - { - inQuote = !inQuote; - } - else if (c == '=' && key == null) - { - key = buf.toString().trim(); - buf.setLength(0); - } - else if (c == ' ' && !inQuote) - { - String value = unquote(buf.toString().trim()); - ret.put(key, value); - key = null; - buf.setLength(0); - } - else if (c != ',' || (i <(len - 1) && text.charAt(i + 1) != ' ')) - { - buf.append(c); - } - } - if (key != null) - { - String value = unquote(buf.toString().trim()); - ret.put(key, value); - } - return ret; - } - - String unquote(String text) - { - int len = text.length(); - if (len > 0 && text.charAt(0) == '"' && text.charAt(len - 1) == '"') - { - return text.substring(1, len - 1); - } - return text; - } - - /** - * Returns the number of times the specified nonce value has been seen. - * This always returns an 8-byte 0-padded hexadecimal string. - */ - String getNonceCount(String nonce) - { - int nc = connection.getNonceCount(nonce); - String hex = Integer.toHexString(nc); - StringBuffer buf = new StringBuffer(); - for (int i = 8 - hex.length(); i > 0; i--) - { - buf.append('0'); - } - buf.append(hex); - return buf.toString(); - } - - /** - * Client nonce value. - */ - byte[] nonce; - - /** - * Generates a new client nonce value. - */ - byte[] generateNonce() - throws IOException, NoSuchAlgorithmException - { - if (nonce == null) - { - long time = System.currentTimeMillis(); - MessageDigest md5 = MessageDigest.getInstance("MD5"); - md5.update(Long.toString(time).getBytes("US-ASCII")); - nonce = md5.digest(); - } - return nonce; - } - - String toHexString(byte[] bytes) - { - char[] ret = new char[bytes.length * 2]; - for (int i = 0, j = 0; i < bytes.length; i++) - { - int c =(int) bytes[i]; - if (c < 0) - { - c += 0x100; - } - ret[j++] = Character.forDigit(c / 0x10, 0x10); - ret[j++] = Character.forDigit(c % 0x10, 0x10); - } - return new String(ret); - } - - /** - * Parse the specified cookie list and notify the cookie manager. - */ - void handleSetCookie(String text) - { - CookieManager cookieManager = connection.getCookieManager(); - if (cookieManager == null) - { - return; - } - String name = null; - String value = null; - String comment = null; - String domain = connection.getHostName(); - String path = this.path; - int lsi = path.lastIndexOf('/'); - if (lsi != -1) - { - path = path.substring(0, lsi); - } - boolean secure = false; - Date expires = null; - - int len = text.length(); - String attr = null; - StringBuffer buf = new StringBuffer(); - boolean inQuote = false; - for (int i = 0; i <= len; i++) - { - char c =(i == len) ? '\u0000' : text.charAt(i); - if (c == '"') - { - inQuote = !inQuote; - } - else if (!inQuote) - { - if (c == '=' && attr == null) - { - attr = buf.toString().trim(); - buf.setLength(0); - } - else if (c == ';' || i == len || c == ',') - { - String val = unquote(buf.toString().trim()); - if (name == null) - { - name = attr; - value = val; - } - else if ("Comment".equalsIgnoreCase(attr)) - { - comment = val; - } - else if ("Domain".equalsIgnoreCase(attr)) - { - domain = val; - } - else if ("Path".equalsIgnoreCase(attr)) - { - path = val; - } - else if ("Secure".equalsIgnoreCase(val)) - { - secure = true; - } - else if ("Max-Age".equalsIgnoreCase(attr)) - { - int delta = Integer.parseInt(val); - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(System.currentTimeMillis()); - cal.add(Calendar.SECOND, delta); - expires = cal.getTime(); - } - else if ("Expires".equalsIgnoreCase(attr)) - { - DateFormat dateFormat = new HTTPDateFormat(); - try - { - expires = dateFormat.parse(val); - } - catch (ParseException e) - { - // if this isn't a valid date, it may be that - // the value was returned unquoted; in that case, we - // want to continue buffering the value - buf.append(c); - continue; - } - } - attr = null; - buf.setLength(0); - // case EOL - if (i == len || c == ',') - { - Cookie cookie = new Cookie(name, value, comment, domain, - path, secure, expires); - cookieManager.setCookie(cookie); - } - if (c == ',') - { - // Reset cookie fields - name = null; - value = null; - comment = null; - domain = connection.getHostName(); - path = this.path; - if (lsi != -1) - { - path = path.substring(0, lsi); - } - secure = false; - expires = null; - } - } - else - { - buf.append(c); - } - } - else - { - buf.append(c); - } - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/RequestBodyWriter.java b/libjava/gnu/java/net/protocol/http/RequestBodyWriter.java deleted file mode 100644 index 05d98ebb81a..00000000000 --- a/libjava/gnu/java/net/protocol/http/RequestBodyWriter.java +++ /dev/null @@ -1,69 +0,0 @@ -/* RequestBodyWriter.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Callback interface for writing request body content. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface RequestBodyWriter -{ - - /** - * Returns the total number of bytes that will be written in a single pass - * by this writer. - */ - int getContentLength(); - - /** - * Initialises the writer. - * This will be called before each pass. - */ - void reset(); - - /** - * Writes body content to the supplied buffer. - * @param buffer the content buffer - * @return the number of bytes written - */ - int write(byte[] buffer); - -} - diff --git a/libjava/gnu/java/net/protocol/http/Response.java b/libjava/gnu/java/net/protocol/http/Response.java deleted file mode 100644 index 29dc28b17d3..00000000000 --- a/libjava/gnu/java/net/protocol/http/Response.java +++ /dev/null @@ -1,185 +0,0 @@ -/* Response.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.util.Date; - -/** - * An HTTP response. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Response -{ - - /** - * The HTTP major version of the server issuing the response. - */ - protected final int majorVersion; - - /** - * The HTTP minor version of the server issuing the response. - */ - protected final int minorVersion; - - /** - * The HTTP status code of the response. - */ - protected final int code; - - /** - * The class of the response. This is the most significant digit of the - * status code. - * <dl> - * <dt><code>1xx</code></dt> <dd>Informational response</dd> - * <dt><code>2xx</code></dt> <dd>Success</dd> - * <dt><code>3xx</code></dt> <dd>Redirection</dd> - * <dt><code>4xx</code></dt> <dd>Client error</dd> - * <dt><code>5xx</code></dt> <dd>Server error</dd> - * </dl> - */ - protected final int codeClass; - - /** - * Human-readable text of the response. - */ - protected final String message; - - /** - * The response headers. - */ - protected final Headers headers; - - /** - * Constructs a new response with the specified parameters. - */ - protected Response(int majorVersion, int minorVersion, int code, - int codeClass, String message, - Headers headers) - { - this.majorVersion = majorVersion; - this.minorVersion = minorVersion; - this.code = code; - this.codeClass = codeClass; - this.message = message; - this.headers = headers; - } - - /** - * Returns the HTTP major version of the server issuing the response. - * @see #majorVersion - */ - public int getMajorVersion() - { - return majorVersion; - } - - /** - * Returns the HTTP minor version of the server issuing the response. - * @see #minorVersion - */ - public int getMinorVersion() - { - return minorVersion; - } - - /** - * Returns the HTTP status code of the response. - * @see #code - */ - public int getCode() - { - return code; - } - - /** - * Returns the class of the response. - * @see #codeClass - */ - public int getCodeClass() - { - return codeClass; - } - - /** - * Returns the human-readable text of the response. - * @see #message - */ - public String getMessage() - { - return message; - } - - /** - * Returns the headers in the response. - */ - public Headers getHeaders() - { - return headers; - } - - /** - * Returns the header value for the specified name. - * @param name the header name - */ - public String getHeader(String name) - { - return headers.getValue(name); - } - - /** - * Returns the header value for the specified name as an integer. - * @param name the header name - */ - public int getIntHeader(String name) - { - return headers.getIntValue(name); - } - - /** - * Returns the header value for the specified name as a date. - * @param name the header name - */ - public Date getDateHeader(String name) - { - return headers.getDateValue(name); - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/ResponseBodyReader.java b/libjava/gnu/java/net/protocol/http/ResponseBodyReader.java deleted file mode 100644 index 49e1b376f0f..00000000000 --- a/libjava/gnu/java/net/protocol/http/ResponseBodyReader.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ResponseBodyReader.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Callback interface for receiving notification of response body content. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface ResponseBodyReader -{ - - /** - * Indicate whether this reader is interested in the specified response. - * If it returns false, it will not receive body content notifications for - * that response. - */ - boolean accept(Request request, Response response); - - /** - * Receive notification of body content. - * @param buffer the content buffer - * @param offset the offset within the buffer that content starts - * @param length the length of the content - */ - void read(byte[] buffer, int offset, int length); - - /** - * Notifies the reader that the end of the content was reached. - */ - void close(); - -} - diff --git a/libjava/gnu/java/net/protocol/http/ResponseHeaderHandler.java b/libjava/gnu/java/net/protocol/http/ResponseHeaderHandler.java deleted file mode 100644 index 8e4e6492acf..00000000000 --- a/libjava/gnu/java/net/protocol/http/ResponseHeaderHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* ResponseHeaderHandler.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -/** - * Callback interface for objects that wish to be notified of response - * header values. - * @see Request#setHeaderHandler(String) - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface ResponseHeaderHandler -{ - - /** - * Sets the value for the header associated with this handler. - */ - void setValue(String value); - -} - diff --git a/libjava/gnu/java/net/protocol/http/SimpleCookieManager.java b/libjava/gnu/java/net/protocol/http/SimpleCookieManager.java deleted file mode 100644 index 8947471885c..00000000000 --- a/libjava/gnu/java/net/protocol/http/SimpleCookieManager.java +++ /dev/null @@ -1,140 +0,0 @@ -/* CookieManager.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * A simple non-persistent cookie manager. This class can be extended to - * provide cookie persistence. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class SimpleCookieManager - implements CookieManager -{ - - /** - * The cookie cache. - * This is a dictionary mapping domains to maps of cookies by name. - */ - protected Map cookies; - - /** - * Constructor. - */ - public SimpleCookieManager() - { - cookies = new HashMap(); - } - - public void setCookie(Cookie cookie) - { - String domain = cookie.getDomain(); - Map map =(Map) cookies.get(domain); - if (map == null) - { - map = new HashMap(); - cookies.put(domain, map); - } - String name = cookie.getName(); - map.put(name, cookie); // will replace a cookie of the same name - } - - public Cookie[] getCookies(String host, boolean secure, String path) - { - List matches = new ArrayList(); - Date now = new Date(); - if (Character.isLetter(host.charAt(0))) - { - int di = host.indexOf('.'); - while (di != -1) - { - addCookies(matches, host, secure, path, now); - host = host.substring(di); - di = host.indexOf('.', 1); - } - } - addCookies(matches, host, secure, path, now); - Cookie[] ret = new Cookie[matches.size()]; - matches.toArray(ret); - return ret; - } - - private void addCookies(List matches, String domain, boolean secure, - String path, Date now) - { - Map map = (Map) cookies.get(domain); - if (map != null) - { - List expired = new ArrayList(); - for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry) i.next(); - Cookie cookie = (Cookie) entry.getValue(); - Date expires = cookie.getExpiryDate(); - if (expires != null && expires.before(now)) - { - expired.add(entry.getKey()); - continue; - } - if (secure && !cookie.isSecure()) - { - continue; - } - if (path.startsWith(cookie.getPath())) - { - matches.add(cookie); - } - } - // Good housekeeping - for (Iterator i = expired.iterator(); i.hasNext(); ) - { - map.remove(i.next()); - } - } - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/event/ConnectionEvent.java b/libjava/gnu/java/net/protocol/http/event/ConnectionEvent.java deleted file mode 100644 index 3f6f5454e73..00000000000 --- a/libjava/gnu/java/net/protocol/http/event/ConnectionEvent.java +++ /dev/null @@ -1,81 +0,0 @@ -/* ConnectionEvent.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventObject; - -/** - * A connection event. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class ConnectionEvent - extends EventObject -{ - - /** - * The connection closed event type. - */ - public static final int CONNECTION_CLOSED = 0; - - /** - * The type of this event. - */ - protected int type; - - /** - * Constructs a connection event with the specified source and type. - */ - public ConnectionEvent(Object source, int type) - { - super(source); - this.type = type; - } - - /** - * Returns the type of this event. - * @see #type - */ - public int getType() - { - return type; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/event/ConnectionListener.java b/libjava/gnu/java/net/protocol/http/event/ConnectionListener.java deleted file mode 100644 index 073e89d4407..00000000000 --- a/libjava/gnu/java/net/protocol/http/event/ConnectionListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* ConnectionListener.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventListener; - -/** - * A connection listener. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface ConnectionListener - extends EventListener -{ - - /** - * Callback invoked when the associated connection is closed. - */ - void connectionClosed(ConnectionEvent event); - -} - diff --git a/libjava/gnu/java/net/protocol/http/event/RequestEvent.java b/libjava/gnu/java/net/protocol/http/event/RequestEvent.java deleted file mode 100644 index 281c621f33f..00000000000 --- a/libjava/gnu/java/net/protocol/http/event/RequestEvent.java +++ /dev/null @@ -1,107 +0,0 @@ -/* RequestEvent.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import gnu.java.net.protocol.http.Request; - -import java.util.EventObject; - -/** - * A request event. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class RequestEvent - extends EventObject -{ - - /** - * The request created event type. - */ - public static final int REQUEST_CREATED = 0; - - /** - * The request sending event type. - */ - public static final int REQUEST_SENDING = 1; - - /** - * The request sent event type. - */ - public static final int REQUEST_SENT = 2; - - /** - * The type of this event. - */ - protected int type; - - /** - * The request associated with this event. - */ - protected Request request; - - /** - * Constructs a request event with the specified source, type, and request. - */ - public RequestEvent(Object source, int type, Request request) - { - super(source); - this.type = type; - this.request = request; - } - - /** - * Returns the type of this event. - * @see #type - */ - public int getType() - { - return type; - } - - /** - * Returns the request associated with this event. - */ - public Request getRequest() - { - return request; - } - -} - diff --git a/libjava/gnu/java/net/protocol/http/event/RequestListener.java b/libjava/gnu/java/net/protocol/http/event/RequestListener.java deleted file mode 100644 index c880fbce6f0..00000000000 --- a/libjava/gnu/java/net/protocol/http/event/RequestListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* RequestListener.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.http.event; - -import java.util.EventListener; - -/** - * A request listener. - * - * @author Chris Burdess (dog@gnu.org) - */ -public interface RequestListener - extends EventListener -{ - - /** - * Callback invoked when a request is created from the associated - * connection. - */ - void requestCreated(RequestEvent event); - - /** - * Callback invoked when the request has been initialised with all data - * and before sending this data to the server. - */ - void requestSending(RequestEvent event); - - /** - * Callback invoked after all request data has been sent to the server. - */ - void requestSent(RequestEvent event); - -} - diff --git a/libjava/gnu/java/net/protocol/https/Handler.java b/libjava/gnu/java/net/protocol/https/Handler.java deleted file mode 100644 index 2b137517021..00000000000 --- a/libjava/gnu/java/net/protocol/https/Handler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* Handler.java -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.https; - -import gnu.java.net.protocol.http.HTTPConnection; -import gnu.java.net.protocol.http.HTTPURLConnection; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * An HTTPS URL stream handler. - * - * @author Chris Burdess (dog@gnu.org) - */ -public class Handler - extends URLStreamHandler -{ - - /** - * Returns the default HTTPS port (443). - */ - protected int getDefaultPort() - { - return HTTPConnection.HTTPS_PORT; - } - - /** - * Returns an HTTPURLConnection for the given URL. - */ - public URLConnection openConnection(URL url) - throws IOException - { - return new HTTPURLConnection(url); - } - -} - diff --git a/libjava/gnu/java/net/protocol/jar/Handler.java b/libjava/gnu/java/net/protocol/jar/Handler.java deleted file mode 100644 index d45411c47e5..00000000000 --- a/libjava/gnu/java/net/protocol/jar/Handler.java +++ /dev/null @@ -1,169 +0,0 @@ -/* gnu.java.net.protocol.jar.Handler - jar protocol handler for java.net - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.net.protocol.jar; - -import gnu.java.net.URLParseError; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * @author Kresten Krab Thorup (krab@gnu.org) - */ -public class Handler extends URLStreamHandler -{ - /** - * A do nothing constructor - */ - public Handler() - { - } - - /** - * This method returs a new JarURLConnection for the specified URL - * - * @param url The URL to return a connection for - * - * @return The URLConnection - * - * @exception IOException If an error occurs - */ - protected URLConnection openConnection(URL url) throws IOException - { - return new Connection(url); - } - - /** - * This method overrides URLStreamHandler's for parsing url of protocol "jar" - * - * @param url The URL object in which to store the results - * @param url_string The String-ized URL to parse - * @param start The position in the string to start scanning from - * @param end The position in the string to stop scanning - */ - protected void parseURL (URL url, String url_string, int start, int end) - { - // This method does not throw an exception or return a value. Thus our - // strategy when we encounter an error in parsing is to return without - // doing anything. - String file = url.getFile(); - - if (!file.equals("")) - { //has context url - url_string = url_string.substring (start, end); - if (url_string.startsWith("/")) - { //url string is an absolute path - int idx = file.lastIndexOf ("!/"); - - if (idx < 0) - throw new URLParseError("no !/ in spec"); - - file = file.substring (0, idx + 1) + url_string; - } - else - { - int idx = file.lastIndexOf ("/"); - if (idx == -1) //context path is weird - file = "/" + url_string; - else if (idx == (file.length() - 1)) - //just concatenate two parts - file = file + url_string; - else - // according to Java API Documentation, here is a little different - // with URLStreamHandler.parseURL - // but JDK seems doesn't handle it well - file = file.substring(0, idx + 1) + url_string; - } - - setURL (url, "jar", url.getHost(), url.getPort(), file, null); - return; - } - - // Bunches of things should be true. Make sure. - if (end < start) - return; - if (end - start < 2) - return; - if (start > url_string.length()) - return; - - // Skip remains of protocol - url_string = url_string.substring (start, end); - - int jar_stop; - if ((jar_stop = url_string.indexOf("!/")) < 0) - throw new URLParseError("no !/ in spec"); - - try - { - new URL(url_string.substring (0, jar_stop)); - } - catch (MalformedURLException e) - { - throw new URLParseError("invalid inner URL: " + e.getMessage()); - } - - if (!url.getProtocol().equals ("jar") ) - throw new URLParseError("unexpected protocol " + url.getProtocol()); - - setURL (url, "jar", url.getHost(), url.getPort(), url_string, null); - } - - /** - * This method converts a Jar URL object into a String. - * - * @param url The URL object to convert - */ - protected String toExternalForm (URL url) - { - String file = url.getFile(); - - // return "jar:" + file; - // Performance!!: - // Do the concatenation manually to avoid resize StringBuffer's - // internal buffer. - StringBuffer sb = new StringBuffer (file.length() + 5); - sb.append ("jar:"); - sb.append (file); - return sb.toString(); - } -} diff --git a/libjava/gnu/java/nio/ChannelInputStream.java b/libjava/gnu/java/nio/ChannelInputStream.java deleted file mode 100644 index 675a62f3d88..00000000000 --- a/libjava/gnu/java/nio/ChannelInputStream.java +++ /dev/null @@ -1,79 +0,0 @@ -/* ChannelInputStream.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.channels.IllegalBlockingModeException; -import java.nio.channels.ReadableByteChannel; -import java.nio.channels.SelectableChannel; - -/** - * @author Michael Koch - */ -public final class ChannelInputStream extends InputStream -{ - private ReadableByteChannel ch; - - public ChannelInputStream (ReadableByteChannel ch) - { - super(); - - this.ch = ch; - } - - public int read() throws IOException - { - if (ch instanceof SelectableChannel - && (! ((SelectableChannel) ch).isBlocking())) - throw new IllegalBlockingModeException(); - - ByteBuffer buffer = ByteBuffer.allocate(1); - int result = ch.read(buffer); - - if (result == -1) - return -1; - - if (result == 0) - throw new IOException("Could not read from channel"); - - return buffer.get(0); - } -} diff --git a/libjava/gnu/java/nio/ChannelOutputStream.java b/libjava/gnu/java/nio/ChannelOutputStream.java deleted file mode 100644 index 08323eacec4..00000000000 --- a/libjava/gnu/java/nio/ChannelOutputStream.java +++ /dev/null @@ -1,67 +0,0 @@ -/* ChannelOutputStream.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.WritableByteChannel; - -/** - * @author Michael Koch - */ -public final class ChannelOutputStream extends OutputStream -{ - private WritableByteChannel ch; - - public ChannelOutputStream (WritableByteChannel ch) - { - super(); - - this.ch = ch; - } - - public void write (int value) throws IOException - { - ByteBuffer buffer = ByteBuffer.allocate (1); - buffer.put ((byte) (value & 0xff)); - buffer.flip(); - ch.write (buffer); - } -} diff --git a/libjava/gnu/java/nio/ChannelReader.java b/libjava/gnu/java/nio/ChannelReader.java deleted file mode 100644 index 44fe6625a3b..00000000000 --- a/libjava/gnu/java/nio/ChannelReader.java +++ /dev/null @@ -1,211 +0,0 @@ -/* ChannelReader.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - GNU Classpath is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.io.Reader; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.channels.ReadableByteChannel; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CoderResult; -import java.nio.charset.CodingErrorAction; - -/** - * A Reader implementation that works using a ReadableByteChannel and a - * CharsetDecoder. - * - * <p> - * This is a bridge between NIO <-> IO character decoding. - * </p> - * - * @author Robert Schuster - */ -public class ChannelReader extends Reader -{ - - private static final int DEFAULT_BUFFER_CAP = 8192; - - private ReadableByteChannel channel; - - private CharsetDecoder decoder; - - private ByteBuffer byteBuffer; - - private CharBuffer charBuffer; - - public ChannelReader(ReadableByteChannel channel, CharsetDecoder decoder, - int minBufferCap) - { - this.channel = channel; - this.decoder = decoder; - - // JDK reports errors, so we do the same. - decoder.onMalformedInput(CodingErrorAction.REPORT); - decoder.onUnmappableCharacter(CodingErrorAction.REPORT); - decoder.reset(); - - int size = (minBufferCap == -1) ? DEFAULT_BUFFER_CAP : minBufferCap; - - // Allocates the buffers and prepares them for reading, because that is the - // first operation being done on them. - byteBuffer = ByteBuffer.allocate(size); - byteBuffer.flip(); - charBuffer = CharBuffer.allocate((int) (size * decoder.averageCharsPerByte())); - } - - public int read(char[] buf, int offset, int count) throws IOException - { - // I declared channel being null meaning that the reader is closed. - if (!channel.isOpen()) - throw new IOException("Reader was already closed."); - - // I declared decoder being null meaning that there is no more data to read - // and convert. - if (decoder == null) - return -1; - - // Stores the amount of character being read. It -1 so that if no conversion - // occured the caller will see this as an 'end of file'. - int sum = -1; - - // Copies any characters which may be left from the last invocation into the - // destination array. - if (charBuffer.remaining() > 0) - { - sum = Math.min(count, charBuffer.remaining()); - charBuffer.get(buf, offset, sum); - - // Updates the control variables according to the latest copy operation. - offset += sum; - count -= sum; - } - - // Copies the character which have not been put in the destination array to - // the beginning. If data is actually copied count will be 0. If no data is - // copied count is >0 and we can now convert some more characters. - charBuffer.compact(); - - int converted = 0; - boolean last = false; - - while (count != 0) - { - // Tries to convert some bytes (Which will intentionally fail in the - // first place because we have not read any bytes yet.) - CoderResult result = decoder.decode(byteBuffer, charBuffer, last); - if (result.isMalformed() || result.isUnmappable()) - { - // JDK throws exception when bytes are malformed for sure. - // FIXME: Unsure what happens when a character is simply - // unmappable. - result.throwException(); - } - - // Marks that we should end this loop regardless whether the caller - // wants more chars or not, when this was the last conversion. - if (last) - { - decoder = null; - } - else if (result.isUnderflow()) - { - // We need more bytes to do the conversion. - - // Copies the not yet converted bytes to the beginning making it - // being able to receive more bytes. - byteBuffer.compact(); - - // Reads in another bunch of bytes for being converted. - if (channel.read(byteBuffer) == -1) - { - // If there is no more data available in the channel we mark - // that state for the final character conversion run which is - // done in the next loop iteration. - last = true; - } - - // Prepares the byteBuffer for the next character conversion run. - byteBuffer.flip(); - } - - // Prepares the charBuffer for being drained. - charBuffer.flip(); - - converted = Math.min(count, charBuffer.remaining()); - charBuffer.get(buf, offset, converted); - - // Copies characters which have not yet being copied into the char-Array - // to the beginning making it possible to read them later (If data is - // really copied here, then the caller has received enough characters so - // far.). - charBuffer.compact(); - - // Updates the control variables according to the latest copy operation. - offset += converted; - count -= converted; - - // Updates the amount of transferred characters. - sum += converted; - - if (decoder == null) - { - break; - } - - // Now that more characters have been transfered we let the loop decide - // what to do next. - } - - // Makes the charBuffer ready for reading on the next invocation. - charBuffer.flip(); - - return sum; - } - - public void close() throws IOException - { - channel.close(); - - // Makes sure all intermediate data is released by the decoder. - if (decoder != null) - decoder.reset(); - } - -} diff --git a/libjava/gnu/java/nio/FileLockImpl.java b/libjava/gnu/java/nio/FileLockImpl.java deleted file mode 100644 index 245fa73402a..00000000000 --- a/libjava/gnu/java/nio/FileLockImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* FileLockImpl.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import gnu.java.nio.channels.FileChannelImpl; - -import java.io.IOException; -import java.nio.channels.FileLock; - -/** - * @author Michael Koch - * @since 1.4 - */ -public class FileLockImpl extends FileLock -{ - private FileChannelImpl ch; - - public FileLockImpl (FileChannelImpl channel, long position, - long size, boolean shared) - { - super (channel, position, size, shared); - ch = channel; - } - - protected void finalize() - { - try - { - release(); - } - catch (IOException e) - { - // Ignore this. - } - } - - public boolean isValid () - { - return channel().isOpen(); - } - - public synchronized void release () throws IOException - { - ch.unlock(position(), size()); - } -} diff --git a/libjava/gnu/java/nio/InputStreamChannel.java b/libjava/gnu/java/nio/InputStreamChannel.java deleted file mode 100644 index a3dffe24554..00000000000 --- a/libjava/gnu/java/nio/InputStreamChannel.java +++ /dev/null @@ -1,88 +0,0 @@ -/* InputStreamChannel.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.ReadableByteChannel; - -/** - * @author Michael Koch - */ -public final class InputStreamChannel implements ReadableByteChannel -{ - private boolean closed = false; - private InputStream in; - - public InputStreamChannel (InputStream in) - { - super(); - this.in = in; - } - - public void close() throws IOException - { - if (!closed) - { - in.close(); - closed = true; - } - } - - public boolean isOpen() - { - return !closed; - } - - public int read (ByteBuffer dst) throws IOException - { - if (!isOpen()) - throw new ClosedChannelException(); - - byte[] buffer = new byte [dst.remaining()]; - int readBytes = in.read (buffer); - - if (readBytes > 0) - dst.put (buffer, 0, readBytes); - - return readBytes; - } -} diff --git a/libjava/gnu/java/nio/NIOConstants.java b/libjava/gnu/java/nio/NIOConstants.java deleted file mode 100644 index bb5b3b7f940..00000000000 --- a/libjava/gnu/java/nio/NIOConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* NIOConstants.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -/** - * @author Michael Koch - */ -public final class NIOConstants -{ - public static final int DEFAULT_TIMEOUT = 50; -} diff --git a/libjava/gnu/java/nio/NIODatagramSocket.java b/libjava/gnu/java/nio/NIODatagramSocket.java deleted file mode 100644 index f23236eca88..00000000000 --- a/libjava/gnu/java/nio/NIODatagramSocket.java +++ /dev/null @@ -1,71 +0,0 @@ -/* NIODatagramSocket.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import gnu.java.net.PlainDatagramSocketImpl; - -import java.net.DatagramSocket; -import java.nio.channels.DatagramChannel; - -/** - * @author Michael Koch - */ -public final class NIODatagramSocket extends DatagramSocket -{ - private PlainDatagramSocketImpl impl; - private DatagramChannelImpl channel; - - public NIODatagramSocket (PlainDatagramSocketImpl impl, - DatagramChannelImpl channel) - { - super (impl); - this.impl = impl; - this.channel = channel; - } - - public final PlainDatagramSocketImpl getPlainDatagramSocketImpl() - { - return impl; - } - - public final DatagramChannel getChannel() - { - return channel; - } -} diff --git a/libjava/gnu/java/nio/NIOSocket.java b/libjava/gnu/java/nio/NIOSocket.java deleted file mode 100644 index 4d812bf44ba..00000000000 --- a/libjava/gnu/java/nio/NIOSocket.java +++ /dev/null @@ -1,77 +0,0 @@ -/* NIOSocket.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import gnu.java.net.PlainSocketImpl; -import java.io.IOException; -import java.net.Socket; -import java.nio.channels.SocketChannel; - -/** - * @author Michael Koch - */ -public final class NIOSocket extends Socket -{ - private PlainSocketImpl impl; - private SocketChannelImpl channel; - - protected NIOSocket (PlainSocketImpl impl, SocketChannelImpl channel) - throws IOException - { - super (impl); - this.impl = impl; - this.channel = channel; - } - - public final PlainSocketImpl getPlainSocketImpl() - { - return impl; - } - - final void setChannel (SocketChannelImpl channel) - { - this.impl = channel.getPlainSocketImpl(); - this.channel = channel; - } - - public final SocketChannel getChannel() - { - return channel; - } -} diff --git a/libjava/gnu/java/nio/OutputStreamChannel.java b/libjava/gnu/java/nio/OutputStreamChannel.java deleted file mode 100644 index 8167426b07d..00000000000 --- a/libjava/gnu/java/nio/OutputStreamChannel.java +++ /dev/null @@ -1,87 +0,0 @@ -/* OutputStreamChannel.java -- - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.WritableByteChannel; - -/** - * @author Michael Koch - */ -public final class OutputStreamChannel implements WritableByteChannel -{ - private boolean closed = false; - private OutputStream out; - - public OutputStreamChannel (OutputStream out) - { - super(); - - this.out = out; - } - - public void close() throws IOException - { - if (!closed) - { - out.close(); - closed = true; - } - } - - public boolean isOpen() - { - return !closed; - } - - public int write (ByteBuffer src) throws IOException - { - if (!isOpen()) - throw new ClosedChannelException(); - - int len = src.remaining(); - byte[] buffer = new byte [len]; - src.get (buffer); - out.write (buffer); - return len; - } -} diff --git a/libjava/gnu/java/nio/PipeImpl.java b/libjava/gnu/java/nio/PipeImpl.java deleted file mode 100644 index f7b01c8b740..00000000000 --- a/libjava/gnu/java/nio/PipeImpl.java +++ /dev/null @@ -1,184 +0,0 @@ -/* PipeImpl.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.Pipe; -import java.nio.channels.spi.SelectorProvider; - -class PipeImpl extends Pipe -{ - public static final class SourceChannelImpl extends Pipe.SourceChannel - { - private int native_fd; - - public SourceChannelImpl (SelectorProvider selectorProvider, - int native_fd) - { - super (selectorProvider); - this.native_fd = native_fd; - } - - protected final void implCloseSelectableChannel() - throws IOException - { - throw new Error ("Not implemented"); - } - - protected void implConfigureBlocking (boolean blocking) - throws IOException - { - throw new Error ("Not implemented"); - } - - public final int read (ByteBuffer src) - throws IOException - { - throw new Error ("Not implemented"); - } - - public final long read (ByteBuffer[] srcs) - throws IOException - { - return read (srcs, 0, srcs.length); - } - - public final synchronized long read (ByteBuffer[] srcs, int offset, - int len) - throws IOException - { - if (offset < 0 - || offset > srcs.length - || len < 0 - || len > srcs.length - offset) - throw new IndexOutOfBoundsException(); - - long bytesRead = 0; - - for (int index = 0; index < len; index++) - bytesRead += read (srcs [offset + index]); - - return bytesRead; - - } - - public final int getNativeFD() - { - return native_fd; - } - } - - public static final class SinkChannelImpl extends Pipe.SinkChannel - { - private int native_fd; - - public SinkChannelImpl (SelectorProvider selectorProvider, - int native_fd) - { - super (selectorProvider); - this.native_fd = native_fd; - } - - protected final void implCloseSelectableChannel() - throws IOException - { - throw new Error ("Not implemented"); - } - - protected final void implConfigureBlocking (boolean blocking) - throws IOException - { - throw new Error ("Not implemented"); - } - - public final int write (ByteBuffer dst) - throws IOException - { - throw new Error ("Not implemented"); - } - - public final long write (ByteBuffer[] srcs) - throws IOException - { - return write (srcs, 0, srcs.length); - } - - public final synchronized long write (ByteBuffer[] srcs, int offset, int len) - throws IOException - { - if (offset < 0 - || offset > srcs.length - || len < 0 - || len > srcs.length - offset) - throw new IndexOutOfBoundsException(); - - long bytesWritten = 0; - - for (int index = 0; index < len; index++) - bytesWritten += write (srcs [offset + index]); - - return bytesWritten; - } - - public final int getNativeFD() - { - return native_fd; - } - } - - private SinkChannelImpl sink; - private SourceChannelImpl source; - - public PipeImpl (SelectorProvider provider) - throws IOException - { - super(); - VMPipe.init (this, provider); - } - - public Pipe.SinkChannel sink() - { - return sink; - } - - public Pipe.SourceChannel source() - { - return source; - } -} diff --git a/libjava/gnu/java/nio/SelectionKeyImpl.java b/libjava/gnu/java/nio/SelectionKeyImpl.java deleted file mode 100644 index a1f125e9f8b..00000000000 --- a/libjava/gnu/java/nio/SelectionKeyImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -/* SelectionKeyImpl.java -- - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio; - -import java.nio.channels.CancelledKeyException; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.spi.AbstractSelectionKey; - -public abstract class SelectionKeyImpl extends AbstractSelectionKey -{ - private int readyOps; - private int interestOps; - private SelectorImpl impl; - SelectableChannel ch; - - public SelectionKeyImpl (SelectableChannel ch, SelectorImpl impl) - { - this.ch = ch; - this.impl = impl; - } - - public SelectableChannel channel () - { - return ch; - } - - public int readyOps () - { - if (!isValid()) - throw new CancelledKeyException(); - - return readyOps; - } - - public SelectionKey readyOps (int ops) - { - if (!isValid()) - throw new CancelledKeyException(); - - readyOps = ops; - return this; - } - - public int interestOps () - { - if (!isValid()) - throw new CancelledKeyException(); - - return interestOps; - } - - public SelectionKey interestOps (int ops) - { - if (!isValid()) - throw new CancelledKeyException(); - - interestOps = ops; - return this; - } - - public Selector selector () - { - return impl; - } - - public abstract int getNativeFD(); -} diff --git a/libjava/gnu/java/nio/SelectorImpl.java b/libjava/gnu/java/nio/SelectorImpl.java deleted file mode 100644 index dcafedeb8bb..00000000000 --- a/libjava/gnu/java/nio/SelectorImpl.java +++ /dev/null @@ -1,394 +0,0 @@ -/* SelectorImpl.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio; - -import java.io.IOException; -import java.nio.channels.ClosedSelectorException; -import java.nio.channels.SelectableChannel; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.spi.AbstractSelectableChannel; -import java.nio.channels.spi.AbstractSelector; -import java.nio.channels.spi.SelectorProvider; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public class SelectorImpl extends AbstractSelector -{ - private Set keys; - private Set selected; - - /** - * A dummy object whose monitor regulates access to both our - * selectThread and unhandledWakeup fields. - */ - private Object selectThreadMutex = new Object (); - - /** - * Any thread that's currently blocked in a select operation. - */ - private Thread selectThread; - - /** - * Indicates whether we have an unhandled wakeup call. This can - * be due to either wakeup() triggering a thread interruption while - * a thread was blocked in a select operation (in which case we need - * to reset this thread's interrupt status after interrupting the - * select), or else that no thread was on a select operation at the - * time that wakeup() was called, in which case the following select() - * operation should return immediately with nothing selected. - */ - private boolean unhandledWakeup; - - public SelectorImpl (SelectorProvider provider) - { - super (provider); - - keys = new HashSet (); - selected = new HashSet (); - } - - protected void finalize() throws Throwable - { - close(); - } - - protected final void implCloseSelector() - throws IOException - { - // Cancel any pending select operation. - wakeup(); - - synchronized (keys) - { - synchronized (selected) - { - synchronized (cancelledKeys ()) - { - // FIXME: Release resources here. - } - } - } - } - - public final Set keys() - { - if (!isOpen()) - throw new ClosedSelectorException(); - - return Collections.unmodifiableSet (keys); - } - - public final int selectNow() - throws IOException - { - // FIXME: We're simulating an immediate select - // via a select with a timeout of one millisecond. - return select (1); - } - - public final int select() - throws IOException - { - return select (0); - } - - private final int[] getFDsAsArray (int ops) - { - int[] result; - int counter = 0; - Iterator it = keys.iterator (); - - // Count the number of file descriptors needed - while (it.hasNext ()) - { - SelectionKeyImpl key = (SelectionKeyImpl) it.next (); - - if ((key.interestOps () & ops) != 0) - { - counter++; - } - } - - result = new int[counter]; - - counter = 0; - it = keys.iterator (); - - // Fill the array with the file descriptors - while (it.hasNext ()) - { - SelectionKeyImpl key = (SelectionKeyImpl) it.next (); - - if ((key.interestOps () & ops) != 0) - { - result[counter] = key.getNativeFD(); - counter++; - } - } - - return result; - } - - public synchronized int select (long timeout) - throws IOException - { - if (!isOpen()) - throw new ClosedSelectorException(); - - synchronized (keys) - { - synchronized (selected) - { - deregisterCancelledKeys(); - - // Set only keys with the needed interest ops into the arrays. - int[] read = getFDsAsArray (SelectionKey.OP_READ - | SelectionKey.OP_ACCEPT); - int[] write = getFDsAsArray (SelectionKey.OP_WRITE - | SelectionKey.OP_CONNECT); - - // FIXME: We dont need to check this yet - int[] except = new int [0]; - - // Test to see if we've got an unhandled wakeup call, - // in which case we return immediately. Otherwise, - // remember our current thread and jump into the select. - // The monitor for dummy object selectThreadMutex regulates - // access to these fields. - - // FIXME: Not sure from the spec at what point we should - // return "immediately". Is it here or immediately upon - // entry to this function? - - // NOTE: There's a possibility of another thread calling - // wakeup() immediately after our thread releases - // selectThreadMutex's monitor here, in which case we'll - // do the select anyway. Since calls to wakeup() and select() - // among different threads happen in non-deterministic order, - // I don't think this is an issue. - synchronized (selectThreadMutex) - { - if (unhandledWakeup) - { - unhandledWakeup = false; - return 0; - } - else - { - selectThread = Thread.currentThread (); - } - } - - // Call the native select() on all file descriptors. - int result = 0; - try - { - begin(); - result = VMSelector.select (read, write, except, timeout); - } - finally - { - end(); - } - - // If our unhandled wakeup flag is set at this point, - // reset our thread's interrupt flag because we were - // awakened by wakeup() instead of an external thread - // interruption. - // - // NOTE: If we were blocked in a select() and one thread - // called Thread.interrupt() on the blocked thread followed - // by another thread calling Selector.wakeup(), then race - // conditions could make it so that the thread's interrupt - // flag is reset even though the Thread.interrupt() call - // "was there first". I don't think we need to care about - // this scenario. - synchronized (selectThreadMutex) - { - if (unhandledWakeup) - { - unhandledWakeup = false; - Thread.interrupted (); - } - selectThread = null; - } - - Iterator it = keys.iterator (); - - while (it.hasNext ()) - { - int ops = 0; - SelectionKeyImpl key = (SelectionKeyImpl) it.next (); - - // If key is already selected retrieve old ready ops. - if (selected.contains (key)) - { - ops = key.readyOps (); - } - - // Set new ready read/accept ops - for (int i = 0; i < read.length; i++) - { - if (key.getNativeFD() == read[i]) - { - if (key.channel () instanceof ServerSocketChannelImpl) - { - ops = ops | SelectionKey.OP_ACCEPT; - } - else - { - ops = ops | SelectionKey.OP_READ; - } - } - } - - // Set new ready write ops - for (int i = 0; i < write.length; i++) - { - if (key.getNativeFD() == write[i]) - { - ops = ops | SelectionKey.OP_WRITE; - - // if (key.channel ().isConnected ()) - // { - // ops = ops | SelectionKey.OP_WRITE; - // } - // else - // { - // ops = ops | SelectionKey.OP_CONNECT; - // } - } - } - - // FIXME: We dont handle exceptional file descriptors yet. - - // If key is not yet selected add it. - if (!selected.contains (key)) - { - selected.add (key); - } - - // Set new ready ops - key.readyOps (key.interestOps () & ops); - } - deregisterCancelledKeys(); - - return result; - } - } - } - - public final Set selectedKeys() - { - if (!isOpen()) - throw new ClosedSelectorException(); - - return selected; - } - - public final Selector wakeup() - { - // IMPLEMENTATION NOTE: Whereas the specification says that - // thread interruption should trigger a call to wakeup, we - // do the reverse under the covers: wakeup triggers a thread - // interrupt followed by a subsequent reset of the thread's - // interrupt status within select(). - - // First, acquire the monitor of the object regulating - // access to our selectThread and unhandledWakeup fields. - synchronized (selectThreadMutex) - { - unhandledWakeup = true; - - // Interrupt any thread which is currently blocked in - // a select operation. - if (selectThread != null) - selectThread.interrupt (); - } - - return this; - } - - private final void deregisterCancelledKeys() - { - Set ckeys = cancelledKeys (); - synchronized (ckeys) - { - Iterator it = ckeys.iterator(); - - while (it.hasNext ()) - { - keys.remove ((SelectionKeyImpl) it.next ()); - it.remove (); - } - } - } - - protected SelectionKey register (SelectableChannel ch, int ops, Object att) - { - return register ((AbstractSelectableChannel) ch, ops, att); - } - - protected final SelectionKey register (AbstractSelectableChannel ch, int ops, - Object att) - { - SelectionKeyImpl result; - - if (ch instanceof SocketChannelImpl) - result = new SocketChannelSelectionKey (ch, this); - else if (ch instanceof DatagramChannelImpl) - result = new DatagramChannelSelectionKey (ch, this); - else if (ch instanceof ServerSocketChannelImpl) - result = new ServerSocketChannelSelectionKey (ch, this); - else - throw new InternalError ("No known channel type"); - - synchronized (keys) - { - keys.add (result); - } - - result.interestOps (ops); - result.attach (att); - return result; - } -} diff --git a/libjava/gnu/java/nio/SelectorProviderImpl.java b/libjava/gnu/java/nio/SelectorProviderImpl.java deleted file mode 100644 index 47521107e90..00000000000 --- a/libjava/gnu/java/nio/SelectorProviderImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* SelectorProviderImpl.java -- - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio; - -import java.io.IOException; -import java.nio.channels.DatagramChannel; -import java.nio.channels.Pipe; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.AbstractSelector; -import java.nio.channels.spi.SelectorProvider; - -public class SelectorProviderImpl extends SelectorProvider -{ - public SelectorProviderImpl () - { - } - - public DatagramChannel openDatagramChannel () - throws IOException - { - return new DatagramChannelImpl (this); - } - - public Pipe openPipe () - throws IOException - { - return new PipeImpl (this); - } - - public AbstractSelector openSelector () - throws IOException - { - return new SelectorImpl (this); - } - - public ServerSocketChannel openServerSocketChannel () - throws IOException - { - return new ServerSocketChannelImpl (this); - } - - public SocketChannel openSocketChannel () - throws IOException - { - return new SocketChannelImpl (this); - } -} diff --git a/libjava/gnu/java/nio/charset/ISO_8859_1.java b/libjava/gnu/java/nio/charset/ISO_8859_1.java deleted file mode 100644 index cc06ecd5ad0..00000000000 --- a/libjava/gnu/java/nio/charset/ISO_8859_1.java +++ /dev/null @@ -1,155 +0,0 @@ -/* ISO_8859_1.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; - -/** - * ISO-8859-1 charset. - * - * @author Jesse Rosenstock - */ -final class ISO_8859_1 extends Charset -{ - ISO_8859_1 () - { - /* Canonical charset name chosen according to: - * http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html - */ - super ("ISO-8859-1", new String[] { - /* These names are provided by - * http://www.iana.org/assignments/character-sets - */ - "iso-ir-100", - "ISO_8859-1", - "latin1", - "l1", - "IBM819", - "CP819", - "csISOLatin1", - "8859_1", - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "ISO8859_1", "ISO_8859_1", "ibm-819", "ISO_8859-1:1987", - "819" - }); - - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII || cs instanceof ISO_8859_1; - } - - public CharsetDecoder newDecoder () - { - return new Decoder (this); - } - - public CharsetEncoder newEncoder () - { - return new Encoder (this); - } - - private static final class Decoder extends CharsetDecoder - { - // Package-private to avoid a trampoline constructor. - Decoder (Charset cs) - { - super (cs, 1.0f, 1.0f); - } - - protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - while (in.hasRemaining ()) - { - byte b = in.get (); - - if (!out.hasRemaining ()) - { - in.position (in.position () - 1); - return CoderResult.OVERFLOW; - } - - out.put ((char) (b & 0xFF)); - } - - return CoderResult.UNDERFLOW; - } - } - - private static final class Encoder extends CharsetEncoder - { - // Package-private to avoid a trampoline constructor. - Encoder (Charset cs) - { - super (cs, 1.0f, 1.0f); - } - - protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - while (in.hasRemaining ()) - { - char c = in.get (); - - if (c > 0xFF) - { - in.position (in.position () - 1); - return CoderResult.unmappableForLength (1); - } - if (!out.hasRemaining ()) - { - in.position (in.position () - 1); - return CoderResult.OVERFLOW; - } - - out.put ((byte) c); - } - - return CoderResult.UNDERFLOW; - } - } -} diff --git a/libjava/gnu/java/nio/charset/US_ASCII.java b/libjava/gnu/java/nio/charset/US_ASCII.java deleted file mode 100644 index d26f7ffc9ab..00000000000 --- a/libjava/gnu/java/nio/charset/US_ASCII.java +++ /dev/null @@ -1,161 +0,0 @@ -/* US_ASCII.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; - -/** - * US-ASCII charset. - * - * @author Jesse Rosenstock - */ -final class US_ASCII extends Charset -{ - US_ASCII () - { - /* Canonical charset name chosen according to: - * http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html - */ - super ("US-ASCII", new String[] { - /* These names are provided by - * http://www.iana.org/assignments/character-sets - */ - "iso-ir-6", - "ANSI_X3.4-1986", - "ISO_646.irv:1991", - "ASCII", - "ISO646-US", - "ASCII", - "us", - "IBM367", - "cp367", - "csASCII", - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "ANSI_X3.4-1968", "iso_646.irv:1983", "ascii7", "646", - "windows-20127" - }); - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII; - } - - public CharsetDecoder newDecoder () - { - return new Decoder (this); - } - - public CharsetEncoder newEncoder () - { - return new Encoder (this); - } - - private static final class Decoder extends CharsetDecoder - { - // Package-private to avoid a trampoline constructor. - Decoder (Charset cs) - { - super (cs, 1.0f, 1.0f); - } - - protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - while (in.hasRemaining ()) - { - byte b = in.get (); - - if (b < 0) - { - in.position (in.position () - 1); - return CoderResult.malformedForLength (1); - } - if (!out.hasRemaining ()) - { - in.position (in.position () - 1); - return CoderResult.OVERFLOW; - } - - out.put ((char) b); - } - - return CoderResult.UNDERFLOW; - } - } - - private static final class Encoder extends CharsetEncoder - { - // Package-private to avoid a trampoline constructor. - Encoder (Charset cs) - { - super (cs, 1.0f, 1.0f); - } - - protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - while (in.hasRemaining ()) - { - char c = in.get (); - - if (c > Byte.MAX_VALUE) - { - in.position (in.position () - 1); - return CoderResult.unmappableForLength (1); - } - if (!out.hasRemaining ()) - { - in.position (in.position () - 1); - return CoderResult.OVERFLOW; - } - - out.put ((byte) c); - } - - return CoderResult.UNDERFLOW; - } - } -} diff --git a/libjava/gnu/java/nio/charset/UTF_16.java b/libjava/gnu/java/nio/charset/UTF_16.java deleted file mode 100644 index f111266ab59..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_16.java +++ /dev/null @@ -1,80 +0,0 @@ -/* UTF_16.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio.charset; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; - -/** - * UTF-16 charset. - * - * @author Jesse Rosenstock - */ -final class UTF_16 extends Charset -{ - UTF_16 () - { - super ("UTF-16", new String[] { - // witnessed by the internet - "UTF16", - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "ISO-10646-UCS-2", "unicode", "csUnicode", "ucs-2" - }); - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII || cs instanceof ISO_8859_1 - || cs instanceof UTF_8 || cs instanceof UTF_16BE - || cs instanceof UTF_16LE || cs instanceof UTF_16; - } - - public CharsetDecoder newDecoder () - { - return new UTF_16Decoder (this, UTF_16Decoder.UNKNOWN_ENDIAN); - } - - public CharsetEncoder newEncoder () - { - return new UTF_16Encoder (this, UTF_16Encoder.BIG_ENDIAN, false); - } -} diff --git a/libjava/gnu/java/nio/charset/UTF_16BE.java b/libjava/gnu/java/nio/charset/UTF_16BE.java deleted file mode 100644 index 15e308fab56..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_16BE.java +++ /dev/null @@ -1,84 +0,0 @@ -/* UTF_16BE.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio.charset; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; - -/** - * UTF-16BE charset. - * - * @author Jesse Rosenstock - */ -final class UTF_16BE extends Charset -{ - UTF_16BE () - { - super ("UTF-16BE", new String[] { - // witnessed by the internet - "UTF16BE", - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "x-utf-16be", "ibm-1200", "ibm-1201", "ibm-5297", - "ibm-13488", "ibm-17584", "windows-1201", "cp1200", "cp1201", - "UTF16_BigEndian", - // see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html - "UnicodeBigUnmarked" - }); - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII || cs instanceof ISO_8859_1 - || cs instanceof UTF_8 || cs instanceof UTF_16BE - || cs instanceof UTF_16LE || cs instanceof UTF_16; - } - - public CharsetDecoder newDecoder () - { - return new UTF_16Decoder (this, UTF_16Decoder.BIG_ENDIAN); - } - - public CharsetEncoder newEncoder () - { - return new UTF_16Encoder (this, UTF_16Encoder.BIG_ENDIAN, true); - } -} diff --git a/libjava/gnu/java/nio/charset/UTF_16Decoder.java b/libjava/gnu/java/nio/charset/UTF_16Decoder.java deleted file mode 100644 index ddcea88dd36..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_16Decoder.java +++ /dev/null @@ -1,151 +0,0 @@ -/* UTF_16Decoder.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CoderResult; - -/** - * Decoder for UTF-16, UTF-15LE, and UTF-16BE. - * - * @author Jesse Rosenstock - */ -final class UTF_16Decoder extends CharsetDecoder -{ - // byte orders - static final int BIG_ENDIAN = 0; - static final int LITTLE_ENDIAN = 1; - static final int UNKNOWN_ENDIAN = 2; - - private static final char BYTE_ORDER_MARK = '\uFEFF'; - private static final char REVERSED_BYTE_ORDER_MARK = '\uFFFE'; - - private final int originalByteOrder; - private int byteOrder; - - UTF_16Decoder (Charset cs, int byteOrder) - { - super (cs, 0.5f, 1.0f); - this.originalByteOrder = byteOrder; - this.byteOrder = byteOrder; - } - - protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - - int inPos = in.position (); - try - { - while (in.remaining () >= 2) - { - byte b1 = in.get (); - byte b2 = in.get (); - - // handle byte order mark - if (byteOrder == UNKNOWN_ENDIAN) - { - char c = (char) ((b1 << 8) | b2); - if (c == BYTE_ORDER_MARK) - { - byteOrder = BIG_ENDIAN; - inPos += 2; - continue; - } - else if (c == REVERSED_BYTE_ORDER_MARK) - { - byteOrder = LITTLE_ENDIAN; - inPos += 2; - continue; - } - else - { - // assume big endian, do not consume bytes, - // continue with normal processing - byteOrder = BIG_ENDIAN; - } - } - - char c = byteOrder == BIG_ENDIAN ? (char) ((b1 << 8) | b2) - : (char) ((b2 << 8) | b1); - - if (0xD800 <= c && c <= 0xDFFF) - { - // c is a surrogate - - // make sure c is a high surrogate - if (c > 0xDBFF) - return CoderResult.malformedForLength (2); - if (in.remaining () < 2) - return CoderResult.UNDERFLOW; - byte b3 = in.get (); - byte b4 = in.get (); - char d = byteOrder == BIG_ENDIAN ? (char) ((b3 << 8) | b4) - : (char) ((b4 << 8) | b3); - // make sure d is a low surrogate - if (d < 0xDC00 || d > 0xDFFF) - return CoderResult.malformedForLength (2); - out.put (c); - out.put (d); - inPos += 4; - } - else - { - if (!out.hasRemaining ()) - return CoderResult.UNDERFLOW; - out.put (c); - inPos += 2; - } - } - - return CoderResult.UNDERFLOW; - } - finally - { - in.position (inPos); - } - } - - protected void implReset () - { - byteOrder = originalByteOrder; - } -} diff --git a/libjava/gnu/java/nio/charset/UTF_16Encoder.java b/libjava/gnu/java/nio/charset/UTF_16Encoder.java deleted file mode 100644 index ae613355171..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_16Encoder.java +++ /dev/null @@ -1,153 +0,0 @@ -/* UTF_16Encoder.java -- - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; - -/** - * Encoder for UTF-16, UTF-15LE, and UTF-16BE. - * - * @author Jesse Rosenstock - */ -final class UTF_16Encoder extends CharsetEncoder -{ - // byte orders - static final int BIG_ENDIAN = 0; - static final int LITTLE_ENDIAN = 1; - - private static final char BYTE_ORDER_MARK = '\uFEFF'; - - private final int byteOrder; - private final boolean useByteOrderMark; - private boolean needsByteOrderMark; - - UTF_16Encoder (Charset cs, int byteOrder, boolean useByteOrderMark) - { - super (cs, 2.0f, - useByteOrderMark ? 2.0f : 4.0f, - byteOrder == BIG_ENDIAN - ? new byte[] { (byte) 0xFF, (byte) 0xFD } - : new byte[] { (byte) 0xFD, (byte) 0xFF }); - this.byteOrder = byteOrder; - this.useByteOrderMark = useByteOrderMark; - this.needsByteOrderMark = useByteOrderMark; - } - - protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - - if (needsByteOrderMark) - { - if (out.remaining () < 2) - return CoderResult.OVERFLOW; - put (out, BYTE_ORDER_MARK); - needsByteOrderMark = false; - } - - int inPos = in.position (); - try - { - while (in.hasRemaining ()) - { - char c = in.get (); - - if (0xD800 <= c && c <= 0xDFFF) - { - // c is a surrogate - - // make sure c is a high surrogate - if (c > 0xDBFF) - return CoderResult.malformedForLength (1); - if (in.remaining () < 1) - return CoderResult.UNDERFLOW; - char d = in.get (); - // make sure d is a low surrogate - if (d < 0xDC00 || d > 0xDFFF) - return CoderResult.malformedForLength (1); - put (out, c); - put (out, d); - inPos += 2; - } - else - { - if (out.remaining () < 2) - return CoderResult.OVERFLOW; - put (out, c); - inPos++; - } - } - - return CoderResult.UNDERFLOW; - } - finally - { - in.position (inPos); - } - } - - /** - * Writes <code>c</code> to <code>out</code> in the byte order - * specified by <code>byteOrder</code>. - **/ - private void put (ByteBuffer out, char c) - { - if (byteOrder == BIG_ENDIAN) - { - out.put ((byte) (c >> 8)); - out.put ((byte) (c & 0xFF)); - } - else - { - out.put ((byte) (c & 0xFF)); - out.put ((byte) (c >> 8)); - } - } - - protected void implReset () - { - needsByteOrderMark = useByteOrderMark; - } - - // TODO: override canEncode(char) and canEncode(CharSequence) - // for performance -} diff --git a/libjava/gnu/java/nio/charset/UTF_16LE.java b/libjava/gnu/java/nio/charset/UTF_16LE.java deleted file mode 100644 index 952f4aa1700..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_16LE.java +++ /dev/null @@ -1,83 +0,0 @@ -/* UTF_16LE.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.nio.charset; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; - -/** - * UTF-16LE charset. - * - * @author Jesse Rosenstock - */ -final class UTF_16LE extends Charset -{ - UTF_16LE () - { - super ("UTF-16LE", new String[] { - // witnessed by the internet - "UTF16LE", - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "x-utf-16le", "ibm-1202", "ibm-13490", "ibm-17586", - "UTF16_LittleEndian", - // see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html - "UnicodeLittleUnmarked" - }); - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII || cs instanceof ISO_8859_1 - || cs instanceof UTF_8 || cs instanceof UTF_16BE - || cs instanceof UTF_16LE || cs instanceof UTF_16; - } - - public CharsetDecoder newDecoder () - { - return new UTF_16Decoder (this, UTF_16Decoder.LITTLE_ENDIAN); - } - - public CharsetEncoder newEncoder () - { - return new UTF_16Encoder (this, UTF_16Encoder.LITTLE_ENDIAN, true); - } -} diff --git a/libjava/gnu/java/nio/charset/UTF_8.java b/libjava/gnu/java/nio/charset/UTF_8.java deleted file mode 100644 index 12f15e1b0c2..00000000000 --- a/libjava/gnu/java/nio/charset/UTF_8.java +++ /dev/null @@ -1,289 +0,0 @@ -/* UTF_8.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.nio.charset; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; - -/** - * UTF-8 charset. - * - * <p> UTF-8 references: - * <ul> - * <li> <a href="http://ietf.org/rfc/rfc2279.txt">RFC 2279</a> - * <li> The <a href="http://www.unicode.org/unicode/standard/standard.html"> - * Unicode standard</a> and - * <a href="http://www.unicode.org/versions/corrigendum1.html"> - * Corrigendum</a> - * </ul> - * - * @author Jesse Rosenstock - */ -final class UTF_8 extends Charset -{ - UTF_8 () - { - super ("UTF-8", new String[] { - /* These names are provided by - * http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL - */ - "ibm-1208", "ibm-1209", "ibm-5304", "ibm-5305", - "windows-65001", "cp1208", - // see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html - "UTF8" - }); - } - - public boolean contains (Charset cs) - { - return cs instanceof US_ASCII || cs instanceof ISO_8859_1 - || cs instanceof UTF_8 || cs instanceof UTF_16BE - || cs instanceof UTF_16LE || cs instanceof UTF_16; - } - - public CharsetDecoder newDecoder () - { - return new Decoder (this); - } - - public CharsetEncoder newEncoder () - { - return new Encoder (this); - } - - private static final class Decoder extends CharsetDecoder - { - // Package-private to avoid a trampoline constructor. - Decoder (Charset cs) - { - super (cs, 1.0f, 1.0f); - } - - protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - int inPos = in.position(); - try - { - while (in.hasRemaining ()) - { - char c; - byte b1 = in.get (); - int highNibble = (b1 >> 4) & 0xF; - - switch (highNibble) - { - case 0: case 1: case 2: case 3: - case 4: case 5: case 6: case 7: - if (out.remaining () < 1) - return CoderResult.OVERFLOW; - out.put ((char) b1); - inPos++; - break; - - case 0xC: case 0xD: - byte b2; - if (in.remaining () < 1) - return CoderResult.UNDERFLOW; - if (out.remaining () < 1) - return CoderResult.OVERFLOW; - if (!isContinuation (b2 = in.get ())) - return CoderResult.malformedForLength (1); - c = (char) (((b1 & 0x1F) << 6) | (b2 & 0x3F)); - // check that we had the shortest encoding - if (c <= 0x7F) - return CoderResult.malformedForLength (2); - out.put (c); - inPos += 2; - break; - - case 0xE: - byte b3; - if (in.remaining () < 2) - return CoderResult.UNDERFLOW; - if (out.remaining () < 1) - return CoderResult.OVERFLOW; - if (!isContinuation (b2 = in.get ())) - return CoderResult.malformedForLength (1); - if (!isContinuation (b3 = in.get ())) - return CoderResult.malformedForLength (1); - c = (char) (((b1 & 0x0F) << 12) - | ((b2 & 0x3F) << 6) - | (b3 & 0x3F)); - // check that we had the shortest encoding - if (c <= 0x7FF) - return CoderResult.malformedForLength (3); - out.put (c); - inPos += 3; - break; - - default: - return CoderResult.malformedForLength (1); - } - } - - return CoderResult.UNDERFLOW; - } - finally - { - // In case we did a get(), then encountered an error, reset the - // position to before the error. If there was no error, this - // will benignly reset the position to the value it already has. - in.position (inPos); - } - } - - private static boolean isContinuation (byte b) - { - return (b & 0xC0) == 0x80; - } - } - - private static final class Encoder extends CharsetEncoder - { - // Package-private to avoid a trampoline constructor. - Encoder (Charset cs) - { - // According to - // http://www-106.ibm.com/developerworks/unicode/library/utfencodingforms/index.html - // On average, English takes slightly over one unit per code point. - // Most Latin-script languages take about 1.1 bytes. Greek, Russian, - // Arabic and Hebrew take about 1.7 bytes, and most others (including - // Japanese, Chinese, Korean and Hindi) take about 3 bytes. - // We assume we will be dealing with latin scripts, and use 1.1 - // for averageBytesPerChar. - super (cs, 1.1f, 4.0f); - } - - protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) - { - int inPos = in.position(); - try - { - // TODO: Optimize this in the case in.hasArray() / out.hasArray() - while (in.hasRemaining ()) - { - int remaining = out.remaining (); - char c = in.get (); - - // UCS-4 range (hex.) UTF-8 octet sequence (binary) - // 0000 0000-0000 007F 0xxxxxxx - // 0000 0080-0000 07FF 110xxxxx 10xxxxxx - // 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx - - // Scalar Value UTF-16 byte 1 byte 2 byte 3 byte 4 - // 0000 0000 0xxx xxxx 0000 0000 0xxx xxxx 0xxx xxxx - // 0000 0yyy yyxx xxxx 0000 0yyy yyxx xxxx 110y yyyy 10xx xxxx - // zzzz yyyy yyxx xxxx zzzz yyyy yyxx xxxx 1110 zzzz 10yy yyyy 10xx xxxx - // u uuuu zzzz yyyy yyxx xxxx 1101 10ww wwzz zzyy 1111 0uuu 10uu zzzz 10yy yyyy 10xx xxxx - // + 1101 11yy yyxx xxxx - // Note: uuuuu = wwww + 1 - - if (c <= 0x7F) - { - if (remaining < 1) - return CoderResult.OVERFLOW; - out.put ((byte) c); - inPos++; - } - else if (c <= 0x7FF) - { - if (remaining < 2) - return CoderResult.OVERFLOW; - out.put ((byte) (0xC0 | (c >> 6))); - out.put ((byte) (0x80 | (c & 0x3F))); - inPos++; - } - else if (0xD800 <= c && c <= 0xDFFF) - { - if (remaining < 4) - return CoderResult.OVERFLOW; - - // we got a low surrogate without a preciding high one - if (c > 0xDBFF) - return CoderResult.malformedForLength (1); - - // high surrogates - if (!in.hasRemaining ()) - return CoderResult.UNDERFLOW; - - char d = in.get (); - - // make sure d is a low surrogate - if (d < 0xDC00 || d > 0xDFFF) - return CoderResult.malformedForLength (1); - - // make the 32 bit value - // int value2 = (c - 0xD800) * 0x400 + (d - 0xDC00) + 0x10000; - int value = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000; - // assert value == value2; - out.put ((byte) (0xF0 | (value >> 18))); - out.put ((byte) (0x80 | ((value >> 12) & 0x3F))); - out.put ((byte) (0x80 | ((value >> 6) & 0x3F))); - out.put ((byte) (0x80 | ((value ) & 0x3F))); - - inPos += 2; - } - else - { - if (remaining < 3) - return CoderResult.OVERFLOW; - - out.put ((byte) (0xE0 | (c >> 12))); - out.put ((byte) (0x80 | ((c >> 6) & 0x3F))); - out.put ((byte) (0x80 | (c & 0x3F))); - inPos++; - } - } - - return CoderResult.UNDERFLOW; - } - finally - { - // In case we did a get(), then encountered an error, reset the - // position to before the error. If there was no error, this - // will benignly reset the position to the value it already has. - in.position (inPos); - } - } - } -} diff --git a/libjava/gnu/java/rmi/RMIMarshalledObjectInputStream.java b/libjava/gnu/java/rmi/RMIMarshalledObjectInputStream.java deleted file mode 100644 index 140069379bc..00000000000 --- a/libjava/gnu/java/rmi/RMIMarshalledObjectInputStream.java +++ /dev/null @@ -1,71 +0,0 @@ -/* gnu.java.rmi.RMIMarshalledObjectInputStream - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi; - -import gnu.java.rmi.server.RMIObjectInputStream; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -/** - * This class is only for java.rmi.MarshalledObject to deserialize object from - * objBytes and locBytes - */ - -public class RMIMarshalledObjectInputStream extends RMIObjectInputStream -{ - private ObjectInputStream locStream; - - public RMIMarshalledObjectInputStream(byte[] objBytes, byte[] locBytes) throws IOException - { - super(new ByteArrayInputStream(objBytes)); - if(locBytes != null) - locStream = new ObjectInputStream(new ByteArrayInputStream(locBytes)); - } - - //This method overrides RMIObjectInputStream's - protected Object getAnnotation() throws IOException, ClassNotFoundException - { - if(locStream == null) - return null; - return locStream.readObject(); - } - -} // End of RMIMarshalledObjectInputStream diff --git a/libjava/gnu/java/rmi/RMIMarshalledObjectOutputStream.java b/libjava/gnu/java/rmi/RMIMarshalledObjectOutputStream.java deleted file mode 100644 index 2bbbaacb45f..00000000000 --- a/libjava/gnu/java/rmi/RMIMarshalledObjectOutputStream.java +++ /dev/null @@ -1,79 +0,0 @@ -/* gnu.java.rmi.RMIMarshalledObjectOutputStream - Copyright (C) 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi; - -import gnu.java.rmi.server.RMIObjectOutputStream; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.OutputStream; - -/** - * This class is only for java.rmi.MarshalledObject to serialize object and - * got objBytes and locBytes - */ -public class RMIMarshalledObjectOutputStream extends RMIObjectOutputStream -{ - private ObjectOutputStream locStream; - private ByteArrayOutputStream locBytesStream; - - public RMIMarshalledObjectOutputStream(OutputStream objStream) throws IOException - { - super(objStream); - locBytesStream = new ByteArrayOutputStream(256); - locStream = new ObjectOutputStream(locBytesStream); - } - - //This method overrides RMIObjectOutputStream's. - protected void setAnnotation(String annotation) throws IOException{ - locStream.writeObject(annotation); - } - - public void flush() throws IOException { - super.flush(); - locStream.flush(); - } - - public byte[] getLocBytes(){ - return locBytesStream.toByteArray(); - } - -} // End of RMIMarshalledObjectOutputStream - diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl.java b/libjava/gnu/java/rmi/dgc/DGCImpl.java deleted file mode 100644 index a32445c343b..00000000000 --- a/libjava/gnu/java/rmi/dgc/DGCImpl.java +++ /dev/null @@ -1,118 +0,0 @@ -/* DGCImpl.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.dgc; - -import gnu.java.rmi.server.UnicastServerRef; - -import java.rmi.RemoteException; -import java.rmi.dgc.DGC; -import java.rmi.dgc.Lease; -import java.rmi.dgc.VMID; -import java.rmi.server.ObjID; -import java.rmi.server.RMISocketFactory; -import java.util.Hashtable; - -/** - * I let DGCImpl to extend UnicastServerRef, but not - * UnicastRemoteObject, because UnicastRemoteObject must - * exportObject automatically. - */ -public class DGCImpl - extends UnicastServerRef implements DGC { - - private static final long LEASE_VALUE = 600000L; - // leaseCache caches a LeaseRecord associated with a vmid - private Hashtable leaseCache = new Hashtable(); - -public DGCImpl() throws RemoteException { - super(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory()); -} - -public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException { - VMID vmid = lease.getVMID(); - if (vmid == null) - vmid = new VMID(); - long leaseValue = LEASE_VALUE; - //long leaseValue = lease.getValue(); - lease = new Lease(vmid, leaseValue); - synchronized(leaseCache){ - LeaseRecord lr = (LeaseRecord)leaseCache.get(vmid); - if (lr != null) - lr.reset(leaseValue); - else{ - lr = new LeaseRecord(vmid, leaseValue); - leaseCache.put(vmid, lr); - } - } - - return (lease); -} - -public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException { - // Not implemented -} - - /** - * LeaseRecord associates a vmid to expireTime. - */ - private static class LeaseRecord{ - private VMID vmid; - private long expireTime; - - LeaseRecord(VMID vmid, long leaseValue){ - this.vmid = vmid; - reset(leaseValue); - } - - // reset expireTime - void reset(long leaseValue){ - long l = System.currentTimeMillis(); - expireTime = l + leaseValue; - } - - boolean isExpired(){ - long l = System.currentTimeMillis(); - if ( l > expireTime) - return true; - return false; - } - - } //End of LeaseRecord - -} //End of DGCImpl diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java b/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java deleted file mode 100644 index 5f032e72f8a..00000000000 --- a/libjava/gnu/java/rmi/dgc/DGCImpl_Skel.java +++ /dev/null @@ -1,144 +0,0 @@ -/* DGCImpl_Skel.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -// Skel class generated by rmic - DO NOT EDIT! - -package gnu.java.rmi.dgc; - -public final class DGCImpl_Skel - implements java.rmi.server.Skeleton -{ - private static final long interfaceHash = -669196253586618813L; - - private static final java.rmi.server.Operation[] operations = { - new java.rmi.server.Operation("void clean(java.rmi.server.ObjID[], long, java.rmi.dgc.VMID, boolean"), - new java.rmi.server.Operation("java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease") - }; - - public java.rmi.server.Operation[] getOperations() { - return ((java.rmi.server.Operation[]) operations.clone()); - } - - public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception { - if (opnum < 0) { - if (hash == -5803803475088455571L) { - opnum = 0; - } - else if (hash == -8139341527526761862L) { - opnum = 1; - } - else { - throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch"); - } - } - else if (hash != interfaceHash) { - throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch"); - } - - gnu.java.rmi.dgc.DGCImpl server = (gnu.java.rmi.dgc.DGCImpl)obj; - switch (opnum) { - case 0: - { - java.rmi.server.ObjID[] $param_0; - long $param_1; - java.rmi.dgc.VMID $param_2; - boolean $param_3; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.rmi.server.ObjID[])in.readObject(); - $param_1 = (long)in.readLong(); - $param_2 = (java.rmi.dgc.VMID)in.readObject(); - $param_3 = (boolean)in.readBoolean(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - server.clean($param_0, $param_1, $param_2, $param_3); - try { - java.io.ObjectOutput out = call.getResultStream(true); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - case 1: - { - java.rmi.server.ObjID[] $param_0; - long $param_1; - java.rmi.dgc.Lease $param_2; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.rmi.server.ObjID[])in.readObject(); - $param_1 = (long)in.readLong(); - $param_2 = (java.rmi.dgc.Lease)in.readObject(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - java.rmi.dgc.Lease $result = server.dirty($param_0, $param_1, $param_2); - try { - java.io.ObjectOutput out = call.getResultStream(true); - out.writeObject($result); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - default: - throw new java.rmi.UnmarshalException("invalid method number"); - } - } -} diff --git a/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java b/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java deleted file mode 100644 index b1e086a73b2..00000000000 --- a/libjava/gnu/java/rmi/dgc/DGCImpl_Stub.java +++ /dev/null @@ -1,158 +0,0 @@ -/* DGCImpl_Stub.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -// Stub class generated by rmic - DO NOT EDIT! - -package gnu.java.rmi.dgc; - -public final class DGCImpl_Stub - extends java.rmi.server.RemoteStub - implements java.rmi.dgc.DGC -{ - private static final long serialVersionUID = 2L; - - private static final long interfaceHash = -669196253586618813L; - - private static boolean useNewInvoke; - - private static final java.rmi.server.Operation[] operations = { - new java.rmi.server.Operation("void clean(java.rmi.server.ObjID[], long, java.rmi.dgc.VMID, boolean)"), - new java.rmi.server.Operation("java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)") - }; - - private static java.lang.reflect.Method $method_clean_0; - private static java.lang.reflect.Method $method_dirty_1; - - static { - try { - java.rmi.server.RemoteRef.class.getMethod("invoke", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class }); - useNewInvoke = true; - $method_clean_0 = gnu.java.rmi.dgc.DGCImpl.class.getMethod("clean", new java.lang.Class[] {java.rmi.server.ObjID[].class, long.class, java.rmi.dgc.VMID.class, boolean.class}); - $method_dirty_1 = gnu.java.rmi.dgc.DGCImpl.class.getMethod("dirty", new java.lang.Class[] {java.rmi.server.ObjID[].class, long.class, java.rmi.dgc.Lease.class}); - - } - catch (java.lang.NoSuchMethodException e) { - useNewInvoke = false; - } - } - - public DGCImpl_Stub() { - super(); - } - public DGCImpl_Stub(java.rmi.server.RemoteRef ref) { - super(ref); - } - - public void clean(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.VMID $param_2, boolean $param_3) throws java.rmi.RemoteException { - try { - if (useNewInvoke) { - ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, new java.lang.Boolean($param_3)}, -5803803475088455571L); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - out.writeLong($param_1); - out.writeObject($param_2); - out.writeBoolean($param_3); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - try { - java.io.ObjectInput in = call.getInputStream(); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - - public java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.Lease $param_2) throws java.rmi.RemoteException { - try { - if (useNewInvoke) { - java.lang.Object $result = ref.invoke(this, $method_dirty_1, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2}, -8139341527526761862L); - return ((java.rmi.dgc.Lease)$result); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 1, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - out.writeLong($param_1); - out.writeObject($param_2); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - java.rmi.dgc.Lease $result; - try { - java.io.ObjectInput in = call.getInputStream(); - $result = (java.rmi.dgc.Lease)in.readObject(); - return ($result); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - -} diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl.java b/libjava/gnu/java/rmi/registry/RegistryImpl.java deleted file mode 100644 index 0c94434d806..00000000000 --- a/libjava/gnu/java/rmi/registry/RegistryImpl.java +++ /dev/null @@ -1,154 +0,0 @@ -/* RegistryImpl.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.registry; - -import gnu.java.rmi.server.UnicastServerRef; - -import java.rmi.AccessException; -import java.rmi.AlreadyBoundException; -import java.rmi.NotBoundException; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.rmi.server.ObjID; -import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RMISocketFactory; -import java.rmi.server.UnicastRemoteObject; -import java.util.Enumeration; -import java.util.Hashtable; - -public class RegistryImpl - extends UnicastRemoteObject implements Registry { - -private Hashtable bindings = new Hashtable(); - -public RegistryImpl(int port) throws RemoteException { - this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory()); -} - -public RegistryImpl(int port, RMIClientSocketFactory cf, RMIServerSocketFactory sf) throws RemoteException { - super(new UnicastServerRef(new ObjID(ObjID.REGISTRY_ID), port, sf)); - // The following is unnecessary, because UnicastRemoteObject export itself automatically. - //((UnicastServerRef)getRef()).exportObject(this); -} - -public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException { - Object obj = bindings.get(name); - if (obj == null) { - throw new NotBoundException(name); - } - return ((Remote)obj); -} - -public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException { - if (bindings.containsKey(name)) { - throw new AlreadyBoundException(name); - } - bindings.put(name, obj); -} - -public void unbind(String name) throws RemoteException, NotBoundException, AccessException { - Object obj = bindings.remove(name); - if (obj == null) { - throw new NotBoundException(name); - } -} - -public void rebind(String name, Remote obj) throws RemoteException, AccessException { - bindings.put(name, obj); -} - -public String[] list() throws RemoteException, AccessException { - int size = bindings.size(); - String[] strings = new String[size]; - Enumeration e = bindings.keys(); - for (int i = 0; i < size; i++) { - strings[i] = (String)e.nextElement(); - } - return (strings); -} - -public static void version() { - System.out.println("rmiregistry (" - + System.getProperty("java.vm.name") - + ") " - + System.getProperty("java.vm.version")); - System.out.println("Copyright 2005 Free Software Foundation, Inc."); - System.out.println("This is free software; see the source for copying conditions. There is NO"); - System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); - System.exit(0); -} - -public static void help() { - System.out.println( -"Usage: rmiregistry [OPTION | PORT]\n" + -"\n" + -" --help Print this help, then exit\n" + -" --version Print version number, then exit\n"); - System.exit(0); -} - -public static void main(String[] args) { - int port = Registry.REGISTRY_PORT; - if (args.length > 0) { - if (args[0].equals("--version")) { - version(); - } - else if (args[0].equals("--help")) { - help(); - } - try { - port = Integer.parseInt(args[0]); - } - catch (NumberFormatException _) { - System.err.println("Bad port number - using default"); - } - } - - try { - Registry impl = LocateRegistry.createRegistry(port); - } - catch (RemoteException _) { - System.err.println("Registry failed"); - } -} - -} diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java b/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java deleted file mode 100644 index 8cf14ccc0c4..00000000000 --- a/libjava/gnu/java/rmi/registry/RegistryImpl_Skel.java +++ /dev/null @@ -1,227 +0,0 @@ -/* RegistryImpl_Skel.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -// Skel class generated by rmic - DO NOT EDIT! - -package gnu.java.rmi.registry; - -public final class RegistryImpl_Skel - implements java.rmi.server.Skeleton -{ - private static final long interfaceHash = 4905912898345647071L; - - private static final java.rmi.server.Operation[] operations = { - new java.rmi.server.Operation("void bind(java.lang.String, java.rmi.Remote"), - new java.rmi.server.Operation("java.lang.String[] list("), - new java.rmi.server.Operation("java.rmi.Remote lookup(java.lang.String"), - new java.rmi.server.Operation("void rebind(java.lang.String, java.rmi.Remote"), - new java.rmi.server.Operation("void unbind(java.lang.String") - }; - - public java.rmi.server.Operation[] getOperations() { - return ((java.rmi.server.Operation[]) operations.clone()); - } - - public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception { - if (opnum < 0) { - if (hash == 7583982177005850366L) { - opnum = 0; - } - else if (hash == 2571371476350237748L) { - opnum = 1; - } - else if (hash == -7538657168040752697L) { - opnum = 2; - } - else if (hash == -8381844669958460146L) { - opnum = 3; - } - else if (hash == 7305022919901907578L) { - opnum = 4; - } - else { - throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch"); - } - } - else if (hash != interfaceHash) { - throw new java.rmi.server.SkeletonMismatchException("interface hash mismatch"); - } - - gnu.java.rmi.registry.RegistryImpl server = (gnu.java.rmi.registry.RegistryImpl)obj; - switch (opnum) { - case 0: - { - java.lang.String $param_0; - java.rmi.Remote $param_1; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.lang.String)in.readObject(); - $param_1 = (java.rmi.Remote)in.readObject(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - server.bind($param_0, $param_1); - try { - java.io.ObjectOutput out = call.getResultStream(true); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - case 1: - { - try { - java.io.ObjectInput in = call.getInputStream(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - java.lang.String[] $result = server.list(); - try { - java.io.ObjectOutput out = call.getResultStream(true); - out.writeObject($result); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - case 2: - { - java.lang.String $param_0; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.lang.String)in.readObject(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - java.rmi.Remote $result = server.lookup($param_0); - try { - java.io.ObjectOutput out = call.getResultStream(true); - out.writeObject($result); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - case 3: - { - java.lang.String $param_0; - java.rmi.Remote $param_1; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.lang.String)in.readObject(); - $param_1 = (java.rmi.Remote)in.readObject(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - server.rebind($param_0, $param_1); - try { - java.io.ObjectOutput out = call.getResultStream(true); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - case 4: - { - java.lang.String $param_0; - try { - java.io.ObjectInput in = call.getInputStream(); - $param_0 = (java.lang.String)in.readObject(); - - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - catch (java.lang.ClassCastException e) { - throw new java.rmi.UnmarshalException("error unmarshalling arguments", e); - } - finally { - call.releaseInputStream(); - } - server.unbind($param_0); - try { - java.io.ObjectOutput out = call.getResultStream(true); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling return", e); - } - break; - } - - default: - throw new java.rmi.UnmarshalException("invalid method number"); - } - } -} diff --git a/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java b/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java deleted file mode 100644 index b289426b4fc..00000000000 --- a/libjava/gnu/java/rmi/registry/RegistryImpl_Stub.java +++ /dev/null @@ -1,293 +0,0 @@ -/* RegistryImpl_Stub.java - Copyright (C) 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -// Stub class generated by rmic - DO NOT EDIT! - -package gnu.java.rmi.registry; - -public final class RegistryImpl_Stub - extends java.rmi.server.RemoteStub - implements java.rmi.registry.Registry -{ - private static final long serialVersionUID = 2L; - - private static final long interfaceHash = 4905912898345647071L; - - private static boolean useNewInvoke; - - private static final java.rmi.server.Operation[] operations = { - new java.rmi.server.Operation("void bind(java.lang.String, java.rmi.Remote)"), - new java.rmi.server.Operation("java.lang.String[] list()"), - new java.rmi.server.Operation("java.rmi.Remote lookup(java.lang.String)"), - new java.rmi.server.Operation("void rebind(java.lang.String, java.rmi.Remote)"), - new java.rmi.server.Operation("void unbind(java.lang.String)") - }; - - private static java.lang.reflect.Method $method_bind_0; - private static java.lang.reflect.Method $method_list_1; - private static java.lang.reflect.Method $method_lookup_2; - private static java.lang.reflect.Method $method_rebind_3; - private static java.lang.reflect.Method $method_unbind_4; - - static { - try { - java.rmi.server.RemoteRef.class.getMethod("invoke", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class }); - useNewInvoke = false; - $method_bind_0 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("bind", new java.lang.Class[] {java.lang.String.class, java.rmi.Remote.class}); - $method_list_1 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("list", new java.lang.Class[] {}); - $method_lookup_2 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("lookup", new java.lang.Class[] {java.lang.String.class}); - $method_rebind_3 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("rebind", new java.lang.Class[] {java.lang.String.class, java.rmi.Remote.class}); - $method_unbind_4 = gnu.java.rmi.registry.RegistryImpl.class.getMethod("unbind", new java.lang.Class[] {java.lang.String.class}); - - } - catch (java.lang.NoSuchMethodException e) { - useNewInvoke = false; - } - } - - public RegistryImpl_Stub() { - super(); - } - public RegistryImpl_Stub(java.rmi.server.RemoteRef ref) { - super(ref); - } - - public void bind(java.lang.String $param_0, java.rmi.Remote $param_1) throws java.rmi.AccessException, java.rmi.AlreadyBoundException, java.rmi.RemoteException { - try { - if (useNewInvoke) { - ref.invoke(this, $method_bind_0, new java.lang.Object[] {$param_0, $param_1}, 7583982177005850366L); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - out.writeObject($param_1); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - try { - java.io.ObjectInput in = call.getInputStream(); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.AccessException e) { - throw e; - } - catch (java.rmi.AlreadyBoundException e) { - throw e; - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - - public java.lang.String[] list() throws java.rmi.AccessException, java.rmi.RemoteException { - try { - if (useNewInvoke) { - java.lang.Object $result = ref.invoke(this, $method_list_1, null, 2571371476350237748L); - return ((java.lang.String[])$result); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 1, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - java.lang.String[] $result; - try { - java.io.ObjectInput in = call.getInputStream(); - $result = (java.lang.String[])in.readObject(); - return ($result); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.AccessException e) { - throw e; - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - - public java.rmi.Remote lookup(java.lang.String $param_0) throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException { - try { - if (useNewInvoke) { - java.lang.Object $result = ref.invoke(this, $method_lookup_2, new java.lang.Object[] {$param_0}, -7538657168040752697L); - return ((java.rmi.Remote)$result); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 2, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - java.rmi.Remote $result; - try { - java.io.ObjectInput in = call.getInputStream(); - $result = (java.rmi.Remote)in.readObject(); - return ($result); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.AccessException e) { - throw e; - } - catch (java.rmi.NotBoundException e) { - throw e; - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - - public void rebind(java.lang.String $param_0, java.rmi.Remote $param_1) throws java.rmi.AccessException, java.rmi.RemoteException { - try { - if (useNewInvoke) { - ref.invoke(this, $method_rebind_3, new java.lang.Object[] {$param_0, $param_1}, -8381844669958460146L); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 3, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - out.writeObject($param_1); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - try { - java.io.ObjectInput in = call.getInputStream(); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.AccessException e) { - throw e; - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - - public void unbind(java.lang.String $param_0) throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException { - try { - if (useNewInvoke) { - ref.invoke(this, $method_unbind_4, new java.lang.Object[] {$param_0}, 7305022919901907578L); - } - else { - java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 4, interfaceHash); - try { - java.io.ObjectOutput out = call.getOutputStream(); - out.writeObject($param_0); - } - catch (java.io.IOException e) { - throw new java.rmi.MarshalException("error marshalling arguments", e); - } - ref.invoke(call); - try { - java.io.ObjectInput in = call.getInputStream(); - } - catch (java.io.IOException e) { - throw new java.rmi.UnmarshalException("error unmarshalling return", e); - } - finally { - ref.done(call); - } - } - } - catch (java.rmi.AccessException e) { - throw e; - } - catch (java.rmi.NotBoundException e) { - throw e; - } - catch (java.rmi.RemoteException e) { - throw e; - } - catch (java.lang.Exception e) { - throw new java.rmi.UnexpectedException("undeclared checked exception", e); - } - } - -} diff --git a/libjava/gnu/java/rmi/server/ConnectionRunnerPool.java b/libjava/gnu/java/rmi/server/ConnectionRunnerPool.java deleted file mode 100644 index 9cc57b2289f..00000000000 --- a/libjava/gnu/java/rmi/server/ConnectionRunnerPool.java +++ /dev/null @@ -1,156 +0,0 @@ -/* gnu.java.rmi.server.ConnectionRunnerPool - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.util.ArrayList; -import java.util.Arrays; - -//Should I generalize this class? - -class ConnectionRunnerPool -{ - - public static - class ConnectionRunner extends Thread{ - private UnicastConnection conn; - private volatile boolean exiting = false; - - public ConnectionRunner(ThreadGroup group, String id){ - super(group, id); - } - - public synchronized void run(){ - while(!exiting){ - if(conn == null) - try{ - wait(); - }catch(InterruptedException e){ - continue; - } - else{ - conn.run(); - conn = null; - synchronized(ConnectionRunnerPool.class){ - freelist.add(this); - if(freelist.size() == 1) - ConnectionRunnerPool.class.notifyAll(); - } - } - } - } - - public synchronized void dispatch(UnicastConnection conn){ - this.conn = conn; - notify(); - } - - void exit(){ - exiting = true; - if(conn != null) - try{ - join(500); - }catch(InterruptedException e){} - interrupt(); - } - - } - - // Should this value equal to number of CPU? - private static int size = 5; - private static int max_size = 10; - - // Package-private to avoid a trampoline. - static ArrayList freelist; - - private static ThreadGroup group = new ThreadGroup("pool"); - - static { - ConnectionRunner[] pools = new ConnectionRunner[size]; - for(int i = 0; i < pools.length; i++){ - pools[i] = new ConnectionRunner(group, new Integer(i).toString()); - pools[i].setContextClassLoader(Thread.currentThread().getContextClassLoader()); - pools[i].start(); - } - freelist = new ArrayList(Arrays.asList(pools)); - } - - public static void setSize(int size_){ - size = size_; - } - - public static void setMaxSize(int size){ - max_size = size; - } - - private static synchronized ConnectionRunner getConnectionRunner() - { - if(freelist.size() == 0){ - if(size < max_size){ - ++size; - ConnectionRunner a = new ConnectionRunner(group, new Integer(size).toString()); - a.start(); - freelist.add(a); - }else - while(freelist.size() == 0) - try{ - ConnectionRunnerPool.class.wait(); - }catch(InterruptedException e){} - } - - // always let the first in pool most busy or other scheduling plan?? - ConnectionRunner a = (ConnectionRunner)freelist.get(0); - freelist.remove(a); - return a; - } - - public static void dispatchConnection(UnicastConnection conn) - { - ConnectionRunner r = getConnectionRunner(); - r.dispatch(conn); - } - - public static void exit() - { - Thread[] list = new Thread[group.activeCount()]; - group.enumerate(list); - for(int i = 0; i < list.length; i++) - ((ConnectionRunner)list[i]).exit(); - } - -} diff --git a/libjava/gnu/java/rmi/server/ProtocolConstants.java b/libjava/gnu/java/rmi/server/ProtocolConstants.java deleted file mode 100644 index 30fb5e89b39..00000000000 --- a/libjava/gnu/java/rmi/server/ProtocolConstants.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ProtocolConstants.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -public interface ProtocolConstants -{ - int PROTOCOL_HEADER = 0x4a524d49; // JRMI - int PROTOCOL_VERSION = 2; - - int STREAM_PROTOCOL = 0x4b; - int SINGLE_OP_PROTOCOL = 0x4c; - int MULTIPLEX_PROTOCOL = 0x4d; - - int PROTOCOL_ACK = 0x4e; - int PROTOCOL_NACK = 0x4f; - - int MESSAGE_CALL = 0x50; - int MESSAGE_CALL_ACK = 0x51; - int MESSAGE_PING = 0x52; - int MESSAGE_PING_ACK = 0x53; - int MESSAGE_DGCACK = 0x54; - - int RETURN_ACK = 0x01; - int RETURN_NACK = 0x02; - - int DEFAULT_PROTOCOL = STREAM_PROTOCOL; -} diff --git a/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java b/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java deleted file mode 100644 index 628e1cc8799..00000000000 --- a/libjava/gnu/java/rmi/server/RMIDefaultSocketFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* RMIDefaultSocketFactory.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.rmi.server.RMISocketFactory; - -public class RMIDefaultSocketFactory - extends RMISocketFactory { - -public RMIDefaultSocketFactory() { -} - -public Socket createSocket(String host, int port) throws IOException { - return (new Socket(host, port)); -} - -public ServerSocket createServerSocket(int port) throws IOException { - return (new ServerSocket(port)); -} - -} diff --git a/libjava/gnu/java/rmi/server/RMIHashes.java b/libjava/gnu/java/rmi/server/RMIHashes.java deleted file mode 100644 index 5a414404d4f..00000000000 --- a/libjava/gnu/java/rmi/server/RMIHashes.java +++ /dev/null @@ -1,98 +0,0 @@ -/* RMIHashes.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import gnu.java.lang.reflect.TypeSignature; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.lang.reflect.Method; -import java.security.MessageDigest; - -public class RMIHashes -{ - //There're other places using DigestOutputStream to generate hash in classpath, but I think the way I used - //here is more efficient, anyway, you can switch to DigestOutputStream by doing like "//or:" comments say. - - //or:add this statement: private static final NullOutputStream nullOutputStream = new NullOutputStream (); - public static long getMethodHash(Method meth) - { - //Object Serialization Spec 8.3 - try - { - MessageDigest md = MessageDigest.getInstance ("SHA"); - //or:remove this statement: DigestOutputStream digest_out = new DigestOutputStream (nullOutputStream, md); - ByteArrayOutputStream digest_out = new ByteArrayOutputStream(); - DataOutputStream data_out = new DataOutputStream (digest_out); - - StringBuffer sbuf = new StringBuffer(); - sbuf.append(meth.getName()); - sbuf.append('('); - Class params[] = meth.getParameterTypes(); - for(int i = 0; i < params.length; i++) - sbuf.append(TypeSignature.getEncodingOfClass(params[i])); - sbuf.append(')'); - Class rcls = meth.getReturnType(); - if(rcls != Void.TYPE) - sbuf.append(TypeSignature.getEncodingOfClass(rcls)); - else - sbuf.append('V'); - - data_out.writeUTF (sbuf.toString()); - data_out.flush(); - data_out.close (); - - md.update(digest_out.toByteArray()); //or:remove this statement - byte[] sha = md.digest (); - long result = 0; - int len = sha.length < 8 ? sha.length : 8; - for (int i=0; i < len; i++) - result += (long)(sha[i] & 0xFF) << (8 * i); - return result; - }catch(Exception _){ - return -1L; - } - } - - public static long getInterfaceHash(Class clazz) - { - return clazz.hashCode (); - } -} - diff --git a/libjava/gnu/java/rmi/server/RMIIncomingThread.java b/libjava/gnu/java/rmi/server/RMIIncomingThread.java deleted file mode 100644 index 990d37bc521..00000000000 --- a/libjava/gnu/java/rmi/server/RMIIncomingThread.java +++ /dev/null @@ -1,58 +0,0 @@ -/* RMIIncomingThread.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -public class RMIIncomingThread extends Thread { - - private String clientHost = null; - - public RMIIncomingThread(Runnable runnable, String s_clientHost) { - super(runnable); - clientHost = s_clientHost; - } - - public String toString() { - return "RMIIncoming from " + clientHost + " " + super.toString(); - } - - public String getClientHost() { - return clientHost; - } - - -} diff --git a/libjava/gnu/java/rmi/server/RMIObjectInputStream.java b/libjava/gnu/java/rmi/server/RMIObjectInputStream.java deleted file mode 100644 index 888b30bf6b6..00000000000 --- a/libjava/gnu/java/rmi/server/RMIObjectInputStream.java +++ /dev/null @@ -1,126 +0,0 @@ -/* RMIObjectInputStream.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectStreamClass; -import java.lang.reflect.Proxy; -import java.net.MalformedURLException; -import java.rmi.server.RMIClassLoader; - -public class RMIObjectInputStream - extends ObjectInputStream { - -public RMIObjectInputStream(InputStream strm) throws IOException { - super(strm); - enableResolveObject(true); -} - -protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { - String annotation = (String)getAnnotation(); - - try { - if(annotation == null) - return (RMIClassLoader.loadClass(desc.getName())); - else - return (RMIClassLoader.loadClass(annotation, desc.getName())); - } - catch (MalformedURLException _) { - throw new ClassNotFoundException(desc.getName()); - } -} - -//Separate it for override by MarshalledObject -protected Object getAnnotation() - throws IOException, ClassNotFoundException -{ - return readObject(); -} - -protected Class resolveProxyClass(String intfs[]) - throws IOException, ClassNotFoundException -{ - String annotation = (String)getAnnotation(); - - Class clss[] = new Class[intfs.length]; - if(annotation == null) - clss[0] = RMIClassLoader.loadClass(intfs[0]); - else - clss[0] = RMIClassLoader.loadClass(annotation, intfs[0]); - - //assume all interfaces can be loaded by the same classloader - ClassLoader loader = clss[0].getClassLoader(); - for (int i = 0; i < intfs.length; i++) - clss[i] = Class.forName(intfs[i], false, loader); - - try { - return Proxy.getProxyClass(loader, clss); - } catch (IllegalArgumentException e) { - throw new ClassNotFoundException(null, e); - } -} - -protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException { - if(valueClass.isPrimitive()){ - if(valueClass == Boolean.TYPE) - return new Boolean(readBoolean()); - if(valueClass == Byte.TYPE) - return new Byte(readByte()); - if(valueClass == Character.TYPE) - return new Character(readChar()); - if(valueClass == Short.TYPE) - return new Short(readShort()); - if(valueClass == Integer.TYPE) - return new Integer(readInt()); - if(valueClass == Long.TYPE) - return new Long(readLong()); - if(valueClass == Float.TYPE) - return new Float(readFloat()); - if(valueClass == Double.TYPE) - return new Double(readDouble()); - else - throw new Error("Unsupported primitive class: " + valueClass); - } else - return readObject(); -} - -} diff --git a/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java b/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java deleted file mode 100644 index d42908a4147..00000000000 --- a/libjava/gnu/java/rmi/server/RMIObjectOutputStream.java +++ /dev/null @@ -1,114 +0,0 @@ -/* RMIObjectOutputStream.java - - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.rmi.Remote; -import java.rmi.server.RMIClassLoader; -import java.rmi.server.RemoteStub; - -public class RMIObjectOutputStream - extends ObjectOutputStream { - -public RMIObjectOutputStream(OutputStream strm) throws IOException { - super(strm); - enableReplaceObject(true); -} - -//Separate it for override by MarshalledObject -protected void setAnnotation(String annotation) throws IOException{ - writeObject(annotation); -} - -protected void annotateClass(Class cls) throws IOException { - setAnnotation(RMIClassLoader.getClassAnnotation(cls)); -} - -protected void annotateProxyClass(Class cls) - throws IOException -{ - annotateClass(cls); -} - -protected Object replaceObject(Object obj) - throws IOException -{ - if((obj instanceof Remote) && !(obj instanceof RemoteStub)){ - UnicastServerRef ref = UnicastServer.getExportedRef((Remote)obj); - if (ref != null) - return ref.getStub(); - } - return obj; -} - -protected void writeValue(Object value, Class valueClass) throws IOException{ - if(valueClass.isPrimitive()){ - if(valueClass == Boolean.TYPE) - writeBoolean(((Boolean)value).booleanValue()); - else - if(valueClass == Byte.TYPE) - writeByte(((Byte)value).byteValue()); - else - if(valueClass == Character.TYPE) - writeChar(((Character)value).charValue()); - else - if(valueClass == Short.TYPE) - writeShort(((Short)value).shortValue()); - else - if(valueClass == Integer.TYPE) - writeInt(((Integer)value).intValue()); - else - if(valueClass == Long.TYPE) - writeLong(((Long)value).longValue()); - else - if(valueClass == Float.TYPE) - writeFloat(((Float)value).floatValue()); - else - if(valueClass == Double.TYPE) - writeDouble(((Double)value).doubleValue()); - else - throw new Error("Unsupported primitive class: " + valueClass); - } else - writeObject(value); -} - -} diff --git a/libjava/gnu/java/rmi/server/RMIVoidValue.java b/libjava/gnu/java/rmi/server/RMIVoidValue.java deleted file mode 100644 index 8e5546d3523..00000000000 --- a/libjava/gnu/java/rmi/server/RMIVoidValue.java +++ /dev/null @@ -1,51 +0,0 @@ -/* RMIVoidValue.java -- - Copyright (c) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -/** - * Package private class used to indicate a void return type. - * INSTANCE is the only object of this class ever made. - */ -final class RMIVoidValue -{ - static RMIVoidValue INSTANCE = new RMIVoidValue(); - - private RMIVoidValue() - { - } -} diff --git a/libjava/gnu/java/rmi/server/UnicastConnection.java b/libjava/gnu/java/rmi/server/UnicastConnection.java deleted file mode 100644 index 216e453e72f..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastConnection.java +++ /dev/null @@ -1,231 +0,0 @@ -/* UnicastConnection.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.Socket; -import java.rmi.RemoteException; - -public class UnicastConnection - implements Runnable, ProtocolConstants { - -UnicastConnectionManager manager; -Socket sock; -DataInputStream din; -DataOutputStream dout; -ObjectInputStream oin; -ObjectOutputStream oout; - -// reviveTime and expireTime make UnicastConnection pool-able -long reviveTime = 0; -long expireTime = Long.MAX_VALUE; - -UnicastConnection(UnicastConnectionManager man, Socket sock) { - this.manager = man; - this.sock = sock; -} - -void acceptConnection() throws IOException { -//System.out.println("Accepting connection on " + sock); - //Use BufferedXXXStream would be more efficient - din = new DataInputStream(new BufferedInputStream(sock.getInputStream())); - dout = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); - - int sig = din.readInt(); - if (sig != PROTOCOL_HEADER) { - throw new IOException("bad protocol header"); - } - short ver = din.readShort(); - if (ver != PROTOCOL_VERSION) { - throw new IOException("bad protocol version"); - } - int protocol = din.readUnsignedByte(); - if (protocol != SINGLE_OP_PROTOCOL) { - // Send an ACK - dout.writeByte(PROTOCOL_ACK); - - // Send my hostname and port - dout.writeUTF(manager.serverName); - dout.writeInt(manager.serverPort); - dout.flush(); - - // Read their hostname and port - String rhost = din.readUTF(); - int rport = din.readInt(); - } - // Okay, ready to roll ... -} - -void makeConnection(int protocol) throws IOException { - //Use BufferedXXXStream would be more efficient - din = new DataInputStream(new BufferedInputStream(sock.getInputStream())); - - dout = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream())); - - // Send header - dout.writeInt(PROTOCOL_HEADER); - dout.writeShort(PROTOCOL_VERSION); - dout.writeByte(protocol); - dout.flush(); - - if (protocol != SINGLE_OP_PROTOCOL) { - // Get back ack. - int ack = din.readUnsignedByte(); - if (ack != PROTOCOL_ACK) { - throw new RemoteException("Unsupported protocol"); - } - - // Read in host and port - String dicard_rhost = din.readUTF(); - int discard_rport = din.readInt(); - - // Send them my endpoint - dout.writeUTF(manager.serverName); - dout.writeInt(manager.serverPort); - dout.flush(); - } - // Okay, ready to roll ... -} - -DataInputStream getDataInputStream() throws IOException { - return (din); -} - -DataOutputStream getDataOutputStream() throws IOException { - return (dout); -} - -/* -* -* get ObjectInputStream for reading more objects -* -*/ -ObjectInputStream getObjectInputStream() throws IOException { - if (oin == null) { - throw new IOException("no ObjectInputtream for reading more objects"); - } - return (oin); -} - -/** -* -* starts ObjectInputStream. -* -*/ -ObjectInputStream startObjectInputStream() throws IOException { - return (oin = new RMIObjectInputStream(din)); -} - -/** -* -* get ObjectOutputStream for sending more objects -* -*/ -ObjectOutputStream getObjectOutputStream() throws IOException { - if (oout == null) { - throw new IOException("no ObjectOutputStream for sending more objects"); - } - return (oout); -} - -/** -* -* starts ObjectOutputStream. -* -*/ -ObjectOutputStream startObjectOutputStream() throws IOException { - return (oout = new RMIObjectOutputStream(dout)); -} - -void disconnect() { - try { - if(oout != null) - oout.close(); - sock.close(); - } - catch (IOException _) { - } - - oin = null; - oout = null; - din = null; - dout = null; - sock = null; -} - -public static final long CONNECTION_TIMEOUT = 10000L; - -static boolean isExpired(UnicastConnection conn, long l){ - if (l <= conn.expireTime ) - return false; - return true; -} - -static void resetTime(UnicastConnection conn){ - long l = System.currentTimeMillis(); - conn.reviveTime = l; - conn.expireTime = l + CONNECTION_TIMEOUT; -} - -/** - * We run connects on the server. Dispatch it then discard it. - */ -public void run() { - do{ - try { - UnicastServer.dispatch(this); - //don't discardConnection explicitly, only when - // exception happens or the connection's expireTime - // comes - } catch (Exception e ){ - manager.discardConnection(this); - break; - } - }while(true); -} - - -} diff --git a/libjava/gnu/java/rmi/server/UnicastConnectionManager.java b/libjava/gnu/java/rmi/server/UnicastConnectionManager.java deleted file mode 100644 index 08f6a9bc394..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastConnectionManager.java +++ /dev/null @@ -1,446 +0,0 @@ -/* UnicastConnectionManager.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.UnknownHostException; -import java.rmi.RemoteException; -import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RMISocketFactory; -import java.util.ArrayList; -import java.util.ConcurrentModificationException; -import java.util.Hashtable; -import java.util.Iterator; - -public class UnicastConnectionManager - implements Runnable, ProtocolConstants { - -private static String localhost; -// use different maps for server/client type UnicastConnectionManager -private static Hashtable servers = new Hashtable(); -// Package-private to avoid trampolines. -static Hashtable clients = new Hashtable(); -ArrayList connections; //client connection pool - -// make serverThread volatile for poll -private volatile Thread serverThread; -private ServerSocket ssock; -String serverName; -int serverPort; - -// Package-private to avoid a trampoline. -static Thread scavenger; - -// If client and server are in the same VM, serverobj represents server -Object serverobj; - -private static RMISocketFactory defaultSocketFactory = RMISocketFactory.getSocketFactory(); -private RMIServerSocketFactory serverFactory; -private RMIClientSocketFactory clientFactory; - -// The following is for debug -private static int ncsock = 0; //count of client socket -private static int nssock = 0; //count of server socket -private static int ncmanager = 0; //count of client manager -private static int nsmanager = 0; //count of server manager - -private static final boolean debug = false; - -private static final Object GLOBAL_LOCK = new Object(); - -static { - try { - //Use host address instead of host name to avoid name resolving issues - //localhost = InetAddress.getLocalHost().getHostName(); - localhost = InetAddress.getLocalHost().getHostAddress(); - } - catch (UnknownHostException _) { - localhost = "localhost"; - } - - -} - -//Only one scavenger thread running globally -private static void startScavenger(){ - scavenger = new Thread(new Runnable(){ - public void run(){ - if (debug) System.out.println("************* start scavenger."); - boolean liveon = true; - while (liveon){ - // Sleep for the expire timeout - try{ - Thread.sleep(UnicastConnection.CONNECTION_TIMEOUT); - }catch(InterruptedException _ie){ - break; - } - liveon = false; - // Scavenge all clients' connections that're expired - Iterator iter = clients.values().iterator(); - long l = System.currentTimeMillis(); - try{ - while(iter.hasNext()){ - UnicastConnectionManager man = (UnicastConnectionManager)iter.next(); - ArrayList conns = man.connections; - synchronized(conns) { // is the lock a little coarser? - for (int last = conns.size() - 1; - last >= 0; - --last) - { - UnicastConnection conn = (UnicastConnection)conns.get(last); - if (UnicastConnection.isExpired(conn, l)){ - conns.remove(last); - conn.disconnect(); - conn = null; - }else - liveon = true; //there're still live connections - } - } - } - }catch(ConcurrentModificationException cme) { - // handle it lazily - liveon = true; - } - } - scavenger = null; - if (debug) System.out.println("************* exit scavenger."); - } - }); - // As it is used for client connection, we may put this thread - // in daemon state to prevent the VM from blocking when exiting. - scavenger.setDaemon(true); - scavenger.start(); -} - -/** - * Client UnicastConnectionManager constructor - */ -private UnicastConnectionManager(String host, int port, RMIClientSocketFactory csf) { - ssock = null; - serverName = host; - serverPort = port; - serverFactory = null; - clientFactory = csf; - connections = new ArrayList(); -} - -/** - * Server UnicastConnectionManager constructor - */ -private UnicastConnectionManager(int port, RMIServerSocketFactory ssf) throws RemoteException { - - try { - ssock = ssf.createServerSocket(port); - serverPort = ssock.getLocalPort(); - } - catch (IOException ioex) { - ssock = null; - serverPort = 0; - throw new java.rmi.server.ExportException("can not create Server Socket on port " + port,ioex); - } - serverName = localhost; - serverFactory = ssf; - clientFactory = null; -} - -/** - * Return a client connection manager which will connect to the given - * host/port. - */ -public static synchronized UnicastConnectionManager getInstance(String host, int port, RMIClientSocketFactory csf) { -//System.out.println("getInstance: " + host + "," + port + "," + csf); - if (csf == null) { - csf = defaultSocketFactory; - } - // change host name to host address to avoid name resolving issues - try{ - host = InetAddress.getByName(host).getHostAddress(); - }catch(Exception _){} - - TripleKey key = new TripleKey(host, port, csf); - UnicastConnectionManager man = (UnicastConnectionManager)clients.get(key); - if (man == null) { - man = new UnicastConnectionManager(host, port, csf); - if (debug) { - ncmanager++; - System.out.println("\n\n ====== " + ncmanager + " client managers.\n\n"); - } - clients.put(key, man); - - // Detect if client and server are in the same VM, i.e., their keys are equal - UnicastConnectionManager svrman = (UnicastConnectionManager)servers.get(key); - if(svrman != null){ // server and client are in the same VM - man.serverobj = svrman.serverobj; - } - } - return (man); -} - -/** - * Return a server connection manager which will accept connection on the - * given port. - */ -public static synchronized UnicastConnectionManager getInstance(int port, RMIServerSocketFactory ssf) throws RemoteException { -//System.out.println("getInstance: " + port + "," + ssf); - if (ssf == null) { - ssf = defaultSocketFactory; - } - TripleKey key = new TripleKey(localhost, port, ssf); - UnicastConnectionManager man = (UnicastConnectionManager)servers.get(key); - if (man == null) { - man = new UnicastConnectionManager(port, ssf); - if (debug) { - nsmanager++; - System.out.println("\n\n ****** " + nsmanager + " server managers.\n\n"); - } - // The provided port might not be the set port. - key.port = man.serverPort; - servers.put(key, man); - } - return (man); -} - -/** - * Get a connection from this manager. - */ -public UnicastConnection getConnection() throws IOException { - if (ssock == null) { - return (getClientConnection()); - } - else { - return (getServerConnection()); - } -} - -/** - * Accept a connection to this server. - */ -private UnicastConnection getServerConnection() throws IOException { - Socket sock = ssock.accept(); - sock.setTcpNoDelay(true); //?? - UnicastConnection conn = new UnicastConnection(this, sock); - conn.acceptConnection(); - if (debug){ - nssock++; - System.out.println("\n\n ****** " + nssock + " server socks.\n\n"); - } - //System.out.println("Server connection " + sock); - return (conn); -} - -/** - * Make a conection from this client to the server. - */ -private UnicastConnection getClientConnection() throws IOException { - ArrayList conns = connections; - UnicastConnection conn; - - synchronized(conns) { - int nconn = conns.size() - 1; - - // if there're free connections in connection pool - if(nconn >= 0) { - conn = (UnicastConnection)conns.get(nconn); - //Should we check if conn is alive using Ping?? - conns.remove(nconn); - - // Check if the connection is already expired - long l = System.currentTimeMillis(); - if (!UnicastConnection.isExpired(conn, l)){ - return conn; - }else { - conn.disconnect(); - conn = null; - } - } - } - - Socket sock = clientFactory.createSocket(serverName, serverPort); - conn = new UnicastConnection(this, sock); - conn.makeConnection(DEFAULT_PROTOCOL); - - if (debug) { - ncsock++; - System.out.println("\n\n ====== " + ncsock + " client socks.\n\n"); - } - - return (conn); -} - -/** - * Discard a connection when we're done with it - maybe it can be - * recycled. - */ -public void discardConnection(UnicastConnection conn) { -//System.out.println("Discarding connection " + conn); - //conn.disconnect(); - if (ssock != null) //server connection - conn.disconnect(); - else { - // To client connection, we'd like to return back to pool - UnicastConnection.resetTime(conn); - //Ensure there're only one scavenger globally - synchronized(GLOBAL_LOCK) { - connections.add(conn); //borrow this lock to garantee thread safety - if (scavenger == null) - startScavenger(); - } - } -} - -/** - * Start a server on this manager if it's a server socket and we've not - * already got one running. - */ -public void startServer() { - synchronized(this) { - if (ssock == null || serverThread != null) { - return; - } - serverThread = new Thread(this); - // The following is not necessary when java.lang.Thread's constructor do this. - // serverThread.setContextClassLoader(Thread.currentThread().getContextClassLoader()); - } - serverThread.start(); -} - -/** - * Stop a server on this manager - */ -public void stopServer() { - synchronized(this) { - if(serverThread != null){ - serverThread = null; - try{ - ssock.close(); - }catch(Exception _){} - } - } -} - -/** - * Server thread for connection manager. - */ -public void run() { - for (;serverThread != null;) { // if serverThread==null, then exit thread - try { -//System.out.println("Waiting for connection on " + serverPort); - UnicastConnection conn = getServerConnection(); - - // get address of remote host for the RMIIncomingThread object - String remoteHost = null; - if (conn.sock != null) { - remoteHost = conn.sock.getInetAddress().getHostAddress(); - } - - // use a thread pool to improve performance - //ConnectionRunnerPool.dispatchConnection(conn); - (new RMIIncomingThread(conn, remoteHost)).start(); -// (new Thread(conn)).start(); - } - catch (Exception e) { - e.printStackTrace(); - } - } -} - -/** - * Serialization routine. - */ -void write(ObjectOutput out) throws IOException { - out.writeUTF(serverName); - out.writeInt(serverPort); -} - -/** - * Serialization routine. - */ -static UnicastConnectionManager read(ObjectInput in) throws IOException { - String host = in.readUTF(); - int port = in.readInt(); - //RMIClientSocketFactory csf = ((RMIObjectInputStream)in).manager.clientFactory; - //return (getInstance(host, port, csf)); - return (getInstance(host, port, null)); -} - -} - -/** - * This is use as the hashkey for the client/server connections. - */ -class TripleKey { - -String host; -int port; -Object other; - -TripleKey(String host, int port, Object other) { - this.host = host; - this.port = port; - this.other = other; -} - -/** - * Hash code just include the host and other - we ignore the port since - * this has unusual matching behaviour. - */ -public int hashCode() { - return (host.hashCode() ^ other.hashCode()); -} - -public boolean equals(Object obj) { - if (obj instanceof TripleKey) { - TripleKey other = (TripleKey)obj; - if (this.host.equals(other.host) && - this.other == other.other && - (this.port == other.port /* || this.port == 0 || other.port == 0*/)) { - return (true); - } - } - return (false); -} - -} diff --git a/libjava/gnu/java/rmi/server/UnicastRef.java b/libjava/gnu/java/rmi/server/UnicastRef.java deleted file mode 100644 index c1b871fb8e5..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastRef.java +++ /dev/null @@ -1,278 +0,0 @@ -/* UnicastRef.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.ObjID; -import java.rmi.server.Operation; -import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RemoteCall; -import java.rmi.server.RemoteObject; -import java.rmi.server.RemoteRef; -import java.rmi.server.UID; - -public class UnicastRef - implements RemoteRef, ProtocolConstants { - -public ObjID objid; -UnicastConnectionManager manager; - -/** - * Used by serialization, and let subclass capable of having default constructor - */ -// must be public otherwise java.rmi.RemoteObject cannot instantiate this class -// -- iP -public UnicastRef() { -} - -public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) { - this(objid); - manager = UnicastConnectionManager.getInstance(host, port, csf); -} - -public UnicastRef(ObjID objid) { - this.objid = objid; -} - -public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception { - // Check if client and server are in the same VM, then local call can be used to - // replace remote call, but it's somewhat violating remote semantic. - Object svrobj = manager.serverobj; - - // Make sure that the server object is compatible. It could be loaded from a different - // classloader --iP - if(svrobj != null && method.getDeclaringClass().isInstance(svrobj)){ - //local call - Object ret = null; - try{ - ret = method.invoke(svrobj, params); - }catch(InvocationTargetException e){ - throw (Exception)e.getTargetException(); - } - //System.out.println("\n\n ***** local call: " + method + "\nreturn: " + ret + "\n\n"); - return ret; - } - //System.out.println("***************** remote call:" + manager.serverPort); - return (invokeCommon(obj, method, params, -1, opnum)); -} - -private Object invokeCommon(Remote obj, Method method, Object[] params, int opnum, long hash) throws Exception { - UnicastConnection conn; - try { - conn = manager.getConnection(); - } - catch (IOException e1) { - throw new RemoteException("connection failed to host: " + manager.serverName, e1); - } - - ObjectOutputStream out; - DataOutputStream dout; - try { - dout = conn.getDataOutputStream(); - dout.writeByte(MESSAGE_CALL); - - out = conn.startObjectOutputStream(); // (re)start ObjectOutputStream - - objid.write(out); - out.writeInt(opnum); - out.writeLong(hash); - - // must handle primitive class and their wrapper classes - Class clss[] = method.getParameterTypes(); - for(int i = 0; i < clss.length; i++) - ((RMIObjectOutputStream)out).writeValue(params[i], clss[i]); - - out.flush(); - } - catch (IOException e2) { - throw new RemoteException("call failed: ", e2); - } - - int returncode; - Object returnval; - DataInputStream din; - ObjectInputStream in; - UID ack; - try { - din = conn.getDataInputStream(); - - if ((returncode = din.readUnsignedByte()) != MESSAGE_CALL_ACK) { - conn.disconnect(); - throw new RemoteException("Call not acked:" + returncode); - } - - in = conn.startObjectInputStream(); // (re)start ObjectInputStream - returncode = in.readUnsignedByte(); - ack = UID.read(in); - - Class cls = method.getReturnType(); - - if (returncode == RETURN_NACK) { - returnval = in.readObject(); // get Exception - - } else if(cls == Void.TYPE) { - returnval = null; - // in.readObject() // not required! returntype 'void' means no field is returned. - } else { - returnval = ((RMIObjectInputStream)in).readValue(cls); // get returnvalue - } - } catch (IOException e3) { - //for debug: e3.printStackTrace(); - throw new RemoteException("call return failed: ", e3); - } - - /* if DGCAck is necessary?? - //According to RMI wire protocol, send a DGCAck - // to indicate receiving return value - dout.writeByte(MESSAGE_DGCACK); - ack.write(dout); - out.flush(); - */ - - manager.discardConnection(conn); - - if (returncode != RETURN_ACK && returnval != null) { - if (returncode == RETURN_NACK) throw (Exception)returnval; - else throw new RemoteException("unexpected returncode: " + returncode); - } - - return (returnval); -} - -/** - * @deprecated - */ -public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) throws RemoteException { - UnicastConnection conn; - - try { - conn = manager.getConnection(); - } - catch (IOException e1) { - throw new RemoteException("connection failed to host: " + manager.serverName, e1); - } - - //obj: useless? - - return (new UnicastRemoteCall(conn, objid, opnum, hash)); -} - -/** - * @deprecated - */ -public void invoke(RemoteCall call) throws Exception { - UnicastRemoteCall c = (UnicastRemoteCall)call; - call.executeCall(); -} - -/** - * @deprecated - */ -public void done(RemoteCall call) throws RemoteException { - UnicastRemoteCall c = (UnicastRemoteCall)call; - try{ - c.done(); - } catch(IOException e){} - UnicastConnection conn = c.getConnection(); - manager.discardConnection(conn); -} - -public void writeExternal(ObjectOutput out) throws IOException { - if (manager == null) { - throw new IOException("no connection"); - } - manager.write(out); - objid.write(out); - // This byte is somewhat confusing when interoperating with JDK - out.writeByte(0); //RETURN_ACK); -} - -public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - manager = UnicastConnectionManager.read(in); - objid = ObjID.read(in); - byte ack = in.readByte(); - // This byte is somewhat confusing when interoperating with JDK - if (ack != RETURN_ACK && ack != 0/*jdk ack value*/) { - throw new IOException("no ack found"); - } -} - -public boolean remoteEquals(RemoteRef ref) { - throw new Error("Not implemented"); -} - -public int remoteHashCode() { - throw new Error("Not implemented"); -} - -public String getRefClass(ObjectOutput out) { - return ("UnicastRef"); -} - -public String remoteToString() { - throw new Error("Not implemented"); -} - -public void dump(UnicastConnection conn) { - try { - DataInputStream din = conn.getDataInputStream(); - for (;;) { - int b = din.readUnsignedByte(); - System.out.print(Integer.toHexString(b)); - if (b >= 32 && b < 128) { - System.out.print(": " + (char)b); - } - System.out.println(); - } - } - catch (IOException _) { - } -} - -} diff --git a/libjava/gnu/java/rmi/server/UnicastRemoteCall.java b/libjava/gnu/java/rmi/server/UnicastRemoteCall.java deleted file mode 100644 index c5206e76df2..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastRemoteCall.java +++ /dev/null @@ -1,525 +0,0 @@ -/* UnicastRemoteCall.java - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004, 2005 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.StreamCorruptedException; -import java.rmi.MarshalException; -import java.rmi.RemoteException; -import java.rmi.UnmarshalException; -import java.rmi.server.ObjID; -import java.rmi.server.RemoteCall; -import java.rmi.server.UID; -import java.util.Vector; - -public class UnicastRemoteCall - implements RemoteCall, ProtocolConstants -{ - - private UnicastConnection conn; - private Object result; - private Object object; - private int opnum; - private long hash; - // These are package-private due to inner class access. - Vector vec; - int ptr; - private ObjID objid; - - private ObjectOutput oout; - private ObjectInput oin; - - /** - * Incoming call. - */ - UnicastRemoteCall(UnicastConnection conn) - { - this.conn = conn; - } - - /** - * Outgoing call. - */ - UnicastRemoteCall(UnicastConnection conn, ObjID objid, int opnum, long hash) - throws RemoteException - { - this.conn = conn; - this.opnum = opnum; - this.hash = hash; - this.objid = objid; - } - - UnicastConnection getConnection() - { - return conn; - } - - public ObjectOutput getOutputStream() throws IOException - { - if (vec == null) - vec = new Vector(); - return (new DummyObjectOutputStream()); - } - - public void releaseOutputStream() throws IOException - { - if (vec != null) - { - oout = conn.getObjectOutputStream(); - - for (int i = 0; i < vec.size(); i += 2) - { - boolean primitive = ((Boolean)vec.elementAt(i)).booleanValue(); - Object data = vec.elementAt(i+1); - - // No type, this is - if (!primitive) - oout.writeObject(data); - else - { - if (data instanceof Boolean) - oout.writeBoolean(((Boolean)data).booleanValue()); - else if (data instanceof Character) - oout.writeChar(((Character)data).charValue()); - else if (data instanceof Byte) - oout.writeByte(((Byte)data).byteValue()); - else if (data instanceof Short) - oout.writeShort(((Short)data).shortValue()); - else if (data instanceof Integer) - oout.writeInt(((Integer)data).intValue()); - else if (data instanceof Long) - oout.writeLong(((Long)data).longValue()); - } - } - vec = null; - } - if(oout != null) - oout.flush(); - } - - /** - * - * (re)starts ObjectInputStream - * - */ - public ObjectInput startInputStream() throws IOException - { - if (conn != null) { - return (oin = conn.startObjectInputStream()); - } else { - return getInputStream(); // dummy Input Stream - } - - } - - public ObjectInput getInputStream() throws IOException - { - if (conn != null) - { - if(oin == null) - return (oin = conn.getObjectInputStream()); - else - return oin; - } - else - { - ptr = 0; - return (new DummyObjectInputStream()); - } - } - - public void releaseInputStream() throws IOException - { - // Does nothing. - } - - public ObjectOutput getResultStream(boolean success) - throws IOException, StreamCorruptedException - { - vec = new Vector(); - return new DummyObjectOutputStream(); - } - - public void executeCall() throws Exception - { - byte returncode; - ObjectInput oin; - - // signal the call when constructing - try - { - DataOutputStream dout = conn.getDataOutputStream(); - dout.write(MESSAGE_CALL); - - oout = conn.startObjectOutputStream(); // (re)start ObjectOutputStream - objid.write(oout); - oout.writeInt(opnum); - oout.writeLong(hash); - } - catch(IOException ex) - { - throw new MarshalException("Try to write header but failed.", ex); - } - - try - { - releaseOutputStream(); - DataInputStream din = conn.getDataInputStream(); - if (din.readByte() != MESSAGE_CALL_ACK) - throw new RemoteException("Call not acked"); - - oin = startInputStream(); - returncode = oin.readByte(); - UID.read(oin); - } - catch(IOException ex) - { - throw new UnmarshalException("Try to read header but failed:", ex); - } - - //check return code - switch(returncode) - { - case RETURN_ACK: //it's ok - return; - case RETURN_NACK: - Object returnobj; - try - { - returnobj = oin.readObject(); - } - catch(Exception ex2) - { - throw new UnmarshalException - ("Try to read exception object but failed", ex2); - } - - if(!(returnobj instanceof Exception)) - throw new UnmarshalException("Should be Exception type here: " - + returnobj); - throw (Exception)returnobj; - - default: - throw new UnmarshalException("Invalid return code"); - } - } - - public void done() throws IOException - { - // conn.disconnect(); - } - - boolean isReturnValue() - { - return vec.size() > 0; - } - - Object returnValue() - { - // This is not the first one (Boolean) but the second. - return vec.elementAt(1); - } - - Object[] getArguments() - { - return vec.toArray(); - } - - Object getObject() - { - return object; - } - - int getOpnum() - { - return opnum; - } - - long getHash() - { - return hash; - } - - void setReturnValue(Object obj) - { - vec.removeAllElements(); - vec.addElement(obj); - } - - /** - * Dummy object output class. - */ - private class DummyObjectOutputStream implements ObjectOutput - { - /** - * Non-private constructor to reduce bytecode emitted. - */ - DummyObjectOutputStream() - { - } - - public void writeBoolean(boolean v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(Boolean.valueOf(v)); - } - - public void writeByte(int v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Byte((byte) v)); - } - - public void writeChar(int v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Character((char) v)); - } - - public void writeDouble(double v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Double(v)); - } - - public void writeFloat(float v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Float(v)); - } - - public void writeInt(int v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Integer(v)); - } - - public void writeLong(long v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Long(v)); - } - - public void writeShort(int v) throws IOException - { - vec.addElement(Boolean.TRUE); - vec.addElement(new Short((short) v)); - } - - public void writeObject(Object obj) throws IOException - { - vec.addElement(Boolean.FALSE); - vec.addElement(obj); - } - - public void write(byte b[]) throws IOException - { - throw new IOException("not required"); - } - - public void write(byte b[], int off, int len) throws IOException - { - throw new IOException("not required"); - } - - public void write(int b) throws IOException - { - throw new IOException("not required"); - } - - public void writeBytes(String s) throws IOException - { - throw new IOException("not required"); - } - - public void writeChars(String s) throws IOException - { - throw new IOException("not required"); - } - - public void writeUTF(String str) throws IOException - { - throw new IOException("not required"); - } - - public void flush() throws IOException - { - } - - public void close() throws IOException - { - } - } // class DummyObjectOutputStream - - /** - * Dummy object input class. - */ - private class DummyObjectInputStream implements ObjectInput - { - /** - * Non-private constructor to reduce bytecode emitted. - */ - DummyObjectInputStream() - { - } - - public boolean readBoolean() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Boolean) obj).booleanValue(); - } - - public byte readByte() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Byte) obj).byteValue(); - } - - public char readChar() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Character) obj).charValue(); - } - - public double readDouble() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Double) obj).doubleValue(); - } - - public float readFloat() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Float) obj).floatValue(); - } - - public int readInt() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Integer) obj).intValue(); - } - - public long readLong() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Long) obj).longValue(); - } - - public short readShort() throws IOException - { - Object obj = vec.elementAt(ptr++); - return ((Short) obj).shortValue(); - } - - public Object readObject() throws IOException - { - return vec.elementAt(ptr++); - } - - public int read(byte b[]) throws IOException - { - throw new IOException("not required"); - } - - public int read(byte b[], int off, int len) throws IOException - { - throw new IOException("not required"); - } - - public int read() throws IOException - { - throw new IOException("not required"); - } - - public long skip(long n) throws IOException - { - throw new IOException("not required"); - } - - public int available() throws IOException - { - throw new IOException("not required"); - } - - public void readFully(byte b[]) throws IOException - { - throw new IOException("not required"); - } - - public void readFully(byte b[], int off, int len) throws IOException - { - throw new IOException("not required"); - } - - public String readLine() throws IOException - { - throw new IOException("not required"); - } - - public String readUTF() throws IOException - { - throw new IOException("not required"); - } - - public int readUnsignedByte() throws IOException - { - throw new IOException("not required"); - } - - public int readUnsignedShort() throws IOException - { - throw new IOException("not required"); - } - - public int skipBytes(int n) throws IOException - { - throw new IOException("not required"); - } - - public void close() throws IOException - { - } - } // class DummyObjectInputStream - -} diff --git a/libjava/gnu/java/rmi/server/UnicastRemoteStub.java b/libjava/gnu/java/rmi/server/UnicastRemoteStub.java deleted file mode 100644 index 87e932de559..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastRemoteStub.java +++ /dev/null @@ -1,50 +0,0 @@ -/* UnicastRemoteStub.java -- - Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.rmi.server; - -import java.rmi.server.RemoteRef; -import java.rmi.server.RemoteStub; - -public class UnicastRemoteStub - extends RemoteStub { - -public static void setStubRef(RemoteStub stub, RemoteRef ref) { - setRef(stub, ref); -} - -} diff --git a/libjava/gnu/java/rmi/server/UnicastServer.java b/libjava/gnu/java/rmi/server/UnicastServer.java deleted file mode 100644 index 065ef8c77ee..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastServer.java +++ /dev/null @@ -1,167 +0,0 @@ -/* UnicastServer.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import gnu.java.rmi.dgc.DGCImpl; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.rmi.NoSuchObjectException; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.ServerError; -import java.rmi.server.ObjID; -import java.rmi.server.UID; -import java.util.Hashtable; - -public class UnicastServer - implements ProtocolConstants { - -static private Hashtable objects = new Hashtable(); //mapping OBJID to server ref -static private Hashtable refcache = new Hashtable(); //mapping obj itself to server ref -static private DGCImpl dgc; - -public static void exportObject(UnicastServerRef obj) { - startDGC(); - objects.put(obj.objid, obj); - refcache.put(obj.myself, obj); - obj.manager.startServer(); -} - -// FIX ME: I haven't handle force parameter -public static boolean unexportObject(UnicastServerRef obj, boolean force) { - objects.remove(obj.objid); - refcache.remove(obj.myself); - obj.manager.stopServer(); - return true; -} - -public static UnicastServerRef getExportedRef(Remote remote){ - return (UnicastServerRef)refcache.get(remote); -} - -private static synchronized void startDGC() { - if (dgc == null) { - try { - dgc = new DGCImpl(); - // Changed DGCImpl to inherit UnicastServerRef directly - //((UnicastServerRef)dgc.getRef()).exportObject(dgc); - dgc.exportObject(dgc); - } - catch (RemoteException e) { - e.printStackTrace(); - } - } -} - -public static void dispatch(UnicastConnection conn) throws Exception { - switch (conn.getDataInputStream().readUnsignedByte()) { - case MESSAGE_CALL: - incomingMessageCall(conn); - break; - case MESSAGE_PING: - // jdk sends a ping before each method call -> answer it! - DataOutputStream out = conn.getDataOutputStream(); - out.writeByte(MESSAGE_PING_ACK); - out.flush(); - break; - default: - throw new Exception("bad method type"); - } -} - -private static void incomingMessageCall(UnicastConnection conn) throws IOException { - ObjectInputStream in = conn.startObjectInputStream(); // (re)start ObjectInputStream - - ObjID objid = ObjID.read(in); - int method = in.readInt(); - long hash = in.readLong(); - -//System.out.println("ObjID: " + objid + ", method: " + method + ", hash: " + hash); - - // Use the objid to locate the relevant UnicastServerRef - UnicastServerRef uref = (UnicastServerRef)objects.get(objid); - Object returnval; - int returncode = RETURN_ACK; - // returnval is from Method.invoke(), so we must check the return class to see - // if it's primitive type - Class returncls = null; - if (uref != null) { - try { - // Dispatch the call to it. - returnval = uref.incomingMessageCall(conn, method, hash); - returncls = uref.getMethodReturnType(method, hash); - } - catch (Exception e) { - returnval = e; - returncode = RETURN_NACK; - } - catch (Error e) { - returnval = new ServerError ("An Error is thrown while processing the invocation on the server", e); - returncode = RETURN_NACK; - } - } - else { - returnval = new NoSuchObjectException(""); - returncode = RETURN_NACK; - } - - conn.getDataOutputStream().writeByte(MESSAGE_CALL_ACK); - - ObjectOutputStream out = conn.startObjectOutputStream(); // (re)start ObjectOutputStream - - out.writeByte(returncode); - (new UID()).write(out); - - //System.out.println("returnval=" + returnval + " returncls=" + returncls); - - if(returnval != null && returncls != null) - ((RMIObjectOutputStream)out).writeValue(returnval, returncls); - - // 1.1/1.2 void return type detection: - else if (!(returnval instanceof RMIVoidValue || returncls == Void.TYPE)) - out.writeObject(returnval); - - out.flush(); -} - -} diff --git a/libjava/gnu/java/rmi/server/UnicastServerRef.java b/libjava/gnu/java/rmi/server/UnicastServerRef.java deleted file mode 100644 index 1f6eedec68a..00000000000 --- a/libjava/gnu/java/rmi/server/UnicastServerRef.java +++ /dev/null @@ -1,306 +0,0 @@ -/* UnicastServerRef.java -- - Copyright (c) 1996, 1997, 1998, 1999, 2002, 2003, 2004 - Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.rmi.server; - -import java.io.ObjectInputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.ObjID; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RemoteRef; -import java.rmi.server.RemoteServer; -import java.rmi.server.RemoteStub; -import java.rmi.server.ServerNotActiveException; -import java.rmi.server.ServerRef; -import java.rmi.server.Skeleton; -import java.util.Hashtable; - -public class UnicastServerRef - extends UnicastRef - implements ServerRef{ //SHOULD implement ServerRef - -final static private Class[] stubprototype = new Class[] { RemoteRef.class }; - -Remote myself; //save the remote object itself -private Skeleton skel; -private RemoteStub stub; -private Hashtable methods = new Hashtable(); - -/** - * Used by serialization. - */ -UnicastServerRef() -{ -} - -public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory ssf) throws RemoteException { - super(id); - manager = UnicastConnectionManager.getInstance(port, ssf); -} - -public RemoteStub exportObject(Remote obj) throws RemoteException { - if (myself == null) { - myself = obj; - // Save it to server manager, to let client calls in the same VM to issue - // local call - manager.serverobj = obj; - - // Find and install the stub - Class cls = obj.getClass(); - Class expCls; - try { - // where ist the _Stub? (check superclasses also) - expCls = findStubSkelClass(cls); - } catch (Exception ex) { - throw new RemoteException("can not find stubs for class: " + cls, ex); - } - - stub = (RemoteStub)getHelperClass(expCls, "_Stub"); - if (stub == null) { - throw new RemoteException("failed to export: " + cls); - } - - // Find and install the skeleton (if there is one) - skel = (Skeleton)getHelperClass(expCls, "_Skel"); - - // Build hash of methods which may be called. - buildMethodHash(obj.getClass(), true); - - // Export it. - UnicastServer.exportObject(this); - } - - return (stub); -} - -public RemoteStub exportObject(Remote remote, Object obj) - throws RemoteException -{ - //FIX ME - return exportObject(remote); -} - -public RemoteStub getStub(){ - return stub; -} - - -public boolean unexportObject(Remote obj, boolean force) { - // Remove all hashes of methods which may be called. - buildMethodHash(obj.getClass(), false); - return UnicastServer.unexportObject(this, force); -} - -/** -* -* The Subs/Skels might not there for the actual class, but maybe -* for one of the superclasses. -* -*/ -private Class findStubSkelClass(Class startCls) throws Exception { - Class cls = startCls; - - while (true) { - try { - String stubClassname = cls.getName() + "_Stub"; - ClassLoader cl = cls.getClassLoader(); - Class scls = cl == null ? Class.forName(stubClassname) - : cl.loadClass(stubClassname); - return cls; // found it - } catch (ClassNotFoundException e) { - Class superCls = cls.getSuperclass(); - if (superCls == null - || superCls == java.rmi.server.UnicastRemoteObject.class) - { - throw new Exception("Neither " + startCls - + " nor one of their superclasses (like" + cls + ")" - + " has a _Stub"); - } - cls = superCls; - } - } -} - - - -private Object getHelperClass(Class cls, String type) { - try { - String classname = cls.getName(); - ClassLoader cl = cls.getClassLoader(); - Class scls = cl == null ? Class.forName(classname + type) - : cl.loadClass(classname + type); - if (type.equals("_Stub")) { - try { - // JDK 1.2 stubs - Constructor con = scls.getConstructor(stubprototype); - return (con.newInstance(new Object[]{this})); - } - catch (NoSuchMethodException e) { - } - catch (InstantiationException e) { - } - catch (IllegalAccessException e) { - } - catch (IllegalArgumentException e) { - } - catch (InvocationTargetException e) { - } - // JDK 1.1 stubs - RemoteStub stub = (RemoteStub)scls.newInstance(); - UnicastRemoteStub.setStubRef(stub, this); - return (stub); - } - else { - // JDK 1.1 skel - return (scls.newInstance()); - } - } - catch (ClassNotFoundException e) { - } - catch (InstantiationException e) { - } - catch (IllegalAccessException e) { - } - return (null); -} - - - -public String getClientHost() throws ServerNotActiveException { - return RemoteServer.getClientHost(); -} - -private void buildMethodHash(Class cls, boolean build) { - Method[] meths = cls.getMethods(); - for (int i = 0; i < meths.length; i++) { - /* Don't need to include any java.xxx related stuff */ - if (meths[i].getDeclaringClass().getName().startsWith("java.")) { - continue; - } - long hash = RMIHashes.getMethodHash(meths[i]); - if(build) - methods.put(new Long (hash), meths[i]); - else - methods.remove(new Long (hash)); -//System.out.println("meth = " + meths[i] + ", hash = " + hash); - } -} - -Class getMethodReturnType(int method, long hash) throws Exception -{ - if (method == -1) { - Method meth = (Method)methods.get(new Long (hash)); - return meth.getReturnType(); - }else - return null; -} - -public Object incomingMessageCall(UnicastConnection conn, int method, long hash) throws Exception { -//System.out.println("method = " + method + ", hash = " + hash); - // If method is -1 then this is JDK 1.2 RMI - so use the hash - // to locate the method - if (method == -1) { - Method meth = (Method)methods.get(new Long (hash)); -//System.out.println("class = " + myself.getClass() + ", meth = " + meth); - if (meth == null) { - throw new NoSuchMethodException(); - } - - ObjectInputStream in = conn.getObjectInputStream(); - int nrargs = meth.getParameterTypes().length; - Object[] args = new Object[nrargs]; - for (int i = 0; i < nrargs; i++) { - /** - * For debugging purposes - we don't handle CodeBases - * quite right so we don't always find the stubs. This - * lets us know that. - */ - try { - // need to handle primitive types - args[i] = ((RMIObjectInputStream)in).readValue(meth.getParameterTypes()[i]); - - } - catch (Exception t) { - t.printStackTrace(); - throw t; - } - } - //We must reinterpret the exception thrown by meth.invoke() - //return (meth.invoke(myself, args)); - Object ret = null; - try{ - ret = meth.invoke(myself, args); - }catch(InvocationTargetException e){ - Throwable cause = e.getTargetException(); - if (cause instanceof Exception) { - throw (Exception)cause; - } - else if (cause instanceof Error) { - throw (Error)cause; - } - else { - throw new Error("The remote method threw a java.lang.Throwable that is neither java.lang.Exception nor java.lang.Error.", e); - } - } - return ret; - } - // Otherwise this is JDK 1.1 style RMI - we find the skeleton - // and invoke it using the method number. We wrap up our - // connection system in a UnicastRemoteCall so it appears in a - // way the Skeleton can handle. - else { - if (skel == null) { - throw new NoSuchMethodException(); - } - UnicastRemoteCall call = new UnicastRemoteCall(conn); - skel.dispatch(myself, call, method, hash); - if (!call.isReturnValue()) - return RMIVoidValue.INSTANCE; - else - return (call.returnValue()); - } -} - -} - - diff --git a/libjava/gnu/java/security/Engine.java b/libjava/gnu/java/security/Engine.java deleted file mode 100644 index b75de5caa95..00000000000 --- a/libjava/gnu/java/security/Engine.java +++ /dev/null @@ -1,237 +0,0 @@ -/* Engine -- generic getInstance method. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import java.security.NoSuchAlgorithmException; -import java.security.Provider; - -/** - * Generic implementation of the getInstance methods in the various - * engine classes in java.security. - * <p> - * These classes ({@link java.security.Signature} for example) can be - * thought of as the "chrome, upholstery, and steering wheel", and the SPI - * (service provider interface, e.g. {@link java.security.SignatureSpi}) - * classes can be thought of as the "engine" -- providing the actual - * functionality of whatever cryptographic algorithm the instance - * represents. - * - * @see Provider - * @author Casey Marshall - */ -public final class Engine -{ - - // Constants. - // ------------------------------------------------------------------------ - - /** Prefix for aliases. */ - private static final String ALG_ALIAS = "Alg.Alias."; - - /** Maximum number of aliases to try. */ - private static final int MAX_ALIASES = 5; - - /** Argument list for no-argument constructors. */ - private static final Object[] NO_ARGS = new Object[0]; - - // Constructor. - // ------------------------------------------------------------------------ - - /** This class cannot be instantiated. */ - private Engine() { } - - // Class method. - // ------------------------------------------------------------------------ - - /** - * Get the implementation for <i>algorithm</i> for service - * <i>service</i> from <i>provider</i>. The service is e.g. - * "Signature", and the algorithm "DSA". - * - * @param service The service name. - * @param algorithm The name of the algorithm to get. - * @param provider The provider to get the implementation from. - * @return The engine class for the specified algorithm; the object - * returned is typically a subclass of the SPI class for that - * service, but callers should check that this is so. - * @throws NoSuchAlgorithmException If the implementation cannot be - * found or cannot be instantiated. - * @throws InvocationTargetException If the SPI class's constructor - * throws an exception. - * @throws IllegalArgumentException If any of the three arguments are null. - */ - public static Object getInstance(String service, String algorithm, - Provider provider) - throws InvocationTargetException, NoSuchAlgorithmException - { - return getInstance(service, algorithm, provider, NO_ARGS); - } - - /** - * Get the implementation for <i>algorithm</i> for service - * <i>service</i> from <i>provider</i>, passing <i>initArgs</i> to the - * SPI class's constructor (which cannot be null; pass a zero-length - * array if the SPI takes no arguments). The service is e.g. - * "Signature", and the algorithm "DSA". - * - * @param service The service name. - * @param algorithm The name of the algorithm to get. - * @param provider The provider to get the implementation from. - * @param initArgs The arguments to pass to the SPI class's - * constructor (cannot be null). - * @return The engine class for the specified algorithm; the object - * returned is typically a subclass of the SPI class for that - * service, but callers should check that this is so. - * @throws NoSuchAlgorithmException If the implementation cannot be - * found or cannot be instantiated. - * @throws InvocationTargetException If the SPI class's constructor - * throws an exception. - * @throws IllegalArgumentException If any of the four arguments are null. - */ - public static Object getInstance(String service, String algorithm, - Provider provider, Object[] initArgs) - throws InvocationTargetException, NoSuchAlgorithmException - { - if (service == null || algorithm == null - || provider == null || initArgs == null) - throw new IllegalArgumentException(); - - // If there is no property "service.algorithm" - if (provider.getProperty(service + "." + algorithm) == null) - { - // Iterate through aliases, until we find the class name or resolve - // too many aliases. - String alias = null; - int count = 0; - while ((alias = provider.getProperty( - ALG_ALIAS + service + "." + algorithm)) != null) - { - if (algorithm.equals(alias)) // Refers to itself! - break; - algorithm = alias; - if (count++ > MAX_ALIASES) - throw new NoSuchAlgorithmException("too many aliases"); - } - if (provider.getProperty(service + "." + algorithm) == null) - throw new NoSuchAlgorithmException(algorithm); - } - - // Find and instantiate the implementation. - Class clazz = null; - ClassLoader loader = provider.getClass().getClassLoader(); - Constructor constructor = null; - String error = algorithm; - - try - { - if (loader != null) - clazz = loader.loadClass(provider.getProperty(service+"."+algorithm)); - else - clazz = Class.forName(provider.getProperty(service+"."+algorithm)); - constructor = getCompatibleConstructor(clazz, initArgs); - return constructor.newInstance(initArgs); - } - catch (ClassNotFoundException cnfe) - { - error = "class not found: " + algorithm; - } - catch (IllegalAccessException iae) - { - error = "illegal access: " + iae.getMessage(); - } - catch (InstantiationException ie) - { - error = "instantiation exception: " + ie.getMessage(); - } - catch (ExceptionInInitializerError eiie) - { - error = "exception in initializer: " + eiie.getMessage(); - } - catch (SecurityException se) - { - error = "security exception: " + se.getMessage(); - } - catch (NoSuchMethodException nsme) - { - error = "no appropriate constructor found"; - } - - throw new NoSuchAlgorithmException(error); - } - - // Own methods. - // ------------------------------------------------------------------------ - - /** - * Find a constructor in the given class that can take the specified - * argument list, allowing any of which to be null. - * - * @param clazz The class from which to get the constructor. - * @param initArgs The argument list to be passed to the constructor. - * @return The constructor. - * @throws NoSuchMethodException If no constructor of the given class - * can take the specified argument array. - */ - private static Constructor getCompatibleConstructor(Class clazz, - Object[] initArgs) - throws NoSuchMethodException - { - Constructor[] c = clazz.getConstructors(); - outer:for (int i = 0; i < c.length; i++) - { - Class[] argTypes = c[i].getParameterTypes(); - if (argTypes.length != initArgs.length) - continue; - for (int j = 0; j < argTypes.length; j++) - { - if (initArgs[j] != null && - !argTypes[j].isAssignableFrom(initArgs[j].getClass())) - continue outer; - } - // If we reach this point, we know this constructor (c[i]) has - // the same number of parameters as the target parameter list, - // and all our parameters are either (1) null, or (2) assignable - // to the target parameter type. - return c[i]; - } - throw new NoSuchMethodException(); - } -} diff --git a/libjava/gnu/java/security/OID.java b/libjava/gnu/java/security/OID.java deleted file mode 100644 index 8cda43eeee8..00000000000 --- a/libjava/gnu/java/security/OID.java +++ /dev/null @@ -1,509 +0,0 @@ -/* OID.java -- numeric representation of an object identifier - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security; - -import gnu.java.security.der.DEREncodingException; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.StringTokenizer; - -/** - * This immutable class represents an object identifier, or OID. - * - * <p>OIDs are represented as a series of hierarcical tokens, each of - * which is usually represented as a single, unsigned integer. The - * hierarchy works so that later tokens are considered within the group - * of earlier tokens. Thus, the OID for the Serpent block cipher, - * 1.3.6.1.4.1.11591.13.2, is maintained by the GNU project, whose OID - * is 1.3.6.1.4.1.11591 (which is, in turn, part of bigger, more general - * bodies; the topmost, 1, stands for the OIDs assigned by the - * International Standards Organization, ISO). - * - * <p>OIDs can be represented in a variety of ways, including the - * dotted-decimal form we use here. - * - * <p>OIDs may be relative, in which case the first two elements of the - * OID are omitted. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class OID implements Cloneable, Comparable, java.io.Serializable -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** - * The numeric ID structure. - */ - private int[] components; - - /** - * The string representation of this OID, in dotted-decimal format. - */ - private transient String strRep; - - /** - * The DER encoding of this OID. - */ - private transient byte[] der; - - /** - * Whether or not this OID is relative. - */ - private boolean relative; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new OID from the given byte array. The argument (which can - * neither be null nor zero-length) is copied to prevent subsequent - * modification. - * - * @param components The numeric IDs. - * @throws IllegalArgumentException If <i>components</i> is null or empty. - */ - public OID(int[] components) - { - this(components, false); - } - - /** - * Create a new OID from the given byte array. The argument (which can - * neither be null nor zero-length) is copied to prevent subsequent - * modification. - * - * @param components The numeric IDs. - * @param relative The relative flag. - * @throws IllegalArgumentException If <i>components</i> is null or empty. - */ - public OID(int[] components, boolean relative) - { - if (components == null || components.length == 0) - throw new IllegalArgumentException(); - this.components = (int[]) components.clone(); - this.relative = relative; - } - - /** - * Create a new OID from the given dotted-decimal representation. - * - * @param strRep The string representation of the OID. - * @throws IllegalArgumentException If the string does not contain at - * least one integer. - * @throws NumberFormatException If the string does not contain only - * numbers and periods ('.'). - */ - public OID(String strRep) - { - this(strRep, false); - } - - /** - * Create a new OID from the given dotted-decimal representation. - * - * @param strRep The string representation of the OID. - * @param relative The relative flag. - * @throws IllegalArgumentException If the string does not contain at - * least one integer. - * @throws NumberFormatException If the string does not contain only - * numbers and periods ('.'). - */ - public OID(String strRep, boolean relative) - { - this.relative = relative; - this.strRep = strRep; - components = fromString(strRep); - } - - /** - * Construct a new OID from the DER bytes in an input stream. This method - * does not read the tag or the length field from the input stream, so - * the caller must supply the number of octets in this OID's encoded - * form. - * - * @param derIn The DER input stream. - * @param len The number of bytes in the encoded form. - * @throws IOException If an error occurs reading the OID. - */ - public OID(InputStream derIn, int len) throws IOException - { - this(derIn, len, false); - } - - /** - * Construct a new OID from the DER bytes in an input stream. This method - * does not read the tag or the length field from the input stream, so - * the caller must supply the number of octets in this OID's encoded - * form. - * - * @param derIn The DER input stream. - * @param len The number of bytes in the encoded form. - * @param relative The relative flag. - * @throws IOException If an error occurs reading the OID. - */ - public OID(InputStream derIn, int len, boolean relative) throws IOException - { - der = new byte[len]; - derIn.read(der); - this.relative = relative; - try - { - components = fromDER(der, relative); - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - aioobe.printStackTrace(); - throw aioobe; - } - } - - /** - * Construct a new OID from the given DER bytes. - * - * @param encoded The DER encoded OID. - * @throws IOException If an error occurs reading the OID. - */ - public OID(byte[] encoded) throws IOException - { - this(encoded, false); - } - - /** - * Construct a new OID from the given DER bytes. - * - * @param root The root OID. - * @param encoded The encoded relative OID. - * @param relative The relative flag. - */ - public OID(byte[] encoded, boolean relative) throws IOException - { - der = (byte[]) encoded.clone(); - this.relative = relative; - try - { - components = fromDER(der, relative); - } - catch (ArrayIndexOutOfBoundsException aioobe) - { - aioobe.printStackTrace(); - throw aioobe; - } - } - - /** - * Our private constructor. - */ - private OID() - { - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return the numeric IDs of this OID. The value returned is copied to - * prevent modification. - * - * @return The IDs in a new integer array. - */ - public int[] getIDs() - { - return (int[]) components.clone(); - } - - /** - * Get the DER encoding of this OID, minus the tag and length fields. - * - * @return The DER bytes. - */ - public byte[] getDER() - { - if (der == null) - { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - int i = 0; - if (!relative) - { - int b = components[i++] * 40 + (components.length > 1 - ? components[i++] : 0); - encodeSubID(bout, b); - } - for ( ; i < components.length; i++) - encodeSubID(bout, components[i]); - der = bout.toByteArray(); - } - return (byte[]) der.clone(); - } - - /** - * Get the parent OID of this OID. That is, if this OID is "1.2.3.4", - * then the parent OID will be "1.2.3". If this OID is a top-level - * OID, this method returns null. - * - * @return The parent OID, or null. - */ - public OID getParent() - { - if (components.length == 1) - return null; - int[] parent = new int[components.length - 1]; - System.arraycopy(components, 0, parent, 0, parent.length); - return new OID(parent); - } - - public OID getChild(int id) - { - int[] child = new int[components.length + 1]; - System.arraycopy(components, 0, child, 0, components.length); - child[child.length - 1] = id; - return new OID(child); - } - - /** - * Get the root OID of this OID. That is, the first two components. - * - * @return The root OID. - */ - public OID getRoot() - { - if (components.length <= 2) - return this; - int[] root = new int[2]; - root[0] = components[0]; - root[1] = components[1]; - return new OID(root); - } - - public boolean isRelative() - { - return relative; - } - - /** - * Returns a copy of this OID. - * - * @return The copy. - */ - public Object clone() - { - OID oid = new OID(); - oid.components = this.components; - oid.strRep = this.strRep; - return oid; - } - - /* Nice idea, but possibly too expensive for whatever benefit it - * provides. - - public String getShortName() - { - return OIDTable.getShortName(this); - } - - public String getLongName() - { - return OIDTable.getLongName(this); - } - - */ - - /** - * Returns the value of this OID in dotted-decimal format. - * - * @return The string representation. - */ - public String toString() - { - if (strRep != null) - return strRep; - else - { - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < components.length; i++) - { - buf.append((long) components[i] & 0xFFFFFFFFL); - if (i < components.length - 1) - buf.append('.'); - } - return (strRep = buf.toString()); - } - } - - /** - * Computes a hash code for this OID. - * - * @return The hash code. - */ - public int hashCode() - { - int ret = 0; - for (int i = 0; i < components.length; i++) - ret += components[i] << (i & 31); - return ret; - } - - /** - * Tests whether or not this OID equals another. - * - * @return Whether or not this OID equals the other. - */ - public boolean equals(Object o) - { - if (!(o instanceof OID)) - return false; - return java.util.Arrays.equals(components, ((OID) o).components); - } - - /** - * Compares this OID to another. The comparison is essentially - * lexicographic, where the two OIDs are compared until their - * first difference, then that difference is returned. If one OID is - * shorter, but all elements equal between the two for the shorter - * length, then the shorter OID is lesser than the longer. - * - * @param o The object to compare. - * @return An integer less than, equal to, or greater than zero if - * this object is less than, equal to, or greater than the - * argument. - * @throws ClassCastException If <i>o</i> is not an OID. - */ - public int compareTo(Object o) - { - if (equals(o)) - return 0; - int[] components2 = ((OID) o).components; - int len = Math.min(components.length, components2.length); - for (int i = 0; i < len; i++) - { - if (components[i] != components2[i]) - return (components[i] < components2[i]) ? -1 : 1; - } - if (components.length == components2.length) - return 0; - return (components.length < components2.length) ? -1 : 1; - } - - // Own methods. - // ------------------------------------------------------------------------ - - private static int[] fromDER(byte[] der, boolean relative) - throws DEREncodingException - { - // cannot be longer than this. - int[] components = new int[der.length + 1]; - int count = 0; - int i = 0; - if (!relative && i < der.length) - { - // Non-relative OIDs have the first two arcs coded as: - // - // i = first_arc * 40 + second_arc; - // - int j = (der[i] & 0xFF); - components[count++] = j / 40; - components[count++] = j % 40; - i++; - } - while (i < der.length) - { - int j = 0; - do - { - j = der[i++] & 0xFF; - components[count] <<= 7; - components[count] |= j & 0x7F; - if (i >= der.length && (j & 0x80) != 0) - throw new DEREncodingException("malformed OID"); - } - while ((j & 0x80) != 0); - count++; - } - if (count == components.length) - return components; - int[] ret = new int[count]; - System.arraycopy(components, 0, ret, 0, count); - return ret; - } - - private static int[] fromString(String strRep) throws NumberFormatException - { - if (strRep.startsWith("OID.") || strRep.startsWith("oid.")) - strRep = strRep.substring(4); - StringTokenizer tok = new StringTokenizer(strRep, "."); - if (tok.countTokens() == 0) - throw new IllegalArgumentException(); - int[] components = new int[tok.countTokens()]; - int i = 0; - while (tok.hasMoreTokens()) - { - components[i++] = Integer.parseInt(tok.nextToken()); - } - return components; - } - - private static void encodeSubID(ByteArrayOutputStream out, int id) - { - if (id < 128) - { - out.write(id); - } - else if (id < 16384) - { - out.write((id >>> 7) | 0x80); - out.write(id & 0x7F); - } - else if (id < 2097152) - { - out.write((id >>> 14) | 0x80); - out.write(((id >>> 7) | 0x80) & 0xFF); - out.write(id & 0x7F); - } - else if (id < 268435456) - { - out.write( (id >>> 21) | 0x80); - out.write(((id >>> 14) | 0x80) & 0xFF); - out.write(((id >>> 7) | 0x80) & 0xFF); - out.write(id & 0x7F); - } - } -} diff --git a/libjava/gnu/java/security/PolicyFile.java b/libjava/gnu/java/security/PolicyFile.java deleted file mode 100644 index dd3a4dec4c4..00000000000 --- a/libjava/gnu/java/security/PolicyFile.java +++ /dev/null @@ -1,667 +0,0 @@ -/* PolicyFile.java -- policy file reader - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security; - -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StreamTokenizer; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.AccessController; -import java.security.CodeSource; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.Policy; -import java.security.Principal; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.security.Security; -import java.security.UnresolvedPermission; -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -/** - * An implementation of a {@link java.security.Policy} object whose - * permissions are specified by a <em>policy file</em>. - * - * <p>The approximate syntax of policy files is:</p> - * - * <pre> - * policyFile ::= keystoreOrGrantEntries ; - * - * keystoreOrGrantEntries ::= keystoreOrGrantEntry | - * keystoreOrGrantEntries keystoreOrGrantEntry | - * EMPTY ; - * - * keystoreOrGrantEntry ::= keystoreEntry | grantEntry ; - * - * keystoreEntry ::= "keystore" keystoreUrl ';' | - * "keystore" keystoreUrl ',' keystoreAlgorithm ';' ; - * - * keystoreUrl ::= URL ; - * keystoreAlgorithm ::= STRING ; - * - * grantEntry ::= "grant" domainParameters '{' permissions '}' ';' - * - * domainParameters ::= domainParameter | - * domainParameter ',' domainParameters ; - * - * domainParameter ::= "signedBy" signerNames | - * "codeBase" codeBaseUrl | - * "principal" principalClassName principalName | - * "principal" principalName ; - * - * signerNames ::= quotedString ; - * codeBaseUrl ::= URL ; - * principalClassName ::= STRING ; - * principalName ::= quotedString ; - * - * quotedString ::= quoteChar STRING quoteChar ; - * quoteChar ::= '"' | '\''; - * - * permissions ::= permission | permissions permission ; - * - * permission ::= "permission" permissionClassName permissionTarget permissionAction | - * "permission" permissionClassName permissionTarget | - * "permission" permissionClassName; - * </pre> - * - * <p>Comments are either form of Java comments. Keystore entries only - * affect subsequent grant entries, so if a grant entry preceeds a - * keystore entry, that grant entry is not affected by that keystore - * entry. Certian instances of <code>${property-name}</code> will be - * replaced with <code>System.getProperty("property-name")</code> in - * quoted strings.</p> - * - * <p>This class will load the following files when created or - * refreshed, in order:</p> - * - * <ol> - * <li>The file <code>${java.home}/lib/security/java.policy</code>.</li> - * <li>All URLs specified by security properties - * <code>"policy.file.<i>n</i>"</code>, for increasing <i>n</i> - * starting from 1. The sequence stops at the first undefined - * property, so you must set <code>"policy.file.1"</code> if you also - * set <code>"policy.file.2"</code>, and so on.</li> - * <li>The URL specified by the property - * <code>"java.security.policy"</code>.</li> - * </ol> - * - * @author Casey Marshall (csm@gnu.org) - * @see java.security.Policy - */ -public final class PolicyFile extends Policy -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - private static final boolean DEBUG = true; - // Package-private to avoid a trampoline. - static void debug(String msg) - { - System.err.print(">> PolicyFile: "); - System.err.println(msg); - } - - private static void debug(Throwable t) - { - System.err.println(">> PolicyFile"); - t.printStackTrace(System.err); - } - - private static final String DEFAULT_POLICY = System.getProperty("java.home") - + System.getProperty("file.separator") + "lib" - + System.getProperty("file.separator") + "security" - + System.getProperty("file.separator") + "java.policy"; - - private final Map cs2pc; - - // Constructors. - // ------------------------------------------------------------------------- - - public PolicyFile() - { - cs2pc = new HashMap(); - refresh(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public PermissionCollection getPermissions(CodeSource codeSource) - { - Permissions perms = new Permissions(); - for (Iterator it = cs2pc.entrySet().iterator(); it.hasNext(); ) - { - Map.Entry e = (Map.Entry) it.next(); - CodeSource cs = (CodeSource) e.getKey(); - if (cs.implies(codeSource)) - { - if (DEBUG) debug(cs+" -> "+codeSource); - PermissionCollection pc = (PermissionCollection) e.getValue(); - for (Enumeration ee = pc.elements(); ee.hasMoreElements(); ) - { - perms.add((Permission) ee.nextElement()); - } - } - else - if (DEBUG) debug(cs+" !-> "+codeSource); - } - if (DEBUG) debug ("returning permissions " + perms + " for " + codeSource); - return perms; - } - - public void refresh() - { - cs2pc.clear(); - List policyFiles = new LinkedList(); - try - { - policyFiles.add(new File(DEFAULT_POLICY).toURL()); - if (DEBUG) debug ("defualt policy is " + DEFAULT_POLICY); - policyFiles.addAll((List) AccessController.doPrivileged( - new PrivilegedExceptionAction() - { - public Object run() throws Exception - { - LinkedList l = new LinkedList(); - for (int i = 1; ; i++) - { - String s = Security.getProperty("policy.file."+i); - if (DEBUG) debug("policy.file."+i+"="+s); - if (s == null) - break; - l.add(new URL(s)); - } - String s = System.getProperty("java.security.policy"); - if (DEBUG) debug("java.security.policy="+s); - if (s != null) - l.add(new URL(s)); - return l; - } - })); - } - catch (PrivilegedActionException pae) - { - if (DEBUG) debug(pae); - } - catch (MalformedURLException mue) - { - if (DEBUG) debug(mue); - } - for (Iterator it = policyFiles.iterator(); it.hasNext(); ) - { - try - { - URL url = (URL) it.next(); - parse(url); - } - catch (IOException ioe) - { - if (DEBUG) debug(ioe); - } - } - } - - public String toString() - { - return super.toString() + " [ " + cs2pc.toString() + " ]"; - } - - // Own methods. - // ------------------------------------------------------------------------- - - private static final int STATE_BEGIN = 0; - private static final int STATE_GRANT = 1; - private static final int STATE_PERMS = 2; - - /** - * Parse a policy file, incorporating the permission definitions - * described therein. - * - * @param url The URL of the policy file to read. - * @throws IOException if an I/O error occurs, or if the policy file - * cannot be parsed. - */ - private void parse(final URL url) throws IOException - { - if (DEBUG) debug ("reading policy file from " + url); - final StreamTokenizer in = new StreamTokenizer(new InputStreamReader(url.openStream())); - in.resetSyntax(); - in.slashSlashComments(true); - in.slashStarComments(true); - in.wordChars('A', 'Z'); - in.wordChars('a', 'z'); - in.wordChars('0', '9'); - in.wordChars('.', '.'); - in.wordChars('_', '_'); - in.wordChars('$', '$'); - in.whitespaceChars(' ', ' '); - in.whitespaceChars('\t', '\t'); - in.whitespaceChars('\f', '\f'); - in.whitespaceChars('\n', '\n'); - in.whitespaceChars('\r', '\r'); - in.quoteChar('\''); - in.quoteChar('"'); - - int tok; - int state = STATE_BEGIN; - List keystores = new LinkedList(); - URL currentBase = null; - List currentCerts = new LinkedList(); - Permissions currentPerms = new Permissions(); - while ((tok = in.nextToken()) != StreamTokenizer.TT_EOF) - { - switch (tok) - { - case '{': - if (state != STATE_GRANT) - error(url, in, "spurious '{'"); - state = STATE_PERMS; - tok = in.nextToken(); - break; - case '}': - if (state != STATE_PERMS) - error(url, in, "spurious '}'"); - state = STATE_BEGIN; - currentPerms.setReadOnly(); - Certificate[] c = null; - if (!currentCerts.isEmpty()) - c = (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]); - cs2pc.put(new CodeSource(currentBase, c), currentPerms); - currentCerts.clear(); - currentPerms = new Permissions(); - currentBase = null; - tok = in.nextToken(); - if (tok != ';') - in.pushBack(); - continue; - } - if (tok != StreamTokenizer.TT_WORD) - { - error(url, in, "expecting word token"); - } - - // keystore "<keystore-path>" [',' "<keystore-type>"] ';' - if (in.sval.equalsIgnoreCase("keystore")) - { - String alg = KeyStore.getDefaultType(); - tok = in.nextToken(); - if (tok != '"' && tok != '\'') - error(url, in, "expecting key store URL"); - String store = in.sval; - tok = in.nextToken(); - if (tok == ',') - { - tok = in.nextToken(); - if (tok != '"' && tok != '\'') - error(url, in, "expecting key store type"); - alg = in.sval; - tok = in.nextToken(); - } - if (tok != ';') - error(url, in, "expecting semicolon"); - try - { - KeyStore keystore = KeyStore.getInstance(alg); - keystore.load(new URL(url, store).openStream(), null); - keystores.add(keystore); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - } - else if (in.sval.equalsIgnoreCase("grant")) - { - if (state != STATE_BEGIN) - error(url, in, "extraneous grant keyword"); - state = STATE_GRANT; - } - else if (in.sval.equalsIgnoreCase("signedBy")) - { - if (state != STATE_GRANT && state != STATE_PERMS) - error(url, in, "spurious 'signedBy'"); - if (keystores.isEmpty()) - error(url, in, "'signedBy' with no keystores"); - tok = in.nextToken(); - if (tok != '"' && tok != '\'') - error(url, in, "expecting signedBy name"); - StringTokenizer st = new StringTokenizer(in.sval, ","); - while (st.hasMoreTokens()) - { - String alias = st.nextToken(); - for (Iterator it = keystores.iterator(); it.hasNext(); ) - { - KeyStore keystore = (KeyStore) it.next(); - try - { - if (keystore.isCertificateEntry(alias)) - currentCerts.add(keystore.getCertificate(alias)); - } - catch (KeyStoreException kse) - { - error(url, in, kse.toString()); - } - } - } - tok = in.nextToken(); - if (tok != ',') - { - if (state != STATE_GRANT) - error(url, in, "spurious ','"); - in.pushBack(); - } - } - else if (in.sval.equalsIgnoreCase("codeBase")) - { - if (state != STATE_GRANT) - error(url, in, "spurious 'codeBase'"); - tok = in.nextToken(); - if (tok != '"' && tok != '\'') - error(url, in, "expecting code base URL"); - String base = expand(in.sval); - if (File.separatorChar != '/') - base = base.replace(File.separatorChar, '/'); - try - { - currentBase = new URL(base); - } - catch (MalformedURLException mue) - { - error(url, in, mue.toString()); - } - tok = in.nextToken(); - if (tok != ',') - in.pushBack(); - } - else if (in.sval.equalsIgnoreCase("principal")) - { - if (state != STATE_GRANT) - error(url, in, "spurious 'principal'"); - tok = in.nextToken(); - if (tok == StreamTokenizer.TT_WORD) - { - tok = in.nextToken(); - if (tok != '"' && tok != '\'') - error(url, in, "expecting principal name"); - String name = in.sval; - Principal p = null; - try - { - Class pclass = Class.forName(in.sval); - Constructor c = - pclass.getConstructor(new Class[] { String.class }); - p = (Principal) c.newInstance(new Object[] { name }); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - for (Iterator it = keystores.iterator(); it.hasNext(); ) - { - KeyStore ks = (KeyStore) it.next(); - try - { - for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) - { - String alias = (String) e.nextElement(); - if (ks.isCertificateEntry(alias)) - { - Certificate cert = ks.getCertificate(alias); - if (!(cert instanceof X509Certificate)) - continue; - if (p.equals(((X509Certificate) cert).getSubjectDN()) || - p.equals(((X509Certificate) cert).getSubjectX500Principal())) - currentCerts.add(cert); - } - } - } - catch (KeyStoreException kse) - { - error(url, in, kse.toString()); - } - } - } - else if (tok == '"' || tok == '\'') - { - String alias = in.sval; - for (Iterator it = keystores.iterator(); it.hasNext(); ) - { - KeyStore ks = (KeyStore) it.next(); - try - { - if (ks.isCertificateEntry(alias)) - currentCerts.add(ks.getCertificate(alias)); - } - catch (KeyStoreException kse) - { - error(url, in, kse.toString()); - } - } - } - else - error(url, in, "expecting principal"); - tok = in.nextToken(); - if (tok != ',') - in.pushBack(); - } - else if (in.sval.equalsIgnoreCase("permission")) - { - if (state != STATE_PERMS) - error(url, in, "spurious 'permission'"); - tok = in.nextToken(); - if (tok != StreamTokenizer.TT_WORD) - error(url, in, "expecting permission class name"); - String className = in.sval; - Class clazz = null; - try - { - clazz = Class.forName(className); - } - catch (ClassNotFoundException cnfe) - { - } - tok = in.nextToken(); - if (tok == ';') - { - if (clazz == null) - { - currentPerms.add(new UnresolvedPermission(className, - null, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); - continue; - } - try - { - currentPerms.add((Permission) clazz.newInstance()); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - continue; - } - if (tok != '"' && tok != '\'') - error(url, in, "expecting permission target"); - String target = expand(in.sval); - tok = in.nextToken(); - if (tok == ';') - { - if (clazz == null) - { - currentPerms.add(new UnresolvedPermission(className, - target, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); - continue; - } - try - { - Constructor c = - clazz.getConstructor(new Class[] { String.class }); - currentPerms.add((Permission) c.newInstance( - new Object[] { target })); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - continue; - } - if (tok != ',') - error(url, in, "expecting ','"); - tok = in.nextToken(); - if (tok == StreamTokenizer.TT_WORD) - { - if (!in.sval.equalsIgnoreCase("signedBy")) - error(url, in, "expecting 'signedBy'"); - try - { - Constructor c = - clazz.getConstructor(new Class[] { String.class }); - currentPerms.add((Permission) c.newInstance( - new Object[] { target })); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - in.pushBack(); - continue; - } - if (tok != '"' && tok != '\'') - error(url, in, "expecting permission action"); - String action = in.sval; - if (clazz == null) - { - currentPerms.add(new UnresolvedPermission(className, - target, action, (Certificate[]) currentCerts.toArray(new Certificate[0]))); - continue; - } - else - { - try - { - Constructor c = clazz.getConstructor( - new Class[] { String.class, String.class }); - currentPerms.add((Permission) c.newInstance( - new Object[] { target, action })); - } - catch (Exception x) - { - error(url, in, x.toString()); - } - } - tok = in.nextToken(); - if (tok != ';' && tok != ',') - error(url, in, "expecting ';' or ','"); - } - } - } - - /** - * Expand all instances of <code>"${property-name}"</code> into - * <code>System.getProperty("property-name")</code>. - */ - private static String expand(final String s) - { - final StringBuffer result = new StringBuffer(); - final StringBuffer prop = new StringBuffer(); - int state = 0; - for (int i = 0; i < s.length(); i++) - { - switch (state) - { - case 0: - if (s.charAt(i) == '$') - state = 1; - else - result.append(s.charAt(i)); - break; - case 1: - if (s.charAt(i) == '{') - state = 2; - else - { - state = 0; - result.append('$').append(s.charAt(i)); - } - break; - case 2: - if (s.charAt(i) == '}') - { - String p = prop.toString(); - if (p.equals("/")) - p = "file.separator"; - p = System.getProperty(p); - if (p == null) - p = ""; - result.append(p); - prop.setLength(0); - state = 0; - } - else - prop.append(s.charAt(i)); - break; - } - } - if (state != 0) - result.append('$').append('{').append(prop); - return result.toString(); - } - - /** - * I miss macros. - */ - private static void error(URL base, StreamTokenizer in, String msg) - throws IOException - { - throw new IOException(base+":"+in.lineno()+": "+msg); - } -} diff --git a/libjava/gnu/java/security/action/GetPropertyAction.java b/libjava/gnu/java/security/action/GetPropertyAction.java deleted file mode 100644 index 2886deb3474..00000000000 --- a/libjava/gnu/java/security/action/GetPropertyAction.java +++ /dev/null @@ -1,89 +0,0 @@ -/* GetPropertyAction.java - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.action; - -import java.security.PrivilegedAction; - -/** - * PrivilegedAction implementation that calls System.getProperty() with - * the property name passed to its constructor. - * - * Example of use: - * <code> - * GetPropertyAction action = new GetPropertyAction("http.proxyPort"); - * String port = AccessController.doPrivileged(action); - * </code> - */ -public class GetPropertyAction implements PrivilegedAction -{ - String name; - String value = null; - - public GetPropertyAction() - { - } - - public GetPropertyAction(String propName) - { - setParameters(propName); - } - - public GetPropertyAction(String propName, String defaultValue) - { - setParameters(propName, defaultValue); - } - - public Object run() - { - return System.getProperty(name, value); - } - - public GetPropertyAction setParameters(String propName) - { - this.name = propName; - this.value = null; - return this; - } - - public GetPropertyAction setParameters(String propName, String defaultValue) - { - this.name = propName; - this.value = defaultValue; - return this; - } -} diff --git a/libjava/gnu/java/security/action/GetSecurityPropertyAction.java b/libjava/gnu/java/security/action/GetSecurityPropertyAction.java deleted file mode 100644 index 97fa15d03e5..00000000000 --- a/libjava/gnu/java/security/action/GetSecurityPropertyAction.java +++ /dev/null @@ -1,93 +0,0 @@ -/* GetSecurityPropertyAction.java - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.action; - -import java.security.PrivilegedAction; -import java.security.Security; - -/** - * PrivilegedAction implementation that calls Security.getProperty() - * with the property name passed to its constructor. - * - * Example of use: - * <code> - * GetSecurityPropertyAction action = new GetSecurityPropertyAction("javax.net.ssl.trustStorePassword"); - * String passwd = AccessController.doPrivileged(action); - * </code> - */ -public class GetSecurityPropertyAction implements PrivilegedAction -{ - private String name; - private String value; - - public GetSecurityPropertyAction() - { - } - - public GetSecurityPropertyAction(String propName) - { - setParameters(propName); - } - - public GetSecurityPropertyAction(String propName, String defaultValue) - { - setParameters(propName, defaultValue); - } - - public GetSecurityPropertyAction setParameters(String propName) - { - this.name = propName; - this.value = null; - return this; - } - - public GetSecurityPropertyAction setParameters(String propName, String defaultValue) - { - this.name = propName; - this.value = defaultValue; - return this; - } - - public Object run() - { - String val = Security.getProperty(name); - if (val == null) - val = value; - return val; - } -} diff --git a/libjava/gnu/java/security/action/SetAccessibleAction.java b/libjava/gnu/java/security/action/SetAccessibleAction.java deleted file mode 100644 index 77e5fc988b8..00000000000 --- a/libjava/gnu/java/security/action/SetAccessibleAction.java +++ /dev/null @@ -1,77 +0,0 @@ -/* SetAccessibleAction.java - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.action; - -import java.lang.reflect.AccessibleObject; -import java.security.PrivilegedAction; - -/** - * PrivilegedAction implementation that calls setAccessible(true) on the - * AccessibleObject passed to its constructor. - * - * Example of use: - * <code> - * Field dataField = cl.getDeclaredField("data"); - * AccessController.doPrivileged(new SetAccessibleAction(dataField)); - * </code> - */ -public class SetAccessibleAction implements PrivilegedAction -{ - AccessibleObject member; - - public SetAccessibleAction() - { - } - - public SetAccessibleAction(AccessibleObject member) - { - this.member = member; - } - - public Object run() - { - member.setAccessible(true); - return null; - } - - public SetAccessibleAction setMember(AccessibleObject member) - { - this.member = member; - return this; - } -} diff --git a/libjava/gnu/java/security/ber/BER.java b/libjava/gnu/java/security/ber/BER.java deleted file mode 100644 index 7efb1bf90cc..00000000000 --- a/libjava/gnu/java/security/ber/BER.java +++ /dev/null @@ -1,46 +0,0 @@ -/* BER.java -- basic encoding rules (BER) constants. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.ber; - -import gnu.java.security.der.DER; - -public interface BER extends DER -{ - BERValue END_OF_SEQUENCE = new BERValue(0, null); -} diff --git a/libjava/gnu/java/security/ber/BEREncodingException.java b/libjava/gnu/java/security/ber/BEREncodingException.java deleted file mode 100644 index aad10932cc4..00000000000 --- a/libjava/gnu/java/security/ber/BEREncodingException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* BEREncodingException.java --- BER Encoding Exception - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.ber; - -import gnu.java.security.der.DEREncodingException; - -public class BEREncodingException extends DEREncodingException -{ - public BEREncodingException() - { - super (); - } - - public BEREncodingException (String msg) - { - super (msg); - } -} diff --git a/libjava/gnu/java/security/ber/BERReader.java b/libjava/gnu/java/security/ber/BERReader.java deleted file mode 100644 index 53a3f3ee9a9..00000000000 --- a/libjava/gnu/java/security/ber/BERReader.java +++ /dev/null @@ -1,103 +0,0 @@ -/* BERReader.java -- basic encoding rules (BER) reader. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.ber; - -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; - -public class BERReader extends DERReader implements BER -{ - - /** - * Create a new DER reader from a byte array. - * - * @param in The encoded bytes. - */ - public BERReader(byte[] in) - { - super(in); - } - - public BERReader (byte[] in, int off, int len) - { - super(in, off, len); - } - - /** - * Create a new DER readed from an input stream. - * - * @param in The encoded bytes. - */ - public BERReader(InputStream in) - { - super(in); - } - - public DERValue read() throws IOException - { - in.mark(2); - int tag = in.read(); - if (tag == -1) - throw new EOFException(); - int length = in.read(); - if (length == 0) - { - if (tag == 0) - return END_OF_SEQUENCE; - return new BERValue(tag, CONSTRUCTED_VALUE, new byte[] { (byte) tag, 0 }); - } - else - { - in.reset(); - return super.read(); - } - } - - public int peek() throws IOException - { - in.mark(1); - int ret = in.read(); - in.reset(); - return ret; - } -} diff --git a/libjava/gnu/java/security/ber/BERValue.java b/libjava/gnu/java/security/ber/BERValue.java deleted file mode 100644 index aeaef39bf2b..00000000000 --- a/libjava/gnu/java/security/ber/BERValue.java +++ /dev/null @@ -1,82 +0,0 @@ -/* BERReader.java -- basic encoding rules (BER) value. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.ber; - -import gnu.java.security.der.DERValue; - -public class BERValue extends DERValue -{ - - private boolean indefinite; - - public BERValue(int tag, Object value, byte[] encoded) - { - super(tag, 0, value, encoded); - indefinite = true; - } - - public BERValue(int tag, int length, Object value, byte[] encoded) - { - super(tag, length, value, encoded); - } - - public BERValue(int tag, Object value) - { - super(tag, 0, value, null); - } - - public static boolean isIndefinite(DERValue value) - { - if (value instanceof BERValue) - return ((BERValue) value).getIndefinite(); - return false; - } - - public boolean getIndefinite() - { - return indefinite; - } - - public int getLength() - { - if (indefinite) - return 0; - return super.getLength(); - } -} diff --git a/libjava/gnu/java/security/der/BitString.java b/libjava/gnu/java/security/der/BitString.java deleted file mode 100644 index b88b14541b6..00000000000 --- a/libjava/gnu/java/security/der/BitString.java +++ /dev/null @@ -1,317 +0,0 @@ -/* BitString.java -- Java representation of the BIT STRING type. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -import java.math.BigInteger; -import java.util.Arrays; - -/** - * Immutable representation of a bit string, which is equivalent to a - * byte array except some number of the rightmost bits are ignored. For - * example, this could be the bit string: - * - * <pre> 00010101 11101101 11010xxx</pre> - * - * <p>Where the "xxx" represents three bits that should be ignored, and - * can have any value. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class BitString implements Cloneable, Comparable -{ - - // Fields. - // ------------------------------------------------------------------------ - - /** The bits themselves. */ - private final byte[] bytes; - - /** - * The exportable byte array. This array has the ignored bits - * removed. - */ - private transient byte[] externBytes; - - /** The number of bits ignored at the end of the byte array. */ - private final int ignoredBits; - - /** This bit string as a boolean array. */ - private transient boolean[] boolVal; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new bit string, shifting the given byte array if needed. - * - * @param bytes The byte array holding the bit string. - * @param ignoredBits The number of bits to ignore. - * @param doShift Pass true in this parameter if the byte array has - * not yet been shifted left by <i>ignoredBits</i>. - * @throws IllegalArgumentException If <i>ignoredBits</i> is negative - * or greater than 7. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes, int ignoredBits, boolean doShift) - { - this(bytes, 0, bytes.length, ignoredBits, doShift); - } - - /** - * Create a new bit string, shifting the given byte array if needed. - * - * @param bytes The byte array holding the bit string. - * @param offset The offset where the meaningful bytes begin. - * @param length The number of meaningful bytes. - * @param ignoredBits The number of bits to ignore. - * @param doShift Pass true in this parameter if the byte array has - * not yet been shifted left by <i>ignoredBits</i>. - * @throws IllegalArgumentException If <i>ignoredBits</i> is negative - * or greater than 7. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes, int offset, int length, - int ignoredBits, boolean doShift) - { - if (ignoredBits < 0 || ignoredBits > 7) - throw new IllegalArgumentException(); - if (bytes == null) - throw new NullPointerException(); - if (doShift && ignoredBits > 0) - { - this.externBytes = new byte[length]; - System.arraycopy(bytes, offset, externBytes, 0, length); - this.bytes = new BigInteger(externBytes).shiftLeft(ignoredBits) - .toByteArray(); - } - else - { - this.bytes = new byte[length]; - System.arraycopy(bytes, offset, this.bytes, 0, length); - } - this.ignoredBits = ignoredBits; - } - - /** - * Create a new bit string. - * - * @param bytes The byte array holding the bit string. - * @param offset The offset where the meaningful bytes begin. - * @param length The number of meaningful bytes. - * @param ignoredBits The number of bits to ignore. - * @throws IllegalArgumentException If <i>ignoredBits</i> is negative - * or greater than 7. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes, int offset, int length, int ignoredBits) - { - this(bytes, offset, length, ignoredBits, false); - } - - /** - * Create a new bit string. - * - * @param bytes The byte array holding the bit string. - * @param ignoredBits The number of bits to ignore. - * @throws IllegalArgumentException If <i>ignoredBits</i> is negative - * or greater than 7. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes, int ignoredBits) - { - this(bytes, 0, bytes.length, ignoredBits, false); - } - - /** - * Create a new bit string. - * - * @param bytes The byte array holding the bit string. - * @param offset The offset where the meaningful bytes begin. - * @param length The number of meaningful bytes. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes, int offset, int length) - { - this(bytes, offset, length, 0, false); - } - - /** - * Create a new bit string. - * - * @param bytes The byte array holding the bit string. - * @throws NullPointerException If <i>bytes</i> is null. - */ - public BitString(byte[] bytes) - { - this(bytes, 0, bytes.length, 0, false); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - /** - * Return this bit string as a byte array, with the ignored bits - * trimmed off. The byte array is cloned every time this method is - * called to prevent modification. - * - * @return The trimmed byte array. - */ - public byte[] toByteArray() - { - if (ignoredBits == 0) - return (byte[]) bytes.clone(); - if (externBytes == null) - externBytes = new BigInteger(bytes).shiftRight(ignoredBits).toByteArray(); - return (byte[]) externBytes.clone(); - } - - /** - * Returns this bit string as a byte array, with the ignored bits - * present. The byte array is cloned every time this method is - * called to prevent modification. - * - * @return The byte array. - */ - public byte[] getShiftedByteArray() - { - return (byte[]) bytes.clone(); - } - - /** - * Returns the number of ignored bits. - * - * @return The number of ignored bits. - */ - public int getIgnoredBits() - { - return ignoredBits; - } - - /** - * Returns the size, in bits, of this bit string. - * - * @return The size of this bit string. - */ - public int size() - { - return (bytes.length << 3) - ignoredBits; - } - - /** - * Return this bit string as a boolean array. The value returned is of - * size {@link #size()}, and each <code>true</code> value - * corresponding to each "1" in this bit string. The boolean array is - * cloned before it is returned. - * - * @return The boolean array. - */ - public boolean[] toBooleanArray() - { - if (boolVal == null) - { - boolVal = new boolean[size()]; - for (int i = 0, j = 7, k = 0; i < boolVal.length; i++) - { - boolVal[i] = (bytes[k] & 1 << j--) != 0; - if (j < 0) - { - j = 7; - k++; - } - } - } - return (boolean[]) boolVal.clone(); - } - - public Object clone() - { - try - { - return super.clone(); - } - catch (CloneNotSupportedException cce) - { - throw new InternalError(cce.getMessage()); - } - } - - public int compareTo(Object o) - { - BitString that = (BitString) o; - if (this.equals(that)) - return 0; - if (this.bytes.length != that.bytes.length) - return (this.bytes.length < that.bytes.length) ? -1 : 1; - if (this.ignoredBits != that.ignoredBits) - return (this.ignoredBits < that.ignoredBits) ? -1 : 1; - for (int i = 0; i < this.bytes.length; i++) - if (this.bytes[i] != that.bytes[i]) - return (this.bytes[i] < that.bytes[i]) ? -1 : 1; - return 0; // not reached. - } - - public boolean equals(Object o) - { - if (!(o instanceof BitString)) - return false; - BitString that = (BitString) o; - // True for cloned instances. - if (this.bytes == that.bytes && this.ignoredBits == that.ignoredBits) - return true; - if (this.ignoredBits == that.ignoredBits) - return Arrays.equals(this.bytes, that.bytes); - return false; - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - for (int i = 0, j = 7, k = 0; i < size(); i++) - { - sb.append((bytes[k] & 1 << j) != 0 ? "1" : "0"); - j--; - if (j < 0) - { - j = 7; - k++; - } - } - return sb.toString(); - } -} diff --git a/libjava/gnu/java/security/der/DER.java b/libjava/gnu/java/security/der/DER.java deleted file mode 100644 index a7eb4a6895e..00000000000 --- a/libjava/gnu/java/security/der/DER.java +++ /dev/null @@ -1,86 +0,0 @@ -/* DER.java -- Basic constants in DER sequences. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -/** - * The set of tags for DER types. - * - * @author Casey Marshall (csm@gnu.org) - */ -public interface DER -{ - int UNIVERSAL = 0x00; - int APPLICATION = 0x40; - int CONTEXT = 0x80; - int PRIVATE = 0xC0; - - int CONSTRUCTED = 0x20; - - int ANY = 0x00; - int BOOLEAN = 0x01; - int INTEGER = 0x02; - int BIT_STRING = 0x03; - int OCTET_STRING = 0x04; - int NULL = 0x05; - int OBJECT_IDENTIFIER = 0x06; - int REAL = 0x09; - int ENUMERATED = 0x0a; - int RELATIVE_OID = 0x0d; - - int SEQUENCE = 0x10; - int SET = 0x11; - - Object CONSTRUCTED_VALUE = new Object(); - - int NUMERIC_STRING = 0x12; - int PRINTABLE_STRING = 0x13; - int T61_STRING = 0x14; - int VIDEOTEX_STRING = 0x15; - int IA5_STRING = 0x16; - int GRAPHIC_STRING = 0x19; - int ISO646_STRING = 0x1A; - int GENERAL_STRING = 0x1B; - - int UTF8_STRING = 0x0C; - int UNIVERSAL_STRING = 0x1C; - int BMP_STRING = 0x1E; - - int UTC_TIME = 0x17; - int GENERALIZED_TIME = 0x18; -} diff --git a/libjava/gnu/java/security/der/DEREncodingException.java b/libjava/gnu/java/security/der/DEREncodingException.java deleted file mode 100644 index 90042a3fc54..00000000000 --- a/libjava/gnu/java/security/der/DEREncodingException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* DEREncodingException.java --- DER Encoding Exception - Copyright (C) 1999,2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -import java.io.IOException; - -public class DEREncodingException extends IOException -{ - public DEREncodingException() - { - super (); - } - - public DEREncodingException (String msg) - { - super (msg); - } -} diff --git a/libjava/gnu/java/security/der/DERReader.java b/libjava/gnu/java/security/der/DERReader.java deleted file mode 100644 index cb07f14325f..00000000000 --- a/libjava/gnu/java/security/der/DERReader.java +++ /dev/null @@ -1,437 +0,0 @@ -/* DERReader.java -- parses ASN.1 DER sequences - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -import gnu.java.security.OID; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -/** - * This class decodes DER sequences into Java objects. The methods of - * this class do not have knowledge of higher-levels of structure in the - * DER stream -- such as ASN.1 constructions -- and it is therefore up - * to the calling application to determine if the data are structured - * properly by inspecting the {@link DERValue} that is returned. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class DERReader implements DER -{ - - // Fields. - // ------------------------------------------------------------------------ - - protected InputStream in; - - protected final ByteArrayOutputStream encBuf; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Create a new DER reader from a byte array. - * - * @param in The encoded bytes. - */ - public DERReader(byte[] in) - { - this(new ByteArrayInputStream(in)); - } - - public DERReader (byte[] in, int off, int len) - { - this (new ByteArrayInputStream (in, off, len)); - } - - /** - * Create a new DER readed from an input stream. - * - * @param in The encoded bytes. - */ - public DERReader(InputStream in) - { - if (!in.markSupported()) - this.in = new BufferedInputStream(in, 16384); - else - this.in = in; - encBuf = new ByteArrayOutputStream(2048); - } - - // Class methods. - // ------------------------------------------------------------------------ - - /** - * Convenience method for reading a single primitive value from the - * given byte array. - * - * @param encoded The encoded bytes. - * @throws IOException If the bytes do not represent an encoded - * object. - */ - public static DERValue read(byte[] encoded) throws IOException - { - return new DERReader(encoded).read(); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public void skip (int bytes) throws IOException - { - in.skip (bytes); - } - - /** - * Decode a single value from the input stream, returning it in a new - * {@link DERValue}. By "single value" we mean any single type in its - * entirety -- including constructed types such as SEQUENCE and all - * the values they contain. Usually it is sufficient to call this - * method once to parse and return the top-level structure, then to - * inspect the returned value for the proper contents. - * - * @return The parsed DER structure. - * @throws IOException If an error occurs reading from the input - * stream. - * @throws DEREncodingException If the input does not represent a - * valid DER stream. - */ - public DERValue read() throws IOException - { - int tag = in.read(); - if (tag == -1) - throw new EOFException(); - encBuf.write(tag); - int len = readLength(); - DERValue value = null; - if ((tag & CONSTRUCTED) == CONSTRUCTED) - { - in.mark(2048); - byte[] encoded = new byte[len]; - in.read(encoded); - encBuf.write(encoded); - value = new DERValue(tag, len, CONSTRUCTED_VALUE, encBuf.toByteArray()); - in.reset(); - encBuf.reset(); - return value; - } - switch (tag & 0xC0) - { - case UNIVERSAL: - value = new DERValue(tag, len, readUniversal(tag, len), - encBuf.toByteArray()); - encBuf.reset(); - break; - case CONTEXT: - byte[] encoded = new byte[len]; - in.read(encoded); - encBuf.write(encoded); - value = new DERValue(tag, len, encoded, encBuf.toByteArray()); - encBuf.reset(); - break; - case APPLICATION: - // This should not be reached, since (I think) APPLICATION is - // always constructed. - throw new DEREncodingException("non-constructed APPLICATION data"); - default: - throw new DEREncodingException("PRIVATE class not supported"); - } - return value; - } - - protected int readLength() throws IOException - { - int i = in.read(); - if (i == -1) - throw new EOFException(); - encBuf.write(i); - if ((i & ~0x7F) == 0) - { - return i; - } - else if (i < 0xFF) - { - byte[] octets = new byte[i & 0x7F]; - in.read(octets); - encBuf.write(octets); - return new BigInteger(1, octets).intValue(); - } - throw new DEREncodingException(); - } - - // Own methods. - // ------------------------------------------------------------------------ - - private Object readUniversal(int tag, int len) throws IOException - { - byte[] value = new byte[len]; - in.read(value); - encBuf.write(value); - switch (tag & 0x1F) - { - case BOOLEAN: - if (value.length != 1) - throw new DEREncodingException(); - return Boolean.valueOf(value[0] != 0); - case NULL: - if (len != 0) - throw new DEREncodingException(); - return null; - case INTEGER: - case ENUMERATED: - return new BigInteger(value); - case BIT_STRING: - byte[] bits = new byte[len - 1]; - System.arraycopy(value, 1, bits, 0, bits.length); - return new BitString(bits, value[0] & 0xFF); - case OCTET_STRING: - return value; - case NUMERIC_STRING: - case PRINTABLE_STRING: - case T61_STRING: - case VIDEOTEX_STRING: - case IA5_STRING: - case GRAPHIC_STRING: - case ISO646_STRING: - case GENERAL_STRING: - case UNIVERSAL_STRING: - case BMP_STRING: - case UTF8_STRING: - return makeString(tag, value); - case UTC_TIME: - case GENERALIZED_TIME: - return makeTime(tag, value); - case OBJECT_IDENTIFIER: - return new OID(value); - case RELATIVE_OID: - return new OID(value, true); - default: - throw new DEREncodingException("unknown tag " + tag); - } - } - - private static String makeString(int tag, byte[] value) - throws IOException - { - switch (tag & 0x1F) - { - case NUMERIC_STRING: - case PRINTABLE_STRING: - case T61_STRING: - case VIDEOTEX_STRING: - case IA5_STRING: - case GRAPHIC_STRING: - case ISO646_STRING: - case GENERAL_STRING: - return fromIso88591(value); - - case UNIVERSAL_STRING: - // XXX The docs say UniversalString is encoded in four bytes - // per character, but Java has no support (yet) for UTF-32. - //return new String(buf, "UTF-32"); - case BMP_STRING: - return fromUtf16Be(value); - - case UTF8_STRING: - return fromUtf8(value); - - default: - throw new DEREncodingException("unknown string tag"); - } - } - - private static String fromIso88591(byte[] bytes) - { - StringBuffer str = new StringBuffer(bytes.length); - for (int i = 0; i < bytes.length; i++) - str.append((char) (bytes[i] & 0xFF)); - return str.toString(); - } - - private static String fromUtf16Be(byte[] bytes) throws IOException - { - if ((bytes.length & 0x01) != 0) - throw new IOException("UTF-16 bytes are odd in length"); - StringBuffer str = new StringBuffer(bytes.length / 2); - for (int i = 0; i < bytes.length; i += 2) - { - char c = (char) ((bytes[i] << 8) & 0xFF); - c |= (char) (bytes[i+1] & 0xFF); - str.append(c); - } - return str.toString(); - } - - private static String fromUtf8(byte[] bytes) throws IOException - { - StringBuffer str = new StringBuffer((int)(bytes.length / 1.5)); - for (int i = 0; i < bytes.length; ) - { - char c = 0; - if ((bytes[i] & 0xE0) == 0xE0) - { - if ((i + 2) >= bytes.length) - throw new IOException("short UTF-8 input"); - c = (char) ((bytes[i++] & 0x0F) << 12); - if ((bytes[i] & 0x80) != 0x80) - throw new IOException("malformed UTF-8 input"); - c |= (char) ((bytes[i++] & 0x3F) << 6); - if ((bytes[i] & 0x80) != 0x80) - throw new IOException("malformed UTF-8 input"); - c |= (char) (bytes[i++] & 0x3F); - } - else if ((bytes[i] & 0xC0) == 0xC0) - { - if ((i + 1) >= bytes.length) - throw new IOException("short input"); - c = (char) ((bytes[i++] & 0x1F) << 6); - if ((bytes[i] & 0x80) != 0x80) - throw new IOException("malformed UTF-8 input"); - c |= (char) (bytes[i++] & 0x3F); - } - else if ((bytes[i] & 0xFF) < 0x80) - { - c = (char) (bytes[i++] & 0xFF); - } - else - throw new IOException("badly formed UTF-8 sequence"); - str.append(c); - } - return str.toString(); - } - - private Date makeTime(int tag, byte[] value) throws IOException - { - Calendar calendar = Calendar.getInstance(); - String str = makeString(PRINTABLE_STRING, value); - - // Classpath's SimpleDateFormat does not work for parsing these - // types of times, so we do this by hand. - String date = str; - String tz = ""; - if (str.indexOf("+") > 0) - { - date = str.substring(0, str.indexOf("+")); - tz = str.substring(str.indexOf("+")); - } - else if (str.indexOf("-") > 0) - { - date = str.substring(0, str.indexOf("-")); - tz = str.substring(str.indexOf("-")); - } - else if (str.endsWith("Z")) - { - date = str.substring(0, str.length()-2); - tz = "Z"; - } - if (!tz.equals("Z") && tz.length() > 0) - calendar.setTimeZone(TimeZone.getTimeZone(tz)); - else - calendar.setTimeZone(TimeZone.getTimeZone("UTC")); - if ((tag & 0x1F) == UTC_TIME) - { - if (date.length() < 10) // must be at least 10 chars long - throw new DEREncodingException("cannot parse date"); - // UTCTime is of the form "yyMMddHHmm[ss](Z|(+|-)hhmm)" - try - { - int year = Integer.parseInt(str.substring(0, 2)); - if (year < 50) - year += 2000; - else - year += 1900; - calendar.set(year, - Integer.parseInt(str.substring( 2, 4))-1, // month - Integer.parseInt(str.substring( 4, 6)), // day - Integer.parseInt(str.substring( 6, 8)), // hour - Integer.parseInt(str.substring( 8, 10))); // minute - if (date.length() == 12); - calendar.set(Calendar.SECOND, - Integer.parseInt(str.substring(10, 12))); - } - catch (NumberFormatException nfe) - { - throw new DEREncodingException("cannot parse date"); - } - } - else - { - if (date.length() < 10) // must be at least 10 chars long - throw new DEREncodingException("cannot parse date"); - // GeneralTime is of the form "yyyyMMddHH[mm[ss[(.|,)SSSS]]]" - // followed by "Z" or "(+|-)hh[mm]" - try - { - calendar.set( - Integer.parseInt(date.substring(0, 4)), // year - Integer.parseInt(date.substring(4, 6))-1, // month - Integer.parseInt(date.substring(6, 8)), // day - Integer.parseInt(date.substring(8, 10)), 0); // hour, min - switch (date.length()) - { - case 19: - case 18: - case 17: - case 16: - calendar.set(Calendar.MILLISECOND, - Integer.parseInt(date.substring(15))); - case 14: - calendar.set(Calendar.SECOND, - Integer.parseInt(date.substring(12, 14))); - case 12: - calendar.set(Calendar.MINUTE, - Integer.parseInt(date.substring(10, 12))); - } - } - catch (NumberFormatException nfe) - { - throw new DEREncodingException("cannot parse date"); - } - } - return calendar.getTime(); - } -} diff --git a/libjava/gnu/java/security/der/DERValue.java b/libjava/gnu/java/security/der/DERValue.java deleted file mode 100644 index 9a597d724cc..00000000000 --- a/libjava/gnu/java/security/der/DERValue.java +++ /dev/null @@ -1,170 +0,0 @@ -/* DERValue.java -- a value read or written to a DER encoding. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -public class DERValue implements DER -{ - - // Fields. - // ------------------------------------------------------------------------ - - private final int tagClass; - private final boolean constructed; - private final int tag; - private int length; - private final Object value; - private byte[] encoded; - - // Constructor. - // ------------------------------------------------------------------------ - - public DERValue(int tag, int length, Object value, byte[] encoded) - { - tagClass = tag & 0xC0; - this.tag = tag & 0x1F; - constructed = (tag & CONSTRUCTED) == CONSTRUCTED; - this.length = length; - this.value = value; - if (encoded != null) - this.encoded = (byte[]) encoded.clone(); - } - - public DERValue(int tag, Object value) - { - this(tag, 0, value, null); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public int getExternalTag() - { - return tagClass | tag | (constructed ? 0x20 : 0x00); - } - - public int getTag() - { - return tag; - } - - public int getTagClass() - { - return tagClass; - } - - public boolean isConstructed() - { - return constructed; - } - - public int getLength() - { - if (encoded == null) - { - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - length = DERWriter.write(out, this); - encoded = out.toByteArray(); - } - catch (IOException ioe) - { - encoded = new byte[0]; - } - } - return length; - } - - public Object getValue() - { - return value; - } - - public Object getValueAs (final int derType) throws IOException - { - byte[] encoded = getEncoded (); - encoded[0] = (byte) derType; - return DERReader.read (encoded).getValue (); - } - - public byte[] getEncoded() - { - if (encoded == null) - { - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - length = DERWriter.write(out, this); - encoded = out.toByteArray(); - } - catch (IOException ioe) - { - encoded = new byte[0]; - } - } - return (byte[]) encoded.clone(); - } - - public int getEncodedLength() - { - if (encoded == null) - { - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - length = DERWriter.write(out, this); - encoded = out.toByteArray(); - } - catch (IOException ioe) - { - encoded = new byte[0]; - } - } - return encoded.length; - } - - public String toString() - { - return "DERValue [ tag=" + tag + ", class=" + tagClass + ", constructed=" - + constructed + ", value=" + value + " ]"; - } -} diff --git a/libjava/gnu/java/security/der/DERWriter.java b/libjava/gnu/java/security/der/DERWriter.java deleted file mode 100644 index 78524fc949f..00000000000 --- a/libjava/gnu/java/security/der/DERWriter.java +++ /dev/null @@ -1,349 +0,0 @@ -/* DERWriter.java -- write Java types in DER format. - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.der; - -import gnu.java.security.OID; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import java.math.BigInteger; - -import java.text.SimpleDateFormat; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TimeZone; - -/** - * Methods that allow various Java types to be written as a DER - * (Distinguished Encoding Rules) stream to the specified output stream. - * DER is used to encode ASN.1 constructions, but this class provides no - * methods for interacting with ASN.1. Rather, callers should construct - * their output objects properly for whatever ASN.1 construct is being - * output. - * - * <p>This class only defines static methods; there are no instance - * variables needed. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class DERWriter implements DER -{ - - // Constructors. - // ------------------------------------------------------------------------ - - /** This class only has static methods. */ - private DERWriter() - { - } - - // Class methods. - // ------------------------------------------------------------------------ - - public static int write(OutputStream out, DERValue object) - throws IOException - { - out.write(object.getExternalTag()); - Object value = object.getValue(); - if (value == null) - { - writeLength(out, 0); - return 0; - } - if (value instanceof Boolean) - return writeBoolean(out, (Boolean) value); - else if (value instanceof BigInteger) - return writeInteger(out, (BigInteger) value); - else if (value instanceof Date) - return writeDate(out, object.getExternalTag(), (Date) value); - else if (value instanceof String) - return writeString(out, object.getExternalTag(), (String) value); - else if (value instanceof List) - return writeSequence(out, (List) value); - else if (value instanceof Set) - return writeSet(out, (Set) value); - else if (value instanceof BitString) - return writeBitString(out, (BitString) value); - else if (value instanceof OID) - return writeOID(out, (OID) value); - else if (value instanceof byte[]) - { - writeLength(out, ((byte[]) value).length); - out.write((byte[]) value); - return ((byte[]) value).length; - } - else if (value instanceof DERValue) - { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - write(bout, (DERValue) value); - byte[] buf = bout.toByteArray(); - writeLength(out, buf.length); - out.write(buf); - return buf.length; - } - else - throw new DEREncodingException("cannot encode " + value.getClass().getName()); - } - - public static int definiteEncodingSize(int length) - { - if (length < 128) - return 1; - else if (length < 256) - return 2; - else if (length < 65536) - return 3; - else if (length < 16777216) - return 4; - else - return 5; - } - - // Own methods. - // ------------------------------------------------------------------------ - - /** - * Write a BOOLEAN type to the given output stream. - * - * @param out The sink output stream. - * @param b The boolean value to write. - */ - private static int writeBoolean(OutputStream out, Boolean b) - throws IOException - { - writeLength(out, 1); - if (b.booleanValue()) - out.write(0xFF); - else - out.write(0); - return 1; - } - - /** - * Write an INTEGER type to the given output stream. - * - * @param out The sink output stream. - * @param integer The integer to write. - */ - private static int writeInteger(OutputStream out, BigInteger integer) - throws IOException - { - byte[] bytes = integer.toByteArray(); - writeLength(out, bytes.length); - out.write(bytes); - return bytes.length; - } - - private static int writeSequence(OutputStream out, List sequence) - throws IOException - { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - for (Iterator i = sequence.iterator(); i.hasNext(); ) - { - write(bout, (DERValue) i.next()); - } - byte[] buf = bout.toByteArray(); - writeLength(out, buf.length); - out.write(buf); - return buf.length; - } - - private static int writeSet(OutputStream out, Set set) - throws IOException - { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - for (Iterator i = set.iterator(); i.hasNext(); ) - { - write(bout, (DERValue) i.next()); - } - byte[] buf = bout.toByteArray(); - writeLength(out, buf.length); - out.write(buf); - return buf.length; - } - - private static int writeOID(OutputStream out, OID oid) - throws IOException - { - byte[] der = oid.getDER(); - writeLength(out, der.length); - out.write(der); - return der.length; - } - - private static int writeBitString(OutputStream out, BitString bs) - throws IOException - { - byte[] buf = bs.getShiftedByteArray(); - out.write(buf.length + 1); - out.write(bs.getIgnoredBits()); - out.write(buf); - return buf.length; - } - - private static int writeString(OutputStream out, int tag, String str) - throws IOException - { - byte[] b = null; - switch (tag & 0x1F) - { - case NUMERIC_STRING: - case PRINTABLE_STRING: - case T61_STRING: - case VIDEOTEX_STRING: - case IA5_STRING: - case GRAPHIC_STRING: - case ISO646_STRING: - case GENERAL_STRING: - b = toIso88591(str); - break; - - case UNIVERSAL_STRING: - case BMP_STRING: - b = toUtf16Be(str); - break; - - case UTF8_STRING: - default: - b = toUtf8(str); - break; - } - writeLength(out, b.length); - out.write(b); - return b.length; - } - - private static byte[] toIso88591(String string) - { - byte[] result = new byte[string.length()]; - for (int i = 0; i < string.length(); i++) - result[i] = (byte) string.charAt(i); - return result; - } - - private static byte[] toUtf16Be(String string) - { - byte[] result = new byte[string.length() * 2]; - for (int i = 0; i < string.length(); i++) - { - result[i*2 ] = (byte) ((string.charAt(i) >>> 8) & 0xFF); - result[i*2+1] = (byte) (string.charAt(i) & 0xFF); - } - return result; - } - - private static byte[] toUtf8(String string) - { - ByteArrayOutputStream buf = - new ByteArrayOutputStream((int)(string.length() * 1.5)); - for (int i = 0; i < string.length(); i++) - { - char c = string.charAt(i); - if (c < 0x0080) - buf.write(c & 0xFF); - else if (c < 0x0800) - { - buf.write(0xC0 | ((c >>> 6) & 0x3F)); - buf.write(0x80 | (c & 0x3F)); - } - else - { - buf.write(0xE0 | ((c >>> 12) & 0x0F)); - buf.write(0x80 | ((c >>> 6) & 0x3F)); - buf.write(0x80 | (c & 0x3F)); - } - } - return buf.toByteArray(); - } - - private static int writeDate(OutputStream out, int tag, Date date) - throws IOException - { - SimpleDateFormat sdf = null; - if ((tag & 0x1F) == UTC_TIME) - sdf = new SimpleDateFormat("yyMMddHHmmss'Z'"); - else - sdf = new SimpleDateFormat("yyyyMMddHHmmss'.'SSS'Z'"); - sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - byte[] b = sdf.format(date).getBytes("ISO-8859-1"); - writeLength(out, b.length); - out.write(b); - return b.length; - } - - // Package method. - // ------------------------------------------------------------------------ - - static void writeLength(OutputStream out, int len) throws IOException - { - if (len < 128) - out.write(len); - else if (len < 256) - { - out.write(0x81); - out.write(len); - } - else if (len < 65536) - { - out.write(0x82); - out.write(len >> 8); - out.write(len); - } - else if (len < 16777216) - { - out.write(0x83); - out.write(len >> 16); - out.write(len >> 8); - out.write(len); - } - else - { - out.write(0x84); - out.write(len >> 24); - out.write(len >> 16); - out.write(len >> 8); - out.write(len); - } - } -} diff --git a/libjava/gnu/java/security/pkcs/PKCS7SignedData.java b/libjava/gnu/java/security/pkcs/PKCS7SignedData.java deleted file mode 100644 index ba5efc7222f..00000000000 --- a/libjava/gnu/java/security/pkcs/PKCS7SignedData.java +++ /dev/null @@ -1,364 +0,0 @@ -/* PKCS7SignedData.java -- reader for PKCS#7 signedData objects - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.pkcs; - -import gnu.java.security.OID; -import gnu.java.security.ber.BER; -import gnu.java.security.ber.BEREncodingException; -import gnu.java.security.ber.BERReader; -import gnu.java.security.ber.BERValue; -import gnu.java.security.der.DERValue; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import java.math.BigInteger; - -import java.security.cert.CRL; -import java.security.cert.CRLException; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * The SignedData object in PKCS #7. This is a read-only implementation of - * this format, and is used to provide signed Jar file support. - * - * @author Casey Marshall (csm@gnu.org) - */ -public class PKCS7SignedData -{ - - public static final OID PKCS7_DATA = new OID("1.2.840.113549.1.7.1"); - public static final OID PKCS7_SIGNED_DATA = new OID("1.2.840.113549.1.7.2"); - - private BigInteger version; - private Set digestAlgorithms; - private OID contentType; - private byte[] content; - private Certificate[] certificates; - private CRL[] crls; - private Set signerInfos; - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - System.err.print("PKCS7SignedData >> "); - System.err.println(msg); - } - - public PKCS7SignedData(InputStream in) - throws CRLException, CertificateException, IOException - { - this(new BERReader(in)); - } - - /** - * Parse an encoded PKCS#7 SignedData object. The ASN.1 format of this - * object is: - * - * <pre> - * SignedData ::= SEQUENCE { - * version Version, - * digestAlgorithms DigestAlgorithmIdentifiers, - * contentInfo ContentInfo, - * certificates - * [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL, - * crls - * [1] IMPLICIT CertificateRevocationLists OPTIONAL, - * signerInfos SignerInfos } - * - * Version ::= INTEGER - * - * DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier - * - * DigestAlgorithmIdentifier ::= AlgorithmIdentifier - * - * ContentInfo ::= SEQUENCE { - * contentType ContentType, - * content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL } - * - * ContentType ::= OBJECT IDENTIFIER - * - * ExtendedCertificatesAndCertificates ::= - * SET OF ExtendedCertificatesAndCertificate - * - * ExtendedCertificatesAndCertificate ::= CHOICE { - * certificate Certificate, -- from X.509 - * extendedCertificate [0] IMPLICIT ExtendedCertificate } - * - * CertificateRevocationLists ::= SET OF CertificateRevocationList - * -- from X.509 - * - * SignerInfos ::= SET OF SignerInfo - * - * SignerInfo ::= SEQUENCE { - * version Version, - * issuerAndSerialNumber IssuerAndSerialNumber, - * digestAlgorithm DigestAlgorithmIdentifier, - * authenticatedAttributes - * [0] IMPLICIT Attributes OPTIONAL, - * digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, - * encryptedDigest EncryptedDigest, - * unauthenticatedAttributes - * [1] IMPLICIT Attributes OPTIONAL } - * - * EncryptedDigest ::= OCTET STRING - * </pre> - * - * <p>(Readers who are confused as to why it takes 40 levels of indirection - * to specify "data with a signature", rest assured that the present author - * is as confused as you are).</p> - */ - public PKCS7SignedData(BERReader ber) - throws CRLException, CertificateException, IOException - { - CertificateFactory x509 = CertificateFactory.getInstance("X509"); - DERValue val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed ContentInfo"); - - val = ber.read(); - if (val.getTag() != BER.OBJECT_IDENTIFIER) - throw new BEREncodingException("malformed ContentType"); - - if (!PKCS7_SIGNED_DATA.equals(val.getValue())) - throw new BEREncodingException("content is not SignedData"); - - val = ber.read(); - if (val.getTag() != 0) - throw new BEREncodingException("malformed Content"); - - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed SignedData"); - - if (DEBUG) - debug("SignedData: " + val); - - val = ber.read(); - if (val.getTag() != BER.INTEGER) - throw new BEREncodingException("expecting Version"); - version = (BigInteger) val.getValue(); - - if (DEBUG) - debug(" Version: " + version); - - digestAlgorithms = new HashSet(); - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed DigestAlgorithmIdentifiers"); - if (DEBUG) - debug(" DigestAlgorithmIdentifiers: " + val); - int count = 0; - DERValue val2 = ber.read(); - while (val2 != BER.END_OF_SEQUENCE && - (val.getLength() > 0 && val.getLength() > count)) - { - if (!val2.isConstructed()) - throw new BEREncodingException("malformed AlgorithmIdentifier"); - if (DEBUG) - debug(" AlgorithmIdentifier: " + val2); - count += val2.getEncodedLength(); - val2 = ber.read(); - if (val2.getTag() != BER.OBJECT_IDENTIFIER) - throw new BEREncodingException("malformed AlgorithmIdentifier"); - if (DEBUG) - debug(" ID: " + val2.getValue()); - List algId = new ArrayList(2); - algId.add(val2.getValue()); - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - { - count += val2.getEncodedLength(); - if (val2.getTag() == BER.NULL) - algId.add(null); - else - algId.add(val2.getEncoded()); - if (DEBUG) - debug(" params: " + new BigInteger(1, val2.getEncoded()).toString(16)); - if (val2.isConstructed()) - ber.skip(val2.getLength()); - if (BERValue.isIndefinite(val)) - val2 = ber.read(); - } - else - algId.add(null); - digestAlgorithms.add(algId); - } - - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed ContentInfo"); - if (DEBUG) - debug(" ContentInfo: " + val); - val2 = ber.read(); - if (val2.getTag() != BER.OBJECT_IDENTIFIER) - throw new BEREncodingException("malformed ContentType"); - contentType = (OID) val2.getValue(); - if (DEBUG) - debug(" ContentType: " + contentType); - if (BERValue.isIndefinite(val) - || (val.getLength() > 0 && val.getLength() > val2.getEncodedLength())) - { - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - { - content = val2.getEncoded(); - if (BERValue.isIndefinite(val)) - val2 = ber.read(); - if (DEBUG) - debug(" Content: " + new BigInteger(1, content).toString(16)); - } - } - - val = ber.read(); - if (val.getTag() == 0) - { - if (!val.isConstructed()) - throw new BEREncodingException("malformed ExtendedCertificatesAndCertificates"); - if (DEBUG) - debug(" ExtendedCertificatesAndCertificates: " + val); - count = 0; - val2 = ber.read(); - List certs = new LinkedList(); - while (val2 != BER.END_OF_SEQUENCE && - (val.getLength() > 0 && val.getLength() > count)) - { - Certificate cert = - x509.generateCertificate(new ByteArrayInputStream(val2.getEncoded())); - if (DEBUG) - debug(" Certificate: " + cert); - certs.add(cert); - count += val2.getEncodedLength(); - ber.skip(val2.getLength()); - if (BERValue.isIndefinite(val) || val.getLength() > count) - val2 = ber.read(); - } - certificates = (Certificate[]) certs.toArray(new Certificate[certs.size()]); - val = ber.read(); - } - - if (val.getTag() == 1) - { - if (!val.isConstructed()) - throw new BEREncodingException("malformed CertificateRevocationLists"); - if (DEBUG) - debug(" CertificateRevocationLists: " + val); - count = 0; - val2 = ber.read(); - List crls = new LinkedList(); - while (val2 != BER.END_OF_SEQUENCE && - (val.getLength() > 0 && val.getLength() > count)) - { - CRL crl = x509.generateCRL(new ByteArrayInputStream(val2.getEncoded())); - if (DEBUG) - debug (" CRL: " + crl); - crls.add(crl); - count += val2.getEncodedLength(); - ber.skip(val2.getLength()); - if (BERValue.isIndefinite(val) || val.getLength() > count) - val2 = ber.read(); - } - this.crls = (CRL[]) crls.toArray(new CRL[crls.size()]); - val = ber.read(); - } - - signerInfos = new HashSet(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed SignerInfos"); - - if (DEBUG) - debug(" SignerInfos: " + val); - - // FIXME read this more carefully. - // Since we are just reading a file (probably) we just read until we - // reach the end. - while (true) - { - int i = ber.peek(); - if (i == 0 || i == -1) - break; - signerInfos.add(new SignerInfo(ber)); - } - } - - public BigInteger getVersion() - { - return version; - } - - public Certificate[] getCertificates() - { - return (certificates != null ? (Certificate[]) certificates.clone() - : null); - } - - public OID getContentType() - { - return contentType; - } - - public byte[] getContent() - { - return (content != null ? (byte[]) content.clone() : null); - } - - public Set getDigestAlgorithms() - { - // FIXME copy contents too, they are mutable!!! - return Collections.unmodifiableSet(digestAlgorithms); - } - - public Set getSignerInfos() - { - Set copy = new HashSet(); - for (Iterator it = signerInfos.iterator(); it.hasNext(); ) - copy.add(it.next()); - return Collections.unmodifiableSet(copy); - } -} diff --git a/libjava/gnu/java/security/pkcs/SignerInfo.java b/libjava/gnu/java/security/pkcs/SignerInfo.java deleted file mode 100644 index c976799bb0c..00000000000 --- a/libjava/gnu/java/security/pkcs/SignerInfo.java +++ /dev/null @@ -1,279 +0,0 @@ -/* SignerInfo.java -- a SignerInfo object, from PKCS #7 - Copyright (C) 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.pkcs; - -import gnu.java.security.OID; -import gnu.java.security.ber.BER; -import gnu.java.security.ber.BEREncodingException; -import gnu.java.security.ber.BERReader; -import gnu.java.security.ber.BERValue; -import gnu.java.security.der.DERValue; - -import java.io.IOException; - -import java.math.BigInteger; - -import javax.security.auth.x500.X500Principal; - -public class SignerInfo -{ - private final BigInteger version; - private final BigInteger serialNumber; - private final X500Principal issuer; - private final OID digestAlgorithmId; - private final byte[] digestAlgorithmParams; - private final byte[] authenticatedAttributes; - private final OID digestEncryptionAlgorithmId; - private final byte[] digestEncryptionAlgorithmParams; - private final byte[] encryptedDigest; - private final byte[] unauthenticatedAttributes; - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - System.err.print("SignerInfo >> "); - System.err.println(msg); - } - - /** - * Parse a SignerInfo object. - */ - public SignerInfo(BERReader ber) throws IOException - { - DERValue val = ber.read(); - if (DEBUG) - debug("SignerInfo: " + val); - if (!val.isConstructed()) - throw new BEREncodingException("malformed SignerInfo"); - - val = ber.read(); - if (val.getTag() != BER.INTEGER) - throw new BEREncodingException("malformed Version"); - version = (BigInteger) val.getValue(); - - if (DEBUG) - debug(" Version: " + version); - - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed IssuerAndSerialNumber"); - - if (DEBUG) - debug(" IssuerAndSerialNumber: " + val); - - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed Issuer"); - issuer = new X500Principal(val.getEncoded()); - ber.skip(val.getLength()); - if (DEBUG) - debug(" Issuer: " + issuer); - - val = ber.read(); - if (val.getTag() != BER.INTEGER) - throw new BEREncodingException("malformed SerialNumber"); - serialNumber = (BigInteger) val.getValue(); - if (DEBUG) - debug(" SerialNumber: " + serialNumber); - - val = ber.read(); - if (!val.isConstructed()) - throw new BEREncodingException("malformed DigestAlgorithmIdentifier"); - if (DEBUG) - debug(" DigestAlgorithmIdentifier: " + val); - - int count = 0; - DERValue val2 = ber.read(); - if (val2.getTag() != BER.OBJECT_IDENTIFIER) - throw new BEREncodingException("malformed AlgorithmIdentifier"); - digestAlgorithmId = (OID) val2.getValue(); - if (DEBUG) - debug(" OID: " + digestAlgorithmId); - - if (BERValue.isIndefinite(val)) - { - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - { - digestAlgorithmParams = val2.getEncoded(); - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - throw new BEREncodingException("expecting BER end-of-sequence"); - } - else - digestAlgorithmParams = null; - } - else if (val2.getEncodedLength() < val.getLength()) - { - val2 = ber.read(); - digestAlgorithmParams = val2.getEncoded(); - if (val2.isConstructed()) - ber.skip(val2.getLength()); - } - else - digestAlgorithmParams = null; - if(DEBUG) - debug(" params: " + (digestAlgorithmParams == null ? null - : new BigInteger(digestAlgorithmParams).toString(16))); - - val = ber.read(); - if (val.getTag() == 0) - { - authenticatedAttributes = val.getEncoded(); - val = ber.read(); - if (val.isConstructed()) - ber.skip(val.getLength()); - if (DEBUG) - debug(" AuthenticatedAttributes: " + val); - val = ber.read(); - } - else - authenticatedAttributes = null; - - if (!val.isConstructed()) - throw new BEREncodingException("malformed DigestEncryptionAlgorithmIdentifier"); - if (DEBUG) - debug(" DigestEncryptionAlgorithmIdentifier: " + val); - count = 0; - val2 = ber.read(); - if (val2.getTag() != BER.OBJECT_IDENTIFIER) - throw new BEREncodingException("malformed AlgorithmIdentifier"); - digestEncryptionAlgorithmId = (OID) val2.getValue(); - if (DEBUG) - debug(" OID: " + digestEncryptionAlgorithmId); - - if (BERValue.isIndefinite(val)) - { - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - { - digestEncryptionAlgorithmParams = val2.getEncoded(); - val2 = ber.read(); - if (val2 != BER.END_OF_SEQUENCE) - throw new BEREncodingException("expecting BER end-of-sequence"); - } - else - digestEncryptionAlgorithmParams = null; - } - else if (val2.getEncodedLength() < val.getLength()) - { - val2 = ber.read(); - digestEncryptionAlgorithmParams = val2.getEncoded(); - if (val2.isConstructed()) - ber.skip(val2.getLength()); - } - else - digestEncryptionAlgorithmParams = null; - if(DEBUG) - debug(" params: " + (digestEncryptionAlgorithmParams == null ? null - : new BigInteger(digestEncryptionAlgorithmParams).toString(16))); - - val = ber.read(); - if (val.getTag() != BER.OCTET_STRING) - throw new BEREncodingException("malformed EncryptedDigest"); - encryptedDigest = (byte[]) val.getValue(); - if (DEBUG) - debug(" EncryptedDigest: " + new BigInteger(1, encryptedDigest).toString(16)); - - if (ber.peek() == 1) - unauthenticatedAttributes = ber.read().getEncoded(); - else - unauthenticatedAttributes = null; - - if (ber.peek() == 0) - ber.read(); - } - - public BigInteger getVersion() - { - return version; - } - - public BigInteger getSerialNumber() - { - return serialNumber; - } - - public X500Principal getIssuer() - { - return issuer; - } - - public OID getDigestAlgorithmId() - { - return digestAlgorithmId; - } - - public byte[] getDigestAlgorithmParams() - { - return (digestAlgorithmParams != null - ? (byte[]) digestAlgorithmParams.clone() - : null); - } - - public byte[] getAuthenticatedAttributes() - { - return (authenticatedAttributes != null - ? (byte[]) authenticatedAttributes.clone() - : null); - } - - public OID getDigestEncryptionAlgorithmId() - { - return digestEncryptionAlgorithmId; - } - - public byte[] getDigestEncryptionAlgorithmParams() - { - return (digestEncryptionAlgorithmParams != null - ? (byte[]) digestEncryptionAlgorithmParams.clone() - : null); - } - - public byte[] getEncryptedDigest() - { - return (encryptedDigest != null ? (byte[]) encryptedDigest.clone() : null); - } - - public byte[] getUnauthenticatedAttributes() - { - return (unauthenticatedAttributes != null - ? (byte[]) unauthenticatedAttributes.clone() - : null); - } -} diff --git a/libjava/gnu/java/security/provider/CollectionCertStoreImpl.java b/libjava/gnu/java/security/provider/CollectionCertStoreImpl.java deleted file mode 100644 index 4bf3d5434ef..00000000000 --- a/libjava/gnu/java/security/provider/CollectionCertStoreImpl.java +++ /dev/null @@ -1,102 +0,0 @@ -/* CollectionCertStore.java -- Collection-based cert store. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.InvalidAlgorithmParameterException; -import java.security.cert.CRL; -import java.security.cert.CRLSelector; -import java.security.cert.CertSelector; -import java.security.cert.CertStoreException; -import java.security.cert.CertStoreParameters; -import java.security.cert.CertStoreSpi; -import java.security.cert.Certificate; -import java.security.cert.CollectionCertStoreParameters; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; - -public final class CollectionCertStoreImpl extends CertStoreSpi -{ - - // Fields. - // ------------------------------------------------------------------------- - - private final Collection store; - - // Constructors. - // ------------------------------------------------------------------------- - - public CollectionCertStoreImpl(CertStoreParameters params) - throws InvalidAlgorithmParameterException - { - super(params); - if (! (params instanceof CollectionCertStoreParameters)) - throw new InvalidAlgorithmParameterException("not a CollectionCertStoreParameters object"); - store = ((CollectionCertStoreParameters) params).getCollection(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public Collection engineGetCertificates(CertSelector selector) - throws CertStoreException - { - LinkedList result = new LinkedList(); - for (Iterator it = store.iterator(); it.hasNext(); ) - { - Object o = it.next(); - if ((o instanceof Certificate) && selector.match((Certificate) o)) - result.add(o); - } - return result; - } - - public Collection engineGetCRLs(CRLSelector selector) - throws CertStoreException - { - LinkedList result = new LinkedList(); - for (Iterator it = store.iterator(); it.hasNext(); ) - { - Object o = it.next(); - if ((o instanceof CRL) && selector.match((CRL) o)) - result.add(o); - } - return result; - } -} diff --git a/libjava/gnu/java/security/provider/DSAKeyFactory.java b/libjava/gnu/java/security/provider/DSAKeyFactory.java deleted file mode 100644 index 7e154e27473..00000000000 --- a/libjava/gnu/java/security/provider/DSAKeyFactory.java +++ /dev/null @@ -1,134 +0,0 @@ -/* DSAKeyFactory.java -- DSA key factory. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.KeyFactorySpi; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.interfaces.DSAPrivateKey; -import java.security.interfaces.DSAPublicKey; -import java.security.spec.DSAPrivateKeySpec; -import java.security.spec.DSAPublicKeySpec; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; - -/** - * DSA key factory. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class DSAKeyFactory extends KeyFactorySpi -{ - - // Constructor. - // ------------------------------------------------------------------------ - - public DSAKeyFactory() - { - super(); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - protected PrivateKey engineGeneratePrivate(KeySpec keySpec) - throws InvalidKeySpecException - { - if (!(keySpec instanceof DSAPrivateKeySpec)) - throw new InvalidKeySpecException(); - return new GnuDSAPrivateKey( - ((DSAPrivateKeySpec) keySpec).getX(), - ((DSAPrivateKeySpec) keySpec).getP(), - ((DSAPrivateKeySpec) keySpec).getQ(), - ((DSAPrivateKeySpec) keySpec).getG()); - } - - protected PublicKey engineGeneratePublic(KeySpec keySpec) - throws InvalidKeySpecException - { - if (!(keySpec instanceof DSAPublicKeySpec)) - throw new InvalidKeySpecException(); - return new GnuDSAPublicKey( - ((DSAPublicKeySpec) keySpec).getY(), - ((DSAPublicKeySpec) keySpec).getP(), - ((DSAPublicKeySpec) keySpec).getQ(), - ((DSAPublicKeySpec) keySpec).getG()); - } - - protected KeySpec engineGetKeySpec(Key key, Class keySpec) - throws InvalidKeySpecException - { - if ((key instanceof DSAPublicKey) && - keySpec.isAssignableFrom(DSAPublicKeySpec.class)) - { - return new DSAPublicKeySpec(((DSAPublicKey) key).getY(), - ((DSAPublicKey) key).getParams().getP(), - ((DSAPublicKey) key).getParams().getQ(), - ((DSAPublicKey) key).getParams().getG()); - } - if ((key instanceof DSAPrivateKey) && - keySpec.isAssignableFrom(DSAPrivateKeySpec.class)) - { - return new DSAPrivateKeySpec(((DSAPrivateKey) key).getX(), - ((DSAPrivateKey) key).getParams().getP(), - ((DSAPrivateKey) key).getParams().getQ(), - ((DSAPrivateKey) key).getParams().getG()); - } - throw new InvalidKeySpecException(); - } - - protected Key engineTranslateKey(Key key) throws InvalidKeyException - { - if ((key instanceof GnuDSAPublicKey) || (key instanceof GnuDSAPrivateKey)) - return key; - if (key instanceof DSAPublicKey) - return new GnuDSAPublicKey(((DSAPublicKey) key).getY(), - ((DSAPublicKey) key).getParams().getP(), - ((DSAPublicKey) key).getParams().getQ(), - ((DSAPublicKey) key).getParams().getG()); - if (key instanceof DSAPrivateKey) - return new GnuDSAPrivateKey(((DSAPrivateKey) key).getX(), - ((DSAPrivateKey) key).getParams().getP(), - ((DSAPrivateKey) key).getParams().getQ(), - ((DSAPrivateKey) key).getParams().getG()); - throw new InvalidKeyException(); - } -} diff --git a/libjava/gnu/java/security/provider/DSAKeyPairGenerator.java b/libjava/gnu/java/security/provider/DSAKeyPairGenerator.java deleted file mode 100644 index 2c643d5c367..00000000000 --- a/libjava/gnu/java/security/provider/DSAKeyPairGenerator.java +++ /dev/null @@ -1,171 +0,0 @@ -/* GnuDSAKeyPairGenerator.java --- Gnu DSA Key Pair Generator - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.math.BigInteger; -import java.security.AlgorithmParameterGenerator; -import java.security.AlgorithmParameters; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidParameterException; -import java.security.KeyPair; -import java.security.KeyPairGeneratorSpi; -import java.security.SecureRandom; -import java.security.interfaces.DSAParams; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.DSAParameterSpec; -import java.util.Random; - -public class DSAKeyPairGenerator extends KeyPairGeneratorSpi - implements java.security.interfaces.DSAKeyPairGenerator -{ -int keysize; -SecureRandom random; -private BigInteger q = null; // the small prime -private BigInteger p = null; // the big prime -private BigInteger g = null; - -DSAKeyPairGenerator() -{ - keysize = 1024; -} - -public void initialize(int keysize, SecureRandom random) -{ - //if( ((keysize % 64) != 0) || (keysize < 512) || (keysize > 1024) ) - // throw new InvalidAlgorithmParameterException("Invalid key size"); - - this.keysize = keysize; - this.random = random; -} - -public void initialize(AlgorithmParameterSpec params, - SecureRandom random) - throws InvalidAlgorithmParameterException -{ - if( !( params instanceof DSAParameterSpec ) ) - throw new InvalidAlgorithmParameterException("Must be DSAParameterSpec"); - - DSAParameterSpec dsaparameterspec = (DSAParameterSpec)params; - p = dsaparameterspec.getP(); - q = dsaparameterspec.getQ(); - g = dsaparameterspec.getG(); - this.random = random; -} - -public void initialize(DSAParams params, SecureRandom random) - throws InvalidParameterException -{ - if(params.getP() != null) - p = params.getP(); - else - throw new InvalidParameterException(); - - if(params.getQ() != null) - q = params.getQ(); - else - throw new InvalidParameterException(); - - if(params.getG() != null) - g = params.getG(); - else - throw new InvalidParameterException(); - - this.random = random; -} - -public void initialize(int modlen, boolean genParams, SecureRandom random) - throws InvalidParameterException -{ - if( ((modlen % 64) != 0) || (modlen < 512) || (modlen > 1024) ) - throw new InvalidParameterException(); - - if( (genParams == false) && (modlen != 512) && (modlen != 768) && (modlen != 1024) ) - throw new InvalidParameterException(); - this.keysize = modlen; - this.random = random; - p = null; - q = null; - g = null; -} - -public KeyPair generateKeyPair() -{ - if( getDefaults() == false) { - try { - AlgorithmParameterGenerator apgDSA = AlgorithmParameterGenerator.getInstance("DSA"); - AlgorithmParameters apDSA = apgDSA.generateParameters(); - DSAParameterSpec dsaparameterspec = (DSAParameterSpec)apDSA.getParameterSpec( DSAParameterSpec.class ); - p = dsaparameterspec.getP(); - q = dsaparameterspec.getQ(); - g = dsaparameterspec.getG(); - } catch ( Exception e ) { - return null; - } - } - - BigInteger x = new BigInteger( 159, new Random() ); - - BigInteger y = g.modPow( x, p ); - - return new KeyPair( new GnuDSAPublicKey(y,p,q,g), new GnuDSAPrivateKey(x,p,q,g)); - //return new KeyPair( public, private ); -} - -//These constants are Sun's Constants copied from the -//Cryptography Specification -private boolean getDefaults() -{ - if( keysize == 512) { - p = new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17", 16); - q = new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16); - g = new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4", 16); - return true; - } else if( keysize == 768) { - p = new BigInteger("e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5d890141922d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a22219d470bce7d777d4a21fbe9c270b57f607002f3cef8393694cf45ee3688c11a8c56ab127a3daf", 16); - q = new BigInteger("9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511", 16); - g = new BigInteger("30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7a31d23c4dbbcbe06174544401a5b2c020965d8c2bd2171d3668445771f74ba084d2029d83c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a7064f316933a346d3f529252", 16); - } else if( keysize == 512) { - p = new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", 16); - q = new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5", 16); - g = new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", 16); - } - return false; -} - -} diff --git a/libjava/gnu/java/security/provider/DSAParameterGenerator.java b/libjava/gnu/java/security/provider/DSAParameterGenerator.java deleted file mode 100644 index ccec1136cd3..00000000000 --- a/libjava/gnu/java/security/provider/DSAParameterGenerator.java +++ /dev/null @@ -1,128 +0,0 @@ -/* DSAParameterGenerator.java --- DSA Parameter Generator Implementation - Copyright (C) 1999 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.util.Prime; - -import java.math.BigInteger; -import java.security.AlgorithmParameterGeneratorSpi; -import java.security.AlgorithmParameters; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.DSAParameterSpec; -import java.security.spec.InvalidParameterSpecException; -import java.util.Random; - -public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi -{ - private int size; - private SecureRandom random = null; - - public DSAParameterGenerator() - { - size = 1024; - } - - public void engineInit(int size, SecureRandom random) - { - if( (size < 512) || (size > 1024) || ( (size % 64) != 0) ) - //throw new InvalidAlgorithmParameterException("Invalid Size"); - return; - this.size = size; - this.random = random; - } - - public void engineInit(AlgorithmParameterSpec genParamSpec, SecureRandom random) - throws InvalidAlgorithmParameterException - { - if( !( genParamSpec instanceof DSAParameterSpec ) ) - throw new InvalidAlgorithmParameterException("Must be DSAParameterSpec"); - - DSAParameterSpec dsaparameterspec = (DSAParameterSpec)genParamSpec; - int tmp = dsaparameterspec.getP().bitLength(); - - if( (tmp < 512) || (tmp > 1024) || ( (tmp % 64) != 0) ) - throw new InvalidAlgorithmParameterException("Invalid Size"); - - this.random = random; - } - - //For more information see IEEE P1363 A.16.1 (10/05/98 Draft) - public AlgorithmParameters engineGenerateParameters() - { - DSAParameterSpec dsaparameterspec; - - int L = size; - BigInteger r, p, k, h, g; - - //q 2^159 < q < 2^160 - r = Prime.generateRandomPrime( 159, 160, BigInteger.valueOf(1)); - - // 2^(L-1) < p < 2^L - p = Prime.generateRandomPrime( r, BigInteger.valueOf(1), L - 1, L, BigInteger.valueOf(1)); - - k = p.subtract( BigInteger.valueOf(1) ); - k = k.divide( r ); - - Random rand = new Random(); - h = BigInteger.valueOf(1); - - for(;;) { - h = h.add(BigInteger.valueOf( 1 ) ); - - g = h.modPow(k, p); - - if( g.compareTo( BigInteger.valueOf(1) ) != 1 ) - break; - } - - try { - dsaparameterspec = new DSAParameterSpec(p, r, g); - AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA"); - ap.init( dsaparameterspec ); - return ap; - } catch ( NoSuchAlgorithmException nsae ) { - return null; - } catch ( InvalidParameterSpecException ipse) { - return null; - } - } -} diff --git a/libjava/gnu/java/security/provider/DSAParameters.java b/libjava/gnu/java/security/provider/DSAParameters.java deleted file mode 100644 index 77d648956ee..00000000000 --- a/libjava/gnu/java/security/provider/DSAParameters.java +++ /dev/null @@ -1,150 +0,0 @@ -/* DSAParameters.java --- DSA Parameters Implementation - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.io.ASN1ParsingException; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.der.DERWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.AlgorithmParametersSpi; -import java.security.spec.AlgorithmParameterSpec; -import java.security.spec.DSAParameterSpec; -import java.security.spec.InvalidParameterSpecException; -import java.util.ArrayList; - -/* - ASN.1 Encoding for DSA from rfc2459 - - id-dsa ID ::= { iso(1) member-body(2) us(840) x9-57(10040) - x9cm(4) 1 } - - Dss-Parms ::= SEQUENCE { - p INTEGER, - q INTEGER, - g INTEGER } - -*/ -public class DSAParameters extends AlgorithmParametersSpi -{ -private BigInteger q; // the small prime -private BigInteger p; // the big prime -private BigInteger g; - - -public void engineInit(AlgorithmParameterSpec paramSpec) - throws InvalidParameterSpecException -{ - if( paramSpec instanceof DSAParameterSpec ) { - DSAParameterSpec dsaParamSpec = (DSAParameterSpec)paramSpec; - p = dsaParamSpec.getP(); - q = dsaParamSpec.getQ(); - g = dsaParamSpec.getG(); - } - else - throw new InvalidParameterSpecException("Only accepts DSAParameterSpec"); -} - -public void engineInit(byte[] params) - throws IOException -{ - DERReader in = new DERReader(params); - DERValue val = in.read(); - if (val.getValue() != DER.CONSTRUCTED_VALUE) - throw new ASN1ParsingException("badly formed parameters"); - try - { - p = (BigInteger) in.read().getValue(); - q = (BigInteger) in.read().getValue(); - g = (BigInteger) in.read().getValue(); - } - catch (Exception x) - { - throw new ASN1ParsingException("badly formed parameters"); - } -} - -public void engineInit(byte[] params, String format) - throws IOException -{ - if( !format.equals("ASN.1") ) - throw new IOException("Invalid Format: Only accepts ASN.1"); - engineInit( params ); -} - -public AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) - throws InvalidParameterSpecException -{ - if( paramSpec.isAssignableFrom(DSAParameterSpec.class) ) - return new DSAParameterSpec(p, q, g); - else - throw new InvalidParameterSpecException("Only accepts DSAParameterSpec"); -} - -public byte[] engineGetEncoded() - throws IOException -{ - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - ArrayList seq = new ArrayList(3); - seq.add(new DERValue(DER.INTEGER, p)); - seq.add(new DERValue(DER.INTEGER, q)); - seq.add(new DERValue(DER.INTEGER, g)); - DERWriter.write(bout, new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, seq)); - return bout.toByteArray(); -} - - -public byte[] engineGetEncoded(String format) - throws IOException -{ - if( !format.equals("ASN.1") ) - throw new IOException("Invalid Format: Only accepts ASN.1"); - return engineGetEncoded(); -} - -public String engineToString() -{ - return ("q: " + q + " p: " + p + " g: " + g); -} - -} diff --git a/libjava/gnu/java/security/provider/DSASignature.java b/libjava/gnu/java/security/provider/DSASignature.java deleted file mode 100644 index 1d3875d28e3..00000000000 --- a/libjava/gnu/java/security/provider/DSASignature.java +++ /dev/null @@ -1,251 +0,0 @@ -/* DSASignature.java -- - Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.der.DERWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.InvalidParameterException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.SecureRandom; -import java.security.SignatureException; -import java.security.SignatureSpi; -import java.security.interfaces.DSAPrivateKey; -import java.security.interfaces.DSAPublicKey; -import java.security.spec.AlgorithmParameterSpec; -import java.util.ArrayList; -import java.util.Random; - -public class DSASignature extends SignatureSpi -{ - private DSAPublicKey publicKey; - private DSAPrivateKey privateKey; - private final MessageDigest digest; - private final SecureRandom random; - - public DSASignature() throws NoSuchAlgorithmException - { - random = new SecureRandom(); - digest = MessageDigest.getInstance ("SHA1"); - } - - private void init() - { - digest.reset(); - } - - public void engineInitVerify (PublicKey publicKey) - throws InvalidKeyException - { - if (publicKey instanceof DSAPublicKey) - this.publicKey = (DSAPublicKey) publicKey; - else - throw new InvalidKeyException(); - init(); - } - - public void engineInitSign (PrivateKey privateKey) - throws InvalidKeyException - { - if (privateKey instanceof DSAPrivateKey) - this.privateKey = (DSAPrivateKey) privateKey; - else - throw new InvalidKeyException ("not a DSA private key"); - - init(); - } - - public void engineInitSign (PrivateKey privateKey, - SecureRandom random) - throws InvalidKeyException - { - if (privateKey instanceof DSAPrivateKey) - this.privateKey = (DSAPrivateKey) privateKey; - else - throw new InvalidKeyException ("not a DSA private key"); - - appRandom = random; - init(); - } - - public void engineUpdate(byte b) - throws SignatureException - { - digest.update (b); - } - - public void engineUpdate (byte[] b, int off, int len) - throws SignatureException - { - digest.update (b, off, len); - } - - public byte[] engineSign() throws SignatureException - { - if (privateKey == null) - throw new SignatureException ("not initialized for signing"); - - try - { - BigInteger g = privateKey.getParams().getG(); - BigInteger p = privateKey.getParams().getP(); - BigInteger q = privateKey.getParams().getQ(); - - BigInteger x = privateKey.getX(); - - BigInteger k = new BigInteger (159, appRandom != null ? appRandom : random); - - BigInteger r = g.modPow(k, p); - r = r.mod(q); - - byte bytes[] = digest.digest(); - BigInteger sha = new BigInteger (1, bytes); - - BigInteger s = sha.add (x.multiply (r)); - s = s.multiply (k.modInverse(q)).mod (q); - - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - ArrayList seq = new ArrayList (2); - seq.add(0, new DERValue (DER.INTEGER, r)); - seq.add(1, new DERValue (DER.INTEGER, s)); - DERWriter.write (bout, new DERValue (DER.CONSTRUCTED | DER.SEQUENCE, seq)); - return bout.toByteArray(); - } - catch (IOException ioe) - { - SignatureException se = new SignatureException(); - se.initCause (ioe); - throw se; - } - catch (ArithmeticException ae) - { - SignatureException se = new SignatureException(); - se.initCause (ae); - throw se; - } - } - - public int engineSign (byte[] outbuf, int offset, int len) - throws SignatureException - { - byte tmp[] = engineSign(); - if (tmp.length > len) - throw new SignatureException ("output buffer too short"); - System.arraycopy (tmp, 0, outbuf, offset, tmp.length); - return tmp.length; - } - - public boolean engineVerify (byte[] sigBytes) - throws SignatureException - { - // Decode sigBytes from ASN.1 DER encoding - try - { - DERReader in = new DERReader (sigBytes); - DERValue val = in.read(); - if (!val.isConstructed()) - throw new SignatureException ("badly formed signature"); - BigInteger r = (BigInteger) in.read().getValue(); - BigInteger s = (BigInteger) in.read().getValue(); - - BigInteger g = publicKey.getParams().getG(); - BigInteger p = publicKey.getParams().getP(); - BigInteger q = publicKey.getParams().getQ(); - - BigInteger y = publicKey.getY(); - - BigInteger w = s.modInverse (q); - - byte bytes[] = digest.digest(); - BigInteger sha = new BigInteger (1, bytes); - - BigInteger u1 = w.multiply (sha).mod ( q ); - - BigInteger u2 = r.multiply (w).mod(q); - - BigInteger v = g.modPow (u1, p).multiply (y.modPow (u2, p)).mod (p).mod (q); - - if (v.equals (r)) - return true; - else - return false; - } - catch (IOException ioe) - { - SignatureException se = new SignatureException ("badly formed signature"); - se.initCause (ioe); - throw se; - } - } - - public void engineSetParameter (String param, - Object value) - throws InvalidParameterException - { - throw new InvalidParameterException(); - } - - public void engineSetParameter (AlgorithmParameterSpec params) - throws InvalidAlgorithmParameterException - { - throw new InvalidParameterException(); - - } - - public Object engineGetParameter (String param) - throws InvalidParameterException - { - throw new InvalidParameterException(); - } - - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } -} diff --git a/libjava/gnu/java/security/provider/DefaultPolicy.java b/libjava/gnu/java/security/provider/DefaultPolicy.java deleted file mode 100644 index d42be6c908f..00000000000 --- a/libjava/gnu/java/security/provider/DefaultPolicy.java +++ /dev/null @@ -1,68 +0,0 @@ -/* DefaultPolicy.java -- - Copyright (C) 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.security.provider; - -import java.security.AllPermission; -import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.Policy; - -/** - * This is just a stub policy implementation which grants all permissions - * to any code source. FIXME: This should be replaced with a real - * implementation that reads the policy configuration from a file, like - * $JAVA_HOME/jre/lib/security/java.security. - */ -public class DefaultPolicy extends Policy -{ - static Permission allPermission = new AllPermission(); - - public PermissionCollection getPermissions(CodeSource codesource) - { - Permissions perms = new Permissions(); - perms.add(allPermission); - return perms; - } - - public void refresh() - { - // Nothing. - } -} diff --git a/libjava/gnu/java/security/provider/EncodedKeyFactory.java b/libjava/gnu/java/security/provider/EncodedKeyFactory.java deleted file mode 100644 index 2bf0fff809e..00000000000 --- a/libjava/gnu/java/security/provider/EncodedKeyFactory.java +++ /dev/null @@ -1,303 +0,0 @@ -/* EncodedKeyFactory.java -- encoded key factory. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.AlgorithmParameters; -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.KeyFactorySpi; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.spec.DSAParameterSpec; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.InvalidParameterSpecException; -import java.security.spec.KeySpec; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.RSAPrivateCrtKeySpec; -import java.security.spec.RSAPublicKeySpec; -import java.security.spec.X509EncodedKeySpec; - -import javax.crypto.spec.DHParameterSpec; - -/** - * A factory for keys encoded in either the X.509 format (for public - * keys) or the PKCS#8 format (for private keys). - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class EncodedKeyFactory extends KeyFactorySpi -{ - - // Constants. - // ------------------------------------------------------------------------ - - private static final OID ID_DSA = new OID("1.2.840.10040.4.1"); - private static final OID ID_RSA = new OID("1.2.840.113549.1.1.1"); - private static final OID ID_DH = new OID("1.2.840.10046.2.1"); - - // Instance methods. - // ------------------------------------------------------------------------ - - public PublicKey engineGeneratePublic(KeySpec spec) - throws InvalidKeySpecException - { - if (!(spec instanceof X509EncodedKeySpec)) - throw new InvalidKeySpecException("only supports X.509 key specs"); - DERReader der = new DERReader(((X509EncodedKeySpec) spec).getEncoded()); - try - { - DERValue spki = der.read(); - if (!spki.isConstructed()) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - DERValue alg = der.read(); - if (!alg.isConstructed()) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - DERValue val = der.read(); - if (!(val.getValue() instanceof OID)) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - OID algId = (OID) val.getValue(); - byte[] algParams = null; - if (alg.getLength() > val.getEncodedLength()) - { - val = der.read(); - algParams = val.getEncoded(); - if (val.isConstructed()) - der.skip(val.getLength()); - } - val = der.read(); - if (!(val.getValue() instanceof BitString)) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - byte[] publicKey = ((BitString) val.getValue()).toByteArray(); - if (algId.equals(ID_DSA)) - { - BigInteger p = null, g = null, q = null, Y; - if (algParams != null) - { - DERReader dsaParams = new DERReader(algParams); - val = dsaParams.read(); - if (!val.isConstructed()) - throw new InvalidKeySpecException("malformed DSA parameters"); - val = dsaParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DSA parameters"); - p = (BigInteger) val.getValue(); - val = dsaParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DSA parameters"); - q = (BigInteger) val.getValue(); - val = dsaParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DSA parameters"); - g = (BigInteger) val.getValue(); - } - DERReader dsaPub = new DERReader(publicKey); - val = dsaPub.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DSA parameters"); - Y = (BigInteger) val.getValue(); - return new GnuDSAPublicKey(Y, p, q, g); - } - else if (algId.equals(ID_RSA)) - { - DERReader rsaParams = new DERReader(publicKey); - if (!rsaParams.read().isConstructed()) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - return new GnuRSAPublicKey(new RSAPublicKeySpec( - (BigInteger) rsaParams.read().getValue(), - (BigInteger) rsaParams.read().getValue())); - } - else if (algId.equals(ID_DH)) - { - if (algParams == null) - throw new InvalidKeySpecException("missing DH parameters"); - DERReader dhParams = new DERReader(algParams); - val = dhParams.read(); - BigInteger p, g, q, Y; - if (!val.isConstructed()) - throw new InvalidKeySpecException("malformed DH parameters"); - val = dhParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DH parameters"); - p = (BigInteger) val.getValue(); - val = dhParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DH parameters"); - g = (BigInteger) val.getValue(); - val = dhParams.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DH parameters"); - q = (BigInteger) val.getValue(); - DERReader dhPub = new DERReader(publicKey); - val = dhPub.read(); - if (!(val.getValue() instanceof BigInteger)) - throw new InvalidKeySpecException("malformed DH parameters"); - Y = (BigInteger) val.getValue(); - return (PublicKey) new GnuDHPublicKey(new DHParameterSpec(p, g), Y, q); - } - else - throw new InvalidKeySpecException("unknown algorithm: " + algId); - } - catch (IOException ioe) - { - throw new InvalidKeySpecException(ioe.getMessage()); - } - } - - public PrivateKey engineGeneratePrivate(KeySpec spec) - throws InvalidKeySpecException - { - if (!(spec instanceof PKCS8EncodedKeySpec)) - { - throw new InvalidKeySpecException("only supports PKCS8 key specs"); - } - DERReader der = new DERReader(((PKCS8EncodedKeySpec) spec).getEncoded()); - try - { - DERValue pki = der.read(); - if (!pki.isConstructed()) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - DERValue val = der.read(); - if (!(val.getValue() instanceof BigInteger)) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - DERValue alg = der.read(); - if (!alg.isConstructed()) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - val = der.read(); - if (!(val.getValue() instanceof OID)) - { - throw new InvalidKeySpecException("malformed encoded key"); - } - OID algId = (OID) val.getValue(); - byte[] algParams = null; - if (alg.getLength() > val.getEncodedLength()) - { - val = der.read(); - algParams = val.getEncoded(); - if (val.isConstructed()) - der.skip(val.getLength()); - } - byte[] privateKey = (byte[]) der.read().getValue(); - if (algId.equals(ID_DSA)) - { - if (algParams == null) - { - throw new InvalidKeySpecException("missing DSA parameters"); - } - AlgorithmParameters params = AlgorithmParameters.getInstance("DSA"); - params.init(algParams); - DSAParameterSpec dsaSpec = (DSAParameterSpec) - params.getParameterSpec(DSAParameterSpec.class); - DERReader dsaPriv = new DERReader(privateKey); - return new GnuDSAPrivateKey((BigInteger) dsaPriv.read().getValue(), - dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG()); - } - else if (algId.equals(ID_RSA)) - { - DERReader rsaParams = new DERReader(privateKey); - if (!rsaParams.read().isConstructed()) - throw new InvalidKeySpecException("malformed encoded key"); - return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec( - (BigInteger) rsaParams.read().getValue(), // n - (BigInteger) rsaParams.read().getValue(), // e - (BigInteger) rsaParams.read().getValue(), // d - (BigInteger) rsaParams.read().getValue(), // p - (BigInteger) rsaParams.read().getValue(), // q - (BigInteger) rsaParams.read().getValue(), // d mod (p - 1) - (BigInteger) rsaParams.read().getValue(), // d mod (q - 1) - (BigInteger) rsaParams.read().getValue())); // (inv q) mod p - } - else - throw new InvalidKeySpecException("unknown algorithm: " + algId); - } - catch (InvalidParameterSpecException iapse) - { - throw new InvalidKeySpecException(iapse.getMessage()); - } - catch (NoSuchAlgorithmException nsae) - { - throw new InvalidKeySpecException(nsae.getMessage()); - } - catch (IOException ioe) - { - throw new InvalidKeySpecException(ioe.getMessage()); - } - } - - public KeySpec engineGetKeySpec(Key key, Class speClass) - throws InvalidKeySpecException - { - if ((key instanceof PrivateKey) && key.getFormat().equals("PKCS#8") - && speClass.isAssignableFrom(PKCS8EncodedKeySpec.class)) - return new PKCS8EncodedKeySpec(key.getEncoded()); - else if ((key instanceof PublicKey) && key.getFormat().equals("X.509") - && speClass.isAssignableFrom(X509EncodedKeySpec.class)) - return new X509EncodedKeySpec(key.getEncoded()); - else - throw new InvalidKeySpecException(); - } - - public Key engineTranslateKey(Key key) throws InvalidKeyException - { - throw new InvalidKeyException("translating keys not supported"); - } -} diff --git a/libjava/gnu/java/security/provider/Gnu.java b/libjava/gnu/java/security/provider/Gnu.java deleted file mode 100644 index 849f63c1601..00000000000 --- a/libjava/gnu/java/security/provider/Gnu.java +++ /dev/null @@ -1,168 +0,0 @@ -/* Gnu.java --- Gnu provider main class - Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.Provider; - -public final class Gnu extends Provider -{ - public Gnu() - { - super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores"); - - AccessController.doPrivileged (new PrivilegedAction() - { - public Object run() - { - // Note that all implementation class names are referenced by using - // Class.getName(). That way when we staticly link the Gnu provider - // we automatically get all the implementation classes. - - // Signature - put("Signature.SHA1withDSA", - gnu.java.security.provider.DSASignature.class.getName()); - - put("Alg.Alias.Signature.DSS", "SHA1withDSA"); - put("Alg.Alias.Signature.DSA", "SHA1withDSA"); - put("Alg.Alias.Signature.SHAwithDSA", "SHA1withDSA"); - put("Alg.Alias.Signature.DSAwithSHA", "SHA1withDSA"); - put("Alg.Alias.Signature.DSAwithSHA1", "SHA1withDSA"); - put("Alg.Alias.Signature.SHA/DSA", "SHA1withDSA"); - put("Alg.Alias.Signature.SHA-1/DSA", "SHA1withDSA"); - put("Alg.Alias.Signature.SHA1/DSA", "SHA1withDSA"); - put("Alg.Alias.Signature.OID.1.2.840.10040.4.3", "SHA1withDSA"); - put("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA1withDSA"); - put("Alg.Alias.Signature.1.3.14.3.2.13", "SHA1withDSA"); - put("Alg.Alias.Signature.1.3.14.3.2.27", "SHA1withDSA"); - - put("Signature.MD2withRSA", MD2withRSA.class.getName()); - put("Signature.MD2withRSA ImplementedIn", "Software"); - put("Alg.Alias.Signature.md2WithRSAEncryption", "MD2withRSA"); - put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.2", "MD2withRSA"); - put("Alg.Alias.Signature.1.2.840.113549.1.1.2", "MD2withRSA"); - - put("Signature.MD4withRSA", MD4withRSA.class.getName()); - put("Signature.MD4withRSA ImplementedIn", "Software"); - put("Alg.Alias.Signature.md4WithRSAEncryption", "MD4withRSA"); - put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.3", "MD4withRSA"); - put("Alg.Alias.Signature.1.2.840.113549.1.1.3", "MD4withRSA"); - - put("Signature.MD5withRSA", MD5withRSA.class.getName()); - put("Signature.MD5withRSA ImplementedIn", "Software"); - put("Alg.Alias.Signature.md5WithRSAEncryption", "MD5withRSA"); - put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.4", "MD5withRSA"); - put("Alg.Alias.Signature.1.2.840.113549.1.1.4", "MD5withRSA"); - - put("Signature.SHA1withRSA", SHA1withRSA.class.getName()); - put("Signature.SHA1withRSA ImplementedIn", "Software"); - put("Alg.Alias.Signature.sha-1WithRSAEncryption", "SHA1withRSA"); - put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA"); - put("Alg.Alias.Signature.1.2.840.113549.1.1.5", "SHA1withRSA"); - - // Key Pair Generator - put("KeyPairGenerator.DSA", - gnu.java.security.provider.DSAKeyPairGenerator.class.getName()); - - put("Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1", "DSA"); - put("Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1", "DSA"); - put("Alg.Alias.KeyPairGenerator.1.3.14.3.2.12", "DSA"); - - // Key Factory - put("KeyFactory.DSA", - gnu.java.security.provider.DSAKeyFactory.class.getName()); - - put("KeyFactory.Encoded", EncodedKeyFactory.class.getName()); - put("KeyFactory.Encoded ImplementedIn", "Software"); - put("Alg.Alias.KeyFactory.X.509", "Encoded"); - put("Alg.Alias.KeyFactory.X509", "Encoded"); - put("Alg.Alias.KeyFactory.PKCS#8", "Encoded"); - put("Alg.Alias.KeyFactory.PKCS8", "Encoded"); - - put("KeyFactory.RSA", RSAKeyFactory.class.getName()); - - put("Alg.Alias.KeyFactory.OID.1.2.840.10040.4.1", "DSA"); - put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA"); - put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA"); - - // Message Digests - put("MessageDigest.SHA", gnu.java.security.provider.SHA.class.getName()); - put("MessageDigest.MD5", gnu.java.security.provider.MD5.class.getName()); - - // Format "Alias", "Actual Name" - put("Alg.Alias.MessageDigest.SHA1", "SHA"); - put("Alg.Alias.MessageDigest.SHA-1", "SHA"); - put("Alg.Alias.MessageDigest.SHA-160", "SHA"); - - // Algorithm Parameters - put("AlgorithmParameters.DSA", - gnu.java.security.provider.DSAParameters.class.getName()); - - put("Alg.Alias.AlgorithmParameters.DSS", "DSA"); - put("Alg.Alias.AlgorithmParameters.SHAwithDSA", "DSA"); - put("Alg.Alias.AlgorithmParameters.OID.1.2.840.10040.4.3", "DSA"); - put("Alg.Alias.AlgorithmParameters.1.2.840.10040.4.3", "DSA"); - - // Algorithm Parameter Generator - put("AlgorithmParameterGenerator.DSA", - gnu.java.security.provider.DSAParameterGenerator.class.getName()); - - // SecureRandom - put("SecureRandom.SHA1PRNG", - gnu.java.security.provider.SHA1PRNG.class.getName()); - - // CertificateFactory - put("CertificateFactory.X509", X509CertificateFactory.class.getName()); - - put("CertificateFactory.X509 ImplementedIn", "Software"); - put("Alg.Alias.CertificateFactory.X.509", "X509"); - - // CertPathValidator - put("CertPathValidator.PKIX", PKIXCertPathValidatorImpl.class.getName()); - put("CertPathValidator.PKIX ImplementedIn", "Software"); - - // CertStore - put("CertStore.Collection", CollectionCertStoreImpl.class.getName()); - - return null; - } - }); - } -} diff --git a/libjava/gnu/java/security/provider/GnuDHPublicKey.java b/libjava/gnu/java/security/provider/GnuDHPublicKey.java deleted file mode 100644 index 6e13f6bf20f..00000000000 --- a/libjava/gnu/java/security/provider/GnuDHPublicKey.java +++ /dev/null @@ -1,115 +0,0 @@ -/* GnuDHPublicKey.java -- A Diffie-Hellman public key. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERValue; - -import java.math.BigInteger; -import java.util.ArrayList; - -import javax.crypto.interfaces.DHPublicKey; -import javax.crypto.spec.DHParameterSpec; - -public class GnuDHPublicKey implements DHPublicKey -{ - - // Fields. - // ------------------------------------------------------------------------- - - private byte[] encoded; - private final DHParameterSpec params; - private final BigInteger Y; - private final BigInteger q; - - // Constructor. - // ------------------------------------------------------------------------- - - public GnuDHPublicKey(DHParameterSpec params, BigInteger Y, BigInteger q) - { - this.params = params; - this.Y = Y; - this.q = q; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public BigInteger getY() - { - return Y; - } - - public DHParameterSpec getParams() - { - return params; - } - - public String getAlgorithm() - { - return "DH"; - } - - public String getFormat() - { - return "X.509"; - } - - public byte[] getEncoded() - { - if (encoded != null) - return (byte[]) encoded.clone(); - ArrayList spki = new ArrayList(2); - ArrayList alg = new ArrayList(2); - alg.add(new DERValue(DER.OBJECT_IDENTIFIER, new OID("1.2.840.10046.2.1"))); - ArrayList param = new ArrayList(3); - param.add(new DERValue(DER.INTEGER, params.getP())); - param.add(new DERValue(DER.INTEGER, params.getG())); - param.add(new DERValue(DER.INTEGER, q)); - alg.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, param)); - spki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg)); - spki.add(new DERValue(DER.BIT_STRING, new BitString(Y.toByteArray()))); - encoded = new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, spki).getEncoded(); - if (encoded != null) - return (byte[]) encoded.clone(); - return null; - } -} diff --git a/libjava/gnu/java/security/provider/GnuDSAPrivateKey.java b/libjava/gnu/java/security/provider/GnuDSAPrivateKey.java deleted file mode 100644 index aac2faab229..00000000000 --- a/libjava/gnu/java/security/provider/GnuDSAPrivateKey.java +++ /dev/null @@ -1,147 +0,0 @@ -/* GnuDSAPrivateKey.java --- Gnu DSA Private Key - Copyright (C) 1999,2003,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERValue; -import gnu.java.security.der.DERWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.interfaces.DSAParams; -import java.security.interfaces.DSAPrivateKey; -import java.security.spec.DSAParameterSpec; -import java.util.ArrayList; - -public class GnuDSAPrivateKey implements DSAPrivateKey -{ - private byte[] encodedKey; - BigInteger x; - BigInteger p; - BigInteger q; - BigInteger g; - - public GnuDSAPrivateKey(BigInteger x, BigInteger p, BigInteger q, BigInteger g ) - { - this.x = x; - this.p = p; - this.q = q; - this.g = g; - } - - public String getAlgorithm() - { - return "DSA"; - } - - public String getFormat() - { - return "PKCS#8"; - } - - /** - * Encodes this key as a <code>PrivateKeyInfo</code>, as described in - * PKCS #8. The ASN.1 specification for this structure is: - * - * <blockquote><pre> - * PrivateKeyInfo ::= SEQUENCE { - * version Version, - * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, - * privateKey PrivateKey, - * attributes [0] IMPLICIT Attributes OPTIONAL } - * - * Version ::= INTEGER - * - * PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier - * - * PrivateKey ::= OCTET STRING - * - * Attributes ::= SET OF Attribute - * </pre></blockquote> - * - * <p>DSA private keys (in Classpath at least) have no attributes. - */ - public byte[] getEncoded() - { - if (encodedKey != null) - return (byte[]) encodedKey.clone(); - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrayList pki = new ArrayList(3); - pki.add(new DERValue(DER.INTEGER, BigInteger.ZERO)); - ArrayList algId = new ArrayList(2); - algId.add(new DERValue(DER.OBJECT_IDENTIFIER, - new OID("1.2.840.10040.4.1"))); - ArrayList algParams = new ArrayList(3); - algParams.add(new DERValue(DER.INTEGER, p)); - algParams.add(new DERValue(DER.INTEGER, q)); - algParams.add(new DERValue(DER.INTEGER, g)); - algId.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, algParams)); - pki.add(new DERValue(DER.OCTET_STRING, x.toByteArray())); - DERWriter.write(out, new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, pki)); - return (byte[]) (encodedKey = out.toByteArray()).clone(); - } - catch (IOException ioe) - { - return null; - } - } - - public DSAParams getParams() - { - return (DSAParams)(new DSAParameterSpec(p,q,g)); - } - - public BigInteger getX() - { - return x; - } - - public String toString() - { - return "GnuDSAPrivateKey: x=" - + (x != null ? x.toString(16) : "null") + " p=" - + (p != null ? p.toString(16) : "null") + " q=" - + (q != null ? q.toString(16) : "null") + " g=" - + (g != null ? g.toString(16) : "null"); - } -} diff --git a/libjava/gnu/java/security/provider/GnuDSAPublicKey.java b/libjava/gnu/java/security/provider/GnuDSAPublicKey.java deleted file mode 100644 index 41195fa992c..00000000000 --- a/libjava/gnu/java/security/provider/GnuDSAPublicKey.java +++ /dev/null @@ -1,137 +0,0 @@ -/* GnuDSAPublicKey.java --- Gnu DSA Public Key - Copyright (C) 1999,2003,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERValue; -import gnu.java.security.der.DERWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.interfaces.DSAParams; -import java.security.interfaces.DSAPublicKey; -import java.security.spec.DSAParameterSpec; -import java.util.ArrayList; - -public class GnuDSAPublicKey implements DSAPublicKey -{ - private byte[] encodedKey; - BigInteger y; - BigInteger p; - BigInteger q; - BigInteger g; - - public GnuDSAPublicKey(BigInteger y, BigInteger p, BigInteger q, BigInteger g ) - { - this.y = y; - this.p = p; - this.q = q; - this.g = g; - } - - public String getAlgorithm() - { - return "DSA"; - } - - public String getFormat() - { - return "X.509"; - } - - /** - * The encoded form of DSA public keys is: - * - * <blockquote><pre> - * SubjectPublicKeyInfo ::= SEQUENCE { - * algorithm AlgorithmIdentifier, - * subjectPublicKey BIT STRING } - * </pre></blockquote> - */ - public byte[] getEncoded() - { - if (encodedKey != null) - return (byte[]) encodedKey.clone(); - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ArrayList spki = new ArrayList(2); - ArrayList alg = new ArrayList(2); - alg.add(new DERValue(DER.OBJECT_IDENTIFIER, - new OID("1.2.840.113549.1.1.1"))); - ArrayList params = new ArrayList(3); - params.add(new DERValue(DER.INTEGER, p)); - params.add(new DERValue(DER.INTEGER, q)); - params.add(new DERValue(DER.INTEGER, g)); - alg.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, params)); - spki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg)); - spki.add(new DERValue(DER.BIT_STRING, new BitString(y.toByteArray()))); - DERWriter.write(out, new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, spki)); - return (byte[]) (encodedKey = out.toByteArray()).clone(); - } - catch (IOException ioe) - { - return null; - } - } - - public DSAParams getParams() - { - if (p == null || q == null || g == null) - return null; - return (DSAParams)(new DSAParameterSpec(p,q,g)); - } - - public BigInteger getY() - { - return y; - } - - public String toString() - { - return - "GnuDSAPublicKey: y=" + (y != null ? y.toString(16) : "(null)") + - " p=" + (p != null ? p.toString(16) : "(null)") + - " q=" + (q != null ? q.toString(16) : "(null)") + - " g=" + (g != null ? g.toString(16) : "(null)"); - } -} diff --git a/libjava/gnu/java/security/provider/GnuRSAPrivateKey.java b/libjava/gnu/java/security/provider/GnuRSAPrivateKey.java deleted file mode 100644 index b09fc88bc5c..00000000000 --- a/libjava/gnu/java/security/provider/GnuRSAPrivateKey.java +++ /dev/null @@ -1,164 +0,0 @@ -/* GnuRSAPrivateKey.java -- GNU RSA private key. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERValue; - -import java.math.BigInteger; -import java.security.interfaces.RSAPrivateCrtKey; -import java.security.spec.RSAPrivateCrtKeySpec; -import java.util.ArrayList; - -class GnuRSAPrivateKey implements RSAPrivateCrtKey -{ - - // Fields. - // ------------------------------------------------------------------------- - - private final RSAPrivateCrtKeySpec spec; - private byte[] encodedKey; - - // Constructor. - // ------------------------------------------------------------------------- - - public GnuRSAPrivateKey(RSAPrivateCrtKeySpec spec) - { - this.spec = spec; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public BigInteger getModulus() - { - return spec.getModulus(); - } - - public BigInteger getPrivateExponent() - { - return spec.getPrivateExponent(); - } - - public BigInteger getCrtCoefficient() - { - return spec.getCrtCoefficient(); - } - - public BigInteger getPrimeExponentP() - { - return spec.getPrimeExponentP(); - } - - public BigInteger getPrimeExponentQ() - { - return spec.getPrimeExponentQ(); - } - - public BigInteger getPrimeP() - { - return spec.getPrimeP(); - } - - public BigInteger getPrimeQ() - { - return spec.getPrimeQ(); - } - - public BigInteger getPublicExponent() - { - return spec.getPublicExponent(); - } - - public String getAlgorithm() - { - return "RSA"; - } - - public String getFormat() - { - return "PKCS#8"; - } - - /** - * The encoded form is: - * - * <pre> - * RSAPrivateKey ::= SEQUENCE { - * version Version, - * modulus INTEGER, -- n - * publicExponent INTEGER, -- e - * privateExponent INTEGER, -- d - * prime1 INTEGER, -- p - * prime2 INTEGER, -- q - * exponent1 INTEGER, -- d mod (p-1) - * exponent2 INTEGER, -- d mod (q-1) - * coefficient INTEGER -- (inverse of q) mod p } - * </pre> - * - * <p>Which is in turn encoded in a PrivateKeyInfo structure from PKCS#8. - */ - public byte[] getEncoded() - { - if (encodedKey != null) - return (byte[]) encodedKey.clone(); - ArrayList key = new ArrayList(9); - key.add(new DERValue(DER.INTEGER, BigInteger.ZERO)); - key.add(new DERValue(DER.INTEGER, getModulus())); - key.add(new DERValue(DER.INTEGER, getPublicExponent())); - key.add(new DERValue(DER.INTEGER, getPrivateExponent())); - key.add(new DERValue(DER.INTEGER, getPrimeP())); - key.add(new DERValue(DER.INTEGER, getPrimeQ())); - key.add(new DERValue(DER.INTEGER, getPrimeExponentP())); - key.add(new DERValue(DER.INTEGER, getPrimeExponentQ())); - key.add(new DERValue(DER.INTEGER, getCrtCoefficient())); - DERValue pk = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, key); - ArrayList pki = new ArrayList(3); - pki.add(new DERValue(DER.INTEGER, BigInteger.ZERO)); - ArrayList alg = new ArrayList(2); - alg.add(new DERValue(DER.OBJECT_IDENTIFIER, - new OID("1.2.840.113549.1.1.1"))); - alg.add(new DERValue(DER.NULL, null)); - pki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, alg)); - pki.add(new DERValue(DER.OCTET_STRING, pk.getEncoded())); - encodedKey = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, pki).getEncoded(); - return (byte[]) encodedKey.clone(); - } -} diff --git a/libjava/gnu/java/security/provider/GnuRSAPublicKey.java b/libjava/gnu/java/security/provider/GnuRSAPublicKey.java deleted file mode 100644 index a35e761c066..00000000000 --- a/libjava/gnu/java/security/provider/GnuRSAPublicKey.java +++ /dev/null @@ -1,109 +0,0 @@ -/* GnuRSAPublicKey.java -- GNU RSA public key. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERValue; - -import java.math.BigInteger; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.RSAPublicKeySpec; -import java.util.ArrayList; - -class GnuRSAPublicKey implements RSAPublicKey -{ - - // Fields. - // ------------------------------------------------------------------------- - - private final RSAPublicKeySpec spec; - private byte[] encodedKey; - - // Constructor. - // ------------------------------------------------------------------------- - - public GnuRSAPublicKey(RSAPublicKeySpec spec) - { - this.spec = spec; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public BigInteger getModulus() - { - return spec.getModulus(); - } - - public BigInteger getPublicExponent() - { - return spec.getPublicExponent(); - } - - public String getAlgorithm() - { - return "RSA"; - } - - public String getFormat() - { - return "X.509"; - } - - public byte[] getEncoded() - { - if (encodedKey != null) - return (byte[]) encodedKey.clone(); - ArrayList key = new ArrayList(2); - key.add(new DERValue(DER.INTEGER, getModulus())); - key.add(new DERValue(DER.INTEGER, getPublicExponent())); - DERValue rsapk = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, key); - ArrayList alg = new ArrayList(2); - alg.add(new DERValue(DER.OBJECT_IDENTIFIER, - new OID("1.2.840.113549.1.1.1"))); - alg.add(new DERValue(DER.NULL, null)); - ArrayList spki = new ArrayList(2); - spki.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, alg)); - spki.add(new DERValue(DER.BIT_STRING, new BitString(rsapk.getEncoded()))); - encodedKey = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, spki).getEncoded(); - return (byte[]) encodedKey.clone(); - } -} diff --git a/libjava/gnu/java/security/provider/MD2withRSA.java b/libjava/gnu/java/security/provider/MD2withRSA.java deleted file mode 100644 index a72ae5588dc..00000000000 --- a/libjava/gnu/java/security/provider/MD2withRSA.java +++ /dev/null @@ -1,54 +0,0 @@ -/* MD2withRSA.java -- MD2 with RSA encryption signatures. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class MD2withRSA extends RSA -{ - - // Constructor. - // ------------------------------------------------------------------------- - - public MD2withRSA() throws NoSuchAlgorithmException - { - super(MessageDigest.getInstance("MD2"), DIGEST_ALGORITHM.getChild(2)); - } -} diff --git a/libjava/gnu/java/security/provider/MD4withRSA.java b/libjava/gnu/java/security/provider/MD4withRSA.java deleted file mode 100644 index 76a6a1ad033..00000000000 --- a/libjava/gnu/java/security/provider/MD4withRSA.java +++ /dev/null @@ -1,54 +0,0 @@ -/* MD4withRSA.java -- MD4 with RSA encryption signatures. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class MD4withRSA extends RSA -{ - - // Constructor. - // ------------------------------------------------------------------------- - - public MD4withRSA() throws NoSuchAlgorithmException - { - super(MessageDigest.getInstance("MD4"), DIGEST_ALGORITHM.getChild(4)); - } -} diff --git a/libjava/gnu/java/security/provider/MD5.java b/libjava/gnu/java/security/provider/MD5.java deleted file mode 100644 index 1534eb91089..00000000000 --- a/libjava/gnu/java/security/provider/MD5.java +++ /dev/null @@ -1,338 +0,0 @@ -/* MD5.java -- Class implementing the MD5 algorithm as specified in RFC1321. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; -import java.security.MessageDigest; - -/** - This class implements the MD5 algorithm as described in RFC1321. - - @see java.security.MessageDigest -*/ -public class MD5 extends MessageDigest implements Cloneable -{ - private final int W[] = new int[16]; - private long bytecount; - private int A; - private int B; - private int C; - private int D; - - public MD5() - { - super("MD5"); - engineReset (); - } - - public Object clone() - { - return new MD5 (this); - } - - private MD5 (MD5 copy) - { - this (); - bytecount = copy.bytecount; - A = copy.A; - B = copy.B; - C = copy.C; - D = copy.D; - System.arraycopy (copy.W, 0, W, 0, 16); - } - - public int engineGetDigestLength() - { - return 16; - } - - // Intialize the A,B,C,D needed for the hash - public void engineReset() - { - bytecount = 0; - A = 0x67452301; - B = 0xefcdab89; - C = 0x98badcfe; - D = 0x10325476; - for(int i = 0; i < 16; i++) - W[i] = 0; - } - - public void engineUpdate (byte b) - { - int i = (int)bytecount % 64; - int shift = (3 - i % 4) * 8; - int idx = i / 4; - - // if you could index ints, this would be: W[idx][shift/8] = b - W[idx] = (W[idx] & ~(0xff << shift)) | ((b & 0xff) << shift); - - // if we've filled up a block, then process it - if ((++ bytecount) % 64 == 0) - munch (); - } - - public void engineUpdate (byte bytes[], int off, int len) - { - if (len < 0) - throw new ArrayIndexOutOfBoundsException (); - - int end = off + len; - while (off < end) - engineUpdate (bytes[off++]); - } - - public byte[] engineDigest() - { - long bitcount = bytecount * 8; - engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding - - // add the rest of the padding to fill this block out, but leave 8 - // bytes to put in the original bytecount - while ((int)bytecount % 64 != 56) - engineUpdate ((byte)0); - - // add the length of the original, unpadded block to the end of - // the padding - W[14] = SWAP((int)(0xffffffff & bitcount)); - W[15] = SWAP((int)(0xffffffff & (bitcount >>> 32))); - bytecount += 8; - - // digest the fully padded block - munch (); - - A = SWAP(A); - B = SWAP(B); - C = SWAP(C); - D = SWAP(D); - byte[] result = new byte[] {(byte)(A >>> 24), (byte)(A >>> 16), - (byte)(A >>> 8), (byte)A, - (byte)(B >>> 24), (byte)(B >>> 16), - (byte)(B >>> 8), (byte)B, - (byte)(C >>> 24), (byte)(C >>> 16), - (byte)(C >>> 8), (byte)C, - (byte)(D >>> 24), (byte)(D >>> 16), - (byte)(D >>> 8), (byte)D}; - - engineReset (); - return result; - } - - private int F( int X, int Y, int Z) - { - return ((X & Y) | (~X & Z)); - } - - private int G( int X, int Y, int Z) - { - return ((X & Z) | (Y & ~Z)); - } - - private int H( int X, int Y, int Z) - { - return (X ^ Y ^ Z); - } - - private int I( int X, int Y, int Z) - { - return (Y ^ (X | ~Z)); - } - - private int rotateLeft( int i, int count) - { - //Taken from FIPS 180-1 - return ( (i << count) | (i >>> (32 - count)) ) ; - } - - /* Round 1. */ - private int FF( int a, int b, int c, int d, int k, int s, int i) - { - /* Let [abcd k s i] denote the operation */ - a += F(b,c,d) + k + i; - return b + rotateLeft(a, s); - } - /* Round 2. */ - private int GG( int a, int b, int c, int d, int k, int s, int i) - { - /* Let [abcd k s i] denote the operation */ - a += G(b,c,d) + k + i; - return b + rotateLeft(a, s); - } - /* Round 3. */ - private int HH( int a, int b, int c, int d, int k, int s, int i) - { - /* Let [abcd k s t] denote the operation */ - a += H(b,c,d) + k + i; - return b + rotateLeft(a, s); - } - - /* Round 4. */ - private int II( int a, int b, int c, int d, int k, int s, int i) - { - /* Let [abcd k s t] denote the operation */ - a += I(b,c,d) + k + i; - return b + rotateLeft(a, s); - } - - private int SWAP(int n) - { - //Copied from md5.c in FSF Gnu Privacy Guard 0.9.2 - return (( (0xff & n) << 24) | ((n & 0xff00) << 8) | ((n >>> 8) & 0xff00) | (n >>> 24)); - } - - private void munch() - { - int AA,BB,CC,DD, j; - int X[] = new int[16]; - - /* Copy block i into X. */ - for(j = 0; j < 16; j++) - X[j] = SWAP(W[j]); - - /* Save A as AA, B as BB, C as CC, and D as DD. */ - AA = A; - BB = B; - CC = C; - DD = D; - - /* The hex constants are from md5.c - in FSF Gnu Privacy Guard 0.9.2 */ - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ - /* Do the following 16 operations. */ - A = FF(A,B,C,D, X[0], 7, 0xd76aa478); - D = FF(D,A,B,C, X[1], 12, 0xe8c7b756); - C = FF(C,D,A,B, X[2], 17, 0x242070db); - B = FF(B,C,D,A, X[3], 22, 0xc1bdceee); - - A = FF(A,B,C,D, X[4], 7, 0xf57c0faf); - D = FF(D,A,B,C, X[5], 12, 0x4787c62a); - C = FF(C,D,A,B, X[6], 17, 0xa8304613); - B = FF(B,C,D,A, X[7], 22, 0xfd469501); - - A = FF(A,B,C,D, X[8], 7, 0x698098d8); - D = FF(D,A,B,C, X[9], 12, 0x8b44f7af); - C = FF(C,D,A,B, X[10], 17, 0xffff5bb1); - B = FF(B,C,D,A, X[11], 22, 0x895cd7be); - - A = FF(A,B,C,D, X[12], 7, 0x6b901122); - D = FF(D,A,B,C, X[13], 12, 0xfd987193); - C = FF(C,D,A,B, X[14], 17, 0xa679438e); - B = FF(B,C,D,A, X[15], 22, 0x49b40821); - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ - /* Do the following 16 operations. */ - A = GG(A,B,C,D, X[1], 5, 0xf61e2562); - D = GG(D,A,B,C, X[6], 9, 0xc040b340); - C = GG(C,D,A,B, X[11], 14, 0x265e5a51); - B = GG(B,C,D,A, X[0], 20, 0xe9b6c7aa); - - A = GG(A,B,C,D, X[5], 5, 0xd62f105d); - D = GG(D,A,B,C, X[10], 9, 0x02441453); - C = GG(C,D,A,B, X[15], 14, 0xd8a1e681); - B = GG(B,C,D,A, X[4], 20, 0xe7d3fbc8); - - A = GG(A,B,C,D, X[9], 5, 0x21e1cde6); - D = GG(D,A,B,C, X[14], 9, 0xc33707d6); - C = GG(C,D,A,B, X[3], 14, 0xf4d50d87); - B = GG(B,C,D,A, X[8], 20, 0x455a14ed); - - A = GG(A,B,C,D, X[13], 5, 0xa9e3e905); - D = GG(D,A,B,C, X[2], 9, 0xfcefa3f8); - C = GG(C,D,A,B, X[7], 14, 0x676f02d9); - B = GG(B,C,D,A, X[12], 20, 0x8d2a4c8a); - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ - /* Do the following 16 operations. */ - A = HH(A,B,C,D, X[5], 4, 0xfffa3942); - D = HH(D,A,B,C, X[8], 11, 0x8771f681); - C = HH(C,D,A,B, X[11], 16, 0x6d9d6122); - B = HH(B,C,D,A, X[14], 23, 0xfde5380c); - - A = HH(A,B,C,D, X[1], 4, 0xa4beea44); - D = HH(D,A,B,C, X[4], 11, 0x4bdecfa9); - C = HH(C,D,A,B, X[7], 16, 0xf6bb4b60); - B = HH(B,C,D,A, X[10], 23, 0xbebfbc70); - - A = HH(A,B,C,D, X[13], 4, 0x289b7ec6); - D = HH(D,A,B,C, X[0], 11, 0xeaa127fa); - C = HH(C,D,A,B, X[3], 16, 0xd4ef3085); - B = HH(B,C,D,A, X[6], 23, 0x04881d05); - - A = HH(A,B,C,D, X[9], 4, 0xd9d4d039); - D = HH(D,A,B,C, X[12], 11, 0xe6db99e5); - C = HH(C,D,A,B, X[15], 16, 0x1fa27cf8); - B = HH(B,C,D,A, X[2], 23, 0xc4ac5665); - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ - /* Do the following 16 operations. */ - A = II(A,B,C,D, X[0], 6, 0xf4292244); - D = II(D,A,B,C, X[7], 10, 0x432aff97); - C = II(C,D,A,B, X[14], 15, 0xab9423a7); - B = II(B,C,D,A, X[5], 21, 0xfc93a039); - - A = II(A,B,C,D, X[12], 6, 0x655b59c3); - D = II(D,A,B,C, X[3], 10, 0x8f0ccc92); - C = II(C,D,A,B, X[10], 15, 0xffeff47d); - B = II(B,C,D,A, X[1], 21, 0x85845dd1); - - A = II(A,B,C,D, X[8], 6, 0x6fa87e4f); - D = II(D,A,B,C, X[15], 10, 0xfe2ce6e0); - C = II(C,D,A,B, X[6], 15, 0xa3014314); - B = II(B,C,D,A, X[13], 21, 0x4e0811a1); - - A = II(A,B,C,D, X[4], 6, 0xf7537e82); - D = II(D,A,B,C, X[11], 10, 0xbd3af235); - C = II(C,D,A,B, X[2], 15, 0x2ad7d2bb); - B = II(B,C,D,A, X[9], 21, 0xeb86d391); - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - A = A + AA; - B = B + BB; - C = C + CC; - D = D + DD; - } -} diff --git a/libjava/gnu/java/security/provider/MD5withRSA.java b/libjava/gnu/java/security/provider/MD5withRSA.java deleted file mode 100644 index 721d897ed24..00000000000 --- a/libjava/gnu/java/security/provider/MD5withRSA.java +++ /dev/null @@ -1,54 +0,0 @@ -/* MD5withRSA.java -- MD5 with RSA encryption signatures. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class MD5withRSA extends RSA -{ - - // Constructor. - // ------------------------------------------------------------------------- - - public MD5withRSA() throws NoSuchAlgorithmException - { - super(MessageDigest.getInstance("MD5"), DIGEST_ALGORITHM.getChild(5)); - } -} diff --git a/libjava/gnu/java/security/provider/PKIXCertPathValidatorImpl.java b/libjava/gnu/java/security/provider/PKIXCertPathValidatorImpl.java deleted file mode 100644 index 1268b169d9b..00000000000 --- a/libjava/gnu/java/security/provider/PKIXCertPathValidatorImpl.java +++ /dev/null @@ -1,701 +0,0 @@ -/* PKIXCertPathValidatorImpl.java -- PKIX certificate path validator. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.x509.GnuPKIExtension; -import gnu.java.security.x509.PolicyNodeImpl; -import gnu.java.security.x509.X509CRLSelectorImpl; -import gnu.java.security.x509.X509CertSelectorImpl; -import gnu.java.security.x509.ext.BasicConstraints; -import gnu.java.security.x509.ext.CertificatePolicies; -import gnu.java.security.x509.ext.Extension; -import gnu.java.security.x509.ext.KeyUsage; -import gnu.java.security.x509.ext.PolicyConstraint; - -import java.io.IOException; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.PublicKey; -import java.security.cert.CRL; -import java.security.cert.CertPath; -import java.security.cert.CertPathParameters; -import java.security.cert.CertPathValidatorException; -import java.security.cert.CertPathValidatorResult; -import java.security.cert.CertPathValidatorSpi; -import java.security.cert.CertStore; -import java.security.cert.CertStoreException; -import java.security.cert.CertificateException; -import java.security.cert.PKIXCertPathChecker; -import java.security.cert.PKIXCertPathValidatorResult; -import java.security.cert.PKIXParameters; -import java.security.cert.TrustAnchor; -import java.security.cert.X509CRL; -import java.security.cert.X509Certificate; -import java.security.interfaces.DSAParams; -import java.security.interfaces.DSAPublicKey; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * An implementation of the Public Key Infrastructure's X.509 - * certificate path validation algorithm. - * - * <p>See <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: - * Internet X.509 Public Key Infrastructure Certificate and - * Certificate Revocation List (CRL) Profile</a>. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class PKIXCertPathValidatorImpl extends CertPathValidatorSpi -{ - - // Constants. - // ------------------------------------------------------------------------- - - private static final boolean DEBUG = false; - private static void debug (String msg) - { - System.err.print (">> PKIXCertPathValidatorImpl: "); - System.err.println (msg); - } - - public static final String ANY_POLICY = "2.5.29.32.0"; - - // Constructor. - // ------------------------------------------------------------------------- - - public PKIXCertPathValidatorImpl() - { - super(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public CertPathValidatorResult engineValidate(CertPath path, - CertPathParameters params) - throws CertPathValidatorException, InvalidAlgorithmParameterException - { - if (!(params instanceof PKIXParameters)) - throw new InvalidAlgorithmParameterException("not a PKIXParameters object"); - - // First check if the certificate path is valid. - // - // This means that: - // - // (a) for all x in {1, ..., n-1}, the subject of certificate x is - // the issuer of certificate x+1; - // - // (b) for all x in {1, ..., n}, the certificate was valid at the - // time in question. - // - // Because this is the X.509 algorithm, we also check if all - // cerificates are of type X509Certificate. - - PolicyNodeImpl rootNode = new PolicyNodeImpl(); - Set initPolicies = ((PKIXParameters) params).getInitialPolicies(); - rootNode.setValidPolicy(ANY_POLICY); - rootNode.setCritical(false); - rootNode.setDepth(0); - if (initPolicies != null) - rootNode.addAllExpectedPolicies(initPolicies); - else - rootNode.addExpectedPolicy(ANY_POLICY); - List checks = ((PKIXParameters) params).getCertPathCheckers(); - List l = path.getCertificates(); - if (l == null || l.size() == 0) - throw new CertPathValidatorException(); - X509Certificate[] p = null; - try - { - p = (X509Certificate[]) l.toArray(new X509Certificate[l.size()]); - } - catch (ClassCastException cce) - { - throw new CertPathValidatorException("invalid certificate path"); - } - - String sigProvider = ((PKIXParameters) params).getSigProvider(); - PublicKey prevKey = null; - Date now = ((PKIXParameters) params).getDate(); - if (now == null) - now = new Date(); - LinkedList policyConstraints = new LinkedList(); - for (int i = p.length - 1; i >= 0; i--) - { - try - { - p[i].checkValidity(now); - } - catch (CertificateException ce) - { - throw new CertPathValidatorException(ce.toString()); - } - Set uce = getCritExts(p[i]); - for (Iterator check = checks.iterator(); check.hasNext(); ) - { - try - { - ((PKIXCertPathChecker) check.next()).check(p[i], uce); - } - catch (Exception x) - { - } - } - - PolicyConstraint constr = null; - if (p[i] instanceof GnuPKIExtension) - { - Extension pcx = - ((GnuPKIExtension) p[i]).getExtension (PolicyConstraint.ID); - if (pcx != null) - constr = (PolicyConstraint) pcx.getValue(); - } - else - { - byte[] pcx = p[i].getExtensionValue (PolicyConstraint.ID.toString()); - if (pcx != null) - { - try - { - constr = new PolicyConstraint (pcx); - } - catch (Exception x) - { - } - } - } - if (constr != null && constr.getRequireExplicitPolicy() >= 0) - { - policyConstraints.add (new int[] - { p.length-i, constr.getRequireExplicitPolicy() }); - } - - updatePolicyTree(p[i], rootNode, p.length-i, (PKIXParameters) params, - checkExplicitPolicy (p.length-i, policyConstraints)); - - // The rest of the tests involve this cert's relationship with the - // next in the path. If this cert is the end entity, we can stop. - if (i == 0) - break; - - basicSanity(p, i); - PublicKey pubKey = null; - try - { - pubKey = p[i].getPublicKey(); - if (pubKey instanceof DSAPublicKey) - { - DSAParams dsa = ((DSAPublicKey) pubKey).getParams(); - // If the DSA public key is missing its parameters, use those - // from the previous cert's key. - if (dsa == null || dsa.getP() == null || dsa.getG() == null - || dsa.getQ() == null) - { - if (prevKey == null) - throw new InvalidKeyException("DSA keys not chainable"); - if (!(prevKey instanceof DSAPublicKey)) - throw new InvalidKeyException("DSA keys not chainable"); - dsa = ((DSAPublicKey) prevKey).getParams(); - pubKey = new GnuDSAPublicKey(((DSAPublicKey) pubKey).getY(), - dsa.getP(), dsa.getQ(), dsa.getG()); - } - } - if (sigProvider == null) - p[i-1].verify(pubKey); - else - p[i-1].verify(pubKey, sigProvider); - prevKey = pubKey; - } - catch (Exception e) - { - throw new CertPathValidatorException(e.toString()); - } - if (!p[i].getSubjectDN().equals(p[i-1].getIssuerDN())) - throw new CertPathValidatorException("issuer DN mismatch"); - boolean[] issuerUid = p[i-1].getIssuerUniqueID(); - boolean[] subjectUid = p[i].getSubjectUniqueID(); - if (issuerUid != null && subjectUid != null) - if (!Arrays.equals(issuerUid, subjectUid)) - throw new CertPathValidatorException("UID mismatch"); - - // Check the certificate against the revocation lists. - if (((PKIXParameters) params).isRevocationEnabled()) - { - X509CRLSelectorImpl selector = new X509CRLSelectorImpl(); - try - { - selector.addIssuerName(p[i].getSubjectDN()); - } - catch (IOException ioe) - { - throw new CertPathValidatorException("error selecting CRLs"); - } - List certStores = ((PKIXParameters) params).getCertStores(); - List crls = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext(); ) - { - CertStore cs = (CertStore) it.next(); - try - { - Collection c = cs.getCRLs(selector); - crls.addAll(c); - } - catch (CertStoreException cse) - { - } - } - if (crls.isEmpty()) - throw new CertPathValidatorException("no CRLs for issuer"); - boolean certOk = false; - for (Iterator it = crls.iterator(); it.hasNext(); ) - { - CRL crl = (CRL) it.next(); - if (!(crl instanceof X509CRL)) - continue; - X509CRL xcrl = (X509CRL) crl; - if (!checkCRL(xcrl, p, now, p[i], pubKey, certStores)) - continue; - if (xcrl.isRevoked(p[i-1])) - throw new CertPathValidatorException("certificate is revoked"); - else - certOk = true; - } - if (!certOk) - throw new CertPathValidatorException("certificate's validity could not be determined"); - } - } - rootNode.setReadOnly(); - - // Now ensure that the first certificate in the chain was issued - // by a trust anchor. - Exception cause = null; - Set anchors = ((PKIXParameters) params).getTrustAnchors(); - for (Iterator i = anchors.iterator(); i.hasNext(); ) - { - TrustAnchor anchor = (TrustAnchor) i.next(); - X509Certificate anchorCert = null; - PublicKey anchorKey = null; - if (anchor.getTrustedCert() != null) - { - anchorCert = anchor.getTrustedCert(); - anchorKey = anchorCert.getPublicKey(); - } - else - anchorKey = anchor.getCAPublicKey(); - if (anchorKey == null) - continue; - try - { - if (anchorCert == null) - anchorCert.checkValidity(now); - p[p.length-1].verify(anchorKey); - if (anchorCert != null && anchorCert.getBasicConstraints() >= 0 - && anchorCert.getBasicConstraints() < p.length) - continue; - - if (((PKIXParameters) params).isRevocationEnabled()) - { - X509CRLSelectorImpl selector = new X509CRLSelectorImpl(); - if (anchorCert != null) - try - { - selector.addIssuerName(anchorCert.getSubjectDN()); - } - catch (IOException ioe) - { - } - else - selector.addIssuerName(anchor.getCAName()); - List certStores = ((PKIXParameters) params).getCertStores(); - List crls = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext(); ) - { - CertStore cs = (CertStore) it.next(); - try - { - Collection c = cs.getCRLs(selector); - crls.addAll(c); - } - catch (CertStoreException cse) - { - } - } - if (crls.isEmpty()) - continue; - for (Iterator it = crls.iterator(); it.hasNext(); ) - { - CRL crl = (CRL) it.next(); - if (!(crl instanceof X509CRL)) - continue; - X509CRL xcrl = (X509CRL) crl; - try - { - xcrl.verify(anchorKey); - } - catch (Exception x) - { - continue; - } - Date nextUpdate = xcrl.getNextUpdate(); - if (nextUpdate != null && nextUpdate.compareTo(now) < 0) - continue; - if (xcrl.isRevoked(p[p.length-1])) - throw new CertPathValidatorException("certificate is revoked"); - } - } - - // The chain is valid; return the result. - return new PKIXCertPathValidatorResult(anchor, rootNode, - p[0].getPublicKey()); - } - catch (Exception ignored) - { - cause = ignored; - continue; - } - } - - // The path is not valid. - CertPathValidatorException cpve = - new CertPathValidatorException("path validation failed"); - if (cause != null) - cpve.initCause (cause); - throw cpve; - } - - // Own methods. - // ------------------------------------------------------------------------- - - /** - * Check if a given CRL is acceptable for checking the revocation status - * of certificates in the path being checked. - * - * <p>The CRL is accepted iff:</p> - * - * <ol> - * <li>The <i>nextUpdate</i> field (if present) is in the future.</li> - * <li>The CRL does not contain any unsupported critical extensions.</li> - * <li>The CRL is signed by one of the certificates in the path, or,</li> - * <li>The CRL is signed by the given public key and was issued by the - * public key's subject, or,</li> - * <li>The CRL is signed by a certificate in the given cert stores, and - * that cert is signed by one of the certificates in the path.</li> - * </ol> - * - * @param crl The CRL being checked. - * @param path The path this CRL is being checked against. - * @param now The value to use as 'now'. - * @param pubKeySubject The subject of the public key. - * @param pubKey The public key to check. - * @return True if the CRL is acceptable. - */ - private static boolean checkCRL(X509CRL crl, X509Certificate[] path, Date now, - X509Certificate pubKeyCert, PublicKey pubKey, - List certStores) - { - Date nextUpdate = crl.getNextUpdate(); - if (nextUpdate != null && nextUpdate.compareTo(now) < 0) - return false; - if (crl.hasUnsupportedCriticalExtension()) - return false; - for (int i = 0; i < path.length; i++) - { - if (!path[i].getSubjectDN().equals(crl.getIssuerDN())) - continue; - boolean[] keyUsage = path[i].getKeyUsage(); - if (keyUsage != null) - { - if (!keyUsage[KeyUsage.CRL_SIGN]) - continue; - } - try - { - crl.verify(path[i].getPublicKey()); - return true; - } - catch (Exception x) - { - } - } - if (crl.getIssuerDN().equals(pubKeyCert.getSubjectDN())) - { - try - { - boolean[] keyUsage = pubKeyCert.getKeyUsage(); - if (keyUsage != null) - { - if (!keyUsage[KeyUsage.CRL_SIGN]) - throw new Exception(); - } - crl.verify(pubKey); - return true; - } - catch (Exception x) - { - } - } - try - { - X509CertSelectorImpl select = new X509CertSelectorImpl(); - select.addSubjectName(crl.getIssuerDN()); - List certs = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext(); ) - { - CertStore cs = (CertStore) it.next(); - try - { - certs.addAll(cs.getCertificates(select)); - } - catch (CertStoreException cse) - { - } - } - for (Iterator it = certs.iterator(); it.hasNext(); ) - { - X509Certificate c = (X509Certificate) it.next(); - for (int i = 0; i < path.length; i++) - { - if (!c.getIssuerDN().equals(path[i].getSubjectDN())) - continue; - boolean[] keyUsage = c.getKeyUsage(); - if (keyUsage != null) - { - if (!keyUsage[KeyUsage.CRL_SIGN]) - continue; - } - try - { - c.verify(path[i].getPublicKey()); - crl.verify(c.getPublicKey()); - return true; - } - catch (Exception x) - { - } - } - if (c.getIssuerDN().equals(pubKeyCert.getSubjectDN())) - { - c.verify(pubKey); - crl.verify(c.getPublicKey()); - } - } - } - catch (Exception x) - { - } - return false; - } - - private static Set getCritExts(X509Certificate cert) - { - HashSet s = new HashSet(); - if (cert instanceof GnuPKIExtension) - { - Collection exts = ((GnuPKIExtension) cert).getExtensions(); - for (Iterator it = exts.iterator(); it.hasNext(); ) - { - Extension ext = (Extension) it.next(); - if (ext.isCritical() && !ext.isSupported()) - s.add(ext.getOid().toString()); - } - } - else - s.addAll(cert.getCriticalExtensionOIDs()); - return s; - } - - /** - * Perform a basic sanity check on the CA certificate at <code>index</code>. - */ - private static void basicSanity(X509Certificate[] path, int index) - throws CertPathValidatorException - { - X509Certificate cert = path[index]; - int pathLen = 0; - for (int i = index - 1; i > 0; i--) - { - if (!path[i].getIssuerDN().equals(path[i].getSubjectDN())) - pathLen++; - } - Extension e = null; - if (cert instanceof GnuPKIExtension) - { - e = ((GnuPKIExtension) cert).getExtension(BasicConstraints.ID); - } - else - { - try - { - e = new Extension(cert.getExtensionValue(BasicConstraints.ID.toString())); - } - catch (Exception x) - { - } - } - if (e == null) - throw new CertPathValidatorException("no basicConstraints"); - BasicConstraints bc = (BasicConstraints) e.getValue(); - if (!bc.isCA()) - throw new CertPathValidatorException("certificate cannot be used to verify signatures"); - if (bc.getPathLengthConstraint() >= 0 && bc.getPathLengthConstraint() < pathLen) - throw new CertPathValidatorException("path is too long"); - - boolean[] keyUsage = cert.getKeyUsage(); - if (keyUsage != null) - { - if (!keyUsage[KeyUsage.KEY_CERT_SIGN]) - throw new CertPathValidatorException("certificate cannot be used to sign certificates"); - } - } - - private static void updatePolicyTree(X509Certificate cert, PolicyNodeImpl root, - int depth, PKIXParameters params, - boolean explicitPolicy) - throws CertPathValidatorException - { - if (DEBUG) debug("updatePolicyTree depth == " + depth); - Set nodes = new HashSet(); - LinkedList stack = new LinkedList(); - Iterator current = null; - stack.addLast(Collections.singleton(root).iterator()); - do - { - current = (Iterator) stack.removeLast(); - while (current.hasNext()) - { - PolicyNodeImpl p = (PolicyNodeImpl) current.next(); - if (DEBUG) debug("visiting node == " + p); - if (p.getDepth() == depth - 1) - { - if (DEBUG) debug("added node"); - nodes.add(p); - } - else - { - if (DEBUG) debug("skipped node"); - stack.addLast(current); - current = p.getChildren(); - } - } - } - while (!stack.isEmpty()); - - Extension e = null; - CertificatePolicies policies = null; - List qualifierInfos = null; - if (cert instanceof GnuPKIExtension) - { - e = ((GnuPKIExtension) cert).getExtension(CertificatePolicies.ID); - if (e != null) - policies = (CertificatePolicies) e.getValue(); - } - - List cp = null; - if (policies != null) - cp = policies.getPolicies(); - else - cp = Collections.EMPTY_LIST; - boolean match = false; - if (DEBUG) debug("nodes are == " + nodes); - if (DEBUG) debug("cert policies are == " + cp); - for (Iterator it = nodes.iterator(); it.hasNext(); ) - { - PolicyNodeImpl parent = (PolicyNodeImpl) it.next(); - if (DEBUG) debug("adding policies to " + parent); - for (Iterator it2 = cp.iterator(); it2.hasNext(); ) - { - OID policy = (OID) it2.next(); - if (DEBUG) debug("trying to add policy == " + policy); - if (policy.toString().equals(ANY_POLICY) && - params.isAnyPolicyInhibited()) - continue; - PolicyNodeImpl child = new PolicyNodeImpl(); - child.setValidPolicy(policy.toString()); - child.addExpectedPolicy(policy.toString()); - if (parent.getExpectedPolicies().contains(policy.toString())) - { - parent.addChild(child); - match = true; - } - else if (parent.getExpectedPolicies().contains(ANY_POLICY)) - { - parent.addChild(child); - match = true; - } - else if (ANY_POLICY.equals (policy.toString())) - { - parent.addChild (child); - match = true; - } - if (match && policies != null) - { - List qualifiers = policies.getPolicyQualifierInfos (policy); - if (qualifiers != null) - child.addAllPolicyQualifiers (qualifiers); - } - } - } - if (!match && (params.isExplicitPolicyRequired() || explicitPolicy)) - throw new CertPathValidatorException("policy tree building failed"); - } - - private boolean checkExplicitPolicy (int depth, List explicitPolicies) - { - if (DEBUG) debug ("checkExplicitPolicy depth=" + depth); - for (Iterator it = explicitPolicies.iterator(); it.hasNext(); ) - { - int[] i = (int[]) it.next(); - int caDepth = i[0]; - int limit = i[1]; - if (DEBUG) debug (" caDepth=" + caDepth + " limit=" + limit); - if (depth - caDepth >= limit) - return true; - } - return false; - } -} diff --git a/libjava/gnu/java/security/provider/RSA.java b/libjava/gnu/java/security/provider/RSA.java deleted file mode 100644 index c3cfbbf79f1..00000000000 --- a/libjava/gnu/java/security/provider/RSA.java +++ /dev/null @@ -1,311 +0,0 @@ -/* RSA.java -- RSA PKCS#1 signatures. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.der.DERWriter; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.SecureRandom; -import java.security.SignatureException; -import java.security.SignatureSpi; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.util.ArrayList; - -public abstract class RSA extends SignatureSpi implements Cloneable -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - /** - * digestAlgorithm OBJECT IDENTIFIER ::= - * { iso(1) member-body(2) US(840) rsadsi(113549) digestAlgorithm(2) } - */ - protected static final OID DIGEST_ALGORITHM = new OID("1.2.840.113549.2"); - - protected final OID digestAlgorithm; - protected final MessageDigest md; - protected RSAPrivateKey signerKey; - protected RSAPublicKey verifierKey; - - // Constructor. - // ------------------------------------------------------------------------- - - protected RSA(MessageDigest md, OID digestAlgorithm) - { - super(); - this.md = md; - this.digestAlgorithm = digestAlgorithm; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public Object clone() throws CloneNotSupportedException - { - return super.clone(); - } - - protected Object engineGetParameter(String param) - { - throw new UnsupportedOperationException("deprecated"); - } - - protected void engineSetParameter(String param, Object value) - { - throw new UnsupportedOperationException("deprecated"); - } - - protected void engineInitSign(PrivateKey privateKey) - throws InvalidKeyException - { - if (!(privateKey instanceof RSAPrivateKey)) - throw new InvalidKeyException(); - verifierKey = null; - signerKey = (RSAPrivateKey) privateKey; - } - - protected void engineInitSign(PrivateKey privateKey, SecureRandom random) - throws InvalidKeyException - { - // This class does not need random bytes. - engineInitSign(privateKey); - } - - protected void engineInitVerify(PublicKey publicKey) - throws InvalidKeyException - { - if (!(publicKey instanceof RSAPublicKey)) - throw new InvalidKeyException(); - signerKey = null; - verifierKey = (RSAPublicKey) publicKey; - } - - protected void engineUpdate(byte b) throws SignatureException - { - if (signerKey == null && verifierKey == null) - throw new SignatureException("not initialized"); - md.update(b); - } - - protected void engineUpdate(byte[] buf, int off, int len) - throws SignatureException - { - if (signerKey == null && verifierKey == null) - throw new SignatureException("not initialized"); - md.update(buf, off, len); - } - - protected byte[] engineSign() throws SignatureException - { - if (signerKey == null) - throw new SignatureException("not initialized for signing"); - // - // The signature will be the RSA encrypted BER representation of - // the following: - // - // DigestInfo ::= SEQUENCE { - // digestAlgorithm DigestAlgorithmIdentifier, - // digest Digest } - // - // DigestAlgorithmIdentifier ::= AlgorithmIdentifier - // - // Digest ::= OCTET STRING - // - ArrayList digestAlg = new ArrayList(2); - digestAlg.add(new DERValue(DER.OBJECT_IDENTIFIER, digestAlgorithm)); - digestAlg.add(new DERValue(DER.NULL, null)); - ArrayList digestInfo = new ArrayList(2); - digestInfo.add(new DERValue(DER.SEQUENCE, digestAlg)); - digestInfo.add(new DERValue(DER.OCTET_STRING, md.digest())); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try - { - DERWriter.write(out, new DERValue(DER.SEQUENCE, digestInfo)); - } - catch (IOException ioe) - { - throw new SignatureException(ioe.toString()); - } - byte[] buf = out.toByteArray(); - md.reset(); - - // k = octect length of the modulus. - int k = signerKey.getModulus().bitLength(); - k = (k >>> 3) + ((k & 7) == 0 ? 0 : 1); - if (buf.length < k - 3) - { - throw new SignatureException("RSA modulus too small"); - } - byte[] d = new byte[k]; - - // Padding type 1: - // 00 | 01 | FF | ... | FF | 00 | D - d[1] = 0x01; - for (int i = 2; i < k - buf.length - 1; i++) - d[i] = (byte) 0xFF; - System.arraycopy(buf, 0, d, k - buf.length, buf.length); - - BigInteger eb = new BigInteger(d); - - byte[] ed = eb.modPow(signerKey.getPrivateExponent(), - signerKey.getModulus()).toByteArray(); - - // Ensure output is k octets long. - if (ed.length < k) - { - byte[] b = new byte[k]; - System.arraycopy(eb, 0, b, k - ed.length, ed.length); - ed = b; - } - else if (ed.length > k) - { - if (ed.length != k + 1) - { - throw new SignatureException("modPow result is larger than the modulus"); - } - // Maybe an extra 00 octect. - byte[] b = new byte[k]; - System.arraycopy(ed, 1, b, 0, k); - ed = b; - } - - return ed; - } - - protected int engineSign(byte[] out, int off, int len) - throws SignatureException - { - if (out == null || off < 0 || len < 0 || off+len > out.length) - throw new SignatureException("illegal output argument"); - byte[] result = engineSign(); - if (result.length > len) - throw new SignatureException("not enough space for signature"); - System.arraycopy(result, 0, out, off, result.length); - return result.length; - } - - protected boolean engineVerify(byte[] sig) throws SignatureException - { - if (verifierKey == null) - throw new SignatureException("not initialized for verifying"); - if (sig == null) - throw new SignatureException("no signature specified"); - int k = verifierKey.getModulus().bitLength(); - k = (k >>> 3) + ((k & 7) == 0 ? 0 : 1); - if (sig.length != k) - throw new SignatureException("signature is the wrong size (expecting " - + k + " bytes, got " + sig.length + ")"); - BigInteger ed = new BigInteger(1, sig); - byte[] eb = ed.modPow(verifierKey.getPublicExponent(), - verifierKey.getModulus()).toByteArray(); - - int i = 0; - if (eb[0] == 0x00) - { - for (i = 1; i < eb.length && eb[i] == 0x00; i++); - if (i == 1) - throw new SignatureException("wrong RSA padding"); - i--; - } - else if (eb[0] == 0x01) - { - for (i = 1; i < eb.length && eb[i] != 0x00; i++) - if (eb[i] != (byte) 0xFF) - throw new IllegalArgumentException("wrong RSA padding"); - } - else - throw new SignatureException("wrong RSA padding type"); - - byte[] d = new byte[eb.length-i-1]; - System.arraycopy(eb, i+1, d, 0, eb.length-i-1); - - DERReader der = new DERReader(d); - try - { - DERValue val = der.read(); - if (val.getTag() != DER.SEQUENCE) - throw new SignatureException("failed to parse DigestInfo"); - val = der.read(); - if (val.getTag() != DER.SEQUENCE) - throw new SignatureException("failed to parse DigestAlgorithmIdentifier"); - boolean sequenceIsBer = val.getLength() == 0; - val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new SignatureException("failed to parse object identifier"); - if (!val.getValue().equals(digestAlgorithm)) - throw new SignatureException("digest algorithms do not match"); - val = der.read(); - // We should never see parameters here, since they are never used. - if (val.getTag() != DER.NULL) - throw new SignatureException("cannot handle digest parameters"); - if (sequenceIsBer) - der.skip(1); // end-of-sequence byte. - val = der.read(); - if (val.getTag() != DER.OCTET_STRING) - throw new SignatureException("failed to parse Digest"); - return MessageDigest.isEqual(md.digest(), (byte[]) val.getValue()); - } - catch (IOException ioe) - { - throw new SignatureException(ioe.toString()); - } - } - - protected boolean engineVerify(byte[] sig, int off, int len) - throws SignatureException - { - if (sig == null || off < 0 || len < 0 || off+len > sig.length) - throw new SignatureException("illegal parameter"); - byte[] buf = new byte[len]; - System.arraycopy(sig, off, buf, 0, len); - return engineVerify(buf); - } -} diff --git a/libjava/gnu/java/security/provider/RSAKeyFactory.java b/libjava/gnu/java/security/provider/RSAKeyFactory.java deleted file mode 100644 index d13cbe510a1..00000000000 --- a/libjava/gnu/java/security/provider/RSAKeyFactory.java +++ /dev/null @@ -1,181 +0,0 @@ -/* RSAKeyFactory.java -- RSA key factory. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.KeyFactorySpi; -import java.security.PrivateKey; -import java.security.PublicKey; - -import java.security.interfaces.RSAPrivateCrtKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.RSAPrivateCrtKeySpec; -import java.security.spec.RSAPrivateKeySpec; -import java.security.spec.RSAPublicKeySpec; -import java.security.spec.X509EncodedKeySpec; - -public class RSAKeyFactory extends KeyFactorySpi -{ - - // Default constructor. - // ------------------------------------------------------------------------- - - // Instance methods. - // ------------------------------------------------------------------------- - - protected PrivateKey engineGeneratePrivate(KeySpec spec) - throws InvalidKeySpecException - { - if (spec instanceof RSAPrivateCrtKeySpec) - { - return new GnuRSAPrivateKey((RSAPrivateCrtKeySpec) spec); - } - if (spec instanceof RSAPrivateKeySpec) - { - return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec( - ((RSAPrivateKeySpec) spec).getModulus(), null, - ((RSAPrivateKeySpec) spec).getPrivateExponent(), null, - null, null, null, null)); - } - if (spec instanceof PKCS8EncodedKeySpec) - { - EncodedKeyFactory ekf = new EncodedKeyFactory(); - PrivateKey pk = ekf.engineGeneratePrivate(spec); - if (pk instanceof RSAPrivateKey) - return pk; - } - throw new InvalidKeySpecException(); - } - - protected PublicKey engineGeneratePublic(KeySpec spec) - throws InvalidKeySpecException - { - if (spec instanceof RSAPublicKeySpec) - { - return new GnuRSAPublicKey((RSAPublicKeySpec) spec); - } - if (spec instanceof X509EncodedKeySpec) - { - EncodedKeyFactory ekf = new EncodedKeyFactory(); - PublicKey pk = ekf.engineGeneratePublic(spec); - if (pk instanceof RSAPublicKey) - return pk; - } - throw new InvalidKeySpecException(); - } - - protected KeySpec engineGetKeySpec(Key key, Class keySpec) - throws InvalidKeySpecException - { - if (keySpec.isAssignableFrom(RSAPrivateCrtKeySpec.class) - && (key instanceof RSAPrivateCrtKey)) - { - return new RSAPrivateCrtKeySpec( - ((RSAPrivateCrtKey) key).getModulus(), - ((RSAPrivateCrtKey) key).getPublicExponent(), - ((RSAPrivateCrtKey) key).getPrivateExponent(), - ((RSAPrivateCrtKey) key).getPrimeP(), - ((RSAPrivateCrtKey) key).getPrimeQ(), - ((RSAPrivateCrtKey) key).getPrimeExponentP(), - ((RSAPrivateCrtKey) key).getPrimeExponentQ(), - ((RSAPrivateCrtKey) key).getCrtCoefficient()); - } - if (keySpec.isAssignableFrom(RSAPrivateKeySpec.class) - && (key instanceof RSAPrivateKey)) - { - return new RSAPrivateKeySpec( - ((RSAPrivateCrtKey) key).getModulus(), - ((RSAPrivateCrtKey) key).getPrivateExponent()); - } - if (keySpec.isAssignableFrom(RSAPublicKeySpec.class) - && (key instanceof RSAPublicKey)) - { - return new RSAPublicKeySpec( - ((RSAPrivateCrtKey) key).getModulus(), - ((RSAPrivateCrtKey) key).getPublicExponent()); - } - if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class) - && key.getFormat().equalsIgnoreCase("PKCS#8")) - { - return new PKCS8EncodedKeySpec(key.getEncoded()); - } - if (keySpec.isAssignableFrom(X509EncodedKeySpec.class) - && key.getFormat().equalsIgnoreCase("X.509")) - { - return new X509EncodedKeySpec(key.getEncoded()); - } - throw new InvalidKeySpecException(); - } - - protected Key engineTranslateKey(Key key) throws InvalidKeyException - { - if (key instanceof RSAPrivateCrtKey) - { - return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec( - ((RSAPrivateCrtKey) key).getModulus(), - ((RSAPrivateCrtKey) key).getPublicExponent(), - ((RSAPrivateCrtKey) key).getPrivateExponent(), - ((RSAPrivateCrtKey) key).getPrimeP(), - ((RSAPrivateCrtKey) key).getPrimeQ(), - ((RSAPrivateCrtKey) key).getPrimeExponentP(), - ((RSAPrivateCrtKey) key).getPrimeExponentQ(), - ((RSAPrivateCrtKey) key).getCrtCoefficient())); - } - if (key instanceof RSAPrivateKey) - { - return new GnuRSAPrivateKey(new RSAPrivateCrtKeySpec( - ((RSAPrivateKey) key).getModulus(), null, - ((RSAPrivateKey) key).getPrivateExponent(), null, - null, null, null, null)); - } - if (key instanceof RSAPublicKey) - { - return new GnuRSAPublicKey(new RSAPublicKeySpec( - ((RSAPrivateCrtKey) key).getModulus(), - ((RSAPrivateCrtKey) key).getPublicExponent())); - } - throw new InvalidKeyException(); - } -} diff --git a/libjava/gnu/java/security/provider/SHA.java b/libjava/gnu/java/security/provider/SHA.java deleted file mode 100644 index e3b09bc5603..00000000000 --- a/libjava/gnu/java/security/provider/SHA.java +++ /dev/null @@ -1,242 +0,0 @@ -/* SHA.java -- Class implementing the SHA-1 algorithm as specified in [1]. - Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.security.MessageDigest; - -/** - This class implements the SHA-1 algorithm as described in [1]. - - [1] Federal Information Processing Standards Publication 180-1. - Specifications for the Secure Hash Standard. April 17, 1995. - - @see java.security.MessageDigest -*/ -public class SHA extends MessageDigest implements Cloneable -{ - public SHA () - { - super("SHA"); - engineReset (); - } - - public int engineGetDigestLength() - { - return 20; - } - - public void engineUpdate (byte b) - { - int i = ((int)bytecount) & 0x3f; //wgs - int shift = (3 - i % 4) << 3; - int idx = i / 4; - - i = (int)b; - W[idx] = (W[idx] & ~(0xff << shift)) | ((i & 0xff) << shift); - - // if we've filled up a block, then process it - if (((++bytecount) & 0x3f) == 0) - munch (); - } - - // This could be optimized. - public void engineUpdate (byte bytes[], int off, int len) - { - if (len < 0) - throw new ArrayIndexOutOfBoundsException (); - - int end = off + len; - while (off < end) - engineUpdate (bytes[off++]); - } - - public void engineReset () - { - bytecount = 0; - // magic numbers from [1] p. 10. - H0 = 0x67452301; - H1 = 0xefcdab89; - H2 = 0x98badcfe; - H3 = 0x10325476; - H4 = 0xc3d2e1f0; - } - - public byte[] engineDigest () - { - long bitcount = bytecount << 3; - engineUpdate ((byte)0x80); // 10000000 in binary; the start of the padding - - // add the rest of the padding to fill this block out, but leave 8 - // bytes to put in the original bytecount - while ((bytecount & 0x3f) != 56) - engineUpdate ((byte)0); - - // add the length of the original, unpadded block to the end of - // the padding - W[14] = (int)(bitcount >>> 32); - W[15] = (int)bitcount; - bytecount += 8; - - // digest the fully padded block - munch (); - - byte[] result - = new byte[] {(byte)(H0 >>> 24), (byte)(H0 >>> 16), - (byte)(H0 >>> 8), (byte)H0, - (byte)(H1 >>> 24), (byte)(H1 >>> 16), - (byte)(H1 >>> 8), (byte)H1, - (byte)(H2 >>> 24), (byte)(H2 >>> 16), - (byte)(H2 >>> 8), (byte)H2, - (byte)(H3 >>> 24), (byte)(H3 >>> 16), - (byte)(H3 >>> 8), (byte)H3, - (byte)(H4 >>> 24), (byte)(H4 >>> 16), - (byte)(H4 >>> 8), (byte)H4}; - - engineReset (); - return result; - } - - // Process a single block. This is pretty much copied verbatim from - // [1] pp. 9, 10. - private void munch () - { - for (int t = 16; t < 80; ++ t) - { - int Wt = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]; - W[t] = Wt << 1 | Wt >>> 31; - } - - int A = H0; - int B = H1; - int C = H2; - int D = H3; - int E = H4; - - for (int t = 0; t < 20; ++ t) - { - int TEMP = (A << 5 | A >>> 27) // S^5(A) - + ((B & C) | (~B & D)) // f_t(B,C,D) - + E + W[t] - + 0x5a827999; // K_t - - E = D; - D = C; - C = B << 30 | B >>> 2; // S^30(B) - B = A; - A = TEMP; - } - - for (int t = 20; t < 40; ++ t) - { - int TEMP = (A << 5 | A >>> 27) // S^5(A) - + (B ^ C ^ D) // f_t(B,C,D) - + E + W[t] - + 0x6ed9eba1; // K_t - - E = D; - D = C; - C = B << 30 | B >>> 2; // S^30(B) - B = A; - A = TEMP; - } - - for (int t = 40; t < 60; ++ t) - { - int TEMP = (A << 5 | A >>> 27) // S^5(A) - + (B & C | B & D | C & D) // f_t(B,C,D) - + E + W[t] - + 0x8f1bbcdc; // K_t - - E = D; - D = C; - C = B << 30 | B >>> 2; // S^30(B) - B = A; - A = TEMP; - } - - for (int t = 60; t < 80; ++ t) - { - int TEMP = (A << 5 | A >>> 27) // S^5(A) - + (B ^ C ^ D) // f_t(B,C,D) - + E + W[t] - + 0xca62c1d6; // K_t - - E = D; - D = C; - C = B << 30 | B >>> 2; // S^30(B) - B = A; - A = TEMP; - } - - H0 += A; - H1 += B; - H2 += C; - H3 += D; - H4 += E; - - // Reset W by clearing it. - for (int t = 0; t < 80; ++ t) - W[t] = 0; - } - - public Object clone () - { - return new SHA (this); - } - - private SHA (SHA copy) - { - this (); - bytecount = copy.bytecount; - H0 = copy.H0; - H1 = copy.H1; - H2 = copy.H2; - H3 = copy.H3; - H4 = copy.H4; - System.arraycopy (copy.W, 0, W, 0, 80); - } - - private final int W[] = new int[80]; - private long bytecount; - private int H0; - private int H1; - private int H2; - private int H3; - private int H4; -} diff --git a/libjava/gnu/java/security/provider/SHA1PRNG.java b/libjava/gnu/java/security/provider/SHA1PRNG.java deleted file mode 100644 index 7f2784881fb..00000000000 --- a/libjava/gnu/java/security/provider/SHA1PRNG.java +++ /dev/null @@ -1,126 +0,0 @@ -/* SHA1PRNG.java --- Secure Random SPI SHA1PRNG - Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import java.io.Serializable; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandomSpi; -import java.util.Random; - -public class SHA1PRNG extends SecureRandomSpi implements Serializable -{ - MessageDigest digest; - byte seed[]; - byte data[]; - int seedpos; - int datapos; - private boolean seeded = false; // set to true when we seed this - - public SHA1PRNG() - { - try { - digest = MessageDigest.getInstance("SHA"); - } catch ( NoSuchAlgorithmException nsae) { -// System.out.println("Failed to find SHA Message Digest: " + nsae); -// nsae.printStackTrace(); - throw new InternalError ("no SHA implementation found"); - } - - seed = new byte[20]; - seedpos = 0; - data = new byte[40]; - datapos = 20; // try to force hashing a first block - } - - public void engineSetSeed(byte[] seed) - { - for(int i = 0; i < seed.length; i++) - this.seed[seedpos++ % 20] ^= seed[i]; - seedpos %= 20; - - } - - public void engineNextBytes(byte[] bytes) - { - ensureIsSeeded (); - int loc = 0; - while (loc < bytes.length) - { - int copy = Math.min (bytes.length - loc, 20 - datapos); - - if (copy > 0) - { - System.arraycopy (data, datapos, bytes, loc, copy); - datapos += copy; - loc += copy; - } - else - { - // No data ready for copying, so refill our buffer. - System.arraycopy( seed, 0, data, 20, 20); - byte[] digestdata = digest.digest( data ); - System.arraycopy( digestdata, 0, data, 0, 20); - datapos = 0; - } - } - } - - public byte[] engineGenerateSeed(int numBytes) - { - byte tmp[] = new byte[numBytes]; - - engineNextBytes( tmp ); - return tmp; - } - - private void ensureIsSeeded() - { - if (!seeded) - { - new Random(0L).nextBytes(seed); - - byte[] digestdata = digest.digest(data); - System.arraycopy(digestdata, 0, data, 0, 20); - - seeded = true; - } - } - -} diff --git a/libjava/gnu/java/security/provider/SHA1withRSA.java b/libjava/gnu/java/security/provider/SHA1withRSA.java deleted file mode 100644 index 0e63fdeeb52..00000000000 --- a/libjava/gnu/java/security/provider/SHA1withRSA.java +++ /dev/null @@ -1,61 +0,0 @@ -/* SHA1withRSA.java -- SHA-1 with RSA encryption signatures. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.security.OID; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class SHA1withRSA extends RSA -{ - - // Constant. - // ------------------------------------------------------------------------- - - private static final OID SHA1 = new OID("1.3.14.3.2.26"); - - // Constructor. - // ------------------------------------------------------------------------- - - public SHA1withRSA() throws NoSuchAlgorithmException - { - super(MessageDigest.getInstance("SHA-160"), SHA1); - } -} diff --git a/libjava/gnu/java/security/provider/X509CertificateFactory.java b/libjava/gnu/java/security/provider/X509CertificateFactory.java deleted file mode 100644 index 1a415eabb05..00000000000 --- a/libjava/gnu/java/security/provider/X509CertificateFactory.java +++ /dev/null @@ -1,305 +0,0 @@ -/* X509CertificateFactory.java -- generates X.509 certificates. - Copyright (C) 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.provider; - -import gnu.java.io.Base64InputStream; -import gnu.java.security.x509.X509CRL; -import gnu.java.security.x509.X509CertPath; -import gnu.java.security.x509.X509Certificate; - -import java.io.BufferedInputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.security.cert.CRL; -import java.security.cert.CRLException; -import java.security.cert.CertPath; -import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactorySpi; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -public class X509CertificateFactory extends CertificateFactorySpi -{ - - // Constants. - // ------------------------------------------------------------------------ - - public static final String BEGIN_CERTIFICATE = "-----BEGIN CERTIFICATE-----"; - public static final String END_CERTIFICATE = "-----END CERTIFICATE-----"; - public static final String BEGIN_X509_CRL = "-----BEGIN X509 CRL-----"; - public static final String END_X509_CRL = "-----END X509 CRL-----"; - - // Constructors. - // ------------------------------------------------------------------------ - - public X509CertificateFactory() - { - super(); - } - - // Instance methods. - // ------------------------------------------------------------------------ - - public Certificate engineGenerateCertificate(InputStream inStream) - throws CertificateException - { - try - { - return generateCert(inStream); - } - catch (IOException ioe) - { - CertificateException ce = new CertificateException(ioe.getMessage()); - ce.initCause (ioe); - throw ce; - } - } - - public Collection engineGenerateCertificates(InputStream inStream) - throws CertificateException - { - LinkedList certs = new LinkedList(); - while (true) - { - try - { - certs.add(generateCert(inStream)); - } - catch (EOFException eof) - { - break; - } - catch (IOException ioe) - { - CertificateException ce = new CertificateException(ioe.getMessage()); - ce.initCause (ioe); - throw ce; - } - } - return certs; - } - - public CRL engineGenerateCRL(InputStream inStream) throws CRLException - { - try - { - return generateCRL(inStream); - } - catch (IOException ioe) - { - CRLException crle = new CRLException(ioe.getMessage()); - crle.initCause (ioe); - throw crle; - } - } - - public Collection engineGenerateCRLs(InputStream inStream) - throws CRLException - { - LinkedList crls = new LinkedList(); - while (true) - { - try - { - crls.add(generateCRL(inStream)); - } - catch (EOFException eof) - { - break; - } - catch (IOException ioe) - { - CRLException crle = new CRLException(ioe.getMessage()); - crle.initCause (ioe); - throw crle; - } - } - return crls; - } - - public CertPath engineGenerateCertPath(List certs) - { - return new X509CertPath(certs); - } - - public CertPath engineGenerateCertPath(InputStream in) - throws CertificateEncodingException - { - return new X509CertPath(in); - } - - public CertPath engineGenerateCertPath(InputStream in, String encoding) - throws CertificateEncodingException - { - return new X509CertPath(in, encoding); - } - - public Iterator engineGetCertPathEncodings() - { - return X509CertPath.ENCODINGS.iterator(); - } - - // Own methods. - // ------------------------------------------------------------------------ - - private X509Certificate generateCert(InputStream inStream) - throws IOException, CertificateException - { - if (inStream == null) - throw new CertificateException("missing input stream"); - if (!inStream.markSupported()) - inStream = new BufferedInputStream(inStream, 8192); - inStream.mark(20); - int i = inStream.read(); - if (i == -1) - throw new EOFException(); - - // If the input is in binary DER format, the first byte MUST be - // 0x30, which stands for the ASN.1 [UNIVERSAL 16], which is the - // UNIVERSAL SEQUENCE, with the CONSTRUCTED bit (0x20) set. - // - // So if we do not see 0x30 here we will assume it is in Base-64. - if (i != 0x30) - { - inStream.reset(); - StringBuffer line = new StringBuffer(80); - do - { - line.setLength(0); - do - { - i = inStream.read(); - if (i == -1) - throw new EOFException(); - if (i != '\n' && i != '\r') - line.append((char) i); - } - while (i != '\n' && i != '\r'); - } - while (!line.toString().equals(BEGIN_CERTIFICATE)); - X509Certificate ret = new X509Certificate( - new BufferedInputStream(new Base64InputStream(inStream), 8192)); - line.setLength(0); - line.append('-'); // Base64InputStream will eat this. - do - { - i = inStream.read(); - if (i == -1) - throw new EOFException(); - if (i != '\n' && i != '\r') - line.append((char) i); - } - while (i != '\n' && i != '\r'); - // XXX ??? - if (!line.toString().equals(END_CERTIFICATE)) - throw new CertificateException("no end-of-certificate marker"); - return ret; - } - else - { - inStream.reset(); - return new X509Certificate(inStream); - } - } - - private X509CRL generateCRL(InputStream inStream) - throws IOException, CRLException - { - if (inStream == null) - throw new CRLException("missing input stream"); - if (!inStream.markSupported()) - inStream = new BufferedInputStream(inStream, 8192); - inStream.mark(20); - int i = inStream.read(); - if (i == -1) - throw new EOFException(); - - // If the input is in binary DER format, the first byte MUST be - // 0x30, which stands for the ASN.1 [UNIVERSAL 16], which is the - // UNIVERSAL SEQUENCE, with the CONSTRUCTED bit (0x20) set. - // - // So if we do not see 0x30 here we will assume it is in Base-64. - if (i != 0x30) - { - inStream.reset(); - StringBuffer line = new StringBuffer(80); - do - { - line.setLength(0); - do - { - i = inStream.read(); - if (i == -1) - throw new EOFException(); - if (i != '\n' && i != '\r') - line.append((char) i); - } - while (i != '\n' && i != '\r'); - } - while (!line.toString().startsWith(BEGIN_X509_CRL)); - X509CRL ret = new X509CRL( - new BufferedInputStream(new Base64InputStream(inStream), 8192)); - line.setLength(0); - line.append('-'); // Base64InputStream will eat this. - do - { - i = inStream.read(); - if (i == -1) - throw new EOFException(); - if (i != '\n' && i != '\r') - line.append((char) i); - } - while (i != '\n' && i != '\r'); - // XXX ??? - if (!line.toString().startsWith(END_X509_CRL)) - throw new CRLException("no end-of-CRL marker"); - return ret; - } - else - { - inStream.reset(); - return new X509CRL(inStream); - } - } -} diff --git a/libjava/gnu/java/security/util/Prime.java b/libjava/gnu/java/security/util/Prime.java deleted file mode 100644 index e493ce67503..00000000000 --- a/libjava/gnu/java/security/util/Prime.java +++ /dev/null @@ -1,164 +0,0 @@ -/* Prime.java --- Prime number generation utilities - Copyright (C) 1999, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.util; -import java.math.BigInteger; -import java.util.Random; -//import java.security.SecureRandom; - -public final class Prime -{ - - /* - See IEEE P1363 A.15.4 (10/05/98 Draft) - */ - public static BigInteger generateRandomPrime( int pmin, int pmax, BigInteger f ) - { - BigInteger d; - - //Step 1 - generate prime - BigInteger p = new BigInteger( (pmax + pmin)/2, new Random() ); - if( p.compareTo( BigInteger.valueOf( 1 ).shiftLeft( pmin ) ) <= 0 ) - { - p = p.add( BigInteger.valueOf( 1 ).shiftLeft( pmin ).subtract( p ) ); - } - - //Step 2 - test for even - if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) - p = p.add( BigInteger.valueOf( 1 ) ); - - for(;;) - { - //Step 3 - if( p.compareTo( BigInteger.valueOf( 1 ).shiftLeft( pmax)) > 0) - { - //Step 3.1 - p = p.subtract( BigInteger.valueOf( 1 ).shiftLeft( pmax) ); - p = p.add( BigInteger.valueOf( 1 ).shiftLeft( pmin) ); - p = p.subtract( BigInteger.valueOf( 1 ) ); - - //Step 3.2 - // put step 2 code here so looping code is cleaner - //Step 2 - test for even - if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) - p = p.add( BigInteger.valueOf( 1 ) ); - continue; - } - - //Step 4 - compute GCD - d = p.subtract( BigInteger.valueOf(1) ); - d = d.gcd( f ); - - //Step 5 - test d - if( d.compareTo( BigInteger.valueOf( 1 ) ) == 0) - { - //Step 5.1 - test primality - if( p.isProbablePrime( 1 ) == true ) - { - //Step 5.2; - return p; - } - } - //Step 6 - p = p.add( BigInteger.valueOf( 2 ) ); - - //Step 7 - } - } - - - /* - See IEEE P1363 A.15.5 (10/05/98 Draft) - */ - public static BigInteger generateRandomPrime( BigInteger r, BigInteger a, int pmin, int pmax, BigInteger f ) - { - BigInteger d, w; - - //Step 1 - generate prime - BigInteger p = new BigInteger( (pmax + pmin)/2, new Random() ); - - steptwo:{ //Step 2 - w = p.mod( r.multiply( BigInteger.valueOf(2) )); - - //Step 3 - p = p.add( r.multiply( BigInteger.valueOf(2) ) ); - p = p.subtract( w ); - p = p.add(a); - - //Step 4 - test for even - if( p.mod( BigInteger.valueOf(2) ).compareTo( BigInteger.valueOf( 0 )) == 0) - p = p.add( r ); - - for(;;) - { - //Step 5 - if( p.compareTo( BigInteger.valueOf( 1 ).shiftLeft( pmax)) > 0) - { - //Step 5.1 - p = p.subtract( BigInteger.valueOf( 1 ).shiftLeft( pmax) ); - p = p.add( BigInteger.valueOf( 1 ).shiftLeft( pmin) ); - p = p.subtract( BigInteger.valueOf( 1 ) ); - - //Step 5.2 - goto to Step 2 - break steptwo; - } - - //Step 6 - d = p.subtract( BigInteger.valueOf(1) ); - d = d.gcd( f ); - - //Step 7 - test d - if( d.compareTo( BigInteger.valueOf( 1 ) ) == 0) - { - //Step 7.1 - test primality - if( p.isProbablePrime( 1 ) == true ) - { - //Step 7.2; - return p; - } - } - //Step 8 - p = p.add( r.multiply( BigInteger.valueOf(2) ) ); - - //Step 9 - } - } - //Should never reach here but makes the compiler happy - return BigInteger.valueOf(0); - } -} diff --git a/libjava/gnu/java/security/x509/GnuPKIExtension.java b/libjava/gnu/java/security/x509/GnuPKIExtension.java deleted file mode 100644 index 8e74b8b24ac..00000000000 --- a/libjava/gnu/java/security/x509/GnuPKIExtension.java +++ /dev/null @@ -1,59 +0,0 @@ -/* GnuPKIExtension.java -- interface for GNU PKI extensions. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.x509.ext.Extension; - -import java.security.cert.X509Extension; -import java.util.Collection; - -public interface GnuPKIExtension extends X509Extension -{ - - /** - * Returns the extension object for the given object identifier. - * - * @param oid The OID of the extension to get. - * @return The extension, or null if there is no such extension. - */ - Extension getExtension(OID oid); - - Collection getExtensions(); -} diff --git a/libjava/gnu/java/security/x509/PolicyNodeImpl.java b/libjava/gnu/java/security/x509/PolicyNodeImpl.java deleted file mode 100644 index 72cb4a9ea91..00000000000 --- a/libjava/gnu/java/security/x509/PolicyNodeImpl.java +++ /dev/null @@ -1,214 +0,0 @@ -/* PolicyNodeImpl.java -- An implementation of a policy tree node. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import java.security.cert.PolicyNode; -import java.security.cert.PolicyQualifierInfo; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public final class PolicyNodeImpl implements PolicyNode -{ - - // Fields. - // ------------------------------------------------------------------------- - - private String policy; - private final Set expectedPolicies; - private final Set qualifiers; - private final Set children; - private PolicyNodeImpl parent; - private int depth; - private boolean critical; - private boolean readOnly; - - // Constructors. - // ------------------------------------------------------------------------- - - public PolicyNodeImpl() - { - expectedPolicies = new HashSet(); - qualifiers = new HashSet(); - children = new HashSet(); - readOnly = false; - critical = false; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public void addChild(PolicyNodeImpl node) - { - if (readOnly) - throw new IllegalStateException("read only"); - if (node.getParent() != null) - throw new IllegalStateException("already a child node"); - node.parent = this; - node.setDepth(depth + 1); - children.add(node); - } - - public Iterator getChildren() - { - return Collections.unmodifiableSet(children).iterator(); - } - - public int getDepth() - { - return depth; - } - - public void setDepth(int depth) - { - if (readOnly) - throw new IllegalStateException("read only"); - this.depth = depth; - } - - public void addAllExpectedPolicies(Set policies) - { - if (readOnly) - throw new IllegalStateException("read only"); - expectedPolicies.addAll(policies); - } - - public void addExpectedPolicy(String policy) - { - if (readOnly) - throw new IllegalStateException("read only"); - expectedPolicies.add(policy); - } - - public Set getExpectedPolicies() - { - return Collections.unmodifiableSet(expectedPolicies); - } - - public PolicyNode getParent() - { - return parent; - } - - public void addAllPolicyQualifiers (Collection qualifiers) - { - for (Iterator it = qualifiers.iterator(); it.hasNext(); ) - { - if (!(it.next() instanceof PolicyQualifierInfo)) - throw new IllegalArgumentException ("can only add PolicyQualifierInfos"); - } - qualifiers.addAll (qualifiers); - } - - public void addPolicyQualifier (PolicyQualifierInfo qualifier) - { - if (readOnly) - throw new IllegalStateException("read only"); - qualifiers.add(qualifier); - } - - public Set getPolicyQualifiers() - { - return Collections.unmodifiableSet(qualifiers); - } - - public String getValidPolicy() - { - return policy; - } - - public void setValidPolicy(String policy) - { - if (readOnly) - throw new IllegalStateException("read only"); - this.policy = policy; - } - - public boolean isCritical() - { - return critical; - } - - public void setCritical(boolean critical) - { - if (readOnly) - throw new IllegalStateException("read only"); - this.critical = critical; - } - - public void setReadOnly() - { - if (readOnly) - return; - readOnly = true; - for (Iterator it = getChildren(); it.hasNext(); ) - ((PolicyNodeImpl) it.next()).setReadOnly(); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < depth; i++) - buf.append(" "); - buf.append("("); - buf.append(PolicyNodeImpl.class.getName()); - buf.append(" (oid "); - buf.append(policy); - buf.append(") (depth "); - buf.append(depth); - buf.append(") (qualifiers "); - buf.append(qualifiers); - buf.append(") (critical "); - buf.append(critical); - buf.append(") (expectedPolicies "); - buf.append(expectedPolicies); - buf.append(") (children ("); - final String nl = System.getProperty("line.separator"); - for (Iterator it = getChildren(); it.hasNext(); ) - { - buf.append(nl); - buf.append(it.next().toString()); - } - buf.append(")))"); - return buf.toString(); - } -} diff --git a/libjava/gnu/java/security/x509/Util.java b/libjava/gnu/java/security/x509/Util.java deleted file mode 100644 index d27392026f8..00000000000 --- a/libjava/gnu/java/security/x509/Util.java +++ /dev/null @@ -1,202 +0,0 @@ -/* Util.java -- Miscellaneous utility methods. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -/** - * A collection of useful class methods. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public final class Util -{ - - // Constants. - // ------------------------------------------------------------------------- - - public static final String HEX = "0123456789abcdef"; - - // Class methods. - // ------------------------------------------------------------------------- - - /** - * Convert a byte array to a hexadecimal string, as though it were a - * big-endian arbitrarily-sized integer. - * - * @param buf The bytes to format. - * @param off The offset to start at. - * @param len The number of bytes to format. - * @return A hexadecimal representation of the specified bytes. - */ - public static String toHexString(byte[] buf, int off, int len) - { - StringBuffer str = new StringBuffer(); - for (int i = 0; i < len; i++) - { - str.append(HEX.charAt(buf[i+off] >>> 4 & 0x0F)); - str.append(HEX.charAt(buf[i+off] & 0x0F)); - } - return str.toString(); - } - - /** - * See {@link #toHexString(byte[],int,int)}. - */ - public static String toHexString(byte[] buf) - { - return Util.toHexString(buf, 0, buf.length); - } - - /** - * Convert a byte array to a hexadecimal string, separating octets - * with the given character. - * - * @param buf The bytes to format. - * @param off The offset to start at. - * @param len The number of bytes to format. - * @param sep The character to insert between octets. - * @return A hexadecimal representation of the specified bytes. - */ - public static String toHexString(byte[] buf, int off, int len, char sep) - { - StringBuffer str = new StringBuffer(); - for (int i = 0; i < len; i++) - { - str.append(HEX.charAt(buf[i+off] >>> 4 & 0x0F)); - str.append(HEX.charAt(buf[i+off] & 0x0F)); - if (i < len - 1) - str.append(sep); - } - return str.toString(); - } - - /** - * See {@link #toHexString(byte[],int,int,char)}. - */ - public static String toHexString(byte[] buf, char sep) - { - return Util.toHexString(buf, 0, buf.length, sep); - } - - /** - * Create a representation of the given byte array similar to the - * output of `hexdump -C', which is - * - * <p><pre>OFFSET SIXTEEN-BYTES-IN-HEX PRINTABLE-BYTES</pre> - * - * <p>The printable bytes show up as-is if they are printable and - * not a newline character, otherwise showing as '.'. - * - * @param buf The bytes to format. - * @param off The offset to start at. - * @param len The number of bytes to encode. - * @return The formatted string. - */ - public static String hexDump(byte[] buf, int off, int len, String prefix) - { - String nl = System.getProperty("line.separator"); - StringBuffer str = new StringBuffer(); - int i = 0; - while (i < len) - { - str.append(prefix); - str.append(Util.formatInt(i+off, 16, 8)); - str.append(" "); - String s = Util.toHexString(buf, i+off, Math.min(16, len-i), ' '); - str.append(s); - for (int j = 56 - (56 - s.length()); j < 56; j++) - str.append(" "); - for (int j = 0; j < Math.min(16, len - i); j++) - { - if ((buf[i+off+j] & 0xFF) < 0x20 || (buf[i+off+j] & 0xFF) > 0x7E) - str.append('.'); - else - str.append((char) (buf[i+off+j] & 0xFF)); - } - str.append(nl); - i += 16; - } - return str.toString(); - } - - /** - * See {@link #hexDump(byte[],int,int)}. - */ - public static String hexDump(byte[] buf, String prefix) - { - return hexDump(buf, 0, buf.length, prefix); - } - - /** - * Format an integer into the specified radix, zero-filled. - * - * @param i The integer to format. - * @param radix The radix to encode to. - * @param len The target length of the string. The string is - * zero-padded to this length, but may be longer. - * @return The formatted integer. - */ - public static String formatInt(int i, int radix, int len) - { - String s = Integer.toString(i, radix); - StringBuffer buf = new StringBuffer(); - for (int j = 0; j < len - s.length(); j++) - buf.append("0"); - buf.append(s); - return buf.toString(); - } - - /** - * Convert a hexadecimal string into its byte representation. - * - * @param hex The hexadecimal string. - * @return The converted bytes. - */ - public static byte[] toByteArray(String hex) - { - hex = hex.toLowerCase(); - byte[] buf = new byte[hex.length() / 2]; - int j = 0; - for (int i = 0; i < buf.length; i++) - { - buf[i] = (byte) ((Character.digit(hex.charAt(j++), 16) << 4) | - Character.digit(hex.charAt(j++), 16)); - } - return buf; - } -} diff --git a/libjava/gnu/java/security/x509/X500DistinguishedName.java b/libjava/gnu/java/security/x509/X500DistinguishedName.java deleted file mode 100644 index daf746f5dc5..00000000000 --- a/libjava/gnu/java/security/x509/X500DistinguishedName.java +++ /dev/null @@ -1,548 +0,0 @@ -/* X500DistinguishedName.java -- X.500 distinguished name. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class X500DistinguishedName implements Principal -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID CN = new OID("2.5.4.3"); - public static final OID C = new OID("2.5.4.6"); - public static final OID L = new OID("2.5.4.7"); - public static final OID ST = new OID("2.5.4.8"); - public static final OID STREET = new OID("2.5.4.9"); - public static final OID O = new OID("2.5.4.10"); - public static final OID OU = new OID("2.5.4.11"); - public static final OID T = new OID("2.5.4.12"); - public static final OID DNQ = new OID("2.5.4.46"); - public static final OID NAME = new OID("2.5.4.41"); - public static final OID GIVENNAME = new OID("2.5.4.42"); - public static final OID INITIALS = new OID("2.5.4.43"); - public static final OID GENERATION = new OID("2.5.4.44"); - public static final OID EMAIL = new OID("1.2.840.113549.1.9.1"); - public static final OID DC = new OID("0.9.2342.19200300.100.1.25"); - public static final OID UID = new OID("0.9.2342.19200300.100.1.1"); - - private List components; - private Map currentRdn; - private boolean fixed; - private String stringRep; - private byte[] encoded; - - // Constructors. - // ------------------------------------------------------------------------- - - public X500DistinguishedName() - { - components = new LinkedList(); - currentRdn = new LinkedHashMap(); - components.add(currentRdn); - } - - public X500DistinguishedName(String name) - { - this(); - try - { - parseString(name); - } - catch (IOException ioe) - { - throw new IllegalArgumentException(ioe.toString()); - } - } - - public X500DistinguishedName(byte[] encoded) throws IOException - { - this(); - parseDer(new DERReader(encoded)); - } - - public X500DistinguishedName(InputStream encoded) throws IOException - { - this(); - parseDer(new DERReader(encoded)); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public String getName() - { - return toString(); - } - - public void newRelativeDistinguishedName() - { - if (fixed || currentRdn.isEmpty()) return; - currentRdn = new LinkedHashMap(); - components.add(currentRdn); - } - - public int size() - { - return components.size(); - } - - public int countComponents() - { - int count = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) - { - count += ((Map) it.next()).size(); - } - return count; - } - - public boolean containsComponent(OID oid, String value) - { - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map rdn = (Map) it.next(); - String s = (String) rdn.get(oid); - if (s == null) - continue; - if (compressWS(value).equalsIgnoreCase(compressWS(s))) - return true; - } - return false; - } - - public String getComponent(OID oid) - { - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map rdn = (Map) it.next(); - if (rdn.containsKey(oid)) - return (String) rdn.get(oid); - } - return null; - } - - public String getComponent(OID oid, int rdn) - { - if (rdn >= size()) - return null; - return (String) ((Map) components.get(rdn)).get(oid); - } - - public void putComponent(OID oid, String value) - { - currentRdn.put(oid, value); - } - - public void putComponent(String name, String value) - { - name = name.trim().toLowerCase(); - if (name.equals("cn")) - putComponent(CN, value); - else if (name.equals("c")) - putComponent(C, value); - else if (name.equals("l")) - putComponent(L, value); - else if (name.equals("street")) - putComponent(STREET, value); - else if (name.equals("st")) - putComponent(ST, value); - else if (name.equals("t")) - putComponent(T, value); - else if (name.equals("dnq")) - putComponent(DNQ, value); - else if (name.equals("name")) - putComponent(NAME, value); - else if (name.equals("givenname")) - putComponent(GIVENNAME, value); - else if (name.equals("initials")) - putComponent(INITIALS, value); - else if (name.equals("generation")) - putComponent(GENERATION, value); - else if (name.equals("email")) - putComponent(EMAIL, value); - else if (name.equals("dc")) - putComponent(DC, value); - else if (name.equals("uid")) - putComponent(UID, value); - else - putComponent(new OID(name), value); - } - - public void setUnmodifiable() - { - if (fixed) return; - fixed = true; - List newComps = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map rdn = (Map) it.next(); - rdn = Collections.unmodifiableMap(rdn); - newComps.add(rdn); - } - components = Collections.unmodifiableList(newComps); - currentRdn = Collections.EMPTY_MAP; - } - - public int hashCode() - { - int sum = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) - { - Map.Entry e = (Map.Entry) it2.next(); - sum += e.getKey().hashCode(); - sum += e.getValue().hashCode(); - } - } - return sum; - } - - public boolean equals(Object o) - { - if (!(o instanceof X500DistinguishedName)) - return false; - if (size() != ((X500DistinguishedName) o).size()) - return false; - for (int i = 0; i < size(); i++) - { - Map m = (Map) components.get(i); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) - { - Map.Entry e = (Map.Entry) it2.next(); - OID oid = (OID) e.getKey(); - String v1 = (String) e.getValue(); - String v2 = ((X500DistinguishedName) o).getComponent(oid, i); - if (!compressWS(v1).equalsIgnoreCase(compressWS(v2))) - return false; - } - } - return true; - } - - public String toString() - { - if (fixed && stringRep != null) - return stringRep; - StringBuffer str = new StringBuffer(); - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) - { - Map.Entry entry = (Map.Entry) it2.next(); - OID oid = (OID) entry.getKey(); - String value = (String) entry.getValue(); - if (oid.equals(CN)) - str.append("CN"); - else if (oid.equals(C)) - str.append("C"); - else if (oid.equals(L)) - str.append("L"); - else if (oid.equals(ST)) - str.append("ST"); - else if (oid.equals(STREET)) - str.append("STREET"); - else if (oid.equals(O)) - str.append("O"); - else if (oid.equals(OU)) - str.append("OU"); - else if (oid.equals(T)) - str.append("T"); - else if (oid.equals(DNQ)) - str.append("DNQ"); - else if (oid.equals(NAME)) - str.append("NAME"); - else - str.append(oid.toString()); - str.append('='); - str.append(value); - if (it2.hasNext()) - str.append("+"); - } - if (it.hasNext()) - str.append(','); - } - return (stringRep = str.toString()); - } - - public byte[] getDer() - { - if (fixed && encoded != null) - return (byte[]) encoded.clone(); - ArrayList name = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) - { - Map m = (Map) it.next(); - if (m.isEmpty()) - continue; - Set rdn = new HashSet(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) - { - Map.Entry e = (Map.Entry) it.next(); - ArrayList atav = new ArrayList(2); - atav.add(new DERValue(DER.OBJECT_IDENTIFIER, e.getKey())); - atav.add(new DERValue(DER.UTF8_STRING, e.getValue())); - rdn.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, atav)); - } - name.add(new DERValue(DER.SET|DER.CONSTRUCTED, rdn)); - } - DERValue val = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, name); - return (byte[]) (encoded = val.getEncoded()).clone(); - } - - // Own methods. - // ------------------------------------------------------------------------- - - private int sep; - - private void parseString(String str) throws IOException - { - Reader in = new StringReader(str); - while (true) - { - String key = readAttributeType(in); - if (key == null) - break; - String value = readAttributeValue(in); - putComponent(key, value); - if (sep == ',') - newRelativeDistinguishedName(); - } - setUnmodifiable(); - } - - private String readAttributeType(Reader in) throws IOException - { - StringBuffer buf = new StringBuffer(); - int ch; - while ((ch = in.read()) != '=') - { - if (ch == -1) - { - if (buf.length() > 0) - throw new EOFException(); - return null; - } - if (ch > 127) - throw new IOException("Invalid char: " + (char) ch); - if (Character.isLetterOrDigit((char) ch) || ch == '-' || ch == '.') - buf.append((char) ch); - else - throw new IOException("Invalid char: " + (char) ch); - } - return buf.toString(); - } - - private String readAttributeValue(Reader in) throws IOException - { - StringBuffer buf = new StringBuffer(); - int ch = in.read(); - if (ch == '#') - { - while (true) - { - ch = in.read(); - if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') - || Character.isDigit((char) ch)) - buf.append((char) ch); - else if (ch == '+' || ch == ',') - { - sep = ch; - String hex = buf.toString(); - return new String(Util.toByteArray(hex)); - } - else - throw new IOException("illegal character: " + (char) ch); - } - } - else if (ch == '"') - { - while (true) - { - ch = in.read(); - if (ch == '"') - break; - else if (ch == '\\') - { - ch = in.read(); - if (ch == -1) - throw new EOFException(); - if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') - || Character.isDigit((char) ch)) - { - int i = Character.digit((char) ch, 16) << 4; - ch = in.read(); - if (!(('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') - || Character.isDigit((char) ch))) - throw new IOException("illegal hex char"); - i |= Character.digit((char) ch, 16); - buf.append((char) i); - } - else - buf.append((char) ch); - } - else - buf.append((char) ch); - } - sep = in.read(); - if (sep != '+' || sep != ',') - throw new IOException("illegal character: " + (char) ch); - return buf.toString(); - } - else - { - while (true) - { - switch (ch) - { - case '+': - case ',': - sep = ch; - return buf.toString(); - case '\\': - ch = in.read(); - if (ch == -1) - throw new EOFException(); - if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') - || Character.isDigit((char) ch)) - { - int i = Character.digit((char) ch, 16) << 4; - ch = in.read(); - if (!(('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') - || Character.isDigit((char) ch))) - throw new IOException("illegal hex char"); - i |= Character.digit((char) ch, 16); - buf.append((char) i); - } - else - buf.append((char) ch); - break; - case '=': - case '<': - case '>': - case '#': - case ';': - throw new IOException("illegal character: " + (char) ch); - case -1: - throw new EOFException(); - default: - buf.append((char) ch); - } - } - } - } - - private void parseDer(DERReader der) throws IOException - { - DERValue name = der.read(); - if (!name.isConstructed()) - throw new IOException("malformed Name"); - encoded = name.getEncoded(); - int len = 0; - while (len < name.getLength()) - { - DERValue rdn = der.read(); - if (!rdn.isConstructed()) - throw new IOException("badly formed RDNSequence"); - int len2 = 0; - while (len2 < rdn.getLength()) - { - DERValue atav = der.read(); - if (!atav.isConstructed()) - throw new IOException("badly formed AttributeTypeAndValue"); - DERValue val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("badly formed AttributeTypeAndValue"); - OID oid = (OID) val.getValue(); - val = der.read(); - if (!(val.getValue() instanceof String)) - throw new IOException("badly formed AttributeTypeAndValue"); - String value = (String) val.getValue(); - putComponent(oid, value); - len2 += atav.getEncodedLength(); - } - len += rdn.getEncodedLength(); - if (len < name.getLength()) - newRelativeDistinguishedName(); - } - setUnmodifiable(); - } - - private static String compressWS(String str) - { - StringBuffer buf = new StringBuffer(); - char lastChar = 0; - for (int i = 0; i < str.length(); i++) - { - char c = str.charAt(i); - if (Character.isWhitespace(c)) - { - if (!Character.isWhitespace(lastChar)) - buf.append(' '); - } - else - buf.append(c); - lastChar = c; - } - return buf.toString().trim(); - } -} diff --git a/libjava/gnu/java/security/x509/X509CRL.java b/libjava/gnu/java/security/x509/X509CRL.java deleted file mode 100644 index 5b2d3b14130..00000000000 --- a/libjava/gnu/java/security/x509/X509CRL.java +++ /dev/null @@ -1,476 +0,0 @@ -/* X509CRL.java -- X.509 certificate revocation list. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.ext.Extension; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Principal; -import java.security.PublicKey; -import java.security.Signature; -import java.security.SignatureException; -import java.security.cert.CRLException; -import java.security.cert.Certificate; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - * X.509 certificate revocation lists. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class X509CRL extends java.security.cert.X509CRL - implements GnuPKIExtension -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - if (DEBUG) - { - System.err.print(">> X509CRL: "); - System.err.println(msg); - } - } - - private static final OID ID_DSA = new OID("1.2.840.10040.4.1"); - private static final OID ID_DSA_WITH_SHA1 = new OID("1.2.840.10040.4.3"); - private static final OID ID_RSA = new OID("1.2.840.113549.1.1.1"); - private static final OID ID_RSA_WITH_MD2 = new OID("1.2.840.113549.1.1.2"); - private static final OID ID_RSA_WITH_MD5 = new OID("1.2.840.113549.1.1.4"); - private static final OID ID_RSA_WITH_SHA1 = new OID("1.2.840.113549.1.1.5"); - - private byte[] encoded; - - private byte[] tbsCRLBytes; - private int version; - private OID algId; - private byte[] algParams; - private Date thisUpdate; - private Date nextUpdate; - private X500DistinguishedName issuerDN; - private HashMap revokedCerts; - private HashMap extensions; - - private OID sigAlg; - private byte[] sigAlgParams; - private byte[] rawSig; - private byte[] signature; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new X.509 CRL. - * - * @param encoded The DER encoded CRL. - * @throws CRLException If the input bytes are incorrect. - * @throws IOException If the input bytes cannot be read. - */ - public X509CRL(InputStream encoded) throws CRLException, IOException - { - super(); - revokedCerts = new HashMap(); - extensions = new HashMap(); - try - { - parse(encoded); - } - catch (IOException ioe) - { - ioe.printStackTrace(); - throw ioe; - } - catch (Exception x) - { - x.printStackTrace(); - throw new CRLException(x.toString()); - } - } - - // X509CRL methods. - // ------------------------------------------------------------------------ - - public boolean equals(Object o) - { - if (!(o instanceof X509CRL)) - return false; - return ((X509CRL) o).getRevokedCertificates().equals(revokedCerts.values()); - } - - public int hashCode() - { - return revokedCerts.hashCode(); - } - - public byte[] getEncoded() throws CRLException - { - return (byte[]) encoded.clone(); - } - - public void verify(PublicKey key) - throws CRLException, NoSuchAlgorithmException, InvalidKeyException, - NoSuchProviderException, SignatureException - { - Signature sig = Signature.getInstance(sigAlg.toString()); - doVerify(sig, key); - } - - public void verify(PublicKey key, String provider) - throws CRLException, NoSuchAlgorithmException, InvalidKeyException, - NoSuchProviderException, SignatureException - { - Signature sig = Signature.getInstance(sigAlg.toString(), provider); - doVerify(sig, key); - } - - public int getVersion() - { - return version; - } - - public Principal getIssuerDN() - { - return issuerDN; - } - - public X500Principal getIssuerX500Principal() - { - return new X500Principal(issuerDN.getDer()); - } - - public Date getThisUpdate() - { - return (Date) thisUpdate.clone(); - } - - public Date getNextUpdate() - { - if (nextUpdate != null) - return (Date) nextUpdate.clone(); - return null; - } - - public java.security.cert.X509CRLEntry getRevokedCertificate(BigInteger serialNo) - { - return (java.security.cert.X509CRLEntry) revokedCerts.get(serialNo); - } - - public Set getRevokedCertificates() - { - return Collections.unmodifiableSet(new HashSet(revokedCerts.values())); - } - - public byte[] getTBSCertList() throws CRLException - { - return (byte[]) tbsCRLBytes.clone(); - } - - public byte[] getSignature() - { - return (byte[]) rawSig.clone(); - } - - public String getSigAlgName() - { - if (sigAlg.equals(ID_DSA_WITH_SHA1)) - return "SHA1withDSA"; - if (sigAlg.equals(ID_RSA_WITH_MD2)) - return "MD2withRSA"; - if (sigAlg.equals(ID_RSA_WITH_MD5)) - return "MD5withRSA"; - if (sigAlg.equals(ID_RSA_WITH_SHA1)) - return "SHA1withRSA"; - return "unknown"; - } - - public String getSigAlgOID() - { - return sigAlg.toString(); - } - - public byte[] getSigAlgParams() - { - if (sigAlgParams != null) - return (byte[]) sigAlgParams.clone(); - return null; - } - - // X509Extension methods. - // ------------------------------------------------------------------------ - - public boolean hasUnsupportedCriticalExtension() - { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical() && !e.isSupported()) - return true; - } - return false; - } - - public Set getCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public Set getNonCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (!e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public byte[] getExtensionValue(String oid) - { - Extension e = getExtension(new OID(oid)); - if (e != null) - { - return e.getValue().getEncoded(); - } - return null; - } - - // GnuPKIExtension method. - // ------------------------------------------------------------------------- - - public Extension getExtension(OID oid) - { - return (Extension) extensions.get(oid); - } - - public Collection getExtensions() - { - return extensions.values(); - } - - // CRL methods. - // ------------------------------------------------------------------------- - - public String toString() - { - return X509CRL.class.getName(); - } - - public boolean isRevoked(Certificate cert) - { - if (!(cert instanceof java.security.cert.X509Certificate)) - throw new IllegalArgumentException("not a X.509 certificate"); - BigInteger certSerial = - ((java.security.cert.X509Certificate) cert).getSerialNumber(); - X509CRLEntry ent = (X509CRLEntry) revokedCerts.get(certSerial); - if (ent == null) - return false; - return ent.getRevocationDate().compareTo(new Date()) < 0; - } - - // Own methods. - // ------------------------------------------------------------------------ - - private void doVerify(Signature sig, PublicKey key) - throws CRLException, InvalidKeyException, SignatureException - { - sig.initVerify(key); - sig.update(tbsCRLBytes); - if (!sig.verify(signature)) - throw new CRLException("signature not verified"); - } - - private void parse(InputStream in) throws Exception - { - // CertificateList ::= SEQUENCE { - DERReader der = new DERReader(in); - DERValue val = der.read(); - debug("start CertificateList len == " + val.getLength()); - if (!val.isConstructed()) - throw new IOException("malformed CertificateList"); - encoded = val.getEncoded(); - - // tbsCertList ::= SEQUENCE { -- TBSCertList - val = der.read(); - if (!val.isConstructed()) - throw new IOException("malformed TBSCertList"); - debug("start tbsCertList len == " + val.getLength()); - tbsCRLBytes = val.getEncoded(); - - // version Version OPTIONAL, - // -- If present must be v2 - val = der.read(); - if (val.getValue() instanceof BigInteger) - { - version = ((BigInteger) val.getValue()).intValue() + 1; - val = der.read(); - } - else - version = 1; - debug("read version == " + version); - - // signature AlgorithmIdentifier, - debug("start AlgorithmIdentifier len == " + val.getLength()); - if (!val.isConstructed()) - throw new IOException("malformed AlgorithmIdentifier"); - DERValue algIdVal = der.read(); - algId = (OID) algIdVal.getValue(); - debug("read object identifier == " + algId); - if (val.getLength() > algIdVal.getEncodedLength()) - { - val = der.read(); - debug("read parameters len == " + val.getEncodedLength()); - algParams = val.getEncoded(); - if (val.isConstructed()) - in.skip(val.getLength()); - } - - // issuer Name, - val = der.read(); - issuerDN = new X500DistinguishedName(val.getEncoded()); - der.skip(val.getLength()); - debug("read issuer == " + issuerDN); - - // thisUpdate Time, - thisUpdate = (Date) der.read().getValue(); - debug("read thisUpdate == " + thisUpdate); - - // nextUpdate Time OPTIONAL, - val = der.read(); - if (val.getValue() instanceof Date) - { - nextUpdate = (Date) val.getValue(); - debug("read nextUpdate == " + nextUpdate); - val = der.read(); - } - - // revokedCertificates SEQUENCE OF SEQUENCE { - // -- X509CRLEntry objects... - // } OPTIONAL, - if (val.getTag() != 0) - { - int len = 0; - while (len < val.getLength()) - { - X509CRLEntry entry = new X509CRLEntry(version, der); - revokedCerts.put(entry.getSerialNumber(), entry); - len += entry.getEncoded().length; - } - val = der.read(); - } - - // crlExtensions [0] EXPLICIT Extensions OPTIONAL - // -- if present MUST be v2 - if (val.getTagClass() != DER.UNIVERSAL && val.getTag() == 0) - { - if (version < 2) - throw new IOException("extra data in CRL"); - DERValue exts = der.read(); - if (!exts.isConstructed()) - throw new IOException("malformed Extensions"); - debug("start Extensions len == " + exts.getLength()); - int len = 0; - while (len < exts.getLength()) - { - DERValue ext = der.read(); - if (!ext.isConstructed()) - throw new IOException("malformed Extension"); - Extension e = new Extension(ext.getEncoded()); - extensions.put(e.getOid(), e); - der.skip(ext.getLength()); - len += ext.getEncodedLength(); - debug("current count == " + len); - } - val = der.read(); - } - - debug("read tag == " + val.getTag()); - if (!val.isConstructed()) - throw new IOException("malformed AlgorithmIdentifier"); - debug("start AlgorithmIdentifier len == " + val.getLength()); - DERValue sigAlgVal = der.read(); - debug("read tag == " + sigAlgVal.getTag()); - if (sigAlgVal.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("malformed AlgorithmIdentifier"); - sigAlg = (OID) sigAlgVal.getValue(); - debug("signature id == " + sigAlg); - debug("sigAlgVal length == " + sigAlgVal.getEncodedLength()); - if (val.getLength() > sigAlgVal.getEncodedLength()) - { - val = der.read(); - debug("sig params tag = " + val.getTag() + " len == " + val.getEncodedLength()); - sigAlgParams = (byte[]) val.getEncoded(); - if (val.isConstructed()) - in.skip(val.getLength()); - } - val = der.read(); - debug("read tag = " + val.getTag()); - rawSig = val.getEncoded(); - signature = ((BitString) val.getValue()).toByteArray(); - } -} diff --git a/libjava/gnu/java/security/x509/X509CRLEntry.java b/libjava/gnu/java/security/x509/X509CRLEntry.java deleted file mode 100644 index a3bcfdea823..00000000000 --- a/libjava/gnu/java/security/x509/X509CRLEntry.java +++ /dev/null @@ -1,278 +0,0 @@ -/* X509CRLEntry.java -- an entry in a X.509 CRL. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.ext.Extension; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.cert.CRLException; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/** - * A single entry in a X.509 certificate revocation list. - * - * @see X509CRL - * @author Casey Marshall - */ -class X509CRLEntry extends java.security.cert.X509CRLEntry - implements GnuPKIExtension -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - if (DEBUG) - { - System.err.print(">> X509CRLEntry: "); - System.err.println(msg); - } - } - - /** The DER encoded form of this CRL entry. */ - private byte[] encoded; - - /** The revoked certificate's serial number. */ - private BigInteger serialNo; - - /** The date the certificate was revoked. */ - private Date revocationDate; - - /** The CRL entry extensions. */ - private HashMap extensions; - - // Constructor. - // ------------------------------------------------------------------------ - - /** - * Create a new X.509 certificate revocation list entry from the given - * input stream and CRL version number. - * - * @param version The CRL version. - * @param encoded The stream of DER bytes. - * @throws CRLException If the ASN.1 structure is invalid. - * @throws IOException If the bytes cannot be read. - */ - X509CRLEntry(int version, DERReader encoded) - throws CRLException, IOException - { - super(); - extensions = new HashMap(); - try - { - parse(version, encoded); - } - catch (IOException ioe) - { - throw ioe; - } - catch (Exception x) - { - throw new CRLException(x.toString()); - } - } - - // X509CRLEntry methods. - // ------------------------------------------------------------------------ - - public boolean equals(Object o) - { - if (!(o instanceof X509CRLEntry)) - return false; - return ((X509CRLEntry) o).getSerialNumber().equals(serialNo) && - ((X509CRLEntry) o).getRevocationDate().equals(revocationDate); - } - - public int hashCode() - { - return serialNo.hashCode(); - } - - public byte[] getEncoded() throws CRLException - { - return (byte[]) encoded.clone(); - } - - public BigInteger getSerialNumber() - { - return serialNo; - } - - public Date getRevocationDate() - { - return (Date) revocationDate.clone(); - } - - public boolean hasExtensions() - { - return ! extensions.isEmpty(); - } - - public String toString() - { - return "X509CRLEntry serial=" + serialNo + " revocation date=" - + revocationDate + " ext=" + extensions; - } - - // X509Extension methods. - // ------------------------------------------------------------------------- - - public boolean hasUnsupportedCriticalExtension() - { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical() && !e.isSupported()) - return true; - } - return false; - } - - public Set getCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public Set getNonCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (!e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public byte[] getExtensionValue(String oid) - { - Extension e = getExtension(new OID(oid)); - if (e != null) - { - return e.getValue().getEncoded(); - } - return null; - } - - // GnuPKIExtension method. - // ------------------------------------------------------------------------- - - public Extension getExtension(OID oid) - { - return (Extension) extensions.get(oid); - } - - public Collection getExtensions() - { - return extensions.values(); - } - - // Own methods. - // ------------------------------------------------------------------------- - - private void parse(int version, DERReader der) throws Exception - { - // RevokedCertificate ::= SEQUENCE { - DERValue entry = der.read(); - debug("start CRL entry len == " + entry.getLength()); - if (!entry.isConstructed()) - throw new IOException("malformed revokedCertificate"); - encoded = entry.getEncoded(); - int len = 0; - - debug("encoded entry:\n" + Util.hexDump(encoded, ">>>> ")); - - // userCertificate CertificateSerialNumber, - DERValue val = der.read(); - serialNo = (BigInteger) val.getValue(); - len += val.getEncodedLength(); - debug("userCertificate == " + serialNo + " current count == " + len); - - // revocationDate Time, - val = der.read(); - revocationDate = (Date) val.getValue(); - len += val.getEncodedLength(); - debug("revocationDate == " + revocationDate + " current count == " + len); - - // crlEntryExtensions Extensions OPTIONAL - // -- if present MUST be v2 - if (len < entry.getLength()) - { - if (version < 2) - throw new IOException("extra data in CRL entry"); - DERValue exts = der.read(); - if (!exts.isConstructed()) - throw new IOException("malformed Extensions"); - debug("start Extensions len == " + exts.getLength()); - len = 0; - while (len < exts.getLength()) - { - val = der.read(); - if (!val.isConstructed()) - throw new IOException("malformed Extension"); - debug("start Extension len == " + val.getLength()); - Extension e = new Extension(val.getEncoded()); - extensions.put(e.getOid(), e); - der.skip(val.getLength()); - len += val.getEncodedLength(); - debug("current count == " + len); - } - } - } -} diff --git a/libjava/gnu/java/security/x509/X509CRLSelectorImpl.java b/libjava/gnu/java/security/x509/X509CRLSelectorImpl.java deleted file mode 100644 index 0ada5501689..00000000000 --- a/libjava/gnu/java/security/x509/X509CRLSelectorImpl.java +++ /dev/null @@ -1,138 +0,0 @@ -/* X509CRLSelectorImpl.java -- implementation of an X509CRLSelector. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import java.io.IOException; - -import java.security.Principal; -import java.security.cert.CRL; -import java.security.cert.CRLSelector; -import java.security.cert.X509CRL; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - * Sun's implementation of X509CRLSelector sucks. This one tries to work - * better. - */ -public class X509CRLSelectorImpl implements CRLSelector -{ - - // Fields. - // ------------------------------------------------------------------------- - - private Set issuerNames; - - // Constructor. - // ------------------------------------------------------------------------- - - public X509CRLSelectorImpl() - { - issuerNames = new HashSet(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public void addIssuerName(byte[] issuerName) throws IOException - { - issuerNames.add(new X500DistinguishedName(issuerName)); - } - - public void addIssuerName(String issuerName) - { - issuerNames.add(new X500DistinguishedName(issuerName)); - } - - public void addIssuerName(Principal issuerName) throws IOException - { - if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); - else if (issuerName instanceof X500Principal) - issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); - else - issuerNames.add(new X500DistinguishedName(issuerName.getName())); - } - - public Collection getIssuerNames() - { - return Collections.unmodifiableSet(issuerNames); - } - - public Object clone() - { - X509CRLSelectorImpl copy = new X509CRLSelectorImpl(); - copy.issuerNames.addAll(issuerNames); - return copy; - } - - public boolean match(CRL crl) - { - if (!(crl instanceof X509CRL)) - return false; - try - { - Principal p = ((X509CRL) crl).getIssuerDN(); - X500DistinguishedName thisName = null; - if (p instanceof X500DistinguishedName) - thisName = (X500DistinguishedName) p; - else if (p instanceof X500Principal) - thisName = new X500DistinguishedName(((X500Principal) p).getEncoded()); - else - thisName = new X500DistinguishedName(p.getName()); - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) - { - X500DistinguishedName name = (X500DistinguishedName) it.next(); - if (thisName.equals(name)) - return true; - } - } - catch (Exception x) - { - } - return false; - } -} - diff --git a/libjava/gnu/java/security/x509/X509CertPath.java b/libjava/gnu/java/security/x509/X509CertPath.java deleted file mode 100644 index e8ed6bf35d1..00000000000 --- a/libjava/gnu/java/security/x509/X509CertPath.java +++ /dev/null @@ -1,303 +0,0 @@ -/* X509CertPath.java -- an X.509 certificate path. - Copyright (C) 2004 Free Software Fonudation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DEREncodingException; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.security.cert.CertPath; -import java.security.cert.Certificate; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * A certificate path (or certificate chain) of X509Certificates. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class X509CertPath extends CertPath -{ - - // Fields. - // ------------------------------------------------------------------------- - - public static final List ENCODINGS = Collections.unmodifiableList( - Arrays.asList(new String[] { "PkiPath", "PKCS7" })); - - private static final OID PKCS7_SIGNED_DATA = new OID("1.2.840.113549.1.7.2"); - private static final OID PKCS7_DATA = new OID("1.2.840.113549.1.7.1"); - - /** The certificate path. */ - private List path; - - /** The cached PKCS #7 encoded bytes. */ - private byte[] pkcs_encoded; - - /** The cached PkiPath encoded bytes. */ - private byte[] pki_encoded; - - // Constructor. - // ------------------------------------------------------------------------- - - public X509CertPath(List path) - { - super("X.509"); - this.path = Collections.unmodifiableList(path); - } - - public X509CertPath(InputStream in) throws CertificateEncodingException - { - this(in, (String) ENCODINGS.get(0)); - } - - public X509CertPath(InputStream in, String encoding) - throws CertificateEncodingException - { - super("X.509"); - try - { - parse(in, encoding); - } - catch (IOException ioe) - { - throw new CertificateEncodingException(); - } - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public List getCertificates() - { - return path; // already unmodifiable - } - - public byte[] getEncoded() throws CertificateEncodingException - { - return getEncoded((String) ENCODINGS.get(0)); - } - - public byte[] getEncoded(String encoding) throws CertificateEncodingException - { - if (encoding.equalsIgnoreCase("PkiPath")) - { - if (pki_encoded == null) - { - try - { - pki_encoded = encodePki(); - } - catch (IOException ioe) - { - throw new CertificateEncodingException(); - } - } - return (byte[]) pki_encoded.clone(); - } - else if (encoding.equalsIgnoreCase("PKCS7")) - { - if (pkcs_encoded == null) - { - try - { - pkcs_encoded = encodePKCS(); - } - catch (IOException ioe) - { - throw new CertificateEncodingException(); - } - } - return (byte[]) pkcs_encoded.clone(); - } - else - throw new CertificateEncodingException("unknown encoding: " + encoding); - } - - public Iterator getEncodings() - { - return ENCODINGS.iterator(); // already unmodifiable - } - - // Own methods. - // ------------------------------------------------------------------------- - - private void parse(InputStream in, String encoding) - throws CertificateEncodingException, IOException - { - DERReader der = new DERReader(in); - DERValue path = null; - if (encoding.equalsIgnoreCase("PkiPath")) - { - // PKI encoding is just a SEQUENCE of X.509 certificates. - path = der.read(); - if (!path.isConstructed()) - throw new DEREncodingException("malformed PkiPath"); - } - else if (encoding.equalsIgnoreCase("PKCS7")) - { - // PKCS #7 encoding means that the certificates are contained in a - // SignedData PKCS #7 type. - // - // ContentInfo ::= SEQUENCE { - // contentType ::= ContentType, - // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL } - // - // ContentType ::= OBJECT IDENTIFIER - // - // SignedData ::= SEQUENCE { - // version Version, - // digestAlgorithms DigestAlgorithmIdentifiers, - // contentInfo ContentInfo, - // certificates [0] IMPLICIT ExtendedCertificatesAndCertificates - // OPTIONAL, - // crls [1] IMPLICIT CertificateRevocationLists OPTIONAL, - // signerInfos SignerInfos } - // - // Version ::= INTEGER - // - DERValue value = der.read(); - if (!value.isConstructed()) - throw new DEREncodingException("malformed ContentInfo"); - value = der.read(); - if (!(value.getValue() instanceof OID) || - ((OID) value.getValue()).equals(PKCS7_SIGNED_DATA)) - throw new DEREncodingException("not a SignedData"); - value = der.read(); - if (!value.isConstructed() || value.getTag() != 0) - throw new DEREncodingException("malformed content"); - value = der.read(); - if (value.getTag() != DER.INTEGER) - throw new DEREncodingException("malformed Version"); - value = der.read(); - if (!value.isConstructed() || value.getTag() != DER.SET) - throw new DEREncodingException("malformed DigestAlgorithmIdentifiers"); - der.skip(value.getLength()); - value = der.read(); - if (!value.isConstructed()) - throw new DEREncodingException("malformed ContentInfo"); - der.skip(value.getLength()); - path = der.read(); - if (!path.isConstructed() || path.getTag() != 0) - throw new DEREncodingException("no certificates"); - } - else - throw new CertificateEncodingException("unknown encoding: " + encoding); - - LinkedList certs = new LinkedList(); - int len = 0; - while (len < path.getLength()) - { - DERValue cert = der.read(); - try - { - certs.add(new X509Certificate(new ByteArrayInputStream(cert.getEncoded()))); - } - catch (CertificateException ce) - { - throw new CertificateEncodingException(ce.getMessage()); - } - len += cert.getEncodedLength(); - der.skip(cert.getLength()); - } - - this.path = Collections.unmodifiableList(certs); - } - - private byte[] encodePki() - throws CertificateEncodingException, IOException - { - synchronized (path) - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) - { - out.write(((Certificate) i.next()).getEncoded()); - } - byte[] b = out.toByteArray(); - DERValue val = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, - b.length, b, null); - return val.getEncoded(); - } - } - - private byte[] encodePKCS() - throws CertificateEncodingException, IOException - { - synchronized (path) - { - ArrayList signedData = new ArrayList(5); - signedData.add(new DERValue(DER.INTEGER, BigInteger.ONE)); - signedData.add(new DERValue(DER.CONSTRUCTED | DER.SET, - Collections.EMPTY_SET)); - signedData.add(new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, - Collections.singletonList( - new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_DATA)))); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) - { - out.write(((Certificate) i.next()).getEncoded()); - } - byte[] b = out.toByteArray(); - signedData.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, - b.length, b, null)); - DERValue sdValue = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, - signedData); - - ArrayList contentInfo = new ArrayList(2); - contentInfo.add(new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_SIGNED_DATA)); - contentInfo.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, sdValue)); - return new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, - contentInfo).getEncoded(); - } - } -} diff --git a/libjava/gnu/java/security/x509/X509CertSelectorImpl.java b/libjava/gnu/java/security/x509/X509CertSelectorImpl.java deleted file mode 100644 index 36187ad8e64..00000000000 --- a/libjava/gnu/java/security/x509/X509CertSelectorImpl.java +++ /dev/null @@ -1,197 +0,0 @@ -/* X509CertSelectorImpl.java -- implementation of an X509CertSelector. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import java.io.IOException; -import java.security.Principal; -import java.security.cert.CertSelector; -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - * Sun's implementation of X509CertSelector sucks. This one tries to work - * better. - */ -public class X509CertSelectorImpl implements CertSelector -{ - - // Fields. - // ------------------------------------------------------------------------- - - private Set issuerNames; - private Set subjectNames; - - // Constructor. - // ------------------------------------------------------------------------- - - public X509CertSelectorImpl() - { - issuerNames = new HashSet(); - subjectNames = new HashSet(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public void addIssuerName(byte[] issuerName) throws IOException - { - issuerNames.add(new X500DistinguishedName(issuerName)); - } - - public void addIssuerName(String issuerName) - { - issuerNames.add(new X500DistinguishedName(issuerName)); - } - - public void addIssuerName(Principal issuerName) throws IOException - { - if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); - else if (issuerName instanceof X500Principal) - issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); - else - issuerNames.add(new X500DistinguishedName(issuerName.getName())); - } - - public Collection getIssuerNames() - { - return Collections.unmodifiableSet(issuerNames); - } - - public void addSubjectName(byte[] subjectName) throws IOException - { - subjectNames.add(new X500DistinguishedName(subjectName)); - } - - public void addSubjectName(String subjectName) throws IOException - { - subjectNames.add(new X500DistinguishedName(subjectName)); - } - - public void addSubjectName(Principal subjectName) throws IOException - { - if (subjectName instanceof X500DistinguishedName) - subjectNames.add(subjectName); - else if (subjectName instanceof X500Principal) - subjectNames.add(new X500DistinguishedName(((X500Principal) subjectName).getEncoded())); - else - subjectNames.add(new X500DistinguishedName(subjectName.getName())); - } - - public Collection getSubjectNames() - { - return Collections.unmodifiableSet(subjectNames); - } - - public Object clone() - { - X509CertSelectorImpl copy = new X509CertSelectorImpl(); - copy.issuerNames.addAll(issuerNames); - copy.subjectNames.addAll(subjectNames); - return copy; - } - - public boolean match(Certificate cert) - { - if (!(cert instanceof X509Certificate)) - return false; - boolean matchIssuer = false; - boolean matchSubject = false; - try - { - Principal p = ((X509Certificate) cert).getIssuerDN(); - X500DistinguishedName thisName = null; - if (p instanceof X500DistinguishedName) - thisName = (X500DistinguishedName) p; - else if (p instanceof X500Principal) - thisName = new X500DistinguishedName(((X500Principal) p).getEncoded()); - else - thisName = new X500DistinguishedName(p.getName()); - if (issuerNames.isEmpty()) - matchIssuer = true; - else - { - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) - { - X500DistinguishedName name = (X500DistinguishedName) it.next(); - if (thisName.equals(name)) - { - matchIssuer = true; - break; - } - } - } - - p = ((X509Certificate) cert).getSubjectDN(); - thisName = null; - if (p instanceof X500DistinguishedName) - thisName = (X500DistinguishedName) p; - else if (p instanceof X500Principal) - thisName = new X500DistinguishedName(((X500Principal) p).getEncoded()); - else - thisName = new X500DistinguishedName(p.getName()); - if (subjectNames.isEmpty()) - matchSubject = true; - else - { - for (Iterator it = subjectNames.iterator(); it.hasNext(); ) - { - X500DistinguishedName name = (X500DistinguishedName) it.next(); - if (thisName.equals(name)) - { - matchSubject = true; - break; - } - } - } - } - catch (Exception x) - { - } - return matchIssuer && matchSubject; - } -} - diff --git a/libjava/gnu/java/security/x509/X509Certificate.java b/libjava/gnu/java/security/x509/X509Certificate.java deleted file mode 100644 index 94a02aa72c9..00000000000 --- a/libjava/gnu/java/security/x509/X509Certificate.java +++ /dev/null @@ -1,743 +0,0 @@ -/* X509Certificate.java -- X.509 certificate. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.ext.BasicConstraints; -import gnu.java.security.x509.ext.ExtendedKeyUsage; -import gnu.java.security.x509.ext.Extension; -import gnu.java.security.x509.ext.IssuerAlternativeNames; -import gnu.java.security.x509.ext.KeyUsage; -import gnu.java.security.x509.ext.SubjectAlternativeNames; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.io.StringWriter; -import java.math.BigInteger; -import java.security.AlgorithmParameters; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Principal; -import java.security.PublicKey; -import java.security.Signature; -import java.security.SignatureException; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateNotYetValidException; -import java.security.cert.CertificateParsingException; -import java.security.interfaces.DSAParams; -import java.security.interfaces.DSAPublicKey; -import java.security.spec.DSAParameterSpec; -import java.security.spec.X509EncodedKeySpec; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -/** - * An implementation of X.509 certificates. - * - * @author Casey Marshall (rsdio@metastatic.org) - */ -public class X509Certificate extends java.security.cert.X509Certificate - implements Serializable, GnuPKIExtension -{ - - // Constants and fields. - // ------------------------------------------------------------------------ - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - if (DEBUG) - { - System.err.print(">> X509Certificate: "); - System.err.println(msg); - } - } - private static void debug(Throwable t) - { - if (DEBUG) - { - System.err.print(">> X509Certificate: "); - t.printStackTrace(); - } - } - - protected static final OID ID_DSA = new OID ("1.2.840.10040.4.1"); - protected static final OID ID_DSA_WITH_SHA1 = new OID ("1.2.840.10040.4.3"); - protected static final OID ID_RSA = new OID ("1.2.840.113549.1.1.1"); - protected static final OID ID_RSA_WITH_MD2 = new OID ("1.2.840.113549.1.1.2"); - protected static final OID ID_RSA_WITH_MD5 = new OID ("1.2.840.113549.1.1.4"); - protected static final OID ID_RSA_WITH_SHA1 = new OID ("1.2.840.113549.1.1.5"); - protected static final OID ID_ECDSA_WITH_SHA1 = new OID ("1.2.840.10045.4.1"); - - // This object SHOULD be serialized with an instance of - // java.security.cert.Certificate.CertificateRep, thus all fields are - // transient. - - // The encoded certificate. - protected transient byte[] encoded; - - // TBSCertificate part. - protected transient byte[] tbsCertBytes; - protected transient int version; - protected transient BigInteger serialNo; - protected transient OID algId; - protected transient byte[] algVal; - protected transient X500DistinguishedName issuer; - protected transient Date notBefore; - protected transient Date notAfter; - protected transient X500DistinguishedName subject; - protected transient PublicKey subjectKey; - protected transient BitString issuerUniqueId; - protected transient BitString subjectUniqueId; - protected transient Map extensions; - - // Signature. - protected transient OID sigAlgId; - protected transient byte[] sigAlgVal; - protected transient byte[] signature; - - // Constructors. - // ------------------------------------------------------------------------ - - /** - * Create a new X.509 certificate from the encoded data. The input - * data are expected to be the ASN.1 DER encoding of the certificate. - * - * @param encoded The encoded certificate data. - * @throws IOException If the certificate cannot be read, possibly - * from a formatting error. - * @throws CertificateException If the data read is not an X.509 - * certificate. - */ - public X509Certificate(InputStream encoded) - throws CertificateException, IOException - { - super(); - extensions = new HashMap(); - try - { - parse(encoded); - } - catch (IOException ioe) - { - debug(ioe); - throw ioe; - } - catch (Exception e) - { - debug(e); - CertificateException ce = new CertificateException(e.getMessage()); - ce.initCause (e); - throw ce; - } - } - - protected X509Certificate() - { - extensions = new HashMap(); - } - - // X509Certificate methods. - // ------------------------------------------------------------------------ - - public void checkValidity() - throws CertificateExpiredException, CertificateNotYetValidException - { - checkValidity(new Date()); - } - - public void checkValidity(Date date) - throws CertificateExpiredException, CertificateNotYetValidException - { - if (date.compareTo(notBefore) < 0) - { - throw new CertificateNotYetValidException(); - } - if (date.compareTo(notAfter) > 0) - { - throw new CertificateExpiredException(); - } - } - - public int getVersion() - { - return version; - } - - public BigInteger getSerialNumber() - { - return serialNo; - } - - public Principal getIssuerDN() - { - return issuer; - } - - public X500Principal getIssuerX500Principal() - { - return new X500Principal(issuer.getDer()); - } - - public Principal getSubjectDN() - { - return subject; - } - - public X500Principal getSubjectX500Principal() - { - return new X500Principal(subject.getDer()); - } - - public Date getNotBefore() - { - return (Date) notBefore.clone(); - } - - public Date getNotAfter() - { - return (Date) notAfter.clone(); - } - - public byte[] getTBSCertificate() throws CertificateEncodingException - { - return (byte[]) tbsCertBytes.clone(); - } - - public byte[] getSignature() - { - return (byte[]) signature.clone(); - } - - public String getSigAlgName() - { - if (sigAlgId.equals(ID_DSA_WITH_SHA1)) - { - return "SHA1withDSA"; - } - if (sigAlgId.equals(ID_RSA_WITH_MD2)) - { - return "MD2withRSA"; - } - if (sigAlgId.equals(ID_RSA_WITH_MD5)) - { - return "MD5withRSA"; - } - if (sigAlgId.equals(ID_RSA_WITH_SHA1)) - { - return "SHA1withRSA"; - } - return "unknown"; - } - - public String getSigAlgOID() - { - return sigAlgId.toString(); - } - - public byte[] getSigAlgParams() - { - return (byte[]) sigAlgVal.clone(); - } - - public boolean[] getIssuerUniqueID() - { - if (issuerUniqueId != null) - { - return issuerUniqueId.toBooleanArray(); - } - return null; - } - - public boolean[] getSubjectUniqueID() - { - if (subjectUniqueId != null) - { - return subjectUniqueId.toBooleanArray(); - } - return null; - } - - public boolean[] getKeyUsage() - { - Extension e = getExtension(KeyUsage.ID); - if (e != null) - { - KeyUsage ku = (KeyUsage) e.getValue(); - boolean[] result = new boolean[9]; - boolean[] b = ku.getKeyUsage().toBooleanArray(); - System.arraycopy(b, 0, result, 0, b.length); - return result; - } - return null; - } - - public List getExtendedKeyUsage() throws CertificateParsingException - { - Extension e = getExtension(ExtendedKeyUsage.ID); - if (e != null) - { - List a = ((ExtendedKeyUsage) e.getValue()).getPurposeIds(); - List b = new ArrayList(a.size()); - for (Iterator it = a.iterator(); it.hasNext(); ) - { - b.add(it.next().toString()); - } - return Collections.unmodifiableList(b); - } - return null; - } - - public int getBasicConstraints() - { - Extension e = getExtension(BasicConstraints.ID); - if (e != null) - { - return ((BasicConstraints) e.getValue()).getPathLengthConstraint(); - } - return -1; - } - - public Collection getSubjectAlternativeNames() - throws CertificateParsingException - { - Extension e = getExtension(SubjectAlternativeNames.ID); - if (e != null) - { - return ((SubjectAlternativeNames) e.getValue()).getNames(); - } - return null; - } - - public Collection getIssuerAlternativeNames() - throws CertificateParsingException - { - Extension e = getExtension(IssuerAlternativeNames.ID); - if (e != null) - { - return ((IssuerAlternativeNames) e.getValue()).getNames(); - } - return null; - } - -// X509Extension methods. - // ------------------------------------------------------------------------ - - public boolean hasUnsupportedCriticalExtension() - { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical() && !e.isSupported()) - return true; - } - return false; - } - - public Set getCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public Set getNonCriticalExtensionOIDs() - { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - Extension e = (Extension) it.next(); - if (!e.isCritical()) - s.add(e.getOid().toString()); - } - return Collections.unmodifiableSet(s); - } - - public byte[] getExtensionValue(String oid) - { - Extension e = getExtension(new OID(oid)); - if (e != null) - { - return e.getValue().getEncoded(); - } - return null; - } - - // GnuPKIExtension method. - // ------------------------------------------------------------------------- - - public Extension getExtension(OID oid) - { - return (Extension) extensions.get(oid); - } - - public Collection getExtensions() - { - return extensions.values(); - } - - // Certificate methods. - // ------------------------------------------------------------------------- - - public byte[] getEncoded() throws CertificateEncodingException - { - return (byte[]) encoded.clone(); - } - - public void verify(PublicKey key) - throws CertificateException, NoSuchAlgorithmException, - InvalidKeyException, NoSuchProviderException, SignatureException - { - Signature sig = Signature.getInstance(sigAlgId.toString()); - doVerify(sig, key); - } - - public void verify(PublicKey key, String provider) - throws CertificateException, NoSuchAlgorithmException, - InvalidKeyException, NoSuchProviderException, SignatureException - { - Signature sig = Signature.getInstance(sigAlgId.toString(), provider); - doVerify(sig, key); - } - - public String toString() - { - StringWriter str = new StringWriter(); - PrintWriter out = new PrintWriter(str); - out.println(X509Certificate.class.getName() + " {"); - out.println(" TBSCertificate {"); - out.println(" version = " + version + ";"); - out.println(" serialNo = " + serialNo + ";"); - out.println(" signature = {"); - out.println(" algorithm = " + getSigAlgName() + ";"); - out.print(" parameters ="); - if (sigAlgVal != null) - { - out.println(); - out.print(Util.hexDump(sigAlgVal, " ")); - } - else - { - out.println(" null;"); - } - out.println(" }"); - out.println(" issuer = " + issuer.getName() + ";"); - out.println(" validity = {"); - out.println(" notBefore = " + notBefore + ";"); - out.println(" notAfter = " + notAfter + ";"); - out.println(" }"); - out.println(" subject = " + subject.getName() + ";"); - out.println(" subjectPublicKeyInfo = {"); - out.println(" algorithm = " + subjectKey.getAlgorithm()); - out.println(" key ="); - out.print(Util.hexDump(subjectKey.getEncoded(), " ")); - out.println(" };"); - out.println(" issuerUniqueId = " + issuerUniqueId + ";"); - out.println(" subjectUniqueId = " + subjectUniqueId + ";"); - out.println(" extensions = {"); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) - { - out.println(" " + it.next()); - } - out.println(" }"); - out.println(" }"); - out.println(" signatureAlgorithm = " + getSigAlgName() + ";"); - out.println(" signatureValue ="); - out.print(Util.hexDump(signature, " ")); - out.println("}"); - return str.toString(); - } - - public PublicKey getPublicKey() - { - return subjectKey; - } - - public boolean equals(Object other) - { - if (!(other instanceof X509Certificate)) - return false; - try - { - if (other instanceof X509Certificate) - return Arrays.equals(encoded, ((X509Certificate) other).encoded); - byte[] enc = ((X509Certificate) other).getEncoded(); - if (enc == null) - return false; - return Arrays.equals(encoded, enc); - } - catch (CertificateEncodingException cee) - { - return false; - } - } - - // Own methods. - // ------------------------------------------------------------------------ - - /** - * Verify this certificate's signature. - */ - private void doVerify(Signature sig, PublicKey key) - throws CertificateException, InvalidKeyException, SignatureException - { - debug("verifying sig=" + sig + " key=" + key); - sig.initVerify(key); - sig.update(tbsCertBytes); - if (!sig.verify(signature)) - { - throw new CertificateException("signature not validated"); - } - } - - /** - * Parse a DER stream into an X.509 certificate. - * - * @param encoded The encoded bytes. - */ - private void parse(InputStream encoded) throws Exception - { - DERReader der = new DERReader(encoded); - - // Certificate ::= SEQUENCE { - DERValue cert = der.read(); - debug("start Certificate len == " + cert.getLength()); - - this.encoded = cert.getEncoded(); - if (!cert.isConstructed()) - { - throw new IOException("malformed Certificate"); - } - - // TBSCertificate ::= SEQUENCE { - DERValue tbsCert = der.read(); - if (tbsCert.getValue() != DER.CONSTRUCTED_VALUE) - { - throw new IOException("malformed TBSCertificate"); - } - tbsCertBytes = tbsCert.getEncoded(); - debug("start TBSCertificate len == " + tbsCert.getLength()); - - // Version ::= INTEGER [0] { v1(0), v2(1), v3(2) } - DERValue val = der.read(); - if (val.getTagClass() == DER.CONTEXT && val.getTag() == 0) - { - version = ((BigInteger) der.read().getValue()).intValue() + 1; - val = der.read(); - } - else - { - version = 1; - } - debug("read version == " + version); - - // SerialNumber ::= INTEGER - serialNo = (BigInteger) val.getValue(); - debug("read serial number == " + serialNo); - - // AlgorithmIdentifier ::= SEQUENCE { - val = der.read(); - if (!val.isConstructed()) - { - throw new IOException("malformed AlgorithmIdentifier"); - } - int certAlgLen = val.getLength(); - debug("start AlgorithmIdentifier len == " + certAlgLen); - val = der.read(); - - // algorithm OBJECT IDENTIFIER, - algId = (OID) val.getValue(); - debug("read algorithm ID == " + algId); - - // parameters ANY DEFINED BY algorithm OPTIONAL } - if (certAlgLen > val.getEncodedLength()) - { - val = der.read(); - if (val == null) - { - algVal = null; - } - else - { - algVal = val.getEncoded(); - - if (val.isConstructed()) - encoded.skip(val.getLength()); - } - debug("read algorithm parameters == " + algVal); - } - - // issuer Name, - val = der.read(); - issuer = new X500DistinguishedName(val.getEncoded()); - der.skip(val.getLength()); - debug("read issuer == " + issuer); - - // Validity ::= SEQUENCE { - // notBefore Time, - // notAfter Time } - if (!der.read().isConstructed()) - { - throw new IOException("malformed Validity"); - } - notBefore = (Date) der.read().getValue(); - notAfter = (Date) der.read().getValue(); - debug("read notBefore == " + notBefore); - debug("read notAfter == " + notAfter); - - // subject Name, - val = der.read(); - subject = new X500DistinguishedName(val.getEncoded()); - der.skip(val.getLength()); - debug("read subject == " + subject); - - // SubjectPublicKeyInfo ::= SEQUENCE { - // algorithm AlgorithmIdentifier, - // subjectPublicKey BIT STRING } - DERValue spki = der.read(); - if (!spki.isConstructed()) - { - throw new IOException("malformed SubjectPublicKeyInfo"); - } - KeyFactory spkFac = KeyFactory.getInstance("X.509"); - subjectKey = spkFac.generatePublic(new X509EncodedKeySpec(spki.getEncoded())); - der.skip(spki.getLength()); - debug("read subjectPublicKey == " + subjectKey); - - if (version > 1) - { - val = der.read(); - } - if (version >= 2 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 1) - { - byte[] b = (byte[]) val.getValue(); - issuerUniqueId = new BitString(b, 1, b.length-1, b[0] & 0xFF); - debug("read issuerUniqueId == " + issuerUniqueId); - val = der.read(); - } - if (version >= 2 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 2) - { - byte[] b = (byte[]) val.getValue(); - subjectUniqueId = new BitString(b, 1, b.length-1, b[0] & 0xFF); - debug("read subjectUniqueId == " + subjectUniqueId); - val = der.read(); - } - if (version >= 3 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 3) - { - val = der.read(); - debug("start Extensions len == " + val.getLength()); - int len = 0; - while (len < val.getLength()) - { - DERValue ext = der.read(); - debug("start extension len == " + ext.getLength()); - Extension e = new Extension(ext.getEncoded()); - extensions.put(e.getOid(), e); - der.skip(ext.getLength()); - len += ext.getEncodedLength(); - debug("count == " + len); - } - } - - val = der.read(); - if (!val.isConstructed()) - { - throw new IOException("malformed AlgorithmIdentifier"); - } - int sigAlgLen = val.getLength(); - debug("start AlgorithmIdentifier len == " + sigAlgLen); - val = der.read(); - sigAlgId = (OID) val.getValue(); - debug("read algorithm id == " + sigAlgId); - if (sigAlgLen > val.getEncodedLength()) - { - val = der.read(); - if (val.getValue() == null) - { - if (subjectKey instanceof DSAPublicKey) - { - AlgorithmParameters params = - AlgorithmParameters.getInstance("DSA"); - DSAParams dsap = ((DSAPublicKey) subjectKey).getParams(); - DSAParameterSpec spec = - new DSAParameterSpec(dsap.getP(), dsap.getQ(), dsap.getG()); - params.init(spec); - sigAlgVal = params.getEncoded(); - } - } - else - { - sigAlgVal = (byte[]) val.getEncoded(); - } - if (val.isConstructed()) - { - encoded.skip(val.getLength()); - } - debug("read parameters == " + sigAlgVal); - } - signature = ((BitString) der.read().getValue()).toByteArray(); - debug("read signature ==\n" + Util.hexDump(signature, ">>>> ")); - } -} diff --git a/libjava/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java b/libjava/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java deleted file mode 100644 index a94b76f093e..00000000000 --- a/libjava/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java +++ /dev/null @@ -1,133 +0,0 @@ -/* AuthorityKeyIdentifier.java -- Authority key identifier extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.Util; - -import java.io.IOException; -import java.math.BigInteger; - -public class AuthorityKeyIdentifier extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.35"); - - private final byte[] keyIdentifier; - private final GeneralNames authorityCertIssuer; - private final BigInteger authorityCertSerialNumber; - - // Contstructor. - // ------------------------------------------------------------------------- - - public AuthorityKeyIdentifier(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - - // AuthorityKeyIdentifier ::= SEQUENCE { - DERValue val = der.read(); - if (!val.isConstructed()) - throw new IOException("malformed AuthorityKeyIdentifier"); - if (val.getLength() > 0) - val = der.read(); - - // keyIdentifier [0] KeyIdentifier OPTIONAL, - // KeyIdentifier ::= OCTET STRING - if (val.getTagClass() == DER.APPLICATION && val.getTag() == 0) - { - keyIdentifier = (byte[]) val.getValue(); - val = der.read(); - } - else - keyIdentifier = null; - - // authorityCertIssuer [1] GeneralNames OPTIONAL, - if (val.getTagClass() == DER.APPLICATION && val.getTag() == 1) - { - byte[] b = val.getEncoded(); - b[0] = (byte) (DER.CONSTRUCTED|DER.SEQUENCE); - authorityCertIssuer = new GeneralNames(b); - der.skip(val.getLength()); - val = der.read(); - } - else - authorityCertIssuer = null; - - // authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL } - if (val.getTagClass() == DER.APPLICATION && val.getTag() == 2) - { - authorityCertSerialNumber = new BigInteger((byte[]) val.getValue()); - } - else - authorityCertSerialNumber = null; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public byte[] getKeyIdentifier() - { - return keyIdentifier != null ? (byte[]) keyIdentifier.clone() : null; - } - - public GeneralNames getAuthorityCertIssuer() - { - return authorityCertIssuer; - } - - public BigInteger getAuthorityCertSerialNumber() - { - return authorityCertSerialNumber; - } - - public String toString() - { - return AuthorityKeyIdentifier.class.getName() + " [ keyId=" + - (keyIdentifier != null ? Util.toHexString (keyIdentifier, ':') : "nil") + - " authorityCertIssuer=" + authorityCertIssuer + - " authorityCertSerialNumbe=" + authorityCertSerialNumber + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/BasicConstraints.java b/libjava/gnu/java/security/x509/ext/BasicConstraints.java deleted file mode 100644 index 00f7a6ed220..00000000000 --- a/libjava/gnu/java/security/x509/ext/BasicConstraints.java +++ /dev/null @@ -1,129 +0,0 @@ -/* BasicConstraints.java -- the basic constraints extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -public class BasicConstraints extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.19"); - - private final boolean ca; - private final int pathLenConstraint; - - // Constructor. - // ------------------------------------------------------------------------- - - public BasicConstraints(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - DERValue bc = der.read(); - if (!bc.isConstructed()) - throw new IOException("malformed BasicConstraints"); - DERValue val = bc; - if (bc.getLength() > 0) - val = der.read(); - if (val.getTag() == DER.BOOLEAN) - { - ca = ((Boolean) val.getValue()).booleanValue(); - if (val.getEncodedLength() < bc.getLength()) - val = der.read(); - } - else - ca = false; - if (val.getTag() == DER.INTEGER) - { - pathLenConstraint = ((BigInteger) val.getValue()).intValue(); - } - else - pathLenConstraint = -1; - } - - public BasicConstraints (final boolean ca, final int pathLenConstraint) - { - this.ca = ca; - this.pathLenConstraint = pathLenConstraint; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public boolean isCA() - { - return ca; - } - - public int getPathLengthConstraint() - { - return pathLenConstraint; - } - - public byte[] getEncoded() - { - if (encoded == null) - { - List bc = new ArrayList (2); - bc.add (new DERValue (DER.BOOLEAN, new Boolean (ca))); - if (pathLenConstraint >= 0) - bc.add (new DERValue (DER.INTEGER, - BigInteger.valueOf ((long) pathLenConstraint))); - encoded = new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, bc).getEncoded(); - } - return (byte[]) encoded.clone(); - } - - public String toString() - { - return BasicConstraints.class.getName() + " [ isCA=" + ca + - " pathLen=" + pathLenConstraint + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/CRLNumber.java b/libjava/gnu/java/security/x509/ext/CRLNumber.java deleted file mode 100644 index 36b1c7b5f1d..00000000000 --- a/libjava/gnu/java/security/x509/ext/CRLNumber.java +++ /dev/null @@ -1,97 +0,0 @@ -/* CRLNumber.java -- CRL number extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.math.BigInteger; - -public class CRLNumber extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.20"); - - private final BigInteger number; - - // Constructor. - // ------------------------------------------------------------------------- - - public CRLNumber(final byte[] encoded) throws IOException - { - super(encoded); - DERValue val = DERReader.read(encoded); - if (val.getTag() != DER.INTEGER) - throw new IOException("malformed CRLNumber"); - number = (BigInteger) val.getValue(); - } - - public CRLNumber (final BigInteger number) - { - this.number = number; - } - - // Instance method. - // ------------------------------------------------------------------------- - - public BigInteger getNumber() - { - return number; - } - - public byte[] getEncoded() - { - if (encoded == null) - { - encoded = new DERValue (DER.INTEGER, number).getEncoded(); - } - return (byte[]) encoded.clone(); - } - - public String toString() - { - return CRLNumber.class.getName() + " [ " + number + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/CertificatePolicies.java b/libjava/gnu/java/security/x509/ext/CertificatePolicies.java deleted file mode 100644 index 50bc6d367d7..00000000000 --- a/libjava/gnu/java/security/x509/ext/CertificatePolicies.java +++ /dev/null @@ -1,189 +0,0 @@ -/* CertificatePolicies.java -- certificate policy extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.security.cert.PolicyQualifierInfo; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public class CertificatePolicies extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.32"); - - private final List policies; - private final Map policyQualifierInfos; - - // Constructor. - // ------------------------------------------------------------------------- - - public CertificatePolicies(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - DERValue pol = der.read(); - if (!pol.isConstructed()) - throw new IOException("malformed CertificatePolicies"); - - int len = 0; - LinkedList policyList = new LinkedList(); - HashMap qualifierMap = new HashMap(); - while (len < pol.getLength()) - { - DERValue policyInfo = der.read(); - if (!policyInfo.isConstructed()) - throw new IOException("malformed PolicyInformation"); - DERValue val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("malformed CertPolicyId"); - OID policyId = (OID) val.getValue(); - policyList.add(policyId); - if (val.getEncodedLength() < policyInfo.getLength()) - { - DERValue qual = der.read(); - int len2 = 0; - LinkedList quals = new LinkedList(); - while (len2 < qual.getLength()) - { - val = der.read(); - quals.add(new PolicyQualifierInfo(val.getEncoded())); - der.skip(val.getLength()); - len2 += val.getEncodedLength(); - } - qualifierMap.put(policyId, quals); - } - len += policyInfo.getEncodedLength(); - } - - policies = Collections.unmodifiableList(policyList); - policyQualifierInfos = Collections.unmodifiableMap(qualifierMap); - } - - public CertificatePolicies (final List policies, - final Map policyQualifierInfos) - { - for (Iterator it = policies.iterator(); it.hasNext(); ) - if (!(it.next() instanceof OID)) - throw new IllegalArgumentException ("policies must be OIDs"); - for (Iterator it = policyQualifierInfos.entrySet().iterator(); it.hasNext();) - { - Map.Entry e = (Map.Entry) it.next(); - if (!(e.getKey() instanceof OID) || !policies.contains (e.getKey())) - throw new IllegalArgumentException - ("policyQualifierInfos keys must be OIDs"); - if (!(e.getValue() instanceof List)) - throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); - for (Iterator it2 = ((List) e.getValue()).iterator(); it.hasNext(); ) - if (!(it2.next() instanceof PolicyQualifierInfo)) - throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); - } - this.policies = Collections.unmodifiableList (new ArrayList (policies)); - this.policyQualifierInfos = Collections.unmodifiableMap - (new HashMap (policyQualifierInfos)); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public List getPolicies() - { - return policies; - } - - public List getPolicyQualifierInfos(OID oid) - { - return (List) policyQualifierInfos.get(oid); - } - - public byte[] getEncoded() - { - if (encoded == null) - { - List pol = new ArrayList (policies.size()); - for (Iterator it = policies.iterator(); it.hasNext(); ) - { - OID policy = (OID) it.next(); - List qualifiers = getPolicyQualifierInfos (policy); - List l = new ArrayList (qualifiers == null ? 1 : 2); - l.add (new DERValue (DER.OBJECT_IDENTIFIER, policy)); - if (qualifiers != null) - { - List ll = new ArrayList (qualifiers.size()); - for (Iterator it2 = qualifiers.iterator(); it.hasNext(); ) - { - PolicyQualifierInfo info = (PolicyQualifierInfo) it2.next(); - try - { - ll.add (DERReader.read (info.getEncoded())); - } - catch (IOException ioe) - { - } - } - l.add (new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ll)); - } - pol.add (new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, l)); - } - encoded = new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, pol).getEncoded(); - } - return (byte[]) encoded.clone(); - } - - public String toString() - { - return CertificatePolicies.class.getName() + " [ policies=" + policies + - " policyQualifierInfos=" + policyQualifierInfos + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/ExtendedKeyUsage.java b/libjava/gnu/java/security/x509/ext/ExtendedKeyUsage.java deleted file mode 100644 index 37b08acf43e..00000000000 --- a/libjava/gnu/java/security/x509/ext/ExtendedKeyUsage.java +++ /dev/null @@ -1,95 +0,0 @@ -/* ExtendedKeyUsage.java -- the extended key usage extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -public class ExtendedKeyUsage extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.37"); - - private final List purposeIds; - - // Constructor. - // ------------------------------------------------------------------------- - - public ExtendedKeyUsage(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - DERValue usageList = der.read(); - if (!usageList.isConstructed()) - throw new IOException("malformed ExtKeyUsageSyntax"); - int len = 0; - purposeIds = new LinkedList(); - while (len < usageList.getLength()) - { - DERValue val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("malformed KeyPurposeId"); - purposeIds.add(val.getValue()); - len += val.getEncodedLength(); - } - } - - // Instance method. - // ------------------------------------------------------------------------- - - public List getPurposeIds() - { - return Collections.unmodifiableList(purposeIds); - } - - public String toString() - { - return ExtendedKeyUsage.class.getName() + " [ " + purposeIds + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/Extension.java b/libjava/gnu/java/security/x509/ext/Extension.java deleted file mode 100644 index 5ca9ac3a91d..00000000000 --- a/libjava/gnu/java/security/x509/ext/Extension.java +++ /dev/null @@ -1,289 +0,0 @@ -/* Extension.java -- an X.509 certificate or CRL extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.Util; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Extension -{ - - // Fields. - // ------------------------------------------------------------------------- - - private static final boolean DEBUG = false; - private static void debug(String msg) - { - System.err.print(">> Extension: "); - System.err.println(msg); - } - - /** - * This extension's object identifier. - */ - protected final OID oid; - - /** - * The criticality flag. - */ - protected final boolean critical; - - /** - * Whether or not this extension is locally supported. - */ - protected boolean isSupported; - - /** - * The extension value. - */ - protected final Value value; - - /** - * The DER encoded form. - */ - protected byte[] encoded; - - // Constructors. - // ------------------------------------------------------------------------- - - public Extension(byte[] encoded) throws IOException - { - this.encoded = (byte[]) encoded.clone(); - DERReader der = new DERReader(encoded); - - // Extension ::= SEQUENCE { - DERValue val = der.read(); - if (DEBUG) debug("read val tag == " + val.getTag() + " len == " + val.getLength()); - if (!val.isConstructed()) - throw new IOException("malformed Extension"); - - // extnID OBJECT IDENTIFIER, - val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("expecting OBJECT IDENTIFIER"); - oid = (OID) val.getValue(); - if (DEBUG) debug("read oid == " + oid); - - // critical BOOLEAN DEFAULT FALSE, - val = der.read(); - if (val.getTag() == DER.BOOLEAN) - { - critical = ((Boolean) val.getValue()).booleanValue(); - val = der.read(); - } - else - critical = false; - if (DEBUG) debug("is critical == " + critical); - - // extnValue OCTET STRING } - if (val.getTag() != DER.OCTET_STRING) - throw new IOException("expecting OCTET STRING"); - byte[] encval = (byte[]) val.getValue(); - isSupported = true; - if (oid.equals(AuthorityKeyIdentifier.ID)) - { - value = new AuthorityKeyIdentifier(encval); - } - else if (oid.equals(SubjectKeyIdentifier.ID)) - { - value = new SubjectKeyIdentifier(encval); - } - else if (oid.equals(KeyUsage.ID)) - { - value = new KeyUsage(encval); - } - else if (oid.equals(PrivateKeyUsagePeriod.ID)) - { - value = new PrivateKeyUsagePeriod(encval); - } - else if (oid.equals(CertificatePolicies.ID)) - { - value = new CertificatePolicies(encval); - } - else if (oid.equals (PolicyConstraint.ID)) - { - value = new PolicyConstraint (encval); - } - else if (oid.equals(PolicyMappings.ID)) - { - value = new PolicyMappings(encval); - } - else if (oid.equals(SubjectAlternativeNames.ID)) - { - value = new SubjectAlternativeNames(encval); - } - else if (oid.equals(IssuerAlternativeNames.ID)) - { - value = new IssuerAlternativeNames(encval); - } - else if (oid.equals(BasicConstraints.ID)) - { - value = new BasicConstraints(encval); - } - else if (oid.equals(ExtendedKeyUsage.ID)) - { - value = new ExtendedKeyUsage(encval); - } - else if (oid.equals(CRLNumber.ID)) - { - value = new CRLNumber(encval); - } - else if (oid.equals(ReasonCode.ID)) - { - value = new ReasonCode(encval); - } - else - { - value = new Value(encval); - isSupported = false; - } - if (DEBUG) debug("read value == " + value); - } - - public Extension (final OID oid, final Value value, final boolean critical) - { - this.oid = oid; - this.value = value; - this.critical = critical; - isSupported = true; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public OID getOid() - { - return oid; - } - - public boolean isCritical() - { - return critical; - } - - public boolean isSupported() - { - return isSupported; - } - - public Value getValue() - { - return value; - } - - public byte[] getEncoded() - { - if (encoded == null) - encode(); - return (byte[]) encoded.clone(); - } - - public String toString() - { - return Extension.class.getName() + " [ id=" + oid + " critical=" + - critical + " value=" + value + " ]"; - } - - public DERValue getDerValue() - { - List ext = new ArrayList (3); - ext.add (new DERValue (DER.OBJECT_IDENTIFIER, oid)); - ext.add (new DERValue (DER.BOOLEAN, new Boolean (critical))); - ext.add (new DERValue (DER.OCTET_STRING, value.getEncoded())); - return new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ext); - } - - // Own methods. - // ------------------------------------------------------------------------- - - private void encode() - { - encoded = getDerValue().getEncoded(); - } - - // Inner class. - // ------------------------------------------------------------------------- - - public static class Value - { - - // Fields. - // ----------------------------------------------------------------------- - - protected byte[] encoded; - - // Constructor. - // ----------------------------------------------------------------------- - - public Value(byte[] encoded) - { - this.encoded = (byte[]) encoded.clone(); - } - - protected Value() { } - - // Instance methods. - // ----------------------------------------------------------------------- - - public byte[] getEncoded() - { - return (byte[]) encoded; - } - - public boolean equals(Object o) - { - if (!(o instanceof Value)) - return false; - return Arrays.equals(encoded, ((Value) o).encoded); - } - - public String toString() - { - return Util.toHexString(encoded, ':'); - } - } -} diff --git a/libjava/gnu/java/security/x509/ext/GeneralNames.java b/libjava/gnu/java/security/x509/ext/GeneralNames.java deleted file mode 100644 index e92aedaefd0..00000000000 --- a/libjava/gnu/java/security/x509/ext/GeneralNames.java +++ /dev/null @@ -1,155 +0,0 @@ -/* GeneralNames.java -- the GeneralNames object - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.X500DistinguishedName; - -import java.io.IOException; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -public class GeneralNames -{ - - // Instance methods. - // ------------------------------------------------------------------------- - - public static final int OTHER_NAME = 0; - public static final int RFC822_NAME = 1; - public static final int DNS_NAME = 2; - public static final int X400_ADDRESS = 3; - public static final int DIRECTORY_NAME = 4; - public static final int EDI_PARTY_NAME = 5; - public static final int URI = 6; - public static final int IP_ADDRESS = 7; - public static final int REGISTERED_ID = 8; - - private List names; - - // Constructor. - // ------------------------------------------------------------------------- - - public GeneralNames(final byte[] encoded) throws IOException - { - names = new LinkedList(); - DERReader der = new DERReader(encoded); - DERValue nameList = der.read(); - if (!nameList.isConstructed()) - throw new IOException("malformed GeneralNames"); - int len = 0; - while (len < nameList.getLength()) - { - DERValue name = der.read(); - List namePair = new ArrayList(2); - if (name.getTagClass() != DER.APPLICATION) - throw new IOException("malformed GeneralName"); - namePair.add(new Integer(name.getTag())); - DERValue val = null; - switch (name.getTag()) - { - case RFC822_NAME: - case DNS_NAME: - case X400_ADDRESS: - case URI: - namePair.add(new String((byte[]) name.getValue())); - break; - - case OTHER_NAME: - case EDI_PARTY_NAME: - namePair.add(name.getValue()); - break; - - case DIRECTORY_NAME: - byte[] b = name.getEncoded(); - b[0] = (byte) (DER.CONSTRUCTED|DER.SEQUENCE); - namePair.add(new X500DistinguishedName(b).toString()); - break; - - case IP_ADDRESS: - namePair.add(InetAddress.getByAddress((byte[]) name.getValue()) - .getHostAddress()); - break; - - case REGISTERED_ID: - byte[] bb = name.getEncoded(); - bb[0] = (byte) DER.OBJECT_IDENTIFIER; - namePair.add(new OID(bb).toString()); - break; - - default: - throw new IOException("unknown tag " + name.getTag()); - } - names.add(namePair); - len += name.getEncodedLength(); - } - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public List getNames() - { - List l = new ArrayList(names.size()); - for (Iterator it = names.iterator(); it.hasNext(); ) - { - List ll = (List) it.next(); - List pair = new ArrayList(2); - pair.add(ll.get(0)); - if (ll.get(1) instanceof byte[]) - pair.add(((byte[]) ll.get(1)).clone()); - else - pair.add(ll.get(1)); - l.add(Collections.unmodifiableList(pair)); - } - return Collections.unmodifiableList(l); - } - - public String toString() - { - return GeneralNames.class.getName() + " [ " + names + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/IssuerAlternativeNames.java b/libjava/gnu/java/security/x509/ext/IssuerAlternativeNames.java deleted file mode 100644 index 8b017dc62d8..00000000000 --- a/libjava/gnu/java/security/x509/ext/IssuerAlternativeNames.java +++ /dev/null @@ -1,77 +0,0 @@ -/* IssuerAlternatuveNames.java -- issuer alternative names extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; - -import java.io.IOException; -import java.util.List; - -public class IssuerAlternativeNames extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.18"); - - private final GeneralNames names; - - // Constructor. - // ------------------------------------------------------------------------- - - public IssuerAlternativeNames(final byte[] encoded) throws IOException - { - super(encoded); - names = new GeneralNames(encoded); - } - - // Instance method. - // ------------------------------------------------------------------------- - - public List getNames() - { - return names.getNames(); - } - - public String toString() - { - return IssuerAlternativeNames.class.getName() + " [ " + names + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/KeyUsage.java b/libjava/gnu/java/security/x509/ext/KeyUsage.java deleted file mode 100644 index dcd98181e12..00000000000 --- a/libjava/gnu/java/security/x509/ext/KeyUsage.java +++ /dev/null @@ -1,92 +0,0 @@ -/* KeyUsage.java -- the key usage extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.BitString; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; - -public class KeyUsage extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.15"); - public static final int DIGITAL_SIGNATURE = 0; - public static final int NON_REPUDIATION = 1; - public static final int KEY_ENCIPHERMENT = 2; - public static final int DATA_ENCIPHERMENT = 3; - public static final int KEY_AGREEMENT = 4; - public static final int KEY_CERT_SIGN = 5; - public static final int CRL_SIGN = 6; - public static final int ENCIPHER_ONLY = 7; - public static final int DECIPHER_ONLY = 8; - - private final BitString keyUsage; - - // Constructor. - // ------------------------------------------------------------------------- - - public KeyUsage(final byte[] encoded) throws IOException - { - super(encoded); - DERValue val = DERReader.read(encoded); - if (val.getTag() != DER.BIT_STRING) - throw new IOException("malformed KeyUsage"); - keyUsage = (BitString) val.getValue(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public BitString getKeyUsage() - { - return keyUsage; - } - - public String toString() - { - return KeyUsage.class.getName() + " [ " + keyUsage + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/PolicyConstraint.java b/libjava/gnu/java/security/x509/ext/PolicyConstraint.java deleted file mode 100644 index 20cf552a0fe..00000000000 --- a/libjava/gnu/java/security/x509/ext/PolicyConstraint.java +++ /dev/null @@ -1,107 +0,0 @@ -/* PolicyConstraint.java -- policyConstraint extension - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.math.BigInteger; - -public class PolicyConstraint extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID ("2.5.29.36"); - - private final int requireExplicitPolicy; - private final int inhibitPolicyMapping; - - // Constructors. - // ------------------------------------------------------------------------- - - public PolicyConstraint (final byte[] encoded) throws IOException - { - super (encoded); - int rpc = -1, ipm = -1; - DERReader der = new DERReader(encoded); - DERValue pc = der.read(); - if (!pc.isConstructed()) - throw new IOException("malformed PolicyConstraints"); - DERValue val; - int len = pc.getLength(); - while (len > 0) - { - val = der.read(); - if (val.getTag() == 0) - rpc = new BigInteger ((byte[]) val.getValue()).intValue(); - else if (val.getTag() == 1) - ipm = new BigInteger ((byte[]) val.getValue()).intValue(); - else - throw new IOException ("invalid policy constraint"); - len -= val.getEncodedLength(); - } - - requireExplicitPolicy = rpc; - inhibitPolicyMapping = ipm; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public int getRequireExplicitPolicy() - { - return requireExplicitPolicy; - } - - public int getInhibitPolicyMapping() - { - return inhibitPolicyMapping; - } - - public String toString() - { - return PolicyConstraint.class.getName() + " [ requireExplicitPolicy=" + - requireExplicitPolicy + " inhibitPolicyMapping=" + inhibitPolicyMapping - + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/PolicyMappings.java b/libjava/gnu/java/security/x509/ext/PolicyMappings.java deleted file mode 100644 index 0493ed89dd4..00000000000 --- a/libjava/gnu/java/security/x509/ext/PolicyMappings.java +++ /dev/null @@ -1,104 +0,0 @@ -/* PolicyMappings.java -- policy mappings extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class PolicyMappings extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.33"); - - private final Map mappings; - - // Constructor. - // ------------------------------------------------------------------------- - - public PolicyMappings(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - DERValue maps = der.read(); - if (!maps.isConstructed()) - throw new IOException("malformed PolicyMappings"); - int len = 0; - HashMap _mappings = new HashMap(); - while (len < maps.getLength()) - { - DERValue map = der.read(); - if (!map.isConstructed()) - throw new IOException("malformed PolicyMapping"); - DERValue val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("malformed PolicyMapping"); - OID issuerPolicy = (OID) val.getValue(); - val = der.read(); - if (val.getTag() != DER.OBJECT_IDENTIFIER) - throw new IOException("malformed PolicyMapping"); - OID subjectPolicy = (OID) val.getValue(); - _mappings.put(issuerPolicy, subjectPolicy); - len += map.getEncodedLength(); - } - mappings = Collections.unmodifiableMap(_mappings); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public OID getSubjectDomainPolicy(OID issuerDomainPolicy) - { - return (OID) mappings.get(issuerDomainPolicy); - } - - public String toString() - { - return PolicyMappings.class.getName() + " [ " + mappings + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/PrivateKeyUsagePeriod.java b/libjava/gnu/java/security/x509/ext/PrivateKeyUsagePeriod.java deleted file mode 100644 index 3b531c05517..00000000000 --- a/libjava/gnu/java/security/x509/ext/PrivateKeyUsagePeriod.java +++ /dev/null @@ -1,105 +0,0 @@ -/* PrivateKeyUsagePeriod.java -- private key usage period extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.util.Date; - -public class PrivateKeyUsagePeriod extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.16"); - - private final Date notBefore; - private final Date notAfter; - - // Constructor. - // ------------------------------------------------------------------------- - - public PrivateKeyUsagePeriod(final byte[] encoded) throws IOException - { - super(encoded); - DERReader der = new DERReader(encoded); - DERValue val = der.read(); - if (!val.isConstructed()) - throw new IOException("malformed PrivateKeyUsagePeriod"); - if (val.getLength() > 0) - val = der.read(); - if (val.getTagClass() == DER.APPLICATION || val.getTag() == 0) - { - notBefore = (Date) val.getValueAs (DER.GENERALIZED_TIME); - val = der.read(); - } - else - notBefore = null; - if (val.getTagClass() == DER.APPLICATION || val.getTag() == 1) - { - notAfter = (Date) val.getValueAs (DER.GENERALIZED_TIME); - } - else - notAfter = null; - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public Date getNotBefore() - { - return notBefore != null ? (Date) notBefore.clone() : null; - } - - public Date getNotAfter() - { - return notAfter != null ? (Date) notAfter.clone() : null; - } - - public String toString() - { - return PrivateKeyUsagePeriod.class.getName() + " [ notBefore=" + notBefore - + " notAfter=" + notAfter + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/ReasonCode.java b/libjava/gnu/java/security/x509/ext/ReasonCode.java deleted file mode 100644 index a6d59e43ae8..00000000000 --- a/libjava/gnu/java/security/x509/ext/ReasonCode.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ReasonCode.java -- a reason code for a certificate revocation. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; - -import java.io.IOException; -import java.math.BigInteger; - -public class ReasonCode extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.21"); - - public final int reason; - - // Constructor. - // ------------------------------------------------------------------------- - - public ReasonCode(final byte[] encoded) throws IOException - { - super(encoded); - DERValue val = DERReader.read(encoded); - if (val.getTag() != DER.ENUMERATED) - throw new IOException("malformed CRLReason"); - reason = ((BigInteger) val.getValue()).intValue(); - if (reason < 0 || reason == 7 || reason > 10) - throw new IOException("illegal reason: " + reason); - } - - // Instance method. - // ------------------------------------------------------------------------- - - public int getReasonCode() - { - return reason; - } - - public String toString() - { - return ReasonCode.class.getName() + " [ " + reason + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/SubjectAlternativeNames.java b/libjava/gnu/java/security/x509/ext/SubjectAlternativeNames.java deleted file mode 100644 index f88e854965f..00000000000 --- a/libjava/gnu/java/security/x509/ext/SubjectAlternativeNames.java +++ /dev/null @@ -1,77 +0,0 @@ -/* SubjectAlternatuveNames.java -- subject alternative names extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; - -import java.io.IOException; -import java.util.List; - -public class SubjectAlternativeNames extends Extension.Value -{ - - // Constants and fields. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.17"); - - private final GeneralNames names; - - // Constructor. - // ------------------------------------------------------------------------- - - public SubjectAlternativeNames(final byte[] encoded) throws IOException - { - super(encoded); - names = new GeneralNames(encoded); - } - - // Instance method. - // ------------------------------------------------------------------------- - - public List getNames() - { - return names.getNames(); - } - - public String toString() - { - return SubjectAlternativeNames.class.getName() + " [ " + names + " ]"; - } -} diff --git a/libjava/gnu/java/security/x509/ext/SubjectKeyIdentifier.java b/libjava/gnu/java/security/x509/ext/SubjectKeyIdentifier.java deleted file mode 100644 index fc65abe211c..00000000000 --- a/libjava/gnu/java/security/x509/ext/SubjectKeyIdentifier.java +++ /dev/null @@ -1,84 +0,0 @@ -/* SubjectKeyIdentifier.java -- subject key identifier extension. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.x509.ext; - -import gnu.java.security.OID; -import gnu.java.security.der.DER; -import gnu.java.security.der.DERReader; -import gnu.java.security.der.DERValue; -import gnu.java.security.x509.Util; - -import java.io.IOException; - -public class SubjectKeyIdentifier extends Extension.Value -{ - - // Constant. - // ------------------------------------------------------------------------- - - public static final OID ID = new OID("2.5.29.14"); - - private final byte[] keyIdentifier; - - // Constructor. - // ------------------------------------------------------------------------- - - public SubjectKeyIdentifier(final byte[] encoded) throws IOException - { - super(encoded); - DERValue val = DERReader.read(encoded); - if (val.getTag() != DER.OCTET_STRING) - throw new IOException("malformed SubjectKeyIdentifier"); - keyIdentifier = (byte[]) val.getValue(); - } - - // Instance methods. - // ------------------------------------------------------------------------- - - public byte[] getKeyIdentifier() - { - return (byte[]) keyIdentifier.clone(); - } - - public String toString() - { - return SubjectKeyIdentifier.class.getName() + " [ " + - Util.toHexString (keyIdentifier, ':') + " ]"; - } -} diff --git a/libjava/gnu/java/text/AttributedFormatBuffer.java b/libjava/gnu/java/text/AttributedFormatBuffer.java deleted file mode 100644 index 8cfc8f56ddb..00000000000 --- a/libjava/gnu/java/text/AttributedFormatBuffer.java +++ /dev/null @@ -1,247 +0,0 @@ -/* AttributedFormatBuffer.java -- Implements an attributed FormatBuffer. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.text; - -import java.text.AttributedCharacterIterator; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * This class is an implementation of a FormatBuffer with attributes. - * - * @author Guilhem Lavaux <guilhem@kaffe.org> - * @date April 10, 2004 - */ -public class AttributedFormatBuffer implements FormatBuffer -{ - private StringBuffer buffer; - private ArrayList ranges; - private ArrayList attributes; - private int[] a_ranges; - private HashMap[] a_attributes; - private int startingRange; - AttributedCharacterIterator.Attribute defaultAttr; - - /** - * This constructor accepts a StringBuffer. If the buffer contains - * already some characters they will not be attributed. - */ - public AttributedFormatBuffer(StringBuffer buffer) - { - this.buffer = buffer; - this.ranges = new ArrayList(); - this.attributes = new ArrayList(); - this.defaultAttr = null; - if (buffer.length() != 0) - { - this.startingRange = buffer.length(); - addAttribute(buffer.length(), null); - } - else - this.startingRange = -1; - } - - public AttributedFormatBuffer(int prebuffer) - { - this(new StringBuffer(prebuffer)); - } - - public AttributedFormatBuffer() - { - this(10); - } - - /** - * This method is a helper function for formatters. Given a set of ranges - * and attributes it adds exactly one attribute for the range of characters - * comprised between the last entry in 'ranges' and the specified new range. - * - * @param new_range A new range to insert in the list. - * @param new_attribute A new attribute to insert in the list. - */ - private final void addAttribute(int new_range, AttributedCharacterIterator.Attribute attr) - { - HashMap map; - - if (attr != null) - { - map = new HashMap(); - map.put(attr, attr); - attributes.add(map); - } - else - attributes.add(null); - - ranges.add(new Integer(new_range)); - } - - public void append(String s) - { - if (startingRange < 0) - startingRange = 0; - buffer.append(s); - } - - public void append(String s, AttributedCharacterIterator.Attribute attr) - { - setDefaultAttribute(attr); - startingRange = buffer.length(); - append(s); - setDefaultAttribute(null); - } - - public void append(String s, int[] ranges, HashMap[] attrs) - { - int curPos = buffer.length(); - - setDefaultAttribute(null); - if (ranges != null) - { - for (int i = 0; i < ranges.length; i++) - { - this.ranges.add(new Integer(ranges[i] + curPos)); - this.attributes.add(attrs[i]); - } - } - startingRange = buffer.length(); - buffer.append(s); - } - - public void append(char c) - { - if (startingRange < 0) - startingRange = buffer.length(); - buffer.append(c); - } - - public void append(char c, AttributedCharacterIterator.Attribute attr) - { - setDefaultAttribute(attr); - buffer.append(c); - setDefaultAttribute(null); - } - - public void setDefaultAttribute(AttributedCharacterIterator.Attribute attr) - { - if (attr == defaultAttr) - return; - - int currentPos = buffer.length(); - - if (startingRange != currentPos && startingRange >= 0) - { - addAttribute(currentPos, defaultAttr); - } - defaultAttr = attr; - startingRange = currentPos; - } - - public AttributedCharacterIterator.Attribute getDefaultAttribute() - { - return defaultAttr; - } - - public void cutTail(int length) - { - buffer.setLength(buffer.length()-length); - } - - public int length() - { - return buffer.length(); - } - - public void clear() - { - buffer.setLength(0); - ranges.clear(); - attributes.clear(); - defaultAttr = null; - startingRange = -1; - } - - /** - * This method synchronizes the state of the attribute array. - * After calling it you may call {@link #getDefaultAttribute()}. - */ - public void sync() - { - if (startingRange < 0 || startingRange == buffer.length()) - return; - - addAttribute(buffer.length(), defaultAttr); - - a_ranges = new int[ranges.size()]; - for (int i = 0; i < a_ranges.length; i++) - a_ranges[i] = ((Integer)(ranges.get (i))).intValue(); - - a_attributes = new HashMap[attributes.size()]; - System.arraycopy(attributes.toArray(), 0, a_attributes, 0, a_attributes.length); - } - - /** - * This method returns the internal StringBuffer describing - * the attributed string. - * - * @return An instance of StringBuffer which contains the string. - */ - public StringBuffer getBuffer() - { - return buffer; - } - - /** - * This method returns the ranges for the attributes. - * - * @return An array of int describing the ranges. - */ - public int[] getRanges() - { - return a_ranges; - } - - /** - * This method returns the array containing the map on the - * attributes. - * - * @return An array of {@link java.util.Map} containing the attributes. - */ - public HashMap[] getAttributes() - { - return a_attributes; - } -} diff --git a/libjava/gnu/java/text/BaseBreakIterator.java b/libjava/gnu/java/text/BaseBreakIterator.java deleted file mode 100644 index c28a2089ad7..00000000000 --- a/libjava/gnu/java/text/BaseBreakIterator.java +++ /dev/null @@ -1,121 +0,0 @@ -/* BaseBreakIterator.java -- Base class for default BreakIterators - Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.text; - -import java.text.BreakIterator; -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; - -/** - * @author Tom Tromey <tromey@cygnus.com> - * @date March 22, 1999 - */ - -public abstract class BaseBreakIterator extends BreakIterator -{ - public BaseBreakIterator () - { - // It isn't documented, but break iterators are created in a - // working state; their methods won't throw exceptions before - // setText(). - iter = new StringCharacterIterator(""); - } - - public int current () - { - return iter.getIndex(); - } - - public int first () - { - iter.first(); - return iter.getBeginIndex(); - } - - public int following (int pos) - { - int save = iter.getIndex(); - iter.setIndex(pos); - int r = next (); - iter.setIndex(save); - return r; - } - - public CharacterIterator getText () - { - return iter; - } - - public int last () - { - iter.last(); - // Go past the last character. - iter.next(); - return iter.getEndIndex(); - } - - public int next (int n) - { - int r = iter.getIndex (); - if (n > 0) - { - while (n > 0 && r != DONE) - { - r = next (); - --n; - } - } - else if (n < 0) - { - while (n < 0 && r != DONE) - { - r = previous (); - ++n; - } - } - return r; - } - - public void setText (CharacterIterator newText) - { - iter = newText; - } - - protected CharacterIterator iter; -} diff --git a/libjava/gnu/java/text/CharacterBreakIterator.java b/libjava/gnu/java/text/CharacterBreakIterator.java deleted file mode 100644 index 5274543a9e5..00000000000 --- a/libjava/gnu/java/text/CharacterBreakIterator.java +++ /dev/null @@ -1,213 +0,0 @@ -/* CharacterBreakIterator.java - Default character BreakIterator. - Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.text; - -import java.text.CharacterIterator; - -/** - * @author Tom Tromey <tromey@cygnus.com> - * @date March 19, 1999 - * Written using The Unicode Standard, Version 2.0. - */ - -public class CharacterBreakIterator extends BaseBreakIterator -{ - // Hangul Jamo constants from Unicode book. - private static final int LBase = 0x1100; - private static final int VBase = 0x1161; - private static final int TBase = 0x11a7; - private static final int LCount = 19; - private static final int VCount = 21; - private static final int TCount = 28; - - // Information about surrogates. - private static final int highSurrogateStart = 0xD800; - private static final int highSurrogateEnd = 0xDBFF; - private static final int lowSurrogateStart = 0xDC00; - private static final int lowSurrogateEnd = 0xDFFF; - - public Object clone () - { - return new CharacterBreakIterator (this); - } - - public CharacterBreakIterator () - { - } - - private CharacterBreakIterator (CharacterBreakIterator other) - { - iter = (CharacterIterator) other.iter.clone(); - } - - // Some methods to tell us different properties of characters. - private final boolean isL (char c) - { - return c >= LBase && c <= LBase + LCount; - } - private final boolean isV (char c) - { - return c >= VBase && c <= VBase + VCount; - } - private final boolean isT (char c) - { - return c >= TBase && c <= TBase + TCount; - } - private final boolean isLVT (char c) - { - return isL (c) || isV (c) || isT (c); - } - private final boolean isHighSurrogate (char c) - { - return c >= highSurrogateStart && c <= highSurrogateEnd; - } - private final boolean isLowSurrogate (char c) - { - return c >= lowSurrogateStart && c <= lowSurrogateEnd; - } - - public int next () - { - int end = iter.getEndIndex(); - if (iter.getIndex() == end) - return DONE; - - char c; - for (char prev = CharacterIterator.DONE; iter.getIndex() < end; prev = c) - { - c = iter.next(); - if (c == CharacterIterator.DONE) - break; - int type = Character.getType(c); - - // Break after paragraph separators. - if (type == Character.PARAGRAPH_SEPARATOR) - break; - - // Now we need some lookahead. - char ahead = iter.next(); - iter.previous(); - if (ahead == CharacterIterator.DONE) - break; - int aheadType = Character.getType(ahead); - - if (aheadType != Character.NON_SPACING_MARK - && ! isLowSurrogate (ahead) - && ! isLVT (ahead)) - break; - if (! isLVT (c) && isLVT (ahead)) - break; - if (isL (c) && ! isLVT (ahead) - && aheadType != Character.NON_SPACING_MARK) - break; - if (isV (c) && ! isV (ahead) && !isT (ahead) - && aheadType != Character.NON_SPACING_MARK) - break; - if (isT (c) && ! isT (ahead) - && aheadType != Character.NON_SPACING_MARK) - break; - - if (! isHighSurrogate (c) && isLowSurrogate (ahead)) - break; - if (isHighSurrogate (c) && ! isLowSurrogate (ahead)) - break; - if (! isHighSurrogate (prev) && isLowSurrogate (c)) - break; - } - - return iter.getIndex(); - } - - public int previous () - { - if (iter.getIndex() == iter.getBeginIndex()) - return DONE; - - while (iter.getIndex() >= iter.getBeginIndex()) - { - char c = iter.previous(); - if (c == CharacterIterator.DONE) - break; - int type = Character.getType(c); - - if (type != Character.NON_SPACING_MARK - && ! isLowSurrogate (c) - && ! isLVT (c)) - break; - - // Now we need some lookahead. - char ahead = iter.previous(); - if (ahead == CharacterIterator.DONE) - { - iter.next(); - break; - } - char ahead2 = iter.previous(); - iter.next(); - iter.next(); - if (ahead2 == CharacterIterator.DONE) - break; - int aheadType = Character.getType(ahead); - - if (aheadType == Character.PARAGRAPH_SEPARATOR) - break; - - if (isLVT (c) && ! isLVT (ahead)) - break; - if (! isLVT (c) && type != Character.NON_SPACING_MARK - && isL (ahead)) - break; - if (! isV (c) && ! isT (c) && type != Character.NON_SPACING_MARK - && isV (ahead)) - break; - if (! isT (c) && type != Character.NON_SPACING_MARK - && isT (ahead)) - break; - - if (isLowSurrogate (c) && ! isHighSurrogate (ahead)) - break; - if (! isLowSurrogate (c) && isHighSurrogate (ahead)) - break; - if (isLowSurrogate (ahead) && ! isHighSurrogate (ahead2)) - break; - } - - return iter.getIndex(); - } -} diff --git a/libjava/gnu/java/text/FormatBuffer.java b/libjava/gnu/java/text/FormatBuffer.java deleted file mode 100644 index e6b68208792..00000000000 --- a/libjava/gnu/java/text/FormatBuffer.java +++ /dev/null @@ -1,136 +0,0 @@ -/* FormatBuffer.java -- General interface to build attributed strings. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.text; - -import java.text.AttributedCharacterIterator; -import java.util.HashMap; - -/** - * This interface describes a modifiable buffer which contains attributed - * characters. The implementation may or may not implements attributes. It - * aims to greatly simplify and clarify the implementation of java.text - * formatters. The buffer may be appended or have its tail cut. It may also - * be completely cleant up. - * - * @author Guilhem Lavaux <guilhem@kaffe.org> - * @date April 10, 2004 - */ -public interface FormatBuffer -{ - /** - * This method appends a simple string to the buffer. This part of - * the buffer will be attributed using the default attribute. - * - * @param s The string to append to the buffer. - */ - public void append(String s); - - /** - * This method appends a simple string to the buffer. This part of - * the buffer will have the specified attribute (and only this one). - * The default attribute may be changed after calling this method. - * - * @param s The string to append to the buffer. - * @param attr Attribute to use for the string in the buffer. - */ - public void append(String s, AttributedCharacterIterator.Attribute attr); - - /** - * This method appends a simple string to the buffer. This part of - * the buffer will be attributed using the specified ranges and attributes. - * To have an example on how to specify ranges see {@link gnu.java.text.FormatCharacterIterator}. - * - * @param s The string to append to the buffer. - * @param ranges The ranges describing how the attributes should be applied - * to the string. - * @param attrs The attributes of the string in the buffer. - */ - public void append(String s, int[] ranges, HashMap[] attrs); - - /** - * This method appends a simple char to the buffer. This part of - * the buffer will be attributed using the default attribute. - * - * @param c The character to append to the buffer. - */ - public void append(char c); - - /** - * This method appends a simple character to the buffer. This part of - * the buffer will have the specified attribute (and only this one). - * The default attribute may be changed after calling this method. - * - * @param c The character to append to the buffer. - * @param attr Attribute to use for the character in the buffer. - */ - public void append(char c, AttributedCharacterIterator.Attribute attr); - - /** - * This method changes the current default attribute for the next string - * or character which will be appended to the buffer. - * - * @param attr The attribute which will be used by default. - */ - public void setDefaultAttribute(AttributedCharacterIterator.Attribute attr); - - /** - * This method returns the current default attribute for the buffer. - * - * @return The default attribute for the buffer. - */ - public AttributedCharacterIterator.Attribute getDefaultAttribute(); - - /** - * This method cuts the last characters of the buffer. The number of - * characters to cut is given by "length". - * - * @param length Number of characters to cut at the end of the buffer. - */ - public void cutTail(int length); - - /** - * This method resets completely the buffer. - */ - public void clear(); - - /** - * This method returns the number of character in the buffer. - * - * @return The number of character in the buffer. - */ - public int length(); -} diff --git a/libjava/gnu/java/text/FormatCharacterIterator.java b/libjava/gnu/java/text/FormatCharacterIterator.java deleted file mode 100644 index 7c41ed27c82..00000000000 --- a/libjava/gnu/java/text/FormatCharacterIterator.java +++ /dev/null @@ -1,534 +0,0 @@ -/* FormatCharacter.java -- Implementation of AttributedCharacterIterator for - formatters. - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.text; - -import gnu.classpath.Configuration; - -import java.text.AttributedCharacterIterator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Vector; - -/** - * This class should not be put public and it is only intended to the - * classes of the java.text package. Its aim is to build a segmented - * character iterator by appending strings and adding attributes to - * portions of strings. The code intends to do some optimization - * concerning memory consumption and attribute access but at the - * end it is only an AttributedCharacterIterator. - * - * @author Guilhem Lavaux <guilhem@kaffe.org> - * @date November 22, 2003 - */ -public class FormatCharacterIterator implements AttributedCharacterIterator -{ - private String formattedString; - private int charIndex; - private int attributeIndex; - private int[] ranges; - private HashMap[] attributes; - - /** - * This constructor builds an empty iterated strings. The attributes - * are empty and so is the string. However you may append strings - * and attributes to this iterator. - */ - public FormatCharacterIterator() - { - formattedString = ""; - ranges = new int[0]; - attributes = new HashMap[0]; - } - - /** - * This constructor take a string <code>s</code>, a set of ranges - * and the corresponding attributes. This is used to build an iterator. - * The array <code>ranges</code> should be formatted as follow: - * each element of <code>ranges</code> specifies the index in the string - * until which the corresponding map of attributes at the same position - * is applied. For example, if you have: - * <pre> - * s = "hello"; - * ranges = new int[] { 2, 6 }; - * attributes = new HashMap[2]; - * </pre> - * <code>"he"</code> will have the attributes <code>attributes[0]</code>, - * <code>"llo"</code> the <code>attributes[1]</code>. - */ - public FormatCharacterIterator (String s, int[] ranges, HashMap[] attributes) - { - formattedString = s; - this.ranges = ranges; - this.attributes = attributes; - } - - /* - * The following methods are inherited from AttributedCharacterIterator, - * and thus are already documented. - */ - - public Set getAllAttributeKeys() - { - if (attributes != null && attributes[attributeIndex] != null) - return attributes[attributeIndex].keySet(); - else - return new HashSet(); - } - - public Map getAttributes() - { - if (attributes != null && attributes[attributeIndex] != null) - return attributes[attributeIndex]; - else - return new HashMap(); - } - - public Object getAttribute (AttributedCharacterIterator.Attribute attrib) - { - if (attributes != null && attributes[attributeIndex] != null) - return attributes[attributeIndex].get (attrib); - else - return null; - } - - public int getRunLimit(Set reqAttrs) - { - if (attributes == null) - return formattedString.length(); - - int currentAttrIndex = attributeIndex; - Set newKeys; - - do - { - currentAttrIndex++; - if (currentAttrIndex == attributes.length) - return formattedString.length(); - if (attributes[currentAttrIndex] == null) - break; - newKeys = attributes[currentAttrIndex].keySet(); - } - while (newKeys.containsAll (reqAttrs)); - - return ranges[currentAttrIndex-1]; - } - - public int getRunLimit (AttributedCharacterIterator.Attribute attribute) - { - Set s = new HashSet(); - - s.add (attribute); - return getRunLimit (s); - } - - public int getRunLimit() - { - if (attributes == null) - return formattedString.length(); - if (attributes[attributeIndex] == null) - { - for (int i=attributeIndex+1;i<attributes.length;i++) - if (attributes[i] != null) - return ranges[i-1]; - return formattedString.length(); - } - - return getRunLimit (attributes[attributeIndex].keySet()); - } - - public int getRunStart (Set reqAttrs) - { - if (attributes == null) - return formattedString.length(); - - int currentAttrIndex = attributeIndex; - Set newKeys = null; - - do - { - if (currentAttrIndex == 0) - return 0; - - currentAttrIndex--; - if (attributes[currentAttrIndex] == null) - break; - newKeys = attributes[currentAttrIndex].keySet(); - } - while (newKeys.containsAll (reqAttrs)); - - return (currentAttrIndex > 0) ? ranges[currentAttrIndex-1] : 0; - } - - public int getRunStart() - { - if (attributes == null) - return 0; - - if (attributes[attributeIndex] == null) - { - for (int i=attributeIndex;i>0;i--) - if (attributes[i] != null) - return ranges[attributeIndex-1]; - return 0; - } - - return getRunStart (attributes[attributeIndex].keySet()); - } - - public int getRunStart (AttributedCharacterIterator.Attribute attribute) - { - Set s = new HashSet(); - - s.add (attribute); - return getRunStart (s); - } - - public Object clone() - { - return new FormatCharacterIterator (formattedString, ranges, attributes); - } - - /* - * The following methods are inherited from CharacterIterator and thus - * are already documented. - */ - - public char current() - { - return formattedString.charAt (charIndex); - } - - public char first() - { - charIndex = 0; - attributeIndex = 0; - return formattedString.charAt (0); - } - - public int getBeginIndex() - { - return 0; - } - - public int getEndIndex() - { - return formattedString.length(); - } - - public int getIndex() - { - return charIndex; - } - - public char last() - { - charIndex = formattedString.length()-1; - if (attributes != null) - attributeIndex = attributes.length-1; - return formattedString.charAt (charIndex); - } - - public char next() - { - charIndex++; - if (charIndex >= formattedString.length()) - { - charIndex = getEndIndex(); - return DONE; - } - if (attributes != null) - { - if (charIndex >= ranges[attributeIndex]) - attributeIndex++; - } - return formattedString.charAt (charIndex); - } - - public char previous() - { - charIndex--; - if (charIndex < 0) - { - charIndex = 0; - return DONE; - } - - if (attributes != null) - { - if (charIndex < ranges[attributeIndex]) - attributeIndex--; - } - return formattedString.charAt (charIndex); - } - - public char setIndex (int position) - { - if (position < 0 || position > formattedString.length()) - throw new IllegalArgumentException ("position is out of range"); - - charIndex = position; - if (attributes != null) - { - for (attributeIndex=0;attributeIndex<attributes.length; - attributeIndex++) - if (ranges[attributeIndex] > charIndex) - break; - attributeIndex--; - } - if (charIndex == formattedString.length()) - return DONE; - else - return formattedString.charAt (charIndex); - } - - /** - * This method merge the specified attributes and ranges with the - * internal tables. This method is in charge of the optimization - * of tables. Two following sets of attributes are never the same. - * - * @see #FormatCharacterIterator() - * - * @param attributes the new array attributes to apply to the string. - */ - public void mergeAttributes (HashMap[] attributes, int[] ranges) - { - Vector new_ranges = new Vector(); - Vector new_attributes = new Vector(); - int i = 0, j = 0; - - debug("merging " + attributes.length + " attrs"); - - while (i < this.ranges.length && j < ranges.length) - { - if (this.attributes[i] != null) - { - new_attributes.add (this.attributes[i]); - if (attributes[j] != null) - this.attributes[i].putAll (attributes[j]); - } - else - { - new_attributes.add (attributes[j]); - } - if (this.ranges[i] == ranges[j]) - { - new_ranges.add (new Integer (ranges[j])); - i++; - j++; - } - else if (this.ranges[i] < ranges[j]) - { - new_ranges.add (new Integer (this.ranges[i])); - i++; - } - else - { - new_ranges.add (new Integer (ranges[j])); - j++; - } - } - - if (i != this.ranges.length) - { - for (;i<this.ranges.length;i++) - { - new_attributes.add (this.attributes[i]); - new_ranges.add (new Integer (this.ranges[i])); - } - } - if (j != ranges.length) - { - for (;j<ranges.length;j++) - { - new_attributes.add (attributes[j]); - new_ranges.add (new Integer (ranges[j])); - } - } - - this.attributes = new HashMap[new_attributes.size()]; - this.ranges = new int[new_ranges.size()]; - System.arraycopy (new_attributes.toArray(), 0, this.attributes, - 0, this.attributes.length); - - for (i=0;i<new_ranges.size();i++) - { - this.ranges[i] = ((Integer)new_ranges.elementAt (i)).intValue(); - } - - dumpTable(); - } - - /** - * This method appends to the internal attributed string the attributed - * string contained in the specified iterator. - * - * @param iterator the iterator which contains the attributed string to - * append to this iterator. - */ - public void append (AttributedCharacterIterator iterator) - { - char c = iterator.first(); - Vector more_ranges = new Vector(); - Vector more_attributes = new Vector(); - - do - { - formattedString = formattedString + String.valueOf (c); - // TODO: Reduce the size of the output array. - more_attributes.add (iterator.getAttributes()); - more_ranges.add (new Integer (formattedString.length())); - // END TOOD - c = iterator.next(); - } - while (c != DONE); - - HashMap[] new_attributes = new HashMap[attributes.length - + more_attributes.size()]; - int[] new_ranges = new int[ranges.length + more_ranges.size()]; - - System.arraycopy (attributes, 0, new_attributes, 0, attributes.length); - System.arraycopy (more_attributes.toArray(), 0, new_attributes, - attributes.length, more_attributes.size()); - - System.arraycopy (ranges, 0, new_ranges, 0, ranges.length); - Object[] new_ranges_array = more_ranges.toArray(); - for (int i = 0; i < more_ranges.size();i++) - new_ranges[i+ranges.length] = ((Integer) new_ranges_array[i]).intValue(); - - attributes = new_attributes; - ranges = new_ranges; - } - - /** - * This method appends an attributed string which attributes are specified - * directly in the calling parameters. - * - * @param text The string to append. - * @param local_attributes The attributes to put on this string in the - * iterator. If it is <code>null</code> the string will simply have no - * attributes. - */ - public void append (String text, HashMap local_attributes) - { - int[] new_ranges = new int[ranges.length+1]; - HashMap[] new_attributes = new HashMap[attributes.length+1]; - - formattedString += text; - System.arraycopy (attributes, 0, new_attributes, 0, attributes.length); - System.arraycopy (ranges, 0, new_ranges, 0, ranges.length); - new_ranges[ranges.length] = formattedString.length(); - new_attributes[attributes.length] = local_attributes; - - ranges = new_ranges; - attributes = new_attributes; - } - - /** - * This method appends a string without attributes. It is completely - * equivalent to call {@link #append(String,HashMap)} with local_attributes - * equal to <code>null</code>. - * - * @param text The string to append to the iterator. - */ - public void append (String text) - { - append (text, null); - } - - /** - * This method adds a set of attributes to a range of character. The - * bounds are always inclusive. In the case many attributes have to - * be added it is advised to directly use {@link #mergeAttributes([Ljava.util.HashMap;[I} - * - * @param attributes Attributes to merge into the iterator. - * @param range_start Lower bound of the range of characters which will receive the - * attribute. - * @param range_end Upper bound of the range of characters which will receive the - * attribute. - * - * @throws IllegalArgumentException if ranges are out of bounds. - */ - public void addAttributes(HashMap attributes, int range_start, int range_end) - { - if (range_start == 0) - mergeAttributes(new HashMap[] { attributes }, new int[] { range_end }); - else - mergeAttributes(new HashMap[] { null, attributes }, new int[] { range_start, range_end }); - } - - private void debug(String s) - { - if (Configuration.DEBUG) - System.out.println(s); - } - - private void dumpTable() - { - int start_range = 0; - - if (!Configuration.DEBUG) - return; - - System.out.println("Dumping internal table:"); - for (int i = 0; i < ranges.length; i++) - { - System.out.print("\t" + start_range + " => " + ranges[i] + ":"); - if (attributes[i] == null) - System.out.println("null"); - else - { - Set keyset = attributes[i].keySet(); - if (keyset != null) - { - Iterator keys = keyset.iterator(); - - while (keys.hasNext()) - System.out.print(" " + keys.next()); - } - else - System.out.println("keySet null"); - System.out.println(); - } - } - System.out.println(); - System.out.flush(); - } -} diff --git a/libjava/gnu/java/text/LineBreakIterator.java b/libjava/gnu/java/text/LineBreakIterator.java deleted file mode 100644 index ad07479fb78..00000000000 --- a/libjava/gnu/java/text/LineBreakIterator.java +++ /dev/null @@ -1,194 +0,0 @@ -/* LineBreakIterator.java - Default word BreakIterator. - Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.text; - -import java.text.CharacterIterator; - -/** - * @author Tom Tromey <tromey@cygnus.com> - * @date March 22, 1999 - * Written using The Unicode Standard, Version 2.0. - */ - -public class LineBreakIterator extends BaseBreakIterator -{ - public Object clone () - { - return new LineBreakIterator (this); - } - - public LineBreakIterator () - { - } - - private LineBreakIterator (LineBreakIterator other) - { - iter = (CharacterIterator) other.iter.clone(); - } - - // Some methods to tell us different properties of characters. - private final boolean isNb (char c) - { - return (c == 0x00a0 // NO-BREAK SPACE - || c == 0x2011 // NON-BREAKING HYPHEN - || c == 0xfeff); // ZERO WITH NO-BREAK SPACE - } - private final boolean isClose (int type) - { - return (type == Character.END_PUNCTUATION - // Unicode book says "comma, period, ...", which I take to - // mean "Po" class. - || type == Character.OTHER_PUNCTUATION); - } - private final boolean isIdeo (char c) - { - return (c >= 0x3040 && c <= 0x309f // Hiragana - || c >= 0x30a0 && c <= 0x30ff // Katakana - || c >= 0x4e00 && c <= 0x9fff // Han - || c >= 0x3100 && c <= 0x312f); // Bopomofo - } - - public int next () - { - int end = iter.getEndIndex(); - if (iter.getIndex() == end) - return DONE; - - while (iter.getIndex() < end) - { - char c = iter.current(); - int type = Character.getType(c); - - char n = iter.next(); - - if (n == CharacterIterator.DONE - || type == Character.PARAGRAPH_SEPARATOR - || type == Character.LINE_SEPARATOR) - break; - - // Handle two cases where we must scan for non-spacing marks. - int start = iter.getIndex(); - if (type == Character.SPACE_SEPARATOR - || type == Character.START_PUNCTUATION - || isIdeo (c)) - { - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.NON_SPACING_MARK) - n = iter.next(); - if (n == CharacterIterator.DONE) - break; - - if (type == Character.SPACE_SEPARATOR) - { - int nt = Character.getType(n); - if (nt != Character.NON_SPACING_MARK - && nt != Character.SPACE_SEPARATOR - && ! isNb (n)) - break; - } - else if (type == Character.START_PUNCTUATION) - { - if (isIdeo (n)) - { - // Open punctuation followed by non spacing marks - // and then ideograph does not have a break in - // it. So skip all this. - start = iter.getIndex(); - } - } - else - { - // Ideograph preceded this character. - if (isClose (Character.getType(n))) - break; - } - } - iter.setIndex(start); - } - - return iter.getIndex(); - } - - public int previous () - { - int start = iter.getBeginIndex(); - if (iter.getIndex() == start) - return DONE; - - while (iter.getIndex() >= start) - { - char c = iter.previous(); - if (c == CharacterIterator.DONE) - break; - int type = Character.getType(c); - - char n = iter.previous(); - if (n == CharacterIterator.DONE) - break; - iter.next(); - - int nt = Character.getType(n); - // Break after paragraph separators. - if (nt == Character.PARAGRAPH_SEPARATOR - || nt == Character.LINE_SEPARATOR) - break; - - // Skip non-spacing marks. - int init = iter.getIndex(); - while (n != CharacterIterator.DONE && nt == Character.NON_SPACING_MARK) - { - n = iter.previous(); - nt = Character.getType(n); - } - - if (nt == Character.SPACE_SEPARATOR - && type != Character.SPACE_SEPARATOR - && type != Character.NON_SPACING_MARK - && ! isNb (c)) - break; - if (! isClose (type) && isIdeo (n)) - break; - if (isIdeo (c) && nt != Character.START_PUNCTUATION) - break; - iter.setIndex(init); - } - - return iter.getIndex(); - } -} diff --git a/libjava/gnu/java/text/SentenceBreakIterator.java b/libjava/gnu/java/text/SentenceBreakIterator.java deleted file mode 100644 index f91d269bb08..00000000000 --- a/libjava/gnu/java/text/SentenceBreakIterator.java +++ /dev/null @@ -1,247 +0,0 @@ -/* SentenceBreakIterator.java - Default sentence BreakIterator. - Copyright (C) 1999, 2001, 2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.text; - -import java.text.CharacterIterator; - -/** - * @author Tom Tromey <tromey@cygnus.com> - * @date March 23, 1999 - * Written using The Unicode Standard, Version 2.0. - */ - -public class SentenceBreakIterator extends BaseBreakIterator -{ - public Object clone () - { - return new SentenceBreakIterator (this); - } - - public SentenceBreakIterator () - { - } - - private SentenceBreakIterator (SentenceBreakIterator other) - { - iter = (CharacterIterator) other.iter.clone(); - } - - public int next () - { - int end = iter.getEndIndex(); - if (iter.getIndex() == end) - return DONE; - - while (iter.getIndex() < end) - { - char c = iter.current(); - if (c == CharacterIterator.DONE) - break; - int type = Character.getType(c); - - char n = iter.next(); - if (n == CharacterIterator.DONE) - break; - - // Always break after paragraph separator. - if (type == Character.PARAGRAPH_SEPARATOR) - break; - - if (c == '!' || c == '?') - { - // Skip close punctuation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.END_PUNCTUATION) - n = iter.next(); - // Skip (java) space, line and paragraph separators. - while (n != CharacterIterator.DONE && Character.isWhitespace(n)) - n = iter.next(); - - // There's always a break somewhere after `!' or `?'. - break; - } - - if (c == '.') - { - int save = iter.getIndex(); - // Skip close punctuation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.END_PUNCTUATION) - n = iter.next(); - // Skip (java) space, line and paragraph separators. - // We keep count because we need at least one for this period to - // represent a terminator. - int spcount = 0; - while (n != CharacterIterator.DONE && Character.isWhitespace(n)) - { - n = iter.next(); - ++spcount; - } - if (spcount > 0) - { - int save2 = iter.getIndex(); - // Skip over open puncutation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.START_PUNCTUATION) - n = iter.next(); - // Next character must not be lower case. - if (n == CharacterIterator.DONE - || ! Character.isLowerCase(n)) - { - iter.setIndex(save2); - break; - } - } - iter.setIndex(save); - } - } - - return iter.getIndex(); - } - - private final int previous_internal () - { - int start = iter.getBeginIndex(); - if (iter.getIndex() == start) - return DONE; - - while (iter.getIndex() >= start) - { - char c = iter.previous(); - if (c == CharacterIterator.DONE) - break; - - char n = iter.previous(); - if (n == CharacterIterator.DONE) - break; - iter.next(); - int nt = Character.getType(n); - - if (! Character.isLowerCase(c) - && (nt == Character.START_PUNCTUATION - || Character.isWhitespace(n))) - { - int save = iter.getIndex(); - int save_nt = nt; - char save_n = n; - // Skip open punctuation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.START_PUNCTUATION) - n = iter.previous(); - if (n == CharacterIterator.DONE) - break; - if (Character.isWhitespace(n)) - { - // Must have at least one (java) space after the `.'. - int save2 = iter.getIndex(); - while (n != CharacterIterator.DONE - && Character.isWhitespace(n)) - n = iter.previous(); - // Skip close punctuation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.END_PUNCTUATION) - n = iter.previous(); - if (n == CharacterIterator.DONE || n == '.') - { - // Communicate location of actual end. - period = iter.getIndex(); - iter.setIndex(save2); - break; - } - } - iter.setIndex(save); - nt = save_nt; - n = save_n; - } - - if (nt == Character.PARAGRAPH_SEPARATOR) - { - // Communicate location of actual end. - period = iter.getIndex(); - break; - } - else if (Character.isWhitespace(n) - || nt == Character.END_PUNCTUATION) - { - int save = iter.getIndex(); - // Skip (java) space, line and paragraph separators. - while (n != CharacterIterator.DONE - && Character.isWhitespace(n)) - n = iter.previous(); - // Skip close punctuation. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.END_PUNCTUATION) - n = iter.previous(); - int here = iter.getIndex(); - iter.setIndex(save); - if (n == CharacterIterator.DONE || n == '!' || n == '?') - { - // Communicate location of actual end. - period = here; - break; - } - } - else if (n == '!' || n == '?') - { - // Communicate location of actual end. - period = iter.getIndex(); - break; - } - } - - return iter.getIndex(); - } - - public int previous () - { - // We want to skip over the first sentence end to the second one. - // However, at the end of the string we want the first end. - int here = iter.getIndex(); - period = here; - int first = previous_internal (); - if (here == iter.getEndIndex() || first == DONE) - return first; - iter.setIndex(period); - return previous_internal (); - } - - // This is used for communication between previous and - // previous_internal. - private int period; -} diff --git a/libjava/gnu/java/text/StringFormatBuffer.java b/libjava/gnu/java/text/StringFormatBuffer.java deleted file mode 100644 index 5772186b4c5..00000000000 --- a/libjava/gnu/java/text/StringFormatBuffer.java +++ /dev/null @@ -1,121 +0,0 @@ -/* StringFormatBuffer.java -- Implements FormatBuffer using StringBuffer. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.java.text; - -import java.text.AttributedCharacterIterator; -import java.util.HashMap; - -/** - * This class is an implementation of a FormatBuffer without attributes. - * - * @author Guilhem Lavaux <guilhem@kaffe.org> - * @date April 10, 2004 - */ -public class StringFormatBuffer implements FormatBuffer -{ - private StringBuffer buffer; - private AttributedCharacterIterator.Attribute defaultAttr; - - public StringFormatBuffer(int prebuffer) - { - buffer = new StringBuffer(prebuffer); - } - - public StringFormatBuffer(StringBuffer buffer) - { - this.buffer = buffer; - } - - public void append(String s) - { - buffer.append(s); - } - - public void append(String s, AttributedCharacterIterator.Attribute attr) - { - buffer.append(s); - } - - public void append(String s, int[] ranges, HashMap[] attrs) - { - buffer.append(s); - } - - public void append(char c) - { - buffer.append(c); - } - - public void append(char c, AttributedCharacterIterator.Attribute attr) - { - buffer.append(c); - } - - public void setDefaultAttribute(AttributedCharacterIterator.Attribute attr) - { - defaultAttr = attr; - } - - public AttributedCharacterIterator.Attribute getDefaultAttribute() - { - return defaultAttr; - } - - public void cutTail(int length) - { - buffer.setLength(buffer.length()-length); - } - - public int length() - { - return buffer.length(); - } - - public void clear() - { - buffer.setLength(0); - } - - /** - * This method returns the internal {@link java.lang.StringBuffer} which - * contains the string of character. - */ - public StringBuffer getBuffer() - { - return buffer; - } -} diff --git a/libjava/gnu/java/text/WordBreakIterator.java b/libjava/gnu/java/text/WordBreakIterator.java deleted file mode 100644 index f140369f8c6..00000000000 --- a/libjava/gnu/java/text/WordBreakIterator.java +++ /dev/null @@ -1,250 +0,0 @@ -/* WordBreakIterator.java - Default word BreakIterator. - Copyright (C) 1999, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.text; - -import java.text.CharacterIterator; - -/** - * @author Tom Tromey <tromey@cygnus.com> - * @date March 22, 1999 - * Written using The Unicode Standard, Version 2.0. - */ - -public class WordBreakIterator extends BaseBreakIterator -{ - public Object clone () - { - return new WordBreakIterator (this); - } - - public WordBreakIterator () - { - } - - private WordBreakIterator (WordBreakIterator other) - { - iter = (CharacterIterator) other.iter.clone(); - } - - // Some methods to tell us different properties of characters. - private final boolean isHira (char c) - { - return c >= 0x3040 && c <= 0x309f; - } - private final boolean isKata (char c) - { - return c >= 0x30a0 && c <= 0x30ff; - } - private final boolean isHan (char c) - { - return c >= 0x4e00 && c <= 0x9fff; - } - - public int next () - { - int end = iter.getEndIndex(); - if (iter.getIndex() == end) - return DONE; - - while (iter.getIndex() < end) - { - char c = iter.current(); - if (c == CharacterIterator.DONE) - break; - int type = Character.getType(c); - - char n = iter.next(); - if (n == CharacterIterator.DONE) - break; - - // Break after paragraph separators. - if (type == Character.PARAGRAPH_SEPARATOR - || type == Character.LINE_SEPARATOR) - break; - - // Break between letters and non-letters. - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - boolean is_letter = Character.isLetter(c); - if (c != '\'' && ! is_letter && type != Character.NON_SPACING_MARK - && Character.isLetter(n)) - break; - - // Always break after certain symbols, such as punctuation. - // This heuristic is derived from hints in the JCL book and is - // not part of Unicode. It seems to be right, however. - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - if (c != '\'' - && (type == Character.DASH_PUNCTUATION - || type == Character.START_PUNCTUATION - || type == Character.END_PUNCTUATION - || type == Character.CONNECTOR_PUNCTUATION - || type == Character.OTHER_PUNCTUATION - || type == Character.MATH_SYMBOL - || type == Character.CURRENCY_SYMBOL - || type == Character.MODIFIER_SYMBOL - || type == Character.OTHER_SYMBOL - || type == Character.FORMAT - || type == Character.CONTROL)) - break; - - boolean is_hira = isHira (c); - boolean is_kata = isKata (c); - boolean is_han = isHan (c); - - // Special case Japanese. - if (! is_hira && ! is_kata && ! is_han - && type != Character.NON_SPACING_MARK - && (isHira (n) || isKata (n) || isHan (n))) - break; - - if (is_hira || is_kata || is_han || is_letter) - { - // Now we need to do some lookahead. We might need to do - // quite a bit of lookahead, so we save our position and - // restore it later. - int save = iter.getIndex(); - // Skip string of non spacing marks. - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.NON_SPACING_MARK) - n = iter.next(); - if (n == CharacterIterator.DONE) - break; - if ((is_hira && ! isHira (n)) - || (is_kata && ! isHira (n) && ! isKata (n)) - || (is_han && ! isHira (n) && ! isHan (n)) - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - || (is_letter && ! Character.isLetter(n) && n != '\'')) - break; - iter.setIndex(save); - } - } - - return iter.getIndex(); - } - - public int previous () - { - int start = iter.getBeginIndex(); - if (iter.getIndex() == start) - return DONE; - - while (iter.getIndex() >= start) - { - char c = iter.previous(); - if (c == CharacterIterator.DONE) - break; - - boolean is_hira = isHira (c); - boolean is_kata = isKata (c); - boolean is_han = isHan (c); - boolean is_letter = Character.isLetter(c); - - char n = iter.previous(); - if (n == CharacterIterator.DONE) - break; - iter.next(); - int type = Character.getType(n); - // Break after paragraph separators. - if (type == Character.PARAGRAPH_SEPARATOR - || type == Character.LINE_SEPARATOR) - break; - - // Break between letters and non-letters. - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - if (n != '\'' && ! Character.isLetter(n) - && type != Character.NON_SPACING_MARK - && is_letter) - break; - - // Always break after certain symbols, such as punctuation. - // This heuristic is derived from hints in the JCL book and is - // not part of Unicode. It seems to be right, however. - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - if (n != '\'' - && (type == Character.DASH_PUNCTUATION - || type == Character.START_PUNCTUATION - || type == Character.END_PUNCTUATION - || type == Character.CONNECTOR_PUNCTUATION - || type == Character.OTHER_PUNCTUATION - || type == Character.MATH_SYMBOL - || type == Character.CURRENCY_SYMBOL - || type == Character.MODIFIER_SYMBOL - || type == Character.OTHER_SYMBOL - || type == Character.FORMAT - || type == Character.CONTROL)) - break; - - // Special case Japanese. - if ((is_hira || is_kata || is_han) - && ! isHira (n) && ! isKata (n) && ! isHan (n) - && type != Character.NON_SPACING_MARK) - break; - - // We might have to skip over non spacing marks to see what's - // on the other side. - if (! is_hira || (! is_letter && c != '\'')) - { - int save = iter.getIndex(); - while (n != CharacterIterator.DONE - && Character.getType(n) == Character.NON_SPACING_MARK) - n = iter.previous(); - iter.setIndex(save); - // This is a strange case: a bunch of non-spacing marks at - // the beginning. We treat the current location as a word - // break. - if (n == CharacterIterator.DONE) - break; - if ((isHira (n) && ! is_hira) - || (isKata (n) && ! is_hira && ! is_kata) - || (isHan (n) && ! is_hira && ! is_han) - // FIXME: we treat apostrophe as part of a word. This - // is an English-ism. - || (! is_letter && c != '\'' && Character.isLetter(n))) - break; - } - } - - return iter.getIndex(); - } -} diff --git a/libjava/gnu/java/util/DoubleEnumeration.java b/libjava/gnu/java/util/DoubleEnumeration.java deleted file mode 100644 index 1fc37f8e0f8..00000000000 --- a/libjava/gnu/java/util/DoubleEnumeration.java +++ /dev/null @@ -1,138 +0,0 @@ -/* gnu.java.util.DoubleEnumeration - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util; - -import java.util.Enumeration; -import java.util.NoSuchElementException; - - -/** - * This is a helper class that combines two Enumerations. - * It returns the elements of the first Enumeration until it has - * no more elements and then returns the elements of the second - * Enumeration.<br> - * - * In the default case: - * <pre> - * doubleEnum = new DoubleEnumeration(enum1, enum2); - * while (doubleEnum.hasMoreElements()) { - * Object o = doubleEnum.nextElement(); - * do_something(o); - * } - * </pre> - * it calls hasMoreElements of the Enumerations as few times as - * possible. - * The references to the Enumerations are cleared as soon as they have no - * more elements to help garbage collecting. - * - * @author Jochen Hoenicke - * @author Mark Wielaard (mark@klomp.org) - */ -public class DoubleEnumeration implements Enumeration -{ - /** - * This is true as long as one of the enumerations has more - * elements. - * Only valid when hasChecked is true. - * Set in <code>hasMoreElements()</code> - */ - private boolean hasMore; - /** - * This is true, if it is sure that hasMore indicates wether there are - * more elements. - * Set to true in <code>hasMoreElements()</code>. - * Set to false in <code>getNextElement()</code>. - */ - private boolean hasChecked; - /** - * The first enumeration. - */ - private Enumeration e1; - /** - * The second enumeration. - */ - private Enumeration e2; - - /** - * Creates a new Enumeration combining the given two enumerations. - * The enumerations mustn't be accessed by other classes. - */ - public DoubleEnumeration(Enumeration e1, Enumeration e2) - { - this.e1 = e1; - this.e2 = e2; - hasChecked = false; - } - - /** - * Returns true, if at least one of the two enumerations has more - * elements. - */ - public boolean hasMoreElements() - { - if (hasChecked) - return hasMore; - - hasMore = (e1 != null && e1.hasMoreElements()); - - if (!hasMore) { - e1 = e2; - e2 = null; - hasMore = (e1 != null && e1.hasMoreElements()); - } - - hasChecked = true; - return hasMore; - } - - /** - * Returns the next element. This returns the next element of the - * first enumeration, if it has more elements, otherwise the next - * element of the second enumeration. If both enumeration don't have - * any elements it throws a <code>NoSuchElementException</code>. - */ - public Object nextElement() - { - if (!hasMoreElements()) - throw new NoSuchElementException(); - else { - hasChecked = false; - return e1.nextElement(); - } - } -} diff --git a/libjava/gnu/java/util/EmptyEnumeration.java b/libjava/gnu/java/util/EmptyEnumeration.java deleted file mode 100644 index 46a82d6cb53..00000000000 --- a/libjava/gnu/java/util/EmptyEnumeration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* EmptyEnumeration.java -- a constant empty enumeration - Copyright (C) 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util; - -import java.io.Serializable; -import java.util.Enumeration; -import java.util.NoSuchElementException; - -/** - * This is a helper class that produces an empty Enumerations. There is only - * one instance of this class that can be used whenever one needs a - * non-null but empty enumeration. Using this class prevents multiple - * small objects and inner classes. <code>getInstance()</code> returns - * the only instance of this class. It can be shared by multiple objects and - * threads. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public final class EmptyEnumeration implements Enumeration, Serializable -{ - /** The only instance of this class */ - private static final EmptyEnumeration instance = new EmptyEnumeration(); - - /** - * Private constructor that creates a new empty Enumeration. - */ - private EmptyEnumeration() - { - } - - /** - * Returns the only instance of this class. - * It can be shared by multiple objects and threads. - * - * @return the common empty enumeration - */ - public static EmptyEnumeration getInstance() - { - return instance; - } - - /** - * Returns false, since there are no elements. - * - * @return false - */ - public boolean hasMoreElements() - { - return false; - } - - /** - * Always throws <code>NoSuchElementException</code>, since it is empty. - * - * @throws NoSuchElementException this is empty - */ - public Object nextElement() - { - throw new NoSuchElementException(); - } -} diff --git a/libjava/gnu/java/util/prefs/FileBasedFactory.java b/libjava/gnu/java/util/prefs/FileBasedFactory.java deleted file mode 100644 index 70f3558fc6f..00000000000 --- a/libjava/gnu/java/util/prefs/FileBasedFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* FileBasedFactory - Default Classpath implementation of a PreferencesFactory - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util.prefs; - -import java.util.prefs.*; - -/** - * Default Classpath implementation of a PreferencesFactory. - * Returns system and user root Preferences nodes that are read from files. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class FileBasedFactory implements PreferencesFactory { - - public Preferences systemRoot() { - return null; - } - - public Preferences userRoot() { - return null; - } -} diff --git a/libjava/gnu/java/util/prefs/MemoryBasedFactory.java b/libjava/gnu/java/util/prefs/MemoryBasedFactory.java deleted file mode 100644 index abaf0016f5b..00000000000 --- a/libjava/gnu/java/util/prefs/MemoryBasedFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/* MemoryBasedFactory - Memory based PreferencesFactory usefull for testing - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util.prefs; - -import java.util.prefs.*; - -/** - * Memory based PreferencesFactory usefull for testing. - * Returns completely empty Preferences for system and user roots. - * All changes are only backed by the current instances in memory. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class MemoryBasedFactory implements PreferencesFactory { - - // Static fields containing the preferences root nodes - private static final Preferences systemPreferences - = new MemoryBasedPreferences(null, "", false); - private static final Preferences userPreferences - = new MemoryBasedPreferences(null, "", true); - - public Preferences systemRoot() { - return systemPreferences; - } - - public Preferences userRoot() { - return userPreferences; - } -} diff --git a/libjava/gnu/java/util/prefs/MemoryBasedPreferences.java b/libjava/gnu/java/util/prefs/MemoryBasedPreferences.java deleted file mode 100644 index b2f321c9c7e..00000000000 --- a/libjava/gnu/java/util/prefs/MemoryBasedPreferences.java +++ /dev/null @@ -1,144 +0,0 @@ -/* MemoryBasedPreferences - A Preference node which holds all entries in memory - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util.prefs; - -import java.util.HashMap; - -import java.util.prefs.*; - -/** - * A Preference node which holds all entries in memory - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class MemoryBasedPreferences extends AbstractPreferences { - - /** True if this is a preference node in the user tree, false otherwise. */ - private final boolean isUser; - - /** Contains all the preference entries of this node. */ - private HashMap entries = new HashMap(); - - /** - * Creates a new preferences node with the given name and parent. - * When isUser is true it will be user node otherwise it will be a system - * node. It will always set the <code>newNode</code> field to true - * since there is no real backing store, so all nodes are new. - */ - public MemoryBasedPreferences(MemoryBasedPreferences parent, - String name, - boolean isUser) { - super(parent, name); - this.isUser = isUser; - - // Since we do not have a real backing store all nodes are new - newNode = true; - } - - /** - * Returns true if this node was created as a user node. - */ - public boolean isUserNode() { - return isUser; - } - - /** - * Returns an empty array since all children names are always already - * chached. - */ - protected String[] childrenNamesSpi() throws BackingStoreException { - return new String[0]; - } - - /** - * Returns a new node with the given name with as parent this node and - * with the <code>isUser</code> flag set to the same value as this node. - */ - protected AbstractPreferences childSpi(String childName) { - return new MemoryBasedPreferences(this, childName, isUser); - } - - /** - * Returns a (possibly empty) array of keys of the preferences entries of - * this node. - */ - protected String[] keysSpi() throws BackingStoreException { - return (String[]) entries.keySet().toArray(new String[entries.size()]); - } - - /** - * Returns the associated value from this nodes preferences entries or - * null when the key has not been set. - */ - protected String getSpi(String key) { - return (String) entries.get(key); - } - - /** - * Sets the value for the given key. - */ - protected void putSpi(String key, String value) { - entries.put(key, value); - } - - /** - * Removes the entry with the given key. - */ - protected void removeSpi(String key) { - entries.remove(key); - } - - /** - * Does nothing since we do not have any backing store. - */ - protected void flushSpi() { - } - - /** - * Does nothing since we do not have any backing store. - */ - protected void syncSpi() { - } - - /** - * Just removes the entries map of this node. - */ - protected void removeNodeSpi() { - entries = null; - } -} diff --git a/libjava/gnu/java/util/prefs/NodeReader.java b/libjava/gnu/java/util/prefs/NodeReader.java deleted file mode 100644 index 4cd52e5dbf9..00000000000 --- a/libjava/gnu/java/util/prefs/NodeReader.java +++ /dev/null @@ -1,223 +0,0 @@ -/* NodeReader - Reads and imports preferences nodes from files - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util.prefs; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.prefs.InvalidPreferencesFormatException; -import java.util.prefs.Preferences; -import java.util.prefs.PreferencesFactory; - -/** - * Reads and imports preferences nodes from files. - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class NodeReader { - - private final BufferedReader br; - private String line = ""; - - private final PreferencesFactory factory; - - public NodeReader(Reader r, PreferencesFactory factory) { - if(r instanceof BufferedReader) { - br = (BufferedReader) r; - } else { - br = new BufferedReader(r); - } - this.factory = factory; - } - - public NodeReader(InputStream is, PreferencesFactory factory) { - this(new InputStreamReader(is), factory); - } - - public void importPreferences() - throws InvalidPreferencesFormatException, IOException - { - readPreferences(); - } - - private void readPreferences() - throws InvalidPreferencesFormatException, IOException - { - // Begin starting tag - skipTill("<preferences"); - - readRoot(); - - // Ending tag - skipTill("</preferences>"); - } - - private void readRoot() - throws InvalidPreferencesFormatException, IOException - { - // Begin starting tag - skipTill("<root"); - - // type attribute - skipTill("type=\""); - String type = readTill("\""); - Preferences root; - if ("user".equals(type)) { - root = factory.userRoot(); - } else if ("system".equals(type)) { - root = factory.systemRoot(); - } else { - throw new InvalidPreferencesFormatException("Unknown type: " - + type); - } - - // Read root map and subnodes - readMap(root); - readNodes(root); - - // Ending tag - skipTill("</root>"); - } - - private void readNodes(Preferences node) - throws InvalidPreferencesFormatException, IOException - { - while ("node".equals(nextTag())) { - skipTill("<node"); - skipTill("name=\""); - String name = readTill("\""); - Preferences subnode = node.node(name); - System.out.println("Found subnode: " + subnode.absolutePath()); - readMap(subnode); - readNodes(subnode); - skipTill("</node>"); - } - - } - - private void readMap(Preferences node) - throws InvalidPreferencesFormatException, IOException - { - // Begin map tag - skipTill("<map"); - - // Empty map? - if (line.startsWith("/>")) { - line = line.substring(2); - return; - } - - // Map entries - readEntries(node); - - // Ending tag - skipTill("</map>"); - } - - private void readEntries(Preferences node) - throws InvalidPreferencesFormatException, IOException - { - while ("entry".equals(nextTag())) { - skipTill("<entry"); - skipTill("key=\""); - String key = readTill("\""); - skipTill("value=\""); - String value = readTill("\""); - System.out.println("Key: " + key + " Value: " + value); - node.put(key, value); - } - } - - private void skipTill(String s) - throws InvalidPreferencesFormatException, IOException - { - while(true) { - if (line == null) - throw new InvalidPreferencesFormatException(s + " not found"); - - int index = line.indexOf(s); - if (index == -1) { - line = br.readLine(); - } else { - line = line.substring(index+s.length()); - return; - } - } - } - - private String readTill(String s) - throws InvalidPreferencesFormatException - { - int index = line.indexOf(s); - if (index == -1) - throw new InvalidPreferencesFormatException(s + " not found"); - - String read = line.substring(0, index); - line = line.substring(index+s.length()); - - return read; - } - - private String nextTag() - throws InvalidPreferencesFormatException, IOException - { - while(true) { - if (line == null) - throw new InvalidPreferencesFormatException("unexpected EOF"); - - int start = line.indexOf("<"); - if (start == -1) { - line = br.readLine(); - } else { - // Find end of tag - int end = start+1; - while (end != line.length() - && " \t\r\n".indexOf(line.charAt(end)) == -1) { - end++; - } - // Line now starts at the found tag - String tag = line.substring(start+1,end); - line = line.substring(start); - return tag; - } - } - } - -} diff --git a/libjava/gnu/java/util/prefs/NodeWriter.java b/libjava/gnu/java/util/prefs/NodeWriter.java deleted file mode 100644 index 1eed9e66e2d..00000000000 --- a/libjava/gnu/java/util/prefs/NodeWriter.java +++ /dev/null @@ -1,315 +0,0 @@ -/* NodeWriter - Writes and exports preferences nodes to files - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.java.util.prefs; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; - -import java.util.StringTokenizer; - -import java.util.prefs.*; - -/** - * Writes and exports preferences nodes to files - * - * @author Mark Wielaard (mark@klomp.org) - */ -public class NodeWriter { - - /** The Preferences node to write. */ - private final Preferences prefs; - - /** The bufferedWriter to write the node to. */ - private final BufferedWriter bw; - - /** - * True if the complete sub tree should be written, - * false if only the node should be written. - */ - private boolean subtree; - - /** - * Creates a new NodeWriter for the given preferences node and writer. - */ - public NodeWriter(Preferences prefs, Writer w) { - this.prefs = prefs; - if (w instanceof BufferedWriter) { - this.bw = (BufferedWriter) w; - } else { - this.bw = new BufferedWriter(w); - } - } - - /** - * Creates a new NodeWriter for the given preferences node and - * outputstream. Creates a new OutputStreamWriter. - */ - public NodeWriter(Preferences prefs, OutputStream os) { - this(prefs, new OutputStreamWriter(os)); - } - - /** - * Writes the preference node plus the complete subtree. - */ - public void writePrefsTree() throws BackingStoreException, IOException { - subtree = true; - writeHeader(); - writePreferences(); - bw.flush(); - } - - /** - * Writes only the preference node. - */ - public void writePrefs() throws BackingStoreException, IOException { - subtree = false; - writeHeader(); - writePreferences(); - bw.flush(); - } - - /** - * Writes the standard header. - */ - private void writeHeader() throws BackingStoreException, IOException { - bw.write("<?xml version=\"1.0\"?>"); - bw.newLine(); - bw.newLine(); - bw.write("<!-- GNU Classpath java.util.prefs Preferences "); - - if (prefs.isUserNode()) { - bw.write("user"); - } else { - bw.write("system"); - } - - // root node? - if (prefs.parent() == null) { - bw.write(" root"); - } - - if (subtree) { - bw.write(" tree"); - } else { - bw.write(" node"); - } - - // no root? - if (prefs.parent() != null) { - bw.newLine(); - bw.write(" '"); - bw.write(prefs.absolutePath()); - bw.write('\''); - bw.newLine(); - } - bw.write(" -->"); - bw.newLine(); - bw.newLine(); - } - - /** - * Write the preferences tag and the root. - */ - private void writePreferences() throws BackingStoreException, IOException { - bw.write("<preferences>"); - bw.newLine(); - writeRoot(); - bw.write("</preferences>"); - bw.newLine(); - } - - private void writeRoot() throws BackingStoreException, IOException { - bw.write(" <root type=\""); - if (prefs.isUserNode()) { - bw.write("user"); - } else { - bw.write("system"); - } - bw.write("\"/>"); - - writeRootMap(); - writeNode(); - - bw.write(" </root>"); - bw.newLine(); - } - - private void writeRootMap() throws BackingStoreException, IOException { - // Is it a root node? - if(prefs.parent() == null && prefs.keys().length > 0) { - bw.newLine(); - writeMap(prefs, 2); - } else { - bw.write("<map/>"); - bw.newLine(); - } - } - - /** - * Writes all the parents of the preferences node without any entries. - * Returns the number of parents written, which has to be used as - * argument to <code>writeCloseParents()</code> after writing the node - * itself. - */ - private int writeParents() throws IOException { - int parents; - String path = prefs.absolutePath(); - int lastslash = path.lastIndexOf("/"); - if (lastslash > 0) { - path = path.substring(1, lastslash); - StringTokenizer st = new StringTokenizer(path); - parents = st.countTokens(); - - System.out.println("path: " + path); - System.out.println("parents: " + parents); - - for (int i=0; i<parents; i++) { - String name = st.nextToken(); - indent(i+2); - bw.write("<node name=\"" + name + "\">"); - bw.write("<map/>"); - bw.write("</node>"); - bw.newLine(); - } - } else { - parents = 0; - } - - return parents; - } - - private void writeCloseParents(int parents) throws IOException { - while(parents > 0) { - indent(parents+1); - bw.write("</node>"); - bw.newLine(); - parents--; - } - } - - private void writeNode() throws BackingStoreException, IOException { - int parents = writeParents(); - // root? - int indent; - if (prefs.parent() == null) { - indent = parents+1; - } else { - indent = parents+2; - } - writeNode(prefs, indent); - writeCloseParents(parents); - } - - private void writeNode(Preferences node, int indent) - throws BackingStoreException, IOException - { - // not root? - if (node.parent() != null) { - indent(indent); - bw.write("<node name=\"" + node.name() + "\">"); - if (node.keys().length > 0) { - bw.newLine(); - } - writeMap(node, indent+1); - } - - if (subtree) { - String[] children = node.childrenNames(); - for (int i=0; i<children.length; i++) { - Preferences child = node.node(children[i]); - writeNode(child, indent+1); - } - } - - // not root? - if (node.parent() != null) { - indent(indent); - bw.write("</node>"); - bw.newLine(); - } - } - - private void writeMap(Preferences node, int indent) - throws BackingStoreException, IOException - { - // construct String used for indentation - StringBuffer indentBuffer = new StringBuffer(2*indent); - for (int i=0; i < indent; i++) - indentBuffer.append(" "); - String indentString = indentBuffer.toString(); - - if (node.keys().length > 0) { - bw.write(indentString); - bw.write("<map>"); - bw.newLine(); - writeEntries(node, indentString + " "); - bw.write(indentString); - bw.write("</map>"); - } else { - bw.write("<map/>"); - } - bw.newLine(); - } - - private void writeEntries(Preferences node, String indent) - throws BackingStoreException, IOException - { - String[] keys = node.keys(); - for(int i = 0; i < keys.length; i++) { - String value = node.get(keys[i], null); - if (value == null) { - throw new BackingStoreException("null value for key '" - + keys[i] + "'"); - } - - bw.write(indent); - bw.write("<entry key=\"" + keys[i] + "\"" - + " value=\"" + value + "\"/>"); - bw.newLine(); - } - } - - private void indent(int x) throws IOException { - for (int i=0; i<x; i++) { - bw.write(" "); - } - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/HTML_401F.java b/libjava/gnu/javax/swing/text/html/parser/HTML_401F.java deleted file mode 100755 index 1ed42a2ab98..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/HTML_401F.java +++ /dev/null @@ -1,3729 +0,0 @@ -/* HTML_401F.java -- HTML 4.01 FRAMESET DTD java conception. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser; - -import gnu.javax.swing.text.html.parser.models.PCDATAonly_model; -import gnu.javax.swing.text.html.parser.models.TableRowContentModel; -import gnu.javax.swing.text.html.parser.models.noTagModel; - -import java.io.IOException; -import java.io.Serializable; - -import javax.swing.text.html.parser.*; -import javax.swing.text.html.parser.ContentModel; -import javax.swing.text.html.parser.DTDConstants; - -/** - * This class represents the java implementation of the HTML 4.01 - * ( -//W3C//DTD HTML 4.01 Frameset//EN ) Frameset version. The - * Frameset version includes as recommended, as obsoleted features and - * also the frameset support. This the default DTD to parse HTML - * documents in this implementation, containing 315 pre-defined general - * entities and 92 elements. - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class HTML_401F - extends gnuDTD - implements DTDConstants, Serializable -{ - private static final long serialVersionUID = 1; - - /** - * The standard name of this DTD, - * '-//W3C//DTD HTML 4.01 Frameset//EN' - */ - public static final String DTD_NAME = "-//W3C//DTD HTML 4.01 Frameset//EN"; - - /** - * The integer representing length in pixels. - */ - static final int PIXELS = NUMBER; - - static final String[] NONE = new String[0]; - - /* Define the HTML tags. */ - static final String PCDATA = "#pcdata"; - static final String A = "a"; - static final String ABBR = "abbr"; - static final String ACRONYM = "acronym"; - static final String ADDRESS = "address"; - static final String APPLET = "applet"; - static final String AREA = "area"; - static final String B = "b"; - static final String BASE = "base"; - static final String BASEFONT = "basefont"; - static final String BDO = "bdo"; - static final String BIG = "big"; - static final String BLOCKQUOTE = "blockquote"; - static final String BODY = "body"; - static final String BR = "br"; - static final String BUTTON = "button"; - static final String CAPTION = "caption"; - static final String CENTER = "center"; - static final String CITE = "cite"; - static final String CODE = "code"; - static final String COL = "col"; - static final String COLGROUP = "colgroup"; - static final String DEFAULTS = "default"; - static final String DD = "dd"; - static final String DEL = "del"; - static final String DFN = "dfn"; - static final String DIR = "dir"; - static final String DIV = "div"; - static final String DL = "dl"; - static final String DT = "dt"; - static final String EM = "em"; - static final String FIELDSET = "fieldset"; - static final String FONT = "font"; - static final String FORM = "form"; - static final String FRAME = "frame"; - static final String FRAMESET = "frameset"; - static final String H1 = "h1"; - static final String H2 = "h2"; - static final String H3 = "h3"; - static final String H4 = "h4"; - static final String H5 = "h5"; - static final String H6 = "h6"; - static final String HEAD = "head"; - static final String HR = "hr"; - static final String HTML = "html"; - static final String I = "i"; - static final String IFRAME = "iframe"; - static final String IMG = "img"; - static final String INPUT = "input"; - static final String INS = "ins"; - static final String ISINDEX = "isindex"; - static final String KBD = "kbd"; - static final String LABEL = "label"; - static final String LEGEND = "legend"; - static final String LI = "li"; - static final String LINK = "link"; - static final String MAP = "map"; - static final String MENU = "menu"; - static final String META = "meta"; - static final String NOFRAMES = "noframes"; - static final String NOSCRIPT = "noscript"; - static final String NONES = "none"; - static final String sNAME = "name"; - static final String OBJECT = "object"; - static final String OL = "ol"; - static final String OPTGROUP = "optgroup"; - static final String OPTION = "option"; - static final String P = "p"; - static final String PARAM = "param"; - static final String PRE = "pre"; - static final String Q = "q"; - static final String S = "s"; - static final String SAMP = "samp"; - static final String SCRIPT = "script"; - static final String SELECT = "select"; - static final String SMALL = "small"; - static final String SPAN = "span"; - static final String STRIKE = "strike"; - static final String STRONG = "strong"; - static final String STYLE = "style"; - static final String SUB = "sub"; - static final String SUP = "sup"; - static final String TABLE = "table"; - static final String TBODY = "tbody"; - static final String TD = "td"; - static final String TEXTAREA = "textarea"; - static final String TFOOT = "tfoot"; - static final String TH = "th"; - static final String THEAD = "thead"; - static final String TITLE = "title"; - static final String TR = "tr"; - static final String TT = "tt"; - static final String U = "u"; - static final String UL = "ul"; - static final String VAR = "var"; - - /* Define the attribute constants. */ - static final String C_0 = "0"; - static final String C_1 = "1"; - static final String CHECKBOX = "checkbox"; - static final String DATA = "data"; - static final String FILE = "file"; - static final String GET = "get"; - static final String HIDDEN = "hidden"; - static final String IMAGE = "image"; - static final String PASSWORD = "password"; - static final String POST = "post"; - static final String RADIO = "radio"; - static final String REF = "ref"; - static final String RESET = "reset"; - static final String SUBMIT = "submit"; - static final String TEXT = "text"; - static final String ABOVE = "above"; - static final String ACCEPT = "accept"; - static final String ACCEPTCHARSET = "accept-charset"; - static final String ACCESSKEY = "accesskey"; - static final String ACTION = "action"; - static final String ALIGN = "align"; - static final String ALINK = "alink"; - static final String ALL = "all"; - static final String ALT = "alt"; - static final String APPLICATION_X_WWW_FORM_URLENCODED - = "application/x-www-form-urlencoded"; - static final String ARCHIVE = "archive"; - static final String AUTO = "auto"; - static final String AXIS = "axis"; - static final String BACKGROUND = "background"; - static final String BASELINE = "baseline"; - static final String BELOW = "below"; - static final String BGCOLOR = "bgcolor"; - static final String BORDER = "border"; - static final String BOTTOM = "bottom"; - static final String BOX = "box"; - static final String CELLPADDING = "cellpadding"; - static final String CELLSPACING = "cellspacing"; - static final String CHAR = "char"; - static final String CHAROFF = "charoff"; - static final String CHARSET = "charset"; - static final String CHECKED = "checked"; - static final String CIRCLE = "circle"; - static final String CLASS = "class"; - static final String CLASSID = "classid"; - static final String CLEAR = "clear"; - static final String CODEBASE = "codebase"; - static final String CODETYPE = "codetype"; - static final String COLOR = "color"; - static final String COLS = "cols"; - static final String COLSPAN = "colspan"; - static final String COMPACT = "compact"; - static final String CONTENT = "content"; - static final String COORDS = "coords"; - static final String DATAPAGESIZE = "datapagesize"; - static final String DATETIME = "datetime"; - static final String DECLARE = "declare"; - static final String DEFER = "defer"; - static final String DISABLED = "disabled"; - static final String DISC = "disc"; - static final String ENCTYPE = "enctype"; - static final String EVENT = "event"; - static final String FACE = "face"; - static final String FOR = "for"; - static final String FRAMEBORDER = "frameborder"; - static final String GROUPS = "groups"; - static final String HEADERS = "headers"; - static final String HEIGHT = "height"; - static final String HREF = "href"; - static final String HREFLANG = "hreflang"; - static final String HSIDES = "hsides"; - static final String HSPACE = "hspace"; - static final String HTTPEQUIV = "http-equiv"; - static final String sID = "id"; - static final String ISMAP = "ismap"; - static final String JUSTIFY = "justify"; - static final String LANG = "lang"; - static final String LANGUAGE = "language"; - static final String LEFT = "left"; - static final String LHS = "lhs"; - static final String LONGDESC = "longdesc"; - static final String LTR = "ltr"; - static final String MARGINHEIGHT = "marginheight"; - static final String MARGINWIDTH = "marginwidth"; - static final String MAXLENGTH = "maxlength"; - static final String MEDIA = "media"; - static final String METHOD = "method"; - static final String MIDDLE = "middle"; - static final String MULTIPLE = "multiple"; - static final String NO = "no"; - static final String NOHREF = "nohref"; - static final String NORESIZE = "noresize"; - static final String NOSHADE = "noshade"; - static final String NOWRAP = "nowrap"; - static final String ONBLUR = "onblur"; - static final String ONCHANGE = "onchange"; - static final String ONCLICK = "onclick"; - static final String ONDBLCLICK = "ondblclick"; - static final String ONFOCUS = "onfocus"; - static final String ONKEYDOWN = "onkeydown"; - static final String ONKEYPRESS = "onkeypress"; - static final String ONKEYUP = "onkeyup"; - static final String ONLOAD = "onload"; - static final String ONMOUSEDOWN = "onmousedown"; - static final String ONMOUSEMOVE = "onmousemove"; - static final String ONMOUSEOUT = "onmouseout"; - static final String ONMOUSEOVER = "onmouseover"; - static final String ONMOUSEUP = "onmouseup"; - static final String ONRESET = "onreset"; - static final String ONSELECT = "onselect"; - static final String ONSUBMIT = "onsubmit"; - static final String ONUNLOAD = "onunload"; - static final String POLY = "poly"; - static final String PROFILE = "profile"; - static final String PROMPT = "prompt"; - static final String READONLY = "readonly"; - static final String RECT = "rect"; - static final String REL = "rel"; - static final String REV = "rev"; - static final String RHS = "rhs"; - static final String RIGHT = "right"; - static final String ROW = "row"; - static final String ROWGROUP = "rowgroup"; - static final String ROWS = "rows"; - static final String ROWSPAN = "rowspan"; - static final String RTL = "rtl"; - static final String RULES = "rules"; - static final String SCHEME = "scheme"; - static final String SCOPE = "scope"; - static final String SCROLLING = "scrolling"; - static final String SELECTED = "selected"; - static final String SHAPE = "shape"; - static final String SIZE = "size"; - static final String SQUARE = "square"; - static final String SRC = "src"; - static final String STANDBY = "standby"; - static final String START = "start"; - static final String SUMMARY = "summary"; - static final String TABINDEX = "tabindex"; - static final String TARGET = "target"; - static final String TOP = "top"; - static final String TYPE = "type"; - static final String USEMAP = "usemap"; - static final String VALIGN = "valign"; - static final String VALUE = "value"; - static final String VALUETYPE = "valuetype"; - static final String VERSION = "version"; - static final String VLINK = "vlink"; - static final String VOID = "void"; - static final String VSIDES = "vsides"; - static final String VSPACE = "vspace"; - static final String WIDTH = "width"; - static final String YES = "yes"; - - static final String[] BLOCK = - new String[] { - ADDRESS, BLOCKQUOTE, CENTER, DIR, - DIV, DL, FIELDSET, FORM, - H1, H2, H3, H4, H5, H6, - HR, ISINDEX, MENU, NOFRAMES, NOSCRIPT, - OL, P, PRE, TABLE, UL - }; - - /** - * Creates this DTD, filling in the entities and attributes data - * as defined in -//W3C//DTD HTML 4.01 Frameset//EN. - */ - protected HTML_401F() - { - super(DTD_NAME); - defineEntities(); - defineElements(); - } - - /** - * Either takes the document (by name) from DTD table, or - * creates a new instance and registers it in the tabe. - * The document is registerd under name "-//W3C//DTD HTML 4.01 Frameset//EN". - * @return The new or existing DTD for parsing HTML 4.01 Frameset. - */ - public static DTD getInstance() - { - try - { - DTD dtd = getDTD(DTD_NAME); - if (dtd == null || dtd.getClass().equals(DTD.class)) - { - dtd = new HTML_401F(); - putDTDHash(DTD_NAME, dtd); - } - return dtd; - } - catch (IOException ex) - { - throw new Error("This should never happen. Report the bug.", ex); - } - } - - /** - * Define all elements of this DTD. - */ - protected void defineElements() - { - /* Define the elements. */ - defElement(PCDATA, 0, false, false, null, NONE, NONE, - new AttributeList[ 0 ]); - - defElement(A, 0, false, false, null, - new String[] { - A - } - , - new String[] { - PCDATA, ABBR, ACRONYM, APPLET, - B, BASEFONT, BDO, BIG, BR, - BUTTON, CITE, CODE, DFN, EM, - FONT, I, IFRAME, IMG, INPUT, - KBD, LABEL, MAP, OBJECT, Q, - S, SAMP, SCRIPT, SELECT, SMALL, - SPAN, STRIKE, STRONG, SUB, SUP, - TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CHARSET, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(HREF, null, null, 0, IMPLIED), - attr(HREFLANG, null, null, 0, IMPLIED), - attr(TARGET, null, null, 0, IMPLIED), - attr(REL, null, null, 0, IMPLIED), - attr(REV, null, null, 0, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(SHAPE, RECT, new String[] { RECT, CIRCLE, POLY, DEFAULTS }, - 0, DEFAULT), - attr(COORDS, null, null, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED) - } - ); - defElement(ABBR, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(ACRONYM, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(ADDRESS, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - P - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(APPLET, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL, PARAM - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(CODEBASE, null, null, 0, IMPLIED), - attr(ARCHIVE, null, null, 0, IMPLIED), - attr(CODE, null, null, 0, IMPLIED), - attr(OBJECT, null, null, 0, IMPLIED), - attr(ALT, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, REQUIRED), - attr(HEIGHT, null, null, 0, REQUIRED), - attr(ALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED), - attr(HSPACE, null, null, 0, IMPLIED), - attr(VSPACE, null, null, 0, IMPLIED) - } - ); - defElement(AREA, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SHAPE, RECT, new String[] { RECT, CIRCLE, POLY, DEFAULTS }, - 0, DEFAULT), - attr(COORDS, null, null, 0, IMPLIED), - attr(HREF, null, null, 0, IMPLIED), - attr(TARGET, null, null, 0, IMPLIED), - attr(NOHREF, null, new String[] { NOHREF }, 0, IMPLIED), - attr(ALT, null, null, 0, REQUIRED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED) - } - ); - defElement(B, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(BASE, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(HREF, null, null, 0, IMPLIED), - attr(TARGET, null, null, 0, IMPLIED) - } - ); - defElement(BASEFONT, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(SIZE, null, null, 0, REQUIRED), - attr(COLOR, null, null, 0, IMPLIED), - attr(FACE, null, null, 0, IMPLIED) - } - ); - defElement(BDO, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, REQUIRED) - } - ); - defElement(BIG, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(BLOCKQUOTE, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CITE, null, null, 0, IMPLIED) - } - ); - defElement(BODY, 0, true, true, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DEL, DIR, - DIV, DL, FIELDSET, FORM, H1, - H2, H3, H4, H5, H6, - HR, INS, ISINDEX, MENU, NOFRAMES, - NOSCRIPT, OL, P, PRE, TABLE, - UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ONLOAD, null, null, 0, IMPLIED), - attr(ONUNLOAD, null, null, 0, IMPLIED), - attr(BACKGROUND, null, null, 0, IMPLIED), - attr(BGCOLOR, null, null, 0, IMPLIED), - attr(TEXT, null, null, 0, IMPLIED), - attr(LINK, null, null, 0, IMPLIED), - attr(VLINK, null, null, 0, IMPLIED), - attr(ALINK, null, null, 0, IMPLIED) - } - ); - defElement(BR, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(CLEAR, "NONE", new String[] { LEFT, ALL, RIGHT, NONES }, - 0, DEFAULT) - } - ); - defElement(BUTTON, 0, false, false, null, - new String[] { - A, BUTTON, IFRAME, INPUT, - LABEL, SELECT, TEXTAREA, FIELDSET, FORM, - ISINDEX - } - , - new String[] { - PCDATA, ABBR, ACRONYM, APPLET, - B, BASEFONT, BDO, BIG, BR, - CITE, CODE, DFN, EM, FONT, - I, IMG, KBD, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SMALL, - SPAN, STRIKE, STRONG, SUB, SUP, - TT, U, VAR, ADDRESS, BLOCKQUOTE, - CENTER, DIR, DIV, DL, H1, - H2, H3, H4, H5, H6, - HR, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(VALUE, null, null, 0, IMPLIED), - attr(TYPE, SUBMIT, new String[] { BUTTON, SUBMIT, RESET }, 0, DEFAULT), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED) - } - ); - defElement(CAPTION, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { TOP, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED) - } - ); - defElement(CENTER, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(CITE, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(CODE, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(COL, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SPAN, C_1, null, NUMBER, DEFAULT), - attr(WIDTH, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED) - } - ); - defElement(COLGROUP, 0, false, true, null, - NONE - , - new String[] { - COL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SPAN, C_1, null, NUMBER, DEFAULT), - attr(WIDTH, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED) - } - ); - defElement(DD, 0, false, true, new ContentModel(0, - new noTagModel( new String[] { DD, DT } ), null ), - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(DEL, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CITE, null, null, 0, IMPLIED), - attr(DATETIME, null, null, 0, IMPLIED) - } - ); - defElement(DFN, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(DIR, 0, false, false, createListModel(), - new String[] { - ADDRESS, BLOCKQUOTE, CENTER, DIR, - DIV, DL, FIELDSET, FORM, H1, - H2, H3, H4, H5, H6, - HR, ISINDEX, MENU, NOFRAMES, NOSCRIPT, - OL, P, PRE, TABLE, UL - } - , - new String[] { - LI, UL, OL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(COMPACT, null, new String[] { COMPACT }, 0, IMPLIED) - } - ); - defElement(DIV, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(DL, 0, false, false, createDefListModel(), - NONE - , - new String[] { - DD, DT - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(COMPACT, null, new String[] { COMPACT }, 0, IMPLIED) - } - ); - defElement(DT, 0, false, true, - new ContentModel(0, - new noTagModel( new String[] { DT, DD } ), null), - BLOCK - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(EM, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(FIELDSET, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL, LEGEND - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(FONT, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(SIZE, null, null, 0, IMPLIED), - attr(COLOR, null, null, 0, IMPLIED), - attr(FACE, null, null, 0, IMPLIED) - } - ); - defElement(FORM, 0, false, false, null, - new String[] { - FORM - } - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, H1, H2, H3, - H4, H5, H6, HR, ISINDEX, - MENU, NOFRAMES, NOSCRIPT, OL, P, - PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ACTION, null, null, 0, REQUIRED), - attr(METHOD, GET, new String[] { GET, POST }, 0, DEFAULT), - attr(ENCTYPE, APPLICATION_X_WWW_FORM_URLENCODED, null, 0, DEFAULT), - attr(ACCEPT, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(ONSUBMIT, null, null, 0, IMPLIED), - attr(ONRESET, null, null, 0, IMPLIED), - attr(TARGET, null, null, 0, IMPLIED), - attr(ACCEPTCHARSET, null, null, 0, IMPLIED) - } - ); - defElement(FRAME, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LONGDESC, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(SRC, null, null, 0, IMPLIED), - attr(FRAMEBORDER, C_1, new String[] { C_1, C_0 }, 0, DEFAULT), - attr(MARGINWIDTH, null, null, PIXELS, IMPLIED), - attr(MARGINHEIGHT, null, null, PIXELS, IMPLIED), - attr(NORESIZE, null, new String[] { NORESIZE }, 0, IMPLIED), - attr(SCROLLING, AUTO, new String[] { YES, NO, AUTO }, 0, DEFAULT) - } - ); - defElement(FRAMESET, 0, false, false, null, - NONE - , - new String[] { - NOFRAMES, FRAME, FRAMESET - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(ROWS, null, null, 0, IMPLIED), - attr(COLS, null, null, 0, IMPLIED), - attr(ONLOAD, null, null, 0, IMPLIED), - attr(ONUNLOAD, null, null, 0, IMPLIED) - } - ); - defElement(H1, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(H2, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(H3, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(H4, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(H5, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(H6, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(HEAD, 0, true, true, null, - new String[] { - BODY - } - , - new String[] { - TITLE, ISINDEX, BASE, - SCRIPT, STYLE, META, LINK, OBJECT - } - , - new AttributeList[] { - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(PROFILE, null, null, 0, IMPLIED) - } - ); - - defElement(HR, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT }, 0, IMPLIED), - attr(NOSHADE, null, new String[] { NOSHADE }, 0, IMPLIED), - attr(SIZE, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED) - } - ); - defElement(HTML, 0, true, true, createHtmlContentModel(), - NONE - , - new String[] { - HEAD, BODY - } - , - new AttributeList[] { - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(VERSION, DTD_NAME, null, 0, FIXED) - } - ); - defElement(I, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(IFRAME, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LONGDESC, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(SRC, null, null, 0, IMPLIED), - attr(FRAMEBORDER, C_1, new String[] { C_1, C_0 }, 0, DEFAULT), - attr(MARGINWIDTH, null, null, PIXELS, IMPLIED), - attr(MARGINHEIGHT, null, null, PIXELS, IMPLIED), - attr(SCROLLING, AUTO, new String[] { YES, NO, AUTO }, 0, DEFAULT), - attr(ALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED), - attr(HEIGHT, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED) - } - ); - defElement(IMG, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SRC, null, null, 0, REQUIRED), - attr(ALT, null, null, 0, REQUIRED), - attr(LONGDESC, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(HEIGHT, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED), - attr(USEMAP, null, null, 0, IMPLIED), - attr(ISMAP, null, new String[] { ISMAP }, 0, IMPLIED), - attr(ALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED), - attr(BORDER, null, null, PIXELS, IMPLIED), - attr(HSPACE, null, null, 0, IMPLIED), - attr(VSPACE, null, null, 0, IMPLIED) - } - ); - defElement(INPUT, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(TYPE, TEXT, new String[] { TEXT, PASSWORD, CHECKBOX, RADIO, - SUBMIT, RESET, FILE, HIDDEN, IMAGE, BUTTON }, 0, DEFAULT), - attr(sNAME, null, null, 0, IMPLIED), - attr(VALUE, null, null, 0, IMPLIED), - attr(CHECKED, null, new String[] { CHECKED }, 0, IMPLIED), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(READONLY, null, new String[] { READONLY }, 0, IMPLIED), - attr(SIZE, null, null, 0, IMPLIED), - attr(MAXLENGTH, null, null, 0, IMPLIED), - attr(SRC, null, null, 0, IMPLIED), - attr(ALT, null, null, 0, IMPLIED), - attr(USEMAP, null, null, 0, IMPLIED), - attr(ISMAP, null, new String[] { ISMAP }, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED), - attr(ONSELECT, null, null, 0, IMPLIED), - attr(ONCHANGE, null, null, 0, IMPLIED), - attr(ACCEPT, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED) - } - ); - defElement(INS, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CITE, null, null, 0, IMPLIED), - attr(DATETIME, null, null, 0, IMPLIED) - } - ); - defElement(ISINDEX, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(PROMPT, null, null, 0, IMPLIED) - } - ); - defElement(KBD, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(LABEL, 0, false, false, null, - new String[] { - LABEL - } - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, MAP, OBJECT, Q, - S, SAMP, SCRIPT, SELECT, SMALL, - SPAN, STRIKE, STRONG, SUB, SUP, - TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(FOR, null, null, 0, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED) - } - ); - defElement(LEGEND, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { TOP, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED) - } - ); - // LI has a special content model that will be resolved into - // by transformer. - defElement(LI, 0, false, true, - new ContentModel(0, - new noTagModel(LI), null), - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, IMPLIED), - attr(VALUE, null, null, NUMBER, IMPLIED) - } - ); - defElement(LINK, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CHARSET, null, null, 0, IMPLIED), - attr(HREF, null, null, 0, IMPLIED), - attr(HREFLANG, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, IMPLIED), - attr(REL, null, null, 0, IMPLIED), - attr(REV, null, null, 0, IMPLIED), - attr(MEDIA, null, null, 0, IMPLIED), - attr(TARGET, null, null, 0, IMPLIED) - } - ); - defElement(MAP, 0, false, false, null, - NONE - , - new String[] { - ADDRESS, BLOCKQUOTE, CENTER, DIR, - DIV, DL, FIELDSET, FORM, H1, - H2, H3, H4, H5, H6, - HR, ISINDEX, MENU, NOFRAMES, NOSCRIPT, - OL, P, PRE, TABLE, UL, - AREA - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, REQUIRED) - } - ); - defElement(MENU, 0, false, false, createListModel(), - new String[] { - ADDRESS, BLOCKQUOTE, CENTER, DIR, - DIV, DL, FIELDSET, FORM, H1, - H2, H3, H4, H5, H6, - HR, ISINDEX, MENU, NOFRAMES, NOSCRIPT, - OL, P, PRE, TABLE, UL - } - , - new String[] { - LI, UL, OL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(COMPACT, null, new String[] { COMPACT }, 0, IMPLIED) - } - ); - defElement(META, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(HTTPEQUIV, null, null, 0, IMPLIED), - attr(sNAME, null, null, NAME, IMPLIED), - attr(CONTENT, null, null, 0, REQUIRED), - attr(SCHEME, null, null, 0, IMPLIED) - } - ); - defElement(NOFRAMES, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(NOSCRIPT, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(OBJECT, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL, PARAM - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(DECLARE, null, new String[] { DECLARE }, 0, IMPLIED), - attr(CLASSID, null, null, 0, IMPLIED), - attr(CODEBASE, null, null, 0, IMPLIED), - attr(DATA, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, IMPLIED), - attr(CODETYPE, null, null, 0, IMPLIED), - attr(ARCHIVE, null, null, 0, IMPLIED), - attr(STANDBY, null, null, 0, IMPLIED), - attr(HEIGHT, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED), - attr(USEMAP, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, LEFT, RIGHT }, - 0, IMPLIED), - attr(BORDER, null, null, PIXELS, IMPLIED), - attr(HSPACE, null, null, 0, IMPLIED), - attr(VSPACE, null, null, 0, IMPLIED) - } - ); - defElement(OL, 0, false, false, createListModel(), - NONE - , - new String[] { - // See note on the createListModel method - LI, UL, OL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, IMPLIED), - attr(COMPACT, null, new String[] { COMPACT }, 0, IMPLIED), - attr(START, null, null, 0, IMPLIED) - } - ); - defElement(OPTGROUP, 0, false, false, null, - NONE - , - new String[] { - OPTION - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(LABEL, null, null, 0, REQUIRED) - } - ); - defElement(OPTION, 0, false, true, new ContentModel(0, - new PCDATAonly_model(), null), - NONE, - new String[] { - PCDATA - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SELECTED, null, new String[] { SELECTED }, 0, IMPLIED), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(LABEL, null, null, 0, IMPLIED), - attr(VALUE, null, null, 0, IMPLIED) - } - ); - defElement(P, 0, false, true, new ContentModel( 0, - new noTagModel(P), null), - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY }, - 0, IMPLIED) - } - ); - defElement(PARAM, EMPTY, false, true, null, - NONE - , - NONE - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(sNAME, null, null, 0, REQUIRED), - attr(VALUE, null, null, 0, IMPLIED), - attr(VALUETYPE, DATA, new String[] { DATA, REF, OBJECT }, 0, DEFAULT), - attr(TYPE, null, null, 0, IMPLIED) - } - ); - defElement(PRE, 0, false, false, null, - new String[] { - APPLET, BASEFONT, BIG, FONT, - IMG, OBJECT, SMALL, SUB, SUP - } - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - B, BDO, BR, BUTTON, CITE, - CODE, DFN, EM, I, IFRAME, - INPUT, KBD, LABEL, MAP, Q, - S, SAMP, SCRIPT, SELECT, SPAN, - STRIKE, STRONG, TEXTAREA, TT, U, - VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(WIDTH, null, null, NUMBER, IMPLIED) - } - ); - defElement(Q, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(CITE, null, null, 0, IMPLIED) - } - ); - defElement(S, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(SAMP, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(SCRIPT, CDATA, false, false, null, - NONE - , - NONE - , - new AttributeList[] { - attr(CHARSET, null, null, 0, IMPLIED), - attr(TYPE, null, null, 0, REQUIRED), - attr(LANGUAGE, null, null, 0, IMPLIED), - attr(SRC, null, null, 0, IMPLIED), - attr(DEFER, null, new String[] { DEFER }, 0, IMPLIED), - attr(EVENT, null, null, 0, IMPLIED), - attr(FOR, null, null, 0, IMPLIED) - } - ); - defElement(SELECT, 0, false, false, null, - NONE - , - new String[] { - OPTGROUP, OPTION - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(SIZE, null, null, NUMBER, IMPLIED), - attr(MULTIPLE, null, new String[] { MULTIPLE }, 0, IMPLIED), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED), - attr(ONCHANGE, null, null, 0, IMPLIED) - } - ); - defElement(SMALL, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(SPAN, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(STRIKE, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(STRONG, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(STYLE, CDATA, false, false, null, - NONE - , - NONE - , - new AttributeList[] { - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(TYPE, null, null, 0, REQUIRED), - attr(MEDIA, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED) - } - ); - defElement(SUB, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(SUP, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(TABLE, 0, false, false, createTableContentModel(), - NONE - , - new String[] { - CAPTION, COL, COLGROUP, TBODY, - TFOOT, THEAD - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(SUMMARY, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED), - attr(BORDER, null, null, PIXELS, IMPLIED), - attr(FRAME, null, new String[] { VOID, ABOVE, BELOW, HSIDES, LHS, RHS, - VSIDES, BOX, BORDER }, 0, IMPLIED), - attr(RULES, null, new String[] { NONES, GROUPS, ROWS, COLS, ALL }, - 0, IMPLIED), - attr(CELLSPACING, null, null, 0, IMPLIED), - attr(CELLPADDING, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT }, 0, IMPLIED), - attr(BGCOLOR, null, null, 0, IMPLIED), - attr(DATAPAGESIZE, null, null, 0, IMPLIED) - } - ); - defElement(TBODY, 0, true, true, model(TR,'+'), - NONE - , - new String[] { - TR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED) - } - ); - - defElement(TD, 0, false, true, - new ContentModel(0, - new noTagModel(new String[] {"TD", "TH", "TR" } ), null), - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ABBR, null, null, 0, IMPLIED), - attr(AXIS, null, null, 0, IMPLIED), - attr(HEADERS, null, null, 0, IMPLIED), - attr(SCOPE, null, new String[] { ROW, COL, ROWGROUP, COLGROUP }, - 0, IMPLIED), - attr(ROWSPAN, C_1, null, NUMBER, DEFAULT), - attr(COLSPAN, C_1, null, NUMBER, DEFAULT), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED), - attr(NOWRAP, null, new String[] { NOWRAP }, 0, IMPLIED), - attr(BGCOLOR, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED), - attr(HEIGHT, null, null, 0, IMPLIED) - } - ); - defElement(TEXTAREA, 0, false, false, null, - NONE - , - new String[] { - PCDATA - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(sNAME, null, null, 0, IMPLIED), - attr(ROWS, null, null, NUMBER, REQUIRED), - attr(COLS, null, null, NUMBER, REQUIRED), - attr(DISABLED, null, new String[] { DISABLED }, 0, IMPLIED), - attr(READONLY, null, new String[] { READONLY }, 0, IMPLIED), - attr(TABINDEX, null, null, NUMBER, IMPLIED), - attr(ACCESSKEY, null, null, 0, IMPLIED), - attr(ONFOCUS, null, null, 0, IMPLIED), - attr(ONBLUR, null, null, 0, IMPLIED), - attr(ONSELECT, null, null, 0, IMPLIED), - attr(ONCHANGE, null, null, 0, IMPLIED) - } - ); - defElement(TFOOT, 0, false, true, model(TR,'+'), - NONE - , - new String[] { - TR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED) - } - ); - defElement(TH, 0, false, true, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR, - ADDRESS, BLOCKQUOTE, CENTER, DIR, DIV, - DL, FIELDSET, FORM, H1, H2, - H3, H4, H5, H6, HR, - ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, - P, PRE, TABLE, UL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ABBR, null, null, 0, IMPLIED), - attr(AXIS, null, null, 0, IMPLIED), - attr(HEADERS, null, null, 0, IMPLIED), - attr(SCOPE, null, new String[] { ROW, COL, ROWGROUP, COLGROUP }, - 0, IMPLIED), - attr(ROWSPAN, C_1, null, NUMBER, DEFAULT), - attr(COLSPAN, C_1, null, NUMBER, DEFAULT), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED), - attr(NOWRAP, null, new String[] { NOWRAP }, 0, IMPLIED), - attr(BGCOLOR, null, null, 0, IMPLIED), - attr(WIDTH, null, null, 0, IMPLIED), - attr(HEIGHT, null, null, 0, IMPLIED) - } - ); - defElement(THEAD, 0, false, true, model(TR,'+'), - NONE - , - new String[] { - TR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED) - } - ); - defElement(TITLE, 0, false, false, null, - new String[] { - OBJECT, SCRIPT, LINK, META, - STYLE - } - , - new String[] { - PCDATA - } - , - new AttributeList[] { - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED) - } - ); - defElement(TR, 0, false, true, - new ContentModel(0, new TableRowContentModel(this), null), - NONE - , - new String[] { - TD, TH - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(ALIGN, null, new String[] { LEFT, CENTER, RIGHT, JUSTIFY, CHAR }, - 0, IMPLIED), - attr(CHAR, null, null, 0, IMPLIED), - attr(CHAROFF, null, null, 0, IMPLIED), - attr(VALIGN, null, new String[] { TOP, MIDDLE, BOTTOM, BASELINE }, - 0, IMPLIED), - attr(BGCOLOR, null, null, 0, IMPLIED) - } - ); - defElement(TT, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(U, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - defElement(UL, 0, false, false, createListModel(), - NONE - , - new String[] { - // See note on the createListModel method - LI, UL, OL - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED), - attr(TYPE, null, new String[] { DISC, SQUARE, CIRCLE }, 0, IMPLIED), - attr(COMPACT, null, new String[] { COMPACT }, 0, IMPLIED) - } - ); - defElement(VAR, 0, false, false, null, - NONE - , - new String[] { - PCDATA, A, ABBR, ACRONYM, - APPLET, B, BASEFONT, BDO, BIG, - BR, BUTTON, CITE, CODE, DFN, - EM, FONT, I, IFRAME, IMG, - INPUT, KBD, LABEL, MAP, OBJECT, - Q, S, SAMP, SCRIPT, SELECT, - SMALL, SPAN, STRIKE, STRONG, SUB, - SUP, TEXTAREA, TT, U, VAR - } - , - new AttributeList[] { - attr(sID, null, null, ID, IMPLIED), - attr(CLASS, null, null, 0, IMPLIED), - attr(STYLE, null, null, 0, IMPLIED), - attr(TITLE, null, null, 0, IMPLIED), - attr(LANG, null, null, 0, IMPLIED), - attr(DIR, null, new String[] { LTR, RTL }, 0, IMPLIED), - attr(ONCLICK, null, null, 0, IMPLIED), - attr(ONDBLCLICK, null, null, 0, IMPLIED), - attr(ONMOUSEDOWN, null, null, 0, IMPLIED), - attr(ONMOUSEUP, null, null, 0, IMPLIED), - attr(ONMOUSEOVER, null, null, 0, IMPLIED), - attr(ONMOUSEMOVE, null, null, 0, IMPLIED), - attr(ONMOUSEOUT, null, null, 0, IMPLIED), - attr(ONKEYPRESS, null, null, 0, IMPLIED), - attr(ONKEYDOWN, null, null, 0, IMPLIED), - attr(ONKEYUP, null, null, 0, IMPLIED) - } - ); - - } - - /** - * Define all entities in this DTD. - */ - protected void defineEntities() - { - /* Define general entities */ - defineEntity("AElig", 198); - defineEntity("Aacute", 193); - defineEntity("Acirc", 194); - defineEntity("Agrave", 192); - defineEntity("Alpha", 913); - defineEntity("Aring", 197); - defineEntity("Atilde", 195); - defineEntity("Auml", 196); - defineEntity("Beta", 914); - defineEntity("Ccedil", 199); - defineEntity("Chi", 935); - defineEntity("Dagger", 8225); - defineEntity("Delta", 916); - defineEntity("ETH", 208); - defineEntity("Eacute", 201); - defineEntity("Ecirc", 202); - defineEntity("Egrave", 200); - defineEntity("Epsilon", 917); - defineEntity("Eta", 919); - defineEntity("Euml", 203); - defineEntity("Gamma", 915); - defineEntity("Iacute", 205); - defineEntity("Icirc", 206); - defineEntity("Igrave", 204); - defineEntity("Iota", 921); - defineEntity("Iuml", 207); - defineEntity("Kappa", 922); - defineEntity("Lambda", 923); - defineEntity("Mu", 924); - defineEntity("Ntilde", 209); - defineEntity("Nu", 925); - defineEntity("OElig", 338); - defineEntity("Oacute", 211); - defineEntity("Ocirc", 212); - defineEntity("Ograve", 210); - defineEntity("Omega", 937); - defineEntity("Omicron", 927); - defineEntity("Oslash", 216); - defineEntity("Otilde", 213); - defineEntity("Ouml", 214); - defineEntity("Phi", 934); - defineEntity("Pi", 928); - defineEntity("Prime", 8243); - defineEntity("Psi", 936); - defineEntity("Rho", 929); - defineEntity("Scaron", 352); - defineEntity("Sigma", 931); - defineEntity("THORN", 222); - defineEntity("Tau", 932); - defineEntity("Theta", 920); - defineEntity("Uacute", 218); - defineEntity("Ucirc", 219); - defineEntity("Ugrave", 217); - defineEntity("Upsilon", 933); - defineEntity("Uuml", 220); - defineEntity("Xi", 926); - defineEntity("Yacute", 221); - defineEntity("Yuml", 376); - defineEntity("Zeta", 918); - defineEntity("aacute", 225); - defineEntity("acirc", 226); - defineEntity("acute", 180); - defineEntity("aelig", 230); - defineEntity("agrave", 224); - defineEntity("alefsym", 8501); - defineEntity("alpha", 945); - defineEntity("amp", 38); - defineEntity("and", 8743); - defineEntity("ang", 8736); - defineEntity("aring", 229); - defineEntity("asymp", 8776); - defineEntity("atilde", 227); - defineEntity("auml", 228); - defineEntity("bdquo", 8222); - defineEntity("beta", 946); - defineEntity("brvbar", 166); - defineEntity("bull", 8226); - defineEntity("cap", 8745); - defineEntity("ccedil", 231); - defineEntity("cedil", 184); - defineEntity("cent", 162); - defineEntity("chi", 967); - defineEntity("circ", 710); - defineEntity("clubs", 9827); - defineEntity("cong", 8773); - defineEntity("copy", 169); - defineEntity("crarr", 8629); - defineEntity("cup", 8746); - defineEntity("curren", 164); - defineEntity("dArr", 8659); - defineEntity("dagger", 8224); - defineEntity("darr", 8595); - defineEntity("deg", 176); - defineEntity("delta", 948); - defineEntity("diams", 9830); - defineEntity("divide", 247); - defineEntity("eacute", 233); - defineEntity("ecirc", 234); - defineEntity("egrave", 232); - defineEntity("empty", 8709); - defineEntity("emsp", 8195); - defineEntity("ensp", 8194); - defineEntity("epsilon", 949); - defineEntity("equiv", 8801); - defineEntity("eta", 951); - defineEntity("eth", 240); - defineEntity("euml", 235); - defineEntity("euro", 8364); - defineEntity("exist", 8707); - defineEntity("fnof", 402); - defineEntity("forall", 8704); - defineEntity("frac12", 189); - defineEntity("frac14", 188); - defineEntity("frac34", 190); - defineEntity("frasl", 8260); - defineEntity("gamma", 947); - defineEntity("ge", 8805); - defineEntity("gt", 62); - defineEntity("hArr", 8660); - defineEntity("harr", 8596); - defineEntity("hearts", 9829); - defineEntity("hellip", 8230); - defineEntity("iacute", 237); - defineEntity("icirc", 238); - defineEntity("iexcl", 161); - defineEntity("igrave", 236); - defineEntity("image", 8465); - defineEntity("infin", 8734); - defineEntity("int", 8747); - defineEntity("iota", 953); - defineEntity("iquest", 191); - defineEntity("isin", 8712); - defineEntity("iuml", 239); - defineEntity("kappa", 954); - defineEntity("lArr", 8656); - defineEntity("lambda", 955); - defineEntity("lang", 9001); - defineEntity("laquo", 171); - defineEntity("larr", 8592); - defineEntity("lceil", 8968); - defineEntity("ldquo", 8220); - defineEntity("le", 8804); - defineEntity("lfloor", 8970); - defineEntity("lowast", 8727); - defineEntity("loz", 9674); - defineEntity("lrm", 8206); - defineEntity("lsaquo", 8249); - defineEntity("lsquo", 8216); - defineEntity("lt", 60); - defineEntity("macr", 175); - defineEntity("mdash", 8212); - defineEntity("micro", 181); - defineEntity("middot", 183); - defineEntity("minus", 8722); - defineEntity("mu", 956); - defineEntity("nabla", 8711); - defineEntity("nbsp", 160); - defineEntity("ndash", 8211); - defineEntity("ne", 8800); - defineEntity("ni", 8715); - defineEntity("not", 172); - defineEntity("notin", 8713); - defineEntity("nsub", 8836); - defineEntity("ntilde", 241); - defineEntity("nu", 957); - defineEntity("oacute", 243); - defineEntity("ocirc", 244); - defineEntity("oelig", 339); - defineEntity("ograve", 242); - defineEntity("oline", 8254); - defineEntity("omega", 969); - defineEntity("omicron", 959); - defineEntity("oplus", 8853); - defineEntity("or", 8744); - defineEntity("ordf", 170); - defineEntity("ordm", 186); - defineEntity("oslash", 248); - defineEntity("otilde", 245); - defineEntity("otimes", 8855); - defineEntity("ouml", 246); - defineEntity("para", 182); - defineEntity("part", 8706); - defineEntity("permil", 8240); - defineEntity("perp", 8869); - defineEntity("phi", 966); - defineEntity("pi", 960); - defineEntity("piv", 982); - defineEntity("plusmn", 177); - defineEntity("pound", 163); - defineEntity("prime", 8242); - defineEntity("prod", 8719); - defineEntity("prop", 8733); - defineEntity("psi", 968); - defineEntity("quot", 34); - defineEntity("rArr", 8658); - defineEntity("radic", 8730); - defineEntity("rang", 9002); - defineEntity("raquo", 187); - defineEntity("rarr", 8594); - defineEntity("rceil", 8969); - defineEntity("rdquo", 8221); - defineEntity("real", 8476); - defineEntity("reg", 174); - defineEntity("rfloor", 8971); - defineEntity("rho", 961); - defineEntity("rlm", 8207); - defineEntity("rsaquo", 8250); - defineEntity("rsquo", 8217); - defineEntity("sbquo", 8218); - defineEntity("scaron", 353); - defineEntity("sdot", 8901); - defineEntity("sect", 167); - defineEntity("shy", 173); - defineEntity("sigma", 963); - defineEntity("sigmaf", 962); - defineEntity("sim", 8764); - defineEntity("spades", 9824); - defineEntity("sub", 8834); - defineEntity("sube", 8838); - defineEntity("sum", 8721); - defineEntity("sup", 8835); - defineEntity("sup1", 185); - defineEntity("sup2", 178); - defineEntity("sup3", 179); - defineEntity("supe", 8839); - defineEntity("szlig", 223); - defineEntity("tau", 964); - defineEntity("there4", 8756); - defineEntity("theta", 952); - defineEntity("thetasym", 977); - defineEntity("thinsp", 8201); - defineEntity("thorn", 254); - defineEntity("tilde", 732); - defineEntity("times", 215); - defineEntity("trade", 8482); - defineEntity("uArr", 8657); - defineEntity("uacute", 250); - defineEntity("uarr", 8593); - defineEntity("ucirc", 251); - defineEntity("ugrave", 249); - defineEntity("uml", 168); - defineEntity("upsih", 978); - defineEntity("upsilon", 965); - defineEntity("uuml", 252); - defineEntity("weierp", 8472); - defineEntity("xi", 958); - defineEntity("yacute", 253); - defineEntity("yen", 165); - defineEntity("yuml", 255); - defineEntity("zeta", 950); - defineEntity("zwj", 8205); - defineEntity("zwnj", 8204); - } - - /** - * Crate a content model, consisting of the single - * element, specified by name. - */ - private ContentModel model(String element) - { - return new ContentModel(getElement(element)); - } - - /** - * Crate a chain from the two content models, - * the last containing the given element and - * the specified unary operation. - */ - private ContentModel model(String element, int unary) - { - ContentModel ct = model(element); - ct.type = unary; - return new ContentModel(0, ct); - } - - /** - * Create the model HEAD, BODY - * @return - */ - protected ContentModel createHtmlContentModel() - { - ContentModel head = model(HEAD); - ContentModel body = model(BODY); - head.next = body; - head.type = ','; - return head; - } - - /** - * Create the model - * ( CAPTION ? , ( COL * | COLGROUP * ) , THEAD ? , TFOOT ? , TBODY + ) - */ - protected ContentModel createTableContentModel() - { - ContentModel col_colgroup = new ContentModel - ('|', model(COL,'*'), model(COLGROUP,'*') ); - - col_colgroup = new ContentModel('*', col_colgroup); - col_colgroup = new ContentModel(',', col_colgroup); - - ContentModel caption = model(CAPTION,'?'); - ContentModel thead = model(THEAD, '?'); - ContentModel tfoot = model(TFOOT, '?'); - ContentModel tbody = model(TBODY, '+'); - - caption.next = col_colgroup; - col_colgroup.next = thead; - thead.next = tfoot; - tfoot.next = tbody; - - caption.type = col_colgroup.type = thead.type = tfoot.type = - tbody.type = ','; - - return caption; - } - - /** - * Creates a model for <DL> tag: - * <code> DT+ | DL+ </code>. - * @return - */ - protected ContentModel createDefListModel() - { - ContentModel dt = model(DT, '+'); - ContentModel dd = model(DD, '+'); - - dt.next = dd; - dt.type = dd.type = '|'; - return dt; - } - - /** - * This model is used for UL, OL, MENU and DIR. - * HTML 4.01 specifies LI only, but the nested - * list seems rendered correctly only if - * it is not enclosed into <LI>-</LI> of the - * parent list. - */ - protected ContentModel createListModel() - { - ContentModel li = model(LI, '+'); - ContentModel ul = model(UL, '+'); - ContentModel ol = model(OL, '+'); - - li.next = ul; - ul.next = ol; - li.type = ul.type = ol.type = '|'; - return li; - } - -} diff --git a/libjava/gnu/javax/swing/text/html/parser/gnuDTD.java b/libjava/gnu/javax/swing/text/html/parser/gnuDTD.java deleted file mode 100755 index 1f4b3ec6adc..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/gnuDTD.java +++ /dev/null @@ -1,422 +0,0 @@ -/* gnuDTD.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser; - -import java.io.PrintStream; -import java.io.Serializable; - -import java.util.BitSet; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Vector; - -import javax.swing.text.html.parser.AttributeList; -import javax.swing.text.html.parser.ContentModel; -import javax.swing.text.html.parser.Element; -import javax.swing.text.html.parser.Entity; - -/** - * <p> - * The class is derived from {@link gnu.javax.swing.text.html.parser.DTD } - * making structure creation methods public. This is required when - * creating the DTD by SGML parser that must have access to the structure. - * - * SGML DTD representation. Provides basis for describing a syntax of the - * HTML documents. The fields of this class are NOT initialized in - * constructor. You need to do this separately before passing this data - * structure to the parser constructor.</p> - * - * <p>This implementation also provides you the derived class - * <code>gnu.javax.swing.text.html.parser.DTD.HTML_4_0_1</code>, where - * all fields are initialized to the values, representing HTML 4.01 - * ("-//W3C//DTD HTML 4.01 Frameset//EN") DTD. You can use it if you do not care - * about the portability between different implementations of the core - * class libraries. </p> - * <p>Use {@link javax.swing.HTML.HTMLEditorKit.Parser#parse } - * for parsing in accordance with "-//W3C//DTD HTML 4.01 Frameset//EN" - * without specifying DTD separately.</p> - * - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class gnuDTD - extends javax.swing.text.html.parser.DTD - implements javax.swing.text.html.parser.DTDConstants, Serializable -{ - /* The undocumented element types, used to specify types, not defined - in DTDConstants. */ - - /** - * The URI element type (not defined in DTDConstants). - */ - public static final int URI = 512; - - /** - * The Length element type - */ - public static final int Length = 513; - - /** - * The Char element type - */ - public static final int Char = 514; - - /** - * The Color element type - */ - public static final int Color = 515; - - /** - * Creates a new instance of gnuDTD. - * @param name the name of the DTD. - */ - public gnuDTD(String name) - { - super(name); - } - - /** - * Creates and returns new attribute (not an attribute list). - * @param name the name of this attribute - * @param type the type of this attribute (FIXED, IMPLIED or - * REQUIRED from <code>DTDConstants</code>). - * @param modifier the modifier of this attribute - * @param default_value the default value of this attribute or null if - * it is not specified. - * @param allowed_values the allowed values of this attribute. The multiple - * possible values in this parameter are supposed to be separated by - * '|', same as in SGML DTD <code><!ATTLIST </code>tag. This parameter - * can be null if no list of allowed values is specified. - * @param atts the previous attribute of this element. This is - * placed to the field - * {@link javax.swing.text.html.parser.AttributeList#next }, - * creating a linked list. - * @return - */ - public AttributeList defAttributeList(String name, int type, int modifier, - String default_value, - String allowed_values, - AttributeList atts - ) - { - return super.defAttributeList(name, type, modifier, default_value, - allowed_values, atts - ); - } - - /** - * Define the attributes for the element with the given name. - * If the element is not exist, it is created. This method is - * needed if the element attributes are defined befor the - * element itself. - * @param forElement - * @param attributes - */ - public void defAttrsFor(String forElement, AttributeList attributes) - { - super.defineAttributes(forElement, attributes); - } - - /** - * Creates a new content model. - * @param type specifies the BNF operation for this content model. - * The valid operations are documented in the - * {@link javax.swing.text.html.parser.ContentModel#type }. - * @param content the content of this content model - * @param next if the content model is specified by BNF-like - * expression, contains the rest of this expression. - * @return The newly created content model. - */ - public ContentModel defContentModel(int type, Object content, - ContentModel next - ) - { - return super.defContentModel(type, content, next); - } - - /** - * Defines a new element and adds it to the element table. - * If the element alredy exists, - * overrides it settings with the specified values. - * @param name the name of the new element - * @param type the type of the element - * @param headless true if the element needs no starting tag - * @param tailless true if the element needs no closing tag - * @param content the element content. - * @param exclusions the elements that must be excluded from the - * content of this element, in all levels of the hierarchy. - * @param inclusions the elements that can be included as the - * content of this element. - * @param attributes the element attributes. - * @return the created or updated element. - */ - public Element defElement(String name, int type, boolean headless, - boolean tailless, ContentModel content, - String[] exclusions, String[] inclusions, - AttributeList attributes - ) - { - return super.defElement(name, type, headless, tailless, content, - exclusions, inclusions, attributes - ); - } - - /** - * Defines a new element and adds it to the element table. - * If the element alredy exists, - * overrides it settings with the specified values. - * @param name the name of the new element - * @param type the type of the element - * @param headless true if the element needs no starting tag - * @param tailless true if the element needs no closing tag - * @param content the element content. - * @param exclusions the elements that must be excluded from the - * content of this element, in all levels of the hierarchy. - * @param inclusions the elements that can be included as the - * content of this element. - * @param attributes the element attributes. - * @return the created or updated element. - */ - public Element defElement(String name, int type, boolean headless, - boolean tailless, ContentModel content, - Collection exclusions, Collection inclusions, - AttributeList attributes - ) - { - return super.defElement(name, type, headless, tailless, content, - toStringArray(exclusions), - toStringArray(inclusions), attributes - ); - } - - /** - * Defines a new element and adds it to the element table. - * If the element alredy exists, - * overrides it settings with the specified values. - * @param name the name of the new element - * @param type the type of the element - * @param headless true if the element needs no starting tag - * @param tailless true if the element needs no closing tag - * @param content the element content. - * @param exclusions the elements that must be excluded from the - * content of this element, in all levels of the hierarchy. - * @param inclusions the elements that can be included as the - * content of this element. - * @param attributes the element attributes (an array and not a - * linked list). The attributes are chained into the linked list - * inside this method. - * @return the created or updated element. - */ - public Element defElement(String name, int type, boolean headless, - boolean tailless, ContentModel content, - String[] exclusions, String[] inclusions, - AttributeList[] attributes - ) - { - AttributeList list; - - if (attributes == null || attributes.length == 0) - list = null; - else - { - if (attributes.length > 1) - for (int i = 1; i < attributes.length; i++) - { - attributes [ i - 1 ].next = attributes [ i ]; - } - list = attributes [ 0 ]; - } - - Element e = - super.defElement(name, type, headless, tailless, content, exclusions, - inclusions, list - ); - return e; - } - - /** - * Creates, adds into the internal table and returns the - * character entity like <code>&lt;</code> - * (means '<code><</code>' ); - * This method inactivates the recursive refenrences to the same - * entity. - * @param name The entity name (without heading & and closing ;) - * @param type The entity type - * @param character The entity value (single character) - * @return The created entity - */ - public Entity defEntity(String name, int type, String data) - { - int r; - String eref = "%" + name + ";"; - do - { - r = data.indexOf(eref); - if (r > 0) - { - data = data.substring(0, r) + data.substring(r + 1); - } - } - while (r > 0); - - return super.defEntity(name, type, data); - } - - /** - * Summarises the document content into the given PrintStream. - */ - public void dump(PrintStream p) - { - Iterator iter = entityHash.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry item = (Map.Entry) iter.next(); - Entity e = (Entity) item.getValue(); - if (e.isGeneral()) - p.println("Entity " + e.getName() + ": " + e.getString()); - } - - iter = elementHash.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry item = (Map.Entry) iter.next(); - Element e = (Element) item.getValue(); - p.println("Element " + e.getName()); - - System.out.println(" includes:"); - dump(e.inclusions); - System.out.println(" excludes:"); - dump(e.exclusions); - System.out.println(" attributes:"); - - AttributeList atts = e.atts; - while (atts != null) - { - p.print(" " + atts.name + " = " + atts.value); - if (atts.values == null || atts.values.size() == 0) - p.println(); - else - { - Iterator viter = atts.values.iterator(); - System.out.print(" ( "); - while (viter.hasNext()) - { - System.out.print(viter.next()); - if (viter.hasNext()) - System.out.print(" | "); - } - System.out.println(" ) "); - } - atts = atts.next; - } - } - } - - /** - * Prints the content of the given attribute set to the System.out. - * @param b - */ - public void dump(BitSet b) - { - if (b != null) - { - for (int i = 0; i < b.size(); i++) - { - if (b.get(i)) - System.out.println(" " + elements.get(i)); - } - } - else - System.out.println(" NULL set"); - } - - /** - * Creates the attribute. - * @param name The attribute name. - * @param type The attribute type. - * @param modifier The attribute modifier. - * @param defaultValue Default value (or null) - * @param allowed_values Allowed values (or null) - * @return The newly created AttributeList. The <code>next</code> - * field is initialized to null. - */ - protected AttributeList attr(String name, String default_value, - String[] allowed_values, int type, int modifier - ) - { - Vector allowed = null; - - if (allowed_values != null) - { - allowed = new Vector(allowed_values.length); - for (int i = 0; i < allowed_values.length; i++) - { - allowed.add(allowed_values [ i ]); - } - } - ; - - AttributeList attr = - new AttributeList(name, type, modifier, default_value, allowed, null); - - return attr; - } - - /** - * Define the general entity, holding a single character. - * @param name The entity name (for example, 'amp'). - * The defined entity <b>is</b> stored into the entity table. - * @param character The entity character (for example, '&'). - */ - protected void defineEntity(String name, int character) - { - super.defEntity(name, GENERAL, character); - } - - private String[] toStringArray(Collection c) - { - String[] s = new String[ c.size() ]; - Iterator iter = c.iterator(); - for (int i = 0; i < s.length; i++) - { - s [ i ] = iter.next().toString(); - } - return s; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/htmlAttributeSet.java b/libjava/gnu/javax/swing/text/html/parser/htmlAttributeSet.java deleted file mode 100644 index a4e6f73c523..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/htmlAttributeSet.java +++ /dev/null @@ -1,133 +0,0 @@ -/* htmlAttributeSet.java -- A set to store HTML attributes - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser; - -import java.util.Enumeration; - -import javax.swing.text.AttributeSet; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.html.HTML; - -/** - * A set, adapted to store HTML attributes. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class htmlAttributeSet - extends SimpleAttributeSet -{ - public static final htmlAttributeSet EMPTY_HTML_ATTRIBUTE_SET = - new htmlAttributeSet(); - AttributeSet parent; - - /** - * Looks in this set and, if not found, later looks in the parent set. - * Calls toString(), allowing to pass as HTML.Attribute, as String - * to this method. - * @param key A key to search for a value. - * @return The value, if one is defined. - */ - public Object getAttribute(Object _key) - { - Object key = _key.toString().toLowerCase(); - - Object v = super.getAttribute(key); - if (v != null) - return v; - else if (parent != null) - return parent.getAttribute(key); - else - return null; - } - - /** - * The name set must return HTML.Attribute and not a string, - * where applicable. - */ - public Enumeration getAttributeNames() - { - // Replace the string keys by HTML.attribute, where applicable - final Enumeration enumeration = super.getAttributeNames(); - - return new Enumeration() - { - public boolean hasMoreElements() - { - return enumeration.hasMoreElements(); - } - - public Object nextElement() - { - Object key = enumeration.nextElement(); - HTML.Attribute hKey = HTML.getAttributeKey((String) key); - if (hKey != null) - return hKey; - else - return key; - } - }; - } - - /** - * Set the parent set, containing the default values. - * @param a_parent - */ - public void setResolveParent(AttributeSet a_parent) - { - parent = a_parent; - } - - /** - * Get the parent set, containing the default values. - * @return - */ - public AttributeSet getResolveParent() - { - return parent; - } - - /** - * Add the attribute to this attribute set. - * @param key Attribute key (will be case insensitive) - * @param value Attribute value - */ - public void addAttribute(Object key, Object value) - { - super.addAttribute(key.toString().toLowerCase(), value); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/htmlValidator.java b/libjava/gnu/javax/swing/text/html/parser/htmlValidator.java deleted file mode 100644 index 1f9eee03a91..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/htmlValidator.java +++ /dev/null @@ -1,610 +0,0 @@ -/* tagStack.java -- The HTML tag stack. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser; - -import gnu.javax.swing.text.html.parser.models.node; -import gnu.javax.swing.text.html.parser.models.transformer; - -import java.util.BitSet; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.ListIterator; - -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.html.HTML; -import javax.swing.text.html.parser.*; - -/** - * <p>The HTML content validator, is responsible for opening and - * closing elements with optional start/end tags, detecting - * the wrongly placed html tags and reporting errors. The working instance - * is the inner class inside the {@link javax.swing.text.html.parser.Parser } - * </p> - * <p>This class could potentially - * provide basis for automated closing and insertion of the html tags, - * correcting the found html errors. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class htmlValidator -{ - /** - * The tag reference, holding additional information that the tag - * has been forcibly closed. - */ - protected class hTag - { - protected final Element element; - protected final HTML.Tag tag; - protected final TagElement tgElement; - protected boolean forcibly_closed; - protected node validationTrace; - - protected hTag(TagElement an_element) - { - element = an_element.getElement(); - tag = an_element.getHTMLTag(); - tgElement = an_element; - - if (element.content != null) - validationTrace = transformer.transform(element.content, dtd); - } - - /** - * This is called when the tag must be forcibly closed because - * it would make the newly appearing tag invalid. - * The parser is not notified about such event (just the error - * is reported). For such tags, the closing message does not - * appear when later reaching the end of stream. The exception is - * the <head> tag: the parser is notified about its silent closing - * when <body> or other html content appears. - */ - protected void forciblyCloseDueContext() - { - forcibly_closed = true; - } - - /** - * This is called when the tag must be forcibly closed after - * reaching the end of stream. The parser is notified as if - * closing the tag explicitly. - */ - protected void forciblyCloseDueEndOfStream() - { - forcibly_closed = true; - handleSupposedEndTag(element); - } - } - - /** - * The DTD, providing information about the valid document structure. - */ - protected final DTD dtd; - - /** - * The stack, holding the current tag context. - */ - protected final LinkedList stack = new LinkedList(); - - /** - * Creates a new tag stack, using the given DTD. - * @param a_dtd A DTD, providing the information about the valid - * tag content. - */ - public htmlValidator(DTD a_dtd) - { - dtd = a_dtd; - } - - /** - * Close all opened tags (called at the end of parsing). - */ - public void closeAll() - { - hTag h; - while (!stack.isEmpty()) - { - h = (hTag) stack.getLast(); - if (!h.forcibly_closed && !h.element.omitEnd()) - s_error("Unclosed <" + h.tag + ">, closing at the end of stream"); - - handleSupposedEndTag(h.element); - - closeTag(h.tgElement); - } - } - - /** - * Remove the given tag from the stack or (if found) from the list - * of the forcibly closed tags. - */ - public void closeTag(TagElement tElement) - { - HTML.Tag tag = tElement.getHTMLTag(); - hTag x; - hTag close; - - if (!stack.isEmpty()) - { - ListIterator iter = stack.listIterator(stack.size()); - - while (iter.hasPrevious()) - { - x = (hTag) iter.previous(); - if (tag.equals(x.tag)) - { - if (x.forcibly_closed && !x.element.omitEnd()) - s_error("The tag <" + x.tag + - "> has already been forcibly closed" - ); - - - // If the tag has a content model defined, forcibly close all - // tags that were opened after the tag being currently closed. - closing: - if (x.element.content != null) - { - iter = stack.listIterator(stack.size()); - while (iter.hasPrevious()) - { - close = (hTag) iter.previous(); - if (close == x) - break closing; - handleSupposedEndTag(close.element); - iter.remove(); - } - } - - stack.remove(x); - return; - } - } - } - s_error("Closing unopened <" + tag + ">"); - } - - /** - * Add the given HTML tag to the stack of the opened tags. Forcibly closes - * all tags in the stack that does not allow this tag in they content (error - * is reported). - * @param element - */ - public void openTag(TagElement tElement, htmlAttributeSet parameters) - { - // If this is a fictional call, the message from the parser - // has recursively returned - ignore. - if (tElement.fictional()) - return; - - validateParameters(tElement, parameters); - - // If the stack is empty, start from HTML - if (stack.isEmpty() && tElement.getHTMLTag() != HTML.Tag.HTML) - { - Element html = dtd.getElement(HTML.Tag.HTML.toString()); - openFictionalTag(html); - } - - Object v = tagIsValidForContext(tElement); - if (v != Boolean.TRUE) - { - // The tag is not valid for context, the content - // model suggest to open another tag. - if (v instanceof Element) - { - int n = 0; - while (v instanceof Element && (n++ < 100)) - { - Element fe = (Element) v; - - // notify the content model that we add the proposed tag - getCurrentContentModel().show(fe); - openFictionalTag(fe); - - Object vv = tagIsValidForContext(tElement); - if (vv instanceof Element) // One level of nesting is supported. - { - openFictionalTag((Element) vv); - - Object vx = tagIsValidForContext(tElement); - if (vx instanceof Element) - openFictionalTag((Element) vx); - } - else if (vv == Boolean.FALSE) - { - // The tag is still not valid for the current - // content after opening a fictional element. - if (fe.omitEnd()) - { - // close the previously opened fictional tag. - closeLast(); - vv = tagIsValidForContext(tElement); - if (vv instanceof Element) - - // another tag was suggested by the content model - openFictionalTag((Element) vv); - } - } - v = tagIsValidForContext(tElement); - } - } - else // If the current element has the optional end tag, close it. - { - if (!stack.isEmpty()) - { - closing: - do - { - hTag last = (hTag) stack.getLast(); - if (last.element.omitEnd()) - { - closeLast(); - v = tagIsValidForContext(tElement); - if (v instanceof Element) // another tag was suggested by the content model - { - openFictionalTag((Element) v); - break closing; - } - } - else - break closing; - } - while (v == Boolean.FALSE && !stack.isEmpty()); - } - } - } - - stack.add(new hTag(tElement)); - } - - /** - * Clear the stack. - */ - public void restart() - { - stack.clear(); - } - - /** - * Check if this tag is valid for the current context. - * Return Boolean.True if it is OK, Boolean.False - * if it is surely not OK or the Element that the - * content model recommends to insert making the situation - * ok. If Boolean.True is returned, the content model current - * position is moved forward. Otherwise this position remains - * the same. - * @param tElement - * @return - */ - public Object tagIsValidForContext(TagElement tElement) - { - // Check the current content model, if one is available. - node cv = getCurrentContentModel(); - - if (cv != null) - return cv.show(tElement.getElement()); - - // Check exclusions and inclusions. - ListIterator iter = stack.listIterator(stack.size()); - hTag t; - final int idx = tElement.getElement().index; - - // Check only known tags. - if (idx >= 0) - { - BitSet inclusions = new BitSet(); - while (iter.hasPrevious()) - { - t = (hTag) iter.previous(); - if (!t.forcibly_closed) - { - if (t.element.exclusions != null && - t.element.exclusions.get(idx) - ) - return Boolean.FALSE; - - if (t.element.inclusions != null) - inclusions.or(t.element.inclusions); - } - } - if (!inclusions.get(idx)) - return Boolean.FALSE; - } - return Boolean.TRUE; - } - - /** - * Validate tag without storing in into the tag stack. This is called - * for the empty tags and results the subsequent calls to the openTag - * and closeTag. - */ - public void validateTag(TagElement tElement, htmlAttributeSet parameters) - { - openTag(tElement, parameters); - closeTag(tElement); - } - - /** - * Check for mandatory elements, subsequent to the last tag: - * @param tElement The element that will be inserted next. - */ - protected void checkContentModel(TagElement tElement, boolean first) - { - if (stack.isEmpty()) - return; - - hTag last = (hTag) stack.getLast(); - if (last.validationTrace == null) - return; - - Object r = last.validationTrace.show(tElement.getElement()); - if (r == Boolean.FALSE) - s_error("The <" + last.element + "> does not match the content model " + - last.validationTrace - ); - else if (r instanceof Element) // The content model recommends insertion of this element - { - if (!first) - closeTag(last.tgElement); - handleSupposedStartTag((Element) r); - openTag(new TagElement((Element) r), null); - } - } - - /** - * The method is called when the tag must be closed because - * it does not allow the subsequent elements inside its context - * or the end of stream has been reached. The parser is only - * informed if the element being closed does not require the - * end tag (the "omitEnd" flag is set). - * The closing message must be passed to the parser mechanism - * before passing message about the opening the next tag. - * - * @param element The tag being fictionally (forcibly) closed. - */ - protected abstract void handleSupposedEndTag(Element element); - - /** - * The method is called when the validator decides to open the - * tag on its own initiative. This may happen if the content model - * includes the element with the optional (supposed) start tag. - * - * @param element The tag being opened. - */ - protected abstract void handleSupposedStartTag(Element element); - - /** - * Handles the error message. This method must be overridden to pass - * the message where required. - * @param msg The message text. - */ - protected abstract void s_error(String msg); - - /** - * Validate the parameters, report the error if the given parameter is - * not in the parameter set, valid for the given attribute. The information - * about the valid parameter set is taken from the Element, enclosed - * inside the tag. The method does not validate the default parameters. - * @param tag The tag - * @param parameters The parameters of this tag. - */ - protected void validateParameters(TagElement tag, htmlAttributeSet parameters) - { - if (parameters == null || - parameters == htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET || - parameters == SimpleAttributeSet.EMPTY - ) - return; - - Enumeration enumeration = parameters.getAttributeNames(); - - while (enumeration.hasMoreElements()) - { - validateAttribute(tag, parameters, enumeration); - } - - // Check for missing required values. - AttributeList a = tag.getElement().getAttributes(); - - while (a != null) - { - if (a.getModifier() == DTDConstants.REQUIRED) - if (parameters.getAttribute(a.getName()) == null) - { - s_error("Missing required attribute '" + a.getName() + "' for <" + - tag.getHTMLTag() + ">" - ); - } - a = a.next; - } - } - - private node getCurrentContentModel() - { - if (!stack.isEmpty()) - { - hTag last = (hTag) stack.getLast(); - return last.validationTrace; - } - else - return null; - } - - private void closeLast() - { - handleSupposedEndTag(((hTag) stack.getLast()).element); - stack.removeLast(); - } - - private void openFictionalTag(Element e) - { - handleSupposedStartTag(e); - stack.add(new hTag(new TagElement(e, true))); - if (!e.omitStart()) - s_error("<" + e + "> is expected (supposing it)"); - } - - private void validateAttribute(TagElement tag, htmlAttributeSet parameters, - Enumeration enumeration - ) - { - Object foundAttribute; - AttributeList dtdAttribute; - foundAttribute = enumeration.nextElement(); - dtdAttribute = tag.getElement().getAttribute(foundAttribute.toString()); - if (dtdAttribute == null) - { - StringBuffer valid = - new StringBuffer("The tag <" + tag.getHTMLTag() + - "> cannot contain the attribute '" + foundAttribute + - "'. The valid attributes for this tag are: " - ); - - AttributeList a = tag.getElement().getAttributes(); - - while (a != null) - { - valid.append(a.name.toUpperCase()); - valid.append(' '); - a = a.next; - } - s_error(valid.toString()); - } - - else - { - String value = parameters.getAttribute(foundAttribute).toString(); - - if (dtdAttribute.type == DTDConstants.NUMBER) - validateNumberAttribute(tag, foundAttribute, value); - - if (dtdAttribute.type == DTDConstants.NAME || - dtdAttribute.type == DTDConstants.ID - ) - validateNameOrIdAttribute(tag, foundAttribute, value); - - if (dtdAttribute.values != null) - validateAttributeWithValueList(tag, foundAttribute, dtdAttribute, - value - ); - } - } - - private void validateAttributeWithValueList(TagElement tag, - Object foundAttribute, - AttributeList dtdAttribute, - String value - ) - { - if (!dtdAttribute.values.contains(value.toLowerCase()) && - !dtdAttribute.values.contains(value.toUpperCase()) - ) - { - StringBuffer valid; - if (dtdAttribute.values.size() == 1) - valid = - new StringBuffer("The attribute '" + foundAttribute + - "' of the tag <" + tag.getHTMLTag() + - "> cannot have the value '" + value + - "'. The only valid value is " - ); - else - valid = - new StringBuffer("The attribute '" + foundAttribute + - "' of the tag <" + tag.getHTMLTag() + - "> cannot have the value '" + value + "'. The " + - dtdAttribute.values.size() + - " valid values are: " - ); - - Enumeration vv = dtdAttribute.values.elements(); - while (vv.hasMoreElements()) - { - valid.append('"'); - valid.append(vv.nextElement()); - valid.append("\" "); - } - s_error(valid.toString()); - } - } - - private void validateNameOrIdAttribute(TagElement tag, Object foundAttribute, - String value - ) - { - boolean ok = true; - - if (!Character.isLetter(value.charAt(0))) - ok = false; - - char c; - for (int i = 0; i < value.length(); i++) - { - c = value.charAt(i); - if (!( - Character.isLetter(c) || Character.isDigit(c) || - "".indexOf(c) >= 0 - ) - ) - ok = false; - } - if (!ok) - s_error("The '" + foundAttribute + "' attribute of the tag <" + - tag.getHTMLTag() + "> must start from letter and consist of " + - "letters, digits, hypens, colons, underscores and periods. " + - "It cannot be '" + value + "'" - ); - } - - private void validateNumberAttribute(TagElement tag, Object foundAttribute, - String value - ) - { - try - { - Integer.parseInt(value); - } - catch (NumberFormatException ex) - { - s_error("The '" + foundAttribute + "' attribute of the tag <" + - tag.getHTMLTag() + "> must be a valid number and not '" + - value + "'" - ); - } - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java b/libjava/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java deleted file mode 100755 index 5a19a1bc13c..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java +++ /dev/null @@ -1,62 +0,0 @@ -/* PCDATAonly_model.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -/** - * The model, allowing only PCDATA in it (like for element OPTION). - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class PCDATAonly_model - extends node - implements Serializable -{ - private static final long serialVersionUID = 1; - - public PCDATAonly_model() - { - super((char) 0, (char) 0, null); - } - - public Object show(Object x) - { - return x.toString().equalsIgnoreCase("#pcdata") ? Boolean.TRUE : Boolean.FALSE; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java b/libjava/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java deleted file mode 100755 index 14514d58458..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/TableRowContentModel.java +++ /dev/null @@ -1,77 +0,0 @@ -/* TableRowContentModel.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.Element; - -/** - * Table row content model. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class TableRowContentModel - extends node - implements Serializable -{ - private static final long serialVersionUID = 1; - final Element TD; - - public TableRowContentModel(DTD dtd) - { - super((char) 0, (char) 0, null); - TD = dtd.getElement("TD"); - } - - public Object show(Object x) - { - // Always accept TD and TH - String s = x.toString(); - if (s.equalsIgnoreCase("TD") || s.equalsIgnoreCase("TH")) - return Boolean.TRUE; - - // Suggest closing in response to TR: - if (s.equalsIgnoreCase("TR")) - return Boolean.FALSE; - - // Recommend TD for other cases: - return TD; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/list.java b/libjava/gnu/javax/swing/text/html/parser/models/list.java deleted file mode 100755 index b77ef7fd850..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/list.java +++ /dev/null @@ -1,382 +0,0 @@ -/* list.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -/** - * Part of the internal representation of the content model. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class list - extends node - implements Serializable -{ - private static final long serialVersionUID = 1; - - /** - * Setting to true means that the list nodes must always be connected - * by the same operation. This is far safer and clearer, but not - * required by default standard. - */ - public static boolean CLEAR; - - /** - * A list of nodes. - */ - public final node[] nodes; - - /** - * Creates a new model list that is a member of some enclosing list. - * @param binary_operator An operator with that this list is connected - * with other members of the enclosing list. - * @param unary_operator The unary operator for this list. - * @param a_nodes The nodes inside this list. - */ - public list(char binary_operator, char unary_operator, node[] a_nodes) - { - super(binary_operator, unary_operator, a_nodes); - nodes = a_nodes; - } - - /** - * Creates a new model list. Assigns the previous field. - * @param a_nodes The nodes for this list. - * @throws an error if the node elements are connected by the - * different operations. This is not supported, use grouping. - */ - public list(node[] a_nodes) - throws Error - { - this(',', (char) 0, a_nodes); - - int operation = nodes [ 0 ].binary; - - for (int i = 0; i < nodes.length; i++) - { - if (CLEAR && nodes [ i ].binary != operation) - throw new Error("List members can only be connected by " + - "the same operation, use grouping" - ); - - if (i > 0) - nodes [ i ].previous = nodes [ i - 1 ]; - } - } - - /** - * Returns true if all members in the list are closed. - */ - public boolean isClosed() - { - if (super.isClosed()) - return true; - for (int i = 0; i < nodes.length; i++) - { - if (!nodes [ i ].isClosed()) - return false; - } - return true; - } - - /** - * Find the token that could match as the next token in - * the token list. - * - * @return Such token object or null if none is found. - */ - public Object findFreeNode() - { - Object fn; - for (int j = 0; j < nodes.length; j++) - { - if (!nodes [ j ].isClosed()) - { - fn = nodes [ j ].findFreeNode(); - if (fn != null) - return fn; - } - } - return null; - } - - /** - * Tries to match this list agains the given token sequence. - * @param tokens the sequence of the tokens to match. - * @return true if the valid match is found. - */ - public boolean matches(Object[] tokens) - { - reset(); - - Object x; - boolean m; - boolean matched = false; - - for (int i = 0; i < tokens.length; i++) - { - matched = false; - x = tokens [ i ]; - - nodescan: - for (int j = 0; j < nodes.length; j++) - { - if (!nodes [ j ].isClosed()) - { - m = nodes [ j ].performMatch(x); - - if (m) - { - matched = true; - break nodescan; - } - } - } - if (!matched) - return false; - } - - boolean valid = true; - - for (int i = 0; i < nodes.length; i++) - { - if (!nodes [ i ].valid()) - valid = false; - } - - return valid; - } - - /** - * The list never closes, despite it is trated as closed - * if all members in the list are closed. - * @return false. - */ - public boolean mustClose() - { - return false; - } - - /** - * Perform a match operation for the single token - * against this list. - * @param token a token to match. - * @return true if the match is found. - */ - public boolean performMatch(Object token) - { - boolean ok = false; - Matching: - for (int i = 0; i < nodes.length; i++) - { - ok = nodes [ i ].performMatch(token); - - if (ok) - break Matching; - } - - if (ok) - matches(); - - return ok; - } - - /** - * Prepeares the list for the next matching operation. - */ - public void reset() - { - super.reset(); - for (int i = 0; i < nodes.length; i++) - nodes [ i ].reset(); - } - - /** - * Check if the provided token can match as a next token in the - * list. In the case of match, the list state changes, moving - * current position after the matched token. However if this method - * returns a suggested new token to insert before the provided one, - * the state of the list does not change. - * @return Boolean.TRUE if the match is found, - * Boolean.FALSE if the match is not possible and no token can be - * inserted to make the match valid. Otherwise, returns the - * token object that can be inserted before the last token in the - * list, probably (not for sure) making the match valid. - * If the object is an instance of Element or TagElement, - * it is first ensured that the object flag "omit start" is set. - */ - public Object show(Object x) - { - boolean m; - boolean matched = false; - - nodescan: - for (int j = 0; j < nodes.length; j++) - { - if (!nodes [ j ].isClosed()) - { - m = nodes [ j ].performMatch(x); - - if (m) - { - matched = true; - break nodescan; - } - else - { - // For comma operation, only first not closed - // node must be tested for a match. - // unless it allows matching zero times. - if (binary == ',' && - !(nodes [ j ].unary == '?' || nodes [ j ].unary == '*') - ) - break nodescan; - } - } - } - - if (!matched) - { - // Find and return that would be matched. - Object freeNode = findFreeNode(); - if (freeNode == null) - return Boolean.FALSE; - else - return freeNode; - } - - for (int i = 0; i < nodes.length; i++) - if (!nodes [ i ].validPreliminary()) - { - return Boolean.FALSE; - } - - return Boolean.TRUE; - } - - /** - * Returns a string representation of the list. - * @return String representation, similar to BNF expression. - */ - public String toString() - { - StringBuffer b = new StringBuffer(); - b.append(" ( "); - for (int i = 0; i < nodes.length; i++) - { - if (i > 0) - b.append(" " + (char) nodes [ i ].binary + " "); - b.append(nodes [ i ]); - } - - b.append(" )"); - if (unary != 0) - b.append((char) unary); - else - b.append(' '); - return b.toString(); - } - - /** - * Returns true if all memebers in the list are valid. - */ - public boolean valid() - { - for (int i = 0; i < nodes.length; i++) - { - if (!nodes [ i ].valid()) - return false; - } - return true; - } - - /** - * Returns true if all memebers in the list are either valid - * or unvisited. The unvisited members can become valid after - * more tokens will be shown. - */ - public boolean validPreliminary() - { - if (silenceAllowed()) - { - boolean everVisited = false; - for (int i = 0; i < nodes.length; i++) - { - if (nodes [ i ].visits > 0) - { - everVisited = true; - break; - } - } - if (!everVisited) - return true; - } - - for (int i = 0; i < nodes.length; i++) - { - if (!nodes [ i ].validPreliminary()) - return false; - } - return true; - } - - /** - * Closes all members in the list. - */ - protected void close() - { - super.close(); - for (int i = 0; i < nodes.length; i++) - { - nodes [ i ].close(); - } - } - - /** - * Compare given token with the token of this node. - * If the token represents a <code>list</code>, the call may be - * delegeted to the child subnodes. - * @param a_token A token to compare. - * @return True if the token matches the token of this node. - */ - protected boolean compare(Object a_token) - { - return performMatch(a_token); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/noTagModel.java b/libjava/gnu/javax/swing/text/html/parser/models/noTagModel.java deleted file mode 100755 index 8aac14d8e16..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/noTagModel.java +++ /dev/null @@ -1,75 +0,0 @@ -/* noTagModel.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -/** - * Disallows a single given tag at the current content level only. - * <p>@author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)</p> - */ -public class noTagModel - extends node - implements Serializable -{ - private static final long serialVersionUID = 1; - final String[] no; - - public noTagModel(String[] noTag) - { - super((char) 0, (char) 0, null); - no = noTag; - } - - public noTagModel(String noTag) - { - super((char) 0, (char) 0, null); - no = new String[] { noTag }; - } - - public Object show(Object x) - { - for (int i = 0; i < no.length; i++) - { - if (x.toString().equalsIgnoreCase(no [ i ])) - return Boolean.FALSE; - } - return Boolean.TRUE; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/node.java b/libjava/gnu/javax/swing/text/html/parser/models/node.java deleted file mode 100755 index c615ddff350..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/node.java +++ /dev/null @@ -1,337 +0,0 @@ -/* node.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -/** - * Part of the internal representation of the content model. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class node - implements Serializable -{ - private static final long serialVersionUID = 1; - - /** - * The token to match (can be instance of list). - */ - public Object token; - - /** - * True for the node that cannot be visited again. - */ - public boolean _closed; - - /** - * The binary operation for this node. - */ - public char binary; - - /** - * The unary opeation for this node. - */ - public char unary; - - /** - * The number of times the node already was visited. - */ - public int visits; - - /** - * The previous node in content model (used for closing nodes). - */ - public node previous; - - /** - * Creates a new node. - * @param binary_operator The operator, connecting all nodes in the list. - * The nodes, connected by the different operators, must be arranged into - * the different lists. - * @param unary_operator The unary operator for this node or zero if - * no such was specified. - * @param token The token to match. This can be either a string or - * the new instance of the list. - * @param a_previous The previous node in the list, null for the first - * node. This is used for propagating the closing operation for the - * comma delimited list. - */ - public node(char binary_operator, char unary_operator, Object a_token) - { - if (a_token != null) - if (a_token.getClass().equals(node.class)) - throw new Error("Creating node in node is redundant and ineffective."); - - binary = binary_operator; - unary = unary_operator; - token = a_token; - } - - /** - * Checks if this node is in the closed state. - * @return True if the node is closed. - */ - public boolean isClosed() - { - return _closed; - } - - /** - * Check if closing this node means closing the previous node. - */ - public boolean closePrevious() - { - return binary == ','; - } - - /** - * Return the token object if it could match as a next token in - * a token list of null if it could not. - * @return - */ - public Object findFreeNode() - { - boolean ok; - if (isClosed() || silenceAllowed()) - return null; - - // Try if the node would stay valid after a one more visit. - visits++; - ok = valid(); - visits--; - - if (ok) - { - if (token instanceof node) - return ((node) token).findFreeNode(); - else - return token; - } - else - return null; - } - - /** - * Check if the current situation is such that the node must be closed - * now. - */ - public boolean mustClose() - { - switch (unary) - { - case 0 : - return true; - - case '*' : - return false; - - case '+' : - return false; - - case '?' : - return visits <= 1; - - default : - throw new Error("Invalid unary operation " + unary + " ( '" + - (char) unary + "' )" - ); - } - } - - /** - * Do the match operation with the given token. This sets various - * flags. - * @param token The token to match. - * @return true if the the token matches node, false if it does not match - * or if the node is closed. - */ - public boolean performMatch(Object a_token) - { - if (isClosed()) - return false; - - boolean matches = compare(a_token); - if (matches) - matches(); - - return matches; - } - - /** - * Prepares the node for matching against a new list of tokens. - */ - public void reset() - { - _closed = false; - visits = 0; - } - - /** - * Check if the provided token can match this node. - * In the case of match, the node state changes, moving - * current position after the matched token. However if this method - * returns a suggested new token to insert before the provided one, - * the state of the list does not change. - * @return Boolean.TRUE if the match is found, - * Boolean.FALSE if the match is not possible and no token can be - * inserted to make the match valid. Otherwise, returns the - * token object that can be inserted before the last token in the - * list, probably (not for sure) making the match valid. - */ - public Object show(Object x) - { - if (compare(x)) - return performMatch(x) ? Boolean.TRUE : Boolean.FALSE; - - Object recommended = findFreeNode(); - return recommended != null ? recommended : Boolean.FALSE; - } - - /** - * Check if it would be a valid case if this node is visited zero times. - * Nodes with unary operator * or ? need not be matched to make a - * model valid. - */ - public boolean silenceAllowed() - { - return unary == '?' || unary == '*'; - } - - /** - * Returns a string representation of the list. - * @return String representation, similar to BNF expression. - */ - public String toString() - { - StringBuffer b = new StringBuffer(); - - b.append(token); - if (unary != 0) - b.append((char) unary); - else - b.append('\''); - - return b.toString(); - } - - /** - * Check if the node state is valid. - */ - public boolean valid() - { - switch (unary) - { - case 0 : - if (binary == '|') - return true; - else - return visits == 1; - - case '*' : - return true; - - case '+' : - return visits > 0; - - case '?' : - return visits <= 1; - - default : - throw new Error("Invalid unary operation " + unary + " ( '" + - (char) unary + "' )" - ); - } - } - - public boolean validPreliminary() - { - return visits == 0 || valid(); - } - - /** - * Closes this node and, if closePrevious() returs true, calls close() for - * the previous node. - */ - protected void close() - { - _closed = true; - if (previous != null && closePrevious()) - previous.close(); - } - - /** - * Compare the provided token object with the token object of this node. - */ - protected boolean compare(Object a_token) - { - if (token instanceof Object[]) - throw new Error("Invalid token object, probably the 'list' " + - "should be used. " - ); - - if (token instanceof node[]) - throw new Error("Do not use 'node' for the array of nodes, use 'list'. "); - - if (token instanceof node) - { - return ((node) token).performMatch(a_token); - } - - boolean rt = false; - - if (token == a_token) - rt = true; - if (token.equals(a_token)) - rt = true; - if (token.toString().equalsIgnoreCase(a_token.toString())) - rt = true; - - return rt; - } - - /** - * Fire the changes that must happen then the token matches this node. - */ - protected void matches() - { - visits++; - if (mustClose()) - close(); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/models/transformer.java b/libjava/gnu/javax/swing/text/html/parser/models/transformer.java deleted file mode 100755 index 22ae3c3fa52..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/models/transformer.java +++ /dev/null @@ -1,201 +0,0 @@ -/* transformer.java -- Content model transforms. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.models; - -import java.io.Serializable; - -import javax.swing.text.html.parser.ContentModel; -import javax.swing.text.html.parser.DTD; - -/** - * Transforms the standard ContentModel tree into the internal representation, - * used in this implementation. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class transformer - implements Serializable -{ - private static final long serialVersionUID = 1; - - /** - * All binary operators. - */ - protected static String binary = "&|,"; - - /** - * All unary operators. - */ - protected static String unary = "+*?"; - - /** - * Measure length of the linked list of the content models. - * @param c The heading element of the linked list. - * @return the length of the list (0 for null 1 if c!=null and c.next==null, - * etc. - */ - public static int measureChainLength(ContentModel c) - { - if (c == null) - return 0; - else - return measureChainLength(c.next) + 1; - } - - /** - * Transform into internal representation without usind dtd. - * This should be used only for testing. - */ - public static node transform(ContentModel c) - { - return transform(c, null); - } - - /** - * Transform into internal representation. - * @param c a model to transform - * @return a transformed model - * @throws Error if the model structure contains errors. - */ - public static node transform(ContentModel c, DTD dtd) - { - // Handle the special cases first. - if (c.content instanceof node) - return (node) c.content; - - // Do the typical transform. - node n; - - /* Case with the single token */ - if (c.next == null) - { - n = optionalTransform(c, dtd); - } - else /* Case with the chain of the multiple tokens. */ - { - node[] l = new node[ measureChainLength(c) ]; - ContentModel m = c; - for (int i = 0; i < l.length; i++) - { - if (m.content instanceof ContentModel) - { - ContentModel nested = (ContentModel) m.content; - if (nested.next == null && - !(nested.content instanceof ContentModel) - ) - { - l [ i ] = - new node((char) m.type, (char) nested.type, nested.content); - } - else - { - l [ i ] = transform(nested, dtd); - } - } - else - l [ i ] = new node((char) 0, (char) 0, m.content); - addtype(l [ i ], (char) m.type); - m = m.next; - } - - if (isBinary(c.type)) - for (int i = 0; i < l.length; i++) - { - l [ i ].binary = (char) c.type; - } - - n = new list(l); - } - - addtype(n, (char) c.type); - - return n; - } - - /** - * True for binary operator - * @param c a character to test - * @return true for [ ,&| ], false otherwise. - */ - private static boolean isBinary(int c) - { - return binary.indexOf((char) c) >= 0; - } - - /** - * True for unary operator. - * @param c a character to test - * @return true for [ +?* ], false otherwise. - */ - private static boolean isUnary(int c) - { - return unary.indexOf((char) c) >= 0; - } - - /** - * Assign an operation type for the given node. - * @param n A node to set the operation to. - * @param type Either binary or unary operation, is assigned to the - * corresponding field of the node. - * @throws error if the operation type is not - * representing a valid unary or binary operation. - */ - private static void addtype(node n, char type) - { - if (isBinary(type)) - n.binary = type; - - else if (isUnary(type)) - n.unary = type; - - else if (type != 0) - throw new Error("Invalid operation '" + (char) type + "'"); - } - - private static node optionalTransform(ContentModel c, DTD dtd) - { - node n; - if (c.content instanceof ContentModel) - n = transform((ContentModel) c.content, dtd); - else - - /* A single token with the specified operation */ - n = new node((char) 0, (char) 0, c.content); - return n; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/Parser.java b/libjava/gnu/javax/swing/text/html/parser/support/Parser.java deleted file mode 100755 index cef94942e16..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/Parser.java +++ /dev/null @@ -1,1443 +0,0 @@ -/* Parser.java -- HTML parser. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support; - -import gnu.javax.swing.text.html.parser.htmlAttributeSet; -import gnu.javax.swing.text.html.parser.htmlValidator; -import gnu.javax.swing.text.html.parser.support.low.Constants; -import gnu.javax.swing.text.html.parser.support.low.ParseException; -import gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer; -import gnu.javax.swing.text.html.parser.support.low.Token; -import gnu.javax.swing.text.html.parser.support.low.node; -import gnu.javax.swing.text.html.parser.support.low.pattern; - -import java.io.IOException; -import java.io.Reader; - -import java.util.Comparator; -import java.util.Set; -import java.util.TreeSet; -import java.util.Vector; - -import javax.swing.text.ChangedCharSetException; -import javax.swing.text.html.HTML; -import javax.swing.text.html.parser.AttributeList; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.DTDConstants; -import javax.swing.text.html.parser.Element; -import javax.swing.text.html.parser.Entity; -import javax.swing.text.html.parser.TagElement; - -/** - * <p>A simple error-tolerant HTML parser that uses a DTD document - * to access data on the possible tokens, arguments and syntax.</p> - * <p> The parser reads an HTML content from a Reader and calls various - * notifying methods (which should be overridden in a subclass) - * when tags or data are encountered.</p> - * <p>Some HTML elements need no opening or closing tags. The - * task of this parser is to invoke the tag handling methods also when - * the tags are not explicitly specified and must be supposed using - * information, stored in the DTD. - * For example, parsing the document - * <p><table><tr><td>a<td>b<td>c</tr> <br> - * will invoke exactly the handling methods exactly in the same order - * (and with the same parameters) as if parsing the document: <br> - * <em><html><head></head><body><table>< - * tbody></em><tr><td>a<em></td></em><td>b<em> - * </td></em><td>c<em></td></tr></em>< - * <em>/tbody></table></body></html></em></p> - * (supposed tags are given in italics). The parser also supports - * obsolete elements of HTML syntax.<p> - * </p> - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Parser - extends ReaderTokenizer - implements DTDConstants -{ - /** - * The current html tag. - */ - public Token hTag = new Token(); - - /** - * The document template description that will be used to parse the documents. - */ - protected DTD dtd; - - /** - * The value of this field determines whether or not the Parser will be - * strict in enforcing SGML compatibility. The default value is false, - * stating that the parser should do everything to parse and get at least - * some information even from the incorrectly written HTML input. - */ - protected boolean strict; - - /** - * This fields has positive values in preformatted tags. - */ - protected int preformatted = 0; - - /** - * The set of the document tags. This field is used for supporting - * markFirstTime(). - */ - private Set documentTags = - new TreeSet(new Comparator() - { - public int compare(Object a, Object b) - { - return ((String) a).compareToIgnoreCase((String) b); - } - } - ); - - /** - * The buffer to collect the incremental output like text or coment. - */ - private StringBuffer buffer = new StringBuffer(); - - /** - * The buffer to store the document title. - */ - private StringBuffer title = new StringBuffer(); - - /** - * The current token. - */ - private Token t; - - /** - * True means that the 'title' tag of this document has - * already been handled. - */ - private boolean titleHandled; - - /** - * True means that the 'title' tag is currently open and all - * text is also added to the title buffer. - */ - private boolean titleOpen; - - /** - * The attributes of the current HTML element. - * Package-private to avoid an accessor method. - */ - htmlAttributeSet attributes = - htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; - - /** - * The validator, controlling the forcible closing of the tags that - * (in accordance to dtd) are not allowed in the current context. - */ - private htmlValidator validator; - - /** - * Provides the default values for parameters in the case when these - * values are defined in the DTD. - */ - private parameterDefaulter defaulter; - - /** - * The text pre-processor for handling line ends and tabs. - */ - private textPreProcessor textProcessor = new textPreProcessor(); - - /** - * Creates a new Parser that uses the given - * {@link javax.swing.text.html.parser.DTD }. The only standard way - * to get an instance of DTD is to construct it manually, filling in - * all required fields. - * @param a_dtd The DTD to use. The parser behaviour after passing null - * as an argument is not documented and may vary between implementations. - */ - public Parser(DTD a_dtd) - { - if (a_dtd == null) - dtd = gnu.javax.swing.text.html.parser.HTML_401F.getInstance(); - else - dtd = a_dtd; - - defaulter = new parameterDefaulter(dtd); - - validator = - new htmlValidator(dtd) - { - /** - * Handles the error message. This method must be overridden to pass - * the message where required. - * @param msg The message text. - */ - protected void s_error(String msg) - { - error(msg); - } - - /** - * The method is called when the tag validator decides to close the - * tag on its own initiative. After reaching the end of stream, - * The tag validator closes all unclosed elements that are required - * to have the end (closing) tag. - * - * @param element The tag being fictionally (forcibly) closed. - */ - protected void handleSupposedEndTag(Element tElement) - { - // The tag is cloned as the original tElement is the - // element from the starting tag - may be accidently used - // somewhere else. - TagElement tag = makeTag(tElement, true); - _handleEndTag_remaining(tag); - } - - /** - * The method is called when the the tag validator decides to open - * the new tag on its own initiative. The tags, opened in this - * way, are HTML, HEAD and BODY. The attribute set is temporary - * assigned to the empty one, the previous value is - * restored before return. - * - * @param element The tag being fictionally (forcibly) closed. - */ - protected void handleSupposedStartTag(Element tElement) - { - TagElement tag = makeTag(tElement, true); - htmlAttributeSet were = attributes; - attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; - _handleStartTag(tag); - attributes = were; - } - }; - } - - /** - * Get the attributes of the current tag. - * @return The attribute set, representing the attributes of the current tag. - */ - public htmlAttributeSet getAttributes() - { - return attributes; - } - - /** - * Invokes the error handler. The default method in this implementation - * delegates the call to handleError, also providing the current line. - */ - public void error(String msg) - { - error(msg, getTokenAhead()); - } - - public void error(String msg, Token atToken) - { - if (atToken != null) - handleError(atToken.where.beginLine, - msg + ": line " + atToken.where.beginLine + - ", absolute pos " + atToken.where.startPosition - ); - else - handleError(0, msg); - } - - /** - * Invokes the error handler. The default method in this implementation - * delegates the call to error (parm1+": '"+parm2+"'"). - */ - public void error(String msg, String invalid) - { - error(msg + ": '" + invalid + "'"); - } - - /** - * Invokes the error handler. The default method in this implementation - * delegates the call to error (parm1+" "+ parm2+" "+ parm3). - */ - public void error(String parm1, String parm2, String parm3) - { - error(parm1 + " " + parm2 + " " + parm3); - } - - /** - * Invokes the error handler. The default method in this implementation - * delegates the call to error (parm1+" "+ parm2+" "+ parm3+" "+ parm4). - */ - public void error(String parm1, String parm2, String parm3, String parm4) - { - error(parm1 + " " + parm2 + " " + parm3 + " " + parm4); - } - - public void flushAttributes() - { - } - - /** - * Parse the HTML text, calling various methods in response to the - * occurence of the corresponding HTML constructions. - * @param reader The reader to read the source HTML from. - * @throws IOException If the reader throws one. - */ - public synchronized void parse(Reader reader) - throws IOException - { - reset(reader); - restart(); - try - { - parseDocument(); - validator.closeAll(); - } - catch (ParseException ex) - { - if (ex != null) - { - error("Unable to continue parsing the document", ex.getMessage()); - - Throwable cause = ex.getCause(); - if (cause instanceof IOException) - throw (IOException) cause; - } - } - } - - /** - * Parses DTD markup declaration. Currently returns null without action. - * @return null. - * @throws IOException - */ - public String parseDTDMarkup() - throws IOException - { - return null; - } - - /** - * Parse SGML insertion ( <! ... > ). When the - * the SGML insertion is found, this method is called, passing - * SGML in the string buffer as a parameter. The default method - * returns false without action and can be overridden to - * implement user - defined SGML support. - * <p> - * If you need more information about SGML insertions in HTML documents, - * the author suggests to read SGML tutorial on - * {@link http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html}. - * We also recommend Goldfarb C.F (1991) <i>The SGML Handbook</i>, - * Oxford University Press, 688 p, ISBN: 0198537379. - * </p> - * @param strBuff - * @return true if this is a valid DTD markup declaration. - * @throws IOException - */ - public boolean parseMarkupDeclarations(StringBuffer strBuff) - throws IOException - { - return false; - } - - /** - * Get the first line of the last parsed token. - */ - protected int getCurrentLine() - { - return hTag.where.beginLine; - } - - /** - * Read parseable character data, add to buffer. - * @param clearBuffer If true, buffer if filled by CDATA section, - * otherwise the section is appended to the existing content of the - * buffer. - * - * @throws ParseException - */ - protected void CDATA(boolean clearBuffer) - throws ParseException - { - Token start = hTag = getTokenAhead(); - - if (clearBuffer) - buffer.setLength(0); - - // Handle expected EOF. - if (start.kind == EOF) - return; - - read: - while (true) - { - t = getTokenAhead(); - if (t.kind == EOF) - { - error("unexpected eof", t); - break read; - } - else if (t.kind == BEGIN) - break read; - else if (t.kind == Constants.ENTITY) - { - resolveAndAppendEntity(t); - getNextToken(); - } - else - { - append(t); - getNextToken(); - } - } - hTag = new Token(start, getTokenAhead(0)); - if (buffer.length() != 0) - _handleText(); - } - - /** - * Process Comment. This method skips till --> without - * taking SGML constructs into consideration. The supported SGML - * constructs are handled separately. - */ - protected void Comment() - throws ParseException - { - buffer.setLength(0); - - Token start = hTag = mustBe(BEGIN); - optional(WS); - mustBe(EXCLAMATION); - optional(WS); - mustBe(DOUBLE_DASH); - - Token t; - Token last; - - comment: - while (true) - { - t = getTokenAhead(); - if (t.kind == EOF) - { - handleEOFInComment(); - last = t; - break comment; - } - else if (COMMENT_END.matches(this)) - { - mustBe(DOUBLE_DASH); - optional(WS); - last = mustBe(END); - break comment; - } - else if (COMMENT_TRIPLEDASH_END.matches(this)) - { - mustBe(DOUBLE_DASH); - t = mustBe(NUMTOKEN); - if (t.getImage().equals("-")) - { - append(t); - last = mustBe(END); - break comment; - } - else - { - buffer.append("--"); - append(t); - t = getTokenAhead(); - } - } - else - /* The lllll-- can match as NUMTOKEN */ - if ((t.getImage().endsWith("--")) && - ( - getTokenAhead(1).kind == END || - (getTokenAhead(1).kind == WS && getTokenAhead(2).kind == END) - ) - ) - { - buffer.append(t.getImage().substring(0, t.getImage().length() - 2)); - - /* Skip the closing > that we have already checked. */ - last = mustBe(t.kind); - break comment; - } - else - append(t); - mustBe(t.kind); - } - hTag = new Token(start, last); - handleComment(); - } - - /** - * Read a script. The text, returned without any changes, - * is terminated only by the closing tag SCRIPT. - */ - protected void Script() - throws ParseException - { - Token name; - - Token start = hTag = mustBe(BEGIN); - optional(WS); - - name = mustBe(SCRIPT); - - optional(WS); - - restOfTag(false, name, start); - - buffer.setLength(0); - - script: - while (!SCRIPT_CLOSE.matches(this)) - { - append(getNextToken()); - } - - consume(SCRIPT_CLOSE); - - _handleText(); - - endTag(false); - _handleEndTag(makeTagElement(name.getImage(), false)); - } - - /** - * Process SGML insertion that is not a comment. - */ - protected void Sgml() - throws ParseException - { - if (COMMENT_OPEN.matches(this)) - Comment(); - else // skip till ">" - { - Token start = hTag = mustBe(BEGIN); - optional(WS); - mustBe(EXCLAMATION); - - buffer.setLength(0); - read: - while (true) - { - t = getNextToken(); - if (t.kind == Constants.ENTITY) - { - resolveAndAppendEntity(t); - } - else if (t.kind == EOF) - { - error("unexpected eof", t); - break read; - } - else if (t.kind == END) - break read; - else - append(t); - } - - try - { - parseMarkupDeclarations(buffer); - } - catch (IOException ex) - { - error("Unable to parse SGML insertion: '" + buffer + "'", - new Token(start, t) - ); - } - } - } - - /** - * Read a style definition. The text, returned without any changes, - * is terminated only by the closing tag STYLE. - */ - protected void Style() - throws ParseException - { - Token name; - - Token start = hTag = mustBe(BEGIN); - optional(WS); - - name = mustBe(STYLE); - - optional(WS); - - restOfTag(false, name, start); - - buffer.setLength(0); - - style: - while (!STYLE_CLOSE.matches(this)) - { - append(getNextToken()); - } - - consume(STYLE_CLOSE); - - _handleText(); - - endTag(false); - _handleEndTag(makeTagElement(name.getImage(), false)); - } - - /** - * Read a html tag. - */ - protected void Tag() - throws ParseException - { - mark(true); - - boolean closing = false; - Token name; - Token start = hTag = mustBe(BEGIN); - - optional(WS); - name = getNextToken(); - optional(WS); - - if (name.kind == SLASH) - { - closing = true; - name = getNextToken(); - } - - restOfTag(closing, name, start); - } - - /** - * A hook, for operations, preceeding call to handleText. - * Handle text in a string buffer. - * In non - preformatted mode, all line breaks immediately following the - * start tag and immediately before an end tag is discarded, - * \r, \n and \t are replaced by spaces, multiple space are replaced - * by the single one and the result is moved into array, - * passing it to handleText(). - */ - protected void _handleText() - { - char[] text; - - if (preformatted > 0) - text = textProcessor.preprocessPreformatted(buffer); - else - text = textProcessor.preprocess(buffer); - - if (text != null && text.length > 0) - { - TagElement pcdata = new TagElement(dtd.getElement("#pcdata")); - attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; - _handleEmptyTag(pcdata); - - handleText(text); - if (titleOpen) - title.append(text); - } - } - - /** - * Add the image of this token to the buffer. - * @param t A token to append. - */ - protected final void append(Token t) - { - if (t.kind != EOF) - t.appendTo(buffer); - } - - /** - * Consume pattern that must match. - * @param p A pattern to consume. - */ - protected final void consume(pattern p) - { - node n; - for (int i = 0; i < p.nodes.length; i++) - { - n = p.nodes [ i ]; - if (n.optional) - optional(n.kind); - else - mustBe(n.kind); - } - } - - /** - * The method is called when the HTML end (closing) tag is found or if - * the parser concludes that the one should be present in the - * current position. The method is called immediatly - * before calling the handleEndTag(). - * @param omitted True if the tag is no actually present in the document, - * but is supposed by the parser (like </html> at the end of the - * document). - */ - protected void endTag(boolean omitted) - { - } - - /** - * Handle HTML comment. The default method returns without action. - * @param comment - */ - protected void handleComment(char[] comment) - { - } - - /** - * This is additionally called in when the HTML content terminates - * without closing the HTML comment. This can only happen if the - * HTML document contains errors (for example, the closing --;gt is - * missing. - */ - protected void handleEOFInComment() - { - error("Unclosed comment"); - } - - /** - * Handle the tag with no content, like <br>. The method is - * called for the elements that, in accordance with the current DTD, - * has an empty content. - * @param The tag being handled. - * @throws javax.swing.text.ChangedCharSetException - */ - protected void handleEmptyTag(TagElement tag) - throws javax.swing.text.ChangedCharSetException - { - } - - /** - * The method is called when the HTML closing tag ((like </table>) - * is found or if the parser concludes that the one should be present - * in the current position. - * @param The tag - */ - protected void handleEndTag(TagElement tag) - { - } - - /* Handle error that has occured in the given line. */ - protected void handleError(int line, String message) - { - } - - /** - * The method is called when the HTML opening tag ((like <table>) - * is found or if the parser concludes that the one should be present - * in the current position. - * @param The tag - */ - protected void handleStartTag(TagElement tag) - { - } - - /** - * Handle the text section. - * <p> For non-preformatted section, the parser replaces - * \t, \r and \n by spaces and then multiple spaces - * by a single space. Additionaly, all whitespace around - * tags is discarded. - * </p> - * <p> For pre-formatted text (inside TEXAREA and PRE), the parser preserves - * all tabs and spaces, but removes <b>one</b> bounding \r, \n or \r\n, - * if it is present. Additionally, it replaces each occurence of \r or \r\n - * by a single \n.</p> - * - * @param text A section text. - */ - protected void handleText(char[] text) - { - } - - /** - * Handle HTML <title> tag. This method is invoked when - * both title starting and closing tags are already behind. - * The passed argument contains the concatenation of all - * title text sections. - * @param The title text. - */ - protected void handleTitle(char[] title) - { - } - - /** - * Constructs the tag from the given element. In this implementation, - * this is defined, but never called. - * @return the tag - */ - protected TagElement makeTag(Element element) - { - return makeTag(element, false); - } - - /** - * Constructs the tag from the given element. - * @param the tag base {@link javax.swing.text.html.parser.Element} - * @param isSupposed true if the tag is not actually present in the - * html input, but the parser supposes that it should to occur in - * the current location. - * @return the tag - */ - protected TagElement makeTag(Element element, boolean isSupposed) - { - return new TagElement(element, isSupposed); - } - - /** - * This is called when the tag, representing the given element, - * occurs first time in the document. - * @param element - */ - protected void markFirstTime(Element element) - { - } - - /** - * Consume the token that was checked before and hence MUST be present. - * @param kind The kind of token to consume. - */ - protected Token mustBe(int kind) - { - if (getTokenAhead().kind == kind) - return getNextToken(); - else - { - String ei = ""; - if (kind < 1000) - ei = " ('" + (char) kind + "') "; - throw new AssertionError("The token of kind " + kind + ei + - " MUST be here," - ); - } - } - - /** - * Handle attribute without value. The default method uses - * the only allowed attribute value from DTD. - * If the attribute is unknown or allows several values, - * the HTML.NULL_ATTRIBUTE_VALUE is used. The attribute with - * this value is added to the attribute set. - * @param element The name of element. - * @param attribute The name of attribute without value. - */ - protected void noValueAttribute(String element, String attribute) - { - Object value = HTML.NULL_ATTRIBUTE_VALUE; - - Element e = (Element) dtd.elementHash.get(element.toLowerCase()); - if (e != null) - { - AttributeList attr = e.getAttribute(attribute); - if (attr != null) - { - Vector values = attr.values; - if (values != null && values.size() == 1) - value = values.get(0); - } - } - attributes.addAttribute(attribute, value); - } - - /** - * Consume the optional token, if present. - * @param kind The kind of token to consume. - */ - protected Token optional(int kind) - { - if (getTokenAhead().kind == kind) - return getNextToken(); - else - return null; - } - - /** Parse the html document. */ - protected void parseDocument() - throws ParseException - { - while (getTokenAhead().kind != EOF) - { - advanced = false; - if (TAG.matches(this)) - Tag(); - else if (COMMENT_OPEN.matches(this)) - Comment(); - else if (STYLE_OPEN.matches(this)) - Style(); - else if (SCRIPT_OPEN.matches(this)) - Script(); - else if (SGML.matches(this)) - Sgml(); - else - CDATA(true); - - // Surely HTML error, treat as a text. - if (!advanced) - { - Token wrong = getNextToken(); - error("unexpected '" + wrong.getImage() + "'", wrong); - buffer.setLength(0); - buffer.append(wrong.getImage()); - _handleText(); - } - } - } - - /** - * Read the element attributes, adding them into attribute set. - * @param element The element name (needed to access attribute - * information in dtd). - */ - protected void readAttributes(String element) - { - Token name; - Token value; - Token next; - String attrValue; - - attributes = new htmlAttributeSet(); - - optional(WS); - - attributeReading: - while (getTokenAhead().kind == NUMTOKEN) - { - name = getNextToken(); - optional(WS); - - next = getTokenAhead(); - if (next.kind == EQ) - { - mustBe(EQ); - optional(WS); - - next = getNextToken(); - - switch (next.kind) - { - case QUOT : - - // read "quoted" attribute. - buffer.setLength(0); - readTillTokenE(QUOT); - attrValue = buffer.toString(); - break; - - case AP : - - // read 'quoted' attribute. - buffer.setLength(0); - readTillTokenE(AP); - attrValue = buffer.toString(); - break; - - // read unquoted attribute. - case NUMTOKEN : - value = next; - optional(WS); - - // Check maybe the opening quote is missing. - next = getTokenAhead(); - if (bQUOTING.get(next.kind)) - { - hTag = next; - error("The value without opening quote is closed with '" + - next.getImage() + "'" - ); - } - attrValue = value.getImage(); - break; - - default : - break attributeReading; - } - attributes.addAttribute(name.getImage(), attrValue); - optional(WS); - } - else // The '=' is missing: attribute without value. - { - noValueAttribute(element, name.getImage()); - } - } - } - - /** - * Return string, corresponding the given named entity. - * The name is passed with the preceeding &, but without - * the ending semicolon. - */ - protected String resolveNamedEntity(final String a_tag) - { - // Discard & - if (!a_tag.startsWith("&")) - throw new AssertionError("Named entity " + a_tag + - " must start witn '&'." - ); - - String tag = a_tag.substring(1); - - try - { - Entity entity = dtd.getEntity(tag); - if (entity != null) - return entity.getString(); - - entity = dtd.getEntity(tag.toLowerCase()); - - if (entity != null) - { - error("The name of this entity should be in lowercase", a_tag); - return entity.getString(); - } - } - catch (IndexOutOfBoundsException ibx) - { - /* The error will be reported. */ - } - - error("Unknown named entity", a_tag); - return a_tag; - } - - /** - * Return char, corresponding the given numeric entity. - * The name is passed with the preceeding &#, but without - * the ending semicolon. - */ - protected char resolveNumericEntity(final String a_tag) - { - // Discard &# - if (!a_tag.startsWith("&#")) - throw new AssertionError("Numeric entity " + a_tag + - " must start witn '&#'." - ); - - String tag = a_tag.substring(2); - - try - { - // Determine the encoding type: - char cx = tag.charAt(0); - if (cx == 'x' || cx == 'X') // Hexadecimal &#Xnnn; - - return (char) Integer.parseInt(tag.substring(1), 16); - - return (char) Integer.parseInt(tag); - } - - /* The error will be reported. */ - catch (NumberFormatException nex) - { - } - catch (IndexOutOfBoundsException ix) - { - } - - error("Invalid numeric entity", a_tag); - return '?'; - } - - /** - * Reset all fields into the intial default state, preparing the - * parset for parsing the next document. - */ - protected void restart() - { - documentTags.clear(); - titleHandled = false; - titleOpen = false; - buffer.setLength(0); - title.setLength(0); - validator.restart(); - } - - /** - * The method is called when the HTML opening tag ((like <table>) - * is found or if the parser concludes that the one should be present - * in the current position. The method is called immediately before - * calling the handleStartTag. - * @param The tag - */ - protected void startTag(TagElement tag) - throws ChangedCharSetException - { - } - - /** - * Handle a complete element, when the tag content is already present in the - * buffer and both starting and heading tags behind. This is called - * in the case when the tag text must not be parsed for the nested - * elements (elements STYLE and SCRIPT). - */ - private void _handleCompleteElement(TagElement tag) - { - _handleStartTag(tag); - - // Suppress inclusion of the SCRIPT ans STYLE texts into the title. - HTML.Tag h = tag.getHTMLTag(); - if (h == HTML.Tag.SCRIPT || h == HTML.Tag.STYLE) - { - boolean tmp = titleOpen; - titleOpen = false; - _handleText(); - titleOpen = tmp; - } - else - _handleText(); - - _handleEndTag(tag); - } - - /** - * A hooks for operations, preceeding call to handleEmptyTag(). - * Handle the tag with no content, like <br>. As no any - * nested tags are expected, the tag validator is not involved. - * @param The tag being handled. - */ - private void _handleEmptyTag(TagElement tag) - { - try - { - validator.validateTag(tag, attributes); - handleEmptyTag(tag); - } - catch (ChangedCharSetException ex) - { - error("Changed charset exception:", ex.getMessage()); - } - } - - /** - * A hooks for operations, preceeding call to handleEndTag(). - * The method is called when the HTML closing tag - * is found. Calls handleTitle after closing the 'title' tag. - * @param The tag - */ - private void _handleEndTag(TagElement tag) - { - validator.closeTag(tag); - _handleEndTag_remaining(tag); - } - - /** - * Actions that are also required if the closing action was - * initiated by the tag validator. - * Package-private to avoid an accessor method. - */ - void _handleEndTag_remaining(TagElement tag) - { - HTML.Tag h = tag.getHTMLTag(); - - handleEndTag(tag); - endTag(tag.fictional()); - - if (h.isPreformatted()) - preformatted--; - if (preformatted < 0) - preformatted = 0; - - if (h == HTML.Tag.TITLE) - { - titleOpen = false; - titleHandled = true; - - char[] a = new char[ title.length() ]; - title.getChars(0, a.length, a, 0); - handleTitle(a); - } - } - - /** - * A hooks for operations, preceeding call to handleStartTag(). - * The method is called when the HTML opening tag ((like <table>) - * is found. - * Package-private to avoid an accessor method. - * @param The tag - */ - void _handleStartTag(TagElement tag) - { - validator.openTag(tag, attributes); - startingTag(tag); - handleStartTag(tag); - - HTML.Tag h = tag.getHTMLTag(); - - if (h.isPreformatted()) - preformatted++; - - if (h == HTML.Tag.TITLE) - { - if (titleHandled) - error("Repetetive <TITLE> tag"); - titleOpen = true; - titleHandled = false; - } - } - - /** - * Resume parsing after heavy errors in HTML tag structure. - * @throws ParseException - */ - private void forciblyCloseTheTag() - throws ParseException - { - int closeAt = 0; - buffer.setLength(0); - - ahead: - for (int i = 1; i < 100; i++) - { - t = getTokenAhead(i - 1); - if (t.kind == EOF || t.kind == BEGIN) - break ahead; - if (t.kind == END) - { - /* Closing '>' found. */ - closeAt = i; - break ahead; - } - } - if (closeAt > 0) - { - buffer.append("Ignoring '"); - for (int i = 1; i <= closeAt; i++) - { - t = getNextToken(); - append(t); - } - buffer.append('\''); - error(buffer.toString()); - } - } - - /** - * Handle comment in string buffer. You can avoid allocating a char - * array each time by processing your comment directly here. - */ - private void handleComment() - { - char[] a = new char[ buffer.length() ]; - buffer.getChars(0, a.length, a, 0); - handleComment(a); - } - - private TagElement makeTagElement(String name, boolean isSupposed) - { - Element e = (Element) dtd.elementHash.get(name.toLowerCase()); - if (e == null) - { - error("Unknown tag <" + name + ">"); - e = dtd.getElement(name); - e.name = name.toUpperCase(); - e.index = -1; - } - - if (!documentTags.contains(e.name)) - { - markFirstTime(e); - documentTags.add(e.name); - } - - return makeTag(e, isSupposed); - } - - /** - * Read till the given token, resolving entities. Consume the given - * token without adding it to buffer. - * @param till The token to read till - * @throws ParseException - */ - private void readTillTokenE(int till) - throws ParseException - { - buffer.setLength(0); - read: - while (true) - { - t = getNextToken(); - if (t.kind == Constants.ENTITY) - { - resolveAndAppendEntity(t); - } - else if (t.kind == EOF) - { - error("unexpected eof", t); - break read; - } - else if (t.kind == till) - break read; - else if (t.kind == WS) - { - // Processing whitespace in accordance with CDATA rules: - String s = t.getImage(); - char c; - for (int i = 0; i < s.length(); i++) - { - c = s.charAt(i); - if (c == '\r') - buffer.append(' '); // CR replaced by space - else if (c == '\n') - ; // LF ignored - else if (c == '\t') - buffer.append(' '); // Tab replaced by space - else - buffer.append(c); - } - } - else - append(t); - } - } - - /** - * Resolve the entity and append it to the end of buffer. - * @param entity - */ - private void resolveAndAppendEntity(Token entity) - { - switch (entity.category) - { - case ENTITY_NAMED : - buffer.append(resolveNamedEntity(entity.getImage())); - break; - - case ENTITY_NUMERIC : - buffer.append(resolveNumericEntity(entity.getImage())); - break; - - default : - throw new AssertionError("Invalid entity category " + - entity.category - ); - } - } - - /** - * Handle the remaining of HTML tags. This is a common end for - * TAG, SCRIPT and STYLE. - * @param closing True for closing tags ( </TAG> ). - * @param name Name of element - * @param start Token where element has started - * @throws ParseException - */ - private void restOfTag(boolean closing, Token name, Token start) - throws ParseException - { - boolean end = false; - Token next; - - optional(WS); - - readAttributes(name.getImage()); - - optional(WS); - - next = getTokenAhead(); - if (next.kind == END) - { - mustBe(END); - end = true; - } - - hTag = new Token(start, next); - - attributes.setResolveParent(defaulter.getDefaultParameters(name.getImage())); - - if (!end) - { - // The tag body contains errors. If additionally the tag - // name is not valid, this construction is treated as text. - if (dtd.elementHash.get(name.getImage().toLowerCase()) == null && - backupMode - ) - { - error("Errors in tag body and unknown tag name. " + - "Treating the tag as a text." - ); - reset(); - - hTag = mustBe(BEGIN); - buffer.setLength(0); - buffer.append(hTag.getImage()); - CDATA(false); - return; - } - else - { - error("Forcibly closing invalid parameter list"); - forciblyCloseTheTag(); - } - } - - if (closing) - { - endTag(false); - _handleEndTag(makeTagElement(name.getImage(), false)); - } - else - { - TagElement te = makeTagElement(name.getImage(), false); - if (te.getElement().type == DTDConstants.EMPTY) - _handleEmptyTag(te); - else - _handleStartTag(te); - } - } - - /** - * This should fire additional actions in response to the - * ChangedCharSetException. The current implementation - * does nothing. - * @param tag - */ - private void startingTag(TagElement tag) - { - try - { - startTag(tag); - } - catch (ChangedCharSetException cax) - { - error("Invalid change of charset"); - } - } - - private void ws_error() - { - error("Whitespace here is not permitted"); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/gnuStringIntMapper.java b/libjava/gnu/javax/swing/text/html/parser/support/gnuStringIntMapper.java deleted file mode 100755 index 9cdf810dd42..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/gnuStringIntMapper.java +++ /dev/null @@ -1,112 +0,0 @@ -/* gnuStringIntMapper.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support; - -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; - -/** - * A helper class, mapping between the strings and they unique integer - * identifiers. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public abstract class gnuStringIntMapper -{ - /** - * Maps argument integer values from DTDConstants into they string - * names. Initialized on demand. - */ - private Map is_Map; - - /** - * Maps argument string names into they integer values from DTDConstants. - * Initialized on demand. - */ - private Map si_Map; - - /** - * Get string from id or null if no such id is present in the mapper. - */ - public final String get(int id) - { - if (is_Map == null) - createTheMap(); - - return (String) is_Map.get(new Integer(id)); - } - - /** Get id from string or 0 if no such string is present in the mapper. */ - public final int get(String id) - { - if (si_Map == null) - createTheMap(); - - Integer i = (Integer) si_Map.get(id); - - return i != null ? i.intValue() : 0; - } - - /** - * Create the mapping table for this mapper by adding the required - * String/int pairs. The method is invoked - * only once for each instance, after the first invocation of the any - * form of the <code>get</code> method. Use <code>add</code> to - * create a map for a concrete instance. - */ - protected abstract void create(); - - /** - * Add an id/string pair to this mapper. This is called from - * the method <code>create</code> only. - */ - protected void add(String name, int id) - { - Integer i = new Integer(id); - si_Map.put(name, i); - is_Map.put(i, name); - } - - private void createTheMap() - { - is_Map = new HashMap(); - si_Map = new TreeMap(); - create(); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/Buffer.java b/libjava/gnu/javax/swing/text/html/parser/support/low/Buffer.java deleted file mode 100644 index a39330af846..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/Buffer.java +++ /dev/null @@ -1,238 +0,0 @@ -/* Buffer.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -/** - * A string buffer that additionally holds line and absolute postion - * information. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Buffer -{ - public static int INITIAL_SIZE = 2048; - - /** - * True if the \n symbol has been seen. - */ - public boolean n_seen; - - /** - * True if the \r symbol has been seen. - */ - public boolean r_seen; - char[] chr = new char[ INITIAL_SIZE ]; - int[] line = new int[ INITIAL_SIZE ]; - int[] position = new int[ INITIAL_SIZE ]; - - /** - * Current line. - */ - int current_line = 0; - - /** - * Point to the next free position. - */ - int length; - - public Buffer() - { - } - - public Buffer(String content) - { - for (int i = 0; i < content.length(); i++) - { - append(content.charAt(i), i); - } - } - - /** - * Get the characters into array. - * @param srcBegin From, inclusive - * @param srcEnd To, exclusive. - * @param dst Into - * @param dstBegin Offset. - */ - public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) - { - System.arraycopy(chr, srcBegin, dst, dstBegin, (srcEnd - srcBegin)); - } - - /** - * Return the sequence, used to separate lines in the document. - * @return one of \n, \r or \r\n. - */ - public String getEndOfLineSequence() - { - if (r_seen && n_seen) - return "\r\n"; - else if (r_seen) - return "\r"; - else - - // This also is returned for single-line document. - return "\n"; - } - - /** - * Truncate. - * @param n The length to truncate till. - */ - public void setLength(int n) - { - length = n; - } - - /** - * Get location information for the given region. - * @param from Region start, inclusive. - * @param to Region end, exclusive. - * @return The location, covering the region. - */ - public Location getLocation(int from, int to) - { - Location l = new Location(); - l.beginLine = line [ from ]; - l.endLine = line [ to - 1 ]; - - l.startPosition = position [ from ]; - l.endPosition = position [ to - 1 ] + 1; - - return l; - } - - /** - * Add the character. - * @param c The character. - * @param pos The character position in the stream (the line number - * is handled internally in the buffer). - */ - public void append(char c, int pos) - { - if (length >= chr.length) - expand(); - chr [ length ] = c; - position [ length ] = pos; - - if (c == '\n') - { - if (!r_seen) - current_line++; - n_seen = true; - } - else if (c == '\r') - { - current_line++; - r_seen = true; - } - - line [ length ] = current_line; - - length++; - } - - /** - * Return char at the given positon. - */ - public char charAt(int i) - { - return chr [ i ]; - } - - /** - * Delete the range - * @param from Start position, inclusive. - * @param to End position, exclusive. - */ - public void delete(int from, int to) - { - int len = to - from; - if (len < 1) - throw new AssertionError("Deleting " + from + " till " + to); - - int tail = length - to; - - System.arraycopy(chr, to, chr, from, tail); - System.arraycopy(position, to, position, from, tail); - System.arraycopy(line, to, line, from, tail); - length = length - len; - } - - /** - * Double the buffer size. - */ - public void expand() - { - int nSize = 2 * chr.length; - - char[] nchr = new char[ nSize ]; - int[] nposition = new int[ nSize ]; - int[] nline = new int[ nSize ]; - - System.arraycopy(chr, 0, nchr, 0, chr.length); - System.arraycopy(position, 0, nposition, 0, position.length); - System.arraycopy(line, 0, nline, 0, line.length); - - chr = nchr; - position = nposition; - line = nline; - } - - /** - * Return length of the occupied part of the buffer. - */ - public int length() - { - return length; - } - - /** - * Prepare for parsing the new document. - */ - public void reset() - { - setLength(0); - r_seen = n_seen = false; - } - - public String toString() - { - return new String(chr, 0, length); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/Constants.java b/libjava/gnu/javax/swing/text/html/parser/support/low/Constants.java deleted file mode 100755 index 283d32385ef..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/Constants.java +++ /dev/null @@ -1,422 +0,0 @@ -/* Constants.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -import java.util.BitSet; - -/** - * The parser constants and operations, directly related to the parser - * constants. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Constants -{ - /* Single character tokens are reflected into they ASCII codes. */ - - /** - * Start of HTML token. - */ - public static final int BEGIN = '<'; - - /** - * End of HTML token. - */ - public static final int END = '>'; - - /** - * Exclamation (indicates SGML or comment). - */ - public static final int EXCLAMATION = '!'; - - /** - * Slash (indicates closing tag). - */ - public static final int SLASH = '/'; - - /** - * Equals sign. - */ - public static final int EQ = '='; - - /** - * Quoting sign. - */ - public static final int AP = '\''; - - /** - * Quoting sign. - */ - public static final int QUOT = '"'; - - /* The numbers of other tokens start outside the ascii space. */ - /* String tokens */ - - /** - * Double dash (--) - */ - public static final int DOUBLE_DASH = 1000; - - /** - * The STYLE tag (needs special handling). - */ - public static final int STYLE = 1001; - - /** - * The SCRIPT tag (needs special handling). - */ - public static final int SCRIPT = 1002; - - /* Pattern tokens */ - - /** - * HTML whitespace. - */ - public static final int WS = 1003; - - /** - * Named or numeric entity, - */ - public static final int ENTITY = 1004; - - /** - * Sequence of valid name characters (can start from digit). - */ - public static final int NUMTOKEN = 1005; - - /* Complex tokens */ - - /** - * Comment opening sequence. - */ - public static final pattern COMMENT_OPEN = - new pattern(new node[] - { - new node(BEGIN), new node(WS, true), new node(EXCLAMATION), - new node(WS, true), new node(DOUBLE_DASH), - } - ); - - /** - * Comment closing sequence - */ - public static final pattern COMMENT_END = - new pattern(new node[] - { - new node(DOUBLE_DASH), new node(WS, true), new node(END) - } - ); - - /** - * Special case ---> (also is treated as end of comment). - */ - public static final pattern COMMENT_TRIPLEDASH_END = - new pattern(new node[] - { - new node(DOUBLE_DASH), new node(NUMTOKEN), new node(END) - } - ); - - /** - * STYLE element heading pattern. - */ - public static final pattern STYLE_OPEN = - new pattern(new node[] { new node(BEGIN), new node(WS, true), new node(STYLE) }); - - /** - * SCRIPT element heading pattern. - */ - public static final pattern SCRIPT_OPEN = - new pattern(new node[] { new node(BEGIN), new node(WS, true), new node(SCRIPT) }); - - /** - * SGML element heading pattern. - */ - public static final pattern SGML = - new pattern(new node[] - { - new node(BEGIN), new node(WS, true), new node(EXCLAMATION) - } - ); - - /** - * SCRIPT element closing pattern. - */ - public static final pattern SCRIPT_CLOSE = - new pattern(new node[] - { - new node(BEGIN), new node(WS, true), new node(SLASH), - new node(WS, true), new node(SCRIPT), new node(WS, true), - new node(END) - } - ); - - /** - * STYLE element closing pattern. - */ - public static final pattern STYLE_CLOSE = - new pattern(new node[] - { - new node(BEGIN), new node(WS, true), new node(SLASH), - new node(WS, true), new node(STYLE), new node(WS, true), - new node(END) - } - ); - - /** - * Ordinary HTML tag heading pattern. - */ - public static final pattern TAG = - new pattern(new node[] - { - new node(BEGIN), new node(WS, true), new node(SLASH, true), - new node(WS, true), new node(NUMTOKEN) - } - ); - - /* Special tokens */ - - /** - * All other tokens. - */ - public static final int OTHER = 1999; - - /** - * The UNICODE "end of text" control code - */ - static final char ETX = 3; - - /** - * End of file. - */ - public static final int EOF = ETX; - - /* Character categories */ - - /** - * All single char tokens. - */ - public static final BitSet bSINGLE_CHAR_TOKEN = new BitSet(); - - /** - * Non letters and non numbers, allowed in HTML names. - */ - public static final BitSet bSPECIAL = new BitSet(); - - /** - * All letters, used in HTML names. - */ - public static final BitSet bLETTER = new BitSet(); - - /** - * Digits. - */ - public static final BitSet bDIGIT = new BitSet(); - - /** - * Both line breaks. - */ - public static final BitSet bLINEBREAK = new BitSet(); - - /** - * All whitespace. - */ - public static final BitSet bWHITESPACE = new BitSet(); - - /** - * Both quoting characters. - */ - public static final BitSet bQUOTING = new BitSet(); - - /** - * Valid name characters. - */ - public static final BitSet bNAME = new BitSet(); - - /* Entity subcategories */ - - /** - * Named entity. - */ - public static final int ENTITY_NAMED = 1; - - /** - * Numeric entity. - */ - public static final int ENTITY_NUMERIC = 2; - - static - { - bQUOTING.set(AP); - bQUOTING.set(QUOT); - - bSINGLE_CHAR_TOKEN.set(BEGIN); - bSINGLE_CHAR_TOKEN.set(END); - bSINGLE_CHAR_TOKEN.set(EXCLAMATION); - bSINGLE_CHAR_TOKEN.set(SLASH); - bSINGLE_CHAR_TOKEN.set(EQ); - bSINGLE_CHAR_TOKEN.set(EOF); - - bSINGLE_CHAR_TOKEN.or(bQUOTING); - - bLINEBREAK.set('\r'); - bLINEBREAK.set('\n'); - - bWHITESPACE.set(' '); - bWHITESPACE.set('\t'); - bWHITESPACE.set(0xC); - bWHITESPACE.or(bLINEBREAK); - - for (char i = '0'; i <= '9'; i++) - { - bDIGIT.set(i); - } - - for (char i = 'a'; i <= 'z'; i++) - { - bLETTER.set(i); - } - - for (char i = 'A'; i <= 'Z'; i++) - { - bLETTER.set(i); - } - - bSPECIAL.set('-'); - bSPECIAL.set('_'); - bSPECIAL.set(':'); - bSPECIAL.set('.'); - - bNAME.or(bLETTER); - bNAME.or(bDIGIT); - bNAME.or(bSPECIAL); - } - - /** - * Verifies if one of the tokens matches the end of string - * buffer. The last character in the string buffer is the - * "future character", some tokens needs to verify it the - * token does not continue "towards the future". If the token - * matches, it matches till "pre-last" character in the buffer. - * @param b - * @return - */ - public Token endMatches(Buffer b) - { - if (b.length() < 2) - return null; - - int p = b.length() - 2; - - if (b.length() > 2 && b.charAt(p) == '-' && b.charAt(p - 1) == '-') - return new Token(DOUBLE_DASH, "--", b.getLocation(p - 1, p + 1)); - - char last = b.charAt(p); - - if (bSINGLE_CHAR_TOKEN.get(last)) - return new Token(last, last, b.getLocation(p, p + 1)); - - char future = b.charAt(p + 1); - - // Check for numtokens, script and style: - if (bNAME.get(last) && !bNAME.get(future)) - { - // Scan the history up: - int u = p - 1; - while (u >= 0 && bNAME.get(b.charAt(u))) - u--; - u++; - - char[] token = new char[ p - u + 1 ]; - - // Found a numtoken - b.getChars(u, p + 1, token, 0); - - // Verify for the built-in tokens: - String e = new String(token); - - // found the entity reference - if (u > 0 && b.charAt(u - 1) == '&') - { - // The subsequent semicolon may be the part of the token - // as well. The semicolon must be ignored. This must be - // handled elsewhere. - return new Token(ENTITY, ENTITY_NAMED, "&" + e, - b.getLocation(u - 1, p + 1) - ); - } - - // found the numeric entity reference - if (u > 1 && b.charAt(u - 1) == '#' && b.charAt(u - 2) == '&') - { - // The subsequent semicolon may be the part of the token - // as well. The semicolon must be ignored. This must be - // handled elsewhere. - return new Token(ENTITY, ENTITY_NUMERIC, "&#" + e, - b.getLocation(u - 2, p + 2) - ); - } - - Location le = b.getLocation(u, p + 1); - - if (e.equalsIgnoreCase("SCRIPT")) - return new Token(SCRIPT, e, le); - else if (e.equalsIgnoreCase("STYLE")) - return new Token(STYLE, e, le); - else - return new Token(NUMTOKEN, e, le); - } - - // Check for whitespace - if (bWHITESPACE.get(last) && !bWHITESPACE.get(future)) - { - // Scan the history up: - int u = p - 1; - while (u >= 0 && bWHITESPACE.get(b.charAt(u))) - u--; - u++; - - char[] token = new char[ p - u + 1 ]; - b.getChars(u, p + 1, token, 0); - - return new Token(WS, new String(token), b.getLocation(u, p + 1)); - } - - return null; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/Location.java b/libjava/gnu/javax/swing/text/html/parser/support/low/Location.java deleted file mode 100644 index 8a1cde1c86c..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/Location.java +++ /dev/null @@ -1,83 +0,0 @@ -/* Location.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -/** - * Defines a region in the text: its bounding positions and the line number. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Location -{ - /** - * The line number, where the token starts. - */ - public int beginLine; - - /** - * The line, where the token ends. - */ - public int endLine; - - /** - * The absolute token end position in the input stream, - * exclusive. - */ - public int endPosition; - - /** - * The absolute token start position in the input stream, - * inclusive. - */ - public int startPosition; - - public Location() - { - } - - /** - * Special case, used to mark EOF. - * @param p The total stream length. - */ - public Location(int p) - { - startPosition = p; - endPosition = p + 1; - beginLine = endLine = -1; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/ParseException.java b/libjava/gnu/javax/swing/text/html/parser/support/low/ParseException.java deleted file mode 100644 index e71c0c1f651..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/ParseException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* ParseException.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -/** - * This can be thrown from various parsing methods. - */ -public class ParseException - extends RuntimeException -{ - public ParseException(String s, Throwable cause) - { - super(s, cause); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/Queue.java b/libjava/gnu/javax/swing/text/html/parser/support/low/Queue.java deleted file mode 100755 index 31cf4bb4d59..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/Queue.java +++ /dev/null @@ -1,142 +0,0 @@ -/* Queue.java -- a token queue. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -import java.util.Arrays; - -/** - * A token queue. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Queue -{ - Token[] m = new Token[ 64 ]; - int a = 0; - int b = 0; - - /** - * True for the empty queue. - */ - public boolean isEmpty() - { - return size() == 0; - } - - /** - * Add this trace to the end of the queue. - */ - public void add(Token u) - { - if (a < m.length) - { - m [ a ] = u; - a++; - } - else // The end of array has been reached. - { - if (b > 0) // If some elements were deleted from the start of the queue, shift. - { - int d = b; - System.arraycopy(m, b, m, 0, a - b); - b = b - d; - a = a - d; - m [ a ] = u; - a++; - } - else // Enlarge the queue, doubling the size. - { - int n = m.length * 2; - Token[] nm = new Token[ 2 * n ]; - System.arraycopy(m, 0, nm, 0, m.length); - Arrays.fill(m, null); - - nm [ a ] = u; - m = nm; - a++; - } - } - } - - /** - * Clear the queue. - */ - public void clear() - { - a = b = 0; - Arrays.fill(m, null); - } - - /** - * Read the value ahead. 0 is the value that will be returned with - * the following next. This method does not remove values from the - * queue. To test if there is enough tokens in the queue, size() must - * be checked before calling this method. - */ - public Token get(int ahead) - { - int p = b + ahead; - if (p < a) - return m [ p ]; - else - throw new ArrayIndexOutOfBoundsException("Not enough tokens"); - } - - /** - * Read the oldest value from the queue and remove this value from - * the queue. - */ - public Token next() - { - if (a == b) - throw new ArrayIndexOutOfBoundsException("queue empty"); - - Token r = m [ b ]; - m [ b ] = null; - b++; - return r; - } - - /** - * Size of the queue. - */ - public int size() - { - return a - b; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/ReaderTokenizer.java b/libjava/gnu/javax/swing/text/html/parser/support/low/ReaderTokenizer.java deleted file mode 100755 index 0ffc6c8b754..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/ReaderTokenizer.java +++ /dev/null @@ -1,374 +0,0 @@ -/* ReaderTokenizer.java -- splits the input char sequence int tokens. - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -import java.io.IOException; -import java.io.Reader; - -/** - * Reader splits the input char sequence into tokens. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class ReaderTokenizer - extends Constants -{ - /** - * This is set to true each time the getNextToken is called. - * Used in preventing loops when all patterns refuse to accept - * the invalid input. - */ - protected boolean advanced; - - /** - * If true, the returned tokens are also placed in the backup - * queue. - */ - protected boolean backupMode; - - /** - * The buffer to read document into. - */ - Buffer buffer = new Buffer(); - - /** - * The queue for supporting mark(). - */ - Queue backup = new Queue(); - - /** - * The queue of found tokens. - */ - Queue queue = new Queue(); - - /** - * The reader to read the document from. - */ - Reader reader; - - /** - * Array of char tokens - */ - char[] charTokens; - - /** - * Array of string tokens. - */ - String[] stringTokens; - - /** - * The current reader position. - */ - int readerPosition = -1; - - /** - * Creates a new ReaderTokenizer. The reset(...) method must be - * subsequently called to set the reader. - */ - public ReaderTokenizer() - { - } - - /** - * Return the sequence, used to separate lines in the document. - * @return one of \n, \r or \r\n. - */ - public String getEndOfLineSequence() - { - return buffer.getEndOfLineSequence(); - } - - /** - * Get the next token. - * @return - */ - public Token getNextToken() - { - Token rt; - advanced = true; - try - { - if (queue.isEmpty()) - read(1); - - if (!queue.isEmpty()) - rt = queue.next(); - else - rt = new Token(EOF, new Location(readerPosition)); - } - catch (IOException ex) - { - throw new ParseException("IO Exception", ex); - } - if (backupMode) - backup.add(rt); - return rt; - } - - /** - * Get a token, lying the given number of tokens - * ahead. getToken(0) will return the same token, - * what would be returned by getNextToken(). - * getToken(..) does change the current position - * in the input stream. If the end of stream is - * reached, the EOF token is always returned. - */ - public Token getTokenAhead(int ahead) - { - try - { - read(ahead - queue.size() + 1); - return queue.size() >= ahead ? queue.get(ahead) : eofToken(); - } - catch (IOException ex) - { - throw new ParseException("IO Exception", ex); - } - } - - /** - * Get a token, bein immediatley ahead. - * If the end of stream is - * reached, the EOF token is always returned. - * The method is equivalent calling getTokenAhead(0). - */ - public Token getTokenAhead() - { - try - { - if (queue.isEmpty()) - read(1); - if (!queue.isEmpty()) - return queue.get(0); - else - return eofToken(); - } - catch (IOException ex) - { - throw new ParseException("IO Exception", ex); - } - } - - /** - * Invokes the error handler. - */ - public void error(String msg, Token at) - { - System.out.println(msg); - } - - /** - * Turns the backup mode on or off. - * It is possible to return where the mark(true) was last called - * by calling reset(). - * @param mode True if it is required to save tokens, making - * returning to the current point possible. - */ - public void mark(boolean mode) - { - backup.clear(); - backupMode = mode; - } - - /** - * Prepare for new parsing from the given stream. - * @param a_reader A reader to parse from. - */ - public void reset(Reader a_reader) - { - reader = a_reader; - readerPosition = -1; - buffer.reset(); - queue.clear(); - } - - /** - * Reset the internal cursor to the position where the mark() - * was last time called. Switches the backup mode off. - */ - public void reset() - { - if (!backupMode) - throw new AssertionError("Call mark(true) before using reset()!"); - backupMode = false; - - // That is now in the queue, will be appended to the end of backup. - while (!queue.isEmpty()) - backup.add(queue.next()); - - Queue t = queue; - queue = backup; - backup = t; - backup.clear(); - } - - /** - * Read the given number of the tokens. Add the needed number of EOF - * tokens if there are no more data in the stream. - * @param amount The number of additional tokens to read. - */ - void read(int numberOfTokens) - throws IOException - { - if (numberOfTokens <= 0) - return; - - reading: - for (int i = 0; i < numberOfTokens; i++) - readToken(); - } - - /** - * Read next token from the reader, add it to the queue - */ - void readToken() - throws IOException - { - Token t; - int ch; - - enlarging: - while (true) - { - t = tokenMatches(); - if (t != null) - break enlarging; - else - { - ch = reader.read(); - readerPosition++; - if (ch == ETX) - ch = ' '; - if (ch < 0) - { - if (buffer.length() == 0) - { - queue.add(eofToken()); - return; - } - else - { - if (buffer.charAt(buffer.length() - 1) != ETX) - buffer.append(ETX, readerPosition++); - else - { - // Discard terminating ETX - buffer.setLength(buffer.length() - 1); - if (buffer.length() > 0) - { - t = new Token(OTHER, buffer.toString(), - buffer.getLocation(0, buffer.length()) - ); - queue.add(t); - buffer.setLength(0); - } - return; - } - } - } - else - buffer.append((char) ch, readerPosition); - } - } - } - - /** - * Check if the end of buffer matches one of the tokens. If it does, - * return this token and remove the token sequence from the end of - * buffer. - * @return The matching token. - */ - Token tokenMatches() - { - Token rt = endMatches(buffer); - if (rt != null) // Remove the matched image - { - // Consume future character if it was an entity and the future - // character is semicolon. - if (rt.kind == ENTITY) - { - if (buffer.charAt(buffer.length() - 1) == ';') - buffer.setLength(buffer.length() - rt.getImage().length() - 1); - else - { - error("Missing closing semicolon for entity '" + rt.getImage() + - "'", rt - ); - consumeBuffer(rt); - } - } - else - { - consumeBuffer(rt); - } - } - - // If the buffer is not empty, some sequence does not match any tokens. - // Add it to the queue as "OTHER". - if (rt != null) - { - if (buffer.length() > 1) - { - String rest = buffer.toString(); - rest = rest.substring(0, rest.length() - 1); - - Token other = - new Token(OTHER, rest, buffer.getLocation(0, buffer.length)); - queue.add(other); - consumeBuffer(other); - } - queue.add(rt); - } - return rt; - } - - private void consumeBuffer(Token rt) - { - buffer.delete(buffer.length() - rt.getImage().length() - 1, - buffer.length() - 1 - ); - } - - /** - * Create EOF token. - */ - private Token eofToken() - { - return new Token(EOF, "#", new Location(readerPosition)); - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/Token.java b/libjava/gnu/javax/swing/text/html/parser/support/low/Token.java deleted file mode 100644 index d91adf47ab8..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/Token.java +++ /dev/null @@ -1,169 +0,0 @@ -/* Token.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -/** - * A token. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class Token -{ - /** - * The place of this token in the document. - */ - public Location where; - - /** - * The additional category of token. - */ - public int category; - - /** - * An integer that describes the kind of this token. - */ - public int kind; - - /** - * The string image of the token, null if the char image must be used. - */ - private String stringImage; - - /** - * The char image of the token. - */ - private char charImage; - - /** - * Creates a new token with fields, initialized to the default values. - */ - public Token() - { - } - - /** - * Creates a new token of the given kind. - */ - public Token(int _kind, Location _where) - { - kind = _kind; - where = _where; - } - - /** - * Creates a new token of the given kind and given single char image. - */ - public Token(int _kind, char _image, Location _where) - { - kind = _kind; - charImage = _image; - where = _where; - } - - /** - * Creates a new token of the given kind and given string image. - */ - public Token(int _kind, String _image, Location _where) - { - kind = _kind; - stringImage = _image; - where = _where; - } - - /** - * Creates a new token of the given kind, category and given string image. - */ - public Token(int _kind, int _category, String _image, Location _where) - { - kind = _kind; - category = _category; - stringImage = _image; - where = _where; - } - - /** - * Creates a new token, where location fields are set as for token, - * spanning over two provided tokens and any tokens between them. - * The image field is initialized to null, the kind field is set to -1. - */ - public Token(Token fromInclusive, Token toInclusive) - { - where = new Location(); - where.beginLine = fromInclusive.where.beginLine; - where.startPosition = fromInclusive.where.startPosition; - - where.endLine = toInclusive.where.endLine; - where.endPosition = toInclusive.where.endPosition; - } - - public String getImage() - { - if (kind == 3) - return "#"; - if (stringImage == null) - { - if (charImage == 0) - return null; - stringImage = new String(new char[] { charImage }); - } - return stringImage; - } - - /** - * Append the token image to the given string buffer. - * This may be more effective that buffer.append(this.getImage()). - * @param buffer A buffer to append. - */ - public void appendTo(StringBuffer buffer) - { - if (charImage == 0) - buffer.append(getImage()); - else - buffer.append(charImage); - } - - /** - * Returns the string image or, if null, the bounding positions. - */ - public String toString() - { - return getImage() != null ? kind + "'" + getImage() - : "<line " + where.beginLine + ", abs pos " + where.startPosition + - ".." + where.endPosition + ">"; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/node.java b/libjava/gnu/javax/swing/text/html/parser/support/low/node.java deleted file mode 100644 index b54ed86a381..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/node.java +++ /dev/null @@ -1,78 +0,0 @@ -/* node.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - -/** - * A text level content model node. The only required unary operations - * here are "appears" and "optionally appears" ('?'). - * <p>@author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)</p> - */ -public class node -{ - /** - * True for node that is optional for the given position. - */ - public boolean optional; - - /** - * The kind of the token to match. - */ - public int kind; - - /** - * Creates the new node for matching a given kind of the token. - * @param kind The kind of the token to match. - * @param modifier The modifier (*?+). - */ - public node(int kind, boolean _optional) - { - this.kind = kind; - optional = _optional; - } - - /** - * Creates the node, indicating that token must match exactluy one time. - * @param kind The kind of token to match. - */ - public node(int kind) - { - this.kind = kind; - optional = false; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/low/pattern.java b/libjava/gnu/javax/swing/text/html/parser/support/low/pattern.java deleted file mode 100755 index 0fe03fdbe87..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/low/pattern.java +++ /dev/null @@ -1,105 +0,0 @@ -/* pattern.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support.low; - - -/** - * The simple pattern, consisting from the sequence of tokens that - * may have the unary modifier '?'. Choices and grouping - * are not required here. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class pattern -{ - /** - * The nodes of this pattern. - */ - public final node[] nodes; - - /** - * Create a pattern, containing the given list of nodes. - * @param a_nodes - */ - public pattern(node[] a_nodes) - { - nodes = a_nodes; - } - - /** - * Checks if the pattern can match the tokens in this - * tokenizer. Does not change the state of tokenizer. - * @param stream The tokenizer to read data from - * @return True if the pattern sequence matches the - * beginning of the tokenizer content. - */ - public boolean matches(ReaderTokenizer stream) - { - try - { - int pt = 0; - int pn = 0; - Token t; - node n; - - while (pn < nodes.length) - { - n = nodes [ pn ]; - t = stream.getTokenAhead(pt); - - if (t.kind == n.kind) - { - pn++; - pt++; - } - else - { - if (!n.optional) - return false; - else - pn++; - } - } - return true; - } - catch (Exception ex) - { - throw new ParseException("Exception", ex); - } - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/parameterDefaulter.java b/libjava/gnu/javax/swing/text/html/parser/support/parameterDefaulter.java deleted file mode 100755 index 654acbbb58c..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/parameterDefaulter.java +++ /dev/null @@ -1,106 +0,0 @@ -/* parameterDefaulter.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support; - -import gnu.javax.swing.text.html.parser.htmlAttributeSet; - -import java.util.Hashtable; - -import javax.swing.text.html.parser.AttributeList; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.Element; - -/** - * Returns an attribute set, containing default - * parameters for the given element. Caches sets of default - * parameters. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class parameterDefaulter -{ - public final DTD dtd; - Hashtable sets = new Hashtable(); - - /** - * Create a parameterDefaulter that looks for the default attribute - * values in the given DTD. - * @param a_dtd - */ - public parameterDefaulter(DTD a_dtd) - { - dtd = a_dtd; - } - - /** - * Get the default parameter set for the given element. - * @param element The element name (case insensitive). - * @return the default attrbute set. - */ - public htmlAttributeSet getDefaultParameters(String element) - { - String key = element.toLowerCase(); - htmlAttributeSet atts = (htmlAttributeSet) sets.get(key); - - if (atts == null) - { - htmlAttributeSet set = new htmlAttributeSet(); - Element e = (Element) dtd.elementHash.get(element.toLowerCase()); - - if (e != null) - { - AttributeList a = e.getAttributes(); - - while (a != null) - { - if (a.value != null) - set.addAttribute(a.name, a.value); - a = a.next; - } - } - - if (set.getAttributeCount() > 0) - sets.put(key, set); - else - sets.put(key, htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET); - - atts = set; - } - return atts; - } -} diff --git a/libjava/gnu/javax/swing/text/html/parser/support/textPreProcessor.java b/libjava/gnu/javax/swing/text/html/parser/support/textPreProcessor.java deleted file mode 100755 index cc1610585a6..00000000000 --- a/libjava/gnu/javax/swing/text/html/parser/support/textPreProcessor.java +++ /dev/null @@ -1,193 +0,0 @@ -/* textPreProcessor.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.javax.swing.text.html.parser.support; - -import gnu.javax.swing.text.html.parser.support.low.Constants; - -/** - * Pre - processes text in text parts of the html document. - * Not thread - safe. - * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) - */ -public class textPreProcessor -{ - /** - * Pre - process non-preformatted text. - * \t, \r and \n mutate into spaces, then multiple spaces mutate - * into single one, all whitespace around tags is consumed. - * The content of the passed buffer is destroyed. - * @param text A text to pre-process. - */ - public char[] preprocess(StringBuffer a_text) - { - if (a_text.length() == 0) - return null; - - char[] text = toCharArray(a_text); - - int a = 0; - int b = text.length - 1; - - try - { - while (Constants.bWHITESPACE.get(text [ a ])) - a++; - while (Constants.bWHITESPACE.get(text [ b ])) - b--; - } - catch (ArrayIndexOutOfBoundsException sx) - { - // A text fragment, consisting from line breaks only. - return null; - } - - a_text.setLength(0); - - boolean spacesWere = false; - boolean spaceNow; - char c; - - chars: - for (int i = a; i <= b; i++) - { - c = text [ i ]; - spaceNow = Constants.bWHITESPACE.get(c); - if (spacesWere && spaceNow) - continue chars; - if (spaceNow) - a_text.append(' '); - else - a_text.append(c); - spacesWere = spaceNow; - } - - if (a_text.length() == text.length) - { - a_text.getChars(0, a_text.length(), text, 0); - return text; - } - else - return toCharArray(a_text); - } - - /** - * Pre - process pre-formatted text. - * Heading/closing spaces and tabs preserved. - * ONE bounding \r, \n or \r\n is removed. - * \r or \r\n mutate into \n. Tabs are - * preserved. - * The content of the passed buffer is destroyed. - * @param text - * @return - */ - public char[] preprocessPreformatted(StringBuffer a_text) - { - if (a_text.length() == 0) - return null; - - char[] text = toCharArray(a_text); - - int a = 0; - int n = text.length - 1; - int b = n; - - if (text [ 0 ] == '\n') - a++; - else - { - if (text [ 0 ] == '\r') - { - a++; - if (text.length > 1 && text [ 1 ] == '\n') - a++; - } - } - - if (text [ n ] == '\r') - b--; - else - { - if (text [ n ] == '\n') - { - b--; - if (n > 0 && text [ n - 1 ] == '\r') - b--; - } - } - - a_text.setLength(0); - - if (a > b) - return null; - - char c; - - for (int i = a; i <= b; i++) - { - c = text [ i ]; - if (c == '\r') - { - if (i == b || text [ i + 1 ] != '\n') - a_text.append('\n'); - } - else - a_text.append(c); - } - - if (a_text.length() == text.length) - { - a_text.getChars(0, a_text.length(), text, 0); - return text; - } - else - return toCharArray(a_text); - } - - /** - * Return array of chars, present in the given buffer. - * @param a_text The buffer - * @return - */ - private static char[] toCharArray(StringBuffer a_text) - { - char[] text = new char[ a_text.length() ]; - a_text.getChars(0, text.length, text, 0); - return text; - } -} diff --git a/libjava/gnu/regexp/CharIndexed.java b/libjava/gnu/regexp/CharIndexed.java deleted file mode 100644 index a0d7106aefa..00000000000 --- a/libjava/gnu/regexp/CharIndexed.java +++ /dev/null @@ -1,84 +0,0 @@ -/* gnu/regexp/CharIndexed.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -/** - * Defines the interface used internally so that different types of source - * text can be accessed in the same way. Built-in concrete classes provide - * support for String, StringBuffer, InputStream and char[] types. - * A class that is CharIndexed supports the notion of a cursor within a - * block of text. The cursor must be able to be advanced via the move() - * method. The charAt() method returns the character at the cursor position - * plus a given offset. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - */ -public interface CharIndexed { - /** - * Defines a constant (0xFFFF was somewhat arbitrarily chosen) - * that can be returned by the charAt() function indicating that - * the specified index is out of range. - */ - char OUT_OF_BOUNDS = '\uFFFF'; - - /** - * Returns the character at the given offset past the current cursor - * position in the input. The index of the current position is zero. - * It is possible for this method to be called with a negative index. - * This happens when using the '^' operator in multiline matching mode - * or the '\b' or '\<' word boundary operators. In any case, the lower - * bound is currently fixed at -2 (for '^' with a two-character newline). - * - * @param index the offset position in the character field to examine - * @return the character at the specified index, or the OUT_OF_BOUNDS - * character defined by this interface. - */ - char charAt(int index); - - /** - * Shifts the input buffer by a given number of positions. Returns - * true if the new cursor position is valid. - */ - boolean move(int index); - - /** - * Returns true if the most recent move() operation placed the cursor - * position at a valid position in the input. - */ - boolean isValid(); -} diff --git a/libjava/gnu/regexp/CharIndexedCharArray.java b/libjava/gnu/regexp/CharIndexedCharArray.java deleted file mode 100644 index 63d858c8709..00000000000 --- a/libjava/gnu/regexp/CharIndexedCharArray.java +++ /dev/null @@ -1,62 +0,0 @@ -/* gnu/regexp/CharIndexedCharArray.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.Serializable; - -class CharIndexedCharArray implements CharIndexed, Serializable { - private char[] s; - private int anchor; - - CharIndexedCharArray(char[] str, int index) { - s = str; - anchor = index; - } - - public char charAt(int index) { - int pos = anchor + index; - return ((pos < s.length) && (pos >= 0)) ? s[pos] : OUT_OF_BOUNDS; - } - - public boolean isValid() { - return (anchor < s.length); - } - - public boolean move(int index) { - return ((anchor += index) < s.length); - } -} diff --git a/libjava/gnu/regexp/CharIndexedInputStream.java b/libjava/gnu/regexp/CharIndexedInputStream.java deleted file mode 100644 index 145fe11b135..00000000000 --- a/libjava/gnu/regexp/CharIndexedInputStream.java +++ /dev/null @@ -1,149 +0,0 @@ -/* gnu/regexp/CharIndexedInputStream.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; - -// TODO: move(x) shouldn't rely on calling next() x times - -class CharIndexedInputStream implements CharIndexed { - private static final int BUFFER_INCREMENT = 1024; - private static final int UNKNOWN = Integer.MAX_VALUE; // value for end - - private BufferedInputStream br; - - // so that we don't try to reset() right away - private int index = -1; - - private int bufsize = BUFFER_INCREMENT; - - private int end = UNKNOWN; - - private char cached = OUT_OF_BOUNDS; - - // Big enough for a \r\n pair - // lookBehind[0] = most recent - // lookBehind[1] = second most recent - private char[] lookBehind = new char[] { OUT_OF_BOUNDS, OUT_OF_BOUNDS }; - - CharIndexedInputStream(InputStream str, int index) { - if (str instanceof BufferedInputStream) br = (BufferedInputStream) str; - else br = new BufferedInputStream(str,BUFFER_INCREMENT); - next(); - if (index > 0) move(index); - } - - private boolean next() { - if (end == 1) return false; - end--; // closer to end - - try { - if (index != -1) { - br.reset(); - } - int i = br.read(); - br.mark(bufsize); - if (i == -1) { - end = 1; - cached = OUT_OF_BOUNDS; - return false; - } - cached = (char) i; - index = 1; - } catch (IOException e) { - e.printStackTrace(); - cached = OUT_OF_BOUNDS; - return false; - } - return true; - } - - public char charAt(int index) { - if (index == 0) { - return cached; - } else if (index >= end) { - return OUT_OF_BOUNDS; - } else if (index == -1) { - return lookBehind[0]; - } else if (index == -2) { - return lookBehind[1]; - } else if (index < -2) { - return OUT_OF_BOUNDS; - } else if (index >= bufsize) { - // Allocate more space in the buffer. - try { - while (bufsize <= index) bufsize += BUFFER_INCREMENT; - br.reset(); - br.mark(bufsize); - br.skip(index-1); - } catch (IOException e) { } - } else if (this.index != index) { - try { - br.reset(); - br.skip(index-1); - } catch (IOException e) { } - } - char ch = OUT_OF_BOUNDS; - - try { - int i = br.read(); - this.index = index+1; // this.index is index of next pos relative to charAt(0) - if (i == -1) { - // set flag that next should fail next time? - end = index; - return ch; - } - ch = (char) i; - } catch (IOException ie) { } - - return ch; - } - - public boolean move(int index) { - // move read position [index] clicks from 'charAt(0)' - boolean retval = true; - while (retval && (index-- > 0)) retval = next(); - return retval; - } - - public boolean isValid() { - return (cached != OUT_OF_BOUNDS); - } -} - diff --git a/libjava/gnu/regexp/CharIndexedString.java b/libjava/gnu/regexp/CharIndexedString.java deleted file mode 100644 index 05be07ac68c..00000000000 --- a/libjava/gnu/regexp/CharIndexedString.java +++ /dev/null @@ -1,64 +0,0 @@ -/* gnu/regexp/CharIndexedString.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.Serializable; - -class CharIndexedString implements CharIndexed, Serializable { - private String s; - private int anchor; - private int len; - - CharIndexedString(String str, int index) { - s = str; - len = s.length(); - anchor = index; - } - - public char charAt(int index) { - int pos = anchor + index; - return ((pos < len) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS; - } - - public boolean isValid() { - return (anchor < len); - } - - public boolean move(int index) { - return ((anchor += index) < len); - } -} diff --git a/libjava/gnu/regexp/CharIndexedStringBuffer.java b/libjava/gnu/regexp/CharIndexedStringBuffer.java deleted file mode 100644 index 1b88e398571..00000000000 --- a/libjava/gnu/regexp/CharIndexedStringBuffer.java +++ /dev/null @@ -1,62 +0,0 @@ -/* gnu/regexp/CharIndexedStringBuffer.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.Serializable; - -class CharIndexedStringBuffer implements CharIndexed, Serializable { - private StringBuffer s; - private int anchor; - - CharIndexedStringBuffer(StringBuffer str, int index) { - s = str; - anchor = index; - } - - public char charAt(int index) { - int pos = anchor + index; - return ((pos < s.length()) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS; - } - - public boolean isValid() { - return (anchor < s.length()); - } - - public boolean move(int index) { - return ((anchor += index) < s.length()); - } -} diff --git a/libjava/gnu/regexp/RE.java b/libjava/gnu/regexp/RE.java deleted file mode 100644 index f5c990d5f83..00000000000 --- a/libjava/gnu/regexp/RE.java +++ /dev/null @@ -1,1394 +0,0 @@ -/* gnu/regexp/RE.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.InputStream; -import java.io.Serializable; -import java.util.Locale; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; -import java.util.Vector; - -/** - * RE provides the user interface for compiling and matching regular - * expressions. - * <P> - * A regular expression object (class RE) is compiled by constructing it - * from a String, StringBuffer or character array, with optional - * compilation flags (below) - * and an optional syntax specification (see RESyntax; if not specified, - * <code>RESyntax.RE_SYNTAX_PERL5</code> is used). - * <P> - * Once compiled, a regular expression object is reusable as well as - * threadsafe: multiple threads can use the RE instance simultaneously - * to match against different input text. - * <P> - * Various methods attempt to match input text against a compiled - * regular expression. These methods are: - * <LI><code>isMatch</code>: returns true if the input text in its - * entirety matches the regular expression pattern. - * <LI><code>getMatch</code>: returns the first match found in the - * input text, or null if no match is found. - * <LI><code>getAllMatches</code>: returns an array of all - * non-overlapping matches found in the input text. If no matches are - * found, the array is zero-length. - * <LI><code>substitute</code>: substitute the first occurence of the - * pattern in the input text with a replacement string (which may - * include metacharacters $0-$9, see REMatch.substituteInto). - * <LI><code>substituteAll</code>: same as above, but repeat for each - * match before returning. - * <LI><code>getMatchEnumeration</code>: returns an REMatchEnumeration - * object that allows iteration over the matches (see - * REMatchEnumeration for some reasons why you may want to do this - * instead of using <code>getAllMatches</code>. - * <P> - * - * These methods all have similar argument lists. The input can be a - * String, a character array, a StringBuffer, or an - * InputStream of some sort. Note that when using an - * InputStream, the stream read position cannot be guaranteed after - * attempting a match (this is not a bug, but a consequence of the way - * regular expressions work). Using an REMatchEnumeration can - * eliminate most positioning problems. - * - * <P> - * - * The optional index argument specifies the offset from the beginning - * of the text at which the search should start (see the descriptions - * of some of the execution flags for how this can affect positional - * pattern operators). For an InputStream, this means an - * offset from the current read position, so subsequent calls with the - * same index argument on an InputStream will not - * necessarily access the same position on the stream, whereas - * repeated searches at a given index in a fixed string will return - * consistent results. - * - * <P> - * You can optionally affect the execution environment by using a - * combination of execution flags (constants listed below). - * - * <P> - * All operations on a regular expression are performed in a - * thread-safe manner. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - * @version 1.1.5-dev, to be released - */ - -public class RE extends REToken { - - private static final class IntPair implements Serializable { - public int first, second; - } - - private static final class CharUnit implements Serializable { - public char ch; - public boolean bk; - } - - // This String will be returned by getVersion() - private static final String VERSION = "1.1.5-dev"; - - // The localized strings are kept in a separate file - private static ResourceBundle messages = PropertyResourceBundle.getBundle("gnu/regexp/MessagesBundle", Locale.getDefault()); - - // These are, respectively, the first and last tokens in our linked list - // If there is only one token, firstToken == lastToken - private REToken firstToken, lastToken; - - // This is the number of subexpressions in this regular expression, - // with a minimum value of zero. Returned by getNumSubs() - private int numSubs; - - /** Minimum length, in characters, of any possible match. */ - private int minimumLength; - - /** - * Compilation flag. Do not differentiate case. Subsequent - * searches using this RE will be case insensitive. - */ - public static final int REG_ICASE = 2; - - /** - * Compilation flag. The match-any-character operator (dot) - * will match a newline character. When set this overrides the syntax - * bit RE_DOT_NEWLINE (see RESyntax for details). This is equivalent to - * the "/s" operator in Perl. - */ - public static final int REG_DOT_NEWLINE = 4; - - /** - * Compilation flag. Use multiline mode. In this mode, the ^ and $ - * anchors will match based on newlines within the input. This is - * equivalent to the "/m" operator in Perl. - */ - public static final int REG_MULTILINE = 8; - - /** - * Execution flag. - * The match-beginning operator (^) will not match at the beginning - * of the input string. Useful for matching on a substring when you - * know the context of the input is such that position zero of the - * input to the match test is not actually position zero of the text. - * <P> - * This example demonstrates the results of various ways of matching on - * a substring. - * <P> - * <CODE> - * String s = "food bar fool";<BR> - * RE exp = new RE("^foo.");<BR> - * REMatch m0 = exp.getMatch(s);<BR> - * REMatch m1 = exp.getMatch(s.substring(8));<BR> - * REMatch m2 = exp.getMatch(s.substring(8),0,RE.REG_NOTBOL); <BR> - * REMatch m3 = exp.getMatch(s,8); <BR> - * REMatch m4 = exp.getMatch(s,8,RE.REG_ANCHORINDEX); <BR> - * <P> - * // Results:<BR> - * // m0.toString(): "food"<BR> - * // m1.toString(): "fool"<BR> - * // m2.toString(): null<BR> - * // m3.toString(): null<BR> - * // m4.toString(): "fool"<BR> - * </CODE> - */ - public static final int REG_NOTBOL = 16; - - /** - * Execution flag. - * The match-end operator ($) does not match at the end - * of the input string. Useful for matching on substrings. - */ - public static final int REG_NOTEOL = 32; - - /** - * Execution flag. - * When a match method is invoked that starts matching at a non-zero - * index into the input, treat the input as if it begins at the index - * given. The effect of this flag is that the engine does not "see" - * any text in the input before the given index. This is useful so - * that the match-beginning operator (^) matches not at position 0 - * in the input string, but at the position the search started at - * (based on the index input given to the getMatch function). See - * the example under REG_NOTBOL. It also affects the use of the \< - * and \b operators. - */ - public static final int REG_ANCHORINDEX = 64; - - /** - * Execution flag. - * The substitute and substituteAll methods will not attempt to - * interpolate occurrences of $1-$9 in the replacement text with - * the corresponding subexpressions. For example, you may want to - * replace all matches of "one dollar" with "$1". - */ - public static final int REG_NO_INTERPOLATE = 128; - - /** Returns a string representing the version of the gnu.regexp package. */ - public static final String version() { - return VERSION; - } - - // Retrieves a message from the ResourceBundle - static final String getLocalizedMessage(String key) { - return messages.getString(key); - } - - /** - * Constructs a regular expression pattern buffer without any compilation - * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5). - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer or char[]. Other input types will be converted to - * strings using the toString() method. - * @exception REException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public RE(Object pattern) throws REException { - this(pattern,0,RESyntax.RE_SYNTAX_PERL5,0,0); - } - - /** - * Constructs a regular expression pattern buffer using the specified - * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5). - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer, or char[]. Other input types will be converted to - * strings using the toString() method. - * @param cflags The logical OR of any combination of the compilation flags listed above. - * @exception REException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public RE(Object pattern, int cflags) throws REException { - this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5,0,0); - } - - /** - * Constructs a regular expression pattern buffer using the specified - * compilation flags and regular expression syntax. - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer, or char[]. Other input types will be converted to - * strings using the toString() method. - * @param cflags The logical OR of any combination of the compilation flags listed above. - * @param syntax The type of regular expression syntax to use. - * @exception REException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public RE(Object pattern, int cflags, RESyntax syntax) throws REException { - this(pattern,cflags,syntax,0,0); - } - - // internal constructor used for alternation - private RE(REToken first, REToken last,int subs, int subIndex, int minLength) { - super(subIndex); - firstToken = first; - lastToken = last; - numSubs = subs; - minimumLength = minLength; - addToken(new RETokenEndSub(subIndex)); - } - - private RE(Object patternObj, int cflags, RESyntax syntax, int myIndex, int nextSub) throws REException { - super(myIndex); // Subexpression index of this token. - initialize(patternObj, cflags, syntax, myIndex, nextSub); - } - - // For use by subclasses - protected RE() { super(0); } - - // The meat of construction - protected void initialize(Object patternObj, int cflags, RESyntax syntax, int myIndex, int nextSub) throws REException { - char[] pattern; - if (patternObj instanceof String) { - pattern = ((String) patternObj).toCharArray(); - } else if (patternObj instanceof char[]) { - pattern = (char[]) patternObj; - } else if (patternObj instanceof StringBuffer) { - pattern = new char [((StringBuffer) patternObj).length()]; - ((StringBuffer) patternObj).getChars(0,pattern.length,pattern,0); - } else { - pattern = patternObj.toString().toCharArray(); - } - - int pLength = pattern.length; - - numSubs = 0; // Number of subexpressions in this token. - Vector branches = null; - - // linked list of tokens (sort of -- some closed loops can exist) - firstToken = lastToken = null; - - // Precalculate these so we don't pay for the math every time we - // need to access them. - boolean insens = ((cflags & REG_ICASE) > 0); - - // Parse pattern into tokens. Does anyone know if it's more efficient - // to use char[] than a String.charAt()? I'm assuming so. - - // index tracks the position in the char array - int index = 0; - - // this will be the current parse character (pattern[index]) - CharUnit unit = new CharUnit(); - - // This is used for {x,y} calculations - IntPair minMax = new IntPair(); - - // Buffer a token so we can create a TokenRepeated, etc. - REToken currentToken = null; - char ch; - boolean quot = false; - - while (index < pLength) { - // read the next character unit (including backslash escapes) - index = getCharUnit(pattern,index,unit,quot); - - if (unit.bk) - if (unit.ch == 'Q') { - quot = true; - continue; - } else if (unit.ch == 'E') { - quot = false; - continue; - } - if (quot) - unit.bk = false; - - // ALTERNATION OPERATOR - // \| or | (if RE_NO_BK_VBAR) or newline (if RE_NEWLINE_ALT) - // not available if RE_LIMITED_OPS is set - - // TODO: the '\n' literal here should be a test against REToken.newline, - // which unfortunately may be more than a single character. - if ( ( (unit.ch == '|' && (syntax.get(RESyntax.RE_NO_BK_VBAR) ^ (unit.bk || quot))) - || (syntax.get(RESyntax.RE_NEWLINE_ALT) && (unit.ch == '\n') && !(unit.bk || quot)) ) - && !syntax.get(RESyntax.RE_LIMITED_OPS)) { - // make everything up to here be a branch. create vector if nec. - addToken(currentToken); - RE theBranch = new RE(firstToken, lastToken, numSubs, subIndex, minimumLength); - minimumLength = 0; - if (branches == null) { - branches = new Vector(); - } - branches.addElement(theBranch); - firstToken = lastToken = currentToken = null; - } - - // INTERVAL OPERATOR: - // {x} | {x,} | {x,y} (RE_INTERVALS && RE_NO_BK_BRACES) - // \{x\} | \{x,\} | \{x,y\} (RE_INTERVALS && !RE_NO_BK_BRACES) - // - // OPEN QUESTION: - // what is proper interpretation of '{' at start of string? - - else if ((unit.ch == '{') && syntax.get(RESyntax.RE_INTERVALS) && (syntax.get(RESyntax.RE_NO_BK_BRACES) ^ (unit.bk || quot))) { - int newIndex = getMinMax(pattern,index,minMax,syntax); - if (newIndex > index) { - if (minMax.first > minMax.second) - throw new REException(getLocalizedMessage("interval.order"),REException.REG_BADRPT,newIndex); - if (currentToken == null) - throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,newIndex); - if (currentToken instanceof RETokenRepeated) - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,newIndex); - if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) - throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,newIndex); - if ((currentToken.getMinimumLength() == 0) && (minMax.second == Integer.MAX_VALUE)) - throw new REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,newIndex); - index = newIndex; - currentToken = setRepeated(currentToken,minMax.first,minMax.second,index); - } - else { - addToken(currentToken); - currentToken = new RETokenChar(subIndex,unit.ch,insens); - } - } - - // LIST OPERATOR: - // [...] | [^...] - - else if ((unit.ch == '[') && !(unit.bk || quot)) { - Vector options = new Vector(); - boolean negative = false; - char lastChar = 0; - if (index == pLength) throw new REException(getLocalizedMessage("unmatched.bracket"),REException.REG_EBRACK,index); - - // Check for initial caret, negation - if ((ch = pattern[index]) == '^') { - negative = true; - if (++index == pLength) throw new REException(getLocalizedMessage("class.no.end"),REException.REG_EBRACK,index); - ch = pattern[index]; - } - - // Check for leading right bracket literal - if (ch == ']') { - lastChar = ch; - if (++index == pLength) throw new REException(getLocalizedMessage("class.no.end"),REException.REG_EBRACK,index); - } - - while ((ch = pattern[index++]) != ']') { - if ((ch == '-') && (lastChar != 0)) { - if (index == pLength) throw new REException(getLocalizedMessage("class.no.end"),REException.REG_EBRACK,index); - if ((ch = pattern[index]) == ']') { - options.addElement(new RETokenChar(subIndex,lastChar,insens)); - lastChar = '-'; - } else { - options.addElement(new RETokenRange(subIndex,lastChar,ch,insens)); - lastChar = 0; - index++; - } - } else if ((ch == '\\') && syntax.get(RESyntax.RE_BACKSLASH_ESCAPE_IN_LISTS)) { - if (index == pLength) throw new REException(getLocalizedMessage("class.no.end"),REException.REG_EBRACK,index); - int posixID = -1; - boolean negate = false; - char asciiEsc = 0; - if (("dswDSW".indexOf(pattern[index]) != -1) && syntax.get(RESyntax.RE_CHAR_CLASS_ESC_IN_LISTS)) { - switch (pattern[index]) { - case 'D': - negate = true; - case 'd': - posixID = RETokenPOSIX.DIGIT; - break; - case 'S': - negate = true; - case 's': - posixID = RETokenPOSIX.SPACE; - break; - case 'W': - negate = true; - case 'w': - posixID = RETokenPOSIX.ALNUM; - break; - } - } - else if ("nrt".indexOf(pattern[index]) != -1) { - switch (pattern[index]) { - case 'n': - asciiEsc = '\n'; - break; - case 't': - asciiEsc = '\t'; - break; - case 'r': - asciiEsc = '\r'; - break; - } - } - if (lastChar != 0) options.addElement(new RETokenChar(subIndex,lastChar,insens)); - - if (posixID != -1) { - options.addElement(new RETokenPOSIX(subIndex,posixID,insens,negate)); - } else if (asciiEsc != 0) { - lastChar = asciiEsc; - } else { - lastChar = pattern[index]; - } - ++index; - } else if ((ch == '[') && (syntax.get(RESyntax.RE_CHAR_CLASSES)) && (index < pLength) && (pattern[index] == ':')) { - StringBuffer posixSet = new StringBuffer(); - index = getPosixSet(pattern,index+1,posixSet); - int posixId = RETokenPOSIX.intValue(posixSet.toString()); - if (posixId != -1) - options.addElement(new RETokenPOSIX(subIndex,posixId,insens,false)); - } else { - if (lastChar != 0) options.addElement(new RETokenChar(subIndex,lastChar,insens)); - lastChar = ch; - } - if (index == pLength) throw new REException(getLocalizedMessage("class.no.end"),REException.REG_EBRACK,index); - } // while in list - // Out of list, index is one past ']' - - if (lastChar != 0) options.addElement(new RETokenChar(subIndex,lastChar,insens)); - - // Create a new RETokenOneOf - addToken(currentToken); - options.trimToSize(); - currentToken = new RETokenOneOf(subIndex,options,negative); - } - - // SUBEXPRESSIONS - // (...) | \(...\) depending on RE_NO_BK_PARENS - - else if ((unit.ch == '(') && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) { - boolean pure = false; - boolean comment = false; - boolean lookAhead = false; - boolean negativelh = false; - if ((index+1 < pLength) && (pattern[index] == '?')) { - switch (pattern[index+1]) { - case '!': - if (syntax.get(RESyntax.RE_LOOKAHEAD)) { - pure = true; - negativelh = true; - lookAhead = true; - index += 2; - } - break; - case '=': - if (syntax.get(RESyntax.RE_LOOKAHEAD)) { - pure = true; - lookAhead = true; - index += 2; - } - break; - case ':': - if (syntax.get(RESyntax.RE_PURE_GROUPING)) { - pure = true; - index += 2; - } - break; - case '#': - if (syntax.get(RESyntax.RE_COMMENTS)) { - comment = true; - } - break; - default: - throw new REException(getLocalizedMessage("repeat.no.token"), REException.REG_BADRPT, index); - } - } - - if (index >= pLength) { - throw new REException(getLocalizedMessage("unmatched.paren"), REException.REG_ESUBREG,index); - } - - // find end of subexpression - int endIndex = index; - int nextIndex = index; - int nested = 0; - - while ( ((nextIndex = getCharUnit(pattern,endIndex,unit,false)) > 0) - && !(nested == 0 && (unit.ch == ')') && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) ) - if ((endIndex = nextIndex) >= pLength) - throw new REException(getLocalizedMessage("subexpr.no.end"),REException.REG_ESUBREG,nextIndex); - else if (unit.ch == '(' && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) - nested++; - else if (unit.ch == ')' && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot))) - nested--; - - // endIndex is now position at a ')','\)' - // nextIndex is end of string or position after ')' or '\)' - - if (comment) index = nextIndex; - else { // not a comment - // create RE subexpression as token. - addToken(currentToken); - if (!pure) { - numSubs++; - } - - int useIndex = (pure || lookAhead) ? 0 : nextSub + numSubs; - currentToken = new RE(String.valueOf(pattern,index,endIndex-index).toCharArray(),cflags,syntax,useIndex,nextSub + numSubs); - numSubs += ((RE) currentToken).getNumSubs(); - - if (lookAhead) { - currentToken = new RETokenLookAhead(currentToken,negativelh); - } - - index = nextIndex; - } // not a comment - } // subexpression - - // UNMATCHED RIGHT PAREN - // ) or \) throw exception if - // !syntax.get(RESyntax.RE_UNMATCHED_RIGHT_PAREN_ORD) - else if (!syntax.get(RESyntax.RE_UNMATCHED_RIGHT_PAREN_ORD) && ((unit.ch == ')') && (syntax.get(RESyntax.RE_NO_BK_PARENS) ^ (unit.bk || quot)))) { - throw new REException(getLocalizedMessage("unmatched.paren"),REException.REG_EPAREN,index); - } - - // START OF LINE OPERATOR - // ^ - - else if ((unit.ch == '^') && !(unit.bk || quot)) { - addToken(currentToken); - currentToken = null; - addToken(new RETokenStart(subIndex,((cflags & REG_MULTILINE) > 0) ? syntax.getLineSeparator() : null)); - } - - // END OF LINE OPERATOR - // $ - - else if ((unit.ch == '$') && !(unit.bk || quot)) { - addToken(currentToken); - currentToken = null; - addToken(new RETokenEnd(subIndex,((cflags & REG_MULTILINE) > 0) ? syntax.getLineSeparator() : null)); - } - - // MATCH-ANY-CHARACTER OPERATOR (except possibly newline and null) - // . - - else if ((unit.ch == '.') && !(unit.bk || quot)) { - addToken(currentToken); - currentToken = new RETokenAny(subIndex,syntax.get(RESyntax.RE_DOT_NEWLINE) || ((cflags & REG_DOT_NEWLINE) > 0),syntax.get(RESyntax.RE_DOT_NOT_NULL)); - } - - // ZERO-OR-MORE REPEAT OPERATOR - // * - - else if ((unit.ch == '*') && !(unit.bk || quot)) { - if (currentToken == null) - throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index); - if (currentToken instanceof RETokenRepeated) - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); - if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) - throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); - if (currentToken.getMinimumLength() == 0) - throw new REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index); - currentToken = setRepeated(currentToken,0,Integer.MAX_VALUE,index); - } - - // ONE-OR-MORE REPEAT OPERATOR / POSSESSIVE MATCHING OPERATOR - // + | \+ depending on RE_BK_PLUS_QM - // not available if RE_LIMITED_OPS is set - - else if ((unit.ch == '+') && !syntax.get(RESyntax.RE_LIMITED_OPS) && (!syntax.get(RESyntax.RE_BK_PLUS_QM) ^ (unit.bk || quot))) { - if (currentToken == null) - throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index); - - // Check for possessive matching on RETokenRepeated - if (currentToken instanceof RETokenRepeated) { - RETokenRepeated tokenRep = (RETokenRepeated)currentToken; - if (syntax.get(RESyntax.RE_POSSESSIVE_OPS) && !tokenRep.isPossessive() && !tokenRep.isStingy()) - tokenRep.makePossessive(); - else - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); - - } - else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) - throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); - else if (currentToken.getMinimumLength() == 0) - throw new REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index); - else - currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index); - } - - // ZERO-OR-ONE REPEAT OPERATOR / STINGY MATCHING OPERATOR - // ? | \? depending on RE_BK_PLUS_QM - // not available if RE_LIMITED_OPS is set - // stingy matching if RE_STINGY_OPS is set and it follows a quantifier - - else if ((unit.ch == '?') && !syntax.get(RESyntax.RE_LIMITED_OPS) && (!syntax.get(RESyntax.RE_BK_PLUS_QM) ^ (unit.bk || quot))) { - if (currentToken == null) throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index); - - // Check for stingy matching on RETokenRepeated - if (currentToken instanceof RETokenRepeated) { - RETokenRepeated tokenRep = (RETokenRepeated)currentToken; - if (syntax.get(RESyntax.RE_STINGY_OPS) && !tokenRep.isStingy() && !tokenRep.isPossessive()) - tokenRep.makeStingy(); - else - throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index); - } - else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary) - throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index); - else - currentToken = setRepeated(currentToken,0,1,index); - } - - // BACKREFERENCE OPERATOR - // \1 \2 ... \9 - // not available if RE_NO_BK_REFS is set - - else if (unit.bk && Character.isDigit(unit.ch) && !syntax.get(RESyntax.RE_NO_BK_REFS)) { - addToken(currentToken); - currentToken = new RETokenBackRef(subIndex,Character.digit(unit.ch,10),insens); - } - - // START OF STRING OPERATOR - // \A if RE_STRING_ANCHORS is set - - else if (unit.bk && (unit.ch == 'A') && syntax.get(RESyntax.RE_STRING_ANCHORS)) { - addToken(currentToken); - currentToken = new RETokenStart(subIndex,null); - } - - // WORD BREAK OPERATOR - // \b if ???? - - else if (unit.bk && (unit.ch == 'b') && syntax.get(RESyntax.RE_STRING_ANCHORS)) { - addToken(currentToken); - currentToken = new RETokenWordBoundary(subIndex, RETokenWordBoundary.BEGIN | RETokenWordBoundary.END, false); - } - - // WORD BEGIN OPERATOR - // \< if ???? - else if (unit.bk && (unit.ch == '<')) { - addToken(currentToken); - currentToken = new RETokenWordBoundary(subIndex, RETokenWordBoundary.BEGIN, false); - } - - // WORD END OPERATOR - // \> if ???? - else if (unit.bk && (unit.ch == '>')) { - addToken(currentToken); - currentToken = new RETokenWordBoundary(subIndex, RETokenWordBoundary.END, false); - } - - // NON-WORD BREAK OPERATOR - // \B if ???? - - else if (unit.bk && (unit.ch == 'B') && syntax.get(RESyntax.RE_STRING_ANCHORS)) { - addToken(currentToken); - currentToken = new RETokenWordBoundary(subIndex, RETokenWordBoundary.BEGIN | RETokenWordBoundary.END, true); - } - - - // DIGIT OPERATOR - // \d if RE_CHAR_CLASS_ESCAPES is set - - else if (unit.bk && (unit.ch == 'd') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.DIGIT,insens,false); - } - - // NON-DIGIT OPERATOR - // \D - - else if (unit.bk && (unit.ch == 'D') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.DIGIT,insens,true); - } - - // NEWLINE ESCAPE - // \n - - else if (unit.bk && (unit.ch == 'n')) { - addToken(currentToken); - currentToken = new RETokenChar(subIndex,'\n',false); - } - - // RETURN ESCAPE - // \r - - else if (unit.bk && (unit.ch == 'r')) { - addToken(currentToken); - currentToken = new RETokenChar(subIndex,'\r',false); - } - - // WHITESPACE OPERATOR - // \s if RE_CHAR_CLASS_ESCAPES is set - - else if (unit.bk && (unit.ch == 's') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.SPACE,insens,false); - } - - // NON-WHITESPACE OPERATOR - // \S - - else if (unit.bk && (unit.ch == 'S') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.SPACE,insens,true); - } - - // TAB ESCAPE - // \t - - else if (unit.bk && (unit.ch == 't')) { - addToken(currentToken); - currentToken = new RETokenChar(subIndex,'\t',false); - } - - // ALPHANUMERIC OPERATOR - // \w - - else if (unit.bk && (unit.ch == 'w') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.ALNUM,insens,false); - } - - // NON-ALPHANUMERIC OPERATOR - // \W - - else if (unit.bk && (unit.ch == 'W') && syntax.get(RESyntax.RE_CHAR_CLASS_ESCAPES)) { - addToken(currentToken); - currentToken = new RETokenPOSIX(subIndex,RETokenPOSIX.ALNUM,insens,true); - } - - // END OF STRING OPERATOR - // \Z - - else if (unit.bk && (unit.ch == 'Z') && syntax.get(RESyntax.RE_STRING_ANCHORS)) { - addToken(currentToken); - currentToken = new RETokenEnd(subIndex,null); - } - - // NON-SPECIAL CHARACTER (or escape to make literal) - // c | \* for example - - else { // not a special character - addToken(currentToken); - currentToken = new RETokenChar(subIndex,unit.ch,insens); - } - } // end while - - // Add final buffered token and an EndSub marker - addToken(currentToken); - - if (branches != null) { - branches.addElement(new RE(firstToken,lastToken,numSubs,subIndex,minimumLength)); - branches.trimToSize(); // compact the Vector - minimumLength = 0; - firstToken = lastToken = null; - addToken(new RETokenOneOf(subIndex,branches,false)); - } - else addToken(new RETokenEndSub(subIndex)); - - } - - private static int getCharUnit(char[] input, int index, CharUnit unit, boolean quot) throws REException { - unit.ch = input[index++]; - if (unit.bk = (unit.ch == '\\' && (!quot || index >= input.length || input[index] == 'E'))) - if (index < input.length) - unit.ch = input[index++]; - else throw new REException(getLocalizedMessage("ends.with.backslash"),REException.REG_ESCAPE,index); - return index; - } - - /** - * Checks if the regular expression matches the input in its entirety. - * - * @param input The input text. - */ - public boolean isMatch(Object input) { - return isMatch(input,0,0); - } - - /** - * Checks if the input string, starting from index, is an exact match of - * this regular expression. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - */ - public boolean isMatch(Object input,int index) { - return isMatch(input,index,0); - } - - - /** - * Checks if the input, starting from index and using the specified - * execution flags, is an exact match of this regular expression. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - */ - public boolean isMatch(Object input,int index,int eflags) { - return isMatchImpl(makeCharIndexed(input,index),index,eflags); - } - - private boolean isMatchImpl(CharIndexed input, int index, int eflags) { - if (firstToken == null) // Trivial case - return (input.charAt(0) == CharIndexed.OUT_OF_BOUNDS); - REMatch m = new REMatch(numSubs, index, eflags); - if (firstToken.match(input, m)) { - while (m != null) { - if (input.charAt(m.index) == CharIndexed.OUT_OF_BOUNDS) { - return true; - } - m = m.next; - } - } - return false; - } - - /** - * Returns the maximum number of subexpressions in this regular expression. - * If the expression contains branches, the value returned will be the - * maximum subexpressions in any of the branches. - */ - public int getNumSubs() { - return numSubs; - } - - // Overrides REToken.setUncle - void setUncle(REToken uncle) { - if (lastToken != null) { - lastToken.setUncle(uncle); - } else super.setUncle(uncle); // to deal with empty subexpressions - } - - // Overrides REToken.chain - - boolean chain(REToken next) { - super.chain(next); - setUncle(next); - return true; - } - - /** - * Returns the minimum number of characters that could possibly - * constitute a match of this regular expression. - */ - public int getMinimumLength() { - return minimumLength; - } - - /** - * Returns an array of all matches found in the input. - * - * If the regular expression allows the empty string to match, it will - * substitute matches at all positions except the end of the input. - * - * @param input The input text. - * @return a non-null (but possibly zero-length) array of matches - */ - public REMatch[] getAllMatches(Object input) { - return getAllMatches(input,0,0); - } - - /** - * Returns an array of all matches found in the input, - * beginning at the specified index position. - * - * If the regular expression allows the empty string to match, it will - * substitute matches at all positions except the end of the input. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @return a non-null (but possibly zero-length) array of matches - */ - public REMatch[] getAllMatches(Object input, int index) { - return getAllMatches(input,index,0); - } - - /** - * Returns an array of all matches found in the input string, - * beginning at the specified index position and using the specified - * execution flags. - * - * If the regular expression allows the empty string to match, it will - * substitute matches at all positions except the end of the input. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @return a non-null (but possibly zero-length) array of matches - */ - public REMatch[] getAllMatches(Object input, int index, int eflags) { - return getAllMatchesImpl(makeCharIndexed(input,index),index,eflags); - } - - // this has been changed since 1.03 to be non-overlapping matches - private REMatch[] getAllMatchesImpl(CharIndexed input, int index, int eflags) { - Vector all = new Vector(); - REMatch m = null; - while ((m = getMatchImpl(input,index,eflags,null)) != null) { - all.addElement(m); - index = m.getEndIndex(); - if (m.end[0] == 0) { // handle pathological case of zero-length match - index++; - input.move(1); - } else { - input.move(m.end[0]); - } - if (!input.isValid()) break; - } - REMatch[] mset = new REMatch[all.size()]; - all.copyInto(mset); - return mset; - } - - /* Implements abstract method REToken.match() */ - boolean match(CharIndexed input, REMatch mymatch) { - if (firstToken == null) return next(input, mymatch); - - // Note the start of this subexpression - mymatch.start[subIndex] = mymatch.index; - - return firstToken.match(input, mymatch); - } - - /** - * Returns the first match found in the input. If no match is found, - * null is returned. - * - * @param input The input text. - * @return An REMatch instance referencing the match, or null if none. - */ - public REMatch getMatch(Object input) { - return getMatch(input,0,0); - } - - /** - * Returns the first match found in the input, beginning - * the search at the specified index. If no match is found, - * returns null. - * - * @param input The input text. - * @param index The offset within the text to begin looking for a match. - * @return An REMatch instance referencing the match, or null if none. - */ - public REMatch getMatch(Object input, int index) { - return getMatch(input,index,0); - } - - /** - * Returns the first match found in the input, beginning - * the search at the specified index, and using the specified - * execution flags. If no match is found, returns null. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @return An REMatch instance referencing the match, or null if none. - */ - public REMatch getMatch(Object input, int index, int eflags) { - return getMatch(input,index,eflags,null); - } - - /** - * Returns the first match found in the input, beginning the search - * at the specified index, and using the specified execution flags. - * If no match is found, returns null. If a StringBuffer is - * provided and is non-null, the contents of the input text from the - * index to the beginning of the match (or to the end of the input, - * if there is no match) are appended to the StringBuffer. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @param buffer The StringBuffer to save pre-match text in. - * @return An REMatch instance referencing the match, or null if none. */ - public REMatch getMatch(Object input, int index, int eflags, StringBuffer buffer) { - return getMatchImpl(makeCharIndexed(input,index),index,eflags,buffer); - } - - REMatch getMatchImpl(CharIndexed input, int anchor, int eflags, StringBuffer buffer) { - // Create a new REMatch to hold results - REMatch mymatch = new REMatch(numSubs, anchor, eflags); - do { - // Optimization: check if anchor + minimumLength > length - if (minimumLength == 0 || input.charAt(minimumLength-1) != CharIndexed.OUT_OF_BOUNDS) { - if (match(input, mymatch)) { - // Find longest match of them all to observe leftmost longest - REMatch longest = mymatch; - while ((mymatch = mymatch.next) != null) { - if (mymatch.index > longest.index) { - longest = mymatch; - } - } - - longest.end[0] = longest.index; - longest.finish(input); - return longest; - } - } - mymatch.clear(++anchor); - // Append character to buffer if needed - if (buffer != null && input.charAt(0) != CharIndexed.OUT_OF_BOUNDS) { - buffer.append(input.charAt(0)); - } - } while (input.move(1)); - - // Special handling at end of input for e.g. "$" - if (minimumLength == 0) { - if (match(input, mymatch)) { - mymatch.finish(input); - return mymatch; - } - } - - return null; - } - - /** - * Returns an REMatchEnumeration that can be used to iterate over the - * matches found in the input text. - * - * @param input The input text. - * @return A non-null REMatchEnumeration instance. - */ - public REMatchEnumeration getMatchEnumeration(Object input) { - return getMatchEnumeration(input,0,0); - } - - - /** - * Returns an REMatchEnumeration that can be used to iterate over the - * matches found in the input text. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @return A non-null REMatchEnumeration instance, with its input cursor - * set to the index position specified. - */ - public REMatchEnumeration getMatchEnumeration(Object input, int index) { - return getMatchEnumeration(input,index,0); - } - - /** - * Returns an REMatchEnumeration that can be used to iterate over the - * matches found in the input text. - * - * @param input The input text. - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @return A non-null REMatchEnumeration instance, with its input cursor - * set to the index position specified. - */ - public REMatchEnumeration getMatchEnumeration(Object input, int index, int eflags) { - return new REMatchEnumeration(this,makeCharIndexed(input,index),index,eflags); - } - - - /** - * Substitutes the replacement text for the first match found in the input. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @return A String interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substitute(Object input,String replace) { - return substitute(input,replace,0,0); - } - - /** - * Substitutes the replacement text for the first match found in the input - * beginning at the specified index position. Specifying an index - * effectively causes the regular expression engine to throw away the - * specified number of characters. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @param index The offset index at which the search should be begin. - * @return A String containing the substring of the input, starting - * at the index position, and interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substitute(Object input,String replace,int index) { - return substitute(input,replace,index,0); - } - - /** - * Substitutes the replacement text for the first match found in the input - * string, beginning at the specified index position and using the - * specified execution flags. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @return A String containing the substring of the input, starting - * at the index position, and interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substitute(Object input,String replace,int index,int eflags) { - return substituteImpl(makeCharIndexed(input,index),replace,index,eflags); - } - - private String substituteImpl(CharIndexed input,String replace,int index,int eflags) { - StringBuffer buffer = new StringBuffer(); - REMatch m = getMatchImpl(input,index,eflags,buffer); - if (m==null) return buffer.toString(); - buffer.append( ((eflags & REG_NO_INTERPOLATE) > 0) ? - replace : m.substituteInto(replace) ); - if (input.move(m.end[0])) { - do { - buffer.append(input.charAt(0)); - } while (input.move(1)); - } - return buffer.toString(); - } - - /** - * Substitutes the replacement text for each non-overlapping match found - * in the input text. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @return A String interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substituteAll(Object input,String replace) { - return substituteAll(input,replace,0,0); - } - - /** - * Substitutes the replacement text for each non-overlapping match found - * in the input text, starting at the specified index. - * - * If the regular expression allows the empty string to match, it will - * substitute matches at all positions except the end of the input. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @param index The offset index at which the search should be begin. - * @return A String containing the substring of the input, starting - * at the index position, and interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substituteAll(Object input,String replace,int index) { - return substituteAll(input,replace,index,0); - } - - /** - * Substitutes the replacement text for each non-overlapping match found - * in the input text, starting at the specified index and using the - * specified execution flags. - * - * @param input The input text. - * @param replace The replacement text, which may contain $x metacharacters (see REMatch.substituteInto). - * @param index The offset index at which the search should be begin. - * @param eflags The logical OR of any execution flags above. - * @return A String containing the substring of the input, starting - * at the index position, and interpolating the substituted text. - * @see REMatch#substituteInto - */ - public String substituteAll(Object input,String replace,int index,int eflags) { - return substituteAllImpl(makeCharIndexed(input,index),replace,index,eflags); - } - - private String substituteAllImpl(CharIndexed input,String replace,int index,int eflags) { - StringBuffer buffer = new StringBuffer(); - REMatch m; - while ((m = getMatchImpl(input,index,eflags,buffer)) != null) { - buffer.append( ((eflags & REG_NO_INTERPOLATE) > 0) ? - replace : m.substituteInto(replace) ); - index = m.getEndIndex(); - if (m.end[0] == 0) { - char ch = input.charAt(0); - if (ch != CharIndexed.OUT_OF_BOUNDS) - buffer.append(ch); - input.move(1); - } else { - input.move(m.end[0]); - } - - if (!input.isValid()) break; - } - return buffer.toString(); - } - - /* Helper function for constructor */ - private void addToken(REToken next) { - if (next == null) return; - minimumLength += next.getMinimumLength(); - if (firstToken == null) { - lastToken = firstToken = next; - } else { - // if chain returns false, it "rejected" the token due to - // an optimization, and next was combined with lastToken - if (lastToken.chain(next)) { - lastToken = next; - } - } - } - - private static REToken setRepeated(REToken current, int min, int max, int index) throws REException { - if (current == null) throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index); - return new RETokenRepeated(current.subIndex,current,min,max); - } - - private static int getPosixSet(char[] pattern,int index,StringBuffer buf) { - // Precondition: pattern[index-1] == ':' - // we will return pos of closing ']'. - int i; - for (i=index; i<(pattern.length-1); i++) { - if ((pattern[i] == ':') && (pattern[i+1] == ']')) - return i+2; - buf.append(pattern[i]); - } - return index; // didn't match up - } - - private int getMinMax(char[] input,int index,IntPair minMax,RESyntax syntax) throws REException { - // Precondition: input[index-1] == '{', minMax != null - - boolean mustMatch = !syntax.get(RESyntax.RE_NO_BK_BRACES); - int startIndex = index; - if (index == input.length) { - if (mustMatch) - throw new REException(getLocalizedMessage("unmatched.brace"),REException.REG_EBRACE,index); - else - return startIndex; - } - - int min,max=0; - CharUnit unit = new CharUnit(); - StringBuffer buf = new StringBuffer(); - - // Read string of digits - do { - index = getCharUnit(input,index,unit,false); - if (Character.isDigit(unit.ch)) - buf.append(unit.ch); - } while ((index != input.length) && Character.isDigit(unit.ch)); - - // Check for {} tomfoolery - if (buf.length() == 0) { - if (mustMatch) - throw new REException(getLocalizedMessage("interval.error"),REException.REG_EBRACE,index); - else - return startIndex; - } - - min = Integer.parseInt(buf.toString()); - - if ((unit.ch == '}') && (syntax.get(RESyntax.RE_NO_BK_BRACES) ^ unit.bk)) - max = min; - else if (index == input.length) - if (mustMatch) - throw new REException(getLocalizedMessage("interval.no.end"),REException.REG_EBRACE,index); - else - return startIndex; - else if ((unit.ch == ',') && !unit.bk) { - buf = new StringBuffer(); - // Read string of digits - while (((index = getCharUnit(input,index,unit,false)) != input.length) && Character.isDigit(unit.ch)) - buf.append(unit.ch); - - if (!((unit.ch == '}') && (syntax.get(RESyntax.RE_NO_BK_BRACES) ^ unit.bk))) - if (mustMatch) - throw new REException(getLocalizedMessage("interval.error"),REException.REG_EBRACE,index); - else - return startIndex; - - // This is the case of {x,} - if (buf.length() == 0) max = Integer.MAX_VALUE; - else max = Integer.parseInt(buf.toString()); - } else - if (mustMatch) - throw new REException(getLocalizedMessage("interval.error"),REException.REG_EBRACE,index); - else - return startIndex; - - // We know min and max now, and they are valid. - - minMax.first = min; - minMax.second = max; - - // return the index following the '}' - return index; - } - - /** - * Return a human readable form of the compiled regular expression, - * useful for debugging. - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - dump(sb); - return sb.toString(); - } - - void dump(StringBuffer os) { - os.append('('); - if (subIndex == 0) - os.append("?:"); - if (firstToken != null) - firstToken.dumpAll(os); - os.append(')'); - } - - // Cast input appropriately or throw exception - private static CharIndexed makeCharIndexed(Object input, int index) { - // We could let a String fall through to final input, but since - // it's the most likely input type, we check it first. - if (input instanceof String) - return new CharIndexedString((String) input,index); - else if (input instanceof char[]) - return new CharIndexedCharArray((char[]) input,index); - else if (input instanceof StringBuffer) - return new CharIndexedStringBuffer((StringBuffer) input,index); - else if (input instanceof InputStream) - return new CharIndexedInputStream((InputStream) input,index); - else if (input instanceof CharIndexed) - return (CharIndexed) input; // do we lose index info? - else - return new CharIndexedString(input.toString(), index); - } -} diff --git a/libjava/gnu/regexp/REException.java b/libjava/gnu/regexp/REException.java deleted file mode 100644 index 73f86fa8add..00000000000 --- a/libjava/gnu/regexp/REException.java +++ /dev/null @@ -1,182 +0,0 @@ -/* gnu/regexp/REException.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -import java.text.MessageFormat; - -/** - * This is the regular expression exception class. An exception of this type - * defines the three attributes: - * <OL> - * <LI> A descriptive message of the error. - * <LI> An integral type code equivalent to one of the statically - * defined symbols listed below. - * <LI> The approximate position in the input string where the error - * occurred. - * </OL> - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - */ - -public class REException extends Exception { - private int type; - private int pos; - - // Error conditions from GNU regcomp(3) manual - - /** - * Error flag. - * Invalid use of repetition operators such as using - * `*' as the first character. - */ - public static final int REG_BADRPT = 1; - - /** - * Error flag. - * Invalid use of back reference operator. - */ - public static final int REG_BADBR = 2; - - /** - * Error flag. - * Un-matched brace interval operators. - */ - public static final int REG_EBRACE = 3; - - /** - * Error flag. - * Un-matched bracket list operators. - */ - public static final int REG_EBRACK = 4; - - /** - * Error flag. - * Invalid use of the range operator, eg. the ending - * point of the range occurs prior to the starting - * point. - */ - public static final int REG_ERANGE = 5; - - /** - * Error flag. - * Unknown character class name. <B>Not implemented</B>. - */ - public static final int REG_ECTYPE = 6; - - /** - * Error flag. - * Un-matched parenthesis group operators. - */ - public static final int REG_EPAREN = 7; - - /** - * Error flag. - * Invalid back reference to a subexpression. - */ - public static final int REG_ESUBREG = 8; - - /** - * Error flag. - * Non specific error. <B>Not implemented</B>. - */ - public static final int REG_EEND = 9; - - /** - * Error flag. - * Invalid escape sequence. <B>Not implemented</B>. - */ - public static final int REG_ESCAPE = 10; - - /** - * Error flag. - * Invalid use of pattern operators such as group or list. - */ - public static final int REG_BADPAT = 11; - - /** - * Error flag. - * Compiled regular expression requires a pattern - * buffer larger than 64Kb. <B>Not implemented</B>. - */ - public static final int REG_ESIZE = 12; - - /** - * Error flag. - * The regex routines ran out of memory. <B>Not implemented</B>. - */ - public static final int REG_ESPACE = 13; - - REException(String msg, int type, int position) { - super(msg); - this.type = type; - this.pos = position; - } - - /** - * Returns the type of the exception, one of the constants listed above. - */ - - public int getType() { - return type; - } - - /** - * Returns the position, relative to the string or character array being - * compiled, where the error occurred. This position is generally the point - * where the error was detected, not necessarily the starting index of - * a bad subexpression. - */ - public int getPosition() { - return pos; - } - - /** - * Reports the descriptive message associated with this exception - * as well as its index position in the string or character array - * being compiled. - */ - public String getMessage() { - Object[] args = {new Integer(pos)}; - StringBuffer sb = new StringBuffer(); - String prefix = RE.getLocalizedMessage("error.prefix"); - sb.append(MessageFormat.format(prefix, args)); - sb.append('\n'); - sb.append(super.getMessage()); - return sb.toString(); - } -} diff --git a/libjava/gnu/regexp/REFilterInputStream.java b/libjava/gnu/regexp/REFilterInputStream.java deleted file mode 100644 index 485de56605d..00000000000 --- a/libjava/gnu/regexp/REFilterInputStream.java +++ /dev/null @@ -1,140 +0,0 @@ -/* gnu/regexp/REFilterInputStream.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; -import java.io.FilterInputStream; -import java.io.InputStream; - -/** - * Replaces instances of a given RE found within an InputStream - * with replacement text. The replacements are interpolated into the - * stream when a match is found. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - * @deprecated This class cannot properly handle all character - * encodings. For proper handling, use the REFilterReader - * class instead. - */ - -public class REFilterInputStream extends FilterInputStream { - - private RE expr; - private String replace; - private String buffer; - private int bufpos; - private int offset; - private CharIndexedInputStream stream; - - /** - * Creates an REFilterInputStream. When reading from this stream, - * occurrences of patterns matching the supplied regular expression - * will be replaced with the supplied replacement text (the - * metacharacters $0 through $9 may be used to refer to the full - * match or subexpression matches). - * - * @param stream The InputStream to be filtered. - * @param expr The regular expression to search for. - * @param replace The text pattern to replace matches with. - */ - public REFilterInputStream(InputStream stream, RE expr, String replace) { - super(stream); - this.stream = new CharIndexedInputStream(stream,0); - this.expr = expr; - this.replace = replace; - } - - /** - * Reads the next byte from the stream per the general contract of - * InputStream.read(). Returns -1 on error or end of stream. - */ - public int read() { - // If we have buffered replace data, use it. - if ((buffer != null) && (bufpos < buffer.length())) { - return (int) buffer.charAt(bufpos++); - } - - // check if input is at a valid position - if (!stream.isValid()) return -1; - - REMatch mymatch = new REMatch(expr.getNumSubs(),offset,0); - if (expr.match(stream, mymatch)) { - mymatch.end[0] = mymatch.index; - mymatch.finish(stream); - stream.move(mymatch.toString().length()); - offset += mymatch.toString().length(); - buffer = mymatch.substituteInto(replace); - bufpos = 1; - - // This is prone to infinite loops if replace string turns out empty. - if (buffer.length() > 0) { - return buffer.charAt(0); - } - } - char ch = stream.charAt(0); - if (ch == CharIndexed.OUT_OF_BOUNDS) return -1; - stream.move(1); - offset++; - return ch; - } - - /** - * Returns false. REFilterInputStream does not support mark() and - * reset() methods. - */ - public boolean markSupported() { - return false; - } - - /** Reads from the stream into the provided array. */ - public int read(byte[] b, int off, int len) { - int i; - int ok = 0; - while (len-- > 0) { - i = read(); - if (i == -1) return (ok == 0) ? -1 : ok; - b[off++] = (byte) i; - ok++; - } - return ok; - } - - /** Reads from the stream into the provided array. */ - public int read(byte[] b) { - return read(b,0,b.length); - } -} diff --git a/libjava/gnu/regexp/REMatch.java b/libjava/gnu/regexp/REMatch.java deleted file mode 100644 index cf25bb331c5..00000000000 --- a/libjava/gnu/regexp/REMatch.java +++ /dev/null @@ -1,263 +0,0 @@ -/* gnu/regexp/REMatch.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; -import java.io.Serializable; - -/** - * An instance of this class represents a match - * completed by a gnu.regexp matching function. It can be used - * to obtain relevant information about the location of a match - * or submatch. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - */ -public final class REMatch implements Serializable, Cloneable { - private String matchedText; - - // These variables are package scope for fast access within the engine - int eflags; // execution flags this match was made using - - // Offset in source text where match was tried. This is zero-based; - // the actual position in the source text is given by (offset + anchor). - int offset; - - // Anchor position refers to the index into the source input - // at which the matching operation began. - // This is also useful for the ANCHORINDEX option. - int anchor; - - // Package scope; used by RE. - int index; // used while matching to mark current match position in input - int[] start; // start positions (relative to offset) for each (sub)exp. - int[] end; // end positions for the same - REMatch next; // other possibility (to avoid having to use arrays) - - public Object clone() { - try { - REMatch copy = (REMatch) super.clone(); - copy.next = null; - - copy.start = (int[]) start.clone(); - copy.end = (int[]) end.clone(); - - return copy; - } catch (CloneNotSupportedException e) { - throw new Error(); // doesn't happen - } - } - - void assignFrom(REMatch other) { - start = other.start; - end = other.end; - index = other.index; - // need to deep clone? - next = other.next; - } - - REMatch(int subs, int anchor, int eflags) { - start = new int[subs+1]; - end = new int[subs+1]; - this.anchor = anchor; - this.eflags = eflags; - clear(anchor); - } - - void finish(CharIndexed text) { - start[0] = 0; - StringBuffer sb = new StringBuffer(); - int i; - for (i = 0; i < end[0]; i++) - sb.append(text.charAt(i)); - matchedText = sb.toString(); - for (i = 0; i < start.length; i++) { - // If any subexpressions didn't terminate, they don't count - // TODO check if this code ever gets hit - if ((start[i] == -1) ^ (end[i] == -1)) { - start[i] = -1; - end[i] = -1; - } - } - next = null; // cut off alternates - } - - /** Clears the current match and moves the offset to the new index. */ - void clear(int index) { - offset = index; - this.index = 0; - for (int i = 0; i < start.length; i++) { - start[i] = end[i] = -1; - } - next = null; // cut off alternates - } - - /** - * Returns the string matching the pattern. This makes it convenient - * to write code like the following: - * <P> - * <code> - * REMatch myMatch = myExpression.getMatch(myString);<br> - * if (myMatch != null) System.out.println("Regexp found: "+myMatch); - * </code> - */ - public String toString() { - return matchedText; - } - - /** - * Returns the index within the input text where the match in its entirety - * began. - */ - public int getStartIndex() { - return offset + start[0]; - } - - /** - * Returns the index within the input string where the match in - * its entirety ends. The return value is the next position after - * the end of the string; therefore, a match created by the - * following call: - * - * <P> - * <code>REMatch myMatch = myExpression.getMatch(myString);</code> - * <P> - * can be viewed (given that myMatch is not null) by creating - * <P> - * <code>String theMatch = myString.substring(myMatch.getStartIndex(), - * myMatch.getEndIndex());</code> - * <P> - * But you can save yourself that work, since the <code>toString()</code> - * method (above) does exactly that for you. - */ - public int getEndIndex() { - return offset + end[0]; - } - - /** - * Returns the string matching the given subexpression. The subexpressions - * are indexed starting with one, not zero. That is, the subexpression - * identified by the first set of parentheses in a regular expression - * could be retrieved from an REMatch by calling match.toString(1). - * - * @param sub Index of the subexpression. - */ - public String toString(int sub) { - if ((sub >= start.length) || (start[sub] == -1)) return ""; - return (matchedText.substring(start[sub],end[sub])); - } - - /** - * Returns the index within the input string used to generate this match - * where subexpression number <i>sub</i> begins, or <code>-1</code> if - * the subexpression does not exist. The initial position is zero. - * - * @param sub Subexpression index - * @deprecated Use getStartIndex(int) instead. - */ - public int getSubStartIndex(int sub) { - if (sub >= start.length) return -1; - int x = start[sub]; - return (x == -1) ? x : offset + x; - } - - /** - * Returns the index within the input string used to generate this match - * where subexpression number <i>sub</i> begins, or <code>-1</code> if - * the subexpression does not exist. The initial position is zero. - * - * @param sub Subexpression index - * @since gnu.regexp 1.1.0 - */ - public int getStartIndex(int sub) { - if (sub >= start.length) return -1; - int x = start[sub]; - return (x == -1) ? x : offset + x; - } - - /** - * Returns the index within the input string used to generate this match - * where subexpression number <i>sub</i> ends, or <code>-1</code> if - * the subexpression does not exist. The initial position is zero. - * - * @param sub Subexpression index - * @deprecated Use getEndIndex(int) instead - */ - public int getSubEndIndex(int sub) { - if (sub >= start.length) return -1; - int x = end[sub]; - return (x == -1) ? x : offset + x; - } - - /** - * Returns the index within the input string used to generate this match - * where subexpression number <i>sub</i> ends, or <code>-1</code> if - * the subexpression does not exist. The initial position is zero. - * - * @param sub Subexpression index - */ - public int getEndIndex(int sub) { - if (sub >= start.length) return -1; - int x = end[sub]; - return (x == -1) ? x : offset + x; - } - - /** - * Substitute the results of this match to create a new string. - * This is patterned after PERL, so the tokens to watch out for are - * <code>$0</code> through <code>$9</code>. <code>$0</code> matches - * the full substring matched; <code>$<i>n</i></code> matches - * subexpression number <i>n</i>. - * - * @param input A string consisting of literals and <code>$<i>n</i></code> tokens. - */ - public String substituteInto(String input) { - // a la Perl, $0 is whole thing, $1 - $9 are subexpressions - StringBuffer output = new StringBuffer(); - int pos; - for (pos = 0; pos < input.length()-1; pos++) { - if ((input.charAt(pos) == '$') && (Character.isDigit(input.charAt(pos+1)))) { - int val = Character.digit(input.charAt(++pos),10); - if (val < start.length) { - output.append(toString(val)); - } - } else output.append(input.charAt(pos)); - } - if (pos < input.length()) output.append(input.charAt(pos)); - return output.toString(); - } -} diff --git a/libjava/gnu/regexp/REMatchEnumeration.java b/libjava/gnu/regexp/REMatchEnumeration.java deleted file mode 100644 index f164a69af4f..00000000000 --- a/libjava/gnu/regexp/REMatchEnumeration.java +++ /dev/null @@ -1,135 +0,0 @@ -/* gnu/regexp/REMatchEnumeration.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.Serializable; -import java.util.Enumeration; -import java.util.NoSuchElementException; - -/** - * An REMatchEnumeration enumerates regular expression matches over a - * given input text. You obtain a reference to an enumeration using - * the <code>getMatchEnumeration()</code> methods on an instance of - * RE. - * - * <P> - * - * REMatchEnumeration does lazy computation; that is, it will not - * search for a match until it needs to. If you'd rather just get all - * the matches at once in a big array, use the - * <code>getAllMatches()</code> methods on RE. However, using an - * enumeration can help speed performance when the entire text does - * not need to be searched immediately. - * - * <P> - * - * The enumerated type is especially useful when searching on a Reader - * or InputStream, because the InputStream read position cannot be - * guaranteed after calling <code>getMatch()</code> (see the - * description of that method for an explanation of why). Enumeration - * also saves a lot of overhead required when calling - * <code>getMatch()</code> multiple times. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - */ -public class REMatchEnumeration implements Enumeration, Serializable { - private static final int YES = 1; - private static final int MAYBE = 0; - private static final int NO = -1; - - private int more; - private REMatch match; - private RE expr; - private CharIndexed input; - private int eflags; - private int index; - - // Package scope constructor is used by RE.getMatchEnumeration() - REMatchEnumeration(RE expr, CharIndexed input, int index, int eflags) { - more = MAYBE; - this.expr = expr; - this.input = input; - this.index = index; - this.eflags = eflags; - } - - /** Returns true if there are more matches in the input text. */ - public boolean hasMoreElements() { - return hasMoreMatches(null); - } - - /** Returns true if there are more matches in the input text. */ - public boolean hasMoreMatches() { - return hasMoreMatches(null); - } - - /** Returns true if there are more matches in the input text. - * Saves the text leading up to the match (or to the end of the input) - * in the specified buffer. - */ - public boolean hasMoreMatches(StringBuffer buffer) { - if (more == MAYBE) { - match = expr.getMatchImpl(input,index,eflags,buffer); - if (match != null) { - input.move((match.end[0] > 0) ? match.end[0] : 1); - - index = (match.end[0] > 0) ? match.end[0] + match.offset : index + 1; - more = YES; - } else more = NO; - } - return (more == YES); - } - - /** Returns the next match in the input text. */ - public Object nextElement() throws NoSuchElementException { - return nextMatch(); - } - - /** - * Returns the next match in the input text. This method is provided - * for convenience to avoid having to explicitly cast the return value - * to class REMatch. - */ - public REMatch nextMatch() throws NoSuchElementException { - if (hasMoreElements()) { - more = (input.isValid()) ? MAYBE : NO; - return match; - } - throw new NoSuchElementException(); - } -} - diff --git a/libjava/gnu/regexp/RESyntax.java b/libjava/gnu/regexp/RESyntax.java deleted file mode 100644 index 7272b03481b..00000000000 --- a/libjava/gnu/regexp/RESyntax.java +++ /dev/null @@ -1,527 +0,0 @@ -/* gnu/regexp/RESyntax.java - Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; -import java.io.Serializable; -import java.util.BitSet; - -/** - * An RESyntax specifies the way a regular expression will be compiled. - * This class provides a number of predefined useful constants for - * emulating popular regular expression syntaxes. Additionally the - * user may construct his or her own syntax, using any combination of the - * syntax bit constants. The syntax is an optional argument to any of the - * matching methods on class RE. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - */ - -public final class RESyntax implements Serializable { - static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator"); - - private static final String SYNTAX_IS_FINAL = RE.getLocalizedMessage("syntax.final"); - - private BitSet bits; - - // true for the constant defined syntaxes - private boolean isFinal = false; - - private String lineSeparator = DEFAULT_LINE_SEPARATOR; - - // Values for constants are bit indexes - - /** - * Syntax bit. Backslash is an escape character in lists. - */ - public static final int RE_BACKSLASH_ESCAPE_IN_LISTS = 0; - - /** - * Syntax bit. Use \? instead of ? and \+ instead of +. - */ - public static final int RE_BK_PLUS_QM = 1; - - /** - * Syntax bit. POSIX character classes ([:...:]) in lists are allowed. - */ - public static final int RE_CHAR_CLASSES = 2; - - /** - * Syntax bit. ^ and $ are special everywhere. - * <B>Not implemented.</B> - */ - public static final int RE_CONTEXT_INDEP_ANCHORS = 3; - - /** - * Syntax bit. Repetition operators are only special in valid positions. - * <B>Not implemented.</B> - */ - public static final int RE_CONTEXT_INDEP_OPS = 4; - - /** - * Syntax bit. Repetition and alternation operators are invalid - * at start and end of pattern and other places. - * <B>Not implemented</B>. - */ - public static final int RE_CONTEXT_INVALID_OPS = 5; - - /** - * Syntax bit. Match-any-character operator (.) matches a newline. - */ - public static final int RE_DOT_NEWLINE = 6; - - /** - * Syntax bit. Match-any-character operator (.) does not match a null. - */ - public static final int RE_DOT_NOT_NULL = 7; - - /** - * Syntax bit. Intervals ({x}, {x,}, {x,y}) are allowed. - */ - public static final int RE_INTERVALS = 8; - - /** - * Syntax bit. No alternation (|), match one-or-more (+), or - * match zero-or-one (?) operators. - */ - public static final int RE_LIMITED_OPS = 9; - - /** - * Syntax bit. Newline is an alternation operator. - */ - public static final int RE_NEWLINE_ALT = 10; // impl. - - /** - * Syntax bit. Intervals use { } instead of \{ \} - */ - public static final int RE_NO_BK_BRACES = 11; - - /** - * Syntax bit. Grouping uses ( ) instead of \( \). - */ - public static final int RE_NO_BK_PARENS = 12; - - /** - * Syntax bit. Backreferences not allowed. - */ - public static final int RE_NO_BK_REFS = 13; - - /** - * Syntax bit. Alternation uses | instead of \| - */ - public static final int RE_NO_BK_VBAR = 14; - - /** - * Syntax bit. <B>Not implemented</B>. - */ - public static final int RE_NO_EMPTY_RANGES = 15; - - /** - * Syntax bit. An unmatched right parenthesis (')' or '\)', depending - * on RE_NO_BK_PARENS) will throw an exception when compiling. - */ - public static final int RE_UNMATCHED_RIGHT_PAREN_ORD = 16; - - /** - * Syntax bit. <B>Not implemented.</B> - */ - public static final int RE_HAT_LISTS_NOT_NEWLINE = 17; - - /** - * Syntax bit. Stingy matching is allowed (+?, *?, ??, {x,y}?). - */ - public static final int RE_STINGY_OPS = 18; - - /** - * Syntax bit. Allow character class escapes (\d, \D, \s, \S, \w, \W). - */ - public static final int RE_CHAR_CLASS_ESCAPES = 19; - - /** - * Syntax bit. Allow use of (?:xxx) grouping (subexpression is not saved). - */ - public static final int RE_PURE_GROUPING = 20; - - /** - * Syntax bit. Allow use of (?=xxx) and (?!xxx) apply the subexpression - * to the text following the current position without consuming that text. - */ - public static final int RE_LOOKAHEAD = 21; - - /** - * Syntax bit. Allow beginning- and end-of-string anchors (\A, \Z). - */ - public static final int RE_STRING_ANCHORS = 22; - - /** - * Syntax bit. Allow embedded comments, (?#comment), as in Perl5. - */ - public static final int RE_COMMENTS = 23; - - /** - * Syntax bit. Allow character class escapes within lists, as in Perl5. - */ - public static final int RE_CHAR_CLASS_ESC_IN_LISTS = 24; - - /** - * Syntax bit. Possessive matching is allowed (++, *+, ?+, {x,y}+). - */ - public static final int RE_POSSESSIVE_OPS = 25; - - private static final int BIT_TOTAL = 26; - - /** - * Predefined syntax. - * Emulates regular expression support in the awk utility. - */ - public static final RESyntax RE_SYNTAX_AWK; - - /** - * Predefined syntax. - * Emulates regular expression support in the ed utility. - */ - public static final RESyntax RE_SYNTAX_ED; - - /** - * Predefined syntax. - * Emulates regular expression support in the egrep utility. - */ - public static final RESyntax RE_SYNTAX_EGREP; - - /** - * Predefined syntax. - * Emulates regular expression support in the GNU Emacs editor. - */ - public static final RESyntax RE_SYNTAX_EMACS; - - /** - * Predefined syntax. - * Emulates regular expression support in the grep utility. - */ - public static final RESyntax RE_SYNTAX_GREP; - - /** - * Predefined syntax. - * Emulates regular expression support in the POSIX awk specification. - */ - public static final RESyntax RE_SYNTAX_POSIX_AWK; - - /** - * Predefined syntax. - * Emulates POSIX basic regular expression support. - */ - public static final RESyntax RE_SYNTAX_POSIX_BASIC; - - /** - * Predefined syntax. - * Emulates regular expression support in the POSIX egrep specification. - */ - public static final RESyntax RE_SYNTAX_POSIX_EGREP; - - /** - * Predefined syntax. - * Emulates POSIX extended regular expression support. - */ - public static final RESyntax RE_SYNTAX_POSIX_EXTENDED; - - /** - * Predefined syntax. - * Emulates POSIX basic minimal regular expressions. - */ - public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_BASIC; - - /** - * Predefined syntax. - * Emulates POSIX extended minimal regular expressions. - */ - public static final RESyntax RE_SYNTAX_POSIX_MINIMAL_EXTENDED; - - /** - * Predefined syntax. - * Emulates regular expression support in the sed utility. - */ - public static final RESyntax RE_SYNTAX_SED; - - /** - * Predefined syntax. - * Emulates regular expression support in Larry Wall's perl, version 4, - */ - public static final RESyntax RE_SYNTAX_PERL4; - - /** - * Predefined syntax. - * Emulates regular expression support in Larry Wall's perl, version 4, - * using single line mode (/s modifier). - */ - public static final RESyntax RE_SYNTAX_PERL4_S; // single line mode (/s) - - /** - * Predefined syntax. - * Emulates regular expression support in Larry Wall's perl, version 5. - */ - public static final RESyntax RE_SYNTAX_PERL5; - - /** - * Predefined syntax. - * Emulates regular expression support in Larry Wall's perl, version 5, - * using single line mode (/s modifier). - */ - public static final RESyntax RE_SYNTAX_PERL5_S; - - /** - * Predefined syntax. - * Emulates regular expression support in Java 1.4's java.util.regex - * package. - */ - public static final RESyntax RE_SYNTAX_JAVA_1_4; - - static { - // Define syntaxes - - RE_SYNTAX_EMACS = new RESyntax().makeFinal(); - - RESyntax RE_SYNTAX_POSIX_COMMON = new RESyntax() - .set(RE_CHAR_CLASSES) - .set(RE_DOT_NEWLINE) - .set(RE_DOT_NOT_NULL) - .set(RE_INTERVALS) - .set(RE_NO_EMPTY_RANGES) - .makeFinal(); - - RE_SYNTAX_POSIX_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON) - .set(RE_BK_PLUS_QM) - .makeFinal(); - - RE_SYNTAX_POSIX_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON) - .set(RE_CONTEXT_INDEP_ANCHORS) - .set(RE_CONTEXT_INDEP_OPS) - .set(RE_NO_BK_BRACES) - .set(RE_NO_BK_PARENS) - .set(RE_NO_BK_VBAR) - .set(RE_UNMATCHED_RIGHT_PAREN_ORD) - .makeFinal(); - - RE_SYNTAX_AWK = new RESyntax() - .set(RE_BACKSLASH_ESCAPE_IN_LISTS) - .set(RE_DOT_NOT_NULL) - .set(RE_NO_BK_PARENS) - .set(RE_NO_BK_REFS) - .set(RE_NO_BK_VBAR) - .set(RE_NO_EMPTY_RANGES) - .set(RE_UNMATCHED_RIGHT_PAREN_ORD) - .makeFinal(); - - RE_SYNTAX_POSIX_AWK = new RESyntax(RE_SYNTAX_POSIX_EXTENDED) - .set(RE_BACKSLASH_ESCAPE_IN_LISTS) - .makeFinal(); - - RE_SYNTAX_GREP = new RESyntax() - .set(RE_BK_PLUS_QM) - .set(RE_CHAR_CLASSES) - .set(RE_HAT_LISTS_NOT_NEWLINE) - .set(RE_INTERVALS) - .set(RE_NEWLINE_ALT) - .makeFinal(); - - RE_SYNTAX_EGREP = new RESyntax() - .set(RE_CHAR_CLASSES) - .set(RE_CONTEXT_INDEP_ANCHORS) - .set(RE_CONTEXT_INDEP_OPS) - .set(RE_HAT_LISTS_NOT_NEWLINE) - .set(RE_NEWLINE_ALT) - .set(RE_NO_BK_PARENS) - .set(RE_NO_BK_VBAR) - .makeFinal(); - - RE_SYNTAX_POSIX_EGREP = new RESyntax(RE_SYNTAX_EGREP) - .set(RE_INTERVALS) - .set(RE_NO_BK_BRACES) - .makeFinal(); - - /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ - - RE_SYNTAX_ED = new RESyntax(RE_SYNTAX_POSIX_BASIC) - .makeFinal(); - - RE_SYNTAX_SED = new RESyntax(RE_SYNTAX_POSIX_BASIC) - .makeFinal(); - - RE_SYNTAX_POSIX_MINIMAL_BASIC = new RESyntax(RE_SYNTAX_POSIX_COMMON) - .set(RE_LIMITED_OPS) - .makeFinal(); - - /* Differs from RE_SYNTAX_POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ - - RE_SYNTAX_POSIX_MINIMAL_EXTENDED = new RESyntax(RE_SYNTAX_POSIX_COMMON) - .set(RE_CONTEXT_INDEP_ANCHORS) - .set(RE_CONTEXT_INVALID_OPS) - .set(RE_NO_BK_BRACES) - .set(RE_NO_BK_PARENS) - .set(RE_NO_BK_REFS) - .set(RE_NO_BK_VBAR) - .set(RE_UNMATCHED_RIGHT_PAREN_ORD) - .makeFinal(); - - /* There is no official Perl spec, but here's a "best guess" */ - - RE_SYNTAX_PERL4 = new RESyntax() - .set(RE_BACKSLASH_ESCAPE_IN_LISTS) - .set(RE_CONTEXT_INDEP_ANCHORS) - .set(RE_CONTEXT_INDEP_OPS) // except for '{', apparently - .set(RE_INTERVALS) - .set(RE_NO_BK_BRACES) - .set(RE_NO_BK_PARENS) - .set(RE_NO_BK_VBAR) - .set(RE_NO_EMPTY_RANGES) - .set(RE_CHAR_CLASS_ESCAPES) // \d,\D,\w,\W,\s,\S - .makeFinal(); - - RE_SYNTAX_PERL4_S = new RESyntax(RE_SYNTAX_PERL4) - .set(RE_DOT_NEWLINE) - .makeFinal(); - - RE_SYNTAX_PERL5 = new RESyntax(RE_SYNTAX_PERL4) - .set(RE_PURE_GROUPING) // (?:) - .set(RE_STINGY_OPS) // *?,??,+?,{}? - .set(RE_LOOKAHEAD) // (?=)(?!) - .set(RE_STRING_ANCHORS) // \A,\Z - .set(RE_CHAR_CLASS_ESC_IN_LISTS)// \d,\D,\w,\W,\s,\S within [] - .set(RE_COMMENTS) // (?#) - .makeFinal(); - - RE_SYNTAX_PERL5_S = new RESyntax(RE_SYNTAX_PERL5) - .set(RE_DOT_NEWLINE) - .makeFinal(); - - RE_SYNTAX_JAVA_1_4 = new RESyntax(RE_SYNTAX_PERL5) - // XXX - .set(RE_POSSESSIVE_OPS) // *+,?+,++,{}+ - .makeFinal(); - } - - /** - * Construct a new syntax object with all bits turned off. - * This is equivalent to RE_SYNTAX_EMACS. - */ - public RESyntax() { - bits = new BitSet(BIT_TOTAL); - } - - /** - * Called internally when constructing predefined syntaxes - * so their interpretation cannot vary. Conceivably useful - * for your syntaxes as well. Causes IllegalAccessError to - * be thrown if any attempt to modify the syntax is made. - * - * @return this object for convenient chaining - */ - public RESyntax makeFinal() { - isFinal = true; - return this; - } - - /** - * Construct a new syntax object with all bits set the same - * as the other syntax. - */ - public RESyntax(RESyntax other) { - bits = (BitSet) other.bits.clone(); - } - - /** - * Check if a given bit is set in this syntax. - */ - public boolean get(int index) { - return bits.get(index); - } - - /** - * Set a given bit in this syntax. - * - * @param index the constant (RESyntax.RE_xxx) bit to set. - * @return a reference to this object for easy chaining. - */ - public RESyntax set(int index) { - if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL); - bits.set(index); - return this; - } - - /** - * Clear a given bit in this syntax. - * - * @param index the constant (RESyntax.RE_xxx) bit to clear. - * @return a reference to this object for easy chaining. - */ - public RESyntax clear(int index) { - if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL); - bits.clear(index); - return this; - } - - /** - * Changes the line separator string for regular expressions - * created using this RESyntax. The default separator is the - * value returned by the system property "line.separator", which - * should be correct when reading platform-specific files from a - * filesystem. However, many programs may collect input from - * sources where the line separator is differently specified (for - * example, in the applet environment, the text box widget - * interprets line breaks as single-character newlines, - * regardless of the host platform. - * - * Note that setting the line separator to a character or - * characters that have specific meaning within the current syntax - * can cause unexpected chronosynclastic infundibula. - * - * @return this object for convenient chaining - */ - public RESyntax setLineSeparator(String aSeparator) { - if (isFinal) throw new IllegalAccessError(SYNTAX_IS_FINAL); - lineSeparator = aSeparator; - return this; - } - - /** - * Returns the currently active line separator string. The default - * is the platform-dependent system property "line.separator". - */ - public String getLineSeparator() { - return lineSeparator; - } -} diff --git a/libjava/gnu/regexp/REToken.java b/libjava/gnu/regexp/REToken.java deleted file mode 100644 index 4eae9ec473c..00000000000 --- a/libjava/gnu/regexp/REToken.java +++ /dev/null @@ -1,86 +0,0 @@ -/* gnu/regexp/REToken.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.io.Serializable; - -abstract class REToken implements Serializable { - - protected REToken next = null; - protected REToken uncle = null; - protected int subIndex; - - protected REToken(int subIndex) { - this.subIndex = subIndex; - } - - int getMinimumLength() { - return 0; - } - - void setUncle(REToken anUncle) { - uncle = anUncle; - } - - /** Returns true if the match succeeded, false if it failed. */ - abstract boolean match(CharIndexed input, REMatch mymatch); - - /** Returns true if the rest of the tokens match, false if they fail. */ - protected boolean next(CharIndexed input, REMatch mymatch) { - if (next == null) { - if (uncle == null) { - return true; - } else { - return uncle.match(input, mymatch); - } - } else { - return next.match(input, mymatch); - } - } - - boolean chain(REToken token) { - next = token; - return true; // Token was accepted - } - - abstract void dump(StringBuffer os); - - void dumpAll(StringBuffer os) { - dump(os); - if (next != null) next.dumpAll(os); - } -} diff --git a/libjava/gnu/regexp/RETokenAny.java b/libjava/gnu/regexp/RETokenAny.java deleted file mode 100644 index ac032dcb3bf..00000000000 --- a/libjava/gnu/regexp/RETokenAny.java +++ /dev/null @@ -1,73 +0,0 @@ -/* gnu/regexp/RETokenAny.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -final class RETokenAny extends REToken { - /** True if '.' can match a newline (RE_DOT_NEWLINE) */ - private boolean newline; - - /** True if '.' can't match a null (RE_DOT_NOT_NULL) */ - private boolean matchNull; - - RETokenAny(int subIndex, boolean newline, boolean matchNull) { - super(subIndex); - this.newline = newline; - this.matchNull = matchNull; - } - - int getMinimumLength() { - return 1; - } - - boolean match(CharIndexed input, REMatch mymatch) { - char ch = input.charAt(mymatch.index); - if ((ch == CharIndexed.OUT_OF_BOUNDS) - || (!newline && (ch == '\n')) - || (matchNull && (ch == 0))) { - return false; - } - ++mymatch.index; - return next(input, mymatch); - } - - void dump(StringBuffer os) { - os.append('.'); - } -} - diff --git a/libjava/gnu/regexp/RETokenBackRef.java b/libjava/gnu/regexp/RETokenBackRef.java deleted file mode 100644 index 674822abd70..00000000000 --- a/libjava/gnu/regexp/RETokenBackRef.java +++ /dev/null @@ -1,72 +0,0 @@ -/* gnu/regexp/RETokenBackRef.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -final class RETokenBackRef extends REToken { - private int num; - private boolean insens; - - RETokenBackRef(int subIndex, int num, boolean insens) { - super(subIndex); - this.num = num; - this.insens = insens; - } - - // should implement getMinimumLength() -- any ideas? - - boolean match(CharIndexed input, REMatch mymatch) { - int b,e; - b = mymatch.start[num]; - e = mymatch.end[num]; - if ((b==-1)||(e==-1)) return false; // this shouldn't happen, but... - for (int i=b; i<e; i++) { - if (input.charAt(mymatch.index+i-b) != input.charAt(i)) { - return false; - } - } - mymatch.index += e-b; - return next(input, mymatch); - } - - void dump(StringBuffer os) { - os.append('\\').append(num); - } -} - - diff --git a/libjava/gnu/regexp/RETokenChar.java b/libjava/gnu/regexp/RETokenChar.java deleted file mode 100644 index a15449b2d96..00000000000 --- a/libjava/gnu/regexp/RETokenChar.java +++ /dev/null @@ -1,91 +0,0 @@ -/* gnu/regexp/RETokenChar.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -final class RETokenChar extends REToken { - private char[] ch; - private boolean insens; - - RETokenChar(int subIndex, char c, boolean ins) { - super(subIndex); - ch = new char [1]; - ch[0] = (insens = ins) ? Character.toLowerCase(c) : c; - } - - int getMinimumLength() { - return ch.length; - } - - boolean match(CharIndexed input, REMatch mymatch) { - int z = ch.length; - char c; - for (int i=0; i<z; i++) { - c = input.charAt(mymatch.index+i); - if (( (insens) ? Character.toLowerCase(c) : c ) != ch[i]) { - return false; - } - } - mymatch.index += z; - - return next(input, mymatch); - } - - // Overrides REToken.chain() to optimize for strings - boolean chain(REToken next) { - if (next instanceof RETokenChar) { - RETokenChar cnext = (RETokenChar) next; - // assume for now that next can only be one character - int newsize = ch.length + cnext.ch.length; - - char[] chTemp = new char [newsize]; - - System.arraycopy(ch,0,chTemp,0,ch.length); - System.arraycopy(cnext.ch,0,chTemp,ch.length,cnext.ch.length); - - ch = chTemp; - return false; - } else return super.chain(next); - } - - void dump(StringBuffer os) { - os.append(ch); - } -} - - diff --git a/libjava/gnu/regexp/RETokenEnd.java b/libjava/gnu/regexp/RETokenEnd.java deleted file mode 100644 index 70483b746a9..00000000000 --- a/libjava/gnu/regexp/RETokenEnd.java +++ /dev/null @@ -1,75 +0,0 @@ -/* gnu/regexp/RETokenEnd.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -final class RETokenEnd extends REToken { - /** - * Indicates whether this token should match on a line break. - */ - private String newline; - - RETokenEnd(int subIndex,String newline) { - super(subIndex); - this.newline = newline; - } - - boolean match(CharIndexed input, REMatch mymatch) { - char ch = input.charAt(mymatch.index); - if (ch == CharIndexed.OUT_OF_BOUNDS) - return ((mymatch.eflags & RE.REG_NOTEOL)>0) ? - false : next(input, mymatch); - if (newline != null) { - char z; - int i = 0; // position in newline - do { - z = newline.charAt(i); - if (ch != z) return false; - ++i; - ch = input.charAt(mymatch.index + i); - } while (i < newline.length()); - - return next(input, mymatch); - } - return false; - } - - void dump(StringBuffer os) { - os.append('$'); - } -} diff --git a/libjava/gnu/regexp/RETokenEndSub.java b/libjava/gnu/regexp/RETokenEndSub.java deleted file mode 100644 index f3bb4f2e131..00000000000 --- a/libjava/gnu/regexp/RETokenEndSub.java +++ /dev/null @@ -1,53 +0,0 @@ -/* gnu/regexp/RETokenEndSub.java - Copyright (C) 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -final class RETokenEndSub extends REToken { - RETokenEndSub(int subIndex) { - super(subIndex); - } - - boolean match(CharIndexed input, REMatch mymatch) { - mymatch.end[subIndex] = mymatch.index; - return next(input, mymatch); - } - - void dump(StringBuffer os) { - // handled by RE - } -} diff --git a/libjava/gnu/regexp/RETokenLookAhead.java b/libjava/gnu/regexp/RETokenLookAhead.java deleted file mode 100644 index 33eaec9fac1..00000000000 --- a/libjava/gnu/regexp/RETokenLookAhead.java +++ /dev/null @@ -1,87 +0,0 @@ -/* gnu/regexp/RETokenLookAhead.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -/** - * @since gnu.regexp 1.1.3 - * @author Shashank Bapat - */ -final class RETokenLookAhead extends REToken -{ - REToken re; - boolean negative; - - RETokenLookAhead(REToken re, boolean negative) throws REException { - super(0); - this.re = re; - this.negative = negative; - } - - boolean match(CharIndexed input, REMatch mymatch) - { - REMatch trymatch = (REMatch)mymatch.clone(); - REMatch trymatch1 = (REMatch)mymatch.clone(); - REMatch newMatch = null; - if (re.match(input, trymatch)) { - if (negative) return false; - if (next(input, trymatch1)) - newMatch = trymatch1; - } - - if (newMatch != null) { - if (negative) return false; - //else - mymatch.assignFrom(newMatch); - return true; - } - else { // no match - if (negative) - return next(input, mymatch); - //else - return false; - } - } - - void dump(StringBuffer os) { - os.append("(?"); - os.append(negative ? '!' : '='); - re.dumpAll(os); - os.append(')'); - } -} - diff --git a/libjava/gnu/regexp/RETokenOneOf.java b/libjava/gnu/regexp/RETokenOneOf.java deleted file mode 100644 index 3f6e89e2103..00000000000 --- a/libjava/gnu/regexp/RETokenOneOf.java +++ /dev/null @@ -1,130 +0,0 @@ -/* gnu/regexp/RETokenOneOf.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; -import java.util.Vector; - -final class RETokenOneOf extends REToken { - private Vector options; - private boolean negative; - - // This constructor is used for convenience when we know the set beforehand, - // e.g. \d --> new RETokenOneOf("0123456789",false, ..) - // \D --> new RETokenOneOf("0123456789",true, ..) - - RETokenOneOf(int subIndex, String optionsStr, boolean negative, boolean insens) { - super(subIndex); - options = new Vector(); - this.negative = negative; - for (int i = 0; i < optionsStr.length(); i++) - options.addElement(new RETokenChar(subIndex,optionsStr.charAt(i),insens)); - } - - RETokenOneOf(int subIndex, Vector options, boolean negative) { - super(subIndex); - this.options = options; - this.negative = negative; - } - - int getMinimumLength() { - int min = Integer.MAX_VALUE; - int x; - for (int i=0; i < options.size(); i++) { - if ((x = ((REToken) options.elementAt(i)).getMinimumLength()) < min) - min = x; - } - return min; - } - - boolean match(CharIndexed input, REMatch mymatch) { - if (negative && (input.charAt(mymatch.index) == CharIndexed.OUT_OF_BOUNDS)) - return false; - - REMatch newMatch = null; - REMatch last = null; - REToken tk; - boolean isMatch; - for (int i=0; i < options.size(); i++) { - tk = (REToken) options.elementAt(i); - REMatch tryMatch = (REMatch) mymatch.clone(); - if (tk.match(input, tryMatch)) { // match was successful - if (negative) return false; - - if (next(input, tryMatch)) { - // Add tryMatch to list of possibilities. - if (last == null) { - newMatch = tryMatch; - last = tryMatch; - } else { - last.next = tryMatch; - last = tryMatch; - } - } // next succeeds - } // is a match - } // try next option - - if (newMatch != null) { - if (negative) { - return false; - } else { - // set contents of mymatch equal to newMatch - - // try each one that matched - mymatch.assignFrom(newMatch); - return true; - } - } else { - if (negative) { - ++mymatch.index; - return next(input, mymatch); - } else { - return false; - } - } - - // index+1 works for [^abc] lists, not for generic lookahead (--> index) - } - - void dump(StringBuffer os) { - os.append(negative ? "[^" : "(?:"); - for (int i = 0; i < options.size(); i++) { - if (!negative && (i > 0)) os.append('|'); - ((REToken) options.elementAt(i)).dumpAll(os); - } - os.append(negative ? ']' : ')'); - } -} diff --git a/libjava/gnu/regexp/RETokenPOSIX.java b/libjava/gnu/regexp/RETokenPOSIX.java deleted file mode 100644 index bbb8066bca8..00000000000 --- a/libjava/gnu/regexp/RETokenPOSIX.java +++ /dev/null @@ -1,144 +0,0 @@ -/* gnu/regexp/RETokenPOSIX.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -final class RETokenPOSIX extends REToken { - int type; - boolean insens; - boolean negated; - - static final int ALNUM = 0; - static final int ALPHA = 1; - static final int BLANK = 2; - static final int CNTRL = 3; - static final int DIGIT = 4; - static final int GRAPH = 5; - static final int LOWER = 6; - static final int PRINT = 7; - static final int PUNCT = 8; - static final int SPACE = 9; - static final int UPPER = 10; - static final int XDIGIT = 11; - - // Array indices correspond to constants defined above. - static final String[] s_nameTable = { - "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower", - "print", "punct", "space", "upper", "xdigit" - }; - - // The RE constructor uses this to look up the constant for a string - static int intValue(String key) { - for (int i = 0; i < s_nameTable.length; i++) { - if (s_nameTable[i].equals(key)) return i; - } - return -1; - } - - RETokenPOSIX(int subIndex, int type, boolean insens, boolean negated) { - super(subIndex); - this.type = type; - this.insens = insens; - this.negated = negated; - } - - int getMinimumLength() { - return 1; - } - - boolean match(CharIndexed input, REMatch mymatch) { - char ch = input.charAt(mymatch.index); - if (ch == CharIndexed.OUT_OF_BOUNDS) - return false; - - boolean retval = false; - switch (type) { - case ALNUM: - // Note that there is some debate over whether '_' should be included - retval = Character.isLetterOrDigit(ch) || (ch == '_'); - break; - case ALPHA: - retval = Character.isLetter(ch); - break; - case BLANK: - retval = ((ch == ' ') || (ch == '\t')); - break; - case CNTRL: - retval = Character.isISOControl(ch); - break; - case DIGIT: - retval = Character.isDigit(ch); - break; - case GRAPH: - retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch))); - break; - case LOWER: - retval = ((insens && Character.isLetter(ch)) || Character.isLowerCase(ch)); - break; - case PRINT: - retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch))) - || (ch == ' '); - break; - case PUNCT: - // This feels sloppy, especially for non-U.S. locales. - retval = ("`~!@#$%^&*()-_=+[]{}\\|;:'\"/?,.<>".indexOf(ch)!=-1); - break; - case SPACE: - retval = Character.isWhitespace(ch); - break; - case UPPER: - retval = ((insens && Character.isLetter(ch)) || Character.isUpperCase(ch)); - break; - case XDIGIT: - retval = (Character.isDigit(ch) || ("abcdefABCDEF".indexOf(ch)!=-1)); - break; - } - - if (negated) retval = !retval; - if (retval) { - ++mymatch.index; - return next(input, mymatch); - } - else return false; - } - - void dump(StringBuffer os) { - if (negated) os.append('^'); - os.append("[:" + s_nameTable[type] + ":]"); - } -} diff --git a/libjava/gnu/regexp/RETokenRange.java b/libjava/gnu/regexp/RETokenRange.java deleted file mode 100644 index dadaf2d8072..00000000000 --- a/libjava/gnu/regexp/RETokenRange.java +++ /dev/null @@ -1,69 +0,0 @@ -/* gnu/regexp/RETokenRange.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -final class RETokenRange extends REToken { - private char lo, hi; - private boolean insens; - - RETokenRange(int subIndex, char lo, char hi, boolean ins) { - super(subIndex); - this.lo = (insens = ins) ? Character.toLowerCase(lo) : lo; - this.hi = ins ? Character.toLowerCase(hi) : hi; - } - - int getMinimumLength() { - return 1; - } - - boolean match(CharIndexed input, REMatch mymatch) { - char c = input.charAt(mymatch.index); - if (c == CharIndexed.OUT_OF_BOUNDS) return false; - if (insens) c = Character.toLowerCase(c); - if ((c >= lo) && (c <= hi)) { - ++mymatch.index; - return next(input, mymatch); - } - return false; - } - - void dump(StringBuffer os) { - os.append(lo).append('-').append(hi); - } -} - diff --git a/libjava/gnu/regexp/RETokenRepeated.java b/libjava/gnu/regexp/RETokenRepeated.java deleted file mode 100644 index 3165a6f1654..00000000000 --- a/libjava/gnu/regexp/RETokenRepeated.java +++ /dev/null @@ -1,240 +0,0 @@ -/* gnu/regexp/RETokenRepeated.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -import java.util.Vector; - -final class RETokenRepeated extends REToken { - private REToken token; - private int min,max; - private boolean stingy; - private boolean possessive; - - RETokenRepeated(int subIndex, REToken token, int min, int max) { - super(subIndex); - this.token = token; - this.min = min; - this.max = max; - } - - /** Sets the minimal matching mode to true. */ - void makeStingy() { - stingy = true; - } - - /** Queries if this token has minimal matching enabled. */ - boolean isStingy() { - return stingy; - } - - /** Sets possessive matching mode to true. */ - void makePossessive() { - possessive = true; - } - - /** Queries if this token has possessive matching enabled. */ - boolean isPossessive() { - return possessive; - } - - /** - * The minimum length of a repeated token is the minimum length - * of the token multiplied by the minimum number of times it must - * match. - */ - int getMinimumLength() { - return (min * token.getMinimumLength()); - } - - // We do need to save every possible point, but the number of clone() - // invocations here is really a killer for performance on non-stingy - // repeat operators. I'm open to suggestions... - - // Hypothetical question: can you have a RE that matches 1 times, - // 3 times, 5 times, but not 2 times or 4 times? Does having - // the subexpression back-reference operator allow that? - - boolean match(CharIndexed input, REMatch mymatch) { - // number of times we've matched so far - int numRepeats = 0; - - // Possible positions for the next repeat to match at - REMatch newMatch = mymatch; - REMatch last = null; - REMatch current; - - // Add the '0-repeats' index - // positions.elementAt(z) == position [] in input after <<z>> matches - Vector positions = new Vector(); - positions.addElement(newMatch); - - // Declare variables used in loop - REMatch doables; - REMatch doablesLast; - REMatch recurrent; - - do { - // Check for stingy match for each possibility. - if (stingy && (numRepeats >= min)) { - REMatch result = matchRest(input, newMatch); - if (result != null) { - mymatch.assignFrom(result); - return true; - } - } - - doables = null; - doablesLast = null; - - // try next repeat at all possible positions - for (current = newMatch; current != null; current = current.next) { - recurrent = (REMatch) current.clone(); - if (token.match(input, recurrent)) { - // add all items in current to doables array - if (doables == null) { - doables = recurrent; - doablesLast = recurrent; - } else { - // Order these from longest to shortest - // Start by assuming longest (more repeats) - doablesLast.next = recurrent; - } - // Find new doablesLast - while (doablesLast.next != null) { - doablesLast = doablesLast.next; - } - } - } - // if none of the possibilities worked out, break out of do/while - if (doables == null) break; - - // reassign where the next repeat can match - newMatch = doables; - - // increment how many repeats we've successfully found - ++numRepeats; - - positions.addElement(newMatch); - } while (numRepeats < max); - - // If there aren't enough repeats, then fail - if (numRepeats < min) return false; - - // We're greedy, but ease off until a true match is found - int posIndex = positions.size(); - - // At this point we've either got too many or just the right amount. - // See if this numRepeats works with the rest of the regexp. - REMatch allResults = null; - REMatch allResultsLast = null; - - REMatch results = null; - while (--posIndex >= min) { - newMatch = (REMatch) positions.elementAt(posIndex); - results = matchRest(input, newMatch); - if (results != null) { - if (allResults == null) { - allResults = results; - allResultsLast = results; - } else { - // Order these from longest to shortest - // Start by assuming longest (more repeats) - allResultsLast.next = results; - } - // Find new doablesLast - while (allResultsLast.next != null) { - allResultsLast = allResultsLast.next; - } - } - // else did not match rest of the tokens, try again on smaller sample - // or break out when performing possessive matching - if (possessive) break; - } - if (allResults != null) { - mymatch.assignFrom(allResults); // does this get all? - return true; - } - // If we fall out, no matches. - return false; - } - - private REMatch matchRest(CharIndexed input, final REMatch newMatch) { - REMatch current, single; - REMatch doneIndex = null; - REMatch doneIndexLast = null; - // Test all possible matches for this number of repeats - for (current = newMatch; current != null; current = current.next) { - // clone() separates a single match from the chain - single = (REMatch) current.clone(); - if (next(input, single)) { - // chain results to doneIndex - if (doneIndex == null) { - doneIndex = single; - doneIndexLast = single; - } else { - doneIndexLast.next = single; - } - // Find new doneIndexLast - while (doneIndexLast.next != null) { - doneIndexLast = doneIndexLast.next; - } - } - } - return doneIndex; - } - - void dump(StringBuffer os) { - os.append("(?:"); - token.dumpAll(os); - os.append(')'); - if ((max == Integer.MAX_VALUE) && (min <= 1)) - os.append( (min == 0) ? '*' : '+' ); - else if ((min == 0) && (max == 1)) - os.append('?'); - else { - os.append('{').append(min); - if (max > min) { - os.append(','); - if (max != Integer.MAX_VALUE) os.append(max); - } - os.append('}'); - } - if (stingy) os.append('?'); - } -} diff --git a/libjava/gnu/regexp/RETokenStart.java b/libjava/gnu/regexp/RETokenStart.java deleted file mode 100644 index 8f7198237e1..00000000000 --- a/libjava/gnu/regexp/RETokenStart.java +++ /dev/null @@ -1,87 +0,0 @@ -/* gnu/regexp/RETokenStart.java - Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -class RETokenStart extends REToken { - private String newline; // matches after a newline - - RETokenStart(int subIndex, String newline) { - super(subIndex); - this.newline = newline; - } - - boolean match(CharIndexed input, REMatch mymatch) { - // charAt(index-n) may be unknown on a Reader/InputStream. FIXME - // Match after a newline if in multiline mode - - if (newline != null) { - int len = newline.length(); - if (mymatch.offset >= len) { - boolean found = true; - char z; - int i = 0; // position in REToken.newline - char ch = input.charAt(mymatch.index - len); - do { - z = newline.charAt(i); - if (ch != z) { - found = false; - break; - } - ++i; - ch = input.charAt(mymatch.index - len + i); - } while (i < len); - - if (found) return next(input, mymatch); - } - } - - // Don't match at all if REG_NOTBOL is set. - if ((mymatch.eflags & RE.REG_NOTBOL) > 0) return false; - - if ((mymatch.eflags & RE.REG_ANCHORINDEX) > 0) - return (mymatch.anchor == mymatch.offset) ? - next(input, mymatch) : false; - else - return ((mymatch.index == 0) && (mymatch.offset == 0)) ? - next(input, mymatch) : false; - } - - void dump(StringBuffer os) { - os.append('^'); - } -} diff --git a/libjava/gnu/regexp/RETokenWordBoundary.java b/libjava/gnu/regexp/RETokenWordBoundary.java deleted file mode 100644 index 6804151e261..00000000000 --- a/libjava/gnu/regexp/RETokenWordBoundary.java +++ /dev/null @@ -1,104 +0,0 @@ -/* gnu/regexp/RETokenWordBoundary.java - Copyright (C) 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.regexp; - -/** - * Represents a combination lookahead/lookbehind for POSIX [:alnum:]. - */ -final class RETokenWordBoundary extends REToken { - private boolean negated; - private int where; - static final int BEGIN = 1; - static final int END = 2; - - RETokenWordBoundary(int subIndex, int where, boolean negated) { - super(subIndex); - this.where = where; - this.negated = negated; - } - - boolean match(CharIndexed input, REMatch mymatch) { - // Word boundary means input[index-1] was a word character - // and input[index] is not, or input[index] is a word character - // and input[index-1] was not - // In the string "one two three", these positions match: - // |o|n|e| |t|w|o| |t|h|r|e|e| - // ^ ^ ^ ^ ^ ^ - boolean after = false; // is current character a letter or digit? - boolean before = false; // is previous character a letter or digit? - char ch; - - // TODO: Also check REG_ANCHORINDEX vs. anchor - if (((mymatch.eflags & RE.REG_ANCHORINDEX) != RE.REG_ANCHORINDEX) - || (mymatch.offset + mymatch.index > mymatch.anchor)) { - if ((ch = input.charAt(mymatch.index - 1)) != CharIndexed.OUT_OF_BOUNDS) { - before = Character.isLetterOrDigit(ch) || (ch == '_'); - } - } - - if ((ch = input.charAt(mymatch.index)) != CharIndexed.OUT_OF_BOUNDS) { - after = Character.isLetterOrDigit(ch) || (ch == '_'); - } - - // if (before) and (!after), we're at end (\>) - // if (after) and (!before), we're at beginning (\<) - boolean doNext = false; - - if ((where & BEGIN) == BEGIN) { - doNext = after && !before; - } - if ((where & END) == END) { - doNext ^= before && !after; - } - - if (negated) doNext = !doNext; - - return (doNext ? next(input, mymatch) : false); - } - - void dump(StringBuffer os) { - if (where == (BEGIN | END)) { - os.append( negated ? "\\B" : "\\b" ); - } else if (where == BEGIN) { - os.append("\\<"); - } else { - os.append("\\>"); - } - } -} diff --git a/libjava/gnu/regexp/UncheckedRE.java b/libjava/gnu/regexp/UncheckedRE.java deleted file mode 100644 index e6712113828..00000000000 --- a/libjava/gnu/regexp/UncheckedRE.java +++ /dev/null @@ -1,109 +0,0 @@ -/* gnu/regexp/UncheckedRE.java - Copyright (C) 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.regexp; - -/** - * UncheckedRE is a subclass of RE that allows programmers an easier means - * of programmatically precompiling regular expressions. It is constructed - * and used in exactly the same manner as an instance of the RE class; the - * only difference is that its constructors do not throw REException. - * Instead, if a syntax error is encountered during construction, a - * RuntimeException will be thrown. - * <P> - * Note that this makes UncheckedRE dangerous if constructed with - * dynamic data. Do not use UncheckedRE unless you are completely sure - * that all input being passed to it contains valid, well-formed - * regular expressions for the syntax specified. - * - * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> - * @see gnu.regexp.RE - * @since gnu.regexp 1.1.4 - */ - -public final class UncheckedRE extends RE { - /** - * Constructs a regular expression pattern buffer without any compilation - * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5). - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer or char[]. Other input types will be converted to - * strings using the toString() method. - * @exception RuntimeException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public UncheckedRE(Object pattern) { - this(pattern,0,RESyntax.RE_SYNTAX_PERL5); - } - - /** - * Constructs a regular expression pattern buffer using the specified - * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5). - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer, or char[]. Other input types will be converted to - * strings using the toString() method. - * @param cflags The logical OR of any combination of the compilation flags in the RE class. - * @exception RuntimeException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public UncheckedRE(Object pattern, int cflags) { - this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5); - } - - /** - * Constructs a regular expression pattern buffer using the specified - * compilation flags and regular expression syntax. - * - * @param pattern A regular expression pattern, in the form of a String, - * StringBuffer, or char[]. Other input types will be converted to - * strings using the toString() method. - * @param cflags The logical OR of any combination of the compilation flags in the RE class. - * @param syntax The type of regular expression syntax to use. - * @exception RuntimeException The input pattern could not be parsed. - * @exception NullPointerException The pattern was null. - */ - public UncheckedRE(Object pattern, int cflags, RESyntax syntax) { - try { - initialize(pattern,cflags,syntax,0,0); - } catch (REException e) { - throw new RuntimeException(e.getMessage()); - } - } -} - - diff --git a/libjava/gnu/xml/aelfred2/ContentHandler2.java b/libjava/gnu/xml/aelfred2/ContentHandler2.java deleted file mode 100644 index 15161383592..00000000000 --- a/libjava/gnu/xml/aelfred2/ContentHandler2.java +++ /dev/null @@ -1,65 +0,0 @@ -/* ContentHandler2.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.aelfred2; - -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; - -/** - * Extension to the SAX ContentHandler interface to report parsing events - * and parameters required by DOM Level 3 but not supported by SAX. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public interface ContentHandler2 - extends ContentHandler -{ - - /** - * Reports the XML declaration. - * @param version the value of the version attribute in the XML - * declaration - * @param encoding the encoding specified in the XML declaration, if any - * @param standalone the standalone attribute from the XML declaration - * @param inputEncoding the encoding of the XML input - */ - void xmlDecl(String version, String encoding, boolean standalone, - String inputEncoding) - throws SAXException; - -} diff --git a/libjava/gnu/xml/aelfred2/JAXPFactory.java b/libjava/gnu/xml/aelfred2/JAXPFactory.java deleted file mode 100644 index 37e8cc9c120..00000000000 --- a/libjava/gnu/xml/aelfred2/JAXPFactory.java +++ /dev/null @@ -1,231 +0,0 @@ -/* JAXPFactory.java -- - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.aelfred2; - -import java.util.Enumeration; -import java.util.Hashtable; - -import org.xml.sax.Parser; -import org.xml.sax.XMLReader; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.helpers.XMLReaderAdapter; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - - -/** - * Configurable factory to create an Ælfred2 JAXP parser; required - * to bootstrap using JAXP. You should use SAX2 directly where possible, - * rather than through JAXP, since that gives you better control. - * This class would normally be configured as a platform default factory. - * - * @author David Brownell - */ -public final class JAXPFactory - extends SAXParserFactory -{ - - private Hashtable flags = new Hashtable(); - - /** - * Constructs a factory which normally returns a non-validating - * parser. - */ - public JAXPFactory() - { - } - - public SAXParser newSAXParser() - throws ParserConfigurationException, SAXException - { - JaxpParser jaxp = new JaxpParser(); - Enumeration e = flags.keys(); - XMLReader parser = jaxp.getXMLReader(); - - parser.setFeature(SAXDriver.FEATURE + "namespaces", - isNamespaceAware()); - parser.setFeature(SAXDriver.FEATURE + "validation", - isValidating()); - // that makes SAX2 feature flags trump JAXP - - while (e.hasMoreElements()) - { - String uri = (String) e.nextElement(); - Boolean value = (Boolean) flags.get(uri); - parser.setFeature(uri, value.booleanValue()); - } - - return jaxp; - } - - // yes, this "feature transfer" mechanism doesn't play well - - public void setFeature(String name, boolean value) - throws ParserConfigurationException, SAXNotRecognizedException, - SAXNotSupportedException - { - try - { - // force "early" detection of errors where possible - // (flags can't necessarily be set before parsing) - new JaxpParser().getXMLReader().setFeature(name, value); - - flags.put(name, new Boolean(value)); - } - catch (SAXNotRecognizedException e) - { - throw new SAXNotRecognizedException(name); - } - catch (SAXNotSupportedException e) - { - throw new SAXNotSupportedException(name); - } - catch (Exception e) - { - throw new ParserConfigurationException(e.getClass().getName() - + ": " - + e.getMessage()); - } - } - - public boolean getFeature(String name) - throws ParserConfigurationException, SAXNotRecognizedException, - SAXNotSupportedException - { - Boolean value = (Boolean) flags.get(name); - - if (value != null) - { - return value.booleanValue(); - } - else - { - try - { - return new JaxpParser().getXMLReader().getFeature(name); - } - catch (SAXNotRecognizedException e) - { - throw new SAXNotRecognizedException(name); - } - catch (SAXNotSupportedException e) - { - throw new SAXNotSupportedException(name); - } - catch (SAXException e) - { - throw new ParserConfigurationException(e.getClass().getName() - + ": " - + e.getMessage()); - } - } - } - - private static class JaxpParser - extends SAXParser - { - - private XmlReader ae2 = new XmlReader(); - private XMLReaderAdapter parser = null; - - JaxpParser() - { - } - - public void setProperty(String id, Object value) - throws SAXNotRecognizedException, SAXNotSupportedException - { - ae2.setProperty(id, value); - } - - public Object getProperty(String id) - throws SAXNotRecognizedException, SAXNotSupportedException - { - return ae2.getProperty(id); - } - - public Parser getParser() - throws SAXException - { - if (parser == null) - { - parser = new XMLReaderAdapter(ae2); - } - return parser; - } - - public XMLReader getXMLReader () - throws SAXException - { - return ae2; - } - - public boolean isNamespaceAware() - { - try - { - return ae2.getFeature(SAXDriver.FEATURE + "namespaces"); - } - catch (Exception e) - { - throw new Error(); - } - } - - public boolean isValidating() - { - try - { - return ae2.getFeature(SAXDriver.FEATURE + "validation"); - } - catch (Exception e) - { - throw new Error(); - } - } - - // TODO isXIncludeAware() - - } - -} - diff --git a/libjava/gnu/xml/aelfred2/SAXDriver.java b/libjava/gnu/xml/aelfred2/SAXDriver.java deleted file mode 100644 index 7e950ce042a..00000000000 --- a/libjava/gnu/xml/aelfred2/SAXDriver.java +++ /dev/null @@ -1,1622 +0,0 @@ -/* SAXDriver.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. - -Portions derived from code which carried the following notice: - - Copyright (c) 1997, 1998 by Microstar Software Ltd. - - AElfred is free for both commercial and non-commercial use and - redistribution, provided that Microstar's copyright and disclaimer are - retained intact. You are free to modify AElfred for your own use and - to redistribute AElfred with your modifications, provided that the - modifications are clearly documented. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - merchantability or fitness for a particular purpose. Please use it AT - YOUR OWN RISK. -*/ - -package gnu.xml.aelfred2; - -import java.io.*; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Locale; -import java.util.Stack; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; - -import org.xml.sax.*; -import org.xml.sax.ext.*; -import org.xml.sax.helpers.NamespaceSupport; - - -/** - * An enhanced SAX2 version of Microstar's Ælfred XML parser. - * The enhancements primarily relate to significant improvements in - * conformance to the XML specification, and SAX2 support. Performance - * has been improved. See the package level documentation for more - * information. - * - * <table border="1" width='100%' cellpadding='3' cellspacing='0'> - * <tr bgcolor='#ccccff'> - * <th><font size='+1'>Name</font></th> - * <th><font size='+1'>Notes</font></th></tr> - * - * <tr><td colspan=2><center><em>Features ... URL prefix is - * <b>http://xml.org/sax/features/</b></em></center></td></tr> - * - * <tr><td>(URL)/external-general-entities</td> - * <td>Value defaults to <em>true</em></td></tr> - * <tr><td>(URL)/external-parameter-entities</td> - * <td>Value defaults to <em>true</em></td></tr> - * <tr><td>(URL)/is-standalone</td> - * <td>(PRELIMINARY) Returns true iff the document's parsing - * has started (some non-error event after <em>startDocument()</em> - * was reported) and the document's standalone flag is set.</td></tr> - * <tr><td>(URL)/namespace-prefixes</td> - * <td>Value defaults to <em>false</em> (but XML 1.0 names are - * always reported)</td></tr> - * <tr><td>(URL)/lexical-handler/parameter-entities</td> - * <td>Value is fixed at <em>true</em></td></tr> - * <tr><td>(URL)/namespaces</td> - * <td>Value defaults to <em>true</em></td></tr> - * <tr><td>(URL)/resolve-dtd-uris</td> - * <td>(PRELIMINARY) Value defaults to <em>true</em></td></tr> - * <tr><td>(URL)/string-interning</td> - * <td>Value is fixed at <em>true</em></td></tr> - * <tr><td>(URL)/use-attributes2</td> - * <td>(PRELIMINARY) Value is fixed at <em>true</em></td></tr> - * <tr><td>(URL)/use-entity-resolver2</td> - * <td>(PRELIMINARY) Value defaults to <em>true</em></td></tr> - * <tr><td>(URL)/validation</td> - * <td>Value is fixed at <em>false</em></td></tr> - * - * <tr><td colspan=2><center><em>Handler Properties ... URL prefix is - * <b>http://xml.org/sax/properties/</b></em></center></td></tr> - * - * <tr><td>(URL)/declaration-handler</td> - * <td>A declaration handler may be provided. </td></tr> - * <tr><td>(URL)/lexical-handler</td> - * <td>A lexical handler may be provided. </td></tr> - * </table> - * - * <p>This parser currently implements the SAX1 Parser API, but - * it may not continue to do so in the future. - * - * @author Written by David Megginson (version 1.2a from Microstar) - * @author Updated by David Brownell <dbrownell@users.sourceforge.net> - * @see org.xml.sax.Parser - */ -final public class SAXDriver - implements Locator, Attributes2, XMLReader, Parser, AttributeList -{ - - private final DefaultHandler2 base = new DefaultHandler2(); - private XmlParser parser; - - private EntityResolver entityResolver = base; - private EntityResolver2 resolver2 = null; - private ContentHandler contentHandler = base; - private DTDHandler dtdHandler = base; - private ErrorHandler errorHandler = base; - private DeclHandler declHandler = base; - private LexicalHandler lexicalHandler = base; - - private String elementName; - private Stack entityStack; - - // one vector (of object/struct): faster, smaller - private List attributesList; - - private boolean namespaces = true; - private boolean xmlNames = false; - private boolean extGE = true; - private boolean extPE = true; - private boolean resolveAll = true; - private boolean useResolver2 = true; - - // package private to allow (read-only) access in XmlParser - boolean stringInterning = true; - - private int attributeCount; - private boolean attributes; - private String[] nsTemp; - private NamespaceSupport prefixStack; - - // - // Constructor. - // - - /** - * Constructs a SAX Parser. - */ - public SAXDriver() - { - reset(); - } - - private void reset() - { - elementName = null; - entityStack = new Stack(); - attributesList = Collections.synchronizedList(new ArrayList()); - attributeCount = 0; - attributes = false; - nsTemp = new String[3]; - prefixStack = null; - } - - - // - // Implementation of org.xml.sax.Parser. - // - - /** - * <b>SAX1</b>: Sets the locale used for diagnostics; currently, - * only locales using the English language are supported. - * @param locale The locale for which diagnostics will be generated - */ - public void setLocale(Locale locale) - throws SAXException - { - if ("en".equals(locale.getLanguage())) - { - return; - } - throw new SAXException ("AElfred2 only supports English locales."); - } - - /** - * <b>SAX2</b>: Returns the object used when resolving external - * entities during parsing (both general and parameter entities). - */ - public EntityResolver getEntityResolver() - { - return (entityResolver == base) ? null : entityResolver; - } - - /** - * <b>SAX1, SAX2</b>: Set the entity resolver for this parser. - * @param handler The object to receive entity events. - */ - public void setEntityResolver(EntityResolver resolver) - { - if (resolver instanceof EntityResolver2) - { - resolver2 = (EntityResolver2) resolver; - } - else - { - resolver2 = null; - } - if (resolver == null) - { - resolver = base; - } - entityResolver = resolver; - } - - /** - * <b>SAX2</b>: Returns the object used to process declarations related - * to notations and unparsed entities. - */ - public DTDHandler getDTDHandler() - { - return (dtdHandler == base) ? null : dtdHandler; - } - - /** - * <b>SAX1, SAX2</b>: Set the DTD handler for this parser. - * @param handler The object to receive DTD events. - */ - public void setDTDHandler(DTDHandler handler) - { - if (handler == null) - { - handler = base; - } - this.dtdHandler = handler; - } - - - /** - * <b>SAX1</b>: Set the document handler for this parser. If a - * content handler was set, this document handler will supplant it. - * The parser is set to report all XML 1.0 names rather than to - * filter out "xmlns" attributes (the "namespace-prefixes" feature - * is set to true). - * - * @deprecated SAX2 programs should use the XMLReader interface - * and a ContentHandler. - * - * @param handler The object to receive document events. - */ - public void setDocumentHandler(DocumentHandler handler) - { - contentHandler = new Adapter(handler); - xmlNames = true; - } - - /** - * <b>SAX2</b>: Returns the object used to report the logical - * content of an XML document. - */ - public ContentHandler getContentHandler() - { - return (contentHandler == base) ? null : contentHandler; - } - - /** - * <b>SAX2</b>: Assigns the object used to report the logical - * content of an XML document. If a document handler was set, - * this content handler will supplant it (but XML 1.0 style name - * reporting may remain enabled). - */ - public void setContentHandler(ContentHandler handler) - { - if (handler == null) - { - handler = base; - } - contentHandler = handler; - } - - /** - * <b>SAX1, SAX2</b>: Set the error handler for this parser. - * @param handler The object to receive error events. - */ - public void setErrorHandler(ErrorHandler handler) - { - if (handler == null) - { - handler = base; - } - this.errorHandler = handler; - } - - /** - * <b>SAX2</b>: Returns the object used to receive callbacks for XML - * errors of all levels (fatal, nonfatal, warning); this is never null; - */ - public ErrorHandler getErrorHandler() - { - return (errorHandler == base) ? null : errorHandler; - } - - /** - * <b>SAX1, SAX2</b>: Auxiliary API to parse an XML document, used mostly - * when no URI is available. - * If you want anything useful to happen, you should set - * at least one type of handler. - * @param source The XML input source. Don't set 'encoding' unless - * you know for a fact that it's correct. - * @see #setEntityResolver - * @see #setDTDHandler - * @see #setContentHandler - * @see #setErrorHandler - * @exception SAXException The handlers may throw any SAXException, - * and the parser normally throws SAXParseException objects. - * @exception IOException IOExceptions are normally through through - * the parser if there are problems reading the source document. - */ - public void parse(InputSource source) - throws SAXException, IOException - { - synchronized (base) - { - parser = new XmlParser(); - if (namespaces) - { - prefixStack = new NamespaceSupport(); - } - else if (!xmlNames) - { - throw new IllegalStateException(); - } - parser.setHandler(this); - - try - { - Reader r = source.getCharacterStream(); - InputStream in = source.getByteStream(); - - parser.doParse(source.getSystemId(), - source.getPublicId(), - r, - in, - source.getEncoding()); - } - catch (SAXException e) - { - throw e; - } - catch (IOException e) - { - throw e; - } - catch (RuntimeException e) - { - throw e; - } - catch (Exception e) - { - throw new SAXParseException(e.getMessage(), this, e); - } - finally - { - contentHandler.endDocument(); - reset(); - } - } - } - - /** - * <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a - * system identifier (URI). - */ - public void parse(String systemId) - throws SAXException, IOException - { - parse(new InputSource(systemId)); - } - - // - // Implementation of SAX2 "XMLReader" interface - // - static final String FEATURE = "http://xml.org/sax/features/"; - static final String PROPERTY = "http://xml.org/sax/properties/"; - - /** - * <b>SAX2</b>: Tells the value of the specified feature flag. - * - * @exception SAXNotRecognizedException thrown if the feature flag - * is neither built in, nor yet assigned. - */ - public boolean getFeature(String featureId) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if ((FEATURE + "validation").equals(featureId)) - { - return false; - } - - // external entities (both types) are optionally included - if ((FEATURE + "external-general-entities").equals(featureId)) - { - return extGE; - } - if ((FEATURE + "external-parameter-entities").equals(featureId)) - { - return extPE; - } - - // element/attribute names are as written in document; no mangling - if ((FEATURE + "namespace-prefixes").equals(featureId)) - { - return xmlNames; - } - - // report element/attribute namespaces? - if ((FEATURE + "namespaces").equals(featureId)) - { - return namespaces; - } - - // all PEs and GEs are reported - if ((FEATURE + "lexical-handler/parameter-entities").equals(featureId)) - { - return true; - } - - // default is true - if ((FEATURE + "string-interning").equals(featureId)) - { - return stringInterning; - } - - // EXTENSIONS 1.1 - - // always returns isSpecified info - if ((FEATURE + "use-attributes2").equals(featureId)) - { - return true; - } - - // meaningful between startDocument/endDocument - if ((FEATURE + "is-standalone").equals(featureId)) - { - if (parser == null) - { - throw new SAXNotSupportedException(featureId); - } - return parser.isStandalone(); - } - - // optionally don't absolutize URIs in declarations - if ((FEATURE + "resolve-dtd-uris").equals(featureId)) - { - return resolveAll; - } - - // optionally use resolver2 interface methods, if possible - if ((FEATURE + "use-entity-resolver2").equals(featureId)) - { - return useResolver2; - } - - throw new SAXNotRecognizedException(featureId); - } - - // package private - DeclHandler getDeclHandler() - { - return declHandler; - } - - // package private - boolean resolveURIs() - { - return resolveAll; - } - - /** - * <b>SAX2</b>: Returns the specified property. - * - * @exception SAXNotRecognizedException thrown if the property value - * is neither built in, nor yet stored. - */ - public Object getProperty(String propertyId) - throws SAXNotRecognizedException - { - if ((PROPERTY + "declaration-handler").equals(propertyId)) - { - return (declHandler == base) ? null : declHandler; - } - - if ((PROPERTY + "lexical-handler").equals(propertyId)) - { - return (lexicalHandler == base) ? null : lexicalHandler; - } - - // unknown properties - throw new SAXNotRecognizedException(propertyId); - } - - /** - * <b>SAX2</b>: Sets the state of feature flags in this parser. Some - * built-in feature flags are mutable. - */ - public void setFeature(String featureId, boolean value) - throws SAXNotRecognizedException, SAXNotSupportedException - { - boolean state; - - // Features with a defined value, we just change it if we can. - state = getFeature (featureId); - - if (state == value) - { - return; - } - if (parser != null) - { - throw new SAXNotSupportedException("not while parsing"); - } - - if ((FEATURE + "namespace-prefixes").equals(featureId)) - { - // in this implementation, this only affects xmlns reporting - xmlNames = value; - // forcibly prevent illegal parser state - if (!xmlNames) - { - namespaces = true; - } - return; - } - - if ((FEATURE + "namespaces").equals(featureId)) - { - namespaces = value; - // forcibly prevent illegal parser state - if (!namespaces) - { - xmlNames = true; - } - return; - } - - if ((FEATURE + "external-general-entities").equals(featureId)) - { - extGE = value; - return; - } - if ((FEATURE + "external-parameter-entities").equals(featureId)) - { - extPE = value; - return; - } - if ((FEATURE + "resolve-dtd-uris").equals(featureId)) - { - resolveAll = value; - return; - } - - if ((FEATURE + "use-entity-resolver2").equals(featureId)) - { - useResolver2 = value; - return; - } - - throw new SAXNotRecognizedException(featureId); - } - - /** - * <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers, - * these may be changed at any time. - */ - public void setProperty(String propertyId, Object value) - throws SAXNotRecognizedException, SAXNotSupportedException - { - // see if the property is recognized - getProperty(propertyId); - - // Properties with a defined value, we just change it if we can. - - if ((PROPERTY + "declaration-handler").equals(propertyId)) - { - if (value == null) - { - declHandler = base; - } - else if (!(value instanceof DeclHandler)) - { - throw new SAXNotSupportedException(propertyId); - } - else - { - declHandler = (DeclHandler) value; - } - return ; - } - - if ((PROPERTY + "lexical-handler").equals(propertyId)) - { - if (value == null) - { - lexicalHandler = base; - } - else if (!(value instanceof LexicalHandler)) - { - throw new SAXNotSupportedException(propertyId); - } - else - { - lexicalHandler = (LexicalHandler) value; - } - return; - } - - throw new SAXNotSupportedException(propertyId); - } - - // - // This is where the driver receives XmlParser callbacks and translates - // them into SAX callbacks. Some more callbacks have been added for - // SAX2 support. - // - - void startDocument() - throws SAXException - { - contentHandler.setDocumentLocator(this); - contentHandler.startDocument(); - attributesList.clear(); - } - - void xmlDecl(String version, - String encoding, - boolean standalone, - String inputEncoding) - throws SAXException - { - if (contentHandler instanceof ContentHandler2) - { - ((ContentHandler2) contentHandler).xmlDecl(version, - encoding, - standalone, - inputEncoding); - } - } - - void skippedEntity(String name) - throws SAXException - { - contentHandler.skippedEntity(name); - } - - InputSource getExternalSubset(String name, String baseURI) - throws SAXException, IOException - { - if (resolver2 == null || !useResolver2 || !extPE) - { - return null; - } - return resolver2.getExternalSubset(name, baseURI); - } - - InputSource resolveEntity(boolean isPE, String name, - InputSource in, String baseURI) - throws SAXException, IOException - { - InputSource source; - - // external entities might be skipped - if (isPE && !extPE) - { - return null; - } - if (!isPE && !extGE) - { - return null; - } - - // ... or not - lexicalHandler.startEntity(name); - if (resolver2 != null && useResolver2) - { - source = resolver2.resolveEntity(name, in.getPublicId(), - baseURI, in.getSystemId()); - if (source == null) - { - in.setSystemId(absolutize(baseURI, - in.getSystemId(), false)); - source = in; - } - } - else - { - in.setSystemId(absolutize(baseURI, in.getSystemId(), false)); - source = entityResolver.resolveEntity(in.getPublicId(), - in.getSystemId()); - if (source == null) - { - source = in; - } - } - startExternalEntity(name, source.getSystemId(), true); - return source; - } - - // absolutize a system ID relative to the specified base URI - // (temporarily) package-visible for external entity decls - String absolutize(String baseURI, String systemId, boolean nice) - throws MalformedURLException, SAXException - { - // FIXME normalize system IDs -- when? - // - Convert to UTF-8 - // - Map reserved and non-ASCII characters to %HH - - try - { - if (baseURI == null) - { - if (XmlParser.uriWarnings) - { - warn ("No base URI; hope this SYSTEM id is absolute: " - + systemId); - } - return new URL(systemId).toString(); - } - else - { - return new URL(new URL(baseURI), systemId).toString(); - } - } - catch (MalformedURLException e) - { - // Let unknown URI schemes pass through unless we need - // the JVM to map them to i/o streams for us... - if (!nice) - { - throw e; - } - - // sometimes sysids for notations or unparsed entities - // aren't really URIs... - warn("Can't absolutize SYSTEM id: " + e.getMessage()); - return systemId; - } - } - - void startExternalEntity(String name, String systemId, boolean stackOnly) - throws SAXException - { - // The following warning was deleted because the application has the - // option of not setting systemId. Sun's JAXP or Xerces seems to - // ignore this case. - /* - if (systemId == null) - warn ("URI was not reported to parser for entity " + name); - */ - if (!stackOnly) // spliced [dtd] needs startEntity - { - lexicalHandler.startEntity(name); - } - entityStack.push(systemId); - } - - void endExternalEntity(String name) - throws SAXException - { - if (!"[document]".equals(name)) - { - lexicalHandler.endEntity(name); - } - entityStack.pop(); - } - - void startInternalEntity(String name) - throws SAXException - { - lexicalHandler.startEntity(name); - } - - void endInternalEntity(String name) - throws SAXException - { - lexicalHandler.endEntity(name); - } - - void doctypeDecl(String name, String publicId, String systemId) - throws SAXException - { - lexicalHandler.startDTD(name, publicId, systemId); - - // ... the "name" is a declaration and should be given - // to the DeclHandler (but sax2 doesn't). - - // the IDs for the external subset are lexical details, - // as are the contents of the internal subset; but sax2 - // doesn't provide the internal subset "pre-parse" - } - - void notationDecl(String name, String publicId, String systemId, - String baseUri) - throws SAXException - { - try - { - dtdHandler.notationDecl(name, publicId, - (resolveAll && systemId != null) - ? absolutize(baseUri, systemId, true) - : systemId); - } - catch (IOException e) - { - // "can't happen" - throw new SAXParseException(e.getMessage(), this, e); - } - } - - void unparsedEntityDecl(String name, String publicId, String systemId, - String baseUri, String notation) - throws SAXException - { - try - { - dtdHandler.unparsedEntityDecl(name, publicId, - resolveAll - ? absolutize(baseUri, systemId, true) - : systemId, - notation); - } - catch (IOException e) - { - // "can't happen" - throw new SAXParseException(e.getMessage(), this, e); - } - } - - void endDoctype() - throws SAXException - { - lexicalHandler.endDTD(); - } - - private void declarePrefix(String prefix, String uri) - throws SAXException - { - int index = uri.indexOf(':'); - - // many versions of nwalsh docbook stylesheets - // have bogus URLs; so this can't be an error... - if (index < 1 && uri.length() != 0) - { - warn("relative URI for namespace: " + uri); - } - - // FIXME: char [0] must be ascii alpha; chars [1..index] - // must be ascii alphanumeric or in "+-." [RFC 2396] - - //Namespace Constraints - //name for xml prefix must be http://www.w3.org/XML/1998/namespace - boolean prefixEquality = prefix.equals("xml"); - boolean uriEquality = uri.equals("http://www.w3.org/XML/1998/namespace"); - if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) - { - fatal("xml is by definition bound to the namespace name " + - "http://www.w3.org/XML/1998/namespace"); - } - - //xmlns prefix declaration is illegal but xml prefix declaration is llegal... - if (prefixEquality && uriEquality) - { - return; - } - - //name for xmlns prefix must be http://www.w3.org/2000/xmlns/ - prefixEquality = prefix.equals("xmlns"); - uriEquality = uri.equals("http://www.w3.org/2000/xmlns/"); - if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) - { - fatal("http://www.w3.org/2000/xmlns/ is by definition bound" + - " to prefix xmlns"); - } - - //even if the uri is http://www.w3.org/2000/xmlns/ - // it is illegal to declare it - if (prefixEquality && uriEquality) - { - fatal ("declaring the xmlns prefix is illegal"); - } - - uri = uri.intern(); - prefixStack.declarePrefix(prefix, uri); - contentHandler.startPrefixMapping(prefix, uri); - } - - void attribute(String qname, String value, boolean isSpecified) - throws SAXException - { - if (!attributes) - { - attributes = true; - if (namespaces) - { - prefixStack.pushContext(); - } - } - - // process namespace decls immediately; - // then maybe forget this as an attribute - if (namespaces) - { - int index; - - // default NS declaration? - if (stringInterning) - { - if ("xmlns" == qname) - { - declarePrefix("", value); - if (!xmlNames) - { - return; - } - } - // NS prefix declaration? - else if ((index = qname.indexOf(':')) == 5 - && qname.startsWith("xmlns")) - { - String prefix = qname.substring(6); - - if (prefix.equals("")) - { - fatal("missing prefix " + - "in namespace declaration attribute"); - } - if (value.length() == 0) - { - verror("missing URI in namespace declaration attribute: " - + qname); - } - else - { - declarePrefix(prefix, value); - } - if (!xmlNames) - { - return; - } - } - } - else - { - if ("xmlns".equals(qname)) - { - declarePrefix("", value); - if (!xmlNames) - { - return; - } - } - // NS prefix declaration? - else if ((index = qname.indexOf(':')) == 5 - && qname.startsWith("xmlns")) - { - String prefix = qname.substring(6); - - if (value.length() == 0) - { - verror("missing URI in namespace decl attribute: " - + qname); - } - else - { - declarePrefix(prefix, value); - } - if (!xmlNames) - { - return; - } - } - } - } - // remember this attribute ... - attributeCount++; - - // attribute type comes from querying parser's DTD records - attributesList.add(new Attribute(qname, value, isSpecified)); - - } - - void startElement(String elname) - throws SAXException - { - ContentHandler handler = contentHandler; - - // - // NOTE: this implementation of namespace support adds something - // like six percent to parsing CPU time, in a large (~50 MB) - // document that doesn't use namespaces at all. (Measured by PC - // sampling, with a bug where endElement processing was omitted.) - // [Measurement referred to older implementation, older JVM ...] - // - // It ought to become notably faster in such cases. Most - // costs are the prefix stack calling Hashtable.get() (2%), - // String.hashCode() (1.5%) and about 1.3% each for pushing - // the context, and two chunks of name processing. - // - - if (!attributes) - { - if (namespaces) - { - prefixStack.pushContext(); - } - } - else if (namespaces) - { - - // now we can patch up namespace refs; we saw all the - // declarations, so now we'll do the Right Thing - Iterator itt = attributesList.iterator(); - while (itt.hasNext()) - { - Attribute attribute = (Attribute) itt.next(); - String qname = attribute.name; - int index; - - // default NS declaration? - if (stringInterning) - { - if ("xmlns" == qname) - { - continue; - } - } - else - { - if ("xmlns".equals(qname)) - { - continue; - } - } - //Illegal in the new Namespaces Draft - //should it be only in 1.1 docs?? - if (qname.equals (":")) - { - fatal("namespace names consisting of a single colon " + - "character are invalid"); - } - index = qname.indexOf(':'); - - // NS prefix declaration? - if (index == 5 && qname.startsWith("xmlns")) - { - continue; - } - - // it's not a NS decl; patch namespace info items - if (prefixStack.processName(qname, nsTemp, true) == null) - { - fatal("undeclared attribute prefix in: " + qname); - } - else - { - attribute.nameSpace = nsTemp[0]; - attribute.localName = nsTemp[1]; - } - } - } - - // save element name so attribute callbacks work - elementName = elname; - if (namespaces) - { - if (prefixStack.processName(elname, nsTemp, false) == null) - { - fatal("undeclared element prefix in: " + elname); - nsTemp[0] = nsTemp[1] = ""; - } - handler.startElement(nsTemp[0], nsTemp[1], elname, this); - } - else - { - handler.startElement("", "", elname, this); - } - // elementName = null; - - // elements with no attributes are pretty common! - if (attributes) - { - attributesList.clear(); - attributeCount = 0; - attributes = false; - } - } - - void endElement(String elname) - throws SAXException - { - ContentHandler handler = contentHandler; - - if (!namespaces) - { - handler.endElement("", "", elname); - return; - } - prefixStack.processName(elname, nsTemp, false); - handler.endElement(nsTemp[0], nsTemp[1], elname); - - Enumeration prefixes = prefixStack.getDeclaredPrefixes(); - - while (prefixes.hasMoreElements()) - { - handler.endPrefixMapping((String) prefixes.nextElement()); - } - prefixStack.popContext(); - } - - void startCDATA() - throws SAXException - { - lexicalHandler.startCDATA(); - } - - void charData(char[] ch, int start, int length) - throws SAXException - { - contentHandler.characters(ch, start, length); - } - - void endCDATA() - throws SAXException - { - lexicalHandler.endCDATA(); - } - - void ignorableWhitespace(char[] ch, int start, int length) - throws SAXException - { - contentHandler.ignorableWhitespace(ch, start, length); - } - - void processingInstruction(String target, String data) - throws SAXException - { - contentHandler.processingInstruction(target, data); - } - - void comment(char[] ch, int start, int length) - throws SAXException - { - if (lexicalHandler != base) - { - lexicalHandler.comment(ch, start, length); - } - } - - void fatal(String message) - throws SAXException - { - SAXParseException fatal; - - fatal = new SAXParseException(message, this); - errorHandler.fatalError(fatal); - - // Even if the application can continue ... we can't! - throw fatal; - } - - // We can safely report a few validity errors that - // make layered SAX2 DTD validation more conformant - void verror(String message) - throws SAXException - { - SAXParseException err; - - err = new SAXParseException(message, this); - errorHandler.error(err); - } - - void warn(String message) - throws SAXException - { - SAXParseException err; - - err = new SAXParseException(message, this); - errorHandler.warning(err); - } - - // - // Implementation of org.xml.sax.Attributes. - // - - /** - * <b>SAX1 AttributeList, SAX2 Attributes</b> method - * (don't invoke on parser); - */ - public int getLength() - { - return attributesList.size(); - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public String getURI(int index) - { - if (index < 0 || index >= attributesList.size()) - { - return null; - } - return ((Attribute) attributesList.get(index)).nameSpace; - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public String getLocalName(int index) - { - if (index < 0 || index >= attributesList.size()) - { - return null; - } - Attribute attr = (Attribute) attributesList.get(index); - // FIXME attr.localName is sometimes null, why? - if (namespaces && attr.localName == null) - { - // XXX fix this here for now - int ci = attr.name.indexOf(':'); - attr.localName = (ci == -1) ? attr.name : - attr.name.substring(ci + 1); - } - return (attr.localName == null) ? "" : attr.localName; - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public String getQName(int index) - { - if (index < 0 || index >= attributesList.size()) - { - return null; - } - Attribute attr = (Attribute) attributesList.get(index); - return (attr.name == null) ? "" : attr.name; - } - - /** - * <b>SAX1 AttributeList</b> method (don't invoke on parser); - */ - public String getName(int index) - { - return getQName(index); - } - - /** - * <b>SAX1 AttributeList, SAX2 Attributes</b> method - * (don't invoke on parser); - */ - public String getType(int index) - { - if (index < 0 || index >= attributesList.size()) - { - return null; - } - String type = parser.getAttributeType(elementName, getQName(index)); - if (type == null) - { - return "CDATA"; - } - // ... use DeclHandler.attributeDecl to see enumerations - if (type == "ENUMERATION") - { - return "NMTOKEN"; - } - return type; - } - - /** - * <b>SAX1 AttributeList, SAX2 Attributes</b> method - * (don't invoke on parser); - */ - public String getValue(int index) - { - if (index < 0 || index >= attributesList.size()) - { - return null; - } - return ((Attribute) attributesList.get(index)).value; - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public int getIndex(String uri, String local) - { - int length = getLength(); - - for (int i = 0; i < length; i++) - { - if (!getURI(i).equals(uri)) - { - continue; - } - if (getLocalName(i).equals(local)) - { - return i; - } - } - return -1; - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public int getIndex(String xmlName) - { - int length = getLength(); - - for (int i = 0; i < length; i++) - { - if (getQName(i).equals(xmlName)) - { - return i; - } - } - return -1; - } - - /** - * <b>SAX2 Attributes</b> method (don't invoke on parser); - */ - public String getType(String uri, String local) - { - int index = getIndex(uri, local); - - if (index < 0) - { - return null; - } - return getType(index); - } - - /** - * <b>SAX1 AttributeList, SAX2 Attributes</b> method - * (don't invoke on parser); - */ - public String getType(String xmlName) - { - int index = getIndex(xmlName); - - if (index < 0) - { - return null; - } - return getType(index); - } - - /** - * <b>SAX Attributes</b> method (don't invoke on parser); - */ - public String getValue(String uri, String local) - { - int index = getIndex(uri, local); - - if (index < 0) - { - return null; - } - return getValue(index); - } - - /** - * <b>SAX1 AttributeList, SAX2 Attributes</b> method - * (don't invoke on parser); - */ - public String getValue(String xmlName) - { - int index = getIndex(xmlName); - - if (index < 0) - { - return null; - } - return getValue(index); - } - - // - // Implementation of org.xml.sax.ext.Attributes2 - // - - /** @return false unless the attribute was declared in the DTD. - * @throws java.lang.ArrayIndexOutOfBoundsException - * When the supplied index does not identify an attribute. - */ - public boolean isDeclared(int index) - { - if (index < 0 || index >= attributeCount) - { - throw new ArrayIndexOutOfBoundsException(); - } - String type = parser.getAttributeType(elementName, getQName(index)); - return (type != null); - } - - /** @return false unless the attribute was declared in the DTD. - * @throws java.lang.IllegalArgumentException - * When the supplied names do not identify an attribute. - */ - public boolean isDeclared(String qName) - { - int index = getIndex(qName); - if (index < 0) - { - throw new IllegalArgumentException(); - } - String type = parser.getAttributeType(elementName, qName); - return (type != null); - } - - /** @return false unless the attribute was declared in the DTD. - * @throws java.lang.IllegalArgumentException - * When the supplied names do not identify an attribute. - */ - public boolean isDeclared(String uri, String localName) - { - int index = getIndex(uri, localName); - return isDeclared(index); - } - - /** - * <b>SAX-ext Attributes2</b> method (don't invoke on parser); - */ - public boolean isSpecified(int index) - { - return ((Attribute) attributesList.get(index)).specified; - } - - /** - * <b>SAX-ext Attributes2</b> method (don't invoke on parser); - */ - public boolean isSpecified(String uri, String local) - { - int index = getIndex (uri, local); - return isSpecified(index); - } - - /** - * <b>SAX-ext Attributes2</b> method (don't invoke on parser); - */ - public boolean isSpecified(String xmlName) - { - int index = getIndex (xmlName); - return isSpecified(index); - } - - // - // Implementation of org.xml.sax.Locator. - // - - /** - * <b>SAX Locator</b> method (don't invoke on parser); - */ - public String getPublicId() - { - return null; // FIXME track public IDs too - } - - /** - * <b>SAX Locator</b> method (don't invoke on parser); - */ - public String getSystemId() - { - if (entityStack.empty()) - { - return null; - } - else - { - return (String) entityStack.peek(); - } - } - - /** - * <b>SAX Locator</b> method (don't invoke on parser); - */ - public int getLineNumber() - { - return parser.getLineNumber(); - } - - /** - * <b>SAX Locator</b> method (don't invoke on parser); - */ - public int getColumnNumber() - { - return parser.getColumnNumber(); - } - - // adapter between SAX2 content handler and SAX1 document handler callbacks - private static class Adapter - implements ContentHandler - { - - private DocumentHandler docHandler; - - Adapter(DocumentHandler dh) - { - docHandler = dh; - } - - public void setDocumentLocator(Locator l) - { - docHandler.setDocumentLocator(l); - } - - public void startDocument() - throws SAXException - { - docHandler.startDocument(); - } - - public void processingInstruction(String target, String data) - throws SAXException - { - docHandler.processingInstruction(target, data); - } - - public void startPrefixMapping(String prefix, String uri) - { - /* ignored */ - } - - public void startElement(String namespace, - String local, - String name, - Attributes attrs) - throws SAXException - { - docHandler.startElement(name, (AttributeList) attrs); - } - - public void characters(char[] buf, int offset, int len) - throws SAXException - { - docHandler.characters(buf, offset, len); - } - - public void ignorableWhitespace(char[] buf, int offset, int len) - throws SAXException - { - docHandler.ignorableWhitespace(buf, offset, len); - } - - public void skippedEntity(String name) - { - /* ignored */ - } - - public void endElement(String u, String l, String name) - throws SAXException - { - docHandler.endElement(name); - } - - public void endPrefixMapping(String prefix) - { - /* ignored */ - } - - public void endDocument() - throws SAXException - { - docHandler.endDocument(); - } - } - - private static class Attribute - { - - String name; - String value; - String nameSpace; - String localName; - boolean specified; - - Attribute(String name, String value, boolean specified) - { - this.name = name; - this.value = value; - this.nameSpace = ""; - this.specified = specified; - } - - } - -} diff --git a/libjava/gnu/xml/aelfred2/XmlParser.java b/libjava/gnu/xml/aelfred2/XmlParser.java deleted file mode 100644 index 15d730ff4a7..00000000000 --- a/libjava/gnu/xml/aelfred2/XmlParser.java +++ /dev/null @@ -1,5835 +0,0 @@ -/* XmlParser.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. - -Partly derived from code which carried the following notice: - - Copyright (c) 1997, 1998 by Microstar Software Ltd. - - AElfred is free for both commercial and non-commercial use and - redistribution, provided that Microstar's copyright and disclaimer are - retained intact. You are free to modify AElfred for your own use and - to redistribute AElfred with your modifications, provided that the - modifications are clearly documented. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - merchantability or fitness for a particular purpose. Please use it AT - YOUR OWN RISK. -*/ - -package gnu.xml.aelfred2; - -import gnu.java.security.action.GetPropertyAction; - -import java.io.BufferedInputStream; -import java.io.CharConversionException; -import java.io.EOFException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.IOException; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLConnection; -import java.security.AccessController; - -import java.util.Iterator; -import java.util.HashMap; -import java.util.LinkedList; - -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - - -/** - * Parse XML documents and return parse events through call-backs. - * Use the <code>SAXDriver</code> class as your entry point, as all - * internal parser interfaces are subject to change. - * - * @author Written by David Megginson <dmeggins@microstar.com> - * (version 1.2a with bugfixes) - * @author Updated by David Brownell <dbrownell@users.sourceforge.net> - * @see SAXDriver - */ -final class XmlParser -{ - - // avoid slow per-character readCh() - private final static boolean USE_CHEATS = true; - - //////////////////////////////////////////////////////////////////////// - // Constants. - //////////////////////////////////////////////////////////////////////// - - // - // Constants for element content type. - // - - /** - * Constant: an element has not been declared. - * @see #getElementContentType - */ - public final static int CONTENT_UNDECLARED = 0; - - /** - * Constant: the element has a content model of ANY. - * @see #getElementContentType - */ - public final static int CONTENT_ANY = 1; - - /** - * Constant: the element has declared content of EMPTY. - * @see #getElementContentType - */ - public final static int CONTENT_EMPTY = 2; - - /** - * Constant: the element has mixed content. - * @see #getElementContentType - */ - public final static int CONTENT_MIXED = 3; - - /** - * Constant: the element has element content. - * @see #getElementContentType - */ - public final static int CONTENT_ELEMENTS = 4; - - - // - // Constants for the entity type. - // - - /** - * Constant: the entity has not been declared. - * @see #getEntityType - */ - public final static int ENTITY_UNDECLARED = 0; - - /** - * Constant: the entity is internal. - * @see #getEntityType - */ - public final static int ENTITY_INTERNAL = 1; - - /** - * Constant: the entity is external, non-parsable data. - * @see #getEntityType - */ - public final static int ENTITY_NDATA = 2; - - /** - * Constant: the entity is external XML data. - * @see #getEntityType - */ - public final static int ENTITY_TEXT = 3; - - // - // Attribute type constants are interned literal strings. - // - - // - // Constants for supported encodings. "external" is just a flag. - // - private final static int ENCODING_EXTERNAL = 0; - private final static int ENCODING_UTF_8 = 1; - private final static int ENCODING_ISO_8859_1 = 2; - private final static int ENCODING_UCS_2_12 = 3; - private final static int ENCODING_UCS_2_21 = 4; - private final static int ENCODING_UCS_4_1234 = 5; - private final static int ENCODING_UCS_4_4321 = 6; - private final static int ENCODING_UCS_4_2143 = 7; - private final static int ENCODING_UCS_4_3412 = 8; - private final static int ENCODING_ASCII = 9; - - // - // Constants for attribute default value. - // - - /** - * Constant: the attribute is not declared. - * @see #getAttributeDefaultValueType - */ - public final static int ATTRIBUTE_DEFAULT_UNDECLARED = 30; - - /** - * Constant: the attribute has a literal default value specified. - * @see #getAttributeDefaultValueType - * @see #getAttributeDefaultValue - */ - public final static int ATTRIBUTE_DEFAULT_SPECIFIED = 31; - - /** - * Constant: the attribute was declared #IMPLIED. - * @see #getAttributeDefaultValueType - */ - public final static int ATTRIBUTE_DEFAULT_IMPLIED = 32; - - /** - * Constant: the attribute was declared #REQUIRED. - * @see #getAttributeDefaultValueType - */ - public final static int ATTRIBUTE_DEFAULT_REQUIRED = 33; - - /** - * Constant: the attribute was declared #FIXED. - * @see #getAttributeDefaultValueType - * @see #getAttributeDefaultValue - */ - public final static int ATTRIBUTE_DEFAULT_FIXED = 34; - - // - // Constants for input. - // - private final static int INPUT_NONE = 0; - private final static int INPUT_INTERNAL = 1; - private final static int INPUT_STREAM = 3; - private final static int INPUT_READER = 5; - - // - // Flags for reading literals. - // - // expand general entity refs (attribute values in dtd and content) - private final static int LIT_ENTITY_REF = 2; - // normalize this value (space chars) (attributes, public ids) - private final static int LIT_NORMALIZE = 4; - // literal is an attribute value - private final static int LIT_ATTRIBUTE = 8; - // don't expand parameter entities - private final static int LIT_DISABLE_PE = 16; - // don't expand [or parse] character refs - private final static int LIT_DISABLE_CREF = 32; - // don't parse general entity refs - private final static int LIT_DISABLE_EREF = 64; - // literal is a public ID value - private final static int LIT_PUBID = 256; - - // - // Flags affecting PE handling in DTDs (if expandPE is true). - // PEs expand with space padding, except inside literals. - // - private final static int CONTEXT_NORMAL = 0; - private final static int CONTEXT_LITERAL = 1; - - // Emit warnings for relative URIs with no base URI. - static boolean uriWarnings; - static - { - String key = "gnu.xml.aelfred2.XmlParser.uriWarnings"; - GetPropertyAction a = new GetPropertyAction(key); - uriWarnings = "true".equals(AccessController.doPrivileged(a)); - } - - // - // The current XML handler interface. - // - private SAXDriver handler; - - // - // I/O information. - // - private Reader reader; // current reader - private InputStream is; // current input stream - private int line; // current line number - private int column; // current column number - private int sourceType; // type of input source - private LinkedList inputStack; // stack of input soruces - private URLConnection externalEntity; // current external entity - private int encoding; // current character encoding - private int currentByteCount; // bytes read from current source - private InputSource scratch; // temporary - - // - // Buffers for decoded but unparsed character input. - // - private char[] readBuffer; - private int readBufferPos; - private int readBufferLength; - private int readBufferOverflow; // overflow from last data chunk. - - // - // Buffer for undecoded raw byte input. - // - private final static int READ_BUFFER_MAX = 16384; - private byte[] rawReadBuffer; - - - // - // Buffer for attribute values, char refs, DTD stuff. - // - private static int DATA_BUFFER_INITIAL = 4096; - private char[] dataBuffer; - private int dataBufferPos; - - // - // Buffer for parsed names. - // - private static int NAME_BUFFER_INITIAL = 1024; - private char[] nameBuffer; - private int nameBufferPos; - - // - // Save any standalone flag - // - private boolean docIsStandalone; - - // - // Hashtables for DTD information on elements, entities, and notations. - // Populated until we start ignoring decls (because of skipping a PE) - // - private HashMap elementInfo; - private HashMap entityInfo; - private HashMap notationInfo; - private boolean skippedPE; - - // - // Element type currently in force. - // - private String currentElement; - private int currentElementContent; - - // - // Stack of entity names, to detect recursion. - // - private LinkedList entityStack; - - // - // PE expansion is enabled in most chunks of the DTD, not all. - // When it's enabled, literals are treated differently. - // - private boolean inLiteral; - private boolean expandPE; - private boolean peIsError; - - // - // can't report entity expansion inside two constructs: - // - attribute expansions (internal entities only) - // - markup declarations (parameter entities only) - // - private boolean doReport; - - // - // Symbol table, for caching interned names. - // - // These show up wherever XML names or nmtokens are used: naming elements, - // attributes, PIs, notations, entities, and enumerated attribute values. - // - // NOTE: This hashtable doesn't grow. The default size is intended to be - // rather large for most documents. Example: one snapshot of the DocBook - // XML 4.1 DTD used only about 350 such names. As a rule, only pathological - // documents (ones that don't reuse names) should ever see much collision. - // - // Be sure that SYMBOL_TABLE_LENGTH always stays prime, for best hashing. - // "2039" keeps the hash table size at about two memory pages on typical - // 32 bit hardware. - // - private final static int SYMBOL_TABLE_LENGTH = 2039; - - private Object[][] symbolTable; - - // - // Hash table of attributes found in current start tag. - // - private String[] tagAttributes; - private int tagAttributePos; - - // - // Utility flag: have we noticed a CR while reading the last - // data chunk? If so, we will have to go back and normalise - // CR or CR/LF line ends. - // - private boolean sawCR; - - // - // Utility flag: are we in CDATA? If so, whitespace isn't ignorable. - // - private boolean inCDATA; - - // - // Xml version. - // - private static final int XML_10 = 0; - private static final int XML_11 = 1; - private int xmlVersion = XML_10; - - ////////////////////////////////////////////////////////////////////// - // Constructors. - //////////////////////////////////////////////////////////////////////// - - /** - * Construct a new parser with no associated handler. - * @see #setHandler - * @see #parse - */ - // package private - XmlParser() - { - } - - /** - * Set the handler that will receive parsing events. - * @param handler The handler to receive callback events. - * @see #parse - */ - // package private - void setHandler(SAXDriver handler) - { - this.handler = handler; - } - - /** - * Parse an XML document from the character stream, byte stream, or URI - * that you provide (in that order of preference). Any URI that you - * supply will become the base URI for resolving relative URI, and may - * be used to acquire a reader or byte stream. - * - * <p> Only one thread at a time may use this parser; since it is - * private to this package, post-parse cleanup is done by the caller, - * which MUST NOT REUSE the parser (just null it). - * - * @param systemId Absolute URI of the document; should never be null, - * but may be so iff a reader <em>or</em> a stream is provided. - * @param publicId The public identifier of the document, or null. - * @param reader A character stream; must be null if stream isn't. - * @param stream A byte input stream; must be null if reader isn't. - * @param encoding The suggested encoding, or null if unknown. - * @exception java.lang.Exception Basically SAXException or IOException - */ - // package private - void doParse(String systemId, String publicId, Reader reader, - InputStream stream, String encoding) - throws Exception - { - if (handler == null) - { - throw new IllegalStateException("no callback handler"); - } - - initializeVariables(); - - // predeclare the built-in entities here (replacement texts) - // we don't need to intern(), since we're guaranteed literals - // are always (globally) interned. - setInternalEntity("amp", "&"); - setInternalEntity("lt", "<"); - setInternalEntity("gt", ">"); - setInternalEntity("apos", "'"); - setInternalEntity("quot", """); - - try - { - // pushURL first to ensure locator is correct in startDocument - // ... it might report an IO or encoding exception. - handler.startDocument(); - pushURL(false, "[document]", - // default baseURI: null - new ExternalIdentifiers(publicId, systemId, null), - reader, stream, encoding, false); - - parseDocument(); - } - catch (EOFException e) - { - //empty input - error("empty document, with no root element."); - } - finally - { - if (reader != null) - { - try - { - reader.close(); - } - catch (IOException e) - { - /* ignore */ - } - } - if (stream != null) - { - try - { - stream.close(); - } - catch (IOException e) - { - /* ignore */ - } - } - if (is != null) - { - try - { - is.close(); - } - catch (IOException e) - { - /* ignore */ - } - } - scratch = null; - } - } - - ////////////////////////////////////////////////////////////////////// - // Error reporting. - ////////////////////////////////////////////////////////////////////// - - /** - * Report an error. - * @param message The error message. - * @param textFound The text that caused the error (or null). - * @see SAXDriver#error - * @see #line - */ - private void error(String message, String textFound, String textExpected) - throws SAXException - { - if (textFound != null) - { - message = message + " (found \"" + textFound + "\")"; - } - if (textExpected != null) - { - message = message + " (expected \"" + textExpected + "\")"; - } - handler.fatal(message); - - // "can't happen" - throw new SAXException(message); - } - - /** - * Report a serious error. - * @param message The error message. - * @param textFound The text that caused the error (or null). - */ - private void error(String message, char textFound, String textExpected) - throws SAXException - { - error(message, new Character(textFound).toString(), textExpected); - } - - /** - * Report typical case fatal errors. - */ - private void error(String message) - throws SAXException - { - handler.fatal(message); - } - - ////////////////////////////////////////////////////////////////////// - // Major syntactic productions. - ////////////////////////////////////////////////////////////////////// - - /** - * Parse an XML document. - * <pre> - * [1] document ::= prolog element Misc* - * </pre> - * <p>This is the top-level parsing function for a single XML - * document. As a minimum, a well-formed document must have - * a document element, and a valid document must have a prolog - * (one with doctype) as well. - */ - private void parseDocument() - throws Exception - { - try - { // added by MHK - boolean sawDTD = parseProlog(); - require('<'); - parseElement(!sawDTD); - } - catch (EOFException ee) - { // added by MHK - error("premature end of file", "[EOF]", null); - } - - try - { - parseMisc(); //skip all white, PIs, and comments - char c = readCh(); //if this doesn't throw an exception... - error("unexpected characters after document end", c, null); - } - catch (EOFException e) - { - return; - } - } - - static final char[] startDelimComment = { '<', '!', '-', '-' }; - static final char[] endDelimComment = { '-', '-' }; - - /** - * Skip a comment. - * <pre> - * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* "-->" - * </pre> - * <p> (The <code><!--</code> has already been read.) - */ - private void parseComment() - throws Exception - { - char c; - boolean saved = expandPE; - - expandPE = false; - parseUntil(endDelimComment); - require('>'); - expandPE = saved; - handler.comment(dataBuffer, 0, dataBufferPos); - dataBufferPos = 0; - } - - static final char[] startDelimPI = { '<', '?' }; - static final char[] endDelimPI = { '?', '>' }; - - /** - * Parse a processing instruction and do a call-back. - * <pre> - * [16] PI ::= '<?' PITarget - * (S (Char* - (Char* '?>' Char*)))? - * '?>' - * [17] PITarget ::= Name - ( ('X'|'x') ('M'|m') ('L'|l') ) - * </pre> - * <p> (The <code><?</code> has already been read.) - */ - private void parsePI() - throws SAXException, IOException - { - String name; - boolean saved = expandPE; - - expandPE = false; - name = readNmtoken(true); - //NE08 - if (name.indexOf(':') >= 0) - { - error("Illegal character(':') in processing instruction name ", - name, null); - } - if ("xml".equalsIgnoreCase(name)) - { - error("Illegal processing instruction target", name, null); - } - if (!tryRead(endDelimPI)) - { - requireWhitespace(); - parseUntil(endDelimPI); - } - expandPE = saved; - handler.processingInstruction(name, dataBufferToString()); - } - - static final char[] endDelimCDATA = { ']', ']', '>' }; - - private boolean isDirtyCurrentElement; - - /** - * Parse a CDATA section. - * <pre> - * [18] CDSect ::= CDStart CData CDEnd - * [19] CDStart ::= '<![CDATA[' - * [20] CData ::= (Char* - (Char* ']]>' Char*)) - * [21] CDEnd ::= ']]>' - * </pre> - * <p> (The '<![CDATA[' has already been read.) - */ - private void parseCDSect() - throws Exception - { - parseUntil(endDelimCDATA); - dataBufferFlush(); - } - - /** - * Parse the prolog of an XML document. - * <pre> - * [22] prolog ::= XMLDecl? Misc* (Doctypedecl Misc*)? - * </pre> - * <p>We do not look for the XML declaration here, because it was - * handled by pushURL (). - * @see pushURL - * @return true if a DTD was read. - */ - private boolean parseProlog() - throws Exception - { - parseMisc(); - - if (tryRead("<!DOCTYPE")) - { - parseDoctypedecl(); - parseMisc(); - return true; - } - return false; - } - - private void checkLegalVersion(String version) - throws SAXException - { - int len = version.length(); - for (int i = 0; i < len; i++) - { - char c = version.charAt(i); - if ('0' <= c && c <= '9') - { - continue; - } - if (c == '_' || c == '.' || c == ':' || c == '-') - { - continue; - } - if ('a' <= c && c <= 'z') - { - continue; - } - if ('A' <= c && c <= 'Z') - { - continue; - } - error ("illegal character in version", version, "1.0"); - } - } - - /** - * Parse the XML declaration. - * <pre> - * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' - * [24] VersionInfo ::= S 'version' Eq - * ("'" VersionNum "'" | '"' VersionNum '"' ) - * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')* - * [32] SDDecl ::= S 'standalone' Eq - * ( "'"" ('yes' | 'no') "'"" | '"' ("yes" | "no") '"' ) - * [80] EncodingDecl ::= S 'encoding' Eq - * ( "'" EncName "'" | "'" EncName "'" ) - * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* - * </pre> - * <p> (The <code><?xml</code> and whitespace have already been read.) - * @return the encoding in the declaration, uppercased; or null - * @see #parseTextDecl - * @see #setupDecoding - */ - private String parseXMLDecl(boolean ignoreEncoding) - throws SAXException, IOException - { - String version; - String encodingName = null; - String standalone = null; - int flags = LIT_DISABLE_CREF | LIT_DISABLE_PE | LIT_DISABLE_EREF; - String inputEncoding = null; - - switch (this.encoding) - { - case ENCODING_EXTERNAL: - case ENCODING_UTF_8: - inputEncoding = "UTF-8"; - break; - case ENCODING_ISO_8859_1: - inputEncoding = "ISO-8859-1"; - break; - case ENCODING_UCS_2_12: - inputEncoding = "UTF-16BE"; - break; - case ENCODING_UCS_2_21: - inputEncoding = "UTF-16LE"; - break; - } - - // Read the version. - require("version"); - parseEq(); - checkLegalVersion(version = readLiteral(flags)); - if (!version.equals("1.0")) - { - if (version.equals("1.1")) - { - handler.warn("expected XML version 1.0, not: " + version); - xmlVersion = XML_11; - } - else - { - error("illegal XML version", version, "1.0 or 1.1"); - } - } - else - { - xmlVersion = XML_10; - } - // Try reading an encoding declaration. - boolean white = tryWhitespace(); - - if (tryRead("encoding")) - { - if (!white) - { - error("whitespace required before 'encoding='"); - } - parseEq(); - encodingName = readLiteral(flags); - if (!ignoreEncoding) - { - setupDecoding(encodingName); - } - } - - // Try reading a standalone declaration - if (encodingName != null) - { - white = tryWhitespace(); - } - if (tryRead("standalone")) - { - if (!white) - { - error("whitespace required before 'standalone='"); - } - parseEq(); - standalone = readLiteral(flags); - if ("yes".equals(standalone)) - { - docIsStandalone = true; - } - else if (!"no".equals(standalone)) - { - error("standalone flag must be 'yes' or 'no'"); - } - } - - skipWhitespace(); - require("?>"); - - if (inputEncoding == null) - { - inputEncoding = encodingName; - } - handler.xmlDecl(version, encodingName, docIsStandalone, - inputEncoding); - - return encodingName; - } - - /** - * Parse a text declaration. - * <pre> - * [79] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' - * [80] EncodingDecl ::= S 'encoding' Eq - * ( '"' EncName '"' | "'" EncName "'" ) - * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* - * </pre> - * <p> (The <code><?xml</code>' and whitespace have already been read.) - * @return the encoding in the declaration, uppercased; or null - * @see #parseXMLDecl - * @see #setupDecoding - */ - private String parseTextDecl(boolean ignoreEncoding) - throws SAXException, IOException - { - String encodingName = null; - int flags = LIT_DISABLE_CREF | LIT_DISABLE_PE | LIT_DISABLE_EREF; - - // Read an optional version. - if (tryRead ("version")) - { - String version; - parseEq(); - checkLegalVersion(version = readLiteral(flags)); - - if (version.equals("1.1")) - { - if (xmlVersion == XML_10) - { - error("external subset has later version number.", "1.0", - version); - } - handler.warn("expected XML version 1.0, not: " + version); - xmlVersion = XML_11; - } - else if (!version.equals("1.0")) - { - error("illegal XML version", version, "1.0 or 1.1"); - } - requireWhitespace(); - } - - // Read the encoding. - require("encoding"); - parseEq(); - encodingName = readLiteral(flags); - if (!ignoreEncoding) - { - setupDecoding(encodingName); - } - skipWhitespace(); - require("?>"); - - return encodingName; - } - - /** - * Sets up internal state so that we can decode an entity using the - * specified encoding. This is used when we start to read an entity - * and we have been given knowledge of its encoding before we start to - * read any data (e.g. from a SAX input source or from a MIME type). - * - * <p> It is also used after autodetection, at which point only very - * limited adjustments to the encoding may be used (switching between - * related builtin decoders). - * - * @param encodingName The name of the encoding specified by the user. - * @exception IOException if the encoding isn't supported either - * internally to this parser, or by the hosting JVM. - * @see #parseXMLDecl - * @see #parseTextDecl - */ - private void setupDecoding(String encodingName) - throws SAXException, IOException - { - encodingName = encodingName.toUpperCase(); - - // ENCODING_EXTERNAL indicates an encoding that wasn't - // autodetected ... we can use builtin decoders, or - // ones from the JVM (InputStreamReader). - - // Otherwise we can only tweak what was autodetected, and - // only for single byte (ASCII derived) builtin encodings. - - // ASCII-derived encodings - if (encoding == ENCODING_UTF_8 || encoding == ENCODING_EXTERNAL) - { - if (encodingName.equals("ISO-8859-1") - || encodingName.equals("8859_1") - || encodingName.equals("ISO8859_1")) - { - encoding = ENCODING_ISO_8859_1; - return; - } - else if (encodingName.equals("US-ASCII") - || encodingName.equals("ASCII")) - { - encoding = ENCODING_ASCII; - return; - } - else if (encodingName.equals("UTF-8") - || encodingName.equals("UTF8")) - { - encoding = ENCODING_UTF_8; - return; - } - else if (encoding != ENCODING_EXTERNAL) - { - // used to start with a new reader ... - throw new UnsupportedEncodingException(encodingName); - } - // else fallthrough ... - // it's ASCII-ish and something other than a builtin - } - - // Unicode and such - if (encoding == ENCODING_UCS_2_12 || encoding == ENCODING_UCS_2_21) - { - if (!(encodingName.equals("ISO-10646-UCS-2") - || encodingName.equals("UTF-16") - || encodingName.equals("UTF-16BE") - || encodingName.equals("UTF-16LE"))) - { - error("unsupported Unicode encoding", encodingName, "UTF-16"); - } - return; - } - - // four byte encodings - if (encoding == ENCODING_UCS_4_1234 - || encoding == ENCODING_UCS_4_4321 - || encoding == ENCODING_UCS_4_2143 - || encoding == ENCODING_UCS_4_3412) - { - // Strictly: "UCS-4" == "UTF-32BE"; also, "UTF-32LE" exists - if (!encodingName.equals("ISO-10646-UCS-4")) - { - error("unsupported 32-bit encoding", encodingName, - "ISO-10646-UCS-4"); - } - return; - } - - // assert encoding == ENCODING_EXTERNAL - // if (encoding != ENCODING_EXTERNAL) - // throw new RuntimeException ("encoding = " + encoding); - - if (encodingName.equals("UTF-16BE")) - { - encoding = ENCODING_UCS_2_12; - return; - } - if (encodingName.equals("UTF-16LE")) - { - encoding = ENCODING_UCS_2_21; - return; - } - - // We couldn't use the builtin decoders at all. But we can try to - // create a reader, since we haven't messed up buffering. Tweak - // the encoding name if necessary. - - if (encodingName.equals("UTF-16") - || encodingName.equals("ISO-10646-UCS-2")) - { - encodingName = "Unicode"; - } - // Ignoring all the EBCDIC aliases here - - reader = new InputStreamReader(is, encodingName); - sourceType = INPUT_READER; - } - - /** - * Parse miscellaneous markup outside the document element and DOCTYPE - * declaration. - * <pre> - * [27] Misc ::= Comment | PI | S - * </pre> - */ - private void parseMisc() - throws Exception - { - while (true) - { - skipWhitespace(); - if (tryRead(startDelimPI)) - { - parsePI(); - } - else if (tryRead(startDelimComment)) - { - parseComment(); - } - else - { - return; - } - } - } - - /** - * Parse a document type declaration. - * <pre> - * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? - * ('[' (markupdecl | PEReference | S)* ']' S?)? '>' - * </pre> - * <p> (The <code><!DOCTYPE</code> has already been read.) - */ - private void parseDoctypedecl() - throws Exception - { - String rootName; - ExternalIdentifiers ids; - - // Read the document type name. - requireWhitespace(); - rootName = readNmtoken(true); - - // Read the External subset's IDs - skipWhitespace(); - ids = readExternalIds(false, true); - - // report (a) declaration of name, (b) lexical info (ids) - handler.doctypeDecl(rootName, ids.publicId, ids.systemId); - - // Internal subset is parsed first, if present - skipWhitespace(); - if (tryRead('[')) - { - - // loop until the subset ends - while (true) - { - doReport = expandPE = true; - skipWhitespace(); - doReport = expandPE = false; - if (tryRead(']')) - { - break; // end of subset - } - else - { - // WFC, PEs in internal subset (only between decls) - peIsError = expandPE = true; - parseMarkupdecl(); - peIsError = expandPE = false; - } - } - } - skipWhitespace(); - require('>'); - - // Read the external subset, if any - InputSource subset; - - if (ids.systemId == null) - { - subset = handler.getExternalSubset(rootName, - handler.getSystemId()); - } - else - { - subset = null; - } - if (ids.systemId != null || subset != null) - { - pushString(null, ">"); - - // NOTE: [dtd] is so we say what SAX2 expects, - // though it's misleading (subset, not entire dtd) - if (ids.systemId != null) - { - pushURL(true, "[dtd]", ids, null, null, null, true); - } - else - { - handler.warn("modifying document by adding external subset"); - pushURL(true, "[dtd]", - new ExternalIdentifiers(subset.getPublicId(), - subset.getSystemId(), - null), - subset.getCharacterStream(), - subset.getByteStream(), - subset.getEncoding(), - false); - } - - // Loop until we end up back at '>' - while (true) - { - doReport = expandPE = true; - skipWhitespace(); - doReport = expandPE = false; - if (tryRead('>')) - { - break; - } - else - { - expandPE = true; - parseMarkupdecl(); - expandPE = false; - } - } - - // the ">" string isn't popped yet - if (inputStack.size() != 1) - { - error("external subset has unmatched '>'"); - } - } - - // done dtd - handler.endDoctype(); - expandPE = false; - doReport = true; - } - - /** - * Parse a markup declaration in the internal or external DTD subset. - * <pre> - * [29] markupdecl ::= elementdecl | Attlistdecl | EntityDecl - * | NotationDecl | PI | Comment - * [30] extSubsetDecl ::= (markupdecl | conditionalSect - * | PEReference | S) * - * </pre> - * <p> Reading toplevel PE references is handled as a lexical issue - * by the caller, as is whitespace. - */ - private void parseMarkupdecl() - throws Exception - { - char[] saved = null; - boolean savedPE = expandPE; - - // prevent "<%foo;" and ensures saved entity is right - require('<'); - unread('<'); - expandPE = false; - - if (tryRead("<!ELEMENT")) - { - saved = readBuffer; - expandPE = savedPE; - parseElementDecl(); - } - else if (tryRead("<!ATTLIST")) - { - saved = readBuffer; - expandPE = savedPE; - parseAttlistDecl(); - } - else if (tryRead("<!ENTITY")) - { - saved = readBuffer; - expandPE = savedPE; - parseEntityDecl(); - } - else if (tryRead("<!NOTATION")) - { - saved = readBuffer; - expandPE = savedPE; - parseNotationDecl(); - } - else if (tryRead(startDelimPI)) - { - saved = readBuffer; - expandPE = savedPE; - parsePI(); - } - else if (tryRead(startDelimComment)) - { - saved = readBuffer; - expandPE = savedPE; - parseComment(); - } - else if (tryRead("<![")) - { - saved = readBuffer; - expandPE = savedPE; - if (inputStack.size() > 0) - { - parseConditionalSect(saved); - } - else - { - error("conditional sections illegal in internal subset"); - } - } - else - { - error("expected markup declaration"); - } - - // VC: Proper Decl/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Declaration/PE nesting"); - } - } - - /** - * Parse an element, with its tags. - * <pre> - * [39] element ::= EmptyElementTag | STag content ETag - * [40] STag ::= '<' Name (S Attribute)* S? '>' - * [44] EmptyElementTag ::= '<' Name (S Attribute)* S? '/>' - * </pre> - * <p> (The '<' has already been read.) - * <p>NOTE: this method actually chains onto parseContent (), if necessary, - * and parseContent () will take care of calling parseETag (). - */ - private void parseElement(boolean maybeGetSubset) - throws Exception - { - String gi; - char c; - int oldElementContent = currentElementContent; - String oldElement = currentElement; - ElementDecl element; - - // This is the (global) counter for the - // array of specified attributes. - tagAttributePos = 0; - - // Read the element type name. - gi = readNmtoken(true); - - // If we saw no DTD, and this is the document root element, - // let the application modify the input stream by providing one. - if (maybeGetSubset) - { - InputSource subset = handler.getExternalSubset(gi, - handler.getSystemId()); - if (subset != null) - { - String publicId = subset.getPublicId(); - String systemId = subset.getSystemId(); - - handler.warn("modifying document by adding DTD"); - handler.doctypeDecl(gi, publicId, systemId); - pushString(null, ">"); - - // NOTE: [dtd] is so we say what SAX2 expects, - // though it's misleading (subset, not entire dtd) - pushURL(true, "[dtd]", - new ExternalIdentifiers(publicId, systemId, null), - subset.getCharacterStream(), - subset.getByteStream(), - subset.getEncoding(), - false); - - // Loop until we end up back at '>' - while (true) - { - doReport = expandPE = true; - skipWhitespace(); - doReport = expandPE = false; - if (tryRead('>')) - { - break; - } - else - { - expandPE = true; - parseMarkupdecl(); - expandPE = false; - } - } - - // the ">" string isn't popped yet - if (inputStack.size() != 1) - { - error("external subset has unmatched '>'"); - } - - handler.endDoctype(); - } - } - - // Determine the current content type. - currentElement = gi; - element = (ElementDecl) elementInfo.get(gi); - currentElementContent = getContentType(element, CONTENT_ANY); - - // Read the attributes, if any. - // After this loop, "c" is the closing delimiter. - boolean white = tryWhitespace(); - c = readCh(); - while (c != '/' && c != '>') - { - unread(c); - if (!white) - { - error("need whitespace between attributes"); - } - parseAttribute(gi); - white = tryWhitespace(); - c = readCh(); - } - - // Supply any defaulted attributes. - Iterator atts = declaredAttributes(element); - if (atts != null) - { - String aname; -loop: - while (atts.hasNext()) - { - aname = (String) atts.next(); - // See if it was specified. - for (int i = 0; i < tagAttributePos; i++) - { - if (tagAttributes[i] == aname) - { - continue loop; - } - } - // ... or has a default - String value = getAttributeDefaultValue(gi, aname); - - if (value == null) - { - continue; - } - handler.attribute(aname, value, false); - } - } - - // Figure out if this is a start tag - // or an empty element, and dispatch an - // event accordingly. - switch (c) - { - case '>': - handler.startElement(gi); - parseContent(); - break; - case '/': - require('>'); - handler.startElement(gi); - handler.endElement(gi); - break; - } - - // Restore the previous state. - currentElement = oldElement; - currentElementContent = oldElementContent; - } - - /** - * Parse an attribute assignment. - * <pre> - * [41] Attribute ::= Name Eq AttValue - * </pre> - * @param name The name of the attribute's element. - * @see SAXDriver#attribute - */ - private void parseAttribute(String name) - throws Exception - { - String aname; - String type; - String value; - int flags = LIT_ATTRIBUTE | LIT_ENTITY_REF; - - // Read the attribute name. - aname = readNmtoken(true); - type = getAttributeType(name, aname); - - // Parse '=' - parseEq(); - - // Read the value, normalizing whitespace - // unless it is CDATA. - if (handler.stringInterning) - { - if (type == "CDATA" || type == null) - { - value = readLiteral(flags); - } - else - { - value = readLiteral(flags | LIT_NORMALIZE); - } - } - else - { - if (type.equals("CDATA") || type == null) - { - value = readLiteral(flags); - } - else - { - value = readLiteral(flags | LIT_NORMALIZE); - } - } - - // WFC: no duplicate attributes - for (int i = 0; i < tagAttributePos; i++) - { - if (aname.equals(tagAttributes [i])) - { - error("duplicate attribute", aname, null); - } - } - - // Inform the handler about the - // attribute. - handler.attribute(aname, value, true); - dataBufferPos = 0; - - // Note that the attribute has been - // specified. - if (tagAttributePos == tagAttributes.length) - { - String newAttrib[] = new String[tagAttributes.length * 2]; - System.arraycopy(tagAttributes, 0, newAttrib, 0, tagAttributePos); - tagAttributes = newAttrib; - } - tagAttributes[tagAttributePos++] = aname; - } - - /** - * Parse an equals sign surrounded by optional whitespace. - * <pre> - * [25] Eq ::= S? '=' S? - * </pre> - */ - private void parseEq() - throws SAXException, IOException - { - skipWhitespace(); - require('='); - skipWhitespace(); - } - - /** - * Parse an end tag. - * <pre> - * [42] ETag ::= '</' Name S? '>' - * </pre> - * <p>NOTE: parseContent () chains to here, we already read the - * "</". - */ - private void parseETag() - throws Exception - { - require(currentElement); - skipWhitespace(); - require('>'); - handler.endElement(currentElement); - // not re-reporting any SAXException re bogus end tags, - // even though that diagnostic might be clearer ... - } - - /** - * Parse the content of an element. - * <pre> - * [43] content ::= (element | CharData | Reference - * | CDSect | PI | Comment)* - * [67] Reference ::= EntityRef | CharRef - * </pre> - * <p> NOTE: consumes ETtag. - */ - private void parseContent() - throws Exception - { - char c; - - while (true) - { - // consume characters (or ignorable whitspace) until delimiter - parseCharData(); - - // Handle delimiters - c = readCh(); - switch (c) - { - case '&': // Found "&" - c = readCh(); - if (c == '#') - { - parseCharRef(); - } - else - { - unread(c); - parseEntityRef(true); - } - isDirtyCurrentElement = true; - break; - - case '<': // Found "<" - dataBufferFlush(); - c = readCh(); - switch (c) - { - case '!': // Found "<!" - c = readCh(); - switch (c) - { - case '-': // Found "<!-" - require('-'); - isDirtyCurrentElement = false; - parseComment(); - break; - case '[': // Found "<![" - isDirtyCurrentElement = false; - require("CDATA["); - handler.startCDATA(); - inCDATA = true; - parseCDSect(); - inCDATA = false; - handler.endCDATA(); - break; - default: - error("expected comment or CDATA section", c, null); - break; - } - break; - - case '?': // Found "<?" - isDirtyCurrentElement = false; - parsePI(); - break; - - case '/': // Found "</" - isDirtyCurrentElement = false; - parseETag(); - return; - - default: // Found "<" followed by something else - isDirtyCurrentElement = false; - unread(c); - parseElement(false); - break; - } - } - } - } - - /** - * Parse an element type declaration. - * <pre> - * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>' - * </pre> - * <p> NOTE: the '<!ELEMENT' has already been read. - */ - private void parseElementDecl() - throws Exception - { - String name; - - requireWhitespace(); - // Read the element type name. - name = readNmtoken(true); - - requireWhitespace(); - // Read the content model. - parseContentspec(name); - - skipWhitespace(); - require('>'); - } - - /** - * Content specification. - * <pre> - * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | elements - * </pre> - */ - private void parseContentspec(String name) - throws Exception - { - // FIXME: move elementDecl() into setElement(), pass EMTPY/ANY ... - if (tryRead("EMPTY")) - { - setElement(name, CONTENT_EMPTY, null, null); - if (!skippedPE) - { - handler.getDeclHandler().elementDecl(name, "EMPTY"); - } - return; - } - else if (tryRead("ANY")) - { - setElement(name, CONTENT_ANY, null, null); - if (!skippedPE) - { - handler.getDeclHandler().elementDecl(name, "ANY"); - } - return; - } - else - { - String model; - char[] saved; - - require('('); - saved = readBuffer; - dataBufferAppend('('); - skipWhitespace(); - if (tryRead("#PCDATA")) - { - dataBufferAppend("#PCDATA"); - parseMixed(saved); - model = dataBufferToString(); - setElement(name, CONTENT_MIXED, model, null); - } - else - { - parseElements(saved); - model = dataBufferToString(); - setElement(name, CONTENT_ELEMENTS, model, null); - } - if (!skippedPE) - { - handler.getDeclHandler().elementDecl(name, model); - } - } - } - - /** - * Parse an element-content model. - * <pre> - * [47] elements ::= (choice | seq) ('?' | '*' | '+')? - * [49] choice ::= '(' S? cp (S? '|' S? cp)+ S? ')' - * [50] seq ::= '(' S? cp (S? ',' S? cp)* S? ')' - * </pre> - * - * <p> NOTE: the opening '(' and S have already been read. - * - * @param saved Buffer for entity that should have the terminal ')' - */ - private void parseElements(char[] saved) - throws Exception - { - char c; - char sep; - - // Parse the first content particle - skipWhitespace(); - parseCp(); - - // Check for end or for a separator. - skipWhitespace(); - c = readCh(); - switch (c) - { - case ')': - // VC: Proper Group/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Group/PE nesting"); - } - - dataBufferAppend(')'); - c = readCh(); - switch (c) - { - case '*': - case '+': - case '?': - dataBufferAppend(c); - break; - default: - unread(c); - } - return; - case ',': // Register the separator. - case '|': - sep = c; - dataBufferAppend(c); - break; - default: - error("bad separator in content model", c, null); - return; - } - - // Parse the rest of the content model. - while (true) - { - skipWhitespace(); - parseCp(); - skipWhitespace(); - c = readCh(); - if (c == ')') - { - // VC: Proper Group/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Group/PE nesting"); - } - - dataBufferAppend(')'); - break; - } - else if (c != sep) - { - error("bad separator in content model", c, null); - return; - } - else - { - dataBufferAppend(c); - } - } - - // Check for the occurrence indicator. - c = readCh(); - switch (c) - { - case '?': - case '*': - case '+': - dataBufferAppend(c); - return; - default: - unread(c); - return; - } - } - - /** - * Parse a content particle. - * <pre> - * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? - * </pre> - */ - private void parseCp() - throws Exception - { - if (tryRead('(')) - { - dataBufferAppend('('); - parseElements(readBuffer); - } - else - { - dataBufferAppend(readNmtoken(true)); - char c = readCh(); - switch (c) - { - case '?': - case '*': - case '+': - dataBufferAppend(c); - break; - default: - unread(c); - break; - } - } - } - - /** - * Parse mixed content. - * <pre> - * [51] Mixed ::= '(' S? ( '#PCDATA' (S? '|' S? Name)*) S? ')*' - * | '(' S? ('#PCDATA') S? ')' - * </pre> - * - * @param saved Buffer for entity that should have the terminal ')' - */ - private void parseMixed(char[] saved) - throws Exception - { - // Check for PCDATA alone. - skipWhitespace(); - if (tryRead(')')) - { - // VC: Proper Group/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Group/PE nesting"); - } - - dataBufferAppend(")*"); - tryRead('*'); - return; - } - - // Parse mixed content. - skipWhitespace(); - while (!tryRead(")")) - { - require('|'); - dataBufferAppend('|'); - skipWhitespace(); - dataBufferAppend(readNmtoken(true)); - skipWhitespace(); - } - - // VC: Proper Group/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Group/PE nesting"); - } - - require('*'); - dataBufferAppend(")*"); - } - - /** - * Parse an attribute list declaration. - * <pre> - * [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>' - * </pre> - * <p>NOTE: the '<!ATTLIST' has already been read. - */ - private void parseAttlistDecl() - throws Exception - { - String elementName; - - requireWhitespace(); - elementName = readNmtoken(true); - boolean white = tryWhitespace(); - while (!tryRead('>')) - { - if (!white) - { - error("whitespace required before attribute definition"); - } - parseAttDef(elementName); - white = tryWhitespace(); - } - } - - /** - * Parse a single attribute definition. - * <pre> - * [53] AttDef ::= S Name S AttType S DefaultDecl - * </pre> - */ - private void parseAttDef(String elementName) - throws Exception - { - String name; - String type; - String enumer = null; - - // Read the attribute name. - name = readNmtoken(true); - - // Read the attribute type. - requireWhitespace(); - type = readAttType(); - - // Get the string of enumerated values if necessary. - if (handler.stringInterning) - { - if ("ENUMERATION" == type || "NOTATION" == type) - { - enumer = dataBufferToString(); - } - } - else - { - if ("ENUMERATION".equals(type) || "NOTATION".equals(type)) - { - enumer = dataBufferToString(); - } - } - - // Read the default value. - requireWhitespace(); - parseDefault(elementName, name, type, enumer); - } - - /** - * Parse the attribute type. - * <pre> - * [54] AttType ::= StringType | TokenizedType | EnumeratedType - * [55] StringType ::= 'CDATA' - * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' - * | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' - * [57] EnumeratedType ::= NotationType | Enumeration - * </pre> - */ - private String readAttType() - throws Exception - { - if (tryRead('(')) - { - parseEnumeration(false); - return "ENUMERATION"; - } - else - { - String typeString = readNmtoken(true); - if (handler.stringInterning) - { - if ("NOTATION" == typeString) - { - parseNotationType(); - return typeString; - } - else if ("CDATA" == typeString - || "ID" == typeString - || "IDREF" == typeString - || "IDREFS" == typeString - || "ENTITY" == typeString - || "ENTITIES" == typeString - || "NMTOKEN" == typeString - || "NMTOKENS" == typeString) - { - return typeString; - } - } - else - { - if ("NOTATION".equals(typeString)) - { - parseNotationType(); - return typeString; - } - else if ("CDATA".equals(typeString) - || "ID".equals(typeString) - || "IDREF".equals(typeString) - || "IDREFS".equals(typeString) - || "ENTITY".equals(typeString) - || "ENTITIES".equals(typeString) - || "NMTOKEN".equals(typeString) - || "NMTOKENS".equals(typeString)) - { - return typeString; - } - } - error("illegal attribute type", typeString, null); - return null; - } - } - - /** - * Parse an enumeration. - * <pre> - * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' - * </pre> - * <p>NOTE: the '(' has already been read. - */ - private void parseEnumeration(boolean isNames) - throws Exception - { - dataBufferAppend('('); - - // Read the first token. - skipWhitespace(); - dataBufferAppend(readNmtoken(isNames)); - // Read the remaining tokens. - skipWhitespace(); - while (!tryRead(')')) - { - require('|'); - dataBufferAppend('|'); - skipWhitespace(); - dataBufferAppend(readNmtoken (isNames)); - skipWhitespace(); - } - dataBufferAppend(')'); - } - - /** - * Parse a notation type for an attribute. - * <pre> - * [58] NotationType ::= 'NOTATION' S '(' S? NameNtoks - * (S? '|' S? name)* S? ')' - * </pre> - * <p>NOTE: the 'NOTATION' has already been read - */ - private void parseNotationType() - throws Exception - { - requireWhitespace(); - require('('); - - parseEnumeration(true); - } - - /** - * Parse the default value for an attribute. - * <pre> - * [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' - * | (('#FIXED' S)? AttValue) - * </pre> - */ - private void parseDefault(String elementName, String name, - String type, String enumer) - throws Exception - { - int valueType = ATTRIBUTE_DEFAULT_SPECIFIED; - String value = null; - int flags = LIT_ATTRIBUTE; - boolean saved = expandPE; - String defaultType = null; - - // LIT_ATTRIBUTE forces '<' checks now (ASAP) and turns whitespace - // chars to spaces (doesn't matter when that's done if it doesn't - // interfere with char refs expanding to whitespace). - - if (!skippedPE) - { - flags |= LIT_ENTITY_REF; - if (handler.stringInterning) - { - if ("CDATA" != type) - { - flags |= LIT_NORMALIZE; - } - } - else - { - if (!"CDATA".equals(type)) - { - flags |= LIT_NORMALIZE; - } - } - } - - expandPE = false; - if (tryRead('#')) - { - if (tryRead("FIXED")) - { - defaultType = "#FIXED"; - valueType = ATTRIBUTE_DEFAULT_FIXED; - requireWhitespace(); - value = readLiteral(flags); - } - else if (tryRead("REQUIRED")) - { - defaultType = "#REQUIRED"; - valueType = ATTRIBUTE_DEFAULT_REQUIRED; - } - else if (tryRead("IMPLIED")) - { - defaultType = "#IMPLIED"; - valueType = ATTRIBUTE_DEFAULT_IMPLIED; - } - else - { - error("illegal keyword for attribute default value"); - } - } - else - { - value = readLiteral(flags); - } - expandPE = saved; - setAttribute(elementName, name, type, enumer, value, valueType); - if (handler.stringInterning) - { - if ("ENUMERATION" == type) - { - type = enumer; - } - else if ("NOTATION" == type) - { - type = "NOTATION " + enumer; - } - } - else - { - if ("ENUMERATION".equals(type)) - { - type = enumer; - } - else if ("NOTATION".equals(type)) - { - type = "NOTATION " + enumer; - } - } - if (!skippedPE) - { - handler.getDeclHandler().attributeDecl(elementName, name, type, - defaultType, value); - } - } - - /** - * Parse a conditional section. - * <pre> - * [61] conditionalSect ::= includeSect || ignoreSect - * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' - * extSubsetDecl ']]>' - * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' - * ignoreSectContents* ']]>' - * [64] ignoreSectContents ::= Ignore - * ('<![' ignoreSectContents* ']]>' Ignore )* - * [65] Ignore ::= Char* - (Char* ( '<![' | ']]>') Char* ) - * </pre> - * <p> NOTE: the '>![' has already been read. - */ - private void parseConditionalSect(char[] saved) - throws Exception - { - skipWhitespace(); - if (tryRead("INCLUDE")) - { - skipWhitespace(); - require('['); - // VC: Proper Conditional Section/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Conditional Section/PE nesting"); - } - skipWhitespace(); - while (!tryRead("]]>")) - { - parseMarkupdecl(); - skipWhitespace(); - } - } - else if (tryRead("IGNORE")) - { - skipWhitespace(); - require('['); - // VC: Proper Conditional Section/PE Nesting - if (readBuffer != saved) - { - handler.verror("Illegal Conditional Section/PE nesting"); - } - int nesting = 1; - char c; - expandPE = false; - for (int nest = 1; nest > 0; ) - { - c = readCh(); - switch (c) - { - case '<': - if (tryRead("![")) - { - nest++; - } - case ']': - if (tryRead("]>")) - { - nest--; - } - } - } - expandPE = true; - } - else - { - error("conditional section must begin with INCLUDE or IGNORE"); - } - } - - private void parseCharRef() - throws SAXException, IOException - { - parseCharRef(true /* do flushDataBuffer by default */); - } - - /** - * Try to read a character reference without consuming data from buffer. - * <pre> - * [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';' - * </pre> - * <p>NOTE: the '&#' has already been read. - */ - private void tryReadCharRef() - throws SAXException, IOException - { - int value = 0; - char c; - - if (tryRead('x')) - { -loop1: - while (true) - { - c = readCh(); - if (c == ';') - { - break loop1; - } - else - { - int n = Character.digit(c, 16); - if (n == -1) - { - error("illegal character in character reference", c, null); - break loop1; - } - value *= 16; - value += n; - } - } - } - else - { -loop2: - while (true) - { - c = readCh(); - if (c == ';') - { - break loop2; - } - else - { - int n = Character.digit(c, 10); - if (n == -1) - { - error("illegal character in character reference", c, null); - break loop2; - } - value *= 10; - value += n; - } - } - } - - // check for character refs being legal XML - if ((value < 0x0020 - && ! (value == '\n' || value == '\t' || value == '\r')) - || (value >= 0xD800 && value <= 0xDFFF) - || value == 0xFFFE || value == 0xFFFF - || value > 0x0010ffff) - { - error("illegal XML character reference U+" - + Integer.toHexString(value)); - } - - // Check for surrogates: 00000000 0000xxxx yyyyyyyy zzzzzzzz - // (1101|10xx|xxyy|yyyy + 1101|11yy|zzzz|zzzz: - if (value > 0x0010ffff) - { - // too big for surrogate - error("character reference " + value + " is too large for UTF-16", - new Integer(value).toString(), null); - } - - } - - /** - * Read and interpret a character reference. - * <pre> - * [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';' - * </pre> - * <p>NOTE: the '&#' has already been read. - */ - private void parseCharRef(boolean doFlush) - throws SAXException, IOException - { - int value = 0; - char c; - - if (tryRead('x')) - { -loop1: - while (true) - { - c = readCh(); - if (c == ';') - { - break loop1; - } - else - { - int n = Character.digit(c, 16); - if (n == -1) - { - error("illegal character in character reference", c, null); - break loop1; - } - value *= 16; - value += n; - } - } - } - else - { -loop2: - while (true) - { - c = readCh(); - if (c == ';') - { - break loop2; - } - else - { - int n = Character.digit(c, 10); - if (n == -1) - { - error("illegal character in character reference", c, null); - break loop2; - } - value *= 10; - value += c - '0'; - } - } - } - - // check for character refs being legal XML - if ((value < 0x0020 - && ! (value == '\n' || value == '\t' || value == '\r')) - || (value >= 0xD800 && value <= 0xDFFF) - || value == 0xFFFE || value == 0xFFFF - || value > 0x0010ffff) - { - error("illegal XML character reference U+" - + Integer.toHexString(value)); - } - - // Check for surrogates: 00000000 0000xxxx yyyyyyyy zzzzzzzz - // (1101|10xx|xxyy|yyyy + 1101|11yy|zzzz|zzzz: - if (value <= 0x0000ffff) - { - // no surrogates needed - dataBufferAppend((char) value); - } - else if (value <= 0x0010ffff) - { - value -= 0x10000; - // > 16 bits, surrogate needed - dataBufferAppend((char) (0xd800 | (value >> 10))); - dataBufferAppend((char) (0xdc00 | (value & 0x0003ff))); - } - else - { - // too big for surrogate - error("character reference " + value + " is too large for UTF-16", - new Integer(value).toString(), null); - } - if (doFlush) - { - dataBufferFlush(); - } - } - - /** - * Parse and expand an entity reference. - * <pre> - * [68] EntityRef ::= '&' Name ';' - * </pre> - * <p>NOTE: the '&' has already been read. - * @param externalAllowed External entities are allowed here. - */ - private void parseEntityRef(boolean externalAllowed) - throws SAXException, IOException - { - String name; - - name = readNmtoken(true); - require(';'); - switch (getEntityType(name)) - { - case ENTITY_UNDECLARED: - // NOTE: XML REC describes amazingly convoluted handling for - // this case. Nothing as meaningful as being a WFness error - // unless the processor might _legitimately_ not have seen a - // declaration ... which is what this implements. - String message; - - message = "reference to undeclared general entity " + name; - if (skippedPE && !docIsStandalone) - { - handler.verror(message); - // we don't know this entity, and it might be external... - if (externalAllowed) - { - handler.skippedEntity(name); - } - } - else - { - error(message); - } - break; - case ENTITY_INTERNAL: - pushString(name, getEntityValue(name)); - - //workaround for possible input pop before marking - //the buffer reading position - char t = readCh(); - unread(t); - int bufferPosMark = readBufferPos; - - int end = readBufferPos + getEntityValue(name).length(); - for (int k = readBufferPos; k < end; k++) - { - t = readCh(); - if (t == '&') - { - t = readCh(); - if (t == '#') - { - //try to match a character ref - tryReadCharRef(); - - //everything has been read - if (readBufferPos >= end) - { - break; - } - k = readBufferPos; - continue; - } - else if (Character.isLetter(t)) - { - //looks like an entity ref - unread(t); - readNmtoken(true); - require(';'); - - //everything has been read - if (readBufferPos >= end) - { - break; - } - k = readBufferPos; - continue; - } - error(" malformed entity reference"); - } - - } - readBufferPos = bufferPosMark; - break; - case ENTITY_TEXT: - if (externalAllowed) - { - pushURL(false, name, getEntityIds(name), - null, null, null, true); - } - else - { - error("reference to external entity in attribute value.", - name, null); - } - break; - case ENTITY_NDATA: - if (externalAllowed) - { - error("unparsed entity reference in content", name, null); - } - else - { - error("reference to external entity in attribute value.", - name, null); - } - break; - default: - throw new RuntimeException(); - } - } - - /** - * Parse and expand a parameter entity reference. - * <pre> - * [69] PEReference ::= '%' Name ';' - * </pre> - * <p>NOTE: the '%' has already been read. - */ - private void parsePEReference() - throws SAXException, IOException - { - String name; - - name = "%" + readNmtoken(true); - require(';'); - switch (getEntityType(name)) - { - case ENTITY_UNDECLARED: - // VC: Entity Declared - handler.verror("reference to undeclared parameter entity " + name); - - // we should disable handling of all subsequent declarations - // unless this is a standalone document (info discarded) - break; - case ENTITY_INTERNAL: - if (inLiteral) - { - pushString(name, getEntityValue(name)); - } - else - { - pushString(name, ' ' + getEntityValue(name) + ' '); - } - break; - case ENTITY_TEXT: - if (!inLiteral) - { - pushString(null, " "); - } - pushURL(true, name, getEntityIds(name), null, null, null, true); - if (!inLiteral) - { - pushString(null, " "); - } - break; - } - } - - /** - * Parse an entity declaration. - * <pre> - * [70] EntityDecl ::= GEDecl | PEDecl - * [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>' - * [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>' - * [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) - * [74] PEDef ::= EntityValue | ExternalID - * [75] ExternalID ::= 'SYSTEM' S SystemLiteral - * | 'PUBLIC' S PubidLiteral S SystemLiteral - * [76] NDataDecl ::= S 'NDATA' S Name - * </pre> - * <p>NOTE: the '<!ENTITY' has already been read. - */ - private void parseEntityDecl() - throws Exception - { - boolean peFlag = false; - int flags = 0; - - // Check for a parameter entity. - expandPE = false; - requireWhitespace(); - if (tryRead('%')) - { - peFlag = true; - requireWhitespace(); - } - expandPE = true; - - // Read the entity name, and prepend - // '%' if necessary. - String name = readNmtoken(true); - //NE08 - if (name.indexOf(':') >= 0) - { - error("Illegal character(':') in entity name ", name, null); - } - if (peFlag) - { - name = "%" + name; - } - - // Read the entity value. - requireWhitespace(); - char c = readCh(); - unread (c); - if (c == '"' || c == '\'') - { - // Internal entity ... replacement text has expanded refs - // to characters and PEs, but not to general entities - String value = readLiteral(flags); - setInternalEntity(name, value); - } - else - { - // Read the external IDs - ExternalIdentifiers ids = readExternalIds(false, false); - - // Check for NDATA declaration. - boolean white = tryWhitespace(); - if (!peFlag && tryRead("NDATA")) - { - if (!white) - { - error("whitespace required before NDATA"); - } - requireWhitespace(); - String notationName = readNmtoken(true); - if (!skippedPE) - { - setExternalEntity(name, ENTITY_NDATA, ids, notationName); - handler.unparsedEntityDecl(name, ids.publicId, ids.systemId, - ids.baseUri, notationName); - } - } - else if (!skippedPE) - { - setExternalEntity(name, ENTITY_TEXT, ids, null); - handler.getDeclHandler() - .externalEntityDecl(name, ids.publicId, - handler.resolveURIs() - // FIXME: ASSUMES not skipped - // "false" forces error on bad URI - ? handler.absolutize(ids.baseUri, - ids.systemId, - false) - : ids.systemId); - } - } - - // Finish the declaration. - skipWhitespace(); - require('>'); - } - - /** - * Parse a notation declaration. - * <pre> - * [82] NotationDecl ::= '<!NOTATION' S Name S - * (ExternalID | PublicID) S? '>' - * [83] PublicID ::= 'PUBLIC' S PubidLiteral - * </pre> - * <P>NOTE: the '<!NOTATION' has already been read. - */ - private void parseNotationDecl() - throws Exception - { - String nname; - ExternalIdentifiers ids; - - requireWhitespace(); - nname = readNmtoken(true); - //NE08 - if (nname.indexOf(':') >= 0) - { - error("Illegal character(':') in notation name ", nname, null); - } - requireWhitespace(); - - // Read the external identifiers. - ids = readExternalIds(true, false); - - // Register the notation. - setNotation(nname, ids); - - skipWhitespace(); - require('>'); - } - - /** - * Parse character data. - * <pre> - * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) - * </pre> - */ - private void parseCharData() - throws Exception - { - char c; - int state = 0; - boolean pureWhite = false; - - // assert (dataBufferPos == 0); - - // are we expecting pure whitespace? it might be dirty... - if ((currentElementContent == CONTENT_ELEMENTS) && !isDirtyCurrentElement) - { - pureWhite = true; - } - - // always report right out of readBuffer - // to minimize (pointless) buffer copies - while (true) - { - int lineAugment = 0; - int columnAugment = 0; - int i; - -loop: - for (i = readBufferPos; i < readBufferLength; i++) - { - switch (c = readBuffer[i]) - { - case '\n': - lineAugment++; - columnAugment = 0; - // pureWhite unmodified - break; - case '\r': // should not happen!! - case '\t': - case ' ': - // pureWhite unmodified - columnAugment++; - break; - case '&': - case '<': - columnAugment++; - // pureWhite unmodified - // CLEAN end of text sequence - state = 1; - break loop; - case ']': - // that's not a whitespace char, and - // can not terminate pure whitespace either - pureWhite = false; - if ((i + 2) < readBufferLength) - { - if (readBuffer [i + 1] == ']' - && readBuffer [i + 2] == '>') - { - // ERROR end of text sequence - state = 2; - break loop; - } - } - else - { - // FIXME missing two end-of-buffer cases - } - columnAugment++; - break; - default: - if ((c < 0x0020 || c > 0xFFFD) - || ((c >= 0x007f) && (c <= 0x009f) && (c != 0x0085) - && xmlVersion == XML_11)) - { - error("illegal XML character U+" - + Integer.toHexString(c)); - } - // that's not a whitespace char - pureWhite = false; - columnAugment++; - } - } - - // report text thus far - if (lineAugment > 0) - { - line += lineAugment; - column = columnAugment; - } - else - { - column += columnAugment; - } - - // report characters/whitspace - int length = i - readBufferPos; - - if (length != 0) - { - if (pureWhite) - { - handler.ignorableWhitespace(readBuffer, - readBufferPos, length); - } - else - { - handler.charData(readBuffer, readBufferPos, length); - } - readBufferPos = i; - } - - if (state != 0) - { - break; - } - - // fill next buffer from this entity, or - // pop stack and continue with previous entity - unread(readCh()); - } - if (!pureWhite) - { - isDirtyCurrentElement = true; - } - // finish, maybe with error - if (state != 1) // finish, no error - { - error("character data may not contain ']]>'"); - } - } - - ////////////////////////////////////////////////////////////////////// - // High-level reading and scanning methods. - ////////////////////////////////////////////////////////////////////// - - /** - * Require whitespace characters. - */ - private void requireWhitespace() - throws SAXException, IOException - { - char c = readCh(); - if (isWhitespace(c)) - { - skipWhitespace(); - } - else - { - error("whitespace required", c, null); - } - } - - /** - * Skip whitespace characters. - * <pre> - * [3] S ::= (#x20 | #x9 | #xd | #xa)+ - * </pre> - */ - private void skipWhitespace() - throws SAXException, IOException - { - // Start with a little cheat. Most of - // the time, the white space will fall - // within the current read buffer; if - // not, then fall through. - if (USE_CHEATS) - { - int lineAugment = 0; - int columnAugment = 0; - -loop: - for (int i = readBufferPos; i < readBufferLength; i++) - { - switch (readBuffer[i]) - { - case ' ': - case '\t': - case '\r': - columnAugment++; - break; - case '\n': - lineAugment++; - columnAugment = 0; - break; - case '%': - if (expandPE) - { - break loop; - } - // else fall through... - default: - readBufferPos = i; - if (lineAugment > 0) - { - line += lineAugment; - column = columnAugment; - } - else - { - column += columnAugment; - } - return; - } - } - } - - // OK, do it the slow way. - char c = readCh (); - while (isWhitespace(c)) - { - c = readCh(); - } - unread(c); - } - - /** - * Read a name or (when parsing an enumeration) name token. - * <pre> - * [5] Name ::= (Letter | '_' | ':') (NameChar)* - * [7] Nmtoken ::= (NameChar)+ - * </pre> - */ - private String readNmtoken(boolean isName) - throws SAXException, IOException - { - char c; - - if (USE_CHEATS) - { -loop: - for (int i = readBufferPos; i < readBufferLength; i++) - { - c = readBuffer[i]; - switch (c) - { - case '%': - if (expandPE) - { - break loop; - } - // else fall through... - - // What may legitimately come AFTER a name/nmtoken? - case '<': case '>': case '&': - case ',': case '|': case '*': case '+': case '?': - case ')': - case '=': - case '\'': case '"': - case '[': - case ' ': case '\t': case '\r': case '\n': - case ';': - case '/': - int start = readBufferPos; - if (i == start) - { - error("name expected", readBuffer[i], null); - } - readBufferPos = i; - return intern(readBuffer, start, i - start); - - default: - // FIXME ... per IBM's OASIS test submission, these: - // ? U+06dd - // Combining U+309B - //these switches are kind of ugly but at least we won't - //have to go over the whole lits for each char - if (isName && i == readBufferPos) - { - char c2 = (char) (c & 0x00f0); - switch (c & 0xff00) - { - //starting with 01 - case 0x0100: - switch (c2) - { - case 0x0030: - if (c == 0x0132 || c == 0x0133 || c == 0x013f) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x0040: - if (c == 0x0140 || c == 0x0149) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x00c0: - if (c == 0x01c4 || c == 0x01cc) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x00f0: - if (c == 0x01f1 || c == 0x01f3) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x00b0: - if (c == 0x01f1 || c == 0x01f3) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - default: - if (c == 0x017f) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - } - - break; - //starting with 11 - case 0x1100: - switch (c2) - { - case 0x0000: - if (c == 0x1104 || c == 0x1108 || - c == 0x110a || c == 0x110d) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x0030: - if (c == 0x113b || c == 0x113f) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x0040: - if (c == 0x1141 || c == 0x114d - || c == 0x114f ) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x0050: - if (c == 0x1151 || c == 0x1156) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x0060: - if (c == 0x1162 || c == 0x1164 - || c == 0x1166 || c == 0x116b - || c == 0x116f) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - case 0x00b0: - if (c == 0x11b6 || c == 0x11b9 - || c == 0x11bb || c == 0x116f) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - break; - default: - if (c == 0x1174 || c == 0x119f - || c == 0x11ac || c == 0x11c3 - || c == 0x11f1) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - } - break; - default: - if (c == 0x0e46 || c == 0x1011 - || c == 0x212f || c == 0x0587 - || c == 0x0230 ) - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - } - } - // punt on exact tests from Appendix A; approximate - // them using the Unicode ID start/part rules - if (i == readBufferPos && isName) - { - if (!Character.isUnicodeIdentifierStart(c) - && c != ':' && c != '_') - { - error("Not a name start character, U+" - + Integer.toHexString(c)); - } - } - else if (!Character.isUnicodeIdentifierPart(c) - && c != '-' && c != ':' && c != '_' && c != '.' - && !isExtender(c)) - { - error("Not a name character, U+" - + Integer.toHexString(c)); - } - } - } - } - - nameBufferPos = 0; - - // Read the first character. -loop: - while (true) - { - c = readCh(); - switch (c) - { - case '%': - case '<': case '>': case '&': - case ',': case '|': case '*': case '+': case '?': - case ')': - case '=': - case '\'': case '"': - case '[': - case ' ': case '\t': case '\n': case '\r': - case ';': - case '/': - unread(c); - if (nameBufferPos == 0) - { - error ("name expected"); - } - // punt on exact tests from Appendix A, but approximate them - if (isName - && !Character.isUnicodeIdentifierStart(nameBuffer[0]) - && ":_".indexOf(nameBuffer[0]) == -1) - { - error("Not a name start character, U+" - + Integer.toHexString(nameBuffer[0])); - } - String s = intern(nameBuffer, 0, nameBufferPos); - nameBufferPos = 0; - return s; - default: - // punt on exact tests from Appendix A, but approximate them - - if ((nameBufferPos != 0 || !isName) - && !Character.isUnicodeIdentifierPart(c) - && ":-_.".indexOf(c) == -1 - && !isExtender(c)) - { - error("Not a name character, U+" - + Integer.toHexString(c)); - } - if (nameBufferPos >= nameBuffer.length) - { - nameBuffer = - (char[]) extendArray(nameBuffer, - nameBuffer.length, nameBufferPos); - } - nameBuffer[nameBufferPos++] = c; - } - } - } - - private static boolean isExtender(char c) - { - // [88] Extender ::= ... - return c == 0x00b7 || c == 0x02d0 || c == 0x02d1 || c == 0x0387 - || c == 0x0640 || c == 0x0e46 || c == 0x0ec6 || c == 0x3005 - || (c >= 0x3031 && c <= 0x3035) - || (c >= 0x309d && c <= 0x309e) - || (c >= 0x30fc && c <= 0x30fe); - } - - /** - * Read a literal. With matching single or double quotes as - * delimiters (and not embedded!) this is used to parse: - * <pre> - * [9] EntityValue ::= ... ([^%&] | PEReference | Reference)* ... - * [10] AttValue ::= ... ([^<&] | Reference)* ... - * [11] SystemLiteral ::= ... (URLchar - "'")* ... - * [12] PubidLiteral ::= ... (PubidChar - "'")* ... - * </pre> - * as well as the quoted strings in XML and text declarations - * (for version, encoding, and standalone) which have their - * own constraints. - */ - private String readLiteral(int flags) - throws SAXException, IOException - { - char delim, c; - int startLine = line; - boolean saved = expandPE; - boolean savedReport = doReport; - - // Find the first delimiter. - delim = readCh(); - if (delim != '"' && delim != '\'') - { - error("expected '\"' or \"'\"", delim, null); - return null; - } - inLiteral = true; - if ((flags & LIT_DISABLE_PE) != 0) - { - expandPE = false; - } - doReport = false; - - // Each level of input source has its own buffer; remember - // ours, so we won't read the ending delimiter from any - // other input source, regardless of entity processing. - char[] ourBuf = readBuffer; - - // Read the literal. - try - { - c = readCh(); - boolean ampRead = false; -loop: - while (! (c == delim && readBuffer == ourBuf)) - { - switch (c) - { - // attributes and public ids are normalized - // in almost the same ways - case '\n': - case '\r': - if ((flags & (LIT_ATTRIBUTE | LIT_PUBID)) != 0) - { - c = ' '; - } - break; - case '\t': - if ((flags & LIT_ATTRIBUTE) != 0) - { - c = ' '; - } - break; - case '&': - c = readCh(); - // Char refs are expanded immediately, except for - // all the cases where it's deferred. - if (c == '#') - { - if ((flags & LIT_DISABLE_CREF) != 0) - { - dataBufferAppend('&'); - break; - } - parseCharRef(false /* Do not do flushDataBuffer */); - - // exotic WFness risk: this is an entity literal, - // dataBuffer [dataBufferPos - 1] == '&', and - // following chars are a _partial_ entity/char ref - - // It looks like an entity ref ... - } - else - { - unread(c); - // Expand it? - if ((flags & LIT_ENTITY_REF) > 0) - { - parseEntityRef(false); - if (String.valueOf(readBuffer).equals("&")) - { - ampRead = true; - } - //Is it just data? - } - else if ((flags & LIT_DISABLE_EREF) != 0) - { - dataBufferAppend('&'); - - // OK, it will be an entity ref -- expanded later. - } - else - { - String name = readNmtoken(true); - require(';'); - dataBufferAppend('&'); - dataBufferAppend(name); - dataBufferAppend(';'); - } - } - c = readCh(); - continue loop; - - case '<': - // and why? Perhaps so "&foo;" expands the same - // inside and outside an attribute? - if ((flags & LIT_ATTRIBUTE) != 0) - { - error("attribute values may not contain '<'"); - } - break; - - // We don't worry about case '%' and PE refs, readCh does. - - default: - break; - } - dataBufferAppend(c); - c = readCh(); - } - } - catch (EOFException e) - { - error("end of input while looking for delimiter (started on line " - + startLine + ')', null, new Character(delim).toString()); - } - inLiteral = false; - expandPE = saved; - doReport = savedReport; - - // Normalise whitespace if necessary. - if ((flags & LIT_NORMALIZE) > 0) - { - dataBufferNormalize(); - } - - // Return the value. - return dataBufferToString(); - } - - /** - * Try reading external identifiers. - * A system identifier is not required for notations. - * @param inNotation Are we parsing a notation decl? - * @param isSubset Parsing external subset decl (may be omitted)? - * @return A three-member String array containing the identifiers, - * or nulls. Order: public, system, baseURI. - */ - private ExternalIdentifiers readExternalIds(boolean inNotation, - boolean isSubset) - throws Exception - { - char c; - ExternalIdentifiers ids = new ExternalIdentifiers(); - int flags = LIT_DISABLE_CREF | LIT_DISABLE_PE | LIT_DISABLE_EREF; - - if (tryRead("PUBLIC")) - { - requireWhitespace(); - ids.publicId = readLiteral(LIT_NORMALIZE | LIT_PUBID | flags); - if (inNotation) - { - skipWhitespace(); - c = readCh(); - unread(c); - if (c == '"' || c == '\'') - { - ids.systemId = readLiteral(flags); - } - } - else - { - requireWhitespace(); - ids.systemId = readLiteral(flags); - } - - for (int i = 0; i < ids.publicId.length(); i++) - { - c = ids.publicId.charAt(i); - if (c >= 'a' && c <= 'z') - { - continue; - } - if (c >= 'A' && c <= 'Z') - { - continue; - } - if (" \r\n0123456789-' ()+,./:=?;!*#@$_%".indexOf(c) != -1) - { - continue; - } - error("illegal PUBLIC id character U+" - + Integer.toHexString(c)); - } - } - else if (tryRead("SYSTEM")) - { - requireWhitespace(); - ids.systemId = readLiteral(flags); - } - else if (!isSubset) - { - error("missing SYSTEM or PUBLIC keyword"); - } - - if (ids.systemId != null) - { - if (ids.systemId.indexOf('#') != -1) - { - handler.verror("SYSTEM id has a URI fragment: " + ids.systemId); - } - ids.baseUri = handler.getSystemId(); - if (ids.baseUri == null && uriWarnings) - { - handler.warn("No base URI; hope URI is absolute: " - + ids.systemId); - } - } - - return ids; - } - - /** - * Test if a character is whitespace. - * <pre> - * [3] S ::= (#x20 | #x9 | #xd | #xa)+ - * </pre> - * @param c The character to test. - * @return true if the character is whitespace. - */ - private final boolean isWhitespace(char c) - { - if (c > 0x20) - { - return false; - } - if (c == 0x20 || c == 0x0a || c == 0x09 || c == 0x0d) - { - return true; - } - return false; // illegal ... - } - - ////////////////////////////////////////////////////////////////////// - // Utility routines. - ////////////////////////////////////////////////////////////////////// - - /** - * Add a character to the data buffer. - */ - private void dataBufferAppend(char c) - { - // Expand buffer if necessary. - if (dataBufferPos >= dataBuffer.length) - { - dataBuffer = (char[]) extendArray(dataBuffer, - dataBuffer.length, dataBufferPos); - } - dataBuffer[dataBufferPos++] = c; - } - - /** - * Add a string to the data buffer. - */ - private void dataBufferAppend(String s) - { - dataBufferAppend(s.toCharArray(), 0, s.length()); - } - - /** - * Append (part of) a character array to the data buffer. - */ - private void dataBufferAppend(char[] ch, int start, int length) - { - dataBuffer = (char[]) extendArray(dataBuffer, dataBuffer.length, - dataBufferPos + length); - - System.arraycopy(ch, start, dataBuffer, dataBufferPos, length); - dataBufferPos += length; - } - - /** - * Normalise space characters in the data buffer. - */ - private void dataBufferNormalize() - { - int i = 0; - int j = 0; - int end = dataBufferPos; - - // Skip spaces at the start. - while (j < end && dataBuffer[j] == ' ') - { - j++; - } - - // Skip whitespace at the end. - while (end > j && dataBuffer[end - 1] == ' ') - { - end --; - } - - // Start copying to the left. - while (j < end) - { - - char c = dataBuffer[j++]; - - // Normalise all other spaces to - // a single space. - if (c == ' ') - { - while (j < end && dataBuffer[j++] == ' ') - { - continue; - } - dataBuffer[i++] = ' '; - dataBuffer[i++] = dataBuffer[j - 1]; - } - else - { - dataBuffer[i++] = c; - } - } - - // The new length is <= the old one. - dataBufferPos = i; - } - - /** - * Convert the data buffer to a string. - */ - private String dataBufferToString() - { - String s = new String(dataBuffer, 0, dataBufferPos); - dataBufferPos = 0; - return s; - } - - /** - * Flush the contents of the data buffer to the handler, as - * appropriate, and reset the buffer for new input. - */ - private void dataBufferFlush() - throws SAXException - { - if (currentElementContent == CONTENT_ELEMENTS - && dataBufferPos > 0 - && !inCDATA) - { - // We can't just trust the buffer to be whitespace, there - // are (error) cases when it isn't - for (int i = 0; i < dataBufferPos; i++) - { - if (!isWhitespace(dataBuffer[i])) - { - handler.charData(dataBuffer, 0, dataBufferPos); - dataBufferPos = 0; - } - } - if (dataBufferPos > 0) - { - handler.ignorableWhitespace(dataBuffer, 0, dataBufferPos); - dataBufferPos = 0; - } - } - else if (dataBufferPos > 0) - { - handler.charData(dataBuffer, 0, dataBufferPos); - dataBufferPos = 0; - } - } - - /** - * Require a string to appear, or throw an exception. - * <p><em>Precondition:</em> Entity expansion is not required. - * <p><em>Precondition:</em> data buffer has no characters that - * will get sent to the application. - */ - private void require(String delim) - throws SAXException, IOException - { - int length = delim.length(); - char[] ch; - - if (length < dataBuffer.length) - { - ch = dataBuffer; - delim.getChars(0, length, ch, 0); - } - else - { - ch = delim.toCharArray(); - } - - if (USE_CHEATS && length <= (readBufferLength - readBufferPos)) - { - int offset = readBufferPos; - - for (int i = 0; i < length; i++, offset++) - { - if (ch[i] != readBuffer[offset]) - { - error ("required string", null, delim); - } - } - readBufferPos = offset; - - } - else - { - for (int i = 0; i < length; i++) - { - require(ch[i]); - } - } - } - - /** - * Require a character to appear, or throw an exception. - */ - private void require(char delim) - throws SAXException, IOException - { - char c = readCh(); - - if (c != delim) - { - error("required character", c, new Character(delim).toString()); - } - } - - /** - * Create an interned string from a character array. - * Ælfred uses this method to create an interned version - * of all names and name tokens, so that it can test equality - * with <code>==</code> instead of <code>String.equals ()</code>. - * - * <p>This is much more efficient than constructing a non-interned - * string first, and then interning it. - * - * @param ch an array of characters for building the string. - * @param start the starting position in the array. - * @param length the number of characters to place in the string. - * @return an interned string. - * @see #intern (String) - * @see java.lang.String#intern - */ - public String intern(char[] ch, int start, int length) - { - int index = 0; - int hash = 0; - Object[] bucket; - - // Generate a hash code. This is a widely used string hash, - // often attributed to Brian Kernighan. - for (int i = start; i < start + length; i++) - { - hash = 31 * hash + ch[i]; - } - hash = (hash & 0x7fffffff) % SYMBOL_TABLE_LENGTH; - - // Get the bucket -- consists of {array,String} pairs - if ((bucket = symbolTable[hash]) == null) - { - // first string in this bucket - bucket = new Object[8]; - - // Search for a matching tuple, and - // return the string if we find one. - } - else - { - while (index < bucket.length) - { - char[] chFound = (char[]) bucket[index]; - - // Stop when we hit an empty entry. - if (chFound == null) - { - break; - } - - // If they're the same length, check for a match. - if (chFound.length == length) - { - for (int i = 0; i < chFound.length; i++) - { - // continue search on failure - if (ch[start + i] != chFound[i]) - { - break; - } - else if (i == length - 1) - { - // That's it, we have a match! - return (String) bucket[index + 1]; - } - } - } - index += 2; - } - // Not found -- we'll have to add it. - - // Do we have to grow the bucket? - bucket = (Object[]) extendArray(bucket, bucket.length, index); - } - symbolTable[hash] = bucket; - - // OK, add it to the end of the bucket -- "local" interning. - // Intern "globally" to let applications share interning benefits. - // That is, "!=" and "==" work on our strings, not just equals(). - String s = new String(ch, start, length).intern(); - bucket[index] = s.toCharArray(); - bucket[index + 1] = s; - return s; - } - - /** - * Ensure the capacity of an array, allocating a new one if - * necessary. Usually extends only for name hash collisions. - */ - private Object extendArray(Object array, int currentSize, int requiredSize) - { - if (requiredSize < currentSize) - { - return array; - } - else - { - Object newArray = null; - int newSize = currentSize * 2; - - if (newSize <= requiredSize) - { - newSize = requiredSize + 1; - } - - if (array instanceof char[]) - { - newArray = new char[newSize]; - } - else if (array instanceof Object[]) - { - newArray = new Object[newSize]; - } - else - { - throw new RuntimeException(); - } - - System.arraycopy(array, 0, newArray, 0, currentSize); - return newArray; - } - } - - ////////////////////////////////////////////////////////////////////// - // XML query routines. - ////////////////////////////////////////////////////////////////////// - - boolean isStandalone() - { - return docIsStandalone; - } - - // - // Elements - // - - private int getContentType(ElementDecl element, int defaultType) - { - int retval; - - if (element == null) - { - return defaultType; - } - retval = element.contentType; - if (retval == CONTENT_UNDECLARED) - { - retval = defaultType; - } - return retval; - } - - /** - * Look up the content type of an element. - * @param name The element type name. - * @return An integer constant representing the content type. - * @see #CONTENT_UNDECLARED - * @see #CONTENT_ANY - * @see #CONTENT_EMPTY - * @see #CONTENT_MIXED - * @see #CONTENT_ELEMENTS - */ - public int getElementContentType(String name) - { - ElementDecl element = (ElementDecl) elementInfo.get(name); - return getContentType(element, CONTENT_UNDECLARED); - } - - /** - * Register an element. - * Array format: - * [0] element type name - * [1] content model (mixed, elements only) - * [2] attribute hash table - */ - private void setElement(String name, int contentType, - String contentModel, HashMap attributes) - throws SAXException - { - if (skippedPE) - { - return; - } - - ElementDecl element = (ElementDecl) elementInfo.get(name); - - // first <!ELEMENT ...> or <!ATTLIST ...> for this type? - if (element == null) - { - element = new ElementDecl(); - element.contentType = contentType; - element.contentModel = contentModel; - element.attributes = attributes; - elementInfo.put(name, element); - return; - } - - // <!ELEMENT ...> declaration? - if (contentType != CONTENT_UNDECLARED) - { - // ... following an associated <!ATTLIST ...> - if (element.contentType == CONTENT_UNDECLARED) - { - element.contentType = contentType; - element.contentModel = contentModel; - } - else - { - // VC: Unique Element Type Declaration - handler.verror("multiple declarations for element type: " - + name); - } - } - - // first <!ATTLIST ...>, before <!ELEMENT ...> ? - else if (attributes != null) - { - element.attributes = attributes; - } - } - - /** - * Look up the attribute hash table for an element. - * The hash table is the second item in the element array. - */ - private HashMap getElementAttributes(String name) - { - ElementDecl element = (ElementDecl) elementInfo.get(name); - return (element == null) ? null : element.attributes; - } - - // - // Attributes - // - - /** - * Get the declared attributes for an element type. - * @param elname The name of the element type. - * @return An iterator over all the attributes declared for - * a specific element type. The results will be valid only - * after the DTD (if any) has been parsed. - * @see #getAttributeType - * @see #getAttributeEnumeration - * @see #getAttributeDefaultValueType - * @see #getAttributeDefaultValue - * @see #getAttributeExpandedValue - */ - private Iterator declaredAttributes(ElementDecl element) - { - HashMap attlist; - - if (element == null) - { - return null; - } - if ((attlist = element.attributes) == null) - { - return null; - } - return attlist.keySet().iterator(); - } - - /** - * Get the declared attributes for an element type. - * @param elname The name of the element type. - * @return An iterator over all the attributes declared for - * a specific element type. The results will be valid only - * after the DTD (if any) has been parsed. - * @see #getAttributeType - * @see #getAttributeEnumeration - * @see #getAttributeDefaultValueType - * @see #getAttributeDefaultValue - * @see #getAttributeExpandedValue - */ - public Iterator declaredAttributes(String elname) - { - return declaredAttributes((ElementDecl) elementInfo.get(elname)); - } - - /** - * Retrieve the declared type of an attribute. - * @param name The name of the associated element. - * @param aname The name of the attribute. - * @return An interend string denoting the type, or null - * indicating an undeclared attribute. - */ - public String getAttributeType(String name, String aname) - { - AttributeDecl attribute = getAttribute(name, aname); - return (attribute == null) ? null : attribute.type; - } - - /** - * Retrieve the allowed values for an enumerated attribute type. - * @param name The name of the associated element. - * @param aname The name of the attribute. - * @return A string containing the token list. - */ - public String getAttributeEnumeration(String name, String aname) - { - AttributeDecl attribute = getAttribute(name, aname); - // assert: attribute.enumeration is "ENUMERATION" or "NOTATION" - return (attribute == null) ? null : attribute.enumeration; - } - - /** - * Retrieve the default value of a declared attribute. - * @param name The name of the associated element. - * @param aname The name of the attribute. - * @return The default value, or null if the attribute was - * #IMPLIED or simply undeclared and unspecified. - * @see #getAttributeExpandedValue - */ - public String getAttributeDefaultValue(String name, String aname) - { - AttributeDecl attribute = getAttribute(name, aname); - return (attribute == null) ? null : attribute.value; - } - - /* - -// FIXME: Leaving this in, until W3C finally resolves the confusion -// between parts of the XML 2nd REC about when entity declararations -// are guaranteed to be known. Current code matches what section 5.1 -// (conformance) describes, but some readings of the self-contradicting -// text in 4.1 (the "Entity Declared" WFC and VC) seem to expect that -// attribute expansion/normalization must be deferred in some cases -// (just TRY to identify them!). - - * Retrieve the expanded value of a declared attribute. - * <p>General entities (and char refs) will be expanded (once). - * @param name The name of the associated element. - * @param aname The name of the attribute. - * @return The expanded default value, or null if the attribute was - * #IMPLIED or simply undeclared - * @see #getAttributeDefaultValue - public String getAttributeExpandedValue (String name, String aname) - throws Exception - { - AttributeDecl attribute = getAttribute (name, aname); - - if (attribute == null) { - return null; - } else if (attribute.defaultValue == null && attribute.value != null) { - // we MUST use the same buf for both quotes else the literal - // can't be properly terminated - char buf [] = new char [1]; - int flags = LIT_ENTITY_REF | LIT_ATTRIBUTE; - String type = getAttributeType (name, aname); - - if (type != "CDATA" && type != null) - flags |= LIT_NORMALIZE; - buf [0] = '"'; - pushCharArray (null, buf, 0, 1); - pushString (null, attribute.value); - pushCharArray (null, buf, 0, 1); - attribute.defaultValue = readLiteral (flags); - } - return attribute.defaultValue; - } - */ - - /** - * Retrieve the default value mode of a declared attribute. - * @see #ATTRIBUTE_DEFAULT_SPECIFIED - * @see #ATTRIBUTE_DEFAULT_IMPLIED - * @see #ATTRIBUTE_DEFAULT_REQUIRED - * @see #ATTRIBUTE_DEFAULT_FIXED - */ - public int getAttributeDefaultValueType(String name, String aname) - { - AttributeDecl attribute = getAttribute(name, aname); - return (attribute == null) ? ATTRIBUTE_DEFAULT_UNDECLARED : - attribute.valueType; - } - - /** - * Register an attribute declaration for later retrieval. - * Format: - * - String type - * - String default value - * - int value type - * - enumeration - * - processed default value - */ - private void setAttribute(String elName, String name, String type, - String enumeration, String value, int valueType) - throws Exception - { - HashMap attlist; - - if (skippedPE) - { - return; - } - - // Create a new hashtable if necessary. - attlist = getElementAttributes(elName); - if (attlist == null) - { - attlist = new HashMap(); - } - - // ignore multiple attribute declarations! - if (attlist.get(name) != null) - { - // warn ... - return; - } - else - { - AttributeDecl attribute = new AttributeDecl(); - attribute.type = type; - attribute.value = value; - attribute.valueType = valueType; - attribute.enumeration = enumeration; - attlist.put(name, attribute); - - // save; but don't overwrite any existing <!ELEMENT ...> - setElement(elName, CONTENT_UNDECLARED, null, attlist); - } - } - - /** - * Retrieve the attribute declaration for the given element name and name. - */ - private AttributeDecl getAttribute(String elName, String name) - { - HashMap attlist = getElementAttributes(elName); - return (attlist == null) ? null : (AttributeDecl) attlist.get(name); - } - - // - // Entities - // - - /** - * Find the type of an entity. - * @returns An integer constant representing the entity type. - * @see #ENTITY_UNDECLARED - * @see #ENTITY_INTERNAL - * @see #ENTITY_NDATA - * @see #ENTITY_TEXT - */ - public int getEntityType(String ename) - { - EntityInfo entity = (EntityInfo) entityInfo.get(ename); - return (entity == null) ? ENTITY_UNDECLARED : entity.type; - } - - /** - * Return an external entity's identifiers. - * @param ename The name of the external entity. - * @return The entity's public identifier, system identifier, and base URI. - * Null if the entity was not declared as an external entity. - * @see #getEntityType - */ - public ExternalIdentifiers getEntityIds(String ename) - { - EntityInfo entity = (EntityInfo) entityInfo.get(ename); - return (entity == null) ? null : entity.ids; - } - - /** - * Return an internal entity's replacement text. - * @param ename The name of the internal entity. - * @return The entity's replacement text, or null if - * the entity was not declared as an internal entity. - * @see #getEntityType - */ - public String getEntityValue(String ename) - { - EntityInfo entity = (EntityInfo) entityInfo.get(ename); - return (entity == null) ? null : entity.value; - } - - /** - * Register an entity declaration for later retrieval. - */ - private void setInternalEntity(String eName, String value) - throws SAXException - { - if (skippedPE) - { - return; - } - - if (entityInfo.get(eName) == null) - { - EntityInfo entity = new EntityInfo(); - entity.type = ENTITY_INTERNAL; - entity.value = value; - entityInfo.put(eName, entity); - } - if (handler.stringInterning) - { - if ("lt" == eName || "gt" == eName || "quot" == eName - || "apos" == eName || "amp" == eName) - { - return; - } - } - else - { - if ("lt".equals(eName) || "gt".equals(eName) || "quot".equals(eName) - || "apos".equals(eName) || "amp".equals(eName)) - { - return; - } - } - handler.getDeclHandler().internalEntityDecl(eName, value); - } - - /** - * Register an external entity declaration for later retrieval. - */ - private void setExternalEntity(String eName, int eClass, - ExternalIdentifiers ids, String nName) - { - if (entityInfo.get(eName) == null) - { - EntityInfo entity = new EntityInfo(); - entity.type = eClass; - entity.ids = ids; - entity.notationName = nName; - entityInfo.put(eName, entity); - } - } - - // - // Notations. - // - - /** - * Report a notation declaration, checking for duplicates. - */ - private void setNotation(String nname, ExternalIdentifiers ids) - throws SAXException - { - if (skippedPE) - { - return; - } - - handler.notationDecl(nname, ids.publicId, ids.systemId, ids.baseUri); - if (notationInfo.get(nname) == null) - { - notationInfo.put(nname, nname); - } - else - { - // VC: Unique Notation Name - handler.verror("Duplicate notation name decl: " + nname); - } - } - - // - // Location. - // - - /** - * Return the current line number. - */ - public int getLineNumber() - { - return line; - } - - /** - * Return the current column number. - */ - public int getColumnNumber() - { - return column; - } - - ////////////////////////////////////////////////////////////////////// - // High-level I/O. - ////////////////////////////////////////////////////////////////////// - - /** - * Read a single character from the readBuffer. - * <p>The readDataChunk () method maintains the buffer. - * <p>If we hit the end of an entity, try to pop the stack and - * keep going. - * <p> (This approach doesn't really enforce XML's rules about - * entity boundaries, but this is not currently a validating - * parser). - * <p>This routine also attempts to keep track of the current - * position in external entities, but it's not entirely accurate. - * @return The next available input character. - * @see #unread (char) - * @see #readDataChunk - * @see #readBuffer - * @see #line - * @return The next character from the current input source. - */ - private char readCh() - throws SAXException, IOException - { - // As long as there's nothing in the - // read buffer, try reading more data - // (for an external entity) or popping - // the entity stack (for either). - while (readBufferPos >= readBufferLength) - { - switch (sourceType) - { - case INPUT_READER: - case INPUT_STREAM: - readDataChunk(); - while (readBufferLength < 1) - { - popInput(); - if (readBufferLength < 1) - { - readDataChunk(); - } - } - break; - - default: - - popInput(); - break; - } - } - - char c = readBuffer[readBufferPos++]; - - if (c == '\n') - { - line++; - column = 0; - } - else - { - if (c == '<') - { - /* the most common return to parseContent () ... NOP */ - } - else if (((c < 0x0020 && (c != '\t') && (c != '\r')) || c > 0xFFFD) - || ((c >= 0x007f) && (c <= 0x009f) && (c != 0x0085) - && xmlVersion == XML_11)) - { - error("illegal XML character U+" + Integer.toHexString(c)); - } - - // If we're in the DTD and in a context where PEs get expanded, - // do so ... 1/14/2000 errata identify those contexts. There - // are also spots in the internal subset where PE refs are fatal - // errors, hence yet another flag. - else if (c == '%' && expandPE) - { - if (peIsError) - { - error("PE reference within decl in internal subset."); - } - parsePEReference(); - return readCh(); - } - column++; - } - - return c; - } - - /** - * Push a single character back onto the current input stream. - * <p>This method usually pushes the character back onto - * the readBuffer. - * <p>I don't think that this would ever be called with - * readBufferPos = 0, because the methods always reads a character - * before unreading it, but just in case, I've added a boundary - * condition. - * @param c The character to push back. - * @see #readCh - * @see #unread (char[]) - * @see #readBuffer - */ - private void unread(char c) - throws SAXException - { - // Normal condition. - if (c == '\n') - { - line--; - column = -1; - } - if (readBufferPos > 0) - { - readBuffer[--readBufferPos] = c; - } - else - { - pushString(null, new Character(c).toString()); - } - } - - /** - * Push a char array back onto the current input stream. - * <p>NOTE: you must <em>never</em> push back characters that you - * haven't actually read: use pushString () instead. - * @see #readCh - * @see #unread (char) - * @see #readBuffer - * @see #pushString - */ - private void unread(char[] ch, int length) - throws SAXException - { - for (int i = 0; i < length; i++) - { - if (ch[i] == '\n') - { - line--; - column = -1; - } - } - if (length < readBufferPos) - { - readBufferPos -= length; - } - else - { - pushCharArray(null, ch, 0, length); - } - } - - /** - * Push, or skip, a new external input source. - * The source will be some kind of parsed entity, such as a PE - * (including the external DTD subset) or content for the body. - * - * @param url The java.net.URL object for the entity. - * @see SAXDriver#resolveEntity - * @see #pushString - * @see #sourceType - * @see #pushInput - * @see #detectEncoding - * @see #sourceType - * @see #readBuffer - */ - private void pushURL(boolean isPE, - String ename, - ExternalIdentifiers ids, - Reader reader, - InputStream stream, - String encoding, - boolean doResolve) - throws SAXException, IOException - { - boolean ignoreEncoding; - String systemId; - InputSource source; - - if (!isPE) - { - dataBufferFlush(); - } - - scratch.setPublicId(ids.publicId); - scratch.setSystemId(ids.systemId); - - // See if we should skip or substitute the entity. - // If we're not skipping, resolving reports startEntity() - // and updates the (handler's) stack of URIs. - if (doResolve) - { - // assert (stream == null && reader == null && encoding == null) - source = handler.resolveEntity(isPE, ename, scratch, ids.baseUri); - if (source == null) - { - handler.warn("skipping entity: " + ename); - handler.skippedEntity(ename); - if (isPE) - { - skippedPE = true; - } - return; - } - - // we might be using alternate IDs/encoding - systemId = source.getSystemId(); - // The following warning and setting systemId was deleted bcause - // the application has the option of not setting systemId - // provided that it has set the characte/byte stream. - /* - if (systemId == null) { - handler.warn ("missing system ID, using " + ids.systemId); - systemId = ids.systemId; - } - */ - } - else - { - // "[document]", or "[dtd]" via getExternalSubset() - scratch.setCharacterStream(reader); - scratch.setByteStream(stream); - scratch.setEncoding(encoding); - source = scratch; - systemId = ids.systemId; - if (handler.stringInterning) - { - handler.startExternalEntity(ename, systemId, - "[document]" == ename); - } - else - { - handler.startExternalEntity(ename, systemId, - "[document]".equals(ename)); - } - } - - // we may have been given I/O streams directly - if (source.getCharacterStream() != null) - { - if (source.getByteStream() != null) - error("InputSource has two streams!"); - reader = source.getCharacterStream(); - } - else if (source.getByteStream() != null) - { - encoding = source.getEncoding(); - if (encoding == null) - { - stream = source.getByteStream(); - } - else - { - try - { - reader = new InputStreamReader(source.getByteStream(), - encoding); - } - catch (IOException e) - { - stream = source.getByteStream(); - } - } - } - else if (systemId == null) - { - error("InputSource has no URI!"); - } - scratch.setCharacterStream(null); - scratch.setByteStream(null); - scratch.setEncoding(null); - - // Push the existing status. - pushInput(ename); - - // Create a new read buffer. - // (Note the four-character margin) - readBuffer = new char[READ_BUFFER_MAX + 4]; - readBufferPos = 0; - readBufferLength = 0; - readBufferOverflow = -1; - is = null; - line = 1; - column = 0; - currentByteCount = 0; - - // If there's an explicit character stream, just - // ignore encoding declarations. - if (reader != null) - { - sourceType = INPUT_READER; - this.reader = reader; - tryEncodingDecl(true); - return; - } - - // Else we handle the conversion, and need to ensure - // it's done right. - sourceType = INPUT_STREAM; - if (stream != null) - { - is = stream; - } - else - { - // We have to open our own stream to the URL. - URL url = new URL(systemId); - - externalEntity = url.openConnection(); - externalEntity.connect(); - is = externalEntity.getInputStream(); - } - - // If we get to here, there must be - // an InputStream available. - if (!is.markSupported()) - { - is = new BufferedInputStream(is); - } - - // Get any external encoding label. - if (encoding == null && externalEntity != null) - { - // External labels can be untrustworthy; filesystems in - // particular often have the wrong default for content - // that wasn't locally originated. Those we autodetect. - if (!"file".equals(externalEntity.getURL().getProtocol())) - { - int temp; - - // application/xml;charset=something;otherAttr=... - // ... with many variants on 'something' - encoding = externalEntity.getContentType(); - - // MHK code (fix for Saxon 5.5.1/007): - // protect against encoding==null - if (encoding == null) - { - temp = -1; - } - else - { - temp = encoding.indexOf("charset"); - } - - // RFC 2376 sez MIME text defaults to ASCII, but since the - // JDK will create a MIME type out of thin air, we always - // autodetect when there's no explicit charset attribute. - if (temp < 0) - { - encoding = null; // autodetect - } - else - { - // only this one attribute - if ((temp = encoding.indexOf(';')) > 0) - { - encoding = encoding.substring(0, temp); - } - - if ((temp = encoding.indexOf('=', temp + 7)) > 0) - { - encoding = encoding.substring(temp + 1); - - // attributes can have comment fields (RFC 822) - if ((temp = encoding.indexOf('(')) > 0) - { - encoding = encoding.substring(0, temp); - } - // ... and values may be quoted - if ((temp = encoding.indexOf('"')) > 0) - { - encoding = - encoding.substring(temp + 1, - encoding.indexOf('"', temp + 2)); - } - encoding.trim(); - } - else - { - handler.warn("ignoring illegal MIME attribute: " - + encoding); - encoding = null; - } - } - } - } - - // if we got an external encoding label, use it ... - if (encoding != null) - { - this.encoding = ENCODING_EXTERNAL; - setupDecoding(encoding); - ignoreEncoding = true; - - // ... else autodetect from first bytes. - } - else - { - detectEncoding(); - ignoreEncoding = false; - } - - // Read any XML or text declaration. - // If we autodetected, it may tell us the "real" encoding. - try - { - tryEncodingDecl(ignoreEncoding); - } - catch (UnsupportedEncodingException x) - { - encoding = x.getMessage(); - - // if we don't handle the declared encoding, - // try letting a JVM InputStreamReader do it - try - { - if (sourceType != INPUT_STREAM) - { - throw x; - } - - is.reset(); - readBufferPos = 0; - readBufferLength = 0; - readBufferOverflow = -1; - line = 1; - currentByteCount = column = 0; - - sourceType = INPUT_READER; - this.reader = new InputStreamReader(is, encoding); - is = null; - - tryEncodingDecl(true); - - } - catch (IOException e) - { - error("unsupported text encoding", - encoding, - null); - } - } - } - - /** - * Check for an encoding declaration. This is the second part of the - * XML encoding autodetection algorithm, relying on detectEncoding to - * get to the point that this part can read any encoding declaration - * in the document (using only US-ASCII characters). - * - * <p> Because this part starts to fill parser buffers with this data, - * it's tricky to setup a reader so that Java's built-in decoders can be - * used for the character encodings that aren't built in to this parser - * (such as EUC-JP, KOI8-R, Big5, etc). - * - * @return any encoding in the declaration, uppercased; or null - * @see detectEncoding - */ - private String tryEncodingDecl(boolean ignoreEncoding) - throws SAXException, IOException - { - // Read the XML/text declaration. - if (tryRead("<?xml")) - { - if (tryWhitespace()) - { - if (inputStack.size() > 0) - { - return parseTextDecl(ignoreEncoding); - } - else - { - return parseXMLDecl(ignoreEncoding); - } - } - else - { - // <?xml-stylesheet ...?> or similar - unread('l'); - unread('m'); - unread('x'); - unread('?'); - unread('<'); - } - } - return null; - } - - /** - * Attempt to detect the encoding of an entity. - * <p>The trick here (as suggested in the XML standard) is that - * any entity not in UTF-8, or in UCS-2 with a byte-order mark, - * <b>must</b> begin with an XML declaration or an encoding - * declaration; we simply have to look for "<?xml" in various - * encodings. - * <p>This method has no way to distinguish among 8-bit encodings. - * Instead, it sets up for UTF-8, then (possibly) revises its assumption - * later in setupDecoding (). Any ASCII-derived 8-bit encoding - * should work, but most will be rejected later by setupDecoding (). - * @see #tryEncoding (byte[], byte, byte, byte, byte) - * @see #tryEncoding (byte[], byte, byte) - * @see #setupDecoding - */ - private void detectEncoding() - throws SAXException, IOException - { - byte[] signature = new byte[4]; - - // Read the first four bytes for - // autodetection. - is.mark(4); - is.read(signature); - is.reset(); - - // - // FIRST: four byte encodings (who uses these?) - // - if (tryEncoding(signature, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x3c)) - { - // UCS-4 must begin with "<?xml" - // 0x00 0x00 0x00 0x3c: UCS-4, big-endian (1234) - // "UTF-32BE" - encoding = ENCODING_UCS_4_1234; - } - else if (tryEncoding(signature, (byte) 0x3c, (byte) 0x00, - (byte) 0x00, (byte) 0x00)) - { - // 0x3c 0x00 0x00 0x00: UCS-4, little-endian (4321) - // "UTF-32LE" - encoding = ENCODING_UCS_4_4321; - } - else if (tryEncoding(signature, (byte) 0x00, (byte) 0x00, - (byte) 0x3c, (byte) 0x00)) - { - // 0x00 0x00 0x3c 0x00: UCS-4, unusual (2143) - encoding = ENCODING_UCS_4_2143; - } - else if (tryEncoding(signature, (byte) 0x00, (byte) 0x3c, - (byte) 0x00, (byte) 0x00)) - { - // 0x00 0x3c 0x00 0x00: UCS-4, unusual (3421) - encoding = ENCODING_UCS_4_3412; - - // 00 00 fe ff UCS_4_1234 (with BOM) - // ff fe 00 00 UCS_4_4321 (with BOM) - } - - // - // SECOND: two byte encodings - // note ... with 1/14/2000 errata the XML spec identifies some - // more "broken UTF-16" autodetection cases, with no XML decl, - // which we don't handle here (that's legal too). - // - else if (tryEncoding(signature, (byte) 0xfe, (byte) 0xff)) - { - // UCS-2 with a byte-order marker. (UTF-16) - // 0xfe 0xff: UCS-2, big-endian (12) - encoding = ENCODING_UCS_2_12; - is.read(); is.read(); - } - else if (tryEncoding(signature, (byte) 0xff, (byte) 0xfe)) - { - // UCS-2 with a byte-order marker. (UTF-16) - // 0xff 0xfe: UCS-2, little-endian (21) - encoding = ENCODING_UCS_2_21; - is.read(); is.read(); - } - else if (tryEncoding(signature, (byte) 0x00, (byte) 0x3c, - (byte) 0x00, (byte) 0x3f)) - { - // UTF-16BE (otherwise, malformed UTF-16) - // 0x00 0x3c 0x00 0x3f: UCS-2, big-endian, no byte-order mark - encoding = ENCODING_UCS_2_12; - error("no byte-order mark for UCS-2 entity"); - } - else if (tryEncoding(signature, (byte) 0x3c, (byte) 0x00, - (byte) 0x3f, (byte) 0x00)) - { - // UTF-16LE (otherwise, malformed UTF-16) - // 0x3c 0x00 0x3f 0x00: UCS-2, little-endian, no byte-order mark - encoding = ENCODING_UCS_2_21; - error("no byte-order mark for UCS-2 entity"); - } - - // - // THIRD: ASCII-derived encodings, fixed and variable lengths - // - else if (tryEncoding(signature, (byte) 0x3c, (byte) 0x3f, - (byte) 0x78, (byte) 0x6d)) - { - // ASCII derived - // 0x3c 0x3f 0x78 0x6d: UTF-8 or other 8-bit markup (read ENCODING) - encoding = ENCODING_UTF_8; - prefetchASCIIEncodingDecl(); - } - else if (signature[0] == (byte) 0xef - && signature[1] == (byte) 0xbb - && signature[2] == (byte) 0xbf) - { - // 0xef 0xbb 0xbf: UTF-8 BOM (not part of document text) - // this un-needed notion slipped into XML 2nd ed through a - // "non-normative" erratum; now required by MSFT and UDDI, - // and E22 made it normative. - encoding = ENCODING_UTF_8; - is.read(); is.read(); is.read(); - } - else - { - // 4c 6f a7 94 ... we don't understand EBCDIC flavors - // ... but we COULD at least kick in some fixed code page - - // (default) UTF-8 without encoding/XML declaration - encoding = ENCODING_UTF_8; - } - } - - /** - * Check for a four-byte signature. - * <p>Utility routine for detectEncoding (). - * <p>Always looks for some part of "<?XML" in a specific encoding. - * @param sig The first four bytes read. - * @param b1 The first byte of the signature - * @param b2 The second byte of the signature - * @param b3 The third byte of the signature - * @param b4 The fourth byte of the signature - * @see #detectEncoding - */ - private static boolean tryEncoding(byte[] sig, byte b1, byte b2, - byte b3, byte b4) - { - return (sig[0] == b1 && sig[1] == b2 - && sig[2] == b3 && sig[3] == b4); - } - - /** - * Check for a two-byte signature. - * <p>Looks for a UCS-2 byte-order mark. - * <p>Utility routine for detectEncoding (). - * @param sig The first four bytes read. - * @param b1 The first byte of the signature - * @param b2 The second byte of the signature - * @see #detectEncoding - */ - private static boolean tryEncoding(byte[] sig, byte b1, byte b2) - { - return ((sig[0] == b1) && (sig[1] == b2)); - } - - /** - * This method pushes a string back onto input. - * <p>It is useful either as the expansion of an internal entity, - * or for backtracking during the parse. - * <p>Call pushCharArray () to do the actual work. - * @param s The string to push back onto input. - * @see #pushCharArray - */ - private void pushString(String ename, String s) - throws SAXException - { - char[] ch = s.toCharArray(); - pushCharArray(ename, ch, 0, ch.length); - } - - /** - * Push a new internal input source. - * <p>This method is useful for expanding an internal entity, - * or for unreading a string of characters. It creates a new - * readBuffer containing the characters in the array, instead - * of characters converted from an input byte stream. - * @param ch The char array to push. - * @see #pushString - * @see #pushURL - * @see #readBuffer - * @see #sourceType - * @see #pushInput - */ - private void pushCharArray(String ename, char[] ch, int start, int length) - throws SAXException - { - // Push the existing status - pushInput(ename); - if (ename != null && doReport) - { - dataBufferFlush(); - handler.startInternalEntity(ename); - } - sourceType = INPUT_INTERNAL; - readBuffer = ch; - readBufferPos = start; - readBufferLength = length; - readBufferOverflow = -1; - } - - /** - * Save the current input source onto the stack. - * <p>This method saves all of the global variables associated with - * the current input source, so that they can be restored when a new - * input source has finished. It also tests for entity recursion. - * <p>The method saves the following global variables onto a stack - * using a fixed-length array: - * <ol> - * <li>sourceType - * <li>externalEntity - * <li>readBuffer - * <li>readBufferPos - * <li>readBufferLength - * <li>line - * <li>encoding - * </ol> - * @param ename The name of the entity (if any) causing the new input. - * @see #popInput - * @see #sourceType - * @see #externalEntity - * @see #readBuffer - * @see #readBufferPos - * @see #readBufferLength - * @see #line - * @see #encoding - */ - private void pushInput(String ename) - throws SAXException - { - // Check for entity recursion. - if (ename != null) - { - Iterator entities = entityStack.iterator(); - while (entities.hasNext()) - { - String e = (String) entities.next(); - if (e != null && e == ename) - { - error("recursive reference to entity", ename, null); - } - } - } - entityStack.addLast(ename); - - // Don't bother if there is no current input. - if (sourceType == INPUT_NONE) - { - return; - } - - // Set up a snapshot of the current - // input source. - Input input = new Input(); - - input.sourceType = sourceType; - input.externalEntity = externalEntity; - input.readBuffer = readBuffer; - input.readBufferPos = readBufferPos; - input.readBufferLength = readBufferLength; - input.line = line; - input.encoding = encoding; - input.readBufferOverflow = readBufferOverflow; - input.is = is; - input.currentByteCount = currentByteCount; - input.column = column; - input.reader = reader; - - // Push it onto the stack. - inputStack.addLast(input); - } - - /** - * Restore a previous input source. - * <p>This method restores all of the global variables associated with - * the current input source. - * @exception java.io.EOFException - * If there are no more entries on the input stack. - * @see #pushInput - * @see #sourceType - * @see #externalEntity - * @see #readBuffer - * @see #readBufferPos - * @see #readBufferLength - * @see #line - * @see #encoding - */ - private void popInput() - throws SAXException, IOException - { - String ename = (String) entityStack.removeLast(); - - if (ename != null && doReport) - { - dataBufferFlush(); - } - switch (sourceType) - { - case INPUT_STREAM: - handler.endExternalEntity(ename); - is.close(); - break; - case INPUT_READER: - handler.endExternalEntity(ename); - reader.close(); - break; - case INPUT_INTERNAL: - if (ename != null && doReport) - { - handler.endInternalEntity(ename); - } - break; - } - - // Throw an EOFException if there - // is nothing else to pop. - if (inputStack.isEmpty()) - { - throw new EOFException("no more input"); - } - - Input input = (Input) inputStack.removeLast(); - - sourceType = input.sourceType; - externalEntity = input.externalEntity; - readBuffer = input.readBuffer; - readBufferPos = input.readBufferPos; - readBufferLength = input.readBufferLength; - line = input.line; - encoding = input.encoding; - readBufferOverflow = input.readBufferOverflow; - is = input.is; - currentByteCount = input.currentByteCount; - column = input.column; - reader = input.reader; - } - - /** - * Return true if we can read the expected character. - * <p>Note that the character will be removed from the input stream - * on success, but will be put back on failure. Do not attempt to - * read the character again if the method succeeds. - * @param delim The character that should appear next. For a - * insensitive match, you must supply this in upper-case. - * @return true if the character was successfully read, or false if - * it was not. - * @see #tryRead (String) - */ - private boolean tryRead(char delim) - throws SAXException, IOException - { - char c; - - // Read the character - c = readCh(); - - // Test for a match, and push the character - // back if the match fails. - if (c == delim) - { - return true; - } - else - { - unread(c); - return false; - } - } - - /** - * Return true if we can read the expected string. - * <p>This is simply a convenience method. - * <p>Note that the string will be removed from the input stream - * on success, but will be put back on failure. Do not attempt to - * read the string again if the method succeeds. - * <p>This method will push back a character rather than an - * array whenever possible (probably the majority of cases). - * @param delim The string that should appear next. - * @return true if the string was successfully read, or false if - * it was not. - * @see #tryRead (char) - */ - private boolean tryRead(String delim) - throws SAXException, IOException - { - return tryRead(delim.toCharArray()); - } - - private boolean tryRead(char[] ch) - throws SAXException, IOException - { - char c; - - // Compare the input, character- - // by character. - - for (int i = 0; i < ch.length; i++) - { - c = readCh(); - if (c != ch[i]) - { - unread(c); - if (i != 0) - { - unread(ch, i); - } - return false; - } - } - return true; - } - - /** - * Return true if we can read some whitespace. - * <p>This is simply a convenience method. - * <p>This method will push back a character rather than an - * array whenever possible (probably the majority of cases). - * @return true if whitespace was found. - */ - private boolean tryWhitespace() - throws SAXException, IOException - { - char c; - c = readCh(); - if (isWhitespace(c)) - { - skipWhitespace(); - return true; - } - else - { - unread(c); - return false; - } - } - - /** - * Read all data until we find the specified string. - * This is useful for scanning CDATA sections and PIs. - * <p>This is inefficient right now, since it calls tryRead () - * for every character. - * @param delim The string delimiter - * @see #tryRead (String, boolean) - * @see #readCh - */ - private void parseUntil(String delim) - throws SAXException, IOException - { - parseUntil(delim.toCharArray()); - } - - private void parseUntil(char[] delim) - throws SAXException, IOException - { - char c; - int startLine = line; - - try - { - while (!tryRead(delim)) - { - c = readCh(); - dataBufferAppend(c); - } - } - catch (EOFException e) - { - error("end of input while looking for delimiter " - + "(started on line " + startLine - + ')', null, new String(delim)); - } - } - - ////////////////////////////////////////////////////////////////////// - // Low-level I/O. - ////////////////////////////////////////////////////////////////////// - - /** - * Prefetch US-ASCII XML/text decl from input stream into read buffer. - * Doesn't buffer more than absolutely needed, so that when an encoding - * decl says we need to create an InputStreamReader, we can discard our - * buffer and reset(). Caller knows the first chars of the decl exist - * in the input stream. - */ - private void prefetchASCIIEncodingDecl() - throws SAXException, IOException - { - int ch; - readBufferPos = readBufferLength = 0; - - is.mark(readBuffer.length); - while (true) - { - ch = is.read(); - readBuffer[readBufferLength++] = (char) ch; - switch (ch) - { - case (int) '>': - return; - case -1: - error("file ends before end of XML or encoding declaration.", - null, "?>"); - } - if (readBuffer.length == readBufferLength) - { - error("unfinished XML or encoding declaration"); - } - } - } - - /** - * Read a chunk of data from an external input source. - * <p>This is simply a front-end that fills the rawReadBuffer - * with bytes, then calls the appropriate encoding handler. - * @see #encoding - * @see #rawReadBuffer - * @see #readBuffer - * @see #filterCR - * @see #copyUtf8ReadBuffer - * @see #copyIso8859_1ReadBuffer - * @see #copyUcs_2ReadBuffer - * @see #copyUcs_4ReadBuffer - */ - private void readDataChunk() - throws SAXException, IOException - { - int count; - - // See if we have any overflow (filterCR sets for CR at end) - if (readBufferOverflow > -1) - { - readBuffer[0] = (char) readBufferOverflow; - readBufferOverflow = -1; - readBufferPos = 1; - sawCR = true; - } - else - { - readBufferPos = 0; - sawCR = false; - } - - // input from a character stream. - if (sourceType == INPUT_READER) - { - count = reader.read(readBuffer, - readBufferPos, READ_BUFFER_MAX - readBufferPos); - if (count < 0) - { - readBufferLength = readBufferPos; - } - else - { - readBufferLength = readBufferPos + count; - } - if (readBufferLength > 0) - { - filterCR(count >= 0); - } - sawCR = false; - return; - } - - // Read as many bytes as possible into the raw buffer. - count = is.read(rawReadBuffer, 0, READ_BUFFER_MAX); - - // Dispatch to an encoding-specific reader method to populate - // the readBuffer. In most parser speed profiles, these routines - // show up at the top of the CPU usage chart. - if (count > 0) - { - switch (encoding) - { - // one byte builtins - case ENCODING_ASCII: - copyIso8859_1ReadBuffer(count, (char) 0x0080); - break; - case ENCODING_UTF_8: - copyUtf8ReadBuffer(count); - break; - case ENCODING_ISO_8859_1: - copyIso8859_1ReadBuffer(count, (char) 0); - break; - - // two byte builtins - case ENCODING_UCS_2_12: - copyUcs2ReadBuffer(count, 8, 0); - break; - case ENCODING_UCS_2_21: - copyUcs2ReadBuffer(count, 0, 8); - break; - - // four byte builtins - case ENCODING_UCS_4_1234: - copyUcs4ReadBuffer(count, 24, 16, 8, 0); - break; - case ENCODING_UCS_4_4321: - copyUcs4ReadBuffer(count, 0, 8, 16, 24); - break; - case ENCODING_UCS_4_2143: - copyUcs4ReadBuffer(count, 16, 24, 0, 8); - break; - case ENCODING_UCS_4_3412: - copyUcs4ReadBuffer(count, 8, 0, 24, 16); - break; - } - } - else - { - readBufferLength = readBufferPos; - } - - readBufferPos = 0; - - // Filter out all carriage returns if we've seen any - // (including any saved from a previous read) - if (sawCR) - { - filterCR(count >= 0); - sawCR = false; - - // must actively report EOF, lest some CRs get lost. - if (readBufferLength == 0 && count >= 0) - { - readDataChunk(); - } - } - - if (count > 0) - { - currentByteCount += count; - } - } - - /** - * Filter carriage returns in the read buffer. - * CRLF becomes LF; CR becomes LF. - * @param moreData true iff more data might come from the same source - * @see #readDataChunk - * @see #readBuffer - * @see #readBufferOverflow - */ - private void filterCR(boolean moreData) - { - int i, j; - - readBufferOverflow = -1; - -loop: - for (i = j = readBufferPos; j < readBufferLength; i++, j++) - { - switch (readBuffer[j]) - { - case '\r': - if (j == readBufferLength - 1) - { - if (moreData) - { - readBufferOverflow = '\r'; - readBufferLength--; - } - else // CR at end of buffer - { - readBuffer[i++] = '\n'; - } - break loop; - } - else if (readBuffer[j + 1] == '\n') - { - j++; - } - readBuffer[i] = '\n'; - break; - - case '\n': - default: - readBuffer[i] = readBuffer[j]; - break; - } - } - readBufferLength = i; - } - - /** - * Convert a buffer of UTF-8-encoded bytes into UTF-16 characters. - * <p>When readDataChunk () calls this method, the raw bytes are in - * rawReadBuffer, and the final characters will appear in - * readBuffer. - * <p>Note that as of Unicode 3.1, good practice became a requirement, - * so that each Unicode character has exactly one UTF-8 representation. - * @param count The number of bytes to convert. - * @see #readDataChunk - * @see #rawReadBuffer - * @see #readBuffer - * @see #getNextUtf8Byte - */ - private void copyUtf8ReadBuffer(int count) - throws SAXException, IOException - { - int i = 0; - int j = readBufferPos; - int b1; - char c = 0; - - /* - // check once, so the runtime won't (if it's smart enough) - if (count < 0 || count > rawReadBuffer.length) - throw new ArrayIndexOutOfBoundsException (Integer.toString (count)); - */ - - while (i < count) - { - b1 = rawReadBuffer[i++]; - - // Determine whether we are dealing - // with a one-, two-, three-, or four- - // byte sequence. - if (b1 < 0) - { - if ((b1 & 0xe0) == 0xc0) - { - // 2-byte sequence: 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx - c = (char) (((b1 & 0x1f) << 6) - | getNextUtf8Byte(i++, count)); - if (c < 0x0080) - { - encodingError("Illegal two byte UTF-8 sequence", - c, 0); - } - - //Sec 2.11 - // [1] the two-character sequence #xD #xA - // [2] the two-character sequence #xD #x85 - if ((c == 0x0085 || c == 0x000a) && sawCR) - { - continue; - } - - // Sec 2.11 - // [3] the single character #x85 - - if (c == 0x0085 && xmlVersion == XML_11) - { - readBuffer[j++] = '\r'; - } - } - else if ((b1 & 0xf0) == 0xe0) - { - // 3-byte sequence: - // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx - // most CJKV characters - c = (char) (((b1 & 0x0f) << 12) | - (getNextUtf8Byte(i++, count) << 6) | - getNextUtf8Byte(i++, count)); - //sec 2.11 - //[4] the single character #x2028 - if (c == 0x2028 && xmlVersion == XML_11) - { - readBuffer[j++] = '\r'; - sawCR = true; - continue; - } - if (c < 0x0800 || (c >= 0xd800 && c <= 0xdfff)) - { - encodingError("Illegal three byte UTF-8 sequence", - c, 0); - } - } - else if ((b1 & 0xf8) == 0xf0) - { - // 4-byte sequence: 11101110wwwwzzzzyy + 110111yyyyxxxxxx - // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx - // (uuuuu = wwww + 1) - // "Surrogate Pairs" ... from the "Astral Planes" - // Unicode 3.1 assigned the first characters there - int iso646 = b1 & 07; - iso646 = (iso646 << 6) + getNextUtf8Byte(i++, count); - iso646 = (iso646 << 6) + getNextUtf8Byte(i++, count); - iso646 = (iso646 << 6) + getNextUtf8Byte(i++, count); - - if (iso646 <= 0xffff) - { - encodingError("Illegal four byte UTF-8 sequence", - iso646, 0); - } - else - { - if (iso646 > 0x0010ffff) - { - encodingError("UTF-8 value out of range for Unicode", - iso646, 0); - } - iso646 -= 0x010000; - readBuffer[j++] = (char) (0xd800 | (iso646 >> 10)); - readBuffer[j++] = (char) (0xdc00 | (iso646 & 0x03ff)); - continue; - } - } - else - { - // The five and six byte encodings aren't supported; - // they exceed the Unicode (and XML) range. - encodingError("unsupported five or six byte UTF-8 sequence", - 0xff & b1, i); - // NOTREACHED - c = 0; - } - } - else - { - // 1-byte sequence: 000000000xxxxxxx = 0xxxxxxx - // (US-ASCII character, "common" case, one branch to here) - c = (char) b1; - } - readBuffer[j++] = c; - if (c == '\r') - { - sawCR = true; - } - } - // How many characters have we read? - readBufferLength = j; - } - - /** - * Return the next byte value in a UTF-8 sequence. - * If it is not possible to get a byte from the current - * entity, throw an exception. - * @param pos The current position in the rawReadBuffer. - * @param count The number of bytes in the rawReadBuffer - * @return The significant six bits of a non-initial byte in - * a UTF-8 sequence. - * @exception EOFException If the sequence is incomplete. - */ - private int getNextUtf8Byte(int pos, int count) - throws SAXException, IOException - { - int val; - - // Take a character from the buffer - // or from the actual input stream. - if (pos < count) - { - val = rawReadBuffer[pos]; - } - else - { - val = is.read(); - if (val == -1) - { - encodingError("unfinished multi-byte UTF-8 sequence at EOF", - -1, pos); - } - } - - // Check for the correct bits at the start. - if ((val & 0xc0) != 0x80) - { - encodingError("bad continuation of multi-byte UTF-8 sequence", - val, pos + 1); - } - - // Return the significant bits. - return (val & 0x3f); - } - - /** - * Convert a buffer of US-ASCII or ISO-8859-1-encoded bytes into - * UTF-16 characters. - * - * <p>When readDataChunk () calls this method, the raw bytes are in - * rawReadBuffer, and the final characters will appear in - * readBuffer. - * - * @param count The number of bytes to convert. - * @param mask For ASCII conversion, 0x7f; else, 0xff. - * @see #readDataChunk - * @see #rawReadBuffer - * @see #readBuffer - */ - private void copyIso8859_1ReadBuffer(int count, char mask) - throws IOException - { - int i, j; - for (i = 0, j = readBufferPos; i < count; i++, j++) - { - char c = (char) (rawReadBuffer[i] & 0xff); - if ((c & mask) != 0) - { - throw new CharConversionException("non-ASCII character U+" - + Integer.toHexString(c)); - } - if (c == 0x0085 && xmlVersion == XML_11) - { - c = '\r'; - } - readBuffer[j] = c; - if (c == '\r') - { - sawCR = true; - } - } - readBufferLength = j; - } - - /** - * Convert a buffer of UCS-2-encoded bytes into UTF-16 characters - * (as used in Java string manipulation). - * - * <p>When readDataChunk () calls this method, the raw bytes are in - * rawReadBuffer, and the final characters will appear in - * readBuffer. - * @param count The number of bytes to convert. - * @param shift1 The number of bits to shift byte 1. - * @param shift2 The number of bits to shift byte 2 - * @see #readDataChunk - * @see #rawReadBuffer - * @see #readBuffer - */ - private void copyUcs2ReadBuffer(int count, int shift1, int shift2) - throws SAXException - { - int j = readBufferPos; - - if (count > 0 && (count % 2) != 0) - { - encodingError("odd number of bytes in UCS-2 encoding", -1, count); - } - // The loops are faster with less internal brancing; hence two - if (shift1 == 0) - { // "UTF-16-LE" - for (int i = 0; i < count; i += 2) - { - char c = (char) (rawReadBuffer[i + 1] << 8); - c |= 0xff & rawReadBuffer[i]; - readBuffer[j++] = c; - if (c == '\r') - { - sawCR = true; - } - } - } - else - { // "UTF-16-BE" - for (int i = 0; i < count; i += 2) - { - char c = (char) (rawReadBuffer[i] << 8); - c |= 0xff & rawReadBuffer[i + 1]; - readBuffer[j++] = c; - if (c == '\r') - { - sawCR = true; - } - } - } - readBufferLength = j; - } - - /** - * Convert a buffer of UCS-4-encoded bytes into UTF-16 characters. - * - * <p>When readDataChunk () calls this method, the raw bytes are in - * rawReadBuffer, and the final characters will appear in - * readBuffer. - * <p>Java has Unicode chars, and this routine uses surrogate pairs - * for ISO-10646 values between 0x00010000 and 0x000fffff. An - * exception is thrown if the ISO-10646 character has no Unicode - * representation. - * - * @param count The number of bytes to convert. - * @param shift1 The number of bits to shift byte 1. - * @param shift2 The number of bits to shift byte 2 - * @param shift3 The number of bits to shift byte 2 - * @param shift4 The number of bits to shift byte 2 - * @see #readDataChunk - * @see #rawReadBuffer - * @see #readBuffer - */ - private void copyUcs4ReadBuffer(int count, int shift1, int shift2, - int shift3, int shift4) - throws SAXException - { - int j = readBufferPos; - - if (count > 0 && (count % 4) != 0) - { - encodingError("number of bytes in UCS-4 encoding " + - "not divisible by 4", - -1, count); - } - for (int i = 0; i < count; i += 4) - { - int value = (((rawReadBuffer [i] & 0xff) << shift1) | - ((rawReadBuffer [i + 1] & 0xff) << shift2) | - ((rawReadBuffer [i + 2] & 0xff) << shift3) | - ((rawReadBuffer [i + 3] & 0xff) << shift4)); - if (value < 0x0000ffff) - { - readBuffer [j++] = (char) value; - if (value == (int) '\r') - { - sawCR = true; - } - } - else if (value < 0x0010ffff) - { - value -= 0x010000; - readBuffer[j++] = (char) (0xd8 | ((value >> 10) & 0x03ff)); - readBuffer[j++] = (char) (0xdc | (value & 0x03ff)); - } - else - { - encodingError("UCS-4 value out of range for Unicode", - value, i); - } - } - readBufferLength = j; - } - - /** - * Report a character encoding error. - */ - private void encodingError(String message, int value, int offset) - throws SAXException - { - if (value != -1) - { - message = message + " (character code: 0x" + - Integer.toHexString(value) + ')'; - error(message); - } - } - - ////////////////////////////////////////////////////////////////////// - // Local Variables. - ////////////////////////////////////////////////////////////////////// - - /** - * Re-initialize the variables for each parse. - */ - private void initializeVariables() - { - // First line - line = 1; - column = 0; - - // Set up the buffers for data and names - dataBufferPos = 0; - dataBuffer = new char[DATA_BUFFER_INITIAL]; - nameBufferPos = 0; - nameBuffer = new char[NAME_BUFFER_INITIAL]; - - // Set up the DTD hash tables - elementInfo = new HashMap(); - entityInfo = new HashMap(); - notationInfo = new HashMap(); - skippedPE = false; - - // Set up the variables for the current - // element context. - currentElement = null; - currentElementContent = CONTENT_UNDECLARED; - - // Set up the input variables - sourceType = INPUT_NONE; - inputStack = new LinkedList(); - entityStack = new LinkedList(); - externalEntity = null; - tagAttributePos = 0; - tagAttributes = new String[100]; - rawReadBuffer = new byte[READ_BUFFER_MAX]; - readBufferOverflow = -1; - - scratch = new InputSource(); - - inLiteral = false; - expandPE = false; - peIsError = false; - - doReport = false; - - inCDATA = false; - - symbolTable = new Object[SYMBOL_TABLE_LENGTH][]; - } - - static class ExternalIdentifiers - { - - String publicId; - String systemId; - String baseUri; - - ExternalIdentifiers() - { - } - - ExternalIdentifiers(String publicId, String systemId, String baseUri) - { - this.publicId = publicId; - this.systemId = systemId; - this.baseUri = baseUri; - } - - } - - static class EntityInfo - { - - int type; - ExternalIdentifiers ids; - String value; - String notationName; - - } - - static class AttributeDecl - { - - String type; - String value; - int valueType; - String enumeration; - String defaultValue; - - } - - static class ElementDecl - { - - int contentType; - String contentModel; - HashMap attributes; - - } - - static class Input - { - - int sourceType; - URLConnection externalEntity; - char[] readBuffer; - int readBufferPos; - int readBufferLength; - int line; - int encoding; - int readBufferOverflow; - InputStream is; - int currentByteCount; - int column; - Reader reader; - - } - -} - diff --git a/libjava/gnu/xml/aelfred2/XmlReader.java b/libjava/gnu/xml/aelfred2/XmlReader.java deleted file mode 100644 index a3bd03a8644..00000000000 --- a/libjava/gnu/xml/aelfred2/XmlReader.java +++ /dev/null @@ -1,374 +0,0 @@ -/* XmlReader.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.aelfred2; - -import java.io.IOException; -import java.util.Locale; - -import org.xml.sax.*; -import org.xml.sax.ext.*; - -import gnu.xml.pipeline.EventFilter; -import gnu.xml.pipeline.ValidationConsumer; - - -/** - * This SAX2 parser optionally layers a validator over the Ælfred2 - * SAX2 parser. While this will not evaluate every XML validity constraint, - * it does support all the validity constraints that are of any real utility - * outside the strict SGML-compatible world. See the documentation for the - * SAXDriver class for information about the SAX2 features and properties - * that are supported, and documentation for the ValidationConsumer for - * information about what validity constraints may not be supported. - * (Ælfred2 tests some of those, even in non-validating mode, to - * achieve better conformance.) - * - * <p> Note that due to its internal construction, you can't change most - * handlers until parse() returns. This diverges slightly from SAX, which - * expects later binding to be supported. Early binding involves less - * runtime overhead, which is an issue for event pipelines as used inside - * this parser. Rather than relying on the parser to handle late binding - * to your own handlers, do it yourself. - * - * @see SAXDriver - * @see gnu.xml.pipeline.ValidationConsumer - * - * @author David Brownell - */ -public final class XmlReader - implements XMLReader -{ - - static class FatalErrorHandler - extends DefaultHandler2 - { - - public void error(SAXParseException e) - throws SAXException - { - throw e; - } - - } - - private SAXDriver aelfred2 = new SAXDriver(); - private EventFilter filter = new EventFilter(); - private boolean isValidating; - private boolean active; - - /** - * Constructs a SAX Parser. - */ - public XmlReader() - { - } - - /** - * Constructs a SAX Parser, optionally treating validity errors - * as if they were fatal errors. - */ - public XmlReader(boolean invalidIsFatal) - { - if (invalidIsFatal) - { - setErrorHandler(new FatalErrorHandler()); - } - } - - /** - * <b>SAX2</b>: Returns the object used to report the logical - * content of an XML document. - */ - public ContentHandler getContentHandler() - { - return filter.getContentHandler(); - } - - /** - * <b>SAX2</b>: Assigns the object used to report the logical - * content of an XML document. - * @exception IllegalStateException if called mid-parse - */ - public void setContentHandler(ContentHandler handler) - { - if (active) - { - throw new IllegalStateException("already parsing"); - } - filter.setContentHandler(handler); - } - - /** - * <b>SAX2</b>: Returns the object used to process declarations related - * to notations and unparsed entities. - */ - public DTDHandler getDTDHandler() - { - return filter.getDTDHandler(); - } - - /** - * <b>SAX1</b> Assigns DTD handler - * @exception IllegalStateException if called mid-parse - */ - public void setDTDHandler(DTDHandler handler) - { - if (active) - { - throw new IllegalStateException("already parsing"); - } - filter.setDTDHandler(handler); - } - - /** - * <b>SAX2</b>: Returns the object used when resolving external - * entities during parsing (both general and parameter entities). - */ - public EntityResolver getEntityResolver() - { - return aelfred2.getEntityResolver(); - } - - /** - * <b>SAX1</b> Assigns parser's entity resolver - */ - public void setEntityResolver(EntityResolver handler) - { - aelfred2.setEntityResolver(handler); - } - - /** - * <b>SAX2</b>: Returns the object used to receive callbacks for XML - * errors of all levels (fatal, nonfatal, warning); this is never null; - */ - public ErrorHandler getErrorHandler() - { - return aelfred2.getErrorHandler(); - } - - /** - * <b>SAX1</b> Assigns error handler - * @exception IllegalStateException if called mid-parse - */ - public void setErrorHandler(ErrorHandler handler) - { - if (active) - { - throw new IllegalStateException("already parsing"); - } - aelfred2.setErrorHandler(handler); - } - - /** - * <b>SAX2</b>: Assigns the specified property. - * @exception IllegalStateException if called mid-parse - */ - public void setProperty(String propertyId, Object value) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if (active) - { - throw new IllegalStateException("already parsing"); - } - if (getProperty(propertyId) != value) - { - filter.setProperty(propertyId, value); - } - } - - /** - * <b>SAX2</b>: Returns the specified property. - */ - public Object getProperty(String propertyId) - throws SAXNotRecognizedException - { - if ((SAXDriver.PROPERTY + "declaration-handler").equals(propertyId) - || (SAXDriver.PROPERTY + "lexical-handler").equals(propertyId)) - { - return filter.getProperty(propertyId); - } - throw new SAXNotRecognizedException(propertyId); - } - - private void forceValidating() - throws SAXNotRecognizedException, SAXNotSupportedException - { - aelfred2.setFeature(SAXDriver.FEATURE + "namespace-prefixes", - true); - aelfred2.setFeature(SAXDriver.FEATURE + "external-general-entities", - true); - aelfred2.setFeature(SAXDriver.FEATURE + "external-parameter-entities", - true); - } - - /** - * <b>SAX2</b>: Sets the state of features supported in this parser. - * Note that this parser requires reporting of namespace prefixes when - * validating. - */ - public void setFeature(String featureId, boolean state) - throws SAXNotRecognizedException, SAXNotSupportedException - { - boolean value = getFeature(featureId); - - if (state == value) - { - return; - } - - if ((SAXDriver.FEATURE + "validation").equals(featureId)) - { - if (active) - { - throw new SAXNotSupportedException("already parsing"); - } - if (state) - { - forceValidating(); - } - isValidating = state; - } - else - { - aelfred2.setFeature(featureId, state); - } - } - - /** - * <b>SAX2</b>: Tells whether this parser supports the specified feature. - * At this time, this directly parallels the underlying SAXDriver, - * except that validation is optionally supported. - * - * @see SAXDriver - */ - public boolean getFeature(String featureId) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if ((SAXDriver.FEATURE + "validation").equals(featureId)) - { - return isValidating; - } - - return aelfred2.getFeature(featureId); - } - - /** - * <b>SAX1</b>: Sets the locale used for diagnostics; currently, - * only locales using the English language are supported. - * @param locale The locale for which diagnostics will be generated - */ - public void setLocale(Locale locale) - throws SAXException - { - aelfred2.setLocale(locale); - } - - /** - * <b>SAX1</b>: Preferred API to parse an XML document, using a - * system identifier (URI). - */ - public void parse(String systemId) - throws SAXException, IOException - { - parse(new InputSource(systemId)); - } - - /** - * <b>SAX1</b>: Underlying API to parse an XML document, used - * directly when no URI is available. When this is invoked, - * and the parser is set to validate, some features will be - * automatically reset to appropriate values: for reporting - * namespace prefixes, and incorporating external entities. - * - * @param source The XML input source. - * - * @exception IllegalStateException if called mid-parse - * @exception SAXException The handlers may throw any SAXException, - * and the parser normally throws SAXParseException objects. - * @exception IOException IOExceptions are normally through through - * the parser if there are problems reading the source document. - */ - public void parse(InputSource source) - throws SAXException, IOException - { - EventFilter next; - boolean nsdecls; - - synchronized (aelfred2) - { - if (active) - { - throw new IllegalStateException("already parsing"); - } - active = true; - } - - // set up the output pipeline - if (isValidating) - { - forceValidating(); - next = new ValidationConsumer(filter); - } - else - { - next = filter; - } - - // connect pipeline and error handler - // don't let _this_ call to bind() affect xmlns* attributes - nsdecls = aelfred2.getFeature(SAXDriver.FEATURE + "namespace-prefixes"); - EventFilter.bind(aelfred2, next); - if (!nsdecls) - { - aelfred2.setFeature(SAXDriver.FEATURE + "namespace-prefixes", - false); - } - - // parse, clean up - try - { - aelfred2.parse(source); - } - finally - { - active = false; - } - } - -} - diff --git a/libjava/gnu/xml/dom/Consumer.java b/libjava/gnu/xml/dom/Consumer.java deleted file mode 100644 index f99e221e998..00000000000 --- a/libjava/gnu/xml/dom/Consumer.java +++ /dev/null @@ -1,368 +0,0 @@ -/* Consumer.java -- - Copyright (C) 2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.xml.dom; - -import org.w3c.dom.DocumentType; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.ext.Attributes2; - -import gnu.xml.pipeline.DomConsumer; -import gnu.xml.pipeline.EventConsumer; - - -/** - * Event consumer which constructs DOM documents using the implementation - * in this package, using SAX2 events. This packages various backdoors - * into this DOM implementation, as needed to address DOM requirements - * that can't be met by strictly conforming implementations of DOM. - * - * <p> These requirements all relate to {@link DocumentType} nodes and - * features of that node type. These features are normally not used, - * because that interface only exposes a subset of the information found - * in DTDs. More, that subset does not include the most important typing - * information. For example, it excludes element content models and - * attribute typing. It does expose some entity management issues, - * although entity management doesn't relate to document typing. - * - * <p> Note that SAX2 does not expose the literal text of the DTD's - * internal subset, so it will not be present in DOM trees constructed - * using this API. (Though with a good SAX2 implementation, it could - * be partially recreated...) - * - * @author David Brownell - */ -public class Consumer extends DomConsumer -{ - /** - * Constructs an unconfigured event consumer, - * as a terminus in a SAX event pipeline. - */ - // used by PipelineFactory [terminus] - public Consumer () - throws SAXException - { - super (DomDocument.class); - setHandler (new Backdoor (this)); - } - - /** - * Constructs an unconfigured event consumer, - * as a stage in a SAX event pipeline. - */ - // used by PipelineFactory [filter] - public Consumer (EventConsumer next) - throws SAXException - { - super (DomDocument.class, next); - setHandler (new Backdoor (this)); - } - - /** - * Implements the backdoors needed by DOM. - * All methods in this class use implementation-specific APIs that are - * implied by the DOM specification (needed to implement testable - * behavior) but which are excluded from the DOM specification. - */ - public static class Backdoor extends DomConsumer.Handler - { - /** - * Constructor. - * @param consumer must have been initialized to use the - * {@link DomDocument} class (or a subclass) for - * constructing DOM trees - */ - protected Backdoor (DomConsumer consumer) - throws SAXException - { super (consumer); } - - // helper routine - private DomDoctype getDoctype () - throws SAXException - { - DomDocument doc = (DomDocument) getDocument (); - DocumentType dt = doc.getDoctype (); - - if (dt == null) - throw new SAXException ("doctype missing!"); - return (DomDoctype) dt; - } - - // SAX2 "lexical" event - public void startDTD (String name, String publicId, String systemId) - throws SAXException - { - DomDocument doc = (DomDocument) getDocument (); - - super.startDTD (name, publicId, systemId); - // DOM L2 doctype creation model is bizarre - DomDoctype dt = new DomDoctype (doc, name, publicId, systemId); - doc.appendChild (dt); - } - - // SAX2 "lexical" event - public void endDTD () - throws SAXException - { - super.endDTD (); - // DOM L2 has no way to make things readonly - getDoctype ().makeReadonly (); - } - - // SAX1 DTD event - public void notationDecl ( - String name, - String publicId, String systemId - ) throws SAXException - { - // DOM L2 can't create/save notation nodes - getDoctype ().declareNotation (name, publicId, systemId); - } - - // SAX1 DTD event - public void unparsedEntityDecl ( - String name, - String publicId, String systemId, - String notationName - ) throws SAXException - { - // DOM L2 can't create/save entity nodes - getDoctype ().declareEntity (name, publicId, systemId, - notationName); - } - - // SAX2 declaration event - public void internalEntityDecl (String name, String value) - throws SAXException - { - // DOM L2 can't create/save entity nodes - // NOTE: this doesn't save the value as a child of this - // node, though it could realistically do so. - getDoctype ().declareEntity (name, null, null, null); - } - - // SAX2 declaration event - public void externalEntityDecl ( - String name, - String publicId, - String systemId - ) throws SAXException - { - // DOM L2 can't create/save entity nodes - // NOTE: DOM allows for these to have children, if - // they don't have unbound namespace references. - getDoctype ().declareEntity (name, publicId, systemId, null); - } - - // SAX2 element - public void startElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - Node top; - - super.startElement (uri, localName, qName, atts); - - // might there be more work? - top = getTop (); - if (!top.hasAttributes () || !(atts instanceof Attributes2)) - return; - - // remember any attributes that got defaulted - DomNamedNodeMap map = (DomNamedNodeMap) top.getAttributes (); - Attributes2 attrs = (Attributes2) atts; - int length = atts.getLength (); - - //map.compact (); - for (int i = 0; i < length; i++) { - if (attrs.isSpecified (i)) - continue; - - // value was defaulted. - String temp = attrs.getQName (i); - DomAttr attr; - - if ("".equals (temp)) - attr = (DomAttr) map.getNamedItemNS (attrs.getURI (i), - atts.getLocalName (i)); - else - attr = (DomAttr) map.getNamedItem (temp); - - // DOM L2 can't write this flag, only read it - attr.setSpecified (false); - } - } - - public void endElement ( - String uri, - String localName, - String qName - ) throws SAXException - { - DomNode top = (DomNode) getTop (); - top.compact (); - super.endElement (uri, localName, qName); - } - - protected Text createText ( - boolean isCDATA, - char buf [], - int off, - int len - ) { - DomDocument doc = (DomDocument) getDocument (); - - if (isCDATA) - return doc.createCDATASection (buf, off, len); - else - return doc.createTextNode (buf, off, len); - } - - public void elementDecl(String name, String model) - throws SAXException - { - getDoctype().elementDecl(name, model); - } - - public void attributeDecl ( - String ename, - String aname, - String type, - String mode, - String value - ) throws SAXException - { - getDoctype().attributeDecl(ename, aname, type, mode, value); - /* - if (value == null && !"ID".equals (type)) - return; - - DomDoctype.ElementInfo info; - - info = getDoctype ().getElementInfo (ename); - if (value != null) - info.setAttrDefault (aname, value); - if ("ID".equals (type)) - info.setIdAttr (aname); - */ - - } - - // force duplicate name checking off while we're - // using parser output (don't duplicate the work) - public void startDocument () throws SAXException - { - super.startDocument (); - - DomDocument doc = (DomDocument) getDocument (); - doc.setStrictErrorChecking(false); - doc.setBuilding(true); - } - - /** - * Required by DOM Level 3 to report document parameters - */ - public void xmlDecl(String version, - String encoding, - boolean standalone, - String inputEncoding) - throws SAXException - { - super.xmlDecl(version, encoding, standalone, inputEncoding); - - DomDocument doc = (DomDocument) getDocument(); - doc.setXmlEncoding(encoding); - doc.setInputEncoding(inputEncoding); - } - - public void endDocument () - throws SAXException - { - DomDocument doc = (DomDocument) getDocument (); - doc.setStrictErrorChecking(true); - doc.setBuilding(false); - doc.compact (); - DomDoctype doctype = (DomDoctype) doc.getDoctype(); - if (doctype != null) - { - doctype.makeReadonly(); - } - super.endDocument (); - } - - // these three methods collaborate to populate entity - // refs, marking contents readonly on end-of-entity - - public boolean canPopulateEntityRefs () - { return true; } - - public void startEntity (String name) - throws SAXException - { - if (name.charAt (0) == '%' || "[dtd]".equals (name)) - return; - super.startEntity (name); - - DomNode top = (DomNode) getTop (); - - if (top.getNodeType () == Node.ENTITY_REFERENCE_NODE) - top.readonly = false; - } - - public void endEntity (String name) - throws SAXException - { - if (name.charAt (0) == '%' || "[dtd]".equals (name)) - return; - DomNode top = (DomNode) getTop (); - - if (top.getNodeType () == Node.ENTITY_REFERENCE_NODE) { - top.compact (); - top.makeReadonly (); - } - super.endEntity (name); - } - } -} diff --git a/libjava/gnu/xml/dom/DTDAttributeTypeInfo.java b/libjava/gnu/xml/dom/DTDAttributeTypeInfo.java deleted file mode 100644 index e3c69c43ecb..00000000000 --- a/libjava/gnu/xml/dom/DTDAttributeTypeInfo.java +++ /dev/null @@ -1,84 +0,0 @@ -/* DTDAttributeTypeInfo.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.TypeInfo; - -/** - * Attribute type information supplied by a DTD attribute declaration. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DTDAttributeTypeInfo - implements TypeInfo -{ - - final String elementName; - final String name; - final String type; - final String mode; - final String value; - - DTDAttributeTypeInfo(String elementName, String name, String type, - String mode, String value) - { - this.elementName = elementName; - this.name = name; - this.type = type; - this.mode = mode; - this.value = value; - } - - public final String getTypeName() - { - return type; - } - - public final String getTypeNamespace() - { - return "http://www.w3.org/TR/REC-xml"; - } - - public final boolean isDerivedFrom(String typeNamespace, String typeName, - int derivationMethod) - { - return false; - } - -} - diff --git a/libjava/gnu/xml/dom/DTDElementTypeInfo.java b/libjava/gnu/xml/dom/DTDElementTypeInfo.java deleted file mode 100644 index c5553e20e62..00000000000 --- a/libjava/gnu/xml/dom/DTDElementTypeInfo.java +++ /dev/null @@ -1,112 +0,0 @@ -/* DTDElementTypeInfo.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.HashMap; -import java.util.Iterator; -import org.w3c.dom.TypeInfo; - -/** - * Element type information provided by a DTD element declaration. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DTDElementTypeInfo - implements TypeInfo -{ - - final String name; - String model; - HashMap attributes; - String idAttrName; - - DTDElementTypeInfo(String name, String model) - { - this.name = name; - this.model = model; - } - - public final String getTypeName() - { - return null; - } - - public final String getTypeNamespace() - { - return "http://www.w3.org/TR/REC-xml"; - } - - public final boolean isDerivedFrom(String typeNamespace, String typeName, - int derivationMethod) - { - return false; - } - - DTDAttributeTypeInfo getAttributeTypeInfo(String name) - { - if (attributes == null) - { - return null; - } - return (DTDAttributeTypeInfo) attributes.get(name); - } - - void setAttributeTypeInfo(String name, DTDAttributeTypeInfo info) - { - if (attributes == null) - { - attributes = new HashMap(); - } - attributes.put(name, info); - if ("ID".equals(info.type)) - { - idAttrName = name; - } - } - - Iterator attributes() - { - if (attributes == null) - { - return null; - } - return attributes.values().iterator(); - } - -} - diff --git a/libjava/gnu/xml/dom/DomAttr.java b/libjava/gnu/xml/dom/DomAttr.java deleted file mode 100644 index 8673a796161..00000000000 --- a/libjava/gnu/xml/dom/DomAttr.java +++ /dev/null @@ -1,380 +0,0 @@ -/* DomAttr.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Attr; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.TypeInfo; -import org.w3c.dom.events.MutationEvent; - - -/** - * <p> "Attr" implementation. In DOM, attributes cost quite a lot of - * memory because their values are complex structures rather than just - * simple strings. To reduce your costs, avoid having more than one - * child of an attribute; stick to a single Text node child, and ignore - * even that by using the attribute's "nodeValue" property.</p> - * - * <p> As a bit of general advice, only look at attribute modification - * events through the DOMAttrModified event (sent to the associated - * element). Implementations are not guaranteed to report other events - * in the same order, so you're very likely to write nonportable code if - * you monitor events at the "children of Attr" level.</p> - * - * <p> At this writing, not all attribute modifications will cause the - * DOMAttrModified event to be triggered ... only the ones using the string - * methods (setNodeValue, setValue, and Element.setAttribute) to modify - * those values. That is, if you manipulate those children directly, - * elements won't get notified that attribute values have changed. - * The natural fix for that will report other modifications, but won't - * be able to expose "previous" attribute value; it'll need to be cached - * or something (at which point why bother using child nodes). </p> - * - * <p><em>You are strongly advised not to use "children" of any attribute - * nodes you work with.</em> </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomAttr - extends DomNsNode - implements Attr -{ - - private boolean specified; - private String value; // string value cache - - /** - * Constructs an Attr node associated with the specified document. - * The "specified" flag is initialized to true, since this DOM has - * no current "back door" mechanisms to manage default values so - * that every value must effectively be "specified". - * - * <p>This constructor should only be invoked by a Document as part of - * its createAttribute functionality, or through a subclass which is - * similarly used in a "Sub-DOM" style layer. - * - * @param owner The document with which this node is associated - * @param namespaceURI Combined with the local part of the name, - * this is used to uniquely identify a type of attribute - * @param name Name of this attribute, which may include a prefix - */ - protected DomAttr(DomDocument owner, String namespaceURI, String name) - { - super(ATTRIBUTE_NODE, owner, namespaceURI, name); - specified = true; - length = 1; - - // XXX register self to get insertion/removal events - // and character data change events and when they happen, - // report self-mutation - } - - /** - * <b>DOM L1</b> - * Returns the attribute name (same as getNodeName) - */ - public final String getName() - { - return getNodeName(); - } - - /** - * <b>DOM L1</b> - * Returns true if a parser reported this was in the source text. - */ - public final boolean getSpecified() - { - return specified; - } - - /** - * Records whether this attribute was in the source text. - */ - public final void setSpecified(boolean value) - { - specified = value; - } - - /** - * <b>DOM L1</b> - * Returns the attribute value, with character and entity - * references substituted. - * <em>NOTE: entity refs as children aren't currently handled.</em> - */ - public String getNodeValue() - { - // If we have a simple node-value, use that - if (first == null) - { - return (value == null) ? "" : value; - } - // Otherwise collect child node-values - StringBuffer buf = new StringBuffer(); - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - switch (ctx.nodeType) - { - case Node.TEXT_NODE: - buf.append(ctx.getNodeValue()); - break; - case Node.ENTITY_REFERENCE_NODE: - // TODO - break; - } - } - return buf.toString(); - } - - /** - * <b>DOM L1</b> - * Assigns the value of the attribute; it will have one child, - * which is a text node with the specified value (same as - * setNodeValue). - */ - public final void setValue(String value) - { - setNodeValue(value); - } - - /** - * <b>DOM L1</b> - * Returns the value of the attribute as a non-null string; same - * as getNodeValue. - * <em>NOTE: entity refs as children aren't currently handled.</em> - */ - public final String getValue() - { - return getNodeValue(); - } - - /** - * <b>DOM L1</b> - * Assigns the attribute value; using this API, no entity or - * character references will exist. - * Causes a DOMAttrModified mutation event to be sent. - */ - public void setNodeValue(String value) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - if (value == null) - { - value = ""; - } - String oldValue = getNodeValue(); - while (last != null) - { - removeChild(last); - } - // don't create a new node just for this... - /* - Node text = owner.createTextNode(value); - appendChild(text); - */ - this.value = value; - length = 1; - specified = true; - - mutating(oldValue, value, MutationEvent.MODIFICATION); - } - - public final Node getFirstChild() - { - // Create a child text node if necessary - if (first == null) - { - length = 0; - Node text = owner.createTextNode((value == null) ? "" : value); - appendChild(text); - } - return first; - } - - public final Node getLastChild() - { - // Create a child text node if necessary - if (last == null) - { - length = 0; - Node text = owner.createTextNode((value == null) ? "" : value); - appendChild(text); - } - return last; - } - - public Node item(int index) - { - // Create a child text node if necessary - if (first == null) - { - length = 0; - Node text = owner.createTextNode((value == null) ? "" : value); - appendChild(text); - } - return super.item(index); - } - - /** - * <b>DOM L2</b> - * Returns the element with which this attribute is associated. - */ - public final Element getOwnerElement() - { - return (Element) parent; - } - - public final Node getNextSibling() - { - return null; - } - - public final Node getPreviousSibling() - { - return null; - } - - public Node getParentNode() - { - return null; - } - - /** - * Records the element with which this attribute is associated. - */ - public final void setOwnerElement(Element e) - { - if (parent != null) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR); - } - if (!(e instanceof DomElement)) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR); - } - parent = (DomElement) e; - depth = parent.depth + 1; - } - - /** - * The base URI of an Attr is always <code>null</code>. - */ - public final String getBaseURI() - { - return null; - } - - /** - * Shallow clone of the attribute, breaking all ties with any - * elements. - */ - public Object clone() - { - DomAttr retval = (DomAttr) super.clone(); - retval.specified = true; - return retval; - } - - private void mutating(String oldValue, String newValue, short why) - { - if (!reportMutations || parent == null) - { - return; - } - - // EVENT: DOMAttrModified, target = parent, - // prev/new values provided, also attr name - MutationEvent event; - - event = (MutationEvent) createEvent ("MutationEvents"); - event.initMutationEvent ("DOMAttrModified", - true /* bubbles */, false /* nocancel */, - null, oldValue, newValue, getNodeName (), why); - parent.dispatchEvent (event); - } - - // DOM Level 3 methods - - public TypeInfo getSchemaTypeInfo() - { - if (parent != null) - { - // DTD implementation - DomDoctype doctype = (DomDoctype) parent.owner.getDoctype(); - if (doctype != null) - { - return doctype.getAttributeTypeInfo(parent.getNodeName(), - getNodeName()); - } - // TODO XML Schema implementation - } - return null; - } - - public boolean isId() - { - if (parent != null) - { - DomDoctype doctype = (DomDoctype) parent.owner.getDoctype(); - if (doctype != null) - { - DTDAttributeTypeInfo info = - doctype.getAttributeTypeInfo(parent.getNodeName(), - getNodeName()); - if (info != null && "ID".equals(info.type)) - { - return true; - } - } - DomElement element = (DomElement) parent; - if (element.userIdAttrs != null && - element.userIdAttrs.contains(this)) - { - return true; - } - // TODO XML Schema implementation - } - return false; - } - -} - diff --git a/libjava/gnu/xml/dom/DomCDATASection.java b/libjava/gnu/xml/dom/DomCDATASection.java deleted file mode 100644 index e34359e71bf..00000000000 --- a/libjava/gnu/xml/dom/DomCDATASection.java +++ /dev/null @@ -1,91 +0,0 @@ -/* DomCDATASection.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.CDATASection; - -/** - * <p> "CDATASection" implementation. - * This is a non-core DOM class, supporting the "XML" feature. - * CDATA sections are just ways to represent text using different - * delimeters. </p> - * - * <p> <em>You are strongly advised not to use CDATASection nodes.</em> - * The advantage of having slightly prettier ways to print text that may - * have lots of embedded XML delimiters, such as "&" and "<", - * can be dwarfed by the cost of dealing with multiple kinds of text - * nodes in all your algorithms. </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomCDATASection - extends DomText - implements CDATASection -{ - - /** - * Constructs a CDATA section node associated with the specified - * document and holding the specified data. - * - * <p>This constructor should only be invoked by a Document as part of - * its createCDATASection functionality, or through a subclass which is - * similarly used in a "Sub-DOM" style layer. - * - */ - protected DomCDATASection(DomDocument owner, String value) - { - super(CDATA_SECTION_NODE, owner, value); - } - - protected DomCDATASection(DomDocument owner, char buf [], int off, int len) - { - super(CDATA_SECTION_NODE, owner, buf, off, len); - } - - /** - * <b>DOM L1</b> - * Returns the string "#cdata-section". - */ - final public String getNodeName() - { - return "#cdata-section"; - } - -} - diff --git a/libjava/gnu/xml/dom/DomCharacterData.java b/libjava/gnu/xml/dom/DomCharacterData.java deleted file mode 100644 index e94dcc4ecf9..00000000000 --- a/libjava/gnu/xml/dom/DomCharacterData.java +++ /dev/null @@ -1,310 +0,0 @@ -/* DomCharacterData.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.CharacterData; -import org.w3c.dom.DOMException; -import org.w3c.dom.events.MutationEvent; - - -/** - * <p> Abstract "CharacterData" implementation. This - * facilitates reusing code in classes implementing subtypes of that DOM - * interface (Text, Comment, CDATASection). </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class DomCharacterData - extends DomNode - implements CharacterData -{ - - private String text; - - // package private - DomCharacterData(short nodeType, DomDocument doc, String value) - { - super(nodeType, doc); - text = (value == null) ? "" : value; - } - - // package private - DomCharacterData(short nodeType, DomDocument doc, - char[] buf, int offset, int length) - { - super(nodeType, doc); - text = (buf == null) ? "" : new String(buf, offset, length); - } - - /** - * <b>DOM L1</b> - * Appends the specified data to the value of this node. - * Causes a DOMCharacterDataModified mutation event to be reported. - */ - public void appendData(String arg) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - String value = text + arg; - mutating(value); - text = value; - } - - /** - * <b>DOM L1</b> - * Modifies the value of this node. - * Causes a DOMCharacterDataModified mutation event to be reported. - */ - public void deleteData(int offset, int count) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - char[] raw = text.toCharArray(); - if (offset < 0 || count < 0 || offset > raw.length) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - if ((offset + count) > raw.length) - { - count = raw.length - offset; - } - if (count == 0) - { - return; - } - try - { - char[] buf = new char[raw.length - count]; - System.arraycopy(raw, 0, buf, 0, offset); - System.arraycopy(raw, offset + count, buf, offset, - raw.length - (offset + count)); - String value = new String(buf); - mutating(value); - text = value; - } - catch (IndexOutOfBoundsException x) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - } - - /** - * <b>DOM L1</b> - * Returns the value of this node. - */ - public String getNodeValue() - { - return text; - } - - /** - * <b>DOM L1</b> - * Returns the value of this node; same as getNodeValue. - */ - public final String getData() - { - return text; - } - - /** - * <b>DOM L1</b> - * Returns the length of the data. - */ - public int getLength() - { - return text.length(); - } - - /** - * <b>DOM L1</b> - * Modifies the value of this node. - */ - public void insertData(int offset, String arg) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - char[] raw = text.toCharArray(); - char[] tmp = arg.toCharArray (); - char[] buf = new char[raw.length + tmp.length]; - - try - { - System.arraycopy(raw, 0, buf, 0, offset); - System.arraycopy(tmp, 0, buf, offset, tmp.length); - System.arraycopy(raw, offset, buf, offset + tmp.length, - raw.length - offset); - String value = new String(buf); - mutating(value); - text = value; - } - catch (IndexOutOfBoundsException x) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - } - - /** - * <b>DOM L1</b> - * Modifies the value of this node. Causes DOMCharacterDataModified - * mutation events to be reported (at least one). - */ - public void replaceData(int offset, int count, String arg) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - char[] raw = text.toCharArray(); - - // deleteData - if (offset < 0 || count < 0 || offset > raw.length) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - if ((offset + count) > raw.length) - { - count = raw.length - offset; - } - try - { - char[] buf = new char[raw.length - count]; - System.arraycopy(raw, 0, buf, 0, offset); - System.arraycopy(raw, offset + count, buf, offset, - raw.length - (offset + count)); - - // insertData - char[] tmp = arg.toCharArray (); - char[] buf2 = new char[buf.length + tmp.length]; - System.arraycopy(raw, 0, buf, 0, offset); - System.arraycopy(tmp, 0, buf, offset, tmp.length); - System.arraycopy(raw, offset, buf, offset + tmp.length, - raw.length - offset); - String value = new String(buf); - mutating(value); - text = value; - } - catch (IndexOutOfBoundsException x) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - } - - /** - * <b>DOM L1</b> - * Assigns the value of this node. - * Causes a DOMCharacterDataModified mutation event to be reported. - */ - public void setNodeValue(String value) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - if (value == null) - { - value = ""; - } - mutating(value); - text = value; - } - - /** - * <b>DOM L1</b> - * Assigns the value of this node; same as setNodeValue. - */ - final public void setData(String data) - { - setNodeValue(data); - } - - /** - * <b>DOM L1</b> - * Returns the specified substring. - */ - public String substringData(int offset, int count) - { - try - { - return text.substring(offset, count); - } - catch (StringIndexOutOfBoundsException e) - { - if (offset >= 0 && count >= 0 && offset < text.length()) - { - return text.substring(offset); - } - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - } - - /** - * The base URI for character data is <code>null</code>. - * @since DOM Level 3 Core - */ - public final String getBaseURI() - { - return null; - } - - private void mutating(String newValue) - { - if (!reportMutations) - { - return; - } - - // EVENT: DOMCharacterDataModified, target = this, - // prev/new values provided - MutationEvent event; - - event = (MutationEvent) createEvent("MutationEvents"); - event.initMutationEvent("DOMCharacterDataModified", - true /* bubbles */, false /* nocancel */, - null, text, newValue, null, (short) 0); - dispatchEvent(event); - } - -} - diff --git a/libjava/gnu/xml/dom/DomComment.java b/libjava/gnu/xml/dom/DomComment.java deleted file mode 100644 index 71c8160485f..00000000000 --- a/libjava/gnu/xml/dom/DomComment.java +++ /dev/null @@ -1,81 +0,0 @@ -/* DomComment.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Comment; - -/** - * <p> "Comment" implementation. - * Comments hold data intended for direct consumption by people; - * programs should only use ProcessingInstruction nodes. Note that - * since SAX makes comment reporting optional, XML systems that - * rely on comments (such as by using this class) will often lose - * those comments at some point in the processing pipeline. </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomComment - extends DomCharacterData - implements Comment -{ - - /** - * Constructs a comment node associated with the specified - * document and holding the specified data. - * - * <p>This constructor should only be invoked by a Document as part of - * its createComment functionality, or through a subclass which is - * similarly used in a "Sub-DOM" style layer. - */ - protected DomComment(DomDocument owner, String value) - { - super(COMMENT_NODE, owner, value); - } - - /** - * <b>DOM L1</b> - * Returns the string "#comment". - */ - final public String getNodeName() - { - return "#comment"; - } - -} - diff --git a/libjava/gnu/xml/dom/DomDOMException.java b/libjava/gnu/xml/dom/DomDOMException.java deleted file mode 100644 index cf93fcf9749..00000000000 --- a/libjava/gnu/xml/dom/DomDOMException.java +++ /dev/null @@ -1,175 +0,0 @@ -/* DomDOMException.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; - -/** - * <p> DOMException implementation. The version that - * is provided by the W3C is abstract, so it can't be instantiated. - * - * <p> This also provides a bit more information about the error - * that is being reported, in terms of the relevant DOM structures - * and data. - * - * @author David Brownell - */ -public class DomDOMException - extends DOMException -{ - - /** @serial Data that caused an error to be reported */ - private String data; - - /** @serial Node associated with the error. */ - private Node node; - - /** @serial Data associated with the error. */ - private int value; - - /** - * Constructs an exception, with the diagnostic message - * corresponding to the specified code. - */ - public DomDOMException(short code) - { - super(code, diagnostic(code)); - } - - /** - * Constructs an exception, with the diagnostic message - * corresponding to the specified code and additional - * information as provided. - */ - public DomDOMException(short code, String data, Node node, int value) - { - super(code, diagnostic(code)); - this.data = data; - this.node = node; - this.value = value; - } - - /** Returns the node to which the diagnotic applies, or null. */ - final public Node getNode() - { - return node; - } - - /** Returns data to which the diagnotic applies, or null. */ - final public String getData() - { - return data; - } - - /** Returns data to which the diagnotic applies, or null. */ - final public int getValue() - { - return value; - } - - /** - * Returns a diagnostic message that may be slightly more useful - * than the generic one, where possible. - */ - public String getMessage() - { - String retval = super.getMessage(); - - if (data != null) - { - retval += "\nMore Information: " + data; - } - if (value != 0) - { - retval += "\nNumber: " + value; - } - if (node != null) - { - retval += "\nNode Name: " + node.getNodeName(); - } - return retval; - } - - // these strings should be localizable. - - private static String diagnostic(short code) - { - switch (code) - { - // DOM L1: - case INDEX_SIZE_ERR: - return "An index or size is out of range."; - case DOMSTRING_SIZE_ERR: - return "A string is too big."; - case HIERARCHY_REQUEST_ERR: - return "The node doesn't belong here."; - case WRONG_DOCUMENT_ERR: - return "The node belongs in another document."; - case INVALID_CHARACTER_ERR: - return "That character is not permitted."; - case NO_DATA_ALLOWED_ERR: - return "This node does not permit data."; - case NO_MODIFICATION_ALLOWED_ERR: - return "No changes are allowed."; - case NOT_FOUND_ERR: - return "The node was not found in that context."; - case NOT_SUPPORTED_ERR: - return "That object is not supported."; - case INUSE_ATTRIBUTE_ERR: - return "The attribute belongs to a different element."; - - // DOM L2: - case INVALID_STATE_ERR: - return "The object is not usable."; - case SYNTAX_ERR: - return "An illegal string was provided."; - case INVALID_MODIFICATION_ERR: - return "An object's type may not be changed."; - case NAMESPACE_ERR: - return "The operation violates XML Namespaces."; - case INVALID_ACCESS_ERR: - return "Parameter or operation isn't supported by this node."; - case TYPE_MISMATCH_ERR: - return "The type of the argument is incompatible with the expected type."; - } - return "Reserved exception number: " + code; - } - -} - diff --git a/libjava/gnu/xml/dom/DomDoctype.java b/libjava/gnu/xml/dom/DomDoctype.java deleted file mode 100644 index d35eedc7f75..00000000000 --- a/libjava/gnu/xml/dom/DomDoctype.java +++ /dev/null @@ -1,455 +0,0 @@ -/* DomDoctype.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.HashMap; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Entity; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Notation; - -/** - * <p> "DocumentType" implementation (with no extensions for supporting - * any document typing information). This is a non-core DOM class, - * supporting the "XML" feature. </p> - * - * <p> <em>Few XML applications will actually care about this partial - * DTD support</em>, since it doesn't expose any (!) of the data typing - * facilities which can motivate applications to use DTDs. It does not - * expose element content models, or information about attribute typing - * rules. Plus the information it exposes isn't very useful; as one example, - * DOM exposes information about unparsed ENTITY objects, which is only used - * with certain element attributes, but does not expose the information about - * those attributes which is needed to apply that data! </p> - * - * <p> Also, note that there are no nonportable ways to associate even the - * notation and entity information exposed by DOM with a DocumentType. While - * there is a DOM L2 method to construct a DocumentType, it only gives access - * to the textual content of the <!DOCTYPE ...> declaration. </p> - * - * <p> In short, <em>you are strongly advised not to rely on this incomplete - * DTD functionality</em> in your application code.</p> - * - * @see DomEntity - * @see DomEntityReference - * @see DomNotation - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomDoctype - extends DomExtern - implements DocumentType -{ - - private DomNamedNodeMap notations; - private DomNamedNodeMap entities; - private final DOMImplementation implementation; - private String subset; - - private HashMap elements = new HashMap(); - private boolean ids; - - /** - * Constructs a DocumentType node associated with the specified - * implementation, with the specified name. - * - * <p>This constructor should only be invoked by a DOMImplementation as - * part of its createDocumentType functionality, or through a subclass - * which is similarly used in a "Sub-DOM" style layer. - * - * <p> Note that at this time there is no standard SAX API granting - * access to the internal subset text, so that relying on that value - * is not currently portable. - * - * @param impl The implementation with which this object is associated - * @param name Name of this root element - * @param publicId If non-null, provides the external subset's - * PUBLIC identifier - * @param systemId If non-null, provides the external subset's - * SYSTEM identifier - * @param internalSubset Provides the literal value (unparsed, no - * entities expanded) of the DTD's internal subset. - */ - protected DomDoctype(DOMImplementation impl, - String name, - String publicId, - String systemId, - String internalSubset) - { - super(DOCUMENT_TYPE_NODE, null, name, publicId, systemId); - implementation = impl; - subset = internalSubset; - } - - /** - * JAXP builder constructor. - * @param doc the document - * @param name the name of the document element - * @param publicId the public ID of the document type declaration - * @param systemId the system ID of the document type declaration - */ - public DomDoctype(DomDocument doc, - String name, - String publicId, - String systemId) - { - super(DOCUMENT_TYPE_NODE, doc, name, publicId, systemId); - implementation = doc.getImplementation(); - } - - /** - * <b>DOM L1</b> - * Returns the root element's name (just like getNodeName). - */ - final public String getName() - { - return getNodeName(); - } - - /** - * <b>DOM L1</b> - * Returns information about any general entities declared - * in the DTD. - * - * <p><em>Note: DOM L1 doesn't throw a DOMException here, but - * then it doesn't have the strange construction rules of L2.</em> - * - * @exception DOMException HIERARCHY_REQUEST_ERR if the DocumentType - * is not associated with a document. - */ - public NamedNodeMap getEntities() - { - if (entities == null) - { - entities = new DomNamedNodeMap(this, Node.ENTITY_NODE); - } - return entities; - } - - /** - * Records the declaration of a general entity in this DocumentType. - * - * @param name Name of the entity - * @param publicId If non-null, provides the entity's PUBLIC identifier - * @param systemId Provides the entity's SYSTEM identifier - * @param notation If non-null, provides the entity's notation - * (indicating an unparsed entity) - * @return The Entity that was declared, or null if the entity wasn't - * recorded (because it's a parameter entity or because an entity with - * this name was already declared). - * - * @exception DOMException NO_MODIFICATION_ALLOWED_ERR if the - * DocumentType is no longer writable. - * @exception DOMException HIERARCHY_REQUEST_ERR if the DocumentType - * is not associated with a document. - */ - public Entity declareEntity(String name, - String publicId, - String systemId, - String notation) - { - DomEntity entity; - - if (name.charAt(0) == '%' || "[dtd]".equals(name)) - { - return null; - } - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - getEntities(); - - DomDocument.checkName(name, (owner != null) ? - "1.1".equals(owner.getXmlVersion()) : false); - if (entities.getNamedItem(name) != null) - { - return null; - } - - entity = new DomEntity(owner, name, publicId, systemId, notation); - entities.setNamedItem(entity); - return entity; - } - - /** - * <b>DOM L1</b> - * Returns information about any notations declared in the DTD. - * - * <p><em>Note: DOM L1 doesn't throw a DOMException here, but - * then it doesn't have the strange construction rules of L2.</em> - * - * @exception DOMException HIERARCHY_REQUEST_ERR if the DocumentType - * is not associated with a document. - */ - public NamedNodeMap getNotations() - { - if (notations == null) - { - notations = new DomNamedNodeMap(this, Node.NOTATION_NODE); - } - return notations; - } - - /** - * Records the declaration of a notation in this DocumentType. - * - * @param name Name of the notation - * @param publicId If non-null, provides the notation's PUBLIC identifier - * @param systemId If non-null, provides the notation's SYSTEM identifier - * @return The notation that was declared. - * - * @exception DOMException NO_MODIFICATION_ALLOWED_ERR if the - * DocumentType is no longer writable. - * @exception DOMException HIERARCHY_REQUEST_ERR if the DocumentType - * is not associated with a document. - */ - public Notation declareNotation(String name, - String publicId, - String systemId) - { - DomNotation notation; - - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - getNotations(); - - DomDocument.checkName(name, (owner != null) ? - "1.1".equals(owner.getXmlVersion()) : false); - - notation = new DomNotation(owner, name, publicId, systemId); - notations.setNamedItem(notation); - return notation; - } - - /** - * <b>DOM L2</b> - * Returns the internal subset of the document, as a string of unparsed - * XML declarations (and comments, PIs, whitespace); or returns null if - * there is no such subset. There is no vendor-independent expectation - * that this attribute be set, or that declarations found in it be - * reflected in the <em>entities</em> or <em>notations</em> attributes - * of this Document "Type" object. - * - * <p> Some application-specific XML profiles require that documents - * only use specific PUBLIC identifiers, without an internal subset - * to modify the interperetation of the declarations associated with - * that PUBLIC identifier through some standard. - */ - public String getInternalSubset() - { - return subset; - } - - /** - * The base URI of a DocumentType is always <code>null</code>. - * See the Infoset Mapping, appendix C. - */ - public final String getBaseURI() - { - return null; - } - - /** - * Sets the internal "readonly" flag so the node and its associated - * data (only lists of entities and notations, no type information - * at the moment) can't be changed. - */ - public void makeReadonly() - { - super.makeReadonly(); - if (entities != null) - { - entities.makeReadonly(); - } - if (notations != null) - { - notations.makeReadonly(); - } - } - - void setOwner(DomDocument doc) - { - if (entities != null) - { - for (DomNode ctx = entities.first; ctx != null; ctx = ctx.next) - { - ctx.setOwner(doc); - } - } - if (notations != null) - { - for (DomNode ctx = notations.first; ctx != null; ctx = ctx.next) - { - ctx.setOwner(doc); - } - } - super.setOwner(doc); - } - - /** - * <b>DOM L2</b> - * Consults the DOM implementation to determine if the requested - * feature is supported. - */ - final public boolean supports(String feature, String version) - { - return implementation.hasFeature(feature, version); - } - - /** - * Returns the implementation associated with this document type. - */ - final public DOMImplementation getImplementation() - { - return implementation; - } - - public void elementDecl(String name, String model) - { - DTDElementTypeInfo info = getElementTypeInfo(name); - if (info == null) - { - info = new DTDElementTypeInfo(name, model); - elements.put(name, info); - } - else - { - info.model = model; - } - } - - DTDElementTypeInfo getElementTypeInfo(String name) - { - return (DTDElementTypeInfo) elements.get(name); - } - - public void attributeDecl(String eName, String aName, String type, - String mode, String value) - { - DTDAttributeTypeInfo info = new DTDAttributeTypeInfo(eName, aName, type, - mode, value); - DTDElementTypeInfo elementInfo = getElementTypeInfo(eName); - if (elementInfo == null) - { - elementInfo = new DTDElementTypeInfo(eName, null); - elements.put(eName, elementInfo); - } - elementInfo.setAttributeTypeInfo(aName, info); - if ("ID".equals(type)) - { - ids = true; - } - } - - DTDAttributeTypeInfo getAttributeTypeInfo(String elementName, String name) - { - DTDElementTypeInfo elementInfo = - (DTDElementTypeInfo) elements.get(elementName); - return (elementInfo == null) ? null : - elementInfo.getAttributeTypeInfo(name); - } - - boolean hasIds() - { - return ids; - } - - public boolean isSameNode(Node arg) - { - if (equals(arg)) - { - return true; - } - if (!(arg instanceof DocumentType)) - { - return false; - } - DocumentType doctype = (DocumentType) arg; - if (!equal(getPublicId(), doctype.getPublicId())) - { - return false; - } - if (!equal(getSystemId(), doctype.getSystemId())) - { - return false; - } - if (!equal(getInternalSubset(), doctype.getInternalSubset())) - { - return false; - } - // TODO entities - // TODO notations - return true; - } - - /** - * Shallow clone of the doctype, except that associated - * entities and notations are (deep) cloned. - */ - public Object clone() - { - DomDoctype node = (DomDoctype) super.clone(); - - if (entities != null) - { - node.entities = new DomNamedNodeMap(node, Node.ENTITY_NODE); - for (DomNode ctx = entities.first; ctx != null; ctx = ctx.next) - { - node.entities.setNamedItem(ctx.cloneNode(true)); - } - } - if (notations != null) - { - node.notations = new DomNamedNodeMap(node, Node.NOTATION_NODE); - for (DomNode ctx = notations.first; ctx != null; ctx = ctx.next) - { - node.notations.setNamedItem(ctx.cloneNode(true)); - } - } - return node; - } - - -} diff --git a/libjava/gnu/xml/dom/DomDocument.java b/libjava/gnu/xml/dom/DomDocument.java deleted file mode 100644 index ec422d1b4de..00000000000 --- a/libjava/gnu/xml/dom/DomDocument.java +++ /dev/null @@ -1,1387 +0,0 @@ -/* DomDocument.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.Iterator; -import javax.xml.XMLConstants; - -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Entity; -import org.w3c.dom.EntityReference; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Notation; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; -import org.w3c.dom.UserDataHandler; -import org.w3c.dom.traversal.DocumentTraversal; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; -import org.w3c.dom.traversal.TreeWalker; -import org.w3c.dom.xpath.XPathEvaluator; -import org.w3c.dom.xpath.XPathException; -import org.w3c.dom.xpath.XPathExpression; -import org.w3c.dom.xpath.XPathNSResolver; - -/** - * <p> "Document" and "DocumentTraversal" implementation. - * - * <p> Note that when this checks names for legality, it uses an - * approximation of the XML rules, not the real ones. Specifically, - * it uses Unicode rules, with sufficient tweaks to pass a majority - * of basic XML conformance tests. (The huge XML character tables are - * hairy to implement.) - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomDocument - extends DomNode - implements Document, DocumentTraversal, XPathEvaluator -{ - - private final DOMImplementation implementation; - private boolean checkingCharacters = true; - boolean checkingWellformedness = true; - - boolean building; // if true, skip mutation events in the tree - - DomDocumentConfiguration config; - - String inputEncoding; - String encoding; - String version = "1.0"; - boolean standalone; - String systemId; - - /** - * Constructs a Document node, associating it with an instance - * of the DomImpl class. - * - * <p> Note that this constructor disables character checking. - * It is normally used when connecting a DOM to an XML parser, - * and duplicating such checks is undesirable. When used for - * purposes other than connecting to a parser, you should - * re-enable that checking. - * - * @see #setCheckingCharacters - */ - public DomDocument() - { - this(new DomImpl()); - } - - /** - * Constructs a Document node, associating it with the specified - * implementation. This should only be used in conjunction with - * a specialized implementation; it will normally be called by - * that implementation. - * - * @see DomImpl - * @see #setCheckingCharacters - */ - protected DomDocument(DOMImplementation impl) - { - super(DOCUMENT_NODE, null); - implementation = impl; - } - - /** - * Sets the <code>building</code> flag. - * Mutation events in the document are not reported. - */ - public void setBuilding(boolean flag) - { - building = flag; - } - - /** - * Sets whether to check for document well-formedness. - * If true, an exception will be raised if a second doctype or root - * element node is added to the document. - */ - public void setCheckWellformedness(boolean flag) - { - checkingWellformedness = flag; - } - - /** - * <b>DOM L1</b> - * Returns the constant "#document". - */ - final public String getNodeName() - { - return "#document"; - } - - /** - * <b>DOM L1</b> - * Returns the document's root element, or null. - */ - final public Element getDocumentElement() - { - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - if (ctx.nodeType == ELEMENT_NODE) - { - return (Element) ctx; - } - } - return null; - } - - /** - * <b>DOM L1</b> - * Returns the document's DocumentType, or null. - */ - final public DocumentType getDoctype() - { - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - if (ctx.nodeType == DOCUMENT_TYPE_NODE) - { - return (DocumentType) ctx; - } - } - return null; - } - - /** - * <b>DOM L1</b> - * Returns the document's DOMImplementation. - */ - final public DOMImplementation getImplementation() - { - return implementation; - } - - /** - * <b>DOM L1 (relocated in DOM L2)</b> - * Returns the element with the specified "ID" attribute, or null. - * - * <p>Returns null unless {@link Consumer} was used to populate internal - * DTD declaration information, using package-private APIs. If that - * internal DTD information is available, the document may be searched for - * the element with that ID. - */ - public Element getElementById(String id) - { - DomDoctype doctype = (DomDoctype) getDoctype(); - - if (doctype == null || !doctype.hasIds() - || id == null || id.length() == 0) - { - return null; - } - - // yes, this is linear in size of document. - // it'd be easy enough to maintain a hashtable. - Node current = getDocumentElement(); - Node temp; - - if (current == null) - { - return null; - } - while (current != this) - { - // done? - if (current.getNodeType() == ELEMENT_NODE) - { - DomElement element = (DomElement) current; - DTDElementTypeInfo info = - doctype.getElementTypeInfo(current.getNodeName()); - if (info != null && - id.equals(element.getAttribute(info.idAttrName))) - { - return element; - } - else if (element.userIdAttrs != null) - { - for (Iterator i = element.userIdAttrs.iterator(); - i.hasNext(); ) - { - Node idAttr = (Node) i.next(); - if (id.equals(idAttr.getNodeValue())) - { - return element; - } - } - } - } - - // descend? - if (current.hasChildNodes()) - { - current = current.getFirstChild(); - continue; - } - - // lateral? - temp = current.getNextSibling(); - if (temp != null) - { - current = temp; - continue; - } - - // back up ... - do - { - temp = current.getParentNode(); - if (temp == null) - { - return null; - } - current = temp; - temp = current.getNextSibling(); - } - while (temp == null); - current = temp; - } - return null; - } - - private void checkNewChild(Node newChild) - { - if (newChild.getNodeType() == ELEMENT_NODE - && getDocumentElement() != null) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR, - "document element already present: " + - getDocumentElement(), newChild, 0); - } - if (newChild.getNodeType() == DOCUMENT_TYPE_NODE - && getDoctype() != null) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR, - "document type already present: " + - getDoctype(), newChild, 0); - } - } - - /** - * <b>DOM L1</b> - * Appends the specified node to this node's list of children, - * enforcing the constraints that there be only one root element - * and one document type child. - */ - public Node appendChild(Node newChild) - { - if (checkingWellformedness) - { - checkNewChild(newChild); - } - return super.appendChild(newChild); - } - - /** - * <b>DOM L1</b> - * Inserts the specified node in this node's list of children, - * enforcing the constraints that there be only one root element - * and one document type child. - */ - public Node insertBefore(Node newChild, Node refChild) - { - if (checkingWellformedness) - { - checkNewChild(newChild); - } - return super.insertBefore(newChild, refChild); - } - - /** - * <b>DOM L1</b> - * Replaces the specified node in this node's list of children, - * enforcing the constraints that there be only one root element - * and one document type child. - */ - public Node replaceChild(Node newChild, Node refChild) - { - if (checkingWellformedness && - ((newChild.getNodeType() == ELEMENT_NODE && - refChild.getNodeType() != ELEMENT_NODE) || - (newChild.getNodeType() == DOCUMENT_TYPE_NODE && - refChild.getNodeType() != DOCUMENT_TYPE_NODE))) - { - checkNewChild(newChild); - } - return super.replaceChild(newChild, refChild); - } - - // NOTE: DOM can't really tell when the name of an entity, - // notation, or PI must follow the namespace rules (excluding - // colons) instead of the XML rules (which allow them without - // much restriction). That's an API issue. verifyXmlName - // aims to enforce the XML rules, not the namespace rules. - - /** - * Throws a DOM exception if the specified name is not a legal XML 1.0 - * Name. - * @deprecated This method is deprecated and may be removed in future - * versions of GNU JAXP - */ - public static void verifyXmlName(String name) - { - // XXX why is this public? - checkName(name, false); - } - - static void checkName(String name, boolean xml11) - { - if (name == null) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, name, null, 0); - } - int len = name.length(); - if (len == 0) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, name, null, 0); - } - - // dog: rewritten to use the rules for XML 1.0 and 1.1 - - // Name start character - char c = name.charAt(0); - if (xml11) - { - // XML 1.1 - if ((c < 0x0041 || c > 0x005a) && - (c < 0x0061 || c > 0x007a) && - c != ':' && c != '_' && - (c < 0x00c0 || c > 0x00d6) && - (c < 0x00d8 || c > 0x00f6) && - (c < 0x00f8 || c > 0x02ff) && - (c < 0x0370 || c > 0x037d) && - (c < 0x037f || c > 0x1fff) && - (c < 0x200c || c > 0x200d) && - (c < 0x2070 || c > 0x218f) && - (c < 0x2c00 || c > 0x2fef) && - (c < 0x3001 || c > 0xd7ff) && - (c < 0xf900 || c > 0xfdcf) && - (c < 0xfdf0 || c > 0xfffd) && - (c < 0x10000 || c > 0xeffff)) - { - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - name, null, c); - } - } - else - { - // XML 1.0 - int type = Character.getType(c); - switch (type) - { - case Character.LOWERCASE_LETTER: // Ll - case Character.UPPERCASE_LETTER: // Lu - case Character.OTHER_LETTER: // Lo - case Character.TITLECASE_LETTER: // Lt - case Character.LETTER_NUMBER: // Nl - if ((c > 0xf900 && c < 0xfffe) || - (c >= 0x20dd && c <= 0x20e0)) - { - // Compatibility area and Unicode 2.0 exclusions - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - name, null, c); - } - break; - default: - if (c != ':' && c != '_' && (c < 0x02bb || c > 0x02c1) && - c != 0x0559 && c != 0x06e5 && c != 0x06e6) - { - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - name, null, c); - } - } - } - - // Subsequent characters - for (int i = 1; i < len; i++) - { - c = name.charAt(i); - if (xml11) - { - // XML 1.1 - if ((c < 0x0041 || c > 0x005a) && - (c < 0x0061 || c > 0x007a) && - (c < 0x0030 || c > 0x0039) && - c != ':' && c != '_' && c != '-' && c != '.' && - (c < 0x00c0 || c > 0x00d6) && - (c < 0x00d8 || c > 0x00f6) && - (c < 0x00f8 || c > 0x02ff) && - (c < 0x0370 || c > 0x037d) && - (c < 0x037f || c > 0x1fff) && - (c < 0x200c || c > 0x200d) && - (c < 0x2070 || c > 0x218f) && - (c < 0x2c00 || c > 0x2fef) && - (c < 0x3001 || c > 0xd7ff) && - (c < 0xf900 || c > 0xfdcf) && - (c < 0xfdf0 || c > 0xfffd) && - (c < 0x10000 || c > 0xeffff) && - c != 0x00b7 && - (c < 0x0300 || c > 0x036f) && - (c < 0x203f || c > 0x2040)) - { - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, - null, c); - } - } - else - { - // XML 1.0 - int type = Character.getType(c); - switch (type) - { - case Character.LOWERCASE_LETTER: // Ll - case Character.UPPERCASE_LETTER: // Lu - case Character.DECIMAL_DIGIT_NUMBER: // Nd - case Character.OTHER_LETTER: // Lo - case Character.TITLECASE_LETTER: // Lt - case Character.LETTER_NUMBER: // Nl - case Character.COMBINING_SPACING_MARK: // Mc - case Character.ENCLOSING_MARK: // Me - case Character.NON_SPACING_MARK: // Mn - case Character.MODIFIER_LETTER: // Lm - if ((c > 0xf900 && c < 0xfffe) || - (c >= 0x20dd && c <= 0x20e0)) - { - // Compatibility area and Unicode 2.0 exclusions - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - name, null, c); - } - break; - default: - if (c != '-' && c != '.' && c != ':' && c != '_' && - c != 0x0387 && (c < 0x02bb || c > 0x02c1) && - c != 0x0559 && c != 0x06e5 && c != 0x06e6 && c != 0x00b7) - { - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - name, null, c); - } - } - } - } - - // FIXME characters with a font or compatibility decomposition (i.e. - // those with a "compatibility formatting tag" in field 5 of the - // database -- marked by field 5 beginning with a "<") are not allowed. - } - - // package private - static void checkNCName(String name, boolean xml11) - { - checkName(name, xml11); - int len = name.length(); - int index = name.indexOf(':'); - if (index != -1) - { - if (index == 0 || index == (len - 1) || - name.lastIndexOf(':') != index) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - name, null, 0); - } - } - } - - // package private - static void checkChar(String value, boolean xml11) - { - char[] chars = value.toCharArray(); - checkChar(chars, 0, chars.length, xml11); - } - - static void checkChar(char[] buf, int off, int len, boolean xml11) - { - for (int i = 0; i < len; i++) - { - char c = buf[i]; - - // assume surrogate pairing checks out OK, for simplicity - if ((c >= 0x0020 && c <= 0xd7ff) || - (c == 0x000a || c == 0x000d || c == 0x0009) || - (c >= 0xe000 && c <= 0xfffd) || - (c >= 0x10000 && c <= 0x10ffff)) - { - continue; - } - if (xml11) - { - if ((c >= 0x0001 && c <= 0x001f) || - (c >= 0x007f && c <= 0x0084) || - (c >= 0x0086 && c <= 0x009f)) - { - continue; - } - } - throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, - new String(buf, off, len), null, c); - } - } - - /** - * <b>DOM L1</b> - * Returns a newly created element with the specified name. - */ - public Element createElement(String name) - { - Element element; - - if (checkingCharacters) - { - checkName(name, "1.1".equals(version)); - } - if (name.startsWith("xml:")) - { - element = createElementNS(null, name); - } - else - { - element = new DomElement(this, null, name); - } - defaultAttributes(element, name); - return element; - } - - /** - * <b>DOM L2</b> - * Returns a newly created element with the specified name - * and namespace information. - */ - public Element createElementNS(String namespaceURI, String name) - { - if (checkingCharacters) - { - checkNCName(name, "1.1".equals(version)); - } - - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - if (name.startsWith("xml:")) - { - if (namespaceURI != null - && !XMLConstants.XML_NS_URI.equals(namespaceURI)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xml namespace is always " + - XMLConstants.XML_NS_URI, this, 0); - } - namespaceURI = XMLConstants.XML_NS_URI; - } - else if (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || - name.startsWith("xmlns:")) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns is reserved", this, 0); - } - else if (namespaceURI == null && name.indexOf(':') != -1) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "prefixed name '" + name + - "' needs a URI", this, 0); - } - - Element element = new DomElement(this, namespaceURI, name); - defaultAttributes(element, name); - return element; - } - - private void defaultAttributes(Element element, String name) - { - DomDoctype doctype = (DomDoctype) getDoctype(); - if (doctype == null) - { - return; - } - - // default any attributes that need it - DTDElementTypeInfo info = doctype.getElementTypeInfo(name); - if (info != null) - { - for (Iterator i = info.attributes(); i != null && i.hasNext(); ) - { - DTDAttributeTypeInfo attr = (DTDAttributeTypeInfo) i.next(); - DomAttr node = (DomAttr) createAttribute(attr.name); - - String value = attr.value; - if (value == null) - { - value = ""; - } - node.setValue(value); - node.setSpecified(false); - element.setAttributeNode(node); - } - } - } - - /** - * <b>DOM L1</b> - * Returns a newly created document fragment. - */ - public DocumentFragment createDocumentFragment() - { - return new DomDocumentFragment(this); - } - - /** - * <b>DOM L1</b> - * Returns a newly created text node with the specified value. - */ - public Text createTextNode(String value) - { - if (checkingCharacters) - { - checkChar(value, "1.1".equals(version)); - } - return new DomText(this, value); - } - - /** - * Returns a newly created text node with the specified value. - */ - public Text createTextNode(char[] buf, int off, int len) - { - if (checkingCharacters) - { - checkChar(buf, off, len, "1.1".equals(version)); - } - return new DomText(this, buf, off, len); - } - - /** - * <b>DOM L1</b> - * Returns a newly created comment node with the specified value. - */ - public Comment createComment(String value) - { - if (checkingCharacters) - { - checkChar(value, "1.1".equals(version)); - } - return new DomComment(this, value); - } - - /** - * <b>DOM L1</b> - * Returns a newly created CDATA section node with the specified value. - */ - public CDATASection createCDATASection(String value) - { - if (checkingCharacters) - { - checkChar(value, "1.1".equals(version)); - } - return new DomCDATASection(this, value); - } - - /** - * Returns a newly created CDATA section node with the specified value. - */ - public CDATASection createCDATASection(char[] buf, int off, int len) - { - if (checkingCharacters) - { - checkChar(buf, off, len, "1.1".equals(version)); - } - return new DomCDATASection(this, buf, off, len); - } - - /** - * <b>DOM L1</b> - * Returns a newly created processing instruction. - */ - public ProcessingInstruction createProcessingInstruction(String target, - String data) - { - if (checkingCharacters) - { - boolean xml11 = "1.1".equals(version); - checkName(target, xml11); - if ("xml".equalsIgnoreCase(target)) - { - throw new DomDOMException(DOMException.SYNTAX_ERR, - "illegal PI target name", - this, 0); - } - checkChar(data, xml11); - } - return new DomProcessingInstruction(this, target, data); - } - - /** - * <b>DOM L1</b> - * Returns a newly created attribute with the specified name. - */ - public Attr createAttribute(String name) - { - if (checkingCharacters) - { - checkName(name, "1.1".equals(version)); - } - if (name.startsWith("xml:")) - { - return createAttributeNS(XMLConstants.XML_NS_URI, name); - } - else if (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || - name.startsWith("xmlns:")) - { - return createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, name); - } - else - { - return new DomAttr(this, null, name); - } - } - - /** - * <b>DOM L2</b> - * Returns a newly created attribute with the specified name - * and namespace information. - */ - public Attr createAttributeNS(String namespaceURI, String name) - { - if (checkingCharacters) - { - checkNCName(name, "1.1".equals(version)); - } - - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - if (name.startsWith ("xml:")) - { - if (namespaceURI == null) - { - namespaceURI = XMLConstants.XML_NS_URI; - } - else if (!XMLConstants.XML_NS_URI.equals(namespaceURI)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xml namespace is always " + - XMLConstants.XML_NS_URI, - this, 0); - } - } - else if (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || - name.startsWith("xmlns:")) - { - if (namespaceURI == null) - { - namespaceURI = XMLConstants.XMLNS_ATTRIBUTE_NS_URI; - } - else if (!XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns namespace must be " + - XMLConstants.XMLNS_ATTRIBUTE_NS_URI, - this, 0); - } - } - else if (namespaceURI == null && name.indexOf(':') != -1) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "prefixed name needs a URI: " + name, this, 0); - } - return new DomAttr(this, namespaceURI, name); - } - - /** - * <b>DOM L1</b> - * Returns a newly created reference to the specified entity. - * The caller should populate this with the appropriate children - * and then mark it as readonly. - * - * @see DomNode#makeReadonly - */ - public EntityReference createEntityReference(String name) - { - DomEntityReference ret = new DomEntityReference(this, name); - DocumentType doctype = getDoctype(); - if (doctype != null) - { - DomEntity ent = (DomEntity) doctype.getEntities().getNamedItem(name); - if (ent != null) - { - for (DomNode ctx = ent.first; ctx != null; ctx = ctx.next) - { - ret.appendChild(ctx.cloneNode(true)); - } - } - } - ret.makeReadonly(); - return ret; - } - - /** - * <b>DOM L2</b> - * Makes a copy of the specified node, with all nodes "owned" by - * this document and with children optionally copied. This type - * of standard utility has become, well, a standard utility. - * - * <p> Note that EntityReference nodes created through this method (either - * directly, or recursively) never have children, and that there is no - * portable way to associate them with such children. - * - * <p> Note also that there is no requirement that the specified node - * be associated with a different document. This differs from the - * <em>cloneNode</em> operation in that the node itself is not given - * an opportunity to participate, so that any information managed - * by node subclasses will be lost. - */ - public Node importNode(Node src, boolean deep) - { - Node dst = null; - switch (src.getNodeType()) - { - case TEXT_NODE: - dst = createTextNode(src.getNodeValue()); - break; - case CDATA_SECTION_NODE: - dst = createCDATASection(src.getNodeValue()); - break; - case COMMENT_NODE: - dst = createComment(src.getNodeValue()); - break; - case PROCESSING_INSTRUCTION_NODE: - dst = createProcessingInstruction(src.getNodeName(), - src.getNodeValue()); - break; - case NOTATION_NODE: - // NOTE: There's no standard way to create - // these, or add them to a doctype. Useless. - Notation notation = (Notation) src; - dst = new DomNotation(this, notation.getNodeName(), - notation.getPublicId(), - notation.getSystemId()); - break; - case ENTITY_NODE: - // NOTE: There's no standard way to create - // these, or add them to a doctype. Useless. - Entity entity = (Entity) src; - dst = new DomEntity(this, entity.getNodeName(), - entity.getPublicId(), - entity.getSystemId(), - entity.getNotationName()); - if (deep) - { - for (Node ctx = src.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - dst.appendChild(importNode(ctx, deep)); - } - } - break; - case ENTITY_REFERENCE_NODE: - dst = createEntityReference(src.getNodeName()); - break; - case DOCUMENT_FRAGMENT_NODE: - dst = new DomDocumentFragment(this); - if (deep) - { - for (Node ctx = src.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - dst.appendChild(importNode(ctx, deep)); - } - } - break; - case ATTRIBUTE_NODE: - String attr_nsuri = src.getNamespaceURI(); - if (attr_nsuri != null) - { - dst = createAttributeNS(attr_nsuri, src.getNodeName()); - } - else - { - dst = createAttribute(src.getNodeName()); - } - // this is _always_ done regardless of "deep" setting - for (Node ctx = src.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - dst.appendChild(importNode(ctx, false)); - } - break; - case ELEMENT_NODE: - String elem_nsuri = src.getNamespaceURI(); - if (elem_nsuri != null) - { - dst = createElementNS(elem_nsuri, src.getNodeName()); - } - else - { - dst = createElement(src.getNodeName()); - } - NamedNodeMap srcAttrs = src.getAttributes(); - NamedNodeMap dstAttrs = dst.getAttributes(); - int len = srcAttrs.getLength(); - for (int i = 0; i < len; i++) - { - Attr a = (Attr) srcAttrs.item(i); - Attr dflt; - - // maybe update defaulted attributes - dflt = (Attr) dstAttrs.getNamedItem(a.getNodeName()); - if (dflt != null) - { - String newval = a.getNodeValue(); - if (!dflt.getNodeValue().equals(newval) - || a.getSpecified () == true) - { - dflt.setNodeValue (newval); - } - continue; - } - - dstAttrs.setNamedItem((Attr) importNode(a, false)); - } - if (deep) - { - for (Node ctx = src.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - dst.appendChild(importNode(ctx, true)); - } - } - break; - // can't import document or doctype nodes - case DOCUMENT_NODE: - case DOCUMENT_TYPE_NODE: - // FALLTHROUGH - // can't import unrecognized or nonstandard nodes - default: - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, null, src, 0); - } - - // FIXME cleanup a bit -- for deep copies, copy those - // children in one place, here (code sharing is healthy) - - if (src instanceof DomNode) - { - ((DomNode) src).notifyUserDataHandlers(UserDataHandler.NODE_IMPORTED, - src, dst); - } - return dst; - } - - /** - * <b>DOM L2 (Traversal)</b> - * Returns a newly created node iterator. Don't forget to detach - * this iterator when you're done using it! - * - * @see DomIterator - */ - public NodeIterator createNodeIterator(Node root, - int whatToShow, - NodeFilter filter, - boolean expandEntities) - { - return new DomNodeIterator(root, whatToShow, filter, expandEntities, - false); - } - - public TreeWalker createTreeWalker(Node root, - int whatToShow, - NodeFilter filter, - boolean expandEntities) - { - return new DomNodeIterator(root, whatToShow, filter, expandEntities, - true); - } - - // DOM Level 3 methods - - /** - * DOM L3 - */ - public String getInputEncoding() - { - return inputEncoding; - } - - public void setInputEncoding(String inputEncoding) - { - this.inputEncoding = inputEncoding; - } - - /** - * DOM L3 - */ - public String getXmlEncoding() - { - return encoding; - } - - public void setXmlEncoding(String encoding) - { - this.encoding = encoding; - } - - public boolean getXmlStandalone() - { - return standalone; - } - - public void setXmlStandalone(boolean xmlStandalone) - { - standalone = xmlStandalone; - } - - public String getXmlVersion() - { - return version; - } - - public void setXmlVersion(String xmlVersion) - { - if (xmlVersion == null) - { - xmlVersion = "1.0"; - } - if ("1.0".equals(xmlVersion) || - "1.1".equals(xmlVersion)) - { - version = xmlVersion; - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - } - - public boolean getStrictErrorChecking() - { - return checkingCharacters; - } - - public void setStrictErrorChecking(boolean strictErrorChecking) - { - checkingCharacters = strictErrorChecking; - } - - public String lookupPrefix(String namespaceURI) - { - Node root = getDocumentElement(); - return (root == null) ? null : root.lookupPrefix(namespaceURI); - } - - public boolean isDefaultNamespace(String namespaceURI) - { - Node root = getDocumentElement(); - return (root == null) ? false : root.isDefaultNamespace(namespaceURI); - } - - public String lookupNamespaceURI(String prefix) - { - Node root = getDocumentElement(); - return (root == null) ? null : root.lookupNamespaceURI(prefix); - } - - public String getBaseURI() - { - return getDocumentURI(); - /* - Node root = getDocumentElement(); - if (root != null) - { - NamedNodeMap attrs = root.getAttributes(); - Node xmlBase = attrs.getNamedItemNS(XMLConstants.XML_NS_URI, "base"); - if (xmlBase != null) - { - return xmlBase.getNodeValue(); - } - } - return systemId; - */ - } - - public String getDocumentURI() - { - return systemId; - } - - public void setDocumentURI(String documentURI) - { - systemId = documentURI; - } - - public Node adoptNode(Node source) - { - switch (source.getNodeType()) - { - case DOCUMENT_NODE: - case DOCUMENT_TYPE_NODE: - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - case ENTITY_NODE: - case NOTATION_NODE: - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - if (source instanceof DomNode) - { - DomNode src = (DomNode) source; - DomNode dst = src; - if (dst.parent != null) - { - dst = (DomNode) dst.cloneNode(true); - } - dst.setOwner(this); - src.notifyUserDataHandlers(UserDataHandler.NODE_ADOPTED, src, dst); - return dst; - } - return null; - } - - public DOMConfiguration getDomConfig() - { - if (config == null) - { - config = new DomDocumentConfiguration(); - } - return config; - } - - public void normalizeDocument() - { - boolean save = building; - building = true; - normalizeNode(this); - building = save; - } - - void normalizeNode(DomNode node) - { - node.normalize(); - if (config != null) - { - switch (node.nodeType) - { - case CDATA_SECTION_NODE: - if (!config.cdataSections) - { - // replace CDATA section with text node - Text text = createTextNode(node.getNodeValue()); - node.parent.insertBefore(text, node); - node.parent.removeChild(node); - // merge adjacent text nodes - String data = text.getWholeText(); - node = (DomNode) text.replaceWholeText(data); - } - else if (config.splitCdataSections) - { - String value = node.getNodeValue(); - int i = value.indexOf("]]>"); - while (i != -1) - { - Node node2 = createCDATASection(value.substring(0, i)); - node.parent.insertBefore(node2, node); - value = value.substring(i + 3); - node.setNodeValue(value); - i = value.indexOf("]]>"); - } - } - break; - case COMMENT_NODE: - if (!config.comments) - { - node.parent.removeChild(node); - } - break; - case TEXT_NODE: - if (!config.elementContentWhitespace && - ((Text) node).isElementContentWhitespace()) - { - node.parent.removeChild(node); - } - break; - case ENTITY_REFERENCE_NODE: - if (!config.entities) - { - for (DomNode ctx = node.first; ctx != null; ) - { - DomNode ctxNext = ctx.next; - node.parent.insertBefore(ctx, node); - ctx = ctxNext; - } - node.parent.removeChild(node); - } - break; - case ELEMENT_NODE: - if (!config.namespaceDeclarations) - { - DomNamedNodeMap attrs = - (DomNamedNodeMap) node.getAttributes(); - boolean aro = attrs.readonly; - attrs.readonly = false; // Ensure we can delete if necessary - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String namespace = attr.getNamespaceURI(); - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespace)) - { - attrs.removeNamedItemNS(namespace, - attr.getLocalName()); - i--; - len--; - } - } - attrs.readonly = aro; - } - break; - } - } - for (DomNode ctx = node.first; ctx != null; ) - { - DomNode ctxNext = ctx.next; - normalizeNode(ctx); - ctx = ctxNext; - } - } - - public Node renameNode(Node n, String namespaceURI, String qualifiedName) - throws DOMException - { - if (n instanceof DomNsNode) - { - DomNsNode src = (DomNsNode) n; - if (src == null) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR); - } - if (src.owner != this) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, src, 0); - } - boolean xml11 = "1.1".equals(version); - checkName(qualifiedName, xml11); - int ci = qualifiedName.indexOf(':'); - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - if (namespaceURI != null) - { - checkNCName(qualifiedName, xml11); - String prefix = (ci == -1) ? "" : - qualifiedName.substring(0, ci); - if (XMLConstants.XML_NS_PREFIX.equals(prefix) && - !XMLConstants.XML_NS_URI.equals(namespaceURI)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xml namespace must be " + - XMLConstants.XML_NS_URI, src, 0); - } - else if (src.nodeType == ATTRIBUTE_NODE && - (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || - XMLConstants.XMLNS_ATTRIBUTE.equals(qualifiedName)) && - !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns namespace must be " + - XMLConstants.XMLNS_ATTRIBUTE_NS_URI, src, 0); - } - if (XMLConstants.XML_NS_URI.equals(namespaceURI) && - !XMLConstants.XML_NS_PREFIX.equals(prefix)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xml namespace must be " + - XMLConstants.XML_NS_URI, src, 0); - } - else if (src.nodeType == ATTRIBUTE_NODE && - XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI) && - !(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || - XMLConstants.XMLNS_ATTRIBUTE.equals(qualifiedName))) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns namespace must be " + - XMLConstants.XMLNS_ATTRIBUTE_NS_URI, src, 0); - } - - } - src.setNodeName(qualifiedName); - src.setNamespaceURI(namespaceURI); - src.notifyUserDataHandlers(UserDataHandler.NODE_RENAMED, src, src); - // TODO MutationNameEvents - // DOMElementNameChanged or DOMAttributeNameChanged - return src; - } - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, null, n, 0); - } - - // -- XPathEvaluator -- - - public XPathExpression createExpression(String expression, - XPathNSResolver resolver) - throws XPathException, DOMException - { - return new DomXPathExpression(this, expression, resolver); - } - - public XPathNSResolver createNSResolver(Node nodeResolver) - { - return new DomXPathNSResolver(nodeResolver); - } - - public Object evaluate(String expression, - Node contextNode, - XPathNSResolver resolver, - short type, - Object result) - throws XPathException, DOMException - { - XPathExpression xpe = - new DomXPathExpression(this, expression, resolver); - return xpe.evaluate(contextNode, type, result); - } - -} - diff --git a/libjava/gnu/xml/dom/DomDocumentBuilder.java b/libjava/gnu/xml/dom/DomDocumentBuilder.java deleted file mode 100644 index 66dd2b0edfa..00000000000 --- a/libjava/gnu/xml/dom/DomDocumentBuilder.java +++ /dev/null @@ -1,159 +0,0 @@ -/* DomDocumentBuilder.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.io.InputStream; -import java.io.IOException; -import javax.xml.parsers.DocumentBuilder; -import org.w3c.dom.Document; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSInput; -import org.w3c.dom.ls.LSParser; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Document builder using the GNU DOM Load & Save implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomDocumentBuilder - extends DocumentBuilder -{ - - final DOMImplementation impl; - final DOMImplementationLS ls; - final LSParser parser; - - DomDocumentBuilder(DOMImplementation impl, - DOMImplementationLS ls, - LSParser parser) - { - this.impl = impl; - this.ls = ls; - this.parser = parser; - } - - public boolean isNamespaceAware() - { - DOMConfiguration config = parser.getDomConfig(); - return ((Boolean) config.getParameter("namespaces")).booleanValue(); - } - - public boolean isValidating() - { - DOMConfiguration config = parser.getDomConfig(); - return ((Boolean) config.getParameter("validating")).booleanValue(); - } - - public boolean isXIncludeAware() - { - DOMConfiguration config = parser.getDomConfig(); - return ((Boolean) config.getParameter("xinclude-aware")).booleanValue(); - } - - public void setEntityResolver(EntityResolver resolver) - { - DOMConfiguration config = parser.getDomConfig(); - config.setParameter("entity-resolver", resolver); - } - - public void setErrorHandler(ErrorHandler handler) - { - DOMConfiguration config = parser.getDomConfig(); - config.setParameter("error-handler", handler); - } - - public DOMImplementation getDOMImplementation() - { - return impl; - } - - public Document newDocument() - { - return impl.createDocument(null, null, null); - } - - public Document parse(InputStream in) - throws SAXException, IOException - { - LSInput input = ls.createLSInput(); - input.setByteStream(in); - return parser.parse(input); - } - - public Document parse(InputStream in, String systemId) - throws SAXException, IOException - { - LSInput input = ls.createLSInput(); - input.setByteStream(in); - input.setSystemId(systemId); - return parser.parse(input); - } - - public Document parse(String systemId) - throws SAXException, IOException - { - return parser.parseURI(systemId); - } - - public Document parse(InputSource is) - throws SAXException, IOException - { - LSInput input = ls.createLSInput(); - InputStream in = is.getByteStream(); - if (in != null) - { - input.setByteStream(in); - } - else - { - input.setCharacterStream(is.getCharacterStream()); - } - input.setPublicId(is.getPublicId()); - input.setSystemId(is.getSystemId()); - input.setEncoding(is.getEncoding()); - return parser.parse(input); - } - -} - diff --git a/libjava/gnu/xml/dom/DomDocumentBuilderFactory.java b/libjava/gnu/xml/dom/DomDocumentBuilderFactory.java deleted file mode 100644 index 814141c9441..00000000000 --- a/libjava/gnu/xml/dom/DomDocumentBuilderFactory.java +++ /dev/null @@ -1,128 +0,0 @@ -/* DomDocumentBuilderFactory.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.bootstrap.DOMImplementationRegistry; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSParser; - -/** - * Document builder factory that uses a DOM Level 3 Load & Save - * implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomDocumentBuilderFactory - extends DocumentBuilderFactory -{ - - final DOMImplementation impl; - final DOMImplementationLS ls; - - public DomDocumentBuilderFactory() - { - try - { - DOMImplementationRegistry reg = - DOMImplementationRegistry.newInstance(); - impl = reg.getDOMImplementation("LS 3.0"); - if (impl == null) - { - throw new FactoryConfigurationError("no LS implementations found"); - } - ls = (DOMImplementationLS) impl; - } - catch (Exception e) - { - throw new FactoryConfigurationError(e); - } - } - - public DocumentBuilder newDocumentBuilder() - throws ParserConfigurationException - { - LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS, - "http://www.w3.org/TR/REC-xml"); - DOMConfiguration config = parser.getDomConfig(); - setParameter(config, "namespaces", - isNamespaceAware() ? Boolean.TRUE : Boolean.FALSE); - setParameter(config, "element-content-whitespace", - isIgnoringElementContentWhitespace() ? Boolean.FALSE : - Boolean.TRUE); - setParameter(config, "comments", - isIgnoringComments() ? Boolean.FALSE : Boolean.TRUE); - setParameter(config, "expand-entity-references", - isExpandEntityReferences() ? Boolean.TRUE : Boolean.FALSE); - setParameter(config, "coalescing", - isCoalescing() ? Boolean.TRUE : Boolean.FALSE); - setParameter(config, "validating", - isValidating() ? Boolean.TRUE : Boolean.FALSE); - setParameter(config, "xinclude-aware", - isXIncludeAware() ? Boolean.TRUE : Boolean.FALSE); - return new DomDocumentBuilder(impl, ls, parser); - } - - void setParameter(DOMConfiguration config, String name, Object value) - throws ParserConfigurationException - { - if (!config.canSetParameter(name, value)) - { - throw new ParserConfigurationException(name); - } - config.setParameter(name, value); - } - - public Object getAttribute(String name) - { - // TODO - return null; - } - - public void setAttribute(String name, Object value) - { - // TODO - } - -} - diff --git a/libjava/gnu/xml/dom/DomDocumentConfiguration.java b/libjava/gnu/xml/dom/DomDocumentConfiguration.java deleted file mode 100644 index 5c589f82fe2..00000000000 --- a/libjava/gnu/xml/dom/DomDocumentConfiguration.java +++ /dev/null @@ -1,260 +0,0 @@ -/* DomDocumentConfiguration.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.Arrays; -import java.util.List; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMErrorHandler; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMStringList; - -/** - * Document configuration, used to store normalization and other parameters. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomDocumentConfiguration - implements DOMConfiguration, DOMStringList -{ - - private static final List SUPPORTED_PARAMETERS = - Arrays.asList(new String[] { "cdata-sections", - "comments", - "element-content-whitespace", - "entities", - "error-handler", - "namespace-declarations", - "split-cdata-sections", - "infoset"}); - - boolean cdataSections = true; - boolean comments = true; - boolean elementContentWhitespace = true; - boolean entities = true; - DOMErrorHandler errorHandler; - boolean namespaceDeclarations = true; - boolean splitCdataSections = true; - - public void setParameter(String name, Object value) - throws DOMException - { - name = name.toLowerCase(); - if ("cdata-sections".equals(name)) - { - cdataSections = "true".equals(value.toString()); - } - else if ("comments".equals(name)) - { - comments = "true".equals(value.toString()); - } - else if ("element-content-whitespace".equals(name)) - { - elementContentWhitespace = "true".equals(value.toString()); - } - else if ("entities".equals(name)) - { - entities = "true".equals(value.toString()); - } - else if ("error-handler".equals(name)) - { - try - { - errorHandler = (DOMErrorHandler) value; - } - catch (ClassCastException e) - { - throw new DomDOMException(DOMException.TYPE_MISMATCH_ERR, - value.getClass().getName(), null, 0); - } - } - else if ("namespace-declarations".equals(name)) - { - namespaceDeclarations = "true".equals(value.toString()); - } - else if ("split-cdata-sections".equals(name)) - { - comments = "true".equals(value.toString()); - } - else if ("infoset".equals(name)) - { - if ("true".equals(value.toString())) - { - entities = false; - cdataSections = false; - namespaceDeclarations = true; - elementContentWhitespace = true; - comments = true; - } - } - else if (("canonical-form".equals(name) || - "check-character-normalization".equals(name) || - "datatype-normalization".equals(name) || - "normalize-characters".equals(name) || - "validate".equals(name) || - "validate-if-schema".equals(name)) && - "false".equals(value.toString())) - { - // NOOP - } - else if (("namespaces".equals(name) || - "well-formed".equals(name)) && - "true".equals(value.toString())) - { - // NOOP - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, - name, null, 0); - } - } - - public Object getParameter(String name) - throws DOMException - { - name = name.toLowerCase(); - if ("cdata-sections".equals(name)) - { - return cdataSections ? Boolean.TRUE : Boolean.FALSE; - } - else if ("comments".equals(name)) - { - return comments ? Boolean.TRUE : Boolean.FALSE; - } - else if ("element-content-whitespace".equals(name)) - { - return elementContentWhitespace ? Boolean.TRUE : Boolean.FALSE; - } - else if ("entities".equals(name)) - { - return entities ? Boolean.TRUE : Boolean.FALSE; - } - else if ("error-handler".equals(name)) - { - return errorHandler; - } - else if ("namespace-declarations".equals(name)) - { - return namespaceDeclarations ? Boolean.TRUE : Boolean.FALSE; - } - else if ("split-cdata-sections".equals(name)) - { - return comments ? Boolean.TRUE : Boolean.FALSE; - } - else if ("canonical-form".equals(name) || - "check-character-normalization".equals(name) || - "datatype-normalization".equals(name) || - "normalize-characters".equals(name) || - "validate".equals(name) || - "validate-if-schema".equals(name)) - { - return Boolean.FALSE; - } - else if ("namespaces".equals(name) || - "well-formed".equals(name)) - { - return Boolean.TRUE; - } - else if ("infoset".equals(name)) - { - return (entities == false && - cdataSections == false && - namespaceDeclarations == true && - comments == true) ? Boolean.TRUE : Boolean.FALSE; - } - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, name, null, 0); - } - - public boolean canSetParameter(String name, Object value) - { - name = name.toLowerCase(); - if ("error-handler".equals(name)) - { - return (value == null || value instanceof DOMErrorHandler); - } - else if (contains(name)) - { - return true; - } - else if ("canonical-form".equals(name) || - "check-character-normalization".equals(name) || - "datatype-normalization".equals(name) || - "normalize-characters".equals(name) || - "validate".equals(name) || - "validate-if-schema".equals(name)) - { - return "false".equals(value.toString()); - } - else if ("namespaces".equals(name) || - "well-formed".equals(name)) - { - return "true".equals(value.toString()); - } - return false; - } - - public DOMStringList getParameterNames() - { - return this; - } - - public String item(int i) - { - try - { - return (String) SUPPORTED_PARAMETERS.get(i); - } - catch (IndexOutOfBoundsException e) - { - return null; - } - } - - public int getLength() - { - return SUPPORTED_PARAMETERS.size(); - } - - public boolean contains(String str) - { - str = str.toLowerCase(); - return SUPPORTED_PARAMETERS.contains(str); - } - -} diff --git a/libjava/gnu/xml/dom/DomDocumentFragment.java b/libjava/gnu/xml/dom/DomDocumentFragment.java deleted file mode 100644 index 8d260377821..00000000000 --- a/libjava/gnu/xml/dom/DomDocumentFragment.java +++ /dev/null @@ -1,76 +0,0 @@ -/* DomDocumentFragment.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DocumentFragment; - -/** - * <p> "DocumentFragment" implementation. </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomDocumentFragment - extends DomNode - implements DocumentFragment -{ - - /** - * Constructs a DocumentFragment node associated with the - * specified document. - * - * <p>This constructor should only be invoked by a Document as part of - * its createDocumentFragment functionality, or through a subclass which - * is similarly used in a "Sub-DOM" style layer. - */ - protected DomDocumentFragment(DomDocument owner) - { - super(DOCUMENT_FRAGMENT_NODE, owner); - } - - /** - * <b>DOM L1</b> - * Returns the string "#document-fragment". - */ - final public String getNodeName() - { - return "#document-fragment"; - } - -} - diff --git a/libjava/gnu/xml/dom/DomElement.java b/libjava/gnu/xml/dom/DomElement.java deleted file mode 100644 index 34509f647bc..00000000000 --- a/libjava/gnu/xml/dom/DomElement.java +++ /dev/null @@ -1,523 +0,0 @@ -/* DomElement.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.HashSet; -import java.util.Set; -import javax.xml.XMLConstants; - -import org.w3c.dom.Attr; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.TypeInfo; - -/** - * <p> "Element" implementation. - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomElement - extends DomNsNode - implements Element -{ - - /** - * User-defined ID attributes. - * Used by DomAttr.isId and DomDocument.getElementById - */ - Set userIdAttrs; - - // Attributes are VERY expensive in DOM, and not just for - // this implementation. Avoid creating them. - private DomNamedNodeMap attributes; - - // xml:space cache - String xmlSpace = ""; - - /** - * Constructs an Element node associated with the specified document. - * - * <p>This constructor should only be invoked by a Document as part - * of its createElement functionality, or through a subclass which is - * similarly used in a "Sub-DOM" style layer. - * - * @param owner The document with which this node is associated - * @param namespaceURI Combined with the local part of the name, - * this is used to uniquely identify a type of element - * @param name Name of this element, which may include a prefix - */ - protected DomElement(DomDocument owner, String namespaceURI, String name) - { - super(ELEMENT_NODE, owner, namespaceURI, name); - } - - /** - * <b>DOM L1</b> - * Returns the element's attributes - */ - public NamedNodeMap getAttributes() - { - if (attributes == null) - { - attributes = new DomNamedNodeMap(this, Node.ATTRIBUTE_NODE); - } - return attributes; - } - - /** - * <b>DOM L2></b> - * Returns true iff this is an element node with attributes. - */ - public boolean hasAttributes() - { - return attributes != null && attributes.length != 0; - } - - /** - * Shallow clone of the element, except that associated - * attributes are (deep) cloned. - */ - public Object clone() - { - DomElement node = (DomElement) super.clone(); - - if (attributes != null) - { - node.attributes = new DomNamedNodeMap(node, Node.ATTRIBUTE_NODE); - for (DomNode ctx = attributes.first; ctx != null; ctx = ctx.next) - { - node.attributes.setNamedItemNS(ctx.cloneNode(true)); - } - } - return node; - } - - void setOwner(DomDocument doc) - { - if (attributes != null) - { - for (DomNode ctx = attributes.first; ctx != null; ctx = ctx.next) - { - ctx.setOwner(doc); - } - } - super.setOwner(doc); - } - - /** - * Marks this element, its children, and its associated attributes as - * readonly. - */ - public void makeReadonly() - { - super.makeReadonly(); - if (attributes != null) - { - attributes.makeReadonly(); - } - } - - /** - * <b>DOM L1</b> - * Returns the element name (same as getNodeName). - */ - final public String getTagName() - { - return getNodeName(); - } - - /** - * <b>DOM L1</b> - * Returns the value of the specified attribute, or an - * empty string. - */ - public String getAttribute(String name) - { - if ("xml:space" == name) // NB only works on interned string - { - // Use cached value - return xmlSpace; - } - Attr attr = getAttributeNode(name); - return (attr == null) ? "" : attr.getValue(); - } - - /** - * <b>DOM L2</b> - * Returns true if the element has an attribute with the - * specified name (specified or DTD defaulted). - */ - public boolean hasAttribute(String name) - { - return getAttributeNode(name) != null; - } - - /** - * <b>DOM L2</b> - * Returns true if the element has an attribute with the - * specified name (specified or DTD defaulted). - */ - public boolean hasAttributeNS(String namespaceURI, String local) - { - return getAttributeNodeNS(namespaceURI, local) != null; - } - - /** - * <b>DOM L2</b> - * Returns the value of the specified attribute, or an - * empty string. - */ - public String getAttributeNS(String namespaceURI, String local) - { - Attr attr = getAttributeNodeNS(namespaceURI, local); - return (attr == null) ? "" : attr.getValue(); - } - - /** - * <b>DOM L1</b> - * Returns the appropriate attribute node; the name is the - * nodeName property of the attribute. - */ - public Attr getAttributeNode(String name) - { - return (attributes == null) ? null : - (Attr) attributes.getNamedItem(name); - } - - /** - * <b>DOM L2</b> - * Returns the appropriate attribute node; the name combines - * the namespace name and the local part. - */ - public Attr getAttributeNodeNS(String namespace, String localPart) - { - return (attributes == null) ? null : - (Attr) attributes.getNamedItemNS(namespace, localPart); - } - - /** - * <b>DOM L1</b> - * Modifies an existing attribute to have the specified value, - * or creates a new one with that value. The name used is the - * nodeName value. - */ - public void setAttribute(String name, String value) - { - Attr attr = getAttributeNode(name); - if (attr != null) - { - attr.setNodeValue(value); - ((DomAttr) attr).setSpecified(true); - return; - } - attr = owner.createAttribute(name); - attr.setNodeValue(value); - setAttributeNode(attr); - } - - /** - * <b>DOM L2</b> - * Modifies an existing attribute to have the specified value, - * or creates a new one with that value. - */ - public void setAttributeNS(String uri, String aname, String value) - { - if (("xmlns".equals (aname) || aname.startsWith ("xmlns:")) - && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals (uri)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "setting xmlns attribute to illegal value", this, 0); - } - - Attr attr = getAttributeNodeNS(uri, aname); - if (attr != null) - { - attr.setNodeValue(value); - return; - } - attr = owner.createAttributeNS(uri, aname); - attr.setNodeValue(value); - setAttributeNodeNS(attr); - } - - /** - * <b>DOM L1</b> - * Stores the specified attribute, optionally overwriting any - * existing one with that name. - */ - public Attr setAttributeNode(Attr attr) - { - return (Attr) getAttributes().setNamedItem(attr); - } - - /** - * <b>DOM L2</b> - * Stores the specified attribute, optionally overwriting any - * existing one with that name. - */ - public Attr setAttributeNodeNS(Attr attr) - { - return (Attr) getAttributes().setNamedItemNS(attr); - } - - /** - * <b>DOM L1</b> - * Removes the appropriate attribute node. - * If there is no such node, this is (bizarrely enough) a NOP so you - * won't see exceptions if your code deletes non-existent attributes. - * - * <p>Note that since there is no portable way for DOM to record - * DTD information, default values for attributes will never be - * provided automatically. - */ - public void removeAttribute(String name) - { - if (attributes == null) - { - return; - } - - try - { - attributes.removeNamedItem(name); - } - catch (DomDOMException e) - { - if (e.code != DOMException.NOT_FOUND_ERR) - { - throw e; - } - } - } - - /** - * <b>DOM L1</b> - * Removes the appropriate attribute node; the name is the - * nodeName property of the attribute. - * - * <p>Note that since there is no portable way for DOM to record - * DTD information, default values for attributes will never be - * provided automatically. - */ - public Attr removeAttributeNode(Attr node) - { - if (attributes == null) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, null, node, 0); - } - return (Attr) attributes.removeNamedItem(node.getNodeName()); - } - - /** - * <b>DOM L2</b> - * Removes the appropriate attribute node; the name combines - * the namespace name and the local part. - * - * <p>Note that since there is no portable way for DOM to record - * DTD information, default values for attributes will never be - * provided automatically. - */ - public void removeAttributeNS(String namespace, String localPart) - { - if (attributes == null) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, localPart, null, 0); - } - attributes.removeNamedItemNS (namespace, localPart); - } - - // DOM Level 3 methods - - public String lookupPrefix(String namespaceURI) - { - if (namespaceURI == null) - { - return null; - } - String namespace = getNamespaceURI(); - if (namespace != null && namespace.equals(namespaceURI)) - { - return getPrefix(); - } - if (attributes != null) - { - for (DomNode ctx = attributes.first; ctx != null; ctx = ctx.next) - { - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI - .equals(ctx.getNamespaceURI())) - { - String value = ctx.getNodeValue(); - if (value.equals(namespaceURI)) - { - return ctx.getLocalName(); - } - } - } - } - return super.lookupPrefix(namespaceURI); - } - - public boolean isDefaultNamespace(String namespaceURI) - { - String namespace = getNamespaceURI(); - if (namespace != null && namespace.equals(namespaceURI)) - { - return getPrefix() == null; - } - if (attributes != null) - { - for (DomNode ctx = attributes.first; ctx != null; ctx = ctx.next) - { - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI - .equals(ctx.getNamespaceURI())) - { - String qName = ctx.getNodeName(); - return (XMLConstants.XMLNS_ATTRIBUTE.equals(qName)); - } - } - } - return super.isDefaultNamespace(namespaceURI); - } - - public String lookupNamespaceURI(String prefix) - { - String namespace = getNamespaceURI(); - if (namespace != null && equal(prefix, getPrefix())) - { - return namespace; - } - if (attributes != null) - { - for (DomNode ctx = attributes.first; ctx != null; ctx = ctx.next) - { - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI - .equals(ctx.getNamespaceURI())) - { - if (prefix == null) - { - if (XMLConstants.XMLNS_ATTRIBUTE.equals(ctx.getNodeName())) - { - return ctx.getNodeValue(); - } - } - else - { - if (prefix.equals(ctx.getLocalName())) - { - return ctx.getNodeValue(); - } - } - } - } - } - return super.lookupNamespaceURI(prefix); - } - - public String getBaseURI() - { - if (attributes != null) - { - Node xmlBase = - attributes.getNamedItemNS(XMLConstants.XML_NS_URI, "base"); - if (xmlBase != null) - { - return xmlBase.getNodeValue(); - } - } - return super.getBaseURI(); - } - - public TypeInfo getSchemaTypeInfo() - { - // DTD implementation - DomDoctype doctype = (DomDoctype) owner.getDoctype(); - if (doctype != null) - { - return doctype.getElementTypeInfo(getNodeName()); - } - // TODO XML Schema implementation - return null; - } - - public void setIdAttribute(String name, boolean isId) - { - NamedNodeMap attrs = getAttributes(); - Attr attr = (Attr) attrs.getNamedItem(name); - setIdAttributeNode(attr, isId); - } - - public void setIdAttributeNode(Attr attr, boolean isId) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - if (attr == null || attr.getOwnerElement() != this) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR); - } - if (isId) - { - if (userIdAttrs == null) - { - userIdAttrs = new HashSet(); - } - userIdAttrs.add(attr); - } - else if (userIdAttrs != null) - { - userIdAttrs.remove(attr); - if (userIdAttrs.isEmpty()) - { - userIdAttrs = null; - } - } - } - - public void setIdAttributeNS(String namespaceURI, String localName, - boolean isId) - { - NamedNodeMap attrs = getAttributes(); - Attr attr = (Attr) attrs.getNamedItemNS(namespaceURI, localName); - setIdAttributeNode(attr, isId); - } - -} diff --git a/libjava/gnu/xml/dom/DomEntity.java b/libjava/gnu/xml/dom/DomEntity.java deleted file mode 100644 index 3a76479a389..00000000000 --- a/libjava/gnu/xml/dom/DomEntity.java +++ /dev/null @@ -1,147 +0,0 @@ -/* DomEntity.java -- - Copyright (C) 1999,2000,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Entity; - -/** - * <p> "Entity" implementation. This is a non-core DOM class, supporting the - * "XML" feature. There are two types of entities, neither of which works - * particularly well in this API:</p><dl> - * - * <dt><em>Unparsed Entities</em></dt> - * <dd>Since ENTITY/ENTITIES attributes, the only legal use of unparsed - * entities in XML, can't be detected with DOM, there isn't much point in - * trying to use unparsed entities in DOM applications. (XML Linking is - * working to provide a better version of this functionality.) </dd> - * - * <dt><em>Parsed Entities</em></dt> - * <dd> While the DOM specification permits nodes for parsed entities - * to have a readonly set of children, this is not required and there - * is no portable way to provide such children. <em>This implementation - * currently does not permit children to be added to Entities.</em> - * There are related issues with the use of EntityReference nodes. </dd> - * - * </dl> - * - * <p> In short, <em>avoid using this DOM functionality</em>. - * - * @see DomDoctype - * @see DomEntityReference - * @see DomNotation - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomEntity - extends DomExtern - implements Entity -{ - - private String notation; - - /** - * Constructs an Entity node associated with the specified document, - * with the specified descriptive data. - * - * <p>This constructor should only be invoked by a DomDoctype as part - * of its declareEntity functionality, or through a subclass which is - * similarly used in a "Sub-DOM" style layer. - * - * @param owner The document with which this entity is associated - * @param name Name of this entity - * @param publicId If non-null, provides the entity's PUBLIC identifier - * @param systemId Provides the entity's SYSTEM identifier (URI) - * @param notation If non-null, provides the unparsed entity's notation. - */ - protected DomEntity(DomDocument owner, - String name, - String publicId, - String systemId, - String notation) - { - super(ENTITY_NODE, owner, name, publicId, systemId); - this.notation = notation; - - // NOTE: if notation == null, this is a parsed entity - // which could reasonably be given child nodes ... - makeReadonly(); - } - - /** - * <b>DOM L1</b> - * Returns the NOTATION identifier associated with this entity, if any. - */ - final public String getNotationName() - { - return notation; - } - - // DOM Level 3 methods - - public String getInputEncoding() - { - // TODO - return null; - } - - public String getXmlEncoding() - { - // TODO - return null; - } - - public String getXmlVersion() - { - // TODO - return null; - } - - /** - * The base URI of an external entity is its system ID. - * The base URI of an internal entity is the parent document's base URI. - * @since DOM Level 3 Core - */ - public String getBaseURI() - { - String systemId = getSystemId(); - return (systemId == null) ? owner.getBaseURI() : systemId; - } - -} - diff --git a/libjava/gnu/xml/dom/DomEntityReference.java b/libjava/gnu/xml/dom/DomEntityReference.java deleted file mode 100644 index d4596b405d4..00000000000 --- a/libjava/gnu/xml/dom/DomEntityReference.java +++ /dev/null @@ -1,130 +0,0 @@ -/* DomEntityReference.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DocumentType; -import org.w3c.dom.Entity; -import org.w3c.dom.EntityReference; - -/** - * <p> "EntityReference" implementation (reference to parsed entity). - * This is a non-core DOM class, supporting the "XML" feature. - * It does not represent builtin entities (such as "&amp;") - * or character references, which are always directly expanded in - * DOM trees.</p> - * - * <p> Note that while the DOM specification permits these nodes to have - * a readonly set of children, this is not required. Similarly, it does - * not require a DOM to couple EntityReference nodes with any Entity nodes - * that have the same entity name (and equivalent children). It also - * effectively guarantees that references created directly or indirectly - * through the <em>Document.ImportNode</em> method will not have children. - * The level of functionality you may get is extremely variable. - * - * <p> Also significant is that even at their most functional level, the fact - * that EntityReference children must be readonly has caused significant - * problems when modifying work products held in DOM trees. Other problems - * include issues related to undeclared namespace prefixes (and references - * to the current default namespace) that may be found in the text of such - * parsed entities nodes. These must be contextually bound as part of DOM - * tree construction. When such nodes are moved, the namespace associated - * with a given prefix (or default) may change to be in conflict with the - * namespace bound to the node at creation time. - * - * <p> In short, <em>avoid using this DOM functionality</em>. - * - * @see DomDoctype - * @see DomEntity - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomEntityReference - extends DomNode - implements EntityReference -{ - - private String name; - - /** - * Constructs an EntityReference node associated with the specified - * document. The creator should populate this with whatever contents - * are appropriate, and then mark it as readonly. - * - * <p>This constructor should only be invoked by a Document as part of - * its createEntityReference functionality, or through a subclass which - * is similarly used in a "Sub-DOM" style layer. - * - * @see DomNode#makeReadonly - */ - protected DomEntityReference(DomDocument owner, String name) - { - super(ENTITY_REFERENCE_NODE, owner); - this.name = name; - } - - /** - * Returns the name of the referenced entity. - * @since DOM Level 1 Core - */ - public final String getNodeName() - { - return name; - } - - /** - * The base URI of an entity reference is the base URI where the entity - * declaration occurs. - * @since DOM Level 3 Core - */ - public final String getBaseURI() - { - DocumentType doctype = owner.getDoctype(); - if (doctype == null) - { - return null; - } - Entity entity = (Entity) doctype.getEntities().getNamedItem(name); - if (entity == null) - { - return null; - } - return entity.getBaseURI(); - } - -} diff --git a/libjava/gnu/xml/dom/DomEvent.java b/libjava/gnu/xml/dom/DomEvent.java deleted file mode 100644 index d57eac0e445..00000000000 --- a/libjava/gnu/xml/dom/DomEvent.java +++ /dev/null @@ -1,345 +0,0 @@ -/* DomEvent.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.*; -import org.w3c.dom.events.*; -import org.w3c.dom.views.AbstractView; // used by UIEvent - -/** - * "Event" implementation. Events are - * created (through DocumentEvent interface methods on the document object), - * and are sent to any target node in the document. - * - * <p> Applications may define application specific event subclasses, but - * should otherwise use the <em>DocumentTraversal</em> interface to acquire - * event objects. - * - * @author David Brownell - */ -public class DomEvent - implements Event -{ - - String type; // init - EventTarget target; - EventTarget currentNode; - short eventPhase; - boolean bubbles; // init - boolean cancelable; // init - long timeStamp; // ? - - /** Returns the event's type (name) as initialized */ - public final String getType() - { - return type; - } - - /** - * Returns event's target; delivery of an event is initiated - * by a <em>target.dispatchEvent(event)</em> invocation. - */ - public final EventTarget getTarget() - { - return target; - } - - /** - * Returns the target to which events are currently being - * delivered. When capturing or bubbling, this will not - * be what <em>getTarget</em> returns. - */ - public final EventTarget getCurrentTarget() - { - return currentNode; - } - - /** - * Returns CAPTURING_PHASE, AT_TARGET, or BUBBLING; - * only meaningful within EventListener.handleEvent - */ - public final short getEventPhase() - { - return eventPhase; - } - - /** - * Returns true if the news of the event bubbles to tree tops - * (as specified during initialization). - */ - public final boolean getBubbles() - { - return bubbles; - } - - /** - * Returns true if the default handling may be canceled - * (as specified during initialization). - */ - public final boolean getCancelable() - { - return cancelable; - } - - /** - * Returns the event's timestamp. - */ - public final long getTimeStamp() - { - return timeStamp; - } - - boolean stop; - boolean doDefault; - - /** - * Requests the event no longer be captured or bubbled; only - * listeners on the event target will see the event, if they - * haven't yet been notified. - * - * <p> <em> Avoid using this </em> except for application-specific - * events, for which you the protocol explicitly "blesses" the use - * of this with some event types. Otherwise, you are likely to break - * algorithms which depend on event notification either directly or - * through bubbling or capturing. </p> - * - * <p> Note that this method is not final, specifically to enable - * enforcing of policies about events always propagating. </p> - */ - public void stopPropagation() - { - stop = true; - } - - /** - * Requests that whoever dispatched the event not perform their - * default processing when event delivery completes. Initializes - * event timestamp. - */ - public final void preventDefault() - { - doDefault = false; - } - - /** Initializes basic event state. */ - public void initEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg) - { - eventPhase = 0; - type = typeArg; - bubbles = canBubbleArg; - cancelable = cancelableArg; - timeStamp = System.currentTimeMillis(); - } - - /** Constructs, but does not initialize, an event. */ - public DomEvent(String type) - { - this.type = type; - } - - /** - * Returns a basic printable description of the event's type, - * state, and delivery conditions - */ - public String toString() - { - StringBuffer buf = new StringBuffer("[Event "); - buf.append(type); - switch (eventPhase) - { - case CAPTURING_PHASE: - buf.append(", CAPTURING"); - break; - case AT_TARGET: - buf.append(", AT TARGET"); - break; - case BUBBLING_PHASE: - buf.append(", BUBBLING"); - break; - default: - buf.append(", (inactive)"); - break; - } - if (bubbles && eventPhase != BUBBLING_PHASE) - { - buf.append(", bubbles"); - } - if (cancelable) - { - buf.append(", can cancel"); - } - // were we to provide subclass info, this's where it'd live - buf.append("]"); - return buf.toString(); - } - - /** - * "MutationEvent" implementation. - */ - public static final class DomMutationEvent - extends DomEvent - implements MutationEvent - { - - // package private - Node relatedNode; // init - - private String prevValue; // init - private String newValue; // init - - private String attrName; // init - private short attrChange; // init - - /** Returns any "related" node provided by this type of event */ - public final Node getRelatedNode() - { - return relatedNode; - } - - /** Returns any "previous value" provided by this type of event */ - public final String getPrevValue() - { - return prevValue; - } - - /** Returns any "new value" provided by this type of event */ - public final String getNewValue() - { - return newValue; - } - - /** For attribute change events, returns the attribute's name */ - public final String getAttrName() - { - return attrName; - } - - /** For attribute change events, returns how the attribuet changed */ - public final short getAttrChange() - { - return attrChange; - } - - /** Initializes a mutation event */ - public final void initMutationEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - Node relatedNodeArg, - String prevValueArg, - String newValueArg, - String attrNameArg, - short attrChangeArg) - { - // super.initEvent is inlined here for speed - // (mutation events are issued on all DOM changes) - eventPhase = 0; - type = typeArg; - bubbles = canBubbleArg; - cancelable = cancelableArg; - timeStamp = System.currentTimeMillis(); - - relatedNode = relatedNodeArg; - prevValue = prevValueArg; - newValue = newValueArg; - attrName = attrNameArg; - attrChange = attrChangeArg; - } - - // clear everything that should be GC-able - void clear() - { - type = null; - target = null; - relatedNode = null; - currentNode = null; - prevValue = newValue = attrName = null; - } - - /** Constructs an uninitialized mutation event. */ - public DomMutationEvent(String type) - { - super(type); - } - - } - - /** - * "UIEvent" implementation. - */ - public static class DomUIEvent - extends DomEvent - implements UIEvent - { - - private AbstractView view; // init - private int detail; // init - - /** Constructs an uninitialized User Interface (UI) event */ - public DomUIEvent (String type) { super (type); } - - public final AbstractView getView () { return view; } - public final int getDetail () { return detail; } - - /** Initializes a UI event */ - public final void initUIEvent(String typeArg, - boolean canBubbleArg, - boolean cancelableArg, - AbstractView viewArg, - int detailArg) - { - super.initEvent(typeArg, canBubbleArg, cancelableArg); - view = viewArg; - detail = detailArg; - } - - } - - /* - - static final class DomMouseEvent extends DomUIEvent - implements MouseEvent - { - // another half dozen state variables/accessors - } - - */ - -} - diff --git a/libjava/gnu/xml/dom/DomExtern.java b/libjava/gnu/xml/dom/DomExtern.java deleted file mode 100644 index 87a6909f758..00000000000 --- a/libjava/gnu/xml/dom/DomExtern.java +++ /dev/null @@ -1,117 +0,0 @@ -/* DomExtern.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -/** - * <p> Abstract implemention of nodes describing external DTD-related - * objects. This facilitates reusing code for Entity, Notation, and - * DocumentType (really, external subset) nodes. Such support is not - * part of the core DOM; it's for the "XML" feature. </p> - * - * <p> Note that you are strongly advised to avoid using the DOM - * features that take advantage of this class, since (as of L2) none - * of them is defined fully enough to permit full use of the - * XML feature they partially expose. </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class DomExtern - extends DomNode -{ - - private final String name; - private final String publicId; - private final String systemId; - - /** - * Constructs a node associated with the specified document, - * with the specified descriptive data. - * - * @param owner The document with which this object is associated - * @param name Name of this object - * @param publicId If non-null, provides the entity's PUBLIC identifier - * @param systemId If non-null, provides the entity's SYSTEM identifier - */ - // package private - DomExtern(short nodeType, - DomDocument owner, - String name, - String publicId, - String systemId) - { - super(nodeType, owner); - this.name = name; - this.publicId = publicId; - this.systemId = systemId; - } - - /** - * <b>DOM L1</b> - * Returns the SYSTEM identifier associated with this object, if any. - */ - public final String getSystemId() - { - return systemId; - } - - /** - * <b>DOM L1</b> - * Returns the PUBLIC identifier associated with this object, if any. - */ - public final String getPublicId() - { - return publicId; - } - - /** - * <b>DOM L1</b> - * Returns the object's name. - */ - public final String getNodeName() - { - return name; - } - - public final String getLocalName() - { - return name; - } - -} - diff --git a/libjava/gnu/xml/dom/DomImpl.java b/libjava/gnu/xml/dom/DomImpl.java deleted file mode 100644 index cabe741c931..00000000000 --- a/libjava/gnu/xml/dom/DomImpl.java +++ /dev/null @@ -1,278 +0,0 @@ -/* DomImpl.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Element; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSInput; -import org.w3c.dom.ls.LSOutput; -import org.w3c.dom.ls.LSParser; -import org.w3c.dom.ls.LSSerializer; -import gnu.xml.dom.html2.DomHTMLImpl; -import gnu.xml.dom.ls.DomLSInput; -import gnu.xml.dom.ls.DomLSOutput; -import gnu.xml.dom.ls.DomLSParser; -import gnu.xml.dom.ls.DomLSSerializer; - -/** - * <p> "DOMImplementation" implementation. </p> - * - * <p> At this writing, the following features are supported: - * "XML" (L1, L2, L3), - * "Events" (L2), "MutationEvents" (L2), "USER-Events" (a conformant extension), - * "HTMLEvents" (L2), "UIEvents" (L2), "Traversal" (L2), "XPath" (L3), - * "LS" (L3) "LS-Async" (L3). - * It is possible to compile the package so it doesn't support some of these - * features (notably, Traversal). - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomImpl - implements DOMImplementation, DOMImplementationLS -{ - - /** - * Constructs a DOMImplementation object which supports - * "XML" and other DOM Level 2 features. - */ - public DomImpl() - { - } - - /** - * <b>DOM L1</b> - * Returns true if the specified feature and version are - * supported. Note that the case of the feature name is ignored. - */ - public boolean hasFeature(String name, String version) - { - if (name.length() == 0) - { - return false; - } - name = name.toLowerCase(); - if (name.charAt(0) == '+') - { - name = name.substring(1); - } - - if ("xml".equals(name) || "core".equals(name)) - { - return (version == null || - "".equals(version) || - "1.0".equals(version) || - "2.0".equals(version) || - "3.0".equals(version)); - - } - else if ("ls".equals(name) || "ls-async".equals(name)) - { - return (version == null || - "".equals(version) || - "3.0".equals(version)); - } - else if ("events".equals(name) - || "mutationevents".equals(name) - || "uievents".equals(name) - // || "mouseevents".equals(name) - || "htmlevents".equals(name)) - { - return (version == null || - "".equals(version) || - "2.0".equals(version)); - - // Extension: "USER-" prefix event types can - // be created and passed through the DOM. - - } - else if ("user-events".equals(name)) - { - return (version == null || - "".equals(version) || - "0.1".equals(version)); - - // NOTE: "hasFeature" for events is here interpreted to - // mean the DOM can manufacture those sorts of events, - // since actually choosing to report the events is more - // often part of the environment or application. It's - // only really an issue for mutation events. - - } - else if (DomNode.reportMutations - && "traversal".equals(name)) - { - return (version == null || - "".equals(version) || - "2.0".equals(version)); - } - else if ("xpath".equals(name)) - { - return (version == null || - "".equals(version) || - "3.0".equals(version)); - } - else if ("html".equals(name) || "xhtml".equals(name)) - { - return (version == null || - "".equals(version) || - "2.0".equals(version)); - } - - // views - // stylesheets - // css, css2 - // range - - return false; - } - - /** - * <b>DOM L2</b> - * Creates and returns a DocumentType, associated with this - * implementation. This DocumentType can have no associated - * objects(notations, entities) until the DocumentType is - * first associated with a document. - * - * <p> Note that there is no implication that this DTD will - * be parsed by the DOM, or ever have contents. Moreover, the - * DocumentType created here can only be added to a document by - * the createDocument method(below). <em>That means that the only - * portable way to create a Document object is to start parsing, - * queue comment and processing instruction (PI) nodes, and then only - * create a DOM Document after <b>(a)</b> it's known if a DocumentType - * object is needed, and <b>(b) the name and namespace of the root - * element is known. Queued comment and PI nodes would then be - * inserted appropriately in the document prologue, both before and - * after the DTD node, and additional attributes assigned to the - * root element.</em> - *(One hopes that the final DOM REC fixes this serious botch.) - */ - public DocumentType createDocumentType(String rootName, - String publicId, - String systemId) - // CR2 deleted internal subset, ensuring DocumentType - // is 100% useless instead of just 90% so. - { - DomDocument.checkNCName(rootName, false); - return new DomDoctype(this, rootName, publicId, systemId, null); - } - - /** - * <b>DOM L2</b> - * Creates and returns a Document, populated only with a root element and - * optionally a document type(if that was provided). - */ - public Document createDocument(String namespaceURI, - String rootName, - DocumentType doctype) - { - Document doc = createDocument(); - Element root = null; - - if (rootName != null) - { - root = doc.createElementNS(namespaceURI, rootName); - if (rootName.startsWith("xmlns:")) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns is reserved", null, 0); - } - } - // Bleech -- L2 seemingly _requires_ omission of xmlns attributes. - if (doctype != null) - { - doc.appendChild(doctype); // handles WRONG_DOCUMENT error - } - if (root != null) - { - doc.appendChild(root); - } - return doc; - } - - protected Document createDocument() - { - return new DomDocument(this); - } - - // DOM Level 3 - - public Object getFeature(String feature, String version) - { - if (hasFeature(feature, version)) - { - if ("html".equalsIgnoreCase(feature) || - "xhtml".equalsIgnoreCase(feature)) - { - return new DomHTMLImpl(); - } - return this; - } - return null; - } - - // -- DOMImplementationLS -- - - public LSParser createLSParser(short mode, String schemaType) - throws DOMException - { - return new DomLSParser(mode, schemaType); - } - - public LSSerializer createLSSerializer() - { - return new DomLSSerializer(); - } - - public LSInput createLSInput() - { - return new DomLSInput(); - } - - public LSOutput createLSOutput() - { - return new DomLSOutput(); - } - -} - diff --git a/libjava/gnu/xml/dom/DomIterator.java b/libjava/gnu/xml/dom/DomIterator.java deleted file mode 100644 index 472c6e80585..00000000000 --- a/libjava/gnu/xml/dom/DomIterator.java +++ /dev/null @@ -1,373 +0,0 @@ -/* DomIterator.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.w3c.dom.events.MutationEvent; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; - -/** - * <p> "NodeIterator" implementation, usable with any L2 DOM which - * supports MutationEvents. </p> - * - * @author David Brownell - */ -public final class DomIterator - implements NodeIterator, EventListener -{ - - private Node reference; - private boolean right; - private boolean done; - - private final Node root; - private final int whatToShow; - private final NodeFilter filter; - private final boolean expandEntityReferences; - - /** - * Constructs and initializes an iterator. - */ - protected DomIterator(Node root, - int whatToShow, - NodeFilter filter, - boolean entityReferenceExpansion) - { - if (!root.isSupported("MutationEvents", "2.0")) - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, - "Iterator needs mutation events", root, 0); - } - - this.root = root; - this.whatToShow = whatToShow; - this.filter = filter; - this.expandEntityReferences = entityReferenceExpansion; - - // start condition: going right, seen nothing yet. - reference = null; - right = true; - - EventTarget target = (EventTarget) root; - target.addEventListener("DOMNodeRemoved", this, false); - } - - /** - * <b>DOM L2</b> - * Flags the iterator as done, unregistering its event listener so - * that the iterator can be garbage collected without relying on weak - * references (a "Java 2" feature) in the event subsystem. - */ - public void detach() - { - EventTarget target = (EventTarget) root; - target.removeEventListener("DOMNodeRemoved", this, false); - done = true; - } - - /** - * <b>DOM L2</b> - * Returns the flag controlling whether iteration descends - * through entity references. - */ - public boolean getExpandEntityReferences() - { - return expandEntityReferences; - } - - /** - * <b>DOM L2</b> - * Returns the filter provided during construction. - */ - public NodeFilter getFilter() - { - return filter; - } - - /** - * <b>DOM L2</b> - * Returns the root of the tree this is iterating through. - */ - public Node getRoot() - { - return root; - } - - /** - * <b>DOM L2</b> - * Returns the mask of flags provided during construction. - */ - public int getWhatToShow() - { - return whatToShow; - } - - /** - * <b>DOM L2</b> - * Returns the next node in a forward iteration, masked and filtered. - * Note that the node may be read-only due to entity expansions. - * A null return indicates the iteration is complete, but may still - * be processed backwards. - */ - public Node nextNode() - { - if (done) - { - throw new DomDOMException(DOMException.INVALID_STATE_ERR); - } - right = true; - return walk(true); - } - - /** - * <b>DOM L2</b> - * Returns the next node in a backward iteration, masked and filtered. - * Note that the node may be read-only due to entity expansions. - * A null return indicates the iteration is complete, but may still - * be processed forwards. - */ - public Node previousNode() - { - if (done) - { - throw new DomDOMException(DOMException.INVALID_STATE_ERR); - } - Node previous = reference; - right = false; - walk(false); - return previous; - } - - private boolean shouldShow(Node node) - // raises Runtime exceptions indirectly, via acceptNode() - { - if ((whatToShow & (1 << (node.getNodeType() - 1))) == 0) - { - return false; - } - if (filter == null) - { - return true; - } - return filter.acceptNode(node) == NodeFilter.FILTER_ACCEPT; - } - - // - // scenario: root = 1, sequence = 1 2 ... 3 4 - // forward walk: 1 2 ... 3 4 null - // then backward: 4 3 ... 2 1 null - // - // At the leftmost end, "previous" == null - // At the rightmost end, "previous" == 4 - // - // The current draft spec really seem to make no sense re the - // role of the reference node, so what it says is ignored here. - // - private Node walk(boolean forward) - { - Node here = reference; - - while ((here = successor(here, forward)) != null - && !shouldShow(here)) - { - continue; - } - if (here != null || !forward) - { - reference = here; - } - return here; - } - - private boolean isLeaf(Node here) - { - boolean leaf = !here.hasChildNodes(); - if (!leaf && !expandEntityReferences) - { - leaf = (here.getNodeType() == Node.ENTITY_REFERENCE_NODE); - } - return leaf; - } - - // - // Returns the immediate successor in a forward (or backward) - // document order walk, sans filtering ... except that it knows - // how to stop, returning null when done. This is a depth first - // preorder traversal when run in the forward direction. - // - private Node successor(Node here, boolean forward) - { - Node next; - - // the "leftmost" end is funky - if (here == null) - { - return forward ? root : null; - } - - // - // Forward, this is preorder: children before siblings. - // Backward, it's postorder: we saw the children already. - // - if (forward && !isLeaf(here)) - { - return here.getFirstChild(); - } - - // - // Siblings ... if forward, we visit them, if backwards - // we visit their children first. - // - if (forward) - { - if ((next = here.getNextSibling()) != null) - { - return next; - } - } - else if ((next = here.getPreviousSibling()) != null) - { - if (isLeaf(next)) - { - return next; - } - next = next.getLastChild(); - while (!isLeaf(next)) - { - next = next.getLastChild(); - } - return next; - } - - // - // We can't go down or lateral -- it's up, then. The logic is - // the converse of what's above: backwards is easy (the parent - // is next), forwards isn't. - // - next = here.getParentNode(); - if (!forward) - { - return next; - } - - Node temp = null; - while (next != null - && next != root - && (temp = next.getNextSibling()) == null) - { - next = next.getParentNode(); - } - if (next == root) - { - return null; - } - return temp; - } - - /** - * Not for public use. This lets the iterator know when its - * reference node will be removed from the tree, so that a new - * one may be selected. - * - * <p> This version works by watching removal events as they - * bubble up. So, don't prevent them from bubbling. - */ - public void handleEvent(Event e) - { - MutationEvent event; - Node ancestor, removed; - - if (reference == null - || !"DOMNodeRemoved".equals(e.getType()) - || e.getEventPhase() != Event.BUBBLING_PHASE) - { - return; - } - - event = (MutationEvent) e; - removed = (Node) event.getTarget(); - - // See if the removal will cause trouble for this iterator - // by being the reference node or an ancestor of it. - for (ancestor = reference; - ancestor != null && ancestor != root; - ancestor = ancestor.getParentNode()) - { - if (ancestor == removed) - { - break; - } - } - if (ancestor != removed) - { - return; - } - - // OK, it'll cause trouble. We want to make the "next" - // node in our current traversal direction seem right. - // So we pick the nearest node that's not getting removed, - // but go in the _opposite_ direction from our current - // traversal ... so the "next" doesn't skip anything. - Node candidate; - -search: - while ((candidate = walk(!right)) != null) - { - for (ancestor = candidate; - ancestor != null && ancestor != root; - ancestor = ancestor.getParentNode()) - { - if (ancestor == removed) - { - continue search; - } - } - return; - } - - // The current DOM WD talks about a special case here; - // I've not yet seen it. - } - -} - diff --git a/libjava/gnu/xml/dom/DomNSResolverContext.java b/libjava/gnu/xml/dom/DomNSResolverContext.java deleted file mode 100644 index 4cf57772e9b..00000000000 --- a/libjava/gnu/xml/dom/DomNSResolverContext.java +++ /dev/null @@ -1,90 +0,0 @@ -/* DomNSResolverContext.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.Iterator; -import javax.xml.namespace.NamespaceContext; -import org.w3c.dom.xpath.XPathNSResolver; - -/** - * Namespace content wrapper for an XPathNSResolver. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomNSResolverContext - implements NamespaceContext, Iterator -{ - - final XPathNSResolver resolver; - - DomNSResolverContext(XPathNSResolver resolver) - { - this.resolver = resolver; - } - - public String getNamespaceURI(String prefix) - { - return resolver.lookupNamespaceURI(prefix); - } - - public String getPrefix(String namespaceURI) - { - return null; - } - - public Iterator getPrefixes(String namespaceURI) - { - return this; - } - - public boolean hasNext() - { - return false; - } - - public Object next() - { - return null; - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - -} diff --git a/libjava/gnu/xml/dom/DomNamedNodeMap.java b/libjava/gnu/xml/dom/DomNamedNodeMap.java deleted file mode 100644 index fa5ac964b8a..00000000000 --- a/libjava/gnu/xml/dom/DomNamedNodeMap.java +++ /dev/null @@ -1,417 +0,0 @@ -/* DomNamedNodeMap.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * <p> "NamedNodeMap" implementation. </p> - * Used mostly to hold element attributes, but sometimes also - * to list notations or entities. - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomNamedNodeMap - implements NamedNodeMap -{ - - final DomNode owner; - final short type; - - DomNode first; - int length; - boolean readonly; - - // package private - DomNamedNodeMap(DomNode owner, short type) - { - this.owner = owner; - this.type = type; - } - - /** - * Exposes the internal "readonly" flag. In DOM, all NamedNodeMap - * objects found in a DocumentType object are read-only (after - * they are fully constructed), and those holding attributes of - * a readonly element will also be readonly. - */ - public final boolean isReadonly() - { - return readonly; - } - - /** - * Sets the internal "readonly" flag so the node and its - * children can't be changed. - */ - public void makeReadonly() - { - readonly = true; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - ctx.makeReadonly(); - } - } - - /** - * <b>DOM L1</b> - * Returns the named item from the map, or null; names are just - * the nodeName property. - */ - public Node getNamedItem(String name) - { - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - if (ctx.getNodeName().equals(name)) - { - return ctx; - } - } - return null; - } - - /** - * <b>DOM L2</b> - * Returns the named item from the map, or null; names are the - * localName and namespaceURI properties, ignoring any prefix. - */ - public Node getNamedItemNS(String namespaceURI, String localName) - { - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - String name = ctx.getLocalName(); - if ((localName == null && name == null) || - (localName != null && localName.equals(name))) - { - String uri = ctx.getNamespaceURI(); - if ("".equals(uri)) - { - uri = null; - } - if ((namespaceURI == null && uri == null) || - (namespaceURI != null && namespaceURI.equals(uri))) - { - return ctx; - } - } - } - return null; - } - - /** - * <b>DOM L1</b> - * Stores the named item into the map, optionally overwriting - * any existing node with that name. The name used is just - * the nodeName attribute. - */ - public Node setNamedItem(Node arg) - { - return setNamedItem(arg, false); - } - - /** - * <b>DOM L2</b> - * Stores the named item into the map, optionally overwriting - * any existing node with that fully qualified name. The name - * used incorporates the localName and namespaceURI properties, - * and ignores any prefix. - */ - public Node setNamedItemNS(Node arg) - { - return setNamedItem(arg, true); - } - - Node setNamedItem(Node arg, boolean ns) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - - DomNode node = (DomNode) arg; - if (node.owner != owner.owner) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR); - } - if (node.nodeType != type) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR); - } - if (node.nodeType == Node.ATTRIBUTE_NODE) - { - DomNode element = node.parent; - if (element != null && element != owner) - { - throw new DomDOMException(DOMException.INUSE_ATTRIBUTE_ERR); - } - node.parent = owner; - node.depth = owner.depth + 1; - } - - String nodeName = node.getNodeName(); - String localName = ns ? node.getLocalName() : null; - String namespaceURI = ns ? node.getNamespaceURI() : null; - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - - // maybe attribute ADDITION events (?) - DomNode last = null; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - boolean test = false; - if (ns) - { - String tln = ctx.getLocalName(); - if (tln.equals(localName)) - { - String tu = ctx.getNamespaceURI(); - if ((tu == null && namespaceURI == null) || - (tu != null && tu.equals(namespaceURI))) - { - test = true; - } - } - } - else - { - test = ctx.getNodeName().equals(nodeName); - } - if (test) - { - // replace - node.previous = ctx.previous; - node.next = ctx.next; - if (ctx.previous != null) - { - ctx.previous.next = node; - } - if (ctx.next != null) - { - ctx.next.previous = node; - } - if (first == ctx) - { - first = node; - } - reparent(node, nodeName, ctx.index); - ctx.parent = null; - ctx.next = null; - ctx.previous = null; - ctx.setDepth(0); - ctx.index = 0; - return ctx; - } - last = ctx; - } - // append - if (last != null) - { - last.next = node; - node.previous = last; - } - else - { - first = node; - } - length++; - reparent(node, nodeName, 0); - return null; - } - - void reparent(DomNode node, String nodeName, int i) - { - node.parent = owner; - node.setDepth(owner.depth + 1); - // index renumbering - for (DomNode ctx = node; ctx != null; ctx = ctx.next) - { - ctx.index = i++; - } - // cache xml:space - boolean xmlSpace = "xml:space".equals(nodeName); - if (xmlSpace && owner instanceof DomElement) - { - ((DomElement) owner).xmlSpace = node.getNodeValue(); - } - } - - /** - * <b>DOM L1</b> - * Removes the named item from the map, or reports an exception; - * names are just the nodeName property. - */ - public Node removeNamedItem(String name) - { - return removeNamedItem(null, name, false); - } - - /** - * <b>DOM L2</b> - * Removes the named item from the map, or reports an exception; - * names are the localName and namespaceURI properties. - */ - public Node removeNamedItemNS(String namespaceURI, String localName) - { - return removeNamedItem(namespaceURI, localName, true); - } - - Node removeNamedItem(String uri, String name, boolean ns) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - - // report attribute REMOVAL event? - - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - boolean test = false; - String nodeName = ctx.getNodeName(); - if (ns) - { - String tln = ctx.getLocalName(); - if (tln.equals(name)) - { - String tu = ctx.getNamespaceURI(); - if ((tu == null && uri == null) || - (tu != null && tu.equals(uri))) - { - test = true; - } - } - } - else - { - test = nodeName.equals(name); - } - if (test) - { - // uncache xml:space - boolean xmlSpace = "xml:space".equals(nodeName); - if (xmlSpace && owner instanceof DomElement) - { - ((DomElement) owner).xmlSpace = ""; - } - // is this a default attribute? - if (ctx.nodeType == Node.ATTRIBUTE_NODE) - { - String def = getDefaultValue(ctx.getNodeName()); - if (def != null) - { - ctx.setNodeValue(def); - ((DomAttr) ctx).setSpecified(false); - return null; - } - } - // remove - if (ctx == first) - { - first = ctx.next; - } - if (ctx.previous != null) - { - ctx.previous.next = ctx.next; - } - if (ctx.next != null) - { - ctx.next.previous = ctx.previous; - } - length--; - ctx.previous = null; - ctx.next = null; - ctx.parent = null; - ctx.setDepth(0); - ctx.index = 0; - return ctx; - } - } - throw new DomDOMException(DOMException.NOT_FOUND_ERR); - } - - String getDefaultValue(String name) - { - DomDoctype doctype = (DomDoctype) owner.owner.getDoctype(); - if (doctype == null) - { - return null; - } - DTDAttributeTypeInfo info = - doctype.getAttributeTypeInfo(owner.getNodeName(), name); - if (info == null) - { - return null; - } - return info.value; - } - - /** - * <b>DOM L1</b> - * Returns the indexed item from the map, or null. - */ - public Node item(int index) - { - DomNode ctx = first; - int count = 0; - while (ctx != null && count < index) - { - ctx = ctx.next; - count++; - } - return ctx; - } - - /** - * <b>DOM L1</b> - * Returns the length of the map. - */ - public int getLength() - { - return length; - } - -} diff --git a/libjava/gnu/xml/dom/DomNode.java b/libjava/gnu/xml/dom/DomNode.java deleted file mode 100644 index 761c8de494d..00000000000 --- a/libjava/gnu/xml/dom/DomNode.java +++ /dev/null @@ -1,2189 +0,0 @@ -/* DomNode.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.w3c.dom.Document; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.w3c.dom.UserDataHandler; -import org.w3c.dom.events.DocumentEvent; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventException; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.w3c.dom.events.MutationEvent; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; - -/** - * <p> "Node", "EventTarget", and "DocumentEvent" implementation. - * This provides most of the core DOM functionality; only more - * specialized features are provided by subclasses. Those subclasses may - * have some particular constraints they must implement, by overriding - * methods defined here. Such constraints are noted here in the method - * documentation. </p> - * - * <p> Note that you can create events with type names prefixed with "USER-", - * and pass them through this DOM. This lets you use the DOM event scheme - * for application specific purposes, although you must use a predefined event - * structure (such as MutationEvent) to pass data along with those events. - * Test for existence of this feature with the "USER-Events" DOM feature - * name.</p> - * - * <p> Other kinds of events you can send include the "html" events, - * like "load", "unload", "abort", "error", and "blur"; and the mutation - * events. If this DOM has been compiled with mutation event support - * enabled, it will send mutation events when you change parts of the - * tree; otherwise you may create and send such events yourself, but - * they won't be generated by the DOM itself. </p> - * - * <p> Note that there is a namespace-aware name comparison method, - * <em>nameAndTypeEquals</em>, which compares the names (and types) of - * two nodes in conformance with the "Namespaces in XML" specification. - * While mostly intended for use with elements and attributes, this should - * also be helpful for ProcessingInstruction nodes and some others which - * do not have namespace URIs. - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class DomNode - implements Node, NodeList, EventTarget, DocumentEvent, Cloneable, Comparable -{ - - // package private - //final static String xmlNamespace = "http://www.w3.org/XML/1998/namespace"; - //final static String xmlnsURI = "http://www.w3.org/2000/xmlns/"; - - // tunable - // NKIDS_* affects arrays of children (which grow) - // (currently) fixed size: - // ANCESTORS_* is for event capture/bubbling, # ancestors - // NOTIFICATIONS_* is for per-node event delivery, # events - private static final int NKIDS_DELTA = 8; - private static final int ANCESTORS_INIT = 20; - private static final int NOTIFICATIONS_INIT = 10; - - // tunable: enable mutation events or not? Enabling it costs about - // 10-15% in DOM construction time, last time it was measured. - - // package private !!! - static final boolean reportMutations = true; - - // locking protocol changeable only within this class - private static final Object lockNode = new Object(); - - // NON-FINAL class data - - // Optimize event dispatch by not allocating memory each time - private static boolean dispatchDataLock; - private static DomNode[] ancestors = new DomNode[ANCESTORS_INIT]; - private static ListenerRecord[] notificationSet - = new ListenerRecord[NOTIFICATIONS_INIT]; - - // Ditto for the (most common) event object itself! - private static boolean eventDataLock; - private static DomEvent.DomMutationEvent mutationEvent - = new DomEvent.DomMutationEvent(null); - - // - // PER-INSTANCE DATA - // - - DomDocument owner; - DomNode parent; // parent node; - DomNode previous; // previous sibling node - DomNode next; // next sibling node - DomNode first; // first child node - DomNode last; // last child node - int index; // index of this node in its parent's children - int depth; // depth of the node in the document - int length; // number of children - final short nodeType; - - // Bleech ... "package private" so a builder can populate entity refs. - // writable during construction. DOM spec is nasty. - boolean readonly; - - // event registrations - private ListenerRecord[] listeners; - private int nListeners; - - // DOM Level 3 userData dictionary. - private HashMap userData; - private HashMap userDataHandlers; - - // - // Some of the methods here are declared 'final' because - // knowledge about their implementation is built into this - // class -- for both integrity and performance. - // - - /** - * Reduces space utilization for this node. - */ - public void compact() - { - if (listeners != null && listeners.length != nListeners) - { - if (nListeners == 0) - { - listeners = null; - } - else - { - ListenerRecord[] l = new ListenerRecord[nListeners]; - System.arraycopy(listeners, 0, l, 0, nListeners); - listeners = l; - } - } - } - - /** - * Constructs a node and associates it with its owner. Only - * Document and DocumentType nodes may be created with no owner, - * and DocumentType nodes get an owner as soon as they are - * associated with a document. - */ - protected DomNode(short nodeType, DomDocument owner) - { - this.nodeType = nodeType; - - if (owner == null) - { - // DOM calls never go down this path - if (nodeType != DOCUMENT_NODE && nodeType != DOCUMENT_TYPE_NODE) - { - throw new IllegalArgumentException ("no owner!"); - } - } - this.owner = owner; - } - - - /** - * <b>DOM L1</b> - * Returns null; Element subclasses must override this method. - */ - public NamedNodeMap getAttributes() - { - return null; - } - - /** - * <b>DOM L2></b> - * Returns true iff this is an element node with attributes. - */ - public boolean hasAttributes() - { - return false; - } - - /** - * <b>DOM L1</b> - * Returns a list, possibly empty, of the children of this node. - * In this implementation, to conserve memory, nodes are the same - * as their list of children. This can have ramifications for - * subclasses, which may need to provide their own getLength method - * for reasons unrelated to the NodeList method of the same name. - */ - public NodeList getChildNodes() - { - return this; - } - - /** - * <b>DOM L1</b> - * Returns the first child of this node, or null if there are none. - */ - public Node getFirstChild() - { - return first; - } - - /** - * <b>DOM L1</b> - * Returns the last child of this node, or null if there are none. - */ - public Node getLastChild() - { - return last; - } - - /** - * <b>DOM L1</b> - * Returns true if this node has children. - */ - public boolean hasChildNodes() - { - return length != 0; - } - - - /** - * Exposes the internal "readonly" flag. In DOM, children of - * entities and entity references are readonly, as are the - * objects associated with DocumentType objets. - */ - public final boolean isReadonly() - { - return readonly; - } - - /** - * Sets the internal "readonly" flag so this subtree can't be changed. - * Subclasses need to override this method for any associated content - * that's not a child node, such as an element's attributes or the - * (few) declarations associated with a DocumentType. - */ - public void makeReadonly() - { - readonly = true; - for (DomNode child = first; child != null; child = child.next) - { - child.makeReadonly(); - } - } - - /** - * Used to adopt a node to a new document. - */ - void setOwner(DomDocument doc) - { - this.owner = doc; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - ctx.setOwner(doc); - } - } - - // just checks the node for inclusion -- may be called many - // times (docfrag) before anything is allowed to change - private void checkMisc(DomNode child) - { - if (readonly && !owner.building) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, - null, this, 0); - } - for (DomNode ctx = this; ctx != null; ctx = ctx.parent) - { - if (child == ctx) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR, - "can't make ancestor into a child", - this, 0); - } - } - - DomDocument owner = (nodeType == DOCUMENT_NODE) ? (DomDocument) this : - this.owner; - DomDocument childOwner = child.owner; - short childNodeType = child.nodeType; - - if (childOwner != owner) - { - // new in DOM L2, this case -- patch it up later, in reparent() - if (!(childNodeType == DOCUMENT_TYPE_NODE && childOwner == null)) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, child, 0); - } - } - - // enforce various structural constraints - switch (nodeType) - { - case DOCUMENT_NODE: - switch (childNodeType) - { - case ELEMENT_NODE: - case PROCESSING_INSTRUCTION_NODE: - case COMMENT_NODE: - case DOCUMENT_TYPE_NODE: - return; - } - break; - - case ATTRIBUTE_NODE: - switch (childNodeType) - { - case TEXT_NODE: - case ENTITY_REFERENCE_NODE: - return; - } - break; - - case DOCUMENT_FRAGMENT_NODE: - case ENTITY_REFERENCE_NODE: - case ELEMENT_NODE: - case ENTITY_NODE: - switch (childNodeType) - { - case ELEMENT_NODE: - case TEXT_NODE: - case COMMENT_NODE: - case PROCESSING_INSTRUCTION_NODE: - case CDATA_SECTION_NODE: - case ENTITY_REFERENCE_NODE: - return; - } - break; - } - if (owner.checkingWellformedness) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR, - "can't append " + - nodeTypeToString(childNodeType) + - " to node of type " + - nodeTypeToString(nodeType), - this, 0); - } - } - - // Here's hoping a good optimizer will detect the case when the - // next several methods are never called, and won't allocate - // object code space of any kind. (Case: not reporting any - // mutation events. We can also remove some static variables - // listed above.) - - private void insertionEvent(DomEvent.DomMutationEvent event, - DomNode target) - { - if (owner == null || owner.building) - { - return; - } - boolean doFree = false; - - if (event == null) - { - event = getMutationEvent(); - } - if (event != null) - { - doFree = true; - } - else - { - event = new DomEvent.DomMutationEvent(null); - } - event.initMutationEvent("DOMNodeInserted", - true /* bubbles */, false /* nocancel */, - this /* related */, null, null, null, (short) 0); - target.dispatchEvent(event); - - // XXX should really visit every descendant of 'target' - // and sent a DOMNodeInsertedIntoDocument event to it... - // bleech, there's no way to keep that acceptably fast. - - if (doFree) - { - event.target = null; - event.relatedNode = null; - event.currentNode = null; - eventDataLock = false; - } // else we created work for the GC - } - - private void removalEvent(DomEvent.DomMutationEvent event, - DomNode target) - { - if (owner == null || owner.building) - { - return; - } - boolean doFree = false; - - if (event == null) - { - event = getMutationEvent(); - } - if (event != null) - { - doFree = true; - } - else - { - event = new DomEvent.DomMutationEvent(null); - } - event.initMutationEvent("DOMNodeRemoved", - true /* bubbles */, false /* nocancel */, - this /* related */, null, null, null, (short) 0); - target.dispatchEvent(event); - - // XXX should really visit every descendant of 'target' - // and sent a DOMNodeRemovedFromDocument event to it... - // bleech, there's no way to keep that acceptably fast. - - event.target = null; - event.relatedNode = null; - event.currentNode = null; - if (doFree) - { - eventDataLock = false; - } - // else we created more work for the GC - } - - // - // Avoid creating lots of memory management work, by using a simple - // allocation strategy for the mutation event objects that get used - // at least once per tree modification. We can't use stack allocation, - // so we do the next simplest thing -- more or less, static allocation. - // Concurrent notifications should be rare, anyway. - // - // Returns the preallocated object, which needs to be carefully freed, - // or null to indicate the caller needs to allocate their own. - // - static private DomEvent.DomMutationEvent getMutationEvent() - { - synchronized (lockNode) - { - if (eventDataLock) - { - return null; - } - eventDataLock = true; - return mutationEvent; - } - } - - // NOTE: this is manually inlined in the insertion - // and removal event methods above; change in sync. - static private void freeMutationEvent() - { - // clear fields to enable GC - mutationEvent.clear(); - eventDataLock = false; - } - - void setDepth(int depth) - { - this.depth = depth; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - ctx.setDepth(depth + 1); - } - } - - /** - * <b>DOM L1</b> - * Appends the specified node to this node's list of children. - * Document subclasses must override this to enforce the restrictions - * that there be only one element and document type child. - * - * <p> Causes a DOMNodeInserted mutation event to be reported. - * Will first cause a DOMNodeRemoved event to be reported if the - * parameter already has a parent. If the new child is a document - * fragment node, both events will be reported for each child of - * the fragment; the order in which children are removed and - * inserted is implementation-specific. - * - * <p> If this DOM has been compiled without mutation event support, - * these events will not be reported. - */ - public Node appendChild(Node newChild) - { - try - { - DomNode child = (DomNode) newChild; - - if (child.nodeType == DOCUMENT_FRAGMENT_NODE) - { - // Append all nodes in the fragment to this node - for (DomNode ctx = child.first; ctx != null; ctx = ctx.next) - { - checkMisc(ctx); - } - for (DomNode ctx = child.first; ctx != null; ) - { - DomNode ctxNext = ctx.next; - appendChild(ctx); - ctx = ctxNext; - } - } - else - { - checkMisc(child); - if (child.parent != null) - { - child.parent.removeChild(child); - } - child.parent = this; - child.index = length++; - child.setDepth(depth + 1); - child.next = null; - if (last == null) - { - first = child; - child.previous = null; - } - else - { - last.next = child; - child.previous = last; - } - last = child; - - if (reportMutations) - { - insertionEvent(null, child); - } - } - - return child; - } - catch (ClassCastException e) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, newChild, 0); - } - } - - /** - * <b>DOM L1</b> - * Inserts the specified node in this node's list of children. - * Document subclasses must override this to enforce the restrictions - * that there be only one element and document type child. - * - * <p> Causes a DOMNodeInserted mutation event to be reported. Will - * first cause a DOMNodeRemoved event to be reported if the newChild - * parameter already has a parent. If the new child is a document - * fragment node, both events will be reported for each child of - * the fragment; the order in which children are removed and inserted - * is implementation-specific. - * - * <p> If this DOM has been compiled without mutation event support, - * these events will not be reported. - */ - public Node insertBefore(Node newChild, Node refChild) - { - if (refChild == null) - { - return appendChild(newChild); - } - - try - { - DomNode child = (DomNode) newChild; - DomNode ref = (DomNode) refChild; - - if (child.nodeType == DOCUMENT_FRAGMENT_NODE) - { - // Append all nodes in the fragment to this node - for (DomNode ctx = child.first; ctx != null; ctx = ctx.next) - { - checkMisc(ctx); - } - for (DomNode ctx = child.first; ctx != null; ) - { - DomNode ctxNext = ctx.next; - insertBefore(ctx, ref); - ctx = ctxNext; - } - } - else - { - checkMisc(child); - if (ref == null || ref.parent != this) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, - null, ref, 0); - } - if (ref == child) - { - throw new DomDOMException(DOMException.HIERARCHY_REQUEST_ERR, - "can't insert node before itself", - ref, 0); - } - - if (child.parent != null) - { - child.parent.removeChild(child); - } - child.parent = this; - int i = ref.index; - child.setDepth(depth + 1); - child.next = ref; - if (ref.previous != null) - { - ref.previous.next = child; - } - child.previous = ref.previous; - ref.previous = child; - if (first == ref) - { - first = child; - } - // index renumbering - for (DomNode ctx = child; ctx != null; ctx = ctx.next) - { - ctx.index = i++; - } - - if (reportMutations) - { - insertionEvent(null, child); - } - } - - return child; - } - catch (ClassCastException e) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, newChild, 0); - } - } - - /** - * <b>DOM L1</b> - * Replaces the specified node in this node's list of children. - * Document subclasses must override this to test the restrictions - * that there be only one element and document type child. - * - * <p> Causes DOMNodeRemoved and DOMNodeInserted mutation event to be - * reported. Will cause another DOMNodeRemoved event to be reported if - * the newChild parameter already has a parent. These events may be - * delivered in any order, except that the event reporting removal - * from such an existing parent will always be delivered before the - * event reporting its re-insertion as a child of some other node. - * The order in which children are removed and inserted is implementation - * specific. - * - * <p> If your application needs to depend on the in which those removal - * and insertion events are delivered, don't use this API. Instead, - * invoke the removeChild and insertBefore methods directly, to guarantee - * a specific delivery order. Similarly, don't use document fragments, - * Otherwise your application code may not work on a DOM which implements - * this method differently. - * - * <p> If this DOM has been compiled without mutation event support, - * these events will not be reported. - */ - public Node replaceChild(Node newChild, Node refChild) - { - try - { - DomNode child = (DomNode) newChild; - DomNode ref = (DomNode) refChild; - - DomEvent.DomMutationEvent event = getMutationEvent(); - boolean doFree = (event != null); - - if (child.nodeType == DOCUMENT_FRAGMENT_NODE) - { - // Append all nodes in the fragment to this node - for (DomNode ctx = child.first; ctx != null; ctx = ctx.next) - { - checkMisc(ctx); - } - if (ref == null || ref.parent != this) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, - null, ref, 0); - } - - if (reportMutations) - { - removalEvent(event, ref); - } - length--; - length += child.length; - - if (child.length == 0) - { - // Removal - if (ref.previous != null) - { - ref.previous.next = ref.next; - } - if (ref.next != null) - { - ref.next.previous = ref.previous; - } - if (first == ref) - { - first = ref.next; - } - if (last == ref) - { - last = ref.previous; - } - } - else - { - int i = ref.index; - for (DomNode ctx = child.first; ctx != null; ctx = ctx.next) - { - // Insertion - ctx.parent = this; - ctx.index = i++; - ctx.setDepth(ref.depth); - if (ctx == child.first) - { - ctx.previous = ref.previous; - } - if (ctx == child.last) - { - ctx.next = ref.next; - } - } - if (first == ref) - { - first = child.first; - } - if (last == ref) - { - last = child.last; - } - } - } - else - { - checkMisc(child); - if (ref == null || ref.parent != this) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, - null, ref, 0); - } - - if (reportMutations) - { - removalEvent(event, ref); - } - - if (child.parent != null) - { - child.parent.removeChild(child); - } - child.parent = this; - child.index = ref.index; - child.setDepth(ref.depth); - if (ref.previous != null) - { - ref.previous.next = child; - } - child.previous = ref.previous; - if (ref.next != null) - { - ref.next.previous = child; - } - child.next = ref.next; - if (first == ref) - { - first = child; - } - if (last == ref) - { - last = child; - } - - if (reportMutations) - { - insertionEvent(event, child); - } - if (doFree) - { - freeMutationEvent(); - } - } - ref.parent = null; - ref.index = 0; - ref.setDepth(0); - ref.previous = null; - ref.next = null; - - return ref; - } - catch (ClassCastException e) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, newChild, 0); - } - } - - /** - * <b>DOM L1</b> - * Removes the specified child from this node's list of children, - * or else reports an exception. - * - * <p> Causes a DOMNodeRemoved mutation event to be reported. - * - * <p> If this DOM has been compiled without mutation event support, - * these events will not be reported. - */ - public Node removeChild(Node refChild) - { - try - { - DomNode ref = (DomNode) refChild; - - if (ref == null || ref.parent != this) - { - throw new DomDOMException(DOMException.NOT_FOUND_ERR, - null, ref, 0); - } - if (readonly && !owner.building) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, - null, this, 0); - } - - for (DomNode child = first; child != null; child = child.next) - { - if (child == ref) - { - if (reportMutations) - { - removalEvent(null, child); - } - - length--; - if (ref.previous != null) - { - ref.previous.next = ref.next; - } - if (ref.next != null) - { - ref.next.previous = ref.previous; - } - if (first == ref) - { - first = ref.next; - } - if (last == ref) - { - last = ref.previous; - } - // renumber indices - int i = 0; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - ctx.index = i++; - } - ref.parent = null; - ref.setDepth(0); - ref.index = 0; - ref.previous = null; - ref.next = null; - - return ref; - } - } - throw new DomDOMException(DOMException.NOT_FOUND_ERR, - "that's no child of mine", refChild, 0); - } - catch (ClassCastException e) - { - throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR, - null, refChild, 0); - } - } - - /** - * <b>DOM L1 (NodeList)</b> - * Returns the item with the specified index in this NodeList, - * else null. - */ - public Node item(int index) - { - DomNode child = first; - int count = 0; - while (child != null && count < index) - { - child = child.next; - count++; - } - return child; - } - - /** - * <b>DOM L1 (NodeList)</b> - * Returns the number of elements in this NodeList. - * (Note that many interfaces have a "Length" property, not just - * NodeList, and if a node subtype must implement one of those, - * it will also need to override getChildNodes.) - */ - public int getLength() - { - return length; - } - - /** - * Minimize extra space consumed by this node to hold children and event - * listeners. - */ - public void trimToSize() - { - if (listeners != null && listeners.length != nListeners) - { - ListenerRecord[] newKids = new ListenerRecord[length]; - System.arraycopy(listeners, 0, newKids, 0, nListeners); - listeners = newKids; - } - } - - /** - * <b>DOM L1</b> - * Returns the previous sibling, if one is known. - */ - public Node getNextSibling() - { - return next; - } - - /** - * <b>DOM L1</b> - * Returns the previous sibling, if one is known. - */ - public Node getPreviousSibling() - { - return previous; - } - - /** - * <b>DOM L1</b> - * Returns the parent node, if one is known. - */ - public Node getParentNode() - { - return parent; - } - - /** - * <b>DOM L2</b> - * Consults the DOM implementation to determine if the requested - * feature is supported. DocumentType subclasses must override - * this method, and associate themselves directly with the - * DOMImplementation node used. (This method relies on being able - * to access the DOMImplementation from the owner document, but - * DocumentType nodes can be created without an owner.) - */ - public boolean isSupported(String feature, String version) - { - Document doc = owner; - DOMImplementation impl = null; - - if (doc == null && nodeType == DOCUMENT_NODE) - { - doc = (Document) this; - } - - if (doc == null) - { - // possible for DocumentType - throw new IllegalStateException ("unbound ownerDocument"); - } - - impl = doc.getImplementation(); - return impl.hasFeature(feature, version); - } - - /** - * <b>DOM L1 (modified in L2)</b> - * Returns the owner document. This is only null for Document nodes, - * and (new in L2) for DocumentType nodes which have not yet been - * associated with the rest of their document. - */ - final public Document getOwnerDocument() - { - return owner; - } - - /** - * <b>DOM L1</b> - * Does nothing; this must be overridden (along with the - * getNodeValue method) for nodes with a non-null defined value. - */ - public void setNodeValue(String value) - { - } - - /** - * <b>DOM L1</b> - * Returns null; this must be overridden for nodes types with - * a defined value, along with the setNodeValue method. - */ - public String getNodeValue() - { - return null; - } - - /** This forces GCJ compatibility. - * Without this method GCJ is unable to compile to byte code. - */ - public final short getNodeType() - { - return nodeType; - } - - /** This forces GCJ compatibility. - * Without this method GCJ seems unable to natively compile GNUJAXP. - */ - public abstract String getNodeName(); - - /** - * <b>DOM L2</b> - * Does nothing; this must be overridden (along with the - * getPrefix method) for element and attribute nodes. - */ - public void setPrefix(String prefix) - { - } - - /** - * <b>DOM L2</b> - * Returns null; this must be overridden for element and - * attribute nodes. - */ - public String getPrefix() - { - return null; - } - - /** - * <b>DOM L2</b> - * Returns null; this must be overridden for element and - * attribute nodes. - */ - public String getNamespaceURI() - { - return null; - } - - /** - * <b>DOM L2</b> - * Returns the node name; this must be overridden for element and - * attribute nodes. - */ - public String getLocalName() - { - return null; - } - - /** - * <b>DOM L1</b> - * Returns a clone of this node which optionally includes cloned - * versions of child nodes. Clones are always mutable, except for - * entity reference nodes. - */ - public Node cloneNode(boolean deep) - { - DomNode node = (DomNode) clone(); - - if (deep) - { - DomDocument doc = (nodeType == DOCUMENT_NODE) ? - (DomDocument) node : node.owner; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - DomNode newChild = (DomNode) ctx.cloneNode(deep); - newChild.setOwner(doc); - node.appendChild(newChild); - } - } - - if (nodeType == ENTITY_REFERENCE_NODE) - { - node.makeReadonly(); - } - notifyUserDataHandlers(UserDataHandler.NODE_CLONED, this, node); - return node; - } - - void notifyUserDataHandlers(short op, Node src, Node dst) - { - if (userDataHandlers != null) - { - for (Iterator i = userDataHandlers.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry) i.next(); - String key = (String) entry.getKey(); - UserDataHandler handler = (UserDataHandler) entry.getValue(); - Object data = userData.get(key); - handler.handle(op, key, data, src, dst); - } - } - } - - /** - * Clones this node; roughly equivalent to cloneNode(false). - * Element subclasses must provide a new implementation which - * invokes this method to handle the basics, and then arranges - * to clone any element attributes directly. Attribute subclasses - * must make similar arrangements, ensuring that existing ties to - * elements are broken by cloning. - */ - public Object clone() - { - try - { - DomNode node = (DomNode) super.clone(); - - node.parent = null; - node.depth = 0; - node.index = 0; - node.length = 0; - node.first = null; - node.last = null; - node.previous = null; - node.next = null; - - node.readonly = false; - node.listeners = null; - node.nListeners = 0; - return node; - - } - catch (CloneNotSupportedException x) - { - throw new Error("clone didn't work"); - } - } - - // the elements-by-tagname stuff is needed for both - // elements and documents ... this is in lieu of a - // common base class between Node and NodeNS. - - /** - * <b>DOM L1</b> - * Creates a NodeList giving array-style access to elements with - * the specified name. Access is fastest if indices change by - * small values, and the DOM is not modified. - */ - public NodeList getElementsByTagName(String tag) - { - return new ShadowList(null, tag); - } - - /** - * <b>DOM L2</b> - * Creates a NodeList giving array-style access to elements with - * the specified namespace and local name. Access is fastest if - * indices change by small values, and the DOM is not modified. - */ - public NodeList getElementsByTagNameNS(String namespace, String local) - { - return new ShadowList(namespace, local); - } - - - // - // This shadow class is GC-able even when the live list it shadows - // can't be, because of event registration hookups. Its finalizer - // makes that live list become GC-able. - // - final class ShadowList - implements NodeList - { - - private LiveNodeList liveList; - - ShadowList(String ns, String local) - { - liveList = new LiveNodeList(ns, local); - } - - public void finalize() - { - liveList.detach(); - liveList = null; - } - - public Node item(int index) - { - return liveList.item(index); - } - - public int getLength() - { - return liveList.getLength(); - } - } - - final class LiveNodeList - implements NodeList, EventListener, NodeFilter - { - - private final boolean matchAnyURI; - private final boolean matchAnyName; - private final String elementURI; - private final String elementName; - - private DomIterator current; - private int lastIndex; - - LiveNodeList(String uri, String name) - { - elementURI = uri; - elementName = name; - matchAnyURI = "*".equals(uri); - matchAnyName = "*".equals(name); - - DomNode.this.addEventListener("DOMNodeInserted", this, true); - DomNode.this.addEventListener("DOMNodeRemoved", this, true); - } - - void detach() - { - current.detach(); - current = null; - - DomNode.this.removeEventListener("DOMNodeInserted", this, true); - DomNode.this.removeEventListener("DOMNodeRemoved", this, true); - } - - public short acceptNode(Node element) - { - if (element == DomNode.this) - { - return FILTER_SKIP; - } - - // use namespace-aware matching ... - if (elementURI != null) - { - if (!(matchAnyURI - || elementURI.equals(element.getNamespaceURI()))) - { - return FILTER_SKIP; - } - if (!(matchAnyName - || elementName.equals(element.getLocalName()))) - { - return FILTER_SKIP; - } - - // ... or qName-based kind. - } - else - { - if (!(matchAnyName - || elementName.equals(element.getNodeName()))) - { - return FILTER_SKIP; - } - } - return FILTER_ACCEPT; - } - - private DomIterator createIterator() - { - return new DomIterator(DomNode.this, - NodeFilter.SHOW_ELEMENT, - this, /* filter */ - true /* expand entity refs */ - ); - } - - public void handleEvent(Event e) - { - MutationEvent mutation = (MutationEvent) e; - Node related = mutation.getRelatedNode(); - - // XXX if it's got children ... check all kids too, they - // will invalidate our saved index - - if (related.getNodeType() != Node.ELEMENT_NODE || - related.getNodeName() != elementName || - related.getNamespaceURI() != elementURI) - { - return; - } - - current = null; - } - - public Node item(int index) - { - if (current == null) - { - current = createIterator(); - lastIndex = -1; - } - - // last node or before? go backwards - if (index <= lastIndex) { - while (index != lastIndex) { - current.previousNode (); - lastIndex--; - } - Node ret = current.previousNode (); - current = null; - return ret; - } - - // somewhere after last node - while (++lastIndex != index) - current.nextNode (); - Node ret = current.nextNode (); - current = null; - return ret; - } - - public int getLength() - { - int retval = 0; - NodeIterator iter = createIterator(); - - while (iter.nextNode() != null) - { - retval++; - } - current = null; - return retval; - } - - } - - // - // EventTarget support - // - static final class ListenerRecord - { - - String type; - EventListener listener; - boolean useCapture; - - // XXX use JDK 1.2 java.lang.ref.WeakReference to listener, - // and we can both get rid of "shadow" classes and remove - // the need for applications to apply similar trix ... but - // JDK 1.2 support isn't generally available yet - - ListenerRecord(String type, EventListener listener, boolean useCapture) - { - this.type = type.intern(); - this.listener = listener; - this.useCapture = useCapture; - } - - boolean equals(ListenerRecord rec) - { - return listener == rec.listener - && useCapture == rec.useCapture - && type == rec.type; - } - - } - - /** - * <b>DOM L2 (Events)</b> - * Returns an instance of the specified type of event object. - * Understands about DOM Mutation, HTML, and UI events. - * - * <p>If the name of the event type begins with "USER-", then an object - * implementing the "Event" class will be returned; this provides a - * limited facility for application-defined events to use the DOM event - * infrastructure. Alternatively, use one of the standard DOM event - * classes and initialize it using use such a "USER-" event type name; - * or defin, instantiate, and initialize an application-specific subclass - * of DomEvent and pass that to dispatchEvent(). - * - * @param eventType Identifies the particular DOM feature module - * defining the type of event, such as "MutationEvents". - * <em>The event "name" is a different kind of "type".</em> - */ - public Event createEvent(String eventType) - { - eventType = eventType.toLowerCase(); - - if ("mutationevents".equals(eventType)) - { - return new DomEvent.DomMutationEvent(null); - } - - if ("htmlevents".equals(eventType) - || "events".equals(eventType) - || "user-events".equals(eventType)) - { - return new DomEvent(null); - } - - if ("uievents".equals(eventType)) - { - return new DomEvent.DomUIEvent(null); - } - - // mouse events - - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR, - eventType, null, 0); - } - - /** - * <b>DOM L2 (Events)</b> - * Registers an event listener's interest in a class of events. - */ - public final void addEventListener(String type, - EventListener listener, - boolean useCapture) - { - if (listeners == null) - { - listeners = new ListenerRecord[1]; - } - else if (nListeners == listeners.length) - { - ListenerRecord[] newListeners = - new ListenerRecord[listeners.length + NKIDS_DELTA]; - System.arraycopy(listeners, 0, newListeners, 0, nListeners); - listeners = newListeners; - } - - // prune duplicates - ListenerRecord record; - - record = new ListenerRecord(type, listener, useCapture); - for (int i = 0; i < nListeners; i++) - { - if (record.equals(listeners[i])) - { - return; - } - } - listeners [nListeners++] = record; - } - - // XXX this exception should be discarded from DOM - - // this class can be instantiated, unlike the one in the spec - static final class DomEventException - extends EventException - { - - DomEventException() - { - super(UNSPECIFIED_EVENT_TYPE_ERR, "unspecified event type"); - } - - } - - /** - * <b>DOM L2 (Events)</b> - * Delivers an event to all relevant listeners, returning true if the - * caller should perform their default action. Note that the event - * must have been provided by the createEvent() method on this - * class, else it can't be dispatched. - * - * @see #createEvent - * - * @exception NullPointerException When a null event is passed. - * @exception ClassCastException When the event wasn't provided by - * the createEvent method, or otherwise isn't a DomEvent. - * @exception EventException If the event type wasn't specified - */ - public final boolean dispatchEvent(Event event) - throws EventException - { - DomEvent e = (DomEvent) event; - DomNode[] ancestors = null; - int ancestorMax = 0; - boolean haveDispatchDataLock = false; - - if (e.type == null) - { - throw new DomEventException(); - } - - e.doDefault = true; - e.target = this; - - // - // Typical case: one nonrecursive dispatchEvent call at a time - // for this class. If that's our case, we can avoid allocating - // garbage, which is overall a big win. Even with advanced GCs - // that deal well with short-lived garbage, and wayfast allocators, - // it still helps. - // - // Remember -- EVERY mutation goes though here at least once. - // - // When populating a DOM tree, trying to send mutation events is - // the primary cost; this dominates the critical path. - // - try - { - DomNode current; - int index; - boolean haveAncestorRegistrations = false; - ListenerRecord[] notificationSet; - int ancestorLen; - - synchronized (lockNode) - { - if (!dispatchDataLock) - { - haveDispatchDataLock = dispatchDataLock = true; - notificationSet = DomNode.notificationSet; - ancestors = DomNode.ancestors; - } - else - { - notificationSet = new ListenerRecord[NOTIFICATIONS_INIT]; - ancestors = new DomNode[ANCESTORS_INIT]; - } - ancestorLen = ancestors.length; - } - - // XXX autogrow ancestors ... based on statistics - - // Climb to the top of this subtree and handle capture, letting - // each node (from the top down) capture until one stops it or - // until we get to this one. - - for (index = 0, current = parent; - current != null && index < ancestorLen; - index++, current = current.parent) - { - if (current.nListeners != 0) - { - haveAncestorRegistrations = true; - } - ancestors [index] = current; - } - if (current != null) - { - throw new RuntimeException("dispatchEvent capture stack size"); - } - - ancestorMax = index; - e.stop = false; - - if (haveAncestorRegistrations) - { - e.eventPhase = Event.CAPTURING_PHASE; - while (!e.stop && index-- > 0) - { - current = ancestors [index]; - if (current.nListeners != 0) - { - notifyNode(e, current, true, notificationSet); - } - } - } - - // Always deliver events to the target node (this) - // unless stopPropagation was called. If we saw - // no registrations yet (typical!), we never will. - if (!e.stop && nListeners != 0) - { - e.eventPhase = Event.AT_TARGET; - notifyNode (e, this, false, notificationSet); - } - else if (!haveAncestorRegistrations) - { - e.stop = true; - } - - // If the event bubbles and propagation wasn't halted, - // walk back up the ancestor list. Stop bubbling when - // any bubbled event handler stops it. - - if (!e.stop && e.bubbles) - { - e.eventPhase = Event.BUBBLING_PHASE; - for (index = 0; - !e.stop - && index < ancestorMax - && (current = ancestors[index]) != null; - index++) - { - if (current.nListeners != 0) - { - notifyNode(e, current, false, notificationSet); - } - } - } - e.eventPhase = 0; - - // Caller chooses whether to perform the default - // action based on return from this method. - return e.doDefault; - - } - finally - { - if (haveDispatchDataLock) - { - // synchronize to force write ordering - synchronized (lockNode) - { - // null out refs to ensure they'll be GC'd - for (int i = 0; i < ancestorMax; i++) - { - ancestors [i] = null; - } - // notificationSet handled by notifyNode - - dispatchDataLock = false; - } - } - } - } - - private void notifyNode(DomEvent e, - DomNode current, - boolean capture, - ListenerRecord[] notificationSet) - { - int count = 0; - - // do any of this set of listeners get notified? - for (int i = 0; i < current.nListeners; i++) - { - ListenerRecord rec = current.listeners[i]; - - if (rec.useCapture != capture) - { - continue; - } - if (!e.type.equals (rec.type)) - { - continue; - } - if (count >= notificationSet.length) - { - // very simple growth algorithm - int len = Math.max(notificationSet.length, 1); - ListenerRecord[] tmp = new ListenerRecord[len * 2]; - System.arraycopy(notificationSet, 0, tmp, 0, - notificationSet.length); - notificationSet = tmp; - } - notificationSet[count++] = rec; - } - - // Notify just those listeners - e.currentNode = current; - for (int i = 0; i < count; i++) - { - try - { - // Late in the DOM CR process (3rd or 4th CR?) the - // removeEventListener spec became asymmetric with respect - // to addEventListener ... effect is now immediate. - for (int j = 0; j < current.nListeners; j++) - { - if (current.listeners[j].equals(notificationSet[i])) - { - notificationSet[i].listener.handleEvent(e); - break; - } - } - - } - catch (Exception x) - { - // ignore all exceptions - } - notificationSet[i] = null; // free for GC - } - } - - /** - * <b>DOM L2 (Events)</b> - * Unregisters an event listener. - */ - public final void removeEventListener(String type, - EventListener listener, - boolean useCapture) - { - for (int i = 0; i < nListeners; i++) - { - if (listeners[i].listener != listener) - { - continue; - } - if (listeners[i].useCapture != useCapture) - { - continue; - } - if (!listeners[i].type.equals(type)) - { - continue; - } - - if (nListeners == 1) - { - listeners = null; - nListeners = 0; - } - else - { - for (int j = i + 1; j < nListeners; j++) - { - listeners[i++] = listeners[j++]; - } - listeners[--nListeners] = null; - } - break; - } - // no exceptions reported - } - - /** - * <b>DOM L1 (relocated in DOM L2)</b> - * In this node and all contained nodes (including attributes if - * relevant) merge adjacent text nodes. This is done while ignoring - * text which happens to use CDATA delimiters). - */ - public final void normalize() - { - // Suspend readonly status - boolean saved = readonly; - readonly = false; - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - switch (ctx.nodeType) - { - case TEXT_NODE: - while (ctx.next != null && ctx.next.nodeType == TEXT_NODE) - { - Text text = (Text) ctx; - text.appendData(ctx.next.getNodeValue()); - removeChild(ctx.next); - } - break; - case ELEMENT_NODE: - NamedNodeMap attrs = ctx.getAttributes(); - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - attrs.item(i).normalize(); - } - // Fall through - case DOCUMENT_NODE: - case DOCUMENT_FRAGMENT_NODE: - case ATTRIBUTE_NODE: - case ENTITY_REFERENCE_NODE: - ctx.normalize(); - break; - } - } - readonly = saved; - } - - /** - * Returns true iff node types match, and either (a) both nodes have no - * namespace and their getNodeName() values are the same, or (b) both - * nodes have the same getNamespaceURI() and same getLocalName() values. - * - * <p>Note that notion of a "Per-Element-Type" attribute name scope, as - * found in a non-normative appendix of the XML Namespaces specification, - * is not supported here. Your application must implement that notion, - * typically by not bothering to check nameAndTypeEquals for attributes - * without namespace URIs unless you already know their elements are - * nameAndTypeEquals. - */ - public boolean nameAndTypeEquals(Node other) - { - if (other == this) - { - return true; - } - // node types must match - if (nodeType != other.getNodeType()) - { - return false; - } - - // if both have namespaces, do a "full" comparision - // this is a "global" partition - String ns1 = this.getNamespaceURI(); - String ns2 = other.getNamespaceURI(); - - if (ns1 != null && ns2 != null) - { - return ns1.equals(ns2) && - getLocalName().equals(other.getLocalName()); - } - - // if neither has a namespace, this is a "no-namespace" name. - if (ns1 == null && ns2 == null) - { - if (!getNodeName().equals(other.getNodeName())) - { - return false; - } - // can test the non-normative "per-element-type" scope here. - // if this is an attribute node and both nodes have been bound - // to elements (!!), then return the nameAndTypeEquals() - // comparison of those elements. - return true; - } - - // otherwise they're unequal: one scoped, one not. - return false; - } - - // DOM Level 3 methods - - public String getBaseURI() - { - return (parent != null) ? parent.getBaseURI() : null; - } - - public short compareDocumentPosition(Node other) - throws DOMException - { - return (short) compareTo(other); - } - - /** - * DOM nodes have a natural ordering: document order. - */ - public final int compareTo(Object other) - { - if (other instanceof DomNode) - { - DomNode n1 = this; - DomNode n2 = (DomNode) other; - if (n1.owner != n2.owner) - { - return 0; - } - int d1 = n1.depth, d2 = n2.depth; - int delta = d1 - d2; - while (d1 > d2) - { - n1 = n1.parent; - d1--; - } - while (d2 > d1) - { - n2 = n2.parent; - d2--; - } - int c = compareTo2(n1, n2); - return (c != 0) ? c : delta; - } - return 0; - } - - /** - * Compare two nodes at the same depth. - */ - final int compareTo2(DomNode n1, DomNode n2) - { - if (n1 == n2 || n1.depth == 0 || n2.depth == 0) - { - return 0; - } - int c = compareTo2(n1.parent, n2.parent); - return (c != 0) ? c : n1.index - n2.index; - } - - public final String getTextContent() - throws DOMException - { - return getTextContent(true); - } - - final String getTextContent(boolean topLevel) - throws DOMException - { - switch (nodeType) - { - case ELEMENT_NODE: - case ENTITY_NODE: - case ENTITY_REFERENCE_NODE: - case DOCUMENT_FRAGMENT_NODE: - StringBuffer buffer = new StringBuffer(); - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - String textContent = ctx.getTextContent(false); - if (textContent != null) - { - buffer.append(textContent); - } - } - return buffer.toString(); - case TEXT_NODE: - case CDATA_SECTION_NODE: - if (((Text) this).isElementContentWhitespace()) - { - return ""; - } - return getNodeValue(); - case ATTRIBUTE_NODE: - return getNodeValue(); - case COMMENT_NODE: - case PROCESSING_INSTRUCTION_NODE: - return topLevel ? getNodeValue() : ""; - default: - return null; - } - } - - public void setTextContent(String textContent) - throws DOMException - { - switch (nodeType) - { - case ELEMENT_NODE: - case ATTRIBUTE_NODE: - case ENTITY_NODE: - case ENTITY_REFERENCE_NODE: - case DOCUMENT_FRAGMENT_NODE: - for (DomNode ctx = first; ctx != null; ) - { - DomNode n = ctx.next; - removeChild(ctx); - ctx = n; - } - if (textContent != null) - { - Text text = owner.createTextNode(textContent); - appendChild(text); - } - break; - case TEXT_NODE: - case CDATA_SECTION_NODE: - case COMMENT_NODE: - case PROCESSING_INSTRUCTION_NODE: - setNodeValue(textContent); - break; - } - } - - public boolean isSameNode(Node other) - { - return this == other; - } - - public String lookupPrefix(String namespaceURI) - { - return (parent == null || parent == owner) ? null : - parent.lookupPrefix(namespaceURI); - } - - public boolean isDefaultNamespace(String namespaceURI) - { - return (parent == null || parent == owner) ? false : - parent.isDefaultNamespace(namespaceURI); - } - - public String lookupNamespaceURI(String prefix) - { - return (parent == null || parent == owner) ? null : - parent.lookupNamespaceURI(prefix); - } - - public boolean isEqualNode(Node arg) - { - if (this == arg) - { - return true; - } - if (arg == null) - { - return false; - } - if (nodeType != arg.getNodeType() || - !equal(getNodeName(), arg.getNodeName()) || - !equal(getLocalName(), arg.getLocalName()) || - !equal(getNamespaceURI(), arg.getNamespaceURI()) || - !equal(getPrefix(), arg.getPrefix()) || - !equal(getNodeValue(), arg.getNodeValue())) - { - return false; - } - // Children - Node argCtx = arg.getFirstChild(); - getFirstChild(); // because of DomAttr lazy children - for (DomNode ctx = first; ctx != null; ctx = ctx.next) - { - if (!ctx.isEqualNode(argCtx)) - { - return false; - } - argCtx = argCtx.getNextSibling(); - } - if (argCtx != null) - { - return false; - } - - // TODO Attr NamedNodeMap - // TODO DocumentType - return true; - } - - boolean equal(String arg1, String arg2) - { - return ((arg1 == null && arg2 == null) || - (arg1 != null && arg1.equals(arg2))); - } - - public Object getFeature(String feature, String version) - { - DOMImplementation impl = (nodeType == DOCUMENT_NODE) ? - ((Document) this).getImplementation() : owner.getImplementation(); - if (impl.hasFeature(feature, version)) - { - return this; - } - return null; - } - - public Object setUserData(String key, Object data, UserDataHandler handler) - { - if (userData == null) - { - userData = new HashMap(); - } - if (handler != null) - { - if (userDataHandlers == null) - { - userDataHandlers = new HashMap(); - } - userDataHandlers.put(key, handler); - } - return userData.put(key, data); - } - - public Object getUserData(String key) - { - if (userData == null) - { - return null; - } - return userData.get(key); - } - - public String toString() - { - String nodeName = getNodeName(); - String nodeValue = getNodeValue(); - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - if (nodeName != null) - { - buf.append(nodeName); - } - if (nodeValue != null) - { - if (nodeName != null) - { - buf.append('='); - } - buf.append('\''); - buf.append(encode(nodeValue)); - buf.append('\''); - } - buf.append(']'); - return buf.toString(); - } - - String encode(String value) - { - StringBuffer buf = null; - int len = value.length(); - for (int i = 0; i < len; i++) - { - char c = value.charAt(i); - if (c == '\n') - { - if (buf == null) - { - buf = new StringBuffer(value.substring(0, i)); - } - buf.append("\\n"); - } - else if (c == '\r') - { - if (buf == null) - { - buf = new StringBuffer(value.substring(0, i)); - } - buf.append("\\r"); - } - else if (buf != null) - { - buf.append(c); - } - } - return (buf != null) ? buf.toString() : value; - } - - String nodeTypeToString(short nodeType) - { - switch (nodeType) - { - case ELEMENT_NODE: - return "ELEMENT_NODE"; - case ATTRIBUTE_NODE: - return "ATTRIBUTE_NODE"; - case TEXT_NODE: - return "TEXT_NODE"; - case CDATA_SECTION_NODE: - return "CDATA_SECTION_NODE"; - case DOCUMENT_NODE: - return "DOCUMENT_NODE"; - case DOCUMENT_TYPE_NODE: - return "DOCUMENT_TYPE_NODE"; - case COMMENT_NODE: - return "COMMENT_NODE"; - case PROCESSING_INSTRUCTION_NODE: - return "PROCESSING_INSTRUCTION_NODE"; - case DOCUMENT_FRAGMENT_NODE: - return "DOCUMENT_FRAGMENT_NODE"; - case ENTITY_NODE: - return "ENTITY_NODE"; - case ENTITY_REFERENCE_NODE: - return "ENTITY_REFERENCE_NODE"; - case NOTATION_NODE: - return "NOTATION_NODE"; - default: - return "UNKNOWN"; - } - } - -} - diff --git a/libjava/gnu/xml/dom/DomNodeIterator.java b/libjava/gnu/xml/dom/DomNodeIterator.java deleted file mode 100644 index 6079f7a126a..00000000000 --- a/libjava/gnu/xml/dom/DomNodeIterator.java +++ /dev/null @@ -1,327 +0,0 @@ -/* DomNodeIterator.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; -import org.w3c.dom.traversal.TreeWalker; - -/** - * Node iterator and tree walker. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomNodeIterator - implements NodeIterator, TreeWalker -{ - - Node root; - final int whatToShow; - final NodeFilter filter; - final boolean entityReferenceExpansion; - final boolean walk; - Node current; - - public DomNodeIterator(Node root, int whatToShow, NodeFilter filter, - boolean entityReferenceExpansion, boolean walk) - { - if (root == null) - { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "null root"); - } - this.root = root; - this.whatToShow = whatToShow; - this.filter = filter; - this.entityReferenceExpansion = entityReferenceExpansion; - this.walk = walk; - current = root; - } - - public Node getRoot() - { - return root; - } - - public int getWhatToShow() - { - return whatToShow; - } - - public NodeFilter getFilter() - { - return filter; - } - - public boolean getExpandEntityReferences() - { - return entityReferenceExpansion; - } - - public Node nextNode() - throws DOMException - { - if (root == null) - { - throw new DOMException(DOMException.INVALID_STATE_ERR, "null root"); - } - Node ret; - do - { - if (current.equals(root)) - { - ret = root.getFirstChild(); - } - else if (walk) - { - ret = current.getFirstChild(); - if (ret == null) - { - ret = current.getNextSibling(); - } - if (ret == null) - { - Node tmp = current; - ret = tmp.getParentNode(); - while (!ret.equals(root) && tmp.equals(ret.getLastChild())) - { - tmp = ret; - ret = tmp.getParentNode(); - } - if (ret.equals(root)) - { - ret = null; - } - else - { - ret = ret.getNextSibling(); - } - } - } - else - { - ret = current.getNextSibling(); - } - } - while (!accept(ret)); - current = (ret == null) ? current : ret; - return ret; - } - - public Node previousNode() - throws DOMException - { - if (root == null) - { - throw new DOMException(DOMException.INVALID_STATE_ERR, "null root"); - } - Node ret; - do - { - if (current.equals(root)) - { - ret = current.getLastChild(); - } - else if (walk) - { - ret = current.getLastChild(); - if (ret == null) - { - ret = current.getPreviousSibling(); - } - if (ret == null) - { - Node tmp = current; - ret = tmp.getParentNode(); - while (!ret.equals(root) && tmp.equals(ret.getFirstChild())) - { - tmp = ret; - ret = tmp.getParentNode(); - } - if (ret.equals(root)) - { - ret = null; - } - else - { - ret = ret.getPreviousSibling(); - } - } - } - else - { - ret = current.getPreviousSibling(); - } - } - while (!accept(ret)); - current = (ret == null) ? current : ret; - return ret; - } - - public Node getCurrentNode() - { - return current; - } - - public void setCurrentNode(Node current) - throws DOMException - { - if (current == null) - { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "null root"); - } - this.current = current; - } - - public Node parentNode() - { - Node ret = current.getParentNode(); - if (!accept (ret)) - { - ret = null; - } - current = (ret == null) ? current : ret; - return ret; - } - - public Node firstChild () - { - Node ret = current.getFirstChild(); - while (!accept(ret)) - { - ret = ret.getNextSibling(); - } - current = (ret == null) ? current : ret; - return ret; - } - - public Node lastChild() - { - Node ret = current.getLastChild(); - while (!accept(ret)) - { - ret = ret.getPreviousSibling(); - } - current = (ret == null) ? current : ret; - return ret; - } - - public Node previousSibling() - { - Node ret = current.getPreviousSibling(); - while (!accept(ret)) - { - ret = ret.getPreviousSibling(); - } - current = (ret == null) ? current : ret; - return ret; - } - - public Node nextSibling() - { - Node ret = current.getNextSibling(); - while (!accept(ret)) - { - ret = ret.getNextSibling(); - } - current = (ret == null) ? current : ret; - return ret; - } - - public void detach() - { - root = null; - } - - boolean accept(Node node) - { - if (node == null) - { - return true; - } - boolean ret; - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - ret = (whatToShow & NodeFilter.SHOW_ATTRIBUTE) != 0; - break; - case Node.CDATA_SECTION_NODE: - ret = (whatToShow & NodeFilter.SHOW_CDATA_SECTION) != 0; - break; - case Node.COMMENT_NODE: - ret = (whatToShow & NodeFilter.SHOW_COMMENT) != 0; - break; - case Node.DOCUMENT_NODE: - ret = (whatToShow & NodeFilter.SHOW_DOCUMENT) != 0; - break; - case Node.DOCUMENT_FRAGMENT_NODE: - ret = (whatToShow & NodeFilter.SHOW_DOCUMENT_FRAGMENT) != 0; - break; - case Node.DOCUMENT_TYPE_NODE: - ret = (whatToShow & NodeFilter.SHOW_DOCUMENT_TYPE) != 0; - break; - case Node.ELEMENT_NODE: - ret = (whatToShow & NodeFilter.SHOW_ELEMENT) != 0; - break; - case Node.ENTITY_NODE: - ret = (whatToShow & NodeFilter.SHOW_ENTITY) != 0; - break; - case Node.ENTITY_REFERENCE_NODE: - ret = (whatToShow & NodeFilter.SHOW_ENTITY_REFERENCE) != 0; - ret = ret && entityReferenceExpansion; - break; - case Node.NOTATION_NODE: - ret = (whatToShow & NodeFilter.SHOW_NOTATION) != 0; - break; - case Node.PROCESSING_INSTRUCTION_NODE: - ret = (whatToShow & NodeFilter.SHOW_PROCESSING_INSTRUCTION) != 0; - break; - case Node.TEXT_NODE: - ret = (whatToShow & NodeFilter.SHOW_TEXT) != 0; - break; - default: - ret = true; - } - if (ret && filter != null) - { - ret = (filter.acceptNode(node) == NodeFilter.FILTER_ACCEPT); - } - return ret; - } - -} diff --git a/libjava/gnu/xml/dom/DomNotation.java b/libjava/gnu/xml/dom/DomNotation.java deleted file mode 100644 index 26e78724f27..00000000000 --- a/libjava/gnu/xml/dom/DomNotation.java +++ /dev/null @@ -1,103 +0,0 @@ -/* DomNotation.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Notation; - -/** - * <p> "Notation" implementation. This is a non-core DOM class, supporting - * the "XML" feature. </p> - * - * <p> Although unparsed entities using this notation can be detected using - * DOM, neither NOTATIONS nor ENTITY/ENTITIES attributes can be so detected. - * More, there is no portable way to construct a Notation node, so there's - * no way that vendor-neutral DOM construction APIs could even report a - * NOTATION used to identify the intended meaning of a ProcessingInstruction. - * </p> - * - * <p> In short, <em>avoid using this DOM functionality</em>. - * - * @see DomDoctype - * @see DomEntity - * @see DomPI - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomNotation - extends DomExtern - implements Notation -{ - - /** - * Constructs a Notation node associated with the specified document, - * with the specified descriptive data. Note that at least one of - * the PUBLIC and SYSTEM identifiers must be provided; unlike other - * external objects in XML, notations may have only a PUBLIC identifier. - * - * <p>This constructor should only be invoked by a DomDoctype object - * as part of its declareNotation functionality, or through a subclass - * which is similarly used in a "Sub-DOM" style layer. - * - * @param owner The document with which this notation is associated - * @param name Name of this notation - * @param publicId If non-null, provides the notation's PUBLIC identifier - * @param systemId If non-null, rovides the notation's SYSTEM identifier - */ - protected DomNotation(DomDocument owner, - String name, - String publicId, - String systemId) - { - super(NOTATION_NODE, owner, name, publicId, systemId); - makeReadonly(); - } - - /** - * The base URI of an external entity is its system ID. - * The base URI of an internal entity is the parent document's base URI. - * @since DOM Level 3 Core - */ - public String getBaseURI() - { - String systemId = getSystemId(); - return (systemId == null) ? owner.getBaseURI() : systemId; - } - -} - diff --git a/libjava/gnu/xml/dom/DomNsNode.java b/libjava/gnu/xml/dom/DomNsNode.java deleted file mode 100644 index 4dec5af21d7..00000000000 --- a/libjava/gnu/xml/dom/DomNsNode.java +++ /dev/null @@ -1,200 +0,0 @@ -/* DomNsNode.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import javax.xml.XMLConstants; -import org.w3c.dom.DOMException; - -/** - * <p> Abstract implemention of namespace support. This facilitates - * sharing code for attribute and element nodes. - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class DomNsNode - extends DomNode -{ - - private String name; - private String namespace; - private String prefix; - private String localName; - - /** - * Constructs a node associated with the specified document, and - * with the specified namespace information. - * - * @param owner The document with which this entity is associated - * @param namespaceURI Combined with the local part of the name, - * this identifies a type of element or attribute; may be null. - * If this is the empty string, it is reassigned as null so that - * applications only need to test that case. - * @param name Name of this node, which may include a prefix - */ - // package private - DomNsNode(short nodeType, DomDocument owner, String namespaceURI, String name) - { - super(nodeType, owner); - setNodeName(name); - setNamespaceURI(namespaceURI); - } - - /** - * <b>DOM L1</b> - * Returns the node's name, including any namespace prefix. - */ - public final String getNodeName() - { - return name; - } - - final void setNodeName(String name) - { - this.name = name.intern(); - int index = name.indexOf(':'); - if (index == -1) - { - prefix = null; - localName = this.name; - } - else - { - prefix = name.substring(0, index).intern(); - localName = name.substring(index + 1).intern(); - } - } - - /** - * <b>DOM L2</b> - * Returns the node's namespace URI - * <em>or null</em> if the node name is not namespace scoped. - */ - public final String getNamespaceURI() - { - return namespace; - } - - final void setNamespaceURI(String namespaceURI) - { - if ("".equals(namespaceURI)) - { - namespaceURI = null; - } - namespace = (namespaceURI == null) ? null : namespaceURI.intern(); - } - - /** - * <b>DOM L2</b> - * Returns any prefix part of the node's name (before any colon). - */ - public final String getPrefix() - { - return prefix; - } - - /** - * <b>DOM L2</b> - * Assigns the prefix part of the node's name (before any colon). - */ - public final void setPrefix(String prefix) - { - if (readonly) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - - if (prefix == null) - { - name = localName; - return; - } - else if (namespace == null) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "can't set prefix, node has no namespace URI", - this, 0); - } - - DomDocument.checkName(prefix, "1.1".equals(owner.getXmlVersion())); - if (prefix.indexOf (':') != -1) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "illegal prefix " + prefix, this, 0); - } - - if (XMLConstants.XML_NS_PREFIX.equals(prefix) - && !XMLConstants.XML_NS_URI.equals(namespace)) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xml namespace is always " + - XMLConstants.XML_NS_URI, this, 0); - } - - if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) - { - if (namespace != null || getNodeType() != ATTRIBUTE_NODE) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "xmlns attribute prefix is reserved", - this, 0); - } - } - else if (getNodeType () == ATTRIBUTE_NODE - && (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || - name.startsWith("xmlns:"))) - { - throw new DomDOMException(DOMException.NAMESPACE_ERR, - "namespace declarations can't change names", - this, 0); - } - - this.prefix = prefix.intern(); - } - - /** - * <b>DOM L2</b> - * Returns the local part of the node's name (after any colon). - */ - public final String getLocalName() - { - return localName; - } - -} - diff --git a/libjava/gnu/xml/dom/DomProcessingInstruction.java b/libjava/gnu/xml/dom/DomProcessingInstruction.java deleted file mode 100644 index 2c90967d00f..00000000000 --- a/libjava/gnu/xml/dom/DomProcessingInstruction.java +++ /dev/null @@ -1,147 +0,0 @@ -/* DomProcessingInstruction.java -- - Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.ProcessingInstruction; - -/** - * <p> "ProcessingInstruction" (PI) implementation. - * This is a non-core DOM class, supporting the "XML" feature. </p> - * - * <p> Unlike other DOM APIs in the "XML" feature, this one fully - * exposes the functionality it describes. So there is no reason - * inherent in DOM to avoid using this API, unless you want to rely - * on NOTATION declarations to associate meaning with your PIs; - * there is no vendor-neutal way to record those notations in DOM.</p> - * - * <p> Also of note is that PI support is part of SAX, so that XML - * systems using PIs can choose among multiple APIs. </p> - * - * @see DomNotation - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomProcessingInstruction - extends DomNode - implements ProcessingInstruction -{ - - private String target; - private String data; - - /** - * Constructs a ProcessingInstruction node associated with the - * specified document, with the specified data. - * - * <p>This constructor should only be invoked by a Document object as - * part of its createProcessingInstruction functionality, or through - * a subclass which is similarly used in a "Sub-DOM" style layer. - */ - protected DomProcessingInstruction(DomDocument owner, - String target, String data) - { - super(PROCESSING_INSTRUCTION_NODE, owner); - this.target = target; - this.data = data; - } - - /** - * <b>DOM L1</b> - * Returns the target of the processing instruction. - */ - public final String getTarget() - { - return target; - } - - /** - * <b>DOM L1</b> - * Returns the target of the processing instruction - * (same as getTarget). - */ - public final String getNodeName() - { - return target; - } - - /** - * <b>DOM L1</b> - * Returns the data associated with the processing instruction. - */ - public final String getData() - { - return data; - } - - /** - * <b>DOM L1</b> - * Returns the data associated with the processing instruction - * (same as getData). - */ - public final String getNodeValue() - { - return data; - } - - /** - * <b>DOM L1</b> - * Assigns the data associated with the processing instruction; - * same as setNodeValue. - */ - public final void setData(String data) - { - setNodeValue(data); - } - - /** - * <b>DOM L1</b> - * Assigns the data associated with the processing instruction. - */ - public final void setNodeValue(String data) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - this.data = data; - } - -} - diff --git a/libjava/gnu/xml/dom/DomText.java b/libjava/gnu/xml/dom/DomText.java deleted file mode 100644 index 3ca17dc9b87..00000000000 --- a/libjava/gnu/xml/dom/DomText.java +++ /dev/null @@ -1,220 +0,0 @@ -/* DomText.java -- - Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.DOMException; -import org.w3c.dom.Text; - -/** - * <p> "Text" implementation. </p> - * - * @author David Brownell - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomText - extends DomCharacterData - implements Text -{ - - // NOTE: deleted unused per-instance "isIgnorable" - // support to reclaim its space. - - /** - * Constructs a text node associated with the specified - * document and holding the specified data. - * - * <p>This constructor should only be invoked by a Document object - * as part of its createTextNode functionality, or through a subclass - * which is similarly used in a "Sub-DOM" style layer. - */ - protected DomText(DomDocument owner, String value) - { - super(TEXT_NODE, owner, value); - } - - protected DomText(DomDocument owner, char[] buf, int off, int len) - { - super(TEXT_NODE, owner, buf, off, len); - } - - // Used by DomCDATA - DomText(short nodeType, DomDocument owner, String value) - { - super(nodeType, owner, value); - } - - DomText(short nodeType, DomDocument owner, char[] buf, int off, int len) - { - super(nodeType, owner, buf, off, len); - } - - /** - * <b>DOM L1</b> - * Returns the string "#text". - */ - // can't be 'final' with CDATA subclassing - public String getNodeName() - { - return "#text"; - } - - /** - * <b>DOM L1</b> - * Splits this text node in two parts at the offset, returning - * the new text node (the sibling with the second part). - */ - public Text splitText(int offset) - { - if (isReadonly()) - { - throw new DomDOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR); - } - try - { - String text = getNodeValue(); - String before = text.substring(0, offset); - String after = text.substring(offset); - Text next; - - if (getNodeType() == TEXT_NODE) - { - next = owner.createTextNode(after); - } - else // CDATA_SECTION_NODE - { - next = owner.createCDATASection(after); - } - - if (this.next != null) - { - parent.insertBefore(next, this.next); - } - else - { - parent.appendChild(next); - } - setNodeValue(before); - return next; - - } - catch (IndexOutOfBoundsException x) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - } - - // DOM Level 3 - - public boolean isElementContentWhitespace() - { - if (parent != null) - { - DomDoctype doctype = (DomDoctype) owner.getDoctype(); - if (doctype != null) - { - DTDElementTypeInfo info = - doctype.getElementTypeInfo(parent.getNodeName()); - if (info != null) - { - if (info.model == null && info.model.indexOf("#PCDATA") != -1) - { - return false; - } - return getNodeValue().trim().length() == 0; - } - } - } - return false; - } - - public String getWholeText() - { - DomNode ref = this; - DomNode ctx; - for (ctx = previous; ctx != null && - (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE); - ctx = ctx.previous) - { - ref = ctx; - } - StringBuffer buf = new StringBuffer(ref.getNodeValue()); - for (ctx = ref.next; ctx != null && - (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE); - ctx = ctx.next) - { - buf.append(ctx.getNodeValue()); - } - return buf.toString (); - } - - public Text replaceWholeText(String content) - throws DOMException - { - boolean isEmpty = (content == null || content.length () == 0); - if (!isEmpty) - { - setNodeValue(content); - } - - DomNode ref = this; - DomNode ctx; - for (ctx = previous; ctx != null && - (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE); - ctx = ctx.previous) - { - ref = ctx; - } - ctx = ref.next; - if ((isEmpty || ref != this) && parent != null) - { - parent.removeChild(ref); - } - for (; ctx != null && - (ctx.nodeType == TEXT_NODE || ctx.nodeType == CDATA_SECTION_NODE); - ctx = ref) - { - ref = ctx.next; - if ((isEmpty || ctx != this) && parent != null) - { - parent.removeChild(ctx); - } - } - return (isEmpty) ? null : this; - } - -} diff --git a/libjava/gnu/xml/dom/DomXPathExpression.java b/libjava/gnu/xml/dom/DomXPathExpression.java deleted file mode 100644 index 25187520c0f..00000000000 --- a/libjava/gnu/xml/dom/DomXPathExpression.java +++ /dev/null @@ -1,147 +0,0 @@ -/* DomXPathExpression.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.xpath.XPathException; -import org.w3c.dom.xpath.XPathNSResolver; -import org.w3c.dom.xpath.XPathResult; -import gnu.xml.xpath.DocumentOrderComparator; - -/** - * An XPath expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomXPathExpression -implements org.w3c.dom.xpath.XPathExpression -{ - - final DomDocument doc; - final XPathExpression expression; - final XPathNSResolver resolver; - - DomXPathExpression(DomDocument doc, String expression, - XPathNSResolver resolver) - throws XPathException - { - this.doc = doc; - this.resolver = resolver; - - XPathFactory factory = XPathFactory.newInstance(); - XPath xpath = factory.newXPath(); - if (resolver != null) - { - xpath.setNamespaceContext(new DomNSResolverContext(resolver)); - } - try - { - this.expression = xpath.compile(expression); - } - catch (XPathExpressionException e) - { - throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, - e.getMessage ()); - } - } - - public Object evaluate(Node contextNode, short type, Object result) - throws XPathException, DOMException - { - try - { - QName typeName = null; - switch (type) - { - case XPathResult.BOOLEAN_TYPE: - typeName = XPathConstants.BOOLEAN; - break; - case XPathResult.NUMBER_TYPE: - typeName = XPathConstants.NUMBER; - break; - case XPathResult.STRING_TYPE: - typeName = XPathConstants.STRING; - break; - case XPathResult.ANY_UNORDERED_NODE_TYPE: - case XPathResult.FIRST_ORDERED_NODE_TYPE: - typeName = XPathConstants.NODE; - break; - case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: - case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - typeName = XPathConstants.NODESET; - break; - default: - throw new XPathException(XPathException.TYPE_ERR, null); - } - Object val = expression.evaluate(contextNode, typeName); - switch (type) - { - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - // Sort the nodes - List ns = new ArrayList((Collection) val); - Collections.sort(ns, new DocumentOrderComparator()); - val = ns; - } - return new DomXPathResult(val, type); - } - catch (javax.xml.xpath.XPathException e) - { - throw new XPathException(XPathException.TYPE_ERR, e.getMessage()); - } - } - - public String toString () - { - return getClass ().getName () + "[expression=" + expression + "]"; - } - -} diff --git a/libjava/gnu/xml/dom/DomXPathNSResolver.java b/libjava/gnu/xml/dom/DomXPathNSResolver.java deleted file mode 100644 index 96dfd97d46a..00000000000 --- a/libjava/gnu/xml/dom/DomXPathNSResolver.java +++ /dev/null @@ -1,64 +0,0 @@ -/* DomXPathNSResolver.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import org.w3c.dom.Node; -import org.w3c.dom.xpath.XPathNSResolver; - -/** - * Generic XPath namespace resolver using a DOM Node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomXPathNSResolver -implements XPathNSResolver -{ - - Node node; - - DomXPathNSResolver (Node node) - { - this.node = node; - } - - public String lookupNamespaceURI (String prefix) - { - return node.lookupNamespaceURI (prefix); - } - -} diff --git a/libjava/gnu/xml/dom/DomXPathResult.java b/libjava/gnu/xml/dom/DomXPathResult.java deleted file mode 100644 index bed249624f9..00000000000 --- a/libjava/gnu/xml/dom/DomXPathResult.java +++ /dev/null @@ -1,233 +0,0 @@ -/* DomXPathResult.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.util.Collection; -import java.util.Iterator; -import org.w3c.dom.Node; -import org.w3c.dom.xpath.XPathException; -import org.w3c.dom.xpath.XPathResult; - -/** - * An XPath result object. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomXPathResult -implements XPathResult -{ - - final Object value; - final short type; - Iterator iterator; - - DomXPathResult (Object value, short requestedType) - { - this.value = value; - if (value instanceof Boolean) - { - type = XPathResult.BOOLEAN_TYPE; - } - else if (value instanceof Double) - { - type = XPathResult.NUMBER_TYPE; - } - else if (value instanceof String) - { - type = XPathResult.STRING_TYPE; - } - else if (value instanceof Collection) - { - Collection ns = (Collection) value; - switch (requestedType) - { - case XPathResult.ANY_TYPE: - case XPathResult.ANY_UNORDERED_NODE_TYPE: - type = (ns.size () == 1) ? XPathResult.FIRST_ORDERED_NODE_TYPE : - XPathResult.ORDERED_NODE_ITERATOR_TYPE; - break; - default: - type = requestedType; - } - iterator = ns.iterator (); - } - else - { - throw new IllegalArgumentException (); - } - } - - public boolean getBooleanValue() - { - if (type == XPathResult.BOOLEAN_TYPE) - { - return ((Boolean) value).booleanValue (); - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public boolean getInvalidIteratorState() - { - return iterator == null; - } - - public double getNumberValue() - { - if (type == XPathResult.NUMBER_TYPE) - { - return ((Double) value).doubleValue (); - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public short getResultType() - { - return type; - } - - public Node getSingleNodeValue() - { - switch (type) - { - case XPathResult.FIRST_ORDERED_NODE_TYPE: - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: - case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: - Collection ns = (Collection) value; - if (ns.isEmpty ()) - { - return null; - } - else - { - return (Node) ns.iterator ().next (); - } - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public int getSnapshotLength() - { - switch (type) - { - case XPathResult.FIRST_ORDERED_NODE_TYPE: - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: - case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: - return ((Collection) value).size (); - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public String getStringValue() - { - if (type == XPathResult.STRING_TYPE) - { - return (String) value; - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public Node iterateNext() - { - if (iterator != null) - { - if (iterator.hasNext ()) - { - return (Node) iterator.next (); - } - else - { - iterator = null; - return null; - } - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public Node snapshotItem(int index) - { - switch (type) - { - case XPathResult.FIRST_ORDERED_NODE_TYPE: - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: - case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: - Collection ns = (Collection) value; - Node[] nodes = new Node[ns.size ()]; - ns.toArray (nodes); - return nodes[index]; - } - throw new XPathException (XPathException.TYPE_ERR, value.toString ()); - } - - public String toString () - { - return getClass ().getName () + "[type=" + typeName (type) + ",value=" + - value + ']'; - } - - private String typeName (short type) - { - switch (type) - { - case XPathResult.BOOLEAN_TYPE: - return "BOOLEAN_TYPE"; - case XPathResult.NUMBER_TYPE: - return "NUMBER_TYPE"; - case XPathResult.STRING_TYPE: - return "STRING_TYPE"; - case XPathResult.FIRST_ORDERED_NODE_TYPE: - return "FIRST_ORDERED_NODE_TYPE"; - case XPathResult.ORDERED_NODE_ITERATOR_TYPE: - return "ORDERED_NODE_ITERATOR_TYPE"; - case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: - return "ORDERED_NODE_SNAPSHOT_TYPE"; - case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: - return "UNORDERED_NODE_ITERATOR_TYPE"; - case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: - return "UNORDERED_NODE_SNAPSHOT_TYPE"; - default: - return "(unknown)"; - } - } - -} diff --git a/libjava/gnu/xml/dom/ImplementationList.java b/libjava/gnu/xml/dom/ImplementationList.java deleted file mode 100644 index 8c0f4491610..00000000000 --- a/libjava/gnu/xml/dom/ImplementationList.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ImplementationList.java -- - Copyright (C) 2004 Free Software Foundation, Inc.. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.xml.dom; - -import java.util.List; - -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.DOMImplementationList; - -/** - * Implementation list for GNU JAXP. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class ImplementationList - implements DOMImplementationList -{ - - private List list; - - ImplementationList(List list) - { - this.list = list; - } - - public int getLength() - { - return list.size(); - } - - public DOMImplementation item(int index) - { - return (DOMImplementation) list.get(index); - } - -} diff --git a/libjava/gnu/xml/dom/ImplementationSource.java b/libjava/gnu/xml/dom/ImplementationSource.java deleted file mode 100644 index 913079cd0c3..00000000000 --- a/libjava/gnu/xml/dom/ImplementationSource.java +++ /dev/null @@ -1,167 +0,0 @@ -/* ImplementationSource.java -- - Copyright (C) 2004 Free Software Foundation, Inc.. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ -package gnu.xml.dom; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.DOMImplementationList; -import org.w3c.dom.DOMImplementationSource; - -/** - * Implementation source for GNU JAXP. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class ImplementationSource - implements DOMImplementationSource -{ - - private static final String DIGITS = "1234567890"; - - /* - * GNU DOM implementations. - */ - private static final DOMImplementation[] implementations; - - static - { - List acc = new ArrayList(); - acc.add(new gnu.xml.dom.DomImpl()); - try - { - Class t = Class.forName("gnu.xml.libxmlj.dom.GnomeDocumentBuilder"); - acc.add(t.newInstance()); - } - catch (Exception e) - { - // libxmlj not available - } - catch (UnsatisfiedLinkError e) - { - // libxmlj not available - } - implementations = new DOMImplementation[acc.size()]; - acc.toArray(implementations); - } - - public DOMImplementation getDOMImplementation(String features) - { - List available = getImplementations(features); - if (available.isEmpty()) - { - return null; - } - return (DOMImplementation) available.get(0); - } - - public DOMImplementationList getDOMImplementationList(String features) - { - List available = getImplementations(features); - return new ImplementationList(available); - } - - /** - * Returns a list of the implementations that support the specified - * features. - */ - private final List getImplementations(String features) - { - List available = new ArrayList(Arrays.asList(implementations)); - for (Iterator i = parseFeatures(features).iterator(); i.hasNext(); ) - { - String feature = (String) i.next(); - String version = null; - int si = feature.indexOf(' '); - if (si != -1) - { - version = feature.substring(si + 1); - feature = feature.substring(0, si); - } - for (Iterator j = available.iterator(); j.hasNext(); ) - { - DOMImplementation impl = (DOMImplementation) j.next(); - if (!impl.hasFeature(feature, version)) - { - j.remove(); - } - } - } - return available; - } - - /** - * Parses the feature list into feature tokens. - */ - final List parseFeatures(String features) - { - List list = new ArrayList(); - int pos = 0, start = 0; - int len = features.length(); - for (; pos < len; pos++) - { - char c = features.charAt(pos); - if (c == ' ') - { - if (pos + 1 < len && - DIGITS.indexOf(features.charAt(pos + 1)) == -1) - { - list.add(getFeature(features, start, pos)); - start = pos + 1; - } - } - } - if (pos > start) - { - list.add(getFeature(features, start, len)); - } - return list; - } - - final String getFeature(String features, int start, int end) - { - if (features.length() > 0 && features.charAt(start) == '+') - { - return features.substring(start + 1, end); - } - return features.substring(start, end); - } - -} diff --git a/libjava/gnu/xml/dom/JAXPFactory.java b/libjava/gnu/xml/dom/JAXPFactory.java deleted file mode 100644 index 8f481fad643..00000000000 --- a/libjava/gnu/xml/dom/JAXPFactory.java +++ /dev/null @@ -1,286 +0,0 @@ -/* JAXPFactory.java -- - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom; - -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.DOMImplementation; - -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParserFactory; - - -/** - * DOM bootstrapping API, for use with JAXP. - * - * @see Consumer - * - * @author David Brownell - */ -public final class JAXPFactory - extends DocumentBuilderFactory -{ - - private static final String PROPERTY = "http://xml.org/sax/properties/"; - private static final String FEATURE = "http://xml.org/sax/features/"; - - private SAXParserFactory pf; - - /** - * Default constructor. - */ - public JAXPFactory() - { - } - - /** - * Constructs a JAXP document builder which uses the default - * JAXP SAX2 parser and the DOM implementation in this package. - */ - public DocumentBuilder newDocumentBuilder() - throws ParserConfigurationException - { - if (pf == null) - { - // Force use of AElfred2 since not all JAXP parsers - // conform very well to the SAX2 API spec ... - pf = new gnu.xml.aelfred2.JAXPFactory(); - // pf = SAXParserFactory.newInstance (); - } - - // JAXP default: false - pf.setValidating(isValidating()); - - // FIXME: this namespace setup may cause errors in some - // conformant SAX2 parsers, which we CAN patch up by - // splicing a "NSFilter" stage up front ... - - // JAXP default: false - pf.setNamespaceAware(isNamespaceAware()); - - try - { - // undo rude "namespace-prefixes=false" default - pf.setFeature(FEATURE + "namespace-prefixes", true); - - return new JAXPBuilder(pf.newSAXParser().getXMLReader(), this); - } - catch (SAXException e) - { - String msg = "can't create JAXP DocumentBuilder: " + e.getMessage(); - throw new ParserConfigurationException(msg); - } - } - - /** There seems to be no useful specification for attribute names */ - public void setAttribute(String name, Object value) - throws IllegalArgumentException - { - if ("http://java.sun.com/xml/jaxp/properties/schemaLanguage".equals(name)) - { - // TODO - } - else - { - throw new IllegalArgumentException(name); - } - } - - /** There seems to be no useful specification for attribute names */ - public Object getAttribute(String name) - throws IllegalArgumentException - { - throw new IllegalArgumentException(name); - } - - static final class JAXPBuilder - extends DocumentBuilder - implements ErrorHandler - { - - private Consumer consumer; - private XMLReader producer; - private DomImpl impl; - - JAXPBuilder(XMLReader parser, JAXPFactory factory) - throws ParserConfigurationException - { - impl = new DomImpl(); - - // set up consumer side - try - { - consumer = new Consumer(); - } - catch (SAXException e) - { - throw new ParserConfigurationException(e.getMessage()); - } - - // JAXP defaults: true, noise nodes are good (bleech) - consumer.setHidingReferences(factory.isExpandEntityReferences()); - consumer.setHidingComments(factory.isIgnoringComments()); - consumer.setHidingWhitespace(factory.isIgnoringElementContentWhitespace()); - consumer.setHidingCDATA(factory.isCoalescing()); - - // set up producer side - producer = parser; - producer.setContentHandler(consumer.getContentHandler()); - producer.setDTDHandler(consumer.getDTDHandler()); - - try - { - String id; - - // if validating, report validity errors, and default - // to treating them as fatal - if (factory.isValidating ()) - { - producer.setFeature(FEATURE + "validation", true); - producer.setErrorHandler(this); - } - - // always save prefix info, maybe do namespace processing - producer.setFeature(FEATURE + "namespace-prefixes", true); - producer.setFeature(FEATURE + "namespaces", - factory.isNamespaceAware()); - - // set important handlers - id = PROPERTY + "lexical-handler"; - producer.setProperty(id, consumer.getProperty(id)); - - id = PROPERTY + "declaration-handler"; - producer.setProperty(id, consumer.getProperty(id)); - - } - catch (SAXException e) - { - throw new ParserConfigurationException(e.getMessage()); - } - } - - public Document parse(InputSource source) - throws SAXException, IOException - { - producer.parse(source); - Document doc = consumer.getDocument(); - // TODO inputEncoding - doc.setDocumentURI(source.getSystemId()); - return doc; - } - - public boolean isNamespaceAware() - { - try - { - return producer.getFeature(FEATURE + "namespaces"); - } - catch (SAXException e) - { - // "can't happen" - throw new RuntimeException(e.getMessage()); - } - } - - public boolean isValidating() - { - try - { - return producer.getFeature(FEATURE + "validation"); - } - catch (SAXException e) - { - // "can't happen" - throw new RuntimeException(e.getMessage()); - } - } - - public void setEntityResolver(EntityResolver resolver) - { - producer.setEntityResolver(resolver); - } - - public void setErrorHandler(ErrorHandler handler) - { - producer.setErrorHandler(handler); - consumer.setErrorHandler(handler); - } - - public DOMImplementation getDOMImplementation() - { - return impl; - } - - public Document newDocument() - { - return new DomDocument(); - } - - // implementation of error handler that's used when validating - public void fatalError(SAXParseException e) - throws SAXException - { - throw e; - } - - public void error(SAXParseException e) - throws SAXException - { - throw e; - } - - public void warning(SAXParseException e) - throws SAXException - { - /* ignore */ - } - - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLAnchorElement.java b/libjava/gnu/xml/dom/html2/DomHTMLAnchorElement.java deleted file mode 100644 index 5da91330604..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLAnchorElement.java +++ /dev/null @@ -1,189 +0,0 @@ -/* DomHTMLAnchorElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLAnchorElement; - -/** - * An HTML 'A' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLAnchorElement - extends DomHTMLElement - implements HTMLAnchorElement -{ - - protected DomHTMLAnchorElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public String getCharset() - { - return getHTMLAttribute("charset"); - } - - public void setCharset(String charset) - { - setHTMLAttribute("charset", charset); - } - - public String getCoords() - { - return getHTMLAttribute("coords"); - } - - public void setCoords(String coords) - { - setHTMLAttribute("coords", coords); - } - - public String getHref() - { - return getHTMLAttribute("href"); - } - - public void setHref(String href) - { - setHTMLAttribute("href", href); - } - - public String getHreflang() - { - return getHTMLAttribute("hreflang"); - } - - public void setHreflang(String hreflang) - { - setHTMLAttribute("hreflang", hreflang); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getRel() - { - return getHTMLAttribute("rel"); - } - - public void setRel(String rel) - { - setHTMLAttribute("rel", rel); - } - - public String getRev() - { - return getHTMLAttribute("rev"); - } - - public void setRev(String rev) - { - setHTMLAttribute("rev", rev); - } - - public String getShape() - { - return getHTMLAttribute("shape"); - } - - public void setShape(String shape) - { - setHTMLAttribute("shape", shape); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getTarget() - { - return getHTMLAttribute("target"); - } - - public void setTarget(String target) - { - setHTMLAttribute("target", target); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - - public void blur() - { - dispatchUIEvent("blur"); - } - - public void focus() - { - dispatchUIEvent("focus"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLAppletElement.java b/libjava/gnu/xml/dom/html2/DomHTMLAppletElement.java deleted file mode 100644 index 8ec4d3c83bb..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLAppletElement.java +++ /dev/null @@ -1,169 +0,0 @@ -/* DomHTMLAppletElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLAppletElement; - -/** - * An HTML 'APPLET' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLAppletElement - extends DomHTMLElement - implements HTMLAppletElement -{ - - protected DomHTMLAppletElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getAlt() - { - return getHTMLAttribute("alt"); - } - - public void setAlt(String alt) - { - setHTMLAttribute("alt", alt); - } - - public String getArchive() - { - return getHTMLAttribute("archive"); - } - - public void setArchive(String archive) - { - setHTMLAttribute("archive", archive); - } - - public String getCode() - { - return getHTMLAttribute("code"); - } - - public void setCode(String code) - { - setHTMLAttribute("code", code); - } - - public String getCodeBase() - { - return getHTMLAttribute("codebase"); - } - - public void setCodeBase(String codeBase) - { - setHTMLAttribute("codebase", codeBase); - } - - public String getHeight() - { - return getHTMLAttribute("height"); - } - - public void setHeight(String height) - { - setHTMLAttribute("height", height); - } - - public int getHspace() - { - return getIntHTMLAttribute("hspace"); - } - - public void setHspace(int hspace) - { - setIntHTMLAttribute("hspace", hspace); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getObject() - { - return getHTMLAttribute("object"); - } - - public void setObject(String object) - { - setHTMLAttribute("object", object); - } - - public int getVspace() - { - return getIntHTMLAttribute("vspace"); - } - - public void setVspace(int vspace) - { - setIntHTMLAttribute("vspace", vspace); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLAreaElement.java b/libjava/gnu/xml/dom/html2/DomHTMLAreaElement.java deleted file mode 100644 index d7eed07dd1f..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLAreaElement.java +++ /dev/null @@ -1,139 +0,0 @@ -/* DomHTMLAreaElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLAreaElement; - -/** - * An HTML 'AREA' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLAreaElement - extends DomHTMLElement - implements HTMLAreaElement -{ - - protected DomHTMLAreaElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public String getAlt() - { - return getHTMLAttribute("alt"); - } - - public void setAlt(String alt) - { - setHTMLAttribute("alt", alt); - } - - public String getCoords() - { - return getHTMLAttribute("coords"); - } - - public void setCoords(String coords) - { - setHTMLAttribute("coords", coords); - } - - public String getHref() - { - return getHTMLAttribute("href"); - } - - public void setHref(String href) - { - setHTMLAttribute("href", href); - } - - public boolean getNoHref() - { - return getBooleanHTMLAttribute("nohref"); - } - - public void setNoHref(boolean nohref) - { - setBooleanHTMLAttribute("nohref", nohref); - } - - public String getShape() - { - return getHTMLAttribute("shape"); - } - - public void setShape(String shape) - { - setHTMLAttribute("shape", shape); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getTarget() - { - return getHTMLAttribute("target"); - } - - public void setTarget(String target) - { - setHTMLAttribute("target", target); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLBRElement.java b/libjava/gnu/xml/dom/html2/DomHTMLBRElement.java deleted file mode 100644 index 673699d527a..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLBRElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLBRElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLBRElement; - -/** - * An HTML 'BR' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLBRElement - extends DomHTMLElement - implements HTMLBRElement -{ - - protected DomHTMLBRElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getClear() - { - return getHTMLAttribute("clear"); - } - - public void setClear(String clear) - { - setHTMLAttribute("clear", clear); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLBaseElement.java b/libjava/gnu/xml/dom/html2/DomHTMLBaseElement.java deleted file mode 100644 index ddc8053079f..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLBaseElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLBaseElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLBaseElement; - -/** - * An HTML 'BASE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLBaseElement - extends DomHTMLElement - implements HTMLBaseElement -{ - - protected DomHTMLBaseElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getHref() - { - return getHTMLAttribute("href"); - } - - public void setHref(String href) - { - setHTMLAttribute("href", href); - } - - public String getTarget() - { - return getHTMLAttribute("target"); - } - - public void setTarget(String target) - { - setHTMLAttribute("target", target); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLBaseFontElement.java b/libjava/gnu/xml/dom/html2/DomHTMLBaseFontElement.java deleted file mode 100644 index 73172d3bf11..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLBaseFontElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DomHTMLBaseFontElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLBaseFontElement; - -/** - * An HTML 'BASEFONT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLBaseFontElement - extends DomHTMLElement - implements HTMLBaseFontElement -{ - - protected DomHTMLBaseFontElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getColor() - { - return getHTMLAttribute("color"); - } - - public void setColor(String color) - { - setHTMLAttribute("color", color); - } - - public String getFace() - { - return getHTMLAttribute("face"); - } - - public void setFace(String face) - { - setHTMLAttribute("face", face); - } - - public int getSize() - { - return getIntHTMLAttribute("size"); - } - - public void setSize(int size) - { - setIntHTMLAttribute("size", size); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLBodyElement.java b/libjava/gnu/xml/dom/html2/DomHTMLBodyElement.java deleted file mode 100644 index 44fbcf23cc5..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLBodyElement.java +++ /dev/null @@ -1,119 +0,0 @@ -/* DomHTMLBodyElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLBodyElement; - -/** - * An HTML 'BODY' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLBodyElement - extends DomHTMLElement - implements HTMLBodyElement -{ - - protected DomHTMLBodyElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getALink() - { - return getHTMLAttribute("alink"); - } - - public void setALink(String alink) - { - setHTMLAttribute("alink", alink); - } - - public String getBackground() - { - return getHTMLAttribute("background"); - } - - public void setBackground(String background) - { - setHTMLAttribute("background", background); - } - - public String getBgColor() - { - return getHTMLAttribute("bgcolor"); - } - - public void setBgColor(String bgcolor) - { - setHTMLAttribute("bgcolor", bgcolor); - } - - public String getLink() - { - return getHTMLAttribute("link"); - } - - public void setLink(String link) - { - setHTMLAttribute("link", link); - } - - public String getText() - { - return getHTMLAttribute("text"); - } - - public void setText(String text) - { - setHTMLAttribute("text", text); - } - - public String getVLink() - { - return getHTMLAttribute("vlink"); - } - - public void setVLink(String vlink) - { - setHTMLAttribute("vlink", vlink); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLButtonElement.java b/libjava/gnu/xml/dom/html2/DomHTMLButtonElement.java deleted file mode 100644 index 5aff5f8c1a9..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLButtonElement.java +++ /dev/null @@ -1,121 +0,0 @@ -/* DomHTMLButtonElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.Node; -import org.w3c.dom.html2.HTMLButtonElement; -import org.w3c.dom.html2.HTMLFormElement; - -/** - * An HTML 'BUTTON' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLButtonElement - extends DomHTMLElement - implements HTMLButtonElement -{ - - protected DomHTMLButtonElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public String getValue() - { - return getHTMLAttribute("value"); - } - - public void setValue(String value) - { - setHTMLAttribute("value", value); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLCollection.java b/libjava/gnu/xml/dom/html2/DomHTMLCollection.java deleted file mode 100644 index 05dc99a271b..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLCollection.java +++ /dev/null @@ -1,218 +0,0 @@ -/* DomHTMLCollection.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import gnu.xml.dom.DomElement; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import org.w3c.dom.DOMException; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLOptionsCollection; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; - -/** - * An HTML element collection. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DomHTMLCollection - implements HTMLCollection, HTMLOptionsCollection, NodeList, NodeFilter -{ - - final DomHTMLDocument doc; - final Node root; - List nodeNames; - List attributeNames; - List results; - - DomHTMLCollection(DomHTMLDocument doc, Node root) - { - this.doc = doc; - this.root = root; - } - - // -- Node name and attribute filtering -- - - void addNodeName(String name) - { - if (nodeNames == null) - { - nodeNames = new LinkedList(); - } - nodeNames.add(name); - } - - void addAttributeName(String name) - { - if (attributeNames == null) - { - attributeNames = new LinkedList(); - } - attributeNames.add(name); - } - - public short acceptNode(Node n) - { - if (n.getNodeType() != Node.ELEMENT_NODE) - { - return NodeFilter.FILTER_SKIP; - } - if (nodeNames != null && !acceptName(n.getLocalName())) - { - return NodeFilter.FILTER_SKIP; - } - if (attributeNames != null && !acceptAttributes(n.getAttributes())) - { - return NodeFilter.FILTER_SKIP; - } - return NodeFilter.FILTER_ACCEPT; - } - - private boolean acceptName(String name) - { - for (Iterator i = nodeNames.iterator(); i.hasNext(); ) - { - String nodeName = (String) i.next(); - if (nodeName.equalsIgnoreCase(name)) - { - return true; - } - } - return false; - } - - private boolean acceptAttributes(NamedNodeMap attrs) - { - for (Iterator i = attributeNames.iterator(); i.hasNext(); ) - { - String attributeName = (String) i.next(); - Node attr = getNamedItem(attrs, attributeName); - if (attr != null) - { - // Check that attribute has a non-null value - String nodeValue = attr.getNodeValue(); - if (nodeValue != null && nodeValue.length() > 0) - { - return true; - } - } - } - return false; - } - - /** - * Case-insensitive version of getNamedItem. - */ - private Node getNamedItem(NamedNodeMap attrs, String name) - { - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String attrName = attr.getLocalName(); - if (name.equalsIgnoreCase(attrName)) - { - return attr; - } - } - return null; - } - - // -- Perform query -- - - void evaluate() - { - NodeIterator i = doc.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, - this, true); - results = new ArrayList(); - for (Node node = i.nextNode(); node != null; node = i.nextNode()) - { - results.add(node); - } - } - - // -- HTMLCollection/NodeList interface -- - - public int getLength() - { - return results.size(); - } - - public void setLength(int length) - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - - public Node item(int index) - { - return (Node) results.get(index); - } - - public Node namedItem(String name) - { - boolean xhtml = false; // FIXME detect XHTML document - for (Iterator i = results.iterator(); i.hasNext(); ) - { - Node node = (Node) i.next(); - NamedNodeMap attrs = node.getAttributes(); - Node attr = getNamedItem(attrs, "id"); - if (name.equals(attr.getTextContent())) - { - return node; - } - if (!xhtml) - { - attr = getNamedItem(attrs, "name"); - if (name.equals(attr.getTextContent())) - { - return node; - } - } - } - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLDListElement.java b/libjava/gnu/xml/dom/html2/DomHTMLDListElement.java deleted file mode 100644 index 2b9dbf23623..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLDListElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLDListElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLDListElement; - -/** - * An HTML 'DL' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLDListElement - extends DomHTMLElement - implements HTMLDListElement -{ - - protected DomHTMLDListElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getCompact() - { - return getBooleanHTMLAttribute("compact"); - } - - public void setCompact(boolean compact) - { - setBooleanHTMLAttribute("compact", compact); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLDirectoryElement.java b/libjava/gnu/xml/dom/html2/DomHTMLDirectoryElement.java deleted file mode 100644 index 26af97e781b..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLDirectoryElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLDirectoryElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLDirectoryElement; - -/** - * An HTML 'DIR' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLDirectoryElement - extends DomHTMLElement - implements HTMLDirectoryElement -{ - - protected DomHTMLDirectoryElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getCompact() - { - return getBooleanHTMLAttribute("compact"); - } - - public void setCompact(boolean compact) - { - setBooleanHTMLAttribute("compact", compact); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLDivElement.java b/libjava/gnu/xml/dom/html2/DomHTMLDivElement.java deleted file mode 100644 index 462069dcf1a..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLDivElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLDivElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLDivElement; - -/** - * An HTML 'DIV' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLDivElement - extends DomHTMLElement - implements HTMLDivElement -{ - - protected DomHTMLDivElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLDocument.java b/libjava/gnu/xml/dom/html2/DomHTMLDocument.java deleted file mode 100644 index 10ee9e74767..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLDocument.java +++ /dev/null @@ -1,425 +0,0 @@ -/* DomHTMLDocument.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDocument; -import gnu.xml.dom.DomDOMException; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLDocument; -import org.w3c.dom.html2.HTMLElement; - -/** - * An HTML document. - * This is the factory object used to create HTML elements. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLDocument - extends DomDocument - implements HTMLDocument -{ - - private static final Class[] ELEMENT_PT = new Class[] { - DomHTMLDocument.class, - String.class, - String.class - }; - - private static Map ELEMENT_CLASSES; - static - { - Map map = new HashMap(); - map.put("a", DomHTMLAnchorElement.class); - map.put("applet", DomHTMLAppletElement.class); - map.put("area", DomHTMLAreaElement.class); - map.put("base", DomHTMLBaseElement.class); - map.put("basefont", DomHTMLBaseFontElement.class); - map.put("body", DomHTMLBodyElement.class); - map.put("br", DomHTMLBRElement.class); - map.put("button", DomHTMLButtonElement.class); - map.put("dir", DomHTMLDirectoryElement.class); - map.put("div", DomHTMLDivElement.class); - map.put("dlist", DomHTMLDListElement.class); - map.put("fieldset", DomHTMLFieldSetElement.class); - map.put("font", DomHTMLFontElement.class); - map.put("form", DomHTMLFormElement.class); - map.put("frame", DomHTMLFrameElement.class); - map.put("frameset", DomHTMLFrameSetElement.class); - map.put("head", DomHTMLHeadElement.class); - map.put("h1", DomHTMLHeadingElement.class); - map.put("h2", DomHTMLHeadingElement.class); - map.put("h3", DomHTMLHeadingElement.class); - map.put("h4", DomHTMLHeadingElement.class); - map.put("h5", DomHTMLHeadingElement.class); - map.put("h6", DomHTMLHeadingElement.class); - map.put("html", DomHTMLHtmlElement.class); - map.put("iframe", DomHTMLIFrameElement.class); - map.put("img", DomHTMLImageElement.class); - map.put("input", DomHTMLInputElement.class); - map.put("isindex", DomHTMLIsIndexElement.class); - map.put("label", DomHTMLLabelElement.class); - map.put("legend", DomHTMLLegendElement.class); - map.put("li", DomHTMLLIElement.class); - map.put("link", DomHTMLLinkElement.class); - map.put("map", DomHTMLMapElement.class); - map.put("menu", DomHTMLMenuElement.class); - map.put("meta", DomHTMLMetaElement.class); - map.put("ins", DomHTMLModElement.class); - map.put("del", DomHTMLModElement.class); - map.put("object", DomHTMLObjectElement.class); - map.put("ol", DomHTMLOListElement.class); - map.put("optgroup", DomHTMLOptGroupElement.class); - map.put("option", DomHTMLOptionElement.class); - map.put("p", DomHTMLParagraphElement.class); - map.put("param", DomHTMLParamElement.class); - map.put("pre", DomHTMLPreElement.class); - map.put("q", DomHTMLQuoteElement.class); - map.put("blockquote", DomHTMLQuoteElement.class); - map.put("script", DomHTMLScriptElement.class); - map.put("select", DomHTMLSelectElement.class); - map.put("style", DomHTMLStyleElement.class); - map.put("caption", DomHTMLTableCaptionElement.class); - map.put("th", DomHTMLTableCellElement.class); - map.put("td", DomHTMLTableCellElement.class); - map.put("col", DomHTMLTableColElement.class); - map.put("colgroup", DomHTMLTableColElement.class); - map.put("table", DomHTMLTableElement.class); - map.put("tr", DomHTMLTableRowElement.class); - map.put("thead", DomHTMLTableSectionElement.class); - map.put("tfoot", DomHTMLTableSectionElement.class); - map.put("tbody", DomHTMLTableSectionElement.class); - map.put("textarea", DomHTMLTextAreaElement.class); - map.put("title", DomHTMLTitleElement.class); - map.put("ul", DomHTMLUListElement.class); - ELEMENT_CLASSES = Collections.unmodifiableMap(map); - } - - private static Set HTML_NS_URIS; - static - { - Set set = new HashSet(); - set.add("http://www.w3.org/TR/html4/strict"); - set.add("http://www.w3.org/TR/html4/loose"); - set.add("http://www.w3.org/TR/html4/frameset"); - set.add("http://www.w3.org/1999/xhtml"); - set.add("http://www.w3.org/TR/xhtml1/strict"); - set.add("http://www.w3.org/TR/xhtml1/loose"); - set.add("http://www.w3.org/TR/xhtml1/frameset"); - HTML_NS_URIS = Collections.unmodifiableSet(set); - } - - /** - * Convenience constructor. - */ - public DomHTMLDocument() - { - this(new DomHTMLImpl()); - } - - /** - * Constructor. - * This is called by the DOMImplementation. - */ - public DomHTMLDocument(DomHTMLImpl impl) - { - super(impl); - } - - private Node getChildNodeByName(Node parent, String name) - { - for (Node ctx = parent.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (name.equalsIgnoreCase(ctx.getNodeName())) - { - return ctx; - } - } - return null; - } - - public String getTitle() - { - Node html = getDocumentElement(); - if (html != null) - { - Node head = getChildNodeByName(html, "head"); - if (head != null) - { - Node title = getChildNodeByName(head, "title"); - if (title != null) - { - return title.getTextContent(); - } - } - } - return null; - } - - public void setTitle(String title) - { - Node html = getDocumentElement(); - if (html == null) - { - html = createElement("html"); - appendChild(html); - } - Node head = getChildNodeByName(html, "head"); - if (head == null) - { - head = createElement("head"); - Node first = html.getFirstChild(); - if (first != null) - { - html.insertBefore(first, head); - } - else - { - html.appendChild(head); - } - } - Node titleNode = getChildNodeByName(head, "title"); - if (titleNode == null) - { - titleNode = createElement("title"); - Node first = head.getFirstChild(); - if (first != null) - { - head.insertBefore(first, titleNode); - } - else - { - head.appendChild(titleNode); - } - } - titleNode.setTextContent(title); - } - - public String getReferrer() - { - // TODO getReferrer - return null; - } - - public String getDomain() - { - try - { - URL url = new URL(getDocumentURI()); - return url.getHost(); - } - catch (MalformedURLException e) - { - return null; - } - } - - public String getURL() - { - return getDocumentURI(); - } - - public HTMLElement getBody() - { - Node html = getDocumentElement(); - if (html != null) - { - Node body = getChildNodeByName(html, "body"); - if (body == null) - { - body = getChildNodeByName(html, "frameset"); - } - return (HTMLElement) body; - } - return null; - } - - public void setBody(HTMLElement body) - { - Node html = getDocumentElement(); - if (html == null) - { - html = createElement("html"); - appendChild(html); - } - Node ref = getBody(); - if (ref == null) - { - html.appendChild(body); - } - else - { - html.replaceChild(body, ref); - } - } - - public HTMLCollection getImages() - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName("img"); - ret.evaluate(); - return ret; - } - - public HTMLCollection getApplets() - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName("object"); - ret.addNodeName("applet"); - ret.evaluate(); - return ret; - } - - public HTMLCollection getLinks() - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName("area"); - ret.addNodeName("a"); - ret.evaluate(); - return ret; - } - - public HTMLCollection getForms() - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName("form"); - ret.evaluate(); - return ret; - } - - public HTMLCollection getAnchors() - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName("a"); - ret.addAttributeName("name"); - ret.evaluate(); - return ret; - } - - public String getCookie() - { - // TODO getCookie - return null; - } - - public void setCookie(String cookie) - { - // TODO setCookie - } - - public void open() - { - // TODO open - } - - public void close() - { - // TODO close - } - - public void write(String text) - { - // TODO write - } - - public void writeln(String text) - { - // TODO write - } - - public NodeList getElementsByName(String name) - { - DomHTMLCollection ret = new DomHTMLCollection(this, this); - ret.addNodeName(name); - ret.evaluate(); - return ret; - // TODO xhtml: return only form controls (?) - } - - public Element createElement(String tagName) - { - return createElementNS(null, tagName); - } - - public Element createElementNS(String uri, String qName) - { - /* If a non-HTML element, use the default implementation. */ - if (uri != null && !HTML_NS_URIS.contains(uri)) - { - return super.createElementNS(uri, qName); - } - String localName = qName.toLowerCase(); - int ci = qName.indexOf(':'); - if (ci != -1) - { - localName = qName.substring(ci + 1); - } - Class t = (Class) ELEMENT_CLASSES.get(localName); - /* If a non-HTML element, use the default implementation. */ - if (t == null) - { - return super.createElementNS(uri, qName); - } - try - { - Constructor c = t.getDeclaredConstructor(ELEMENT_PT); - Object[] args = new Object[] { this, uri, qName }; - return (Element) c.newInstance(args); - } - catch (Exception e) - { - DOMException e2 = new DomDOMException(DOMException.TYPE_MISMATCH_ERR); - e2.initCause(e); - throw e2; - } - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLElement.java b/libjava/gnu/xml/dom/html2/DomHTMLElement.java deleted file mode 100644 index 844ffefe49c..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLElement.java +++ /dev/null @@ -1,269 +0,0 @@ -/* DomHTMLElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import gnu.xml.dom.DomElement; -import gnu.xml.dom.DomEvent; -import org.w3c.dom.DOMException; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.events.UIEvent; -import org.w3c.dom.html2.HTMLElement; - -/** - * Abstract implementation of an HTML element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class DomHTMLElement - extends DomElement - implements HTMLElement -{ - - protected DomHTMLElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - /** - * Returns the value of the specified attribute. - * The attribute name is case insensitive. - */ - protected String getHTMLAttribute(String name) - { - if (hasAttributes()) - { - NamedNodeMap attrs = getAttributes(); - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String attrName = attr.getLocalName(); - if (attrName.equalsIgnoreCase(name)) - { - return attr.getNodeValue(); - } - } - } - return ""; - } - - protected int getIntHTMLAttribute(String name) - { - String value = getHTMLAttribute(name); - if (value == null) - { - return -1; - } - try - { - return Integer.parseInt(value); - } - catch (NumberFormatException e) - { - return -1; - } - } - - protected boolean getBooleanHTMLAttribute(String name) - { - String value = getHTMLAttribute(name); - return value != null; - } - - /** - * Sets the value of the specified attribute. - * The attribute name is case insensitive. - */ - protected void setHTMLAttribute(String name, String value) - { - Node attr; - NamedNodeMap attrs = getAttributes(); - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - attr = attrs.item(i); - String attrName = attr.getLocalName(); - if (attrName.equalsIgnoreCase(name)) - { - if (value != null) - { - attr.setNodeValue(value); - } - else - { - attrs.removeNamedItem(attr.getNodeName()); - } - return; - } - } - if (value != null) - { - // Create a new attribute - DomHTMLDocument doc = (DomHTMLDocument) getOwnerDocument(); - // XXX namespace URI for attribute? - attr = doc.createAttribute(name); - attr.setNodeValue(value); - } - } - - protected void setIntHTMLAttribute(String name, int value) - { - setHTMLAttribute(name, Integer.toString(value)); - } - - protected void setBooleanHTMLAttribute(String name, boolean value) - { - setHTMLAttribute(name, value ? name : null); - } - - /** - * Returns the first parent element with the specified name. - */ - protected Node getParentElement(String name) - { - for (Node parent = getParentNode(); parent != null; - parent = parent.getParentNode()) - { - if (name.equalsIgnoreCase(parent.getLocalName())) - { - return parent; - } - } - return null; - } - - /** - * Returns the first child element with the specified name. - */ - protected Node getChildElement(String name) - { - for (Node child = getFirstChild(); child != null; - child = child.getNextSibling()) - { - if (name.equalsIgnoreCase(child.getLocalName())) - { - return child; - } - } - return null; - } - - /** - * Returns the index of this element among elements of the same name, - * relative to its parent. - */ - protected int getIndex() - { - int index = 0; - Node parent = getParentNode(); - if (parent != null) - { - for (Node ctx = parent.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx == this) - { - return index; - } - index++; - } - } - throw new DomDOMException(DOMException.NOT_FOUND_ERR); - } - - protected void dispatchUIEvent(String name) - { - UIEvent event = new DomEvent.DomUIEvent(name); - dispatchEvent(event); - } - - public String getId() - { - return getHTMLAttribute("id"); - } - - public void setId(String id) - { - setHTMLAttribute("id", id); - } - - public String getTitle() - { - return getHTMLAttribute("title"); - } - - public void setTitle(String title) - { - setHTMLAttribute("title", title); - } - - public String getLang() - { - return getHTMLAttribute("lang"); - } - - public void setLang(String lang) - { - setHTMLAttribute("lang", lang); - } - - public String getDir() - { - return getHTMLAttribute("dir"); - } - - public void setDir(String dir) - { - setHTMLAttribute("dir", dir); - } - - public String getClassName() - { - return getHTMLAttribute("class"); - } - - public void setClassName(String className) - { - setHTMLAttribute("class", className); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLFieldSetElement.java b/libjava/gnu/xml/dom/html2/DomHTMLFieldSetElement.java deleted file mode 100644 index 2c857721947..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLFieldSetElement.java +++ /dev/null @@ -1,65 +0,0 @@ -/* DomHTMLFieldSetElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFieldSetElement; -import org.w3c.dom.html2.HTMLFormElement; - -/** - * An HTML 'FIELDSET' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLFieldSetElement - extends DomHTMLElement - implements HTMLFieldSetElement -{ - - protected DomHTMLFieldSetElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLFontElement.java b/libjava/gnu/xml/dom/html2/DomHTMLFontElement.java deleted file mode 100644 index 08bd349fa62..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLFontElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DomHTMLFontElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFontElement; - -/** - * An HTML 'FONT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLFontElement - extends DomHTMLElement - implements HTMLFontElement -{ - - protected DomHTMLFontElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getColor() - { - return getHTMLAttribute("color"); - } - - public void setColor(String color) - { - setHTMLAttribute("color", color); - } - - public String getFace() - { - return getHTMLAttribute("face"); - } - - public void setFace(String face) - { - setHTMLAttribute("face", face); - } - - public String getSize() - { - return getHTMLAttribute("size"); - } - - public void setSize(String size) - { - setHTMLAttribute("size", size); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLFormElement.java b/libjava/gnu/xml/dom/html2/DomHTMLFormElement.java deleted file mode 100644 index 119d97eb885..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLFormElement.java +++ /dev/null @@ -1,150 +0,0 @@ -/* DomHTMLFormElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLFormElement; - -/** - * An HTML 'FORM' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLFormElement - extends DomHTMLElement - implements HTMLFormElement -{ - - protected DomHTMLFormElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLCollection getElements() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("input"); - ret.addNodeName("button"); - ret.addNodeName("select"); - ret.addNodeName("textarea"); - ret.addNodeName("isindex"); - ret.addNodeName("label"); - ret.addNodeName("option"); - ret.evaluate(); - return ret; - } - - public int getLength() - { - return getElements().getLength(); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getAcceptCharset() - { - return getHTMLAttribute("accept-charset"); - } - - public void setAcceptCharset(String acceptCharset) - { - setHTMLAttribute("accept-charset", acceptCharset); - } - - public String getAction() - { - return getHTMLAttribute("action"); - } - - public void setAction(String action) - { - setHTMLAttribute("action", action); - } - - public String getEnctype() - { - return getHTMLAttribute("enctype"); - } - - public void setEnctype(String enctype) - { - setHTMLAttribute("enctype", enctype); - } - - public String getMethod() - { - return getHTMLAttribute("method"); - } - - public void setMethod(String method) - { - setHTMLAttribute("method", method); - } - - public String getTarget() - { - return getHTMLAttribute("target"); - } - - public void setTarget(String target) - { - setHTMLAttribute("target", target); - } - - public void submit() - { - dispatchUIEvent("submit"); - } - - public void reset() - { - dispatchUIEvent("reset"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLFrameElement.java b/libjava/gnu/xml/dom/html2/DomHTMLFrameElement.java deleted file mode 100644 index 124f35268e8..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLFrameElement.java +++ /dev/null @@ -1,146 +0,0 @@ -/* DomHTMLFrameElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.Document; -import org.w3c.dom.html2.HTMLFrameElement; - -/** - * An HTML 'FRAME' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLFrameElement - extends DomHTMLElement - implements HTMLFrameElement -{ - - protected DomHTMLFrameElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getFrameBorder() - { - return getHTMLAttribute("frameborder"); - } - - public void setFrameBorder(String frameBorder) - { - setHTMLAttribute("frameborder", frameBorder); - } - - public String getLongDesc() - { - return getHTMLAttribute("longdesc"); - } - - public void setLongDesc(String longDesc) - { - setHTMLAttribute("longdesc", longDesc); - } - - public String getMarginHeight() - { - return getHTMLAttribute("marginheight"); - } - - public void setMarginHeight(String marginHeight) - { - setHTMLAttribute("marginheight", marginHeight); - } - - public String getMarginWidth() - { - return getHTMLAttribute("marginwidth"); - } - - public void setMarginWidth(String marginWidth) - { - setHTMLAttribute("marginwidth", marginWidth); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public boolean getNoResize() - { - return getBooleanHTMLAttribute("noresize"); - } - - public void setNoResize(boolean noResize) - { - setBooleanHTMLAttribute("noresize", noResize); - } - - public String getScrolling() - { - return getHTMLAttribute("scrolling"); - } - - public void setScrolling(String scrolling) - { - setHTMLAttribute("scrolling", scrolling); - } - - public String getSrc() - { - return getHTMLAttribute("src"); - } - - public void setSrc(String src) - { - setHTMLAttribute("src", src); - } - - public Document getContentDocument() - { - // TODO getContentDocument - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLFrameSetElement.java b/libjava/gnu/xml/dom/html2/DomHTMLFrameSetElement.java deleted file mode 100644 index 44d317f64a3..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLFrameSetElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLFrameSetElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFrameSetElement; - -/** - * An HTML 'FRAMESET' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLFrameSetElement - extends DomHTMLElement - implements HTMLFrameSetElement -{ - - protected DomHTMLFrameSetElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getCols() - { - return getHTMLAttribute("cols"); - } - - public void setCols(String cols) - { - setHTMLAttribute("cols", cols); - } - - public String getRows() - { - return getHTMLAttribute("rows"); - } - - public void setRows(String rows) - { - setHTMLAttribute("rows", rows); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLHRElement.java b/libjava/gnu/xml/dom/html2/DomHTMLHRElement.java deleted file mode 100644 index d1b48012175..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLHRElement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* DomHTMLHRElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLHRElement; - -/** - * An HTML 'HR' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLHRElement - extends DomHTMLElement - implements HTMLHRElement -{ - - protected DomHTMLHRElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public boolean getNoShade() - { - return getBooleanHTMLAttribute("noshade"); - } - - public void setNoShade(boolean noShade) - { - setBooleanHTMLAttribute("noshade", noShade); - } - - public String getSize() - { - return getHTMLAttribute("size"); - } - - public void setSize(String size) - { - setHTMLAttribute("size", size); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLHeadElement.java b/libjava/gnu/xml/dom/html2/DomHTMLHeadElement.java deleted file mode 100644 index f68e8c7fad3..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLHeadElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLHeadElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLHeadElement; - -/** - * An HTML 'HEAD' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLHeadElement - extends DomHTMLElement - implements HTMLHeadElement -{ - - protected DomHTMLHeadElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getProfile() - { - return getHTMLAttribute("profile"); - } - - public void setProfile(String profile) - { - setHTMLAttribute("profile", profile); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLHeadingElement.java b/libjava/gnu/xml/dom/html2/DomHTMLHeadingElement.java deleted file mode 100644 index f1427ad89e6..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLHeadingElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLHeadingElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLHeadingElement; - -/** - * An HTML 'H1', 'H2', 'H3', 'H4', 'H5', or 'H6' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLHeadingElement - extends DomHTMLElement - implements HTMLHeadingElement -{ - - protected DomHTMLHeadingElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLHtmlElement.java b/libjava/gnu/xml/dom/html2/DomHTMLHtmlElement.java deleted file mode 100644 index 95d45264eee..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLHtmlElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLHtmlElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLHtmlElement; - -/** - * An HTML 'HTML' top-level element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLHtmlElement - extends DomHTMLElement - implements HTMLHtmlElement -{ - - protected DomHTMLHtmlElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getVersion() - { - return getHTMLAttribute("version"); - } - - public void setVersion(String version) - { - setHTMLAttribute("version", version); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLIFrameElement.java b/libjava/gnu/xml/dom/html2/DomHTMLIFrameElement.java deleted file mode 100644 index c5ca75d8c21..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLIFrameElement.java +++ /dev/null @@ -1,166 +0,0 @@ -/* DomHTMLIFrameElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.Document; -import org.w3c.dom.html2.HTMLIFrameElement; - -/** - * An HTML 'IFRAME' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLIFrameElement - extends DomHTMLElement - implements HTMLIFrameElement -{ - - protected DomHTMLIFrameElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getFrameBorder() - { - return getHTMLAttribute("frameborder"); - } - - public void setFrameBorder(String frameBorder) - { - setHTMLAttribute("frameborder", frameBorder); - } - - public String getHeight() - { - return getHTMLAttribute("height"); - } - - public void setHeight(String height) - { - setHTMLAttribute("height", height); - } - - public String getLongDesc() - { - return getHTMLAttribute("longdesc"); - } - - public void setLongDesc(String longDesc) - { - setHTMLAttribute("longdesc", longDesc); - } - - public String getMarginHeight() - { - return getHTMLAttribute("marginheight"); - } - - public void setMarginHeight(String marginHeight) - { - setHTMLAttribute("marginheight", marginHeight); - } - - public String getMarginWidth() - { - return getHTMLAttribute("marginwidth"); - } - - public void setMarginWidth(String marginWidth) - { - setHTMLAttribute("marginwidth", marginWidth); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getScrolling() - { - return getHTMLAttribute("scrolling"); - } - - public void setScrolling(String scrolling) - { - setHTMLAttribute("scrolling", scrolling); - } - - public String getSrc() - { - return getHTMLAttribute("src"); - } - - public void setSrc(String src) - { - setHTMLAttribute("src", src); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - - public Document getContentDocument() - { - // TODO getContentDocument - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLImageElement.java b/libjava/gnu/xml/dom/html2/DomHTMLImageElement.java deleted file mode 100644 index c96e5fede4d..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLImageElement.java +++ /dev/null @@ -1,179 +0,0 @@ -/* DomHTMLImageElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLImageElement; - -/** - * An HTML 'IMG' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLImageElement - extends DomHTMLElement - implements HTMLImageElement -{ - - protected DomHTMLImageElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getAlt() - { - return getHTMLAttribute("alt"); - } - - public void setAlt(String alt) - { - setHTMLAttribute("alt", alt); - } - - public String getBorder() - { - return getHTMLAttribute("border"); - } - - public void setBorder(String border) - { - setHTMLAttribute("border", border); - } - - public int getHeight() - { - return getIntHTMLAttribute("height"); - } - - public void setHeight(int height) - { - setIntHTMLAttribute("height", height); - } - - public int getHspace() - { - return getIntHTMLAttribute("hspace"); - } - - public void setHspace(int hspace) - { - setIntHTMLAttribute("hspace", hspace); - } - - public boolean getIsMap() - { - return getBooleanHTMLAttribute("ismap"); - } - - public void setIsMap(boolean isMap) - { - setBooleanHTMLAttribute("ismap", isMap); - } - - public String getLongDesc() - { - return getHTMLAttribute("longdesc"); - } - - public void setLongDesc(String longDesc) - { - setHTMLAttribute("longdesc", longDesc); - } - - public String getSrc() - { - return getHTMLAttribute("src"); - } - - public void setSrc(String src) - { - setHTMLAttribute("src", src); - } - - public String getUseMap() - { - return getHTMLAttribute("usemap"); - } - - public void setUseMap(String useMap) - { - setHTMLAttribute("usemap", useMap); - } - - public int getVspace() - { - return getIntHTMLAttribute("vspace"); - } - - public void setVspace(int vspace) - { - setIntHTMLAttribute("vspace", vspace); - } - - public int getWidth() - { - return getIntHTMLAttribute("width"); - } - - public void setWidth(int width) - { - setIntHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLImpl.java b/libjava/gnu/xml/dom/html2/DomHTMLImpl.java deleted file mode 100644 index 9f0db085040..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/* DomHTMLImpl.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomImpl; -import org.w3c.dom.Document; - -/** - * Specialised DOMImplementation for creating HTML documents. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLImpl - extends DomImpl -{ - - protected Document createDocument() - { - return new DomHTMLDocument(this); - } - - public Object getFeature(String feature, String version) - { - if (hasFeature(feature, version)) - { - return this; - } - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLInputElement.java b/libjava/gnu/xml/dom/html2/DomHTMLInputElement.java deleted file mode 100644 index 1dbc9c28de0..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLInputElement.java +++ /dev/null @@ -1,266 +0,0 @@ -/* DomHTMLInputElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLInputElement; - -/** - * An HTML 'INPUT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLInputElement - extends DomHTMLElement - implements HTMLInputElement -{ - - protected String value; - protected Boolean checked; - - protected DomHTMLInputElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getDefaultValue() - { - return getHTMLAttribute("value"); - } - - public void setDefaultValue(String defaultValue) - { - setHTMLAttribute("value", defaultValue); - } - - public boolean getDefaultChecked() - { - return getBooleanHTMLAttribute("checked"); - } - - public void setDefaultChecked(boolean defaultChecked) - { - setBooleanHTMLAttribute("checked", defaultChecked); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getAccept() - { - return getHTMLAttribute("accept"); - } - - public void setAccept(String accept) - { - setHTMLAttribute("accept", accept); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getAlt() - { - return getHTMLAttribute("alt"); - } - - public void setAlt(String alt) - { - setHTMLAttribute("alt", alt); - } - - public boolean getChecked() - { - if (checked == null) - { - checked = Boolean.valueOf(getDefaultChecked()); - } - return checked.booleanValue(); - } - - public void setChecked(boolean checked) - { - this.checked = Boolean.valueOf(checked); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public int getMaxLength() - { - return getIntHTMLAttribute("maxLength"); - } - - public void setMaxLength(int maxLength) - { - setIntHTMLAttribute("maxLength", maxLength); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public boolean getReadOnly() - { - return getBooleanHTMLAttribute("readonly"); - } - - public void setReadOnly(boolean readOnly) - { - setBooleanHTMLAttribute("readonly", readOnly); - } - - public int getSize() - { - return getIntHTMLAttribute("size"); - } - - public void setSize(int size) - { - setIntHTMLAttribute("size", size); - } - - public String getSrc() - { - return getHTMLAttribute("src"); - } - - public void setSrc(String src) - { - setHTMLAttribute("src", src); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - - public String getUseMap() - { - return getHTMLAttribute("usemap"); - } - - public void setUseMap(String useMap) - { - setHTMLAttribute("usemap", useMap); - } - - public String getValue() - { - if (value == null) - { - value = getDefaultValue(); - } - return value; - } - - public void setValue(String value) - { - this.value = value; - } - - public void blur() - { - dispatchUIEvent("blur"); - } - - public void focus() - { - dispatchUIEvent("focus"); - } - - public void select() - { - dispatchUIEvent("select"); - } - - public void click() - { - dispatchUIEvent("click"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLIsIndexElement.java b/libjava/gnu/xml/dom/html2/DomHTMLIsIndexElement.java deleted file mode 100644 index 087f4a0cd79..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLIsIndexElement.java +++ /dev/null @@ -1,75 +0,0 @@ -/* DomHTMLIsIndexElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLIsIndexElement; - -/** - * An HTML 'ISINDEX' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLIsIndexElement - extends DomHTMLElement - implements HTMLIsIndexElement -{ - - protected DomHTMLIsIndexElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getPrompt() - { - return getHTMLAttribute("prompt"); - } - - public void setPrompt(String prompt) - { - setHTMLAttribute("prompt", prompt); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLLIElement.java b/libjava/gnu/xml/dom/html2/DomHTMLLIElement.java deleted file mode 100644 index 11eccdf5df3..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLLIElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLLIElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLLIElement; - -/** - * An HTML 'LI' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLLIElement - extends DomHTMLElement - implements HTMLLIElement -{ - - protected DomHTMLLIElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - - public int getValue() - { - return getIntHTMLAttribute("value"); - } - - public void setValue(int value) - { - setIntHTMLAttribute("value", value); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLLabelElement.java b/libjava/gnu/xml/dom/html2/DomHTMLLabelElement.java deleted file mode 100644 index c0cc39f8e96..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLLabelElement.java +++ /dev/null @@ -1,85 +0,0 @@ -/* DomHTMLLabelElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLLabelElement; - -/** - * An HTML 'LABEL' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLLabelElement - extends DomHTMLElement - implements HTMLLabelElement -{ - - protected DomHTMLLabelElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public String getHtmlFor() - { - return getHTMLAttribute("for"); - } - - public void setHtmlFor(String htmlFor) - { - setHTMLAttribute("for", htmlFor); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLLegendElement.java b/libjava/gnu/xml/dom/html2/DomHTMLLegendElement.java deleted file mode 100644 index a500f8fa14c..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLLegendElement.java +++ /dev/null @@ -1,85 +0,0 @@ -/* DomHTMLLegendElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLLegendElement; - -/** - * An HTML 'LEGEND' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLLegendElement - extends DomHTMLElement - implements HTMLLegendElement -{ - - protected DomHTMLLegendElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLLinkElement.java b/libjava/gnu/xml/dom/html2/DomHTMLLinkElement.java deleted file mode 100644 index 127726ef7e3..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLLinkElement.java +++ /dev/null @@ -1,149 +0,0 @@ -/* DomHTMLLinkElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLLinkElement; - -/** - * An HTML 'LINK' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLLinkElement - extends DomHTMLElement - implements HTMLLinkElement -{ - - protected DomHTMLLinkElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getCharset() - { - return getHTMLAttribute("charset"); - } - - public void setCharset(String charset) - { - setHTMLAttribute("charset", charset); - } - - public String getHref() - { - return getHTMLAttribute("href"); - } - - public void setHref(String href) - { - setHTMLAttribute("href", href); - } - - public String getHreflang() - { - return getHTMLAttribute("hreflang"); - } - - public void setHreflang(String hreflang) - { - setHTMLAttribute("hreflang", hreflang); - } - - public String getMedia() - { - return getHTMLAttribute("media"); - } - - public void setMedia(String media) - { - setHTMLAttribute("media", media); - } - - public String getRel() - { - return getHTMLAttribute("rel"); - } - - public void setRel(String rel) - { - setHTMLAttribute("rel", rel); - } - - public String getRev() - { - return getHTMLAttribute("rev"); - } - - public void setRev(String rev) - { - setHTMLAttribute("rev", rev); - } - - public String getTarget() - { - return getHTMLAttribute("target"); - } - - public void setTarget(String target) - { - setHTMLAttribute("target", target); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLMapElement.java b/libjava/gnu/xml/dom/html2/DomHTMLMapElement.java deleted file mode 100644 index 1f7182f4f29..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLMapElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLMapElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLMapElement; - -/** - * An HTML 'MAP' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLMapElement - extends DomHTMLElement - implements HTMLMapElement -{ - - protected DomHTMLMapElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLCollection getAreas() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("area"); - ret.evaluate(); - return ret; - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLMenuElement.java b/libjava/gnu/xml/dom/html2/DomHTMLMenuElement.java deleted file mode 100644 index 17f6f589f9a..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLMenuElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLMenuElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLMenuElement; - -/** - * An HTML 'MENU' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLMenuElement - extends DomHTMLElement - implements HTMLMenuElement -{ - - protected DomHTMLMenuElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getCompact() - { - return getBooleanHTMLAttribute("compact"); - } - - public void setCompact(boolean compact) - { - setBooleanHTMLAttribute("compact", compact); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLMetaElement.java b/libjava/gnu/xml/dom/html2/DomHTMLMetaElement.java deleted file mode 100644 index 1a0440504de..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLMetaElement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* DomHTMLMetaElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLMetaElement; - -/** - * An HTML 'META' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLMetaElement - extends DomHTMLElement - implements HTMLMetaElement -{ - - protected DomHTMLMetaElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getContent() - { - return getHTMLAttribute("content"); - } - - public void setContent(String content) - { - setHTMLAttribute("content", content); - } - - public String getHttpEquiv() - { - return getHTMLAttribute("http-equiv"); - } - - public void setHttpEquiv(String httpEquiv) - { - setHTMLAttribute("http-equiv", httpEquiv); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getScheme() - { - return getHTMLAttribute("scheme"); - } - - public void setScheme(String scheme) - { - setHTMLAttribute("scheme", scheme); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLModElement.java b/libjava/gnu/xml/dom/html2/DomHTMLModElement.java deleted file mode 100644 index 493f7242ba1..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLModElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLModElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLModElement; - -/** - * An HTML 'INS' or 'DEL' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLModElement - extends DomHTMLElement - implements HTMLModElement -{ - - protected DomHTMLModElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getCite() - { - return getHTMLAttribute("cite"); - } - - public void setCite(String cite) - { - setHTMLAttribute("cite", cite); - } - - public String getDateTime() - { - return getHTMLAttribute("datetime"); - } - - public void setDateTime(String dateTime) - { - setHTMLAttribute("datetime", dateTime); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLOListElement.java b/libjava/gnu/xml/dom/html2/DomHTMLOListElement.java deleted file mode 100644 index fb98cf40d79..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLOListElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DomHTMLOListElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLOListElement; - -/** - * An HTML 'OL' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLOListElement - extends DomHTMLElement - implements HTMLOListElement -{ - - protected DomHTMLOListElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getCompact() - { - return getBooleanHTMLAttribute("compact"); - } - - public void setCompact(boolean compact) - { - setBooleanHTMLAttribute("compact", compact); - } - - public int getStart() - { - return getIntHTMLAttribute("start"); - } - - public void setStart(int start) - { - setIntHTMLAttribute("start", start); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLObjectElement.java b/libjava/gnu/xml/dom/html2/DomHTMLObjectElement.java deleted file mode 100644 index fdea9b15373..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLObjectElement.java +++ /dev/null @@ -1,242 +0,0 @@ -/* DomHTMLObjectElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.Document; -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLObjectElement; - -/** - * An HTML 'OBJECT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLObjectElement - extends DomHTMLElement - implements HTMLObjectElement -{ - - protected DomHTMLObjectElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getCode() - { - return getHTMLAttribute("code"); - } - - public void setCode(String code) - { - setHTMLAttribute("code", code); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getArchive() - { - return getHTMLAttribute("archive"); - } - - public void setArchive(String archive) - { - setHTMLAttribute("archive", archive); - } - - public String getBorder() - { - return getHTMLAttribute("border"); - } - - public void setBorder(String border) - { - setHTMLAttribute("border", border); - } - - public String getCodeBase() - { - return getHTMLAttribute("codebase"); - } - - public void setCodeBase(String codeBase) - { - setHTMLAttribute("codebase", codeBase); - } - - public String getCodeType() - { - return getHTMLAttribute("codetype"); - } - - public void setCodeType(String codeType) - { - setHTMLAttribute("codetype", codeType); - } - - public String getData() - { - return getHTMLAttribute("data"); - } - - public void setData(String data) - { - setHTMLAttribute("data", data); - } - - public boolean getDeclare() - { - return getBooleanHTMLAttribute("declare"); - } - - public void setDeclare(boolean declare) - { - setBooleanHTMLAttribute("declare", declare); - } - - public String getHeight() - { - return getHTMLAttribute("height"); - } - - public void setHeight(String height) - { - setHTMLAttribute("height", height); - } - - public int getHspace() - { - return getIntHTMLAttribute("hspace"); - } - - public void setHspace(int hspace) - { - setIntHTMLAttribute("hspace", hspace); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getStandby() - { - return getHTMLAttribute("standby"); - } - - public void setStandby(String standby) - { - setHTMLAttribute("standby", standby); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - - public String getUseMap() - { - return getHTMLAttribute("usemap"); - } - - public void setUseMap(String useMap) - { - setHTMLAttribute("usemap", useMap); - } - - public int getVspace() - { - return getIntHTMLAttribute("vspace"); - } - - public void setVspace(int vspace) - { - setIntHTMLAttribute("vspace", vspace); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - - public Document getContentDocument() - { - // TODO getContentDocument - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLOptGroupElement.java b/libjava/gnu/xml/dom/html2/DomHTMLOptGroupElement.java deleted file mode 100644 index 76545e130cb..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLOptGroupElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLOptGroupElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLOptGroupElement; - -/** - * An HTML 'OPTGROUP' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLOptGroupElement - extends DomHTMLElement - implements HTMLOptGroupElement -{ - - protected DomHTMLOptGroupElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getLabel() - { - return getHTMLAttribute("label"); - } - - public void setLabel(String label) - { - setHTMLAttribute("label", label); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLOptionElement.java b/libjava/gnu/xml/dom/html2/DomHTMLOptionElement.java deleted file mode 100644 index 69c059d9d43..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLOptionElement.java +++ /dev/null @@ -1,131 +0,0 @@ -/* DomHTMLOptionElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLOptionElement; - -/** - * An HTML 'OPTION' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLOptionElement - extends DomHTMLElement - implements HTMLOptionElement -{ - - protected Boolean selected; - - protected DomHTMLOptionElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public boolean getDefaultSelected() - { - return getBooleanHTMLAttribute("selected"); - } - - public void setDefaultSelected(boolean defaultSelected) - { - setBooleanHTMLAttribute("selected", defaultSelected); - } - - public String getText() - { - return getTextContent(); - } - - public int getIndex() - { - return super.getIndex(); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getLabel() - { - return getHTMLAttribute("label"); - } - - public void setLabel(String label) - { - setHTMLAttribute("label", label); - } - - public boolean getSelected() - { - if (selected == null) - { - selected = Boolean.valueOf(getDefaultSelected()); - } - return selected.booleanValue(); - } - - public void setSelected(boolean selected) - { - this.selected = Boolean.valueOf(selected); - } - - public String getValue() - { - return getHTMLAttribute("value"); - } - - public void setValue(String value) - { - setHTMLAttribute("value", value); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLParagraphElement.java b/libjava/gnu/xml/dom/html2/DomHTMLParagraphElement.java deleted file mode 100644 index 2a8c4f6fb11..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLParagraphElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLParagraphElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLParagraphElement; - -/** - * An HTML 'P' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLParagraphElement - extends DomHTMLElement - implements HTMLParagraphElement -{ - - protected DomHTMLParagraphElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLParamElement.java b/libjava/gnu/xml/dom/html2/DomHTMLParamElement.java deleted file mode 100644 index 81c6559529e..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLParamElement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* DomHTMLParamElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLParamElement; - -/** - * An HTML 'PARAM' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLParamElement - extends DomHTMLElement - implements HTMLParamElement -{ - - protected DomHTMLParamElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - - public String getValue() - { - return getHTMLAttribute("value"); - } - - public void setValue(String value) - { - setHTMLAttribute("value", value); - } - - public String getValueType() - { - return getHTMLAttribute("valuetype"); - } - - public void setValueType(String valueType) - { - setHTMLAttribute("valuetype", valueType); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLParser.java b/libjava/gnu/xml/dom/html2/DomHTMLParser.java deleted file mode 100644 index 7b445622509..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLParser.java +++ /dev/null @@ -1,266 +0,0 @@ -/* DomHTMLParser.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.xml.dom.html2; - -import gnu.javax.swing.text.html.parser.support.Parser; - -import java.io.IOException; -import java.io.Reader; - -import java.util.Enumeration; -import java.util.Iterator; -import java.util.LinkedList; - -import javax.swing.text.AttributeSet; -import javax.swing.text.html.HTML; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.TagElement; - -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.html2.HTMLDocument; - -/** - * This parser reads HTML from the given stream and stores into - * {@link HTMLDocument}. The HTML tag becomes the {@link Node}. - * The tag attributes become the node attributes. The text inside - * HTML tag is inserted as one or several text nodes. The nested - * HTML tags are inserted as child nodes. - * - * If the strict tree structure, closing the tag means closing all - * nested tags. To work around this, this parser closes the nested - * tags and immediately reopens them after the closed tag. - * In this way, <code><b><i>c</b>d</code> - * is parsed as <code><b><i>c</i></b><i>d</code> . - * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) - */ -public class DomHTMLParser - extends gnu.javax.swing.text.html.parser.support.Parser -{ - /** - * The target where HTML document will be inserted. - */ - protected DomHTMLDocument document; - - /** - * The subsequently created new nodes will be inserted as the - * childs of this cursor. - */ - protected Node cursor; - - /** - * Create parser using the given DTD. - * - * @param dtd the DTD (for example, - * {@link gnu.javax.swing.text.html.parser.HTML_401F}). - */ - public DomHTMLParser(DTD dtd) - { - super(dtd); - } - - /** - * Parse SGML insertion ( <! ... > ). - * Currently just treats it as comment. - */ - public boolean parseMarkupDeclarations(StringBuffer strBuff) - throws java.io.IOException - { - Node c = document.createComment(strBuff.toString()); - cursor.appendChild(c); - return false; - } - - /** - * Read the document, present in the given stream, and - * return the corresponding {@link HTMLDocument}. - * - * @param input a stream to read from. - * @return a document, reflecting the structure of the provided HTML - * text. - * - * @throws IOException if the reader throws one. - */ - public HTMLDocument parseDocument(Reader input) - throws IOException - { - try - { - document = new DomHTMLDocument(); - - cursor = document; - - parse(input); - - DomHTMLDocument h = document; - document = null; - return h; - } - catch (Exception ex) - { - ex.printStackTrace(); - throw new IOException("Exception: " + ex.getMessage()); - } - } - - /** - * Create a new node. - * @param name the name of node, case insensitive. - * @return the created node. - */ - protected Node createNode(String name) - { - Node new_node = document.createElement(name.toLowerCase()); - AttributeSet hatts = getAttributes(); - NamedNodeMap natts = new_node.getAttributes(); - - Enumeration enumeration = hatts.getAttributeNames(); - Object key; - Node attribute; - - while (hatts != null) - { - while (enumeration.hasMoreElements()) - { - key = enumeration.nextElement(); - attribute = document.createAttribute(key.toString()); - attribute.setNodeValue(hatts.getAttribute(key).toString()); - natts.setNamedItem(attribute); - } - - // The default values are stored in a parent node. - hatts = hatts.getResolveParent(); - } - - return new_node; - } - - /** - * Handle comment by inserting the comment node. - * @param text the comment text. - */ - protected void handleComment(char[] text) - { - Node c = document.createComment(new String(text)); - cursor.appendChild(c); - } - - /** - * Handle the tag with no content. - * @param tag the tag to handle. - */ - protected void handleEmptyTag(TagElement tag) - { - String name = tag.getHTMLTag().toString(); - - if (name.equalsIgnoreCase("#pcdata")) - return; - - Node c = createNode(name); - cursor.appendChild(c); - } - - /** - * Close the given tag. Close and reopen all nested tags. - * @param tag the tag to close. - */ - protected void handleEndTag(TagElement tag) - { - String name = tag.getHTMLTag().toString(); - String nname = cursor.getNodeName(); - - // Closing the current tag. - if (nname != null && nname.equalsIgnoreCase(name)) - { - cursor = cursor.getParentNode(); - } - else - { - Node nCursor = cursor.getParentNode(); - - // Remember the opened nodes. - LinkedList open = new LinkedList(); - Node close = cursor; - while (close != null && !close.getNodeName().equalsIgnoreCase(name)) - { - if (close != document) - open.addFirst(close); - close = close.getParentNode(); - } - - if (close == null) - cursor = document; - else - cursor = close.getParentNode(); - - // Insert the copies of the opened nodes. - Iterator iter = open.iterator(); - while (iter.hasNext()) - { - Node item = (Node) iter.next(); - Node copy = item.cloneNode(true); - cursor.appendChild(copy); - cursor = copy; - } - } - } - - /** - * Handle the start tag by inserting the HTML element. - * @param tag the tag to handle. - */ - protected void handleStartTag(TagElement tag) - { - HTML.Tag h = tag.getHTMLTag(); - Node c = createNode(h.toString()); - cursor.appendChild(c); - cursor = c; - } - - /** - * Handle text by inserting the text node. - * @param text the text to insert. - */ - protected void handleText(char[] text) - { - Node c = document.createTextNode(text, 0, text.length); - cursor.appendChild(c); - } -} diff --git a/libjava/gnu/xml/dom/html2/DomHTMLPreElement.java b/libjava/gnu/xml/dom/html2/DomHTMLPreElement.java deleted file mode 100644 index 9b36a288700..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLPreElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLPreElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLPreElement; - -/** - * An HTML 'PRE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLPreElement - extends DomHTMLElement - implements HTMLPreElement -{ - - protected DomHTMLPreElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public int getWidth() - { - return getIntHTMLAttribute("width"); - } - - public void setWidth(int width) - { - setIntHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLQuoteElement.java b/libjava/gnu/xml/dom/html2/DomHTMLQuoteElement.java deleted file mode 100644 index 678a5ada697..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLQuoteElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLQuoteElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLQuoteElement; - -/** - * An HTML 'Q' or 'BLOCKQUOTE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLQuoteElement - extends DomHTMLElement - implements HTMLQuoteElement -{ - - protected DomHTMLQuoteElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getCite() - { - return getHTMLAttribute("cite"); - } - - public void setCite(String cite) - { - setHTMLAttribute("cite", cite); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLScriptElement.java b/libjava/gnu/xml/dom/html2/DomHTMLScriptElement.java deleted file mode 100644 index 8f8fff58a82..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLScriptElement.java +++ /dev/null @@ -1,129 +0,0 @@ -/* DomHTMLScriptElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLScriptElement; - -/** - * An HTML 'SCRIPT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLScriptElement - extends DomHTMLElement - implements HTMLScriptElement -{ - - protected DomHTMLScriptElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getText() - { - return getTextContent(); - } - - public void setText(String text) - { - setTextContent(text); - } - - public String getHtmlFor() - { - return getHTMLAttribute("for"); - } - - public void setHtmlFor(String htmlFor) - { - setHTMLAttribute("for", htmlFor); - } - - public String getEvent() - { - return getHTMLAttribute("event"); - } - - public void setEvent(String event) - { - setHTMLAttribute("event", event); - } - - public String getCharset() - { - return getHTMLAttribute("charset"); - } - - public void setCharset(String charset) - { - setHTMLAttribute("charset", charset); - } - - public boolean getDefer() - { - return getBooleanHTMLAttribute("defer"); - } - - public void setDefer(boolean defer) - { - setBooleanHTMLAttribute("defer", defer); - } - - public String getSrc() - { - return getHTMLAttribute("src"); - } - - public void setSrc(String src) - { - setHTMLAttribute("src", src); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLSelectElement.java b/libjava/gnu/xml/dom/html2/DomHTMLSelectElement.java deleted file mode 100644 index 09752e1ffe4..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLSelectElement.java +++ /dev/null @@ -1,211 +0,0 @@ -/* DomHTMLSelectElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import org.w3c.dom.DOMException; -import org.w3c.dom.html2.HTMLElement; -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLOptionElement; -import org.w3c.dom.html2.HTMLOptionsCollection; -import org.w3c.dom.html2.HTMLSelectElement; - -/** - * An HTML 'SELECT' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLSelectElement - extends DomHTMLElement - implements HTMLSelectElement -{ - - protected DomHTMLSelectElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public int getSelectedIndex() - { - HTMLOptionsCollection options = getOptions(); - int len = options.getLength(); - for (int i = 0; i < len; i++) - { - HTMLOptionElement option = (HTMLOptionElement) options.item(i); - if (option.getSelected()) - { - return i; - } - } - return -1; - } - - public void setSelectedIndex(int selectedIndex) - { - HTMLOptionsCollection options = getOptions(); - int len = options.getLength(); - if (selectedIndex < 0 || selectedIndex >= len) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - for (int i = 0; i < len; i++) - { - HTMLOptionElement option = (HTMLOptionElement) options.item(i); - option.setSelected(i == selectedIndex); - } - } - - public String getValue() - { - return getHTMLAttribute("value"); - } - - public void setValue(String value) - { - setHTMLAttribute("value", value); - } - - public int getLength() - { - return getIntHTMLAttribute("length"); - } - - public void setLength(int length) - { - setIntHTMLAttribute("length", length); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public HTMLOptionsCollection getOptions() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("option"); - ret.evaluate(); - return ret; - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public boolean getMultiple() - { - return getBooleanHTMLAttribute("multiple"); - } - - public void setMultiple(boolean multiple) - { - setBooleanHTMLAttribute("multiple", multiple); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public int getSize() - { - return getIntHTMLAttribute("size"); - } - - public void setSize(int size) - { - setIntHTMLAttribute("size", size); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public void add(HTMLElement element, HTMLElement before) - { - insertBefore(before, element); - } - - public void remove(int index) - { - HTMLOptionsCollection options = getOptions(); - int len = options.getLength(); - if (index < 0 || index >= len) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - HTMLOptionElement option = (HTMLOptionElement) options.item(index); - option.getParentNode().removeChild(option); - } - - public void blur() - { - dispatchUIEvent("blur"); - } - - public void focus() - { - dispatchUIEvent("focus"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLStyleElement.java b/libjava/gnu/xml/dom/html2/DomHTMLStyleElement.java deleted file mode 100644 index f6f1fcc6844..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLStyleElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/* DomHTMLStyleElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLStyleElement; - -/** - * An HTML 'STYLE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLStyleElement - extends DomHTMLElement - implements HTMLStyleElement -{ - - protected DomHTMLStyleElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getMedia() - { - return getHTMLAttribute("media"); - } - - public void setMedia(String media) - { - setHTMLAttribute("media", media); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableCaptionElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableCaptionElement.java deleted file mode 100644 index 28ea3418895..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableCaptionElement.java +++ /dev/null @@ -1,70 +0,0 @@ -/* DomHTMLTableCaptionElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLTableCaptionElement; - -/** - * An HTML 'CAPTION' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableCaptionElement - extends DomHTMLElement - implements HTMLTableCaptionElement -{ - - protected DomHTMLTableCaptionElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableCellElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableCellElement.java deleted file mode 100644 index 41d33af26f8..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableCellElement.java +++ /dev/null @@ -1,205 +0,0 @@ -/* DomHTMLTableCellElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLTableCellElement; - -/** - * An HTML 'TH' or 'TD' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableCellElement - extends DomHTMLElement - implements HTMLTableCellElement -{ - - protected DomHTMLTableCellElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public int getCellIndex() - { - return getIndex(); - } - - public String getAbbr() - { - return getHTMLAttribute("abbr"); - } - - public void setAbbr(String abbr) - { - setHTMLAttribute("abbr", abbr); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getAxis() - { - return getHTMLAttribute("axis"); - } - - public void setAxis(String axis) - { - setHTMLAttribute("axis", axis); - } - - public String getBgColor() - { - return getHTMLAttribute("bgcolor"); - } - - public void setBgColor(String bgColor) - { - setHTMLAttribute("bgcolor", bgColor); - } - - public String getCh() - { - return getHTMLAttribute("char"); - } - - public void setCh(String ch) - { - setHTMLAttribute("char", ch); - } - - public String getChOff() - { - return getHTMLAttribute("charoff"); - } - - public void setChOff(String chOff) - { - setHTMLAttribute("charoff", chOff); - } - - public int getColSpan() - { - return getIntHTMLAttribute("colspan"); - } - - public void setColSpan(int colSpan) - { - setIntHTMLAttribute("colspan", colSpan); - } - - public String getHeaders() - { - return getHTMLAttribute("headers"); - } - - public void setHeaders(String headers) - { - setHTMLAttribute("headers", headers); - } - - public String getHeight() - { - return getHTMLAttribute("height"); - } - - public void setHeight(String height) - { - setHTMLAttribute("height", height); - } - - public boolean getNoWrap() - { - return getBooleanHTMLAttribute("nowrap"); - } - - public void setNoWrap(boolean noWrap) - { - setBooleanHTMLAttribute("nowrap", noWrap); - } - - public int getRowSpan() - { - return getIntHTMLAttribute("rowspan"); - } - - public void setRowSpan(int rowSpan) - { - setIntHTMLAttribute("rowspan", rowSpan); - } - - public String getScope() - { - return getHTMLAttribute("scope"); - } - - public void setScope(String scope) - { - setHTMLAttribute("scope", scope); - } - - public String getVAlign() - { - return getHTMLAttribute("valign"); - } - - public void setVAlign(String vAlign) - { - setHTMLAttribute("valign", vAlign); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableColElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableColElement.java deleted file mode 100644 index 799447dc81e..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableColElement.java +++ /dev/null @@ -1,120 +0,0 @@ -/* DomHTMLTableColElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLTableColElement; - -/** - * An HTML 'COL' or 'COLGROUP' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableColElement - extends DomHTMLElement - implements HTMLTableColElement -{ - - protected DomHTMLTableColElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getCh() - { - return getHTMLAttribute("char"); - } - - public void setCh(String ch) - { - setHTMLAttribute("char", ch); - } - - public String getChOff() - { - return getHTMLAttribute("charoff"); - } - - public void setChOff(String chOff) - { - setHTMLAttribute("charoff", chOff); - } - - public int getSpan() - { - return getIntHTMLAttribute("span"); - } - - public void setSpan(int span) - { - setIntHTMLAttribute("span", span); - } - - public String getVAlign() - { - return getHTMLAttribute("valign"); - } - - public void setVAlign(String vAlign) - { - setHTMLAttribute("valign", vAlign); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableElement.java deleted file mode 100644 index 73a3a45c61d..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableElement.java +++ /dev/null @@ -1,383 +0,0 @@ -/* DomHTMLTableElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLElement; -import org.w3c.dom.html2.HTMLTableCaptionElement; -import org.w3c.dom.html2.HTMLTableElement; -import org.w3c.dom.html2.HTMLTableSectionElement; - -/** - * An HTML 'TABLE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableElement - extends DomHTMLElement - implements HTMLTableElement -{ - - protected DomHTMLTableElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public HTMLTableCaptionElement getCaption() - { - return (HTMLTableCaptionElement) getChildElement("caption"); - } - - public void setCaption(HTMLTableCaptionElement caption) - { - HTMLTableCaptionElement ref = getCaption(); - if (ref == null) - { - appendChild(caption); - } - else - { - replaceChild(caption, ref); - } - } - - public HTMLTableSectionElement getTHead() - { - return (HTMLTableSectionElement) getChildElement("thead"); - } - - public void setTHead(HTMLTableSectionElement tHead) - { - HTMLTableSectionElement ref = getTHead(); - if (ref == null) - { - appendChild(tHead); - } - else - { - replaceChild(tHead, ref); - } - } - - public HTMLTableSectionElement getTFoot() - { - return (HTMLTableSectionElement) getChildElement("tfoot"); - } - - public void setTFoot(HTMLTableSectionElement tFoot) - { - HTMLTableSectionElement ref = getTFoot(); - if (ref == null) - { - appendChild(tFoot); - } - else - { - replaceChild(tFoot, ref); - } - } - - public HTMLCollection getRows() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("tr"); - ret.evaluate(); - return ret; - } - - public HTMLCollection getTBodies() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("tbody"); - ret.evaluate(); - return ret; - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getBgColor() - { - return getHTMLAttribute("bgcolor"); - } - - public void setBgColor(String bgColor) - { - setHTMLAttribute("bgcolor", bgColor); - } - - public String getBorder() - { - return getHTMLAttribute("border"); - } - - public void setBorder(String border) - { - setHTMLAttribute("border", border); - } - - public String getCellPadding() - { - return getHTMLAttribute("cellpadding"); - } - - public void setCellPadding(String cellPadding) - { - setHTMLAttribute("cellpadding", cellPadding); - } - - public String getCellSpacing() - { - return getHTMLAttribute("cellspacing"); - } - - public void setCellSpacing(String cellSpacing) - { - setHTMLAttribute("cellspacing", cellSpacing); - } - - public String getFrame() - { - return getHTMLAttribute("frame"); - } - - public void setFrame(String frame) - { - setHTMLAttribute("frame", frame); - } - - public String getRules() - { - return getHTMLAttribute("rules"); - } - - public void setRules(String rules) - { - setHTMLAttribute("rules", rules); - } - - public String getSummary() - { - return getHTMLAttribute("summary"); - } - - public void setSummary(String summary) - { - setHTMLAttribute("summary", summary); - } - - public String getWidth() - { - return getHTMLAttribute("width"); - } - - public void setWidth(String width) - { - setHTMLAttribute("width", width); - } - - public HTMLElement createTHead() - { - HTMLTableSectionElement ref = getTHead(); - if (ref == null) - { - return (HTMLElement) getOwnerDocument().createElement("thead"); - } - else - { - return ref; - } - } - - public void deleteTHead() - { - HTMLTableSectionElement ref = getTHead(); - if (ref != null) - { - removeChild(ref); - } - } - - public HTMLElement createTFoot() - { - HTMLTableSectionElement ref = getTFoot(); - if (ref == null) - { - return (HTMLElement) getOwnerDocument().createElement("tfoot"); - } - else - { - return ref; - } - } - - public void deleteTFoot() - { - HTMLTableSectionElement ref = getTFoot(); - if (ref != null) - { - removeChild(ref); - } - } - - public HTMLElement createCaption() - { - HTMLTableCaptionElement ref = getCaption(); - if (ref == null) - { - return (HTMLElement) getOwnerDocument().createElement("caption"); - } - else - { - return ref; - } - } - - public void deleteCaption() - { - HTMLTableCaptionElement ref = getCaption(); - if (ref != null) - { - removeChild(ref); - } - } - - public HTMLElement insertRow(int index) - { - Node ref = getRow(index); - Node row = getOwnerDocument().createElement("tr"); - if (ref == null) - { - Node tbody = getChildElement("tbody"); - if (tbody == null) - { - tbody = getOwnerDocument().createElement("tfoot"); - appendChild(tbody); - } - tbody.appendChild(row); - } - else - { - ref.getParentNode().insertBefore(row, ref); - } - return (HTMLElement) row; - } - - public void deleteRow(int index) - { - Node ref = getRow(index); - if (ref == null) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - ref.getParentNode().removeChild(ref); - } - - Node getRow(final int index) - { - int i = 0; - Node thead = getChildElement("thead"); - if (thead != null) - { - for (Node ctx = thead.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (!"tr".equalsIgnoreCase(ctx.getLocalName())) - { - continue; - } - if (index == i) - { - return ctx; - } - i++; - } - } - Node tbody = getChildElement("tbody"); - if (tbody == null) - { - tbody = this; - } - for (Node ctx = tbody.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (!"tr".equalsIgnoreCase(ctx.getLocalName())) - { - continue; - } - if (index == i) - { - return ctx; - } - i++; - } - Node tfoot = getChildElement("tfoot"); - if (tfoot != null) - { - for (Node ctx = tfoot.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (!"tr".equalsIgnoreCase(ctx.getLocalName())) - { - continue; - } - if (index == i) - { - return ctx; - } - i++; - } - } - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableRowElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableRowElement.java deleted file mode 100644 index 2a1b6785a5d..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableRowElement.java +++ /dev/null @@ -1,225 +0,0 @@ -/* DomHTMLTableRowElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLElement; -import org.w3c.dom.html2.HTMLTableRowElement; - -/** - * An HTML 'TR' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableRowElement - extends DomHTMLElement - implements HTMLTableRowElement -{ - - protected DomHTMLTableRowElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public int getRowIndex() - { - return getIndex(); - } - - public int getSectionRowIndex() - { - int index = 0; - DomHTMLElement parent = (DomHTMLElement) getParentElement("table"); - if (parent != null) - { - Node thead = parent.getChildElement("thead"); - if (thead != null) - { - for (Node ctx = thead.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx == this) - { - return index; - } - index++; - } - } - Node tbody = parent.getChildElement("tbody"); - if (tbody != null) - { - for (Node ctx = tbody.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx == this) - { - return index; - } - index++; - } - } - Node tfoot = parent.getChildElement("tfoot"); - if (tfoot != null) - { - for (Node ctx = tfoot.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx == this) - { - return index; - } - index++; - } - } - } - throw new DomDOMException(DOMException.NOT_FOUND_ERR); - } - - public HTMLCollection getCells() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("th"); - ret.addNodeName("td"); - ret.evaluate(); - return ret; - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getBgColor() - { - return getHTMLAttribute("bgcolor"); - } - - public void setBgColor(String bgColor) - { - setHTMLAttribute("bgcolor", bgColor); - } - - public String getCh() - { - return getHTMLAttribute("char"); - } - - public void setCh(String ch) - { - setHTMLAttribute("char", ch); - } - - public String getChOff() - { - return getHTMLAttribute("charoff"); - } - - public void setChOff(String chOff) - { - setHTMLAttribute("charoff", chOff); - } - - public String getVAlign() - { - return getHTMLAttribute("valign"); - } - - public void setVAlign(String vAlign) - { - setHTMLAttribute("valign", vAlign); - } - - public HTMLElement insertCell(int index) - { - Node ref = getCell(index); - Node cell = getOwnerDocument().createElement("td"); - if (ref == null) - { - appendChild(cell); - } - else - { - insertBefore(cell, ref); - } - return (HTMLElement) cell; - } - - public void deleteCell(int index) - { - Node ref = getCell(index); - if (ref == null) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - removeChild(ref); - } - - Node getCell(final int index) - { - int i = 0; - for (Node ctx = getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - String name = ctx.getLocalName(); - if (!"td".equalsIgnoreCase(name) && - !"th".equalsIgnoreCase(name)) - { - continue; - } - if (index == i) - { - return ctx; - } - i++; - } - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTableSectionElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTableSectionElement.java deleted file mode 100644 index 79cce67feeb..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTableSectionElement.java +++ /dev/null @@ -1,158 +0,0 @@ -/* DomHTMLTableSectionElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import gnu.xml.dom.DomDOMException; -import org.w3c.dom.DOMException; -import org.w3c.dom.Node; -import org.w3c.dom.html2.HTMLCollection; -import org.w3c.dom.html2.HTMLElement; -import org.w3c.dom.html2.HTMLTableSectionElement; - -/** - * An HTML 'THEAD', 'TFOOT', or 'TBODY' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTableSectionElement - extends DomHTMLElement - implements HTMLTableSectionElement -{ - - protected DomHTMLTableSectionElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getAlign() - { - return getHTMLAttribute("align"); - } - - public void setAlign(String align) - { - setHTMLAttribute("align", align); - } - - public String getCh() - { - return getHTMLAttribute("char"); - } - - public void setCh(String ch) - { - setHTMLAttribute("char", ch); - } - - public String getChOff() - { - return getHTMLAttribute("charoff"); - } - - public void setChOff(String chOff) - { - setHTMLAttribute("charoff", chOff); - } - - public String getVAlign() - { - return getHTMLAttribute("valign"); - } - - public void setVAlign(String vAlign) - { - setHTMLAttribute("valign", vAlign); - } - - public HTMLCollection getRows() - { - DomHTMLCollection ret = - new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); - ret.addNodeName("tr"); - ret.evaluate(); - return ret; - } - - public HTMLElement insertRow(int index) - { - Node ref = getRow(index); - Node row = getOwnerDocument().createElement("tr"); - if (ref == null) - { - appendChild(row); - } - else - { - insertBefore(row, ref); - } - return (HTMLElement) row; - } - - public void deleteRow(int index) - { - Node ref = getRow(index); - if (ref == null) - { - throw new DomDOMException(DOMException.INDEX_SIZE_ERR); - } - removeChild(ref); - } - - Node getRow(final int index) - { - int i = 0; - for (Node ctx = getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (!"tr".equalsIgnoreCase(ctx.getLocalName())) - { - continue; - } - if (index == i) - { - return ctx; - } - i++; - } - return null; - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTextAreaElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTextAreaElement.java deleted file mode 100644 index 22d6105696f..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTextAreaElement.java +++ /dev/null @@ -1,182 +0,0 @@ -/* DomHTMLTextAreaElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLFormElement; -import org.w3c.dom.html2.HTMLTextAreaElement; - -/** - * An HTML 'TEXTAREA' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTextAreaElement - extends DomHTMLElement - implements HTMLTextAreaElement -{ - - protected String value; - - protected DomHTMLTextAreaElement(DomHTMLDocument owner, - String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getDefaultValue() - { - return getHTMLAttribute("value"); - } - - public void setDefaultValue(String defaultValue) - { - setHTMLAttribute("value", defaultValue); - } - - public HTMLFormElement getForm() - { - return (HTMLFormElement) getParentElement("form"); - } - - public String getAccessKey() - { - return getHTMLAttribute("accesskey"); - } - - public void setAccessKey(String accessKey) - { - setHTMLAttribute("accesskey", accessKey); - } - - public int getCols() - { - return getIntHTMLAttribute("cols"); - } - - public void setCols(int cols) - { - setIntHTMLAttribute("cols", cols); - } - - public boolean getDisabled() - { - return getBooleanHTMLAttribute("disabled"); - } - - public void setDisabled(boolean disabled) - { - setBooleanHTMLAttribute("disabled", disabled); - } - - public String getName() - { - return getHTMLAttribute("name"); - } - - public void setName(String name) - { - setHTMLAttribute("name", name); - } - - public boolean getReadOnly() - { - return getBooleanHTMLAttribute("readOnly"); - } - - public void setReadOnly(boolean readOnly) - { - setBooleanHTMLAttribute("readonly", readOnly); - } - - public int getRows() - { - return getIntHTMLAttribute("rows"); - } - - public void setRows(int rows) - { - setIntHTMLAttribute("rows", rows); - } - - public int getTabIndex() - { - return getIntHTMLAttribute("tabindex"); - } - - public void setTabIndex(int tabIndex) - { - setIntHTMLAttribute("tabindex", tabIndex); - } - - public String getType() - { - return "textarea"; - } - - public String getValue() - { - if (value == null) - { - value = getDefaultValue(); - } - return value; - } - - public void setValue(String value) - { - this.value = value; - } - - public void blur() - { - dispatchUIEvent("blur"); - } - - public void focus() - { - dispatchUIEvent("focus"); - } - - public void select() - { - dispatchUIEvent("select"); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLTitleElement.java b/libjava/gnu/xml/dom/html2/DomHTMLTitleElement.java deleted file mode 100644 index f62342d6ff5..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLTitleElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* DomHTMLTitleElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLTitleElement; - -/** - * An HTML 'TITLE' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLTitleElement - extends DomHTMLElement - implements HTMLTitleElement -{ - - protected DomHTMLTitleElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public String getText() - { - return getTextContent(); - } - - public void setText(String text) - { - setTextContent(text); - } - -} - diff --git a/libjava/gnu/xml/dom/html2/DomHTMLUListElement.java b/libjava/gnu/xml/dom/html2/DomHTMLUListElement.java deleted file mode 100644 index c07adeabf20..00000000000 --- a/libjava/gnu/xml/dom/html2/DomHTMLUListElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* DomHTMLUListElement.java -- - Copyright (C) 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.html2; - -import org.w3c.dom.html2.HTMLUListElement; - -/** - * An HTML 'UL' element node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomHTMLUListElement - extends DomHTMLElement - implements HTMLUListElement -{ - - protected DomHTMLUListElement(DomHTMLDocument owner, String namespaceURI, - String name) - { - super(owner, namespaceURI, name); - } - - public boolean getCompact() - { - return getBooleanHTMLAttribute("compact"); - } - - public void setCompact(boolean compact) - { - setBooleanHTMLAttribute("compact", compact); - } - - public String getType() - { - return getHTMLAttribute("type"); - } - - public void setType(String type) - { - setHTMLAttribute("type", type); - } - -} - diff --git a/libjava/gnu/xml/dom/ls/DomLSException.java b/libjava/gnu/xml/dom/ls/DomLSException.java deleted file mode 100644 index 6ac49e66934..00000000000 --- a/libjava/gnu/xml/dom/ls/DomLSException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* DomLSException.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import org.w3c.dom.ls.LSException; - -/** - * A DOM LS exception incorporating a cause. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomLSException - extends LSException -{ - - public DomLSException(short type, Exception cause) - { - super(type, (cause == null) ? null : cause.getMessage()); - initCause(cause); - } - -} diff --git a/libjava/gnu/xml/dom/ls/DomLSInput.java b/libjava/gnu/xml/dom/ls/DomLSInput.java deleted file mode 100644 index 44274ec4734..00000000000 --- a/libjava/gnu/xml/dom/ls/DomLSInput.java +++ /dev/null @@ -1,158 +0,0 @@ -/* DomLSInput.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import org.w3c.dom.ls.LSInput; - -/** - * Specification of XML input to parse. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomLSInput - implements LSInput -{ - - private InputStream in; - private String systemId; - private String publicId; - private String baseURI; - private String encoding; - private boolean certifiedText; - - public Reader getCharacterStream() - { - return new InputStreamReader(in); - } - - public void setCharacterStream(Reader characterStream) - { - in = new ReaderInputStream(characterStream); - } - - public InputStream getByteStream() - { - return in; - } - - public void setByteStream(InputStream byteStream) - { - in = byteStream; - } - - public String getStringData() - { - StringBuffer acc = new StringBuffer(); - Reader reader = getCharacterStream(); - try - { - char[] buf = new char[4096]; - for (int len = reader.read(buf); len != -1; len = reader.read(buf)) - { - acc.append(buf, 0, len); - } - } - catch (IOException e) - { - return null; // ? - } - return acc.toString(); - } - - public void setStringData(String stringData) - { - in = new ReaderInputStream(new StringReader(stringData)); - } - - public String getSystemId() - { - return systemId; - } - - public void setSystemId(String systemId) - { - this.systemId = systemId; - } - - public String getPublicId() - { - return publicId; - } - - public void setPublicId(String publicId) - { - this.publicId = publicId; - } - - public String getBaseURI() - { - return baseURI; - } - - public void setBaseURI(String baseURI) - { - this.baseURI = baseURI; - } - - public String getEncoding() - { - return encoding; - } - - public void setEncoding(String encoding) - { - this.encoding = encoding; - } - - public boolean getCertifiedText() - { - return certifiedText; - } - - public void setCertifiedText(boolean certifiedText) - { - this.certifiedText = certifiedText; - } - -} - diff --git a/libjava/gnu/xml/dom/ls/DomLSOutput.java b/libjava/gnu/xml/dom/ls/DomLSOutput.java deleted file mode 100644 index c2f4d4132ce..00000000000 --- a/libjava/gnu/xml/dom/ls/DomLSOutput.java +++ /dev/null @@ -1,98 +0,0 @@ -/* DomLSOutput.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import org.w3c.dom.ls.LSOutput; - -/** - * Specification of XML output to produce. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomLSOutput - implements LSOutput -{ - - private OutputStream out; - private String systemId; - private String encoding; - - public Writer getCharacterStream() - { - return new OutputStreamWriter(out); - } - - public void setCharacterStream(Writer characterStream) - { - out = new WriterOutputStream(characterStream); - } - - public OutputStream getByteStream() - { - return out; - } - - public void setByteStream(OutputStream out) - { - this.out = out; - } - - public String getSystemId() - { - return systemId; - } - - public void setSystemId(String systemId) - { - this.systemId = systemId; - } - - public String getEncoding() - { - return encoding; - } - - public void setEncoding(String encoding) - { - this.encoding = encoding; - } - -} diff --git a/libjava/gnu/xml/dom/ls/DomLSParser.java b/libjava/gnu/xml/dom/ls/DomLSParser.java deleted file mode 100644 index eb7c1c49f3a..00000000000 --- a/libjava/gnu/xml/dom/ls/DomLSParser.java +++ /dev/null @@ -1,574 +0,0 @@ -/* DomLSParser.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.File; -import java.io.InputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.List; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.w3c.dom.Document; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMStringList; -import org.w3c.dom.Node; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSException; -import org.w3c.dom.ls.LSInput; -import org.w3c.dom.ls.LSParser; -import org.w3c.dom.ls.LSParserFilter; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import gnu.xml.dom.DomDocument; -import gnu.xml.dom.DomDOMException; - -/** - * Parser implementation for GNU DOM. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomLSParser - implements LSParser, DOMConfiguration, DOMStringList, ErrorHandler -{ - - private static final List SUPPORTED_PARAMETERS - = Arrays.asList(new String[] { "cdata-sections", - "comments", - "element-content-whitespace", - "namespaces", - "expand-entity-references", - "coalescing", - "validating", - "xinclude-aware", - "entity-resolver", - "error-handler" }); - - private LSParserFilter filter; - private final boolean async; - private String schemaType; - private SAXEventSink eventSink; - private SAXParserFactory factory; - private XMLReader reader; - - private boolean namespaceAware = true; - private boolean ignoreWhitespace; - private boolean expandEntityReferences; - private boolean ignoreComments; - private boolean coalescing; - private boolean validating; - private boolean xIncludeAware; - private EntityResolver entityResolver; - private ErrorHandler errorHandler; - - public DomLSParser(short mode, String schemaType) - throws DOMException - { - switch (mode) - { - case DOMImplementationLS.MODE_ASYNCHRONOUS: - async = true; - break; - case DOMImplementationLS.MODE_SYNCHRONOUS: - async = false; - break; - default: - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - // TODO schemaType - this.schemaType = schemaType; - factory = SAXParserFactory.newInstance(); - } - - // -- LSParser -- - - public DOMConfiguration getDomConfig() - { - return this; - } - - public LSParserFilter getFilter() - { - return filter; - } - - public void setFilter(LSParserFilter filter) - { - this.filter = filter; - } - - public boolean getAsync() - { - return async; - } - - public boolean getBusy() - { - return eventSink != null; - } - - public Document parse(LSInput input) - throws DOMException, LSException - { - if (async) - { - return doParse(input); - } - else - { - synchronized (this) - { - return doParse(input); - } - } - } - - public Document parseURI(String uri) - throws DOMException, LSException - { - LSInput input = new DomLSInput(); - input.setSystemId(uri); - return parse(input); - } - - public Node parseWithContext(LSInput input, Node context, short action) - throws DOMException, LSException - { - Document doc = (context.getNodeType() == Node.DOCUMENT_NODE) ? - (Document) context : context.getOwnerDocument(); - input.setBaseURI(doc.getDocumentURI()); - // TODO use namespaces defined on context node - Document ret = parse(input); - Node root = ret.getDocumentElement(); - root = doc.adoptNode(root); - switch (action) - { - case ACTION_APPEND_AS_CHILDREN: - context.appendChild(root); - break; - case ACTION_REPLACE_CHILDREN: - Node c1 = context.getFirstChild(); - while (c1 != null) - { - Node next = c1.getNextSibling(); - context.removeChild(c1); - c1 = next; - } - context.appendChild(root); - break; - case ACTION_INSERT_BEFORE: - Node p1 = context.getParentNode(); - p1.insertBefore(root, context); - break; - case ACTION_INSERT_AFTER: - Node p2 = context.getParentNode(); - Node r1 = context.getNextSibling(); - if (r1 == null) - { - p2.appendChild(root); - } - else - { - p2.insertBefore(root, r1); - } - break; - case ACTION_REPLACE: - Node p3 = context.getParentNode(); - Node r2 = context.getNextSibling(); - p3.removeChild(context); - if (r2 == null) - { - p3.appendChild(root); - } - else - { - p3.insertBefore(root, r2); - } - break; - } - return root; - } - - public void abort() - { - if (eventSink != null) - { - eventSink.interrupt(); - } - } - - private Document doParse(LSInput input) - throws DOMException, LSException - { - // create event sink - if (eventSink != null) - { - throw new LSException(LSException.PARSE_ERR, "parse in progress"); - } - InputSource source = getInputSource(input); - eventSink = (filter == null) ? new SAXEventSink() : - new FilteredSAXEventSink(filter); - // configure sink - eventSink.namespaceAware = namespaceAware; - eventSink.ignoreWhitespace = ignoreWhitespace; - eventSink.expandEntityReferences = expandEntityReferences; - eventSink.ignoreComments = ignoreComments; - eventSink.coalescing = coalescing; - // get and configure reader - XMLReader reader = getXMLReader(); - try - { - reader.setContentHandler(eventSink); - reader.setDTDHandler(eventSink); - reader.setProperty("http://xml.org/sax/properties/lexical-handler", - eventSink); - reader.setProperty("http://xml.org/sax/properties/declaration-handler", - eventSink); - reader.setFeature("http://xml.org/sax/features/namespaces", - namespaceAware); - reader.setFeature("http://xml.org/sax/features/namespace-prefixes", - true); - reader.setFeature("http://xml.org/sax/features/validation", - validating); - try - { - reader.setFeature("http://xml.org/sax/features/use-attributes2", - true); - } - catch (SAXNotRecognizedException e) - { - // ignore - } - try - { - reader.setFeature("http://xml.org/sax/features/external-general-entities", - true); - } - catch (SAXNotRecognizedException e) - { - // ignore - } - reader.setEntityResolver(entityResolver); - reader.setErrorHandler(errorHandler); - // parse - reader.parse(source); - } - catch (DOMException e) - { - reader = null; - eventSink = null; - throw e; - } - catch (SAXException e) - { - reader = null; - eventSink = null; - throw new DomLSException(LSException.PARSE_ERR, e); - } - catch (IOException e) - { - reader = null; - eventSink = null; - throw new DomLSException(LSException.PARSE_ERR, e); - } - // return document - Document ret = eventSink.doc; - String systemId = input.getSystemId(); - if (systemId != null && ret instanceof DomDocument) - { - ((DomDocument) ret).setDocumentURI(systemId); - } - eventSink = null; - return ret; - } - - private XMLReader getXMLReader() - throws LSException - { - if (reader == null) - { - factory.setNamespaceAware(namespaceAware); - factory.setValidating(validating); - factory.setXIncludeAware(xIncludeAware); - try - { - SAXParser parser = factory.newSAXParser(); - reader = parser.getXMLReader(); - } - catch (ParserConfigurationException e) - { - throw new DomLSException(LSException.PARSE_ERR, e); - } - catch (SAXException e) - { - throw new DomLSException(LSException.PARSE_ERR, e); - } - } - return reader; - } - - private InputSource getInputSource(LSInput input) - throws LSException - { - InputSource source = null; - String systemId = input.getSystemId(); - InputStream in = input.getByteStream(); - if (in != null) - { - source = new InputSource(in); - source.setSystemId(systemId); - } - if (source == null && entityResolver != null) - { - String publicId = input.getPublicId(); - try - { - source = entityResolver.resolveEntity(publicId, systemId); - } - catch (SAXException e) - { - throw new DomLSException(LSException.PARSE_ERR, e); - } - catch (IOException e) - { - throw new DomLSException(LSException.PARSE_ERR, e); - } - } - if (source == null) - { - URL url = null; - String base = input.getBaseURI(); - try - { - try - { - URL baseURL = (base == null) ? null : new URL(base); - url = (baseURL == null) ? new URL(systemId) : - new URL(baseURL, systemId); - } - catch (MalformedURLException e) - { - File baseFile = (base == null) ? null : new File(base); - url = (baseFile == null) ? new File(systemId).toURL() : - new File(baseFile, systemId).toURL(); - } - in = url.openStream(); - systemId = url.toString(); - source = new InputSource(in); - source.setSystemId(systemId); - } - catch (IOException e) - { - throw new DomLSException(LSException.PARSE_ERR, e); - } - } - return source; - } - - // -- DOMConfiguration -- - - public void setParameter(String name, Object value) - throws DOMException - { - name = name.toLowerCase(); - if ("cdata-sections".equals(name)) - { - coalescing = !((Boolean) value).booleanValue(); - } - else if ("comments".equals(name)) - { - ignoreComments = !((Boolean) value).booleanValue(); - } - else if ("element-content-whitespace".equals(name)) - { - ignoreWhitespace = !((Boolean) value).booleanValue(); - } - else if ("namespaces".equals(name)) - { - namespaceAware = ((Boolean) value).booleanValue(); - } - else if ("expand-entity-references".equals(name)) - { - expandEntityReferences = ((Boolean) value).booleanValue(); - } - else if ("coalescing".equals(name)) - { - coalescing = ((Boolean) value).booleanValue(); - } - else if ("validating".equals(name)) - { - validating = ((Boolean) value).booleanValue(); - } - else if ("xinclude-aware".equals(name)) - { - xIncludeAware = ((Boolean) value).booleanValue(); - } - else if ("entity-resolver".equals(name)) - { - entityResolver = (EntityResolver) value; - } - else if ("error-handler".equals(name)) - { - errorHandler = (ErrorHandler) value; - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - // invalidate reader, a new one will be created - reader = null; - } - - public Object getParameter(String name) - throws DOMException - { - name = name.toLowerCase(); - if ("cdata-sections".equals(name)) - { - return coalescing ? Boolean.FALSE : Boolean.TRUE; - } - else if ("comments".equals(name)) - { - return ignoreComments ? Boolean.FALSE : Boolean.TRUE; - } - else if ("element-content-whitespace".equals(name)) - { - return ignoreWhitespace ? Boolean.FALSE : Boolean.TRUE; - } - else if ("namespaces".equals(name)) - { - return namespaceAware ? Boolean.TRUE : Boolean.FALSE; - } - else if ("expand-entity-references".equals(name)) - { - return expandEntityReferences ? Boolean.TRUE : Boolean.FALSE; - } - else if ("coalescing".equals(name)) - { - return coalescing ? Boolean.TRUE : Boolean.FALSE; - } - else if ("validating".equals(name)) - { - return validating ? Boolean.TRUE : Boolean.FALSE; - } - else if ("xinclude-aware".equals(name)) - { - return xIncludeAware ? Boolean.TRUE : Boolean.FALSE; - } - else if ("entity-resolver".equals(name)) - { - return entityResolver; - } - else if ("error-handler".equals(name)) - { - return errorHandler; - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - } - - public boolean canSetParameter(String name, Object value) - { - return contains(name); - } - - public DOMStringList getParameterNames() - { - return this; - } - - // -- DOMStringList -- - - public String item(int i) - { - return (String) SUPPORTED_PARAMETERS.get(i); - } - - public int getLength() - { - return SUPPORTED_PARAMETERS.size(); - } - - public boolean contains(String str) - { - return SUPPORTED_PARAMETERS.contains(str); - } - - // -- ErrorHandler -- - - public void warning(SAXParseException e) - throws SAXException - { - if (errorHandler != null) - { - errorHandler.warning(e); - } - } - - public void error(SAXParseException e) - throws SAXException - { - if (errorHandler != null) - { - errorHandler.error(e); - } - } - - public void fatalError(SAXParseException e) - throws SAXException - { - if (errorHandler != null) - { - errorHandler.fatalError(e); - } - abort(); - } - -} - diff --git a/libjava/gnu/xml/dom/ls/DomLSSerializer.java b/libjava/gnu/xml/dom/ls/DomLSSerializer.java deleted file mode 100644 index cedaf151e70..00000000000 --- a/libjava/gnu/xml/dom/ls/DomLSSerializer.java +++ /dev/null @@ -1,354 +0,0 @@ -/* DomLSSerializer.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.StringWriter; -import java.io.Writer; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; -import java.util.List; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMStringList; -import org.w3c.dom.Node; -import org.w3c.dom.ls.LSException; -import org.w3c.dom.ls.LSOutput; -import org.w3c.dom.ls.LSSerializer; -import org.w3c.dom.ls.LSSerializerFilter; -import org.w3c.dom.traversal.NodeFilter; -import gnu.xml.dom.DomDOMException; -import gnu.xml.transform.StreamSerializer; - -/** - * Serialize a DOM node to a stream. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DomLSSerializer - extends StreamSerializer - implements LSSerializer, DOMConfiguration, DOMStringList -{ - - private static final List SUPPORTED_PARAMETERS = - Arrays.asList(new String[] {"discard-default-content", - "xml-declaration"}); - - private LSSerializerFilter filter; - private StreamSerializer serializer; - - public DomLSSerializer() - { - super(); - discardDefaultContent = true; - } - - // -- LSSerializer -- - - public DOMConfiguration getDomConfig() - { - return this; - } - - public String getNewLine() - { - return eol; - } - - public void setNewLine(String newLine) - { - if (newLine == null) - { - newLine = System.getProperty("line.separator"); - } - eol = newLine; - } - - public LSSerializerFilter getFilter() - { - return filter; - } - - public void setFilter(LSSerializerFilter filter) - { - this.filter = filter; - } - - public boolean write(Node node, LSOutput output) - throws LSException - { - OutputStream out = output.getByteStream(); - try - { - if (out == null) - { - String systemId = output.getSystemId(); - try - { - URL url = new URL(systemId); - URLConnection connection = url.openConnection(); - connection.setDoOutput(true); - if (connection instanceof HttpURLConnection) - { - ((HttpURLConnection) connection).setRequestMethod("PUT"); - } - out = connection.getOutputStream(); - } - catch (MalformedURLException e) - { - File file = new File(systemId); - out = new FileOutputStream(file); - } - } - serialize(node, out); - out.flush(); - return true; - } - catch (IOException e) - { - throw new DomLSException(LSException.SERIALIZE_ERR, e); - } - } - - public boolean writeToURI(Node node, String uri) - throws LSException - { - LSOutput output = new DomLSOutput(); - output.setSystemId(uri); - return write(node, output); - } - - public String writeToString(Node node) - throws DOMException, LSException - { - Writer writer = new StringWriter(); - LSOutput output = new DomLSOutput(); - output.setCharacterStream(writer); - write(node, output); - return writer.toString(); - } - - public void serialize(Node node, OutputStream out) - throws IOException - { - if (filter == null) - { - super.serialize(node, out); - } - else - { - int wts = filter.getWhatToShow(); - if (wts != NodeFilter.SHOW_ALL) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - if ((wts & NodeFilter.SHOW_ATTRIBUTE) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.TEXT_NODE: - if ((wts & NodeFilter.SHOW_TEXT) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.ELEMENT_NODE: - if ((wts & NodeFilter.SHOW_ELEMENT) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.CDATA_SECTION_NODE: - if ((wts & NodeFilter.SHOW_CDATA_SECTION) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.COMMENT_NODE: - if ((wts & NodeFilter.SHOW_COMMENT) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.DOCUMENT_NODE: - if ((wts & NodeFilter.SHOW_DOCUMENT) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.DOCUMENT_TYPE_NODE: - if ((wts & NodeFilter.SHOW_DOCUMENT_TYPE) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.PROCESSING_INSTRUCTION_NODE: - if ((wts & NodeFilter.SHOW_PROCESSING_INSTRUCTION) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.DOCUMENT_FRAGMENT_NODE: - if ((wts & NodeFilter.SHOW_DOCUMENT_FRAGMENT) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.ENTITY_NODE: - if ((wts & NodeFilter.SHOW_ENTITY) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.ENTITY_REFERENCE_NODE: - if ((wts & NodeFilter.SHOW_ENTITY_REFERENCE) == 0) - { - super.serialize(node, out); - return; - } - break; - case Node.NOTATION_NODE: - if ((wts & NodeFilter.SHOW_NOTATION) == 0) - { - super.serialize(node, out); - return; - } - break; - } - } - switch (filter.acceptNode(node)) - { - case NodeFilter.FILTER_ACCEPT: - super.serialize(node, out); - break; - case NodeFilter.FILTER_REJECT: - break; - case NodeFilter.FILTER_SKIP: - Node first = node.getFirstChild(); - if (first != null) - { - serialize(first, out); - } - break; - } - } - } - - // -- DOMConfiguration -- - - public void setParameter(String name, Object value) - throws DOMException - { - if ("discard-default-content".equals(name)) - { - discardDefaultContent = "true".equals(value.toString()); - } - else if ("xml-declaration".equals(name)) - { - xmlDeclaration = "false".equals(value.toString()); - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - } - - public Object getParameter(String name) - throws DOMException - { - if ("discard-default-content".equals(name)) - { - return discardDefaultContent ? "true" : "false"; - } - else if ("xml-declaration".equals(name)) - { - return xmlDeclaration ? "true" : "false"; - } - else - { - throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR); - } - } - - public boolean canSetParameter(String name, Object value) - { - return contains(name); - } - - public DOMStringList getParameterNames() - { - return this; - } - - // -- DOMStringList -- - - public String item(int i) - { - return (String) SUPPORTED_PARAMETERS.get(i); - } - - public int getLength() - { - return SUPPORTED_PARAMETERS.size(); - } - - public boolean contains(String str) - { - return SUPPORTED_PARAMETERS.contains(str); - } - -} - diff --git a/libjava/gnu/xml/dom/ls/FilteredSAXEventSink.java b/libjava/gnu/xml/dom/ls/FilteredSAXEventSink.java deleted file mode 100644 index 1c99ee524fa..00000000000 --- a/libjava/gnu/xml/dom/ls/FilteredSAXEventSink.java +++ /dev/null @@ -1,354 +0,0 @@ -/* FilteredSAXEventSink.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.util.LinkedList; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import org.w3c.dom.ls.LSParserFilter; -import org.w3c.dom.traversal.NodeFilter; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * A SAX event sink that calls out to a parser filter in order to decide - * whether to insert nodes into the tree. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class FilteredSAXEventSink - extends SAXEventSink -{ - - final LSParserFilter filter; - final int whatToShow; - - /** - * Stack of elements to insert. - */ - LinkedList nodes; - - /** - * Corresponding stack of filter decisions about the nodes. - */ - LinkedList decisions; - - /** - * True when rejecting child nodes. - */ - boolean rejecting; - - FilteredSAXEventSink(LSParserFilter filter) - { - this.filter = filter; - whatToShow = filter.getWhatToShow(); - } - - public void startDocument() - throws SAXException - { - if (interrupted) - { - return; - } - nodes = new LinkedList(); - decisions = new LinkedList(); - - super.startDocument(); - } - - public void endDocument() - throws SAXException - { - if (interrupted) - { - return; - } - super.endDocument(); - - switch (getDecision(ctx, false)) - { - case LSParserFilter.FILTER_REJECT: - ctx = null; - doc = null; - break; - } - - nodes = null; - decisions = null; - } - - public void startElement(String uri, String localName, String qName, - Attributes atts) - throws SAXException - { - if (rejecting || interrupted) - { - return; - } - Element element = createElement(uri, localName, qName, atts); - ctx = element; - - short decision = getDecision(element, true); - nodes.addLast(element); - decisions.addLast(new Short(decision)); - - switch (decision) - { - case LSParserFilter.FILTER_REJECT: - rejecting = true; - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - protected Attr createAttr(Attributes atts, int index) - { - Attr attr = super.createAttr(atts, index); - short decision = getDecision(attr, false); - switch (decision) - { - case LSParserFilter.FILTER_REJECT: - return null; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - return null; - } - return attr; - } - - public void endElement(String uri, String localName, String qName) - throws SAXException - { - if (rejecting || interrupted) - { - return; - } - super.endElement(uri, localName, qName); - - Element element = (Element) nodes.removeLast(); - Node parent = nodes.isEmpty() ? doc : (Node) nodes.getLast(); - ctx = parent; - short decision = ((Short) decisions.removeLast()).shortValue(); - switch (decision) - { - case LSParserFilter.FILTER_SKIP: - // Add all children of element to parent - for (Node child = element.getFirstChild(); child != null; - child = child.getNextSibling()) - { - parent.insertBefore(child, element); - } - return; - case LSParserFilter.FILTER_REJECT: - rejecting = false; - break; - } - decision = getDecision(element, false); - switch (decision) - { - case LSParserFilter.FILTER_ACCEPT: - parent.appendChild(element); - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - public void characters(char[] c, int off, int len) - throws SAXException - { - if (rejecting || interrupted) - { - return; - } - Text text = createText(c, off, len); - short decision = getDecision(text, false); - switch (decision) - { - case LSParserFilter.FILTER_ACCEPT: - ctx.appendChild(text); - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - public void processingInstruction(String target, String data) - throws SAXException - { - if (rejecting || interrupted || inDTD) - { - return; - } - Node pi = createProcessingInstruction(target, data); - short decision = getDecision(pi, false); - switch (decision) - { - case LSParserFilter.FILTER_ACCEPT: - ctx.appendChild(pi); - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - public void startDTD(String name, String publicId, String systemId) - throws SAXException - { - if (interrupted) - { - return; - } - Node doctype = createDocumentType(name, publicId, systemId); - ctx = doctype; - inDTD = true; - nodes.addLast(doctype); - decisions.addLast(new Short(LSParserFilter.FILTER_ACCEPT)); - } - - public void endDTD() - throws SAXException - { - if (interrupted) - { - return; - } - Node doctype = (Node) nodes.removeLast(); - decisions.removeLast(); - inDTD = false; - ctx = doc; - short decision = getDecision(doctype, false); - switch (decision) - { - case LSParserFilter.FILTER_ACCEPT: - ctx.appendChild(doctype); - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - public void comment(char[] c, int off, int len) - throws SAXException - { - if (rejecting || interrupted || inDTD) - { - return; - } - Node comment = createComment(c, off, len); - short decision = getDecision(comment, false); - switch (decision) - { - case LSParserFilter.FILTER_ACCEPT: - ctx.appendChild(comment); - break; - case LSParserFilter.FILTER_INTERRUPT: - interrupted = true; - break; - } - } - - // TODO declarations - - short getDecision(Node node, boolean start) - { - boolean show = (whatToShow == NodeFilter.SHOW_ALL); - if (!show) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - show = ((whatToShow & NodeFilter.SHOW_ATTRIBUTE) != 0); - break; - case Node.TEXT_NODE: - show = ((whatToShow & NodeFilter.SHOW_TEXT) != 0); - break; - case Node.CDATA_SECTION_NODE: - show = ((whatToShow & NodeFilter.SHOW_CDATA_SECTION) != 0); - break; - case Node.ELEMENT_NODE: - show = ((whatToShow & NodeFilter.SHOW_ELEMENT) != 0); - break; - case Node.COMMENT_NODE: - show = ((whatToShow & NodeFilter.SHOW_COMMENT) != 0); - break; - case Node.DOCUMENT_NODE: - show = ((whatToShow & NodeFilter.SHOW_DOCUMENT) != 0); - break; - case Node.PROCESSING_INSTRUCTION_NODE: - show = ((whatToShow & NodeFilter.SHOW_PROCESSING_INSTRUCTION) != 0); - break; - case Node.DOCUMENT_FRAGMENT_NODE: - show = ((whatToShow & NodeFilter.SHOW_DOCUMENT_FRAGMENT) != 0); - break; - case Node.DOCUMENT_TYPE_NODE: - show = ((whatToShow & NodeFilter.SHOW_DOCUMENT_TYPE) != 0); - break; - case Node.ENTITY_REFERENCE_NODE: - show = ((whatToShow & NodeFilter.SHOW_ENTITY_REFERENCE) != 0); - break; - case Node.ENTITY_NODE: - show = ((whatToShow & NodeFilter.SHOW_ENTITY) != 0); - break; - case Node.NOTATION_NODE: - show = ((whatToShow & NodeFilter.SHOW_NOTATION) != 0); - break; - } - } - if (!show) - { - return LSParserFilter.FILTER_ACCEPT; - } - if (start) - { - return filter.startElement((Element) node); - } - return filter.acceptNode(node); - } - -} - diff --git a/libjava/gnu/xml/dom/ls/ReaderInputStream.java b/libjava/gnu/xml/dom/ls/ReaderInputStream.java deleted file mode 100644 index 5b41abd3d74..00000000000 --- a/libjava/gnu/xml/dom/ls/ReaderInputStream.java +++ /dev/null @@ -1,237 +0,0 @@ -/* ReaderInputStream.java -- - Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.InputStream; -import java.io.IOException; -import java.io.Reader; - -/** - * Character stream wrapper. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - * @author <a href='mailto:mark@klomp.org'>Mark Wielaard</a> - */ -public class ReaderInputStream - extends InputStream -{ - - private Reader reader; - private String encoding; - - // Holds extra spillover data if necessary - private byte extra[]; - private int pos; - - private byte extra_marked[]; - private int pos_marked; - - public ReaderInputStream(Reader reader) - { - this.reader = reader; - this.encoding = "UTF-8"; - } - - void setEncoding(String encoding) - { - this.encoding = encoding; - } - - public int read() - throws IOException - { - if (extra != null) - { - int result = extra[pos]; - pos++; - if (pos >= extra.length) - { - extra = null; - } - return result; - } - return reader.read(); - } - - public int read(byte[] b) - throws IOException - { - return read(b, 0, b.length); - } - - public int read(byte[] b, int off, int len) - throws IOException - { - if (len == 0) - { - return 0; - } - - if (extra != null) - { - int available = extra.length - pos; - int l = available < len ? available : len; - System.arraycopy(extra, 0, b, off, l); - pos += l; - if (pos >= extra.length) - { - extra = null; - } - return l; - } - - char[] c = new char[len]; - int l = reader.read(c, 0, len); - if (l == -1) - { - return -1; - } - - String s = new String(c, 0, l); - byte[] d = s.getBytes(encoding); - - int available = d.length; - int more = d.length - len; - if (more > 0) - { - extra = new byte[more]; - pos = 0; - System.arraycopy(d, len, extra, 0, more); - available -= more; - } - - System.arraycopy(d, 0, b, off, available); - return available; - } - - public void close() - throws IOException - { - reader.close(); - } - - public boolean markSupported() - { - return reader.markSupported(); - } - - public void mark(int limit) - { - if (extra != null) - { - extra_marked = new byte[extra.length]; - System.arraycopy(extra, 0, extra_marked, 0, extra.length); - pos_marked = pos; - } - else - { - extra_marked = null; - } - - try - { - // Note that this might be a bit more than asked for. - // Because we might also have the extra_marked bytes. - // That is fine (and necessary for reset() to work). - reader.mark(limit); - } - catch (IOException ioe) - { - throw new RuntimeException(ioe); - } - } - - public void reset() - throws IOException - { - extra = extra_marked; - pos = pos_marked; - extra_marked = null; - - reader.reset(); - } - - public long skip(long n) - throws IOException - { - long done = 0; - if (extra != null) - { - int available = extra.length - pos; - done = available < n ? available : n; - pos += done; - if (pos >= extra.length) - { - extra = null; - } - } - - n -= done; - if (n > 0) - { - return reader.skip(n) + done; - } - else - { - return done; - } - } - - /** - * Returns conservative number of bytes available without blocking. - * Actual number of bytes that can be read without blocking might - * be (much) bigger. - */ - public int available() - throws IOException - { - if (extra != null) - { - return pos - extra.length; - } - - return reader.ready() ? 1 : 0; - } - - public String toString() - { - return getClass().getName() + "[" + reader + ", " + encoding + "]"; - } - -} - diff --git a/libjava/gnu/xml/dom/ls/SAXEventSink.java b/libjava/gnu/xml/dom/ls/SAXEventSink.java deleted file mode 100644 index a850460b1e2..00000000000 --- a/libjava/gnu/xml/dom/ls/SAXEventSink.java +++ /dev/null @@ -1,557 +0,0 @@ -/* SAXEventSink.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import javax.xml.XMLConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Entity; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import org.xml.sax.Attributes; -import org.xml.sax.DTDHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.ext.Attributes2; -import org.xml.sax.ext.DeclHandler; -import org.xml.sax.ext.LexicalHandler; -import gnu.xml.aelfred2.ContentHandler2; -import gnu.xml.dom.DomAttr; -import gnu.xml.dom.DomDocument; -import gnu.xml.dom.DomDoctype; - -/** - * A SAX content and lexical handler used to construct a DOM document. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class SAXEventSink - implements ContentHandler2, LexicalHandler, DTDHandler, DeclHandler -{ - - private static final String XMLNS_URI = XMLConstants.XMLNS_ATTRIBUTE_NS_URI; - private static final String XMLNS_PREFIX = XMLConstants.XMLNS_ATTRIBUTE; - - boolean namespaceAware; - boolean ignoreWhitespace; - boolean expandEntityReferences; - boolean ignoreComments; - boolean coalescing; - - DomDocument doc; // document being constructed - Node ctx; // current context (parent node) - LinkedList entityCtx; // entity context - List pending; // namespace nodes waiting for a declaring element - Locator locator; - boolean inCDATA; - boolean inDTD; - boolean interrupted; - - void interrupt() - { - interrupted = true; - } - - // -- ContentHandler2 -- - - public void setDocumentLocator(Locator locator) - { - this.locator = locator; - } - - public void startDocument() - throws SAXException - { - if (namespaceAware) - { - pending = new LinkedList(); - } - doc = new DomDocument(); - doc.setStrictErrorChecking(false); - doc.setBuilding(true); - ctx = doc; - } - - public void xmlDecl(String version, String encoding, boolean standalone, - String inputEncoding) - throws SAXException - { - if (interrupted) - { - return; - } - doc.setXmlVersion(version); - doc.setXmlEncoding(encoding); - doc.setXmlStandalone(standalone); - doc.setInputEncoding(inputEncoding); - } - - public void endDocument() - throws SAXException - { - doc.setStrictErrorChecking(true); - doc.setBuilding(false); - DomDoctype doctype = (DomDoctype) doc.getDoctype(); - if (doctype != null) - { - doctype.makeReadonly(); - } - ctx = null; - locator = null; - } - - public void startPrefixMapping(String prefix, String uri) - throws SAXException - { - if (namespaceAware) - { - String nsName = (prefix != null && prefix.length() > 0) ? - XMLNS_PREFIX + ":" + prefix : XMLNS_PREFIX; - DomAttr ns = (DomAttr) doc.createAttributeNS(XMLNS_URI, nsName); - ns.setNodeValue(uri); - if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) - { - // Add to owner element - Node target = ((Attr) ctx).getOwnerElement(); - target.getAttributes().setNamedItemNS(ns); - } - else - { - // Add to pending list; namespace node will be inserted when - // element is seen - pending.add(ns); - } - } - } - - public void endPrefixMapping(String prefix) - throws SAXException - { - } - - public void startElement(String uri, String localName, String qName, - Attributes atts) - throws SAXException - { - if (interrupted) - { - return; - } - Element element = createElement(uri, localName, qName, atts); - // add element to context - ctx.appendChild(element); - ctx = element; - } - - protected Element createElement(String uri, String localName, String qName, - Attributes atts) - throws SAXException - { - // create element node - Element element = namespaceAware ? - doc.createElementNS(uri, qName) : - doc.createElement(qName); - NamedNodeMap attrs = element.getAttributes(); - if (namespaceAware && !pending.isEmpty()) - { - // add pending namespace nodes - for (Iterator i = pending.iterator(); i.hasNext(); ) - { - Node ns = (Node) i.next(); - attrs.setNamedItemNS(ns); - } - pending.clear(); - } - // add attributes - int len = atts.getLength(); - for (int i = 0; i < len; i++) - { - // create attribute - Attr attr = createAttr(atts, i); - if (attr != null) - { - // add attribute to element - if (namespaceAware) - { - attrs.setNamedItemNS(attr); - } - else - { - attrs.setNamedItem(attr); - } - } - } - return element; - } - - protected Attr createAttr(Attributes atts, int index) - { - DomAttr attr; - if (namespaceAware) - { - String a_uri = atts.getURI(index); - String a_qName = atts.getQName(index); - attr = (DomAttr) doc.createAttributeNS(a_uri, a_qName); - } - else - { - String a_qName = atts.getQName(index); - attr = (DomAttr) doc.createAttribute(a_qName); - } - attr.setNodeValue(atts.getValue(index)); - if (atts instanceof Attributes2) - { - Attributes2 atts2 = (Attributes2) atts; - // TODO attr.setDeclared(atts2.isDeclared(index)); - attr.setSpecified(atts2.isSpecified(index)); - } - return attr; - } - - public void endElement(String uri, String localName, String qName) - throws SAXException - { - if (interrupted) - { - return; - } - if (namespaceAware) - { - pending.clear(); - } - ctx = ctx.getParentNode(); - } - - public void characters(char[] c, int off, int len) - throws SAXException - { - if (interrupted) - { - return; - } - ctx.appendChild(createText(c, off, len)); - } - - protected Text createText(char[] c, int off, int len) - throws SAXException - { - Text text = (inCDATA && !coalescing) ? - doc.createCDATASection(new String(c, off, len)) : - doc.createTextNode(new String(c, off, len)); - return text; - } - - public void ignorableWhitespace(char[] c, int off, int len) - throws SAXException - { - if (interrupted) - { - return; - } - if (!ignoreWhitespace) - { - characters(c, off, len); - } - } - - public void processingInstruction(String target, String data) - throws SAXException - { - if (interrupted) - { - return; - } - if (!inDTD) - { - Node pi = createProcessingInstruction(target, data); - ctx.appendChild(pi); - } - } - - protected Node createProcessingInstruction(String target, String data) - { - return doc.createProcessingInstruction(target, data); - } - - public void skippedEntity(String name) - throws SAXException - { - // This callback is totally pointless - } - - // -- LexicalHandler -- - - public void startDTD(String name, String publicId, String systemId) - throws SAXException - { - if (interrupted) - { - return; - } - Node doctype = createDocumentType(name, publicId, systemId); - doc.appendChild(doctype); - ctx = doctype; - inDTD = true; - } - - protected Node createDocumentType(String name, String publicId, - String systemId) - { - return new DomDoctype(doc, name, publicId, systemId); - } - - public void endDTD() - throws SAXException - { - if (interrupted) - { - return; - } - inDTD = false; - ctx = ctx.getParentNode(); - } - - public void startEntity(String name) - throws SAXException - { - DocumentType doctype = doc.getDoctype(); - if (doctype == null) - { - throw new SAXException("SAX parser error: " + - "reference to entity in undeclared doctype"); - } - if ("[dtd]".equals(name) || name.charAt(0) == '%') - { - // Ignore DTD and parameter entities - ctx = doctype; - return; - } - if ("lt".equals(name) || - "gt".equals(name) || - "amp".equals(name) || - "apos".equals(name) || - "quot".equals(name)) - { - return; - } - // Get entity - NamedNodeMap entities = doctype.getEntities(); - Entity entity = (Entity) entities.getNamedItem(name); - if (entity == null) - { - throw new SAXException("SAX parser error: " + - "reference to undeclared entity: " + name); - } - pushEntity(entity); - } - - public void endEntity(String name) - throws SAXException - { - if ("[dtd]".equals(name) || name.charAt(0) == '%') - { - // Ignore DTD and parameter entities - return; - } - if ("lt".equals(name) || - "gt".equals(name) || - "amp".equals(name) || - "apos".equals(name) || - "quot".equals(name)) - { - return; - } - // Get entity - Entity entity = popEntity(); - // TODO resolve external entities to ensure that entity has content - if (expandEntityReferences) - { - // Get entity content - for (Node child = entity.getFirstChild(); child != null; - child = child.getNextSibling()) - { - ctx.appendChild(child); - } - } - else - { - Node entityReference = doc.createEntityReference(name); - ctx.appendChild(entityReference); - } - } - - void pushEntity(Node entity) - { - if (entityCtx == null) - { - entityCtx = new LinkedList(); - } - entityCtx.addLast(ctx); - ctx = entity; - } - - Entity popEntity() - { - Entity ret = (Entity) ctx; - ctx = (Node) entityCtx.removeLast(); - return ret; - } - - public void startCDATA() - throws SAXException - { - inCDATA = true; - } - - public void endCDATA() - throws SAXException - { - inCDATA = false; - } - - public void comment(char[] c, int off, int len) - throws SAXException - { - if (interrupted) - { - return; - } - if (!inDTD) - { - Node comment = createComment(c, off, len); - ctx.appendChild(comment); - } - } - - protected Node createComment(char[] c, int off, int len) - { - return doc.createComment(new String(c, off, len)); - } - - // -- DTDHandler -- - - public void notationDecl(String name, String publicId, String systemId) - throws SAXException - { - if (interrupted) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - doctype.declareNotation(name, publicId, systemId); - } - - public void unparsedEntityDecl(String name, String publicId, String systemId, - String notationName) - throws SAXException - { - if (interrupted) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - Entity entity = doctype.declareEntity(name, publicId, systemId, - notationName); - } - - // -- DeclHandler -- - - public void elementDecl(String name, String model) - throws SAXException - { - if (interrupted) - { - return; - } - // Ignore fake element declarations generated by ValidationConsumer. - // If an element is not really declared in the DTD it will not be - // declared in the document model. - if (!(ctx instanceof DomDoctype)) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - doctype.elementDecl(name, model); - } - - public void attributeDecl(String eName, String aName, String type, - String mode, String value) - throws SAXException - { - if (interrupted) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - doctype.attributeDecl(eName, aName, type, mode, value); - } - - public void internalEntityDecl(String name, String value) - throws SAXException - { - if (interrupted) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - Entity entity = doctype.declareEntity(name, null, null, null); - if (entity != null) - { - Node text = doc.createTextNode(value); - entity.appendChild(text); - } - } - - public void externalEntityDecl(String name, String publicId, String systemId) - throws SAXException - { - if (interrupted) - { - return; - } - DomDoctype doctype = (DomDoctype) ctx; - Entity entity = doctype.declareEntity(name, publicId, systemId, null); - } - -} - diff --git a/libjava/gnu/xml/dom/ls/WriterOutputStream.java b/libjava/gnu/xml/dom/ls/WriterOutputStream.java deleted file mode 100644 index 2fb20614722..00000000000 --- a/libjava/gnu/xml/dom/ls/WriterOutputStream.java +++ /dev/null @@ -1,98 +0,0 @@ -/* WriterOutputStream.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.dom.ls; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; - -/** - * Character stream wrapper. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class WriterOutputStream - extends OutputStream -{ - - private Writer writer; - private String encoding; - - public WriterOutputStream(Writer writer) - { - this.writer = writer; - this.encoding = "UTF-8"; - } - - void setEncoding(String encoding) - { - this.encoding = encoding; - } - - public void write(int c) - throws IOException - { - writer.write(c); - } - - public void write(byte[] b) - throws IOException - { - write(b, 0, b.length); - } - - public void write(byte[] b, int off, int len) - throws IOException - { - writer.write(new String(b, off, len, encoding)); - } - - public void close() - throws IOException - { - writer.close(); - } - - public void flush() - throws IOException - { - writer.flush(); - } - -} - diff --git a/libjava/gnu/xml/pipeline/CallFilter.java b/libjava/gnu/xml/pipeline/CallFilter.java deleted file mode 100644 index 3b337517377..00000000000 --- a/libjava/gnu/xml/pipeline/CallFilter.java +++ /dev/null @@ -1,257 +0,0 @@ -/* CallFilter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.net.URL; -import java.net.URLConnection; -import java.io.Writer; - -import org.xml.sax.DTDHandler; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -import gnu.xml.util.Resolver; -import gnu.xml.util.XMLWriter; - - -/** - * Input is sent as an XML request to given URI, and the output of this - * filter is the parsed response to that request. - * A connection is opened to the remote URI when the startDocument call is - * issued through this filter, and the request is finished when the - * endDocument call is issued. Events should be written quickly enough to - * prevent the remote HTTP server from aborting the connection due to - * inactivity; you may want to buffer text in an earlier pipeline stage. - * If your application requires validity checking of such - * outputs, have the output pipeline include a validation stage. - * - * <p>In effect, this makes a remote procedure call to the URI, with the - * request and response document syntax as chosen by the application. - * <em>Note that all the input events must be seen, and sent to the URI, - * before the first output event can be seen. </em> Clients are delayed - * at least by waiting for the server to respond, constraining concurrency. - * Services can thus be used to synchronize concurrent activities, and - * even to prioritize service among different clients. - * - * <p> You are advised to avoid restricting yourself to an "RPC" model - * for distributed computation. With a World Wide Web, network latencies - * and failures (e.g. non-availability) - * are significant; adopting a "procedure" model, rather than a workflow - * model where bulk requests are sent and worked on asynchronously, is not - * generally an optimal system-wide architecture. When the messages may - * need authentication, such as with an OpenPGP signature, or when server - * loads don't argue in favor of immediate responses, non-RPC models can - * be advantageous. (So-called "peer to peer" computing models are one - * additional type of model, though too often that term is applied to - * systems that still have a centralized control structure.) - * - * <p> <em>Be strict in what you send, liberal in what you accept,</em> as - * the Internet tradition goes. Strictly conformant data should never cause - * problems to its receiver; make your request pipeline be very strict, and - * don't compromise on that. Make your response pipeline strict as well, - * but be ready to tolerate specific mild, temporary, and well-documented - * variations from specific communications peers. - * - * @see XmlServlet - * - * @author David Brownell - */ -final public class CallFilter implements EventConsumer -{ - private Requestor req; - private EventConsumer next; - private URL target; - private URLConnection conn; - private ErrorHandler errHandler; - - - /** - * Initializes a call filter so that its inputs are sent to the - * specified URI, and its outputs are sent to the next consumer - * provided. - * - * @exception IOException if the URI isn't accepted as a URL - */ - // constructor used by PipelineFactory - public CallFilter (String uri, EventConsumer next) - throws IOException - { - this.next = next; - req = new Requestor (); - setCallTarget (uri); - } - - /** - * Assigns the URI of the call target to be used. - * Does not affect calls currently being made. - */ - final public void setCallTarget (String uri) - throws IOException - { - target = new URL (uri); - } - - /** - * Assigns the error handler to be used to present most fatal - * errors. - */ - public void setErrorHandler (ErrorHandler handler) - { - req.setErrorHandler (handler); - } - - - /** - * Returns the call target's URI. - */ - final public String getCallTarget () - { - return target.toString (); - } - - /** Returns the content handler currently in use. */ - final public org.xml.sax.ContentHandler getContentHandler () - { - return req; - } - - /** Returns the DTD handler currently in use. */ - final public DTDHandler getDTDHandler () - { - return req; - } - - - /** - * Returns the declaration or lexical handler currently in - * use, or throws an exception for other properties. - */ - final public Object getProperty (String id) - throws SAXNotRecognizedException - { - if (EventFilter.DECL_HANDLER.equals (id)) - return req; - if (EventFilter.LEXICAL_HANDLER.equals (id)) - return req; - throw new SAXNotRecognizedException (id); - } - - - // JDK 1.1 seems to need it to be done this way, sigh - ErrorHandler getErrorHandler () { return errHandler; } - - // - // Takes input and echoes to server as POST input. - // Then sends the POST reply to the next pipeline element. - // - final class Requestor extends XMLWriter - { - Requestor () - { - super ((Writer)null); - } - - public synchronized void startDocument () throws SAXException - { - // Connect to remote object and set up to send it XML text - try { - if (conn != null) - throw new IllegalStateException ("call is being made"); - - conn = target.openConnection (); - conn.setDoOutput (true); - conn.setRequestProperty ("Content-Type", - "application/xml;charset=UTF-8"); - - setWriter (new OutputStreamWriter ( - conn.getOutputStream (), - "UTF8"), "UTF-8"); - - } catch (IOException e) { - fatal ("can't write (POST) to URI: " + target, e); - } - - // NOW base class can safely write that text! - super.startDocument (); - } - - public void endDocument () throws SAXException - { - // - // Finish writing the request (for HTTP, a POST); - // this closes the output stream. - // - super.endDocument (); - - // - // Receive the response. - // Produce events for the next stage. - // - InputSource source; - XMLReader producer; - String encoding; - - try { - - source = new InputSource (conn.getInputStream ()); - -// FIXME if status is anything but success, report it!! It'd be good to -// save the request data just in case we need to deal with a forward. - - encoding = Resolver.getEncoding (conn.getContentType ()); - if (encoding != null) - source.setEncoding (encoding); - - producer = XMLReaderFactory.createXMLReader (); - producer.setErrorHandler (getErrorHandler ()); - EventFilter.bind (producer, next); - producer.parse (source); - conn = null; - - } catch (IOException e) { - fatal ("I/O Exception reading response, " + e.getMessage (), e); - } - } - } -} diff --git a/libjava/gnu/xml/pipeline/DomConsumer.java b/libjava/gnu/xml/pipeline/DomConsumer.java deleted file mode 100644 index 389e02bb387..00000000000 --- a/libjava/gnu/xml/pipeline/DomConsumer.java +++ /dev/null @@ -1,982 +0,0 @@ -/* DomConsumer.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import gnu.xml.aelfred2.ContentHandler2; -import gnu.xml.util.DomParser; - -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXParseException; -import org.xml.sax.ext.DeclHandler; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.AttributesImpl; -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.CharacterData; -import org.w3c.dom.Document; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Element; -import org.w3c.dom.EntityReference; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - -/** - * This consumer builds a DOM Document from its input, acting either as a - * pipeline terminus or as an intermediate buffer. When a document's worth - * of events has been delivered to this consumer, that document is read with - * a {@link DomParser} and sent to the next consumer. It is also available - * as a read-once property. - * - * <p>The DOM tree is constructed as faithfully as possible. There are some - * complications since a DOM should expose behaviors that can't be implemented - * without API backdoors into that DOM, and because some SAX parsers don't - * report all the information that DOM permits to be exposed. The general - * problem areas involve information from the Document Type Declaration (DTD). - * DOM only represents a limited subset, but has some behaviors that depend - * on much deeper knowledge of a document's DTD. You shouldn't have much to - * worry about unless you change handling of "noise" nodes from its default - * setting (which ignores them all); note if you use JAXP to populate your - * DOM trees, it wants to save "noise" nodes by default. (Such nodes include - * ignorable whitespace, comments, entity references and CDATA boundaries.) - * Otherwise, your - * main worry will be if you use a SAX parser that doesn't flag ignorable - * whitespace unless it's validating (few don't). - * - * <p> The SAX2 events used as input must contain XML Names for elements - * and attributes, with original prefixes. In SAX2, - * this is optional unless the "namespace-prefixes" parser feature is set. - * Moreover, many application components won't provide completely correct - * structures anyway. <em>Before you convert a DOM to an output document, - * you should plan to postprocess it to create or repair such namespace - * information.</em> The {@link NSFilter} pipeline stage does such work. - * - * <p> <em>Note: changes late in DOM L2 process made it impractical to - * attempt to create the DocumentType node in any implementation-neutral way, - * much less to populate it (L1 didn't support even creating such nodes). - * To create and populate such a node, subclass the inner - * {@link DomConsumer.Handler} class and teach it about the backdoors into - * whatever DOM implementation you want. It's possible that some revised - * DOM API (L3?) will make this problem solvable again. </em> - * - * @see DomParser - * - * @author David Brownell - */ -public class DomConsumer implements EventConsumer -{ - private Class domImpl; - - private boolean hidingCDATA = true; - private boolean hidingComments = true; - private boolean hidingWhitespace = true; - private boolean hidingReferences = true; - - private Handler handler; - private ErrorHandler errHandler; - - private EventConsumer next; - - // FIXME: this can't be a generic pipeline stage just now, - // since its input became a Class not a String (to be turned - // into a class, using the right class loader) - - - /** - * Configures this pipeline terminus to use the specified implementation - * of DOM when constructing its result value. - * - * @param impl class implementing {@link org.w3c.dom.Document Document} - * which publicly exposes a default constructor - * - * @exception SAXException when there is a problem creating an - * empty DOM document using the specified implementation - */ - public DomConsumer (Class impl) - throws SAXException - { - domImpl = impl; - handler = new Handler (this); - } - - /** - * This is the hook through which a subclass provides a handler - * which knows how to access DOM extensions, specific to some - * implementation, to record additional data in a DOM. - * Treat this as part of construction; don't call it except - * before (or between) parses. - */ - protected void setHandler (Handler h) - { - handler = h; - } - - - private Document emptyDocument () - throws SAXException - { - try { - return (Document) domImpl.newInstance (); - } catch (IllegalAccessException e) { - throw new SAXException ("can't access constructor: " - + e.getMessage ()); - } catch (InstantiationException e) { - throw new SAXException ("can't instantiate Document: " - + e.getMessage ()); - } - } - - - /** - * Configures this consumer as a buffer/filter, using the specified - * DOM implementation when constructing its result value. - * - * <p> This event consumer acts as a buffer and filter, in that it - * builds a DOM tree and then writes it out when <em>endDocument</em> - * is invoked. Because of the limitations of DOM, much information - * will as a rule not be seen in that replay. To get a full fidelity - * copy of the input event stream, use a {@link TeeConsumer}. - * - * @param impl class implementing {@link org.w3c.dom.Document Document} - * which publicly exposes a default constructor - * @param next receives a "replayed" sequence of parse events when - * the <em>endDocument</em> method is invoked. - * - * @exception SAXException when there is a problem creating an - * empty DOM document using the specified DOM implementation - */ - public DomConsumer (Class impl, EventConsumer n) - throws SAXException - { - this (impl); - next = n; - } - - - /** - * Returns the document constructed from the preceding - * sequence of events. This method should not be - * used again until another sequence of events has been - * given to this EventConsumer. - */ - final public Document getDocument () - { - return handler.clearDocument (); - } - - public void setErrorHandler (ErrorHandler handler) - { - errHandler = handler; - } - - - /** - * Returns true if the consumer is hiding entity references nodes - * (the default), and false if EntityReference nodes should - * instead be created. Such EntityReference nodes will normally be - * empty, unless an implementation arranges to populate them and then - * turn them back into readonly objects. - * - * @see #setHidingReferences - */ - final public boolean isHidingReferences () - { return hidingReferences; } - - /** - * Controls whether the consumer will hide entity expansions, - * or will instead mark them with entity reference nodes. - * - * @see #isHidingReferences - * @param flag False if entity reference nodes will appear - */ - final public void setHidingReferences (boolean flag) - { hidingReferences = flag; } - - - /** - * Returns true if the consumer is hiding comments (the default), - * and false if they should be placed into the output document. - * - * @see #setHidingComments - */ - public final boolean isHidingComments () - { return hidingComments; } - - /** - * Controls whether the consumer is hiding comments. - * - * @see #isHidingComments - */ - public final void setHidingComments (boolean flag) - { hidingComments = flag; } - - - /** - * Returns true if the consumer is hiding ignorable whitespace - * (the default), and false if such whitespace should be placed - * into the output document as children of element nodes. - * - * @see #setHidingWhitespace - */ - public final boolean isHidingWhitespace () - { return hidingWhitespace; } - - /** - * Controls whether the consumer hides ignorable whitespace - * - * @see #isHidingComments - */ - public final void setHidingWhitespace (boolean flag) - { hidingWhitespace = flag; } - - - /** - * Returns true if the consumer is saving CDATA boundaries, or - * false (the default) otherwise. - * - * @see #setHidingCDATA - */ - final public boolean isHidingCDATA () - { return hidingCDATA; } - - /** - * Controls whether the consumer will save CDATA boundaries. - * - * @see #isHidingCDATA - * @param flag True to treat CDATA text differently from other - * text nodes - */ - final public void setHidingCDATA (boolean flag) - { hidingCDATA = flag; } - - - - /** Returns the document handler being used. */ - final public ContentHandler getContentHandler () - { return handler; } - - /** Returns the DTD handler being used. */ - final public DTDHandler getDTDHandler () - { return handler; } - - /** - * Returns the lexical handler being used. - * (DOM construction can't really use declaration handlers.) - */ - final public Object getProperty (String id) - throws SAXNotRecognizedException - { - if ("http://xml.org/sax/properties/lexical-handler".equals (id)) - return handler; - if ("http://xml.org/sax/properties/declaration-handler".equals (id)) - return handler; - throw new SAXNotRecognizedException (id); - } - - EventConsumer getNext () { return next; } - - ErrorHandler getErrorHandler () { return errHandler; } - - /** - * Class used to intercept various parsing events and use them to - * populate a DOM document. Subclasses would typically know and use - * backdoors into specific DOM implementations, used to implement - * DTD-related functionality. - * - * <p> Note that if this ever throws a DOMException (runtime exception) - * that will indicate a bug in the DOM (e.g. doesn't support something - * per specification) or the parser (e.g. emitted an illegal name, or - * accepted illegal input data). </p> - */ - public static class Handler - implements ContentHandler2, LexicalHandler, - DTDHandler, DeclHandler - { - protected DomConsumer consumer; - - private DOMImplementation impl; - private Document document; - private boolean isL2; - - private Locator locator; - private Node top; - private boolean inCDATA; - private boolean mergeCDATA; - private boolean inDTD; - private String currentEntity; - - private boolean recreatedAttrs; - private AttributesImpl attributes = new AttributesImpl (); - - /** - * Subclasses may use SAX2 events to provide additional - * behaviors in the resulting DOM. - */ - protected Handler (DomConsumer consumer) - throws SAXException - { - this.consumer = consumer; - document = consumer.emptyDocument (); - impl = document.getImplementation (); - isL2 = impl.hasFeature ("XML", "2.0"); - } - - private void fatal (String message, Exception x) - throws SAXException - { - SAXParseException e; - ErrorHandler errHandler = consumer.getErrorHandler ();; - - if (locator == null) - e = new SAXParseException (message, null, null, -1, -1, x); - else - e = new SAXParseException (message, locator, x); - if (errHandler != null) - errHandler.fatalError (e); - throw e; - } - - /** - * Returns and forgets the document produced. If the handler is - * reused, a new document may be created. - */ - Document clearDocument () - { - Document retval = document; - document = null; - locator = null; - return retval; - } - - /** - * Returns the document under construction. - */ - protected Document getDocument () - { return document; } - - /** - * Returns the current node being populated. This is usually - * an Element or Document, but it might be an EntityReference - * node if some implementation-specific code knows how to put - * those into the result tree and later mark them as readonly. - */ - protected Node getTop () - { return top; } - - - // SAX1 - public void setDocumentLocator (Locator locator) - { - this.locator = locator; - } - - // SAX1 - public void startDocument () - throws SAXException - { - if (document == null) - try { - if (isL2) { - // couple to original implementation - document = impl.createDocument (null, "foo", null); - document.removeChild (document.getFirstChild ()); - } else { - document = consumer.emptyDocument (); - } - } catch (Exception e) { - fatal ("DOM create document", e); - } - top = document; - } - - // ContentHandler2 - public void xmlDecl(String version, - String encoding, - boolean standalone, - String inputEncoding) - throws SAXException - { - if (document != null) - { - document.setXmlVersion(version); - document.setXmlStandalone(standalone); - } - } - - // SAX1 - public void endDocument () - throws SAXException - { - try { - if (consumer.getNext () != null && document != null) { - DomParser parser = new DomParser (document); - - EventFilter.bind (parser, consumer.getNext ()); - parser.parse ("ignored"); - } - } finally { - top = null; - } - } - - // SAX1 - public void processingInstruction (String target, String data) - throws SAXException - { - // we can't create populated entity ref nodes using - // only public DOM APIs (they've got to be readonly) - if (currentEntity != null) - return; - - ProcessingInstruction pi; - - if (isL2 - // && consumer.isUsingNamespaces () - && target.indexOf (':') != -1) - namespaceError ( - "PI target name is namespace nonconformant: " - + target); - if (inDTD) - return; - pi = document.createProcessingInstruction (target, data); - top.appendChild (pi); - } - - /** - * Subclasses may overrride this method to provide a more efficient - * way to construct text nodes. - * Typically, copying the text into a single character array will - * be more efficient than doing that as well as allocating other - * needed for a String, including an internal StringBuffer. - * Those additional memory and CPU costs can be incurred later, - * if ever needed. - * Unfortunately the standard DOM factory APIs encourage those costs - * to be incurred early. - */ - protected Text createText ( - boolean isCDATA, - char ch [], - int start, - int length - ) { - String value = new String (ch, start, length); - - if (isCDATA) - return document.createCDATASection (value); - else - return document.createTextNode (value); - } - - // SAX1 - public void characters (char ch [], int start, int length) - throws SAXException - { - // we can't create populated entity ref nodes using - // only public DOM APIs (they've got to be readonly - // at creation time) - if (currentEntity != null) - return; - - Node lastChild = top.getLastChild (); - - // merge consecutive text or CDATA nodes if appropriate. - if (lastChild instanceof Text) { - if (consumer.isHidingCDATA () - // consecutive Text content ... always merge - || (!inCDATA - && !(lastChild instanceof CDATASection)) - // consecutive CDATASection content ... don't - // merge between sections, only within them - || (inCDATA && mergeCDATA - && lastChild instanceof CDATASection) - ) { - CharacterData last = (CharacterData) lastChild; - String value = new String (ch, start, length); - - last.appendData (value); - return; - } - } - if (inCDATA && !consumer.isHidingCDATA ()) { - top.appendChild (createText (true, ch, start, length)); - mergeCDATA = true; - } else - top.appendChild (createText (false, ch, start, length)); - } - - // SAX2 - public void skippedEntity (String name) - throws SAXException - { - // this callback is useless except to report errors, since - // we can't know if the ref was in content, within an - // attribute, within a declaration ... only one of those - // cases supports more intelligent action than a panic. - fatal ("skipped entity: " + name, null); - } - - // SAX2 - public void startPrefixMapping (String prefix, String uri) - throws SAXException - { - // reconstruct "xmlns" attributes deleted by all - // SAX2 parsers without "namespace-prefixes" = true - if ("".equals (prefix)) - attributes.addAttribute ("", "", "xmlns", - "CDATA", uri); - else - attributes.addAttribute ("", "", "xmlns:" + prefix, - "CDATA", uri); - recreatedAttrs = true; - } - - // SAX2 - public void endPrefixMapping (String prefix) - throws SAXException - { } - - // SAX2 - public void startElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - // we can't create populated entity ref nodes using - // only public DOM APIs (they've got to be readonly) - if (currentEntity != null) - return; - - // parser discarded basic information; DOM tree isn't writable - // without massaging to assign prefixes to all nodes. - // the "NSFilter" class does that massaging. - if (qName.length () == 0) - qName = localName; - - - Element element; - int length = atts.getLength (); - - if (!isL2) { - element = document.createElement (qName); - - // first the explicit attributes ... - length = atts.getLength (); - for (int i = 0; i < length; i++) - element.setAttribute (atts.getQName (i), - atts.getValue (i)); - // ... then any recreated ones (DOM deletes duplicates) - if (recreatedAttrs) { - recreatedAttrs = false; - length = attributes.getLength (); - for (int i = 0; i < length; i++) - element.setAttribute (attributes.getQName (i), - attributes.getValue (i)); - attributes.clear (); - } - - top.appendChild (element); - top = element; - return; - } - - // For an L2 DOM when namespace use is enabled, use - // createElementNS/createAttributeNS except when - // (a) it's an element in the default namespace, or - // (b) it's an attribute with no prefix - String namespace; - - if (localName.length () != 0) - namespace = (uri.length () == 0) ? null : uri; - else - namespace = getNamespace (getPrefix (qName), atts); - - if (namespace == null) - element = document.createElement (qName); - else - element = document.createElementNS (namespace, qName); - - populateAttributes (element, atts); - if (recreatedAttrs) { - recreatedAttrs = false; - // ... DOM deletes any duplicates - populateAttributes (element, attributes); - attributes.clear (); - } - - top.appendChild (element); - top = element; - } - - final static String xmlnsURI = "http://www.w3.org/2000/xmlns/"; - - private void populateAttributes (Element element, Attributes attrs) - throws SAXParseException - { - int length = attrs.getLength (); - - for (int i = 0; i < length; i++) { - String type = attrs.getType (i); - String value = attrs.getValue (i); - String name = attrs.getQName (i); - String local = attrs.getLocalName (i); - String uri = attrs.getURI (i); - - // parser discarded basic information, DOM tree isn't writable - if (name.length () == 0) - name = local; - - // all attribute types other than these three may not - // contain scoped names... enumerated attributes get - // reported as NMTOKEN, except for NOTATION values - if (!("CDATA".equals (type) - || "NMTOKEN".equals (type) - || "NMTOKENS".equals (type))) { - if (value.indexOf (':') != -1) { - namespaceError ( - "namespace nonconformant attribute value: " - + "<" + element.getNodeName () - + " " + name + "='" + value + "' ...>"); - } - } - - // xmlns="" is legal (undoes default NS) - // xmlns:foo="" is illegal - String prefix = getPrefix (name); - String namespace; - - if ("xmlns".equals (prefix)) { - if ("".equals (value)) - namespaceError ("illegal null namespace decl, " + name); - namespace = xmlnsURI; - } else if ("xmlns".equals (name)) - namespace = xmlnsURI; - - else if (prefix == null) - namespace = null; - else if (!"".equals(uri) && uri.length () != 0) - namespace = uri; - else - namespace = getNamespace (prefix, attrs); - - if (namespace == null) - element.setAttribute (name, value); - else - element.setAttributeNS (namespace, name, value); - } - } - - private String getPrefix (String name) - { - int temp; - - if ((temp = name.indexOf (':')) > 0) - return name.substring (0, temp); - return null; - } - - // used with SAX1-level parser output - private String getNamespace (String prefix, Attributes attrs) - throws SAXParseException - { - String namespace; - String decl; - - // defaulting - if (prefix == null) { - decl = "xmlns"; - namespace = attrs.getValue (decl); - if ("".equals (namespace)) - return null; - else if (namespace != null) - return namespace; - - // "xmlns" is like a keyword - // ... according to the Namespace REC, but DOM L2 CR2+ - // and Infoset violate that by assigning a namespace. - // that conflict is resolved elsewhere. - } else if ("xmlns".equals (prefix)) - return null; - - // "xml" prefix is fixed - else if ("xml".equals (prefix)) - return "http://www.w3.org/XML/1998/namespace"; - - // otherwise, expect a declaration - else { - decl = "xmlns:" + prefix; - namespace = attrs.getValue (decl); - } - - // if we found a local declaration, great - if (namespace != null) - return namespace; - - - // ELSE ... search up the tree we've been building - for (Node n = top; - n != null && n.getNodeType () != Node.DOCUMENT_NODE; - n = (Node) n.getParentNode ()) { - if (n.getNodeType () == Node.ENTITY_REFERENCE_NODE) - continue; - Element e = (Element) n; - Attr attr = e.getAttributeNode (decl); - if (attr != null) - return attr.getNodeValue (); - } - // see above re "xmlns" as keyword - if ("xmlns".equals (decl)) - return null; - - namespaceError ("Undeclared namespace prefix: " + prefix); - return null; - } - - // SAX2 - public void endElement (String uri, String localName, String qName) - throws SAXException - { - // we can't create populated entity ref nodes using - // only public DOM APIs (they've got to be readonly) - if (currentEntity != null) - return; - - top = top.getParentNode (); - } - - // SAX1 (mandatory reporting if validating) - public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - if (consumer.isHidingWhitespace ()) - return; - characters (ch, start, length); - } - - // SAX2 lexical event - public void startCDATA () - throws SAXException - { - inCDATA = true; - // true except for the first fragment of a cdata section - mergeCDATA = false; - } - - // SAX2 lexical event - public void endCDATA () - throws SAXException - { - inCDATA = false; - } - - // SAX2 lexical event - // - // this SAX2 callback merges two unrelated things: - // - Declaration of the root element type ... belongs with - // the other DTD declaration methods, NOT HERE. - // - IDs for the optional external subset ... belongs here - // with other lexical information. - // - // ...and it doesn't include the internal DTD subset, desired - // both to support DOM L2 and to enable "pass through" processing - // - public void startDTD (String name, String publicId, String SystemId) - throws SAXException - { - // need to filter out comments and PIs within the DTD - inDTD = true; - } - - // SAX2 lexical event - public void endDTD () - throws SAXException - { - inDTD = false; - } - - // SAX2 lexical event - public void comment (char ch [], int start, int length) - throws SAXException - { - Node comment; - - // we can't create populated entity ref nodes using - // only public DOM APIs (they've got to be readonly) - if (consumer.isHidingComments () - || inDTD - || currentEntity != null) - return; - comment = document.createComment (new String (ch, start, length)); - top.appendChild (comment); - } - - /** - * May be overridden by subclasses to return true, indicating - * that entity reference nodes can be populated and then made - * read-only. - */ - public boolean canPopulateEntityRefs () - { return false; } - - // SAX2 lexical event - public void startEntity (String name) - throws SAXException - { - // are we ignoring what would be contents of an - // entity ref, since we can't populate it? - if (currentEntity != null) - return; - - // Are we hiding all entity boundaries? - if (consumer.isHidingReferences ()) - return; - - // SAX2 shows parameter entities; DOM hides them - if (name.charAt (0) == '%' || "[dtd]".equals (name)) - return; - - // Since we can't create a populated entity ref node in any - // standard way, we create an unpopulated one. - EntityReference ref = document.createEntityReference (name); - top.appendChild (ref); - top = ref; - - // ... allowing subclasses to populate them - if (!canPopulateEntityRefs ()) - currentEntity = name; - } - - // SAX2 lexical event - public void endEntity (String name) - throws SAXException - { - if (name.charAt (0) == '%' || "[dtd]".equals (name)) - return; - if (name.equals (currentEntity)) - currentEntity = null; - if (!consumer.isHidingReferences ()) - top = top.getParentNode (); - } - - - // SAX1 DTD event - public void notationDecl ( - String name, - String publicId, String SystemId - ) throws SAXException - { - /* IGNORE -- no public DOM API lets us store these - * into the doctype node - */ - } - - // SAX1 DTD event - public void unparsedEntityDecl ( - String name, - String publicId, String SystemId, - String notationName - ) throws SAXException - { - /* IGNORE -- no public DOM API lets us store these - * into the doctype node - */ - } - - // SAX2 declaration event - public void elementDecl (String name, String model) - throws SAXException - { - /* IGNORE -- no content model support in DOM L2 */ - } - - // SAX2 declaration event - public void attributeDecl ( - String eName, - String aName, - String type, - String mode, - String value - ) throws SAXException - { - /* IGNORE -- no attribute model support in DOM L2 */ - } - - // SAX2 declaration event - public void internalEntityDecl (String name, String value) - throws SAXException - { - /* IGNORE -- no public DOM API lets us store these - * into the doctype node - */ - } - - // SAX2 declaration event - public void externalEntityDecl ( - String name, - String publicId, - String SystemId - ) throws SAXException - { - /* IGNORE -- no public DOM API lets us store these - * into the doctype node - */ - } - - // - // These really should offer the option of nonfatal handling, - // like other validity errors, though that would cause major - // chaos in the DOM data structures. DOM is already spec'd - // to treat many of these as fatal, so this is consistent. - // - private void namespaceError (String description) - throws SAXParseException - { - SAXParseException err; - - err = new SAXParseException (description, locator); - throw err; - } - } -} diff --git a/libjava/gnu/xml/pipeline/EventConsumer.java b/libjava/gnu/xml/pipeline/EventConsumer.java deleted file mode 100644 index 017bc7f74f1..00000000000 --- a/libjava/gnu/xml/pipeline/EventConsumer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* EventConsumer.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import org.xml.sax.*; - - -/** - * Collects the event consumption apparatus of a SAX pipeline stage. - * Consumers which permit some handlers or other characteristics to be - * configured will provide methods to support that configuration. - * - * <p> Two important categories of consumers include <em>filters</em>, which - * process events and pass them on to other consumers, and <em>terminus</em> - * (or <em>terminal</em>) stages, which don't pass events on. Filters are not - * necessarily derived from the {@link EventFilter} class, although that - * class can substantially simplify their construction by automating the - * most common activities. - * - * <p> Event consumers which follow certain conventions for the signatures - * of their constructors can be automatically assembled into pipelines - * by the {@link PipelineFactory} class. - * - * @author David Brownell - */ -public interface EventConsumer -{ - /** Most stages process these core SAX callbacks. */ - public ContentHandler getContentHandler (); - - /** Few stages will use unparsed entities. */ - public DTDHandler getDTDHandler (); - - /** - * This method works like the SAX2 XMLReader method of the same name, - * and is used to retrieve the optional lexical and declaration handlers - * in a pipeline. - * - * @param id This is a URI identifying the type of property desired. - * @return The value of that property, if it is defined. - * - * @exception SAXNotRecognizedException Thrown if the particular - * pipeline stage does not understand the specified identifier. - */ - public Object getProperty (String id) - throws SAXNotRecognizedException; - - /** - * This method provides a filter stage with a handler that abstracts - * presentation of warnings and both recoverable and fatal errors. - * Most pipeline stages should share a single policy and mechanism - * for such reports, since application components require consistency - * in such activities. Accordingly, typical responses to this method - * invocation involve saving the handler for use; filters will pass - * it on to any other consumers they use. - * - * @param handler encapsulates error handling policy for this stage - */ - public void setErrorHandler (ErrorHandler handler); -} diff --git a/libjava/gnu/xml/pipeline/EventFilter.java b/libjava/gnu/xml/pipeline/EventFilter.java deleted file mode 100644 index 6600271718a..00000000000 --- a/libjava/gnu/xml/pipeline/EventFilter.java +++ /dev/null @@ -1,809 +0,0 @@ -/* EventFilter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.xml.sax.*; -import org.xml.sax.ext.*; -import org.xml.sax.helpers.XMLFilterImpl; - -import gnu.xml.aelfred2.ContentHandler2; - -/** - * A customizable event consumer, used to assemble various kinds of filters - * using SAX handlers and an optional second consumer. It can be constructed - * in two ways: <ul> - * - * <li> To serve as a passthrough, sending all events to a second consumer. - * The second consumer may be identified through {@link #getNext}. - * - * <li> To serve as a dead end, with all handlers null; - * {@link #getNext} returns null. - * - * </ul> - * - * <p> Additionally, SAX handlers may be assigned, which completely replace - * the "upstream" view (through {@link EventConsumer}) of handlers, initially - * null or the "next" consumer provided to the constructor. To make - * it easier to build specialized filter classes, this class implements - * all the standard SAX consumer handlers, and those implementations - * delegate "downstream" to the consumer accessed by {@link #getNext}. - * - * <p> The simplest way to create a custom a filter class is to create a - * subclass which overrides one or more handler interface methods. The - * constructor for that subclass then registers itself as a handler for - * those interfaces using a call such as <em>setContentHandler(this)</em>, - * so the "upstream" view of event delivery is modified from the state - * established in the base class constructor. That way, - * the overridden methods intercept those event callbacks - * as they go "downstream", and - * all other event callbacks will pass events to any next consumer. - * Overridden methods may invoke superclass methods (perhaps after modifying - * parameters) if they wish to delegate such calls. Such subclasses - * should use {@link #getErrorHandler} to report errors using the - * common error reporting mechanism. - * - * <p> Another important technique is to construct a filter consisting - * of only a few specific types of handler. For example, one could easily - * prune out lexical events or various declarations by providing handlers - * which don't pass those events downstream, or by providing null handlers. - * - * <hr /> - * - * <p> This may be viewed as the consumer oriented analogue of the SAX2 - * {@link org.xml.sax.helpers.XMLFilterImpl XMLFilterImpl} class. - * Key differences include: <ul> - * - * <li> This fully separates consumer and producer roles: it - * does not implement the producer side <em>XMLReader</em> or - * <em>EntityResolver</em> interfaces, so it can only be used - * in "push" mode (it has no <em>parse()</em> methods). - * - * <li> "Extension" handlers are fully supported, enabling a - * richer set of application requirements. - * And it implements {@link EventConsumer}, which groups related - * consumer methods together, rather than leaving them separated. - * - * <li> The chaining which is visible is "downstream" to the next - * consumer, not "upstream" to the preceding producer. - * It supports "fan-in", where - * a consumer can be fed by several producers. (For "fan-out", - * see the {@link TeeConsumer} class.) - * - * <li> Event chaining is set up differently. It is intended to - * work "upstream" from terminus towards producer, during filter - * construction, as described above. - * This is part of an early binding model: - * events don't need to pass through stages which ignore them. - * - * <li> ErrorHandler support is separated, on the grounds that - * pipeline stages need to share the same error handling policy. - * For the same reason, error handler setup goes "downstream": - * when error handlers get set, they are passed to subsequent - * consumers. - * - * </ul> - * - * <p> The {@link #chainTo chainTo()} convenience routine supports chaining to - * an XMLFilterImpl, in its role as a limited functionality event - * consumer. Its event producer role ({@link XMLFilter}) is ignored. - * - * <hr /> - * - * <p> The {@link #bind bind()} routine may be used associate event pipelines - * with any kind of {@link XMLReader} that will produce the events. - * Such pipelines don't necessarily need to have any members which are - * implemented using this class. That routine has some intelligence - * which supports automatic changes to parser feature flags, letting - * event piplines become largely independent of the particular feature - * sets of parsers. - * - * @author David Brownell - */ -public class EventFilter - implements EventConsumer, ContentHandler2, DTDHandler, - LexicalHandler, DeclHandler -{ - // SAX handlers - private ContentHandler docHandler, docNext; - private DTDHandler dtdHandler, dtdNext; - private LexicalHandler lexHandler, lexNext; - private DeclHandler declHandler, declNext; - // and ideally, one more for the stuff SAX2 doesn't show - - private Locator locator; - private EventConsumer next; - private ErrorHandler errHandler; - - - /** SAX2 URI prefix for standard feature flags. */ - public static final String FEATURE_URI - = "http://xml.org/sax/features/"; - /** SAX2 URI prefix for standard properties (mostly for handlers). */ - public static final String PROPERTY_URI - = "http://xml.org/sax/properties/"; - - /** SAX2 property identifier for {@link DeclHandler} events */ - public static final String DECL_HANDLER - = PROPERTY_URI + "declaration-handler"; - /** SAX2 property identifier for {@link LexicalHandler} events */ - public static final String LEXICAL_HANDLER - = PROPERTY_URI + "lexical-handler"; - - // - // These class objects will be null if the relevant class isn't linked. - // Small configurations (pJava and some kinds of embedded systems) need - // to facilitate smaller executables. So "instanceof" is undesirable - // when bind() sees if it can remove some stages. - // - // SECURITY NOTE: assuming all these classes are part of the same sealed - // package, there's no problem saving these in the instance of this class - // that's associated with "this" class loader. But that wouldn't be true - // for classes in another package. - // - private static boolean loaded; - private static Class nsClass; - private static Class validClass; - private static Class wfClass; - private static Class xincClass; - - static ClassLoader getClassLoader () - { - Method m = null; - - try { - m = Thread.class.getMethod("getContextClassLoader", null); - } catch (NoSuchMethodException e) { - // Assume that we are running JDK 1.1, use the current ClassLoader - return EventFilter.class.getClassLoader(); - } - - try { - return (ClassLoader) m.invoke(Thread.currentThread(), null); - } catch (IllegalAccessException e) { - // assert(false) - throw new UnknownError(e.getMessage()); - } catch (InvocationTargetException e) { - // assert(e.getTargetException() instanceof SecurityException) - throw new UnknownError(e.getMessage()); - } - } - - static Class loadClass (ClassLoader classLoader, String className) - { - try { - if (classLoader == null) - return Class.forName(className); - else - return classLoader.loadClass(className); - } catch (Exception e) { - return null; - } - } - - static private void loadClasses () - { - ClassLoader loader = getClassLoader (); - - nsClass = loadClass (loader, "gnu.xml.pipeline.NSFilter"); - validClass = loadClass (loader, "gnu.xml.pipeline.ValidationConsumer"); - wfClass = loadClass (loader, "gnu.xml.pipeline.WellFormednessFilter"); - xincClass = loadClass (loader, "gnu.xml.pipeline.XIncludeFilter"); - loaded = true; - } - - - /** - * Binds the standard SAX2 handlers from the specified consumer - * pipeline to the specified producer. These handlers include the core - * {@link ContentHandler} and {@link DTDHandler}, plus the extension - * {@link DeclHandler} and {@link LexicalHandler}. Any additional - * application-specific handlers need to be bound separately. - * The {@link ErrorHandler} is handled differently: the producer's - * error handler is passed through to the consumer pipeline. - * The producer is told to include namespace prefix information if it - * can, since many pipeline stages need that Infoset information to - * work well. - * - * <p> At the head of the pipeline, certain standard event filters are - * recognized and handled specially. This facilitates construction - * of processing pipelines that work regardless of the capabilities - * of the XMLReader implementation in use; for example, it permits - * validating output of a {@link gnu.xml.util.DomParser}. <ul> - * - * <li> {@link NSFilter} will be removed if the producer can be - * told not to discard namespace data, using the "namespace-prefixes" - * feature flag. - * - * <li> {@link ValidationConsumer} will be removed if the producer - * can be told to validate, using the "validation" feature flag. - * - * <li> {@link WellFormednessFilter} is always removed, on the - * grounds that no XMLReader is permitted to producee malformed - * event streams and this would just be processing overhead. - * - * <li> {@link XIncludeFilter} stops the special handling, except - * that it's told about the "namespace-prefixes" feature of the - * event producer so that the event stream is internally consistent. - * - * <li> The first consumer which is not one of those classes stops - * such special handling. This means that if you want to force - * one of those filters to be used, you could just precede it with - * an instance of {@link EventFilter} configured as a pass-through. - * You might need to do that if you are using an {@link NSFilter} - * subclass to fix names found in attributes or character data. - * - * </ul> - * - * <p> Other than that, this method works with any kind of event consumer, - * not just event filters. Note that in all cases, the standard handlers - * are assigned; any previous handler assignments for the handler will - * be overridden. - * - * @param producer will deliver events to the specified consumer - * @param consumer pipeline supplying event handlers to be associated - * with the producer (may not be null) - */ - public static void bind (XMLReader producer, EventConsumer consumer) - { - Class klass = null; - boolean prefixes; - - if (!loaded) - loadClasses (); - - // DOM building, printing, layered validation, and other - // things don't work well when prefix info is discarded. - // Include it by default, whenever possible. - try { - producer.setFeature (FEATURE_URI + "namespace-prefixes", - true); - prefixes = true; - } catch (SAXException e) { - prefixes = false; - } - - // NOTE: This loop doesn't use "instanceof", since that - // would prevent compiling/linking without those classes - // being present. - while (consumer != null) { - klass = consumer.getClass (); - - // we might have already changed this problematic SAX2 default. - if (nsClass != null && nsClass.isAssignableFrom (klass)) { - if (!prefixes) - break; - consumer = ((EventFilter)consumer).getNext (); - - // the parser _might_ do DTD validation by default ... - // if not, maybe we can change this setting. - } else if (validClass != null - && validClass.isAssignableFrom (klass)) { - try { - producer.setFeature (FEATURE_URI + "validation", - true); - consumer = ((ValidationConsumer)consumer).getNext (); - } catch (SAXException e) { - break; - } - - // parsers are required not to have such bugs - } else if (wfClass != null && wfClass.isAssignableFrom (klass)) { - consumer = ((WellFormednessFilter)consumer).getNext (); - - // stop on the first pipeline stage we can't remove - } else - break; - - if (consumer == null) - klass = null; - } - - // the actual setting here doesn't matter as much - // as that producer and consumer agree - if (xincClass != null && klass != null - && xincClass.isAssignableFrom (klass)) - ((XIncludeFilter)consumer).setSavingPrefixes (prefixes); - - // Some SAX parsers can't handle null handlers -- bleech - DefaultHandler2 h = new DefaultHandler2 (); - - if (consumer != null && consumer.getContentHandler () != null) - producer.setContentHandler (consumer.getContentHandler ()); - else - producer.setContentHandler (h); - if (consumer != null && consumer.getDTDHandler () != null) - producer.setDTDHandler (consumer.getDTDHandler ()); - else - producer.setDTDHandler (h); - - try { - Object dh; - - if (consumer != null) - dh = consumer.getProperty (DECL_HANDLER); - else - dh = null; - if (dh == null) - dh = h; - producer.setProperty (DECL_HANDLER, dh); - } catch (Exception e) { /* ignore */ } - try { - Object lh; - - if (consumer != null) - lh = consumer.getProperty (LEXICAL_HANDLER); - else - lh = null; - if (lh == null) - lh = h; - producer.setProperty (LEXICAL_HANDLER, lh); - } catch (Exception e) { /* ignore */ } - - // this binding goes the other way around - if (producer.getErrorHandler () == null) - producer.setErrorHandler (h); - if (consumer != null) - consumer.setErrorHandler (producer.getErrorHandler ()); - } - - /** - * Initializes all handlers to null. - */ - // constructor used by PipelineFactory - public EventFilter () { } - - - /** - * Handlers that are not otherwise set will default to those from - * the specified consumer, making it easy to pass events through. - * If the consumer is null, all handlers are initialzed to null. - */ - // constructor used by PipelineFactory - public EventFilter (EventConsumer consumer) - { - if (consumer == null) - return; - - next = consumer; - - // We delegate through the "xxNext" handlers, and - // report the "xxHandler" ones on our input side. - - // Normally a subclass would both override handler - // methods and register itself as the "xxHandler". - - docHandler = docNext = consumer.getContentHandler (); - dtdHandler = dtdNext = consumer.getDTDHandler (); - try { - declHandler = declNext = (DeclHandler) - consumer.getProperty (DECL_HANDLER); - } catch (SAXException e) { /* leave value null */ } - try { - lexHandler = lexNext = (LexicalHandler) - consumer.getProperty (LEXICAL_HANDLER); - } catch (SAXException e) { /* leave value null */ } - } - - /** - * Treats the XMLFilterImpl as a limited functionality event consumer, - * by arranging to deliver events to it; this lets such classes be - * "wrapped" as pipeline stages. - * - * <p> <em>Upstream Event Setup:</em> - * If no handlers have been assigned to this EventFilter, then the - * handlers from specified XMLFilterImpl are returned from this - * {@link EventConsumer}: the XMLFilterImpl is just "wrapped". - * Otherwise the specified handlers will be returned. - * - * <p> <em>Downstream Event Setup:</em> - * Subclasses may chain event delivery to the specified XMLFilterImpl - * by invoking the appropiate superclass methods, - * as if their constructor passed a "next" EventConsumer to the - * constructor for this class. - * If this EventFilter has an ErrorHandler, it is assigned as - * the error handler for the XMLFilterImpl, just as would be - * done for a next stage implementing {@link EventConsumer}. - * - * @param next the next downstream component of the pipeline. - * @exception IllegalStateException if the "next" consumer has - * already been set through the constructor. - */ - public void chainTo (XMLFilterImpl next) - { - if (this.next != null) - throw new IllegalStateException (); - - docNext = next.getContentHandler (); - if (docHandler == null) - docHandler = docNext; - dtdNext = next.getDTDHandler (); - if (dtdHandler == null) - dtdHandler = dtdNext; - - try { - declNext = (DeclHandler) next.getProperty (DECL_HANDLER); - if (declHandler == null) - declHandler = declNext; - } catch (SAXException e) { /* leave value null */ } - try { - lexNext = (LexicalHandler) next.getProperty (LEXICAL_HANDLER); - if (lexHandler == null) - lexHandler = lexNext; - } catch (SAXException e) { /* leave value null */ } - - if (errHandler != null) - next.setErrorHandler (errHandler); - } - - /** - * Records the error handler that should be used by this stage, and - * passes it "downstream" to any subsequent stage. - */ - final public void setErrorHandler (ErrorHandler handler) - { - errHandler = handler; - if (next != null) - next.setErrorHandler (handler); - } - - /** - * Returns the error handler assigned this filter stage, or null - * if no such assigment has been made. - */ - final public ErrorHandler getErrorHandler () - { - return errHandler; - } - - - /** - * Returns the next event consumer in sequence; or null if there - * is no such handler. - */ - final public EventConsumer getNext () - { return next; } - - - /** - * Assigns the content handler to use; a null handler indicates - * that these events will not be forwarded. - * This overrides the previous settting for this handler, which was - * probably pointed to the next consumer by the base class constructor. - */ - final public void setContentHandler (ContentHandler h) - { - docHandler = h; - } - - /** Returns the content handler being used. */ - final public ContentHandler getContentHandler () - { - return docHandler; - } - - /** - * Assigns the DTD handler to use; a null handler indicates - * that these events will not be forwarded. - * This overrides the previous settting for this handler, which was - * probably pointed to the next consumer by the base class constructor. - */ - final public void setDTDHandler (DTDHandler h) - { dtdHandler = h; } - - /** Returns the dtd handler being used. */ - final public DTDHandler getDTDHandler () - { - return dtdHandler; - } - - /** - * Stores the property, normally a handler; a null handler indicates - * that these events will not be forwarded. - * This overrides the previous handler settting, which was probably - * pointed to the next consumer by the base class constructor. - */ - final public void setProperty (String id, Object o) - throws SAXNotRecognizedException, SAXNotSupportedException - { - try { - Object value = getProperty (id); - - if (value == o) - return; - if (DECL_HANDLER.equals (id)) { - declHandler = (DeclHandler) o; - return; - } - if (LEXICAL_HANDLER.equals (id)) { - lexHandler = (LexicalHandler) o; - return; - } - throw new SAXNotSupportedException (id); - - } catch (ClassCastException e) { - throw new SAXNotSupportedException (id); - } - } - - /** Retrieves a property of unknown intent (usually a handler) */ - final public Object getProperty (String id) - throws SAXNotRecognizedException - { - if (DECL_HANDLER.equals (id)) - return declHandler; - if (LEXICAL_HANDLER.equals (id)) - return lexHandler; - - throw new SAXNotRecognizedException (id); - } - - /** - * Returns any locator provided to the next consumer, if this class - * (or a subclass) is handling {@link ContentHandler } events. - */ - public Locator getDocumentLocator () - { return locator; } - - - // CONTENT HANDLER DELEGATIONS - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void setDocumentLocator (Locator locator) - { - this.locator = locator; - if (docNext != null) - docNext.setDocumentLocator (locator); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void startDocument () throws SAXException - { - if (docNext != null) - docNext.startDocument (); - } - - public void xmlDecl(String version, String encoding, boolean standalone, - String inputEncoding) - throws SAXException - { - if (docNext != null && docNext instanceof ContentHandler2) - { - ((ContentHandler2) docNext).xmlDecl(version, encoding, standalone, - inputEncoding); - } - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void skippedEntity (String name) throws SAXException - { - if (docNext != null) - docNext.skippedEntity (name); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void processingInstruction (String target, String data) - throws SAXException - { - if (docNext != null) - docNext.processingInstruction (target, data); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void characters (char ch [], int start, int length) - throws SAXException - { - if (docNext != null) - docNext.characters (ch, start, length); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - if (docNext != null) - docNext.ignorableWhitespace (ch, start, length); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void startPrefixMapping (String prefix, String uri) - throws SAXException - { - if (docNext != null) - docNext.startPrefixMapping (prefix, uri); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void startElement ( - String uri, String localName, - String qName, Attributes atts - ) throws SAXException - { - if (docNext != null) - docNext.startElement (uri, localName, qName, atts); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void endElement (String uri, String localName, String qName) - throws SAXException - { - if (docNext != null) - docNext.endElement (uri, localName, qName); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void endPrefixMapping (String prefix) throws SAXException - { - if (docNext != null) - docNext.endPrefixMapping (prefix); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void endDocument () throws SAXException - { - if (docNext != null) - docNext.endDocument (); - locator = null; - } - - - // DTD HANDLER DELEGATIONS - - /** <b>SAX1:</b> passes this callback to the next consumer, if any */ - public void unparsedEntityDecl ( - String name, - String publicId, - String systemId, - String notationName - ) throws SAXException - { - if (dtdNext != null) - dtdNext.unparsedEntityDecl (name, publicId, systemId, notationName); - } - - /** <b>SAX1:</b> passes this callback to the next consumer, if any */ - public void notationDecl (String name, String publicId, String systemId) - throws SAXException - { - if (dtdNext != null) - dtdNext.notationDecl (name, publicId, systemId); - } - - - // LEXICAL HANDLER DELEGATIONS - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void startDTD (String name, String publicId, String systemId) - throws SAXException - { - if (lexNext != null) - lexNext.startDTD (name, publicId, systemId); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void endDTD () - throws SAXException - { - if (lexNext != null) - lexNext.endDTD (); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void comment (char ch [], int start, int length) - throws SAXException - { - if (lexNext != null) - lexNext.comment (ch, start, length); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void startCDATA () - throws SAXException - { - if (lexNext != null) - lexNext.startCDATA (); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void endCDATA () - throws SAXException - { - if (lexNext != null) - lexNext.endCDATA (); - } - - /** - * <b>SAX2:</b> passes this callback to the next consumer, if any. - */ - public void startEntity (String name) - throws SAXException - { - if (lexNext != null) - lexNext.startEntity (name); - } - - /** - * <b>SAX2:</b> passes this callback to the next consumer, if any. - */ - public void endEntity (String name) - throws SAXException - { - if (lexNext != null) - lexNext.endEntity (name); - } - - - // DECLARATION HANDLER DELEGATIONS - - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void elementDecl (String name, String model) - throws SAXException - { - if (declNext != null) - declNext.elementDecl (name, model); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void attributeDecl (String eName, String aName, - String type, String mode, String value) - throws SAXException - { - if (declNext != null) - declNext.attributeDecl (eName, aName, type, mode, value); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void externalEntityDecl (String name, - String publicId, String systemId) - throws SAXException - { - if (declNext != null) - declNext.externalEntityDecl (name, publicId, systemId); - } - - /** <b>SAX2:</b> passes this callback to the next consumer, if any */ - public void internalEntityDecl (String name, String value) - throws SAXException - { - if (declNext != null) - declNext.internalEntityDecl (name, value); - } -} diff --git a/libjava/gnu/xml/pipeline/LinkFilter.java b/libjava/gnu/xml/pipeline/LinkFilter.java deleted file mode 100644 index ddb9fda2e75..00000000000 --- a/libjava/gnu/xml/pipeline/LinkFilter.java +++ /dev/null @@ -1,242 +0,0 @@ -/* LinkFilter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.IOException; -import java.net.URL; -import java.util.Enumeration; -import java.util.Vector; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - - -/** - * Pipeline filter to remember XHTML links found in a document, - * so they can later be crawled. Fragments are not counted, and duplicates - * are ignored. Callers are responsible for filtering out URLs they aren't - * interested in. Events are passed through unmodified. - * - * <p> Input MUST include a setDocumentLocator() call, as it's used to - * resolve relative links in the absence of a "base" element. Input MUST - * also include namespace identifiers, since it is the XHTML namespace - * identifier which is used to identify the relevant elements. - * - * <p><em>FIXME:</em> handle xml:base attribute ... in association with - * a stack of base URIs. Similarly, recognize/support XLink data. - * - * @author David Brownell - */ -public class LinkFilter extends EventFilter -{ - // for storing URIs - private Vector vector = new Vector (); - - // struct for "full" link record (tbd) - // these for troubleshooting original source: - // original uri - // uri as resolved (base, relative, etc) - // URI of originating doc - // line # - // original element + attrs (img src, desc, etc) - - // XLink model of the link ... for inter-site pairups ? - - private String baseURI; - - private boolean siteRestricted = false; - - // - // XXX leverage blacklist info (like robots.txt) - // - // XXX constructor w/param ... pipeline for sending link data - // probably XHTML --> XLink, providing info as sketched above - // - - - /** - * Constructs a new event filter, which collects links in private data - * structure for later enumeration. - */ - // constructor used by PipelineFactory - public LinkFilter () - { - super.setContentHandler (this); - } - - - /** - * Constructs a new event filter, which collects links in private data - * structure for later enumeration and passes all events, unmodified, - * to the next consumer. - */ - // constructor used by PipelineFactory - public LinkFilter (EventConsumer next) - { - super (next); - super.setContentHandler (this); - } - - - /** - * Returns an enumeration of the links found since the filter - * was constructed, or since removeAllLinks() was called. - * - * @return enumeration of strings. - */ - public Enumeration getLinks () - { - return vector.elements (); - } - - /** - * Removes records about all links reported to the event - * stream, as if the filter were newly created. - */ - public void removeAllLinks () - { - vector = new Vector (); - } - - - /** - * Collects URIs for (X)HTML content from elements which hold them. - */ - public void startElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - String link; - - // Recognize XHTML links. - if ("http://www.w3.org/1999/xhtml".equals (uri)) { - - if ("a".equals (localName) || "base".equals (localName) - || "area".equals (localName)) - link = atts.getValue ("href"); - else if ("iframe".equals (localName) || "frame".equals (localName)) - link = atts.getValue ("src"); - else if ("blockquote".equals (localName) || "q".equals (localName) - || "ins".equals (localName) || "del".equals (localName)) - link = atts.getValue ("cite"); - else - link = null; - link = maybeAddLink (link); - - // "base" modifies designated baseURI - if ("base".equals (localName) && link != null) - baseURI = link; - - if ("iframe".equals (localName) || "img".equals (localName)) - maybeAddLink (atts.getValue ("longdesc")); - } - - super.startElement (uri, localName, qName, atts); - } - - private String maybeAddLink (String link) - { - int index; - - // ignore empty links and fragments inside docs - if (link == null) - return null; - if ((index = link.indexOf ("#")) >= 0) - link = link.substring (0, index); - if (link.equals ("")) - return null; - - try { - // get the real URI - URL base = new URL ((baseURI != null) - ? baseURI - : getDocumentLocator ().getSystemId ()); - URL url = new URL (base, link); - - link = url.toString (); - - // ignore duplicates - if (vector.contains (link)) - return link; - - // other than what "base" does, stick to original site: - if (siteRestricted) { - // don't switch protocols - if (!base.getProtocol ().equals (url.getProtocol ())) - return link; - // don't switch servers - if (base.getHost () != null - && !base.getHost ().equals (url.getHost ())) - return link; - } - - vector.addElement (link); - - return link; - - } catch (IOException e) { - // bad URLs we don't want - } - return null; - } - - /** - * Reports an error if no Locator has been made available. - */ - public void startDocument () - throws SAXException - { - if (getDocumentLocator () == null) - throw new SAXException ("no Locator!"); - } - - /** - * Forgets about any base URI information that may be recorded. - * Applications will often want to call removeAllLinks(), likely - * after examining the links which were reported. - */ - public void endDocument () - throws SAXException - { - baseURI = null; - super.endDocument (); - } -} diff --git a/libjava/gnu/xml/pipeline/NSFilter.java b/libjava/gnu/xml/pipeline/NSFilter.java deleted file mode 100644 index db875e1debf..00000000000 --- a/libjava/gnu/xml/pipeline/NSFilter.java +++ /dev/null @@ -1,341 +0,0 @@ -/* NSFilter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.util.Enumeration; -import java.util.Stack; - -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.NamespaceSupport; - -/** - * This filter ensures that element and attribute names are properly prefixed, - * and that such prefixes are declared. Such data is critical for operations - * like writing XML text, and validating against DTDs: names or their prefixes - * may have been discarded, although they are essential to the exchange of - * information using XML. There are various common ways that such data - * gets discarded: <ul> - * - * <li> By default, SAX2 parsers must discard the "xmlns*" - * attributes, and may also choose not to report properly prefixed - * names for elements or attributes. (Some parsers may support - * changing the <em>namespace-prefixes</em> value from the default - * to <em>true</em>, effectively eliminating the need to use this - * filter on their output.) - * - * <li> When event streams are generated from a DOM tree, they may - * have never have had prefixes or declarations for namespaces; or - * the existing prefixes or declarations may have been invalidated - * by structural modifications to that DOM tree. - * - * <li> Other software writing SAX event streams won't necessarily - * be worrying about prefix management, and so they will need to - * have a transparent solution for managing them. - * - * </ul> - * - * <p> This filter uses a heuristic to choose the prefix to assign to any - * particular name which wasn't already corectly prefixed. The associated - * namespace will be correct, and the prefix will be declared. Original - * structures facilitating text editing, such as conventions about use of - * mnemonic prefix names or the scoping of prefixes, can't always be - * reconstructed after they are discarded, as strongly encouraged by the - * current SAX2 defaults. - * - * <p> Note that this can't possibly know whether values inside attribute - * value or document content involve prefixed names. If your application - * requires using prefixed names in such locations you'll need to add some - * appropriate logic (perhaps adding additional heuristics in a subclass). - * - * @author David Brownell - */ -public class NSFilter extends EventFilter -{ - private NamespaceSupport nsStack = new NamespaceSupport (); - private Stack elementStack = new Stack (); - - private boolean pushedContext; - private String nsTemp [] = new String [3]; - private AttributesImpl attributes = new AttributesImpl (); - private boolean usedDefault; - - // gensymmed prefixes use this root name - private static final String prefixRoot = "prefix-"; - - - /** - * Passes events through to the specified consumer, after first - * processing them. - * - * @param next the next event consumer to receive events. - */ - // constructor used by PipelineFactory - public NSFilter (EventConsumer next) - { - super (next); - - setContentHandler (this); - } - - private void fatalError (String message) - throws SAXException - { - SAXParseException e; - ErrorHandler handler = getErrorHandler (); - Locator locator = getDocumentLocator (); - - if (locator == null) - e = new SAXParseException (message, null, null, -1, -1); - else - e = new SAXParseException (message, locator); - if (handler != null) - handler.fatalError (e); - throw e; - } - - - public void startDocument () throws SAXException - { - elementStack.removeAllElements (); - nsStack.reset (); - pushedContext = false; - super.startDocument (); - } - - /** - * This call is not passed to the next consumer in the chain. - * Prefix declarations and scopes are only exposed in the form - * of attributes; this callback just records a declaration that - * will be exposed as an attribute. - */ - public void startPrefixMapping (String prefix, String uri) - throws SAXException - { - if (pushedContext == false) { - nsStack.pushContext (); - pushedContext = true; - } - - // this check is awkward, but the paranoia prevents big trouble - for (Enumeration e = nsStack.getDeclaredPrefixes (); - e.hasMoreElements (); - /* NOP */ ) { - String declared = (String) e.nextElement (); - - if (!declared.equals (prefix)) - continue; - if (uri.equals (nsStack.getURI (prefix))) - return; - fatalError ("inconsistent binding for prefix '" + prefix - + "' ... " + uri + " (was " + nsStack.getURI (prefix) + ")"); - } - - if (!nsStack.declarePrefix (prefix, uri)) - fatalError ("illegal prefix declared: " + prefix); - } - - private String fixName (String ns, String l, String name, boolean isAttr) - throws SAXException - { - if ("".equals (name) || name == null) { - name = l; - if ("".equals (name) || name == null) - fatalError ("empty/null name"); - } - - // can we correctly process the name as-is? - // handles "element scope" attribute names here. - if (nsStack.processName (name, nsTemp, isAttr) != null - && nsTemp [0].equals (ns) - ) { - return nsTemp [2]; - } - - // nope, gotta modify the name or declare a default mapping - int temp; - - // get rid of any current prefix - if ((temp = name.indexOf (':')) >= 0) { - name = name.substring (temp + 1); - - // ... maybe that's enough (use/prefer default namespace) ... - if (!isAttr && nsStack.processName (name, nsTemp, false) != null - && nsTemp [0].equals (ns) - ) { - return nsTemp [2]; - } - } - - // must we define and use the default/undefined prefix? - if ("".equals (ns)) { - if (isAttr) - fatalError ("processName bug"); - if (attributes.getIndex ("xmlns") != -1) - fatalError ("need to undefine default NS, but it's bound: " - + attributes.getValue ("xmlns")); - - nsStack.declarePrefix ("", ""); - attributes.addAttribute ("", "", "xmlns", "CDATA", ""); - return name; - } - - // is there at least one non-null prefix we can use? - for (Enumeration e = nsStack.getDeclaredPrefixes (); - e.hasMoreElements (); - /* NOP */) { - String prefix = (String) e.nextElement (); - String uri = nsStack.getURI (prefix); - - if (uri == null || !uri.equals (ns)) - continue; - return prefix + ":" + name; - } - - // no such luck. create a prefix name, declare it, use it. - for (temp = 0; temp >= 0; temp++) { - String prefix = prefixRoot + temp; - - if (nsStack.getURI (prefix) == null) { - nsStack.declarePrefix (prefix, ns); - attributes.addAttribute ("", "", "xmlns:" + prefix, - "CDATA", ns); - return prefix + ":" + name; - } - } - fatalError ("too many prefixes genned"); - // NOTREACHED - return null; - } - - public void startElement ( - String uri, String localName, - String qName, Attributes atts - ) throws SAXException - { - if (!pushedContext) - nsStack.pushContext (); - pushedContext = false; - - // make sure we have all NS declarations handy before we start - int length = atts.getLength (); - - for (int i = 0; i < length; i++) { - String aName = atts.getQName (i); - - if (!aName.startsWith ("xmlns")) - continue; - - String prefix; - - if ("xmlns".equals (aName)) - prefix = ""; - else if (aName.indexOf (':') == 5) - prefix = aName.substring (6); - else // "xmlnsfoo" etc. - continue; - startPrefixMapping (prefix, atts.getValue (i)); - } - - // put namespace decls at the start of our regenned attlist - attributes.clear (); - for (Enumeration e = nsStack.getDeclaredPrefixes (); - e.hasMoreElements (); - /* NOP */) { - String prefix = (String) e.nextElement (); - - attributes.addAttribute ("", "", - ("".equals (prefix) - ? "xmlns" - : "xmlns:" + prefix), - "CDATA", - nsStack.getURI (prefix)); - } - - // name fixups: element, then attributes. - // fixName may declare a new prefix or, for the element, - // redeclare the default (if element name needs it). - qName = fixName (uri, localName, qName, false); - - for (int i = 0; i < length; i++) { - String aName = atts.getQName (i); - String aNS = atts.getURI (i); - String aLocal = atts.getLocalName (i); - String aType = atts.getType (i); - String aValue = atts.getValue (i); - - if (aName.startsWith ("xmlns")) - continue; - aName = fixName (aNS, aLocal, aName, true); - attributes.addAttribute (aNS, aLocal, aName, aType, aValue); - } - - elementStack.push (qName); - - // pass event along, with cleaned-up names and decls. - super.startElement (uri, localName, qName, attributes); - } - - public void endElement (String uri, String localName, String qName) - throws SAXException - { - nsStack.popContext (); - qName = (String) elementStack.pop (); - super.endElement (uri, localName, qName); - } - - /** - * This call is not passed to the next consumer in the chain. - * Prefix declarations and scopes are only exposed in their - * attribute form. - */ - public void endPrefixMapping (String prefix) - throws SAXException - { } - - public void endDocument () throws SAXException - { - elementStack.removeAllElements (); - nsStack.reset (); - super.endDocument (); - } -} diff --git a/libjava/gnu/xml/pipeline/PipelineFactory.java b/libjava/gnu/xml/pipeline/PipelineFactory.java deleted file mode 100644 index f88ab164311..00000000000 --- a/libjava/gnu/xml/pipeline/PipelineFactory.java +++ /dev/null @@ -1,723 +0,0 @@ -/* PipelineFactory.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.lang.reflect.Constructor; -import java.util.StringTokenizer; - -import org.xml.sax.*; -import org.xml.sax.ext.*; - - -/** - * This provides static factory methods for creating simple event pipelines. - * These pipelines are specified by strings, suitable for passing on - * command lines or embedding in element attributes. For example, one way - * to write a pipeline that restores namespace syntax, validates (stopping - * the pipeline on validity errors) and then writes valid data to standard - * output is this: <pre> - * nsfix | validate | write ( stdout )</pre> - * - * <p> In this syntax, the tokens are always separated by whitespace, and each - * stage of the pipeline may optionally have a parameter (which can be a - * pipeline) in parentheses. Interior stages are called filters, and the - * rightmost end of a pipeline is called a terminus. - * - * <p> Stages are usually implemented by a single class, which may not be - * able to act as both a filter and a terminus; but any terminus can be - * automatically turned into a filter, through use of a {@link TeeConsumer}. - * The stage identifiers are either class names, or are one of the following - * short identifiers built into this class. (Most of these identifiers are - * no more than aliases for classes.) The built-in identifiers include:</p> - - <table border="1" cellpadding="3" cellspacing="0"> - <tr bgcolor="#ccccff" class="TableHeadingColor"> - <th align="center" width="5%">Stage</th> - <th align="center" width="9%">Parameter</th> - <th align="center" width="1%">Terminus</th> - <th align="center">Description</th> - </tr> - - <tr valign="top" align="center"> - <td><a href="../dom/Consumer.html">dom</a></td> - <td><em>none</em></td> - <td> yes </td> - <td align="left"> Applications code can access a DOM Document built - from the input event stream. When used as a filter, this buffers - data up to an <em>endDocument</em> call, and then uses a DOM parser - to report everything that has been recorded (which can easily be - less than what was reported to it). </td> - </tr> - <tr valign="top" align="center"> - <td><a href="NSFilter.html">nsfix</a></td> - <td><em>none</em></td> - <td>no</td> - <td align="left">This stage ensures that the XML element and attribute - names in its output use namespace prefixes and declarations correctly. - That is, so that they match the "Namespace plus LocalName" naming data - with which each XML element and attribute is already associated. </td> - </tr> - <tr valign="top" align="center"> - <td><a href="EventFilter.html">null</a></td> - <td><em>none</em></td> - <td>yes</td> - <td align="left">This stage ignores all input event data.</td> - </tr> - <tr valign="top" align="center"> - <td><a href="CallFilter.html">server</a></td> - <td><em>required</em><br> server URL </td> - <td>no</td> - <td align="left">Sends its input as XML request to a remote server, - normally a web application server using the HTTP or HTTPS protocols. - The output of this stage is the parsed response from that server.</td> - </tr> - <tr valign="top" align="center"> - <td><a href="TeeConsumer.html">tee</a></td> - <td><em>required</em><br> first pipeline</td> - <td>no</td> - <td align="left">This sends its events down two paths; its parameter - is a pipeline descriptor for the first path, and the second path - is the output of this stage.</td> - </tr> - - <tr valign="top" align="center"> - <td><a href="ValidationConsumer.html">validate</a></td> - <td><em>none</em></td> - <td>yes</td> - <td align="left">This checks for validity errors, and reports them - through its error handler. The input must include declaration events - and some lexical events. </td> - </tr> - <tr valign="top" align="center"> - <td><a href="WellFormednessFilter.html">wf</a></td> - <td><em>none</em></td> - <td>yes</td> - <td align="left"> This class provides some basic "well formedness" - tests on the input event stream, and reports a fatal error if any - of them fail. One example: start/end calls for elements must match. - No SAX parser is permitted to produce malformed output, but other - components can easily do so.</td> - </tr> - <tr valign="top" align="center"> - <td>write</td> - <td><em>required</em><br> "stdout", "stderr", or filename</td> - <td>yes</td> - <td align="left"> Writes its input to the specified output, as pretty - printed XML text encoded using UTF-8. Input events must be well - formed and "namespace fixed", else the output won't be XML (or possibly - namespace) conformant. The symbolic names represent - <em>System.out</em> and <em>System.err</em> respectively; names must - correspond to files which don't yet exist.</td> - </tr> - <tr valign="top" align="center"> - <td>xhtml</td> - <td><em>required</em><br> "stdout", "stderr", or filename</td> - <td>yes</td> - <td align="left"> Like <em>write</em> (above), except that XHTML rules - are followed. The XHTML 1.0 Transitional document type is declared, - and only ASCII characters are written (for interoperability). Other - characters are written as entity or character references; the text is - pretty printed.</td> - </tr> - <tr valign="top" align="center"> - <td><a href="XIncludeFilter.html">xinclude</a></td> - <td><em>none</em></td> - <td>no</td> - <td align="left">This stage handles XInclude processing. - This is like entity inclusion, except that the included content - is declared in-line rather than in the DTD at the beginning of - a document. - </td> - </tr> - <tr valign="top" align="center"> - <td><a href="XsltFilter.html">xslt</a></td> - <td><em>required</em><br> XSLT stylesheet URI</td> - <td>no</td> - <td align="left">This stage handles XSLT transformation - according to a stylesheet. - The implementation of the transformation may not actually - stream data, although if such an XSLT engine is in use - then that can happen. - </td> - </tr> - - </table> - - * <p> Note that {@link EventFilter#bind} can automatically eliminate - * some filters by setting SAX2 parser features appropriately. This means - * that you can routinely put filters like "nsfix", "validate", or "wf" at the - * front of a pipeline (for components that need inputs conditioned to match - * that level of correctness), and know that it won't actually be used unless - * it's absolutely necessary. - * - * @author David Brownell - */ -public class PipelineFactory -{ - /** - * Creates a simple pipeline according to the description string passed in. - */ - public static EventConsumer createPipeline (String description) - throws IOException - { - return createPipeline (description, null); - } - - /** - * Extends an existing pipeline by prepending the filter pipeline to the - * specified consumer. Some pipelines need more customization than can - * be done through this simplified syntax. When they are set up with - * direct API calls, use this method to merge more complex pipeline - * segments with easily configured ones. - */ - public static EventConsumer createPipeline ( - String description, - EventConsumer next - ) throws IOException - { - // tokens are (for now) what's separated by whitespace; - // very easy to parse, but IDs never have spaces. - - StringTokenizer tokenizer; - String tokens []; - - tokenizer = new StringTokenizer (description); - tokens = new String [tokenizer.countTokens ()]; - for (int i = 0; i < tokens.length; i++) - tokens [i] = tokenizer.nextToken (); - - PipelineFactory factory = new PipelineFactory (); - Pipeline pipeline = factory.parsePipeline (tokens, next); - - return pipeline.createPipeline (); - } - - - private PipelineFactory () { /* NYET */ } - - - /** - * Extends an existing pipeline by prepending a pre-tokenized filter - * pipeline to the specified consumer. Tokens are class names (or the - * predefined aliases) left and right parenthesis, and the vertical bar. - */ - public static EventConsumer createPipeline ( - String tokens [], - EventConsumer next - ) throws IOException - { - PipelineFactory factory = new PipelineFactory (); - Pipeline pipeline = factory.parsePipeline (tokens, next); - - return pipeline.createPipeline (); - } - - - private String tokens []; - private int index; - - private Pipeline parsePipeline (String toks [], EventConsumer next) - { - tokens = toks; - index = 0; - - Pipeline retval = parsePipeline (next); - - if (index != toks.length) - throw new ArrayIndexOutOfBoundsException ( - "extra token: " + tokens [index]); - return retval; - } - - // pipeline ::= stage | stage '|' pipeline - private Pipeline parsePipeline (EventConsumer next) - { - Pipeline retval = new Pipeline (parseStage ()); - - // minimal pipelines: "stage" and "... | id" - if (index > (tokens.length - 2) - || !"|".equals (tokens [index]) - ) { - retval.next = next; - return retval; - } - index++; - retval.rest = parsePipeline (next); - return retval; - } - - // stage ::= id | id '(' pipeline ')' - private Stage parseStage () - { - Stage retval = new Stage (tokens [index++]); - - // minimal stages: "id" and "id ( id )" - if (index > (tokens.length - 2) - || !"(".equals (tokens [index]) /*)*/ - ) - return retval; - - index++; - retval.param = parsePipeline (null); - if (index >= tokens.length) - throw new ArrayIndexOutOfBoundsException ( - "missing right paren"); - if (/*(*/ !")".equals (tokens [index++])) - throw new ArrayIndexOutOfBoundsException ( - "required right paren, not: " + tokens [index - 1]); - return retval; - } - - - // - // these classes obey the conventions for constructors, so they're - // only built in to this table of shortnames - // - // - filter (one or two types of arglist) - // * last constructor is 'next' element - // * optional (first) string parameter - // - // - terminus (one or types of arglist) - // * optional (only) string parameter - // - // terminus stages are transformed into filters if needed, by - // creating a "tee". filter stages aren't turned to terminus - // stages though; either eliminate such stages, or add some - // terminus explicitly. - // - private static final String builtinStages [][] = { - { "dom", "gnu.xml.dom.Consumer" }, - { "nsfix", "gnu.xml.pipeline.NSFilter" }, - { "null", "gnu.xml.pipeline.EventFilter" }, - { "server", "gnu.xml.pipeline.CallFilter" }, - { "tee", "gnu.xml.pipeline.TeeConsumer" }, - { "validate", "gnu.xml.pipeline.ValidationConsumer" }, - { "wf", "gnu.xml.pipeline.WellFormednessFilter" }, - { "xinclude", "gnu.xml.pipeline.XIncludeFilter" }, - { "xslt", "gnu.xml.pipeline.XsltFilter" }, - -// XXX want: option for validate, to preload external part of a DTD - - // xhtml, write ... nyet generic-ready - }; - - private static class Stage - { - String id; - Pipeline param; - - Stage (String name) - { id = name; } - - public String toString () - { - if (param == null) - return id; - return id + " ( " + param + " )"; - } - - private void fail (String message) - throws IOException - { - throw new IOException ("in '" + id - + "' stage of pipeline, " + message); - } - - EventConsumer createStage (EventConsumer next) - throws IOException - { - String name = id; - - // most builtins are just class aliases - for (int i = 0; i < builtinStages.length; i++) { - if (id.equals (builtinStages [i][0])) { - name = builtinStages [i][1]; - break; - } - } - - // Save output as XML or XHTML text - if ("write".equals (name) || "xhtml".equals (name)) { - String filename; - boolean isXhtml = "xhtml".equals (name); - OutputStream out = null; - TextConsumer consumer; - - if (param == null) - fail ("parameter is required"); - - filename = param.toString (); - if ("stdout".equals (filename)) - out = System.out; - else if ("stderr".equals (filename)) - out = System.err; - else { - File f = new File (filename); - -/* - if (!f.isAbsolute ()) - fail ("require absolute file paths"); - */ - if (f.exists ()) - fail ("file already exists: " + f.getName ()); - -// XXX this races against the existence test - out = new FileOutputStream (f); - } - - if (!isXhtml) - consumer = new TextConsumer (out); - else - consumer = new TextConsumer ( - new OutputStreamWriter (out, "8859_1"), - true); - - consumer.setPrettyPrinting (true); - if (next == null) - return consumer; - return new TeeConsumer (consumer, next); - - } else { - // - // Here go all the builtins that are just aliases for - // classes, and all stage IDs that started out as such - // class names. The following logic relies on several - // documented conventions for constructor invocation. - // - String msg = null; - - try { - Class klass = Class.forName (name); - Class argTypes [] = null; - Constructor constructor = null; - boolean filter = false; - Object params [] = null; - Object obj = null; - - // do we need a filter stage? - if (next != null) { - // "next" consumer is always passed, with - // or without the optional string param - if (param == null) { - argTypes = new Class [1]; - argTypes [0] = EventConsumer.class; - - params = new Object [1]; - params [0] = next; - - msg = "no-param filter"; - } else { - argTypes = new Class [2]; - argTypes [0] = String.class; - argTypes [1] = EventConsumer.class; - - params = new Object [2]; - params [0] = param.toString (); - params [1] = next; - - msg = "one-param filter"; - } - - - try { - constructor = klass.getConstructor (argTypes); - } catch (NoSuchMethodException e) { - // try creating a filter from a - // terminus and a tee - filter = true; - msg += " built from "; - } - } - - // build from a terminus stage, with or - // without the optional string param - if (constructor == null) { - String tmp; - - if (param == null) { - argTypes = new Class [0]; - params = new Object [0]; - - tmp = "no-param terminus"; - } else { - argTypes = new Class [1]; - argTypes [0] = String.class; - - params = new Object [1]; - params [0] = param.toString (); - - tmp = "one-param terminus"; - } - if (msg == null) - msg = tmp; - else - msg += tmp; - constructor = klass.getConstructor (argTypes); - // NOT creating terminus by dead-ending - // filters ... users should think about - // that one, something's likely wrong - } - - obj = constructor.newInstance (params); - - // return EventConsumers directly, perhaps after - // turning them into a filter - if (obj instanceof EventConsumer) { - if (filter) - return new TeeConsumer ((EventConsumer) obj, next); - return (EventConsumer) obj; - } - - // if it's not a handler, it's an error - // we can wrap handlers in a filter - EventFilter retval = new EventFilter (); - boolean updated = false; - - if (obj instanceof ContentHandler) { - retval.setContentHandler ((ContentHandler) obj); - updated = true; - } - if (obj instanceof DTDHandler) { - retval.setDTDHandler ((DTDHandler) obj); - updated = true; - } - if (obj instanceof LexicalHandler) { - retval.setProperty ( - EventFilter.PROPERTY_URI + "lexical-handler", - obj); - updated = true; - } - if (obj instanceof DeclHandler) { - retval.setProperty ( - EventFilter.PROPERTY_URI + "declaration-handler", - obj); - updated = true; - } - - if (!updated) - fail ("class is neither Consumer nor Handler"); - - if (filter) - return new TeeConsumer (retval, next); - return retval; - - } catch (IOException e) { - throw e; - - } catch (NoSuchMethodException e) { - fail (name + " constructor missing -- " + msg); - - } catch (ClassNotFoundException e) { - fail (name + " class not found"); - - } catch (Exception e) { - // e.printStackTrace (); - fail ("stage not available: " + e.getMessage ()); - } - } - // NOTREACHED - return null; - } - } - - private static class Pipeline - { - Stage stage; - - // rest may be null - Pipeline rest; - EventConsumer next; - - Pipeline (Stage s) - { stage = s; } - - public String toString () - { - if (rest == null && next == null) - return stage.toString (); - if (rest != null) - return stage + " | " + rest; - throw new IllegalArgumentException ("next"); - } - - EventConsumer createPipeline () - throws IOException - { - if (next == null) { - if (rest == null) - next = stage.createStage (null); - else - next = stage.createStage (rest.createPipeline ()); - } - return next; - } - } - -/* - public static void main (String argv []) - { - try { - // three basic terminus cases - createPipeline ("null"); - createPipeline ("validate"); - createPipeline ("write ( stdout )"); - - // four basic filters - createPipeline ("nsfix | write ( stderr )"); - createPipeline ("wf | null"); - createPipeline ("null | null"); - createPipeline ( -"call ( http://www.example.com/services/xml-1a ) | xhtml ( stdout )"); - - // tee junctions - createPipeline ("tee ( validate ) | write ( stdout )"); - createPipeline ("tee ( nsfix | write ( stdout ) ) | validate"); - - // longer pipeline - createPipeline ("nsfix | tee ( validate ) | write ( stdout )"); - createPipeline ( - "null | wf | nsfix | tee ( validate ) | write ( stdout )"); - - // try some parsing error cases - try { - createPipeline ("null ("); // extra token '(' - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - try { - createPipeline ("nsfix |"); // extra token '|' - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - try { - createPipeline ("xhtml ( foo"); // missing right paren - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - try { - createPipeline ("xhtml ( foo bar"); // required right paren - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - try { - createPipeline ("tee ( nsfix | validate");// missing right paren - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - // try some construction error cases - - try { - createPipeline ("call"); // missing param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("call ( foobar )"); // broken param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("nsfix ( foobar )"); // illegal param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("null ( foobar )"); // illegal param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("wf ( foobar )"); // illegal param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("xhtml ( foobar.html )"); - new File ("foobar.html").delete (); - // now supported - } catch (Exception e) { - System.err.println ("** err: " + e.getMessage ()); } - try { - createPipeline ("xhtml"); // missing param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("write ( stdout ) | null"); // nonterminal - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("validate | null"); - // now supported - } catch (Exception e) { - System.err.println ("** err: " + e.getMessage ()); } - try { - createPipeline ("validate ( foo )"); // illegal param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - createPipeline ("tee"); // missing param - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - try { - // only builtins so far - createPipeline ("com.example.xml.FilterClass"); - System.err.println ("** didn't report error"); - } catch (Exception e) { - System.err.println ("== err: " + e.getMessage ()); } - - } catch (Exception e) { - e.printStackTrace (); - } - } -/**/ - -} diff --git a/libjava/gnu/xml/pipeline/TeeConsumer.java b/libjava/gnu/xml/pipeline/TeeConsumer.java deleted file mode 100644 index 8186de4df66..00000000000 --- a/libjava/gnu/xml/pipeline/TeeConsumer.java +++ /dev/null @@ -1,417 +0,0 @@ -/* TeeConsumer.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.ext.DeclHandler; -import org.xml.sax.ext.LexicalHandler; - -/** - * Fans its events out to two other consumers, a "tee" filter stage in an - * event pipeline. Networks can be assembled with multiple output points. - * - * <p> Error handling should be simple if you remember that exceptions - * you throw will cancel later stages in that callback's pipeline, and - * generally the producer will stop if it sees such an exception. You - * may want to protect your pipeline against such backflows, making a - * kind of reverse filter (or valve?) so that certain exceptions thrown by - * your pipeline will caught and handled before the producer sees them. - * Just use a "try/catch" block, rememebering that really important - * cleanup tasks should be in "finally" clauses. - * - * <p> That issue isn't unique to "tee" consumers, but tee consumers have - * the additional twist that exceptions thrown by the first consumer - * will cause the second consumer not to see the callback (except for - * the endDocument callback, which signals state cleanup). - * - * @author David Brownell - */ -final public class TeeConsumer - implements EventConsumer, - ContentHandler, DTDHandler, - LexicalHandler,DeclHandler -{ - private EventConsumer first, rest; - - // cached to minimize time overhead - private ContentHandler docFirst, docRest; - private DeclHandler declFirst, declRest; - private LexicalHandler lexFirst, lexRest; - - - /** - * Constructs a consumer which sends all its events to the first - * consumer, and then the second one. If the first consumer throws - * an exception, the second one will not see the event which - * caused that exception to be reported. - * - * @param car The first consumer to get the events - * @param cdr The second consumer to get the events - */ - public TeeConsumer (EventConsumer car, EventConsumer cdr) - { - if (car == null || cdr == null) - throw new NullPointerException (); - first = car; - rest = cdr; - - // - // Cache the handlers. - // - docFirst = first.getContentHandler (); - docRest = rest.getContentHandler (); - // DTD handler isn't cached (rarely needed) - - try { - declFirst = null; - declFirst = (DeclHandler) first.getProperty ( - EventFilter.DECL_HANDLER); - } catch (SAXException e) {} - try { - declRest = null; - declRest = (DeclHandler) rest.getProperty ( - EventFilter.DECL_HANDLER); - } catch (SAXException e) {} - - try { - lexFirst = null; - lexFirst = (LexicalHandler) first.getProperty ( - EventFilter.LEXICAL_HANDLER); - } catch (SAXException e) {} - try { - lexRest = null; - lexRest = (LexicalHandler) rest.getProperty ( - EventFilter.LEXICAL_HANDLER); - } catch (SAXException e) {} - } - -/* FIXME - /** - * Constructs a pipeline, and is otherwise a shorthand for the - * two-consumer constructor for this class. - * - * @param first Description of the first pipeline to get events, - * which will be passed to {@link PipelineFactory#createPipeline} - * @param rest The second pipeline to get the events - * / - // constructor used by PipelineFactory - public TeeConsumer (String first, EventConsumer rest) - throws IOException - { - this (PipelineFactory.createPipeline (first), rest); - } -*/ - - /** Returns the first pipeline to get event calls. */ - public EventConsumer getFirst () - { return first; } - - /** Returns the second pipeline to get event calls. */ - public EventConsumer getRest () - { return rest; } - - /** Returns the content handler being used. */ - final public ContentHandler getContentHandler () - { - if (docRest == null) - return docFirst; - if (docFirst == null) - return docRest; - return this; - } - - /** Returns the dtd handler being used. */ - final public DTDHandler getDTDHandler () - { - // not cached (hardly used) - if (rest.getDTDHandler () == null) - return first.getDTDHandler (); - if (first.getDTDHandler () == null) - return rest.getDTDHandler (); - return this; - } - - /** Returns the declaration or lexical handler being used. */ - final public Object getProperty (String id) - throws SAXNotRecognizedException - { - // - // in degenerate cases, we have no work to do. - // - Object firstProp = null, restProp = null; - - try { firstProp = first.getProperty (id); } - catch (SAXNotRecognizedException e) { /* ignore */ } - try { restProp = rest.getProperty (id); } - catch (SAXNotRecognizedException e) { /* ignore */ } - - if (restProp == null) - return firstProp; - if (firstProp == null) - return restProp; - - // - // we've got work to do; handle two builtin cases. - // - if (EventFilter.DECL_HANDLER.equals (id)) - return this; - if (EventFilter.LEXICAL_HANDLER.equals (id)) - return this; - - // - // non-degenerate, handled by both consumers, but we don't know - // how to handle this. - // - throw new SAXNotRecognizedException ("can't tee: " + id); - } - - /** - * Provides the error handler to both subsequent nodes of - * this filter stage. - */ - public void setErrorHandler (ErrorHandler handler) - { - first.setErrorHandler (handler); - rest.setErrorHandler (handler); - } - - - // - // ContentHandler - // - public void setDocumentLocator (Locator locator) - { - // this call is not made by all parsers - docFirst.setDocumentLocator (locator); - docRest.setDocumentLocator (locator); - } - - public void startDocument () - throws SAXException - { - docFirst.startDocument (); - docRest.startDocument (); - } - - public void endDocument () - throws SAXException - { - try { - docFirst.endDocument (); - } finally { - docRest.endDocument (); - } - } - - public void startPrefixMapping (String prefix, String uri) - throws SAXException - { - docFirst.startPrefixMapping (prefix, uri); - docRest.startPrefixMapping (prefix, uri); - } - - public void endPrefixMapping (String prefix) - throws SAXException - { - docFirst.endPrefixMapping (prefix); - docRest.endPrefixMapping (prefix); - } - - public void skippedEntity (String name) - throws SAXException - { - docFirst.skippedEntity (name); - docRest.skippedEntity (name); - } - - public void startElement (String uri, String localName, - String qName, Attributes atts) - throws SAXException - { - docFirst.startElement (uri, localName, qName, atts); - docRest.startElement (uri, localName, qName, atts); - } - - public void endElement (String uri, String localName, String qName) - throws SAXException - { - docFirst.endElement (uri, localName, qName); - docRest.endElement (uri, localName, qName); - } - - public void processingInstruction (String target, String data) - throws SAXException - { - docFirst.processingInstruction (target, data); - docRest.processingInstruction (target, data); - } - - public void characters (char ch [], int start, int length) - throws SAXException - { - docFirst.characters (ch, start, length); - docRest.characters (ch, start, length); - } - - public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - docFirst.ignorableWhitespace (ch, start, length); - docRest.ignorableWhitespace (ch, start, length); - } - - - // - // DTDHandler - // - public void notationDecl (String name, String publicId, String systemId) - throws SAXException - { - DTDHandler l1 = first.getDTDHandler (); - DTDHandler l2 = rest.getDTDHandler (); - - l1.notationDecl (name, publicId, systemId); - l2.notationDecl (name, publicId, systemId); - } - - public void unparsedEntityDecl (String name, - String publicId, String systemId, - String notationName - ) throws SAXException - { - DTDHandler l1 = first.getDTDHandler (); - DTDHandler l2 = rest.getDTDHandler (); - - l1.unparsedEntityDecl (name, publicId, systemId, notationName); - l2.unparsedEntityDecl (name, publicId, systemId, notationName); - } - - - // - // DeclHandler - // - public void attributeDecl (String eName, String aName, - String type, - String mode, String value) - throws SAXException - { - declFirst.attributeDecl (eName, aName, type, mode, value); - declRest.attributeDecl (eName, aName, type, mode, value); - } - - public void elementDecl (String name, String model) - throws SAXException - { - declFirst.elementDecl (name, model); - declRest.elementDecl (name, model); - } - - public void externalEntityDecl (String name, - String publicId, String systemId) - throws SAXException - { - declFirst.externalEntityDecl (name, publicId, systemId); - declRest.externalEntityDecl (name, publicId, systemId); - } - - public void internalEntityDecl (String name, String value) - throws SAXException - { - declFirst.internalEntityDecl (name, value); - declRest.internalEntityDecl (name, value); - } - - - // - // LexicalHandler - // - public void comment (char ch [], int start, int length) - throws SAXException - { - lexFirst.comment (ch, start, length); - lexRest.comment (ch, start, length); - } - - public void startCDATA () - throws SAXException - { - lexFirst.startCDATA (); - lexRest.startCDATA (); - } - - public void endCDATA () - throws SAXException - { - lexFirst.endCDATA (); - lexRest.endCDATA (); - } - - public void startEntity (String name) - throws SAXException - { - lexFirst.startEntity (name); - lexRest.startEntity (name); - } - - public void endEntity (String name) - throws SAXException - { - lexFirst.endEntity (name); - lexRest.endEntity (name); - } - - public void startDTD (String name, String publicId, String systemId) - throws SAXException - { - lexFirst.startDTD (name, publicId, systemId); - lexRest.startDTD (name, publicId, systemId); - } - - public void endDTD () - throws SAXException - { - lexFirst.endDTD (); - lexRest.endDTD (); - } -} diff --git a/libjava/gnu/xml/pipeline/TextConsumer.java b/libjava/gnu/xml/pipeline/TextConsumer.java deleted file mode 100644 index 67bd23b00d6..00000000000 --- a/libjava/gnu/xml/pipeline/TextConsumer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* TextConsumer.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.*; - -import org.xml.sax.*; - -import gnu.xml.util.XMLWriter; - - -/** - * Terminates a pipeline, consuming events to print them as well formed - * XML (or XHTML) text. - * - * <p> Input must be well formed, and must include XML names (e.g. the - * prefixes and prefix declarations must be present), or the output of - * this class is undefined. - * - * @see NSFilter - * @see WellFormednessFilter - * - * @author David Brownell - */ -public class TextConsumer extends XMLWriter implements EventConsumer -{ - /** - * Constructs an event consumer which echoes its input as text, - * optionally adhering to some basic XHTML formatting options - * which increase interoperability with old (v3) browsers. - * - * <p> For the best interoperability, when writing as XHTML only - * ASCII characters are emitted; other characters are turned to - * entity or character references as needed, and no XML declaration - * is provided in the document. - */ - public TextConsumer (Writer w, boolean isXhtml) - throws IOException - { - super (w, isXhtml ? "US-ASCII" : null); - setXhtml (isXhtml); - } - - /** - * Constructs a consumer that writes its input as XML text. - * XHTML rules are not followed. - */ - public TextConsumer (Writer w) - throws IOException - { - this (w, false); - } - - /** - * Constructs a consumer that writes its input as XML text, - * encoded in UTF-8. XHTML rules are not followed. - */ - public TextConsumer (OutputStream out) - throws IOException - { - this (new OutputStreamWriter (out, "UTF8"), false); - } - - /** <b>EventConsumer</b> Returns the document handler being used. */ - public ContentHandler getContentHandler () - { return this; } - - /** <b>EventConsumer</b> Returns the dtd handler being used. */ - public DTDHandler getDTDHandler () - { return this; } - - /** <b>XMLReader</b>Retrieves a property (lexical and decl handlers) */ - public Object getProperty (String propertyId) - throws SAXNotRecognizedException - { - if (EventFilter.LEXICAL_HANDLER.equals (propertyId)) - return this; - if (EventFilter.DECL_HANDLER.equals (propertyId)) - return this; - throw new SAXNotRecognizedException (propertyId); - } -} diff --git a/libjava/gnu/xml/pipeline/ValidationConsumer.java b/libjava/gnu/xml/pipeline/ValidationConsumer.java deleted file mode 100644 index 2510c768cfb..00000000000 --- a/libjava/gnu/xml/pipeline/ValidationConsumer.java +++ /dev/null @@ -1,1929 +0,0 @@ -/* ValidationConsumer.java -- - Copyright (C) 1999,2000,2001, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.EmptyStackException; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Stack; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.xml.sax.Attributes; -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -/** - * This class checks SAX2 events to report validity errors; it works as - * both a filter and a terminus on an event pipeline. It relies on the - * producer of SAX events to: </p> <ol> - * - * <li> Conform to the specification of a non-validating XML parser that - * reads all external entities, reported using SAX2 events. </li> - * - * <li> Report ignorable whitespace as such (through the ContentHandler - * interface). This is, strictly speaking, optional for nonvalidating - * XML processors. </li> - * - * <li> Make SAX2 DeclHandler callbacks, with default - * attribute values already normalized (and without "<").</li> - * - * <li> Make SAX2 LexicalHandler startDTD() and endDTD () - * callbacks. </li> - * - * <li> Act as if the <em>(URI)/namespace-prefixes</em> property were - * set to true, by providing XML 1.0 names and all <code>xmlns*</code> - * attributes (rather than omitting either or both). </li> - * - * </ol> - * - * <p> At this writing, the major SAX2 parsers (such as Ælfred2, - * Crimson, and Xerces) meet these requirements, and this validation - * module is used by the optional Ælfred2 validation support. - * </p> - * - * <p> Note that because this is a layered validator, it has to duplicate some - * work that the parser is doing; there are also other cost to layering. - * However, <em>because of layering it doesn't need a parser</em> in order - * to work! You can use it with anything that generates SAX events, such - * as an application component that wants to detect invalid content in - * a changed area without validating an entire document, or which wants to - * ensure that it doesn't write invalid data to a communications partner.</p> - * - * <p> Also, note that because this is a layered validator, the line numbers - * reported for some errors may seem strange. For example, if an element does - * not permit character content, the validator - * will use the locator provided to it. - * That might reflect the last character of a <em>characters</em> event - * callback, rather than the first non-whitespace character. </p> - * - * <hr /> - * - * <!-- - * <p> Of interest is the fact that unlike most currently known XML validators, - * this one can report some cases of non-determinism in element content models. - * It is a compile-time option, enabled by default. This will only report - * such XML errors if they relate to content actually appearing in a document; - * content models aren't aggressively scanned for non-deterministic structure. - * Documents which trigger such non-deterministic transitions may be handled - * differently by different validating parsers, without losing conformance - * to the XML specification. </p> - * --> - * - * <p> Current limitations of the validation performed are in roughly three - * categories. </p> - * - * <p> The first category represents constraints which demand violations - * of software layering: exposing lexical details, one of the first things - * that <em>application</em> programming interfaces (APIs) hide. These - * invariably relate to XML entity handling, and to historical oddities - * of the XML validation semantics. Curiously, - * recent (Autumn 1999) conformance testing showed that these constraints are - * among those handled worst by existing XML validating parsers. Arguments - * have been made that each of these VCs should be turned into WFCs (most - * of them) or discarded (popular for the standalone declaration); in short, - * that these are bugs in the XML specification (not all via SGML): </p><ul> - * - * <li> The <em>Proper Declaration/PE Nesting</em> and - * <em>Proper Group/PE Nesting</em> VCs can't be tested because they - * require access to particularly low level lexical level information. - * In essence, the reason XML isn't a simple thing to parse is that - * it's not a context free grammar, and these constraints elevate that - * SGML-derived context sensitivity to the level of a semantic rule. - * - * <li> The <em>Standalone Document Declaration</em> VC can't be - * tested. This is for two reasons. First, this flag isn't made - * available through SAX2. Second, it also requires breaking that - * lexical layering boundary. (If you ever wondered why classes - * in compiler construction or language design barely mention the - * existence of context-sensitive grammars, it's because of messy - * issues like these.) - * - * <li> The <em>Entity Declared</em> VC can't be tested, because it - * also requires breaking that lexical layering boundary! There's also - * another issue: the VC wording (and seemingly intent) is ambiguous. - * (This is still true in the "Second edition" XML spec.) - * Since there is a WFC of the same name, everyone's life would be - * easier if references to undeclared parsed entities were always well - * formedness errors, regardless of whether they're parameter entities - * or not. (Note that nonvalidating parsers are not required - * to report all such well formedness errors if they don't read external - * parameter entities, although currently most XML parsers read them - * in an attempt to avoid problems from inconsistent parser behavior.) - * - * </ul> - * - * <p> The second category of limitations on this validation represent - * constraints associated with information that is not guaranteed to be - * available (or in one case, <em>is guaranteed not to be available</em>, - * through the SAX2 API: </p><ul> - * - * <li> The <em>Unique Element Type Declaration</em> VC may not be - * reportable, if the underlying parser happens not to expose - * multiple declarations. (Ælfred2 reports these validity - * errors directly.)</li> - * - * <li> Similarly, the <em>Unique Notation Name</em> VC, added in the - * 14-January-2000 XML spec errata to restrict typing models used by - * elements, may not be reportable. (Ælfred reports these - * validity errors directly.) </li> - * - * </ul> - * - * <p> A third category relates to ease of implementation. (Think of this - * as "bugs".) The most notable issue here is character handling. Rather - * than attempting to implement the voluminous character tables in the XML - * specification (Appendix B), Unicode rules are used directly from - * the java.lang.Character class. Recent JVMs have begun to diverge from - * the original specification for that class (Unicode 2.0), meaning that - * different JVMs may handle that aspect of conformance differently. - * </p> - * - * <p> Note that for some of the validity errors that SAX2 does not - * expose, a nonvalidating parser is permitted (by the XML specification) - * to report validity errors. When used with a parser that does so for - * the validity constraints mentioned above (or any other SAX2 event - * stream producer that does the same thing), overall conformance is - * substantially improved. - * - * @see gnu.xml.aelfred2.SAXDriver - * @see gnu.xml.aelfred2.XmlReader - * - * @author David Brownell - */ -public final class ValidationConsumer extends EventFilter -{ - // report error if we happen to notice a non-deterministic choice? - // we won't report buggy content models; just buggy instances - private static final boolean warnNonDeterministic = false; - - // for tracking active content models - private String rootName; - private Stack contentStack = new Stack (); - - // flags for "saved DTD" processing - private boolean disableDeclarations; - private boolean disableReset; - - // - // most VCs get tested when we see element start tags. the per-element - // info (including attributes) recorded here duplicates that found inside - // many nonvalidating parsers, hence dual lookups etc ... that's why a - // layered validator isn't going to be as fast as a non-layered one. - // - - // key = element name; value = ElementInfo - private Hashtable elements = new Hashtable (); - - // some VCs relate to ID/IDREF/IDREFS attributes - // key = id; value = boolean true (defd) or false (refd) - private Hashtable ids = new Hashtable (); - - // we just record declared notation and unparsed entity names. - // the implementation here is simple/slow; these features - // are seldom used, one hopes they'll wither away soon - private Vector notations = new Vector (5, 5); - private Vector nDeferred = new Vector (5, 5); - private Vector unparsed = new Vector (5, 5); - private Vector uDeferred = new Vector (5, 5); - - // note: DocBk 3.1.7 XML defines over 2 dozen notations, - // used when defining unparsed entities for graphics - // (and maybe in other places) - - - - /** - * Creates a pipeline terminus which consumes all events passed to - * it; this will report validity errors as if they were fatal errors, - * unless an error handler is assigned. - * - * @see #setErrorHandler - */ - // constructor used by PipelineFactory - // ... and want one taking system ID of an external subset - public ValidationConsumer () - { - this (null); - } - - /** - * Creates a pipeline filter which reports validity errors and then - * passes events on to the next consumer if they were not fatal. - * - * @see #setErrorHandler - */ - // constructor used by PipelineFactory - // ... and want one taking system ID of an external subset - // (which won't send declaration events) - public ValidationConsumer (EventConsumer next) - { - super (next); - - setContentHandler (this); - setDTDHandler (this); - try { setProperty (DECL_HANDLER, this); } - catch (Exception e) { /* "can't happen" */ } - try { setProperty (LEXICAL_HANDLER, this); } - catch (Exception e) { /* "can't happen" */ } - } - - - private static final String fakeRootName - = ":Nobody:in:their_Right.Mind_would:use:this-name:1x:"; - - /** - * Creates a validation consumer which is preloaded with the DTD provided. - * It does this by constructing a document with that DTD, then parsing - * that document and recording its DTD declarations. Then it arranges - * not to modify that information. - * - * <p> The resulting validation consumer will only validate against - * the specified DTD, regardless of whether some other DTD is found - * in a document being parsed. - * - * @param rootName The name of the required root element; if this is - * null, any root element name will be accepted. - * @param publicId If non-null and there is a non-null systemId, this - * identifier provides an alternate access identifier for the DTD's - * external subset. - * @param systemId If non-null, this is a URI (normally URL) that - * may be used to access the DTD's external subset. - * @param internalSubset If non-null, holds literal markup declarations - * comprising the DTD's internal subset. - * @param resolver If non-null, this will be provided to the parser for - * use when resolving parameter entities (including any external subset). - * @param resolver If non-null, this will be provided to the parser for - * use when resolving parameter entities (including any external subset). - * @param minimalElement If non-null, a minimal valid document. - * - * @exception SAXNotSupportedException If the default SAX parser does - * not support the standard lexical or declaration handlers. - * @exception SAXParseException If the specified DTD has either - * well-formedness or validity errors - * @exception IOException If the specified DTD can't be read for - * some reason - */ - public ValidationConsumer ( - String rootName, - String publicId, - String systemId, - String internalSubset, - EntityResolver resolver, - String minimalDocument - ) throws SAXException, IOException - { - this (null); - - disableReset = true; - if (rootName == null) - rootName = fakeRootName; - - // - // Synthesize document with that DTD; is it possible to do - // better for the declaration of the root element? - // - // NOTE: can't use SAX2 to write internal subsets. - // - StringWriter writer = new StringWriter (); - - writer.write ("<!DOCTYPE "); - writer.write (rootName); - if (systemId != null) { - writer.write ("\n "); - if (publicId != null) { - writer.write ("PUBLIC '"); - writer.write (publicId); - writer.write ("'\n\t'"); - } else - writer.write ("SYSTEM '"); - writer.write (systemId); - writer.write ("'"); - } - writer.write (" [ "); - if (rootName == fakeRootName) { - writer.write ("\n<!ELEMENT "); - writer.write (rootName); - writer.write (" EMPTY>"); - } - if (internalSubset != null) - writer.write (internalSubset); - writer.write ("\n ]>"); - - if (minimalDocument != null) { - writer.write ("\n"); - writer.write (minimalDocument); - writer.write ("\n"); - } else { - writer.write (" <"); - writer.write (rootName); - writer.write ("/>\n"); - } - minimalDocument = writer.toString (); - - // - // OK, load it - // - XMLReader producer; - - producer = XMLReaderFactory.createXMLReader (); - bind (producer, this); - - if (resolver != null) - producer.setEntityResolver (resolver); - - InputSource in; - - in = new InputSource (new StringReader (minimalDocument)); - producer.parse (in); - - disableDeclarations = true; - if (rootName == fakeRootName) - this.rootName = null; - } - - private void resetState () - { - if (!disableReset) { - rootName = null; - contentStack.removeAllElements (); - elements.clear (); - ids.clear (); - - notations.removeAllElements (); - nDeferred.removeAllElements (); - unparsed.removeAllElements (); - uDeferred.removeAllElements (); - } - } - - - private void warning (String description) - throws SAXException - { - ErrorHandler errHandler = getErrorHandler (); - Locator locator = getDocumentLocator (); - SAXParseException err; - - if (errHandler == null) - return; - - if (locator == null) - err = new SAXParseException (description, null, null, -1, -1); - else - err = new SAXParseException (description, locator); - errHandler.warning (err); - } - - // package private (for ChildrenRecognizer) - private void error (String description) - throws SAXException - { - ErrorHandler errHandler = getErrorHandler (); - Locator locator = getDocumentLocator (); - SAXParseException err; - - if (locator == null) - err = new SAXParseException (description, null, null, -1, -1); - else - err = new SAXParseException (description, locator); - if (errHandler != null) - errHandler.error (err); - else // else we always treat it as fatal! - throw err; - } - - private void fatalError (String description) - throws SAXException - { - ErrorHandler errHandler = getErrorHandler (); - Locator locator = getDocumentLocator (); - SAXParseException err; - - if (locator != null) - err = new SAXParseException (description, locator); - else - err = new SAXParseException (description, null, null, -1, -1); - if (errHandler != null) - errHandler.fatalError (err); - // we always treat this as fatal, regardless of the handler - throw err; - } - - - private static boolean isExtender (char c) - { - // [88] Extender ::= ... - return c == 0x00b7 || c == 0x02d0 || c == 0x02d1 || c == 0x0387 - || c == 0x0640 || c == 0x0e46 || c == 0x0ec6 || c == 0x3005 - || (c >= 0x3031 && c <= 0x3035) - || (c >= 0x309d && c <= 0x309e) - || (c >= 0x30fc && c <= 0x30fe); - } - - - // use augmented Unicode rules, not full XML rules - private boolean isName (String name, String context, String id) - throws SAXException - { - char buf [] = name.toCharArray (); - boolean pass = true; - - if (!Character.isUnicodeIdentifierStart (buf [0]) - && ":_".indexOf (buf [0]) == -1) - pass = false; - else { - int max = buf.length; - for (int i = 1; pass && i < max; i++) { - char c = buf [i]; - if (!Character.isUnicodeIdentifierPart (c) - && ":-_.".indexOf (c) == -1 - && !isExtender (c)) - pass = false; - } - } - - if (!pass) - error ("In " + context + " for " + id - + ", '" + name + "' is not a name"); - return pass; // true == OK - } - - // use augmented Unicode rules, not full XML rules - private boolean isNmtoken (String nmtoken, String context, String id) - throws SAXException - { - char buf [] = nmtoken.toCharArray (); - boolean pass = true; - int max = buf.length; - - // XXX make this share code with isName - - for (int i = 0; pass && i < max; i++) { - char c = buf [i]; - if (!Character.isUnicodeIdentifierPart (c) - && ":-_.".indexOf (c) == -1 - && !isExtender (c)) - pass = false; - } - - if (!pass) - error ("In " + context + " for " + id - + ", '" + nmtoken + "' is not a name token"); - return pass; // true == OK - } - - private void checkEnumeration (String value, String type, String name) - throws SAXException - { - if (!hasMatch (value, type)) - // VC: Enumeration - error ("Value '" + value - + "' for attribute '" + name - + "' is not permitted: " + type); - } - - // used to test enumerated attributes and mixed content models - // package private - static boolean hasMatch (String value, String orList) - { - int len = value.length (); - int max = orList.length () - len; - - for (int start = 0; - (start = orList.indexOf (value, start)) != -1; - start++) { - char c; - - if (start > max) - break; - c = orList.charAt (start - 1); - if (c != '|' && c != '('/*)*/) - continue; - c = orList.charAt (start + len); - if (c != '|' && /*(*/ c != ')') - continue; - return true; - } - return false; - } - - /** - * <b>LexicalHandler</b> Records the declaration of the root - * element, so it can be verified later. - * Passed to the next consumer, unless this one was - * preloaded with a particular DTD. - */ - public void startDTD (String name, String publicId, String systemId) - throws SAXException - { - if (disableDeclarations) - return; - - rootName = name; - super.startDTD (name, publicId, systemId); - } - - /** - * <b>LexicalHandler</b> Verifies that all referenced notations - * and unparsed entities have been declared. - * Passed to the next consumer, unless this one was - * preloaded with a particular DTD. - */ - public void endDTD () - throws SAXException - { - if (disableDeclarations) - return; - - // this is a convenient hook for end-of-dtd checks, but we - // could also trigger it in the first startElement call. - // locator info is more appropriate here though. - - // VC: Notation Declared (NDATA can refer to them before decls, - // as can NOTATION attribute enumerations and defaults) - int length = nDeferred.size (); - for (int i = 0; i < length; i++) { - String notation = (String) nDeferred.elementAt (i); - if (!notations.contains (notation)) { - error ("A declaration referred to notation '" + notation - + "' which was never declared"); - } - } - nDeferred.removeAllElements (); - - // VC: Entity Name (attribute values can refer to them - // before they're declared); VC Attribute Default Legal - length = uDeferred.size (); - for (int i = 0; i < length; i++) { - String entity = (String) uDeferred.elementAt (i); - if (!unparsed.contains (entity)) { - error ("An attribute default referred to entity '" + entity - + "' which was never declared"); - } - } - uDeferred.removeAllElements (); - super.endDTD (); - } - - - // These are interned, so we can rely on "==" to find the type of - // all attributes except enumerations ... - // "(this|or|that|...)" and "NOTATION (this|or|that|...)" - static final String types [] = { - "CDATA", - "ID", "IDREF", "IDREFS", - "NMTOKEN", "NMTOKENS", - "ENTITY", "ENTITIES" - }; - - - /** - * <b>DecllHandler</b> Records attribute declaration for later use - * in validating document content, and checks validity constraints - * that are applicable to attribute declarations. - * Passed to the next consumer, unless this one was - * preloaded with a particular DTD. - */ - public void attributeDecl ( - String eName, - String aName, - String type, - String mode, - String value - ) throws SAXException - { - if (disableDeclarations) - return; - - ElementInfo info = (ElementInfo) elements.get (eName); - AttributeInfo ainfo = new AttributeInfo (); - boolean checkOne = false; - boolean interned = false; - - // cheap interning of type names and #FIXED, #REQUIRED - // for faster startElement (we can use "==") - for (int i = 0; i < types.length; i++) { - if (types [i].equals (type)) { - type = types [i]; - interned = true; - break; - } - } - if ("#FIXED".equals (mode)) - mode = "#FIXED"; - else if ("#REQUIRED".equals (mode)) - mode = "#REQUIRED"; - - ainfo.type = type; - ainfo.mode = mode; - ainfo.value = value; - - // we might not have seen the content model yet - if (info == null) { - info = new ElementInfo (eName); - elements.put (eName, info); - } - if ("ID" == type) { - checkOne = true; - if (!("#REQUIRED" == mode || "#IMPLIED".equals (mode))) { - // VC: ID Attribute Default - error ("ID attribute '" + aName - + "' must be #IMPLIED or #REQUIRED"); - } - - } else if (!interned && type.startsWith ("NOTATION ")) { - checkOne = true; - - // VC: Notation Attributes (notations must be declared) - StringTokenizer tokens = new StringTokenizer ( - type.substring (10, type.lastIndexOf (')')), - "|"); - while (tokens.hasMoreTokens ()) { - String token = tokens.nextToken (); - if (!notations.contains (token)) - nDeferred.addElement (token); - } - } - if (checkOne) { - for (Enumeration e = info.attributes.keys (); - e.hasMoreElements (); - /* NOP */) { - String name; - AttributeInfo ainfo2; - - name = (String) e.nextElement (); - ainfo2 = (AttributeInfo) info.attributes.get (name); - if (type == ainfo2.type || !interned /* NOTATION */) { - // VC: One ID per Element Type - // VC: One Notation per Element TYpe - error ("Element '" + eName - + "' already has an attribute of type " - + (interned ? "NOTATION" : type) - + " ('" + name - + "') so '" + aName - + "' is a validity error"); - } - } - } - - // VC: Attribute Default Legal - if (value != null) { - - if ("CDATA" == type) { - // event source rejected '<' - - } else if ("NMTOKEN" == type) { - // VC: Name Token (is a nmtoken) - isNmtoken (value, "attribute default", aName); - - } else if ("NMTOKENS" == type) { - // VC: Name Token (is a nmtoken; at least one value) - StringTokenizer tokens = new StringTokenizer (value); - if (!tokens.hasMoreTokens ()) - error ("Default for attribute '" + aName - + "' must have at least one name token."); - else do { - String token = tokens.nextToken (); - isNmtoken (token, "attribute default", aName); - } while (tokens.hasMoreTokens ()); - - } else if ("IDREF" == type || "ENTITY" == type) { - // VC: Entity Name (is a name) - // VC: IDREF (is a name) (is declared) - isName (value, "attribute default", aName); - if ("ENTITY" == type && !unparsed.contains (value)) - uDeferred.addElement (value); - - } else if ("IDREFS" == type || "ENTITIES" == type) { - // VC: Entity Name (is a name; at least one value) - // VC: IDREF (is a name; at least one value) - StringTokenizer names = new StringTokenizer (value); - if (!names.hasMoreTokens ()) - error ("Default for attribute '" + aName - + "' must have at least one name."); - else do { - String name = names.nextToken (); - isName (name, "attribute default", aName); - if ("ENTITIES" == type && !unparsed.contains (name)) - uDeferred.addElement (value); - } while (names.hasMoreTokens ()); - - } else if (type.charAt (0) == '(' /*)*/ ) { - // VC: Enumeration (must match) - checkEnumeration (value, type, aName); - - } else if (!interned && checkOne) { /* NOTATION */ - // VC: Notation attributes (must be names) - isName (value, "attribute default", aName); - - // VC: Notation attributes (must be declared) - if (!notations.contains (value)) - nDeferred.addElement (value); - - // VC: Enumeration (must match) - checkEnumeration (value, type, aName); - - } else if ("ID" != type) - throw new RuntimeException ("illegal attribute type: " + type); - } - - if (info.attributes.get (aName) == null) - info.attributes.put (aName, ainfo); - /* - else - warning ("Element '" + eName - + "' already has an attribute named '" + aName + "'"); - */ - - if ("xml:space".equals (aName)) { - if (!("(default|preserve)".equals (type) - || "(preserve|default)".equals (type) - // these next two are arguable; XHTML's DTD doesn't - // deserve errors. After all, it's not like any - // illegal _value_ could pass ... - || "(preserve)".equals (type) - || "(default)".equals (type) - )) - error ( - "xml:space attribute type must be like '(default|preserve)'" - + " not '" + type + "'" - ); - - } - super.attributeDecl (eName, aName, type, mode, value); - } - - /** - * <b>DecllHandler</b> Records the element declaration for later use - * when checking document content, and checks validity constraints that - * apply to element declarations. Passed to the next consumer, unless - * this one was preloaded with a particular DTD. - */ - public void elementDecl (String name, String model) - throws SAXException - { - if (disableDeclarations) - return; - - ElementInfo info = (ElementInfo) elements.get (name); - - // we might have seen an attribute decl already - if (info == null) { - info = new ElementInfo (name); - elements.put (name, info); - } - if (info.model != null) { - // NOTE: not all parsers can report such duplicates. - // VC: Unique Element Type Declaration - error ("Element type '" + name - + "' was already declared."); - } else { - info.model = model; - - // VC: No Duplicate Types (in mixed content models) - if (model.charAt (1) == '#') // (#PCDATA... - info.getRecognizer (this); - } - super.elementDecl (name, model); - } - - /** - * <b>DecllHandler</b> passed to the next consumer, unless this - * one was preloaded with a particular DTD - */ - public void internalEntityDecl (String name, String value) - throws SAXException - { - if (!disableDeclarations) - super.internalEntityDecl (name, value); - } - - /** - * <b>DecllHandler</b> passed to the next consumer, unless this - * one was preloaded with a particular DTD - */ - public void externalEntityDecl (String name, - String publicId, String systemId) - throws SAXException - { - if (!disableDeclarations) - super.externalEntityDecl (name, publicId, systemId); - } - - - /** - * <b>DTDHandler</b> Records the notation name, for checking - * NOTATIONS attribute values and declararations of unparsed - * entities. Passed to the next consumer, unless this one was - * preloaded with a particular DTD. - */ - public void notationDecl (String name, String publicId, String systemId) - throws SAXException - { - if (disableDeclarations) - return; - - notations.addElement (name); - super.notationDecl (name, publicId, systemId); - } - - /** - * <b>DTDHandler</b> Records the entity name, for checking - * ENTITY and ENTITIES attribute values; records the notation - * name if it hasn't yet been declared. Passed to the next consumer, - * unless this one was preloaded with a particular DTD. - */ - public void unparsedEntityDecl ( - String name, - String publicId, - String systemId, - String notationName - ) throws SAXException - { - if (disableDeclarations) - return; - - unparsed.addElement (name); - if (!notations.contains (notationName)) - nDeferred.addElement (notationName); - super.unparsedEntityDecl (name, publicId, systemId, notationName); - } - - - /** - * <b>ContentHandler</b> Ensures that state from any previous parse - * has been deleted. - * Passed to the next consumer. - */ - public void startDocument () - throws SAXException - { - resetState (); - super.startDocument (); - } - - - private static boolean isAsciiLetter (char c) - { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); - } - - - /** - * <b>ContentHandler</b> Reports a fatal exception. Validating - * XML processors may not skip any entities. - */ - public void skippedEntity (String name) - throws SAXException - { - fatalError ("may not skip entities"); - } - - /* - * SAX2 doesn't expand non-PE refs in attribute defaults... - */ - private String expandDefaultRefs (String s) - throws SAXException - { - if (s.indexOf ('&') < 0) - return s; - -// FIXME: handle &#nn; &#xnn; &name; - String message = "Can't expand refs in attribute default: " + s; - warning (message); - - return s; - } - - /** - * <b>ContentHandler</b> Performs validity checks against element - * (and document) content models, and attribute values. - * Passed to the next consumer. - */ - public void startElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - // - // First check content model for the enclosing scope. - // - if (contentStack.isEmpty ()) { - // VC: Root Element Type - if (!qName.equals (rootName)) { - if (rootName == null) - warning ("This document has no DTD, can't be valid"); - else - error ("Root element type '" + qName - + "' was declared to be '" + rootName + "'"); - } - } else { - Recognizer state = (Recognizer) contentStack.peek (); - - if (state != null) { - Recognizer newstate = state.acceptElement (qName); - - if (newstate == null) - error ("Element type '" + qName - + "' in element '" + state.type.name - + "' violates content model " + state.type.model - ); - if (newstate != state) { - contentStack.pop (); - contentStack.push (newstate); - } - } - } - - // - // Then check that this element was declared, and push the - // object used to validate its content model onto our stack. - // - // This is where the recognizer gets created, if needed; if - // it's a "children" (elements) content model, an NDFA is - // created. (One recognizer is used per content type, no - // matter how complex that recognizer is.) - // - ElementInfo info; - - info = (ElementInfo) elements.get (qName); - if (info == null || info.model == null) { - // VC: Element Valid (base clause) - error ("Element type '" + qName + "' was not declared"); - contentStack.push (null); - - // for less diagnostic noise, fake a declaration. - elementDecl (qName, "ANY"); - } else - contentStack.push (info.getRecognizer (this)); - - // - // Then check each attribute present - // - int len; - String aname; - AttributeInfo ainfo; - - if (atts != null) - len = atts.getLength (); - else - len = 0; - - for (int i = 0; i < len; i++) { - aname = atts.getQName (i); - - if (info == null - || (ainfo = (AttributeInfo) info.attributes.get (aname)) - == null) { - // VC: Attribute Value Type - error ("Attribute '" + aname - + "' was not declared for element type " + qName); - continue; - } - - String value = atts.getValue (i); - - // note that "==" for type names and "#FIXED" is correct - // (and fast) since we've interned those literals. - - if ("#FIXED" == ainfo.mode) { - String expanded = expandDefaultRefs (ainfo.value); - - // VC: Fixed Attribute Default - if (!value.equals (expanded)) { - error ("Attribute '" + aname - + "' must match " + expanded - ); - continue; - } - } - - if ("CDATA" == ainfo.type) - continue; - - // - // For all other attribute types, there are various - // rules to follow. - // - - if ("ID" == ainfo.type) { - // VC: ID (must be a name) - if (isName (value, "ID attribute", aname)) { - if (Boolean.TRUE == ids.get (value)) - // VC: ID (appears once) - error ("ID attribute " + aname - + " uses an ID value '" + value - + "' which was already declared."); - else - // any forward refs are no longer problems - ids.put (value, Boolean.TRUE); - } - continue; - } - - if ("IDREF" == ainfo.type) { - // VC: IDREF (value must be a name) - if (isName (value, "IDREF attribute", aname)) { - // VC: IDREF (must match some ID attribute) - if (ids.get (value) == null) - // new -- assume it's a forward ref - ids.put (value, Boolean.FALSE); - } - continue; - } - - if ("IDREFS" == ainfo.type) { - StringTokenizer tokens = new StringTokenizer (value, " "); - - if (!tokens.hasMoreTokens ()) { - // VC: IDREF (one or more values) - error ("IDREFS attribute " + aname - + " must have at least one ID ref"); - } else do { - String id = tokens.nextToken (); - - // VC: IDREF (value must be a name) - if (isName (id, "IDREFS attribute", aname)) { - // VC: IDREF (must match some ID attribute) - if (ids.get (id) == null) - // new -- assume it's a forward ref - ids.put (id, Boolean.FALSE); - } - } while (tokens.hasMoreTokens ()); - continue; - } - - if ("NMTOKEN" == ainfo.type) { - // VC: Name Token (is a name token) - isNmtoken (value, "NMTOKEN attribute", aname); - continue; - } - - if ("NMTOKENS" == ainfo.type) { - StringTokenizer tokens = new StringTokenizer (value, " "); - - if (!tokens.hasMoreTokens ()) { - // VC: Name Token (one or more values) - error ("NMTOKENS attribute " + aname - + " must have at least one name token"); - } else do { - String token = tokens.nextToken (); - - // VC: Name Token (is a name token) - isNmtoken (token, "NMTOKENS attribute", aname); - } while (tokens.hasMoreTokens ()); - continue; - } - - if ("ENTITY" == ainfo.type) { - if (!unparsed.contains (value)) - // VC: Entity Name - error ("Value of attribute '" + aname - + "' refers to unparsed entity '" + value - + "' which was not declared."); - continue; - } - - if ("ENTITIES" == ainfo.type) { - StringTokenizer tokens = new StringTokenizer (value, " "); - - if (!tokens.hasMoreTokens ()) { - // VC: Entity Name (one or more values) - error ("ENTITIES attribute " + aname - + " must have at least one name token"); - } else do { - String entity = tokens.nextToken (); - - if (!unparsed.contains (entity)) - // VC: Entity Name - error ("Value of attribute '" + aname - + "' refers to unparsed entity '" + entity - + "' which was not declared."); - } while (tokens.hasMoreTokens ()); - continue; - } - - // - // check for enumerations last; more expensive - // - if (ainfo.type.charAt (0) == '(' /*)*/ - || ainfo.type.startsWith ("NOTATION ") - ) { - // VC: Enumeration (value must be defined) - checkEnumeration (value, ainfo.type, aname); - continue; - } - } - - // - // Last, check that all #REQUIRED attributes were provided - // - if (info != null) { - Hashtable table = info.attributes; - - if (table.size () != 0) { - Enumeration e = table.keys (); - - // XXX table.keys uses the heap, bleech -- slows things - - while (e.hasMoreElements ()) { - aname = (String) e.nextElement (); - ainfo = (AttributeInfo) table.get (aname); - - // "#REQUIRED" mode was interned in attributeDecl - if ("#REQUIRED" == ainfo.mode - && atts.getValue (aname) == null) { - // VC: Required Attribute - error ("Attribute '" + aname + "' must be specified " - + "for element type " + qName); - } - } - } - } - super.startElement (uri, localName, qName, atts); - } - - /** - * <b>ContentHandler</b> Reports a validity error if the element's content - * model does not permit character data. - * Passed to the next consumer. - */ - public void characters (char ch [], int start, int length) - throws SAXException - { - Recognizer state; - - if (contentStack.empty ()) - state = null; - else - state = (Recognizer) contentStack.peek (); - - // NOTE: if this ever supports with SAX parsers that don't - // report ignorable whitespace as such (only XP?), this class - // needs to morph it into ignorableWhitespace() as needed ... - - if (state != null && !state.acceptCharacters ()) - // VC: Element Valid (clauses three, four -- see recognizer) - error ("Character content not allowed in element " - + state.type.name); - - super.characters (ch, start, length); - } - - - /** - * <b>ContentHandler</b> Reports a validity error if the element's content - * model does not permit end-of-element yet, or a well formedness error - * if there was no matching startElement call. - * Passed to the next consumer. - */ - public void endElement (String uri, String localName, String qName) - throws SAXException - { - try { - Recognizer state = (Recognizer) contentStack.pop (); - - if (state != null && !state.completed ()) - // VC: Element valid (clauses two, three, four; see Recognizer) - error ("Premature end for element '" - + state.type.name - + "', content model " - + state.type.model); - - // could insist on match of start element, but that's - // something the input stream must to guarantee. - - } catch (EmptyStackException e) { - fatalError ("endElement without startElement: " + qName - + ((uri == null) - ? "" - : ( " { '" + uri + "', " + localName + " }"))); - } - super.endElement (uri, localName, qName); - } - - /** - * <b>ContentHandler</b> Checks whether all ID values that were - * referenced have been declared, and releases all resources. - * Passed to the next consumer. - * - * @see #setDocumentLocator - */ - public void endDocument () - throws SAXException - { - for (Enumeration idNames = ids.keys (); - idNames.hasMoreElements (); - /* NOP */) { - String id = (String) idNames.nextElement (); - - if (Boolean.FALSE == ids.get (id)) { - // VC: IDREF (must match ID) - error ("Undeclared ID value '" + id - + "' was referred to by an IDREF/IDREFS attribute"); - } - } - - resetState (); - super.endDocument (); - } - - - /** Holds per-element declarations */ - static private final class ElementInfo - { - String name; - String model; - - // key = attribute name; value = AttributeInfo - Hashtable attributes = new Hashtable (11); - - ElementInfo (String n) { name = n; } - - private Recognizer recognizer; - - // for validating content models: one per type, shared, - // and constructed only on demand ... so unused elements do - // not need to consume resources. - Recognizer getRecognizer (ValidationConsumer consumer) - throws SAXException - { - if (recognizer == null) { - if ("ANY".equals (model)) - recognizer = ANY; - else if ("EMPTY".equals (model)) - recognizer = new EmptyRecognizer (this); - else if ('#' == model.charAt (1)) - // n.b. this constructor does a validity check - recognizer = new MixedRecognizer (this, consumer); - else - recognizer = new ChildrenRecognizer (this, consumer); - } - return recognizer; - } - } - - /** Holds per-attribute declarations */ - static private final class AttributeInfo - { - String type; - String mode; // #REQUIRED, etc (or null) - String value; // or null - } - - - // - // Content model validation - // - - // GCJ LOCAL: package private to work around gcj bug. - static final Recognizer ANY = new Recognizer (null); - - - // Base class defines the calls used to validate content, - // and supports the "ANY" content model - static private class Recognizer - { - final ElementInfo type; - - Recognizer (ElementInfo t) { type = t; } - - // return true iff character data is legal here - boolean acceptCharacters () - throws SAXException - // VC: Element Valid (third and fourth clauses) - { return true; } - - // null return = failure - // otherwise, next state (like an FSM) - // prerequisite: tested that name was declared - Recognizer acceptElement (String name) - throws SAXException - // VC: Element Valid (fourth clause) - { return this; } - - // return true iff model is completed, can finish - boolean completed () - throws SAXException - // VC: Element Valid (fourth clause) - { return true; } - - public String toString () - // n.b. "children" is the interesting case! - { return (type == null) ? "ANY" : type.model; } - } - - // "EMPTY" content model -- no characters or elements - private static final class EmptyRecognizer extends Recognizer - { - public EmptyRecognizer (ElementInfo type) - { super (type); } - - // VC: Element Valid (first clause) - boolean acceptCharacters () - { return false; } - - // VC: Element Valid (first clause) - Recognizer acceptElement (String name) - { return null; } - } - - // "Mixed" content model -- ANY, but restricts elements - private static final class MixedRecognizer extends Recognizer - { - private String permitted []; - - // N.B. constructor tests for duplicated element names (VC) - public MixedRecognizer (ElementInfo t, ValidationConsumer v) - throws SAXException - { - super (t); - - // (#PCDATA...)* or (#PCDATA) ==> ... or empty - // with the "..." being "|elname|..." - StringTokenizer tokens = new StringTokenizer ( - t.model.substring (8, t.model.lastIndexOf (')')), - "|"); - Vector vec = new Vector (); - - while (tokens.hasMoreTokens ()) { - String token = tokens.nextToken (); - - if (vec.contains (token)) - v.error ("element " + token - + " is repeated in mixed content model: " - + t.model); - else - vec.addElement (token.intern ()); - } - permitted = new String [vec.size ()]; - for (int i = 0; i < permitted.length; i++) - permitted [i] = (String) vec.elementAt (i); - - // in one large machine-derived DTD sample, most of about - // 250 mixed content models were empty, and 25 had ten or - // more entries. 2 had over a hundred elements. Linear - // search isn't obviously wrong. - } - - // VC: Element Valid (third clause) - Recognizer acceptElement (String name) - { - int length = permitted.length; - - // first pass -- optimistic w.r.t. event source interning - // (and document validity) - for (int i = 0; i < length; i++) - if (permitted [i] == name) - return this; - // second pass -- pessimistic w.r.t. event source interning - for (int i = 0; i < length; i++) - if (permitted [i].equals (name)) - return this; - return null; - } - } - - - // recognizer loop flags, see later - private static final int F_LOOPHEAD = 0x01; - private static final int F_LOOPNEXT = 0x02; - - // for debugging -- used to label/count nodes in toString() - private static int nodeCount; - - /** - * "Children" content model -- these are nodes in NDFA state graphs. - * They work in fixed space. Note that these graphs commonly have - * cycles, handling features such as zero-or-more and one-or-more. - * - * <p>It's readonly, so only one copy is ever needed. The content model - * stack may have any number of pointers into each graph, when a model - * happens to be needed more than once due to element nesting. Since - * traversing the graph just moves to another node, and never changes - * it, traversals never interfere with each other. - * - * <p>There is an option to report non-deterministic models. These are - * always XML errors, but ones which are not often reported despite the - * fact that they can lead to different validating parsers giving - * different results for the same input. (The XML spec doesn't require - * them to be reported.) - * - * <p><b>FIXME</b> There's currently at least one known bug here, in that - * it's not actually detecting the non-determinism it tries to detect. - * (Of the "optional.xml" test, the once-or-twice-2* tests are all non-D; - * maybe some others.) This may relate to the issue flagged below as - * "should not" happen (but it was), which showed up when patching the - * graph to have one exit node (or more EMPTY nodes). - */ - private static final class ChildrenRecognizer extends Recognizer - implements Cloneable - { - // for reporting non-deterministic content models - // ... a waste of space if we're not reporting those! - // ... along with the 'model' member (in base class) - private ValidationConsumer consumer; - - // for CHOICE nodes -- each component is an arc that - // accepts a different NAME (or is EMPTY indicating - // NDFA termination). - private Recognizer components []; - - // for NAME/SEQUENCE nodes -- accepts that NAME and - // then goes to the next node (CHOICE, NAME, EMPTY). - private String name; - private Recognizer next; - - // loops always point back to a CHOICE node. we mark such choice - // nodes (F_LOOPHEAD) for diagnostics and faster deep cloning. - // We also mark nodes before back pointers (F_LOOPNEXT), to ensure - // termination when we patch sequences and loops. - private int flags; - - - // prevent a needless indirection between 'this' and 'node' - private void copyIn (ChildrenRecognizer node) - { - // model & consumer are already set - components = node.components; - name = node.name; - next = node.next; - flags = node.flags; - } - - // used to construct top level "children" content models, - public ChildrenRecognizer (ElementInfo type, ValidationConsumer vc) - { - this (vc, type); - populate (type.model.toCharArray (), 0); - patchNext (new EmptyRecognizer (type), null); - } - - // used internally; populating is separate - private ChildrenRecognizer (ValidationConsumer vc, ElementInfo type) - { - super (type); - consumer = vc; - } - - - // - // When rewriting some graph nodes we need deep clones in one case; - // mostly shallow clones (what the JVM handles for us) are fine. - // - private ChildrenRecognizer shallowClone () - { - try { - return (ChildrenRecognizer) clone (); - } catch (CloneNotSupportedException e) { - throw new Error ("clone"); - } - } - - private ChildrenRecognizer deepClone () - { - return deepClone (new Hashtable (37)); - } - - private ChildrenRecognizer deepClone (Hashtable table) - { - ChildrenRecognizer retval; - - if ((flags & F_LOOPHEAD) != 0) { - retval = (ChildrenRecognizer) table.get (this); - if (retval != null) - return this; - - retval = shallowClone (); - table.put (this, retval); - } else - retval = shallowClone (); - - if (next != null) { - if (next instanceof ChildrenRecognizer) - retval.next = ((ChildrenRecognizer)next) - .deepClone (table); - else if (!(next instanceof EmptyRecognizer)) - throw new RuntimeException ("deepClone"); - } - - if (components != null) { - retval.components = new Recognizer [components.length]; - for (int i = 0; i < components.length; i++) { - Recognizer temp = components [i]; - - if (temp == null) - retval.components [i] = null; - else if (temp instanceof ChildrenRecognizer) - retval.components [i] = ((ChildrenRecognizer)temp) - .deepClone (table); - else if (!(temp instanceof EmptyRecognizer)) - throw new RuntimeException ("deepClone"); - } - } - - return retval; - } - - // connect subgraphs, first to next (sequencing) - private void patchNext (Recognizer theNext, Hashtable table) - { - // backpointers must not be repatched or followed - if ((flags & F_LOOPNEXT) != 0) - return; - - // XXX this table "shouldn't" be needed, right? - // but some choice nodes looped if it isn't there. - if (table != null && table.get (this) != null) - return; - if (table == null) - table = new Hashtable (); - - // NAME/SEQUENCE - if (name != null) { - if (next == null) - next = theNext; - else if (next instanceof ChildrenRecognizer) { - ((ChildrenRecognizer)next).patchNext (theNext, table); - } else if (!(next instanceof EmptyRecognizer)) - throw new RuntimeException ("patchNext"); - return; - } - - // CHOICE - for (int i = 0; i < components.length; i++) { - if (components [i] == null) - components [i] = theNext; - else if (components [i] instanceof ChildrenRecognizer) { - ((ChildrenRecognizer)components [i]) - .patchNext (theNext, table); - } else if (!(components [i] instanceof EmptyRecognizer)) - throw new RuntimeException ("patchNext"); - } - - if (table != null && (flags | F_LOOPHEAD) != 0) - table.put (this, this); - } - - /** - * Parses a 'children' spec (or recursively 'cp') and makes this - * become a regular graph node. - * - * @return index after this particle - */ - private int populate (char parseBuf [], int startPos) - { - int nextPos = startPos + 1; - char c; - - if (nextPos < 0 || nextPos >= parseBuf.length) - throw new IndexOutOfBoundsException (); - - // Grammar of the string is from the XML spec, but - // with whitespace removed by the SAX parser. - - // children ::= (choice | seq) ('?' | '*' | '+')? - // cp ::= (Name | choice | seq) ('?' | '*' | '+')? - // choice ::= '(' cp ('|' choice)* ')' - // seq ::= '(' cp (',' choice)* ')' - - // interior nodes only - // cp ::= name ... - if (parseBuf [startPos] != '('/*)*/) { - boolean done = false; - do { - switch (c = parseBuf [nextPos]) { - case '?': case '*': case '+': - case '|': case ',': - case /*(*/ ')': - done = true; - continue; - default: - nextPos++; - continue; - } - } while (!done); - name = new String (parseBuf, startPos, nextPos - startPos); - - // interior OR toplevel nodes - // cp ::= choice .. - // cp ::= seq .. - } else { - // collect everything as a separate list, and merge it - // into "this" later if we can (SEQUENCE or singleton) - ChildrenRecognizer first; - - first = new ChildrenRecognizer (consumer, type); - nextPos = first.populate (parseBuf, nextPos); - c = parseBuf [nextPos++]; - - if (c == ',' || c == '|') { - ChildrenRecognizer current = first; - char separator = c; - Vector v = null; - - if (separator == '|') { - v = new Vector (); - v.addElement (first); - } - - do { - ChildrenRecognizer link; - - link = new ChildrenRecognizer (consumer, type); - nextPos = link.populate (parseBuf, nextPos); - - if (separator == ',') { - current.patchNext (link, null); - current = link; - } else - v.addElement (link); - - c = parseBuf [nextPos++]; - } while (c == separator); - - // choice ... collect everything into one array. - if (separator == '|') { - // assert v.size() > 1 - components = new Recognizer [v.size ()]; - for (int i = 0; i < components.length; i++) { - components [i] = (Recognizer) - v.elementAt (i); - } - // assert flags == 0 - - // sequence ... merge into "this" to be smaller. - } else - copyIn (first); - - // treat singletons like one-node sequences. - } else - copyIn (first); - - if (c != /*(*/ ')') - throw new RuntimeException ("corrupt content model"); - } - - // - // Arity is optional, and the root of all fun. We keep the - // FSM state graph simple by only having NAME/SEQUENCE and - // CHOICE nodes (or EMPTY to terminate a model), easily - // evaluated. So we rewrite each node that has arity, using - // those primitives. We create loops here, if needed. - // - if (nextPos < parseBuf.length) { - c = parseBuf [nextPos]; - if (c == '?' || c == '*' || c == '+') { - nextPos++; - - // Rewrite 'zero-or-one' "?" arity to a CHOICE: - // - SEQUENCE (clone, what's next) - // - or, what's next - // Size cost: N --> N + 1 - if (c == '?') { - Recognizer once = shallowClone (); - - components = new Recognizer [2]; - components [0] = once; - // components [1] initted to null - name = null; - next = null; - flags = 0; - - - // Rewrite 'zero-or-more' "*" arity to a CHOICE. - // - LOOP (clone, back to this CHOICE) - // - or, what's next - // Size cost: N --> N + 1 - } else if (c == '*') { - ChildrenRecognizer loop = shallowClone (); - - loop.patchNext (this, null); - loop.flags |= F_LOOPNEXT; - flags = F_LOOPHEAD; - - components = new Recognizer [2]; - components [0] = loop; - // components [1] initted to null - name = null; - next = null; - - - // Rewrite 'one-or-more' "+" arity to a SEQUENCE. - // Basically (a)+ --> ((a),(a)*). - // - this - // - CHOICE - // * LOOP (clone, back to the CHOICE) - // * or, whatever's next - // Size cost: N --> 2N + 1 - } else if (c == '+') { - ChildrenRecognizer loop = deepClone (); - ChildrenRecognizer choice; - - choice = new ChildrenRecognizer (consumer, type); - loop.patchNext (choice, null); - loop.flags |= F_LOOPNEXT; - choice.flags = F_LOOPHEAD; - - choice.components = new Recognizer [2]; - choice.components [0] = loop; - // choice.components [1] initted to null - // choice.name, choice.next initted to null - - patchNext (choice, null); - } - } - } - - return nextPos; - } - - // VC: Element Valid (second clause) - boolean acceptCharacters () - { return false; } - - // VC: Element Valid (second clause) - Recognizer acceptElement (String type) - throws SAXException - { - // NAME/SEQUENCE - if (name != null) { - if (name.equals (type)) - return next; - return null; - } - - // CHOICE ... optionally reporting nondeterminism we - // run across. we won't check out every transition - // for nondeterminism; only the ones we follow. - Recognizer retval = null; - - for (int i = 0; i < components.length; i++) { - Recognizer temp = components [i].acceptElement (type); - - if (temp == null) - continue; - else if (!warnNonDeterministic) - return temp; - else if (retval == null) - retval = temp; - else if (retval != temp) - consumer.error ("Content model " + this.type.model - + " is non-deterministic for " + type); - } - return retval; - } - - // VC: Element Valid (second clause) - boolean completed () - throws SAXException - { - // expecting a specific element - if (name != null) - return false; - - // choice, some sequences - for (int i = 0; i < components.length; i++) { - if (components [i].completed ()) - return true; - } - - return false; - } - -/** / - // FOR DEBUGGING ... flattens the graph for printing. - - public String toString () - { - StringBuffer buf = new StringBuffer (); - - // only one set of loop labels can be generated - // at a time... - synchronized (ANY) { - nodeCount = 0; - - toString (buf, new Hashtable ()); - return buf.toString (); - } - } - - private void toString (StringBuffer buf, Hashtable table) - { - // When we visit a node, label and count it. - // Nodes are never visited/counted more than once. - // For small models labels waste space, but if arity - // mappings were used the savings are substantial. - // (Plus, the output can be more readily understood.) - String temp = (String) table.get (this); - - if (temp != null) { - buf.append ('{'); - buf.append (temp); - buf.append ('}'); - return; - } else { - StringBuffer scratch = new StringBuffer (15); - - if ((flags & F_LOOPHEAD) != 0) - scratch.append ("loop"); - else - scratch.append ("node"); - scratch.append ('-'); - scratch.append (++nodeCount); - temp = scratch.toString (); - - table.put (this, temp); - buf.append ('['); - buf.append (temp); - buf.append (']'); - buf.append (':'); - } - - // NAME/SEQUENCE - if (name != null) { - // n.b. some output encodings turn some name chars into '?' - // e.g. with Japanese names and ASCII output - buf.append (name); - if (components != null) // bug! - buf.append ('$'); - if (next == null) - buf.append (",*"); - else if (next instanceof EmptyRecognizer) // patch-to-next - buf.append (",{}"); - else if (next instanceof ChildrenRecognizer) { - buf.append (','); - ((ChildrenRecognizer)next).toString (buf, table); - } else // bug! - buf.append (",+"); - return; - } - - // CHOICE - buf.append ("<"); - for (int i = 0; i < components.length; i++) { - if (i != 0) - buf.append ("|"); - if (components [i] instanceof EmptyRecognizer) { - buf.append ("{}"); - } else if (components [i] == null) { // patch-to-next - buf.append ('*'); - } else { - ChildrenRecognizer r; - - r = (ChildrenRecognizer) components [i]; - r.toString (buf, table); - } - } - buf.append (">"); - } -/**/ - } -} diff --git a/libjava/gnu/xml/pipeline/WellFormednessFilter.java b/libjava/gnu/xml/pipeline/WellFormednessFilter.java deleted file mode 100644 index ef430165203..00000000000 --- a/libjava/gnu/xml/pipeline/WellFormednessFilter.java +++ /dev/null @@ -1,363 +0,0 @@ -/* WellFormednessFilter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.util.EmptyStackException; -import java.util.Stack; - -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * This filter reports fatal exceptions in the case of event streams that - * are not well formed. The rules currently tested include: <ul> - * - * <li>setDocumentLocator ... may be called only before startDocument - * - * <li>startDocument/endDocument ... must be paired, and all other - * calls (except setDocumentLocator) must be nested within these. - * - * <li>startElement/endElement ... must be correctly paired, and - * may never appear within CDATA sections. - * - * <li>comment ... can't contain "--" - * - * <li>character data ... can't contain "]]>" - * - * <li>whitespace ... can't contain CR - * - * <li>whitespace and character data must be within an element - * - * <li>processing instruction ... can't contain "?>" or CR - * - * <li>startCDATA/endCDATA ... must be correctly paired. - * - * </ul> - * - * <p> Other checks for event stream correctness may be provided in - * the future. For example, insisting that - * entity boundaries nest correctly, - * namespace scopes nest correctly, - * namespace values never contain relative URIs, - * attributes don't have "<" characters; - * and more. - * - * @author David Brownell - */ -public final class WellFormednessFilter extends EventFilter -{ - private boolean startedDoc; - private Stack elementStack = new Stack (); - private boolean startedCDATA; - private String dtdState = "before"; - - - /** - * Swallows all events after performing well formedness checks. - */ - // constructor used by PipelineFactory - public WellFormednessFilter () - { this (null); } - - - /** - * Passes events through to the specified consumer, after first - * processing them. - */ - // constructor used by PipelineFactory - public WellFormednessFilter (EventConsumer consumer) - { - super (consumer); - - setContentHandler (this); - setDTDHandler (this); - - try { - setProperty (LEXICAL_HANDLER, this); - } catch (SAXException e) { /* can't happen */ } - } - - /** - * Resets state as if any preceding event stream was well formed. - * Particularly useful if it ended through some sort of error, - * and the endDocument call wasn't made. - */ - public void reset () - { - startedDoc = false; - startedCDATA = false; - elementStack.removeAllElements (); - } - - - private SAXParseException getException (String message) - { - SAXParseException e; - Locator locator = getDocumentLocator (); - - if (locator == null) - return new SAXParseException (message, null, null, -1, -1); - else - return new SAXParseException (message, locator); - } - - private void fatalError (String message) - throws SAXException - { - SAXParseException e = getException (message); - ErrorHandler handler = getErrorHandler (); - - if (handler != null) - handler.fatalError (e); - throw e; - } - - /** - * Throws an exception when called after startDocument. - * - * @param locator the locator, to be used in error reporting or relative - * URI resolution. - * - * @exception IllegalStateException when called after the document - * has already been started - */ - public void setDocumentLocator (Locator locator) - { - if (startedDoc) - throw new IllegalStateException ( - "setDocumentLocator called after startDocument"); - super.setDocumentLocator (locator); - } - - public void startDocument () throws SAXException - { - if (startedDoc) - fatalError ("startDocument called more than once"); - startedDoc = true; - startedCDATA = false; - elementStack.removeAllElements (); - super.startDocument (); - } - - public void startElement ( - String uri, String localName, - String qName, Attributes atts - ) throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if ("inside".equals (dtdState)) - fatalError ("element inside DTD?"); - else - dtdState = "after"; - if (startedCDATA) - fatalError ("element inside CDATA section"); - if (qName == null || "".equals (qName)) - fatalError ("startElement name missing"); - elementStack.push (qName); - super.startElement (uri, localName, qName, atts); - } - - public void endElement (String uri, String localName, String qName) - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if (startedCDATA) - fatalError ("element inside CDATA section"); - if (qName == null || "".equals (qName)) - fatalError ("endElement name missing"); - - try { - String top = (String) elementStack.pop (); - - if (!qName.equals (top)) - fatalError ("<" + top + " ...>...</" + qName + ">"); - // XXX could record/test namespace info - } catch (EmptyStackException e) { - fatalError ("endElement without startElement: </" + qName + ">"); - } - super.endElement (uri, localName, qName); - } - - public void endDocument () throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - dtdState = "before"; - startedDoc = false; - super.endDocument (); - } - - - public void startDTD (String root, String publicId, String systemId) - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if ("before" != dtdState) - fatalError ("two DTDs?"); - if (!elementStack.empty ()) - fatalError ("DTD must precede root element"); - dtdState = "inside"; - super.startDTD (root, publicId, systemId); - } - - public void notationDecl (String name, String publicId, String systemId) - throws SAXException - { -// FIXME: not all parsers will report startDTD() ... -// we'd rather insist we're "inside". - if ("after" == dtdState) - fatalError ("not inside DTD"); - super.notationDecl (name, publicId, systemId); - } - - public void unparsedEntityDecl (String name, - String publicId, String systemId, String notationName) - throws SAXException - { -// FIXME: not all parsers will report startDTD() ... -// we'd rather insist we're "inside". - if ("after" == dtdState) - fatalError ("not inside DTD"); - super.unparsedEntityDecl (name, publicId, systemId, notationName); - } - - // FIXME: add the four DeclHandler calls too - - public void endDTD () - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if ("inside" != dtdState) - fatalError ("DTD ends without start?"); - dtdState = "after"; - super.endDTD (); - } - - public void characters (char ch [], int start, int length) - throws SAXException - { - int here = start, end = start + length; - if (elementStack.empty ()) - fatalError ("characters must be in an element"); - while (here < end) { - if (ch [here++] != ']') - continue; - if (here == end) // potential problem ... - continue; - if (ch [here++] != ']') - continue; - if (here == end) // potential problem ... - continue; - if (ch [here++] == '>') - fatalError ("character data can't contain \"]]>\""); - } - super.characters (ch, start, length); - } - - public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - int here = start, end = start + length; - if (elementStack.empty ()) - fatalError ("characters must be in an element"); - while (here < end) { - if (ch [here++] == '\r') - fatalError ("whitespace can't contain CR"); - } - super.ignorableWhitespace (ch, start, length); - } - - public void processingInstruction (String target, String data) - throws SAXException - { - if (data.indexOf ('\r') > 0) - fatalError ("PIs can't contain CR"); - if (data.indexOf ("?>") > 0) - fatalError ("PIs can't contain \"?>\""); - } - - public void comment (char ch [], int start, int length) - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if (startedCDATA) - fatalError ("comments can't nest in CDATA"); - int here = start, end = start + length; - while (here < end) { - if (ch [here] == '\r') - fatalError ("comments can't contain CR"); - if (ch [here++] != '-') - continue; - if (here == end) - fatalError ("comments can't end with \"--->\""); - if (ch [here++] == '-') - fatalError ("comments can't contain \"--\""); - } - super.comment (ch, start, length); - } - - public void startCDATA () - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if (startedCDATA) - fatalError ("CDATA starts can't nest"); - startedCDATA = true; - super.startCDATA (); - } - - public void endCDATA () - throws SAXException - { - if (!startedDoc) - fatalError ("callback outside of document?"); - if (!startedCDATA) - fatalError ("CDATA end without start?"); - startedCDATA = false; - super.endCDATA (); - } -} diff --git a/libjava/gnu/xml/pipeline/XIncludeFilter.java b/libjava/gnu/xml/pipeline/XIncludeFilter.java deleted file mode 100644 index 02607a4e06d..00000000000 --- a/libjava/gnu/xml/pipeline/XIncludeFilter.java +++ /dev/null @@ -1,579 +0,0 @@ -/* XIncludeFilter.java -- - Copyright (C) 2001,2002 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Hashtable; -import java.util.Stack; -import java.util.Vector; - -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -import gnu.xml.util.Resolver; - - - -/** - * Filter to process an XPointer-free subset of - * <a href="http://www.w3.org/TR/xinclude">XInclude</a>, supporting its - * use as a kind of replacement for parsed general entities. - * XInclude works much like the <code>#include</code> of C/C++ but - * works for XML documents as well as unparsed text files. - * Restrictions from the 17-Sept-2002 CR draft of XInclude are as follows: - * - * <ul> - * - * <li> URIs must not include fragment identifiers. - * The CR specifies support for XPointer <em>element()</em> fragment IDs, - * which is not currently implemented here. - * - * <li> <em>xi:fallback</em> handling of resource errors is not - * currently supported. - * - * <li> DTDs are not supported in included files, since the SAX DTD events - * must have completely preceded any included file. - * The CR explicitly allows the DTD related portions of the infoset to - * grow as an effect of including XML documents. - * - * <li> <em>xml:base</em> fixup isn't done. - * - * </ul> - * - * <p> XML documents that are included will normally be processed using - * the default SAX namespace rules, meaning that prefix information may - * be discarded. This may be changed with {@link #setSavingPrefixes - * setSavingPrefixes()}. <em>You are strongly advised to do this.</em> - * - * <p> Note that XInclude allows highly incompatible implementations, which - * are specialized to handle application-specific infoset extensions. Some - * such implementations can be implemented by subclassing this one, but - * they may only be substituted in applications at "user option". - * - * <p>TBD: "IURI" handling. - * - * @author David Brownell - */ -public class XIncludeFilter extends EventFilter implements Locator -{ - private Hashtable extEntities = new Hashtable (5, 5); - private int ignoreCount; - private Stack uris = new Stack (); - private Locator locator; - private Vector inclusions = new Vector (5, 5); - private boolean savingPrefixes; - - /** - */ - public XIncludeFilter (EventConsumer next) - throws SAXException - { - super (next); - setContentHandler (this); - // DTDHandler callbacks pass straight through - setProperty (DECL_HANDLER, this); - setProperty (LEXICAL_HANDLER, this); - } - - private void fatal (SAXParseException e) throws SAXException - { - ErrorHandler eh; - - eh = getErrorHandler (); - if (eh != null) - eh.fatalError (e); - throw e; - } - - /** - * Passes "this" down the filter chain as a proxy locator. - */ - public void setDocumentLocator (Locator locator) - { - this.locator = locator; - super.setDocumentLocator (this); - } - - /** Used for proxy locator; do not call directly. */ - public String getSystemId () - { return (locator == null) ? null : locator.getSystemId (); } - /** Used for proxy locator; do not call directly. */ - public String getPublicId () - { return (locator == null) ? null : locator.getPublicId (); } - /** Used for proxy locator; do not call directly. */ - public int getLineNumber () - { return (locator == null) ? -1 : locator.getLineNumber (); } - /** Used for proxy locator; do not call directly. */ - public int getColumnNumber () - { return (locator == null) ? -1 : locator.getColumnNumber (); } - - /** - * Assigns the flag controlling the setting of the SAX2 - * <em>namespace-prefixes</em> flag. - */ - public void setSavingPrefixes (boolean flag) - { savingPrefixes = flag; } - - /** - * Returns the flag controlling the setting of the SAX2 - * <em>namespace-prefixes</em> flag when parsing included documents. - * The default value is the SAX2 default (false), which discards - * information that can be useful. - */ - public boolean isSavingPrefixes () - { return savingPrefixes; } - - // - // Two mechanisms are interacting here. - // - // - XML Base implies a stack of base URIs, updated both by - // "real entity" boundaries and element boundaries. - // - // - Active "Real Entities" (for document and general entities, - // and by xincluded files) are tracked to prevent circular - // inclusions. - // - private String addMarker (String uri) - throws SAXException - { - if (locator != null && locator.getSystemId () != null) - uri = locator.getSystemId (); - - // guard against InputSource objects without system IDs - if (uri == null) - fatal (new SAXParseException ("Entity URI is unknown", locator)); - - try { - URL url = new URL (uri); - - uri = url.toString (); - if (inclusions.contains (uri)) - fatal (new SAXParseException ( - "XInclude, circular inclusion", locator)); - inclusions.addElement (uri); - uris.push (url); - } catch (IOException e) { - // guard against illegal relative URIs (Xerces) - fatal (new SAXParseException ("parser bug: relative URI", - locator, e)); - } - return uri; - } - - private void pop (String uri) - { - inclusions.removeElement (uri); - uris.pop (); - } - - // - // Document entity boundaries get both treatments. - // - public void startDocument () throws SAXException - { - ignoreCount = 0; - addMarker (null); - super.startDocument (); - } - - public void endDocument () throws SAXException - { - inclusions.setSize (0); - extEntities.clear (); - uris.setSize (0); - super.endDocument (); - } - - // - // External general entity boundaries get both treatments. - // - public void externalEntityDecl (String name, - String publicId, String systemId) - throws SAXException - { - if (name.charAt (0) == '%') - return; - try { - URL url = new URL (locator.getSystemId ()); - systemId = new URL (url, systemId).toString (); - } catch (IOException e) { - // what could we do? - } - extEntities.put (name, systemId); - } - - public void startEntity (String name) - throws SAXException - { - if (ignoreCount != 0) { - ignoreCount++; - return; - } - - String uri = (String) extEntities.get (name); - if (uri != null) - addMarker (uri); - super.startEntity (name); - } - - public void endEntity (String name) - throws SAXException - { - if (ignoreCount != 0) { - if (--ignoreCount != 0) - return; - } - - String uri = (String) extEntities.get (name); - - if (uri != null) - pop (uri); - super.endEntity (name); - } - - // - // element boundaries only affect the base URI stack, - // unless they're XInclude elements. - // - public void - startElement (String uri, String localName, String qName, Attributes atts) - throws SAXException - { - if (ignoreCount != 0) { - ignoreCount++; - return; - } - - URL baseURI = (URL) uris.peek (); - String base; - - base = atts.getValue ("http://www.w3.org/XML/1998/namespace", "base"); - if (base == null) - uris.push (baseURI); - else { - URL url; - - if (base.indexOf ('#') != -1) - fatal (new SAXParseException ( - "xml:base with fragment: " + base, - locator)); - - try { - baseURI = new URL (baseURI, base); - uris.push (baseURI); - } catch (Exception e) { - fatal (new SAXParseException ( - "xml:base with illegal uri: " + base, - locator, e)); - } - } - - if (!"http://www.w3.org/2001/XInclude".equals (uri)) { - super.startElement (uri, localName, qName, atts); - return; - } - - if ("include".equals (localName)) { - String href = atts.getValue ("href"); - String parse = atts.getValue ("parse"); - String encoding = atts.getValue ("encoding"); - URL url = (URL) uris.peek (); - SAXParseException x = null; - - if (href == null) - fatal (new SAXParseException ( - "XInclude missing href", - locator)); - if (href.indexOf ('#') != -1) - fatal (new SAXParseException ( - "XInclude with fragment: " + href, - locator)); - - if (parse == null || "xml".equals (parse)) - x = xinclude (url, href); - else if ("text".equals (parse)) - x = readText (url, href, encoding); - else - fatal (new SAXParseException ( - "unknown XInclude parsing mode: " + parse, - locator)); - if (x == null) { - // strip out all child content - ignoreCount++; - return; - } - - // FIXME the 17-Sept-2002 CR of XInclude says we "must" - // use xi:fallback elements to handle resource errors, - // if they exist. - fatal (x); - - } else if ("fallback".equals (localName)) { - fatal (new SAXParseException ( - "illegal top level XInclude 'fallback' element", - locator)); - } else { - ErrorHandler eh = getErrorHandler (); - - // CR doesn't say this is an error - if (eh != null) - eh.warning (new SAXParseException ( - "unrecognized toplevel XInclude element: " + localName, - locator)); - super.startElement (uri, localName, qName, atts); - } - } - - public void endElement (String uri, String localName, String qName) - throws SAXException - { - if (ignoreCount != 0) { - if (--ignoreCount != 0) - return; - } - - uris.pop (); - if (!("http://www.w3.org/2001/XInclude".equals (uri) - && "include".equals (localName))) - super.endElement (uri, localName, qName); - } - - // - // ignore all content within non-empty xi:include elements - // - public void characters (char ch [], int start, int length) - throws SAXException - { - if (ignoreCount == 0) - super.characters (ch, start, length); - } - - public void processingInstruction (String target, String value) - throws SAXException - { - if (ignoreCount == 0) - super.processingInstruction (target, value); - } - - public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - if (ignoreCount == 0) - super.ignorableWhitespace (ch, start, length); - } - - public void comment (char ch [], int start, int length) - throws SAXException - { - if (ignoreCount == 0) - super.comment (ch, start, length); - } - - public void startCDATA () throws SAXException - { - if (ignoreCount == 0) - super.startCDATA (); - } - - public void endCDATA () throws SAXException - { - if (ignoreCount == 0) - super.endCDATA (); - } - - public void startPrefixMapping (String prefix, String uri) - throws SAXException - { - if (ignoreCount == 0) - super.startPrefixMapping (prefix, uri); - } - - public void endPrefixMapping (String prefix) throws SAXException - { - if (ignoreCount == 0) - super.endPrefixMapping (prefix); - } - - public void skippedEntity (String name) throws SAXException - { - if (ignoreCount == 0) - super.skippedEntity (name); - } - - // JDK 1.1 seems to need it to be done this way, sigh - void setLocator (Locator l) { locator = l; } - Locator getLocator () { return locator; } - - - // - // for XIncluded entities, manage the current locator and - // filter out events that would be incorrect to report - // - private class Scrubber extends EventFilter - { - Scrubber (EventFilter f) - throws SAXException - { - // delegation passes to next in chain - super (f); - - // process all content events - super.setContentHandler (this); - super.setProperty (LEXICAL_HANDLER, this); - - // drop all DTD events - super.setDTDHandler (null); - super.setProperty (DECL_HANDLER, null); - } - - // maintain proxy locator - // only one startDocument()/endDocument() pair per event stream - public void setDocumentLocator (Locator l) - { setLocator (l); } - public void startDocument () - { } - public void endDocument () - { } - - private void reject (String message) throws SAXException - { fatal (new SAXParseException (message, getLocator ())); } - - // only the DTD from the "base document" gets reported - public void startDTD (String root, String publicId, String systemId) - throws SAXException - { reject ("XIncluded DTD: " + systemId); } - public void endDTD () - throws SAXException - { reject ("XIncluded DTD"); } - // ... so this should never happen - public void skippedEntity (String name) throws SAXException - { reject ("XInclude skipped entity: " + name); } - - // since we rejected DTDs, only builtin entities can be reported - } - - // <xi:include parse='xml' ...> - // relative to the base URI passed - private SAXParseException xinclude (URL url, String href) - throws SAXException - { - XMLReader helper; - Scrubber scrubber; - Locator savedLocator = locator; - - // start with a parser acting just like our input - // modulo DTD-ish stuff (validation flag, entity resolver) - helper = XMLReaderFactory.createXMLReader (); - helper.setErrorHandler (getErrorHandler ()); - helper.setFeature (FEATURE_URI + "namespace-prefixes", true); - - // Set up the proxy locator and event filter. - scrubber = new Scrubber (this); - locator = null; - bind (helper, scrubber); - - // Merge the included document, except its DTD - try { - url = new URL (url, href); - href = url.toString (); - - if (inclusions.contains (href)) - fatal (new SAXParseException ( - "XInclude, circular inclusion", locator)); - - inclusions.addElement (href); - uris.push (url); - helper.parse (new InputSource (href)); - return null; - } catch (java.io.IOException e) { - return new SAXParseException (href, locator, e); - } finally { - pop (href); - locator = savedLocator; - } - } - - // <xi:include parse='text' ...> - // relative to the base URI passed - private SAXParseException readText (URL url, String href, String encoding) - throws SAXException - { - InputStream in = null; - - try { - URLConnection conn; - InputStreamReader reader; - char buf [] = new char [4096]; - int count; - - url = new URL (url, href); - conn = url.openConnection (); - in = conn.getInputStream (); - if (encoding == null) - encoding = Resolver.getEncoding (conn.getContentType ()); - if (encoding == null) { - ErrorHandler eh = getErrorHandler (); - if (eh != null) - eh.warning (new SAXParseException ( - "guessing text encoding for URL: " + url, - locator)); - reader = new InputStreamReader (in); - } else - reader = new InputStreamReader (in, encoding); - - while ((count = reader.read (buf, 0, buf.length)) != -1) - super.characters (buf, 0, count); - in.close (); - return null; - } catch (IOException e) { - return new SAXParseException ( - "can't XInclude text", - locator, e); - } - } -} diff --git a/libjava/gnu/xml/pipeline/XsltFilter.java b/libjava/gnu/xml/pipeline/XsltFilter.java deleted file mode 100644 index 0a1872c5a80..00000000000 --- a/libjava/gnu/xml/pipeline/XsltFilter.java +++ /dev/null @@ -1,130 +0,0 @@ -/* XsltFilter.java -- - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.pipeline; - -import java.io.IOException; - -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.sax.*; -import javax.xml.transform.stream.StreamSource; - -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; - - -/** - * Packages an XSLT transform as a pipeline component. - * Note that all DTD events (callbacks to DeclHandler and DTDHandler - * interfaces) are discarded, although XSLT transforms may be set up to - * use the LexicalHandler to write DTDs with only an external subset. - * Not every XSLT engine will necessarily be usable with this filter, - * but current versions of - * <a href="http://saxon.sourceforge.net">SAXON</a> and - * <a href="http://xml.apache.org/xalan-j">Xalan</a> should work well. - * - * @see TransformerFactory - * - * @author David Brownell - */ -final public class XsltFilter extends EventFilter -{ - /** - * Creates a filter that performs the specified transform. - * Uses the JAXP 1.1 interfaces to access the default XSLT - * engine configured for in the current execution context, - * and parses the stylesheet without custom EntityResolver - * or ErrorHandler support. - * - * @param stylesheet URI for the stylesheet specifying the - * XSLT transform - * @param next provides the ContentHandler and LexicalHandler - * to receive XSLT output. - * @exception SAXException if the stylesheet can't be parsed - * @exception IOException if there are difficulties - * bootstrapping the XSLT engine, such as it not supporting - * SAX well enough to use this way. - */ - public XsltFilter (String stylesheet, EventConsumer next) - throws SAXException, IOException - { - // First, get a transformer with the stylesheet preloaded - TransformerFactory tf = null; - TransformerHandler th; - - try { - SAXTransformerFactory stf; - - tf = TransformerFactory.newInstance (); - if (!tf.getFeature (SAXTransformerFactory.FEATURE) // sax inputs - || !tf.getFeature (SAXResult.FEATURE) // sax outputs - || !tf.getFeature (StreamSource.FEATURE) // stylesheet - ) - throw new IOException ("XSLT factory (" - + tf.getClass ().getName () - + ") does not support SAX"); - stf = (SAXTransformerFactory) tf; - th = stf.newTransformerHandler (new StreamSource (stylesheet)); - } catch (TransformerConfigurationException e) { - throw new IOException ("XSLT factory (" - + (tf == null - ? "none available" - : tf.getClass ().getName ()) - + ") configuration error, " - + e.getMessage () - ); - } - - // Hook its outputs up to the pipeline ... - SAXResult out = new SAXResult (); - - out.setHandler (next.getContentHandler ()); - try { - LexicalHandler lh; - lh = (LexicalHandler) next.getProperty (LEXICAL_HANDLER); - out.setLexicalHandler (lh); - } catch (Exception e) { - // ignore - } - th.setResult (out); - - // ... and make sure its inputs look like ours. - setContentHandler (th); - setProperty (LEXICAL_HANDLER, th); - } -} diff --git a/libjava/gnu/xml/transform/AbstractNumberNode.java b/libjava/gnu/xml/transform/AbstractNumberNode.java deleted file mode 100644 index 01c2dbb83d8..00000000000 --- a/libjava/gnu/xml/transform/AbstractNumberNode.java +++ /dev/null @@ -1,321 +0,0 @@ -/* AbstractNumberNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>number</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -abstract class AbstractNumberNode - extends TemplateNode -{ - - static final int ALPHABETIC = 0; - static final int TRADITIONAL = 1; - - final TemplateNode format; - final String lang; - final int letterValue; - final String groupingSeparator; - final int groupingSize; - - AbstractNumberNode(TemplateNode children, TemplateNode next, - TemplateNode format, String lang, - int letterValue, String groupingSeparator, - int groupingSize) - { - super(children, next); - this.format = format; - this.lang = lang; - this.letterValue = letterValue; - this.groupingSeparator = groupingSeparator; - this.groupingSize = groupingSize; - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - DocumentFragment fragment = doc.createDocumentFragment(); - format.apply(stylesheet, mode, context, pos, len, fragment, null); - String f = Expr._string(context, Collections.singleton(fragment)); - String value = format(f, compute(stylesheet, context, pos, len)); - Text text = doc.createTextNode(value); - if (nextSibling != null) - { - parent.insertBefore(text, nextSibling); - } - else - { - parent.appendChild(text); - } - // xsl:number doesn't process children - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - String format(String format, int[] number) - { - if (number.length == 0) - { - return ""; - } - int start = 0, end = 0, len = format.length(); // region of format - // Tokenize - List tokens = new ArrayList((number.length * 2) + 1); - List types = new ArrayList(tokens.size()); - while (end < len) - { - while (end < len && !isAlphanumeric(format.charAt(end))) - { - end++; - } - if (end > start) - { - tokens.add(format.substring(start, end)); - types.add(Boolean.FALSE); - } - start = end; - while (end < len && isAlphanumeric(format.charAt(end))) - { - end++; - } - if (end > start) - { - tokens.add(format.substring(start, end)); - types.add(Boolean.TRUE); - } - start = end; - } - // Process tokens - StringBuffer buf = new StringBuffer(); - len = tokens.size(); - int pos = 0; - for (int i = 0; i < len; i++) - { - String token = (i < 0) ? "." : (String) tokens.get(i); - boolean alpha = (i < 0) ? true : - ((Boolean) types.get(i)).booleanValue(); - if (!alpha) - { - buf.append(token); - } - else - { - if (pos < number.length) - { - format(buf, number[pos++], token); - if (((i + 1 == len) || (i + 2 == len)) && - (pos < number.length)) - { - // More numbers than tokens, reuse last token - i -= 2; - } - } - if (pos == number.length && i < (len - 2)) - { - // No more numbers. Skip to the end... - i = len - 2; - if (((Boolean) types.get(i + 1)).booleanValue()) - { - // number formatting token, ignore - i++; - } - } - } - } - //System.err.println("format: '"+format+"' "+asList(number)+" = '"+buf.toString()+"'"); - return buf.toString(); - } - - /*List asList(int[] number) - { - List l = new ArrayList(); - for (int i = 0; i < number.length; i++) - l.add(new Integer(number[i])); - return l; - }*/ - - void format(StringBuffer buf, int number, String formatToken) - { - int len = formatToken.length(); - char c = formatToken.charAt(len - 1); - if (Character.digit(c, 10) == 1) - { - // Check preceding characters - for (int i = len - 2; i >= 0; i--) - { - if (formatToken.charAt(i) != (c - 1)) - { - format(buf, number, "1"); - return; - } - } - // Decimal representation - String val = Integer.toString(number); - for (int d = len - val.length(); d > 0; d--) - { - buf.append('0'); - } - buf.append(val); - } - else if ("A".equals(formatToken)) - { - buf.append(alphabetic('@', number)); - } - else if ("a".equals(formatToken)) - { - buf.append(alphabetic('`', number)); - } - else if ("i".equals(formatToken)) - { - buf.append(roman(false, number)); - } - else if ("I".equals(formatToken)) - { - buf.append(roman(true, number)); - } - else - { - // Unknown numbering sequence - format(buf, number, "1"); - } - } - - static final boolean isAlphanumeric(char c) - { - switch (Character.getType(c)) - { - case Character.DECIMAL_DIGIT_NUMBER: // Nd - case Character.LETTER_NUMBER: // Nl - case Character.OTHER_NUMBER: // No - case Character.UPPERCASE_LETTER: // Lu - case Character.LOWERCASE_LETTER: // Ll - case Character.TITLECASE_LETTER: // Lt - case Character.MODIFIER_LETTER: // Lm - case Character.OTHER_LETTER: // Lo - return true; - default: - return false; - } - } - - static final String alphabetic(char offset, int number) - { - StringBuffer buf = new StringBuffer(); - while (number > 0) - { - int r = number % 26; - number = number / 26; - buf.insert(0, (char) (offset + r)); - } - return buf.toString(); - } - - static final int[] roman_numbers = {1, 5, 10, 50, 100, 500, 1000}; - static final char[] roman_chars = {'i', 'v', 'x', 'l', 'c', 'd', 'm'}; - - static final String roman(boolean upper, int number) - { - StringBuffer buf = new StringBuffer(); - for (int pos = roman_numbers.length - 1; pos >= 0; pos -= 2) - { - int f = number / roman_numbers[pos]; - if (f != 0) - { - number = number % (f * roman_numbers[pos]); - } - if (f > 4 && f < 9) - { - buf.append(roman_chars[pos + 1]); - f -= 5; - } - if (f == 4) - { - buf.append(roman_chars[pos]); - buf.append(roman_chars[pos + 1]); - } - else if (f == 9) - { - buf.append(roman_chars[pos]); - buf.append(roman_chars[pos + 2]); - } - else - { - for (; f > 0; f--) - { - buf.append(roman_chars[pos]); - } - } - } - return upper ? buf.toString().toUpperCase() : buf.toString(); - } - - abstract int[] compute(Stylesheet stylesheet, Node context, int pos, int len) - throws TransformerException; - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("format="); - buf.append(format); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/ApplyImportsNode.java b/libjava/gnu/xml/transform/ApplyImportsNode.java deleted file mode 100644 index 4d171b7acf6..00000000000 --- a/libjava/gnu/xml/transform/ApplyImportsNode.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ApplyImportsNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; - -/** - * A template node representing an XSLT <code>apply-imports</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ApplyImportsNode - extends TemplateNode -{ - - ApplyImportsNode(TemplateNode children, TemplateNode next) - { - super(children, next); - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ApplyImportsNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - TemplateNode t = stylesheet.getTemplate(mode, context, true); - if (t != null) - { - t.apply(stylesheet, mode, context, pos, len, - parent, nextSibling); - } - if (next != null) - { - next.apply(stylesheet, mode, context, pos, len, - parent, nextSibling); - } - } - -} - diff --git a/libjava/gnu/xml/transform/ApplyTemplatesNode.java b/libjava/gnu/xml/transform/ApplyTemplatesNode.java deleted file mode 100644 index bf267212013..00000000000 --- a/libjava/gnu/xml/transform/ApplyTemplatesNode.java +++ /dev/null @@ -1,193 +0,0 @@ -/* ApplyTemplatesNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>apply-templates</code> - * instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ApplyTemplatesNode - extends TemplateNode -{ - - final Expr select; - final QName mode; - final List sortKeys; - final List withParams; - final boolean isDefault; - - ApplyTemplatesNode(TemplateNode children, TemplateNode next, - Expr select, QName mode, - List sortKeys, List withParams, boolean isDefault) - { - super(children, next); - this.select = select; - this.mode = mode; - this.sortKeys = sortKeys; - this.withParams = withParams; - this.isDefault = isDefault; - } - - TemplateNode clone(Stylesheet stylesheet) - { - int len = sortKeys.size(); - List sortKeys2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - sortKeys2.add(((Key) sortKeys.get(i)).clone(stylesheet)); - } - len = withParams.size(); - List withParams2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - withParams2.add(((WithParam) withParams.get(i)).clone(stylesheet)); - } - return new ApplyTemplatesNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - select.clone(stylesheet), - mode, sortKeys2, withParams2, isDefault); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Object ret = select.evaluate(context, pos, len); - if (ret != null && ret instanceof Collection) - { - if (withParams != null) - { - // push the parameter context - stylesheet.bindings.push(false); - // set the parameters - for (Iterator i = withParams.iterator(); i.hasNext(); ) - { - WithParam p = (WithParam) i.next(); - Object value = p.getValue(stylesheet, mode, context, pos, len); - stylesheet.bindings.set(p.name, value, false); - } - } - Collection ns = (Collection) ret; - List nodes = new ArrayList(ns); - if (sortKeys != null) - { - for (Iterator i = sortKeys.iterator(); i.hasNext(); ) - { - SortKey sortKey = (SortKey) i.next(); - sortKey.init(stylesheet, mode, context, pos, len, parent, - nextSibling); - } - Collections.sort(nodes, new XSLComparator(sortKeys)); - } - else - { - Collections.sort(nodes, documentOrderComparator); - } - int l = nodes.size(); - QName effectiveMode = isDefault ? mode : this.mode; - for (int i = 0; i < l; i++) - { - Node node = (Node) nodes.get(i); - TemplateNode t = stylesheet.getTemplate(effectiveMode, node, - false); - if (t != null) - { - if (stylesheet.debug) - { - System.err.println("Applying " + t); - } - stylesheet.current = node; - t.apply(stylesheet, effectiveMode, node, i + 1, l, - parent, nextSibling); - } - } - if (withParams != null) - { - // pop the variable context - stylesheet.bindings.pop(false); - } - } - // apply-templates doesn't have processable children - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - boolean o = false; - if (select != null) - { - buf.append("select="); - buf.append(select); - o = true; - } - if (mode != null) - { - if (o) - { - buf.append(','); - } - buf.append("mode="); - buf.append(mode); - } - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/AttributeNode.java b/libjava/gnu/xml/transform/AttributeNode.java deleted file mode 100644 index c26a7f6f52b..00000000000 --- a/libjava/gnu/xml/transform/AttributeNode.java +++ /dev/null @@ -1,246 +0,0 @@ -/* AttributeNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Attr; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSL <code>attribute</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class AttributeNode - extends TemplateNode -{ - - final TemplateNode name; - final TemplateNode namespace; - final Node source; - - AttributeNode(TemplateNode children, TemplateNode next, TemplateNode name, - TemplateNode namespace, Node source) - { - super(children, next); - this.name = name; - this.namespace = namespace; - this.source = source; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new AttributeNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : next.clone(stylesheet), - name.clone(stylesheet), - (namespace == null) ? null : - namespace.clone(stylesheet), - source); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - // Create a document fragment to hold the name - DocumentFragment fragment = doc.createDocumentFragment(); - // Apply name to the fragment - name.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - String nameValue = Expr.stringValue(fragment); - - String namespaceValue = null; - if (namespace != null) - { - // Create a document fragment to hold the namespace - fragment = doc.createDocumentFragment(); - // Apply namespace to the fragment - namespace.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - namespaceValue = Expr.stringValue(fragment); - if (namespaceValue.length() == 0) - { - namespaceValue = null; - } - } - - String prefix = getPrefix(nameValue); - if (namespaceValue == null) - { - if (prefix != null) - { - if (XMLConstants.XML_NS_PREFIX.equals(prefix)) - { - namespaceValue = XMLConstants.XML_NS_URI; - } - else - { - // Resolve namespace for this prefix - namespaceValue = source.lookupNamespaceURI(prefix); - } - } - } - else - { - if (prefix != null) - { - String ns2 = source.lookupNamespaceURI(prefix); - if (ns2 != null && !ns2.equals(namespaceValue)) - { - // prefix clashes, reset it - prefix = null; - int ci = nameValue.indexOf(':'); - nameValue = nameValue.substring(ci + 1); - } - } - } - if (prefix == null) - { - // Resolve prefix for this namespace - prefix = source.lookupPrefix(namespaceValue); - if (prefix != null) - { - nameValue = prefix + ":" + nameValue; - } - else - { - if (namespaceValue != null) - { - // Must invent a prefix - prefix = inventPrefix(parent); - nameValue = prefix + ":" + nameValue; - } - } - } - NamedNodeMap attrs = parent.getAttributes(); - boolean insert = true; - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceValue) || - XMLConstants.XMLNS_ATTRIBUTE.equals(nameValue) || - nameValue.startsWith("xmlns:")) - { - // Namespace declaration, do not output - insert = false; - } - if (prefix != null && namespaceValue == null) - { - // Not a QName - insert = false; - } - if (parent.getNodeType() == Node.ELEMENT_NODE && - parent.getFirstChild() != null) - { - // XSLT 7.1.3 Adding an attribute to an element after children have - // been added to it is an error - insert = false; - } - if (insert) - { - // Insert attribute - Attr attr = (namespaceValue != null) ? - doc.createAttributeNS(namespaceValue, nameValue) : - doc.createAttribute(nameValue); - if (attrs != null) - { - if (namespace != null) - { - attrs.setNamedItemNS(attr); - } - else - { - attrs.setNamedItem(attr); - } - } - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - attr, null); - } - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - final String getPrefix(String name) - { - int ci = name.indexOf(':'); - return (ci == -1) ? null : name.substring(0, ci); - } - - final String inventPrefix(Node parent) - { - String base = "ns"; - int count = 0; - String ret = base + Integer.toString(count); - while (parent.lookupNamespaceURI(ret) != null) - { - count++; - ret = base + Integer.toString(count); - } - return ret; - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("name="); - buf.append(name); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/AttributeSet.java b/libjava/gnu/xml/transform/AttributeSet.java deleted file mode 100644 index 3ece9c83f5e..00000000000 --- a/libjava/gnu/xml/transform/AttributeSet.java +++ /dev/null @@ -1,67 +0,0 @@ -/* AttributeSet.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -/** - * An attribute-set entry in a stylesheet. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class AttributeSet -{ - - final TemplateNode children; - final String name; - final String uas; - - AttributeSet(TemplateNode children, String name, String uas) - { - this.children = children; - this.name = name; - this.uas = uas; - } - - AttributeSet clone(Stylesheet stylesheet) - { - return new AttributeSet((children == null) ? null : - children.clone(stylesheet), - name, uas); - } - -} - diff --git a/libjava/gnu/xml/transform/Bindings.java b/libjava/gnu/xml/transform/Bindings.java deleted file mode 100644 index 7bea4e8231d..00000000000 --- a/libjava/gnu/xml/transform/Bindings.java +++ /dev/null @@ -1,242 +0,0 @@ -/* Bindings.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathVariableResolver; -import org.w3c.dom.Node; - -/** - * The set of variable bindings in effect for a stylesheet. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class Bindings - implements XPathVariableResolver, Cloneable -{ - - final Stylesheet stylesheet; - - /** - * Global variables. - */ - final LinkedList variables; - - /** - * Parameter value stack. - */ - final LinkedList parameters; - - Bindings(Stylesheet stylesheet) - { - this.stylesheet = stylesheet; - variables = new LinkedList(); - parameters = new LinkedList(); - push(true); - push(false); - } - - public Object clone() - { - try - { - return (Bindings) super.clone(); - } - catch (CloneNotSupportedException e) - { - throw new Error(e.getMessage()); - } - } - - void push(boolean global) - { - if (global) - { - variables.addFirst(new HashMap()); - } - else - { - parameters.addFirst(new HashMap()); - } - } - - void pop(boolean global) - { - if (global) - { - variables.removeFirst(); - } - else - { - parameters.removeFirst(); - } - } - - public boolean containsKey(String name, boolean global) - { - Iterator i = global ? variables.iterator() : parameters.iterator(); - while (i.hasNext()) - { - Map ctx = (Map) i.next(); - if (ctx.containsKey(name)) - { - return true; - } - } - return false; - } - - public Object get(String name, Node context, int pos, int len) - { - //System.err.println("bindings.get: "+name); - //System.err.println("\t"+toString()); - Object ret = null; - for (Iterator i = variables.iterator(); i.hasNext() && ret == null; ) - { - Map vctx = (Map) i.next(); - ret = vctx.get(name); - } - if (ret == null) - { - for (Iterator i = parameters.iterator(); i.hasNext() && ret == null; ) - { - Map pctx = (Map) i.next(); - ret = pctx.get(name); - } - } - /*if (ret instanceof Expr && context != null) - { - Expr expr = (Expr) ret; - ret = expr.evaluate(context, 1, 1); - }*/ - if (ret instanceof Node) - { - ret = Collections.singleton(ret); - } - if (ret == null) - { - ret = ""; - } - //System.err.println("\tret="+ret); - return ret; - } - - void set(String name, Object value, boolean global) - { - if (global) - { - Map context = (Map) variables.getFirst(); - context.put(name, value); - } - else - { - Map context = (Map) parameters.getFirst(); - context.put(name, value); - } - } - - public Object resolveVariable(QName qName) - { - return get(qName.toString(), null, 1, 1); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - boolean next = false; - Collection seen = new HashSet(); - buf.append('{'); - for (Iterator i = variables.iterator(); i.hasNext(); ) - { - Map ctx = (Map) i.next(); - for (Iterator j = ctx.entrySet().iterator(); j.hasNext(); ) - { - if (next) - { - buf.append(','); - } - else - { - next = true; - } - Map.Entry entry = (Map.Entry) j.next(); - Object key = entry.getKey(); - if (!seen.contains(key)) - { - buf.append(key); - buf.append('='); - buf.append(entry.getValue()); - seen.add(key); - } - } - } - for (Iterator i = parameters.iterator(); i.hasNext(); ) - { - Map ctx = (Map) i.next(); - for (Iterator j = ctx.entrySet().iterator(); j.hasNext(); ) - { - if (next) - { - buf.append(','); - } - else - { - next = true; - } - Map.Entry entry = (Map.Entry) j.next(); - Object key = entry.getKey(); - if (!seen.contains(key)) - { - buf.append(key); - buf.append('='); - buf.append(entry.getValue()); - seen.add(key); - } - } - } - buf.append('}'); - return buf.toString(); - } -} diff --git a/libjava/gnu/xml/transform/CallTemplateNode.java b/libjava/gnu/xml/transform/CallTemplateNode.java deleted file mode 100644 index bb494084f7c..00000000000 --- a/libjava/gnu/xml/transform/CallTemplateNode.java +++ /dev/null @@ -1,130 +0,0 @@ -/* CallTemplateNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; - -/** - * A template node representing the XSL <code>call-template</code> - * instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CallTemplateNode - extends TemplateNode -{ - - final QName name; - final List withParams; - - CallTemplateNode(TemplateNode children, TemplateNode next, - QName name, List withParams) - { - super(children, next); - this.name = name; - this.withParams = withParams; - } - - TemplateNode clone(Stylesheet stylesheet) - { - int len = withParams.size(); - List withParams2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - withParams2.add(((WithParam) withParams.get(i)).clone(stylesheet)); - } - return new CallTemplateNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - name, withParams2); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (withParams != null) - { - // push the parameter context - stylesheet.bindings.push(false); - // set the parameters - for (Iterator i = withParams.iterator(); i.hasNext(); ) - { - WithParam p = (WithParam) i.next(); - Object value = p.getValue(stylesheet, mode, context, pos, len); - stylesheet.bindings.set(p.name, value, false); - } - } - TemplateNode t = stylesheet.getTemplate(mode, name); - if (t != null) - { - t.apply(stylesheet, mode, context, pos, len, - parent, nextSibling); - } - if (withParams != null) - { - // pop the variable context - stylesheet.bindings.pop(false); - } - // call-template doesn't have processable children - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("name="); - buf.append(name); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/ChooseNode.java b/libjava/gnu/xml/transform/ChooseNode.java deleted file mode 100644 index 4a34712e43c..00000000000 --- a/libjava/gnu/xml/transform/ChooseNode.java +++ /dev/null @@ -1,93 +0,0 @@ -/* ChooseNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; - -/** - * A template node representing an XSL <code>choose</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ChooseNode - extends TemplateNode -{ - - ChooseNode(TemplateNode children, TemplateNode next) - { - super(children, next); - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ChooseNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/CommentNode.java b/libjava/gnu/xml/transform/CommentNode.java deleted file mode 100644 index 969555e8419..00000000000 --- a/libjava/gnu/xml/transform/CommentNode.java +++ /dev/null @@ -1,115 +0,0 @@ -/* CommentNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>comment</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CommentNode - extends TemplateNode -{ - - CommentNode(TemplateNode children, TemplateNode next) - { - super(children, next); - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new CommentNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - String value = ""; - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - if (children != null) - { - // Create a document fragment to hold the text - DocumentFragment fragment = doc.createDocumentFragment(); - // Apply children to the fragment - children.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - value = Expr.stringValue(fragment); - } - Comment comment = doc.createComment(value); - // Insert into result tree - if (nextSibling != null) - { - parent.insertBefore(comment, nextSibling); - } - else - { - parent.appendChild(comment); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/CopyNode.java b/libjava/gnu/xml/transform/CopyNode.java deleted file mode 100644 index b2c81b725ec..00000000000 --- a/libjava/gnu/xml/transform/CopyNode.java +++ /dev/null @@ -1,179 +0,0 @@ -/* CopyNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Iterator; -import java.util.StringTokenizer; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * A template node representing the XSL <code>copy</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CopyNode - extends TemplateNode -{ - - final String uas; - - CopyNode(TemplateNode children, TemplateNode next, String uas) - { - super(children, next); - this.uas = uas; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new CopyNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - uas); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Node copy = parent; - switch (context.getNodeType()) - { - case Node.TEXT_NODE: - case Node.ATTRIBUTE_NODE: - case Node.ELEMENT_NODE: - case Node.PROCESSING_INSTRUCTION_NODE: - case Node.COMMENT_NODE: - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - copy = context.cloneNode(false); - copy = doc.adoptNode(copy); - if (copy.getNodeType() == Node.ATTRIBUTE_NODE) - { - if (parent.getFirstChild() != null) - { - // Ignore attempt to add attribute after children - } - else - { - NamedNodeMap attrs = parent.getAttributes(); - if (attrs != null) - { - attrs.setNamedItemNS(copy); - } - } - } - else - { - if (nextSibling != null) - { - parent.insertBefore(copy, nextSibling); - } - else - { - parent.appendChild(copy); - } - } - } - if (uas != null) - { - StringTokenizer st = new StringTokenizer(uas, " "); - while (st.hasMoreTokens()) - { - addAttributeSet(stylesheet, mode, context, pos, len, - copy, null, st.nextToken()); - } - } - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - copy, null); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - void addAttributeSet(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling, String attributeSet) - throws TransformerException - { - for (Iterator i = stylesheet.attributeSets.iterator(); i.hasNext(); ) - { - AttributeSet as = (AttributeSet) i.next(); - if (!as.name.equals(attributeSet)) - { - continue; - } - if (as.uas != null) - { - StringTokenizer st = new StringTokenizer(as.uas, " "); - while (st.hasMoreTokens()) - { - addAttributeSet(stylesheet, mode, context, pos, len, - parent, nextSibling, st.nextToken()); - } - } - if (as.children != null) - { - as.children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/CopyOfNode.java b/libjava/gnu/xml/transform/CopyOfNode.java deleted file mode 100644 index 4e09eeffb63..00000000000 --- a/libjava/gnu/xml/transform/CopyOfNode.java +++ /dev/null @@ -1,179 +0,0 @@ -/* CopyOfNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSLT <code>copy-of</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CopyOfNode - extends TemplateNode -{ - - final Expr select; - - CopyOfNode(TemplateNode children, TemplateNode next, Expr select) - { - super(children, next); - this.select = select; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new CopyOfNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - select.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Object ret = select.evaluate(context, pos, len); - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - if (ret instanceof Collection) - { - Collection ns = (Collection) ret; - List list = new ArrayList(ns); - Collections.sort(list, documentOrderComparator); - for (Iterator i = list.iterator(); i.hasNext(); ) - { - Node src = (Node) i.next(); - short nodeType = src.getNodeType(); - if (nodeType == Node.DOCUMENT_NODE) - { - // Use document element - src = ((Document) src).getDocumentElement(); - if (src == null) - { - continue; - } - nodeType = Node.ELEMENT_NODE; - } - else if (nodeType == Node.ATTRIBUTE_NODE) - { - if (parent.getFirstChild() != null) - { - // Ignore attempt to add attribute after children - continue; - } - } - if (parent.getNodeType() == Node.ATTRIBUTE_NODE && - nodeType != Node.TEXT_NODE && - nodeType != Node.ENTITY_REFERENCE_NODE) - { - // Ignore - continue; - } - Node node = src.cloneNode(true); - node = doc.adoptNode(node); - if (nodeType == Node.ATTRIBUTE_NODE) - { - NamedNodeMap attrs = parent.getAttributes(); - if (attrs != null) - { - attrs.setNamedItemNS(node); - } - } - else - { - if (nextSibling != null) - { - parent.insertBefore(node, nextSibling); - } - else - { - parent.appendChild(node); - } - } - } - } - else - { - String value = Expr._string(context, ret); - if (value != null && value.length() > 0) - { - Text textNode = doc.createTextNode(value); - if (nextSibling != null) - { - parent.insertBefore(textNode, nextSibling); - } - else - { - parent.appendChild(textNode); - } - } - } - // copy-of doesn't process children - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("select="); - buf.append(select); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/CurrentFunction.java b/libjava/gnu/xml/transform/CurrentFunction.java deleted file mode 100644 index 845793ac795..00000000000 --- a/libjava/gnu/xml/transform/CurrentFunction.java +++ /dev/null @@ -1,98 +0,0 @@ -/* CurrentFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collections; -import java.util.List; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>current()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CurrentFunction - extends Expr - implements Function, XPathFunction -{ - - final Stylesheet stylesheet; - - CurrentFunction(Stylesheet stylesheet) - { - this.stylesheet = stylesheet; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - // We can't do anything useful here. - // So much for the JAXP API... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - } - - public Object evaluate(Node context, int pos, int len) - { - return Collections.singleton(stylesheet.current); - } - - public Expr clone(Object context) - { - Stylesheet s = stylesheet; - if (context instanceof Stylesheet) - { - s = (Stylesheet) context; - } - return new CurrentFunction(s); - } - - public String toString() - { - return "current()"; - } - -} - diff --git a/libjava/gnu/xml/transform/DOMSourceLocator.java b/libjava/gnu/xml/transform/DOMSourceLocator.java deleted file mode 100644 index 9bc8fb1b6c8..00000000000 --- a/libjava/gnu/xml/transform/DOMSourceLocator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* DOMSourceLocator.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.transform.dom.DOMLocator; -import org.w3c.dom.Node; - -/** - * Simple DOMLocator implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class DOMSourceLocator - implements DOMLocator -{ - - final Node node; - - DOMSourceLocator(Node node) - { - this.node = node; - } - - public Node getOriginatingNode() - { - return node; - } - - public String getPublicId() - { - return null; - } - - public String getSystemId() - { - return null; - } - - public int getLineNumber() - { - return -1; - } - - public int getColumnNumber() - { - return -1; - } - -} diff --git a/libjava/gnu/xml/transform/DocumentFunction.java b/libjava/gnu/xml/transform/DocumentFunction.java deleted file mode 100644 index 22dac75db12..00000000000 --- a/libjava/gnu/xml/transform/DocumentFunction.java +++ /dev/null @@ -1,243 +0,0 @@ -/* DocumentFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; -import javax.xml.transform.TransformerException; -import javax.xml.transform.dom.DOMSource; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Constant; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; -import gnu.xml.xpath.IdFunction; - -/** - * The XSLT <code>document()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class DocumentFunction - extends Expr - implements Function, XPathFunction -{ - - final Stylesheet stylesheet; - final Node base; - List args; - List values; - - DocumentFunction(Stylesheet stylesheet, Node base) - { - this.stylesheet = stylesheet; - this.base = base; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - values = args; - return evaluate(null, 1, 1); - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - int arity = args.size(); - if (values == null) - { - values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - } - Object ret; - switch (arity) - { - case 1: - Object arg = values.get(0); - if (arg instanceof Collection) - { - Collection ns = (Collection) arg; - Collection acc = new TreeSet(); - for (Iterator i = ns.iterator(); i.hasNext(); ) - { - Node node = (Node) i.next(); - String s = Expr.stringValue(node); - acc.addAll(document(s, node.getBaseURI())); - } - ret = acc; - } - else - { - String s = Expr._string(context, arg); - ret = document(s, base.getBaseURI()); - } - break; - case 2: - Object arg1 = values.get(0); - Object arg2 = values.get(1); - if (!(arg2 instanceof Collection)) - { - throw new RuntimeException("second argument is not a node-set"); - } - Collection arg2ns = (Collection) arg2; - String base2 = arg2ns.isEmpty() ? null : - ((Node) arg2ns.iterator().next()).getBaseURI(); - if (arg1 instanceof Collection) - { - Collection arg1ns = (Collection) arg1; - Collection acc = new TreeSet(); - for (Iterator i = arg1ns.iterator(); i.hasNext(); ) - { - Node node = (Node) i.next(); - String s = Expr.stringValue(node); - acc.addAll(document(s, base2)); - } - ret = acc; - } - else - { - String s = Expr._string(context, arg1); - ret = document(s, base2); - } - break; - default: - throw new RuntimeException("invalid arity"); - } - values = null; - return ret; - } - - /** - * The XSL <code>document</code> function. - * @see XSLT 12.1 - * @param uri the URI from which to retrieve nodes - * @param base the base URI for relative URIs - */ - Collection document(String uri, String base) - { - if ("".equals(uri) || uri == null) - { - uri = this.base.getBaseURI(); - } - - // Get fragment - Expr fragment = null; - int hi = uri.indexOf('#'); - if (hi != -1) - { - String f = uri.substring(hi + 1); - uri = uri.substring(0, hi); - // TODO handle xpointer() here - // this only handles IDs - fragment = new IdFunction(new Constant(f)); - } - - // Get document source - try - { - DOMSource source; - XSLURIResolver resolver = stylesheet.factory.resolver; - synchronized (resolver) - { - if (stylesheet.transformer != null) - { - resolver.setUserResolver(stylesheet.transformer.uriResolver); - resolver.setUserListener(stylesheet.transformer.errorListener); - } - source = resolver.resolveDOM(null, base, uri); - } - Node node = source.getNode(); - if (fragment == null) - { - return Collections.singleton(node); - } - else - { - Object ret = fragment.evaluate(node, 1, 1); - if (!(ret instanceof Collection)) - { - // XXX Report error? - return Collections.EMPTY_SET; - } - return (Collection) ret; - } - } - catch (TransformerException e) - { - String msg = "can't open " + uri; - if (base != null) - { - msg += " with base " + base; - } - throw new RuntimeException(msg); - } - } - - public Expr clone(Object context) - { - Stylesheet s = stylesheet; - if (context instanceof Stylesheet) - { - s = (Stylesheet) context; - } - DocumentFunction f = new DocumentFunction(s, base); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} diff --git a/libjava/gnu/xml/transform/ElementAvailableFunction.java b/libjava/gnu/xml/transform/ElementAvailableFunction.java deleted file mode 100644 index 7cf00d3252d..00000000000 --- a/libjava/gnu/xml/transform/ElementAvailableFunction.java +++ /dev/null @@ -1,169 +0,0 @@ -/* ElementAvailableFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.TreeSet; -import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>element-available</code> function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class ElementAvailableFunction - extends Expr - implements Function, XPathFunction -{ - - static final Collection elements; - static - { - TreeSet acc = new TreeSet(); - acc.add("stylesheet"); - acc.add("template"); - acc.add("param"); - acc.add("variable"); - acc.add("include"); - acc.add("import"); - acc.add("output"); - acc.add("preserve-space"); - acc.add("strip-space"); - acc.add("key"); - acc.add("decimal-format"); - acc.add("namespace-alias"); - acc.add("attribute-set"); - acc.add("apply-templates"); - acc.add("call-template"); - acc.add("value-of"); - acc.add("for-each"); - acc.add("if"); - acc.add("choose"); - acc.add("when"); - acc.add("otherwise"); - acc.add("element"); - acc.add("attribute"); - acc.add("text"); - acc.add("copy"); - acc.add("processing-instruction"); - acc.add("comment"); - acc.add("number"); - acc.add("copy-of"); - acc.add("message"); - acc.add("sort"); - acc.add("with-param"); - acc.add("fallback"); - acc.add("apply-imports"); - elements = Collections.unmodifiableSet(acc); - } - - final NamespaceContext nsctx; - List args; - - ElementAvailableFunction(NamespaceContext nsctx) - { - this.nsctx = nsctx; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - Expr arg = (Expr) args.get(0); - Object val = arg.evaluate(context, pos, len); - String name = _string(context, val); - String prefix, localName, uri; - int ci = name.indexOf(':'); - if (ci == -1) - { - prefix = null; - localName = name; - } - else - { - prefix = name.substring(0, ci); - localName = name.substring(ci + 1); - } - uri = nsctx.getNamespaceURI(prefix); - if (Stylesheet.XSL_NS.equals(uri)) - { - return elements.contains(localName) ? - Boolean.TRUE : Boolean.FALSE; - // TODO extension elements - } - return Boolean.FALSE; - } - - public Expr clone(Object context) - { - NamespaceContext n = nsctx; - if (context instanceof NamespaceContext) - { - n = (NamespaceContext) context; - } - ElementAvailableFunction f = new ElementAvailableFunction(n); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/ElementNode.java b/libjava/gnu/xml/transform/ElementNode.java deleted file mode 100644 index 3609f0e0c19..00000000000 --- a/libjava/gnu/xml/transform/ElementNode.java +++ /dev/null @@ -1,279 +0,0 @@ -/* ElementNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.StringTokenizer; -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSL <code>element</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ElementNode - extends TemplateNode -{ - - final TemplateNode name; - final TemplateNode namespace; - final String uas; - final Node source; - final Collection elementExcludeResultPrefixes; - - ElementNode(TemplateNode children, TemplateNode next, TemplateNode name, - TemplateNode namespace, String uas, Node source) - { - super(children, next); - this.name = name; - this.namespace = namespace; - this.uas = uas; - this.source = source; - NamedNodeMap attrs = source.getAttributes(); - Node attr = attrs.getNamedItemNS(Stylesheet.XSL_NS, - "exclude-result-prefixes"); - if (attr != null) - { - elementExcludeResultPrefixes = new HashSet(); - StringTokenizer st = new StringTokenizer(attr.getNodeValue()); - while (st.hasMoreTokens()) - { - elementExcludeResultPrefixes.add(st.nextToken()); - } - } - else - { - elementExcludeResultPrefixes = Collections.EMPTY_SET; - } - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ElementNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - name.clone(stylesheet), - (namespace == null) ? null : - namespace.clone(stylesheet), - uas, source); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - // Create a document fragment to hold the name - DocumentFragment fragment = doc.createDocumentFragment(); - // Apply name to the fragment - name.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - String nameValue = Expr.stringValue(fragment); - - String namespaceValue = null; - if (namespace != null) - { - // Create a document fragment to hold the namespace - fragment = doc.createDocumentFragment(); - // Apply namespace to the fragment - namespace.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - namespaceValue = Expr.stringValue(fragment); - if (namespaceValue.length() == 0) - { - namespaceValue = null; - } - } - - String prefix = getPrefix(nameValue); - if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) - { - int ci = nameValue.indexOf(':'); - nameValue = nameValue.substring(ci + 1); - } - else - { - // Namespace aliasing - if (prefix == null) - { - prefix = "#default"; - } - String resultPrefix = - (String) stylesheet.namespaceAliases.get(prefix); - if (resultPrefix != null) - { - if ("#default".equals(resultPrefix)) - { - resultPrefix = null; - } - namespaceValue = source.lookupNamespaceURI(resultPrefix); - } - if (prefix == "#default") - { - prefix = null; - } - // Look up ordinary namespace for this prefix - if (namespaceValue == null) - { - if (XMLConstants.XML_NS_PREFIX.equals(prefix)) - { - namespaceValue = XMLConstants.XML_NS_URI; - } - else - { - // Resolve namespace for this prefix - namespaceValue = source.lookupNamespaceURI(prefix); - } - } - /*if (prefix == null) - { - // Resolve prefix for this namespace - prefix = parent.lookupPrefix(namespaceValue); - if (prefix != null) - { - nameValue = prefix + ":" + nameValue; - } - }*/ - } - // Create element - Element element = (namespaceValue != null) ? - doc.createElementNS(namespaceValue, nameValue) : - doc.createElement(nameValue); - if (nextSibling != null) - { - parent.insertBefore(element, nextSibling); - } - else - { - parent.appendChild(element); - } - stylesheet.addNamespaceNodes(source, element, doc, - elementExcludeResultPrefixes); - if (uas != null) - { - StringTokenizer st = new StringTokenizer(uas, " "); - while (st.hasMoreTokens()) - { - addAttributeSet(stylesheet, mode, context, pos, len, - element, null, st.nextToken()); - } - } - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - element, null); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - final String getPrefix(String name) - { - int ci = name.indexOf(':'); - return (ci == -1) ? null : name.substring(0, ci); - } - - void addAttributeSet(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling, String attributeSet) - throws TransformerException - { - for (Iterator i = stylesheet.attributeSets.iterator(); i.hasNext(); ) - { - AttributeSet as = (AttributeSet) i.next(); - if (!as.name.equals(attributeSet)) - { - continue; - } - if (as.uas != null) - { - StringTokenizer st = new StringTokenizer(as.uas, " "); - while (st.hasMoreTokens()) - { - addAttributeSet(stylesheet, mode, context, pos, len, - parent, nextSibling, st.nextToken()); - } - } - if (as.children != null) - { - as.children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("name="); - buf.append(name); - if (uas != null) - { - buf.append(",uas="); - buf.append(uas); - } - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/ErrorListenerErrorHandler.java b/libjava/gnu/xml/transform/ErrorListenerErrorHandler.java deleted file mode 100644 index d79bb15467a..00000000000 --- a/libjava/gnu/xml/transform/ErrorListenerErrorHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -/* ErrorListenerErrorHandler.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.transform.ErrorListener; -import javax.xml.transform.TransformerException; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * An ErrorHandler that wraps an ErrorListener. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class ErrorListenerErrorHandler - implements ErrorHandler -{ - - final ErrorListener listener; - - ErrorListenerErrorHandler(ErrorListener listener) - { - this.listener = listener; - } - - public void warning(SAXParseException e) - throws SAXException - { - try - { - listener.warning(new TransformerException(e)); - } - catch (TransformerException e2) - { - throw new SAXException(e2); - } - } - - public void error(SAXParseException e) - throws SAXException - { - try - { - listener.error(new TransformerException(e)); - } - catch (TransformerException e2) - { - throw new SAXException(e2); - } - } - - public void fatalError(SAXParseException e) - throws SAXException - { - try - { - listener.fatalError(new TransformerException(e)); - } - catch (TransformerException e2) - { - throw new SAXException(e2); - } - } - -} diff --git a/libjava/gnu/xml/transform/ForEachNode.java b/libjava/gnu/xml/transform/ForEachNode.java deleted file mode 100644 index fd9797dd474..00000000000 --- a/libjava/gnu/xml/transform/ForEachNode.java +++ /dev/null @@ -1,149 +0,0 @@ -/* ForEachNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSLT <code>for-each</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ForEachNode - extends TemplateNode -{ - - final Expr select; - final List sortKeys; - - ForEachNode(TemplateNode children, TemplateNode next, Expr select, - List sortKeys) - { - super(children, next); - this.select = select; - this.sortKeys = sortKeys; - } - - TemplateNode clone(Stylesheet stylesheet) - { - int len = sortKeys.size(); - List sortKeys2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - sortKeys2.add(((Key) sortKeys.get(i)).clone(stylesheet)); - } - return new ForEachNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - select.clone(stylesheet), - sortKeys2); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (children != null) - { - // Set current template to null - Template saved = stylesheet.currentTemplate; - stylesheet.currentTemplate = null; - Object ret = select.evaluate(context, pos, len); - //System.err.println(toString() + ": " + context+" -> "+ret); - if (ret instanceof Collection) - { - Collection ns = (Collection) ret; - List list = new ArrayList(ns); - if (sortKeys != null) - { - for (Iterator i = sortKeys.iterator(); i.hasNext(); ) - { - SortKey sortKey = (SortKey) i.next(); - sortKey.init(stylesheet, mode, context, pos, len, parent, - nextSibling); - } - Collections.sort(list, new XSLComparator(sortKeys)); - } - else - { - Collections.sort(list, documentOrderComparator); - } - // Perform children for each node - int l = list.size(); - int p = 1; - for (Iterator i = list.iterator(); i.hasNext(); ) - { - Node node = (Node) i.next(); - stylesheet.current = node; - children.apply(stylesheet, mode, - node, p++, l, - parent, nextSibling); - } - } - // Restore current template - stylesheet.currentTemplate = saved; - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("select="); - buf.append(select); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/FormatNumberFunction.java b/libjava/gnu/xml/transform/FormatNumberFunction.java deleted file mode 100644 index aaa015b4ae9..00000000000 --- a/libjava/gnu/xml/transform/FormatNumberFunction.java +++ /dev/null @@ -1,132 +0,0 @@ -/* FormatNumberFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>format-number()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class FormatNumberFunction - extends Expr - implements XPathFunction, Function -{ - - final Stylesheet stylesheet; - List args; - - FormatNumberFunction(Stylesheet stylesheet) - { - this.stylesheet = stylesheet; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - int arity = args.size(); - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - double number = _number(context, values.get(0)); - String pattern = _string(context, values.get(1)); - // Currency symbol ¤ is not supposed to be present - if (pattern.indexOf('\u00a4') != -1) - { - // Replace with $ (Xalan does this) - pattern = pattern.replace('\u00a4', '$'); - } - String dfName = null; - if (arity > 2) - { - dfName = _string(context, values.get(2)); - // otherwise the default decimal-format will be used - } - DecimalFormat df = (DecimalFormat) stylesheet.decimalFormats.get(dfName); - if (df == null) - { - throw new IllegalArgumentException("No such decimal-format: " + - dfName); - } - df.applyLocalizedPattern(pattern); - return df.format(number); - } - - public Expr clone(Object context) - { - Stylesheet s = stylesheet; - if (context instanceof Stylesheet) - { - s = (Stylesheet) context; - } - FormatNumberFunction f = new FormatNumberFunction(s); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/FunctionAvailableFunction.java b/libjava/gnu/xml/transform/FunctionAvailableFunction.java deleted file mode 100644 index b7dfb6192ff..00000000000 --- a/libjava/gnu/xml/transform/FunctionAvailableFunction.java +++ /dev/null @@ -1,175 +0,0 @@ -/* FunctionAvailableFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.TreeSet; -import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>function-available</code> function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class FunctionAvailableFunction - extends Expr - implements Function, XPathFunction -{ - - static final Collection xsltFunctions; - static final Collection xpathFunctions; - static - { - TreeSet acc = new TreeSet(); - acc.add("document"); - acc.add("key"); - acc.add("format-number"); - acc.add("current"); - acc.add("unparsed-entity-uri"); - acc.add("generate-id"); - acc.add("system-property"); - acc.add("element-available"); - acc.add("function-available"); - xsltFunctions = Collections.unmodifiableSet(acc); - acc = new TreeSet(); - acc.add("boolean"); - acc.add("ceiling"); - acc.add("concat"); - acc.add("contains"); - acc.add("count"); - acc.add("false"); - acc.add("floor"); - acc.add("id"); - acc.add("lang"); - acc.add("last"); - acc.add("local-name"); - acc.add("name"); - acc.add("namespace-uri"); - acc.add("normalize-space"); - acc.add("not"); - acc.add("number"); - acc.add("position"); - acc.add("round"); - acc.add("starts-with"); - acc.add("string"); - acc.add("string-length"); - acc.add("substring-after"); - acc.add("substring-before"); - acc.add("substring"); - acc.add("sum"); - acc.add("translate"); - acc.add("true"); - xpathFunctions = Collections.unmodifiableSet(acc); - } - - final NamespaceContext nsctx; - List args; - - FunctionAvailableFunction(NamespaceContext nsctx) - { - this.nsctx = nsctx; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - Expr arg = (Expr) args.get(0); - Object val = arg.evaluate(context, pos, len); - String name = _string(context, val); - String prefix, localName, uri; - int ci = name.indexOf(':'); - if (ci == -1) - { - prefix = null; - localName = name; - } - else - { - prefix = name.substring(0, ci); - localName = name.substring(ci + 1); - } - uri = nsctx.getNamespaceURI(prefix); - if (uri == null) - { - return xsltFunctions.contains(localName) || - xpathFunctions.contains(localName) ? - Boolean.TRUE : Boolean.FALSE; - // TODO extension functions - } - return Boolean.FALSE; - } - - public Expr clone(Object context) - { - NamespaceContext n = nsctx; - if (context instanceof NamespaceContext) - { - n = (NamespaceContext) context; - } - FunctionAvailableFunction f = new FunctionAvailableFunction(n); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/GenerateIdFunction.java b/libjava/gnu/xml/transform/GenerateIdFunction.java deleted file mode 100644 index a7682c91802..00000000000 --- a/libjava/gnu/xml/transform/GenerateIdFunction.java +++ /dev/null @@ -1,126 +0,0 @@ -/* GenerateIdFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>generate-id()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class GenerateIdFunction - extends Expr - implements XPathFunction, Function -{ - - List args; - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - int arity = args.size(); - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - Node node; - Collection ns = (arity == 0) ? Collections.EMPTY_SET : - (Collection) values.get(0); - if (ns.isEmpty()) - { - node = context; - } - else - { - List list = new ArrayList(ns); - Collections.sort(list, documentOrderComparator); - node = (Node) list.get(0); - } - - String name = node.getNodeName(); - int index = 0, depth = 0; - for (Node ctx = node.getPreviousSibling(); ctx != null; - ctx = ctx.getPreviousSibling()) - { - index++; - } - for (Node ctx = node.getParentNode(); ctx != null; - ctx = ctx.getParentNode()) - { - depth++; - } - return name + "-" + index + "-" + depth; - } - - public Expr clone(Object context) - { - GenerateIdFunction f = new GenerateIdFunction(); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/IfNode.java b/libjava/gnu/xml/transform/IfNode.java deleted file mode 100644 index f277cce07b9..00000000000 --- a/libjava/gnu/xml/transform/IfNode.java +++ /dev/null @@ -1,107 +0,0 @@ -/* IfNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSL <code>if</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class IfNode - extends TemplateNode -{ - - final Expr test; - - IfNode(TemplateNode children, TemplateNode next, Expr test) - { - super(children, next); - this.test = test; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new IfNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - test.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Object ret = test.evaluate(context, pos, len); - boolean success = (ret instanceof Boolean) ? - ((Boolean) ret).booleanValue() : - Expr._boolean(context, ret); - if (success) - { - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("test="); - buf.append(test); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/Key.java b/libjava/gnu/xml/transform/Key.java deleted file mode 100644 index 72bd90aedb0..00000000000 --- a/libjava/gnu/xml/transform/Key.java +++ /dev/null @@ -1,71 +0,0 @@ -/* Key.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Pattern; - -/** - * An XSL key. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class Key -{ - - final QName name; - final Pattern match; - final Expr use; - - Key(QName name, Pattern match, Expr use) - { - this.name = name; - this.match = match; - this.use = use; - } - - Key clone(Stylesheet stylesheet) - { - return new Key(name, - (Pattern) match.clone(stylesheet), - use.clone(stylesheet)); - } - -} - diff --git a/libjava/gnu/xml/transform/KeyFunction.java b/libjava/gnu/xml/transform/KeyFunction.java deleted file mode 100644 index eb842f289c9..00000000000 --- a/libjava/gnu/xml/transform/KeyFunction.java +++ /dev/null @@ -1,216 +0,0 @@ -/* KeyFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; -import gnu.xml.xpath.Pattern; - -/** - * The XSLT <code>key()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class KeyFunction - extends Pattern - implements XPathFunction, Function -{ - - final Stylesheet stylesheet; - List args; - - KeyFunction(Stylesheet stylesheet) - { - this.stylesheet = stylesheet; - } - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public boolean matches(Node context) - { - Object ret = evaluate(context, 1, 1); - return !((Collection) ret).isEmpty(); - } - - public Object evaluate(Node context, int pos, int len) - { - // Evaluate arguments - int arity = args.size(); - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - // Get key name - QName keyName = QName.valueOf(_string(context, values.get(0))); - // Expand qualified name - String uri = keyName.getNamespaceURI(); - String prefix = keyName.getPrefix(); - if ((uri == null || uri.length() == 0) && - (prefix != null && prefix.length() > 0)) - { - uri = stylesheet.getNamespaceURI(prefix); - if (uri != null && uri.length() > 0) - { - String localName = keyName.getLocalPart(); - keyName = new QName(uri, localName, prefix); - } - } - // Compute matching key set - Collection keySet = new LinkedList(); - for (Iterator i = stylesheet.keys.iterator(); i.hasNext(); ) - { - Key key = (Key) i.next(); - if (key.name.equals(keyName)) - { - keySet.add(key); - } - } - // Get target - Object target = values.get(1); - Collection acc = new LinkedHashSet(); - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - if (target instanceof Collection) - { - for (Iterator i = ((Collection) target).iterator(); i.hasNext(); ) - { - String val = Expr.stringValue((Node) i.next()); - addKeyNodes(doc, keySet, val, acc); - } - } - else - { - String val = Expr._string(context, target); - addKeyNodes(doc, keySet, val, acc); - } - List ret = new ArrayList(acc); - Collections.sort(ret, documentOrderComparator); - return ret; - } - - final void addKeyNodes(Node node, Collection keySet, - String value, Collection acc) - { - addKeyNodeIfMatch(node, keySet, value, acc); - // Apply children - for (Node ctx = node.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - addKeyNodes(ctx, keySet, value, acc); - } - } - - final void addKeyNodeIfMatch(Node node, Collection keySet, - String value, Collection acc) - { - for (Iterator i = keySet.iterator(); i.hasNext(); ) - { - Key key = (Key) i.next(); - if (key.match.matches(node)) - { - Object eval = key.use.evaluate(node, 1, 1); - if (eval instanceof Collection) - { - for (Iterator j = ((Collection) eval).iterator(); - j.hasNext(); ) - { - String keyValue = Expr.stringValue((Node) j.next()); - if (value.equals(keyValue)) - { - acc.add(node); - return; - } - } - } - else - { - String keyValue = Expr._string(node, eval); - if (value.equals(keyValue)) - { - acc.add(node); - return; - } - } - } - } - } - - public Expr clone(Object context) - { - Stylesheet s = stylesheet; - if (context instanceof Stylesheet) - { - s = (Stylesheet) context; - } - KeyFunction f = new KeyFunction(s); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/LiteralNode.java b/libjava/gnu/xml/transform/LiteralNode.java deleted file mode 100644 index b053727d7f3..00000000000 --- a/libjava/gnu/xml/transform/LiteralNode.java +++ /dev/null @@ -1,225 +0,0 @@ -/* LiteralNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.StringTokenizer; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * A template node that copies a DOM node in the template to the result - * tree. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class LiteralNode - extends TemplateNode -{ - - /** - * The source node in the XSL template. - */ - final Node source; - - final Collection elementExcludeResultPrefixes; - - LiteralNode(TemplateNode children, TemplateNode next, Node source) - { - super(children, next); - this.source = source; - if (source.getNodeType() == Node.ELEMENT_NODE) - { - NamedNodeMap attrs = source.getAttributes(); - Node attr = attrs.getNamedItemNS(Stylesheet.XSL_NS, - "exclude-result-prefixes"); - if (attr != null) - { - elementExcludeResultPrefixes = new HashSet(); - StringTokenizer st = new StringTokenizer(attr.getNodeValue()); - while (st.hasMoreTokens()) - { - elementExcludeResultPrefixes.add(st.nextToken()); - } - } - else - { - elementExcludeResultPrefixes = Collections.EMPTY_SET; - } - } - else - { - elementExcludeResultPrefixes = null; - } - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new LiteralNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - source); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Node result = null; - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - short nodeType = source.getNodeType(); - if (nodeType == Node.ATTRIBUTE_NODE && - parent.getFirstChild() != null) - { - // Ignore attributes added after child elements - } - else - { - // Namespace aliasing - if (nodeType == Node.ELEMENT_NODE) - { - String prefix = source.getPrefix(); - if (prefix == null) - { - prefix = "#default"; - } - String resultPrefix = - (String) stylesheet.namespaceAliases.get(prefix); - if (resultPrefix != null) - { - if ("#default".equals(resultPrefix)) - { - resultPrefix = null; - } - String uri = source.lookupNamespaceURI(resultPrefix); - String name = source.getNodeName(); - // Create a new element node in the result document - result = doc.createElementNS(uri, name); - // copy attributes - NamedNodeMap srcAttrs = source.getAttributes(); - NamedNodeMap dstAttrs = result.getAttributes(); - int l = srcAttrs.getLength(); - for (int i = 0; i < l; i++) - { - Node attr = srcAttrs.item(i); - if (!Stylesheet.XSL_NS.equals(attr.getNamespaceURI())) - { - attr = attr.cloneNode(true); - attr = doc.adoptNode(attr); - dstAttrs.setNamedItemNS(attr); - } - } - } - } - if (result == null) - { - // Create result node - result = source.cloneNode(false); - // Remove any XSL attributes - NamedNodeMap attrs = result.getAttributes(); - if (attrs != null) - { - int l = attrs.getLength(); - for (int i = 0; i < l; i++) - { - Node attr = attrs.item(i); - if (Stylesheet.XSL_NS.equals(attr.getNamespaceURI())) - { - attrs.removeNamedItem(attr.getNodeName()); - i--; - l--; - } - } - } - result = doc.adoptNode(result); - if (result == null) - { - String msg = "Error adopting node to result tree"; - DOMSourceLocator l = new DOMSourceLocator(context); - throw new TransformerException(msg, l); - } - } - if (nextSibling != null) - { - parent.insertBefore(result, nextSibling); - } - else - { - parent.appendChild(result); - } - if (nodeType == Node.ELEMENT_NODE) - { - stylesheet.addNamespaceNodes(source, result, doc, - elementExcludeResultPrefixes); - } - // children - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - result, null); - } - } - // next sibling - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("source="); - buf.append(source); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/MessageNode.java b/libjava/gnu/xml/transform/MessageNode.java deleted file mode 100644 index 9feeb752788..00000000000 --- a/libjava/gnu/xml/transform/MessageNode.java +++ /dev/null @@ -1,97 +0,0 @@ -/* MessageNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * An XSL <code>message</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class MessageNode - extends TemplateNode -{ - - final boolean terminate; - - MessageNode(TemplateNode children, TemplateNode next, boolean terminate) - { - super(children, next); - this.terminate = terminate; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new MessageNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - terminate); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (children != null) - { - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - DocumentFragment fragment = doc.createDocumentFragment(); - children.apply(stylesheet, mode, context, pos, len, fragment, null); - String message = Expr.stringValue(fragment); - System.err.println(message); - if (terminate) - { - stylesheet.terminated = true; - } - } - if (next != null && !terminate) - { - next.apply(stylesheet, mode, context, pos, len, parent, nextSibling); - } - } - -} diff --git a/libjava/gnu/xml/transform/NodeNumberNode.java b/libjava/gnu/xml/transform/NodeNumberNode.java deleted file mode 100644 index 99ffe8bbb24..00000000000 --- a/libjava/gnu/xml/transform/NodeNumberNode.java +++ /dev/null @@ -1,258 +0,0 @@ -/* NodeNumberNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Pattern; -import gnu.xml.xpath.Selector; -import gnu.xml.xpath.UnionExpr; - -/** - * A template node representing the XSL <code>number</code> instruction - * with no <code>value</code> expression, i.e. the value is computed from - * the document position of the context node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NodeNumberNode - extends AbstractNumberNode -{ - - static final int SINGLE = 0; - static final int MULTIPLE = 1; - static final int ANY = 2; - - final int level; - final Pattern count; - final Pattern from; - - NodeNumberNode(TemplateNode children, TemplateNode next, - int level, Pattern count, Pattern from, - TemplateNode format, String lang, - int letterValue, String groupingSeparator, int groupingSize) - { - super(children, next, format, lang, letterValue, groupingSeparator, - groupingSize); - this.level = level; - this.count = count; - this.from = from; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new NodeNumberNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - level, - (count == null) ? null : - (Pattern) count.clone(stylesheet), - (from == null) ? from : - (Pattern) from.clone(stylesheet), - format, lang, letterValue, - groupingSeparator, groupingSize); - } - - int[] compute(Stylesheet stylesheet, Node context, int pos, int len) - throws TransformerException - { - /*if (from != null) - { - Object ret = from.evaluate(context, pos, len); - if (ret instanceof Collection) - { - Collection ns = (Collection) ret; - if (ns.size() > 0) - { - List list = new ArrayList(ns); - Collections.sort(list, documentOrderComparator); - context = (Node) list.get(0); - } - else - { - return new int[0]; - } - } - else - { - return new int[0]; - } - }*/ - Node current = context; - switch (level) - { - case SINGLE: - if (from == null) - { - while (context != null && !countMatches(current, context)) - { - context = context.getParentNode(); - } - } - else - { - while (context != null && !countMatches(current, context) && - !fromMatches(context)) - { - context = context.getParentNode(); - } - } - return (context == null) ? new int[0] : - new int[] { (context == current) ? pos : getIndex(current, context) }; - case MULTIPLE: - List ancestors = new ArrayList(); - while (context != null) - { - if (countMatches(current, context)) - { - if (from == null || fromMatches(context)) - { - ancestors.add(context); - } - } - context = context.getParentNode(); - } - Collections.sort(ancestors, documentOrderComparator); - int[] ret = new int[ancestors.size()]; - for (int i = 0; i < ret.length; i++) - { - ret[i] = getIndex(current, (Node) ancestors.get(i)); - } - return ret; - case ANY: - Expr preceding = new Selector(Selector.PRECEDING, - Collections.EMPTY_LIST); - Expr ancestorOrSelf = new Selector(Selector.ANCESTOR_OR_SELF, - Collections.EMPTY_LIST); - Expr any = new UnionExpr(preceding, ancestorOrSelf); - Object eval = any.evaluate(context, pos, len); - if (eval instanceof Collection) - { - Collection ns = (Collection) eval; - List candidates = new ArrayList(); - for (Iterator i = ns.iterator(); i.hasNext(); ) - { - Node candidate = (Node) i.next(); - if (countMatches(current, candidate)) - { - candidates.add(candidate); - if (from != null && from.matches(candidate)) - { - break; - } - } - } - return new int[] { candidates.size() }; - } - return new int[0]; - default: - throw new TransformerException("invalid level"); - } - } - - boolean countMatches(Node current, Node node) - { - if (count == null) - { - int cnt = current.getNodeType(); - int nnt = node.getNodeType(); - if (cnt != nnt) - { - return false; - } - if (nnt == Node.ELEMENT_NODE || nnt == Node.ATTRIBUTE_NODE) - { - String curi = current.getNamespaceURI(); - String nuri = node.getNamespaceURI(); - if ((curi == null && nuri != null) || - (curi != null && !curi.equals(nuri))) - { - return false; - } - String cn = current.getLocalName(); - String nn = current.getLocalName(); - if (!cn.equals(nn)) - { - return false; - } - } - return true; - } - else - { - return count.matches(node); - } - } - - boolean fromMatches(Node node) - { - for (Node ctx = node.getParentNode(); ctx != null; - ctx = ctx.getParentNode()) - { - if (from.matches(ctx)) - { - return true; - } - } - return false; - } - - int getIndex(Node current, Node node) - { - int index = 0; - do - { - do - { - node = node.getPreviousSibling(); - } - while (node != null && !countMatches(current, node)); - index++; - } - while (node != null); - return index; - } - -} diff --git a/libjava/gnu/xml/transform/NumberNode.java b/libjava/gnu/xml/transform/NumberNode.java deleted file mode 100644 index c16324b63a4..00000000000 --- a/libjava/gnu/xml/transform/NumberNode.java +++ /dev/null @@ -1,85 +0,0 @@ -/* NumberNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>number</code> instruction - * with a <code>value</code> expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NumberNode - extends AbstractNumberNode -{ - - final Expr value; - - NumberNode(TemplateNode children, TemplateNode next, - Expr value, TemplateNode format, String lang, - int letterValue, String groupingSeparator, int groupingSize) - { - super(children, next, format, lang, letterValue, groupingSeparator, - groupingSize); - this.value = value; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new NumberNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - value.clone(stylesheet), - format, lang, letterValue, - groupingSeparator, groupingSize); - } - - int[] compute(Stylesheet stylesheet, Node context, int pos, int len) - throws TransformerException - { - Object ret = value.evaluate(context, pos, len); - Double d = (ret instanceof Double) ? ((Double) ret) : - new Double(Expr._number(context, ret)); - return new int[] { d.intValue() }; - } - -} diff --git a/libjava/gnu/xml/transform/OtherwiseNode.java b/libjava/gnu/xml/transform/OtherwiseNode.java deleted file mode 100644 index 00a3d9d3c81..00000000000 --- a/libjava/gnu/xml/transform/OtherwiseNode.java +++ /dev/null @@ -1,93 +0,0 @@ -/* OtherwiseNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; - -/** - * A template node representing an XSL <code>otherwise</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class OtherwiseNode - extends TemplateNode -{ - - OtherwiseNode(TemplateNode children, TemplateNode next) - { - super(children, next); - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new OtherwiseNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/ParameterNode.java b/libjava/gnu/xml/transform/ParameterNode.java deleted file mode 100644 index 8d709f80115..00000000000 --- a/libjava/gnu/xml/transform/ParameterNode.java +++ /dev/null @@ -1,156 +0,0 @@ -/* ParameterNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collections; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node that sets a variable or parameter during template - * processing. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ParameterNode - extends TemplateNode -{ - - final String name; - final Expr select; - final boolean global; - - ParameterNode(TemplateNode children, TemplateNode next, - String name, Expr select, boolean global) - { - super(children, next); - this.name = name; - this.select = select; - this.global = global; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ParameterNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - name, - select.clone(stylesheet), - global); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - boolean apply = global || !stylesheet.bindings.containsKey(name, global); - if (apply) - { - // push the variable context - stylesheet.bindings.push(global); - // set the variable - Object value = getValue(stylesheet, mode, context, pos, len); - if (value != null) - { - stylesheet.bindings.set(name, value, global); - } - } - // variable and param don't process children as such - // all subsequent instructions are processed with that variable context - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - if (apply) - { - // pop the variable context - stylesheet.bindings.pop(global); - } - } - - Object getValue(Stylesheet stylesheet, QName mode, - Node context, int pos, int len) - throws TransformerException - { - if (select != null) - { - return select.evaluate(context, pos, len); - } - else if (children != null) - { - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - DocumentFragment fragment = doc.createDocumentFragment(); - children.apply(stylesheet, mode, context, pos, len, fragment, null); - return Collections.singleton(fragment); - } - else - { - return null; - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("name="); - buf.append(name); - if (select != null) - { - buf.append(",select="); - buf.append(select); - } - if (global) - { - buf.append(",global"); - } - buf.append(']'); - return buf.toString(); - } - -} - diff --git a/libjava/gnu/xml/transform/ProcessingInstructionNode.java b/libjava/gnu/xml/transform/ProcessingInstructionNode.java deleted file mode 100644 index e6823a5b2c6..00000000000 --- a/libjava/gnu/xml/transform/ProcessingInstructionNode.java +++ /dev/null @@ -1,123 +0,0 @@ -/* ProcessingInstructionNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>processing-instruction</code> - * instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ProcessingInstructionNode - extends TemplateNode -{ - - final String name; - - ProcessingInstructionNode(TemplateNode children, TemplateNode next, - String name) - { - super(children, next); - this.name = name; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ProcessingInstructionNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - name); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - String data = null; - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - if (children != null) - { - // Create a document fragment to hold the text - DocumentFragment fragment = doc.createDocumentFragment(); - // Apply children to the fragment - children.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - data = Expr.stringValue(fragment); - } - ProcessingInstruction pi = doc.createProcessingInstruction(name, data); - // Insert into result tree - if (nextSibling != null) - { - parent.insertBefore(pi, nextSibling); - } - else - { - parent.appendChild(pi); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("name="); - buf.append(name); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/SAXSerializer.java b/libjava/gnu/xml/transform/SAXSerializer.java deleted file mode 100644 index 9650e3e052d..00000000000 --- a/libjava/gnu/xml/transform/SAXSerializer.java +++ /dev/null @@ -1,305 +0,0 @@ -/* SAXSerializer.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import org.w3c.dom.Attr; -import org.w3c.dom.DocumentType; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; - -/** - * Serializes a DOM node to a sequence of SAX events. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class SAXSerializer - implements Attributes -{ - - transient NamedNodeMap attrs; - transient LinkedList namespaces = new LinkedList(); - - boolean isDefined(String prefix, String uri) - { - for (Iterator i = namespaces.iterator(); i.hasNext(); ) - { - HashMap ctx = (HashMap) i.next(); - if (uri.equals(ctx.get(prefix))) - { - return true; - } - } - return false; - } - - void define(String prefix, String uri) - { - for (Iterator i = namespaces.iterator(); i.hasNext(); ) - { - HashMap ctx = (HashMap) i.next(); - if (ctx.containsKey(prefix)) - { - HashMap newCtx = new HashMap(); - newCtx.put(prefix, uri); - namespaces.addFirst(newCtx); - return; - } - } - HashMap ctx; - if (namespaces.isEmpty()) - { - ctx = new HashMap(); - namespaces.add(ctx); - } - else - { - ctx = (HashMap) namespaces.getFirst(); - } - ctx.put(prefix, uri); - } - - void undefine(String prefix, String uri) - { - for (Iterator i = namespaces.iterator(); i.hasNext(); ) - { - HashMap ctx = (HashMap) i.next(); - if (uri.equals(ctx.get(prefix))) - { - ctx.remove(prefix); - if (ctx.isEmpty()) - { - namespaces.remove(ctx); - } - return; - } - } - } - - public int getLength() - { - return attrs.getLength(); - } - - public String getURI(int index) - { - return attrs.item(index).getNamespaceURI(); - } - - public String getLocalName(int index) - { - return attrs.item(index).getLocalName(); - } - - public String getQName(int index) - { - return attrs.item(index).getNodeName(); - } - - public String getType(int index) - { - Attr attr = (Attr) attrs.item(index); - return attr.isId() ? "ID" : "CDATA"; - } - - public String getValue(int index) - { - return attrs.item(index).getNodeValue(); - } - - public int getIndex(String uri, String localName) - { - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String a_uri = attr.getNamespaceURI(); - String a_localName = attr.getLocalName(); - if (((a_uri == null && uri == null) || - (a_uri != null && a_uri.equals(uri))) && - a_localName.equals(localName)) - { - return i; - } - } - return -1; - } - - public int getIndex(String qName) - { - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String a_name = attr.getNodeName(); - if (a_name.equals(qName)) - { - return i; - } - } - return -1; - } - - public String getType(String uri, String localName) - { - Attr attr = (Attr) attrs.getNamedItemNS(uri, localName); - return attr.isId() ? "ID" : "CDATA"; - } - - public String getType(String qName) - { - Attr attr = (Attr) attrs.getNamedItem(qName); - return attr.isId() ? "ID" : "CDATA"; - } - - public String getValue(String uri, String localName) - { - return attrs.getNamedItemNS(uri, localName).getNodeValue(); - } - - public String getValue(String qName) - { - return attrs.getNamedItem(qName).getNodeValue(); - } - - void serialize(Node node, ContentHandler ch, LexicalHandler lh) - throws SAXException - { - attrs = node.getAttributes(); - Node children; - Node next = node.getNextSibling(); - switch (node.getNodeType()) - { - case Node.ELEMENT_NODE: - String uri = node.getNamespaceURI(); - String prefix = node.getPrefix(); - boolean defined = isDefined(prefix, uri); - if (!defined) - { - define(prefix, uri); - ch.startPrefixMapping(prefix, uri); - } - String localName = node.getLocalName(); - String qName = node.getNodeName(); - ch.startElement(uri, localName, qName, this); - children = node.getFirstChild(); - if (children != null) - { - serialize(children, ch, lh); - } - ch.endElement(uri, localName, qName); - if (!defined) - { - ch.endPrefixMapping(prefix); - undefine(prefix, uri); - } - break; - case Node.TEXT_NODE: - char[] chars = node.getNodeValue().toCharArray(); - ch.characters(chars, 0, chars.length); - break; - case Node.CDATA_SECTION_NODE: - char[] cdata = node.getNodeValue().toCharArray(); - if (lh != null) - { - lh.startCDATA(); - ch.characters(cdata, 0, cdata.length); - lh.endCDATA(); - } - else - { - ch.characters(cdata, 0, cdata.length); - } - break; - case Node.COMMENT_NODE: - if (lh != null) - { - char[] comment = node.getNodeValue().toCharArray(); - lh.comment(comment, 0, comment.length); - } - break; - case Node.DOCUMENT_NODE: - case Node.DOCUMENT_FRAGMENT_NODE: - ch.startDocument(); - children = node.getFirstChild(); - if (children != null) - { - serialize(children, ch, lh); - } - ch.endDocument(); - break; - case Node.DOCUMENT_TYPE_NODE: - if (lh != null) - { - DocumentType doctype = (DocumentType) node; - String publicId = doctype.getPublicId(); - String systemId = doctype.getSystemId(); - lh.startDTD(node.getNodeName(), publicId, systemId); - NamedNodeMap entities = doctype.getEntities(); - int len = entities.getLength(); - for (int i = 0; i < len; i++) - { - Node entity = entities.item(i); - String entityName = entity.getNodeName(); - lh.startEntity(entityName); - lh.endEntity(entityName); - } - lh.endDTD(); - } - break; - case Node.PROCESSING_INSTRUCTION_NODE: - ch.processingInstruction(node.getNodeName(), node.getNodeValue()); - break; - case Node.ENTITY_REFERENCE_NODE: - ch.skippedEntity(node.getNodeName()); - break; - } - attrs = null; - if (next != null) - { - serialize(next, ch, lh); - } - } - -} diff --git a/libjava/gnu/xml/transform/SortKey.java b/libjava/gnu/xml/transform/SortKey.java deleted file mode 100644 index 1ec9bdd57b9..00000000000 --- a/libjava/gnu/xml/transform/SortKey.java +++ /dev/null @@ -1,154 +0,0 @@ -/* SortKey.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * An XSL sort key. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SortKey -{ - - static final int DEFAULT = 0; - static final int UPPER_FIRST = 1; - static final int LOWER_FIRST = 2; - - final Expr select; - final TemplateNode langTemplate; - final TemplateNode dataTypeTemplate; - final TemplateNode orderTemplate; - final TemplateNode caseOrderTemplate; - - transient String lang; - transient String dataType; - transient boolean descending; - transient int caseOrder; - - SortKey(Expr select, TemplateNode lang, TemplateNode dataType, - TemplateNode order, TemplateNode caseOrder) - { - this.select = select; - this.langTemplate = lang; - this.dataTypeTemplate = dataType; - this.orderTemplate = order; - this.caseOrderTemplate = caseOrder; - } - - String key(Node node) - { - Object ret = select.evaluate(node, 1, 1); - if (ret instanceof String) - { - return (String) ret; - } - else - { - return Expr._string(node, ret); - } - } - - /** - * Prepare for a sort. - * This sets all transient variables from their AVTs. - */ - void init(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - if (langTemplate == null) - { - lang = null; - } - else - { - DocumentFragment fragment = doc.createDocumentFragment(); - langTemplate.apply(stylesheet, mode, context, pos, len, - fragment, null); - lang = Expr.stringValue(fragment); - } - if (dataTypeTemplate == null) - { - dataType = "text"; - } - else - { - DocumentFragment fragment = doc.createDocumentFragment(); - dataTypeTemplate.apply(stylesheet, mode, context, pos, len, - fragment, null); - dataType = Expr.stringValue(fragment); - } - if (orderTemplate == null) - { - descending = false; - } - else - { - DocumentFragment fragment = doc.createDocumentFragment(); - orderTemplate.apply(stylesheet, mode, context, pos, len, - fragment, null); - String order = Expr.stringValue(fragment); - descending = "descending".equals(order); - } - if (caseOrderTemplate == null) - { - caseOrder = DEFAULT; - } - else - { - DocumentFragment fragment = doc.createDocumentFragment(); - caseOrderTemplate.apply(stylesheet, mode, context, pos, len, - fragment, null); - String co = Expr.stringValue(fragment); - caseOrder = "upper-first".equals(co) ? UPPER_FIRST : - "lower-first".equals(co) ? LOWER_FIRST : - DEFAULT; - } - } - -} diff --git a/libjava/gnu/xml/transform/StreamSerializer.java b/libjava/gnu/xml/transform/StreamSerializer.java deleted file mode 100644 index 80a1f7016a5..00000000000 --- a/libjava/gnu/xml/transform/StreamSerializer.java +++ /dev/null @@ -1,632 +0,0 @@ -/* StreamSerializer.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import javax.xml.XMLConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * Serializes a DOM node to an output stream. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class StreamSerializer -{ - - static final int SPACE = 0x20; - static final int BANG = 0x21; // ! - static final int APOS = 0x27; // ' - static final int SLASH = 0x2f; // / - static final int BRA = 0x3c; // < - static final int KET = 0x3e; // > - static final int EQ = 0x3d; // = - - protected String encoding; - boolean compatibilityMode; - final int mode; - final Map namespaces; - protected String eol; - Collection cdataSectionElements = Collections.EMPTY_SET; - - protected boolean discardDefaultContent; - protected boolean xmlDeclaration = true; - - public StreamSerializer() - { - this(Stylesheet.OUTPUT_XML, null, null); - } - - public StreamSerializer(String encoding) - { - this(Stylesheet.OUTPUT_XML, encoding, null); - } - - public StreamSerializer(int mode, String encoding, String eol) - { - this.mode = mode; - if (encoding == null) - { - encoding = "UTF-8"; - } - this.encoding = encoding.intern(); - compatibilityMode = true; - if (encoding.length() > 3) - { - String p = encoding.substring(0, 3); - if (p.equalsIgnoreCase("UTF") || - p.equalsIgnoreCase("UCS")) - { - compatibilityMode = false; - } - } - this.eol = (eol != null) ? eol : System.getProperty("line.separator"); - namespaces = new HashMap(); - } - - void setCdataSectionElements(Collection c) - { - cdataSectionElements = c; - } - - public void serialize(final Node node, final OutputStream out) - throws IOException - { - serialize(node, out, false); - } - - void serialize(final Node node, final OutputStream out, - boolean convertToCdata) - throws IOException - { - if (out == null) - { - throw new NullPointerException("no output stream"); - } - String value, prefix; - Node children; - Node next = node.getNextSibling(); - String uri = node.getNamespaceURI(); - boolean defined = false; - short nt = node.getNodeType(); - if (convertToCdata && nt == Node.TEXT_NODE) - { - nt = Node.CDATA_SECTION_NODE; - } - switch (nt) - { - case Node.ATTRIBUTE_NODE: - prefix = node.getPrefix(); - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || - XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || - (prefix != null && prefix.startsWith("xmlns:"))) - { - String nsuri = node.getNodeValue(); - if (isDefined(nsuri)) - { - break; - } - define(nsuri, node.getLocalName()); - } - else if (uri != null && !isDefined(uri)) - { - prefix = define(uri, prefix); - String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; - out.write(SPACE); - out.write(encodeText(nsname)); - out.write(EQ); - String nsvalue = "'" + encode(uri, true, true) + "'"; - out.write(nsvalue.getBytes(encoding)); - defined = true; - } - out.write(SPACE); - String a_nodeName = node.getNodeName(); - out.write(encodeText(a_nodeName)); - String a_nodeValue = node.getNodeValue(); - if (mode == Stylesheet.OUTPUT_HTML && - a_nodeName.equals(a_nodeValue)) - { - break; - } - out.write(EQ); - value = "'" + encode(a_nodeValue, true, true) + "'"; - out.write(encodeText(value)); - break; - case Node.ELEMENT_NODE: - value = node.getNodeName(); - out.write(BRA); - out.write(encodeText(value)); - if (uri != null && !isDefined(uri)) - { - prefix = define(uri, node.getPrefix()); - String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; - out.write(SPACE); - out.write(encodeText(nsname)); - out.write(EQ); - String nsvalue = "'" + encode(uri, true, true) + "'"; - out.write(encodeText(nsvalue)); - defined = true; - } - NamedNodeMap attrs = node.getAttributes(); - if (attrs != null) - { - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Attr attr = (Attr) attrs.item(i); - if (discardDefaultContent && !attr.getSpecified()) - { - // NOOP - } - else - { - serialize(attr, out, false); - } - } - } - convertToCdata = cdataSectionElements.contains(value); - children = node.getFirstChild(); - if (children == null) - { - out.write(SLASH); - out.write(KET); - } - else - { - out.write(KET); - serialize(children, out, convertToCdata); - out.write(BRA); - out.write(SLASH); - out.write(encodeText(value)); - out.write(KET); - } - break; - case Node.TEXT_NODE: - value = node.getNodeValue(); - if (!"yes".equals(node.getUserData("disable-output-escaping"))) - { - value = encode(value, false, false); - } - out.write(encodeText(value)); - break; - case Node.CDATA_SECTION_NODE: - value = "<![CDATA[" + node.getNodeValue() + "]]>"; - out.write(encodeText(value)); - break; - case Node.COMMENT_NODE: - value = "<!--" + node.getNodeValue() + "-->"; - out.write(encodeText(value)); - Node cp = node.getParentNode(); - if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) - { - out.write(encodeText(eol)); - } - break; - case Node.DOCUMENT_NODE: - case Node.DOCUMENT_FRAGMENT_NODE: - if (mode == Stylesheet.OUTPUT_XML) - { - if ("UTF-16".equalsIgnoreCase(encoding)) - { - out.write(0xfe); - out.write(0xff); - } - if (!"yes".equals(node.getUserData("omit-xml-declaration")) && - xmlDeclaration) - { - Document doc = (node instanceof Document) ? - (Document) node : null; - String version = (doc != null) ? doc.getXmlVersion() : null; - if (version == null) - { - version = (String) node.getUserData("version"); - } - if (version == null) - { - version = "1.0"; - } - out.write(BRA); - out.write(0x3f); - out.write("xml version='".getBytes("US-ASCII")); - out.write(version.getBytes("US-ASCII")); - out.write(APOS); - if (!("UTF-8".equalsIgnoreCase(encoding))) - { - out.write(" encoding='".getBytes("US-ASCII")); - out.write(encoding.getBytes("US-ASCII")); - out.write(APOS); - } - if ((doc != null && doc.getXmlStandalone()) || - "yes".equals(node.getUserData("standalone"))) - { - out.write(" standalone='yes'".getBytes("US-ASCII")); - } - out.write(0x3f); - out.write(KET); - out.write(encodeText(eol)); - } - // TODO warn if not outputting the declaration would be a - // problem - } - else if (mode == Stylesheet.OUTPUT_HTML) - { - // Ensure that encoding is accessible - String mediaType = (String) node.getUserData("media-type"); - if (mediaType == null) - { - mediaType = "text/html"; - } - String contentType = mediaType + "; charset=" + - ((encoding.indexOf(' ') != -1) ? - "\"" + encoding + "\"" : - encoding); - Document doc = (node instanceof Document) ? (Document) node : - node.getOwnerDocument(); - Node html = null; - for (Node ctx = node.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx.getNodeType() == Node.ELEMENT_NODE) - { - html = ctx; - break; - } - } - if (html == null) - { - html = doc.createElement("html"); - node.appendChild(html); - } - Node head = null; - for (Node ctx = html.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx.getNodeType() == Node.ELEMENT_NODE && - "head".equalsIgnoreCase(ctx.getLocalName())) - { - head = ctx; - break; - } - } - if (head == null) - { - head = doc.createElement("head"); - Node c1 = null; - for (Node ctx = html.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx.getNodeType() == Node.ELEMENT_NODE) - { - c1 = ctx; - break; - } - } - if (c1 != null) - { - html.insertBefore(head, c1); - } - else - { - html.appendChild(head); - } - } - Node meta = null; - Node metaContent = null; - for (Node ctx = head.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - if (ctx.getNodeType() == Node.ELEMENT_NODE && - "meta".equalsIgnoreCase(ctx.getLocalName())) - { - NamedNodeMap metaAttrs = ctx.getAttributes(); - int len = metaAttrs.getLength(); - String httpEquiv = null; - Node content = null; - for (int i = 0; i < len; i++) - { - Node attr = metaAttrs.item(i); - String attrName = attr.getNodeName(); - if ("http-equiv".equalsIgnoreCase(attrName)) - { - httpEquiv = attr.getNodeValue(); - } - else if ("content".equalsIgnoreCase(attrName)) - { - content = attr; - } - } - if ("Content-Type".equalsIgnoreCase(httpEquiv)) - { - meta = ctx; - metaContent = content; - break; - } - } - } - if (meta == null) - { - meta = doc.createElement("meta"); - // Insert first - Node first = head.getFirstChild(); - if (first == null) - { - head.appendChild(meta); - } - else - { - head.insertBefore(meta, first); - } - Node metaHttpEquiv = doc.createAttribute("http-equiv"); - meta.getAttributes().setNamedItem(metaHttpEquiv); - metaHttpEquiv.setNodeValue("Content-Type"); - } - if (metaContent == null) - { - metaContent = doc.createAttribute("content"); - meta.getAttributes().setNamedItem(metaContent); - } - metaContent.setNodeValue(contentType); - // phew - } - children = node.getFirstChild(); - if (children != null) - { - serialize(children, out, convertToCdata); - } - break; - case Node.DOCUMENT_TYPE_NODE: - DocumentType doctype = (DocumentType) node; - out.write(BRA); - out.write(BANG); - value = doctype.getNodeName(); - out.write(encodeText(value)); - String publicId = doctype.getPublicId(); - if (publicId != null) - { - out.write(encodeText(" PUBLIC ")); - out.write(APOS); - out.write(encodeText(publicId)); - out.write(APOS); - } - String systemId = doctype.getSystemId(); - if (systemId != null) - { - out.write(encodeText(" SYSTEM ")); - out.write(APOS); - out.write(encodeText(systemId)); - out.write(APOS); - } - String internalSubset = doctype.getInternalSubset(); - if (internalSubset != null) - { - out.write(encodeText(internalSubset)); - } - out.write(KET); - out.write(eol.getBytes(encoding)); - break; - case Node.ENTITY_REFERENCE_NODE: - value = "&" + node.getNodeValue() + ";"; - out.write(encodeText(value)); - break; - case Node.PROCESSING_INSTRUCTION_NODE: - value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; - out.write(encodeText(value)); - Node pp = node.getParentNode(); - if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) - { - out.write(encodeText(eol)); - } - break; - } - if (defined) - { - undefine(uri); - } - if (next != null) - { - serialize(next, out, convertToCdata); - } - } - - boolean isDefined(String uri) - { - return XMLConstants.XML_NS_URI.equals(uri) || - XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || - namespaces.containsKey(uri); - } - - String define(String uri, String prefix) - { - while (namespaces.containsValue(prefix)) - { - // Fabricate new prefix - prefix = prefix + "_"; - } - namespaces.put(uri, prefix); - return prefix; - } - - void undefine(String uri) - { - namespaces.remove(uri); - } - - final byte[] encodeText(String text) - throws UnsupportedEncodingException - { - if (compatibilityMode) - { - int len = text.length(); - StringBuffer buf = null; - for (int i = 0; i < len; i++) - { - char c = text.charAt(i); - if (c >= 127) - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append('&'); - buf.append('#'); - buf.append((int) c); - buf.append(';'); - } - else if (buf != null) - { - buf.append(c); - } - } - if (buf != null) - { - text = buf.toString(); - } - } - return text.getBytes(encoding); - } - - String encode(String text, boolean encodeCtl, boolean inAttr) - { - int len = text.length(); - StringBuffer buf = null; - for (int i = 0; i < len; i++) - { - char c = text.charAt(i); - if (c == '<') - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append("<"); - } - else if (c == '>') - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append(">"); - } - else if (c == '&') - { - if (mode == Stylesheet.OUTPUT_HTML && (i + 1) < len && - text.charAt(i + 1) == '{') - { - if (buf != null) - { - buf.append(c); - } - } - else - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append("&"); - } - } - else if (c == '\'' && inAttr) - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append("'"); - } - else if (c == '"' && inAttr) - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append("""); - } - else if (encodeCtl) - { - if (c < 0x20) - { - if (buf == null) - { - buf = new StringBuffer(text.substring(0, i)); - } - buf.append('&'); - buf.append('#'); - buf.append((int) c); - buf.append(';'); - } - else if (buf != null) - { - buf.append(c); - } - } - else if (buf != null) - { - buf.append(c); - } - } - return (buf == null) ? text : buf.toString(); - } - - String toString(Node node) - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try - { - serialize(node, out); - return new String(out.toByteArray(), encoding); - } - catch (IOException e) - { - throw new RuntimeException(e.getMessage()); - } - } - -} diff --git a/libjava/gnu/xml/transform/Stylesheet.java b/libjava/gnu/xml/transform/Stylesheet.java deleted file mode 100644 index 5efd5ca3e3e..00000000000 --- a/libjava/gnu/xml/transform/Stylesheet.java +++ /dev/null @@ -1,1728 +0,0 @@ -/* Stylesheet.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeSet; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionResolver; -import javax.xml.xpath.XPathExpressionException; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import org.w3c.dom.UserDataHandler; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.NameTest; -import gnu.xml.xpath.NodeTypeTest; -import gnu.xml.xpath.Pattern; -import gnu.xml.xpath.Selector; -import gnu.xml.xpath.Root; -import gnu.xml.xpath.Test; -import gnu.xml.xpath.XPathImpl; - -/** - * An XSL stylesheet. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class Stylesheet - implements NamespaceContext, XPathFunctionResolver, UserDataHandler, Cloneable -{ - - static final String XSL_NS = "http://www.w3.org/1999/XSL/Transform"; - - static final int OUTPUT_XML = 0; - static final int OUTPUT_HTML = 1; - static final int OUTPUT_TEXT = 2; - - final TransformerFactoryImpl factory; - TransformerImpl transformer; - Stylesheet parent; - final XPathImpl xpath; - final String systemId; - final int precedence; - - final boolean debug; - - /** - * Version of XSLT. - */ - String version; - - Collection extensionElementPrefixes; - Collection excludeResultPrefixes; - - /** - * Set of element names for which we should strip whitespace. - */ - Set stripSpace; - - /** - * Set of element names for which we should preserve whitespace. - */ - Set preserveSpace; - - /** - * Output options. - */ - int outputMethod; - String outputVersion; - String outputEncoding; - boolean outputOmitXmlDeclaration; - boolean outputStandalone; - String outputPublicId; - String outputSystemId; - Collection outputCdataSectionElements; - boolean outputIndent; - String outputMediaType; - - /** - * Keys. - */ - Collection keys; - - /** - * Decimal formats. - */ - Map decimalFormats; - - /** - * Namespace aliases. - */ - Map namespaceAliases; - - /** - * Attribute-sets. - */ - List attributeSets; - - /** - * Variables. - */ - List variables; - - /** - * Variable and parameter bindings. - */ - Bindings bindings; - - /** - * Templates. - */ - LinkedList templates; - - TemplateNode builtInNodeTemplate; - TemplateNode builtInTextTemplate; - - /** - * Holds the current node while parsing. - * Necessary to associate the document function with its declaring node, - * to resolve namespaces, and to maintain the current node for the - * current() function. - */ - Node current; - - /** - * Set by a terminating message. - */ - transient boolean terminated; - - /** - * Current template in force. - */ - transient Template currentTemplate; - - Stylesheet(TransformerFactoryImpl factory, - Stylesheet parent, - Document doc, - String systemId, - int precedence) - throws TransformerConfigurationException - { - this.factory = factory; - this.systemId = systemId; - this.precedence = precedence; - this.parent = parent; - extensionElementPrefixes = new HashSet(); - excludeResultPrefixes = new HashSet(); - stripSpace = new LinkedHashSet(); - preserveSpace = new LinkedHashSet(); - outputCdataSectionElements = new LinkedHashSet(); - xpath = (XPathImpl) factory.xpathFactory.newXPath(); - if (parent == null) - { - bindings = new Bindings(this); - attributeSets = new LinkedList(); - variables = new LinkedList(); - namespaceAliases = new LinkedHashMap(); - templates = new LinkedList(); - keys = new LinkedList(); - decimalFormats = new LinkedHashMap(); - initDefaultDecimalFormat(); - xpath.setNamespaceContext(this); - xpath.setXPathFunctionResolver(this); - } - else - { - /* Test for import circularity */ - for (Stylesheet ctx = this; ctx.parent != null; ctx = ctx.parent) - { - if (systemId != null && systemId.equals(ctx.parent.systemId)) - { - String msg = "circularity importing " + systemId; - throw new TransformerConfigurationException(msg); - } - } - /* OK */ - Stylesheet root = getRootStylesheet(); - bindings = root.bindings; - attributeSets = root.attributeSets; - variables = root.variables; - namespaceAliases = root.namespaceAliases; - templates = root.templates; - keys = root.keys; - decimalFormats = root.decimalFormats; - xpath.setNamespaceContext(root); - xpath.setXPathFunctionResolver(root); - } - xpath.setXPathVariableResolver(bindings); - - Test anyNode = new NodeTypeTest((short) 0); - List tests = Collections.singletonList(anyNode); - builtInNodeTemplate = - new ApplyTemplatesNode(null, null, - new Selector(Selector.CHILD, tests), - null, null, null, true); - builtInTextTemplate = - new ValueOfNode(null, null, - new Selector(Selector.SELF, tests), - false); - - parse(doc.getDocumentElement(), true); - current = doc; // Alow namespace resolution during processing - - debug = ("yes".equals(System.getProperty("xsl.debug"))); - - if (debug) - { - System.err.println("Stylesheet: " + doc.getDocumentURI()); - for (Iterator i = templates.iterator(); i.hasNext(); ) - { - Template t = (Template) i.next(); - t.list(System.err); - System.err.println("--------------------"); - } - } - } - - Stylesheet getRootStylesheet() - { - Stylesheet stylesheet = this; - while (stylesheet.parent != null) - { - stylesheet = stylesheet.parent; - } - return stylesheet; - } - - void initDefaultDecimalFormat() - { - DecimalFormat defaultDecimalFormat = new DecimalFormat(); - DecimalFormatSymbols symbols = new DecimalFormatSymbols(); - symbols.setDecimalSeparator('.'); - symbols.setGroupingSeparator(','); - symbols.setPercent('%'); - symbols.setPerMill('\u2030'); - symbols.setZeroDigit('0'); - symbols.setDigit('#'); - symbols.setPatternSeparator(';'); - symbols.setInfinity("Infinity"); - symbols.setNaN("NaN"); - symbols.setMinusSign('-'); - defaultDecimalFormat.setDecimalFormatSymbols(symbols); - decimalFormats.put(null, defaultDecimalFormat); - } - - // -- Cloneable -- - - public Object clone() - { - try - { - Stylesheet clone = (Stylesheet) super.clone(); - clone.bindings = (Bindings) bindings.clone(); - - LinkedList templates2 = new LinkedList(); - for (Iterator i = templates.iterator(); i.hasNext(); ) - { - Template t = (Template) i.next(); - templates2.add(t.clone(clone)); - } - clone.templates = templates2; - - LinkedList attributeSets2 = new LinkedList(); - for (Iterator i = attributeSets.iterator(); i.hasNext(); ) - { - AttributeSet as = (AttributeSet) i.next(); - attributeSets2.add(as.clone(clone)); - } - clone.attributeSets = attributeSets2; - - LinkedList variables2 = new LinkedList(); - for (Iterator i = variables.iterator(); i.hasNext(); ) - { - ParameterNode var = (ParameterNode) i.next(); - variables2.add(var.clone(clone)); - } - clone.variables = variables2; - - LinkedList keys2 = new LinkedList(); - for (Iterator i = keys.iterator(); i.hasNext(); ) - { - Key k = (Key) i.next(); - keys2.add(k.clone(clone)); - } - clone.keys = keys2; - - return clone; - } - catch (CloneNotSupportedException e) - { - throw new Error(e.getMessage()); - } - } - - // -- Variable evaluation -- - - void initTopLevelVariables(Node context) - throws TransformerException - { - for (Iterator i = variables.iterator(); i.hasNext(); ) - { - ParameterNode var = (ParameterNode) i.next(); - bindings.set(var.name, - var.getValue(this, null, context, 1, 1), - var.global); - } - } - - // -- NamespaceContext -- - - public String getNamespaceURI(String prefix) - { - return (current == null) ? null : current.lookupNamespaceURI(prefix); - } - - public String getPrefix(String namespaceURI) - { - return (current == null) ? null : current.lookupPrefix(namespaceURI); - } - - public Iterator getPrefixes(String namespaceURI) - { - // TODO - return Collections.singleton(getPrefix(namespaceURI)).iterator(); - } - - // -- Template selection -- - - TemplateNode getTemplate(QName mode, Node context, boolean applyImports) - throws TransformerException - { - //System.err.println("getTemplate: mode="+mode+" context="+context); - Set candidates = new TreeSet(); - for (Iterator j = templates.iterator(); j.hasNext(); ) - { - Template t = (Template) j.next(); - boolean isMatch = t.matches(mode, context); - if (applyImports) - { - if (currentTemplate == null) - { - String msg = "current template may not be null " + - "during apply-imports"; - throw new TransformerException(msg); - } - if (!currentTemplate.imports(t)) - { - isMatch = false; - } - } - //System.err.println("\t"+context+" "+t+"="+isMatch); - if (isMatch) - { - candidates.add(t); - } - } - //System.err.println("\tcandidates="+candidates); - if (candidates.isEmpty()) - { - // Apply built-in template - // Current template is unchanged - //System.err.println("\tbuiltInTemplate context="+context); - switch (context.getNodeType()) - { - case Node.ELEMENT_NODE: - case Node.DOCUMENT_NODE: - case Node.DOCUMENT_FRAGMENT_NODE: - case Node.PROCESSING_INSTRUCTION_NODE: - case Node.COMMENT_NODE: - return builtInNodeTemplate; - case Node.TEXT_NODE: - case Node.ATTRIBUTE_NODE: - return builtInTextTemplate; - default: - return null; - } - } - else - { - Template t = (Template) candidates.iterator().next(); - // Set current template - currentTemplate = t; - //System.err.println("\ttemplate="+t+" context="+context); - return t.node; - } - } - - TemplateNode getTemplate(QName mode, QName name) - throws TransformerException - { - //System.err.println("getTemplate: mode="+mode+" name="+name); - Set candidates = new TreeSet(); - for (Iterator j = templates.iterator(); j.hasNext(); ) - { - Template t = (Template) j.next(); - boolean isMatch = t.matches(name); - //System.err.println("\t"+name+" "+t+"="+isMatch); - if (isMatch) - { - candidates.add(t); - } - } - if (candidates.isEmpty()) - { - return null; - //throw new TransformerException("template '" + name + "' not found"); - } - Template t = (Template) candidates.iterator().next(); - //System.err.println("\ttemplate="+t+" context="+context); - return t.node; - } - - /** - * template - */ - final Template parseTemplate(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException, XPathExpressionException - { - String n = getAttribute(attrs, "name"); - QName name = (n == null) ? null : getQName(n); - String m = getAttribute(attrs, "match"); - Pattern match = null; - if (m != null) - { - try - { - match = (Pattern) xpath.compile(m); - } - catch (ClassCastException e) - { - String msg = "illegal pattern: " + m; - throw new TransformerConfigurationException(msg); - } - } - String p = getAttribute(attrs, "priority"); - String mm = getAttribute(attrs, "mode"); - QName mode = (mm == null) ? null : getQName(mm); - double priority = (p == null) ? Template.DEFAULT_PRIORITY : - Double.parseDouble(p); - return new Template(this, name, match, parse(node.getFirstChild()), - precedence, priority, mode); - } - - /** - * output - */ - final void parseOutput(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException - { - String method = getAttribute(attrs, "method"); - if ("xml".equals(method) || method == null) - { - outputMethod = OUTPUT_XML; - } - else if ("html".equals(method)) - { - outputMethod = OUTPUT_HTML; - } - else if ("text".equals(method)) - { - outputMethod = OUTPUT_TEXT; - } - else - { - String msg = "unsupported output method: " + method; - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(msg, l); - } - outputPublicId = getAttribute(attrs, "public-id"); - outputSystemId = getAttribute(attrs, "system-id"); - outputEncoding = getAttribute(attrs, "encoding"); - String indent = getAttribute(attrs, "indent"); - if (indent != null) - { - outputIndent = "yes".equals(indent); - } - outputVersion = getAttribute(attrs, "version"); - String omitXmlDecl = getAttribute(attrs, "omit-xml-declaration"); - if (omitXmlDecl != null) - { - outputOmitXmlDeclaration = "yes".equals(omitXmlDecl); - } - String standalone = getAttribute(attrs, "standalone"); - if (standalone != null) - { - outputStandalone = "yes".equals(standalone); - } - outputMediaType = getAttribute(attrs, "media-type"); - String cdataSectionElements = - getAttribute(attrs, "cdata-section-elements"); - if (cdataSectionElements != null) - { - StringTokenizer st = new StringTokenizer(cdataSectionElements, " "); - while (st.hasMoreTokens()) - { - outputCdataSectionElements.add(st.nextToken()); - } - } - } - - /** - * key - */ - final void parseKey(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException, XPathExpressionException - { - String n = getRequiredAttribute(attrs, "name", node); - String m = getRequiredAttribute(attrs, "match", node); - String u = getRequiredAttribute(attrs, "use", node); - QName name = getQName(n); - Expr use = (Expr) xpath.compile(u); - try - { - Pattern match = (Pattern) xpath.compile(m); - Key key = new Key(name, match, use); - keys.add(key); - } - catch (ClassCastException e) - { - throw new TransformerConfigurationException("invalid pattern: " + m); - } - } - - /** - * decimal-format - */ - final void parseDecimalFormat(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException - { - String dfName = getAttribute(attrs, "name"); - DecimalFormat df = new DecimalFormat(); - DecimalFormatSymbols symbols = new DecimalFormatSymbols(); - symbols.setDecimalSeparator(parseDFChar(attrs, "decimal-separator", '.')); - symbols.setGroupingSeparator(parseDFChar(attrs, "grouping-separator", ',')); - symbols.setInfinity(parseDFString(attrs, "infinity", "Infinity")); - symbols.setMinusSign(parseDFChar(attrs, "minus-sign", '-')); - symbols.setNaN(parseDFString(attrs, "NaN", "NaN")); - symbols.setPercent(parseDFChar(attrs, "percent", '%')); - symbols.setPerMill(parseDFChar(attrs, "per-mille", '\u2030')); - symbols.setZeroDigit(parseDFChar(attrs, "zero-digit", '0')); - symbols.setDigit(parseDFChar(attrs, "digit", '#')); - symbols.setPatternSeparator(parseDFChar(attrs, "pattern-separator", ';')); - df.setDecimalFormatSymbols(symbols); - decimalFormats.put(dfName, df); - } - - private final char parseDFChar(NamedNodeMap attrs, String name, char def) - throws TransformerConfigurationException - { - Node attr = attrs.getNamedItem(name); - try - { - return (attr == null) ? def : attr.getNodeValue().charAt(0); - } - catch (StringIndexOutOfBoundsException e) - { - throw new TransformerConfigurationException("empty attribute '" + - name + - "' in decimal-format", e); - } - } - - private final String parseDFString(NamedNodeMap attrs, String name, - String def) - { - Node attr = attrs.getNamedItem(name); - return (attr == null) ? def : attr.getNodeValue(); - } - - /** - * namespace-alias - */ - final void parseNamespaceAlias(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException - { - String sp = getRequiredAttribute(attrs, "stylesheet-prefix", node); - String rp = getRequiredAttribute(attrs, "result-prefix", node); - namespaceAliases.put(sp, rp); - } - - /** - * attribute-set - */ - final void parseAttributeSet(Node node, NamedNodeMap attrs) - throws TransformerConfigurationException, XPathExpressionException - { - TemplateNode children = parse(node.getFirstChild()); - String name = getRequiredAttribute(attrs, "name", node); - String uas = getAttribute(attrs, "use-attribute-sets"); - attributeSets.add(new AttributeSet(children, name, uas)); - } - - /** - * Parse top-level elements. - */ - void parse(Node node, boolean root) - throws TransformerConfigurationException - { - if (node == null) - { - return; - } - current = node; - try - { - String namespaceUri = node.getNamespaceURI(); - if (XSL_NS.equals(namespaceUri) && - node.getNodeType() == Node.ELEMENT_NODE) - { - String name = node.getLocalName(); - NamedNodeMap attrs = node.getAttributes(); - if ("stylesheet".equals(name)) - { - version = getAttribute(attrs, "version"); - String eep = getAttribute(attrs, "extension-element-prefixes"); - if (eep != null) - { - StringTokenizer st = new StringTokenizer(eep); - while (st.hasMoreTokens()) - { - extensionElementPrefixes.add(st.nextToken()); - } - } - String erp = getAttribute(attrs, "exclude-result-prefixes"); - if (erp != null) - { - StringTokenizer st = new StringTokenizer(erp); - while (st.hasMoreTokens()) - { - excludeResultPrefixes.add(st.nextToken()); - } - } - parse(node.getFirstChild(), false); - return; - } - else if ("template".equals(name)) - { - templates.addFirst(parseTemplate(node, attrs)); - } - else if ("param".equals(name) || - "variable".equals(name)) - { - boolean global = "variable".equals(name); - TemplateNode content = parse(node.getFirstChild()); - String paramName = getRequiredAttribute(attrs, "name", node); - String select = getAttribute(attrs, "select"); - if (select != null && select.length() > 0) - { - if (content != null) - { - String msg = "parameter '" + paramName + - "' has both select and content"; - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(msg, l); - } - Expr expr = (Expr) xpath.compile(select); - variables.add(new ParameterNode(null, null, - paramName, - expr, global)); - } - else - { - variables.add(new ParameterNode(content, null, - paramName, - null, global)); - } - bindings.set(paramName, content, global); - } - else if ("include".equals(name) || "import".equals(name)) - { - int delta = "import".equals(name) ? -1 : 0; - String href = getRequiredAttribute(attrs, "href", node); - Source source; - synchronized (factory.resolver) - { - if (transformer != null) - { - factory.resolver - .setUserResolver(transformer.getURIResolver()); - factory.resolver - .setUserListener(transformer.getErrorListener()); - } - source = factory.resolver.resolve(systemId, href); - } - factory.newStylesheet(source, precedence + delta, this); - } - else if ("output".equals(name)) - { - parseOutput(node, attrs); - } - else if ("preserve-space".equals(name)) - { - String elements = - getRequiredAttribute(attrs, "elements", node); - StringTokenizer st = new StringTokenizer(elements, - " \t\n\r"); - while (st.hasMoreTokens()) - { - preserveSpace.add(parseNameTest(st.nextToken())); - } - } - else if ("strip-space".equals(name)) - { - String elements = - getRequiredAttribute(attrs, "elements", node); - StringTokenizer st = new StringTokenizer(elements, - " \t\n\r"); - while (st.hasMoreTokens()) - { - stripSpace.add(parseNameTest(st.nextToken())); - } - } - else if ("key".equals(name)) - { - parseKey(node, attrs); - } - else if ("decimal-format".equals(name)) - { - parseDecimalFormat(node, attrs); - } - else if ("namespace-alias".equals(name)) - { - parseNamespaceAlias(node, attrs); - } - else if ("attribute-set".equals(name)) - { - parseAttributeSet(node, attrs); - } - parse(node.getNextSibling(), false); - } - else if (root) - { - // Literal document element - Attr versionNode = - ((Element)node).getAttributeNodeNS(XSL_NS, "version"); - if (versionNode == null) - { - String msg = "no xsl:version attribute on literal result node"; - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(msg, l); - } - version = versionNode.getValue(); - Node rootClone = node.cloneNode(true); - NamedNodeMap attrs = rootClone.getAttributes(); - attrs.removeNamedItemNS(XSL_NS, "version"); - templates.add(new Template(this, null, new Root(), - parse(rootClone), - precedence, - Template.DEFAULT_PRIORITY, - null)); - } - else - { - // Skip unknown elements, text, comments, etc - parse(node.getNextSibling(), false); - } - } - catch (TransformerException e) - { - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(e.getMessage(), l, e); - } - catch (DOMException e) - { - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(e.getMessage(), l, e); - } - catch (XPathExpressionException e) - { - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(e.getMessage(), l, e); - } - } - - final NameTest parseNameTest(String token) - { - if ("*".equals(token)) - { - return new NameTest(null, true, true); - } - else if (token.endsWith(":*")) - { - QName qName = getQName(token.substring(0, token.length() - 2)); - return new NameTest(qName, true, false); - } - else - { - QName qName = getQName(token); - return new NameTest(qName, false, false); - } - } - - final QName getQName(String name) - { - QName qName = QName.valueOf(name); - String prefix = qName.getPrefix(); - String uri = qName.getNamespaceURI(); - if (prefix != null && (uri == null || uri.length() == 0)) - { - uri = getNamespaceURI(prefix); - String localName = qName.getLocalPart(); - qName = new QName(uri, localName, prefix); - } - return qName; - } - - final TemplateNode parseAttributeValueTemplate(String value, Node source) - throws TransformerConfigurationException, XPathExpressionException - { - current = source; - // Tokenize - int len = value.length(); - int off = 0; - List tokens = new ArrayList(); // text tokens - List types = new ArrayList(); // literal or expression - int depth = 0; - for (int i = 0; i < len; i++) - { - char c = value.charAt(i); - if (c == '{') - { - if (i < (len - 1) && value.charAt(i + 1) == '{') - { - tokens.add(value.substring(off, i + 1)); - types.add(Boolean.FALSE); - i++; - off = i + 1; - continue; - } - if (depth == 0) - { - if (i - off > 0) - { - tokens.add(value.substring(off, i)); - types.add(Boolean.FALSE); - } - off = i + 1; - } - depth++; - } - else if (c == '}') - { - if (i < (len - 1) && value.charAt(i + 1) == '}') - { - tokens.add(value.substring(off, i + 1)); - types.add(Boolean.FALSE); - i++; - off = i + 1; - continue; - } - if (depth == 1) - { - if (i - off > 0) - { - tokens.add(value.substring(off, i)); - types.add(Boolean.TRUE); - } - else - { - String msg = "attribute value template " + - "must contain expression: " + value; - DOMSourceLocator l = new DOMSourceLocator(source); - throw new TransformerConfigurationException(msg, l); - } - off = i + 1; - } - depth--; - } - } - if (depth > 0) - { - String msg = "invalid attribute value template: " + value; - throw new TransformerConfigurationException(msg); - } - if (len - off > 0) - { - // Trailing text - tokens.add(value.substring(off)); - types.add(Boolean.FALSE); - } - - // Construct template node tree - TemplateNode ret = null; - Document doc = source.getOwnerDocument(); - len = tokens.size(); - for (int i = len - 1; i >= 0; i--) - { - String token = (String) tokens.get(i); - Boolean type = (Boolean) types.get(i); - if (type == Boolean.TRUE) - { - // Expression text - Expr select = (Expr) xpath.compile(token); - ret = new ValueOfNode(null, ret, select, false); - } - else - { - // Verbatim text - ret = new LiteralNode(null, ret, doc.createTextNode(token)); - } - } - return ret; - } - - boolean isPreserved(Text text) - throws TransformerConfigurationException - { - // Check characters in text - String value = text.getData(); - if (value != null) - { - int len = value.length(); - for (int i = 0; i < len; i++) - { - char c = value.charAt(i); - if (c != 0x20 && c != 0x09 && c != 0x0a && c != 0x0d) - { - return true; - } - } - } - // Check parent node - Node ctx = text.getParentNode(); - if (!preserveSpace.isEmpty()) - { - for (Iterator i = preserveSpace.iterator(); i.hasNext(); ) - { - NameTest preserveTest = (NameTest) i.next(); - if (preserveTest.matches(ctx, 1, 1)) - { - boolean override = false; - if (!stripSpace.isEmpty()) - { - for (Iterator j = stripSpace.iterator(); j.hasNext(); ) - { - NameTest stripTest = (NameTest) j.next(); - if (stripTest.matches(ctx, 1, 1)) - { - override = true; - break; - } - } - } - if (!override) - { - return true; - } - } - } - } - // Check whether any ancestor specified xml:space - while (ctx != null) - { - if (ctx.getNodeType() == Node.ELEMENT_NODE) - { - Element element = (Element) ctx; - String xmlSpace = element.getAttribute("xml:space"); - if ("default".equals(xmlSpace)) - { - break; - } - else if ("preserve".equals(xmlSpace)) - { - return true; - } - else if (xmlSpace.length() > 0) - { - String msg = "Illegal value for xml:space: " + xmlSpace; - throw new TransformerConfigurationException(msg); - } - else if ("text".equals(ctx.getLocalName()) && - XSL_NS.equals(ctx.getNamespaceURI())) - { - // xsl:text implies xml:space='preserve' - return true; - } - } - ctx = ctx.getParentNode(); - } - return false; - } - - public XPathFunction resolveFunction(QName name, int arity) - { - String uri = name.getNamespaceURI(); - if (XSL_NS.equals(uri) || uri == null || uri.length() == 0) - { - String localName = name.getLocalPart(); - if ("document".equals(localName) && (arity == 1 || arity == 2)) - { - if (current == null) - { - throw new RuntimeException("current is null"); - } - return new DocumentFunction(getRootStylesheet(), current); - } - else if ("key".equals(localName) && (arity == 2)) - { - return new KeyFunction(getRootStylesheet()); - } - else if ("format-number".equals(localName) && - (arity == 2 || arity == 3)) - { - return new FormatNumberFunction(getRootStylesheet()); - } - else if ("current".equals(localName) && (arity == 0)) - { - return new CurrentFunction(getRootStylesheet()); - } - else if ("unparsed-entity-uri".equals(localName) && (arity == 1)) - { - return new UnparsedEntityUriFunction(); - } - else if ("generate-id".equals(localName) && - (arity == 1 || arity == 0)) - { - return new GenerateIdFunction(); - } - else if ("system-property".equals(localName) && (arity == 1)) - { - return new SystemPropertyFunction(); - } - else if ("element-available".equals(localName) && (arity == 1)) - { - return new ElementAvailableFunction(this); - } - else if ("function-available".equals(localName) && (arity == 1)) - { - return new FunctionAvailableFunction(this); - } - } - return null; - } - - // -- Parsing -- - - /** - * apply-templates - */ - final TemplateNode parseApplyTemplates(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String m = getAttribute(attrs, "mode"); - QName mode = (m == null) ? null : getQName(m); - String s = getAttribute(attrs, "select"); - if (s == null) - { - s = "child::node()"; - } - List sortKeys = parseSortKeys(children); - List withParams = parseWithParams(children); - Expr select = (Expr) xpath.compile(s); - return new ApplyTemplatesNode(null, parse(next), - select, mode, - sortKeys, withParams, false); - } - - /** - * call-template - */ - final TemplateNode parseCallTemplate(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String n = getRequiredAttribute(attrs, "name", node); - QName name = getQName(n); - List withParams = parseWithParams(children); - return new CallTemplateNode(null, parse(next), name, - withParams); - } - - /** - * value-of - */ - final TemplateNode parseValueOf(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String s = getRequiredAttribute(attrs, "select", node); - String doe = getAttribute(attrs, "disable-output-escaping"); - boolean d = "yes".equals(doe); - Expr select = (Expr) xpath.compile(s); - return new ValueOfNode(null, parse(next), select, d); - } - - /** - * for-each - */ - final TemplateNode parseForEach(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String s = getRequiredAttribute(attrs, "select", node); - List sortKeys = parseSortKeys(children); - Expr select = (Expr) xpath.compile(s); - return new ForEachNode(parse(children), parse(next), select, sortKeys); - } - - /** - * if - */ - final TemplateNode parseIf(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String t = getRequiredAttribute(attrs, "test", node); - Expr test = (Expr) xpath.compile(t); - return new IfNode(parse(children), parse(next), test); - } - - /** - * when - */ - final TemplateNode parseWhen(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String t = getRequiredAttribute(attrs, "test", node); - Expr test = (Expr) xpath.compile(t); - return new WhenNode(parse(children), parse(next), test); - } - - /** - * element - */ - final TemplateNode parseElement(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String name = getRequiredAttribute(attrs, "name", node); - String namespace = getAttribute(attrs, "namespace"); - String uas = getAttribute(attrs, "use-attribute-sets"); - TemplateNode n = parseAttributeValueTemplate(name, node); - TemplateNode ns = (namespace == null) ? null : - parseAttributeValueTemplate(namespace, node); - return new ElementNode(parse(children), parse(next), n, ns, uas, node); - } - - /** - * attribute - */ - final TemplateNode parseAttribute(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String name = getRequiredAttribute(attrs, "name", node); - String namespace = getAttribute(attrs, "namespace"); - TemplateNode n = parseAttributeValueTemplate(name, node); - TemplateNode ns = (namespace == null) ? null : - parseAttributeValueTemplate(namespace, node); - return new AttributeNode(parse(children), parse(next), n, ns, node); - } - - /** - * text - */ - final TemplateNode parseText(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String doe = getAttribute(attrs, "disable-output-escaping"); - boolean d = "yes".equals(doe); - return new TextNode(parse(children), parse(next), d); - } - - /** - * copy - */ - final TemplateNode parseCopy(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String uas = getAttribute(attrs, "use-attribute-sets"); - return new CopyNode(parse(children), parse(next), uas); - } - - /** - * processing-instruction - */ - final TemplateNode parseProcessingInstruction(Node node, Node children, - Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String name = getRequiredAttribute(attrs, "name", node); - return new ProcessingInstructionNode(parse(children), - parse(next), name); - } - - /** - * number - */ - final TemplateNode parseNumber(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String v = getAttribute(attrs, "value"); - String ff = getAttribute(attrs, "format"); - if (ff == null) - { - ff = "1"; - } - TemplateNode format = parseAttributeValueTemplate(ff, node); - String lang = getAttribute(attrs, "lang"); - String lv = getAttribute(attrs, "letter-value"); - int letterValue = "traditional".equals(lv) ? - AbstractNumberNode.TRADITIONAL : - AbstractNumberNode.ALPHABETIC; - String gs = getAttribute(attrs, "grouping-separator"); - String gz = getAttribute(attrs, "grouping-size"); - int gz2 = (gz != null && gz.length() > 0) ? - Integer.parseInt(gz) : 1; - if (v != null && v.length() > 0) - { - Expr value = (Expr) xpath.compile(v); - return new NumberNode(parse(children), parse(next), - value, format, lang, - letterValue, gs, gz2); - } - else - { - String l = getAttribute(attrs, "level"); - int level = - "multiple".equals(l) ? NodeNumberNode.MULTIPLE : - "any".equals(l) ? NodeNumberNode.ANY : - NodeNumberNode.SINGLE; - String c = getAttribute(attrs, "count"); - String f = getAttribute(attrs, "from"); - Pattern count = null; - Pattern from = null; - if (c != null) - { - try - { - count = (Pattern) xpath.compile(c); - } - catch (ClassCastException e) - { - String msg = "invalid pattern: " + c; - throw new TransformerConfigurationException(msg); - } - } - if (f != null) - { - try - { - from = (Pattern) xpath.compile(f); - } - catch (ClassCastException e) - { - String msg = "invalid pattern: " + f; - throw new TransformerConfigurationException(msg); - } - } - return new NodeNumberNode(parse(children), parse(next), - level, count, from, - format, lang, - letterValue, gs, gz2); - } - } - - /** - * copy-of - */ - final TemplateNode parseCopyOf(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String s = getRequiredAttribute(attrs, "select", node); - Expr select = (Expr) xpath.compile(s); - return new CopyOfNode(parse(children), parse(next), select); - } - - /** - * message - */ - final TemplateNode parseMessage(Node node, Node children, Node next) - throws TransformerConfigurationException, XPathExpressionException - { - NamedNodeMap attrs = node.getAttributes(); - String t = getAttribute(attrs, "terminate"); - boolean terminate = "yes".equals(t); - return new MessageNode(parse(children), parse(next), terminate); - } - - /** - * Parse template-level elements. - */ - final TemplateNode parse(Node node) - throws TransformerConfigurationException - { - if (node == null) - { - return null; - } - // Hack to associate the document function with its declaring node - current = node; - Node children = node.getFirstChild(); - Node next = node.getNextSibling(); - try - { - String namespaceUri = node.getNamespaceURI(); - if (Stylesheet.XSL_NS.equals(namespaceUri) && - Node.ELEMENT_NODE == node.getNodeType()) - { - String name = node.getLocalName(); - if ("apply-templates".equals(name)) - { - return parseApplyTemplates(node, children, next); - } - else if ("call-template".equals(name)) - { - return parseCallTemplate(node, children, next); - } - else if ("value-of".equals(name)) - { - return parseValueOf(node, children, next); - } - else if ("for-each".equals(name)) - { - return parseForEach(node, children, next); - } - else if ("if".equals(name)) - { - return parseIf(node, children, next); - } - else if ("choose".equals(name)) - { - return new ChooseNode(parse(children), parse(next)); - } - else if ("when".equals(name)) - { - return parseWhen(node, children, next); - } - else if ("otherwise".equals(name)) - { - return new OtherwiseNode(parse(children), parse(next)); - } - else if ("element".equals(name)) - { - return parseElement(node, children, next); - } - else if ("attribute".equals(name)) - { - return parseAttribute(node, children, next); - } - else if ("text".equals(name)) - { - return parseText(node, children, next); - } - else if ("copy".equals(name)) - { - return parseCopy(node, children, next); - } - else if ("processing-instruction".equals(name)) - { - return parseProcessingInstruction(node, children, next); - } - else if ("comment".equals(name)) - { - return new CommentNode(parse(children), parse(next)); - } - else if ("number".equals(name)) - { - return parseNumber(node, children, next); - } - else if ("param".equals(name) || - "variable".equals(name)) - { - boolean global = "variable".equals(name); - NamedNodeMap attrs = node.getAttributes(); - TemplateNode content = parse(children); - String paramName = getRequiredAttribute(attrs, "name", node); - String select = getAttribute(attrs, "select"); - if (select != null) - { - if (content != null) - { - String msg = "parameter '" + paramName + - "' has both select and content"; - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(msg, l); - } - Expr expr = (Expr) xpath.compile(select); - return new ParameterNode(null, parse(next), - paramName, expr, global); - } - else - { - return new ParameterNode(content, parse(next), - paramName, null, global); - } - } - else if ("copy-of".equals(name)) - { - return parseCopyOf(node, children, next); - } - else if ("message".equals(name)) - { - return parseMessage(node, children, next); - } - else if ("apply-imports".equals(name)) - { - return new ApplyImportsNode(parse(children), parse(next)); - } - else - { - // xsl:fallback - // Pass over any other XSLT nodes - return parse(next); - } - } - String prefix = node.getPrefix(); - if (extensionElementPrefixes.contains(prefix)) - { - // Pass over extension elements - return parse(next); - } - switch (node.getNodeType()) - { - case Node.TEXT_NODE: - // Determine whether to strip whitespace - Text text = (Text) node; - if (!isPreserved(text)) - { - // Strip - text.getParentNode().removeChild(text); - return parse(next); - } - break; - case Node.COMMENT_NODE: - // Ignore comments - return parse(next); - case Node.ELEMENT_NODE: - // Check for attribute value templates and use-attribute-sets - NamedNodeMap attrs = node.getAttributes(); - boolean convert = false; - String useAttributeSets = null; - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String value = attr.getNodeValue(); - if (Stylesheet.XSL_NS.equals(attr.getNamespaceURI()) && - "use-attribute-sets".equals(attr.getLocalName())) - { - useAttributeSets = value; - convert = true; - break; - } - int start = value.indexOf('{'); - int end = value.indexOf('}'); - if (start != -1 || end != -1) - { - convert = true; - break; - } - } - if (convert) - { - // Create an element-producing template node instead - // with appropriate attribute-producing child template nodes - TemplateNode child = parse(children); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String ans = attr.getNamespaceURI(); - String aname = attr.getNodeName(); - if (Stylesheet.XSL_NS.equals(ans) && - "use-attribute-sets".equals(attr.getLocalName())) - { - continue; - } - String value = attr.getNodeValue(); - TemplateNode grandchild = - parseAttributeValueTemplate(value, node); - TemplateNode n = - parseAttributeValueTemplate(aname, node); - TemplateNode ns = (ans == null) ? null : - parseAttributeValueTemplate(ans, node); - child = new AttributeNode(grandchild, child, n, ns, attr); - } - String ename = node.getNodeName(); - TemplateNode n = parseAttributeValueTemplate(ename, node); - TemplateNode ns = (namespaceUri == null) ? null : - parseAttributeValueTemplate(namespaceUri, node); - return new ElementNode(child, parse(next), - n, ns, useAttributeSets, - node); - } - // Otherwise fall through - break; - } - } - catch (XPathExpressionException e) - { - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(e.getMessage(), l, e); - } - return new LiteralNode(parse(children), parse(next), node); - } - - final List parseSortKeys(Node node) - throws TransformerConfigurationException, XPathExpressionException - { - List ret = new LinkedList(); - while (node != null) - { - String namespaceUri = node.getNamespaceURI(); - if (Stylesheet.XSL_NS.equals(namespaceUri) && - Node.ELEMENT_NODE == node.getNodeType() && - "sort".equals(node.getLocalName())) - { - NamedNodeMap attrs = node.getAttributes(); - String s = getAttribute(attrs, "select"); - if (s == null) - { - s = "."; - } - Expr select = (Expr) xpath.compile(s); - String l = getAttribute(attrs, "lang"); - TemplateNode lang = (l == null) ? null : - parseAttributeValueTemplate(l, node); - String dt = getAttribute(attrs, "data-type"); - TemplateNode dataType = (dt == null) ? null : - parseAttributeValueTemplate(dt, node); - String o = getAttribute(attrs, "order"); - TemplateNode order = (o == null) ? null : - parseAttributeValueTemplate(o, node); - String co = getAttribute(attrs, "case-order"); - TemplateNode caseOrder = (co == null) ? null : - parseAttributeValueTemplate(co, node); - ret.add(new SortKey(select, lang, dataType, order, caseOrder)); - } - node = node.getNextSibling(); - } - return ret.isEmpty() ? null : ret; - } - - final List parseWithParams(Node node) - throws TransformerConfigurationException, XPathExpressionException - { - List ret = new LinkedList(); - while (node != null) - { - String namespaceUri = node.getNamespaceURI(); - if (Stylesheet.XSL_NS.equals(namespaceUri) && - Node.ELEMENT_NODE == node.getNodeType() && - "with-param".equals(node.getLocalName())) - { - NamedNodeMap attrs = node.getAttributes(); - TemplateNode content = parse(node.getFirstChild()); - String name = getRequiredAttribute(attrs, "name", node); - String select = getAttribute(attrs, "select"); - if (select != null) - { - if (content != null) - { - String msg = "parameter '" + name + - "' has both select and content"; - DOMSourceLocator l = new DOMSourceLocator(node); - throw new TransformerConfigurationException(msg, l); - } - Expr expr = (Expr) xpath.compile(select); - ret.add(new WithParam(name, expr)); - } - else - { - ret.add(new WithParam(name, content)); - } - } - node = node.getNextSibling(); - } - return ret.isEmpty() ? null : ret; - } - - /** - * Created element nodes have a copy of the namespace nodes in the - * stylesheet, except the XSLT namespace, extension namespaces, and - * exclude-result-prefixes. - */ - final void addNamespaceNodes(Node source, Node target, Document doc, - Collection elementExcludeResultPrefixes) - { - NamedNodeMap attrs = source.getAttributes(); - if (attrs != null) - { - int len = attrs.getLength(); - for (int i = 0; i < len; i++) - { - Node attr = attrs.item(i); - String uri = attr.getNamespaceURI(); - if (uri == XMLConstants.XMLNS_ATTRIBUTE_NS_URI) - { - String prefix = attr.getLocalName(); - if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) - { - prefix = "#default"; - } - String ns = attr.getNodeValue(); - // Should the namespace be excluded? - if (XSL_NS.equals(ns) || - extensionElementPrefixes.contains(prefix) || - elementExcludeResultPrefixes.contains(prefix) || - excludeResultPrefixes.contains(prefix)) - { - continue; - } - // Is the namespace already defined on the target? - if (prefix == "#default") - { - prefix = null; - } - if (target.lookupNamespaceURI(prefix) != null) - { - continue; - } - attr = attr.cloneNode(true); - attr = doc.adoptNode(attr); - target.getAttributes().setNamedItemNS(attr); - } - } - } - Node parent = source.getParentNode(); - if (parent != null) - { - addNamespaceNodes(parent, target, doc, elementExcludeResultPrefixes); - } - } - - static final String getAttribute(NamedNodeMap attrs, String name) - { - Node attr = attrs.getNamedItem(name); - if (attr == null) - { - return null; - } - String ret = attr.getNodeValue(); - if (ret.length() == 0) - { - return null; - } - return ret; - } - - static final String getRequiredAttribute(NamedNodeMap attrs, String name, - Node source) - throws TransformerConfigurationException - { - String value = getAttribute(attrs, name); - if (value == null || value.length() == 0) - { - String msg = - name + " attribute is required on " + source.getNodeName(); - DOMSourceLocator l = new DOMSourceLocator(source); - throw new TransformerConfigurationException(msg, l); - } - return value; - } - - // Handle user data changes when nodes are cloned etc - - public void handle(short op, String key, Object data, Node src, Node dst) - { - dst.setUserData(key, data, this); - } - -} - diff --git a/libjava/gnu/xml/transform/SystemPropertyFunction.java b/libjava/gnu/xml/transform/SystemPropertyFunction.java deleted file mode 100644 index 33616d39628..00000000000 --- a/libjava/gnu/xml/transform/SystemPropertyFunction.java +++ /dev/null @@ -1,128 +0,0 @@ -/* SystemPropertyFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>system-property()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SystemPropertyFunction - extends Expr - implements XPathFunction, Function -{ - - List args; - - public Object evaluate(List args) - throws XPathFunctionException - { - String name = (String) args.get(0); - return systemProperty(QName.valueOf(name)); - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - int arity = args.size(); - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - String name = _string(context, values.get(0)); - return systemProperty(QName.valueOf(name)); - } - - Object systemProperty(QName name) - { - String localName = name.getLocalPart(); - String prefix = name.getPrefix(); - String uri = name.getNamespaceURI(); - if (Stylesheet.XSL_NS.equals(uri) || - "xsl".equals(prefix)) - { - if ("version".equals(localName)) - { - return new Double(1.0d); - } - else if ("vendor".equals(localName)) - { - return "The Free Software Foundation"; - } - else if ("vendor-url".equals(localName)) - { - return "http://www.gnu.org/"; - } - else - { - return ""; - } - } - return System.getProperty(localName); - } - - public Expr clone(Object context) - { - SystemPropertyFunction f = new SystemPropertyFunction(); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/Template.java b/libjava/gnu/xml/transform/Template.java deleted file mode 100644 index 1673a8aa63b..00000000000 --- a/libjava/gnu/xml/transform/Template.java +++ /dev/null @@ -1,252 +0,0 @@ -/* Template.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.PrintStream; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.NameTest; -import gnu.xml.xpath.NodeTypeTest; -import gnu.xml.xpath.Pattern; -import gnu.xml.xpath.Selector; -import gnu.xml.xpath.Test; - -/** - * A template in an XSL stylesheet. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class Template - implements Comparable -{ - - static final double DEFAULT_PRIORITY = 0.5d; - - final Stylesheet stylesheet; - final QName name; - final Pattern match; - final TemplateNode node; - final double priority; - final int precedence; - final QName mode; - - Template(Stylesheet stylesheet, - QName name, Pattern match, TemplateNode node, - int precedence, double priority, QName mode) - { - this.stylesheet = stylesheet; - this.name = name; - this.match = match; - this.node = node; - // adjust priority if necessary - // see XSLT section 5.5 - Test test = getNodeTest(match); - if (test != null) - { - if (test instanceof NameTest) - { - NameTest nameTest = (NameTest) test; - if (nameTest.matchesAny() || - nameTest.matchesAnyLocalName()) - { - priority = -0.25d; - } - else - { - priority = 0.0d; - } - } - else - { - NodeTypeTest nodeTypeTest = (NodeTypeTest) test; - if (nodeTypeTest.getNodeType() == - Node.PROCESSING_INSTRUCTION_NODE && - nodeTypeTest.getData() != null) - { - priority = 0.0d; - } - else - { - priority = -0.5d; - } - } - } - this.precedence = precedence; - this.priority = priority; - this.mode = mode; - } - - Template clone(Stylesheet stylesheet) - { - // FIXME by cloning we lose the imports() functionality, so - // apply-imports will be broken. - return new Template(stylesheet, - name, - (match == null) ? null : - (Pattern) match.clone(stylesheet), - (node == null) ? null : node.clone(stylesheet), - precedence, - priority, - mode); - } - - public int compareTo(Object other) - { - if (other instanceof Template) - { - Template t = (Template) other; - int d = t.precedence - precedence; - if (d != 0) - { - return d; - } - double d2 = t.priority - priority; - if (d2 != 0.0d) - { - return (int) Math.round(d2 * 1000.0d); - } - } - return 0; - } - - Test getNodeTest(Expr expr) - { - if (expr instanceof Selector) - { - Selector selector = (Selector) expr; - Test[] tests = selector.getTests(); - if (tests.length > 0) - { - return tests[0]; - } - } - return null; - } - - boolean matches(QName mode, Node node) - { - if ((mode == null && this.mode != null) || - (mode != null && !mode.equals(this.mode))) - { - return false; - } - if (match == null) - { - return false; - } - return match.matches(node); - } - - boolean matches(QName name) - { - return name.equals(this.name); - } - - boolean imports(Template other) - { - for (Stylesheet ctx = other.stylesheet.parent; - ctx != null; - ctx = ctx.parent) - { - if (ctx == stylesheet) - { - return true; - } - } - return false; - } - - /** - * @param stylesheet the stylesheet - * @param parent the parent of result nodes - * @param context the context node in the source document - * @param pos the context position - * @param len the context size - * @param nextSibling if non-null, add result nodes before this node - */ - void apply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - //System.err.println("...applying " + toString() + " to " + context); - if (node != null) - { - node.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - if (name != null) - { - buf.append("name="); - buf.append(name); - } - else if (match != null) - { - buf.append("match="); - buf.append(match); - } - if (mode != null) - { - buf.append(",mode="); - buf.append(mode); - } - buf.append(']'); - return buf.toString(); - - //return (name != null) ? name.toString() : match.toString(); - } - - void list(PrintStream out) - { - out.println(toString()); - if (node != null) - { - node.list(1, out, true); - } - } - -} diff --git a/libjava/gnu/xml/transform/TemplateNode.java b/libjava/gnu/xml/transform/TemplateNode.java deleted file mode 100644 index df13a4d1ec0..00000000000 --- a/libjava/gnu/xml/transform/TemplateNode.java +++ /dev/null @@ -1,115 +0,0 @@ -/* TemplateNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.PrintStream; -import java.util.Comparator; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.DocumentOrderComparator; - -/** - * Wrapper for a source node in a template. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -abstract class TemplateNode -{ - - static final Comparator documentOrderComparator = - new DocumentOrderComparator(); - - final TemplateNode children; - final TemplateNode next; - - TemplateNode(TemplateNode children, TemplateNode next) - { - this.children = children; - this.next = next; - } - - final void apply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - if (stylesheet.terminated) - { - return; - } - if (Thread.currentThread().isInterrupted()) - { - // Try to head off any infinite loops at the pass - return; - } - if (stylesheet.debug) - { - System.err.println("Applying " + toString()); - } - doApply(stylesheet, mode, context, pos, len, parent, nextSibling); - } - - abstract void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException; - - abstract TemplateNode clone(Stylesheet stylesheet); - - /** - * Debugging - */ - void list(int depth, PrintStream out, boolean listNext) - { - for (int i = 0; i < depth; i++) - { - out.print(" "); - } - out.println(toString()); - if (children != null) - { - children.list(depth + 1, out, true); - } - if (listNext && next != null) - { - next.list(depth, out, listNext); - } - } - -} diff --git a/libjava/gnu/xml/transform/TemplatesImpl.java b/libjava/gnu/xml/transform/TemplatesImpl.java deleted file mode 100644 index 527bd979db0..00000000000 --- a/libjava/gnu/xml/transform/TemplatesImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* TemplatesImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Properties; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; - -/** - * GNU precompiled stylesheet implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class TemplatesImpl - implements Templates -{ - - final TransformerFactoryImpl factory; - final Stylesheet stylesheet; - final Properties outputProperties; - - TemplatesImpl(TransformerFactoryImpl factory, Stylesheet stylesheet) - { - this.factory = factory; - this.stylesheet = stylesheet; - outputProperties = new TransformerOutputProperties(stylesheet); - } - - public Transformer newTransformer() - throws TransformerConfigurationException - { - Stylesheet stylesheet = (Stylesheet) this.stylesheet.clone(); - TransformerImpl transformer = - new TransformerImpl(factory, stylesheet, outputProperties); - stylesheet.transformer = transformer; - return transformer; - } - - public Properties getOutputProperties() - { - return (Properties) outputProperties.clone(); - } - -} diff --git a/libjava/gnu/xml/transform/TextNode.java b/libjava/gnu/xml/transform/TextNode.java deleted file mode 100644 index b5ea1b57af7..00000000000 --- a/libjava/gnu/xml/transform/TextNode.java +++ /dev/null @@ -1,116 +0,0 @@ -/* TextNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import gnu.xml.xpath.Expr; - -/** - * A template node representing the XSL <code>text</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class TextNode - extends TemplateNode -{ - - final boolean disableOutputEscaping; - - TextNode(TemplateNode children, TemplateNode next, - boolean disableOutputEscaping) - { - super(children, next); - this.disableOutputEscaping = disableOutputEscaping; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new TextNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - disableOutputEscaping); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - String value = ""; - Document doc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - if (children != null) - { - // Create a document fragment to hold the text - DocumentFragment fragment = doc.createDocumentFragment(); - // Apply children to the fragment - children.apply(stylesheet, mode, - context, pos, len, - fragment, null); - // Use XPath string-value of fragment - value = Expr.stringValue(fragment); - } - Text text = doc.createTextNode(value); - if (disableOutputEscaping) - { - text.setUserData("disable-output-escaping", "yes", stylesheet); - } - // Insert into result tree - if (nextSibling != null) - { - parent.insertBefore(text, nextSibling); - } - else - { - parent.appendChild(text); - } - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - -} diff --git a/libjava/gnu/xml/transform/TransformerFactoryImpl.java b/libjava/gnu/xml/transform/TransformerFactoryImpl.java deleted file mode 100644 index dde2017ff6b..00000000000 --- a/libjava/gnu/xml/transform/TransformerFactoryImpl.java +++ /dev/null @@ -1,345 +0,0 @@ -/* TransformerFactoryImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.IOException; -import java.net.URL; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Properties; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.URIResolver; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import javax.xml.xpath.XPathFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import gnu.xml.dom.DomDocument; - -/** - * GNU transformer factory implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class TransformerFactoryImpl - extends TransformerFactory -{ - - final XPathFactory xpathFactory; - final XSLURIResolver resolver; - ErrorListener userListener; - URIResolver userResolver; - - public TransformerFactoryImpl() - { - xpathFactory = new gnu.xml.xpath.XPathFactoryImpl(); - resolver = new XSLURIResolver(); - } - - public Transformer newTransformer(Source source) - throws TransformerConfigurationException - { - Stylesheet stylesheet = newStylesheet(source, 0, null); - Properties outputProperties = - new TransformerOutputProperties(stylesheet); - TransformerImpl transformer = - new TransformerImpl(this, stylesheet, outputProperties); - stylesheet.transformer = transformer; - return transformer; - } - - public Transformer newTransformer() - throws TransformerConfigurationException - { - return new TransformerImpl(this, null, new Properties()); - } - - public Templates newTemplates(Source source) - throws TransformerConfigurationException - { - Stylesheet stylesheet = newStylesheet(source, 0, null); - return new TemplatesImpl(this, stylesheet); - } - - Stylesheet newStylesheet(Source source, int precedence, Stylesheet parent) - throws TransformerConfigurationException - { - Document doc = null; - String systemId = null; - if (source != null) - { - try - { - DOMSource ds; - synchronized (resolver) - { - resolver.setUserResolver(userResolver); - resolver.setUserListener(userListener); - ds = resolver.resolveDOM(source, null, null); - } - Node node = ds.getNode(); - if (node == null) - { - throw new TransformerConfigurationException("no source document"); - } - doc = (node instanceof Document) ? (Document) node : - node.getOwnerDocument(); - systemId = ds.getSystemId(); - } - catch (TransformerException e) - { - throw new TransformerConfigurationException(e); - } - } - return new Stylesheet(this, parent, doc, systemId, precedence); - } - - public Source getAssociatedStylesheet(Source source, - String media, - String title, - String charset) - throws TransformerConfigurationException - { - try - { - DOMSource ds; - synchronized (resolver) - { - resolver.setUserResolver(userResolver); - resolver.setUserListener(userListener); - ds = resolver.resolveDOM(source, null, null); - } - Node node = ds.getNode(); - if (node == null) - { - throw new TransformerConfigurationException("no source document"); - } - Document doc = (node instanceof Document) ? (Document) node : - node.getOwnerDocument(); - LinkedList matches = new LinkedList(); - for (node = doc.getFirstChild(); - node != null; - node = node.getNextSibling()) - { - if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && - "xml-stylesheet".equals(node.getNodeName())) - { - Map params = parseParameters(node.getNodeValue()); - if (media != null && !media.equals(params.get("media"))) - { - continue; - } - if (title != null && !title.equals(params.get("title"))) - { - continue; - } - if (charset != null && !charset.equals(params.get("charset"))) - { - continue; - } - String href = (String) params.get("href"); - URL url = resolver.resolveURL(null, node.getBaseURI(), href); - matches.add(url); - } - } - switch (matches.size()) - { - case 0: - return null; - case 1: - return new StreamSource(((URL) matches.getFirst()).toString()); - default: - // Create a source representing a stylesheet with a list of - // imports - DomDocument ssDoc = new DomDocument(); - ssDoc.setBuilding(true); - // Create document element - Node root = - ssDoc.createElementNS(Stylesheet.XSL_NS, "stylesheet"); - Node version = - ssDoc.createAttributeNS(null, "version"); - version.setNodeValue("1.0"); - root.getAttributes().setNamedItemNS(version); - ssDoc.appendChild(root); - // Create xsl:import for each URL - for (Iterator i = matches.iterator(); i.hasNext(); ) - { - URL url = (URL) i.next(); - Node imp = - ssDoc.createElementNS(Stylesheet.XSL_NS, "import"); - Node href = - ssDoc.createAttributeNS(null, "href"); - href.setNodeValue(url.toString()); - imp.getAttributes().setNamedItemNS(href); - root.appendChild(imp); - } - ssDoc.setBuilding(false); - return new DOMSource(ssDoc); - } - } - catch (IOException e) - { - throw new TransformerConfigurationException(e); - } - catch (TransformerException e) - { - throw new TransformerConfigurationException(e); - } - } - - Map parseParameters(String data) - { - Map ret = new LinkedHashMap(); - int len = data.length(); - String key = null; - int start = 0; - char quoteChar = '\u0000'; - for (int i = 0; i < len; i++) - { - char c = data.charAt(i); - if (quoteChar == '\u0000' && c == ' ') - { - if (key == null && start < i) - { - key = data.substring(start, i); - } - else - { - String val = unquote(data.substring(start, i).trim()); - ret.put(key, val); - key = null; - } - start = i + 1; - } - else if (c == '"') - { - quoteChar = (quoteChar == c) ? '\u0000' : c; - } - else if (c == '\'') - { - quoteChar = (quoteChar == c) ? '\u0000' : c; - } - } - if (start < len && key != null) - { - String val = unquote(data.substring(start, len).trim()); - ret.put(key, val); - } - return ret; - } - - String unquote(String text) - { - int end = text.length() - 1; - if (text.charAt(0) == '\'' && text.charAt(end) == '\'') - { - return text.substring(1, end); - } - if (text.charAt(0) == '"' && text.charAt(end) == '"') - { - return text.substring(1, end); - } - return text; - } - - public void setURIResolver(URIResolver resolver) - { - userResolver = resolver; - } - - public URIResolver getURIResolver() - { - return userResolver; - } - - public void setFeature(String name, boolean value) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException("not supported"); - } - - public boolean getFeature(String name) - { - if (SAXSource.FEATURE.equals(name) || - SAXResult.FEATURE.equals(name) || - StreamSource.FEATURE.equals(name) || - StreamResult.FEATURE.equals(name) || - DOMSource.FEATURE.equals(name) || - DOMResult.FEATURE.equals(name)) - { - return true; - } - return false; - } - - public void setAttribute(String name, Object value) - throws IllegalArgumentException - { - throw new IllegalArgumentException("not supported"); - } - - public Object getAttribute(String name) - throws IllegalArgumentException - { - throw new IllegalArgumentException("not supported"); - } - - public void setErrorListener(ErrorListener listener) - throws IllegalArgumentException - { - userListener = listener; - } - - public ErrorListener getErrorListener() - { - return userListener; - } - -} diff --git a/libjava/gnu/xml/transform/TransformerImpl.java b/libjava/gnu/xml/transform/TransformerImpl.java deleted file mode 100644 index 73c4c0a4e08..00000000000 --- a/libjava/gnu/xml/transform/TransformerImpl.java +++ /dev/null @@ -1,580 +0,0 @@ -/* TransformerImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.net.MalformedURLException; -import java.net.UnknownServiceException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Collection; -import java.util.Properties; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; -import gnu.xml.dom.DomDoctype; -import gnu.xml.dom.DomDocument; -import gnu.xml.dom.ls.WriterOutputStream; - -/** - * The transformation process for a given stylesheet. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class TransformerImpl - extends Transformer -{ - - final TransformerFactoryImpl factory; - final Stylesheet stylesheet; - URIResolver uriResolver; - ErrorListener errorListener; - Properties outputProperties; - - TransformerImpl(TransformerFactoryImpl factory, - Stylesheet stylesheet, - Properties outputProperties) - throws TransformerConfigurationException - { - this.factory = factory; - uriResolver = factory.userResolver; - errorListener = factory.userListener; - this.stylesheet = stylesheet; - this.outputProperties = outputProperties; - if (stylesheet != null) - { - // Set up parameter context for this transformer - stylesheet.bindings.push(false); - } - } - - public void transform(Source xmlSource, Result outputTarget) - throws TransformerException - { - // Get the source tree - DOMSource source; - synchronized (factory.resolver) - { - factory.resolver.setUserResolver(uriResolver); - factory.resolver.setUserListener(errorListener); - source = factory.resolver.resolveDOM(xmlSource, null, null); - } - Node context = source.getNode(); - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - if (doc instanceof DomDocument) - { - // Suppress mutation events - ((DomDocument) doc).setBuilding(true); - // TODO find a better/more generic way of doing this than - // casting - } - // Get the result tree - Node parent = null, nextSibling = null; - if (outputTarget instanceof DOMResult) - { - DOMResult dr = (DOMResult) outputTarget; - parent = dr.getNode(); - nextSibling = dr.getNextSibling(); - - Document rdoc = (parent instanceof Document) ? (Document) parent : - parent.getOwnerDocument(); - if (rdoc instanceof DomDocument) - { - // Suppress mutation events and allow multiple root elements - DomDocument drdoc = (DomDocument) rdoc; - drdoc.setBuilding(true); - drdoc.setCheckWellformedness(false); - // TODO find a better/more generic way of doing this than - // casting - } - } - boolean created = false; - // Transformation - if (stylesheet != null) - { - if (parent == null) - { - // Create a new document to hold the result - DomDocument resultDoc = new DomDocument(); - resultDoc.setBuilding(true); - resultDoc.setCheckWellformedness(false); - parent = resultDoc; - created = true; - } - // Make a copy of the source node, and strip it - context = context.cloneNode(true); - strip(context); - // XSLT transformation - try - { - // Set output properties in the underlying stylesheet - ((TransformerOutputProperties) outputProperties).apply(); - stylesheet.initTopLevelVariables(context); - TemplateNode t = stylesheet.getTemplate(null, context, false); - if (t != null) - { - stylesheet.current = context; - t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); - } - } - catch (TransformerException e) - { - // Done transforming, reset document - if (doc instanceof DomDocument) - { - ((DomDocument) doc).setBuilding(false); - } - throw e; - } - } - else - { - // Identity transform - Node clone = context.cloneNode(true); - if (context.getNodeType() != Node.DOCUMENT_NODE) - { - Document resultDoc; - if (parent == null) - { - // Create a new document to hold the result - DomDocument rd = new DomDocument(); - rd.setBuilding(true); - rd.setCheckWellformedness(false); - parent = resultDoc = rd; - created = true; - } - else - { - resultDoc = (parent instanceof Document) ? - (Document) parent : - parent.getOwnerDocument(); - } - Document sourceDoc = context.getOwnerDocument(); - if (sourceDoc != resultDoc) - { - clone = resultDoc.adoptNode(clone); - } - if (nextSibling != null) - { - parent.insertBefore(clone, nextSibling); - } - else - { - parent.appendChild(clone); - } - } - else - { - // Cannot append document to another tree - parent = clone; - created = true; - } - } - String method = outputProperties.getProperty(OutputKeys.METHOD); - int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : - "text".equals(method) ? Stylesheet.OUTPUT_TEXT : - Stylesheet.OUTPUT_XML; - String encoding = outputProperties.getProperty(OutputKeys.ENCODING); - String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); - String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); - String version = outputProperties.getProperty(OutputKeys.VERSION); - boolean omitXmlDeclaration = - "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); - boolean standalone = - "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); - String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); - // TODO cdata-section-elements - // TODO indent - if (created) - { - // Discover document element - DomDocument resultDoc = (DomDocument) parent; - Node root = resultDoc.getDocumentElement(); - // Add doctype if specified - if ((publicId != null || systemId != null) && - root != null) - { - // We must know the name of the root element to - // create the document type - resultDoc.appendChild(new DomDoctype(resultDoc, - root.getNodeName(), - publicId, - systemId)); - } - resultDoc.setBuilding(false); - resultDoc.setCheckWellformedness(true); - } - else if (publicId != null || systemId != null) - { - switch (parent.getNodeType()) - { - case Node.DOCUMENT_NODE: - case Node.DOCUMENT_FRAGMENT_NODE: - Document resultDoc = (parent instanceof Document) ? - (Document) parent : - parent.getOwnerDocument(); - DOMImplementation impl = resultDoc.getImplementation(); - DocumentType doctype = - impl.createDocumentType(resultDoc.getNodeName(), - publicId, - systemId); - // Try to insert doctype before first element - Node ctx = parent.getFirstChild(); - for (; ctx != null && - ctx.getNodeType() != Node.ELEMENT_NODE; - ctx = ctx.getNextSibling()) - { - } - if (ctx != null) - { - parent.insertBefore(doctype, ctx); - } - else - { - parent.appendChild(doctype); - } - } - } - if (version != null) - { - parent.setUserData("version", version, stylesheet); - } - if (omitXmlDeclaration) - { - parent.setUserData("omit-xml-declaration", "yes", stylesheet); - } - if (standalone) - { - parent.setUserData("standalone", "yes", stylesheet); - } - if (mediaType != null) - { - parent.setUserData("media-type", mediaType, stylesheet); - } - // Render result to the target device - if (outputTarget instanceof DOMResult) - { - if (created) - { - DOMResult dr = (DOMResult) outputTarget; - dr.setNode(parent); - dr.setNextSibling(null); - } - } - else if (outputTarget instanceof StreamResult) - { - StreamResult sr = (StreamResult) outputTarget; - IOException ex = null; - try - { - writeStreamResult(parent, sr, outputMethod, encoding); - } - catch (UnsupportedEncodingException e) - { - try - { - writeStreamResult(parent, sr, outputMethod, "UTF-8"); - } - catch (IOException e2) - { - ex = e2; - } - } - catch (IOException e) - { - ex = e; - } - if (ex != null) - { - if (errorListener != null) - { - errorListener.error(new TransformerException(ex)); - } - else - { - ex.printStackTrace(System.err); - } - } - } - else if (outputTarget instanceof SAXResult) - { - SAXResult sr = (SAXResult) outputTarget; - try - { - ContentHandler ch = sr.getHandler(); - LexicalHandler lh = sr.getLexicalHandler(); - if (lh == null && ch instanceof LexicalHandler) - { - lh = (LexicalHandler) ch; - } - SAXSerializer serializer = new SAXSerializer(); - serializer.serialize(parent, ch, lh); - } - catch (SAXException e) - { - if (errorListener != null) - { - errorListener.error(new TransformerException(e)); - } - else - { - e.printStackTrace(System.err); - } - } - } - } - - /** - * Strip whitespace from the source tree. - */ - void strip(Node node) - throws TransformerConfigurationException - { - short nt = node.getNodeType(); - if (nt == Node.ENTITY_REFERENCE_NODE) - { - // Replace entity reference with its content - Node parent = node.getParentNode(); - Node child = node.getFirstChild(); - if (child != null) - { - strip(child); - } - while (child != null) - { - Node next = child.getNextSibling(); - node.removeChild(child); - parent.insertBefore(child, node); - child = next; - } - parent.removeChild(node); - } - if (nt == Node.TEXT_NODE) // CDATA sections ? - { - if (!stylesheet.isPreserved((Text) node)) - { - node.getParentNode().removeChild(node); - } - } - else - { - for (Node child = node.getFirstChild(); child != null; - child = child.getNextSibling()) - { - strip(child); - } - } - } - - /** - * Obtain a suitable output stream for writing the result to, - * and use the StreamSerializer to write the result tree to the stream. - */ - void writeStreamResult(Node node, StreamResult sr, int outputMethod, - String encoding) - throws IOException - { - OutputStream out = null; - try - { - out = sr.getOutputStream(); - if (out == null) - { - Writer writer = sr.getWriter(); - if (writer != null) - { - out = new WriterOutputStream(writer); - } - } - if (out == null) - { - String systemId = sr.getSystemId(); - try - { - URL url = new URL(systemId); - URLConnection connection = url.openConnection(); - connection.setDoOutput(true); - out = connection.getOutputStream(); - } - catch (MalformedURLException e) - { - out = new FileOutputStream(systemId); - } - catch (UnknownServiceException e) - { - URL url = new URL(systemId); - out = new FileOutputStream(url.getPath()); - } - } - out = new BufferedOutputStream(out); - StreamSerializer serializer = - new StreamSerializer(outputMethod, encoding, null); - if (stylesheet != null) - { - Collection celem = stylesheet.outputCdataSectionElements; - serializer.setCdataSectionElements(celem); - } - serializer.serialize(node, out); - out.flush(); - } - finally - { - try - { - if (out != null) - { - out.close(); - } - } - catch (IOException e) - { - } - } - } - - void copyChildren(Document dstDoc, Node src, Node dst) - { - Node srcChild = src.getFirstChild(); - while (srcChild != null) - { - Node dstChild = dstDoc.adoptNode(srcChild); - dst.appendChild(dstChild); - srcChild = srcChild.getNextSibling(); - } - } - - public void setParameter(String name, Object value) - { - if (stylesheet != null) - { - stylesheet.bindings.set(name, value, false); - } - } - - public Object getParameter(String name) - { - if (stylesheet != null) - { - return stylesheet.bindings.get(name, null, 1, 1); - } - return null; - } - - public void clearParameters() - { - if (stylesheet != null) - { - stylesheet.bindings.pop(false); - stylesheet.bindings.push(false); - } - } - - public void setURIResolver(URIResolver resolver) - { - uriResolver = resolver; - } - - public URIResolver getURIResolver() - { - return uriResolver; - } - - public void setOutputProperties(Properties oformat) - throws IllegalArgumentException - { - if (oformat == null) - { - outputProperties.clear(); - } - else - { - outputProperties.putAll(oformat); - } - } - - public Properties getOutputProperties() - { - return (Properties) outputProperties.clone(); - } - - public void setOutputProperty(String name, String value) - throws IllegalArgumentException - { - outputProperties.put(name, value); - } - - public String getOutputProperty(String name) - throws IllegalArgumentException - { - return outputProperties.getProperty(name); - } - - public void setErrorListener(ErrorListener listener) - { - errorListener = listener; - } - - public ErrorListener getErrorListener() - { - return errorListener; - } - -} diff --git a/libjava/gnu/xml/transform/TransformerOutputProperties.java b/libjava/gnu/xml/transform/TransformerOutputProperties.java deleted file mode 100644 index cc8593c4601..00000000000 --- a/libjava/gnu/xml/transform/TransformerOutputProperties.java +++ /dev/null @@ -1,185 +0,0 @@ -/* TransformerOutputProperties.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Properties; -import java.util.StringTokenizer; -import javax.xml.transform.OutputKeys; - -/** - * Helper class to manage JAXP user setting of output properties. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class TransformerOutputProperties - extends Properties -{ - - final Properties defaultProperties; - final Stylesheet stylesheet; - boolean dirty; - - TransformerOutputProperties(Stylesheet stylesheet) - { - this.stylesheet = stylesheet; - defaultProperties = new Properties(); - switch (stylesheet.outputMethod) - { - case Stylesheet.OUTPUT_XML: - defaultProperties.put(OutputKeys.METHOD, "xml"); - break; - case Stylesheet.OUTPUT_HTML: - defaultProperties.put(OutputKeys.METHOD, "html"); - break; - case Stylesheet.OUTPUT_TEXT: - defaultProperties.put(OutputKeys.METHOD, "text"); - break; - } - if (stylesheet.outputVersion != null) - { - defaultProperties.put(OutputKeys.VERSION, stylesheet.outputVersion); - } - if (stylesheet.outputEncoding != null) - { - defaultProperties.put(OutputKeys.ENCODING, stylesheet.outputEncoding); - } - defaultProperties.put(OutputKeys.OMIT_XML_DECLARATION, - stylesheet.outputOmitXmlDeclaration ? "yes" : "no"); - defaultProperties.put(OutputKeys.STANDALONE, - stylesheet.outputStandalone ? "yes" : "no"); - if (stylesheet.outputPublicId != null) - { - defaultProperties.put(OutputKeys.DOCTYPE_PUBLIC, - stylesheet.outputPublicId); - } - if (stylesheet.outputSystemId != null) - { - defaultProperties.put(OutputKeys.DOCTYPE_SYSTEM, - stylesheet.outputSystemId); - } - StringBuffer buf = new StringBuffer(); - for (Iterator i = stylesheet.outputCdataSectionElements.iterator(); - i.hasNext(); ) - { - if (buf.length() > 0) - { - buf.append(' '); - } - buf.append((String) i.next()); - } - defaultProperties.put(OutputKeys.CDATA_SECTION_ELEMENTS, buf.toString()); - defaultProperties.put(OutputKeys.INDENT, - stylesheet.outputIndent ? "yes" : "no"); - if (stylesheet.outputMediaType != null) - { - defaultProperties.put(OutputKeys.MEDIA_TYPE, - stylesheet.outputMediaType); - } - } - - public String getProperty(String key) - { - String val = super.getProperty(key); - if (val == null) - { - val = defaultProperties.getProperty(key); - } - return val; - } - - public Object put(Object key, Object value) - { - Object ret = super.put(key, value); - dirty = true; - return ret; - } - - public void clear() - { - super.clear(); - dirty = true; - } - - /** - * Applies the current set of properties to the underlying stylesheet. - */ - void apply() - { - if (!dirty) - { - return; - } - String method = getProperty(OutputKeys.METHOD); - if ("xml".equals(method)) - { - stylesheet.outputMethod = Stylesheet.OUTPUT_XML; - } - else if ("html".equals(method)) - { - stylesheet.outputMethod = Stylesheet.OUTPUT_HTML; - } - else if ("text".equals(method)) - { - stylesheet.outputMethod = Stylesheet.OUTPUT_TEXT; - } - stylesheet.outputVersion = getProperty(OutputKeys.VERSION); - stylesheet.outputEncoding = getProperty(OutputKeys.ENCODING); - stylesheet.outputOmitXmlDeclaration = - "yes".equals(getProperty(OutputKeys.OMIT_XML_DECLARATION)); - stylesheet.outputStandalone = - "yes".equals(getProperty(OutputKeys.STANDALONE)); - stylesheet.outputPublicId = getProperty(OutputKeys.DOCTYPE_PUBLIC); - stylesheet.outputSystemId = getProperty(OutputKeys.DOCTYPE_SYSTEM); - StringTokenizer st = - new StringTokenizer(getProperty(OutputKeys.CDATA_SECTION_ELEMENTS)); - Collection acc = new LinkedHashSet(); - while (st.hasMoreTokens()) - { - acc.add(st.nextToken()); - } - stylesheet.outputCdataSectionElements = acc; - stylesheet.outputIndent = "yes".equals(getProperty(OutputKeys.INDENT)); - stylesheet.outputMediaType = getProperty(OutputKeys.MEDIA_TYPE); - dirty = false; - } - -} - diff --git a/libjava/gnu/xml/transform/URIResolverEntityResolver.java b/libjava/gnu/xml/transform/URIResolverEntityResolver.java deleted file mode 100644 index 762416fde36..00000000000 --- a/libjava/gnu/xml/transform/URIResolverEntityResolver.java +++ /dev/null @@ -1,83 +0,0 @@ -/* URIResolverEntityResolver.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.IOException; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.sax.SAXSource; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * EntityResolver that wraps a URIResolver. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class URIResolverEntityResolver - implements EntityResolver -{ - - final URIResolver resolver; - - URIResolverEntityResolver(URIResolver resolver) - { - this.resolver = resolver; - } - - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException - { - try - { - Source source = resolver.resolve(null, systemId); - if (source == null) - { - return null; - } - return SAXSource.sourceToInputSource(source); - } - catch (TransformerException e) - { - throw new SAXException(e); - } - } - -} diff --git a/libjava/gnu/xml/transform/UnparsedEntityUriFunction.java b/libjava/gnu/xml/transform/UnparsedEntityUriFunction.java deleted file mode 100644 index ca72b6534df..00000000000 --- a/libjava/gnu/xml/transform/UnparsedEntityUriFunction.java +++ /dev/null @@ -1,118 +0,0 @@ -/* UnparsedEntityUriFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import org.w3c.dom.DocumentType; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Notation; -import gnu.xml.xpath.Expr; -import gnu.xml.xpath.Function; - -/** - * The XSLT <code>unparsed-entity-uri()</code>function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class UnparsedEntityUriFunction - extends Expr - implements XPathFunction, Function -{ - - List args; - - public Object evaluate(List args) - throws XPathFunctionException - { - // Useless... - return Collections.EMPTY_SET; - } - - public void setArguments(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - int arity = args.size(); - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - String name = _string(context, values.get(0)); - DocumentType doctype = context.getOwnerDocument().getDoctype(); - if (doctype != null) - { - NamedNodeMap notations = doctype.getNotations(); - Notation notation = (Notation) notations.getNamedItem(name); - if (notation != null) - { - String systemId = notation.getSystemId(); - // XXX absolutize? - if (systemId != null) - { - return systemId; - } - } - } - return ""; - } - - public Expr clone(Object context) - { - UnparsedEntityUriFunction f = new UnparsedEntityUriFunction(); - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - f.setArguments(args2); - return f; - } - -} - diff --git a/libjava/gnu/xml/transform/ValueOfNode.java b/libjava/gnu/xml/transform/ValueOfNode.java deleted file mode 100644 index 88ab166911d..00000000000 --- a/libjava/gnu/xml/transform/ValueOfNode.java +++ /dev/null @@ -1,126 +0,0 @@ -/* ValueOfNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSLT <code>value-of</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ValueOfNode - extends TemplateNode -{ - - final Expr select; - final boolean disableOutputEscaping; - - ValueOfNode(TemplateNode children, TemplateNode next, Expr select, - boolean disableOutputEscaping) - { - super(children, next); - this.select = select; - this.disableOutputEscaping = disableOutputEscaping; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new ValueOfNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - select.clone(stylesheet), - disableOutputEscaping); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Object ret = select.evaluate(context, pos, len); - String value = Expr._string(context, ret); - //System.err.println("value-of: "+context+" "+ select + " -> "+ value); - if (value != null && value.length() > 0) - { - Document doc = (parent instanceof Document) ? - (Document) parent : parent.getOwnerDocument(); - Text textNode = doc.createTextNode(value); - if (disableOutputEscaping) - { - textNode.setUserData("disable-output-escaping", "yes", stylesheet); - } - if (nextSibling != null) - { - parent.insertBefore(textNode, nextSibling); - } - else - { - parent.appendChild(textNode); - } - } - // value-of doesn't process children - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("select="); - buf.append(select); - if (disableOutputEscaping) - { - buf.append(",disableOutputEscaping"); - } - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/WhenNode.java b/libjava/gnu/xml/transform/WhenNode.java deleted file mode 100644 index 8c292fb279b..00000000000 --- a/libjava/gnu/xml/transform/WhenNode.java +++ /dev/null @@ -1,110 +0,0 @@ -/* WhenNode.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A template node representing an XSL <code>when</code> instruction. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class WhenNode - extends TemplateNode -{ - - final Expr test; - - WhenNode(TemplateNode children, TemplateNode next, Expr test) - { - super(children, next); - this.test = test; - } - - TemplateNode clone(Stylesheet stylesheet) - { - return new WhenNode((children == null) ? null : - children.clone(stylesheet), - (next == null) ? null : - next.clone(stylesheet), - test.clone(stylesheet)); - } - - void doApply(Stylesheet stylesheet, QName mode, - Node context, int pos, int len, - Node parent, Node nextSibling) - throws TransformerException - { - Object ret = test.evaluate(context, pos, len); - boolean success = (ret instanceof Boolean) ? - ((Boolean) ret).booleanValue() : - Expr._boolean(context, ret); - if (success) - { - if (children != null) - { - children.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - else - { - if (next != null) - { - next.apply(stylesheet, mode, - context, pos, len, - parent, nextSibling); - } - } - } - - public String toString() - { - StringBuffer buf = new StringBuffer(getClass().getName()); - buf.append('['); - buf.append("test="); - buf.append(test); - buf.append(']'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/transform/WithParam.java b/libjava/gnu/xml/transform/WithParam.java deleted file mode 100644 index 7c3379833ce..00000000000 --- a/libjava/gnu/xml/transform/WithParam.java +++ /dev/null @@ -1,110 +0,0 @@ -/* WithParam.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Collections; -import javax.xml.namespace.QName; -import javax.xml.transform.TransformerException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * A specification for setting a variable or parameter during template - * processing with <code>apply-templates</code> or - * <code>call-template</code>. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class WithParam -{ - - final String name; - final Expr select; - final TemplateNode content; - - WithParam(String name, Expr select) - { - this.name = name; - this.select = select; - content = null; - } - - WithParam(String name, TemplateNode content) - { - this.name = name; - this.content = content; - select = null; - } - - Object getValue(Stylesheet stylesheet, QName mode, - Node context, int pos, int len) - throws TransformerException - { - if (select != null) - { - return select.evaluate(context, pos, len); - } - else - { - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - DocumentFragment fragment = doc.createDocumentFragment(); - content.apply(stylesheet, mode, - context, pos, len, - fragment, null); - return Collections.singleton(fragment); - } - } - - WithParam clone(Stylesheet stylesheet) - { - if (content == null) - { - return new WithParam(name, - select.clone(stylesheet)); - } - else - { - return new WithParam(name, - content.clone(stylesheet)); - } - } - -} diff --git a/libjava/gnu/xml/transform/XSLComparator.java b/libjava/gnu/xml/transform/XSLComparator.java deleted file mode 100644 index 222f370c8b9..00000000000 --- a/libjava/gnu/xml/transform/XSLComparator.java +++ /dev/null @@ -1,124 +0,0 @@ -/* XSLComparator.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.text.Collator; -import org.w3c.dom.Node; -import gnu.xml.xpath.Expr; - -/** - * Comparator for sorting lists of nodes according to a list of sort keys. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class XSLComparator - implements Comparator -{ - - final List sortKeys; - - XSLComparator(List sortKeys) - { - this.sortKeys = sortKeys; - } - - public int compare(Object o1, Object o2) - { - if (o1 instanceof Node && o2 instanceof Node) - { - Node n1 = (Node) o1; - Node n2 = (Node) o2; - for (Iterator i = sortKeys.iterator(); i.hasNext(); ) - { - SortKey sortKey = (SortKey) i.next(); - String k1 = sortKey.key(n1); - String k2 = sortKey.key(n2); - if ("text".equals(sortKey.dataType)) - { - Locale locale = (sortKey.lang == null) ? Locale.getDefault() : - new Locale(sortKey.lang); - Collator collator = Collator.getInstance(locale); - int d = collator.compare(k1, k2); - if (d != 0) - { - switch (sortKey.caseOrder) - { - case SortKey.UPPER_FIRST: - // TODO - break; - case SortKey.LOWER_FIRST: - // TODO - break; - } - if (sortKey.descending) - { - d = -d; - } - return d; - } - } - else if ("number".equals(sortKey.dataType)) - { - double kn1 = Expr._number(n1, k1); - double kn2 = Expr._number(n2, k2); - int d; - if (Double.isNaN(kn1) || Double.isInfinite(kn2)) - { - d = -1; - } - else if (Double.isNaN(kn2) || Double.isInfinite(kn1)) - { - d = 1; - } - else - { - // conversion to int may give 0 for small numbers - d = (kn1 > kn2) ? 1 : (kn1 < kn2) ? -1 : 0; - } - return (sortKey.descending) ? -d : d; - } - } - } - return 0; - } - -} diff --git a/libjava/gnu/xml/transform/XSLURIResolver.java b/libjava/gnu/xml/transform/XSLURIResolver.java deleted file mode 100644 index 2e4e6545a87..00000000000 --- a/libjava/gnu/xml/transform/XSLURIResolver.java +++ /dev/null @@ -1,269 +0,0 @@ -/* XSLURIResolver.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.transform; - -import java.io.File; -import java.io.InputStream; -import java.io.IOException; -import java.io.Reader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.HashMap; -import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.ErrorListener; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamSource; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import gnu.xml.dom.ls.ReaderInputStream; - -/** - * URI resolver for XSLT. - * This resolver parses external entities into DOMSources. It - * maintains a cache of URIs to DOMSources to avoid expensive re-parsing. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class XSLURIResolver - implements URIResolver -{ - - Map lastModifiedCache = new HashMap(); - Map nodeCache = new HashMap(); - DocumentBuilder builder; - URIResolver userResolver; - ErrorListener userListener; - - void setUserResolver(URIResolver userResolver) - { - this.userResolver = userResolver; - } - - void setUserListener(ErrorListener userListener) - { - this.userListener = userListener; - } - - /** - * Clear the cache. - */ - void flush() - { - lastModifiedCache.clear(); - nodeCache.clear(); - } - - public Source resolve(String href, String base) - throws TransformerException - { - Source source = null; - if (userResolver != null) - { - source = userResolver.resolve(base, href); - } - return resolveDOM(source, href, base); - } - - DOMSource resolveDOM(Source source, String base, String href) - throws TransformerException - { - if (source != null && source instanceof DOMSource) - { - return (DOMSource) source; - } - String systemId = (source == null) ? null : source.getSystemId(); - long lastModified = 0L, lastLastModified = 0L; - - try - { - URL url = resolveURL(systemId, base, href); - Node node = null; - InputStream in = null; - if (source instanceof StreamSource) - { - StreamSource ss = (StreamSource) source; - in = ss.getInputStream(); - if (in == null) - { - Reader reader = ss.getReader(); - if (reader != null) - { - in = new ReaderInputStream(reader); - } - } - } - if (in == null && url != null) - { - systemId = url.toString(); - node = (Node) nodeCache.get(systemId); - // Is the resource up to date? - URLConnection conn = url.openConnection(); - Long llm = (Long) lastModifiedCache.get(systemId); - if (llm != null) - { - lastLastModified = llm.longValue(); - conn.setIfModifiedSince(lastLastModified); - } - conn.connect(); - lastModified = conn.getLastModified(); - if (node != null && - lastModified > 0L && - lastModified <= lastLastModified) - { - // Resource unchanged - return new DOMSource(node, systemId); - } - else - { - // Resource new or modified - in = conn.getInputStream(); - nodeCache.put(systemId, node); - lastModifiedCache.put(systemId, new Long(lastModified)); - } - } - InputSource input = new InputSource(in); - input.setSystemId(systemId); - DocumentBuilder builder = getDocumentBuilder(); - node = builder.parse(input); - return new DOMSource(node, systemId); - } - catch (IOException e) - { - throw new TransformerException(e); - } - catch (SAXException e) - { - throw new TransformerException(e); - } - } - - URL resolveURL(String systemId, String base, String href) - throws IOException - { - URL url = null; - try - { - if (systemId != null) - { - try - { - url = new URL(systemId); - } - catch (MalformedURLException e) - { - // Try building from base + href - } - } - if (url == null) - { - if (base != null) - { - URL baseURL = new URL(base); - url = new URL(baseURL, href); - } - else if (href != null) - { - url = new URL(href); - } - } - return url; - } - catch (MalformedURLException e) - { - // Fall back to local filesystem - File file = null; - if (href == null) - { - href = systemId; - } - if (base != null) - { - int lsi = base.lastIndexOf(File.separatorChar); - if (lsi != -1 && lsi < base.length() - 1) - { - base = base.substring(0, lsi); - } - File baseFile = new File(base); - file = new File(baseFile, href); - } - else if (href != null) - { - file = new File(href); - } - return (file == null) ? null : file.toURL(); - } - } - - DocumentBuilder getDocumentBuilder() - throws TransformerException - { - try - { - if (builder == null) - { - DocumentBuilderFactory factory = - DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - factory.setExpandEntityReferences(true); - builder = factory.newDocumentBuilder(); - } - if (userResolver != null) - { - builder.setEntityResolver(new URIResolverEntityResolver(userResolver)); - } - if (userListener != null) - { - builder.setErrorHandler(new ErrorListenerErrorHandler(userListener)); - } - return builder; - } - catch (Exception e) - { - throw new TransformerException(e); - } - } - -} - diff --git a/libjava/gnu/xml/util/DoParse.java b/libjava/gnu/xml/util/DoParse.java deleted file mode 100644 index 5da086ed8f9..00000000000 --- a/libjava/gnu/xml/util/DoParse.java +++ /dev/null @@ -1,300 +0,0 @@ -/* DoParse.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.io.IOException; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -import gnu.xml.pipeline.EventConsumer; -import gnu.xml.pipeline.EventFilter; -import gnu.xml.pipeline.NSFilter; -import gnu.xml.pipeline.PipelineFactory; -import gnu.xml.pipeline.TeeConsumer; -import gnu.xml.pipeline.ValidationConsumer; -import gnu.xml.pipeline.WellFormednessFilter; - -/** - * This class provides a driver which may be invoked from the command line - * to process a document using a SAX2 parser and a specified XML processing - * pipeline. - * This facilitates some common types of command line tools, such as parsing an - * XML document in order test it for well formedness or validity. - * - * <p>The SAX2 XMLReaderFactory should return a SAX2 XML parser which - * supports both of the standardized extension handlers (for declaration - * and lexical events). That parser will be used to produce events. - * - * <p>The first parameter to the command gives the name of the document that - * will be given to that processor. If it is a file name, it is converted - * to a URL first. - * - * <p>The second parameter describes a simple processing pipeline, and will - * be used as input to {@link gnu.xml.pipeline.PipelineFactory} - * methods which identify the processing to be done. Examples of such a - * pipeline include <pre> - * - * nsfix | validate <em>to validate the input document </em> - * nsfix | write ( stdout ) <em>to echo the file as XML text</em> - * dom | nsfix | write ( stdout ) <em>parse into DOM, print the result</em> - * </pre> - * - * <p> Relatively complex pipelines can be described on the command line, but - * not all interesting ones will require as little configuration as can be done - * in that way. Put filters like "nsfix", perhaps followed by "validate", - * at the front of the pipeline so they can be optimized out if a parser - * supports those modes natively. - * - * <p> If the parsing is aborted for any reason, the JVM will exit with a - * failure code. If a validating parse was done then both validation and - * well formedness errors will cause a failure. A non-validating parse - * will report failure on well formedness errors. - * - * @see gnu.xml.pipeline.PipelineFactory - * - * @author David Brownell - */ -final public class DoParse -{ - private DoParse () { /* no instances allowed */ } - - // first reported nonrecoverable error - private static SAXParseException fatal; - - // error categories - private static int errorCount; - private static int fatalCount; - - /** - * Command line invoker for this class; pass a filename or URL - * as the first argument, and a pipeline description as the second. - * Make sure to use filters to condition the input to stages that - * require it; an <em>nsfix</em> filter will be a common requirement, - * to restore syntax that SAX2 parsers delete by default. Some - * conditioning filters may be eliminated by setting parser options. - * (For example, "nsfix" can set the "namespace-prefixes" feature to - * a non-default value of "true". In the same way, "validate" can set - * the "validation" feature to "true".) - */ - public static void main (String argv []) - throws IOException - { - int exitStatus = 1; - - if (argv.length != 2) { - System.err.println ("Usage: DoParse [filename|URL] pipeline-spec"); - System.err.println ("Example pipeline specs:"); - System.err.println (" 'nsfix | validate'"); - System.err.println ( - " ... restore namespace syntax, validate"); - System.err.println (" 'nsfix | write ( stdout )'"); - System.err.println ( - " ... restore namespace syntax, write to stdout as XML" - ); - System.exit (1); - } - - try { - // - // Get input source for specified document (or try ;-) - // - argv [0] = Resolver.getURL (argv [0]); - InputSource input = new InputSource (argv [0]); - - // - // Get the producer, using the system default parser (which - // can be overridden for this particular invocation). - // - // And the pipeline, using commandline options. - // - XMLReader producer; - EventConsumer consumer; - - producer = XMLReaderFactory.createXMLReader (); - - // - // XXX pipeline factory now has a pre-tokenized input - // method, use it ... that way at least some params - // can be written using quotes (have spaces, ...) - // - consumer = PipelineFactory.createPipeline (argv [1]); - - // - // XXX want commandline option for tweaking error handler. - // Want to be able to present warnings. - // - producer.setErrorHandler (new MyErrorHandler ()); - - // XXX need facility enabling resolving to local DTDs - - // - // Parse. The pipeline may get optimized a bit, so we - // can't always fail cleanly for validation without taking - // a look at the filter stages. - // - EventFilter.bind (producer, consumer); - producer.parse (input); - - try { - if (producer.getFeature ( - "http://org.xml/sax/features/validation")) - exitStatus = ((errorCount + fatalCount) > 0) ? 1 : 0; - else if (fatalCount == 0) - exitStatus = 0; - } catch (SAXException e) { - if (hasValidator (consumer)) - exitStatus = ((errorCount + fatalCount) > 0) ? 1 : 0; - else if (fatalCount == 0) - exitStatus = 0; - } - - } catch (java.net.MalformedURLException e) { - System.err.println ("** Malformed URL: " + e.getMessage ()); - System.err.println ("Is '" + argv [0] + "' a non-existent file?"); - e.printStackTrace (); - // e.g. FNF - - } catch (SAXParseException e) { - if (e != fatal) { - System.err.print (printParseException ("Parsing Aborted", e)); - e.printStackTrace (); - if (e.getException () != null) { - System.err.println ("++ Wrapped exception:"); - e.getException ().printStackTrace (); - } - } - - } catch (SAXException e) { - Exception x = e; - if (e.getException () != null) - x = e.getException (); - x.printStackTrace (); - - } catch (Throwable t) { - t.printStackTrace (); - } - - System.exit (exitStatus); - } - - // returns true if saw a validator (before end or unrecognized node) - // false otherwise - private static boolean hasValidator (EventConsumer e) - { - if (e == null) - return false; - if (e instanceof ValidationConsumer) - return true; - if (e instanceof TeeConsumer) { - TeeConsumer t = (TeeConsumer) e; - return hasValidator (t.getFirst ()) - || hasValidator (t.getRest ()); - } - if (e instanceof WellFormednessFilter - || e instanceof NSFilter - ) - return hasValidator (((EventFilter)e).getNext ()); - - // else ... gee, we can't know. Assume not. - - return false; - } - - static class MyErrorHandler implements ErrorHandler - { - // dump validation errors, but continue - public void error (SAXParseException e) - throws SAXParseException - { - errorCount++; - System.err.print (printParseException ("Error", e)); - } - - public void warning (SAXParseException e) - throws SAXParseException - { - // System.err.print (printParseException ("Warning", e)); - } - - // try to continue fatal errors, in case a parser reports more - public void fatalError (SAXParseException e) - throws SAXParseException - { - fatalCount++; - if (fatal == null) - fatal = e; - System.err.print (printParseException ("Nonrecoverable Error", e)); - } - } - - static private String printParseException ( - String label, - SAXParseException e - ) { - StringBuffer buf = new StringBuffer (); - int temp; - - buf.append ("** "); - buf.append (label); - buf.append (": "); - buf.append (e.getMessage ()); - buf.append ('\n'); - if (e.getSystemId () != null) { - buf.append (" URI: "); - buf.append (e.getSystemId ()); - buf.append ('\n'); - } - if ((temp = e.getLineNumber ()) != -1) { - buf.append (" line: "); - buf.append (temp); - buf.append ('\n'); - } - if ((temp = e.getColumnNumber ()) != -1) { - buf.append (" char: "); - buf.append (temp); - buf.append ('\n'); - } - - return buf.toString (); - } -} diff --git a/libjava/gnu/xml/util/DomParser.java b/libjava/gnu/xml/util/DomParser.java deleted file mode 100644 index b28b6103b70..00000000000 --- a/libjava/gnu/xml/util/DomParser.java +++ /dev/null @@ -1,804 +0,0 @@ -/* DomParser.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.util.Enumeration; -import java.util.Locale; - -import org.xml.sax.*; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.NamespaceSupport; -import org.xml.sax.ext.DeclHandler; -import org.xml.sax.ext.DefaultHandler2; -import org.xml.sax.ext.LexicalHandler; - -import org.w3c.dom.*; - - -/** - * This parser emits SAX2 parsing events as it traverses a DOM tree, using - * any conformant implementation of DOM. It exposes all SAX1 features, - * and the following SAX2 features and properties (as - * identified by standard URIs which are not fully provided here). Note - * that if a Level 1 DOM implementation is given, then this behaves as if - * namespaces were disabled, and namespace prefixes were enabled. </p> - * - * <table border="1" width='100%' cellpadding='3' cellspacing='0'> - * <tr bgcolor='#ccccff'> - * <th><font size='+1'>Name</font></th> - * <th><font size='+1'>Notes</font></th></tr> - * - * <tr><td colspan=2><center><em>Features ... URL prefix is - * <b>http://xml.org/sax/features/</b></em></center></td></tr> - * - * <tr><td>(URL)/external-general-entities</td> - * <td>false (does no parsing)</td></tr> - * <tr><td>(URL)/external-parameter-entities</td> - * <td>false (does no parsing)</td></tr> - * <tr><td>(URL)/namespaces</td> - * <td>Value is fixed at <em>true</em></td></tr> - * <tr><td>(URL)/namespace-prefixes</td> - * <td>Value is settable, defaulting to <em>false</em> - * (<code>xmlns</code> attributes hidden, and names aren't prefixed) - * </td></tr> - * <tr><td>(URL)/string-interning</td> - * <td>Value is fixed at <em>false</em> (DOM provides no - * guarantees as to interning)</td></tr> - * <tr><td>(URL)/validation</td> - * <td>false (does no parsing)</td></tr> - * <tr><td>(URL)/lexical-handler/parameter-entities</td> - * <td>false (DOM doesn't do parameter entities)</td></tr> - * - * <tr><td colspan=2><center><em>Properties ... URL prefix is - * <b>http://xml.org/sax/properties/</b></em></center></td></tr> - * - * - * <tr><td>(URL)/dom-node</td> - * <td>This property may be set before parsing to hold a DOM - * <em>Document</em> node; any arguments given to <em>parse</em> - * methods are ignored. When retrieved - * during a parse, this value contains the "current" DOM node. - * </td></tr> - * <tr><td>(URL)/declaration-handler</td> - * <td>A declaration handler may be provided. Declaration of external - * general entities is exposed, but not parameter entities; none of the - * entity names reported here will begin with "%". </td></tr> - * <tr><td>(URL)/lexical-handler</td> - * <td>A lexical handler may be provided. While the start and end of - * any external subset are reported, expansion of other parameter - * entities (e.g. inside attribute list declarations) is not exposed. - * Expansion of general entities within attributes is also not exposed - * (see below).</td></tr> - * </table> - * - * <P> The consequences of modifying a DOM document tree as it is being walked - * by this "parser" are unspecified; don't do it! </P> - * - * @author David Brownell - */ -final public class DomParser implements XMLReader -{ - // Stuff used internally to route events correctly - private DefaultHandler2 defaultHandler = new DefaultHandler2 (); - - // per-parse SAX stuff - private ContentHandler contentHandler = defaultHandler; - private DTDHandler dtdHandler = defaultHandler; - private DeclHandler declHandler = defaultHandler; - private LexicalHandler lexicalHandler = defaultHandler; - - // shared context - private ErrorHandler errHandler = defaultHandler; - private EntityResolver resolver = defaultHandler; - private Locale locale = Locale.getDefault (); - - // parser state - private Node start; - private Node current; - private boolean isL2; - private boolean showNamespaces = true; - private boolean showXML1_0 = false; - private NamespaceSupport prefixStack = new NamespaceSupport (); - private boolean isDocument; - - - /** - * Constructs an unitialized <b>SAX2</b> parser. - */ - public DomParser () { - } - - /** - * Constructs an <b>SAX2</b> parser initialized to traverse the specified - * DOM tree. If the node is a document, the startDocument() and - * endDocument() calls bracket the calls exposing children. - */ - public DomParser (Node node) { - setStart (node); - } - - - // stuff that most components in an application should be sharing: - // resolver and error locale. - - /** - * <b>SAX2</b>: Returns the object used when resolving external - * entities during parsing (both general and parameter entities). - */ - public EntityResolver getEntityResolver () - { - return resolver; - } - - /** - * <b>SAX1</b>: Provides an object which may be used when resolving external - * entities during parsing (both general and parameter entities). - */ - public void setEntityResolver (EntityResolver resolver) - { - if (resolver == null) - resolver = defaultHandler; - this.resolver = resolver; - } - - /** - * <b>SAX1</b>: Identifies the locale which the parser should use for the - * diagnostics it provides. - * - * @exception SAXException as defined in the specification for - * <em>org.xml.sax.Parser.setLocale()</em> - */ - public void setLocale (Locale locale) - throws SAXException - { - if (locale == null) - locale = Locale.getDefault (); - this.locale = locale; - } - - - // different modules will tend to handle error handling the same, - // but it may not be the same through the whole app - - /** - * <b>SAX2</b>: Returns the object used to receive callbacks for XML - * errors of all levels (fatal, nonfatal, warning). - */ - public ErrorHandler getErrorHandler () - { - return errHandler; - } - - /** - * <b>SAX1</b>: Provides an object which receives callbacks for XML errors - * of all levels (fatal, nonfatal, warning). - */ - public void setErrorHandler (ErrorHandler handler) - { - if (handler == null) - handler = defaultHandler; - errHandler = handler; - } - - - // stuff different parts of a module will handle differently - - /** - * <b>SAX2</b>: Returns the object used to report the logical - * content of an XML document. - */ - public ContentHandler getContentHandler () - { - return contentHandler; - } - - /** - * <b>SAX2</b>: Assigns the object used to report the logical - * content of an XML document. - */ - public void setContentHandler (ContentHandler handler) - { - if (handler == null) - handler = defaultHandler; - contentHandler = handler; - } - - /** - * <b>SAX2</b>: Returns the object used to process declarations related - * to notations and unparsed entities. - */ - public DTDHandler getDTDHandler () - { - return dtdHandler; - } - - /** - * <b>SAX1</b>: Provides an object which may be used to intercept - * declarations related to notations and unparsed entities. - */ - public void setDTDHandler (DTDHandler handler) - { - if (handler == null) - handler = defaultHandler; - dtdHandler = handler; - } - - - /** - * <b>SAX1</b>: Parses the previously provided DOM document (the - * input parameter is ignored). When this returns, that same - * document may be parsed again without needing a "reset". - * - * @param uri ignored (pass an empty string) - * @exception SAXException as defined in the specification for - * <em>org.xml.sax.Parser.parse()</em> - */ - public void parse (String uri) throws SAXException - { - parse (); - } - - /** - * <b>SAX1</b>: Parses the previously provided DOM document (the - * input parameter is ignored). When this returns, that same - * document may be parsed again without needing a "reset". - * - * @param input ignored - * @exception SAXException as defined in the specification for - * <em>org.xml.sax.Parser.parse()</em> - */ - public void parse (InputSource input) throws SAXException - { - parse (); - } - - private void parse () throws SAXException - { - try { - walk (); - } finally { - if (isDocument) - contentHandler.endDocument (); - current = null; - prefixStack.reset (); - } - } - - private boolean getIsL2 (Node node) - { - DOMImplementation impl; - Document doc; - - if (node instanceof Document) - doc = (Document) node; - else - doc = node.getOwnerDocument (); - if (doc == null) - throw new RuntimeException ("? unowned node - L2 DTD ?"); - impl = doc.getImplementation (); - return impl.hasFeature ("XML", "2.0"); - } - - - private static final String FEATURES = "http://xml.org/sax/features/"; - private static final String HANDLERS = "http://xml.org/sax/properties/"; - - /** - * <b>SAX2</b>: Tells whether this parser supports the specified feature. - */ - public boolean getFeature (String name) - throws SAXNotRecognizedException, SAXNotSupportedException - { - // basically, none are relevant -- they relate more to - // parsing than to walking a "parse tree". - - // FIXME: DOM feature to expose interning? - - if ((FEATURES + "validation").equals (name) - || (FEATURES + "external-general-entities") - .equals (name) - || (FEATURES + "external-parameter-entities") - .equals (name) - || (FEATURES + "string-interning").equals (name) - ) - return false; - - if ((FEATURES + "namespaces").equals (name)) - return showNamespaces; - if ((FEATURES + "namespace-prefixes").equals (name)) - return showXML1_0; - - throw new SAXNotRecognizedException (name); - } - - /** - * <b>SAX2</b>: Returns the specified property. At this time only - * the declaration and lexical handlers, and current the "DOM" node, - * are supported. - */ - public Object getProperty (String name) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if ((HANDLERS + "declaration-handler").equals (name)) - return declHandler == defaultHandler ? null : declHandler; - if ((HANDLERS + "lexical-handler").equals (name)) - return lexicalHandler == defaultHandler ? null : lexicalHandler; - - if ((HANDLERS + "dom-node").equals (name)) - return current; - - // unknown properties - throw new SAXNotRecognizedException (name); - } - - /** - * <b>SAX2</b>: Sets the state of features supported in this parser. - * Only the namespace support features are mutable. - */ - public void setFeature (String name, boolean state) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if (current != null) - throw new IllegalStateException ("feature change midparse"); - - boolean value = getFeature (name); - - if (value == state) - return; - - if ((FEATURES + "namespaces").equals (name)) { - if (!showXML1_0 && state == false) - throw new SAXNotSupportedException ("Illegal namespace " - + "processing configuration"); - showNamespaces = state; - return; - } - if ((FEATURES + "namespace-prefixes").equals (name)) { - if (!showNamespaces && state == false) - throw new SAXNotSupportedException ("Illegal namespace " - + "processing configuration"); - showXML1_0 = state; - return; - } - - throw new SAXNotSupportedException (name); - } - - /** - * <b>SAX2</b>: Assigns the specified property. At this time only - * declaration and lexical handlers, and the initial DOM document, are - * supported. These must not be changed to values of the wrong type. - * Like SAX1 handlers, these handlers may be changed at any time. - * Like SAX1 input source or document URI, the initial DOM document - * may not be changed during a parse. - */ - public void setProperty (String name, Object state) - throws SAXNotRecognizedException, SAXNotSupportedException - { - if ((HANDLERS + "declaration-handler").equals (name)) { - if (!(state instanceof DeclHandler || state == null)) - throw new SAXNotSupportedException (name); - declHandler = (DeclHandler) state; - return; - } - - if ((HANDLERS + "lexical-handler").equals (name)) { - if (!(state instanceof LexicalHandler || state == null)) - throw new SAXNotSupportedException (name); - lexicalHandler = (LexicalHandler) state; - return; - } - - if ((HANDLERS + "dom-node").equals (name)) { - if (state == null || state instanceof Node) { - if (current != null) - throw new SAXNotSupportedException ( - "property is readonly during parse: " + name); - setStart ((Node) state); - return; - } - throw new SAXNotSupportedException ("not a DOM Node"); - } - - // unknown properties - throw new SAXNotRecognizedException (name); - } - - private void setStart (Node property) - { - start = property; - if (start != null) { - isL2 = getIsL2 (start); - isDocument = (start instanceof Document); - } - } - - // - // Non-recursive walk, using DOM state when backtracking is needed - // - private void walk () - throws SAXException - { - int type; - NamedNodeMap nodes; - int length; - AttributesImpl attrs = new AttributesImpl (); - char chars []; - String ns, local; - - synchronized (this) { - if (current != null) - throw new IllegalStateException ("already walking tree"); - - // JVM guarantees assignments are atomic; so no other - // thread could get this far till this walk's done. - current = start; - } - - for (;;) { - type = current.getNodeType (); - - // - // First, visit the current node, including any "start" calls - // - switch (type) { - - case Node.DOCUMENT_NODE: - contentHandler.startDocument (); - break; - - case Node.ELEMENT_NODE: - nodes = current.getAttributes (); - length = nodes.getLength (); - prefixStack.pushContext (); - for (int i = 0; i < length; i++) { - Attr attr = (Attr) nodes.item (i); - String name = attr.getNodeName (); - - if (showNamespaces && name.startsWith ("xmlns")) { - String prefix; - String uri; - - // NOTE: DOM L2 (CR2+ and REC) violate the - // Namespaces REC, treat "xmlns" like a strange - // attribute instead of a magic token - if ("xmlns".equals (name)) - prefix = ""; - else - prefix = name.substring (6); - uri = attr.getNodeValue (); - - prefixStack.declarePrefix (prefix, uri); - contentHandler.startPrefixMapping (prefix, uri); - - if (!showXML1_0) - continue; - } - - // - // NOTE: DOM doesn't record the attribute type info - // which SAX exposes; so this always reports CDATA. - // - // NOTE: SAX doesn't expose the isSpecified info which - // DOM exposes; that's discarded here. Similarly with - // the information DOM hides inside itself about what - // the default values for an attribute are. - // - if (showNamespaces) { - if (isL2) { - if ((ns = attr.getNamespaceURI ()) == null) - ns = ""; - // Note: SAX2 and DOM handle "local" names - // differently - if ((local = attr.getLocalName ()) == null) - local = name; - } else { -// XXX - throw new RuntimeException ( - "NYI, ns lookup when parsing L1 DOM"); - } - } else - ns = local = ""; - attrs.addAttribute (ns, local, name, - "CDATA", attr.getNodeValue ()); - } - if (showNamespaces) { - if (isL2) { - if ((ns = current.getNamespaceURI ()) == null) - ns = ""; - // Note: SAX2 and DOM handle "local" names differently - if ((local = current.getLocalName ()) == null) - local = current.getNodeName (); - } else { -// XXX - throw new RuntimeException ( - "NYI, ns lookup when parsing L1 DOM"); - } - } else - ns = local = ""; - contentHandler.startElement (ns, local, - current.getNodeName (), attrs); - if (length != 0) - attrs.clear (); - break; - - case Node.CDATA_SECTION_NODE: - lexicalHandler.startCDATA (); - chars = current.getNodeValue ().toCharArray (); - contentHandler.characters (chars, 0, chars.length); - lexicalHandler.endCDATA (); - break; - - case Node.COMMENT_NODE: - chars = current.getNodeValue ().toCharArray (); - lexicalHandler.comment (chars, 0, chars.length); - break; - - case Node.DOCUMENT_TYPE_NODE: - { - DocumentType doctype = (DocumentType) current; - - // - // Only DOM L2 supports recreating even some DTDs in full. - // - if (isL2) { - lexicalHandler.startDTD (doctype.getName (), - doctype.getPublicId (), - doctype.getSystemId ()); - } else - lexicalHandler.startDTD (doctype.getName (), - null, null); - - // - // The only sure way to recreate is to provide both the - // internal and external subsets. Otherwise, only part - // of the job can be done ... because from the DTD, DOM - // discards both the critical data, like the attribute and - // element declarations, as well as the PIs and comments - // that are used to hold their documentation. - // - // Even the entity and notation declarations that it can - // expose can't be recorded without proprietary extensions. - // - // We construct a comment to tell what we know about how - // (in)complete this particular really DTD is. - // - { - String message; - char buf []; - - // - // Though DOM L2 lets the whole doctype be recreated, - // SAX2 can't represent it (input or output). - // So this will be the typical case. - // - if (isL2 && doctype.getInternalSubset () != null) - message = - " Full DTD known; can't be shown using SAX2. "; - - // - // Otherwise, we'll concoct a partial DTD. If there's - // any more data here at all, it was provided using a - // (proprietary) extension to DOM. - // - else - message = - " This DTD was was recreated using incomplete DOM L2 records. "; - - buf = message.toCharArray (); - lexicalHandler.comment (buf, 0, buf.length); - } - - // report notations first - nodes = doctype.getNotations (); - length = nodes.getLength (); - for (int i = 0; i < length; i++) { - Notation notation = (Notation) nodes.item (i); - dtdHandler.notationDecl ( - notation.getNodeName (), - notation.getPublicId (), - notation.getSystemId ()); - } - - // then parsed and unparsed external general entities - nodes = doctype.getEntities (); - length = nodes.getLength (); - for (int i = 0; i < length; i++) { - Entity entity = (Entity) nodes.item (i); - String notation = entity.getNotationName (); - - if (notation != null) - dtdHandler.unparsedEntityDecl ( - entity.getNodeName (), - entity.getPublicId (), - entity.getSystemId (), - notation); - else if (entity.getSystemId () != null) - declHandler.externalEntityDecl ( - entity.getNodeName (), - entity.getPublicId (), - entity.getSystemId ()); - - // - // NOTE: DOM doesn't clearly provide internal - // entity support; but in case someone tries to - // fudge such support, we defend ourselves above. - // - // NOTE: DOM doesn't expose parameter entities - // (thank you thank you thank you thank you) - // - } - - // - // NOTE: DOM (levels 1 and 2) doesn't expose real - // typing information (element or attribute decls), - // as exposed by SAX2 declaration handlers. - // - lexicalHandler.endDTD (); - } - break; - - case Node.ENTITY_REFERENCE_NODE: - // this isn't done except (a) in content, and - // (b) not within a start tag (att value) - lexicalHandler.startEntity (current.getNodeName ()); - break; - - case Node.PROCESSING_INSTRUCTION_NODE: - contentHandler.processingInstruction ( - current.getNodeName (), current.getNodeValue ()); - break; - - case Node.TEXT_NODE: - chars = current.getNodeValue ().toCharArray (); - contentHandler.characters (chars, 0, chars.length); - break; - - default: - // e.g. fragments, entities, notations, attributes - throw new SAXException ("Illegal DOM Node type in Document: " - + current.getNodeType ()); - } - - // - // Then, pick the next node to visit. If the next node isn't - // a child, an "end" call may be needed before moving on. - // If there's no next node, we're done. - // - Node next; - - switch (type) { - case Node.DOCUMENT_NODE: - case Node.ELEMENT_NODE: - case Node.ENTITY_REFERENCE_NODE: - // - // For elements that can have children, visit those - // children before any siblings (i.e. depth first) - // and after visiting this node (i.e. preorder) - // - next = current.getFirstChild (); - if (next != null) { - current = next; - break; - } - // - // Else treat this like other childless nodes, but - // handle this node's "end" immediately. - // - callEnd (current); - - // FALLTHROUGH - - case Node.CDATA_SECTION_NODE: - case Node.COMMENT_NODE: - case Node.DOCUMENT_TYPE_NODE: - case Node.ENTITY_NODE: - case Node.PROCESSING_INSTRUCTION_NODE: - case Node.TEXT_NODE: - // - // Use next sibling, if there is one. - // Else, climb up a level (calling "end") - // until we find an ancestral sibling - // or until we we climb off the top (FINISH) - // - for (;;) { - if ((next = current.getNextSibling ()) != null) - break; - current = current.getParentNode (); - if (current == null || current == start) - return; - callEnd (current); - } - current = next; - break; - - default: - throw new SAXException ( - "Illegal DOM Node type found: " + current.getNodeType ()); - } - } - } - - private void callEnd (Node node) throws SAXException - { - switch (node.getNodeType ()) { - // only these three container types may ever be found - // directly inside a Document. - case Node.DOCUMENT_NODE: - // for SAX conformance, endDocument must always - // be called ... it's done in a "finally" clause) - return; - - case Node.ELEMENT_NODE: - if (showNamespaces) { - if (isL2) - contentHandler.endElement ( - node.getNamespaceURI (), - node.getLocalName (), - node.getNodeName ()); - else -// XXX - throw new RuntimeException ( - "NYI, ns lookup when parsing L1 DOM"); - for (Enumeration e = prefixStack.getDeclaredPrefixes (); - e.hasMoreElements (); - ) { - contentHandler.endPrefixMapping ((String) e.nextElement ()); - } - } else - contentHandler.endElement ("", "", node.getNodeName ()); - prefixStack.popContext (); - return; - - case Node.ENTITY_REFERENCE_NODE: - // see above -- in content, outside start tags. - lexicalHandler.endEntity (node.getNodeName ()); - return; - - // these can be given at the top level - case Node.DOCUMENT_FRAGMENT_NODE: - case Node.ATTRIBUTE_NODE: - return; - - default: - throw new SAXException ( - "Illegal DOM container type found: " - + current.getNodeType ()); - } - } -} diff --git a/libjava/gnu/xml/util/Resolver.java b/libjava/gnu/xml/util/Resolver.java deleted file mode 100644 index e84b5ade106..00000000000 --- a/libjava/gnu/xml/util/Resolver.java +++ /dev/null @@ -1,263 +0,0 @@ -/* Resolver.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.io.File; -import java.io.IOException; -import java.util.Dictionary; - -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Utility implementation of a SAX resolver, which can be used to improve - * network utilization of SAX based XML components. It does this by - * supporting local caches of external entities. - * SAX parsers <em>should</em> use such local caches when possible. - * - * @see XCat - */ -public class Resolver implements EntityResolver, Cloneable -{ - /** - * Updates a dictionary used to map PUBLIC identifiers to file names, - * so that it uses the mappings in a specified directory. - * - * @param mappings Array of string pairs, where the first member - * of each pair is a PUBLIC identifier and the second is the - * name of a file, relative to the specified directory. - * @param directory File holding the specified files. - */ - public static void addDirectoryMapping ( - Dictionary table, - String mappings [][], - File directory - ) throws IOException - { - for (int i = 0; i < mappings.length; i++) { - File file = new File (directory, mappings [i][1]); - String temp; - - if (!file.exists ()) // ?? log a warning ?? - continue; - - temp = fileToURL (file); - table.put (mappings [i][0], temp); - } - } - - // FIXME: these *URL routines don't quite belong here, except - // that they're all in the same spirit of making it easy to - // use local filesystem URIs with XML parsers. - - /** - * Provides the URL for a named file, without relying on the JDK 1.2 - * {@link java.io.File#toURL File.toURL}() utility method. - * - * @param filename the file name to convert. Relative file names - * are resolved the way the JVM resolves them (current to the - * process-global current working directory). - * - * @exception IOException if the file does not exist - */ - public static String fileNameToURL (String filename) - throws IOException - { - return fileToURL (new File (filename)); - } - - /** - * Provides the URL for a file, without relying on the JDK 1.2 - * {@link java.io.File#toURL File.toURL}() utility method. - * - * @param f the file to convert. Relative file names - * are resolved the way the JVM resolves them (current to the - * process-global current working directory). - * - * @exception IOException if the file does not exist - */ - public static String fileToURL (File f) - throws IOException - { - String temp; - - // NOTE: the javax.xml.parsers.DocumentBuilder and - // javax.xml.transform.stream.StreamSource versions - // of this don't have this test. Some JVM versions - // don't report this error sanely through URL code. - if (!f.exists ()) - throw new IOException ("no such file: " + f.getName ()); - - // FIXME: getAbsolutePath() seems buggy; I'm seeing components - // like "/foo/../" which are clearly not "absolute" - // and should have been resolved with the filesystem. - - // Substituting "/" would be wrong, "foo" may have been - // symlinked ... the URL code will make that change - // later, so that things can get _really_ broken! - - temp = f.getAbsolutePath (); - - if (File.separatorChar != '/') - temp = temp.replace (File.separatorChar, '/'); - if (!temp.startsWith ("/")) - temp = "/" + temp; - if (!temp.endsWith ("/") && f.isDirectory ()) - temp = temp + "/"; - return "file:" + temp; - } - - - /** - * Returns a URL string. Note that if a malformed URL is provided, or - * the parameter names a nonexistent file, the resulting URL may be - * malformed. - * - * @param fileOrURL If this is the name of a file which exists, - * then its URL is returned. Otherwise the argument is returned. - */ - public static String getURL (String fileOrURL) - { - try { - return fileNameToURL (fileOrURL); - } catch (Exception e) { - return fileOrURL; - } - } - - - - // note: cloneable, this is just copied; unguarded against mods - private Dictionary pubidMapping; - - /** - * Constructs a resolver which understands how to map PUBLIC identifiers - * to other URIs, typically for local copies of standard DTD components. - * - * @param dictionary maps PUBLIC identifiers to URIs. This is not - * copied; subsequent modifications will be reported through the - * resolution operations. - */ - public Resolver (Dictionary dict) - { pubidMapping = dict; } - - - // FIXME: want notion of a "system default" resolver, presumably - // loaded with all sorts of useful stuff. At the same time need - // a notion of resolver chaining (failure --> next) so that subsystems - // can set up things that won't interfere with other ones. - - /** - * This parses most MIME content type strings that have <em>charset=...</em> - * encoding declarations to and returns the specified encoding. This - * conforms to RFC 3023, and is useful when constructing InputSource - * objects from URLConnection objects or other objects using MIME - * content typing. - * - * @param contentType the MIME content type that will be parsed; must - * not be null. - * @return the appropriate encoding, or null if the content type is - * not text and there's no <code>charset=...</code> attribute - */ - static public String getEncoding (String contentType) - { - // currently a dumb parsing algorithm that works "mostly" and handles - // ..anything...charset=ABC - // ..anything...charset=ABC;otherAttr=DEF - // ..anything...charset=ABC (comment);otherAttr=DEF - // ..anything...charset= "ABC" (comment);otherAttr=DEF - - int temp; - String encoding; - String defValue = null; - - if (contentType.startsWith ("text/")) - defValue = contentType.startsWith ("text/html") - ? "ISO-8859-1" : "US-ASCII"; - - // Assumes 'charset' is only an attribute name, not part - // of a value, comment, or other attribute name - // ALSO assumes no escaped values like "\;" or "\)" - if ((temp = contentType.indexOf ("charset")) != -1) { - // strip out everything up to '=' ... - temp = contentType.indexOf ('=', temp); - if (temp == -1) - return defValue; - encoding = contentType.substring (temp + 1); - // ... and any subsequent attributes - if ((temp = encoding.indexOf (';')) != -1) - encoding = encoding.substring (0, temp); - // ... and any comments after value - if ((temp = encoding.indexOf ('(')) != -1) - encoding = encoding.substring (0, temp); - // ... then whitespace, and any (double) quotes - encoding = encoding.trim (); - if (encoding.charAt (0) == '"') - encoding = encoding.substring (1, encoding.length () - 1); - } else - encoding = defValue; - return encoding; - } - - - /** - * Uses a local dictionary of public identifiers to resolve URIs, - * normally with the goal of minimizing network traffic or latencies. - */ - public InputSource resolveEntity (String publicId, String systemId) - throws IOException, SAXException - { - InputSource retval = null; - String uri; - - if (publicId != null - && ((uri = (String) pubidMapping.get (publicId)) != null)) { - retval = new InputSource (uri); - retval.setPublicId (publicId); - } - - // Could do URN resolution here - - // URL resolution always done by parser - - // FIXME: chain to "next" resolver - - return retval; - } -} diff --git a/libjava/gnu/xml/util/SAXNullTransformerFactory.java b/libjava/gnu/xml/util/SAXNullTransformerFactory.java deleted file mode 100644 index 81ad8231270..00000000000 --- a/libjava/gnu/xml/util/SAXNullTransformerFactory.java +++ /dev/null @@ -1,676 +0,0 @@ -/* SAXNullTransformerFactory.java -- - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.Hashtable; -import java.util.Properties; - -import gnu.xml.dom.Consumer; -import gnu.xml.dom.DomDocument; -import gnu.xml.pipeline.DomConsumer; -import gnu.xml.pipeline.EventFilter; - -import javax.xml.transform.*; -import javax.xml.transform.dom.*; -import javax.xml.transform.sax.*; -import javax.xml.transform.stream.*; - -import org.xml.sax.*; -import org.xml.sax.helpers.XMLReaderFactory; -import org.xml.sax.helpers.LocatorImpl; - - -/** - * Implements null transforms. XSLT stylesheets are not supported. - * This class provides a way to translate three representations of - * XML data (SAX event stream, DOM tree, and XML text) into each other. - * In essence it's a thinnish wrapper around basic SAX event - * <a href="../pipeline/package-summary.html">pipeline</a> facilities, which - * exposes only limited functionality. The <em>javax.xml.transform</em> - * functionality is implemented as follows: <ul> - * - * <li>The {@link javax.xml.transform.sax.SAXSource SAXSource} class - * just wraps an {@link XMLReader} and {@link InputSource}, while the - * {@link javax.xml.transform.sax.SAXResult SAXResult} class is less - * functional than a {@link gnu.xml.pipeline.EventConsumer EventConsumer}. - * (Notably, it drops all but one declaration from any DTD.)</li> - * - * <li>The {@link javax.xml.transform.dom.DOMSource DOMSource} class - * corresponds to special SAX parsers like {@link DomParser}, and the - * {@link javax.xml.transform.dom.DOMResult DOMResult} class corresponds - * to a {@link gnu.xml.pipeline.DomConsumer DomConsumer}.</li> - * - * <li>The {@link javax.xml.transform.stream.StreamSource StreamSource} - * class corresponds to a SAX {@link InputSource}, and the - * {@link javax.xml.transform.stream.StreamResult StreamResult} class - * corresponds to a {@link gnu.xml.pipeline.TextConsumer TextConsumer}.</li> - * - * </ul> - * - * <p><em>This implementation is preliminary.</em> - * - * @see gnu.xml.pipeline.XsltFilter - * - * @author David Brownell - */ -public class SAXNullTransformerFactory extends SAXTransformerFactory -{ - - private ErrorListener errListener; - private URIResolver uriResolver; - - /** Default constructor */ - public SAXNullTransformerFactory () { } - - // - // only has stuff that makes sense with null transforms - // - - /** - * Returns true if the requested feature is supported. - * All three kinds of input and output are accepted: - * XML text, SAX events, and DOM nodes. - */ - public boolean getFeature (String feature) - { - return SAXTransformerFactory.FEATURE.equals (feature) - || SAXResult.FEATURE.equals (feature) - || SAXSource.FEATURE.equals (feature) - || DOMResult.FEATURE.equals (feature) - || DOMSource.FEATURE.equals (feature) - || StreamResult.FEATURE.equals (feature) - || StreamSource.FEATURE.equals (feature) - ; - } - - public void setFeature(String name, boolean value) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException(name); - } - - - /** Throws an exception (no implementation attributes are supported) */ - public void setAttribute (String key, Object value) - { - throw new IllegalArgumentException (); - } - - /** Throws an exception (no implementation attributes are supported) */ - public Object getAttribute (String key) - { - throw new IllegalArgumentException (); - } - - /** (not yet implemented) */ - public Source getAssociatedStylesheet (Source source, - String media, - String title, - String charset) - throws TransformerConfigurationException - { - // parse, and find the appropriate xsl-stylesheet PI contents - throw new IllegalArgumentException (); - } - - public Transformer newTransformer () - throws TransformerConfigurationException - { - return new NullTransformer (); - } - - /** - * Returns a TransformerHandler that knows how to generate output - * in all three standard formats. Output text is generated using - * {@link XMLWriter}, and the GNU implementation of - * {@link DomDocument DOM} is used. - * - * @see SAXResult - * @see StreamResult - * @see DOMResult - */ - public TransformerHandler newTransformerHandler () - throws TransformerConfigurationException - { - NullTransformer transformer = new NullTransformer (); - return transformer.handler; - } - - // - // Stuff that depends on XSLT support, which we don't provide - // - private static final String noXSLT = "No XSLT support"; - - /** Throws an exception (XSLT is not supported). */ - public Transformer newTransformer (Source stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public Templates newTemplates (Source stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public TemplatesHandler newTemplatesHandler () - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public TransformerHandler newTransformerHandler (Source stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public TransformerHandler newTransformerHandler (Templates stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public XMLFilter newXMLFilter (Source stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Throws an exception (XSLT is not supported). */ - public XMLFilter newXMLFilter (Templates stylesheet) - throws TransformerConfigurationException - { - throw new TransformerConfigurationException (noXSLT); - } - - /** Returns the value assigned by {@link #setErrorListener}. */ - public ErrorListener getErrorListener () - { - return errListener; - } - - /** Assigns a value that would be used when parsing stylesheets */ - public void setErrorListener (ErrorListener e) - { - errListener = e; - } - - /** Returns the value assigned by {@link #setURIResolver}. */ - public URIResolver getURIResolver () - { - return uriResolver; - } - - /** Assigns a value that would be used when parsing stylesheets */ - public void setURIResolver (URIResolver u) - { - uriResolver = u; - } - - - // - // Helper classes. These might in theory be subclassed - // by an XSLT implementation, if they were exported. - // - - static class DomTerminus - extends DomConsumer - { - - DomTerminus (DOMResult result) - throws SAXException - { - // won't really throw SAXException - super (DomDocument.class); - setHandler (new DomHandler (this, result)); - } - - } - - static class DomHandler - extends Consumer.Backdoor - { - - private DOMResult result; - - DomHandler (DomConsumer c, DOMResult r) - throws SAXException - { - // won't really throw SAXException - super (c); - result = r; - } - - public void endDocument () - throws SAXException - { - super.endDocument (); - result.setNode (getDocument ()); - } - - } - - private static OutputStream getOutputStream (String uri) - throws IOException - { - // JDK stupidity: file "protocol does not support output" ... - if (uri.startsWith ("file:")) - return new FileOutputStream (uri.substring (5)); - - // Otherwise ... - URL url = new URL (uri); - URLConnection conn = url.openConnection (); - - conn.setDoOutput (true); - return conn.getOutputStream (); - } - - - static class NullHandler - extends EventFilter - implements TransformerHandler - { - - private String systemId; - private Transformer transformer; - - NullHandler (Transformer t) - { - transformer = t; - } - - public Transformer getTransformer () - { - return transformer; - } - - public String getSystemId () - { - return systemId; - } - - public void setSystemId (String id) - { - systemId = id; - } - - public void setResult (Result result) - { - if (result.getSystemId () != null) - systemId = result.getSystemId (); - - try - { - - // output to partial SAX event stream? - if (result instanceof SAXResult) - { - SAXResult r = (SAXResult) result; - - setContentHandler (r.getHandler ()); - setProperty (LEXICAL_HANDLER, r.getLexicalHandler ()); - // DTD info is filtered out by javax.transform - - // output to DOM tree? - } - else if (result instanceof DOMResult) - { - DomTerminus out = new DomTerminus ((DOMResult) result); - - setContentHandler (out.getContentHandler ()); - setProperty (LEXICAL_HANDLER, - out.getProperty (LEXICAL_HANDLER)); - // save DTD-derived info, if any. - setDTDHandler (out.getDTDHandler ()); - setProperty (DECL_HANDLER, - out.getProperty (DECL_HANDLER)); - - // node is saved into result on endDocument() - - // output to (XML) text? - } - else if (result instanceof StreamResult) - { - StreamResult r = (StreamResult) result; - XMLWriter out; - - // FIXME: when do output properties take effect? - // encoding, standalone decl, xml/xhtml/... ... - - // FIXME: maybe put nsfix filter up front - - try - { - if (r.getWriter () != null) - out = new XMLWriter (r.getWriter ()); - else if (r.getOutputStream () != null) - out = new XMLWriter (r.getOutputStream ()); - else if (r.getSystemId () != null) - out = new XMLWriter ( - getOutputStream (r.getSystemId ())); - else - throw new IllegalArgumentException ( - "bad StreamResult"); - } - catch (IOException e) - { - e.printStackTrace (); - // on jdk 1.4, pass the root cause ... - throw new IllegalArgumentException (e.getMessage ()); - } - - // out.setExpandingEntities (true); - // out.setPrettyPrinting (true); - // out.setXhtml (true); - - setContentHandler (out); - setProperty (LEXICAL_HANDLER, out); - // save DTD info, if any; why not? - setDTDHandler (out); - setProperty (DECL_HANDLER, out); - } - - } - catch (SAXException e) - { - // SAXNotSupportedException or SAXNotRecognizedException: - // "can't happen" ... but SAXException for DOM build probs - // could happen, so ... - // on jdk 1.4, pass the root cause ... - throw new IllegalArgumentException (e.getMessage ()); - } - } - } - - // an interface that adds no value - static class LocatorAdapter - extends LocatorImpl - implements SourceLocator - { - - LocatorAdapter (SAXParseException e) - { - setSystemId (e.getSystemId ()); - setPublicId (e.getPublicId ()); - setLineNumber (e.getLineNumber ()); - setColumnNumber (e.getColumnNumber ()); - } - - } - - // another interface that adds no value - static class ListenerAdapter - implements ErrorHandler - { - - NullTransformer transformer; - - ListenerAdapter (NullTransformer t) - { - transformer = t; - } - - private TransformerException map (SAXParseException e) - { - return new TransformerException ( - e.getMessage (), - new LocatorAdapter (e), - e); - } - - public void error (SAXParseException e) - throws SAXParseException - { - try - { - if (transformer.errListener != null) - transformer.errListener.error (map (e)); - } - catch (TransformerException ex) - { - transformer.ex = ex; - throw e; - } - } - - public void fatalError (SAXParseException e) - throws SAXParseException - { - try - { - if (transformer.errListener != null) - transformer.errListener.fatalError (map (e)); - else - throw map (e); - } catch (TransformerException ex) { - transformer.ex = ex; - throw e; - } - } - - public void warning (SAXParseException e) - throws SAXParseException - { - try - { - if (transformer.errListener != null) - transformer.errListener.warning (map (e)); - } - catch (TransformerException ex) - { - transformer.ex = ex; - throw e; - } - } - } - - static class NullTransformer - extends Transformer - { - - private URIResolver uriResolver; - private Properties props = new Properties (); - private Hashtable params = new Hashtable (7); - - ErrorListener errListener = null; - TransformerException ex = null; - NullHandler handler; - - NullTransformer () - { - super (); - handler = new NullHandler (this); - } - - public ErrorListener getErrorListener () - { - return errListener; - } - - public void setErrorListener (ErrorListener e) - { - errListener = e; - } - - public URIResolver getURIResolver () - { - return uriResolver; - } - - public void setURIResolver (URIResolver u) - { - uriResolver = u; - } - - public void setOutputProperties (Properties p) - { - props = (Properties) p.clone (); - } - - public Properties getOutputProperties () - { - return (Properties) props.clone (); - } - - public void setOutputProperty (String name, String value) - { - props.setProperty (name, value); - } - - public String getOutputProperty (String name) - { - return props.getProperty (name); - } - - public void clearParameters () - { - params.clear (); - } - - public void setParameter (String name, Object value) - { - props.put (name, value); - } - - public Object getParameter (String name) - { - return props.get (name); - } - - public void transform (Source in, Result out) - throws TransformerException - { - try - { - XMLReader producer; - InputSource input; - - // Input from DOM? - if (in instanceof DOMSource) - { - DOMSource source = (DOMSource) in; - - if (source.getNode () == null) - throw new IllegalArgumentException ("no DOM node"); - producer = new DomParser (source.getNode ()); - input = null; - - // Input from SAX? - } - else if (in instanceof SAXSource) - { - SAXSource source = (SAXSource) in; - - producer = source.getXMLReader (); - if (producer == null) - producer = XMLReaderFactory.createXMLReader (); - - input = source.getInputSource (); - if (input == null) - { - if (source.getSystemId () != null) - input = new InputSource (source.getSystemId ()); - else - throw new IllegalArgumentException ( - "missing SAX input"); - } - - // Input from a stream or something? - } - else - { - producer = XMLReaderFactory.createXMLReader (); - input = SAXSource.sourceToInputSource (in); - if (input == null) - throw new IllegalArgumentException ("missing input"); - } - - // preserve original namespace prefixes - try - { - producer.setFeature(EventFilter.FEATURE_URI + - "namespace-prefixes", - true); - } - catch (Exception e) - { - /* ignore */ - // FIXME if we couldn't, "NsFix" stage before the output .. - } - - // arrange the output - handler.setResult (out); - EventFilter.bind (producer, handler); - - // then parse ... single element pipeline - producer.parse (input); - - } - catch (IOException e) - { - throw new TransformerException ("transform failed", e); - - } - catch (SAXException e) - { - if (ex == null && ex.getCause () == e) - throw ex; - else - throw new TransformerException ("transform failed", e); - - } - finally - { - ex = null; - } - } - } - -} diff --git a/libjava/gnu/xml/util/XCat.java b/libjava/gnu/xml/util/XCat.java deleted file mode 100644 index 0f163387081..00000000000 --- a/libjava/gnu/xml/util/XCat.java +++ /dev/null @@ -1,1609 +0,0 @@ -/* XCat.java -- - Copyright (C) 2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.xml.util; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.StringTokenizer; -import java.util.Stack; -import java.util.Vector; - -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; - -import org.xml.sax.ext.DefaultHandler2; -import org.xml.sax.ext.EntityResolver2; - -import org.xml.sax.helpers.XMLReaderFactory; - -/** - * Packages <a href= - "http://www.oasis-open.org/committees/entity/spec-2001-08-06.html" - >OASIS XML Catalogs</a>, - * primarily for entity resolution by parsers. - * That specification defines an XML syntax for mappings between - * identifiers declared in DTDs (particularly PUBLIC identifiers) and - * locations. SAX has always supported such mappings, but conventions for - * an XML file syntax to maintain them have previously been lacking. - * - * <p> This has three main operational modes. The primary intended mode is - * to create a resolver, then preloading it with one or more site-standard - * catalogs before using it with one or more SAX parsers: <pre> - * XCat catalog = new XCat (); - * catalog.setErrorHandler (diagnosticErrorHandler); - * catalog.loadCatalog ("file:/local/catalogs/catalog.cat"); - * catalog.loadCatalog ("http://shared/catalog.cat"); - * ... - * catalog.disableLoading (); - * parser1.setEntityResolver (catalog); - * parser2.setEntityResolver (catalog); - * ...</pre> - * - * <p>A second mode is to arrange that your application uses instances of - * this class as its entity resolver, and automatically loads catalogs - * referenced by <em><?oasis-xml-catalog...?></em> processing - * instructions found before the DTD in documents it parses. - * It would then discard the resolver after each parse. - * - * <p> A third mode applies catalogs in contexts other than entity - * resolution for parsers. - * The {@link #resolveURI resolveURI()} method supports resolving URIs - * stored in XML application data, rather than inside DTDs. - * Catalogs would be loaded as shown above, and the catalog could - * be used concurrently for parser entity resolution and for - * application URI resolution. - * </p> - * - * <center><hr width='70%'></center> - * - * <p>Errors in catalogs implicitly loaded (during resolution) are ignored - * beyond being reported through any <em>ErrorHandler</em> assigned using - * {@link #setErrorHandler setErrorHandler()}. SAX exceptions - * thrown from such a handler won't abort resolution, although throwing a - * <em>RuntimeException</em> or <em>Error</em> will normally abort both - * resolution and parsing. Useful diagnostic information is available to - * any <em>ErrorHandler</em> used to report problems, or from any exception - * thrown from an explicit {@link #loadCatalog loadCatalog()} invocation. - * Applications can use that information as troubleshooting aids. - * - * <p>While this class requires <em>SAX2 Extensions 1.1</em> classes in - * its class path, basic functionality does not require using a SAX2 - * parser that supports the extended entity resolution functionality. - * See the original SAX1 - * {@link #resolveEntity(java.lang.String,java.lang.String) resolveEntity()} - * method for a list of restrictions which apply when it is used with - * older SAX parsers. - * - * @see EntityResolver2 - * - * @author David Brownell - */ -public class XCat implements EntityResolver2 -{ - private Catalog catalogs []; - private boolean usingPublic = true; - private boolean loadingPermitted = true; - private boolean unified = true; - private String parserClass; - private ErrorHandler errorHandler; - - // private EntityResolver next; // chain to next if we fail... - - // - // NOTE: This is a straightforward implementation, and if - // there are lots of "nextCatalog" or "delegate*" entries - // in use, two tweaks would be worth considering: - // - // - Centralize some sort of cache (key by URI) for individual - // resolvers. That'd avoid multiple copies of a given catalog. - // - // - Have resolution track what catalogs (+modes) have been - // searched. This would support loop detection. - // - - - /** - * Initializes without preloading a catalog. - * This API is convenient when you may want to arrange that catalogs - * are automatically loaded when explicitly referenced in documents, - * using the <em>oasis-xml-catalog</em> processing instruction. - * In such cases you won't usually be able to preload catalogs. - */ - public XCat () { } - - /** - * Initializes, and preloads a catalog using the default SAX parser. - * This API is convenient when you operate with one or more standard - * catalogs. - * - * <p> This just delegates to {@link #loadCatalog loadCatalog()}; - * see it for exception information. - * - * @param uri absolute URI for the catalog file. - */ - public XCat (String uri) - throws SAXException, IOException - { loadCatalog (uri); } - - - /** - * Loads an OASIS XML Catalog. - * It is appended to the list of currently active catalogs, or - * reloaded if a catalog with the same URI was already loaded. - * Callers have control over what parser is used, how catalog parsing - * errors are reported, and whether URIs will be resolved consistently. - * - * <p> The OASIS specification says that errors detected when loading - * catalogs "must recover by ignoring the catalog entry file that - * failed, and proceeding." In this API, that action can be the - * responsibility of applications, when they explicitly load any - * catalog using this method. - * - * <p>Note that catalogs referenced by this one will not be loaded - * at this time. Catalogs referenced through <em>nextCatalog</em> - * or <em>delegate*</em> elements are normally loaded only if needed. - * - * @see #setErrorHandler - * @see #setParserClass - * @see #setUnified - * - * @param uri absolute URI for the catalog file. - * - * @exception IOException As thrown by the parser, typically to - * indicate problems reading data from that URI. - * @exception SAXException As thrown by the parser, typically to - * indicate problems parsing data from that URI. It may also - * be thrown if the parser doesn't support necessary handlers. - * @exception IllegalStateException When attempting to load a - * catalog after loading has been {@link #disableLoading disabled}, - * such as after any entity or URI lookup has been performed. - */ - public synchronized void loadCatalog (String uri) - throws SAXException, IOException - { - Catalog catalog; - int index = -1; - - if (!loadingPermitted) - throw new IllegalStateException (); - - uri = normalizeURI (uri); - if (catalogs != null) { - // maybe just reload - for (index = 0; index < catalogs.length; index++) - if (uri.equals (catalogs [index].catalogURI)) - break; - } - catalog = loadCatalog (parserClass, errorHandler, uri, unified); - - // add to list of catalogs - if (catalogs == null) { - index = 0; - catalogs = new Catalog [1]; - } else if (index == catalogs.length) { - Catalog tmp []; - - tmp = new Catalog [index + 1]; - System.arraycopy (catalogs, 0, tmp, 0, index); - catalogs = tmp; - } - catalogs [index] = catalog; - } - - - /** - * "New Style" external entity resolution for parsers. - * Calls to this method prevent explicit loading of additional catalogs - * using {@link #loadCatalog loadCatalog()}. - * - * <p>This supports the full core catalog functionality for locating - * (and relocating) parsed entities that have been declared in a - * document's DTD. - * - * @param name Entity name, such as "dudley", "%nell", or "[dtd]". - * @param publicId Either a normalized public ID, or null. - * @param baseURI Absolute base URI associated with systemId. - * @param systemId URI found in entity declaration (may be - * relative to baseURI). - * - * @return Input source for accessing the external entity, or null - * if no mapping was found. The input source may have opened - * the stream, and will have a fully resolved URI. - * - * @see #getExternalSubset - */ - public InputSource resolveEntity ( - String name, // UNUSED ... systemId is always non-null - String publicId, - String baseURI, // UNUSED ... it just lets sysId be relative - String systemId - ) throws SAXException, IOException - { - if (loadingPermitted) - disableLoading (); - - try { - // steps as found in OASIS XML catalog spec 7.1.2 - // steps 1, 8 involve looping over the list of catalogs - for (int i = 0; i < catalogs.length; i++) { - InputSource retval; - retval = catalogs [i].resolve (usingPublic, publicId, systemId); - if (retval != null) - return retval;; - } - } catch (DoneDelegation x) { - // done! - } - // step 9 involves returning "no match" - return null; - } - - - /** - * "New Style" parser callback to add an external subset. - * For documents that don't include an external subset, this may - * return one according to <em>doctype</em> catalog entries. - * (This functionality is not a core part of the OASIS XML Catalog - * specification, though it's presented in an appendix.) - * If no such entry is defined, this returns null to indicate that - * this document will not be modified to include such a subset. - * Calls to this method prevent explicit loading of additional catalogs - * using {@link #loadCatalog loadCatalog()}. - * - * <p><em>Warning:</em> That catalog functionality can be dangerous. - * It can provide definitions of general entities, and thereby mask - * certain well formedess errors. - * - * @param name Name of the document element, either as declared in - * a DOCTYPE declaration or as observed in the text. - * @param baseURI Document's base URI (absolute). - * - * @return Input source for accessing the external subset, or null - * if no mapping was found. The input source may have opened - * the stream, and will have a fully resolved URI. - */ - public InputSource getExternalSubset (String name, String baseURI) - throws SAXException, IOException - { - if (loadingPermitted) - disableLoading (); - try { - for (int i = 0; i < catalogs.length; i++) { - InputSource retval = catalogs [i].getExternalSubset (name); - if (retval != null) - return retval; - } - } catch (DoneDelegation x) { - // done! - } - return null; - } - - - /** - * "Old Style" external entity resolution for parsers. - * This API provides only core functionality. - * Calls to this method prevent explicit loading of additional catalogs - * using {@link #loadCatalog loadCatalog()}. - * - * <p>The functional limitations of this interface include:</p><ul> - * - * <li>Since system IDs will be absolutized before the resolver - * sees them, matching against relative URIs won't work. - * This may affect <em>system</em>, <em>rewriteSystem</em>, - * and <em>delegateSystem</em> catalog entries. - * - * <li>Because of that absolutization, documents declaring entities - * with system IDs using URI schemes that the JVM does not recognize - * may be unparsable. URI schemes such as <em>file:/</em>, - * <em>http://</em>, <em>https://</em>, and <em>ftp://</em> - * will usually work reliably. - * - * <li>Because missing external subsets can't be provided, the - * <em>doctype</em> catalog entries will be ignored. - * (The {@link #getExternalSubset getExternalSubset()} method is - * a "New Style" resolution option.) - * - * </ul> - * - * <p>Applications can tell whether this limited functionality will be - * used: if the feature flag associated with the {@link EntityResolver2} - * interface is not <em>true</em>, the limitations apply. Applications - * can't usually know whether a given document and catalog will trigger - * those limitations. The issue can only be bypassed by operational - * procedures such as not using catalogs or documents which involve - * those features. - * - * @param publicId Either a normalized public ID, or null - * @param systemId Always an absolute URI. - * - * @return Input source for accessing the external entity, or null - * if no mapping was found. The input source may have opened - * the stream, and will have a fully resolved URI. - */ - final public InputSource resolveEntity (String publicId, String systemId) - throws SAXException, IOException - { - return resolveEntity (null, publicId, null, systemId); - } - - - /** - * Resolves a URI reference that's not defined to the DTD. - * This is intended for use with URIs found in document text, such as - * <em>xml-stylesheet</em> processing instructions and in attribute - * values, where they are not recognized as URIs by XML parsers. - * Calls to this method prevent explicit loading of additional catalogs - * using {@link #loadCatalog loadCatalog()}. - * - * <p>This functionality is supported by the OASIS XML Catalog - * specification, but will never be invoked by an XML parser. - * It corresponds closely to functionality for mapping system - * identifiers for entities declared in DTDs; closely enough that - * this implementation's default behavior is that they be - * identical, to minimize potential confusion. - * - * <p>This method could be useful when implementing the - * {@link javax.xml.transform.URIResolver} interface, wrapping the - * input source in a {@link javax.xml.transform.sax.SAXSource}. - * - * @see #isUnified - * @see #setUnified - * - * @param baseURI The relevant base URI as specified by the XML Base - * specification. This recognizes <em>xml:base</em> attributes - * as overriding the actual (physical) base URI. - * @param uri Either an absolute URI, or one relative to baseURI - * - * @return Input source for accessing the mapped URI, or null - * if no mapping was found. The input source may have opened - * the stream, and will have a fully resolved URI. - */ - public InputSource resolveURI (String baseURI, String uri) - throws SAXException, IOException - { - if (loadingPermitted) - disableLoading (); - - // NOTE: baseURI isn't used here, but caller MUST have it, - // and heuristics _might_ use it in the future ... plus, - // it's symmetric with resolveEntity (). - - // steps 1, 6 involve looping - try { - for (int i = 0; i < catalogs.length; i++) { - InputSource tmp = catalogs [i].resolveURI (uri); - if (tmp != null) - return tmp; - } - } catch (DoneDelegation x) { - // done - } - // step 7 reports no match - return null; - } - - - /** - * Records that catalog loading is no longer permitted. - * Loading is automatically disabled when lookups are performed, - * and should be manually disabled when <em>startDTD()</em> (or - * any other DTD declaration callback) is invoked, or at the latest - * when the document root element is seen. - */ - public synchronized void disableLoading () - { - // NOTE: this method and loadCatalog() are synchronized - // so that it's impossible to load (top level) catalogs - // after lookups start. Likewise, deferred loading is also - // synchronized (for "next" and delegated catalogs) to - // ensure that parsers can share resolvers. - loadingPermitted = false; - } - - - /** - * Returns the error handler used to report catalog errors. - * Null is returned if the parser's default error handling - * will be used. - * - * @see #setErrorHandler - */ - public ErrorHandler getErrorHandler () - { return errorHandler; } - - /** - * Assigns the error handler used to report catalog errors. - * These errors may come either from the SAX2 parser or - * from the catalog parsing code driven by the parser. - * - * <p> If you're sharing the resolver between parsers, don't - * change this once lookups have begun. - * - * @see #getErrorHandler - * - * @param parser The error handler, or null saying to use the default - * (no diagnostics, and only fatal errors terminate loading). - */ - public void setErrorHandler (ErrorHandler handler) - { errorHandler = handler; } - - - /** - * Returns the name of the SAX2 parser class used to parse catalogs. - * Null is returned if the system default is used. - * @see #setParserClass - */ - public String getParserClass () - { return parserClass; } - - /** - * Names the SAX2 parser class used to parse catalogs. - * - * <p> If you're sharing the resolver between parsers, don't change - * this once lookups have begun. - * - * <p> Note that in order to properly support the <em>xml:base</em> - * attribute and relative URI resolution, the SAX parser used to parse - * the catalog must provide a {@link Locator} and support the optional - * declaration and lexical handlers. - * - * @see #getParserClass - * - * @param parser The parser class name, or null saying to use the - * system default SAX2 parser. - */ - public void setParserClass (String parser) - { parserClass = parser; } - - - /** - * Returns true (the default) if all methods resolve - * a given URI in the same way. - * Returns false if calls resolving URIs as entities (such as - * {@link #resolveEntity resolveEntity()}) use different catalog entries - * than those resolving them as URIs ({@link #resolveURI resolveURI()}), - * which will generally produce different results. - * - * <p>The OASIS XML Catalog specification defines two related schemes - * to map URIs "as URIs" or "as system IDs". - * URIs use <em>uri</em>, <em>rewriteURI</em>, and <em>delegateURI</em> - * elements. System IDs do the same things with <em>systemId</em>, - * <em>rewriteSystemId</em>, and <em>delegateSystemId</em>. - * It's confusing and error prone to maintain two parallel copies of - * such data. Accordingly, this class makes that behavior optional. - * The <em>unified</em> interpretation of URI mappings is preferred, - * since it prevents surprises where one URI gets mapped to different - * contents depending on whether the reference happens to have come - * from a DTD (or not). - * - * @see #setUnified - */ - public boolean isUnified () - { return unified; } - - /** - * Assigns the value of the flag returned by {@link #isUnified}. - * Set it to false to be strictly conformant with the OASIS XML Catalog - * specification. Set it to true to make all mappings for a given URI - * give the same result, regardless of the reason for the mapping. - * - * <p>Don't change this once you've loaded the first catalog. - * - * @param value new flag setting - */ - public void setUnified (boolean value) - { unified = value; } - - - /** - * Returns true (the default) if a catalog's public identifier - * mappings will be used. - * When false is returned, such mappings are ignored except when - * system IDs are discarded, such as for - * entities using the <em>urn:publicid:</em> URI scheme in their - * system identifiers. (See RFC 3151 for information about that - * URI scheme. Using it in system identifiers may not work well - * with many SAX parsers unless the <em>resolve-dtd-uris</em> - * feature flag is set to false.) - * @see #setUsingPublic - */ - public boolean isUsingPublic () - { return usingPublic; } - - /** - * Specifies which catalog search mode is used. - * By default, public identifier mappings are able to override system - * identifiers when both are available. - * Applications may choose to ignore public - * identifier mappings in such cases, so that system identifiers - * declared in DTDs will only be overridden by an explicit catalog - * match for that system ID. - * - * <p> If you're sharing the resolver between parsers, don't - * change this once lookups have begun. - * @see #isUsingPublic - * - * @param value true to always use public identifier mappings, - * false to only use them for system ids using the <em>urn:publicid:</em> - * URI scheme. - */ - public void setUsingPublic (boolean value) - { usingPublic = value; } - - - - // hmm, what's this do? :) - private static Catalog loadCatalog ( - String parserClass, - ErrorHandler eh, - String uri, - boolean unified - ) throws SAXException, IOException - { - XMLReader parser; - Loader loader; - boolean doesIntern = false; - - if (parserClass == null) - parser = XMLReaderFactory.createXMLReader (); - else - parser = XMLReaderFactory.createXMLReader (parserClass); - if (eh != null) - parser.setErrorHandler (eh); - // resolve-dtd-entities is at default value (unrecognized == true) - - try { - doesIntern = parser.getFeature ( - "http://xml.org/sax/features/string-interning"); - } catch (SAXNotRecognizedException e) { } - - loader = new Loader (doesIntern, eh, unified); - loader.cat.parserClass = parserClass; - loader.cat.catalogURI = uri; - - parser.setContentHandler (loader); - parser.setProperty ( - "http://xml.org/sax/properties/declaration-handler", - loader); - parser.setProperty ( - "http://xml.org/sax/properties/lexical-handler", - loader); - parser.parse (uri); - - return loader.cat; - } - - // perform one or both the normalizations for public ids - private static String normalizePublicId (boolean full, String publicId) - { - if (publicId.startsWith ("urn:publicid:")) { - StringBuffer buf = new StringBuffer (); - char chars [] = publicId.toCharArray (); -boolean hasbug = false; - - for (int i = 13; i < chars.length; i++) { - switch (chars [i]) { - case '+': buf.append (' '); continue; - case ':': buf.append ("//"); continue; - case ';': buf.append ("::"); continue; - case '%': -// FIXME unhex that char! meanwhile, warn and fallthrough ... - hasbug = true; - default: buf.append (chars [i]); continue; - } - } - publicId = buf.toString (); -if (hasbug) -System.err.println ("nyet unhexing public id: " + publicId); - full = true; - } - - // SAX parsers do everything except that URN mapping, but - // we can't trust other sources to normalize correctly - if (full) { - StringTokenizer tokens; - String token; - - tokens = new StringTokenizer (publicId, " \r\n"); - publicId = null; - while (tokens.hasMoreTokens ()) { - if (publicId == null) - publicId = tokens.nextToken (); - else - publicId += " " + tokens.nextToken (); - } - } - return publicId; - } - - private static boolean isUriExcluded (int c) - { return c <= 0x20 || c >= 0x7f || "\"<>^`{|}".indexOf (c) != -1; } - - private static int hexNibble (int c) - { - if (c < 10) - return c + '0'; - return ('a' - 10) + c; - } - - // handles URIs with "excluded" characters - private static String normalizeURI (String systemId) - { - int length = systemId.length (); - - for (int i = 0; i < length; i++) { - char c = systemId.charAt (i); - - // escape non-ASCII plus "excluded" characters - if (isUriExcluded (c)) { - byte buf []; - ByteArrayOutputStream out; - int b; - - // a JVM that doesn't know UTF8 and 8859_1 is unusable! - try { - buf = systemId.getBytes ("UTF8"); - out = new ByteArrayOutputStream (buf.length + 10); - - for (i = 0; i < buf.length; i++) { - b = buf [i] & 0x0ff; - if (isUriExcluded (b)) { - out.write ((int) '%'); - out.write (hexNibble (b >> 4)); - out.write (hexNibble (b & 0x0f)); - } else - out.write (b); - } - return out.toString ("8859_1"); - } catch (IOException e) { - throw new RuntimeException ( - "can't normalize URI: " + e.getMessage ()); - } - } - } - return systemId; - } - - // thrown to mark authoritative end of a search - private static class DoneDelegation extends SAXException - { - DoneDelegation () { } - } - - - /** - * Represents a OASIS XML Catalog, and encapsulates much of - * the catalog functionality. - */ - private static class Catalog - { - // loading infrastructure - String catalogURI; - ErrorHandler eh; - boolean unified; - String parserClass; - - // catalog data - boolean hasPreference; - boolean usingPublic; - - Hashtable publicIds; - Hashtable publicDelegations; - - Hashtable systemIds; - Hashtable systemRewrites; - Hashtable systemDelegations; - - Hashtable uris; - Hashtable uriRewrites; - Hashtable uriDelegations; - - Hashtable doctypes; - - Vector next; - - // nonpublic! - Catalog () { } - - - // steps as found in OASIS XML catalog spec 7.1.2 - private InputSource locatePublicId (String publicId) - throws SAXException, IOException - { - // 5. return (first) 'public' entry - if (publicIds != null) { - String retval = (String) publicIds.get (publicId); - if (retval != null) { - // IF the URI is accessible ... - return new InputSource (retval); - } - } - - // 6. return delegatePublic catalog match [complex] - if (publicDelegations != null) - return checkDelegations (publicDelegations, publicId, - publicId, null); - - return null; - } - - // steps as found in OASIS XML catalog spec 7.1.2 or 7.2.2 - private InputSource mapURI ( - String uri, - Hashtable ids, - Hashtable rewrites, - Hashtable delegations - ) throws SAXException, IOException - { - // 7.1.2: 2. return (first) 'system' entry - // 7.2.2: 2. return (first) 'uri' entry - if (ids != null) { - String retval = (String) ids.get (uri); - if (retval != null) { - // IF the URI is accessible ... - return new InputSource (retval); - } - } - - // 7.1.2: 3. return 'rewriteSystem' entries - // 7.2.2: 3. return 'rewriteURI' entries - if (rewrites != null) { - String prefix = null; - String replace = null; - int prefixLen = -1; - - for (Enumeration e = rewrites.keys (); - e.hasMoreElements (); - /* NOP */) { - String temp = (String) e.nextElement (); - int len = -1; - - if (!uri.startsWith (temp)) - continue; - if (prefix != null - && (len = temp.length ()) < prefixLen) - continue; - prefix = temp; - prefixLen = len; - replace = (String) rewrites.get (temp); - } - if (prefix != null) { - StringBuffer buf = new StringBuffer (replace); - buf.append (uri.substring (prefixLen)); - // IF the URI is accessible ... - return new InputSource (buf.toString ()); - } - } - - // 7.1.2: 4. return 'delegateSystem' catalog match [complex] - // 7.2.2: 4. return 'delegateURI' catalog match [complex] - if (delegations != null) - return checkDelegations (delegations, uri, null, uri); - - return null; - } - - - /** - * Returns a URI for an external entity. - */ - public InputSource resolve ( - boolean usingPublic, - String publicId, - String systemId - ) throws SAXException, IOException - { - boolean preferSystem; - InputSource retval; - - if (hasPreference) - preferSystem = !this.usingPublic; - else - preferSystem = !usingPublic; - - if (publicId != null) - publicId = normalizePublicId (false, publicId); - - // behavior here matches section 7.1.1 of the oasis spec - if (systemId != null) { - if (systemId.startsWith ("urn:publicid:")) { - String temp = normalizePublicId (true, systemId); - if (publicId == null) { - publicId = temp; - systemId = null; - } else if (!publicId.equals (temp)) { - // error; ok to recover by: - systemId = null; - } - } else - systemId = normalizeURI (systemId); - } - - if (systemId == null && publicId == null) - return null; - - if (systemId != null) { - retval = mapURI (systemId, systemIds, systemRewrites, - systemDelegations); - if (retval != null) { - retval.setPublicId (publicId); - return retval; - } - } - - if (publicId != null - && !(systemId != null && preferSystem)) { - retval = locatePublicId (publicId); - if (retval != null) { - retval.setPublicId (publicId); - return retval; - } - } - - // 7. apply nextCatalog entries - if (next != null) { - int length = next.size (); - for (int i = 0; i < length; i++) { - Catalog n = getNext (i); - retval = n.resolve (usingPublic, publicId, systemId); - if (retval != null) - return retval; - } - } - - return null; - } - - /** - * Maps one URI into another, for resources that are not defined - * using XML external entity or notation syntax. - */ - public InputSource resolveURI (String uri) - throws SAXException, IOException - { - if (uri.startsWith ("urn:publicid:")) - return resolve (true, normalizePublicId (true, uri), null); - - InputSource retval; - - uri = normalizeURI (uri); - - // 7.2.2 steps 2-4 - retval = mapURI (uri, uris, uriRewrites, uriDelegations); - if (retval != null) - return retval; - - // 7.2.2 step 5. apply nextCatalog entries - if (next != null) { - int length = next.size (); - for (int i = 0; i < length; i++) { - Catalog n = getNext (i); - retval = n.resolveURI (uri); - if (retval != null) - return retval; - } - } - - return null; - } - - - /** - * Finds the external subset associated with a given root element. - */ - public InputSource getExternalSubset (String name) - throws SAXException, IOException - { - if (doctypes != null) { - String value = (String) doctypes.get (name); - if (value != null) { - // IF the URI is accessible ... - return new InputSource (value); - } - } - if (next != null) { - int length = next.size (); - for (int i = 0; i < length; i++) { - Catalog n = getNext (i); - if (n == null) - continue; - InputSource retval = n.getExternalSubset (name); - if (retval != null) - return retval; - } - } - return null; - } - - private synchronized Catalog getNext (int i) - throws SAXException, IOException - { - Object obj; - - if (next == null || i < 0 || i >= next.size ()) - return null; - obj = next.elementAt (i); - if (obj instanceof Catalog) - return (Catalog) obj; - - // ok, we deferred reading that catalog till now. - // load and cache it. - Catalog cat = null; - - try { - cat = loadCatalog (parserClass, eh, (String) obj, unified); - next.setElementAt (cat, i); - } catch (SAXException e) { - // must fail quietly, says the OASIS spec - } catch (IOException e) { - // same applies here - } - return cat; - } - - private InputSource checkDelegations ( - Hashtable delegations, - String id, - String publicId, // only one of public/system - String systemId // will be non-null... - ) throws SAXException, IOException - { - Vector matches = null; - int length = 0; - - // first, see if any prefixes match. - for (Enumeration e = delegations.keys (); - e.hasMoreElements (); - /* NOP */) { - String prefix = (String) e.nextElement (); - - if (!id.startsWith (prefix)) - continue; - if (matches == null) - matches = new Vector (); - - // maintain in longer->shorter sorted order - // NOTE: assumes not many matches will fire! - int index; - - for (index = 0; index < length; index++) { - String temp = (String) matches.elementAt (index); - if (prefix.length () > temp.length ()) { - matches.insertElementAt (prefix, index); - break; - } - } - if (index == length) - matches.addElement (prefix); - length++; - } - if (matches == null) - return null; - - // now we know the list of catalogs to replace our "top level" - // list ... we use it here, rather than somehow going back and - // restarting, since this helps avoid reading most catalogs. - // this assumes stackspace won't be a problem. - for (int i = 0; i < length; i++) { - Catalog catalog = null; - InputSource result; - - // get this catalog. we may not have read it yet. - synchronized (delegations) { - Object prefix = matches.elementAt (i); - Object cat = delegations.get (prefix); - - if (cat instanceof Catalog) - catalog = (Catalog) cat; - else { - try { - // load and cache that catalog - catalog = loadCatalog (parserClass, eh, - (String) cat, unified); - delegations.put (prefix, catalog); - } catch (SAXException e) { - // must ignore, says the OASIS spec - } catch (IOException e) { - // same applies here - } - } - } - - // ignore failed loads, and proceed - if (catalog == null) - continue; - - // we have a catalog ... resolve! - // usingPublic value can't matter, there's no choice - result = catalog.resolve (true, publicId, systemId); - if (result != null) - return result; - } - - // if there were no successes, the entire - // lookup failed (all the way to top level) - throw new DoneDelegation (); - } - } - - - /** This is the namespace URI used for OASIS XML Catalogs. */ - private static final String catalogNamespace = - "urn:oasis:names:tc:entity:xmlns:xml:catalog"; - - - /** - * Loads/unmarshals one catalog. - */ - private static class Loader extends DefaultHandler2 - { - private boolean preInterned; - private ErrorHandler handler; - private boolean unified; - private int ignoreDepth; - private Locator locator; - private boolean started; - private Hashtable externals; - private Stack bases; - - Catalog cat = new Catalog (); - - - /** - * Constructor. - * @param flag true iff the parser already interns strings. - * @param eh Errors and warnings are delegated to this. - * @param unified true keeps one table for URI mappings; - * false matches OASIS spec, storing mappings - * for URIs and SYSTEM ids in parallel tables. - */ - Loader (boolean flag, ErrorHandler eh, boolean unified) - { - preInterned = flag; - handler = eh; - this.unified = unified; - cat.unified = unified; - cat.eh = eh; - } - - - // strips out fragments - private String nofrag (String uri) - throws SAXException - { - if (uri.indexOf ('#') != -1) { - warn ("URI with fragment: " + uri); - uri = uri.substring (0, uri.indexOf ('#')); - } - return uri; - } - - // absolutizes relative URIs - private String absolutize (String uri) - throws SAXException - { - // avoid creating URLs if they're already absolutized, - // or if the URI is already using a known scheme - if (uri.startsWith ("file:/") - || uri.startsWith ("http:/") - || uri.startsWith ("https:/") - || uri.startsWith ("ftp:/") - || uri.startsWith ("urn:") - ) - return uri; - - // otherwise, let's hope the JDK handles this URI scheme. - try { - URL base = (URL) bases.peek (); - return new URL (base, uri).toString (); - } catch (Exception e) { - fatal ("can't absolutize URI: " + uri); - return null; - } - } - - // recoverable error - private void error (String message) - throws SAXException - { - if (handler == null) - return; - handler.error (new SAXParseException (message, locator)); - } - - // nonrecoverable error - private void fatal (String message) - throws SAXException - { - SAXParseException spe; - - spe = new SAXParseException (message, locator); - if (handler != null) - handler.fatalError (spe); - throw spe; - } - - // low severity problem - private void warn (String message) - throws SAXException - { - if (handler == null) - return; - handler.warning (new SAXParseException (message, locator)); - } - - // callbacks: - - public void setDocumentLocator (Locator l) - { locator = l; } - - public void startDocument () - throws SAXException - { - if (locator == null) - error ("no locator!"); - bases = new Stack (); - String uri = locator.getSystemId (); - try { - bases.push (new URL (uri)); - } catch (IOException e) { - fatal ("bad document base URI: " + uri); - } - } - - public void endDocument () - throws SAXException - { - try { - if (!started) - error ("not a catalog!"); - } finally { - locator = null; - handler = null; - externals = null; - bases = null; - } - } - - // XML Base support for external entities. - - // NOTE: expects parser is in default "resolve-dtd-uris" mode. - public void externalEntityDecl (String name, String pub, String sys) - throws SAXException - { - if (externals == null) - externals = new Hashtable (); - if (externals.get (name) == null) - externals.put (name, pub); - } - - public void startEntity (String name) - throws SAXException - { - if (externals == null) - return; - String uri = (String) externals.get (name); - - // NOTE: breaks if an EntityResolver substitutes these URIs. - // If toplevel loader supports one, must intercept calls... - if (uri != null) { - try { - bases.push (new URL (uri)); - } catch (IOException e) { - fatal ("entity '" + name + "', bad URI: " + uri); - } - } - } - - public void endEntity (String name) - { - if (externals == null) - return; - String value = (String) externals.get (name); - - if (value != null) - bases.pop (); - } - - /** - * Processes catalog elements, saving their data. - */ - public void startElement (String namespace, String local, - String qName, Attributes atts) - throws SAXException - { - // must ignore non-catalog elements, and their contents - if (ignoreDepth != 0 || !catalogNamespace.equals (namespace)) { - ignoreDepth++; - return; - } - - // basic sanity checks - if (!preInterned) - local = local.intern (); - if (!started) { - started = true; - if ("catalog" != local) - fatal ("root element not 'catalog': " + local); - } - - // Handle any xml:base attribute - String xmlbase = atts.getValue ("xml:base"); - - if (xmlbase != null) { - URL base = (URL) bases.peek (); - try { - base = new URL (base, xmlbase); - } catch (IOException e) { - fatal ("can't resolve xml:base attribute: " + xmlbase); - } - bases.push (base); - } else - bases.push (bases.peek ()); - - // fetch multi-element attributes, apply standard tweaks - // values (uri, catalog, rewritePrefix) get normalized too, - // as a precaution and since we may compare the values - String catalog = atts.getValue ("catalog"); - if (catalog != null) - catalog = normalizeURI (absolutize (catalog)); - - String rewritePrefix = atts.getValue ("rewritePrefix"); - if (rewritePrefix != null) - rewritePrefix = normalizeURI (absolutize (rewritePrefix)); - - String systemIdStartString; - systemIdStartString = atts.getValue ("systemIdStartString"); - if (systemIdStartString != null) { - systemIdStartString = normalizeURI (systemIdStartString); - // unmatchable <rewriteSystemId>, <delegateSystemId> elements - if (systemIdStartString.startsWith ("urn:publicid:")) { - error ("systemIdStartString is really a publicId!!"); - return; - } - } - - String uri = atts.getValue ("uri"); - if (uri != null) - uri = normalizeURI (absolutize (uri)); - - String uriStartString; - uriStartString = atts.getValue ("uriStartString"); - if (uriStartString != null) { - uriStartString = normalizeURI (uriStartString); - // unmatchable <rewriteURI>, <delegateURI> elements - if (uriStartString.startsWith ("urn:publicid:")) { - error ("uriStartString is really a publicId!!"); - return; - } - } - - // strictly speaking "group" and "catalog" shouldn't nest - // ... arbitrary restriction, no evident motivation - -// FIXME stack "prefer" settings (two elements only!) and use -// them to populate different public mapping/delegation tables - - if ("catalog" == local || "group" == local) { - String prefer = atts.getValue ("prefer"); - - if (prefer != null && !"public".equals (prefer)) { - if (!"system".equals (prefer)) { - error ("in <" + local + " ... prefer='...'>, " - + "assuming 'public'"); - prefer = "public"; - } - } - if (prefer != null) { - if ("catalog" == local) { - cat.hasPreference = true; - cat.usingPublic = "public".equals (prefer); - } else { - if (!cat.hasPreference || cat.usingPublic - != "public".equals (prefer)) { -fatal ("<group prefer=...> case not handled"); - } - } - } else if ("group" == local && cat.hasPreference) { -fatal ("<group prefer=...> case not handled"); - } - - // - // PUBLIC ids: cleanly set up for id substitution - // - } else if ("public" == local) { - String publicId = atts.getValue ("publicId"); - String value = null; - - if (publicId == null || uri == null) { - error ("expecting <public publicId=... uri=.../>"); - return; - } - publicId = normalizePublicId (true, publicId); - uri = nofrag (uri); - if (cat.publicIds == null) - cat.publicIds = new Hashtable (); - else - value = (String) cat.publicIds.get (publicId); - if (value != null) { - if (!value.equals (uri)) - warn ("ignoring <public...> entry for " + publicId); - } else - cat.publicIds.put (publicId, uri); - - } else if ("delegatePublic" == local) { - String publicIdStartString; - Object value = null; - - publicIdStartString = atts.getValue ("publicIdStartString"); - if (publicIdStartString == null || catalog == null) { - error ("expecting <delegatePublic " - + "publicIdStartString=... catalog=.../>"); - return; - } - publicIdStartString = normalizePublicId (true, - publicIdStartString); - if (cat.publicDelegations == null) - cat.publicDelegations = new Hashtable (); - else - value = cat.publicDelegations.get (publicIdStartString); - if (value != null) { - if (!value.equals (catalog)) - warn ("ignoring <delegatePublic...> entry for " - + uriStartString); - } else - cat.publicDelegations.put (publicIdStartString, catalog); - - - // - // SYSTEM ids: need substitution due to operational issues - // - } else if ("system" == local) { - String systemId = atts.getValue ("systemId"); - String value = null; - - if (systemId == null || uri == null) { - error ("expecting <system systemId=... uri=.../>"); - return; - } - systemId = normalizeURI (systemId); - uri = nofrag (uri); - if (systemId.startsWith ("urn:publicid:")) { - error ("systemId is really a publicId!!"); - return; - } - if (cat.systemIds == null) { - cat.systemIds = new Hashtable (); - if (unified) - cat.uris = cat.systemIds; - } else - value = (String) cat.systemIds.get (systemId); - if (value != null) { - if (!value.equals (uri)) - warn ("ignoring <system...> entry for " + systemId); - } else - cat.systemIds.put (systemId, uri); - - } else if ("rewriteSystem" == local) { - String value = null; - - if (systemIdStartString == null || rewritePrefix == null - || systemIdStartString.length () == 0 - || rewritePrefix.length () == 0 - ) { - error ("expecting <rewriteSystem " - + "systemIdStartString=... rewritePrefix=.../>"); - return; - } - if (cat.systemRewrites == null) { - cat.systemRewrites = new Hashtable (); - if (unified) - cat.uriRewrites = cat.systemRewrites; - } else - value = (String) cat.systemRewrites.get ( - systemIdStartString); - if (value != null) { - if (!value.equals (rewritePrefix)) - warn ("ignoring <rewriteSystem...> entry for " - + systemIdStartString); - } else - cat.systemRewrites.put (systemIdStartString, - rewritePrefix); - - } else if ("delegateSystem" == local) { - Object value = null; - - if (systemIdStartString == null || catalog == null) { - error ("expecting <delegateSystem " - + "systemIdStartString=... catalog=.../>"); - return; - } - if (cat.systemDelegations == null) { - cat.systemDelegations = new Hashtable (); - if (unified) - cat.uriDelegations = cat.systemDelegations; - } else - value = cat.systemDelegations.get (systemIdStartString); - if (value != null) { - if (!value.equals (catalog)) - warn ("ignoring <delegateSystem...> entry for " - + uriStartString); - } else - cat.systemDelegations.put (systemIdStartString, catalog); - - - // - // URI: just like "system" ID support, except that - // fragment IDs are disallowed in "system" elements. - // - } else if ("uri" == local) { - String name = atts.getValue ("name"); - String value = null; - - if (name == null || uri == null) { - error ("expecting <uri name=... uri=.../>"); - return; - } - if (name.startsWith ("urn:publicid:")) { - error ("name is really a publicId!!"); - return; - } - name = normalizeURI (name); - if (cat.uris == null) { - cat.uris = new Hashtable (); - if (unified) - cat.systemIds = cat.uris; - } else - value = (String) cat.uris.get (name); - if (value != null) { - if (!value.equals (uri)) - warn ("ignoring <uri...> entry for " + name); - } else - cat.uris.put (name, uri); - - } else if ("rewriteURI" == local) { - String value = null; - - if (uriStartString == null || rewritePrefix == null - || uriStartString.length () == 0 - || rewritePrefix.length () == 0 - ) { - error ("expecting <rewriteURI " - + "uriStartString=... rewritePrefix=.../>"); - return; - } - if (cat.uriRewrites == null) { - cat.uriRewrites = new Hashtable (); - if (unified) - cat.systemRewrites = cat.uriRewrites; - } else - value = (String) cat.uriRewrites.get (uriStartString); - if (value != null) { - if (!value.equals (rewritePrefix)) - warn ("ignoring <rewriteURI...> entry for " - + uriStartString); - } else - cat.uriRewrites.put (uriStartString, rewritePrefix); - - } else if ("delegateURI" == local) { - Object value = null; - - if (uriStartString == null || catalog == null) { - error ("expecting <delegateURI " - + "uriStartString=... catalog=.../>"); - return; - } - if (cat.uriDelegations == null) { - cat.uriDelegations = new Hashtable (); - if (unified) - cat.systemDelegations = cat.uriDelegations; - } else - value = cat.uriDelegations.get (uriStartString); - if (value != null) { - if (!value.equals (catalog)) - warn ("ignoring <delegateURI...> entry for " - + uriStartString); - } else - cat.uriDelegations.put (uriStartString, catalog); - - // - // NON-DELEGATING approach to modularity - // - } else if ("nextCatalog" == local) { - if (catalog == null) { - error ("expecting <nextCatalog catalog=.../>"); - return; - } - if (cat.next == null) - cat.next = new Vector (); - cat.next.addElement (catalog); - - // - // EXTENSIONS from appendix E - // - } else if ("doctype" == local) { - String name = atts.getValue ("name"); - String value = null; - - if (name == null || uri == null) { - error ("expecting <doctype name=... uri=.../>"); - return; - } - name = normalizeURI (name); - if (cat.doctypes == null) - cat.doctypes = new Hashtable (); - else - value = (String) cat.doctypes.get (name); - if (value != null) { - if (!value.equals (uri)) - warn ("ignoring <doctype...> entry for " - + uriStartString); - } else - cat.doctypes.put (name, uri); - - - // - // RESERVED ... ignore (like reserved attributes) but warn - // - } else { - warn ("ignoring unknown catalog element: " + local); - ignoreDepth++; - } - } - - public void endElement (String uri, String local, String qName) - throws SAXException - { - if (ignoreDepth != 0) - ignoreDepth--; - else - bases.pop (); - } - } -} diff --git a/libjava/gnu/xml/util/XHTMLWriter.java b/libjava/gnu/xml/util/XHTMLWriter.java deleted file mode 100644 index 272c66cd34c..00000000000 --- a/libjava/gnu/xml/util/XHTMLWriter.java +++ /dev/null @@ -1,112 +0,0 @@ -/* XHTMLWriter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; - - -/** - * This extends XMLWriter to create a class which defaults to writing - * XHTML text, preferring the US-ASCII encoding. It adds no unique - * functionality, only changing the defaults slightly to simplify writing - * XHTML processing components by providing a bean class whose properties - * have more convenient defaults. An artifact of using the US-ASCII - * encoding is that no XML declaration is written, so that HTML tools - * that can't accept them will not become confused. Components can treat - * the output as UTF-8, ISO-8859-1, or US-ASCII without incurring any - * data loss. - * - * @author David Brownell - */ -public class XHTMLWriter extends XMLWriter -{ - /** - * Constructs this handler with System.out used to write - * SAX events using the US-ASCII encoding, as XHTML. - */ - public XHTMLWriter () - throws IOException - { - this (System.out); - } - - /** - * Constructs this handler such that the specified output stream - * is used to write SAX events in the US-ASCII encoding, as XHTML. - * - * @param out Where US-ASCII encoding of the stream of SAX - * events will be sent. - */ - public XHTMLWriter (OutputStream out) - throws IOException - { - // not all JVMs understand "ASCII" as an encoding name, so - // we use 8859_1 (they all seem to handle that one) and - // make the echo handler filter out non-ASCII characters - this (new OutputStreamWriter (out, "8859_1"), "US-ASCII"); - } - - /** - * Constructs this handler such that the specified output stream - * is used to write SAX events as XHTML. - * - * @param out Where the stream of SAX events will be written. - */ - public XHTMLWriter (Writer out) - { - this (out, null); - } - - /** - * Constructs this handler such that the specified output stream - * is used to write SAX events as XHTML, labeled with the specified - * encoding. - * - * @param out Where the stream of SAX events will be written. - * @param encoding If non-null, this names the encoding to be - * placed in the encoding declaration. - */ - public XHTMLWriter (Writer out, String encoding) - { - super (out, encoding); - setXhtml (true); - } -} diff --git a/libjava/gnu/xml/util/XMLWriter.java b/libjava/gnu/xml/util/XMLWriter.java deleted file mode 100644 index fd36b715325..00000000000 --- a/libjava/gnu/xml/util/XMLWriter.java +++ /dev/null @@ -1,1927 +0,0 @@ -/* XMLWriter.java -- - Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.util; - -import java.io.BufferedWriter; -import java.io.CharConversionException; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.Stack; - -import org.xml.sax.*; -import org.xml.sax.ext.*; -import org.xml.sax.helpers.*; - - -/** - * This class is a SAX handler which writes all its input as a well formed - * XML or XHTML document. If driven using SAX2 events, this output may - * include a recreated document type declaration, subject to limitations - * of SAX (no internal subset exposed) or DOM (the important declarations, - * with their documentation, are discarded). - * - * <p> By default, text is generated "as-is", but some optional modes - * are supported. Pretty-printing is supported, to make life easier - * for people reading the output. XHTML (1.0) output has can be made - * particularly pretty; all the built-in character entities are known. - * Canonical XML can also be generated, assuming the input is properly - * formed. - * - * <hr> - * - * <p> Some of the methods on this class are intended for applications to - * use directly, rather than as pure SAX2 event callbacks. Some of those - * methods access the JavaBeans properties (used to tweak output formats, - * for example canonicalization and pretty printing). Subclasses - * are expected to add new behaviors, not to modify current behavior, so - * many such methods are final.</p> - * - * <p> The <em>write*()</em> methods may be slightly simpler for some - * applications to use than direct callbacks. For example, they support - * a simple policy for encoding data items as the content of a single element. - * - * <p> To reuse an XMLWriter you must provide it with a new Writer, since - * this handler closes the writer it was given as part of its endDocument() - * handling. (XML documents have an end of input, and the way to encode - * that on a stream is to close it.) </p> - * - * <hr> - * - * <p> Note that any relative URIs in the source document, as found in - * entity and notation declarations, ought to have been fully resolved by - * the parser providing events to this handler. This means that the - * output text should only have fully resolved URIs, which may not be - * the desired behavior in cases where later binding is desired. </p> - * - * <p> <em>Note that due to SAX2 defaults, you may need to manually - * ensure that the input events are XML-conformant with respect to namespace - * prefixes and declarations. {@link gnu.xml.pipeline.NSFilter} is - * one solution to this problem, in the context of processing pipelines.</em> - * Something as simple as connecting this handler to a parser might not - * generate the correct output. Another workaround is to ensure that the - * <em>namespace-prefixes</em> feature is always set to true, if you're - * hooking this directly up to some XMLReader implementation. - * - * @see gnu.xml.pipeline.TextConsumer - * - * @author David Brownell - */ -public class XMLWriter - implements ContentHandler, LexicalHandler, DTDHandler, DeclHandler -{ - // text prints/escapes differently depending on context - // CTX_ENTITY ... entity literal value - // CTX_ATTRIBUTE ... attribute literal value - // CTX_CONTENT ... content of an element - // CTX_UNPARSED ... CDATA, comment, PI, names, etc - // CTX_NAME ... name or nmtoken, no escapes possible - private static final int CTX_ENTITY = 1; - private static final int CTX_ATTRIBUTE = 2; - private static final int CTX_CONTENT = 3; - private static final int CTX_UNPARSED = 4; - private static final int CTX_NAME = 5; - -// FIXME: names (element, attribute, PI, notation, etc) are not -// currently written out with range checks (escapeChars). -// In non-XHTML, some names can't be directly written; panic! - - private static String sysEOL; - - static { - try { - sysEOL = System.getProperty ("line.separator", "\n"); - - // don't use the system's EOL if it's illegal XML. - if (!isLineEnd (sysEOL)) - sysEOL = "\n"; - - } catch (SecurityException e) { - sysEOL = "\n"; - } - } - - private static boolean isLineEnd (String eol) - { - return "\n".equals (eol) - || "\r".equals (eol) - || "\r\n".equals (eol); - } - - private Writer out; - private boolean inCDATA; - private int elementNestLevel; - private String eol = sysEOL; - - private short dangerMask; - private StringBuffer stringBuf; - private Locator locator; - private ErrorHandler errHandler; - - private boolean expandingEntities = false; - private int entityNestLevel; - private boolean xhtml; - private boolean startedDoctype; - private String encoding; - - private boolean canonical; - private boolean inDoctype; - private boolean inEpilogue; - - // pretty printing controls - private boolean prettyPrinting; - private int column; - private boolean noWrap; - private Stack space = new Stack (); - - // this is not a hard'n'fast rule -- longer lines are OK, - // but are to be avoided. Here, prettyprinting is more to - // show structure "cleanly" than to be precise about it. - // better to have ragged layout than one line 24Kb long. - private static final int lineLength = 75; - - - /** - * Constructs this handler with System.out used to write SAX events - * using the UTF-8 encoding. Avoid using this except when you know - * it's safe to close System.out at the end of the document. - */ - public XMLWriter () throws IOException - { this (System.out); } - - /** - * Constructs a handler which writes all input to the output stream - * in the UTF-8 encoding, and closes it when endDocument is called. - * (Yes it's annoying that this throws an exception -- but there's - * really no way around it, since it's barely possible a JDK may - * exist somewhere that doesn't know how to emit UTF-8.) - */ - public XMLWriter (OutputStream out) throws IOException - { - this (new OutputStreamWriter (out, "UTF8")); - } - - /** - * Constructs a handler which writes all input to the writer, and then - * closes the writer when the document ends. If an XML declaration is - * written onto the output, and this class can determine the name of - * the character encoding for this writer, that encoding name will be - * included in the XML declaration. - * - * <P> See the description of the constructor which takes an encoding - * name for imporant information about selection of encodings. - * - * @param writer XML text is written to this writer. - */ - public XMLWriter (Writer writer) - { - this (writer, null); - } - - /** - * Constructs a handler which writes all input to the writer, and then - * closes the writer when the document ends. If an XML declaration is - * written onto the output, this class will use the specified encoding - * name in that declaration. If no encoding name is specified, no - * encoding name will be declared unless this class can otherwise - * determine the name of the character encoding for this writer. - * - * <P> At this time, only the UTF-8 ("UTF8") and UTF-16 ("Unicode") - * output encodings are fully lossless with respect to XML data. If you - * use any other encoding you risk having your data be silently mangled - * on output, as the standard Java character encoding subsystem silently - * maps non-encodable characters to a question mark ("?") and will not - * report such errors to applications. - * - * <p> For a few other encodings the risk can be reduced. If the writer is - * a java.io.OutputStreamWriter, and uses either the ISO-8859-1 ("8859_1", - * "ISO8859_1", etc) or US-ASCII ("ASCII") encodings, content which - * can't be encoded in those encodings will be written safely. Where - * relevant, the XHTML entity names will be used; otherwise, numeric - * character references will be emitted. - * - * <P> However, there remain a number of cases where substituting such - * entity or character references is not an option. Such references are - * not usable within a DTD, comment, PI, or CDATA section. Neither may - * they be used when element, attribute, entity, or notation names have - * the problematic characters. - * - * @param writer XML text is written to this writer. - * @param encoding if non-null, and an XML declaration is written, - * this is the name that will be used for the character encoding. - */ - public XMLWriter (Writer writer, String encoding) - { - setWriter (writer, encoding); - } - - private void setEncoding (String encoding) - { - if (encoding == null && out instanceof OutputStreamWriter) - encoding = ((OutputStreamWriter)out).getEncoding (); - - if (encoding != null) { - encoding = encoding.toUpperCase (); - - // Use official encoding names where we know them, - // avoiding the Java-only names. When using common - // encodings where we can easily tell if characters - // are out of range, we'll escape out-of-range - // characters using character refs for safety. - - // I _think_ these are all the main synonyms for these! - if ("UTF8".equals (encoding)) { - encoding = "UTF-8"; - } else if ("US-ASCII".equals (encoding) - || "ASCII".equals (encoding)) { - dangerMask = (short) 0xff80; - encoding = "US-ASCII"; - } else if ("ISO-8859-1".equals (encoding) - || "8859_1".equals (encoding) - || "ISO8859_1".equals (encoding)) { - dangerMask = (short) 0xff00; - encoding = "ISO-8859-1"; - } else if ("UNICODE".equals (encoding) - || "UNICODE-BIG".equals (encoding) - || "UNICODE-LITTLE".equals (encoding)) { - encoding = "UTF-16"; - - // TODO: UTF-16BE, UTF-16LE ... no BOM; what - // release of JDK supports those Unicode names? - } - - if (dangerMask != 0) - stringBuf = new StringBuffer (); - } - - this.encoding = encoding; - } - - - /** - * Resets the handler to write a new text document. - * - * @param writer XML text is written to this writer. - * @param encoding if non-null, and an XML declaration is written, - * this is the name that will be used for the character encoding. - * - * @exception IllegalStateException if the current - * document hasn't yet ended (with {@link #endDocument}) - */ - final public void setWriter (Writer writer, String encoding) - { - if (out != null) - throw new IllegalStateException ( - "can't change stream in mid course"); - out = writer; - if (out != null) - setEncoding (encoding); - if (!(out instanceof BufferedWriter)) - out = new BufferedWriter (out); - space.push ("default"); - } - - /** - * Assigns the line ending style to be used on output. - * @param eolString null to use the system default; else - * "\n", "\r", or "\r\n". - */ - final public void setEOL (String eolString) - { - if (eolString == null) - eol = sysEOL; - else if (!isLineEnd (eolString)) - eol = eolString; - else - throw new IllegalArgumentException (eolString); - } - - /** - * Assigns the error handler to be used to present most fatal - * errors. - */ - public void setErrorHandler (ErrorHandler handler) - { - errHandler = handler; - } - - /** - * Used internally and by subclasses, this encapsulates the logic - * involved in reporting fatal errors. It uses locator information - * for good diagnostics, if available, and gives the application's - * ErrorHandler the opportunity to handle the error before throwing - * an exception. - */ - protected void fatal (String message, Exception e) - throws SAXException - { - SAXParseException x; - - if (locator == null) - x = new SAXParseException (message, null, null, -1, -1, e); - else - x = new SAXParseException (message, locator, e); - if (errHandler != null) - errHandler.fatalError (x); - throw x; - } - - - // JavaBeans properties - - /** - * Controls whether the output should attempt to follow the "transitional" - * XHTML rules so that it meets the "HTML Compatibility Guidelines" - * appendix in the XHTML specification. A "transitional" Document Type - * Declaration (DTD) is placed near the beginning of the output document, - * instead of whatever DTD would otherwise have been placed there, and - * XHTML empty elements are printed specially. When writing text in - * US-ASCII or ISO-8859-1 encodings, the predefined XHTML internal - * entity names are used (in preference to character references) when - * writing content characters which can't be expressed in those encodings. - * - * <p> When this option is enabled, it is the caller's responsibility - * to ensure that the input is otherwise valid as XHTML. Things to - * be careful of in all cases, as described in the appendix referenced - * above, include: <ul> - * - * <li> Element and attribute names must be in lower case, both - * in the document and in any CSS style sheet. - * <li> All XML constructs must be valid as defined by the XHTML - * "transitional" DTD (including all familiar constructs, - * even deprecated ones). - * <li> The root element must be "html". - * <li> Elements that must be empty (such as <em><br></em> - * must have no content. - * <li> Use both <em>lang</em> and <em>xml:lang</em> attributes - * when specifying language. - * <li> Similarly, use both <em>id</em> and <em>name</em> attributes - * when defining elements that may be referred to through - * URI fragment identifiers ... and make sure that the - * value is a legal NMTOKEN, since not all such HTML 4.0 - * identifiers are valid in XML. - * <li> Be careful with character encodings; make sure you provide - * a <em><meta http-equiv="Content-type" - * content="text/xml;charset=..." /></em> element in - * the HTML "head" element, naming the same encoding - * used to create this handler. Also, if that encoding - * is anything other than US-ASCII, make sure that if - * the document is given a MIME content type, it has - * a <em>charset=...</em> attribute with that encoding. - * </ul> - * - * <p> Additionally, some of the oldest browsers have additional - * quirks, to address with guidelines such as: <ul> - * - * <li> Processing instructions may be rendered, so avoid them. - * (Similarly for an XML declaration.) - * <li> Embedded style sheets and scripts should not contain XML - * markup delimiters: &, <, and ]]> are trouble. - * <li> Attribute values should not have line breaks or multiple - * consecutive white space characters. - * <li> Use no more than one of the deprecated (transitional) - * <em><isindex></em> elements. - * <li> Some boolean attributes (such as <em>compact, checked, - * disabled, readonly, selected,</em> and more) confuse - * some browsers, since they only understand minimized - * versions which are illegal in XML. - * </ul> - * - * <p> Also, some characteristics of the resulting output may be - * a function of whether the document is later given a MIME - * content type of <em>text/html</em> rather than one indicating - * XML (<em>application/xml</em> or <em>text/xml</em>). Worse, - * some browsers ignore MIME content types and prefer to rely URI - * name suffixes -- so an "index.xml" could always be XML, never - * XHTML, no matter its MIME type. - */ - final public void setXhtml (boolean value) - { - if (locator != null) - throw new IllegalStateException ("started parsing"); - xhtml = value; - if (xhtml) - canonical = false; - } - - /** - * Returns true if the output attempts to echo the input following - * "transitional" XHTML rules and matching the "HTML Compatibility - * Guidelines" so that an HTML version 3 browser can read the output - * as HTML; returns false (the default) othewise. - */ - final public boolean isXhtml () - { - return xhtml; - } - - /** - * Controls whether the output text contains references to - * entities (the default), or instead contains the expanded - * values of those entities. - */ - final public void setExpandingEntities (boolean value) - { - if (locator != null) - throw new IllegalStateException ("started parsing"); - expandingEntities = value; - if (!expandingEntities) - canonical = false; - } - - /** - * Returns true if the output will have no entity references; - * returns false (the default) otherwise. - */ - final public boolean isExpandingEntities () - { - return expandingEntities; - } - - /** - * Controls pretty-printing, which by default is not enabled - * (and currently is most useful for XHTML output). - * Pretty printing enables structural indentation, sorting of attributes - * by name, line wrapping, and potentially other mechanisms for making - * output more or less readable. - * - * <p> At this writing, structural indentation and line wrapping are - * enabled when pretty printing is enabled and the <em>xml:space</em> - * attribute has the value <em>default</em> (its other legal value is - * <em>preserve</em>, as defined in the XML specification). The three - * XHTML element types which use another value are recognized by their - * names (namespaces are ignored). - * - * <p> Also, for the record, the "pretty" aspect of printing here - * is more to provide basic structure on outputs that would otherwise - * risk being a single long line of text. For now, expect the - * structure to be ragged ... unless you'd like to submit a patch - * to make this be more strictly formatted! - * - * @exception IllegalStateException thrown if this method is invoked - * after output has begun. - */ - final public void setPrettyPrinting (boolean value) - { - if (locator != null) - throw new IllegalStateException ("started parsing"); - prettyPrinting = value; - if (prettyPrinting) - canonical = false; - } - - /** - * Returns value of flag controlling pretty printing. - */ - final public boolean isPrettyPrinting () - { - return prettyPrinting; - } - - - /** - * Sets the output style to be canonicalized. Input events must - * meet requirements that are slightly more stringent than the - * basic well-formedness ones, and include: <ul> - * - * <li> Namespace prefixes must not have been changed from those - * in the original document. (This may only be ensured by setting - * the SAX2 XMLReader <em>namespace-prefixes</em> feature flag; - * by default, it is cleared.) - * - * <li> Redundant namespace declaration attributes have been - * removed. (If an ancestor element defines a namespace prefix - * and that declaration hasn't been overriden, an element must - * not redeclare it.) - * - * <li> If comments are not to be included in the canonical output, - * they must first be removed from the input event stream; this - * <em>Canonical XML with comments</em> by default. - * - * <li> If the input character encoding was not UCS-based, the - * character data must have been normalized using Unicode - * Normalization Form C. (UTF-8 and UTF-16 are UCS-based.) - * - * <li> Attribute values must have been normalized, as is done - * by any conformant XML processor which processes all external - * parameter entities. - * - * <li> Similarly, attribute value defaulting has been performed. - * - * </ul> - * - * <p> Note that fragments of XML documents, as specified by an XPath - * node set, may be canonicalized. In such cases, elements may need - * some fixup (for <em>xml:*</em> attributes and application-specific - * context). - * - * @exception IllegalArgumentException if the output encoding - * is anything other than UTF-8. - */ - final public void setCanonical (boolean value) - { - if (value && !"UTF-8".equals (encoding)) - throw new IllegalArgumentException ("encoding != UTF-8"); - canonical = value; - if (canonical) { - prettyPrinting = xhtml = false; - expandingEntities = true; - eol = "\n"; - } - } - - - /** - * Returns value of flag controlling canonical output. - */ - final public boolean isCanonical () - { - return canonical; - } - - - /** - * Flushes the output stream. When this handler is used in long lived - * pipelines, it can be important to flush buffered state, for example - * so that it can reach the disk as part of a state checkpoint. - */ - final public void flush () - throws IOException - { - if (out != null) - out.flush (); - } - - - // convenience routines - -// FIXME: probably want a subclass that holds a lot of these... -// and maybe more! - - /** - * Writes the string as if characters() had been called on the contents - * of the string. This is particularly useful when applications act as - * producers and write data directly to event consumers. - */ - final public void write (String data) - throws SAXException - { - char buf [] = data.toCharArray (); - characters (buf, 0, buf.length); - } - - - /** - * Writes an element that has content consisting of a single string. - * @see #writeEmptyElement - * @see #startElement - */ - public void writeElement ( - String uri, - String localName, - String qName, - Attributes atts, - String content - ) throws SAXException - { - if (content == null || content.length () == 0) { - writeEmptyElement (uri, localName, qName, atts); - return; - } - startElement (uri, localName, qName, atts); - char chars [] = content.toCharArray (); - characters (chars, 0, chars.length); - endElement (uri, localName, qName); - } - - - /** - * Writes an element that has content consisting of a single integer, - * encoded as a decimal string. - * @see #writeEmptyElement - * @see #startElement - */ - public void writeElement ( - String uri, - String localName, - String qName, - Attributes atts, - int content - ) throws SAXException - { - writeElement (uri, localName, qName, atts, Integer.toString (content)); - } - - - // SAX1 ContentHandler - /** <b>SAX1</b>: provides parser status information */ - final public void setDocumentLocator (Locator l) - { - locator = l; - } - - - // URL for dtd that validates against all normal HTML constructs - private static final String xhtmlFullDTD = - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; - - - /** - * <b>SAX1</b>: indicates the beginning of a document parse. - * If you're writing (well formed) fragments of XML, neither - * this nor endDocument should be called. - */ - // NOT final - public void startDocument () - throws SAXException - { - try { - if (out == null) - throw new IllegalStateException ( - "null Writer given to XMLWriter"); - - // Not all parsers provide the locator we want; this also - // flags whether events are being sent to this object yet. - // We could only have this one call if we only printed whole - // documents ... but we also print fragments, so most of the - // callbacks here replicate this test. - - if (locator == null) - locator = new LocatorImpl (); - - // Unless the data is in US-ASCII or we're canonicalizing, write - // the XML declaration if we know the encoding. US-ASCII won't - // normally get mangled by web server confusion about the - // character encodings used. Plus, it's an easy way to - // ensure we can write ASCII that's unlikely to confuse - // elderly HTML parsers. - - if (!canonical - && dangerMask != (short) 0xff80 - && encoding != null) { - rawWrite ("<?xml version='1.0'"); - rawWrite (" encoding='" + encoding + "'"); - rawWrite ("?>"); - newline (); - } - - if (xhtml) { - - rawWrite ("<!DOCTYPE html PUBLIC"); - newline (); - rawWrite (" '-//W3C//DTD XHTML 1.0 Transitional//EN'"); - newline (); - rawWrite (" '"); - // NOTE: URL (above) matches the REC - rawWrite (xhtmlFullDTD); - rawWrite ("'>"); - newline (); - newline (); - - // fake the rest of the handler into ignoring - // everything until the root element, so any - // XHTML DTD comments, PIs, etc are ignored - startedDoctype = true; - } - - entityNestLevel = 0; - - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * <b>SAX1</b>: indicates the completion of a parse. - * Note that all complete SAX event streams make this call, even - * if an error is reported during a parse. - */ - // NOT final - public void endDocument () - throws SAXException - { - try { - if (!canonical) { - newline (); - newline (); - } - out.close (); - out = null; - locator = null; - } catch (IOException e) { - fatal ("can't write", e); - } - } - - // XHTML elements declared as EMPTY print differently - final private static boolean isEmptyElementTag (String tag) - { - switch (tag.charAt (0)) { - case 'a': return "area".equals (tag); - case 'b': return "base".equals (tag) - || "basefont".equals (tag) - || "br".equals (tag); - case 'c': return "col".equals (tag); - case 'f': return "frame".equals (tag); - case 'h': return "hr".equals (tag); - case 'i': return "img".equals (tag) - || "input".equals (tag) - || "isindex".equals (tag); - case 'l': return "link".equals (tag); - case 'm': return "meta".equals (tag); - case 'p': return "param".equals (tag); - } - return false; - } - - private static boolean indentBefore (String tag) - { - // basically indent before block content - // and within structure like tables, lists - switch (tag.charAt (0)) { - case 'a': return "applet".equals (tag); - case 'b': return "body".equals (tag) - || "blockquote".equals (tag); - case 'c': return "center".equals (tag); - case 'f': return "frame".equals (tag) - || "frameset".equals (tag); - case 'h': return "head".equals (tag); - case 'm': return "meta".equals (tag); - case 'o': return "object".equals (tag); - case 'p': return "param".equals (tag) - || "pre".equals (tag); - case 's': return "style".equals (tag); - case 't': return "title".equals (tag) - || "td".equals (tag) - || "th".equals (tag); - } - // ... but not inline elements like "em", "b", "font" - return false; - } - - private static boolean spaceBefore (String tag) - { - // blank line AND INDENT before certain structural content - switch (tag.charAt (0)) { - case 'h': return "h1".equals (tag) - || "h2".equals (tag) - || "h3".equals (tag) - || "h4".equals (tag) - || "h5".equals (tag) - || "h6".equals (tag) - || "hr".equals (tag); - case 'l': return "li".equals (tag); - case 'o': return "ol".equals (tag); - case 'p': return "p".equals (tag); - case 't': return "table".equals (tag) - || "tr".equals (tag); - case 'u': return "ul".equals (tag); - } - return false; - } - - // XHTML DTDs say these three have xml:space="preserve" - private static boolean spacePreserve (String tag) - { - return "pre".equals (tag) - || "style".equals (tag) - || "script".equals (tag); - } - - /** - * <b>SAX2</b>: ignored. - */ - final public void startPrefixMapping (String prefix, String uri) - {} - - /** - * <b>SAX2</b>: ignored. - */ - final public void endPrefixMapping (String prefix) - {} - - private void writeStartTag ( - String name, - Attributes atts, - boolean isEmpty - ) throws SAXException, IOException - { - rawWrite ('<'); - rawWrite (name); - - // write out attributes ... sorting is particularly useful - // with output that's been heavily defaulted. - if (atts != null && atts.getLength () != 0) { - - // Set up to write, with optional sorting - int indices [] = new int [atts.getLength ()]; - - for (int i= 0; i < indices.length; i++) - indices [i] = i; - - // optionally sort - -// FIXME: canon xml demands xmlns nodes go first, -// and sorting by URI first (empty first) then localname -// it should maybe use a different sort - - if (canonical || prettyPrinting) { - - // insertion sort by attribute name - for (int i = 1; i < indices.length; i++) { - int n = indices [i], j; - String s = atts.getQName (n); - - for (j = i - 1; j >= 0; j--) { - if (s.compareTo (atts.getQName (indices [j])) - >= 0) - break; - indices [j + 1] = indices [j]; - } - indices [j + 1] = n; - } - } - - // write, sorted or no - for (int i= 0; i < indices.length; i++) { - String s = atts.getQName (indices [i]); - - if (s == null || "".equals (s)) - throw new IllegalArgumentException ("no XML name"); - rawWrite (" "); - rawWrite (s); - rawWrite ("="); - writeQuotedValue (atts.getValue (indices [i]), - CTX_ATTRIBUTE); - } - } - if (isEmpty) - rawWrite (" /"); - rawWrite ('>'); - } - - /** - * <b>SAX2</b>: indicates the start of an element. - * When XHTML is in use, avoid attribute values with - * line breaks or multiple whitespace characters, since - * not all user agents handle them correctly. - */ - final public void startElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - startedDoctype = false; - - if (locator == null) - locator = new LocatorImpl (); - - if (qName == null || "".equals (qName)) - throw new IllegalArgumentException ("no XML name"); - - try { - if (entityNestLevel != 0) - return; - if (prettyPrinting) { - String whitespace = null; - - if (xhtml && spacePreserve (qName)) - whitespace = "preserve"; - else if (atts != null) - whitespace = atts.getValue ("xml:space"); - if (whitespace == null) - whitespace = (String) space.peek (); - space.push (whitespace); - - if ("default".equals (whitespace)) { - if (xhtml) { - if (spaceBefore (qName)) { - newline (); - doIndent (); - } else if (indentBefore (qName)) - doIndent (); - // else it's inlined, modulo line length - // FIXME: incrementing element nest level - // for inlined elements causes ugliness - } else - doIndent (); - } - } - elementNestLevel++; - writeStartTag (qName, atts, xhtml && isEmptyElementTag (qName)); - - if (xhtml) { -// FIXME: if this is an XHTML "pre" element, turn -// off automatic wrapping. - } - - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * Writes an empty element. - * @see #startElement - */ - public void writeEmptyElement ( - String uri, - String localName, - String qName, - Attributes atts - ) throws SAXException - { - if (canonical) { - startElement (uri, localName, qName, atts); - endElement (uri, localName, qName); - } else { - try { - writeStartTag (qName, atts, true); - } catch (IOException e) { - fatal ("can't write", e); - } - } - } - - - /** <b>SAX2</b>: indicates the end of an element */ - final public void endElement (String uri, String localName, String qName) - throws SAXException - { - if (qName == null || "".equals (qName)) - throw new IllegalArgumentException ("no XML name"); - - try { - elementNestLevel--; - if (entityNestLevel != 0) - return; - if (xhtml && isEmptyElementTag (qName)) - return; - rawWrite ("</"); - rawWrite (qName); - rawWrite ('>'); - - if (prettyPrinting) { - if (!space.empty ()) - space.pop (); - else - fatal ("stack discipline", null); - } - if (elementNestLevel == 0) - inEpilogue = true; - - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX1</b>: reports content characters */ - final public void characters (char ch [], int start, int length) - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - - try { - if (entityNestLevel != 0) - return; - if (inCDATA) { - escapeChars (ch, start, length, CTX_UNPARSED); - } else { - escapeChars (ch, start, length, CTX_CONTENT); - } - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX1</b>: reports ignorable whitespace */ - final public void ignorableWhitespace (char ch [], int start, int length) - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - - try { - if (entityNestLevel != 0) - return; - // don't forget to map NL to CRLF, CR, etc - escapeChars (ch, start, length, CTX_CONTENT); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * <b>SAX1</b>: reports a PI. - * This doesn't check for illegal target names, such as "xml" or "XML", - * or namespace-incompatible ones like "big:dog"; the caller is - * responsible for ensuring those names are legal. - */ - final public void processingInstruction (String target, String data) - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - - // don't print internal subset for XHTML - if (xhtml && startedDoctype) - return; - - // ancient HTML browsers might render these ... their loss. - // to prevent: "if (xhtml) return;". - - try { - if (entityNestLevel != 0) - return; - if (canonical && inEpilogue) - newline (); - rawWrite ("<?"); - rawWrite (target); - rawWrite (' '); - escapeChars (data.toCharArray (), -1, -1, CTX_UNPARSED); - rawWrite ("?>"); - if (elementNestLevel == 0 && !(canonical && inEpilogue)) - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX1</b>: indicates a non-expanded entity reference */ - public void skippedEntity (String name) - throws SAXException - { - try { - rawWrite ("&"); - rawWrite (name); - rawWrite (";"); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - // SAX2 LexicalHandler - - /** <b>SAX2</b>: called before parsing CDATA characters */ - final public void startCDATA () - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - - if (canonical) - return; - - try { - inCDATA = true; - if (entityNestLevel == 0) - rawWrite ("<![CDATA["); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX2</b>: called after parsing CDATA characters */ - final public void endCDATA () - throws SAXException - { - if (canonical) - return; - - try { - inCDATA = false; - if (entityNestLevel == 0) - rawWrite ("]]>"); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * <b>SAX2</b>: called when the doctype is partially parsed - * Note that this, like other doctype related calls, is ignored - * when XHTML is in use. - */ - final public void startDTD (String name, String publicId, String systemId) - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - if (xhtml) - return; - try { - inDoctype = startedDoctype = true; - if (canonical) - return; - rawWrite ("<!DOCTYPE "); - rawWrite (name); - rawWrite (' '); - - if (!expandingEntities) { - if (publicId != null) - rawWrite ("PUBLIC '" + publicId + "' '" + systemId + "' "); - else if (systemId != null) - rawWrite ("SYSTEM '" + systemId + "' "); - } - - rawWrite ('['); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX2</b>: called after the doctype is parsed */ - final public void endDTD () - throws SAXException - { - inDoctype = false; - if (canonical || xhtml) - return; - try { - rawWrite ("]>"); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * <b>SAX2</b>: called before parsing a general entity in content - */ - final public void startEntity (String name) - throws SAXException - { - try { - boolean writeEOL = true; - - // Predefined XHTML entities (for characters) will get - // mapped back later. - if (xhtml || expandingEntities) - return; - - entityNestLevel++; - if (name.equals ("[dtd]")) - return; - if (entityNestLevel != 1) - return; - if (!name.startsWith ("%")) { - writeEOL = false; - rawWrite ('&'); - } - rawWrite (name); - rawWrite (';'); - if (writeEOL) - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** - * <b>SAX2</b>: called after parsing a general entity in content - */ - final public void endEntity (String name) - throws SAXException - { - if (xhtml || expandingEntities) - return; - entityNestLevel--; - } - - /** - * <b>SAX2</b>: called when comments are parsed. - * When XHTML is used, the old HTML tradition of using comments - * to for inline CSS, or for JavaScript code is discouraged. - * This is because XML processors are encouraged to discard, on - * the grounds that comments are for users (and perhaps text - * editors) not programs. Instead, use external scripts - */ - final public void comment (char ch [], int start, int length) - throws SAXException - { - if (locator == null) - locator = new LocatorImpl (); - - // don't print internal subset for XHTML - if (xhtml && startedDoctype) - return; - // don't print comment in doctype for canon xml - if (canonical && inDoctype) - return; - - try { - boolean indent; - - if (prettyPrinting && space.empty ()) - fatal ("stack discipline", null); - indent = prettyPrinting && "default".equals (space.peek ()); - if (entityNestLevel != 0) - return; - if (indent) - doIndent (); - if (canonical && inEpilogue) - newline (); - rawWrite ("<!--"); - escapeChars (ch, start, length, CTX_UNPARSED); - rawWrite ("-->"); - if (indent) - doIndent (); - if (elementNestLevel == 0 && !(canonical && inEpilogue)) - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - // SAX1 DTDHandler - - /** <b>SAX1</b>: called on notation declarations */ - final public void notationDecl (String name, - String publicId, String systemId) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) - return; - - if (entityNestLevel != 0) - return; - rawWrite ("<!NOTATION " + name + " "); - if (publicId != null) - rawWrite ("PUBLIC \"" + publicId + '"'); - else - rawWrite ("SYSTEM "); - if (systemId != null) - rawWrite ('"' + systemId + '"'); - rawWrite (">"); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX1</b>: called on unparsed entity declarations */ - final public void unparsedEntityDecl (String name, - String publicId, String systemId, - String notationName) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) { - // FIXME: write to temporary buffer, and make the start - // of the root element write these declarations. - return; - } - - if (entityNestLevel != 0) - return; - rawWrite ("<!ENTITY " + name + " "); - if (publicId != null) - rawWrite ("PUBLIC \"" + publicId + '"'); - else - rawWrite ("SYSTEM "); - rawWrite ('"' + systemId + '"'); - rawWrite (" NDATA " + notationName + ">"); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - // SAX2 DeclHandler - - /** <b>SAX2</b>: called on attribute declarations */ - final public void attributeDecl (String eName, String aName, - String type, String mode, String value) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) - return; - if (entityNestLevel != 0) - return; - rawWrite ("<!ATTLIST " + eName + ' ' + aName + ' '); - rawWrite (type); - rawWrite (' '); - if (mode != null) - rawWrite (mode + ' '); - if (value != null) - writeQuotedValue (value, CTX_ATTRIBUTE); - rawWrite ('>'); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX2</b>: called on element declarations */ - final public void elementDecl (String name, String model) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) - return; - if (entityNestLevel != 0) - return; - rawWrite ("<!ELEMENT " + name + ' ' + model + '>'); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX2</b>: called on external entity declarations */ - final public void externalEntityDecl ( - String name, - String publicId, - String systemId) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) - return; - if (entityNestLevel != 0) - return; - rawWrite ("<!ENTITY "); - if (name.startsWith ("%")) { - rawWrite ("% "); - rawWrite (name.substring (1)); - } else - rawWrite (name); - if (publicId != null) - rawWrite (" PUBLIC \"" + publicId + '"'); - else - rawWrite (" SYSTEM "); - rawWrite ('"' + systemId + "\">"); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - /** <b>SAX2</b>: called on internal entity declarations */ - final public void internalEntityDecl (String name, String value) - throws SAXException - { - if (xhtml) - return; - try { - // At this time, only SAX2 callbacks start these. - if (!startedDoctype) - return; - if (entityNestLevel != 0) - return; - rawWrite ("<!ENTITY "); - if (name.startsWith ("%")) { - rawWrite ("% "); - rawWrite (name.substring (1)); - } else - rawWrite (name); - rawWrite (' '); - writeQuotedValue (value, CTX_ENTITY); - rawWrite ('>'); - newline (); - } catch (IOException e) { - fatal ("can't write", e); - } - } - - private void writeQuotedValue (String value, int code) - throws SAXException, IOException - { - char buf [] = value.toCharArray (); - int off = 0, len = buf.length; - - // we can't add line breaks to attribute/entity/... values - noWrap = true; - rawWrite ('"'); - escapeChars (buf, off, len, code); - rawWrite ('"'); - noWrap = false; - } - - // From "HTMLlat1x.ent" ... names of entities for ISO-8859-1 - // (Latin/1) characters, all codes: 160-255 (0xA0-0xFF). - // Codes 128-159 have no assigned values. - private static final String HTMLlat1x [] = { - // 160 - "nbsp", "iexcl", "cent", "pound", "curren", - "yen", "brvbar", "sect", "uml", "copy", - - // 170 - "ordf", "laquo", "not", "shy", "reg", - "macr", "deg", "plusmn", "sup2", "sup3", - - // 180 - "acute", "micro", "para", "middot", "cedil", - "sup1", "ordm", "raquo", "frac14", "frac12", - - // 190 - "frac34", "iquest", "Agrave", "Aacute", "Acirc", - "Atilde", "Auml", "Aring", "AElig", "Ccedil", - - // 200 - "Egrave", "Eacute", "Ecirc", "Euml", "Igrave", - "Iacute", "Icirc", "Iuml", "ETH", "Ntilde", - - // 210 - "Ograve", "Oacute", "Ocirc", "Otilde", "Ouml", - "times", "Oslash", "Ugrave", "Uacute", "Ucirc", - - // 220 - "Uuml", "Yacute", "THORN", "szlig", "agrave", - "aacute", "acirc", "atilde", "auml", "aring", - - // 230 - "aelig", "ccedil", "egrave", "eacute", "ecirc", - "euml", "igrave", "iacute", "icirc", "iuml", - - // 240 - "eth", "ntilde", "ograve", "oacute", "ocirc", - "otilde", "ouml", "divide", "oslash", "ugrave", - - // 250 - "uacute", "ucirc", "uuml", "yacute", "thorn", - "yuml" - }; - - // From "HTMLsymbolx.ent" ... some of the symbols that - // we can conveniently handle. Entities for the Greek. - // alphabet (upper and lower cases) are compact. - private static final String HTMLsymbolx_GR [] = { - // 913 - "Alpha", "Beta", "Gamma", "Delta", "Epsilon", - "Zeta", "Eta", "Theta", "Iota", "Kappa", - - // 923 - "Lambda", "Mu", "Nu", "Xi", "Omicron", - "Pi", "Rho", null, "Sigma", "Tau", - - // 933 - "Upsilon", "Phi", "Chi", "Psi", "Omega" - }; - - private static final String HTMLsymbolx_gr [] = { - // 945 - "alpha", "beta", "gamma", "delta", "epsilon", - "zeta", "eta", "theta", "iota", "kappa", - - // 955 - "lambda", "mu", "nu", "xi", "omicron", - "pi", "rho", "sigmaf", "sigma", "tau", - - // 965 - "upsilon", "phi", "chi", "psi", "omega" - }; - - - // General routine to write text and substitute predefined - // entities (XML, and a special case for XHTML) as needed. - private void escapeChars (char buf [], int off, int len, int code) - throws SAXException, IOException - { - int first = 0; - - if (off < 0) { - off = 0; - len = buf.length; - } - for (int i = 0; i < len; i++) { - String esc; - char c = buf [off + i]; - - switch (c) { - // Note that CTX_ATTRIBUTE isn't explicitly tested here; - // all syntax delimiters are escaped in CTX_ATTRIBUTE, - // otherwise it's similar to CTX_CONTENT - - // ampersand flags entity references; entity replacement - // text has unexpanded references, other text doesn't. - case '&': - if (code == CTX_ENTITY || code == CTX_UNPARSED) - continue; - esc = "amp"; - break; - - // attributes and text may NOT have literal '<', but - // entities may have markup constructs - case '<': - if (code == CTX_ENTITY || code == CTX_UNPARSED) - continue; - esc = "lt"; - break; - - // as above re markup constructs; but otherwise - // except when canonicalizing, this is for consistency - case '>': - if (code == CTX_ENTITY || code == CTX_UNPARSED) - continue; - esc = "gt"; - break; - case '\'': - if (code == CTX_CONTENT || code == CTX_UNPARSED) - continue; - if (canonical) - continue; - esc = "apos"; - break; - - // needed when printing quoted attribute/entity values - case '"': - if (code == CTX_CONTENT || code == CTX_UNPARSED) - continue; - esc = "quot"; - break; - - // make line ends work per host OS convention - case '\n': - esc = eol; - break; - - // - // No other characters NEED special treatment ... except - // for encoding-specific issues, like whether the character - // can really be represented in that encoding. - // - default: - // - // There are characters we can never write safely; getting - // them is an error. - // - // (a) They're never legal in XML ... detected by range - // checks, and (eventually) by remerging surrogate - // pairs on output. (Easy error for apps to prevent.) - // - // (b) This encoding can't represent them, and we - // can't make reference substitution (e.g. inside - // CDATA sections, names, PI data, etc). (Hard for - // apps to prevent, except by using UTF-8 or UTF-16 - // as their output encoding.) - // - // We know a very little bit about what characters - // the US-ASCII and ISO-8859-1 encodings support. For - // other encodings we can't detect the second type of - // error at all. (Never an issue for UTF-8 or UTF-16.) - // - -// FIXME: CR in CDATA is an error; in text, turn to a char ref - -// FIXME: CR/LF/TAB in attributes should become char refs - - if ((c > 0xfffd) - || ((c < 0x0020) && !((c == 0x0009) - || (c == 0x000A) || (c == 0x000D))) - || (((c & dangerMask) != 0) - && (code == CTX_UNPARSED))) { - - // if case (b) in CDATA, we might end the section, - // write a reference, then restart ... possible - // in one DOM L3 draft. - - throw new CharConversionException ( - "Illegal or non-writable character: U+" - + Integer.toHexString (c)); - } - - // - // If the output encoding represents the character - // directly, let it do so! Else we'll escape it. - // - if ((c & dangerMask) == 0) - continue; - esc = null; - - // Avoid numeric refs where symbolic ones exist, as - // symbolic ones make more sense to humans reading! - if (xhtml) { - // all the HTMLlat1x.ent entities - // (all the "ISO-8859-1" characters) - if (c >= 160 && c <= 255) - esc = HTMLlat1x [c - 160]; - - // not quite half the HTMLsymbolx.ent entities - else if (c >= 913 && c <= 937) - esc = HTMLsymbolx_GR [c - 913]; - else if (c >= 945 && c <= 969) - esc = HTMLsymbolx_gr [c - 945]; - - else switch (c) { - // all of the HTMLspecialx.ent entities - case 338: esc = "OElig"; break; - case 339: esc = "oelig"; break; - case 352: esc = "Scaron"; break; - case 353: esc = "scaron"; break; - case 376: esc = "Yuml"; break; - case 710: esc = "circ"; break; - case 732: esc = "tilde"; break; - case 8194: esc = "ensp"; break; - case 8195: esc = "emsp"; break; - case 8201: esc = "thinsp"; break; - case 8204: esc = "zwnj"; break; - case 8205: esc = "zwj"; break; - case 8206: esc = "lrm"; break; - case 8207: esc = "rlm"; break; - case 8211: esc = "ndash"; break; - case 8212: esc = "mdash"; break; - case 8216: esc = "lsquo"; break; - case 8217: esc = "rsquo"; break; - case 8218: esc = "sbquo"; break; - case 8220: esc = "ldquo"; break; - case 8221: esc = "rdquo"; break; - case 8222: esc = "bdquo"; break; - case 8224: esc = "dagger"; break; - case 8225: esc = "Dagger"; break; - case 8240: esc = "permil"; break; - case 8249: esc = "lsaquo"; break; - case 8250: esc = "rsaquo"; break; - case 8364: esc = "euro"; break; - - // the other HTMLsymbox.ent entities - case 402: esc = "fnof"; break; - case 977: esc = "thetasym"; break; - case 978: esc = "upsih"; break; - case 982: esc = "piv"; break; - case 8226: esc = "bull"; break; - case 8230: esc = "hellip"; break; - case 8242: esc = "prime"; break; - case 8243: esc = "Prime"; break; - case 8254: esc = "oline"; break; - case 8260: esc = "frasl"; break; - case 8472: esc = "weierp"; break; - case 8465: esc = "image"; break; - case 8476: esc = "real"; break; - case 8482: esc = "trade"; break; - case 8501: esc = "alefsym"; break; - case 8592: esc = "larr"; break; - case 8593: esc = "uarr"; break; - case 8594: esc = "rarr"; break; - case 8595: esc = "darr"; break; - case 8596: esc = "harr"; break; - case 8629: esc = "crarr"; break; - case 8656: esc = "lArr"; break; - case 8657: esc = "uArr"; break; - case 8658: esc = "rArr"; break; - case 8659: esc = "dArr"; break; - case 8660: esc = "hArr"; break; - case 8704: esc = "forall"; break; - case 8706: esc = "part"; break; - case 8707: esc = "exist"; break; - case 8709: esc = "empty"; break; - case 8711: esc = "nabla"; break; - case 8712: esc = "isin"; break; - case 8713: esc = "notin"; break; - case 8715: esc = "ni"; break; - case 8719: esc = "prod"; break; - case 8721: esc = "sum"; break; - case 8722: esc = "minus"; break; - case 8727: esc = "lowast"; break; - case 8730: esc = "radic"; break; - case 8733: esc = "prop"; break; - case 8734: esc = "infin"; break; - case 8736: esc = "ang"; break; - case 8743: esc = "and"; break; - case 8744: esc = "or"; break; - case 8745: esc = "cap"; break; - case 8746: esc = "cup"; break; - case 8747: esc = "int"; break; - case 8756: esc = "there4"; break; - case 8764: esc = "sim"; break; - case 8773: esc = "cong"; break; - case 8776: esc = "asymp"; break; - case 8800: esc = "ne"; break; - case 8801: esc = "equiv"; break; - case 8804: esc = "le"; break; - case 8805: esc = "ge"; break; - case 8834: esc = "sub"; break; - case 8835: esc = "sup"; break; - case 8836: esc = "nsub"; break; - case 8838: esc = "sube"; break; - case 8839: esc = "supe"; break; - case 8853: esc = "oplus"; break; - case 8855: esc = "otimes"; break; - case 8869: esc = "perp"; break; - case 8901: esc = "sdot"; break; - case 8968: esc = "lceil"; break; - case 8969: esc = "rceil"; break; - case 8970: esc = "lfloor"; break; - case 8971: esc = "rfloor"; break; - case 9001: esc = "lang"; break; - case 9002: esc = "rang"; break; - case 9674: esc = "loz"; break; - case 9824: esc = "spades"; break; - case 9827: esc = "clubs"; break; - case 9829: esc = "hearts"; break; - case 9830: esc = "diams"; break; - } - } - - // else escape with numeric char refs - if (esc == null) { - stringBuf.setLength (0); - stringBuf.append ("#x"); - stringBuf.append (Integer.toHexString (c).toUpperCase ()); - esc = stringBuf.toString (); - - // FIXME: We don't write surrogate pairs correctly. - // They should work as one ref per character, since - // each pair is one character. For reading back into - // Unicode, it matters beginning in Unicode 3.1 ... - } - break; - } - if (i != first) - rawWrite (buf, off + first, i - first); - first = i + 1; - if (esc == eol) - newline (); - else { - rawWrite ('&'); - rawWrite (esc); - rawWrite (';'); - } - } - if (first < len) - rawWrite (buf, off + first, len - first); - } - - - - private void newline () - throws SAXException, IOException - { - out.write (eol); - column = 0; - } - - private void doIndent () - throws SAXException, IOException - { - int space = elementNestLevel * 2; - - newline (); - column = space; - // track tabs only at line starts - while (space > 8) { - out.write ("\t"); - space -= 8; - } - while (space > 0) { - out.write (" "); - space -= 2; - } - } - - private void rawWrite (char c) - throws IOException - { - out.write (c); - column++; - } - - private void rawWrite (String s) - throws SAXException, IOException - { - if (prettyPrinting && "default".equals (space.peek ())) { - char data [] = s.toCharArray (); - rawWrite (data, 0, data.length); - } else { - out.write (s); - column += s.length (); - } - } - - // NOTE: if xhtml, the REC gives some rules about whitespace - // which we could follow ... notably, many places where conformant - // agents "must" consolidate/normalize whitespace. Line ends can - // be removed there, etc. This may not be the right place to do - // such mappings though. - - // Line buffering may help clarify algorithms and improve results. - - // It's likely xml:space needs more attention. - - private void rawWrite (char buf [], int offset, int length) - throws SAXException, IOException - { - boolean wrap; - - if (prettyPrinting && space.empty ()) - fatal ("stack discipline", null); - - wrap = prettyPrinting && "default".equals (space.peek ()); - if (!wrap) { - out.write (buf, offset, length); - column += length; - return; - } - - // we're pretty printing and want to fill lines out only - // to the desired line length. - while (length > 0) { - int target = lineLength - column; - boolean wrote = false; - - // Do we even have a problem? - if (target > length || noWrap) { - out.write (buf, offset, length); - column += length; - return; - } - - // break the line at a space character, trying to fill - // as much of the line as possible. - char c; - - for (int i = target - 1; i >= 0; i--) { - if ((c = buf [offset + i]) == ' ' || c == '\t') { - i++; - out.write (buf, offset, i); - doIndent (); - offset += i; - length -= i; - wrote = true; - break; - } - } - if (wrote) - continue; - - // no space character permitting break before target - // line length is filled. So, take the next one. - if (target < 0) - target = 0; - for (int i = target; i < length; i++) - if ((c = buf [offset + i]) == ' ' || c == '\t') { - i++; - out.write (buf, offset, i); - doIndent (); - offset += i; - length -= i; - wrote = true; - break; - } - if (wrote) - continue; - - // no such luck. - out.write (buf, offset, length); - column += length; - break; - } - } -} diff --git a/libjava/gnu/xml/xpath/AndExpr.java b/libjava/gnu/xml/xpath/AndExpr.java deleted file mode 100644 index 680e84792fb..00000000000 --- a/libjava/gnu/xml/xpath/AndExpr.java +++ /dev/null @@ -1,81 +0,0 @@ -/* AndExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Logical and. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class AndExpr - extends Expr -{ - - final Expr lhs; - final Expr rhs; - - public AndExpr(Expr lhs, Expr rhs) - { - this.lhs = lhs; - this.rhs = rhs; - } - - public Object evaluate(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - if (!_boolean(context, left)) - { - return Boolean.FALSE; - } - Object right = rhs.evaluate(context, pos, len); - return _boolean(context, right) ? Boolean.TRUE : Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new AndExpr(lhs.clone(context), rhs.clone(context)); - } - - public String toString() - { - return lhs + " and " + rhs; - } - -} diff --git a/libjava/gnu/xml/xpath/ArithmeticExpr.java b/libjava/gnu/xml/xpath/ArithmeticExpr.java deleted file mode 100644 index f972d7d4afd..00000000000 --- a/libjava/gnu/xml/xpath/ArithmeticExpr.java +++ /dev/null @@ -1,148 +0,0 @@ -/* ArithmeticExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Binary arithmetic expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ArithmeticExpr - extends Expr -{ - - static final int ADD = 0; - static final int SUBTRACT = 1; - static final int MULTIPLY = 2; - static final int DIVIDE = 3; - static final int MODULO = 4; - - final Expr lhs; - final Expr rhs; - final int op; - - ArithmeticExpr(Expr lhs, Expr rhs, int op) - { - this.lhs = lhs; - this.rhs = rhs; - switch (op) - { - case ADD: - case SUBTRACT: - case MULTIPLY: - case DIVIDE: - case MODULO: - this.op = op; - break; - default: - throw new IllegalArgumentException(); - } - } - - public Object evaluate(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - Object right = rhs.evaluate(context, pos, len); - - double ln = _number(context, left); - double rn = _number(context, right); - switch (op) - { - case ADD: - return new Double(ln + rn); - case SUBTRACT: - return new Double(ln - rn); - case MULTIPLY: - return new Double(ln * rn); - case DIVIDE: - if (rn == 0.0d || rn == -0.0d) - { - return new Double(ln < 0.0d ? - Double.NEGATIVE_INFINITY : - Double.POSITIVE_INFINITY); - } - return new Double(ln / rn); - case MODULO: - if (rn == 0.0d || rn == -0.0d) - { - return new Double(ln < 0.0d ? - Double.NEGATIVE_INFINITY : - Double.POSITIVE_INFINITY); - } - return new Double(ln % rn); - default: - throw new IllegalStateException(); - } - } - - public Expr clone(Object context) - { - return new ArithmeticExpr(lhs.clone(context), rhs.clone(context), op); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - buf.append(lhs); - buf.append(' '); - switch (op) - { - case ADD: - buf.append('+'); - break; - case SUBTRACT: - buf.append('-'); - break; - case MULTIPLY: - buf.append('*'); - break; - case DIVIDE: - buf.append("div"); - break; - case MODULO: - buf.append("mod"); - break; - } - buf.append(' '); - buf.append(rhs); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/BooleanFunction.java b/libjava/gnu/xml/xpath/BooleanFunction.java deleted file mode 100644 index 018348ff2e7..00000000000 --- a/libjava/gnu/xml/xpath/BooleanFunction.java +++ /dev/null @@ -1,89 +0,0 @@ -/* BooleanFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>boolean</code> function converts its argument to a boolean as - * follows: - * <ul> - * <li>a number is true if and only if it is neither positive or negative - * zero nor NaN</li> - * <li>a node-set is true if and only if it is non-empty</li> - * <li>a string is true if and only if its length is non-zero</li> - * <li>an object of a type other than the four basic types is converted to a - * boolean in a way that is dependent on that type</li> - * </ul> - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class BooleanFunction - extends Expr -{ - - final Expr arg; - - BooleanFunction(List args) - { - this((Expr) args.get(0)); - } - - BooleanFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - return _boolean(context, val) ? Boolean.TRUE : Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new BooleanFunction(arg.clone(context)); - } - - public String toString() - { - return "boolean(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/CeilingFunction.java b/libjava/gnu/xml/xpath/CeilingFunction.java deleted file mode 100644 index 50dc45d550f..00000000000 --- a/libjava/gnu/xml/xpath/CeilingFunction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* CeilingFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>ceiling</code> function returns the smallest (closest to - * negative infinity) number that is not less than the argument and that - * is an integer. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CeilingFunction - extends Expr -{ - - final Expr arg; - - CeilingFunction(List args) - { - this((Expr) args.get(0)); - } - - CeilingFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - double n = _number(context, val); - return new Double(Math.ceil(n)); - } - - public Expr clone(Object context) - { - return new CeilingFunction(arg.clone(context)); - } - - public String toString() - { - return "ceiling(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/ConcatFunction.java b/libjava/gnu/xml/xpath/ConcatFunction.java deleted file mode 100644 index 60802081d92..00000000000 --- a/libjava/gnu/xml/xpath/ConcatFunction.java +++ /dev/null @@ -1,100 +0,0 @@ -/* ConcatFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>concat</code> function returns the concatenation of its arguments. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ConcatFunction - extends Expr -{ - - final List args; - - ConcatFunction(List args) - { - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - StringBuffer buf = new StringBuffer(); - for (Iterator i = args.iterator(); i.hasNext(); ) - { - Expr arg = (Expr) i.next(); - Object val = arg.evaluate(context, pos, len); - buf.append(_string(context, val)); - } - return buf.toString(); - } - - public Expr clone(Object context) - { - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - return new ConcatFunction(args2); - } - - public String toString() - { - StringBuffer buf = new StringBuffer("concat("); - int len = args.size(); - for (int i = 0; i < len; i++) - { - if (i > 0) - { - buf.append(','); - } - buf.append(args.get(i)); - } - buf.append(')'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/Constant.java b/libjava/gnu/xml/xpath/Constant.java deleted file mode 100644 index ca7c1d674b0..00000000000 --- a/libjava/gnu/xml/xpath/Constant.java +++ /dev/null @@ -1,92 +0,0 @@ -/* Constant.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Constant value (string literal or number). - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class Constant - extends Expr -{ - - final Object value; - - public Constant(Object value) - { - this.value = value; - } - - public Object evaluate(Node context, int pos, int len) - { - return value; - } - - public Expr clone(Object context) - { - return new Constant(value); - } - - public String toString() - { - String ret = value.toString(); - if (value instanceof String) - { - if (ret.indexOf('\'') == -1) - { - return '\'' + ret + '\''; - } - else - { - return '"' + ret + '"'; - } - } - if (value instanceof Double) - { - if (ret.endsWith(".0")) - { - ret = ret.substring(0, ret.length() - 2); - } - } - return ret; - } - -} diff --git a/libjava/gnu/xml/xpath/ContainsFunction.java b/libjava/gnu/xml/xpath/ContainsFunction.java deleted file mode 100644 index 3910d15ef26..00000000000 --- a/libjava/gnu/xml/xpath/ContainsFunction.java +++ /dev/null @@ -1,86 +0,0 @@ -/* ContainsFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>contains</code> function returns true if the first argument - * string contains the second argument string, and otherwise returns false. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ContainsFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - - ContainsFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1)); - } - - ContainsFunction(Expr arg1, Expr arg2) - { - this.arg1 = arg1; - this.arg2 = arg2; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - String s1 = _string(context, val1); - String s2 = _string(context, val2); - return (s1.indexOf(s2) != -1) ? Boolean.TRUE : Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new ContainsFunction(arg1.clone(context), arg2.clone(context)); - } - - public String toString() - { - return "contains(" + arg1 + "," + arg2 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/CountFunction.java b/libjava/gnu/xml/xpath/CountFunction.java deleted file mode 100644 index 4164f69f321..00000000000 --- a/libjava/gnu/xml/xpath/CountFunction.java +++ /dev/null @@ -1,82 +0,0 @@ -/* CountFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>count</code> function returns the number of nodes in the - * argument node-set. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class CountFunction - extends Expr -{ - - final Expr arg; - - CountFunction(List args) - { - this((Expr) args.get(0)); - } - - CountFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - return new Double((double) ((Collection) val).size()); - } - - public Expr clone(Object context) - { - return new CountFunction(arg.clone(context)); - } - - public String toString() - { - return "count(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/DocumentOrderComparator.java b/libjava/gnu/xml/xpath/DocumentOrderComparator.java deleted file mode 100644 index c7d7de9f7c7..00000000000 --- a/libjava/gnu/xml/xpath/DocumentOrderComparator.java +++ /dev/null @@ -1,63 +0,0 @@ -/* DocumentOrderComparator.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Comparator; -import org.w3c.dom.Node; - -/** - * Sorts nodes into document order. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class DocumentOrderComparator - implements Comparator -{ - - public int compare(Object o1, Object o2) - { - if (o1 instanceof Node && o2 instanceof Node) - { - Node n1 = (Node)o1; - Node n2 = (Node)o2; - return (int) n1.compareDocumentPosition(n2); - } - return 0; - } - -} diff --git a/libjava/gnu/xml/xpath/EqualityExpr.java b/libjava/gnu/xml/xpath/EqualityExpr.java deleted file mode 100644 index d4a2f6890f0..00000000000 --- a/libjava/gnu/xml/xpath/EqualityExpr.java +++ /dev/null @@ -1,258 +0,0 @@ -/* EqualityExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.Iterator; -import org.w3c.dom.Node; - -/** - * Boolean equality expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class EqualityExpr - extends Expr -{ - - final Expr lhs; - final Expr rhs; - final boolean invert; - - EqualityExpr(Expr lhs, Expr rhs, boolean invert) - { - this.lhs = lhs; - this.rhs = rhs; - this.invert = invert; - } - - public Object evaluate(Node context, int pos, int len) - { - boolean val = evaluateImpl(context, pos, len); - if (invert) - { - return val ? Boolean.FALSE : Boolean.TRUE; - } - else - { - return val ? Boolean.TRUE : Boolean.FALSE; - } - } - - private boolean evaluateImpl(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - Object right = rhs.evaluate(context, pos, len); - - /* - * If both objects to be compared are node-sets, then the comparison - * will be true if and only if there is a node in the first node-set and - * a node in the second node-set such that the result of performing the - * comparison on the string-values of the two nodes is true. - */ - boolean flns = left instanceof Collection; - boolean frns = right instanceof Collection; - if (flns && frns) - { - Collection lns = (Collection) left; - Collection rns = (Collection) right; - boolean all = true; - for (Iterator i = lns.iterator(); i.hasNext(); ) - { - Node ltest = (Node) i.next(); - for (Iterator j = rns.iterator(); j.hasNext(); ) - { - Node rtest = (Node) j.next(); - if (ltest == rtest || ltest.equals(rtest)) - { - // much shorter - if (!invert) - { - return true; - } - } - else if (stringValue(ltest).equals(stringValue(rtest))) - { - if (!invert) - { - return true; - } - } - else - { - all = false; - } - } - } - return false; - } - /* - * If one object to be compared is a node-set and the other is a number, - * then the comparison will be true if and only if there is a node in - * the node-set such that the result of performing the comparison on the - * number to be compared and on the result of converting the - * string-value of that node to a number using the number function is - * true. - */ - boolean fln = left instanceof Double; - boolean frn = right instanceof Double; - if ((flns && frn) || (frns && fln)) - { - Collection ns = flns ? (Collection) left : (Collection) right; - double n = fln ? ((Double) left).doubleValue() : - ((Double) right).doubleValue(); - boolean all = true; - for (Iterator i = ns.iterator(); i.hasNext(); ) - { - Node test = (Node) i.next(); - double nn = _number(context, stringValue(test)); - if (nn == n) - { - if (!invert) - { - return true; - } - } - else - { - all = false; - } - } - return invert ? all : false; - } - /* - * If one object to be compared is a node-set and the other is a - * string, then the comparison will be true if and only if there is a - * node in the node-set such that the result of performing the - * comparison on the string-value of the node and the other string is - * true. - */ - boolean fls = left instanceof String; - boolean frs = right instanceof String; - if ((flns && frs) || (frns && fls)) - { - Collection ns = flns ? (Collection) left : (Collection) right; - String s = fls ? (String) left : (String) right; - boolean all = true; - for (Iterator i = ns.iterator(); i.hasNext(); ) - { - Node test = (Node) i.next(); - if (stringValue(test).equals(s)) - { - if (!invert) - { - return true; - } - } - else - { - all = false; - } - } - return invert ? all : false; - } - /* - * If one object to be compared is a node-set and the other is a - * boolean, then the comparison will be true if and only if the result - * of performing the comparison on the boolean and on the result of - * converting the node-set to a boolean using the boolean function is - * true. - */ - boolean flb = left instanceof Boolean; - boolean frb = right instanceof Boolean; - if ((flns && frb) || (frns && flb)) - { - Collection ns = flns ? (Collection) left : (Collection) right; - boolean b = flb ? ((Boolean) left).booleanValue() : - ((Boolean) right).booleanValue(); - return _boolean(context, ns) == b; - } - /* - * If at least one object to be compared is a boolean, then each object - * to be compared is converted to a boolean as if by applying the - * boolean function. - */ - if (flb || frb) - { - boolean lb = flb ? ((Boolean) left).booleanValue() : - _boolean(context, left); - boolean rb = frb ? ((Boolean) right).booleanValue() : - _boolean(context, right); - return lb == rb; - } - /* - * Otherwise, if at least one object to be compared is - * a number, then each object to be compared is converted to a number as - * if by applying the number function. - */ - if (fln || frn) - { - double ln = fln ? ((Double) left).doubleValue() : - _number(context, left); - double rn = frn ? ((Double) right).doubleValue() : - _number(context, right); - return ln == rn; - } - /* - * Otherwise, both objects to be - * compared are converted to strings as if by applying the string - * function. - */ - String ls = fls ? (String) left : _string(context, left); - String rs = frs ? (String) right : _string(context, right); - return ls.equals(rs); - } - - public Expr clone(Object context) - { - return new EqualityExpr(lhs.clone(context), rhs.clone(context), invert); - } - - public String toString() - { - if (invert) - { - return lhs + " != " + rhs; - } - else - { - return lhs + " = " + rhs; - } - } - -} diff --git a/libjava/gnu/xml/xpath/Expr.java b/libjava/gnu/xml/xpath/Expr.java deleted file mode 100644 index 5957828522e..00000000000 --- a/libjava/gnu/xml/xpath/Expr.java +++ /dev/null @@ -1,474 +0,0 @@ -/* Expr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.io.IOException; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.StringTokenizer; -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * An XPath expression. - * This can be evaluated in the context of a node to produce a result. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class Expr - implements XPathExpression -{ - - protected static final Comparator documentOrderComparator = - new DocumentOrderComparator(); - - protected static final DecimalFormat decimalFormat = - new DecimalFormat("####################################################" + - ".####################################################", - new DecimalFormatSymbols(Locale.US)); - - public Object evaluate(Object item, QName returnType) - throws XPathExpressionException - { - Object ret = null; - Node context = null; - if (item instanceof Node) - { - context = (Node) item; - ret = evaluate(context, 1, 1); - if (XPathConstants.STRING == returnType && - !(ret instanceof String)) - { - ret = _string(context, ret); - } - else if (XPathConstants.NUMBER == returnType && - !(ret instanceof Double)) - { - ret = new Double(_number(context, ret)); - } - else if (XPathConstants.BOOLEAN == returnType && - !(ret instanceof Boolean)) - { - ret = _boolean(context, ret) ? Boolean.TRUE : Boolean.FALSE; - } - else if (XPathConstants.NODE == returnType) - { - if (ret instanceof Collection) - { - Collection ns = (Collection) ret; - switch (ns.size()) - { - case 0: - ret = null; - break; - case 1: - ret = (Node) ns.iterator().next(); - break; - default: - throw new XPathExpressionException("multiple nodes in node-set"); - } - } - else if (ret != null) - { - throw new XPathExpressionException("return value is not a node-set"); - } - } - else if (XPathConstants.NODESET == returnType) - { - if (ret != null && !(ret instanceof Collection)) - { - throw new XPathExpressionException("return value is not a node-set"); - } - } - } - return ret; - } - - public String evaluate(Object item) - throws XPathExpressionException - { - return (String) evaluate(item, XPathConstants.STRING); - } - - public Object evaluate(InputSource source, QName returnType) - throws XPathExpressionException - { - try - { - DocumentBuilderFactory factory = - new gnu.xml.dom.JAXPFactory(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.parse(source); - return evaluate(doc, returnType); - } - catch (ParserConfigurationException e) - { - throw new XPathExpressionException(e); - } - catch (SAXException e) - { - throw new XPathExpressionException(e); - } - catch (IOException e) - { - throw new XPathExpressionException(e); - } - } - - public String evaluate(InputSource source) - throws XPathExpressionException - { - return (String) evaluate(source, XPathConstants.STRING); - } - - public abstract Object evaluate(Node context, int pos, int len); - - public abstract Expr clone(Object context); - - /* -- 4.1 Node Set Functions -- */ - - /** - * The id function selects elements by their unique ID. - * When the argument to id is of type node-set, then the result is - * the union of the result of applying id to the string-value of each of - * the nodes in the argument node-set. When the argument to id is of any - * other type, the argument is converted to a string as if by a call to - * the string function; the string is split into a whitespace-separated - * list of tokens (whitespace is any sequence of characters matching the - * production S); the result is a node-set containing the elements in the - * same document as the context node that have a unique ID equal to any of - * the tokens in the list. - */ - public static Collection _id(Node context, Object object) - { - Set ret = new HashSet(); - if (object instanceof Collection) - { - Collection nodeSet = (Collection) object; - for (Iterator i = nodeSet.iterator(); i.hasNext(); ) - { - String string = stringValue((Node) i.next()); - ret.addAll(_id (context, string)); - } - } - else - { - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - String string = _string(context, object); - StringTokenizer st = new StringTokenizer(string, " \t\r\n"); - while (st.hasMoreTokens()) - { - Node element = doc.getElementById(st.nextToken()); - if (element != null) - { - ret.add(element); - } - } - } - return ret; - } - - /** - * The local-name function returns the local part of the expanded-name of - * the node in the argument node-set that is first in document order. If - * the argument node-set is empty or the first node has no expanded-name, - * an empty string is returned. If the argument is omitted, it defaults to - * a node-set with the context node as its only member. - */ - public static String _local_name(Node context, Collection nodeSet) - { - Node node = (nodeSet == null || nodeSet.size() == 0) ? context : - firstNode(nodeSet); - return node.getLocalName(); - } - - /** - * The namespace-uri function returns the namespace URI of the - * expanded-name of the node in the argument node-set that is first in - * document order. If the argument node-set is empty, the first node has - * no expanded-name, or the namespace URI of the expanded-name is null, an - * empty string is returned. If the argument is omitted, it defaults to a - * node-set with the context node as its only member. - */ - public static String _namespace_uri(Node context, Collection nodeSet) - { - Node node = (nodeSet == null || nodeSet.size() == 0) ? context : - firstNode(nodeSet); - return node.getNamespaceURI(); - } - - /** - * The name function returns a string containing a QName representing the - * expanded-name of the node in the argument node-set that is first in - * document order. The QName must represent the expanded-name with respect - * to the namespace declarations in effect on the node whose expanded-name - * is being represented. Typically, this will be the QName that occurred - * in the XML source. This need not be the case if there are namespace - * declarations in effect on the node that associate multiple prefixes - * with the same namespace. However, an implementation may include - * information about the original prefix in its representation of nodes; - * in this case, an implementation can ensure that the returned string is - * always the same as the QName used in the XML source. If the argument - * node-set is empty or the first node has no expanded-name, an empty - * string is returned. If the argument it omitted, it defaults to a - * node-set with the context node as its only member. - */ - public static String _name(Node context, Collection nodeSet) - { - Node node = (nodeSet == null || nodeSet.size() == 0) ? context : - firstNode(nodeSet); - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - case Node.ELEMENT_NODE: - case Node.PROCESSING_INSTRUCTION_NODE: - return node.getNodeName(); - default: - return ""; - } - } - - /** - * Returns the first node in the set in document order. - */ - static Node firstNode(Collection nodeSet) - { - List list = new ArrayList(nodeSet); - Collections.sort(list, documentOrderComparator); - return (Node) list.get(0); - } - - /* -- 4.2 String Functions -- */ - - /** - * Implementation of the XPath <code>string</code> function. - */ - public static String _string(Node context, Object object) - { - if (object == null) - { - return stringValue(context); - } - if (object instanceof String) - { - return (String) object; - } - if (object instanceof Boolean) - { - return object.toString(); - } - if (object instanceof Double) - { - double d = ((Double) object).doubleValue(); - if (Double.isNaN(d)) - { - return "NaN"; - } - else if (d == 0.0d) - { - return "0"; - } - else if (Double.isInfinite(d)) - { - if (d < 0) - { - return "-Infinity"; - } - else - { - return "Infinity"; - } - } - else - { - String ret = decimalFormat.format(d); - if (ret.endsWith (".0")) - { - ret = ret.substring(0, ret.length() - 2); - } - return ret; - } - } - if (object instanceof Collection) - { - Collection nodeSet = (Collection) object; - if (nodeSet.isEmpty()) - { - return ""; - } - Node node = firstNode(nodeSet); - return stringValue(node); - } - throw new IllegalArgumentException(object.toString()); - } - - /* -- 4.3 Boolean Functions -- */ - - /** - * Implementation of the XPath <code>boolean</code> function. - */ - public static boolean _boolean(Node context, Object object) - { - if (object instanceof Boolean) - { - return ((Boolean) object).booleanValue(); - } - if (object instanceof Double) - { - return ((Double) object).doubleValue() != 0.0; - } - if (object instanceof String) - { - return ((String) object).length() != 0; - } - if (object instanceof Collection) - { - return ((Collection) object).size() != 0; - } - return false; // TODO user defined types - } - - /* -- 4.4 Number Functions -- */ - - /** - * Implementation of the XPath <code>number</code> function. - */ - public static double _number(Node context, Object object) - { - if (object == null) - { - object = Collections.singleton(context); - } - if (object instanceof Double) - { - return ((Double) object).doubleValue(); - } - if (object instanceof Boolean) - { - return ((Boolean) object).booleanValue() ? 1.0 : 0.0; - } - if (object instanceof Collection) - { - // Convert node-set to string - object = stringValue((Collection) object); - } - if (object instanceof String) - { - String string = ((String) object).trim(); - try - { - return Double.parseDouble(string); - } - catch (NumberFormatException e) - { - return Double.NaN; - } - } - return Double.NaN; // TODO user-defined types - } - - /** - * Computes the XPath string-value of the specified node-set. - */ - public static String stringValue(Collection nodeSet) - { - StringBuffer buf = new StringBuffer(); - for (Iterator i = nodeSet.iterator(); i.hasNext(); ) - { - buf.append(stringValue((Node) i.next())); - } - return buf.toString(); - } - - /** - * Computes the XPath string-value of the specified node. - */ - public static String stringValue(Node node) - { - return stringValue(node, false); - } - - static String stringValue(Node node, boolean elementMode) - { - switch (node.getNodeType()) - { - case Node.DOCUMENT_NODE: // 5.1 Root Node - case Node.DOCUMENT_FRAGMENT_NODE: - case Node.ELEMENT_NODE: // 5.2 Element Nodes - StringBuffer buf = new StringBuffer(); - for (Node ctx = node.getFirstChild(); ctx != null; - ctx = ctx.getNextSibling()) - { - buf.append(stringValue(ctx, true)); - } - return buf.toString(); - case Node.TEXT_NODE: // 5.7 Text Nodes - case Node.CDATA_SECTION_NODE: - return node.getNodeValue(); - case Node.ATTRIBUTE_NODE: // 5.3 Attribute Nodes - case Node.PROCESSING_INSTRUCTION_NODE: // 5.5 Processing Instruction - case Node.COMMENT_NODE: // 5.6 Comment Nodes - if (!elementMode) - { - return node.getNodeValue(); - } - default: - return ""; - } - } - -} diff --git a/libjava/gnu/xml/xpath/FalseFunction.java b/libjava/gnu/xml/xpath/FalseFunction.java deleted file mode 100644 index ca07b7870e8..00000000000 --- a/libjava/gnu/xml/xpath/FalseFunction.java +++ /dev/null @@ -1,66 +0,0 @@ -/* FalseFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * The <code>false</code> function returns false. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class FalseFunction - extends Expr -{ - - public Object evaluate(Node context, int pos, int len) - { - return Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new FalseFunction(); - } - - public String toString() - { - return "false()"; - } - -} diff --git a/libjava/gnu/xml/xpath/FloorFunction.java b/libjava/gnu/xml/xpath/FloorFunction.java deleted file mode 100644 index c8608cdc1f5..00000000000 --- a/libjava/gnu/xml/xpath/FloorFunction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* FloorFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>floor</code> function returns the largest (closest to positive - * infinity) number that is not greater than the argument and that is an - * integer. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class FloorFunction - extends Expr -{ - - final Expr arg; - - FloorFunction(List args) - { - this((Expr) args.get(0)); - } - - FloorFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - double n = _number(context, val); - return new Double(Math.floor(n)); - } - - public Expr clone(Object context) - { - return new FloorFunction(arg.clone(context)); - } - - public String toString() - { - return "floor(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/Function.java b/libjava/gnu/xml/xpath/Function.java deleted file mode 100644 index aecd49d9c73..00000000000 --- a/libjava/gnu/xml/xpath/Function.java +++ /dev/null @@ -1,57 +0,0 @@ -/* Function.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; - -/** - * Interface to be implemented by external functions that need to receive - * parameter values. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public interface Function -{ - - /** - * Sets the list of expressions to evaluate as parameter values. - */ - void setArguments(List args); - -} - diff --git a/libjava/gnu/xml/xpath/FunctionCall.java b/libjava/gnu/xml/xpath/FunctionCall.java deleted file mode 100644 index 97763e09764..00000000000 --- a/libjava/gnu/xml/xpath/FunctionCall.java +++ /dev/null @@ -1,150 +0,0 @@ -/* FunctionCall.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; -import javax.xml.xpath.XPathFunctionResolver; -import org.w3c.dom.Node; - -/** - * Executes an XPath core or extension function. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class FunctionCall - extends Expr -{ - - final XPathFunctionResolver resolver; - final String name; - final List args; - - public FunctionCall(XPathFunctionResolver resolver, String name) - { - this(resolver, name, Collections.EMPTY_LIST); - } - - public FunctionCall(XPathFunctionResolver resolver, String name, List args) - { - this.resolver = resolver; - this.name = name; - this.args = args; - } - - public Object evaluate(Node context, int pos, int len) - { - if (resolver != null) - { - QName qname = QName.valueOf(name); - int arity = args.size(); - XPathFunction function = resolver.resolveFunction(qname, arity); - if (function != null) - { - //System.err.println("Calling "+toString()+" with "+values); - if (function instanceof Expr) - { - if (function instanceof Function) - { - ((Function) function).setArguments(args); - } - return ((Expr) function).evaluate(context, pos, len); - } - else - { - List values = new ArrayList(arity); - for (int i = 0; i < arity; i++) - { - Expr arg = (Expr) args.get(i); - values.add(arg.evaluate(context, pos, len)); - } - try - { - return function.evaluate(values); - } - catch (XPathFunctionException e) - { - e.printStackTrace(System.err); // FIXME - throw new RuntimeException(e.getMessage(), e); - } - } - } - } - throw new IllegalArgumentException("Invalid function call: " + - toString()); - } - - public Expr clone(Object context) - { - int len = args.size(); - List args2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - args2.add(((Expr) args.get(i)).clone(context)); - } - XPathFunctionResolver r = resolver; - if (context instanceof XPathFunctionResolver) - { - r = (XPathFunctionResolver) context; - } - return new FunctionCall(r, name, args2); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - buf.append(name); - buf.append('('); - int len = args.size(); - for (int i = 0; i < len; i++) - { - if (i > 0) - { - buf.append(','); - } - buf.append(args.get(i)); - } - buf.append(')'); - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/IdFunction.java b/libjava/gnu/xml/xpath/IdFunction.java deleted file mode 100644 index 164e141a7c4..00000000000 --- a/libjava/gnu/xml/xpath/IdFunction.java +++ /dev/null @@ -1,96 +0,0 @@ -/* IdFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>id</code> function selects elements by their unique ID. - * When the argument to id is of type node-set, then the result is - * the union of the result of applying id to the string-value of each of the - * nodes in the argument node-set. When the argument to id is of any other - * type, the argument is converted to a string as if by a call to the string - * function; the string is split into a whitespace-separated list of tokens - * (whitespace is any sequence of characters matching the production S); the - * result is a node-set containing the elements in the same document as the - * context node that have a unique ID equal to any of the tokens in the - * list. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class IdFunction - extends Pattern -{ - - final Expr arg; - - IdFunction(List args) - { - this((Expr) args.get(0)); - } - - public IdFunction(Expr arg) - { - this.arg = arg; - } - - public boolean matches(Node context) - { - Object ret = evaluate(context, 1, 1); - return !((Collection) ret).isEmpty(); - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - return _id(context, val); - } - - public Expr clone(Object context) - { - return new IdFunction(arg.clone(context)); - } - - public String toString() - { - return "id(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/LangFunction.java b/libjava/gnu/xml/xpath/LangFunction.java deleted file mode 100644 index fbf3af1f95c..00000000000 --- a/libjava/gnu/xml/xpath/LangFunction.java +++ /dev/null @@ -1,110 +0,0 @@ -/* LangFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * The <code>lang</code> function returns true or false depending on whether - * the language of the context node as specified by xml:lang attributes is - * the same as or is a sublanguage of the language specified by the argument - * string. The language of the context node is determined by the value of - * the xml:lang attribute on the context node, or, if the context node has - * no xml:lang attribute, by the value of the xml:lang attribute on the - * nearest ancestor of the context node that has an xml:lang attribute. If - * there is no such attribute, then lang returns false. If there is such an - * attribute, then lang returns true if the attribute value is equal to the - * argument ignoring case, or if there is some suffix starting with - such - * that the attribute value is equal to the argument ignoring that suffix of - * the attribute value and ignoring case. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class LangFunction - extends Expr -{ - - final Expr arg; - - LangFunction(List args) - { - this((Expr) args.get(0)); - } - - LangFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - String lang = _string(context, val); - String clang = getLang(context); - while (clang == null && context != null) - { - context = context.getParentNode(); - clang = getLang(context); - } - boolean ret = (clang == null) ? false : - clang.toLowerCase().startsWith(lang.toLowerCase()); - return ret ? Boolean.TRUE : Boolean.FALSE; - } - - String getLang(Node node) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - return ((Element) node).getAttribute("xml:lang"); - } - return null; - } - - public Expr clone(Object context) - { - return new IdFunction(arg.clone(context)); - } - - public String toString() - { - return "lang(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/LastFunction.java b/libjava/gnu/xml/xpath/LastFunction.java deleted file mode 100644 index b24e0482d90..00000000000 --- a/libjava/gnu/xml/xpath/LastFunction.java +++ /dev/null @@ -1,67 +0,0 @@ -/* LastFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * The <code>last</code> function returns a number equal to the context - * size from the expression evaluation context. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class LastFunction - extends Expr -{ - - public Object evaluate(Node context, int pos, int len) - { - return new Double((double) len); - } - - public Expr clone(Object context) - { - return new LastFunction(); - } - - public String toString() - { - return "last()"; - } - -} diff --git a/libjava/gnu/xml/xpath/LocalNameFunction.java b/libjava/gnu/xml/xpath/LocalNameFunction.java deleted file mode 100644 index 342d9331a74..00000000000 --- a/libjava/gnu/xml/xpath/LocalNameFunction.java +++ /dev/null @@ -1,87 +0,0 @@ -/* LocalNameFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>local-name</code> function returns the local part of the - * expanded-name of the node in the argument node-set that is first in - * document order. - * If the argument node-set is empty or the first node has no expanded-name, - * an empty string is returned. If the argument is omitted, it defaults to a - * node-set with the context node as its only member. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class LocalNameFunction - extends Expr -{ - - final Expr arg; - - LocalNameFunction(List args) - { - this(args.size() > 0 ? (Expr) args.get(0) : null); - } - - LocalNameFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - return _local_name(context, (Collection) val); - } - - public Expr clone(Object context) - { - return new LocalNameFunction((arg == null) ? null : - arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "local-name()" : "local-name(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/NameFunction.java b/libjava/gnu/xml/xpath/NameFunction.java deleted file mode 100644 index bd34325a097..00000000000 --- a/libjava/gnu/xml/xpath/NameFunction.java +++ /dev/null @@ -1,95 +0,0 @@ -/* NameFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>name</code> function returns a string containing a QName - * representing the expanded-name of the node in the argument node-set that - * is first in document order. The QName must represent the expanded-name - * with respect to the namespace declarations in effect on the node whose - * expanded-name is being represented. Typically, this will be the QName - * that occurred in the XML source. This need not be the case if there are - * namespace declarations in effect on the node that associate multiple - * prefixes with the same namespace. However, an implementation may include - * information about the original prefix in its representation of nodes; in - * this case, an implementation can ensure that the returned string is - * always the same as the QName used in the XML source. If the argument - * node-set is empty or the first node has no expanded-name, an empty string - * is returned. If the argument it omitted, it defaults to a node-set with - * the context node as its only member. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NameFunction - extends Expr -{ - - final Expr arg; - - NameFunction(List args) - { - this(args.size() > 0 ? (Expr) args.get(0) : null); - } - - NameFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - return _name(context, (Collection) val); - } - - public Expr clone(Object context) - { - return new NameFunction((arg == null) ? null : - arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "name()" : "name(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/NameTest.java b/libjava/gnu/xml/xpath/NameTest.java deleted file mode 100644 index d2e892beb2b..00000000000 --- a/libjava/gnu/xml/xpath/NameTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* NameTest.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import org.w3c.dom.Node; - -/** - * Tests whether a node has the specified name. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class NameTest - extends Test -{ - - final QName qName; - final boolean anyLocalName; - final boolean any; - - public NameTest(QName qName, boolean anyLocalName, boolean any) - { - this.anyLocalName = anyLocalName; - this.any = any; - this.qName = qName; - } - - public boolean matchesAny() - { - return any; - } - - public boolean matchesAnyLocalName() - { - return anyLocalName; - } - - public boolean matches(Node node, int pos, int len) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - // Do not match namespace attributes - String uri = node.getNamespaceURI(); - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getPrefix()) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getNodeName())) - { - return false; - } - // Fall through - case Node.ELEMENT_NODE: - break; - default: - return false; - } - if (any) - { - return true; - } - String uri = qName.getNamespaceURI(); - if (!equal(uri, node.getNamespaceURI())) - { - return false; - } - if (anyLocalName) - { - return true; - } - String localName = qName.getLocalPart(); - return (localName.equals(node.getLocalName())); - } - - final boolean equal(String s1, String s2) - { - return (((s1 == null || s1.length() == 0) && - (s2 == null || s2.length() == 0)) || - s1 != null && s1.equals(s2)); - } - - public Test clone(Object context) - { - return new NameTest(qName, anyLocalName, any); - } - - public String toString () - { - if (any) - { - return "*"; - } - return qName.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/NamespaceTest.java b/libjava/gnu/xml/xpath/NamespaceTest.java deleted file mode 100644 index 8240bf8deaf..00000000000 --- a/libjava/gnu/xml/xpath/NamespaceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* NamespaceTest.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import org.w3c.dom.Node; - -/** - * Tests whether a namespace attribute has the specified name. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class NamespaceTest - extends Test -{ - - final QName qName; - final boolean anyLocalName; - final boolean any; - - public NamespaceTest(QName qName, boolean anyLocalName, boolean any) - { - this.anyLocalName = anyLocalName; - this.any = any; - this.qName = qName; - } - - public boolean matchesAny() - { - return any; - } - - public boolean matchesAnyLocalName() - { - return anyLocalName; - } - - public boolean matches(Node node, int pos, int len) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE: - // Only match namespace attributes - String uri = node.getNamespaceURI(); - if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getPrefix()) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getNodeName())) - { - break; - } - // Fall through - default: - // Only process namespace attributes - return false; - } - if (any) - { - return true; - } - if (anyLocalName) - { - return true; - } - String localName = qName.getLocalPart(); - return (localName.equals(node.getLocalName())); - } - - public Test clone(Object context) - { - return new NamespaceTest(qName, anyLocalName, any); - } - - public String toString () - { - if (any) - { - return "*"; - } - return qName.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/NamespaceUriFunction.java b/libjava/gnu/xml/xpath/NamespaceUriFunction.java deleted file mode 100644 index 9a42e775488..00000000000 --- a/libjava/gnu/xml/xpath/NamespaceUriFunction.java +++ /dev/null @@ -1,87 +0,0 @@ -/* NamespaceUriFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>namespace-uri</code> function returns the namespace URI of the - * expanded-name of the node in the argument node-set that is first in - * document order. If the argument node-set is empty, the first node has no - * expanded-name, or the namespace URI of the expanded-name is null, an - * empty string is returned. If the argument is omitted, it defaults to a - * node-set with the context node as its only member. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NamespaceUriFunction - extends Expr -{ - - final Expr arg; - - NamespaceUriFunction(List args) - { - this(args.size() > 0 ? (Expr) args.get(0) : null); - } - - NamespaceUriFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - return _namespace_uri(context, (Collection) val); - } - - public Expr clone(Object context) - { - return new NamespaceUriFunction((arg == null) ? null : - arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "namespace-uri()" : "namespace-uri(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/NegativeExpr.java b/libjava/gnu/xml/xpath/NegativeExpr.java deleted file mode 100644 index bb84eebf05e..00000000000 --- a/libjava/gnu/xml/xpath/NegativeExpr.java +++ /dev/null @@ -1,75 +0,0 @@ -/* NegativeExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Unary negative. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NegativeExpr - extends Expr -{ - - final Expr expr; - - NegativeExpr(Expr expr) - { - this.expr = expr; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = expr.evaluate(context, pos, len); - double n = _number(context, val); - return new Double(-n); - } - - public Expr clone(Object context) - { - return new NegativeExpr(expr.clone(context)); - } - - public String toString() - { - return "-" + expr; - } - -} diff --git a/libjava/gnu/xml/xpath/NodeTypeTest.java b/libjava/gnu/xml/xpath/NodeTypeTest.java deleted file mode 100644 index 521104cdb75..00000000000 --- a/libjava/gnu/xml/xpath/NodeTypeTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* NodeTypeTest.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Tests whether a node is of a given type. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class NodeTypeTest - extends Test -{ - - final short type; - final String data; - - public NodeTypeTest(short type) - { - this(type, null); - } - - public NodeTypeTest(short type, String data) - { - this.type = type; - this.data = data; - } - - public short getNodeType() - { - return type; - } - - public String getData() - { - return data; - } - - public boolean matches(Node node, int pos, int len) - { - short nodeType = node.getNodeType(); - switch (nodeType) - { - case Node.ELEMENT_NODE: - case Node.ATTRIBUTE_NODE: - case Node.TEXT_NODE: - case Node.CDATA_SECTION_NODE: - case Node.COMMENT_NODE: - case Node.PROCESSING_INSTRUCTION_NODE: - if (type > 0) - { - if (nodeType != type) - { - return false; - } - if (data != null && !data.equals(node.getNodeValue())) - { - return false; - } - } - return true; - default: - // Not part of XPath data model - return false; - } - } - - public Test clone(Object context) - { - return new NodeTypeTest(type, data); - } - - public String toString() - { - switch (type) - { - case 0: - return "node()"; - case Node.TEXT_NODE: - return "text()"; - case Node.COMMENT_NODE: - return "comment()"; - case Node.PROCESSING_INSTRUCTION_NODE: - if (data != null) - { - return "processing-instruction('" + data + "')"; - } - return "processing-instruction()"; - default: - throw new IllegalStateException(); - } - } - -} diff --git a/libjava/gnu/xml/xpath/NormalizeSpaceFunction.java b/libjava/gnu/xml/xpath/NormalizeSpaceFunction.java deleted file mode 100644 index a61e118f2e5..00000000000 --- a/libjava/gnu/xml/xpath/NormalizeSpaceFunction.java +++ /dev/null @@ -1,99 +0,0 @@ -/* NormalizeSpaceFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import java.util.StringTokenizer; -import org.w3c.dom.Node; - -/** - * The <code>normalize-space</code> function returns the argument string - * with whitespace normalized by stripping leading and trailing whitespace - * and replacing sequences of whitespace characters by a single space. - * Whitespace characters are the same as those allowed by the S production - * in XML. If the argument is omitted, it defaults to the context node - * converted to a string, in other words the string-value of the context - * node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NormalizeSpaceFunction - extends Expr -{ - - final Expr arg; - - NormalizeSpaceFunction(List args) - { - this((Expr) args.get(0)); - } - - NormalizeSpaceFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - String s = _string(context, val); - StringTokenizer st = new StringTokenizer(s, " \t\r\n"); - StringBuffer buf = new StringBuffer(); - if (st.hasMoreTokens()) - { - buf.append(st.nextToken()); - while (st.hasMoreTokens()) - { - buf.append(' '); - buf.append(st.nextToken()); - } - } - return buf.toString(); - } - - public Expr clone(Object context) - { - return new NormalizeSpaceFunction(arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "normalize-space()" : "normalize-space(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/NotFunction.java b/libjava/gnu/xml/xpath/NotFunction.java deleted file mode 100644 index dcb7ad4fb68..00000000000 --- a/libjava/gnu/xml/xpath/NotFunction.java +++ /dev/null @@ -1,81 +0,0 @@ -/* NotFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>not</code> function returns true if its argument is false, - * and false otherwise. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NotFunction - extends Expr -{ - - final Expr arg; - - NotFunction(List args) - { - this((Expr) args.get(0)); - } - - NotFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - return _boolean(context, val) ? Boolean.FALSE : Boolean.TRUE; - } - - public Expr clone(Object context) - { - return new NotFunction(arg.clone(context)); - } - - public String toString() - { - return "not(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/NumberFunction.java b/libjava/gnu/xml/xpath/NumberFunction.java deleted file mode 100644 index a27eb7a46cf..00000000000 --- a/libjava/gnu/xml/xpath/NumberFunction.java +++ /dev/null @@ -1,96 +0,0 @@ -/* NumberFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>number</code> function converts its argument to a number as - * follows: - * <ul> - * <li>a string that consists of optional whitespace followed by an optional - * minus sign followed by a Number followed by whitespace is converted to - * the IEEE 754 number that is nearest (according to the IEEE 754 - * round-to-nearest rule) to the mathematical value represented by the - * string; any other string is converted to NaN</li> - * <li>boolean true is converted to 1; boolean false is converted to 0</li> - * <li>a node-set is first converted to a string as if by a call to the - * string function and then converted in the same way as a string - * argument</li> - * <li>an object of a type other than the four basic types is converted to a - * number in a way that is dependent on that type</li> - * </ul> - * If the argument is omitted, it defaults to a node-set with the context - * node as its only member. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class NumberFunction - extends Expr -{ - - final Expr arg; - - NumberFunction(List args) - { - this(args.size() > 0 ? (Expr) args.get(0) : null); - } - - NumberFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - return new Double(_number(context, val)); - } - - public Expr clone(Object context) - { - return new NumberFunction(arg.clone(context)); - } - - public String toString() - { - return "number(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/OrExpr.java b/libjava/gnu/xml/xpath/OrExpr.java deleted file mode 100644 index ca3fd227718..00000000000 --- a/libjava/gnu/xml/xpath/OrExpr.java +++ /dev/null @@ -1,81 +0,0 @@ -/* OrExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Logical or. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class OrExpr - extends Expr -{ - - final Expr lhs; - final Expr rhs; - - public OrExpr(Expr lhs, Expr rhs) - { - this.lhs = lhs; - this.rhs = rhs; - } - - public Object evaluate(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - if (_boolean(context, left)) - { - return Boolean.TRUE; - } - Object right = rhs.evaluate(context, pos, len); - return _boolean(context, right) ? Boolean.TRUE : Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new OrExpr(lhs.clone(context), rhs.clone(context)); - } - - public String toString() - { - return lhs + " or " + rhs; - } - -} diff --git a/libjava/gnu/xml/xpath/ParenthesizedExpr.java b/libjava/gnu/xml/xpath/ParenthesizedExpr.java deleted file mode 100644 index 6a8bb12fa32..00000000000 --- a/libjava/gnu/xml/xpath/ParenthesizedExpr.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ParenthesizedExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import org.w3c.dom.Node; - -/** - * Simple subexpression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class ParenthesizedExpr - extends Expr -{ - - final Expr expr; - - ParenthesizedExpr(Expr expr) - { - this.expr = expr; - } - - public Object evaluate(Node context, int pos, int len) - { - Object ret = expr.evaluate(context, pos, len); - if (ret instanceof Collection) - { - List list = new ArrayList((Collection) ret); - Collections.sort(list, documentOrderComparator); - ret = list; - } - return ret; - } - - public Expr clone(Object context) - { - return new ParenthesizedExpr(expr.clone(context)); - } - - public String toString() - { - return "(" + expr + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/Path.java b/libjava/gnu/xml/xpath/Path.java deleted file mode 100644 index 4b01f0918ab..00000000000 --- a/libjava/gnu/xml/xpath/Path.java +++ /dev/null @@ -1,54 +0,0 @@ -/* Path.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import org.w3c.dom.Node; - -/** - * An XPath path component expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -abstract class Path - extends Pattern -{ - - abstract Collection evaluate(Node context, Collection nodeSet); - -} diff --git a/libjava/gnu/xml/xpath/Pattern.java b/libjava/gnu/xml/xpath/Pattern.java deleted file mode 100644 index d992c6d4e63..00000000000 --- a/libjava/gnu/xml/xpath/Pattern.java +++ /dev/null @@ -1,54 +0,0 @@ -/* Pattern.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Interface implemented by expressions that can for part of XSL patterns. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class Pattern - extends Expr -{ - - public abstract boolean matches(Node context); - -} - diff --git a/libjava/gnu/xml/xpath/PositionFunction.java b/libjava/gnu/xml/xpath/PositionFunction.java deleted file mode 100644 index 790b0e005cf..00000000000 --- a/libjava/gnu/xml/xpath/PositionFunction.java +++ /dev/null @@ -1,67 +0,0 @@ -/* PositionFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * The <code>position</code> function returns a number equal to the context - * position from the expression evaluation context. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class PositionFunction - extends Expr -{ - - public Object evaluate(Node context, int pos, int len) - { - return new Double((double) pos); - } - - public Expr clone(Object context) - { - return new PositionFunction(); - } - - public String toString() - { - return "position()"; - } - -} diff --git a/libjava/gnu/xml/xpath/Predicate.java b/libjava/gnu/xml/xpath/Predicate.java deleted file mode 100644 index d495440fdbb..00000000000 --- a/libjava/gnu/xml/xpath/Predicate.java +++ /dev/null @@ -1,79 +0,0 @@ -/* Predicate.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Tests whether an expression matches against a given context node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -class Predicate - extends Test -{ - - final Expr expr; - - Predicate(Expr expr) - { - this.expr = expr; - } - - public boolean matches(Node node, int pos, int len) - { - Object ret = expr.evaluate(node, pos, len); - if (ret instanceof Double) - { - // Same as [position() = x] - return ((Double) ret).intValue() == pos; - } - return Expr._boolean(node, expr.evaluate(node, pos, len)); - } - - public Test clone(Object context) - { - return new Predicate(expr.clone(context)); - } - - public String toString() - { - return "[" + expr + "]"; - } - -} diff --git a/libjava/gnu/xml/xpath/RelationalExpr.java b/libjava/gnu/xml/xpath/RelationalExpr.java deleted file mode 100644 index 622d2290106..00000000000 --- a/libjava/gnu/xml/xpath/RelationalExpr.java +++ /dev/null @@ -1,101 +0,0 @@ -/* RelationalExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * Numerical comparison expression. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class RelationalExpr - extends Expr -{ - - final Expr lhs; - final Expr rhs; - final boolean lt; - final boolean eq; - - RelationalExpr(Expr lhs, Expr rhs, boolean lt, boolean eq) - { - this.lhs = lhs; - this.rhs = rhs; - this.lt = lt; - this.eq = eq; - } - - public Object evaluate(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - Object right = rhs.evaluate(context, pos, len); - double ln = _number(context, left); - double rn = _number(context, right); - if (eq && ln == rn) - { - return Boolean.TRUE; - } - if (lt) - { - if (ln < rn || Double.isInfinite(rn)) - { - return Boolean.TRUE; - } - } - else - { - if (ln > rn || Double.isInfinite(ln)) - { - return Boolean.TRUE; - } - } - return Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new RelationalExpr(lhs.clone(context), rhs.clone(context), lt, eq); - } - - public String toString() - { - return lhs + " " + (lt ? "<" : ">") + (eq ? "=" : "") + " " + rhs; - } - -} diff --git a/libjava/gnu/xml/xpath/Root.java b/libjava/gnu/xml/xpath/Root.java deleted file mode 100644 index cf8f8d17e54..00000000000 --- a/libjava/gnu/xml/xpath/Root.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Root.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.Collections; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Expression that evaluates to the document root. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class Root - extends Path -{ - - public boolean matches(Node node) - { - return (node.getNodeType() == Node.DOCUMENT_NODE); - } - - public Object evaluate(Node context, int pos, int len) - { - return evaluate(context, Collections.EMPTY_SET); - } - - Collection evaluate(Node context, Collection ns) - { - Document doc = (context instanceof Document) ? (Document) context : - context.getOwnerDocument(); - return Collections.singleton(doc); - } - - public Expr clone(Object context) - { - return new Root(); - } - - public String toString() - { - return "/"; - } - -} diff --git a/libjava/gnu/xml/xpath/RoundFunction.java b/libjava/gnu/xml/xpath/RoundFunction.java deleted file mode 100644 index 7f9ff2a96a3..00000000000 --- a/libjava/gnu/xml/xpath/RoundFunction.java +++ /dev/null @@ -1,90 +0,0 @@ -/* RoundFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>round</code> function returns the number that is closest to the - * argument and that is an integer. If there are two such numbers, then the - * one that is closest to positive infinity is returned. If the argument is - * NaN, then NaN is returned. If the argument is positive infinity, then - * positive infinity is returned. If the argument is negative infinity, then - * negative infinity is returned. If the argument is positive zero, then - * positive zero is returned. If the argument is negative zero, then - * negative zero is returned. If the argument is less than zero, but greater - * than or equal to -0.5, then negative zero is returned. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class RoundFunction - extends Expr -{ - - final Expr arg; - - RoundFunction(List args) - { - this((Expr) args.get(0)); - } - - RoundFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - double n = _number(context, val); - return (Double.isNaN(n) || Double.isInfinite(n)) ? - new Double(n) : new Double(Math.round(n)); - } - - public Expr clone(Object context) - { - return new RoundFunction(arg.clone(context)); - } - - public String toString() - { - return "round(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/Selector.java b/libjava/gnu/xml/xpath/Selector.java deleted file mode 100644 index 383893d9280..00000000000 --- a/libjava/gnu/xml/xpath/Selector.java +++ /dev/null @@ -1,498 +0,0 @@ -/* Selector.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import javax.xml.XMLConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * A single component of a location path. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class Selector - extends Path -{ - - public static final int ANCESTOR = 0; - public static final int ANCESTOR_OR_SELF = 1; - public static final int ATTRIBUTE = 2; - public static final int CHILD = 3; - public static final int DESCENDANT = 4; - public static final int DESCENDANT_OR_SELF = 5; - public static final int FOLLOWING = 6; - public static final int FOLLOWING_SIBLING = 7; - public static final int NAMESPACE = 8; - public static final int PARENT = 9; - public static final int PRECEDING = 10; - public static final int PRECEDING_SIBLING = 11; - public static final int SELF = 12; - - /** - * Axis to select nodes in. - */ - final int axis; - - /** - * List of tests to perform on candidates. - */ - final Test[] tests; - - public Selector(int axis, List tests) - { - this.axis = axis; - this.tests = new Test[tests.size()]; - tests.toArray(this.tests); - if (axis == NAMESPACE && - this.tests.length > 0 && - this.tests[0] instanceof NameTest) - { - NameTest nt = (NameTest) this.tests[0]; - this.tests[0] = new NamespaceTest(nt.qName, nt.anyLocalName, nt.any); - } - } - - /** - * Returns the list of tests to perform on candidates. - */ - public Test[] getTests() - { - return tests; - } - - public boolean matches(Node context) - { - short nodeType = context.getNodeType(); - switch (axis) - { - case CHILD: - if (nodeType == Node.ATTRIBUTE_NODE) - { - return false; - } - break; - case ATTRIBUTE: - case NAMESPACE: - if (nodeType != Node.ATTRIBUTE_NODE) - { - return false; - } - break; - case DESCENDANT_OR_SELF: - return true; - default: - return false; - } - int tlen = tests.length; - if (tlen > 0) - { - int pos = getContextPosition(context); - int len = getContextSize(context); - for (int j = 0; j < tlen && len > 0; j++) - { - Test test = tests[j]; - if (!test.matches(context, pos, len)) - { - return false; - } - } - } - return true; - } - - private int getContextPosition(Node ctx) - { - int pos = 1; - for (ctx = ctx.getPreviousSibling(); ctx != null; - ctx = ctx.getPreviousSibling()) - { - pos++; - } - return pos; - } - - private int getContextSize(Node ctx) - { - if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) - { - Node parent = ((Attr) ctx).getOwnerElement(); - return parent.getAttributes().getLength(); - } - Node parent = ctx.getParentNode(); - if (parent != null) - { - return parent.getChildNodes().getLength(); - } - return 1; - } - - public Object evaluate(Node context, int pos, int len) - { - Set acc = new LinkedHashSet(); - addCandidates(context, acc); - List candidates = new ArrayList(acc); - //Collections.sort(candidates, documentOrderComparator); - List ret = filterCandidates(candidates, false); - return ret; - } - - Collection evaluate(Node context, Collection ns) - { - Set acc = new LinkedHashSet(); - for (Iterator i = ns.iterator(); i.hasNext(); ) - { - addCandidates((Node) i.next(), acc); - } - List candidates = new ArrayList(acc); - //Collections.sort(candidates, documentOrderComparator); - List ret = filterCandidates(candidates, true); - return ret; - } - - /** - * Filter the given list of candidates according to the node tests. - */ - List filterCandidates(List candidates, boolean cascade) - { - int len = candidates.size(); - int tlen = tests.length; - if (tlen > 0 && len > 0) - { - // Present the result of each successful generation to the next test - for (int j = 0; j < tlen && len > 0; j++) - { - Test test = tests[j]; - List successful = new ArrayList(len); - for (int i = 0; i < len; i++) - { - Node node = (Node) candidates.get(i); - if (cascade) - { - // Documents and DocumentFragments should be considered - // if part of a location path where the axis involves - // the SELF concept - short nodeType = node.getNodeType(); - if ((nodeType == Node.DOCUMENT_NODE || - nodeType == Node.DOCUMENT_FRAGMENT_NODE) && - (axis == DESCENDANT_OR_SELF || - axis == ANCESTOR_OR_SELF || - axis == SELF) && - (tests.length == 1 && - tests[0] instanceof NodeTypeTest && - ((NodeTypeTest) tests[0]).type == (short) 0)) - { - successful.add(node); - continue; - } - } - if (test.matches(node, i + 1, len)) - { - successful.add(node); - } - /* - System.err.println("Testing "+node); - int p = getContextPosition(node); - int l = getContextSize(node); - if (test.matches(node, p, l)) - { - successful.add(node); - }*/ - } - candidates = successful; - len = candidates.size(); - } - } - return candidates; - } - - void addCandidates(Node context, Collection candidates) - { - // Build list of candidates - switch (axis) - { - case CHILD: - addChildNodes(context, candidates, false); - break; - case DESCENDANT: - addChildNodes(context, candidates, true); - break; - case DESCENDANT_OR_SELF: - candidates.add (context); - addChildNodes(context, candidates, true); - break; - case PARENT: - addParentNode(context, candidates, false); - break; - case ANCESTOR: - addParentNode(context, candidates, true); - break; - case ANCESTOR_OR_SELF: - candidates.add(context); - addParentNode(context, candidates, true); - break; - case FOLLOWING_SIBLING: - addFollowingNodes(context, candidates, false); - break; - case PRECEDING_SIBLING: - addPrecedingNodes(context, candidates, false); - break; - case FOLLOWING: - addFollowingNodes(context, candidates, true); - break; - case PRECEDING: - addPrecedingNodes(context, candidates, true); - break; - case ATTRIBUTE: - addAttributes(context, candidates); - break; - case NAMESPACE: - addNamespaceAttributes(context, candidates); - break; - case SELF: - candidates.add(context); - break; - } - } - - void addChildNodes(Node context, Collection acc, boolean recurse) - { - Node child = context.getFirstChild(); - while (child != null) - { - acc.add(child); - if (recurse) - { - addChildNodes(child, acc, recurse); - } - child = child.getNextSibling(); - } - } - - void addParentNode(Node context, Collection acc, boolean recurse) - { - Node parent = (context.getNodeType() == Node.ATTRIBUTE_NODE) ? - ((Attr) context).getOwnerElement() : context.getParentNode(); - if (parent != null) - { - acc.add(parent); - if (recurse) - { - addParentNode(parent, acc, recurse); - } - } - } - - void addFollowingNodes(Node context, Collection acc, boolean recurse) - { - Node cur = context.getNextSibling(); - while (cur != null) - { - acc.add(cur); - if (recurse) - { - addChildNodes(cur, acc, true); - } - cur = cur.getNextSibling(); - } - if (recurse) - { - context = (context.getNodeType() == Node.ATTRIBUTE_NODE) ? - ((Attr) context).getOwnerElement() : context.getParentNode(); - if (context != null) - { - addFollowingNodes(context, acc, recurse); - } - } - } - - void addPrecedingNodes(Node context, Collection acc, boolean recurse) - { - Node cur = context.getPreviousSibling(); - while (cur != null) - { - acc.add(cur); - if (recurse) - { - addChildNodes(cur, acc, true); - } - cur = cur.getPreviousSibling(); - } - if (recurse) - { - context = (context.getNodeType() == Node.ATTRIBUTE_NODE) ? - ((Attr) context).getOwnerElement() : context.getParentNode(); - if (context != null) - { - addPrecedingNodes(context, acc, recurse); - } - } - } - - void addAttributes(Node context, Collection acc) - { - NamedNodeMap attrs = context.getAttributes(); - if (attrs != null) - { - int attrLen = attrs.getLength(); - for (int i = 0; i < attrLen; i++) - { - Node attr = attrs.item(i); - if (!isNamespaceAttribute(attr)) - { - acc.add(attr); - } - } - } - } - - void addNamespaceAttributes(Node context, Collection acc) - { - NamedNodeMap attrs = context.getAttributes(); - if (attrs != null) - { - int attrLen = attrs.getLength(); - for (int i = 0; i < attrLen; i++) - { - Node attr = attrs.item(i); - if (isNamespaceAttribute(attr)) - { - acc.add(attr); - } - } - } - } - - final boolean isNamespaceAttribute(Node node) - { - String uri = node.getNamespaceURI(); - return (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getPrefix()) || - XMLConstants.XMLNS_ATTRIBUTE.equals(node.getNodeName())); - } - - public Expr clone(Object context) - { - int len = tests.length; - List tests2 = new ArrayList(len); - for (int i = 0; i < len; i++) - { - tests2.add(tests[i].clone(context)); - } - return new Selector(axis, tests2); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - switch (axis) - { - case ANCESTOR: - buf.append("ancestor::"); - break; - case ANCESTOR_OR_SELF: - buf.append("ancestor-or-self::"); - break; - case ATTRIBUTE: - buf.append("attribute::"); - break; - case CHILD: - //buf.append("child::"); - break; - case DESCENDANT: - buf.append("descendant::"); - break; - case DESCENDANT_OR_SELF: - buf.append("descendant-or-self::"); - break; - case FOLLOWING: - buf.append("following::"); - break; - case FOLLOWING_SIBLING: - buf.append("following-sibling::"); - break; - case NAMESPACE: - buf.append("namespace::"); - break; - case PARENT: - if (tests.length == 0 || - (tests[0] instanceof NodeTypeTest && - ((NodeTypeTest) tests[0]).type == 0)) - { - return ".."; - } - buf.append("parent::"); - break; - case PRECEDING: - buf.append("preceding::"); - break; - case PRECEDING_SIBLING: - buf.append("preceding-sibling::"); - break; - case SELF: - if (tests.length == 0 || - (tests[0] instanceof NodeTypeTest && - ((NodeTypeTest) tests[0]).type == 0)) - { - return "."; - } - buf.append("self::"); - break; - } - if (tests.length == 0) - { - buf.append('*'); - } - else - { - for (int i = 0; i < tests.length; i++) - { - buf.append(tests[i]); - } - } - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/StartsWithFunction.java b/libjava/gnu/xml/xpath/StartsWithFunction.java deleted file mode 100644 index 2cee8555fbf..00000000000 --- a/libjava/gnu/xml/xpath/StartsWithFunction.java +++ /dev/null @@ -1,86 +0,0 @@ -/* StartsWithFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>starts-with</code> function returns true if the first argument - * string starts with the second argument string, and otherwise returns false. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class StartsWithFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - - StartsWithFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1)); - } - - StartsWithFunction(Expr arg1, Expr arg2) - { - this.arg1 = arg1; - this.arg2 = arg2; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - String s1 = _string(context, val1); - String s2 = _string(context, val2); - return s1.startsWith(s2) ? Boolean.TRUE : Boolean.FALSE; - } - - public Expr clone(Object context) - { - return new StartsWithFunction(arg1.clone(context), arg2.clone(context)); - } - - public String toString() - { - return "starts-with(" + arg1 + "," + arg2 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/Steps.java b/libjava/gnu/xml/xpath/Steps.java deleted file mode 100644 index e8cbc4e619b..00000000000 --- a/libjava/gnu/xml/xpath/Steps.java +++ /dev/null @@ -1,240 +0,0 @@ -/* Steps.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Set; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -/** - * A list of transitions between components in a location path. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class Steps - extends Path -{ - - final LinkedList path; - - public Steps() - { - this(new LinkedList()); - } - - Steps(LinkedList path) - { - this.path = path; - } - - public boolean matches(Node context) - { - // Right to left - return matches(context, path.size() - 1); - } - - boolean matches(Node context, int pos) - { - Pattern right = (Pattern) path.get(pos); - if (!right.matches(context)) - { - return false; - } - if (pos > 0) - { - Pattern left = (Pattern) path.get(pos - 1); - Iterator j = possibleContexts(right, context).iterator(); - while (j.hasNext()) - { - Node candidate = (Node) j.next(); - if (left.matches(candidate) && - matches(candidate, pos - 1)) - { - return true; - } - // keep going, there may be another candidate - } - return false; - } - return true; - } - - /** - * Essentially the reverse of Selector.addCandidates. - * The idea is to determine possible context nodes for a match. - */ - Collection possibleContexts(Pattern pattern, Node context) - { - if (pattern instanceof Selector) - { - Selector s = (Selector) pattern; - Collection candidates = new LinkedHashSet(); - switch (s.axis) - { - case Selector.PARENT: - s.addChildNodes(context, candidates, false); - break; - case Selector.ANCESTOR: - s.addChildNodes(context, candidates, true); - break; - case Selector.ANCESTOR_OR_SELF: - candidates.add (context); - s.addChildNodes(context, candidates, true); - break; - case Selector.CHILD: - s.addParentNode(context, candidates, false); - break; - case Selector.DESCENDANT: - s.addParentNode(context, candidates, true); - break; - case Selector.DESCENDANT_OR_SELF: - candidates.add(context); - s.addParentNode(context, candidates, true); - break; - case Selector.PRECEDING_SIBLING: - s.addFollowingNodes(context, candidates, false); - break; - case Selector.FOLLOWING_SIBLING: - s.addPrecedingNodes(context, candidates, false); - break; - case Selector.PRECEDING: - s.addFollowingNodes(context, candidates, true); - break; - case Selector.FOLLOWING: - s.addPrecedingNodes(context, candidates, true); - break; - case Selector.ATTRIBUTE: - case Selector.NAMESPACE: - if (context.getNodeType() == Node.ATTRIBUTE_NODE) - { - candidates.add(((Attr) context).getOwnerElement()); - } - break; - case Selector.SELF: - candidates.add(context); - break; - } - return candidates; - } - return Collections.EMPTY_SET; - } - - public Object evaluate(Node context, int pos, int len) - { - //System.err.println(toString()+" evaluate"); - // Left to right - Iterator i = path.iterator(); - Expr lhs = (Expr) i.next(); - Object val = lhs.evaluate(context, pos, len); - //System.err.println("\tevaluate "+lhs+" = "+val); - while (val instanceof Collection && i.hasNext()) - { - Path rhs = (Path) i.next(); - val = rhs.evaluate(context, (Collection) val); - //System.err.println("\tevaluate "+rhs+" = "+val); - } - return val; - } - - Collection evaluate(Node context, Collection ns) - { - // Left to right - Iterator i = path.iterator(); - Expr lhs = (Expr) i.next(); - if (lhs instanceof Path) - { - ns = ((Path) lhs).evaluate(context, ns); - } - else - { - Set acc = new LinkedHashSet(); - int pos = 1, len = ns.size(); - for (Iterator j = ns.iterator(); j.hasNext(); ) - { - Node node = (Node) j.next(); - Object ret = lhs.evaluate(node, pos++, len); - if (ret instanceof Collection) - { - acc.addAll((Collection) ret); - } - } - ns = acc; - } - while (i.hasNext()) - { - Path rhs = (Path) i.next(); - ns = rhs.evaluate(context, ns); - } - return ns; - } - - public Expr clone(Object context) - { - int len = path.size(); - LinkedList path2 = new LinkedList(); - for (int i = 0; i < len; i++) - { - path2.add(((Expr) path.get(i)).clone(context)); - } - return new Steps(path2); - } - - public String toString() - { - StringBuffer buf = new StringBuffer(); - Iterator i = path.iterator(); - Expr expr = (Expr) i.next(); - if (!(expr instanceof Root)) - { - buf.append(expr); - } - while (i.hasNext()) - { - expr = (Expr) i.next(); - buf.append('/'); - buf.append(expr); - } - return buf.toString(); - } - -} diff --git a/libjava/gnu/xml/xpath/StringFunction.java b/libjava/gnu/xml/xpath/StringFunction.java deleted file mode 100644 index fac15050aaf..00000000000 --- a/libjava/gnu/xml/xpath/StringFunction.java +++ /dev/null @@ -1,113 +0,0 @@ -/* StringFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>string function converts an object to a string as follows: - * <ul> - * <li>A node-set is converted to a string by returning the string-value of - * the node in the node-set that is first in document order. If the node-set - * is empty, an empty string is returned.</li> - * <li>A number is converted to a string as follows - * <ul> - * <li>NaN is converted to the string NaN</li> - * <li>positive zero is converted to the string 0</li> - * <li>negative zero is converted to the string 0</li> - * <li>positive infinity is converted to the string Infinity</li> - * <li>negative infinity is converted to the string -Infinity</li> - * <li>if the number is an integer, the number is represented in decimal - * form as a Number with no decimal point and no leading zeros, preceded by - * a minus sign (-) if the number is negative</li> - * <li>otherwise, the number is represented in decimal form as a Number - * including a decimal point with at least one digit before the decimal - * point and at least one digit after the decimal point, preceded by a minus - * sign (-) if the number is negative; there must be no leading zeros before - * the decimal point apart possibly from the one required digit immediately - * before the decimal point; beyond the one required digit after the decimal - * point there must be as many, but only as many, more digits as are needed - * to uniquely distinguish the number from all other IEEE 754 numeric - * values.</li> - * </ul> - * </li> - * <li>The boolean false value is converted to the string false. The boolean - * true value is converted to the string true.</li> - * <li>An object of a type other than the four basic types is converted to a - * string in a way that is dependent on that type.</li> - * </ul> - * If the argument is omitted, it defaults to a node-set with the context - * node as its only member. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class StringFunction - extends Expr -{ - - final Expr arg; - - StringFunction(List args) - { - this(args.size() > 0 ? (Expr) args.get(0) : null); - } - - StringFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - return _string(context, val); - } - - public Expr clone(Object context) - { - return new StringFunction((arg == null) ? null : - arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "string()" : "string(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/StringLengthFunction.java b/libjava/gnu/xml/xpath/StringLengthFunction.java deleted file mode 100644 index 4545c895fec..00000000000 --- a/libjava/gnu/xml/xpath/StringLengthFunction.java +++ /dev/null @@ -1,85 +0,0 @@ -/* StringLengthFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>string-length</code> function returns the number of characters - * in the string. - * If the argument is omitted, it defaults to the context node converted to - * a string, in other words the string-value of the context node. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class StringLengthFunction - extends Expr -{ - - final Expr arg; - - StringLengthFunction(List args) - { - this(args.isEmpty() ? null : (Expr) args.get(0)); - } - - StringLengthFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = (arg == null) ? null : arg.evaluate(context, pos, len); - String s = _string(context, val); - return new Double((double) s.length()); - } - - public Expr clone(Object context) - { - return new StringLengthFunction((arg == null) ? null : - arg.clone(context)); - } - - public String toString() - { - return (arg == null) ? "string-length()" : "string-length(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/SubstringAfterFunction.java b/libjava/gnu/xml/xpath/SubstringAfterFunction.java deleted file mode 100644 index dcdff31f165..00000000000 --- a/libjava/gnu/xml/xpath/SubstringAfterFunction.java +++ /dev/null @@ -1,92 +0,0 @@ -/* SubstringAfterFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>substring-after</code> function returns the substring of the - * first argument string that follows the first occurrence of the second - * argument string in the first argument string, or the empty string if the - * first argument string does not contain the second argument string. For - * example, substring-after("1999/04/01","/") returns 04/01, and - * substring-after("1999/04/01","19") returns 99/04/01. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SubstringAfterFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - - SubstringAfterFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1)); - } - - SubstringAfterFunction(Expr arg1, Expr arg2) - { - this.arg1 = arg1; - this.arg2 = arg2; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - String s1 = _string(context, val1); - String s2 = _string(context, val2); - int index = s1.indexOf(s2); - return (index == -1) ? "" : s1.substring(index + s2.length()); - } - - public Expr clone(Object context) - { - return new SubstringAfterFunction(arg1.clone(context), - arg2.clone(context)); - } - - public String toString() - { - return "substring-after(" + arg1 + "," + arg2 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/SubstringBeforeFunction.java b/libjava/gnu/xml/xpath/SubstringBeforeFunction.java deleted file mode 100644 index 4322bcd691b..00000000000 --- a/libjava/gnu/xml/xpath/SubstringBeforeFunction.java +++ /dev/null @@ -1,91 +0,0 @@ -/* SubstringBeforeFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>substring-before</code> function returns the substring of the - * first argument string that precedes the first occurrence of the second - * argument string in the first argument string, or the empty string if the - * first argument string does not contain the second argument string. For - * example, substring-before("1999/04/01","/") returns 1999. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SubstringBeforeFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - - SubstringBeforeFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1)); - } - - SubstringBeforeFunction(Expr arg1, Expr arg2) - { - this.arg1 = arg1; - this.arg2 = arg2; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - String s1 = _string(context, val1); - String s2 = _string(context, val2); - int index = s1.indexOf(s2); - return (index == -1) ? "" : s1.substring(0, index); - } - - public Expr clone(Object context) - { - return new SubstringBeforeFunction(arg1.clone(context), - arg2.clone(context)); - } - - public String toString() - { - return "substring-before(" + arg1 + "," + arg2 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/SubstringFunction.java b/libjava/gnu/xml/xpath/SubstringFunction.java deleted file mode 100644 index a554045cff0..00000000000 --- a/libjava/gnu/xml/xpath/SubstringFunction.java +++ /dev/null @@ -1,122 +0,0 @@ -/* SubstringFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The substring function returns the substring of the first argument - * starting at the position specified in the second argument with length - * specified in the third argument. For example, substring("12345",2,3) - * returns "234". If the third argument is not specified, it returns the - * substring starting at the position specified in the second argument and - * continuing to the end of the string. For example, substring("12345",2) - * returns "2345". - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SubstringFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - final Expr arg3; - - SubstringFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1), - (args.size() > 2) ? (Expr) args.get(2) : null); - } - - SubstringFunction(Expr arg1, Expr arg2, Expr arg3) - { - this.arg1 = arg1; - this.arg2 = arg2; - this.arg3 = arg3; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - String s = _string(context, val1); - int p = (val2 instanceof Double) ? - ((Double) val2).intValue() : - (int) Math.round(_number(context, val2)); - p--; - if (p < 0) - { - p = 0; - } - - int l = s.length() - p; - if (l <= 0) - { - return ""; - } - - if (arg3 != null) - { - Object val3 = arg3.evaluate(context, pos, len); - int v3 = (val3 instanceof Double) ? - ((Double) val3).intValue() : - (int) Math.round(_number(context, val3)); - if (v3 < l) - { - l = v3; - } - } - - return s.substring(p, p + l); - } - - public Expr clone(Object context) - { - return new SubstringFunction(arg1.clone(context), arg2.clone(context), - (arg3 == null) ? null : arg3.clone(context)); - } - - public String toString() - { - return (arg3 == null) ? "substring(" + arg1 + "," + arg2 + ")" : - "substring(" + arg1 + "," + arg2 + "," + arg3 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/SumFunction.java b/libjava/gnu/xml/xpath/SumFunction.java deleted file mode 100644 index 61452f80947..00000000000 --- a/libjava/gnu/xml/xpath/SumFunction.java +++ /dev/null @@ -1,94 +0,0 @@ -/* SumFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>sum</code> function returns the sum, for each node in the - * argument node-set, of the result of converting the string-values of the - * node to a number. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class SumFunction - extends Expr -{ - - final Expr arg; - - SumFunction(List args) - { - this((Expr) args.get(0)); - } - - SumFunction(Expr arg) - { - this.arg = arg; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val = arg.evaluate(context, pos, len); - double sum = 0.0d; - if (val instanceof Collection) - { - for (Iterator i = ((Collection) val).iterator(); i.hasNext(); ) - { - Node node = (Node) i.next(); - String s = stringValue(node); - sum += _number(context, s); - } - } - return new Double(sum); - } - - public Expr clone(Object context) - { - return new SumFunction(arg.clone(context)); - } - - public String toString() - { - return "sum(" + arg + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/Test.java b/libjava/gnu/xml/xpath/Test.java deleted file mode 100644 index 1ea4bc473a4..00000000000 --- a/libjava/gnu/xml/xpath/Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Test.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * A test that can be performed on a node to determine whether to include it - * in a selection. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public abstract class Test -{ - - public abstract boolean matches(Node node, int pos, int len); - - public abstract Test clone(Object context); - -} diff --git a/libjava/gnu/xml/xpath/TranslateFunction.java b/libjava/gnu/xml/xpath/TranslateFunction.java deleted file mode 100644 index b62180734ce..00000000000 --- a/libjava/gnu/xml/xpath/TranslateFunction.java +++ /dev/null @@ -1,126 +0,0 @@ -/* TranslateFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.List; -import org.w3c.dom.Node; - -/** - * The <code>translate</code> function returns the first argument string - * with occurrences of characters in the second argument string replaced by - * the character at the corresponding position in the third argument string. - * For example, translate("bar","abc","ABC") returns the string BAr. If - * there is a character in the second argument string with no character at a - * corresponding position in the third argument string (because the second - * argument string is longer than the third argument string), then - * occurrences of that character in the first argument string are removed. - * For example, translate("--aaa--","abc-","ABC") returns "AAA". If a - * character occurs more than once in the second argument string, then the - * first occurrence determines the replacement character. If the third - * argument string is longer than the second argument string, then excess - * characters are ignored. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class TranslateFunction - extends Expr -{ - - final Expr arg1; - final Expr arg2; - final Expr arg3; - - TranslateFunction(List args) - { - this((Expr) args.get(0), (Expr) args.get(1), (Expr) args.get(2)); - } - - TranslateFunction(Expr arg1, Expr arg2, Expr arg3) - { - this.arg1 = arg1; - this.arg2 = arg2; - this.arg3 = arg3; - } - - public Object evaluate(Node context, int pos, int len) - { - Object val1 = arg1.evaluate(context, pos, len); - Object val2 = arg2.evaluate(context, pos, len); - Object val3 = arg3.evaluate(context, pos, len); - String string = _string(context, val1); - String search = _string(context, val2); - String replace = _string(context, val3); - StringBuffer buf = new StringBuffer(); - int l1 = string.length(); - int l2 = search.length(); - int l3 = replace.length(); - for (int i = 0; i < l1; i++) - { - char c = string.charAt(i); - boolean replaced = false; - for (int j = 0; j < l2; j++) - { - if (c == search.charAt(j)) - { - if (j < l3) - { - buf.append(replace.charAt(j)); - } - replaced = true; - } - } - if (!replaced) - { - buf.append(c); - } - } - return new String(buf); - } - - public Expr clone(Object context) - { - return new TranslateFunction(arg1.clone(context), arg2.clone(context), - arg3.clone(context)); - } - - public String toString() - { - return "translate(" + arg1 + "," + arg2 + "," + arg3 + ")"; - } - -} diff --git a/libjava/gnu/xml/xpath/TrueFunction.java b/libjava/gnu/xml/xpath/TrueFunction.java deleted file mode 100644 index 3dd68bd5aa4..00000000000 --- a/libjava/gnu/xml/xpath/TrueFunction.java +++ /dev/null @@ -1,66 +0,0 @@ -/* TrueFunction.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import org.w3c.dom.Node; - -/** - * The <code>true</code> function returns true. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -final class TrueFunction - extends Expr -{ - - public Object evaluate(Node context, int pos, int len) - { - return Boolean.TRUE; - } - - public Expr clone(Object context) - { - return new TrueFunction(); - } - - public String toString() - { - return "true()"; - } - -} diff --git a/libjava/gnu/xml/xpath/UnionExpr.java b/libjava/gnu/xml/xpath/UnionExpr.java deleted file mode 100644 index 58c28a4d176..00000000000 --- a/libjava/gnu/xml/xpath/UnionExpr.java +++ /dev/null @@ -1,102 +0,0 @@ -/* UnionExpr.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.w3c.dom.Node; - -/** - * The union of two node-sets. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public final class UnionExpr - extends Pattern -{ - - final Expr lhs; - final Expr rhs; - - public UnionExpr(Expr lhs, Expr rhs) - { - this.lhs = lhs; - this.rhs = rhs; - } - - public boolean matches(Node context) - { - if (lhs instanceof Pattern && rhs instanceof Pattern) - { - return ((Pattern) lhs).matches(context) || - ((Pattern) rhs).matches(context); - } - return false; - } - - public Object evaluate(Node context, int pos, int len) - { - Object left = lhs.evaluate(context, pos, len); - Object right = rhs.evaluate(context, pos, len); - if (left instanceof Collection && right instanceof Collection) - { - Set set = new HashSet(); - set.addAll ((Collection) left); - set.addAll ((Collection) right); - List list = new ArrayList(set); - Collections.sort(list, documentOrderComparator); - return list; - } - return Collections.EMPTY_SET; - } - - public Expr clone(Object context) - { - return new UnionExpr(lhs.clone(context), rhs.clone(context)); - } - - public String toString() - { - return lhs + " | " + rhs; - } - -} diff --git a/libjava/gnu/xml/xpath/VariableReference.java b/libjava/gnu/xml/xpath/VariableReference.java deleted file mode 100644 index e53d1faa858..00000000000 --- a/libjava/gnu/xml/xpath/VariableReference.java +++ /dev/null @@ -1,88 +0,0 @@ -/* VariableReference.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathVariableResolver; -import org.w3c.dom.Node; -import gnu.xml.transform.Bindings; - -public class VariableReference - extends Expr -{ - - final XPathVariableResolver resolver; - final String name; - - public VariableReference(XPathVariableResolver resolver, String name) - { - this.resolver = resolver; - this.name = name; - } - - public Object evaluate(Node context, int pos, int len) - { - if (resolver != null) - { - if (resolver instanceof Bindings) - { - // Needs context to operate properly - return ((Bindings) resolver).get(name, context, pos, len); - } - QName qname = QName.valueOf(name); - return resolver.resolveVariable(qname); - } - throw new IllegalStateException("no variable resolver"); - } - - public Expr clone(Object context) - { - XPathVariableResolver r = resolver; - if (context instanceof XPathVariableResolver) - { - r = (XPathVariableResolver) context; - } - return new VariableReference(r, name); - } - - public String toString() - { - return "$" + name; - } - -} diff --git a/libjava/gnu/xml/xpath/XPathFactoryImpl.java b/libjava/gnu/xml/xpath/XPathFactoryImpl.java deleted file mode 100644 index 45dc57ed14a..00000000000 --- a/libjava/gnu/xml/xpath/XPathFactoryImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -/* XPathFactoryImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPathFactoryConfigurationException; -import javax.xml.xpath.XPathFunctionResolver; -import javax.xml.xpath.XPathVariableResolver; - -/** - * GNU XPath factory implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class XPathFactoryImpl - extends XPathFactory -{ - - XPathVariableResolver variableResolver; - XPathFunctionResolver functionResolver; - - public boolean isObjectModelSupported(String objectModel) - { - return XPathFactory.DEFAULT_OBJECT_MODEL_URI.equals(objectModel); - } - - public void setFeature(String name, boolean value) - throws XPathFactoryConfigurationException - { - throw new XPathFactoryConfigurationException(name); - } - - public boolean getFeature(String name) - throws XPathFactoryConfigurationException - { - throw new XPathFactoryConfigurationException(name); - } - - public void setXPathVariableResolver(XPathVariableResolver resolver) - { - variableResolver = resolver; - } - - public void setXPathFunctionResolver(XPathFunctionResolver resolver) - { - functionResolver = resolver; - } - - public XPath newXPath() - { - return new XPathImpl(null, variableResolver, functionResolver); - } - -} diff --git a/libjava/gnu/xml/xpath/XPathImpl.java b/libjava/gnu/xml/xpath/XPathImpl.java deleted file mode 100644 index 3511834ca90..00000000000 --- a/libjava/gnu/xml/xpath/XPathImpl.java +++ /dev/null @@ -1,164 +0,0 @@ -/* XPathImpl.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.io.IOException; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFunctionResolver; -import javax.xml.xpath.XPathVariableResolver; -import org.xml.sax.InputSource; - -/** - * JAXP XPath implementation. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class XPathImpl - implements XPath -{ - - XPathParser parser; - NamespaceContext namespaceContext; - XPathVariableResolver variableResolver; - XPathFunctionResolver functionResolver; - - XPathImpl(NamespaceContext namespaceContext, - XPathVariableResolver variableResolver, - XPathFunctionResolver functionResolver) - { - parser = new XPathParser(); - this.namespaceContext = namespaceContext; - this.variableResolver = variableResolver; - this.functionResolver = functionResolver; - reset(); - } - - public void reset() - { - parser.namespaceContext = namespaceContext; - parser.variableResolver = variableResolver; - parser.functionResolver = functionResolver; - } - - public void setXPathVariableResolver(XPathVariableResolver resolver) - { - parser.variableResolver = resolver; - } - - public XPathVariableResolver getXPathVariableResolver() - { - return parser.variableResolver; - } - - public void setXPathFunctionResolver(XPathFunctionResolver resolver) - { - parser.functionResolver = resolver; - } - - public XPathFunctionResolver getXPathFunctionResolver() - { - return parser.functionResolver; - } - - public void setNamespaceContext(NamespaceContext nsContext) - { - parser.namespaceContext = nsContext; - } - - public NamespaceContext getNamespaceContext() - { - return parser.namespaceContext; - } - - public XPathExpression compile(String expression) - throws XPathExpressionException - { - XPathTokenizer tokenizer = new XPathTokenizer(expression); - try - { - return (Expr) parser.yyparse(tokenizer); - } - catch (IOException e) - { - throw new XPathExpressionException(e); - } - catch (XPathParser.yyException e) - { - throw new XPathExpressionException(expression); - } - } - - public Object evaluate(String expression, - Object item, - QName returnType) - throws XPathExpressionException - { - XPathExpression expr = compile(expression); - return expr.evaluate(item, returnType); - } - - public String evaluate(String expression, - Object item) - throws XPathExpressionException - { - XPathExpression expr = compile(expression); - return expr.evaluate(item); - } - - public Object evaluate(String expression, - InputSource source, - QName returnType) - throws XPathExpressionException - { - XPathExpression expr = compile(expression); - return expr.evaluate(source, returnType); - } - - public String evaluate(String expression, - InputSource source) - throws XPathExpressionException - { - XPathExpression expr = compile(expression); - return expr.evaluate(source); - } - -} diff --git a/libjava/gnu/xml/xpath/XPathParser.java b/libjava/gnu/xml/xpath/XPathParser.java deleted file mode 100644 index 01c744790dc..00000000000 --- a/libjava/gnu/xml/xpath/XPathParser.java +++ /dev/null @@ -1,1461 +0,0 @@ -// created by jay 0.8 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de - - // line 2 "XPathParser.y" -/* XPathParser.java -- An XPath 1.0 parser. - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunctionResolver; -import javax.xml.xpath.XPathVariableResolver; -import org.w3c.dom.Node; - -/** - * An XPath 1.0 parser. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class XPathParser -{ - - NamespaceContext namespaceContext; - XPathVariableResolver variableResolver; - XPathFunctionResolver functionResolver; - - QName getQName(String name) - { - QName qName = QName.valueOf(name); - if (namespaceContext != null) - { - String prefix = qName.getPrefix(); - String uri = qName.getNamespaceURI(); - if (prefix != null && (uri == null || uri.length() == 0)) - { - uri = namespaceContext.getNamespaceURI(prefix); - String localName = qName.getLocalPart(); - qName = new QName(uri, localName, prefix); - } - } - return qName; - } - - Expr lookupFunction(String name, List args) - { - int arity = args.size(); - if ("position".equals(name) && arity == 0) - { - return new PositionFunction(); - } - else if ("last".equals(name) && arity == 0) - { - return new LastFunction(); - } - else if ("string".equals(name) && (arity == 1 || arity == 0)) - { - return new StringFunction(args); - } - else if ("number".equals(name) && (arity == 1 || arity == 0)) - { - return new NumberFunction(args); - } - else if ("boolean".equals(name) && arity == 1) - { - return new BooleanFunction(args); - } - else if ("count".equals(name) && arity == 1) - { - return new CountFunction(args); - } - else if ("not".equals(name) && arity == 1) - { - return new NotFunction(args); - } - else if ("id".equals(name) && arity == 1) - { - return new IdFunction(args); - } - else if ("concat".equals(name) && arity > 1) - { - return new ConcatFunction(args); - } - else if ("true".equals(name) && arity == 0) - { - return new TrueFunction(); - } - else if ("false".equals(name) && arity == 0) - { - return new FalseFunction(); - } - else if ("name".equals(name) && (arity == 1 || arity == 0)) - { - return new NameFunction(args); - } - else if ("local-name".equals(name) && (arity == 1 || arity == 0)) - { - return new LocalNameFunction(args); - } - else if ("namespace-uri".equals(name) && (arity == 1 || arity == 0)) - { - return new NamespaceUriFunction(args); - } - else if ("starts-with".equals(name) && arity == 2) - { - return new StartsWithFunction(args); - } - else if ("contains".equals(name) && arity == 2) - { - return new ContainsFunction(args); - } - else if ("string-length".equals(name) && (arity == 1 || arity == 0)) - { - return new StringLengthFunction(args); - } - else if ("translate".equals(name) && arity == 3) - { - return new TranslateFunction(args); - } - else if ("normalize-space".equals(name) && (arity == 1 || arity == 0)) - { - return new NormalizeSpaceFunction(args); - } - else if ("substring".equals(name) && (arity == 2 || arity == 3)) - { - return new SubstringFunction(args); - } - else if ("substring-before".equals(name) && arity == 2) - { - return new SubstringBeforeFunction(args); - } - else if ("substring-after".equals(name) && arity == 2) - { - return new SubstringAfterFunction(args); - } - else if ("lang".equals(name) && arity == 1) - { - return new LangFunction(args); - } - else if ("sum".equals(name) && arity == 1) - { - return new SumFunction(args); - } - else if ("floor".equals(name) && arity == 1) - { - return new FloorFunction(args); - } - else if ("ceiling".equals(name) && arity == 1) - { - return new CeilingFunction(args); - } - else if ("round".equals(name) && arity == 1) - { - return new RoundFunction(args); - } - else if (functionResolver != null) - { - QName qName = QName.valueOf(name); - Object function = functionResolver.resolveFunction(qName, arity); - if (function != null && - function instanceof Function && - function instanceof Expr) - { - Function f = (Function) function; - f.setArguments(args); - return (Expr) function; - } - } - return new FunctionCall(functionResolver, name, args); - } - - // line 210 "-" -// %token constants - - public static final int LITERAL = 257; - public static final int DIGITS = 258; - public static final int NAME = 259; - public static final int LP = 260; - public static final int RP = 261; - public static final int LB = 262; - public static final int RB = 263; - public static final int COMMA = 264; - public static final int PIPE = 265; - public static final int SLASH = 266; - public static final int DOUBLE_SLASH = 267; - public static final int EQ = 268; - public static final int NE = 269; - public static final int GT = 270; - public static final int LT = 271; - public static final int GTE = 272; - public static final int LTE = 273; - public static final int PLUS = 274; - public static final int MINUS = 275; - public static final int AT = 276; - public static final int STAR = 277; - public static final int DOLLAR = 278; - public static final int COLON = 279; - public static final int DOUBLE_COLON = 280; - public static final int DOT = 281; - public static final int DOUBLE_DOT = 282; - public static final int ANCESTOR = 283; - public static final int ANCESTOR_OR_SELF = 284; - public static final int ATTRIBUTE = 285; - public static final int CHILD = 286; - public static final int DESCENDANT = 287; - public static final int DESCENDANT_OR_SELF = 288; - public static final int FOLLOWING = 289; - public static final int FOLLOWING_SIBLING = 290; - public static final int NAMESPACE = 291; - public static final int PARENT = 292; - public static final int PRECEDING = 293; - public static final int PRECEDING_SIBLING = 294; - public static final int SELF = 295; - public static final int DIV = 296; - public static final int MOD = 297; - public static final int OR = 298; - public static final int AND = 299; - public static final int COMMENT = 300; - public static final int PROCESSING_INSTRUCTION = 301; - public static final int TEXT = 302; - public static final int NODE = 303; - public static final int UNARY = 304; - public static final int yyErrorCode = 256; - - /** thrown for irrecoverable syntax errors and stack overflow. - */ - public static class yyException extends java.lang.Exception { - public yyException (String message) { - super(message); - } - } - - /** must be implemented by a scanner object to supply input to the parser. - */ - public interface yyInput { - /** move on to next token. - @return false if positioned beyond tokens. - @throws IOException on input error. - */ - boolean advance () throws java.io.IOException; - /** classifies current token. - Should not be called if advance() returned false. - @return current %token or single character. - */ - int token (); - /** associated with current token. - Should not be called if advance() returned false. - @return value for token(). - */ - Object value (); - } - - /** simplified error message. - @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a> - */ - public void yyerror (String message) { - yyerror(message, null); - } - - /** (syntax) error message. - Can be overwritten to control message format. - @param message text to be displayed. - @param expected vector of acceptable tokens, if available. - */ - public void yyerror (String message, String[] expected) { - if (expected != null && expected.length > 0) { - System.err.print(message+", expecting"); - for (int n = 0; n < expected.length; ++ n) - System.err.print(" "+expected[n]); - System.err.println(); - } else - System.err.println(message); - } - - /** debugging support, requires the package jay.yydebug. - Set to null to suppress debugging messages. - */ -//t protected jay.yydebug.yyDebug yydebug; - - protected static final int yyFinal = 30; - - /** index-checked interface to yyName[]. - @param token single character or %token value. - @return token name or [illegal] or [unknown]. - */ -//t public static final String yyname (int token) { -//t if (token < 0 || token > YyNameClass.yyName.length) return "[illegal]"; -//t String name; -//t if ((name = YyNameClass.yyName[token]) != null) return name; -//t return "[unknown]"; -//t } - - /** computes list of expected tokens on error by tracing the tables. - @param state for which to compute the list. - @return list of token names. - */ - protected String[] yyExpecting (int state) { - int token, n, len = 0; - boolean[] ok = new boolean[YyNameClass.yyName.length]; - - if ((n = YySindexClass.yySindex[state]) != 0) - for (token = n < 0 ? -n : 0; - token < YyNameClass.yyName.length && n+token < YyTableClass.yyTable.length; ++ token) - if (YyCheckClass.yyCheck[n+token] == token && !ok[token] && YyNameClass.yyName[token] != null) { - ++ len; - ok[token] = true; - } - if ((n = YyRindexClass.yyRindex[state]) != 0) - for (token = n < 0 ? -n : 0; - token < YyNameClass.yyName.length && n+token < YyTableClass.yyTable.length; ++ token) - if (YyCheckClass.yyCheck[n+token] == token && !ok[token] && YyNameClass.yyName[token] != null) { - ++ len; - ok[token] = true; - } - - String result[] = new String[len]; - for (n = token = 0; n < len; ++ token) - if (ok[token]) result[n++] = YyNameClass.yyName[token]; - return result; - } - - /** the generated parser, with debugging messages. - Maintains a state and a value stack, currently with fixed maximum size. - @param yyLex scanner. - @param yydebug debug message writer implementing yyDebug, or null. - @return result of the last reduction, if any. - @throws yyException on irrecoverable parse error. - */ - public Object yyparse (yyInput yyLex, Object yydebug) - throws java.io.IOException, yyException { -//t this.yydebug = (jay.yydebug.yyDebug)yydebug; - return yyparse(yyLex); - } - - /** initial size and increment of the state/value stack [default 256]. - This is not final so that it can be overwritten outside of invocations - of yyparse(). - */ - protected int yyMax; - - /** executed at the beginning of a reduce action. - Used as $$ = yyDefault($1), prior to the user-specified action, if any. - Can be overwritten to provide deep copy, etc. - @param first value for $1, or null. - @return first. - */ - protected Object yyDefault (Object first) { - return first; - } - - /** the generated parser. - Maintains a state and a value stack, currently with fixed maximum size. - @param yyLex scanner. - @return result of the last reduction, if any. - @throws yyException on irrecoverable parse error. - */ - public Object yyparse (yyInput yyLex) - throws java.io.IOException, yyException { - if (yyMax <= 0) yyMax = 256; // initial size - int yyState = 0, yyStates[] = new int[yyMax]; // state stack - Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack - int yyToken = -1; // current input - int yyErrorFlag = 0; // #tks to shift - - yyLoop: for (int yyTop = 0;; ++ yyTop) { - if (yyTop >= yyStates.length) { // dynamically increase - int[] i = new int[yyStates.length+yyMax]; - System.arraycopy(yyStates, 0, i, 0, yyStates.length); - yyStates = i; - Object[] o = new Object[yyVals.length+yyMax]; - System.arraycopy(yyVals, 0, o, 0, yyVals.length); - yyVals = o; - } - yyStates[yyTop] = yyState; - yyVals[yyTop] = yyVal; -//t if (yydebug != null) yydebug.push(yyState, yyVal); - - yyDiscarded: for (;;) { // discarding a token does not change stack - int yyN; - if ((yyN = YyDefRedClass.yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) - if (yyToken < 0) { - yyToken = yyLex.advance() ? yyLex.token() : 0; -//t if (yydebug != null) -//t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value()); - } - if ((yyN = YySindexClass.yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 - && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) { -//t if (yydebug != null) -//t yydebug.shift(yyState, YyTableClass.yyTable[yyN], yyErrorFlag-1); - yyState = YyTableClass.yyTable[yyN]; // shift to yyN - yyVal = yyLex.value(); - yyToken = -1; - if (yyErrorFlag > 0) -- yyErrorFlag; - continue yyLoop; - } - if ((yyN = YyRindexClass.yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 - && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) - yyN = YyTableClass.yyTable[yyN]; // reduce (yyN) - else - switch (yyErrorFlag) { - - case 0: - yyerror("syntax error", yyExpecting(yyState)); -//t if (yydebug != null) yydebug.error("syntax error"); - - case 1: case 2: - yyErrorFlag = 3; - do { - if ((yyN = YySindexClass.yySindex[yyStates[yyTop]]) != 0 - && (yyN += yyErrorCode) >= 0 && yyN < YyTableClass.yyTable.length - && YyCheckClass.yyCheck[yyN] == yyErrorCode) { -//t if (yydebug != null) -//t yydebug.shift(yyStates[yyTop], YyTableClass.yyTable[yyN], 3); - yyState = YyTableClass.yyTable[yyN]; - yyVal = yyLex.value(); - continue yyLoop; - } -//t if (yydebug != null) yydebug.pop(yyStates[yyTop]); - } while (-- yyTop >= 0); -//t if (yydebug != null) yydebug.reject(); - throw new yyException("irrecoverable syntax error"); - - case 3: - if (yyToken == 0) { -//t if (yydebug != null) yydebug.reject(); - throw new yyException("irrecoverable syntax error at end-of-file"); - } -//t if (yydebug != null) -//t yydebug.discard(yyState, yyToken, yyname(yyToken), -//t yyLex.value()); - yyToken = -1; - continue yyDiscarded; // leave stack alone - } - } - int yyV = yyTop + 1-YyLenClass.yyLen[yyN]; -//t if (yydebug != null) -//t yydebug.reduce(yyState, yyStates[yyV-1], yyN, YyRuleClass.yyRule[yyN], YyLenClass.yyLen[yyN]); - yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); - switch (yyN) { -case 4: - // line 276 "XPathParser.y" - { - yyVal = new Root(); - } - break; -case 5: - // line 280 "XPathParser.y" - { - Steps steps; - if (yyVals[0+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[0+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[0+yyTop]); - } - steps.path.addFirst(new Root()); - yyVal = steps; - /*$$ = new Step(new Root(), (Path) $2);*/ - } - break; -case 6: - // line 296 "XPathParser.y" - { - Test nt = new NodeTypeTest((short) 0); - Selector s = new Selector(Selector.DESCENDANT_OR_SELF, - Collections.singletonList (nt)); - Steps steps; - if (yyVals[0+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[0+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[0+yyTop]); - } - steps.path.addFirst(s); - steps.path.addFirst(new Root()); - yyVal = steps; - /*Step step = new Step(s, (Path) $2);*/ - /*$$ = new Step(new Root(), step);*/ - } - break; -case 8: - // line 321 "XPathParser.y" - { - Steps steps; - if (yyVals[-2+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[-2+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[-2+yyTop]); - } - steps.path.addLast(yyVals[0+yyTop]); - yyVal = steps; - /*$$ = new Step((Expr) $1, (Path) $3);*/ - } - break; -case 9: - // line 337 "XPathParser.y" - { - Test nt = new NodeTypeTest((short) 0); - Selector s = new Selector(Selector.DESCENDANT_OR_SELF, - Collections.singletonList (nt)); - Steps steps; - if (yyVals[-2+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[-2+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[-2+yyTop]); - } - steps.path.addLast(s); - steps.path.addLast(yyVals[0+yyTop]); - yyVal = steps; - /*Step step = new Step(s, (Path) $3);*/ - /*$$ = new Step((Expr) $1, step);*/ - } - break; -case 10: - // line 361 "XPathParser.y" - { - yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); - } - break; -case 11: - // line 365 "XPathParser.y" - { - yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); - } - break; -case 12: - // line 369 "XPathParser.y" - { - yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); - } - break; -case 13: - // line 373 "XPathParser.y" - { - yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST); - } - break; -case 14: - // line 377 "XPathParser.y" - { - yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST); - } - break; -case 15: - // line 384 "XPathParser.y" - { - List list = new ArrayList(); - list.add(yyVals[0+yyTop]); - yyVal = list; - } - break; -case 16: - // line 390 "XPathParser.y" - { - List list = (List)yyVals[-1+yyTop]; - list.add(yyVals[0+yyTop]); - yyVal = list; - } - break; -case 17: - // line 414 "XPathParser.y" - { - yyVal = new Integer(Selector.ANCESTOR); - } - break; -case 18: - // line 418 "XPathParser.y" - { - yyVal = new Integer(Selector.ANCESTOR_OR_SELF); - } - break; -case 19: - // line 422 "XPathParser.y" - { - yyVal = new Integer(Selector.ATTRIBUTE); - } - break; -case 20: - // line 426 "XPathParser.y" - { - yyVal = new Integer(Selector.CHILD); - } - break; -case 21: - // line 430 "XPathParser.y" - { - yyVal = new Integer(Selector.DESCENDANT); - } - break; -case 22: - // line 434 "XPathParser.y" - { - yyVal = new Integer(Selector.DESCENDANT_OR_SELF); - } - break; -case 23: - // line 438 "XPathParser.y" - { - yyVal = new Integer(Selector.FOLLOWING); - } - break; -case 24: - // line 442 "XPathParser.y" - { - yyVal = new Integer(Selector.FOLLOWING_SIBLING); - } - break; -case 25: - // line 446 "XPathParser.y" - { - yyVal = new Integer(Selector.NAMESPACE); - } - break; -case 26: - // line 450 "XPathParser.y" - { - yyVal = new Integer(Selector.PARENT); - } - break; -case 27: - // line 454 "XPathParser.y" - { - yyVal = new Integer(Selector.PRECEDING); - } - break; -case 28: - // line 458 "XPathParser.y" - { - yyVal = new Integer(Selector.PRECEDING_SIBLING); - } - break; -case 29: - // line 462 "XPathParser.y" - { - yyVal = new Integer(Selector.SELF); - } - break; -case 31: - // line 471 "XPathParser.y" - { - yyVal = new NodeTypeTest(Node.PROCESSING_INSTRUCTION_NODE, (String) yyVals[-1+yyTop]); - } - break; -case 32: - // line 476 "XPathParser.y" - { - yyVal = new NodeTypeTest(((Short) yyVals[-1+yyTop]).shortValue()); - } - break; -case 33: - // line 483 "XPathParser.y" - { - yyVal = new Predicate((Expr) yyVals[-1+yyTop]); - } - break; -case 35: - // line 491 "XPathParser.y" - { - yyVal = new ParenthesizedExpr((Expr) yyVals[-1+yyTop]); - } - break; -case 36: - // line 495 "XPathParser.y" - { - yyVal = new Constant(yyVals[0+yyTop]); - } - break; -case 37: - // line 499 "XPathParser.y" - { - yyVal = new Constant(yyVals[0+yyTop]); - } - break; -case 39: - // line 507 "XPathParser.y" - { - yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST); - } - break; -case 40: - // line 511 "XPathParser.y" - { - yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); - } - break; -case 41: - // line 518 "XPathParser.y" - { - List list = new ArrayList(); - list.add(yyVals[0+yyTop]); - yyVal = list; - } - break; -case 42: - // line 524 "XPathParser.y" - { - List list = (List) yyVals[0+yyTop]; - list.add(0, yyVals[-2+yyTop]); - yyVal = list; - } - break; -case 44: - // line 534 "XPathParser.y" - { - yyVal = new UnionExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); - } - break; -case 47: - // line 543 "XPathParser.y" - { - Steps steps; - if (yyVals[0+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[0+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[0+yyTop]); - } - steps.path.addFirst(yyVals[-2+yyTop]); - yyVal = steps; - /*$$ = new Step ((Expr) $1, (Path) $3);*/ - } - break; -case 48: - // line 559 "XPathParser.y" - { - Test nt = new NodeTypeTest((short) 0); - Selector s = new Selector(Selector.DESCENDANT_OR_SELF, - Collections.singletonList(nt)); - Steps steps; - if (yyVals[0+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[0+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[0+yyTop]); - } - steps.path.addFirst(s); - steps.path.addFirst(yyVals[-2+yyTop]); - yyVal = steps; - /*Step step = new Step (s, (Path) $3);*/ - /*$$ = new Step ((Expr) $1, step);*/ - } - break; -case 50: - // line 584 "XPathParser.y" - { - Predicate filter = (Predicate) yyVals[0+yyTop]; - Selector s = new Selector(Selector.SELF, - Collections.singletonList(filter)); - Steps steps; - if (yyVals[-1+yyTop] instanceof Steps) - { - steps = (Steps) yyVals[-1+yyTop]; - } - else - { - steps = new Steps(); - steps.path.addFirst(yyVals[-1+yyTop]); - } - steps.path.addLast(s); - yyVal = steps; - /*$$ = new Step ((Expr) $1, s);*/ - } - break; -case 52: - // line 607 "XPathParser.y" - { - yyVal = new OrExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); - } - break; -case 54: - // line 615 "XPathParser.y" - { - yyVal = new AndExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); - } - break; -case 56: - // line 623 "XPathParser.y" - { - yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false); - } - break; -case 57: - // line 627 "XPathParser.y" - { - yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true); - } - break; -case 59: - // line 635 "XPathParser.y" - { - yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, false); - } - break; -case 60: - // line 639 "XPathParser.y" - { - yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, false); - } - break; -case 61: - // line 643 "XPathParser.y" - { - yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, true); - } - break; -case 62: - // line 647 "XPathParser.y" - { - yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, true); - } - break; -case 64: - // line 655 "XPathParser.y" - { - yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.ADD); - } - break; -case 65: - // line 659 "XPathParser.y" - { - yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.SUBTRACT); - } - break; -case 67: - // line 667 "XPathParser.y" - { - yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MULTIPLY); - } - break; -case 68: - // line 671 "XPathParser.y" - { - yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.DIVIDE); - } - break; -case 69: - // line 675 "XPathParser.y" - { - yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MODULO); - } - break; -case 71: - // line 683 "XPathParser.y" - { - yyVal = new NegativeExpr((Expr) yyVals[0+yyTop]); - } - break; -case 72: - // line 690 "XPathParser.y" - { - yyVal = new Double((String) yyVals[0+yyTop] + ".0"); - } - break; -case 73: - // line 694 "XPathParser.y" - { - yyVal = new Double((String) yyVals[-1+yyTop] + ".0"); - } - break; -case 74: - // line 698 "XPathParser.y" - { - yyVal = new Double((String) yyVals[-2+yyTop] + "." + (String) yyVals[0+yyTop]); - } - break; -case 75: - // line 702 "XPathParser.y" - { - yyVal = new Double("0." + (String) yyVals[0+yyTop]); - } - break; -case 77: - // line 731 "XPathParser.y" - { - yyVal = new VariableReference(variableResolver, (String) yyVals[0+yyTop]); - } - break; -case 78: - // line 738 "XPathParser.y" - { - yyVal = new NameTest(null, true, true); - } - break; -case 79: - // line 742 "XPathParser.y" - { - QName qName = getQName((String) yyVals[-2+yyTop]); - yyVal = new NameTest(qName, true, false); - } - break; -case 80: - // line 747 "XPathParser.y" - { - QName qName = getQName((String) yyVals[0+yyTop]); - yyVal = new NameTest(qName, false, false); - } - break; -case 82: - // line 756 "XPathParser.y" - { - yyVal = (String) yyVals[-2+yyTop] + ':' + (String) yyVals[0+yyTop]; - } - break; -case 83: - // line 763 "XPathParser.y" - { - yyVal = new Short(Node.COMMENT_NODE); - } - break; -case 84: - // line 767 "XPathParser.y" - { - yyVal = new Short(Node.TEXT_NODE); - } - break; -case 85: - // line 771 "XPathParser.y" - { - yyVal = new Short(Node.PROCESSING_INSTRUCTION_NODE); - } - break; -case 86: - // line 775 "XPathParser.y" - { - yyVal = new Short((short) 0); - } - break; - // line 986 "-" - } - yyTop -= YyLenClass.yyLen[yyN]; - yyState = yyStates[yyTop]; - int yyM = YyLhsClass.yyLhs[yyN]; - if (yyState == 0 && yyM == 0) { -//t if (yydebug != null) yydebug.shift(0, yyFinal); - yyState = yyFinal; - if (yyToken < 0) { - yyToken = yyLex.advance() ? yyLex.token() : 0; -//t if (yydebug != null) -//t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value()); - } - if (yyToken == 0) { -//t if (yydebug != null) yydebug.accept(yyVal); - return yyVal; - } - continue yyLoop; - } - if ((yyN = YyGindexClass.yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 - && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyState) - yyState = YyTableClass.yyTable[yyN]; - else - yyState = YyDgotoClass.yyDgoto[yyM]; -//t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState); - continue yyLoop; - } - } - } - - protected static final class YyLhsClass { - - public static final short yyLhs [] = { -1, - 0, 2, 2, 4, 4, 4, 3, 3, 3, 5, - 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, - 8, 8, 9, 12, 12, 12, 12, 12, 15, 15, - 17, 17, 18, 18, 19, 19, 19, 19, 20, 20, - 1, 1, 21, 21, 22, 22, 22, 23, 23, 23, - 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, - 26, 14, 14, 14, 14, 16, 13, 10, 10, 10, - 27, 27, 11, 11, 11, 11, - }; - } /* End of class YyLhsClass */ - - protected static final class YyLenClass { - - public static final short yyLen [] = { 2, - 1, 1, 1, 1, 2, 2, 1, 3, 3, 1, - 2, 3, 1, 1, 1, 2, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 3, 2, 3, 1, 3, 1, 1, 1, 3, 4, - 1, 3, 1, 3, 1, 1, 3, 3, 1, 2, - 1, 3, 1, 3, 1, 3, 3, 1, 3, 3, - 3, 3, 1, 3, 3, 1, 3, 3, 3, 1, - 2, 1, 2, 3, 2, 1, 2, 1, 3, 1, - 1, 3, 1, 1, 1, 1, - }; - } /* End class YyLenClass */ - - protected static final class YyDefRedClass { - - public static final short yyDefRed [] = { 0, - 36, 0, 0, 0, 0, 0, 0, 0, 78, 0, - 0, 14, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 83, 0, 84, 86, 0, - 0, 45, 0, 3, 7, 0, 0, 15, 30, 0, - 49, 34, 37, 38, 0, 0, 43, 0, 0, 0, - 0, 0, 0, 66, 0, 0, 0, 0, 13, 0, - 80, 0, 71, 0, 0, 77, 75, 0, 0, 0, - 0, 0, 16, 0, 32, 0, 0, 0, 0, 50, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 74, 82, 79, 35, 0, 31, 0, 8, - 9, 0, 0, 39, 0, 0, 44, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 67, 68, - 69, 33, 0, 40, 42, - }; - } /* End of class YyDefRedClass */ - - protected static final class YyDgotoClass { - - public static final short yyDgoto [] = { 105, - 31, 32, 33, 34, 35, 36, 37, 38, 73, 39, - 40, 41, 42, 43, 44, 45, 106, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, - }; - } /* End of class YyDgotoClass */ - - protected static final class YySindexClass { - - public static final short yySindex [] = { -97, - 0, -271, -267, -97, -239, -239, -97, -199, 0, -236, - -222, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -218, 0, 0, 0, - -257, 0, -241, 0, 0, -205, -221, 0, 0, -194, - 0, 0, 0, 0, -190, -185, 0, -238, -211, -234, - -255, -209, -275, 0, 0, -169, -250, -168, 0, -241, - 0, -241, 0, -205, -187, 0, 0, -167, -97, -239, - -239, -97, 0, -199, 0, -151, -43, -239, -239, 0, - -97, -97, -97, -97, -97, -97, -97, -97, -97, -97, - -97, -97, 0, 0, 0, 0, -164, 0, -211, 0, - 0, -166, -205, 0, -165, -163, 0, -241, -241, -234, - -255, -255, -209, -209, -209, -209, -275, -275, 0, 0, - 0, 0, -97, 0, 0, - }; - } /* End of class YySindexClass */ - - protected static final class YyRindexClass { - - public static final short yyRindex [] = { 0, - 0, 58, 1, 0, 420, 0, 0, 0, 0, 0, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -161, 0, 0, 0, - 40, 0, 237, 0, 0, 168, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 459, 0, 277, 557, 544, - 656, 561, 474, 0, 19, 75, 0, 0, 0, 295, - 0, 334, 0, 183, 114, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 686, 0, - 0, 0, 222, 0, -156, 0, 0, 351, 405, 553, - 665, 697, 577, 600, 617, 639, 513, 528, 0, 0, - 0, 0, 0, 0, 0, - }; - } /* End of class YyRindexClass */ - - protected static final class YyGindexClass { - - public static final short yyGindex [] = { 7, - 0, 0, 8, 0, 3, -3, 0, 0, 48, 0, - 0, 0, 0, 0, 0, 0, -12, 0, 35, 0, - 44, 36, -1, -54, 2, -7, -2, - }; - } /* End of class YyGindexClass */ - - protected static final class YyTableClass { - - public static final short yyTable [] = { 63, - 81, 90, 61, 61, 64, 61, 30, 66, 94, 56, - 58, 57, 60, 62, 84, 85, 86, 87, 80, 3, - 91, 92, 65, 72, 70, 71, 95, 78, 79, 113, - 114, 115, 116, 82, 83, 67, 8, 9, 68, 1, - 69, 59, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 72, 72, 74, 3, - 26, 27, 28, 29, 88, 89, 75, 61, 61, 76, - 103, 61, 100, 101, 73, 61, 61, 9, 102, 77, - 111, 112, 119, 120, 121, 108, 109, 81, 93, 117, - 118, 97, 96, 98, 94, 80, 122, 124, 123, 85, - 26, 27, 28, 29, 41, 1, 2, 3, 4, 104, - 125, 107, 99, 81, 5, 6, 110, 0, 0, 0, - 0, 0, 0, 7, 8, 9, 10, 0, 13, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 0, 0, 0, 0, 26, 27, - 28, 29, 0, 0, 0, 0, 0, 0, 0, 1, - 2, 3, 4, 0, 0, 0, 0, 10, 5, 6, - 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, - 10, 0, 11, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, - 0, 0, 26, 27, 28, 29, 0, 0, 0, 0, - 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, - 0, 12, 5, 6, 0, 0, 0, 0, 0, 0, - 0, 0, 8, 9, 10, 0, 2, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 0, 0, 0, 0, 26, 27, 28, 29, - 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 46, 81, 76, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 5, 80, 81, 81, 81, 81, - 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 80, 80, 80, 80, 72, 72, - 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, - 72, 72, 72, 6, 72, 73, 73, 73, 73, 73, - 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, - 47, 73, 0, 72, 72, 72, 72, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 73, 73, 73, 73, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 81, 81, 81, 81, 81, 81, 13, - 81, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 48, 13, 0, 0, 0, 81, - 81, 81, 81, 0, 0, 0, 0, 0, 0, 4, - 0, 0, 0, 0, 13, 13, 13, 13, 10, 0, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 11, 10, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 70, 11, - 0, 0, 0, 10, 10, 10, 10, 0, 0, 0, - 0, 0, 0, 63, 0, 0, 0, 0, 11, 11, - 11, 11, 12, 0, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 2, 12, 2, - 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, - 2, 2, 64, 2, 0, 0, 0, 12, 12, 12, - 12, 0, 0, 0, 0, 0, 0, 65, 0, 0, - 0, 0, 2, 2, 2, 2, 0, 46, 0, 46, - 46, 46, 0, 53, 46, 46, 46, 46, 46, 46, - 46, 46, 54, 46, 0, 5, 51, 5, 5, 5, - 58, 0, 5, 5, 5, 5, 5, 5, 5, 5, - 0, 5, 46, 46, 46, 46, 60, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 5, 5, 5, 5, 6, 0, 6, 6, 6, 59, - 0, 6, 6, 6, 6, 6, 6, 6, 6, 0, - 6, 47, 0, 47, 47, 47, 62, 0, 47, 47, - 47, 47, 47, 47, 47, 47, 0, 47, 0, 6, - 6, 6, 6, 0, 0, 0, 0, 0, 61, 0, - 0, 0, 0, 0, 0, 0, 47, 47, 47, 47, - 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, - 0, 0, 0, 0, 56, 48, 0, 48, 48, 48, - 0, 0, 48, 48, 48, 48, 48, 48, 48, 48, - 4, 48, 4, 4, 4, 52, 0, 4, 4, 4, - 4, 4, 4, 4, 4, 0, 57, 0, 0, 0, - 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 4, 4, 4, 70, - 0, 70, 70, 0, 0, 0, 70, 70, 70, 70, - 70, 70, 70, 70, 63, 70, 63, 63, 0, 0, - 0, 63, 63, 63, 63, 63, 63, 63, 63, 0, - 0, 0, 0, 0, 70, 70, 70, 70, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 63, 63, 64, 0, 64, 64, 0, 0, 0, - 64, 64, 64, 64, 64, 64, 64, 64, 65, 0, - 65, 65, 0, 0, 0, 65, 65, 65, 65, 65, - 65, 65, 65, 0, 53, 0, 53, 53, 0, 0, - 64, 64, 0, 54, 0, 54, 54, 51, 0, 51, - 51, 58, 0, 58, 58, 65, 65, 0, 58, 58, - 58, 58, 58, 58, 0, 0, 0, 60, 0, 60, - 60, 53, 53, 0, 60, 60, 60, 60, 60, 60, - 54, 54, 0, 0, 51, 0, 0, 0, 58, 58, - 59, 0, 59, 59, 0, 0, 0, 59, 59, 59, - 59, 59, 59, 0, 60, 60, 0, 62, 0, 62, - 62, 0, 0, 0, 62, 62, 62, 62, 62, 62, - 0, 0, 0, 0, 0, 0, 0, 59, 59, 61, - 0, 61, 61, 0, 0, 0, 61, 61, 61, 61, - 61, 61, 0, 0, 62, 62, 55, 0, 55, 55, - 0, 0, 0, 55, 55, 56, 0, 56, 56, 0, - 0, 0, 56, 56, 0, 0, 61, 61, 0, 0, - 0, 0, 0, 0, 0, 0, 52, 0, 52, 52, - 0, 0, 0, 55, 55, 0, 0, 57, 0, 57, - 57, 0, 56, 56, 57, 57, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 57, 57, - }; - } /* End of class YyTableClass */ - - protected static final class YyCheckClass { - - public static final short yyCheck [] = { 7, - 0, 277, 5, 6, 8, 8, 0, 10, 259, 281, - 4, 279, 5, 6, 270, 271, 272, 273, 0, 259, - 296, 297, 259, 262, 266, 267, 277, 266, 267, 84, - 85, 86, 87, 268, 269, 258, 276, 277, 257, 0, - 298, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 291, 292, 293, 294, 295, 262, 0, 280, 259, - 300, 301, 302, 303, 274, 275, 261, 70, 71, 260, - 74, 74, 70, 71, 0, 78, 79, 277, 72, 265, - 82, 83, 90, 91, 92, 78, 79, 299, 258, 88, - 89, 279, 261, 261, 259, 48, 263, 261, 264, 261, - 300, 301, 302, 303, 261, 257, 258, 259, 260, 261, - 123, 77, 69, 0, 266, 267, 81, -1, -1, -1, - -1, -1, -1, 275, 276, 277, 278, -1, 0, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, - 292, 293, 294, 295, -1, -1, -1, -1, 300, 301, - 302, 303, -1, -1, -1, -1, -1, -1, -1, 257, - 258, 259, 260, -1, -1, -1, -1, 0, 266, 267, - -1, -1, -1, -1, -1, -1, -1, 275, 276, 277, - 278, -1, 0, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 291, 292, 293, 294, 295, -1, -1, - -1, -1, 300, 301, 302, 303, -1, -1, -1, -1, - -1, -1, -1, 257, 258, 259, 260, -1, -1, -1, - -1, 0, 266, 267, -1, -1, -1, -1, -1, -1, - -1, -1, 276, 277, 278, -1, 0, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, - 294, 295, -1, -1, -1, -1, 300, 301, 302, 303, - 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, - 270, 271, 272, 273, 274, 275, 0, 277, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, 275, 0, 277, 296, 297, 298, 299, - 261, -1, 263, 264, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 296, 297, 298, 299, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 0, 277, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, - 0, 277, -1, 296, 297, 298, 299, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 296, 297, 298, 299, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 261, - 277, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, 275, 0, 277, -1, -1, -1, 296, - 297, 298, 299, -1, -1, -1, -1, -1, -1, 0, - -1, -1, -1, -1, 296, 297, 298, 299, 261, -1, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 261, 277, 263, 264, 265, 266, 267, - 268, 269, 270, 271, 272, 273, 274, 275, 0, 277, - -1, -1, -1, 296, 297, 298, 299, -1, -1, -1, - -1, -1, -1, 0, -1, -1, -1, -1, 296, 297, - 298, 299, 261, -1, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 261, 277, 263, - 264, 265, -1, -1, 268, 269, 270, 271, 272, 273, - 274, 275, 0, 277, -1, -1, -1, 296, 297, 298, - 299, -1, -1, -1, -1, -1, -1, 0, -1, -1, - -1, -1, 296, 297, 298, 299, -1, 261, -1, 263, - 264, 265, -1, 0, 268, 269, 270, 271, 272, 273, - 274, 275, 0, 277, -1, 261, 0, 263, 264, 265, - 0, -1, 268, 269, 270, 271, 272, 273, 274, 275, - -1, 277, 296, 297, 298, 299, 0, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 296, 297, 298, 299, 261, -1, 263, 264, 265, 0, - -1, 268, 269, 270, 271, 272, 273, 274, 275, -1, - 277, 261, -1, 263, 264, 265, 0, -1, 268, 269, - 270, 271, 272, 273, 274, 275, -1, 277, -1, 296, - 297, 298, 299, -1, -1, -1, -1, -1, 0, -1, - -1, -1, -1, -1, -1, -1, 296, 297, 298, 299, - -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, - -1, -1, -1, -1, 0, 261, -1, 263, 264, 265, - -1, -1, 268, 269, 270, 271, 272, 273, 274, 275, - 261, 277, 263, 264, 265, 0, -1, 268, 269, 270, - 271, 272, 273, 274, 275, -1, 0, -1, -1, -1, - 296, 297, 298, 299, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 296, 297, 298, 299, 261, - -1, 263, 264, -1, -1, -1, 268, 269, 270, 271, - 272, 273, 274, 275, 261, 277, 263, 264, -1, -1, - -1, 268, 269, 270, 271, 272, 273, 274, 275, -1, - -1, -1, -1, -1, 296, 297, 298, 299, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 298, 299, 261, -1, 263, 264, -1, -1, -1, - 268, 269, 270, 271, 272, 273, 274, 275, 261, -1, - 263, 264, -1, -1, -1, 268, 269, 270, 271, 272, - 273, 274, 275, -1, 261, -1, 263, 264, -1, -1, - 298, 299, -1, 261, -1, 263, 264, 261, -1, 263, - 264, 261, -1, 263, 264, 298, 299, -1, 268, 269, - 270, 271, 272, 273, -1, -1, -1, 261, -1, 263, - 264, 298, 299, -1, 268, 269, 270, 271, 272, 273, - 298, 299, -1, -1, 298, -1, -1, -1, 298, 299, - 261, -1, 263, 264, -1, -1, -1, 268, 269, 270, - 271, 272, 273, -1, 298, 299, -1, 261, -1, 263, - 264, -1, -1, -1, 268, 269, 270, 271, 272, 273, - -1, -1, -1, -1, -1, -1, -1, 298, 299, 261, - -1, 263, 264, -1, -1, -1, 268, 269, 270, 271, - 272, 273, -1, -1, 298, 299, 261, -1, 263, 264, - -1, -1, -1, 268, 269, 261, -1, 263, 264, -1, - -1, -1, 268, 269, -1, -1, 298, 299, -1, -1, - -1, -1, -1, -1, -1, -1, 261, -1, 263, 264, - -1, -1, -1, 298, 299, -1, -1, 261, -1, 263, - 264, -1, 298, 299, 268, 269, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 298, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 298, 299, - }; - } /* End of class YyCheckClass */ - - -//t protected static final class YyRuleClass { - -//t public static final String yyRule [] = { -//t "$accept : expr", -//t "expr : or_expr", -//t "location_path : relative_location_path", -//t "location_path : absolute_location_path", -//t "absolute_location_path : SLASH", -//t "absolute_location_path : SLASH relative_location_path", -//t "absolute_location_path : DOUBLE_SLASH relative_location_path", -//t "relative_location_path : step", -//t "relative_location_path : relative_location_path SLASH step", -//t "relative_location_path : relative_location_path DOUBLE_SLASH step", -//t "step : step_node_test", -//t "step : AT step_node_test", -//t "step : axis_name DOUBLE_COLON step_node_test", -//t "step : DOT", -//t "step : DOUBLE_DOT", -//t "step_node_test : node_test", -//t "step_node_test : step_node_test predicate", -//t "axis_name : ANCESTOR", -//t "axis_name : ANCESTOR_OR_SELF", -//t "axis_name : ATTRIBUTE", -//t "axis_name : CHILD", -//t "axis_name : DESCENDANT", -//t "axis_name : DESCENDANT_OR_SELF", -//t "axis_name : FOLLOWING", -//t "axis_name : FOLLOWING_SIBLING", -//t "axis_name : NAMESPACE", -//t "axis_name : PARENT", -//t "axis_name : PRECEDING", -//t "axis_name : PRECEDING_SIBLING", -//t "axis_name : SELF", -//t "node_test : name_test", -//t "node_test : PROCESSING_INSTRUCTION LITERAL RP", -//t "node_test : node_type RP", -//t "predicate : LB expr RB", -//t "primary_expr : variable_reference", -//t "primary_expr : LP expr RP", -//t "primary_expr : LITERAL", -//t "primary_expr : number", -//t "primary_expr : function_call", -//t "function_call : function_name LP RP", -//t "function_call : function_name LP argument_list RP", -//t "argument_list : expr", -//t "argument_list : expr COMMA argument_list", -//t "union_expr : path_expr", -//t "union_expr : union_expr PIPE path_expr", -//t "path_expr : location_path", -//t "path_expr : filter_expr", -//t "path_expr : filter_expr SLASH relative_location_path", -//t "path_expr : filter_expr DOUBLE_SLASH relative_location_path", -//t "filter_expr : primary_expr", -//t "filter_expr : filter_expr predicate", -//t "or_expr : and_expr", -//t "or_expr : or_expr OR and_expr", -//t "and_expr : equality_expr", -//t "and_expr : and_expr AND equality_expr", -//t "equality_expr : relational_expr", -//t "equality_expr : equality_expr EQ relational_expr", -//t "equality_expr : equality_expr NE relational_expr", -//t "relational_expr : additive_expr", -//t "relational_expr : relational_expr LT additive_expr", -//t "relational_expr : relational_expr GT additive_expr", -//t "relational_expr : relational_expr LTE additive_expr", -//t "relational_expr : relational_expr GTE additive_expr", -//t "additive_expr : multiplicative_expr", -//t "additive_expr : additive_expr PLUS multiplicative_expr", -//t "additive_expr : additive_expr MINUS multiplicative_expr", -//t "multiplicative_expr : unary_expr", -//t "multiplicative_expr : multiplicative_expr STAR unary_expr", -//t "multiplicative_expr : multiplicative_expr DIV unary_expr", -//t "multiplicative_expr : multiplicative_expr MOD unary_expr", -//t "unary_expr : union_expr", -//t "unary_expr : MINUS unary_expr", -//t "number : DIGITS", -//t "number : DIGITS DOT", -//t "number : DIGITS DOT DIGITS", -//t "number : DOT DIGITS", -//t "function_name : qname", -//t "variable_reference : DOLLAR qname", -//t "name_test : STAR", -//t "name_test : NAME COLON STAR", -//t "name_test : qname", -//t "qname : NAME", -//t "qname : NAME COLON NAME", -//t "node_type : COMMENT", -//t "node_type : TEXT", -//t "node_type : PROCESSING_INSTRUCTION", -//t "node_type : NODE", -//t }; -//t } /* End of class YyRuleClass */ - - protected static final class YyNameClass { - - public static final String yyName [] = { - "end-of-file",null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,null,null,null,null,null,null,null, - null,null,null,null,null,null,null,"LITERAL","DIGITS","NAME","LP", - "RP","LB","RB","COMMA","PIPE","SLASH","DOUBLE_SLASH","EQ","NE","GT", - "LT","GTE","LTE","PLUS","MINUS","AT","STAR","DOLLAR","COLON", - "DOUBLE_COLON","DOT","DOUBLE_DOT","ANCESTOR","ANCESTOR_OR_SELF", - "ATTRIBUTE","CHILD","DESCENDANT","DESCENDANT_OR_SELF","FOLLOWING", - "FOLLOWING_SIBLING","NAMESPACE","PARENT","PRECEDING", - "PRECEDING_SIBLING","SELF","DIV","MOD","OR","AND","COMMENT", - "PROCESSING_INSTRUCTION","TEXT","NODE","UNARY", - }; - } /* End of class YyNameClass */ - - - // line 781 "XPathParser.y" - -} - // line 1461 "-" diff --git a/libjava/gnu/xml/xpath/XPathTokenizer.java b/libjava/gnu/xml/xpath/XPathTokenizer.java deleted file mode 100644 index a287137827b..00000000000 --- a/libjava/gnu/xml/xpath/XPathTokenizer.java +++ /dev/null @@ -1,592 +0,0 @@ -/* XPathTokenizer.java -- - Copyright (C) 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package gnu.xml.xpath; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.Map; -import java.util.TreeMap; - -/*import antlr.Token; -import antlr.TokenStream; -import antlr.TokenStreamException; -import antlr.TokenStreamIOException;*/ - -/** - * XPath 1.0 expression tokenizer. - * - * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> - */ -public class XPathTokenizer -implements XPathParser.yyInput -//implements TokenStream -{ - - static class XPathToken - //extends Token - { - - int type; - String val; - - XPathToken (int type) - { - this (type, null); - } - - XPathToken (int type, String val) - { - //super (type); - this.type = type; - this.val = val; - } - - public String getText () - { - return val; - } - - public String toString () - { - return val; - } - - } - - static final Map keywords = new TreeMap (); - static - { - keywords.put ("ancestor", new Integer (XPathParser.ANCESTOR)); - keywords.put ("ancestor-or-self", new Integer (XPathParser.ANCESTOR_OR_SELF)); - keywords.put ("attribute", new Integer (XPathParser.ATTRIBUTE)); - keywords.put ("child", new Integer (XPathParser.CHILD)); - keywords.put ("descendant", new Integer (XPathParser.DESCENDANT)); - keywords.put ("descendant-or-self", new Integer (XPathParser.DESCENDANT_OR_SELF)); - keywords.put ("following", new Integer (XPathParser.FOLLOWING)); - keywords.put ("following-sibling", new Integer (XPathParser.FOLLOWING_SIBLING)); - keywords.put ("namespace", new Integer (XPathParser.NAMESPACE)); - keywords.put ("parent", new Integer (XPathParser.PARENT)); - keywords.put ("preceding", new Integer (XPathParser.PRECEDING)); - keywords.put ("preceding-sibling", new Integer (XPathParser.PRECEDING_SIBLING)); - keywords.put ("self", new Integer (XPathParser.SELF)); - keywords.put ("div", new Integer (XPathParser.DIV)); - keywords.put ("mod", new Integer (XPathParser.MOD)); - keywords.put ("or", new Integer (XPathParser.OR)); - keywords.put ("and", new Integer (XPathParser.AND)); - keywords.put ("comment", new Integer (XPathParser.COMMENT)); - keywords.put ("processing-instruction", new Integer (XPathParser.PROCESSING_INSTRUCTION)); - keywords.put ("text", new Integer (XPathParser.TEXT)); - keywords.put ("node", new Integer (XPathParser.NODE)); - } - - Reader in; - XPathToken token; - XPathToken lastToken; - - public XPathTokenizer (String expr) - { - this (new StringReader (expr)); - } - - XPathTokenizer (Reader in) - { - this.in = in.markSupported () ? in : new BufferedReader (in); - } - - /* Begin ANTLR specific * - - public Token nextToken () - throws TokenStreamException - { - try - { - if (!advance ()) - { - throw new TokenStreamException ("eof"); - } - token (); - return token; - } - catch (IOException e) - { - throw new TokenStreamIOException (e); - } - } - - * End ANTLR specific */ - - public boolean advance () - throws IOException - { - lastToken = token; - int c = in.read (); - switch (c) - { - case -1: // eof - return false; - case 0x20: - case 0x09: - case 0x0d: - case 0x0a: // skip whitespace - return advance (); - case 0x22: // " - case 0x27: // ' - token = consume_literal (c); - break; - case 0x28: // ( - token = new XPathToken (XPathParser.LP); - break; - case 0x29: // ) - token = new XPathToken (XPathParser.RP); - break; - case 0x5b: // [ - token = new XPathToken (XPathParser.LB); - break; - case 0x5d: // ] - token = new XPathToken (XPathParser.RB); - break; - case 0x2c: // , - token = new XPathToken (XPathParser.COMMA); - break; - case 0x7c: // | - token = new XPathToken (XPathParser.PIPE); - break; - case 0x2f: // / - in.mark (1); - int d1 = in.read (); - if (d1 == 0x2f) - { - token = new XPathToken (XPathParser.DOUBLE_SLASH); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.SLASH); - } - break; - case 0x3d: // = - token = new XPathToken (XPathParser.EQ); - break; - case 0x21: // ! - in.mark (1); - int d2 = in.read (); - if (d2 == 0x3d) // = - { - token = new XPathToken (XPathParser.NE); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.yyErrorCode); - } - break; - case 0x3e: // > - in.mark (1); - int d3 = in.read (); - if (d3 == 0x3d) // = - { - token = new XPathToken (XPathParser.GTE); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.GT); - } - break; - case 0x3c: // < - in.mark (1); - int d4 = in.read (); - if (d4 == 0x3d) // = - { - token = new XPathToken (XPathParser.LTE); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.LT); - } - break; - case 0x2b: // + - token = new XPathToken (XPathParser.PLUS); - break; - case 0x2d: // - - token = new XPathToken (XPathParser.MINUS); - break; - case 0x40: // @ - token = new XPathToken (XPathParser.AT); - break; - case 0x2a: // * - token = new XPathToken (XPathParser.STAR); - break; - case 0x24: // $ - token = new XPathToken (XPathParser.DOLLAR); - break; - case 0x3a: // : - in.mark (1); - int d5 = in.read (); - if (d5 == 0x3a) - { - token = new XPathToken (XPathParser.DOUBLE_COLON); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.COLON); - } - break; - case 0x2e: // . - in.mark (1); - int d6 = in.read (); - if (d6 == 0x2e) - { - token = new XPathToken (XPathParser.DOUBLE_DOT); - } - else - { - in.reset (); - token = new XPathToken (XPathParser.DOT); - } - break; - default: - if (c >= 0x30 && c <= 0x39) - { - token = consume_digits (c); - } - else if (c == 0x5f || Character.isLetter ((char) c)) - { - token = consume_name (c); - } - else - { - token = new XPathToken (XPathParser.yyErrorCode); - } - } - return true; - } - - public int token () - { - return token.type; - } - - public Object value () - { - return token.val; - } - - XPathToken consume_literal (int delimiter) - throws IOException - { - StringBuffer buf = new StringBuffer (); - while (true) - { - int c = in.read (); - if (c == -1) - { - return new XPathToken (XPathParser.yyErrorCode); - } - else if (c == delimiter) - { - return new XPathToken (XPathParser.LITERAL, buf.toString ()); - } - else - { - buf.append ((char) c); - } - } - } - - XPathToken consume_digits (int c) - throws IOException - { - StringBuffer buf = new StringBuffer (); - buf.append ((char) c); - while (true) - { - in.mark (1); - c = in.read (); - if (c >= 0x30 && c <= 0x39) - { - buf.append ((char) c); - } - else - { - in.reset (); - return new XPathToken (XPathParser.DIGITS, buf.toString ()); - } - } - } - - XPathToken consume_name (int c) - throws IOException - { - StringBuffer buf = new StringBuffer (); - buf.append ((char) c); - while (true) - { - in.mark (1); - c = in.read (); - if (isNameChar (c)) - { - buf.append ((char) c); - } - else - { - in.reset (); - String name = buf.toString (); - Integer keyword = (Integer) keywords.get (name); - if (keyword == null) - { - return new XPathToken (XPathParser.NAME, name); - } - else - { - int val = keyword.intValue (); - switch (val) - { - case XPathParser.NODE: - case XPathParser.COMMENT: - case XPathParser.TEXT: - case XPathParser.PROCESSING_INSTRUCTION: - // Consume subsequent ( - in.mark (1); - do - { - c = in.read (); - } - while (c == 0x20 || c == 0x09); - if (c != 0x28) - { - in.reset (); - return new XPathToken (XPathParser.NAME, name); - } - break; - case XPathParser.CHILD: - case XPathParser.PARENT: - case XPathParser.SELF: - case XPathParser.DESCENDANT: - case XPathParser.ANCESTOR: - case XPathParser.DESCENDANT_OR_SELF: - case XPathParser.ANCESTOR_OR_SELF: - case XPathParser.ATTRIBUTE: - case XPathParser.NAMESPACE: - case XPathParser.FOLLOWING: - case XPathParser.FOLLOWING_SIBLING: - case XPathParser.PRECEDING: - case XPathParser.PRECEDING_SIBLING: - // Check that this is an axis specifier - in.mark(1); - do - { - c = in.read(); - } - while (c == 0x20 || c == 0x09); - if (c == 0x3a) - { - c = in.read(); - if (c == 0x3a) - { - in.reset(); - return new XPathToken(val); - } - } - in.reset(); - return new XPathToken(XPathParser.NAME, name); - case XPathParser.DIV: - case XPathParser.MOD: - // May be a name - if (lastToken == null) - { - return new XPathToken(XPathParser.NAME, name); - } - switch (lastToken.type) - { - case XPathParser.LP: - case XPathParser.LB: - case XPathParser.COMMA: - case XPathParser.PIPE: - case XPathParser.EQ: - case XPathParser.NE: - case XPathParser.GT: - case XPathParser.LT: - case XPathParser.GTE: - case XPathParser.LTE: - case XPathParser.PLUS: - case XPathParser.MINUS: - case XPathParser.STAR: - case XPathParser.AT: - case XPathParser.DOLLAR: - case XPathParser.COLON: - case XPathParser.DOUBLE_COLON: - case XPathParser.DIV: - case XPathParser.MOD: - case XPathParser.OR: - case XPathParser.AND: - case XPathParser.SLASH: - return new XPathToken(XPathParser.NAME, name); - } - break; - } - return new XPathToken (val); - } - } - } - } - - boolean isNameChar (int c) - { - /* Name */ - return (c == 0x5f - || c == 0x2d - || c == 0x2e - || (c >= 0x30 && c <= 0x39) - /* CombiningChar */ - || (c >= 0x0300 && c <= 0x0345) - || (c >= 0x0360 && c <= 0x0361) - || (c >= 0x0483 && c <= 0x0486) - || (c >= 0x0591 && c <= 0x05A1) - || (c >= 0x05A3 && c <= 0x05B9) - || (c >= 0x05BB && c <= 0x05BD) - || c == 0x05BF - || (c >= 0x05C1 && c <= 0x05C2) - || c == 0x05C4 - || (c >= 0x064B && c <= 0x0652) - || c == 0x0670 - || (c >= 0x06D6 && c <= 0x06DC) - || (c >= 0x06DD && c <= 0x06DF) - || (c >= 0x06E0 && c <= 0x06E4) - || (c >= 0x06E7 && c <= 0x06E8) - || (c >= 0x06EA && c <= 0x06ED) - || (c >= 0x0901 && c <= 0x0903) - || c == 0x093C - || (c >= 0x093E && c <= 0x094C) - || c == 0x094D - || (c >= 0x0951 && c <= 0x0954) - || (c >= 0x0962 && c <= 0x0963) - || (c >= 0x0981 && c <= 0x0983) - || c == 0x09BC - || c == 0x09BE - || c == 0x09BF - || (c >= 0x09C0 && c <= 0x09C4) - || (c >= 0x09C7 && c <= 0x09C8) - || (c >= 0x09CB && c <= 0x09CD) - || c == 0x09D7 - || (c >= 0x09E2 && c <= 0x09E3) - || c == 0x0A02 - || c == 0x0A3C - || c == 0x0A3E - || c == 0x0A3F - || (c >= 0x0A40 && c <= 0x0A42) - || (c >= 0x0A47 && c <= 0x0A48) - || (c >= 0x0A4B && c <= 0x0A4D) - || (c >= 0x0A70 && c <= 0x0A71) - || (c >= 0x0A81 && c <= 0x0A83) - || c == 0x0ABC - || (c >= 0x0ABE && c <= 0x0AC5) - || (c >= 0x0AC7 && c <= 0x0AC9) - || (c >= 0x0ACB && c <= 0x0ACD) - || (c >= 0x0B01 && c <= 0x0B03) - || c == 0x0B3C - || (c >= 0x0B3E && c <= 0x0B43) - || (c >= 0x0B47 && c <= 0x0B48) - || (c >= 0x0B4B && c <= 0x0B4D) - || (c >= 0x0B56 && c <= 0x0B57) - || (c >= 0x0B82 && c <= 0x0B83) - || (c >= 0x0BBE && c <= 0x0BC2) - || (c >= 0x0BC6 && c <= 0x0BC8) - || (c >= 0x0BCA && c <= 0x0BCD) - || c == 0x0BD7 - || (c >= 0x0C01 && c <= 0x0C03) - || (c >= 0x0C3E && c <= 0x0C44) - || (c >= 0x0C46 && c <= 0x0C48) - || (c >= 0x0C4A && c <= 0x0C4D) - || (c >= 0x0C55 && c <= 0x0C56) - || (c >= 0x0C82 && c <= 0x0C83) - || (c >= 0x0CBE && c <= 0x0CC4) - || (c >= 0x0CC6 && c <= 0x0CC8) - || (c >= 0x0CCA && c <= 0x0CCD) - || (c >= 0x0CD5 && c <= 0x0CD6) - || (c >= 0x0D02 && c <= 0x0D03) - || (c >= 0x0D3E && c <= 0x0D43) - || (c >= 0x0D46 && c <= 0x0D48) - || (c >= 0x0D4A && c <= 0x0D4D) - || c == 0x0D57 - || c == 0x0E31 - || (c >= 0x0E34 && c <= 0x0E3A) - || (c >= 0x0E47 && c <= 0x0E4E) - || c == 0x0EB1 - || (c >= 0x0EB4 && c <= 0x0EB9) - || (c >= 0x0EBB && c <= 0x0EBC) - || (c >= 0x0EC8 && c <= 0x0ECD) - || (c >= 0x0F18 && c <= 0x0F19) - || c == 0x0F35 - || c == 0x0F37 - || c == 0x0F39 - || c == 0x0F3E - || c == 0x0F3F - || (c >= 0x0F71 && c <= 0x0F84) - || (c >= 0x0F86 && c <= 0x0F8B) - || (c >= 0x0F90 && c <= 0x0F95) - || c == 0x0F97 - || (c >= 0x0F99 && c <= 0x0FAD) - || (c >= 0x0FB1 && c <= 0x0FB7) - || c == 0x0FB9 - || (c >= 0x20D0 && c <= 0x20DC) - || c == 0x20E1 - || (c >= 0x302A && c <= 0x302F) - || c == 0x3099 - || c == 0x309A - /* Extender */ - || c == 0x00B7 - || c == 0x02D0 - || c == 0x02D1 - || c == 0x0387 - || c == 0x0640 - || c == 0x0E46 - || c == 0x0EC6 - || c == 0x3005 - || (c >= 0x3031 && c <= 0x3035) - || (c >= 0x309D && c <= 0x309E) - || (c >= 0x30FC && c <= 0x30FE) - /* Name */ - || Character.isLetter ((char) c)); - } - -} |