From: <ls...@us...> - 2007-01-07 08:33:14
|
Revision: 3012 http://jnode.svn.sourceforge.net/jnode/?rev=3012&view=rev Author: lsantha Date: 2007-01-07 00:33:13 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/XSLURIResolver.java trunk/core/src/classpath/gnu/gnu/xml/util/XCat.java trunk/core/src/classpath/gnu/gnu/xml/xpath/Expr.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java Modified: trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -172,7 +172,6 @@ else return super.current_member_kind(); } - ; /** @inheritDoc */ public String current_member_name() throws TypeMismatch, InvalidValue @@ -182,7 +181,6 @@ else return super.current_member_name(); } - ; /** @inheritDoc */ public NameDynAnyPair[] get_members_as_dyn_any() throws InvalidValue @@ -191,7 +189,6 @@ throw new InvalidValue(ISNULL); return super.gnu_get_members_as_dyn_any(); } - ; /** @inheritDoc */ public NameValuePair[] get_members() throws InvalidValue @@ -201,7 +198,6 @@ else return super.gnu_get_members(); } - ; /** @inheritDoc */ public void set_members_as_dyn_any(NameDynAnyPair[] value) @@ -210,7 +206,6 @@ super.set_members_as_dyn_any(value); isNull = false; } - ; /** @inheritDoc */ public void set_members(NameValuePair[] value) @@ -219,7 +214,6 @@ super.set_members(value); isNull = false; } - ; /** @inheritDoc */ public boolean is_null() Modified: trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1348,7 +1348,6 @@ { return name; } - ; /** * Return the parent of this POA. Modified: trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -49,6 +49,7 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.ServiceConfigurationError; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -176,7 +177,6 @@ */ private static final Logger LOGGER = Logger.getLogger("gnu.classpath"); - /** * Declared private in order to prevent constructing instances of * this utility class. @@ -225,6 +225,51 @@ public static Iterator lookupProviders(Class spi, ClassLoader loader) { + return lookupProviders(spi, loader, false); + } + + /** + * 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)}. + * @param error true if a {@link ServiceConfigurationError} + * should be thrown when an error occurs, rather + * than it merely being logged. + * @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, + boolean error) + { String resourceName; Enumeration urls; @@ -246,10 +291,14 @@ * does not return anything (no providers installed). */ log(Level.WARNING, "cannot access {0}", resourceName, ioex); + if (error) + throw new ServiceConfigurationError("Failed to access + " + + resourceName, ioex); + else return Collections.EMPTY_LIST.iterator(); } - return new ServiceIterator(spi, urls, loader, + return new ServiceIterator(spi, urls, loader, error, AccessController.getContext()); } @@ -342,6 +391,11 @@ */ private Object nextProvider; + /** + * True if a {@link ServiceConfigurationError} should be thrown + * when an error occurs, instead of it merely being logged. + */ + private boolean error; /** * Constructs an Iterator that loads and initializes services on @@ -359,16 +413,21 @@ * @param loader the ClassLoader that gets used for loading * service providers. * + * @param error true if a {@link ServiceConfigurationError} + * should be thrown when an error occurs, rather + * than it merely being logged. + * * @param securityContext the security context to use when loading * and initializing service providers. */ ServiceIterator(Class spi, Enumeration urls, ClassLoader loader, - AccessControlContext securityContext) + boolean error, AccessControlContext securityContext) { this.spi = spi; this.urls = urls; this.loader = loader; this.securityContext = securityContext; + this.error = error; this.nextProvider = loadNextServiceProvider(); } @@ -426,6 +485,9 @@ log(Level.WARNING, "IOException upon reading {0}", currentURL, readProblem); line = null; + if (error) + throw new ServiceConfigurationError("Error reading " + + currentURL, readProblem); } /* When we are at the end of one list of services, @@ -477,6 +539,13 @@ log(Level.WARNING, msg, new Object[] { line, spi.getName(), currentURL }, ex); + if (error) + throw new ServiceConfigurationError("Cannot load service "+ + "provider class " + + line + " specified by "+ + "\"META-INF/services/"+ + spi.getName() + "\" in "+ + currentURL, ex); continue; } } @@ -497,6 +566,9 @@ catch (Exception ex) { log(Level.WARNING, "cannot close {0}", currentURL, ex); + if (error) + throw new ServiceConfigurationError("Cannot close " + + currentURL, ex); } reader = null; currentURL = null; @@ -515,6 +587,9 @@ catch (Exception ex) { log(Level.WARNING, "cannot open {0}", currentURL, ex); + if (error) + throw new ServiceConfigurationError("Cannot open " + + currentURL, ex); } } while (reader == null); Modified: trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -98,8 +98,13 @@ */ public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2); - /* Indices 3 and 4 reserved for future use by SSL components. */ + /** + * Trace running of delegated tasks. + */ + public static final Component SSL_DELEGATED_TASK = new Component ("SSL DELEGATED TASK", 3); + /* Index 4 reserved for future use by SSL components. */ + /** * Trace the operation of cryptographic primitives. */ Modified: trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -42,11 +42,12 @@ import java.security.AccessController; import java.util.StringTokenizer; +import java.util.logging.Level; import java.util.logging.Logger; -public final class SystemLogger +public final class SystemLogger extends Logger { - public static final Logger SYSTEM = Logger.getLogger ("gnu.classpath"); + public static final SystemLogger SYSTEM = new SystemLogger(); static { @@ -62,12 +63,40 @@ Component c = Component.forName (tok.nextToken ()); if (c != null) PreciseFilter.GLOBAL.enable (c); - SYSTEM.log (java.util.logging.Level.INFO, "enabled: {0}", c); + SYSTEM.log (Level.INFO, "enabled: {0}", c); } } + } - java.util.logging.Handler[] h = SYSTEM.getHandlers (); - for (int i = 0; i < h.length; i++) - System.out.println (h[i]); + /** + * Fetch the system logger instance. The logger returned is meant for debug + * and diagnostic logging for Classpath internals. + * + * @return The system logger. + */ + public static SystemLogger getSystemLogger() + { + // XXX Check some permission here? + return SYSTEM; } + + /** + * Keep only one instance of the system logger. + */ + private SystemLogger() + { + super("gnu.classpath", null); + } + + /** + * Variable-arguments log method. + * + * @param level The level to log to. + * @param format The format string. + * @param args The arguments. + */ + public void logv(Level level, String format, Object... args) + { + log(level, format, args); + } } Modified: trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* AWTUtilities.java -- Common utility methods for AWT and Swing. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,6 +47,7 @@ import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.AbstractSequentialList; import java.util.List; @@ -694,4 +695,204 @@ { return java.awt.EventQueue.isDispatchThread(); } + + /** + * Returns whether the specified key code is valid. + */ + public static boolean isValidKey(int keyCode) + { + switch (keyCode) + { + case KeyEvent.VK_ENTER: + case KeyEvent.VK_BACK_SPACE: + case KeyEvent.VK_TAB: + case KeyEvent.VK_CANCEL: + case KeyEvent.VK_CLEAR: + case KeyEvent.VK_SHIFT: + case KeyEvent.VK_CONTROL: + case KeyEvent.VK_ALT: + case KeyEvent.VK_PAUSE: + case KeyEvent.VK_CAPS_LOCK: + case KeyEvent.VK_ESCAPE: + case KeyEvent.VK_SPACE: + case KeyEvent.VK_PAGE_UP: + case KeyEvent.VK_PAGE_DOWN: + case KeyEvent.VK_END: + case KeyEvent.VK_HOME: + case KeyEvent.VK_LEFT: + case KeyEvent.VK_UP: + case KeyEvent.VK_RIGHT: + case KeyEvent.VK_DOWN: + case KeyEvent.VK_COMMA: + case KeyEvent.VK_MINUS: + case KeyEvent.VK_PERIOD: + case KeyEvent.VK_SLASH: + case KeyEvent.VK_0: + case KeyEvent.VK_1: + case KeyEvent.VK_2: + case KeyEvent.VK_3: + case KeyEvent.VK_4: + case KeyEvent.VK_5: + case KeyEvent.VK_6: + case KeyEvent.VK_7: + case KeyEvent.VK_8: + case KeyEvent.VK_9: + case KeyEvent.VK_SEMICOLON: + case KeyEvent.VK_EQUALS: + case KeyEvent.VK_A: + case KeyEvent.VK_B: + case KeyEvent.VK_C: + case KeyEvent.VK_D: + case KeyEvent.VK_E: + case KeyEvent.VK_F: + case KeyEvent.VK_G: + case KeyEvent.VK_H: + case KeyEvent.VK_I: + case KeyEvent.VK_J: + case KeyEvent.VK_K: + case KeyEvent.VK_L: + case KeyEvent.VK_M: + case KeyEvent.VK_N: + case KeyEvent.VK_O: + case KeyEvent.VK_P: + case KeyEvent.VK_Q: + case KeyEvent.VK_R: + case KeyEvent.VK_S: + case KeyEvent.VK_T: + case KeyEvent.VK_U: + case KeyEvent.VK_V: + case KeyEvent.VK_W: + case KeyEvent.VK_X: + case KeyEvent.VK_Y: + case KeyEvent.VK_Z: + case KeyEvent.VK_OPEN_BRACKET: + case KeyEvent.VK_BACK_SLASH: + case KeyEvent.VK_CLOSE_BRACKET: + case KeyEvent.VK_NUMPAD0: + case KeyEvent.VK_NUMPAD1: + case KeyEvent.VK_NUMPAD2: + case KeyEvent.VK_NUMPAD3: + case KeyEvent.VK_NUMPAD4: + case KeyEvent.VK_NUMPAD5: + case KeyEvent.VK_NUMPAD6: + case KeyEvent.VK_NUMPAD7: + case KeyEvent.VK_NUMPAD8: + case KeyEvent.VK_NUMPAD9: + case KeyEvent.VK_MULTIPLY: + case KeyEvent.VK_ADD: + case KeyEvent.VK_SEPARATOR: + case KeyEvent.VK_SUBTRACT: + case KeyEvent.VK_DECIMAL: + case KeyEvent.VK_DIVIDE: + case KeyEvent.VK_DELETE: + case KeyEvent.VK_NUM_LOCK: + case KeyEvent.VK_SCROLL_LOCK: + case KeyEvent.VK_F1: + case KeyEvent.VK_F2: + case KeyEvent.VK_F3: + case KeyEvent.VK_F4: + case KeyEvent.VK_F5: + case KeyEvent.VK_F6: + case KeyEvent.VK_F7: + case KeyEvent.VK_F8: + case KeyEvent.VK_F9: + case KeyEvent.VK_F10: + case KeyEvent.VK_F11: + case KeyEvent.VK_F12: + case KeyEvent.VK_F13: + case KeyEvent.VK_F14: + case KeyEvent.VK_F15: + case KeyEvent.VK_F16: + case KeyEvent.VK_F17: + case KeyEvent.VK_F18: + case KeyEvent.VK_F19: + case KeyEvent.VK_F20: + case KeyEvent.VK_F21: + case KeyEvent.VK_F22: + case KeyEvent.VK_F23: + case KeyEvent.VK_F24: + case KeyEvent.VK_PRINTSCREEN: + case KeyEvent.VK_INSERT: + case KeyEvent.VK_HELP: + case KeyEvent.VK_META: + case KeyEvent.VK_BACK_QUOTE: + case KeyEvent.VK_QUOTE: + case KeyEvent.VK_KP_UP: + case KeyEvent.VK_KP_DOWN: + case KeyEvent.VK_KP_LEFT: + case KeyEvent.VK_KP_RIGHT: + case KeyEvent.VK_DEAD_GRAVE: + case KeyEvent.VK_DEAD_ACUTE: + case KeyEvent.VK_DEAD_CIRCUMFLEX: + case KeyEvent.VK_DEAD_TILDE: + case KeyEvent.VK_DEAD_MACRON: + case KeyEvent.VK_DEAD_BREVE: + case KeyEvent.VK_DEAD_ABOVEDOT: + case KeyEvent.VK_DEAD_DIAERESIS: + case KeyEvent.VK_DEAD_ABOVERING: + case KeyEvent.VK_DEAD_DOUBLEACUTE: + case KeyEvent.VK_DEAD_CARON: + case KeyEvent.VK_DEAD_CEDILLA: + case KeyEvent.VK_DEAD_OGONEK: + case KeyEvent.VK_DEAD_IOTA: + case KeyEvent.VK_DEAD_VOICED_SOUND: + case KeyEvent.VK_DEAD_SEMIVOICED_SOUND: + case KeyEvent.VK_AMPERSAND: + case KeyEvent.VK_ASTERISK: + case KeyEvent.VK_QUOTEDBL: + case KeyEvent.VK_LESS: + case KeyEvent.VK_GREATER: + case KeyEvent.VK_BRACELEFT: + case KeyEvent.VK_BRACERIGHT: + case KeyEvent.VK_AT: + case KeyEvent.VK_COLON: + case KeyEvent.VK_CIRCUMFLEX: + case KeyEvent.VK_DOLLAR: + case KeyEvent.VK_EURO_SIGN: + case KeyEvent.VK_EXCLAMATION_MARK: + case KeyEvent.VK_INVERTED_EXCLAMATION_MARK: + case KeyEvent.VK_LEFT_PARENTHESIS: + case KeyEvent.VK_NUMBER_SIGN: + case KeyEvent.VK_PLUS: + case KeyEvent.VK_RIGHT_PARENTHESIS: + case KeyEvent.VK_UNDERSCORE: + case KeyEvent.VK_FINAL: + case KeyEvent.VK_CONVERT: + case KeyEvent.VK_NONCONVERT: + case KeyEvent.VK_ACCEPT: + case KeyEvent.VK_MODECHANGE: + case KeyEvent.VK_KANA: + case KeyEvent.VK_KANJI: + case KeyEvent.VK_ALPHANUMERIC: + case KeyEvent.VK_KATAKANA: + case KeyEvent.VK_HIRAGANA: + case KeyEvent.VK_FULL_WIDTH: + case KeyEvent.VK_HALF_WIDTH: + case KeyEvent.VK_ROMAN_CHARACTERS: + case KeyEvent.VK_ALL_CANDIDATES: + case KeyEvent.VK_PREVIOUS_CANDIDATE: + case KeyEvent.VK_CODE_INPUT: + case KeyEvent.VK_JAPANESE_KATAKANA: + case KeyEvent.VK_JAPANESE_HIRAGANA: + case KeyEvent.VK_JAPANESE_ROMAN: + case KeyEvent.VK_KANA_LOCK: + case KeyEvent.VK_INPUT_METHOD_ON_OFF: + case KeyEvent.VK_CUT: + case KeyEvent.VK_COPY: + case KeyEvent.VK_PASTE: + case KeyEvent.VK_UNDO: + case KeyEvent.VK_AGAIN: + case KeyEvent.VK_FIND: + case KeyEvent.VK_PROPS: + case KeyEvent.VK_STOP: + case KeyEvent.VK_COMPOSE: + case KeyEvent.VK_ALT_GRAPH: + case KeyEvent.VK_BEGIN: + case KeyEvent.VK_CONTEXT_MENU: + case KeyEvent.VK_WINDOWS: + return true; + default: + return false; + } + } } Modified: trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -153,7 +153,7 @@ writer = new StAXWriter(os); root = new Root(); - final ScannerState start = current = new GenericScannerState(root);; + final ScannerState start = current = new GenericScannerState(root); ScannerState conf; // Use the ReportingScannerState to debug serialization issues. Modified: trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -55,105 +55,44 @@ public class LocaleHelper { /** - * This method is used by the localized name lookup methods to retrieve - * the localized name of a particular piece of locale data. - * If the display name can not be localized to the supplied - * locale, it will fall back on other output in the following order: - * - * <ul> - * <li>the localized name in the default locale</li> - * <li>the localized name in English (optional)</li> - * <li>the localized name in the root locale bundle (optional)</li> - * <li>the localized input string</li> - * </ul> * <p> - * If the supplied key is merely the empty string, then the empty string is - * returned. + * This method is used by the localized name lookup methods to + * retrieve the next locale to try. The next locale is derived + * from the supplied locale by applying the first applicable + * rule from the following: * </p> + * <ol> + * <li>If the variant contains a <code>'_'</code>, then + * this and everything following it is trimmed.</li> + * <li>If the variant is non-empty, it is converted to + * an empty string.</li> + * <li>If the country is non-empty, it is converted to + * an empty string.</li> + * <li>If the language is non-empty, it is converted to + * an empty string (forming {@link java.util.Locale#ROOT})</li> + * </ol> + * <p> + * The base fallback locale is {@link java.util.Locale#ROOT}. + * </p> * - * @param inLocale the locale to use for formatting the display string. - * @param key the locale data used as a key to the localized lookup tables. - * @param name the name of the hashtable containing the localized data. - * @param checkEnglish true if the method should fall back on data - * from the English locale. - * @param checkRoot true if the method should fall back on data from the - * unlocalized root locale. - * @return a <code>String</code>, hopefully containing the localized - * variant of the input data. - * @throws NullPointerException if <code>inLocale</code> is null. + * @param locale the locale for which a localized piece of + * data could not be obtained. + * @return the next fallback locale to try. */ - public static String getLocalizedString(Locale inLocale, String key, - String name, boolean checkEnglish, - boolean checkRoot) - { - String localizedString; - String property; - - if (key.equals("")) - return ""; - property = name + "." + key; - /* Localize to inLocale */ - try + public static Locale getFallbackLocale(Locale locale) { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - inLocale).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - /* Localize to default locale */ - if (localizedString == null) - { - try - { - ResourceBundle bundle; - - bundle = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation"); - localizedString = bundle.getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Localize to English */ - if (localizedString == null && checkEnglish) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - Locale.ENGLISH).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return unlocalized version */ - if (localizedString == null && checkRoot) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - new Locale("","","") - ).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return original input string */ - if (localizedString == null) - { - localizedString = key; - } - return localizedString; + String language = locale.getLanguage(); + String country = locale.getCountry(); + String variant = locale.getVariant(); + int uscore = variant.indexOf('_'); + if (uscore != -1) + return new Locale(language, country, + variant.substring(0, uscore)); + if (!variant.isEmpty()) + return new Locale(language, country, ""); + if (!country.isEmpty()) + return new Locale(language, "", ""); + return Locale.ROOT; } /** Modified: trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* gnu.java.util.DoubleEnumeration - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,7 +63,7 @@ * @author Jochen Hoenicke * @author Mark Wielaard (ma...@kl...) */ -public class DoubleEnumeration implements Enumeration +public class DoubleEnumeration<T> implements Enumeration<T> { /** * This is true as long as one of the enumerations has more @@ -82,17 +82,17 @@ /** * The first enumeration. */ - private Enumeration e1; + private Enumeration<T> e1; /** * The second enumeration. */ - private Enumeration e2; + private Enumeration<T> 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) + public DoubleEnumeration(Enumeration<T> e1, Enumeration<T> e2) { this.e1 = e1; this.e2 = e2; @@ -126,7 +126,7 @@ * element of the second enumeration. If both enumeration don't have * any elements it throws a <code>NoSuchElementException</code>. */ - public Object nextElement() + public T nextElement() { if (!hasMoreElements()) throw new NoSuchElementException(); Modified: trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -53,7 +53,7 @@ // This is a queue of events to dispatch. This thread waits on // the queue and when notified will remove events until the queue // is empty. - private static final ArrayList queue = new ArrayList(); + private static final ArrayList<Runnable> queue = new ArrayList<Runnable>(); // FIXME: this thread probably ought to go in some classpath-internal // ThreadGroup. But we don't have that yet. @@ -81,7 +81,7 @@ // Ignore. } } - r = (Runnable) queue.remove(0); + r = queue.remove(0); } // Invoke outside the synchronization, so that // we aren't blocking other threads from posting events. Modified: trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -52,7 +52,7 @@ private final boolean isUser; /** Contains all the preference entries of this node. */ - private HashMap entries = new HashMap(); + private HashMap<String, String> entries = new HashMap<String, String>(); /** * Creates a new preferences node with the given name and parent. @@ -98,7 +98,7 @@ * this node. */ protected String[] keysSpi() throws BackingStoreException { - return (String[]) entries.keySet().toArray(new String[entries.size()]); + return entries.keySet().toArray(new String[entries.size()]); } /** @@ -106,7 +106,7 @@ * null when the key has not been set. */ protected String getSpi(String key) { - return (String) entries.get(key); + return entries.get(key); } /** Modified: trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -61,7 +61,9 @@ { super( type, data, crc ); int i = 0; - while( data[i++] != 0 ); + while( data[i++] != 0 ) + ; + try { name = new String(data, 0, i, "8859_1"); Modified: trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* UtilDelegateImpl.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,8 @@ package gnu.javax.rmi.CORBA; +import gnu.classpath.VMStackWalker; + import gnu.CORBA.Minor; import gnu.CORBA.ObjectCreator; import gnu.CORBA.Poa.ORB_1_4; @@ -70,6 +72,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.net.MalformedURLException; import java.rmi.AccessException; import java.rmi.MarshalException; import java.rmi.NoSuchObjectException; @@ -374,37 +377,24 @@ throws ClassNotFoundException { if (loader == null) - loader = Thread.currentThread().getContextClassLoader(); + loader = VMStackWalker.firstNonNullClassLoader(); String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly"); boolean useCodebaseOnly = p_useCodebaseOnly != null && p_useCodebaseOnly.trim().equalsIgnoreCase("true"); - try - { - if (remoteCodebase != null && !useCodebaseOnly) - return RMIClassLoader.loadClass(remoteCodebase, className); - } - catch (Exception e) - { - // This failed but try others. - } + if (useCodebaseOnly) + remoteCodebase = null; try { - if (remoteCodebase == null || useCodebaseOnly) - return RMIClassLoader.loadClass(remoteCodebase, className); + return RMIClassLoader.loadClass(remoteCodebase, className, loader); } - catch (Exception e) + catch (MalformedURLException x) { - // This failed but try others. + throw new ClassNotFoundException(className, x); } - - if (loader != null) - return Class.forName(className, true, loader); - - throw new ClassNotFoundException(className + " at " + remoteCodebase); } /** Modified: trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -122,7 +122,9 @@ initParser(r); while (parseAppOrOtherEntry()) - ; // do nothing + { + /* do nothing */ + } } private void initParser(Reader r) throws IOException @@ -157,7 +159,9 @@ List lmis = new ArrayList(); while (parseACE(lmis)) - ; // do nothing + { + /* do nothing */ + } c = cft.nextToken(); if (c != '}') Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -308,7 +308,9 @@ { // FIXME: Handle block and ATKEYWORD. boolean success = parseAny(s); - while (parseAny(s)); + while (parseAny(s)) + ; + return success; } @@ -329,7 +331,8 @@ boolean ret = parseAny(sel); if (ret) { - while (parseAny(sel)); + while (parseAny(sel)) + ; } return ret; } Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -390,7 +390,6 @@ allowed.add(allowed_values [ i ]); } } - ; AttributeList attr = new AttributeList(name, type, modifier, default_value, allowed, null); Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -56,6 +56,7 @@ import java.util.Vector; import javax.swing.text.ChangedCharSetException; +import javax.swing.text.SimpleAttributeSet; import javax.swing.text.html.HTML; import javax.swing.text.html.parser.AttributeList; import javax.swing.text.html.parser.DTD; @@ -250,9 +251,9 @@ * Get the attributes of the current tag. * @return The attribute set, representing the attributes of the current tag. */ - public htmlAttributeSet getAttributes() + public SimpleAttributeSet getAttributes() { - return attributes; + return new SimpleAttributeSet(attributes); } /** @@ -497,6 +498,9 @@ mustBe(t.kind); } hTag = new Token(start, last); + + // Consume any whitespace immediately following a comment. + optional(WS); handleComment(); } @@ -579,6 +583,8 @@ ); } } + // Consume any whitespace that follows the Sgml insertion. + optional(WS); } /** @@ -658,7 +664,10 @@ else text = textProcessor.preprocess(buffer); - if (text != null && text.length > 0) + if (text != null && text.length > 0 + // According to the specs we need to discard whitespace immediately + // before a closing tag. + && (text.length > 1 || text[0] != ' ' || ! TAG_CLOSE.matches(this))) { TagElement pcdata = new TagElement(dtd.getElement("#pcdata")); attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; @@ -889,6 +898,8 @@ protected void parseDocument() throws ParseException { + // Read up any initial whitespace. + optional(WS); while (getTokenAhead().kind != EOF) { advanced = false; @@ -979,13 +990,15 @@ + next.getImage() + "'"); attrValue = value.getImage(); } - else if (next.kind == SLASH) - // The slash in this context is treated as the ordinary - // character, not as a token. The slash may be part of + else if (next.kind == SLASH || next.kind == OTHER) + // The slash and other characters (like %) in this context is + // treated as the ordinary + // character, not as a token. The character may be part of // the unquoted URL. { StringBuffer image = new StringBuffer(value.getImage()); - while (next.kind == NUMTOKEN || next.kind == SLASH) + while (next.kind == NUMTOKEN || next.kind == SLASH + || next.kind == OTHER) { image.append(getNextToken().getImage()); next = getTokenAhead(); @@ -1177,6 +1190,13 @@ { validator.validateTag(tag, attributes); handleEmptyTag(tag); + HTML.Tag h = tag.getHTMLTag(); + // When a block tag is closed, consume whitespace that follows after + // it. + // For some unknown reason a FRAME tag is not treated as block element. + // However in this case it should be treated as such. + if (isBlock(h)) + optional(WS); } catch (ChangedCharSetException ex) { @@ -1192,7 +1212,7 @@ */ private void _handleEndTag(TagElement tag) { - validator.closeTag(tag); + if (validator.closeTag(tag)) _handleEndTag_remaining(tag); } @@ -1213,6 +1233,11 @@ if (preformatted < 0) preformatted = 0; + // When a block tag is closed, consume whitespace that follows after + // it. + if (isBlock(h)) + optional(WS); + if (h == HTML.Tag.TITLE) { titleOpen = false; @@ -1239,6 +1264,9 @@ HTML.Tag h = tag.getHTMLTag(); + if (isBlock(h)) + optional(WS); + if (h.isPreformatted()) preformatted++; @@ -1354,7 +1382,7 @@ if (c == '\r') buffer.append(' '); // CR replaced by space else if (c == '\n') - ; // LF ignored + { /* LF ignored */ } else if (c == '\t') buffer.append(' '); // Tab replaced by space else @@ -1418,8 +1446,6 @@ hTag = new Token(start, next); - attributes.setResolveParent(defaulter.getDefaultParameters(name.getImage())); - if (!end) { // The tag body contains errors. If additionally the tag @@ -1457,9 +1483,14 @@ if (te.getElement().type == DTDConstants.EMPTY) _handleEmptyTag(te); else + { + // According to the specs we need to consume whitespace following + // immediately after a opening tag. + optional(WS); _handleStartTag(te); } } + } /** * This should fire additional actions in response to the @@ -1483,4 +1514,19 @@ { error("Whitespace here is not permitted"); } + + /** + * Returns true when the specified tag should be considered a block tag + * wrt whitespace handling. We need this special handling, since there + * are a couple of tags that we must treat as block tags but which aren't + * officially block tags. + * + * @param tag the tag to check + * @return true when the specified tag should be considered a block tag + * wrt whitespace handling + */ + private boolean isBlock(HTML.Tag tag) + { + return tag.isBlock() || tag == HTML.Tag.STYLE || tag == HTML.Tag.FRAME; + } } Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -209,6 +209,17 @@ } ); + /** + * Ordinary HTML tag closing pattern. + */ + public static final pattern TAG_CLOSE = + new pattern(new node[] + { + new node(BEGIN), new node(WS, true), new node(SLASH), + new node(WS, true), new node(NUMTOKEN) + } + ); + /* Special tokens */ /** Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -42,17 +42,17 @@ /** * Pre - processes text in text parts of the html document. - * Not thread - safe. + * * @author Audrius Meskauskas, Lithuania (Aud...@Bi...) */ 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. + * 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 a_text A text to pre-process. */ public char[] preprocess(StringBuffer a_text) { @@ -64,18 +64,15 @@ int a = 0; int b = text.length - 1; - try - { - while (Constants.bWHITESPACE.get(text [ a ])) + // Remove leading/trailing whitespace, leaving at most one character + int len = text.length; + while (a + 1 < len && Constants.bWHITESPACE.get(text[a]) + && Constants.bWHITESPACE.get(text[a + 1])) a++; - while (Constants.bWHITESPACE.get(text [ b ])) + + while (b > a && Constants.bWHITESPACE.get(text[b]) + && Constants.bWHITESPACE.get(text[b - 1])) b--; - } - catch (ArrayIndexOutOfBoundsException sx) - { - // A text fragment, consisting from line breaks only. - return null; - } a_text.setLength(0); @@ -83,10 +80,9 @@ boolean spaceNow; char c; - chars: - for (int i = a; i <= b; i++) + chars: for (int i = a; i <= b; i++) { - c = text [ i ]; + c = text[i]; spaceNow = Constants.bWHITESPACE.get(c); if (spacesWere && spaceNow) continue chars; Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -316,7 +316,7 @@ private void mutating(String oldValue, String newValue, short why) { - if (!reportMutations || parent == null) + if (!reportMutations || parent == null || equal(newValue, oldValue)) { return; } Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -668,6 +668,7 @@ { insertionEvent(null, child); } + length++; } return child; @@ -1561,7 +1562,7 @@ // 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. - current = parent; + current = (parent == null) ? this : parent; if (current.depth >= ANCESTORS_INIT) { DomNode[] newants = new DomNode[current.depth + 1]; Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -43,6 +43,7 @@ import java.util.List; import javax.xml.XMLConstants; import org.w3c.dom.Attr; +import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; @@ -72,7 +73,7 @@ * * @author <a href='mailto:do...@gn...'>Chris Burdess</a> */ -class SAXEventSink +public class SAXEventSink implements ContentHandler, LexicalHandler, DTDHandler, DeclHandler { @@ -110,6 +111,11 @@ interrupted = true; } + protected Document getDocument() + { + return doc; + } + // -- ContentHandler2 -- public void setDocumentLocator(Locator locator) Modified: trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -365,7 +365,7 @@ throws SAXException { SAXParseException e; - ErrorHandler errHandler = consumer.getErrorHandler ();; + ErrorHandler errHandler = consumer.getErrorHandler (); if (locator == null) e = new SAXParseException (message, null, null, -1, -1, x); Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1021,9 +1021,18 @@ SAXParser parser = new SAXParser(validating, namespaceAware, xIncludeAware); InputSource input = new InputSource(args[pos]); + java.io.FileReader fr = new java.io.FileReader(args[pos]); + input.setCharacterStream(fr); + try + { XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.parse(input); + } + finally + { + fr.close(); + } pos++; } } Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -664,12 +664,10 @@ public void writeDTD(String dtd) throws XMLStreamException { - // Really thoroughly pointless method... try { - if (!isName(dtd)) - throw new IllegalArgumentException("illegal Name: " + dtd); - + // XXX: Should we parse the doctypedecl at this point to ensure + // wellformedness? writer.write("<!DOCTYPE "); writer.write(dtd); writer.write('>'); Added: trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -0,0 +1,97 @@ +/* SAXTemplatesHandler.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but 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.Templates; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.TemplatesHandler; +import org.w3c.dom.Document; +import gnu.xml.dom.ls.SAXEventSink; + +/** + * A content handler that acts as a sink for SAX parse events, + * constructing an XSL stylesheet. + * Internally, this class simply creates a DOM tree from the events, + * and then parses the DOM into a Templates object. + * + * @author Chris Burdess (do...@gn...) + */ +class SAXTemplatesHandler + extends SAXEventSink + implements TemplatesHandler +{ + + final TransformerFactoryImpl factory; + String systemId; + + SAXTemplatesHandler(TransformerFactoryImpl factory) + { + this.factory = factory; + } + + public String getSystemId() + { + return systemId; + } + + public void setSystemId(String systemId) + { + this.systemId = systemId; + } + + public Templates getTemplates() + { + Document doc = getDocument(); + if (doc == null) + throw new IllegalStateException("Parsing of stylesheet incomplete"); + DOMSource ds = new DOMSource(doc, systemId); + try + { + return factory.newTemplates(ds); + } + catch (TransformerConfigurationException e) + { + String msg = "Unable to construct templates from this event stream"; + IllegalStateException e2 = new IllegalStateException(msg); + e2.initCause(e); + throw e2; + } + } + +} Added: trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -0,0 +1,111 @@ +/* SAXTransformerHandler.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but 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.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.TransformerHandler; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import gnu.xml.dom.ls.SAXEventSink; + +/** + * A SAX event sink that processes an XML source represented as a stream of + * SAX events into a result tree. + * This works by simply buffering all the events into a DOM tree and then + * using this DOM tree as the source of the transformation. + * + * @author Chris Burdess (do...@gn...) + */ +class SAXTransformerHandler + extends SAXEventSink + implements TransformerHandler +{ + + final TransformerFactoryImpl factory; + final Transformer transformer; + String systemId; + Result result; + + SAXTransformerHandler(TransformerFactoryImpl factory, Transformer transformer) + { + this.factory = factory; + this.transformer = transformer; + } + + public String getSystemId() + { + return systemId; + } + + public void setSystemId(String systemId) + { + this.systemId = systemId; + } + + public Transformer getTransformer() + { + return transformer; + } + + public void setResult(Result result) + { + this.result = result; + } + + public void endDocument() + throws SAXException + { + super.endDocument(); + try + { + Document doc = getDocument(); + DOMSource ds = new DOMSource(doc, systemId); + transformer.transform(ds, result); + } + catch (TransformerException e) + { + SAXException e2 = new SAXException(e.getMessage()); + e2.initCause(e); + throw e2; + } + } + +} Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -324,7 +324,8 @@ break; case Node.TEXT_NODE: value = node.getNodeValue(); - if (!"yes".equals(node.getUserData("disable-output-escaping"))) + if (!"yes".equals(node.getUserData("disable-output-escaping")) && + mode != Stylesheet.OUTPUT_TEXT) value = encode(value, false, false); out.write(encodeText(value)); break; Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -60,11 +60,15 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TemplatesHandler; +import javax.xml.transform.sax.TransformerHandler; 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 org.xml.sax.XMLFilter; import gnu.xml.dom.DomDocument; /** @@ -73,7 +77,7 @@ * @author <a href='mailto:do...@gn...'>Chris Burdess</a> */ public class TransformerFactoryImpl - extends TransformerFactory + extends SAXTransformerFactory { final XPathFactory xpathFactory; @@ -316,7 +320,8 @@ StreamSource.FEATURE.equals(name) || StreamResult.FEATURE.equals(name) || DOMSource.FEATURE.equals(name) || - DOMResult.FEATURE.equals(name)) + DOMResult.FEATURE.equals(name) || + SAXTransformerFactory.FEATURE.equals(name)) { return true; } @@ -346,6 +351,49 @@ return userListener; } + // -- SAXTransformerFactory -- + + public TemplatesHandler newTemplatesHandler() + throws TransformerConfigurationException + { + return new SAXTemplatesHandler(this); + } + + public TransformerHandler newTransformerHandler() + throws TransformerConfigurationException + { + Transformer transformer = newTransformer(); + return new SAXTransformerHandler(this, transformer); + } + + public TransformerHandler newTransformerHandler(Source source) + throws TransformerConfigurationException + { + Transformer transformer = newTransformer(source); + return new SAXTransformerHandler(this, transformer); + } + + public TransformerHandler newTransformerHandler(Templates templates) + throws TransformerConfigurationException + { + Transformer transformer = templates.newTransformer(); + return new SAXTransformerHandler(this, transformer); + } + + public XMLFilter newXMLFilter(Source source) + throws TransformerConfigurationException + { + throw new UnsupportedOperationException(); + } + + public XMLFilter newXMLFilter(Templates templates) + throws TransformerConfigurationException + { + throw new UnsupportedOperationException(); + } + + // -- SAXTransformerFactory end -- + /** * Syntax: TransformerFactoryImpl [<stylesheet> [<input> [<output>]]] */ Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java 2007-01-07 08:31:59 UT... [truncated message content] |