
libjava/ChangeLog: 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * sources.am, Makfile.in: Regenerate. 2008-10-17 Matthias Klose <doko@ubuntu.com> * configure.ac: Fix bashisms. * configure: Regenerate. 2008-10-15 Matthias Klose <doko@ubuntu.com> * configure.ac: Disable build of gjdoc, if configured without --with-antlr-jar or if no antlr.jar found. * configure: Regenerate. 2008-10-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure.ac, * classpath/m4/ac_prog_antlr.m4, * classpath/m4/ac_prog_java.m4, * classpath/tools/Makefile.am: Ported --regen-gjdoc-parser patch and cantlr support from GNU Classpath. 2008-10-06 Andrew Haley <aph@redhat.com> * java/lang/Thread.java (Thread): Always create the ThreadLocalMap when creating a thread. (getThreadLocals) Don't lazily create the ThreadLocalMap. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/java/lang/ThreadLocalMap.java, * java/lang/ThreadLocalMap$Entry.h, * java/lang/ThreadLocalMap.h, * lib/java/lang/ThreadLocalMap.class, * lib/java/lang/ThreadLocalMap$Entry.class: Add the new files for the ThreadLocal patch. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/ChangeLog, * classpath/java/lang/InheritableThreadLocal.java, * classpath/java/lang/Thread.java, * classpath/java/lang/ThreadLocal.java: Merge Daniel Frampton's ThreadLocal patch. * gcj/javaprims.h: Updated. * java/lang/Thread.h: Regenerated. * java/lang/Thread.java: Replace WeakIdentityHashMap with ThreadLocalMap. (getThreadLocals()): Likewise. * java/lang/ThreadLocal.h: Regenerated. * java/lang/ThreadLocal.java: (computeNextHash()): New method. (ThreadLocal()): Initialise fastHash. (internalGet()): Updated to match Classpath's get(). (internalSet(Object)): Likewise for set(Object). (internalRemove()): Likewise for remove(). 2008-09-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure, * classpath/configure.ac: Resynchronise with Classpath's configure. * classpath/examples/Makefile.in: Add equivalent support for building as in tools/Makefile.in. * classpath/java/nio/Buffer.java, * classpath/java/nio/ByteBuffer.java, * classpath/java/nio/ByteBufferImpl.java, * classpath/java/nio/CharBuffer.java, * classpath/java/nio/CharBufferImpl.java, * classpath/java/nio/CharSequenceBuffer.java, * classpath/java/nio/CharViewBufferImpl.java, * classpath/java/nio/DirectByteBufferImpl.java, * classpath/java/nio/DoubleBuffer.java, * classpath/java/nio/DoubleBufferImpl.java, * classpath/java/nio/DoubleViewBufferImpl.java, * classpath/java/nio/FloatBuffer.java, * classpath/java/nio/FloatBufferImpl.java, * classpath/java/nio/FloatViewBufferImpl.java, * classpath/java/nio/IntBuffer.java, * classpath/java/nio/IntBufferImpl.java, * classpath/java/nio/IntViewBufferImpl.java, * classpath/java/nio/LongBuffer.java, * classpath/java/nio/LongBufferImpl.java, * classpath/java/nio/LongViewBufferImpl.java, * classpath/java/nio/MappedByteBuffer.java, * classpath/java/nio/MappedByteBufferImpl.java, * classpath/java/nio/ShortBuffer.java, * classpath/java/nio/ShortBufferImpl.java, * classpath/java/nio/ShortViewBufferImpl.java: Replace use of gnu.classpath.Pointer with gnu.gcj.RawData, and fix some formatting issues. * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.txt: Regenerated (later version of antlr). * java/nio/Buffer.h: Regenerated. * java/nio/Buffer.java: Ported changes from Classpath. * java/nio/ByteBuffer.h, * java/nio/CharBuffer.h: Regenerated. * java/nio/DirectByteBufferImpl.java: Ported changes from Classpath. * java/nio/DoubleBuffer.h, * java/nio/FloatBuffer.h, * java/nio/IntBuffer.h, * java/nio/LongBuffer.h, * java/nio/MappedByteBuffer.h, * java/nio/MappedByteBufferImpl.h: Regenerated. * java/nio/MappedByteBufferImpl.java: Ported changes from Classpath. * java/nio/ShortBuffer.h: Regenerated. 2008-09-24 Matthias Klose <doko@ubuntu.com> * configure.ac: Search for antlr.jar, if not configured. * configure: Regenerate. 2008-09-24 Matthias Klose <doko@ubuntu.com> * Makefile.am: Build a gjdoc binary, if enabled. * configure.ac: Add options --disable-gjdoc, --with-antlr-jar=file. * Makefile.in, */Makefile.in, configure: Regenerate. 2008-09-22 Andrew Haley <aph@redhat.com> * java/lang/String.java (toString(char[], int, int)): New method. 2008-09-14 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080914). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --disable-gjdoc to classpath. * sources.am: Regenerated. * HACKING: Mention to build gjdoc in maintainer builds. * gnu/classpath/Configuration.java: Update classpath version. * gcj/javaprims.h: Update. 2008-09-08 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.am: Replace natStringBuffer.cc and natStringBuilder.cc with natAbstractStringBuffer.cc. * Makefile.in: Regenerated. * java/lang/AbstractStringBuffer.java: (append(int)): Made native. (regionMatches(int,String)): Likewise. * java/lang/StringBuffer.h: Regenerated. * java/lang/StringBuffer.java: Remerged with GNU Classpath. * java/lang/StringBuilder.h: Regenerated. * java/lang/StringBuilder.java: Remerged with GNU Classpath. * java/lang/natAbstractStringBuffer.cc: Provide common native methods for StringBuffer and StringBuilder. * java/lang/natStringBuffer.cc, * java/lang/natStringBuilder.cc: Removed. 2008-09-04 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in, * classpath/configure: Regenerated. * gnu/gcj/util/natDebug.cc, * gnu/gcj/xlib/natColormap.cc, * gnu/gcj/xlib/natDisplay.cc, * gnu/gcj/xlib/natDrawable.cc, * gnu/gcj/xlib/natFont.cc, * gnu/gcj/xlib/natWMSizeHints.cc, * gnu/gcj/xlib/natWindow.cc, * gnu/gcj/xlib/natXImage.cc: Add :: prefix to namespaces. * java/io/CharArrayWriter.h, * java/lang/StringBuffer.h: Regenerated using patched gjavah. * java/lang/natStringBuffer.cc: Fix naming of append(jint). * java/sql/Timestamp.h: Regenerated using patched gjavah. * jni.cc: Rename p to functions to match change in GNU Classpath. * scripts/makemake.tcl: Switch gnu.java.math to BC compilation. * sources.am: Regenerated. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated location of Configuration.java. * classpath/lib/gnu/java/locale/LocaleData.class: Regenerated. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated with new Java files. * classpath/configure: Regenerated. * classpath/tools/Makefile.am: Add missing use of GJDOC_EX so --disable-gjdoc works. * classpath/tools/Makefile.in: Regenerated. 2008-08-15 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080811). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --with-fastjar to classpath, substitute new dummy value in classpath/gnu/classpath/Configuration.java.in, pass --disable-gjdoc to classpath. * scripts/makemake.tcl: * sources.am: Regenerated. * java/lang/AbstractStringBuffer.java, gnu/java/lang/VMCPStringBuilder.java: New, copied from classpath, use System instead of VMSystem. * java/lang/StringBuffer.java: Merge from classpath. * java/lang/ClassLoader.java: Merge from classpath. * gcj/javaprims.h: Update class definitions, remove _Jv_jobjectRefType, jobjectRefType definitions. libjava/classpath/ChangeLog.gcj: 2008-10-21 Matthias Klose <doko@ubuntu.com> * classpath/tools/gnu/classpath/tools/gjdoc/expr/Java*: Move from ... * classpath/tools/generated/gnu/classpath/tools/gjdoc/expr/ ... here. * Update .class files. 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Always generate parser in the srcdir. 2008-10-21 Matthias Klose <doko@ubuntu.com> * doc/Makefile.am (MAINTAINERCLEANFILES): Add gjdoc.1. * doc/Makefile.in: Regenerate. 2008-10-20 Matthias Klose <doko@ubuntu.com> * configure.ac: Don't check for working java, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_java.m4: Revert previous change. * m4/ac_prog_javac.m4: Apply it here. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac.m4: Don't check for working javac, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. * Makefile.in, */Makefile.in: Regenerate. 2008-09-30 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for cantlr binary as well. 2008-09-29 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for antlr binary as well. 2008-09-28 Matthias Klose <doko@ubuntu.com> * PR libgcj/37636. Revert: 2008-02-20 Matthias Klose <doko@ubuntu.com> * tools/Makefile.am ($(TOOLS_ZIP)): Revert part of previous change, Do copy resource files in JAVA_MAINTAINER_MODE only. * tools/Makefile.in: Regenerate. 2008-09-14 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac_works.m4, m4/ac_prog_javac.m4, m4/acinclude.m4: Revert local changes. * m4/ac_prog_antlr.m4: Check for an runantlr binary. * tools/Makefile.am, lib/Makefile.am: Revert local changes (JCOMPILER). * tools/Makefile.am: Remove USE_JAVAC_FLAGS, pass ANTLR_JAR in GLIBJ_CLASSPATH. 2008-09-14 Matthias Klose <doko@ubuntu.com> Revert: Daniel Frampton <zyridium at zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-08-15 Matthias Klose <doko@ubuntu.com> * m4/acinclude.m4 (CLASSPATH_JAVAC_MEM_CHECK): Remove unknown args for javac. libjava/classpath/ChangeLog: 2008-10-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr.m4: Remove redundant checks. * tools/Makefile.am: Use gjdoc_gendir when calling antlr. 2008-10-15 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Remove superfluous AC_PROG_JAVA call. 2008-10-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr: Check for cantlr as well. * tools/Makefile.am: Only build GJDoc parser when both CREATE_GJDOC and CREATE_GJDOC_PARSER are on. 2008-10-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Add regen-gjdoc-parser option, and separate antlr tests. * m4/ac_prog_antlr.m4: Turn single test into AC_LIB_ANTLR and AC_PROG_ANTLR. * m4/ac_prog_java.m4: Quote tests. * tools/Makefile.am: Support CREATE_GJDOC_PARSER option. 2008-09-14 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am: Check lib directly as well as glibj.zip for boot classes. * m4/acinclude.m4: Only require the class files to be built to allow the tools and examples to be built, not the installation of glibj.zip. * tools/Makefile.am: Check lib directly as well as glibj.zip for boot classes. 2008-09-13 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am, * lib/Makefile.am: Add GCJ rules. * m4/ac_prog_javac.m4: Check whether JAVAC is gcj. * m4/ac_prog_javac_works.m4: Add GCJ rules. * m4/acinclude.m4: Don't bother checking for -J if using GCJ. * tools/Makefile.am: Add GCJ rules. 2007-08-23 Daniel Frampton <zyridium@zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk> * java/util/zip/ZipEntry.java: Use byte fields instead of integer fields, store the time as well as the DOS time and don't retain a global Calendar instance. (setDOSTime(int)): Set KNOWN_DOSTIME instead of KNOWN_TIME, and unset KNOWN_TIME. (getDOSTime()): Compute DOS time from UNIX time only when needed. (clone()): Provide cloning via the ZipEntry constructor where possible. (setTime(long)): Don't compute DOS time at this point. (getCalendar()): Removed. 2008-09-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/getopt/Parser.java: (setHeader(String)): Make synchronized. (setFooter(String)): Likewise. * tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java, (reset()): Make synchronized. (name(Class)): Likewise. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * gnu/java/nio/charset/ByteDecodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. * gnu/java/nio/charset/ByteEncodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * java/text/DecimalFormat.java: (scanFix): Use 'i + 1' when looking at following character. (scanNegativePattern): Dito. 2008-09-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/javah/ClassWrapper.java: (makeVtable()): Populate methodNameMap. (printMethods(CniPrintStream)): Always use pre-populated methodNameMap for bridge targets. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XImage.java (XImageProducer): remove @Override annotation to allow compilation on javac < 1.6 and ecj < 3.4. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XGraphicsDevice.java (getDisplay): fix to support new Escher API. * gnu/java/awt/peer/x/XImage.java (getSource): method implemented. * gnu/java/awt/peer/x/XImage.java (XImageProducer): implement ImageProducer for getSource. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/BacktrackStack.java, * gnu/java/util/regex/CharIndexed.java, * gnu/java/util/regex/CharIndexedCharArray.java, * gnu/java/util/regex/CharIndexedCharSequence.java, * gnu/java/util/regex/CharIndexedInputStream.java, * gnu/java/util/regex/CharIndexedString.java, * gnu/java/util/regex/CharIndexedStringBuffer.java, * gnu/java/util/regex/RE.java, * gnu/java/util/regex/REException.java, * gnu/java/util/regex/REFilterInputStream.java, * gnu/java/util/regex/REMatch.java, * gnu/java/util/regex/REMatchEnumeration.java, * gnu/java/util/regex/RESyntax.java, * gnu/java/util/regex/REToken.java, * gnu/java/util/regex/RETokenAny.java, * gnu/java/util/regex/RETokenBackRef.java, * gnu/java/util/regex/RETokenChar.java, * gnu/java/util/regex/RETokenEnd.java, * gnu/java/util/regex/RETokenEndOfPreviousMatch.java, * gnu/java/util/regex/RETokenEndSub.java, * gnu/java/util/regex/RETokenIndependent.java, * gnu/java/util/regex/RETokenLookAhead.java, * gnu/java/util/regex/RETokenLookBehind.java, * gnu/java/util/regex/RETokenNamedProperty.java, * gnu/java/util/regex/RETokenOneOf.java, * gnu/java/util/regex/RETokenPOSIX.java, * gnu/java/util/regex/RETokenRange.java, * gnu/java/util/regex/RETokenRepeated.java, * gnu/java/util/regex/RETokenStart.java, * gnu/java/util/regex/RETokenWordBoundary.java, * gnu/java/util/regex/UncheckedRE.java: Fix indentation. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/RETokenStart.java: (getMaximumLength()): Add Override annotation. (matchThis(CharIndexed, REMatch)): Likewise. (returnsFixedLengthMatches()): Renamed from returnsFixedLengthmatches and added Override annotation. (findFixedLengthMatches(CharIndexed,REMatch,int)): Add Override annotation. (dump(CPStringBuilder)): Likewise. * gnu/javax/print/ipp/IppRequest.java: (RequestWriter.writeOperationAttributes(AttributeSet)): Throw exception, don't just create and drop it. * javax/management/MBeanServerPermission.java: (MBeanServerPermissionCollection.add(Permission)): Compare against individual Strings not the entire array, and store the result of replace. * javax/swing/text/html/StyleSheet.java: (setBaseFontSize(size)): Store result of trim(). 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/tools/FileObject.java: (openReader(boolean)): Document new parameter. 2008-03-27 Michael Franz <mvfranz@gmail.com> PR classpath/35690: * javax/tools/FileObject.java: (toUri()): Fix case from toURI. (openReader(boolean)): Add missing boolean argument. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/35487: * gnu/javax/management/Server.java: (beans): Change to ConcurrentHashMap. (defaultDomain): Make final. (outer): Likewise. (LazyListenersHolder): Added to wrap listeners, also now a ConcurrentHashMap, providing lazy initialisation safely. (sequenceNumber): Documented. (getBean(ObjectName)): Remove redundant cast. (addNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Remove map initialisation and use holder. (getObjectInstance(ObjectName)): Remove redundant cast. (registerMBean(Object,ObjectName)): Add bean atomically. (removeNotificationListener(ObjectName,NotificationListener)): Simplified. (removeNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Likewise. (notify(ObjectName,String)): Documented. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Server.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Translator.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/DefaultLoaderRepository.java, * javax/management/JMX.java, * javax/management/MBeanAttributeInfo.java, * javax/management/MBeanConstructorInfo.java, * javax/management/MBeanOperationInfo.java, * javax/management/MBeanServerDelegate.java: Fix warnings due to generics. 2008-08-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/MBeanPermission.java, * javax/management/MBeanServerDelegate.java, * javax/management/MBeanServerFactory.java, * javax/management/MBeanServerInvocationHandler.java, * javax/management/MBeanServerPermission.java: Fix warnings due to use of non-generic collections. 2008-08-25 Mario Torre <neugens@aicas.com> * gnu/javax/rmi/CORBA/RmiUtilities.java (readValue): check if sender is null to avoid NPE. 2008-08-22 Mario Torre <neugens@aicas.com> * gnu/CORBA/OrbFunctional.java (set_parameters): Fix NullPointerException checking when param is null. 2008-08-23 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (reset()): Reset append position so we don't try and append to the end of the old input. 2008-08-22 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: Also allow versions of GJDoc from 0.8* on, as CVS is 0.8.0-pre. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: (CLASSPATH_WITH_GJDOC): Ensure version 0.7.9 is being used. 2008-08-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Add taglets subdirectory to list of excluded paths when GJDoc is not compiled. 2008-08-19 David P Grove <groved@us.ibm.com> * scripts/check_jni_methods.sh.in: Fix build issue on AIX by splitting generation of method list. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * native/jni/gstreamer-peer/gst_native_pipeline.c: (get_free_space(int)): Use #else not #elif when there is no condition. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/31895: * java/text/DecimalFormat.java: (setCurrency(Currency)): Update prefixes and suffixes when currency changes. * java/text/DecimalFormatSymbols.java: (DecimalFormatSymbols(Locale)): Set locale earlier so it can be used by setCurrency(Currency). (setCurrency(Currency)): Set the symbol correctly using the locale of the instance. * java/util/Currency.java: Throw error instead of just printing a message. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/activation/ActivationDataFlavor.java: Suppress warnings from public API. (mimeType): Made final. (representationClass): Added generic type and made final. (normalizeMimeTypeParameter(String,String)): Use CPStringBuilder. * javax/activation/CommandInfo.java: (verb): Made final. (className): Made final. * javax/activation/DataHandler.java: (dataSource): Made final. * javax/activation/FileDataSource.java: (file): Made final. * javax/activation/MailcapCommandMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeType.java: (toString()): Use CPStringBuilder. (getBaseType()): Likewise. * javax/activation/MimeTypeParameterList.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeTypeParseException.java: (MimeTypeParseException(String,String)): Use CPStringBuilder. * javax/activation/MimetypesFileTypeMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/URLDataSource.java: (url): Made final. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/activation/viewers/ImageViewer.java, * gnu/javax/activation/viewers/TextEditor.java, * gnu/javax/activation/viewers/TextViewer.java, * javax/activation/ActivationDataFlavor.java, * javax/activation/CommandInfo.java, * javax/activation/CommandMap.java, * javax/activation/CommandObject.java, * javax/activation/DataContentHandler.java, * javax/activation/DataContentHandlerFactory.java, * javax/activation/DataHandler.java, * javax/activation/DataHandlerDataSource.java, * javax/activation/DataSource.java, * javax/activation/DataSourceDataContentHandler.java, * javax/activation/FileDataSource.java, * javax/activation/FileTypeMap.java, * javax/activation/MailcapCommandMap.java, * javax/activation/MimeType.java, * javax/activation/MimeTypeParameterList.java, * javax/activation/MimeTypeParseException.java, * javax/activation/MimetypesFileTypeMap.java, * javax/activation/ObjectDataContentHandler.java, * javax/activation/URLDataSource.java, * javax/activation/UnsupportedDataTypeException.java, * javax/activation/package.html, * resource/META-INF/mailcap.default, * resource/META-INF/mimetypes.default: Import GNU JAF CVS as of 17/08/2008. 2006-04-25 Archit Shah <ashah@redhat.com> * javax/activation/MimeTypeParameterList.java: Insert ';' separator before parameter list. 2005-06-29 Xavier Poinsard <xpoinsard@openpricer.com> * javax/activation/ObjectDataContentHandler.java: Fixed typo. 2005-05-28 Chris Burdess <dog@bluezoo.org> * javax/activation/CommandMap.java, * javax/activation/MailcapCommandMap.java: Updated to JAF 1.1. 2004-06-09 Chris Burdess <dog@bluezoo.org> * javax/activation/MailcapCommandMap.java: Fixed bug whereby x-java prefix was not attempted. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * AUTHORS: Added Laszlo. 2008-04-20 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/30436: * java/util/Scanner.java: Fix package to be java.util and correct indentation. 2007-07-25 Laszlo Andras Hernadi <e0327023@student.tuwien.ac.at> PR classpath/30436: * java/util/Scanner.java: Initial implementation. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (toMatchResult()): Implemented. 2008-08-13 Joshua Sumali <jsumali@redhat.com> * doc/Makefile.am (gjdoc.pod): Generate gjdoc pod from cp-tools.texinfo instead of invoke.texi. Remove invoke.texi from EXTRA_DIST. * doc/invoke.texi: Removed and merged into ... * doc/cp-tools.texinfo: Here 2008-08-12 Robert Schuster <robertschuster@fsfe.org> * native/jni/java-net/local.c (local_bind): Removed fprintf call, fixed access outside of array bounds. From-SVN: r141271
1773 lines
58 KiB
Java
1773 lines
58 KiB
Java
/* Stylesheet.java --
|
|
Copyright (C) 2004,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 gnu.java.lang.CPStringBuilder;
|
|
|
|
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 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";
|
|
private static final NameTest STYLESHEET_PRESERVE_TEXT =
|
|
new NameTest(new QName(XSL_NS, "text"), false, false);
|
|
|
|
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<String> extensionElementPrefixes;
|
|
Collection<String> excludeResultPrefixes;
|
|
|
|
/**
|
|
* Set of element names for which we should strip whitespace.
|
|
*/
|
|
Set<StrippingInstruction> stripSpace;
|
|
|
|
/**
|
|
* Set of element names for which we should preserve whitespace.
|
|
*/
|
|
Set<StrippingInstruction> preserveSpace;
|
|
|
|
/**
|
|
* Output options.
|
|
*/
|
|
Node output;
|
|
int outputMethod;
|
|
String outputVersion;
|
|
String outputEncoding;
|
|
boolean outputOmitXmlDeclaration;
|
|
boolean outputStandalone;
|
|
String outputPublicId;
|
|
String outputSystemId;
|
|
Collection<String> outputCdataSectionElements;
|
|
boolean outputIndent;
|
|
String outputMediaType;
|
|
|
|
/**
|
|
* Keys.
|
|
*/
|
|
Collection<Key> keys;
|
|
|
|
/**
|
|
* Decimal formats.
|
|
*/
|
|
Map<String,DecimalFormat> decimalFormats;
|
|
|
|
/**
|
|
* Namespace aliases.
|
|
*/
|
|
Map<String,String> namespaceAliases;
|
|
|
|
/**
|
|
* Attribute-sets.
|
|
*/
|
|
List<AttributeSet> attributeSets;
|
|
|
|
/**
|
|
* Variables.
|
|
*/
|
|
List<ParameterNode> variables;
|
|
|
|
/**
|
|
* Variable and parameter bindings.
|
|
*/
|
|
Bindings bindings;
|
|
|
|
/**
|
|
* Templates.
|
|
*/
|
|
LinkedList<Template> 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<String>();
|
|
excludeResultPrefixes = new HashSet<String>();
|
|
stripSpace = new LinkedHashSet<StrippingInstruction>();
|
|
preserveSpace = new LinkedHashSet<StrippingInstruction>();
|
|
outputCdataSectionElements = new LinkedHashSet<String>();
|
|
xpath = (XPathImpl) factory.xpathFactory.newXPath();
|
|
xpath.setNamespaceContext(this);
|
|
if (parent == null)
|
|
{
|
|
bindings = new Bindings(this);
|
|
attributeSets = new LinkedList<AttributeSet>();
|
|
variables = new LinkedList<ParameterNode>();
|
|
namespaceAliases = new LinkedHashMap<String,String>();
|
|
templates = new LinkedList<Template>();
|
|
keys = new LinkedList<Key>();
|
|
decimalFormats = new LinkedHashMap<String,DecimalFormat>();
|
|
initDefaultDecimalFormat();
|
|
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.setXPathFunctionResolver(root);
|
|
}
|
|
xpath.setXPathVariableResolver(bindings);
|
|
|
|
Test anyNode = new NodeTypeTest((short) 0);
|
|
List<Test> tests = Collections.singletonList(anyNode);
|
|
builtInNodeTemplate =
|
|
new ApplyTemplatesNode(new Selector(Selector.CHILD, tests),
|
|
null, null, null, true);
|
|
builtInTextTemplate =
|
|
new ValueOfNode(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 (Template t : templates)
|
|
{
|
|
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<Template> templates2 = new LinkedList<Template>();
|
|
for (Template t : templates)
|
|
{
|
|
templates2.add(t.clone(clone));
|
|
}
|
|
clone.templates = templates2;
|
|
|
|
LinkedList<AttributeSet> attributeSets2 = new LinkedList<AttributeSet>();
|
|
for (AttributeSet as : attributeSets)
|
|
{
|
|
attributeSets2.add(as.clone(clone));
|
|
}
|
|
clone.attributeSets = attributeSets2;
|
|
|
|
LinkedList<ParameterNode> variables2 = new LinkedList<ParameterNode>();
|
|
for (ParameterNode var : variables)
|
|
{
|
|
variables2.add(var.clone(clone));
|
|
}
|
|
clone.variables = variables2;
|
|
|
|
LinkedList<Key> keys2 = new LinkedList<Key>();
|
|
for (Key k : keys)
|
|
{
|
|
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
|
|
{
|
|
current = context;
|
|
// Sort the variables into order
|
|
// See XSLT 11.4: "If the template or expression specifying the value of
|
|
// a global variable x references a global variable y, then the value
|
|
// for y must be computed before the value of x."
|
|
List<ParameterNode> topLevel = new ArrayList<ParameterNode>(variables);
|
|
Collections.sort(topLevel);
|
|
for (ParameterNode var : topLevel)
|
|
{
|
|
bindings.set(var.name,
|
|
var.getValue(this, null, context, 1, 1),
|
|
var.type);
|
|
}
|
|
current = null;
|
|
}
|
|
|
|
// -- 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<String> getPrefixes(String namespaceURI)
|
|
{
|
|
// TODO
|
|
return Collections.singleton(getPrefix(namespaceURI)).iterator();
|
|
}
|
|
|
|
final QName getQName(String name)
|
|
{
|
|
String localName = name, uri = null, prefix = null;
|
|
int ci = name.indexOf(':');
|
|
if (ci != -1)
|
|
{
|
|
prefix = name.substring(0, ci);
|
|
localName = name.substring(ci + 1);
|
|
uri = getNamespaceURI(prefix);
|
|
}
|
|
return new QName(uri, localName, prefix);
|
|
}
|
|
|
|
// -- Template selection --
|
|
|
|
TemplateNode getTemplate(QName mode, Node context, boolean applyImports)
|
|
throws TransformerException
|
|
{
|
|
if (debug)
|
|
System.err.println("getTemplate: mode="+mode+" context="+context);
|
|
Template selected = null;
|
|
for (Template t : templates)
|
|
{
|
|
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)
|
|
{
|
|
// Conflict resolution
|
|
// @see http://www.w3.org/TR/xslt#conflict
|
|
if (selected == null)
|
|
selected = t;
|
|
else
|
|
{
|
|
if (t.precedence < selected.precedence ||
|
|
t.priority < selected.priority)
|
|
continue;
|
|
selected = t;
|
|
}
|
|
}
|
|
}
|
|
if (selected == null)
|
|
{
|
|
// Apply built-in template
|
|
// Current template is unchanged
|
|
if (debug)
|
|
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.CDATA_SECTION_NODE:
|
|
case Node.ATTRIBUTE_NODE:
|
|
return builtInTextTemplate;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
// Set current template
|
|
currentTemplate = selected;
|
|
if (debug)
|
|
System.err.println("\ttemplate="+currentTemplate+" context="+context);
|
|
return currentTemplate.node;
|
|
}
|
|
|
|
TemplateNode getTemplate(QName mode, QName name)
|
|
throws TransformerException
|
|
{
|
|
Template selected = null;
|
|
for (Template t : templates)
|
|
{
|
|
boolean isMatch = t.matches(name);
|
|
if (isMatch)
|
|
{
|
|
// Conflict resolution
|
|
// @see http://www.w3.org/TR/xslt#conflict
|
|
if (selected == null)
|
|
selected = t;
|
|
else
|
|
{
|
|
if (t.precedence < selected.precedence ||
|
|
t.priority < selected.priority)
|
|
continue;
|
|
selected = t;
|
|
}
|
|
}
|
|
}
|
|
if (selected == null)
|
|
return null;
|
|
return selected.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);
|
|
Node children = node.getFirstChild();
|
|
return new Template(this, name, match, parse(children),
|
|
precedence, p, mode);
|
|
}
|
|
|
|
/**
|
|
* output
|
|
*/
|
|
final void parseOutput(Node node, NamedNodeMap attrs)
|
|
throws TransformerConfigurationException
|
|
{
|
|
output = node;
|
|
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, "doctype-public");
|
|
outputSystemId = getAttribute(attrs, "doctype-system");
|
|
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
|
|
{
|
|
while (node != null)
|
|
{
|
|
current = node;
|
|
doParse(node, root);
|
|
node = node.getNextSibling();
|
|
}
|
|
}
|
|
|
|
void doParse(Node node, boolean root)
|
|
throws TransformerConfigurationException
|
|
{
|
|
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);
|
|
}
|
|
else if ("template".equals(name))
|
|
templates.add(parseTemplate(node, attrs));
|
|
else if ("param".equals(name) ||
|
|
"variable".equals(name))
|
|
{
|
|
int type = "variable".equals(name) ?
|
|
Bindings.VARIABLE : Bindings.PARAM;
|
|
TemplateNode content = parse(node.getFirstChild());
|
|
QName paramName =
|
|
getQName(getRequiredAttribute(attrs, "name", node));
|
|
String select = getAttribute(attrs, "select");
|
|
ParameterNode param;
|
|
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);
|
|
param = new ParameterNode(paramName, expr, type);
|
|
}
|
|
else
|
|
{
|
|
param = new ParameterNode(paramName, null, type);
|
|
param.children = content;
|
|
}
|
|
variables.add(param);
|
|
}
|
|
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())
|
|
{
|
|
NameTest element = parseNameTest(st.nextToken());
|
|
preserveSpace.add(new StrippingInstruction(element,
|
|
precedence));
|
|
}
|
|
}
|
|
else if ("strip-space".equals(name))
|
|
{
|
|
String elements =
|
|
getRequiredAttribute(attrs, "elements", node);
|
|
StringTokenizer st = new StringTokenizer(elements,
|
|
" \t\n\r");
|
|
while (st.hasMoreTokens())
|
|
{
|
|
NameTest element = parseNameTest(st.nextToken());
|
|
stripSpace.add(new StrippingInstruction(element,
|
|
precedence));
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
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,
|
|
null,
|
|
null));
|
|
}
|
|
else
|
|
{
|
|
// Skip unknown elements, text, comments, etc
|
|
}
|
|
}
|
|
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);
|
|
return new NameTest(qName, true, false);
|
|
}
|
|
else
|
|
{
|
|
QName qName = getQName(token);
|
|
return new NameTest(qName, false, false);
|
|
}
|
|
}
|
|
|
|
final TemplateNode parseAttributeValueTemplate(String value, Node source)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
current = source;
|
|
// Tokenize
|
|
int len = value.length();
|
|
int off = 0;
|
|
List<String> tokens = new ArrayList<String>(); // text tokens
|
|
List<Boolean> types = new ArrayList<Boolean>(); // 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 = tokens.get(i);
|
|
Boolean type = types.get(i);
|
|
if (type == Boolean.TRUE)
|
|
{
|
|
// Expression text
|
|
Expr select = (Expr) xpath.compile(token);
|
|
TemplateNode ret2 = new ValueOfNode(select, false);
|
|
ret2.next = ret;
|
|
ret = ret2;
|
|
}
|
|
else
|
|
{
|
|
// Verbatim text
|
|
TemplateNode ret2 = new LiteralNode(doc.createTextNode(token));
|
|
ret2.next = ret;
|
|
ret = ret2;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* Whitespace stripping.
|
|
* @param text the text node
|
|
* @param source true if a source node, false if a stylesheet text node
|
|
* @see http://www.w3.org/TR/xslt#strip
|
|
*/
|
|
boolean isPreserved(Text text, boolean source)
|
|
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 (source)
|
|
{
|
|
// Source document text node
|
|
boolean preserve = true;
|
|
float psPriority = 0.0f, ssPriority = 0.0f;
|
|
if (!stripSpace.isEmpty())
|
|
{
|
|
// Conflict resolution
|
|
StrippingInstruction ssi = null, psi = null;
|
|
for (StrippingInstruction si : stripSpace)
|
|
{
|
|
if (si.element.matches(ctx, 1, 1))
|
|
{
|
|
if (ssi != null)
|
|
{
|
|
if (si.precedence < ssi.precedence)
|
|
continue;
|
|
float p = si.getPriority();
|
|
if (p < ssPriority)
|
|
continue;
|
|
}
|
|
ssi = si;
|
|
}
|
|
}
|
|
for (StrippingInstruction si : preserveSpace)
|
|
{
|
|
if (si.element.matches(ctx, 1, 1))
|
|
{
|
|
if (psi != null)
|
|
{
|
|
if (si.precedence < psi.precedence)
|
|
continue;
|
|
float p = si.getPriority();
|
|
if (p < psPriority)
|
|
continue;
|
|
}
|
|
psi = si;
|
|
}
|
|
}
|
|
if (ssi != null)
|
|
{
|
|
if (psi != null)
|
|
{
|
|
if (psi.precedence < ssi.precedence)
|
|
preserve = false;
|
|
else if (psPriority < ssPriority)
|
|
preserve = false;
|
|
}
|
|
else
|
|
preserve = false;
|
|
}
|
|
}
|
|
if (preserve)
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
// Stylesheet text node
|
|
if (STYLESHEET_PRESERVE_TEXT.matches(ctx, 1, 1))
|
|
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);
|
|
}
|
|
}
|
|
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(new NamespaceProxy(current));
|
|
else if ("function-available".equals(localName) && (arity == 1))
|
|
return new FunctionAvailableFunction(new NamespaceProxy(current));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// -- Parsing --
|
|
|
|
/**
|
|
* apply-templates
|
|
*/
|
|
final TemplateNode parseApplyTemplates(Node node)
|
|
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()";
|
|
Node children = node.getFirstChild();
|
|
List<SortKey> sortKeys = parseSortKeys(children);
|
|
List<WithParam> withParams = parseWithParams(children);
|
|
Expr select = (Expr) xpath.compile(s);
|
|
return new ApplyTemplatesNode(select, mode,
|
|
sortKeys, withParams, false);
|
|
}
|
|
|
|
/**
|
|
* call-template
|
|
*/
|
|
final TemplateNode parseCallTemplate(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String n = getRequiredAttribute(attrs, "name", node);
|
|
QName name = getQName(n);
|
|
Node children = node.getFirstChild();
|
|
List<WithParam> withParams = parseWithParams(children);
|
|
return new CallTemplateNode(name, withParams);
|
|
}
|
|
|
|
/**
|
|
* value-of
|
|
*/
|
|
final TemplateNode parseValueOf(Node node)
|
|
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(select, d);
|
|
}
|
|
|
|
/**
|
|
* for-each
|
|
*/
|
|
final TemplateNode parseForEach(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String s = getRequiredAttribute(attrs, "select", node);
|
|
Node children = node.getFirstChild();
|
|
List<SortKey> sortKeys = parseSortKeys(children);
|
|
Expr select = (Expr) xpath.compile(s);
|
|
ForEachNode ret = new ForEachNode(select, sortKeys);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* if
|
|
*/
|
|
final TemplateNode parseIf(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String t = getRequiredAttribute(attrs, "test", node);
|
|
Expr test = (Expr) xpath.compile(t);
|
|
Node children = node.getFirstChild();
|
|
IfNode ret = new IfNode(test);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* when
|
|
*/
|
|
final TemplateNode parseWhen(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String t = getRequiredAttribute(attrs, "test", node);
|
|
Expr test = (Expr) xpath.compile(t);
|
|
Node children = node.getFirstChild();
|
|
WhenNode ret = new WhenNode(test);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* element
|
|
*/
|
|
final TemplateNode parseElement(Node node)
|
|
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);
|
|
Node children = node.getFirstChild();
|
|
ElementNode ret = new ElementNode(n, ns, uas, node);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* attribute
|
|
*/
|
|
final TemplateNode parseAttribute(Node node)
|
|
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);
|
|
Node children = node.getFirstChild();
|
|
AttributeNode ret = new AttributeNode(n, ns, node);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* text
|
|
*/
|
|
final TemplateNode parseText(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String doe = getAttribute(attrs, "disable-output-escaping");
|
|
boolean d = "yes".equals(doe);
|
|
Node children = node.getFirstChild();
|
|
TextNode ret = new TextNode(d);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* copy
|
|
*/
|
|
final TemplateNode parseCopy(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String uas = getAttribute(attrs, "use-attribute-sets");
|
|
Node children = node.getFirstChild();
|
|
CopyNode ret = new CopyNode(uas);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* processing-instruction
|
|
*/
|
|
final TemplateNode parseProcessingInstruction(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String name = getRequiredAttribute(attrs, "name", node);
|
|
Node children = node.getFirstChild();
|
|
ProcessingInstructionNode ret = new ProcessingInstructionNode(name);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* number
|
|
*/
|
|
final TemplateNode parseNumber(Node node)
|
|
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;
|
|
Node children = node.getFirstChild();
|
|
TemplateNode ret;
|
|
if (v != null && v.length() > 0)
|
|
{
|
|
Expr value = (Expr) xpath.compile(v);
|
|
ret = new NumberNode(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);
|
|
}
|
|
}
|
|
ret = new NodeNumberNode(level, count, from,
|
|
format, lang,
|
|
letterValue, gs, gz2);
|
|
}
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* copy-of
|
|
*/
|
|
final TemplateNode parseCopyOf(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String s = getRequiredAttribute(attrs, "select", node);
|
|
Expr select = (Expr) xpath.compile(s);
|
|
Node children = node.getFirstChild();
|
|
CopyOfNode ret = new CopyOfNode(select);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* message
|
|
*/
|
|
final TemplateNode parseMessage(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
String t = getAttribute(attrs, "terminate");
|
|
boolean terminate = "yes".equals(t);
|
|
Node children = node.getFirstChild();
|
|
MessageNode ret = new MessageNode(terminate);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* Parse template-level elements.
|
|
*/
|
|
final TemplateNode parse(Node node)
|
|
throws TransformerConfigurationException
|
|
{
|
|
TemplateNode first = null;
|
|
TemplateNode previous = null;
|
|
while (node != null)
|
|
{
|
|
Node next = node.getNextSibling();
|
|
TemplateNode tnode = doParse(node);
|
|
if (tnode != null)
|
|
{
|
|
if (first == null)
|
|
first = tnode;
|
|
if (previous != null)
|
|
previous.next = tnode;
|
|
previous = tnode;
|
|
}
|
|
node = next;
|
|
}
|
|
return first;
|
|
}
|
|
|
|
private final TemplateNode doParse(Node node)
|
|
throws TransformerConfigurationException
|
|
{
|
|
// Hack to associate the document function with its declaring node
|
|
current = node;
|
|
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);
|
|
else if ("call-template".equals(name))
|
|
return parseCallTemplate(node);
|
|
else if ("value-of".equals(name))
|
|
return parseValueOf(node);
|
|
else if ("for-each".equals(name))
|
|
return parseForEach(node);
|
|
else if ("if".equals(name))
|
|
return parseIf(node);
|
|
else if ("choose".equals(name))
|
|
{
|
|
Node children = node.getFirstChild();
|
|
ChooseNode ret = new ChooseNode();
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
else if ("when".equals(name))
|
|
return parseWhen(node);
|
|
else if ("otherwise".equals(name))
|
|
{
|
|
Node children = node.getFirstChild();
|
|
OtherwiseNode ret = new OtherwiseNode();
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
else if ("element".equals(name))
|
|
return parseElement(node);
|
|
else if ("attribute".equals(name))
|
|
return parseAttribute(node);
|
|
else if ("text".equals(name))
|
|
return parseText(node);
|
|
else if ("copy".equals(name))
|
|
return parseCopy(node);
|
|
else if ("processing-instruction".equals(name))
|
|
return parseProcessingInstruction(node);
|
|
else if ("comment".equals(name))
|
|
{
|
|
Node children = node.getFirstChild();
|
|
CommentNode ret = new CommentNode();
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
else if ("number".equals(name))
|
|
return parseNumber(node);
|
|
else if ("param".equals(name) ||
|
|
"variable".equals(name))
|
|
{
|
|
int type = "variable".equals(name) ?
|
|
Bindings.VARIABLE : Bindings.PARAM;
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
Node children = node.getFirstChild();
|
|
TemplateNode content = parse(children);
|
|
QName paramName =
|
|
getQName(getRequiredAttribute(attrs, "name", node));
|
|
String select = getAttribute(attrs, "select");
|
|
ParameterNode ret;
|
|
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);
|
|
ret = new ParameterNode(paramName, expr, type);
|
|
}
|
|
else
|
|
{
|
|
ret = new ParameterNode(paramName, null, type);
|
|
ret.children = content;
|
|
}
|
|
return ret;
|
|
}
|
|
else if ("copy-of".equals(name))
|
|
return parseCopyOf(node);
|
|
else if ("message".equals(name))
|
|
return parseMessage(node);
|
|
else if ("apply-imports".equals(name))
|
|
{
|
|
Node children = node.getFirstChild();
|
|
ApplyImportsNode ret = new ApplyImportsNode();
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
else
|
|
{
|
|
// xsl:fallback
|
|
// Pass over any other XSLT nodes
|
|
return null;
|
|
}
|
|
}
|
|
String prefix = node.getPrefix();
|
|
if (extensionElementPrefixes.contains(prefix))
|
|
{
|
|
// Check for xsl:fallback
|
|
for (Node ctx = node.getFirstChild(); ctx != null;
|
|
ctx = ctx.getNextSibling())
|
|
{
|
|
String ctxUri = ctx.getNamespaceURI();
|
|
if (XSL_NS.equals(ctxUri) &&
|
|
"fallback".equals(ctx.getLocalName()))
|
|
{
|
|
ctx = ctx.getFirstChild();
|
|
return (ctx == null) ? null : parse(ctx);
|
|
}
|
|
}
|
|
// Otherwise pass over extension element
|
|
return null;
|
|
}
|
|
switch (node.getNodeType())
|
|
{
|
|
case Node.TEXT_NODE:
|
|
case Node.CDATA_SECTION_NODE:
|
|
// Determine whether to strip whitespace
|
|
Text text = (Text) node;
|
|
if (!isPreserved(text, false))
|
|
{
|
|
// Strip
|
|
text.getParentNode().removeChild(text);
|
|
return null;
|
|
}
|
|
break;
|
|
case Node.COMMENT_NODE:
|
|
// Ignore comments
|
|
return null;
|
|
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
|
|
Node children = node.getFirstChild();
|
|
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);
|
|
TemplateNode newChild = new AttributeNode(n, ns, attr);
|
|
newChild.children = grandchild;
|
|
newChild.next = child;
|
|
child = newChild;
|
|
}
|
|
String ename = node.getNodeName();
|
|
TemplateNode n = parseAttributeValueTemplate(ename, node);
|
|
//TemplateNode ns = (namespaceUri == null) ? null :
|
|
// parseAttributeValueTemplate(namespaceUri, node);
|
|
TemplateNode ns = null;
|
|
ElementNode ret = new ElementNode(n, ns, useAttributeSets,
|
|
node);
|
|
ret.children = child;
|
|
return ret;
|
|
}
|
|
// Otherwise fall through
|
|
break;
|
|
}
|
|
}
|
|
catch (XPathExpressionException e)
|
|
{
|
|
DOMSourceLocator l = new DOMSourceLocator(node);
|
|
throw new TransformerConfigurationException(e.getMessage(), l, e);
|
|
}
|
|
Node children = node.getFirstChild();
|
|
LiteralNode ret = new LiteralNode(node);
|
|
ret.children = parse(children);
|
|
return ret;
|
|
}
|
|
|
|
final List<SortKey> parseSortKeys(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
List<SortKey> ret = new LinkedList<SortKey>();
|
|
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;
|
|
}
|
|
|
|
final List<WithParam> parseWithParams(Node node)
|
|
throws TransformerConfigurationException, XPathExpressionException
|
|
{
|
|
List<WithParam> ret = new LinkedList<WithParam>();
|
|
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());
|
|
QName name =
|
|
getQName(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;
|
|
}
|
|
|
|
/**
|
|
* 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<String> 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);
|
|
}
|
|
|
|
public String toString()
|
|
{
|
|
CPStringBuilder b = new CPStringBuilder(getClass().getName());
|
|
b.append("[templates=");
|
|
b.append(templates);
|
|
b.append("]");
|
|
return b.toString();
|
|
}
|
|
|
|
}
|
|
|