diff --git a/jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java b/jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java index 45b91dc9aa2..39b6929379b 100644 --- a/jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java +++ b/jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -385,8 +386,18 @@ public class CoreDOMImplementationImpl * reference to the default error handler. */ public LSSerializer createLSSerializer() { - return new DOMSerializerImpl(); - } + try { + Class serializerClass = ObjectFactory.findProviderClass( + "com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl", + ObjectFactory.findClassLoader(), true); + return (LSSerializer) serializerClass.newInstance(); + } + catch (Exception e) {} + // Fall back to Xerces' deprecated serializer if + // the Xalan based serializer is unavailable. + return new DOMSerializerImpl(); + } + /** * DOM Level 3 LS CR - Experimental. * Create a new empty input source. diff --git a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java index 526f5e1b5f0..ea0e9b7a9a4 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java @@ -3145,7 +3145,11 @@ public class SAX2DTM2 extends SAX2DTM m_data.elementAt(-dataIndex+1)); } } - else if (DTM.ELEMENT_NODE == type || DTM.DOCUMENT_FRAGMENT_NODE == type + else if (DTM.ELEMENT_NODE == type) + { + return getStringValueX(nodeHandle); + } + else if (DTM.DOCUMENT_FRAGMENT_NODE == type || DTM.DOCUMENT_NODE == type) { return null; diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/BaseMarkupSerializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/BaseMarkupSerializer.java index 3150b10d860..2c9a4988fca 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/BaseMarkupSerializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/BaseMarkupSerializer.java @@ -123,6 +123,11 @@ import org.xml.sax.ext.LexicalHandler; * @author Sunitha Reddy, Sun Microsystems * @see Serializer * @see org.w3c.dom.ls.LSSerializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public abstract class BaseMarkupSerializer implements ContentHandler, DocumentHandler, LexicalHandler, diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializer.java index 40566616ed9..408b35cd9ba 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializer.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -35,6 +36,11 @@ import org.w3c.dom.DocumentFragment; * * @author Scott Boag * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public interface DOMSerializer { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java index eae65068d82..dc9378b39e5 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java @@ -72,6 +72,9 @@ import org.w3c.dom.ls.LSSerializerFilter; * @author Gopal Sharma, Sun Microsystems * @author Arun Yadav, Sun Microsystems * @author Sunitha Reddy, Sun Microsystems + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, replaced by + * {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl} */ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/ElementState.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/ElementState.java index d6b412e50fe..8b556f93431 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/ElementState.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/ElementState.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -28,9 +29,13 @@ import java.util.Hashtable; /** * Holds the state of the currently serialized element. * - * * @author Assaf Arkin * @see BaseMarkupSerializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class ElementState { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/EncodingInfo.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/EncodingInfo.java index 252483fc53d..6756daf410b 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/EncodingInfo.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/EncodingInfo.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 2000-2002,2004,2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -29,6 +30,10 @@ import com.sun.org.apache.xerces.internal.util.EncodingMap; /** * This class represents an encoding. * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class EncodingInfo { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Encodings.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Encodings.java index 711b217b87d..adc8c3c86ba 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Encodings.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Encodings.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -36,6 +37,11 @@ import com.sun.org.apache.xerces.internal.util.EncodingMap; * for each encoding. * * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class Encodings { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/HTMLdtd.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/HTMLdtd.java index 17e3964bfa5..6b50dcd1567 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/HTMLdtd.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/HTMLdtd.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -45,8 +46,12 @@ import java.util.Locale; * from value to name. A small entities resource is loaded into memory the * first time any of these methods is called for fast and efficient access. * - * * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public final class HTMLdtd { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/IndentPrinter.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/IndentPrinter.java index efc7af1248d..34e03138974 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/IndentPrinter.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/IndentPrinter.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -32,6 +33,11 @@ import java.io.IOException; * wrapping. * * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class IndentPrinter extends Printer diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/LineSeparator.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/LineSeparator.java index bb4b1b9ae18..1886ac44055 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/LineSeparator.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/LineSeparator.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -25,6 +26,11 @@ package com.sun.org.apache.xml.internal.serialize; /** * @author Assaf Arkin * @see OutputFormat + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public final class LineSeparator { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Method.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Method.java index c6cfff09d7d..99b97d0572a 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Method.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Method.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -25,6 +26,11 @@ package com.sun.org.apache.xml.internal.serialize; /** * @author Assaf Arkin * @see OutputFormat + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public final class Method { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/OutputFormat.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/OutputFormat.java index 505a8996df3..1d0db3fa57d 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/OutputFormat.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/OutputFormat.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -59,6 +60,11 @@ import org.w3c.dom.html.HTMLDocument; * @see Serializer * @see Method * @see LineSeparator + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class OutputFormat { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Printer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Printer.java index ab9d8e4a0e5..2e966809094 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Printer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Printer.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -40,6 +41,11 @@ import java.io.IOException; * extending this class. * * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class Printer { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Serializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Serializer.java index 5aecb4ffe43..3bb0fd6de90 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/Serializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/Serializer.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -60,6 +61,11 @@ import org.xml.sax.DocumentHandler; * @see ContentHandler * @see OutputFormat * @see DOMSerializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public interface Serializer { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactory.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactory.java index 2150e31a0b5..d1af445b11d 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactory.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactory.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -34,6 +35,11 @@ import java.util.StringTokenizer; * * @author Scott Boag * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public abstract class SerializerFactory { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactoryImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactoryImpl.java index dd27e57ceec..8883a820dfb 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactoryImpl.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactoryImpl.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -34,6 +35,11 @@ import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter; * * @author Scott Boag * @author Assaf Arkin + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ final class SerializerFactoryImpl extends SerializerFactory diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/TextSerializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/TextSerializer.java index 789f6368cfd..09ceaf0f3f5 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/TextSerializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/TextSerializer.java @@ -3,11 +3,12 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -58,6 +59,11 @@ import org.xml.sax.SAXException; * * @author Assaf Arkin * @see Serializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class TextSerializer extends BaseMarkupSerializer diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/XML11Serializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/XML11Serializer.java index ced3ef5c4d5..514e417acb3 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/XML11Serializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/XML11Serializer.java @@ -73,10 +73,16 @@ import org.xml.sax.SAXException; * boundaries, indent lines, and serialize elements on separate * lines. Line terminators will be regarded as spaces, and * spaces at beginning of line will be stripped. + * * @author Assaf Arkin * @author Rahul Srivastava * @author Elena Litani IBM * @see Serializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class XML11Serializer extends XMLSerializer { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serialize/XMLSerializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serialize/XMLSerializer.java index 884fd4b5fe5..0c39d3eeaf8 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serialize/XMLSerializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serialize/XMLSerializer.java @@ -84,10 +84,16 @@ import org.xml.sax.helpers.AttributesImpl; * boundaries, indent lines, and serialize elements on separate * lines. Line terminators will be regarded as spaces, and * spaces at beginning of line will be stripped. + * * @author Assaf Arkin * @author Rahul Srivastava * @author Elena Litani IBM * @see Serializer + * + * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation + * is replaced by that of Xalan. Main class + * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced + * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. */ public class XMLSerializer extends BaseMarkupSerializer { diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/DOM3Serializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/DOM3Serializer.java new file mode 100644 index 00000000000..a31c68b9ec3 --- /dev/null +++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/DOM3Serializer.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * $Id: $ + */ + +package com.sun.org.apache.xml.internal.serializer; + +import java.io.IOException; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMErrorHandler; +import org.w3c.dom.ls.LSSerializerFilter; + +/** + * Interface for a DOM serializer capable of serializing DOMs as specified in + * the DOM Level 3 Save Recommendation. + *
+ * The DOM3Serializer is a facet of a serializer and is obtained from the + * asDOM3Serializer() method of the org.apache.xml.serializer.Serializer interface. + * A serializer may or may not support a level 3 DOM serializer, if it does not then the + * return value from asDOM3Serializer() is null. + *
+ * Example: + *
+ * Document doc; + * Serializer ser; + * OutputStream os; + * DOMErrorHandler handler; + * + * ser = ...; + * os = ...; + * handler = ...; + * + * ser.setOutputStream( os ); + * DOM3Serialzier dser = (DOM3Serialzier)ser.asDOM3Serializer(); + * dser.setErrorHandler(handler); + * dser.serialize(doc); + *+ * + * @see org.apache.xml.serializer.Serializer + * + * @xsl.usage general + * + */ +public interface DOM3Serializer { + /** + * Serializes the Level 3 DOM node. Throws an exception only if an I/O + * exception occured while serializing. + * + * This interface is a public API. + * + * @param node the Level 3 DOM node to serialize + * @throws IOException if an I/O exception occured while serializing + */ + public void serializeDOM3(Node node) throws IOException; + + /** + * Sets a DOMErrorHandler on the DOM Level 3 Serializer. + * + * This interface is a public API. + * + * @param handler the Level 3 DOMErrorHandler + */ + public void setErrorHandler(DOMErrorHandler handler); + + /** + * Returns a DOMErrorHandler set on the DOM Level 3 Serializer. + * + * This interface is a public API. + * + * @return A Level 3 DOMErrorHandler + */ + public DOMErrorHandler getErrorHandler(); + + /** + * Sets a LSSerializerFilter on the DOM Level 3 Serializer to filter nodes + * during serialization. + * + * This interface is a public API. + * + * @param filter the Level 3 LSSerializerFilter + */ + public void setNodeFilter(LSSerializerFilter filter); + + /** + * Returns a LSSerializerFilter set on the DOM Level 3 Serializer to filter nodes + * during serialization. + * + * This interface is a public API. + * + * @return The Level 3 LSSerializerFilter + */ + public LSSerializerFilter getNodeFilter(); + + /** + * Sets the new line character to be used during serialization + * @param newLine a String that is the end-of-line character sequence to be + * used in serialization. + */ + public void setNewLine(String newLine); +} diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java index 09a13dace09..35952c88d0c 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java @@ -786,4 +786,13 @@ public class EmptySerializer implements SerializationHandler aMethodIsCalled(); } + + /** + * @see org.apache.xml.serializer.Serializer#asDOM3Serializer() + */ + public Object asDOM3Serializer() throws IOException + { + couldThrowIOException(); + return null; + } } diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java index 80eb8a5d969..18e76134891 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java @@ -152,6 +152,24 @@ public final class Encodings extends Object return ei; } + /** + * Determines if the encoding specified was recognized by the + * serializer or not. + * + * @param encoding The encoding + * @return boolean - true if the encoding was recognized else false + */ + public static boolean isRecognizedEncoding(String encoding) + { + EncodingInfo ei; + + String normalizedEncoding = toUpperCaseFast(encoding); + ei = _encodingInfos.findEncoding(normalizedEncoding); + if (ei != null) + return true; + return false; + } + /** * A fast and cheap way to uppercase a String that is * only made of printable ASCII characters. diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java index 1e918553be7..93331efc589 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java @@ -3,9 +3,11 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 2003-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -110,9 +112,29 @@ public interface SerializationHandler public void setNamespaceMappings(NamespaceMappings mappings); /** - * Flush any pending events currently queued up in the serializer. This will - * flush any input that the serializer has which it has not yet sent as - * output. + * A SerializationHandler accepts SAX-like events, so + * it can accumulate attributes or namespace nodes after + * a startElement(). + *
+ * If the SerializationHandler has a Writer or OutputStream, + * a call to this method will flush such accumulated + * events as a closed start tag for an element. + *
+ * If the SerializationHandler wraps a ContentHandler, + * a call to this method will flush such accumulated + * events as a SAX (not SAX-like) calls to + * startPrefixMapping() and startElement(). + *
+ * If one calls endDocument() then one need not call + * this method since a call to endDocument() will + * do what this method does. However, in some + * circumstances, such as with document fragments, + * endDocument() is not called and it may be + * necessary to call this method to flush + * any pending events. + *
+ * For performance reasons this method should not be called + * very often. */ public void flushPending() throws SAXException; diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/Serializer.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/Serializer.java index 9cae2d22d0b..b855659a226 100644 --- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/Serializer.java +++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/Serializer.java @@ -3,9 +3,11 @@ * DO NOT REMOVE OR ALTER! */ /* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -220,4 +222,20 @@ public interface Serializer { * @return True if serializer has been reset and can be reused */ public boolean reset(); + + /** + * Return an Object into this serializer to be cast to a DOM3Serializer. + * Through the returned object the document to be serialized, + * a DOM (Level 3), can be provided to the serializer. + * If the serializer does not support casting to a {@link DOM3Serializer} + * interface, it should return null. + *
+ * In principle only one of asDOM3Serializer() or asContentHander()
+ * should be called.
+ *
+ * @return An Object to be cast to a DOM3Serializer interface into this serializer,
+ * or null if the serializer is not DOM capable
+ * @throws IOException An I/O exception occured
+ */
+ public Object asDOM3Serializer() throws IOException;
}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java
index fb80d771f00..5d706e2f5ab 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java
@@ -1558,6 +1558,21 @@ public abstract class SerializerBase
return getProp(name,false);
}
+ /**
+ * Return a {@link DOM3Serializer} interface into this serializer. If the
+ * serializer does not support the {@link DOM3Serializer} interface, it should
+ * return null.
+ *
+ * @return A {@link DOM3Serializer} interface into this serializer, or null
+ * if the serializer is not DOM capable
+ * @throws IOException An I/O exception occured
+ * @see org.apache.xml.serializer.Serializer#asDOM3Serializer()
+ */
+ public Object asDOM3Serializer() throws IOException
+ {
+ return new com.sun.org.apache.xml.internal.serializer.dom3.DOM3SerializerImpl(this);
+ }
+
/**
* Get the default value of an xsl:output property,
* which would be null only if no default value exists
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerFactory.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerFactory.java
index 358c4f25bb6..d2c5f264b18 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerFactory.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerFactory.java
@@ -136,7 +136,7 @@ public final class SerializerFactory
if (obj instanceof SerializationHandler)
{
// this is one of the supplied serializers
- ser = (Serializer) cls.newInstance();
+ ser = (Serializer) obj;
ser.setOutputFormat(format);
}
else
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
index 2195e71f8b0..0e0efe7c2e2 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
@@ -537,7 +537,7 @@ abstract public class ToStream extends SerializerBase
if (OutputPropertiesFactory.S_KEY_INDENT_AMOUNT.equals(name)) {
setIndentAmount(Integer.parseInt(val));
} else if (OutputKeys.INDENT.equals(name)) {
- boolean b = "yes".equals(val) ? true : false;
+ boolean b = val.endsWith("yes") ? true : false;
m_doIndent = b;
}
@@ -556,7 +556,7 @@ abstract public class ToStream extends SerializerBase
break;
case 'o':
if (OutputKeys.OMIT_XML_DECLARATION.equals(name)) {
- boolean b = "yes".equals(val) ? true : false;
+ boolean b = val.endsWith("yes") ? true : false;
this.m_shouldNotWriteXMLHeader = b;
}
break;
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java
index a68382c4160..9583dd5d30f 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java
@@ -1335,4 +1335,12 @@ public final class ToUnknownStream extends SerializerBase
ch.length);
}
}
+
+ /**
+ * @see org.apache.xml.serializer.Serializer#asDOM3Serializer()
+ */
+ public Object asDOM3Serializer() throws IOException
+ {
+ return m_handler.asDOM3Serializer();
+ }
}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3SerializerImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3SerializerImpl.java
new file mode 100644
index 00000000000..0d4509c2a97
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3SerializerImpl.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import java.io.IOException;
+
+import com.sun.org.apache.xml.internal.serializer.DOM3Serializer;
+import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
+import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
+import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.Node;
+import org.w3c.dom.ls.LSSerializerFilter;
+
+/**
+ * This class implements the DOM3Serializer interface.
+ *
+ * @xsl.usage internal
+ */
+public final class DOM3SerializerImpl implements DOM3Serializer {
+
+ /**
+ * Private class members
+ */
+ // The DOMErrorHandler
+ private DOMErrorHandler fErrorHandler;
+
+ // A LSSerializerFilter
+ private LSSerializerFilter fSerializerFilter;
+
+ // The end-of-line character sequence
+ private String fNewLine;
+
+ // A SerializationHandler ex. an instance of ToXMLStream
+ private SerializationHandler fSerializationHandler;
+
+ /**
+ * Constructor
+ *
+ * @param handler An instance of the SerializationHandler interface.
+ */
+ public DOM3SerializerImpl(SerializationHandler handler) {
+ fSerializationHandler = handler;
+ }
+
+ // Public memebers
+
+ /**
+ * Returns a DOMErrorHandler set on the DOM Level 3 Serializer.
+ *
+ * This interface is a public API.
+ *
+ * @return A Level 3 DOMErrorHandler
+ */
+ public DOMErrorHandler getErrorHandler() {
+ return fErrorHandler;
+ }
+
+ /**
+ * Returns a LSSerializerFilter set on the DOM Level 3 Serializer to filter nodes
+ * during serialization.
+ *
+ * This interface is a public API.
+ *
+ * @return The Level 3 LSSerializerFilter
+ */
+ public LSSerializerFilter getNodeFilter() {
+ return fSerializerFilter;
+ }
+
+
+ /**
+ * Serializes the Level 3 DOM node by creating an instance of DOM3TreeWalker
+ * which traverses the DOM tree and invokes handler events to serialize
+ * the DOM NOde. Throws an exception only if an I/O exception occured
+ * while serializing.
+ * This interface is a public API.
+ *
+ * @param node the Level 3 DOM node to serialize
+ * @throws IOException if an I/O exception occured while serializing
+ */
+ public void serializeDOM3(Node node) throws IOException {
+ try {
+ DOM3TreeWalker walker = new DOM3TreeWalker(fSerializationHandler,
+ fErrorHandler, fSerializerFilter, fNewLine);
+
+ walker.traverse(node);
+ } catch (org.xml.sax.SAXException se) {
+ throw new WrappedRuntimeException(se);
+ }
+ }
+
+ /**
+ * Sets a DOMErrorHandler on the DOM Level 3 Serializer.
+ *
+ * This interface is a public API.
+ *
+ * @param handler the Level 3 DOMErrorHandler
+ */
+ public void setErrorHandler(DOMErrorHandler handler) {
+ fErrorHandler = handler;
+ }
+
+ /**
+ * Sets a LSSerializerFilter on the DOM Level 3 Serializer to filter nodes
+ * during serialization.
+ *
+ * This interface is a public API.
+ *
+ * @param filter the Level 3 LSSerializerFilter
+ */
+ public void setNodeFilter(LSSerializerFilter filter) {
+ fSerializerFilter = filter;
+ }
+
+ /**
+ * Sets a SerializationHandler on the DOM Serializer.
+ *
+ * This interface is a public API.
+ *
+ * @param handler An instance of SerializationHandler
+ */
+ public void setSerializationHandler(SerializationHandler handler) {
+ fSerializationHandler = handler;
+ }
+
+ /**
+ * Sets the new line character to be used during serialization
+ * @param newLine a String that is the end-of-line character sequence to be
+ * used in serialization.
+ */
+ public void setNewLine(String newLine) {
+ fNewLine = newLine;
+ }
+}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
new file mode 100644
index 00000000000..b83d2ebde50
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
@@ -0,0 +1,2145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory;
+import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+import com.sun.org.apache.xerces.internal.util.XML11Char;
+import com.sun.org.apache.xerces.internal.util.XMLChar;
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.DOMError;
+import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Entity;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.w3c.dom.ls.LSSerializerFilter;
+import org.w3c.dom.traversal.NodeFilter;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.LocatorImpl;
+
+/**
+ * Built on org.apache.xml.serializer.TreeWalker and adds functionality to
+ * traverse and serialize a DOM Node (Level 2 or Level 3) as specified in
+ * the DOM Level 3 LS Recommedation by evaluating and applying DOMConfiguration
+ * parameters and filters if any during serialization.
+ *
+ * @xsl.usage internal
+ */
+final class DOM3TreeWalker {
+
+ /**
+ * The SerializationHandler, it extends ContentHandler and when
+ * this class is instantiated via the constructor provided, a
+ * SerializationHandler object is passed to it.
+ */
+ private SerializationHandler fSerializer = null;
+
+ /** We do not need DOM2Helper since DOM Level 3 LS applies to DOM Level 2 or newer */
+
+ /** Locator object for this TreeWalker */
+ private LocatorImpl fLocator = new LocatorImpl();
+
+ /** ErrorHandler */
+ private DOMErrorHandler fErrorHandler = null;
+
+ /** LSSerializerFilter */
+ private LSSerializerFilter fFilter = null;
+
+ /** If the serializer is an instance of a LexicalHandler */
+ private LexicalHandler fLexicalHandler = null;
+
+ private int fWhatToShowFilter;
+
+ /** New Line character to use in serialization */
+ private String fNewLine = null;
+
+ /** DOMConfiguration Properties */
+ private Properties fDOMConfigProperties = null;
+
+ /** Keeps track if we are in an entity reference when entities=true */
+ private boolean fInEntityRef = false;
+
+ /** Stores the version of the XML document to be serialize */
+ private String fXMLVersion = null;
+
+ /** XML Version, default 1.0 */
+ private boolean fIsXMLVersion11 = false;
+
+ /** Is the Node a Level 3 DOM node */
+ private boolean fIsLevel3DOM = false;
+
+ /** DOM Configuration Parameters */
+ private int fFeatures = 0;
+
+ /** Flag indicating whether following text to be processed is raw text */
+ boolean fNextIsRaw = false;
+
+ //
+ private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+
+ //
+ private static final String XMLNS_PREFIX = "xmlns";
+
+ //
+ private static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
+
+ //
+ private static final String XML_PREFIX = "xml";
+
+ /** stores namespaces in scope */
+ protected NamespaceSupport fNSBinder;
+
+ /** stores all namespace bindings on the current element */
+ protected NamespaceSupport fLocalNSBinder;
+
+ /** stores the current element depth */
+ private int fElementDepth = 0;
+
+ // ***********************************************************************
+ // DOMConfiguration paramter settings
+ // ***********************************************************************
+ // Parameter canonical-form, true [optional] - NOT SUPPORTED
+ private final static int CANONICAL = 0x1 << 0;
+
+ // Parameter cdata-sections, true [required] (default)
+ private final static int CDATA = 0x1 << 1;
+
+ // Parameter check-character-normalization, true [optional] - NOT SUPPORTED
+ private final static int CHARNORMALIZE = 0x1 << 2;
+
+ // Parameter comments, true [required] (default)
+ private final static int COMMENTS = 0x1 << 3;
+
+ // Parameter datatype-normalization, true [optional] - NOT SUPPORTED
+ private final static int DTNORMALIZE = 0x1 << 4;
+
+ // Parameter element-content-whitespace, true [required] (default) - value - false [optional] NOT SUPPORTED
+ private final static int ELEM_CONTENT_WHITESPACE = 0x1 << 5;
+
+ // Parameter entities, true [required] (default)
+ private final static int ENTITIES = 0x1 << 6;
+
+ // Parameter infoset, true [required] (default), false has no effect --> True has no effect for the serializer
+ private final static int INFOSET = 0x1 << 7;
+
+ // Parameter namespaces, true [required] (default)
+ private final static int NAMESPACES = 0x1 << 8;
+
+ // Parameter namespace-declarations, true [required] (default)
+ private final static int NAMESPACEDECLS = 0x1 << 9;
+
+ // Parameter normalize-characters, true [optional] - NOT SUPPORTED
+ private final static int NORMALIZECHARS = 0x1 << 10;
+
+ // Parameter split-cdata-sections, true [required] (default)
+ private final static int SPLITCDATA = 0x1 << 11;
+
+ // Parameter validate, true [optional] - NOT SUPPORTED
+ private final static int VALIDATE = 0x1 << 12;
+
+ // Parameter validate-if-schema, true [optional] - NOT SUPPORTED
+ private final static int SCHEMAVALIDATE = 0x1 << 13;
+
+ // Parameter split-cdata-sections, true [required] (default)
+ private final static int WELLFORMED = 0x1 << 14;
+
+ // Parameter discard-default-content, true [required] (default)
+ // Not sure how this will be used in level 2 Documents
+ private final static int DISCARDDEFAULT = 0x1 << 15;
+
+ // Parameter format-pretty-print, true [optional]
+ private final static int PRETTY_PRINT = 0x1 << 16;
+
+ // Parameter ignore-unknown-character-denormalizations, true [required] (default)
+ // We currently do not support XML 1.1 character normalization
+ private final static int IGNORE_CHAR_DENORMALIZE = 0x1 << 17;
+
+ // Parameter discard-default-content, true [required] (default)
+ private final static int XMLDECL = 0x1 << 18;
+
+ /**
+ * Constructor.
+ * @param contentHandler serialHandler The implemention of the SerializationHandler interface
+ */
+ DOM3TreeWalker(
+ SerializationHandler serialHandler,
+ DOMErrorHandler errHandler,
+ LSSerializerFilter filter,
+ String newLine) {
+ fSerializer = serialHandler;
+ //fErrorHandler = errHandler == null ? new DOMErrorHandlerImpl() : errHandler; // Should we be using the default?
+ fErrorHandler = errHandler;
+ fFilter = filter;
+ fLexicalHandler = null;
+ fNewLine = newLine;
+
+ fNSBinder = new NamespaceSupport();
+ fLocalNSBinder = new NamespaceSupport();
+
+ fDOMConfigProperties = fSerializer.getOutputFormat();
+ fSerializer.setDocumentLocator(fLocator);
+ initProperties(fDOMConfigProperties);
+
+ try {
+ // Bug see Bugzilla 26741
+ fLocator.setSystemId(
+ System.getProperty("user.dir") + File.separator + "dummy.xsl");
+ } catch (SecurityException se) { // user.dir not accessible from applet
+
+ }
+ }
+
+ /**
+ * Perform a pre-order traversal non-recursive style.
+ *
+ * Note that TreeWalker assumes that the subtree is intended to represent
+ * a complete (though not necessarily well-formed) document and, during a
+ * traversal, startDocument and endDocument will always be issued to the
+ * SAX listener.
+ *
+ * @param pos Node in the tree where to start traversal
+ *
+ * @throws TransformerException
+ */
+ public void traverse(Node pos) throws org.xml.sax.SAXException {
+ this.fSerializer.startDocument();
+
+ // Determine if the Node is a DOM Level 3 Core Node.
+ if (pos.getNodeType() != Node.DOCUMENT_NODE) {
+ Document ownerDoc = pos.getOwnerDocument();
+ if (ownerDoc != null
+ && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
+ fIsLevel3DOM = true;
+ }
+ } else {
+ if (((Document) pos)
+ .getImplementation()
+ .hasFeature("Core", "3.0")) {
+ fIsLevel3DOM = true;
+ }
+ }
+
+ if (fSerializer instanceof LexicalHandler) {
+ fLexicalHandler = ((LexicalHandler) this.fSerializer);
+ }
+
+ if (fFilter != null)
+ fWhatToShowFilter = fFilter.getWhatToShow();
+
+ Node top = pos;
+
+ while (null != pos) {
+ startNode(pos);
+
+ Node nextNode = null;
+
+ nextNode = pos.getFirstChild();
+
+ while (null == nextNode) {
+ endNode(pos);
+
+ if (top.equals(pos))
+ break;
+
+ nextNode = pos.getNextSibling();
+
+ if (null == nextNode) {
+ pos = pos.getParentNode();
+
+ if ((null == pos) || (top.equals(pos))) {
+ if (null != pos)
+ endNode(pos);
+
+ nextNode = null;
+
+ break;
+ }
+ }
+ }
+
+ pos = nextNode;
+ }
+ this.fSerializer.endDocument();
+ }
+
+ /**
+ * Perform a pre-order traversal non-recursive style.
+
+ * Note that TreeWalker assumes that the subtree is intended to represent
+ * a complete (though not necessarily well-formed) document and, during a
+ * traversal, startDocument and endDocument will always be issued to the
+ * SAX listener.
+ *
+ * @param pos Node in the tree where to start traversal
+ * @param top Node in the tree where to end traversal
+ *
+ * @throws TransformerException
+ */
+ public void traverse(Node pos, Node top) throws org.xml.sax.SAXException {
+
+ this.fSerializer.startDocument();
+
+ // Determine if the Node is a DOM Level 3 Core Node.
+ if (pos.getNodeType() != Node.DOCUMENT_NODE) {
+ Document ownerDoc = pos.getOwnerDocument();
+ if (ownerDoc != null
+ && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
+ fIsLevel3DOM = true;
+ }
+ } else {
+ if (((Document) pos)
+ .getImplementation()
+ .hasFeature("Core", "3.0")) {
+ fIsLevel3DOM = true;
+ }
+ }
+
+ if (fSerializer instanceof LexicalHandler) {
+ fLexicalHandler = ((LexicalHandler) this.fSerializer);
+ }
+
+ if (fFilter != null)
+ fWhatToShowFilter = fFilter.getWhatToShow();
+
+ while (null != pos) {
+ startNode(pos);
+
+ Node nextNode = null;
+
+ nextNode = pos.getFirstChild();
+
+ while (null == nextNode) {
+ endNode(pos);
+
+ if ((null != top) && top.equals(pos))
+ break;
+
+ nextNode = pos.getNextSibling();
+
+ if (null == nextNode) {
+ pos = pos.getParentNode();
+
+ if ((null == pos) || ((null != top) && top.equals(pos))) {
+ nextNode = null;
+
+ break;
+ }
+ }
+ }
+
+ pos = nextNode;
+ }
+ this.fSerializer.endDocument();
+ }
+
+ /**
+ * Optimized dispatch of characters.
+ */
+ private final void dispatachChars(Node node)
+ throws org.xml.sax.SAXException {
+ if (fSerializer != null) {
+ this.fSerializer.characters(node);
+ } else {
+ String data = ((Text) node).getData();
+ this.fSerializer.characters(data.toCharArray(), 0, data.length());
+ }
+ }
+
+ /**
+ * Start processing given node
+ *
+ * @param node Node to process
+ *
+ * @throws org.xml.sax.SAXException
+ */
+ protected void startNode(Node node) throws org.xml.sax.SAXException {
+ if (node instanceof Locator) {
+ Locator loc = (Locator) node;
+ fLocator.setColumnNumber(loc.getColumnNumber());
+ fLocator.setLineNumber(loc.getLineNumber());
+ fLocator.setPublicId(loc.getPublicId());
+ fLocator.setSystemId(loc.getSystemId());
+ } else {
+ fLocator.setColumnNumber(0);
+ fLocator.setLineNumber(0);
+ }
+
+ switch (node.getNodeType()) {
+ case Node.DOCUMENT_TYPE_NODE :
+ serializeDocType((DocumentType) node, true);
+ break;
+ case Node.COMMENT_NODE :
+ serializeComment((Comment) node);
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE :
+ // Children are traversed
+ break;
+ case Node.DOCUMENT_NODE :
+ break;
+ case Node.ELEMENT_NODE :
+ serializeElement((Element) node, true);
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ serializePI((ProcessingInstruction) node);
+ break;
+ case Node.CDATA_SECTION_NODE :
+ serializeCDATASection((CDATASection) node);
+ break;
+ case Node.TEXT_NODE :
+ serializeText((Text) node);
+ break;
+ case Node.ENTITY_REFERENCE_NODE :
+ serializeEntityReference((EntityReference) node, true);
+ break;
+ default :
+ }
+ }
+
+ /**
+ * End processing of given node
+ *
+ *
+ * @param node Node we just finished processing
+ *
+ * @throws org.xml.sax.SAXException
+ */
+ protected void endNode(Node node) throws org.xml.sax.SAXException {
+
+ switch (node.getNodeType()) {
+ case Node.DOCUMENT_NODE :
+ break;
+ case Node.DOCUMENT_TYPE_NODE :
+ serializeDocType((DocumentType) node, false);
+ break;
+ case Node.ELEMENT_NODE :
+ serializeElement((Element) node, false);
+ break;
+ case Node.CDATA_SECTION_NODE :
+ break;
+ case Node.ENTITY_REFERENCE_NODE :
+ serializeEntityReference((EntityReference) node, false);
+ break;
+ default :
+ }
+ }
+
+ // ***********************************************************************
+ // Node serialization methods
+ // ***********************************************************************
+ /**
+ * Applies a filter on the node to serialize
+ *
+ * @param node The Node to serialize
+ * @return True if the node is to be serialized else false if the node
+ * is to be rejected or skipped.
+ */
+ protected boolean applyFilter(Node node, int nodeType) {
+ if (fFilter != null && (fWhatToShowFilter & nodeType) != 0) {
+
+ short code = fFilter.acceptNode(node);
+ switch (code) {
+ case NodeFilter.FILTER_REJECT :
+ case NodeFilter.FILTER_SKIP :
+ return false; // skip the node
+ default : // fall through..
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Serializes a Document Type Node.
+ *
+ * @param node The Docuemnt Type Node to serialize
+ * @param bStart Invoked at the start or end of node. Default true.
+ */
+ protected void serializeDocType(DocumentType node, boolean bStart)
+ throws SAXException {
+ // The DocType and internalSubset can not be modified in DOM and is
+ // considered to be well-formed as the outcome of successful parsing.
+ String docTypeName = node.getNodeName();
+ String publicId = node.getPublicId();
+ String systemId = node.getSystemId();
+ String internalSubset = node.getInternalSubset();
+
+ //DocumentType nodes are never passed to the filter
+
+ if (internalSubset != null && !"".equals(internalSubset)) {
+
+ if (bStart) {
+ try {
+ // The Serializer does not provide a way to write out the
+ // DOCTYPE internal subset via an event call, so we write it
+ // out here.
+ Writer writer = fSerializer.getWriter();
+ StringBuffer dtd = new StringBuffer();
+
+ dtd.append("");
+ dtd.append(fNewLine);
+
+ writer.write(dtd.toString());
+ writer.flush();
+
+ } catch (IOException e) {
+ throw new SAXException(Utils.messages.createMessage(
+ MsgKey.ER_WRITING_INTERNAL_SUBSET, null), e);
+ }
+ } // else if !bStart do nothing
+
+ } else {
+
+ if (bStart) {
+ if (fLexicalHandler != null) {
+ fLexicalHandler.startDTD(docTypeName, publicId, systemId);
+ }
+ } else {
+ if (fLexicalHandler != null) {
+ fLexicalHandler.endDTD();
+ }
+ }
+ }
+ }
+
+ /**
+ * Serializes a Comment Node.
+ *
+ * @param node The Comment Node to serialize
+ */
+ protected void serializeComment(Comment node) throws SAXException {
+ // comments=true
+ if ((fFeatures & COMMENTS) != 0) {
+ String data = node.getData();
+
+ // well-formed=true
+ if ((fFeatures & WELLFORMED) != 0) {
+ isCommentWellFormed(data);
+ }
+
+ if (fLexicalHandler != null) {
+ // apply the LSSerializer filter after the operations requested by the
+ // DOMConfiguration parameters have been applied
+ if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) {
+ return;
+ }
+
+ fLexicalHandler.comment(data.toCharArray(), 0, data.length());
+ }
+ }
+ }
+
+ /**
+ * Serializes an Element Node.
+ *
+ * @param node The Element Node to serialize
+ * @param bStart Invoked at the start or end of node.
+ */
+ protected void serializeElement(Element node, boolean bStart)
+ throws SAXException {
+ if (bStart) {
+ fElementDepth++;
+
+ // We use the Xalan specific startElement and starPrefixMapping calls
+ // (and addAttribute and namespaceAfterStartElement) as opposed to
+ // SAX specific, for performance reasons as they reduce the overhead
+ // of creating an AttList object upfront.
+
+ // well-formed=true
+ if ((fFeatures & WELLFORMED) != 0) {
+ isElementWellFormed(node);
+ }
+
+ // REVISIT: We apply the LSSerializer filter for elements before
+ // namesapce fixup
+ if (!applyFilter(node, NodeFilter.SHOW_ELEMENT)) {
+ return;
+ }
+
+ // namespaces=true, record and fixup namspaced element
+ if ((fFeatures & NAMESPACES) != 0) {
+ fNSBinder.pushContext();
+ fLocalNSBinder.reset();
+
+ recordLocalNSDecl(node);
+ fixupElementNS(node);
+ }
+
+ // Namespace normalization
+ fSerializer.startElement(
+ node.getNamespaceURI(),
+ node.getLocalName(),
+ node.getNodeName());
+
+ serializeAttList(node);
+
+ } else {
+ fElementDepth--;
+
+ // apply the LSSerializer filter
+ if (!applyFilter(node, NodeFilter.SHOW_ELEMENT)) {
+ return;
+ }
+
+ this.fSerializer.endElement(
+ node.getNamespaceURI(),
+ node.getLocalName(),
+ node.getNodeName());
+ // since endPrefixMapping was not used by SerializationHandler it was removed
+ // for performance reasons.
+
+ if ((fFeatures & NAMESPACES) != 0 ) {
+ fNSBinder.popContext();
+ }
+
+ }
+ }
+
+ /**
+ * Serializes the Attr Nodes of an Element.
+ *
+ * @param node The OwnerElement whose Attr Nodes are to be serialized.
+ */
+ protected void serializeAttList(Element node) throws SAXException {
+ NamedNodeMap atts = node.getAttributes();
+ int nAttrs = atts.getLength();
+
+ for (int i = 0; i < nAttrs; i++) {
+ Node attr = atts.item(i);
+
+ String localName = attr.getLocalName();
+ String attrName = attr.getNodeName();
+ String attrPrefix = attr.getPrefix() == null ? "" : attr.getPrefix();
+ String attrValue = attr.getNodeValue();
+
+ // Determine the Attr's type.
+ String type = null;
+ if (fIsLevel3DOM) {
+ type = ((Attr) attr).getSchemaTypeInfo().getTypeName();
+ }
+ type = type == null ? "CDATA" : type;
+
+ String attrNS = attr.getNamespaceURI();
+ if (attrNS !=null && attrNS.length() == 0) {
+ attrNS=null;
+ // we must remove prefix for this attribute
+ attrName=attr.getLocalName();
+ }
+
+ boolean isSpecified = ((Attr) attr).getSpecified();
+ boolean addAttr = true;
+ boolean applyFilter = false;
+ boolean xmlnsAttr =
+ attrName.equals("xmlns") || attrName.startsWith("xmlns:");
+
+ // well-formed=true
+ if ((fFeatures & WELLFORMED) != 0) {
+ isAttributeWellFormed(attr);
+ }
+
+ //-----------------------------------------------------------------
+ // start Attribute namespace fixup
+ //-----------------------------------------------------------------
+ // namespaces=true, normalize all non-namespace attributes
+ // Step 3. Attribute
+ if ((fFeatures & NAMESPACES) != 0 && !xmlnsAttr) {
+
+ // If the Attr has a namespace URI
+ if (attrNS != null) {
+ attrPrefix = attrPrefix == null ? "" : attrPrefix;
+
+ String declAttrPrefix = fNSBinder.getPrefix(attrNS);
+ String declAttrNS = fNSBinder.getURI(attrPrefix);
+
+ // attribute has no prefix (default namespace decl does not apply to
+ // attributes)
+ // OR
+ // attribute prefix is not declared
+ // OR
+ // conflict: attribute has a prefix that conflicts with a binding
+ if ("".equals(attrPrefix) || "".equals(declAttrPrefix)
+ || !attrPrefix.equals(declAttrPrefix)) {
+
+ // namespaceURI matches an in scope declaration of one or
+ // more prefixes
+ if (declAttrPrefix != null && !"".equals(declAttrPrefix)) {
+ // pick the prefix that was found and change attribute's
+ // prefix and nodeName.
+ attrPrefix = declAttrPrefix;
+
+ if (declAttrPrefix.length() > 0 ) {
+ attrName = declAttrPrefix + ":" + localName;
+ } else {
+ attrName = localName;
+ }
+ } else {
+ // The current prefix is not null and it has no in scope
+ // declaration
+ if (attrPrefix != null && !"".equals(attrPrefix)
+ && declAttrNS == null) {
+ // declare this prefix
+ if ((fFeatures & NAMESPACEDECLS) != 0) {
+ fSerializer.addAttribute(XMLNS_URI, attrPrefix,
+ XMLNS_PREFIX + ":" + attrPrefix, "CDATA",
+ attrNS);
+ fNSBinder.declarePrefix(attrPrefix, attrNS);
+ fLocalNSBinder.declarePrefix(attrPrefix, attrNS);
+ }
+ } else {
+ // find a prefix following the pattern "NS" +index
+ // (starting at 1)
+ // make sure this prefix is not declared in the current
+ // scope.
+ int counter = 1;
+ attrPrefix = "NS" + counter++;
+
+ while (fLocalNSBinder.getURI(attrPrefix) != null) {
+ attrPrefix = "NS" + counter++;
+ }
+ // change attribute's prefix and Name
+ attrName = attrPrefix + ":" + localName;
+
+ // create a local namespace declaration attribute
+ // Add the xmlns declaration attribute
+ if ((fFeatures & NAMESPACEDECLS) != 0) {
+
+ fSerializer.addAttribute(XMLNS_URI, attrPrefix,
+ XMLNS_PREFIX + ":" + attrPrefix, "CDATA",
+ attrNS);
+ fNSBinder.declarePrefix(attrPrefix, attrNS);
+ fLocalNSBinder.declarePrefix(attrPrefix, attrNS);
+ }
+ }
+ }
+ }
+
+ } else { // if the Attr has no namespace URI
+ // Attr has no localName
+ if (localName == null) {
+ // DOM Level 1 node!
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_NULL_LOCAL_ELEMENT_NAME,
+ new Object[] { attrName });
+
+ if (fErrorHandler != null) {
+ fErrorHandler
+ .handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_ERROR, msg,
+ MsgKey.ER_NULL_LOCAL_ELEMENT_NAME, null,
+ null, null));
+ }
+
+ } else { // uri=null and no colon
+ // attr has no namespace URI and no prefix
+ // no action is required, since attrs don't use default
+ }
+ }
+
+ }
+
+
+ // discard-default-content=true
+ // Default attr's are not passed to the filter and this contraint
+ // is applied only when discard-default-content=true
+ // What about default xmlns attributes???? check for xmlnsAttr
+ if ((((fFeatures & DISCARDDEFAULT) != 0) && isSpecified)
+ || ((fFeatures & DISCARDDEFAULT) == 0)) {
+ applyFilter = true;
+ } else {
+ addAttr = false;
+ }
+
+ if (applyFilter) {
+ // apply the filter for Attributes that are not default attributes
+ // or namespace decl attributes
+ if (fFilter != null
+ && (fFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)
+ != 0) {
+
+ if (!xmlnsAttr) {
+ short code = fFilter.acceptNode(attr);
+ switch (code) {
+ case NodeFilter.FILTER_REJECT :
+ case NodeFilter.FILTER_SKIP :
+ addAttr = false;
+ break;
+ default : //fall through..
+ }
+ }
+ }
+ }
+
+ // if the node is a namespace node
+ if (addAttr && xmlnsAttr) {
+ // If namespace-declarations=true, add the node , else don't add it
+ if ((fFeatures & NAMESPACEDECLS) != 0) {
+ // The namespace may have been fixed up, in that case don't add it.
+ if (localName != null && !"".equals(localName)) {
+ fSerializer.addAttribute(attrNS, localName, attrName, type, attrValue);
+ }
+ }
+ } else if (
+ addAttr && !xmlnsAttr) { // if the node is not a namespace node
+ // If namespace-declarations=true, add the node with the Attr nodes namespaceURI
+ // else add the node setting it's namespace to null or else the serializer will later
+ // attempt to add a xmlns attr for the prefixed attribute
+ if (((fFeatures & NAMESPACEDECLS) != 0) && (attrNS != null)) {
+ fSerializer.addAttribute(
+ attrNS,
+ localName,
+ attrName,
+ type,
+ attrValue);
+ } else {
+ fSerializer.addAttribute(
+ "",
+ localName,
+ attrName,
+ type,
+ attrValue);
+ }
+ }
+
+ //
+ if (xmlnsAttr && ((fFeatures & NAMESPACEDECLS) != 0)) {
+ int index;
+ // Use "" instead of null, as Xerces likes "" for the
+ // name of the default namespace. Fix attributed
+ // to "Steven Murray" See also the DOMError Interface definition from Document Object Model (DOM) Level 3 Core Specification.
+ *
+ * @xsl.usage internal
+ */
+
+final class DOMErrorImpl implements DOMError {
+
+ /** private data members */
+
+ // The DOMError Severity
+ private short fSeverity = DOMError.SEVERITY_WARNING;
+
+ // The Error message
+ private String fMessage = null;
+
+ // A String indicating which related data is expected in relatedData.
+ private String fType;
+
+ // The platform related exception
+ private Exception fException = null;
+
+ //
+ private Object fRelatedData;
+
+ // The location of the exception
+ private DOMLocatorImpl fLocation = new DOMLocatorImpl();
+
+
+ //
+ // Constructors
+ //
+
+ /**
+ * Default constructor.
+ */
+ DOMErrorImpl () {
+ }
+
+ /**
+ * @param severity
+ * @param message
+ * @param type
+ */
+ DOMErrorImpl(short severity, String message, String type) {
+ fSeverity = severity;
+ fMessage = message;
+ fType = type;
+ }
+
+ /**
+ * @param severity
+ * @param message
+ * @param type
+ * @param exception
+ */
+ DOMErrorImpl(short severity, String message, String type,
+ Exception exception) {
+ fSeverity = severity;
+ fMessage = message;
+ fType = type;
+ fException = exception;
+ }
+
+ /**
+ * @param severity
+ * @param message
+ * @param type
+ * @param exception
+ * @param relatedData
+ * @param location
+ */
+ DOMErrorImpl(short severity, String message, String type,
+ Exception exception, Object relatedData, DOMLocatorImpl location) {
+ fSeverity = severity;
+ fMessage = message;
+ fType = type;
+ fException = exception;
+ fRelatedData = relatedData;
+ fLocation = location;
+ }
+
+
+ /**
+ * The severity of the error, either See also the Document Object Model (DOM) Level 3 Core Specification.
+ * This class is a copy of the Xerces-2J class org.apache.xerces.dom.DOMLocatorImpl.java v 1.10
+ *
+ * @author Gopal Sharma, SUN Microsystems Inc.
+ * @version $Id:
+ *
+ * @xsl.usage internal
+ */
+final class DOMLocatorImpl implements DOMLocator {
+
+ //
+ // Data
+ //
+
+ /**
+ * The column number where the error occured,
+ * or -1 if there is no column number available.
+ */
+ private final int fColumnNumber;
+
+ /**
+ * The line number where the error occured,
+ * or -1 if there is no line number available.
+ */
+ private final int fLineNumber;
+
+ /** related data node*/
+ private final Node fRelatedNode;
+
+ /**
+ * The URI where the error occured,
+ * or null if there is no URI available.
+ */
+ private final String fUri;
+
+ /**
+ * The byte offset into the input source this locator is pointing to or -1
+ * if there is no byte offset available
+ */
+ private final int fByteOffset;
+
+ /**
+ * The UTF-16, as defined in [Unicode] and Amendment 1 of [ISO/IEC 10646],
+ * offset into the input source this locator is pointing to or -1 if there
+ * is no UTF-16 offset available.
+ */
+ private final int fUtf16Offset;
+
+ //
+ // Constructors
+ //
+
+ DOMLocatorImpl(){
+ fColumnNumber = -1;
+ fLineNumber = -1;
+ fRelatedNode = null;
+ fUri = null;
+ fByteOffset = -1;
+ fUtf16Offset = -1;
+ }
+
+ DOMLocatorImpl (int lineNumber, int columnNumber, String uri ){
+ fLineNumber = lineNumber ;
+ fColumnNumber = columnNumber ;
+ fUri = uri;
+
+ fRelatedNode = null;
+ fByteOffset = -1;
+ fUtf16Offset = -1;
+ } // DOMLocatorImpl (int lineNumber, int columnNumber, String uri )
+
+ DOMLocatorImpl (int lineNumber, int columnNumber, int utf16Offset, String uri ){
+ fLineNumber = lineNumber ;
+ fColumnNumber = columnNumber ;
+ fUri = uri;
+ fUtf16Offset = utf16Offset;
+
+
+ fRelatedNode = null;
+ fByteOffset = -1;
+ } // DOMLocatorImpl (int lineNumber, int columnNumber, int utf16Offset, String uri )
+
+ DOMLocatorImpl (int lineNumber, int columnNumber, int byteoffset, Node relatedData, String uri ){
+ fLineNumber = lineNumber ;
+ fColumnNumber = columnNumber ;
+ fByteOffset = byteoffset ;
+ fRelatedNode = relatedData ;
+ fUri = uri;
+
+ fUtf16Offset = -1;
+ } // DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node errorNode, String uri )
+
+ DOMLocatorImpl (int lineNumber, int columnNumber, int byteoffset, Node relatedData, String uri, int utf16Offset ){
+ fLineNumber = lineNumber ;
+ fColumnNumber = columnNumber ;
+ fByteOffset = byteoffset ;
+ fRelatedNode = relatedData ;
+ fUri = uri;
+ fUtf16Offset = utf16Offset;
+ } // DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node errorNode, String uri )
+
+
+ /**
+ * The line number where the error occured, or -1 if there is no line
+ * number available.
+ */
+ public int getLineNumber(){
+ return fLineNumber;
+ }
+
+ /**
+ * The column number where the error occured, or -1 if there is no column
+ * number available.
+ */
+ public int getColumnNumber(){
+ return fColumnNumber;
+ }
+
+
+ /**
+ * The URI where the error occured, or null if there is no URI available.
+ */
+ public String getUri(){
+ return fUri;
+ }
+
+
+ public Node getRelatedNode(){
+ return fRelatedNode;
+ }
+
+
+ /**
+ * The byte offset into the input source this locator is pointing to or -1
+ * if there is no byte offset available
+ */
+ public int getByteOffset(){
+ return fByteOffset;
+ }
+
+ /**
+ * The UTF-16, as defined in [Unicode] and Amendment 1 of [ISO/IEC 10646],
+ * offset into the input source this locator is pointing to or -1 if there
+ * is no UTF-16 offset available.
+ */
+ public int getUtf16Offset(){
+ return fUtf16Offset;
+ }
+
+}// class DOMLocatorImpl
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMOutputImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMOutputImpl.java
new file mode 100644
index 00000000000..d6c0a5d59a8
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMOutputImpl.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import org.w3c.dom.ls.LSOutput;
+
+import java.io.Writer;
+import java.io.OutputStream;
+
+/**
+ * This is a copy of the Xerces-2J class org.apache.xerces.dom.DOMOutputImpl.java
+ *
+ * This class represents an output destination for data.
+ * This interface allows an application to encapsulate information about an
+ * output destination in a single object, which may include a URI, a byte stream
+ * (possibly with a specifiedencoding), a base URI, and/or a character stream.
+ * The exact definitions of a byte stream and a character stream are binding
+ * dependent.
+ * The application is expected to provide objects that implement this interface
+ * whenever such objects are needed. The application can either provide its
+ * own objects that implement this interface, or it can use the generic factory
+ * method DOMImplementationLS.createLSOutput() to create objects that
+ * implement this interface.
+ * The DOMSerializer will use the LSOutput object to determine where to
+ * serialize the output to. The DOMSerializer will look at the different
+ * outputs specified in the LSOutput in the following order to know which one
+ * to output to, the first one that data can be output to will be used:
+ * 1.LSOutput.characterStream
+ * 2.LSOutput.byteStream
+ * 3.LSOutput.systemId
+ * LSOutput objects belong to the application. The DOM implementation will
+ * never modify them (though it may make copies and modify the copies,
+ * if necessary).
+ *
+ *
+ * @author Arun Yadav, Sun Microsytems
+ * @author Gopal Sharma, Sun Microsystems
+ * @version $Id :
+ * @xsl.usage internal
+ */
+
+final class DOMOutputImpl implements LSOutput {
+
+ private Writer fCharStream = null;
+ private OutputStream fByteStream = null;
+ private String fSystemId = null;
+ private String fEncoding = null;
+
+ /**
+ * Default Constructor
+ */
+ DOMOutputImpl() {}
+
+ /**
+ * An attribute of a language and binding dependent type that represents a
+ * writable stream of bytes. If the application knows the character encoding
+ * of the byte stream, it should set the encoding attribute. Setting the
+ * encoding in this way will override any encoding specified in an XML
+ * declaration in the data.
+ */
+
+ public Writer getCharacterStream(){
+ return fCharStream;
+ };
+
+ /**
+ * An attribute of a language and binding dependent type that represents a
+ * writable stream of bytes. If the application knows the character encoding
+ * of the byte stream, it should set the encoding attribute. Setting the
+ * encoding in this way will override any encoding specified in an XML
+ * declaration in the data.
+ */
+
+ public void setCharacterStream(Writer characterStream){
+ fCharStream = characterStream;
+ };
+
+ /**
+ * Depending on the language binding in use, this attribute may not be
+ * available. An attribute of a language and binding dependent type that
+ * represents a writable stream to which 16-bit units can be output. The
+ * application must encode the stream using UTF-16 (defined in [Unicode] and
+ * Amendment 1 of [ISO/IEC 10646]).
+ */
+
+ public OutputStream getByteStream(){
+ return fByteStream;
+ };
+
+ /**
+ * Depending on the language binding in use, this attribute may not be
+ * available. An attribute of a language and binding dependent type that
+ * represents a writable stream to which 16-bit units can be output. The
+ * application must encode the stream using UTF-16 (defined in [Unicode] and
+ * Amendment 1 of [ISO/IEC 10646]).
+ */
+
+ public void setByteStream(OutputStream byteStream){
+ fByteStream = byteStream;
+ };
+
+ /**
+ * The system identifier, a URI reference [IETF RFC 2396], for this output
+ * destination. If the application knows the character encoding of the
+ * object pointed to by the system identifier, it can set the encoding
+ * using the encoding attribute. If the system ID is a relative URI
+ * reference (see section 5 in [IETF RFC 2396]), the behavior is
+ * implementation dependent.
+ */
+
+ public String getSystemId(){
+ return fSystemId;
+ };
+
+ /**
+ * The system identifier, a URI reference [IETF RFC 2396], for this output
+ * destination. If the application knows the character encoding of the
+ * object pointed to by the system identifier, it can set the encoding
+ * using the encoding attribute. If the system ID is a relative URI
+ * reference (see section 5 in [IETF RFC 2396]), the behavior is
+ * implementation dependent.
+ */
+
+ public void setSystemId(String systemId){
+ fSystemId = systemId;
+ };
+
+ /**
+ * The character encoding, if known. The encoding must be a string
+ * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
+ * "Character Encoding in Entities"). This attribute has no effect when the
+ * application provides a character stream or string data. For other sources
+ * of input, an encoding specified by means of this attribute will override
+ * any encoding specified in the XML declaration or the Text declaration, or
+ * an encoding obtained from a higher level protocol, such as HTTP
+ * [IETF RFC 2616].
+ */
+
+ public String getEncoding(){
+ return fEncoding;
+ };
+
+ /**
+ * The character encoding, if known. The encoding must be a string
+ * acceptable for an XML encoding declaration ([XML 1.0] section 4.3.3
+ * "Character Encoding in Entities"). This attribute has no effect when the
+ * application provides a character stream or string data. For other sources
+ * of input, an encoding specified by means of this attribute will override
+ * any encoding specified in the XML declaration or the Text declaration, or
+ * an encoding obtained from a higher level protocol, such as HTTP
+ * [IETF RFC 2616].
+ */
+
+ public void setEncoding(String encoding){
+ fEncoding = encoding;
+ };
+
+}//DOMOutputImpl
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMStringListImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMStringListImpl.java
new file mode 100644
index 00000000000..11eac2aa2e8
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMStringListImpl.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import java.util.Vector;
+
+//import org.apache.xerces.dom3.DOMStringList;
+import org.w3c.dom.DOMStringList;
+
+/**
+ * This class implemets the DOM Level 3 Core interface DOMStringList.
+ *
+ * @xsl.usage internal
+ */
+final class DOMStringListImpl implements DOMStringList {
+
+ //A collection of DOMString values
+ private Vector fStrings;
+
+ /**
+ * Construct an empty list of DOMStringListImpl
+ */
+ DOMStringListImpl() {
+ fStrings = new Vector();
+ }
+
+ /**
+ * Construct an empty list of DOMStringListImpl
+ */
+ DOMStringListImpl(Vector params) {
+ fStrings = params;
+ }
+
+ /**
+ * Construct an empty list of DOMStringListImpl
+ */
+ DOMStringListImpl(String[] params ) {
+ fStrings = new Vector();
+ if (params != null) {
+ for (int i=0; i < params.length; i++) {
+ fStrings.add(params[i]);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.xerces.dom3.DOMStringList#item(int)
+ */
+ public String item(int index) {
+ try {
+ return (String) fStrings.elementAt(index);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @see org.apache.xerces.dom3.DOMStringList#getLength()
+ */
+ public int getLength() {
+ return fStrings.size();
+ }
+
+ /**
+ * @see org.apache.xerces.dom3.DOMStringList#contains(String)
+ */
+ public boolean contains(String param) {
+ return fStrings.contains(param) ;
+ }
+
+ /**
+ * DOM Internal:
+ * Add a See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface DocumentRange {
/**
diff --git a/jaxp/src/org/w3c/dom/ranges/Range.java b/jaxp/src/org/w3c/dom/ranges/Range.java
index d42fad0c0fe..0efefe21945 100644
--- a/jaxp/src/org/w3c/dom/ranges/Range.java
+++ b/jaxp/src/org/w3c/dom/ranges/Range.java
@@ -47,7 +47,7 @@ import org.w3c.dom.DocumentFragment;
/**
* See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface Range {
/**
diff --git a/jaxp/src/org/w3c/dom/ranges/RangeException.java b/jaxp/src/org/w3c/dom/ranges/RangeException.java
index 198a135111c..69551a81c95 100644
--- a/jaxp/src/org/w3c/dom/ranges/RangeException.java
+++ b/jaxp/src/org/w3c/dom/ranges/RangeException.java
@@ -45,7 +45,7 @@ package org.w3c.dom.ranges;
* Range operations may throw a See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public class RangeException extends RuntimeException {
public RangeException(short code, String message) {
diff --git a/jaxp/src/org/w3c/dom/traversal/DocumentTraversal.java b/jaxp/src/org/w3c/dom/traversal/DocumentTraversal.java
index 80938886afe..bbb53740235 100644
--- a/jaxp/src/org/w3c/dom/traversal/DocumentTraversal.java
+++ b/jaxp/src/org/w3c/dom/traversal/DocumentTraversal.java
@@ -53,7 +53,7 @@ import org.w3c.dom.DOMException;
* Traversal feature, See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface DocumentTraversal {
/**
diff --git a/jaxp/src/org/w3c/dom/traversal/NodeFilter.java b/jaxp/src/org/w3c/dom/traversal/NodeFilter.java
index e6f22b2b917..5cc8177eeac 100644
--- a/jaxp/src/org/w3c/dom/traversal/NodeFilter.java
+++ b/jaxp/src/org/w3c/dom/traversal/NodeFilter.java
@@ -59,7 +59,7 @@ import org.w3c.dom.Node;
* filter may be used with a number of different kinds of traversals,
* encouraging code reuse.
* See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface NodeFilter {
// Constants returned by acceptNode
diff --git a/jaxp/src/org/w3c/dom/traversal/NodeIterator.java b/jaxp/src/org/w3c/dom/traversal/NodeIterator.java
index 0f6aebf0821..70ef322254f 100644
--- a/jaxp/src/org/w3c/dom/traversal/NodeIterator.java
+++ b/jaxp/src/org/w3c/dom/traversal/NodeIterator.java
@@ -55,7 +55,7 @@ import org.w3c.dom.DOMException;
* See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface NodeIterator {
/**
diff --git a/jaxp/src/org/w3c/dom/traversal/TreeWalker.java b/jaxp/src/org/w3c/dom/traversal/TreeWalker.java
index f0876e5206d..262fd96d167 100644
--- a/jaxp/src/org/w3c/dom/traversal/TreeWalker.java
+++ b/jaxp/src/org/w3c/dom/traversal/TreeWalker.java
@@ -60,7 +60,7 @@ import org.w3c.dom.DOMException;
* nodes will be siblings and appear as direct children of the root node, no
* matter how deeply nested the structure of the original document.
* See also the Document Object Model (DOM) Level 2 Traversal and Range Specification.
- * @since DOM Level 2
+ * @since 1.9, DOM Level 2
*/
public interface TreeWalker {
/**
SEVERITY_WARNING
,
+ * SEVERITY_ERROR
, or SEVERITY_FATAL_ERROR
.
+ *
+ * @return A short containing the DOMError severity
+ */
+ public short getSeverity() {
+ return fSeverity;
+ }
+
+ /**
+ * The DOMError message string.
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return fMessage;
+ }
+
+ /**
+ * The location of the DOMError.
+ *
+ * @return A DOMLocator object containing the DOMError location.
+ */
+ public DOMLocator getLocation() {
+ return fLocation;
+ }
+
+ /**
+ * The related platform dependent exception if any.
+ *
+ * @return A java.lang.Exception
+ */
+ public Object getRelatedException(){
+ return fException;
+ }
+
+ /**
+ * Returns a String indicating which related data is expected in relatedData.
+ *
+ * @return A String
+ */
+ public String getType(){
+ return fType;
+ }
+
+ /**
+ * The related DOMError.type dependent data if any.
+ *
+ * @return java.lang.Object
+ */
+ public Object getRelatedData(){
+ return fRelatedData;
+ }
+
+ public void reset(){
+ fSeverity = DOMError.SEVERITY_WARNING;
+ fException = null;
+ fMessage = null;
+ fType = null;
+ fRelatedData = null;
+ fLocation = null;
+ }
+
+}// class DOMErrorImpl
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMLocatorImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMLocatorImpl.java
new file mode 100644
index 00000000000..f0e87c340f4
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/DOMLocatorImpl.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import org.w3c.dom.DOMLocator;
+import org.w3c.dom.Node;
+
+
+/**
+ * DOMLocatorImpl
is an implementaion that describes a location (e.g.
+ * where an error occured).
+ * DOMString
to the list.
+ *
+ * @param domString A string to add to the list
+ */
+ public void add(String param) {
+ fStrings.add(param);
+ }
+
+}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java
new file mode 100644
index 00000000000..5ab43abad0e
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java
@@ -0,0 +1,1405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import com.sun.org.apache.xml.internal.serializer.DOM3Serializer;
+import com.sun.org.apache.xml.internal.serializer.Encodings;
+import com.sun.org.apache.xml.internal.serializer.Serializer;
+import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory;
+import com.sun.org.apache.xml.internal.serializer.SerializerFactory;
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver;
+import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.DOMError;
+import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.DOMStringList;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.ls.LSException;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+import org.w3c.dom.ls.LSSerializerFilter;
+
+
+/**
+ * Implemenatation of DOM Level 3 org.w3c.ls.LSSerializer and
+ * org.w3c.dom.ls.DOMConfiguration. Serialization is achieved by delegating
+ * serialization calls to org.apache.xml.serializer.ToStream
or
+ * one of its derived classes depending on the serialization method, while walking
+ * the DOM in DOM3TreeWalker.
+ * @see org.w3c.dom.ls.LSSerializer
+ * @see org.w3c.dom.DOMConfiguration
+ *
+ * @version $Id:
+ *
+ * @xsl.usage internal
+ */
+final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
+
+ /** private data members */
+ private Serializer fXMLSerializer = null;
+
+ // Tracks DOMConfiguration features.
+ protected int fFeatures = 0;
+
+ // Common DOM serializer
+ private DOM3Serializer fDOMSerializer = null;
+
+ // A filter set on the LSSerializer
+ private LSSerializerFilter fSerializerFilter = null;
+
+ // Stores the nodeArg parameter to speed up multiple writes of the same node.
+ private Node fVisitedNode = null;
+
+ // The end-of-line character sequence used in serialization. "\n" is whats used on the web.
+ private String fEndOfLine = "\n";
+
+ // The DOMErrorhandler.
+ private DOMErrorHandler fDOMErrorHandler = null;
+
+ // The Configuration parameter to pass to the Underlying serilaizer.
+ private Properties fDOMConfigProperties = null;
+
+ // The encoding to use during serialization.
+ private String fEncoding;
+
+ // ************************************************************************
+ // DOM Level 3 DOM Configuration parameter names
+ // ************************************************************************
+ // Parameter canonical-form, true [optional] - NOT SUPPORTED
+ private final static int CANONICAL = 0x1 << 0;
+
+ // Parameter cdata-sections, true [required] (default)
+ private final static int CDATA = 0x1 << 1;
+
+ // Parameter check-character-normalization, true [optional] - NOT SUPPORTED
+ private final static int CHARNORMALIZE = 0x1 << 2;
+
+ // Parameter comments, true [required] (default)
+ private final static int COMMENTS = 0x1 << 3;
+
+ // Parameter datatype-normalization, true [optional] - NOT SUPPORTED
+ private final static int DTNORMALIZE = 0x1 << 4;
+
+ // Parameter element-content-whitespace, true [required] (default) - value - false [optional] NOT SUPPORTED
+ private final static int ELEM_CONTENT_WHITESPACE = 0x1 << 5;
+
+ // Parameter entities, true [required] (default)
+ private final static int ENTITIES = 0x1 << 6;
+
+ // Parameter infoset, true [required] (default), false has no effect --> True has no effect for the serializer
+ private final static int INFOSET = 0x1 << 7;
+
+ // Parameter namespaces, true [required] (default)
+ private final static int NAMESPACES = 0x1 << 8;
+
+ // Parameter namespace-declarations, true [required] (default)
+ private final static int NAMESPACEDECLS = 0x1 << 9;
+
+ // Parameter normalize-characters, true [optional] - NOT SUPPORTED
+ private final static int NORMALIZECHARS = 0x1 << 10;
+
+ // Parameter split-cdata-sections, true [required] (default)
+ private final static int SPLITCDATA = 0x1 << 11;
+
+ // Parameter validate, true [optional] - NOT SUPPORTED
+ private final static int VALIDATE = 0x1 << 12;
+
+ // Parameter validate-if-schema, true [optional] - NOT SUPPORTED
+ private final static int SCHEMAVALIDATE = 0x1 << 13;
+
+ // Parameter split-cdata-sections, true [required] (default)
+ private final static int WELLFORMED = 0x1 << 14;
+
+ // Parameter discard-default-content, true [required] (default)
+ // Not sure how this will be used in level 2 Documents
+ private final static int DISCARDDEFAULT = 0x1 << 15;
+
+ // Parameter format-pretty-print, true [optional]
+ private final static int PRETTY_PRINT = 0x1 << 16;
+
+ // Parameter ignore-unknown-character-denormalizations, true [required] (default)
+ // We currently do not support XML 1.1 character normalization
+ private final static int IGNORE_CHAR_DENORMALIZE = 0x1 << 17;
+
+ // Parameter discard-default-content, true [required] (default)
+ private final static int XMLDECL = 0x1 << 18;
+ // ************************************************************************
+
+ // Recognized parameters for which atleast one value can be set
+ private String fRecognizedParameters [] = {
+ DOMConstants.DOM_CANONICAL_FORM,
+ DOMConstants.DOM_CDATA_SECTIONS,
+ DOMConstants.DOM_CHECK_CHAR_NORMALIZATION,
+ DOMConstants.DOM_COMMENTS,
+ DOMConstants.DOM_DATATYPE_NORMALIZATION,
+ DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE,
+ DOMConstants.DOM_ENTITIES,
+ DOMConstants.DOM_INFOSET,
+ DOMConstants.DOM_NAMESPACES,
+ DOMConstants.DOM_NAMESPACE_DECLARATIONS,
+ //DOMConstants.DOM_NORMALIZE_CHARACTERS,
+ DOMConstants.DOM_SPLIT_CDATA,
+ DOMConstants.DOM_VALIDATE,
+ DOMConstants.DOM_VALIDATE_IF_SCHEMA,
+ DOMConstants.DOM_WELLFORMED,
+ DOMConstants.DOM_DISCARD_DEFAULT_CONTENT,
+ DOMConstants.DOM_FORMAT_PRETTY_PRINT,
+ DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS,
+ DOMConstants.DOM_XMLDECL,
+ DOMConstants.DOM_ERROR_HANDLER
+ };
+
+
+ /**
+ * Constructor: Creates a LSSerializerImpl object. The underlying
+ * XML 1.0 or XML 1.1 org.apache.xml.serializer.Serializer object is
+ * created and initialized the first time any of the write methods are
+ * invoked to serialize the Node. Subsequent write methods on the same
+ * LSSerializerImpl object will use the previously created Serializer object.
+ */
+ public LSSerializerImpl () {
+ // set default parameters
+ fFeatures |= CDATA;
+ fFeatures |= COMMENTS;
+ fFeatures |= ELEM_CONTENT_WHITESPACE;
+ fFeatures |= ENTITIES;
+ fFeatures |= NAMESPACES;
+ fFeatures |= NAMESPACEDECLS;
+ fFeatures |= SPLITCDATA;
+ fFeatures |= WELLFORMED;
+ fFeatures |= DISCARDDEFAULT;
+ fFeatures |= XMLDECL;
+
+ // New OutputFormat properties
+ fDOMConfigProperties = new Properties();
+
+ // Initialize properties to be passed on the underlying serializer
+ initializeSerializerProps();
+
+ // Read output_xml.properties and System Properties to initialize properties
+ Properties configProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
+
+ // change xml version from 1.0 to 1.1
+ //configProps.setProperty("version", "1.1");
+
+ // Get a serializer that seriailizes according to the properties,
+ // which in this case is to xml
+ fXMLSerializer = SerializerFactory.getSerializer(configProps);
+
+ // Initialize Serializer
+ fXMLSerializer.setOutputFormat(fDOMConfigProperties);
+ }
+
+ /**
+ * Initializes the underlying serializer's configuration depending on the
+ * default DOMConfiguration parameters. This method must be called before a
+ * node is to be serialized.
+ *
+ * @xsl.usage internal
+ */
+ public void initializeSerializerProps () {
+ // canonical-form
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CANONICAL_FORM, DOMConstants.DOM3_DEFAULT_FALSE);
+
+ // cdata-sections
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // "check-character-normalization"
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CHECK_CHAR_NORMALIZATION,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+
+ // comments
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // datatype-normalization
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DATATYPE_NORMALIZATION,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+
+ // element-content-whitespace
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE,
+ DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // entities
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_DEFAULT_TRUE);
+ // preserve entities
+ fDOMConfigProperties.setProperty(
+ OutputPropertiesFactory.S_KEY_ENTITIES, DOMConstants.S_XSL_VALUE_ENTITIES);
+
+ // error-handler
+ // Should we set our default ErrorHandler
+ /*
+ * if (fDOMConfig.getParameter(Constants.DOM_ERROR_HANDLER) != null) {
+ * fDOMErrorHandler =
+ * (DOMErrorHandler)fDOMConfig.getParameter(Constants.DOM_ERROR_HANDLER); }
+ */
+
+ // infoset
+ if ((fFeatures & INFOSET) != 0) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_DEFAULT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACE_DECLARATIONS,
+ DOMConstants.DOM3_DEFAULT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_DEFAULT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE,
+ DOMConstants.DOM3_DEFAULT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_DEFAULT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_DEFAULT_FALSE);
+ // preserve entities
+ fDOMConfigProperties.setProperty(
+ OutputPropertiesFactory.S_KEY_ENTITIES, "");
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CDATA_SECTIONS,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE_IF_SCHEMA,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DATATYPE_NORMALIZATION,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ }
+
+ // namespaces
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // namespace-declarations
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACE_DECLARATIONS,
+ DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // normalize-characters
+ /*
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NORMALIZE_CHARACTERS,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ */
+
+ // split-cdata-sections
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // validate
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE, DOMConstants.DOM3_DEFAULT_FALSE);
+
+ // validate-if-schema
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE_IF_SCHEMA,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+
+ // well-formed
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // pretty-print
+ fDOMConfigProperties.setProperty(
+ DOMConstants.S_XSL_OUTPUT_INDENT,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ fDOMConfigProperties.setProperty(
+ OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, Integer.toString(4));
+
+ //
+
+ // discard-default-content
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT,
+ DOMConstants.DOM3_DEFAULT_TRUE);
+
+ // xml-declaration
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
+
+ }
+
+ // ************************************************************************
+ // DOMConfiguraiton implementation
+ // ************************************************************************
+
+ /**
+ * Checks if setting a parameter to a specific value is supported.
+ *
+ * @see org.w3c.dom.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
+ * @since DOM Level 3
+ * @param name A String containing the DOMConfiguration parameter name.
+ * @param value An Object specifying the value of the corresponding parameter.
+ */
+ public boolean canSetParameter(String name, Object value) {
+ if (value instanceof Boolean){
+ if ( name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)
+ || name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)
+ || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)
+ || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)
+ || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)
+ || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)
+ || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)
+ || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)
+ || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
+ || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
+ || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
+ || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
+ // both values supported
+ return true;
+ }
+ else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
+ || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
+ // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
+ ) {
+ // true is not supported
+ return !((Boolean)value).booleanValue();
+ }
+ else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
+ // false is not supported
+ return ((Boolean)value).booleanValue();
+ }
+ }
+ else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
+ value == null || value instanceof DOMErrorHandler){
+ return true;
+ }
+ return false;
+ }
+ /**
+ * This method returns the value of a parameter if known.
+ *
+ * @see org.w3c.dom.DOMConfiguration#getParameter(java.lang.String)
+ *
+ * @param name A String containing the DOMConfiguration parameter name
+ * whose value is to be returned.
+ * @return Object The value of the parameter if known.
+ */
+ public Object getParameter(String name) throws DOMException {
+
+ if(name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)){
+ return null;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
+ return ((fFeatures & COMMENTS) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
+ return ((fFeatures & CDATA) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
+ return ((fFeatures & ENTITIES) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
+ return ((fFeatures & NAMESPACES) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
+ return ((fFeatures & NAMESPACEDECLS) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
+ return ((fFeatures & SPLITCDATA) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
+ return ((fFeatures & WELLFORMED) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
+ return ((fFeatures & DISCARDDEFAULT) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
+ return ((fFeatures & PRETTY_PRINT) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
+ return ((fFeatures & XMLDECL) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
+ return ((fFeatures & ELEM_CONTENT_WHITESPACE) != 0) ? Boolean.TRUE : Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
+ return Boolean.TRUE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
+ || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
+ // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
+ return Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)){
+ if ((fFeatures & ENTITIES) == 0 &&
+ (fFeatures & CDATA) == 0 &&
+ (fFeatures & ELEM_CONTENT_WHITESPACE) != 0 &&
+ (fFeatures & NAMESPACES) != 0 &&
+ (fFeatures & NAMESPACEDECLS) != 0 &&
+ (fFeatures & WELLFORMED) != 0 &&
+ (fFeatures & COMMENTS) != 0) {
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER)) {
+ return fDOMErrorHandler;
+ } else if (
+ name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
+ return null;
+ } else {
+ // Here we have to add the Xalan specific DOM Message Formatter
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_FOUND,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+ }
+ }
+
+ /**
+ * This method returns a of the parameters supported by this DOMConfiguration object
+ * and for which at least one value can be set by the application
+ *
+ * @see org.w3c.dom.DOMConfiguration#getParameterNames()
+ *
+ * @return DOMStringList A list of DOMConfiguration parameters recognized
+ * by the serializer
+ */
+ public DOMStringList getParameterNames() {
+ return new DOMStringListImpl(fRecognizedParameters);
+ }
+
+ /**
+ * This method sets the value of the named parameter.
+ *
+ * @see org.w3c.dom.DOMConfiguration#setParameter(java.lang.String, java.lang.Object)
+ *
+ * @param name A String containing the DOMConfiguration parameter name.
+ * @param value An Object contaiing the parameters value to set.
+ */
+ public void setParameter(String name, Object value) throws DOMException {
+ // If the value is a boolean
+ if (value instanceof Boolean) {
+ boolean state = ((Boolean) value).booleanValue();
+
+ if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
+ fFeatures = state ? fFeatures | COMMENTS : fFeatures
+ & ~COMMENTS;
+ // comments
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
+ fFeatures = state ? fFeatures | CDATA : fFeatures
+ & ~CDATA;
+ // cdata-sections
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
+ fFeatures = state ? fFeatures | ENTITIES : fFeatures
+ & ~ENTITIES;
+ // entities
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(
+ OutputPropertiesFactory.S_KEY_ENTITIES, DOMConstants.S_XSL_VALUE_ENTITIES);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
+ fFeatures = state ? fFeatures | NAMESPACES : fFeatures
+ & ~NAMESPACES;
+ // namespaces
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name
+ .equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
+ fFeatures = state ? fFeatures | NAMESPACEDECLS
+ : fFeatures & ~NAMESPACEDECLS;
+ // namespace-declarations
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
+ fFeatures = state ? fFeatures | SPLITCDATA : fFeatures
+ & ~SPLITCDATA;
+ // split-cdata-sections
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
+ fFeatures = state ? fFeatures | WELLFORMED : fFeatures
+ & ~WELLFORMED;
+ // well-formed
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name
+ .equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
+ fFeatures = state ? fFeatures | DISCARDDEFAULT
+ : fFeatures & ~DISCARDDEFAULT;
+ // discard-default-content
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
+ fFeatures = state ? fFeatures | PRETTY_PRINT : fFeatures
+ & ~PRETTY_PRINT;
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_INDENT,DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, Integer.toString(4));
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_INDENT,DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
+ fFeatures = state ? fFeatures | XMLDECL : fFeatures
+ & ~XMLDECL;
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
+ fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures
+ & ~ELEM_CONTENT_WHITESPACE;
+ // element-content-whitespace
+ if (state) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_FALSE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
+ // false is not supported
+ if (!state) {
+ // Here we have to add the Xalan specific DOM Message Formatter
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_SUPPORTED,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+ } else {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)
+ || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)
+ || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)
+ // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
+ ) {
+ // true is not supported
+ if (state) {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_SUPPORTED,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+ } else {
+ if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CANONICAL_FORM, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
+ fDOMConfigProperties.setProperty(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION
+ + DOMConstants.DOM_CHECK_CHAR_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } /* else if (name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)) {
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NORMALIZE_CHARACTERS, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } */
+ }
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
+ if (state) {
+ fFeatures &= ~ENTITIES;
+ fFeatures &= ~CDATA;
+ fFeatures &= ~SCHEMAVALIDATE;
+ fFeatures &= ~DTNORMALIZE;
+ fFeatures |= NAMESPACES;
+ fFeatures |= NAMESPACEDECLS;
+ fFeatures |= WELLFORMED;
+ fFeatures |= ELEM_CONTENT_WHITESPACE;
+ fFeatures |= COMMENTS;
+ }
+
+ // infoset
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
+
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
+ fDOMConfigProperties.setProperty(
+ OutputPropertiesFactory.S_KEY_ENTITIES, "");
+
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
+ fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
+ } else if (name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)) {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_SUPPORTED,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+ } else {
+ // Setting this to false has no effect
+ }
+ } // If the parameter value is not a boolean
+ else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER)) {
+ if (value == null || value instanceof DOMErrorHandler) {
+ fDOMErrorHandler = (DOMErrorHandler)value;
+ } else {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_TYPE_MISMATCH_ERR,
+ new Object[] { name });
+ throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
+ }
+ } else if (
+ name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION)
+ || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)
+ || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
+ && value != null) {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_SUPPORTED,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
+ } else {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_FEATURE_NOT_FOUND,
+ new Object[] { name });
+ throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+ }
+ }
+ // ************************************************************************
+
+
+ // ************************************************************************
+ // DOMConfiguraiton implementation
+ // ************************************************************************
+
+ /**
+ * Returns the DOMConfiguration of the LSSerializer.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#getDomConfig()
+ * @since DOM Level 3
+ * @return A DOMConfiguration object.
+ */
+ public DOMConfiguration getDomConfig() {
+ return (DOMConfiguration)this;
+ }
+
+ /**
+ * Returns the DOMConfiguration of the LSSerializer.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#getFilter()
+ * @since DOM Level 3
+ * @return A LSSerializerFilter object.
+ */
+ public LSSerializerFilter getFilter() {
+ return fSerializerFilter;
+ }
+
+ /**
+ * Returns the End-Of-Line sequence of characters to be used in the XML
+ * being serialized. If none is set a default "\n" is returned.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#getNewLine()
+ * @since DOM Level 3
+ * @return A String containing the end-of-line character sequence used in
+ * serialization.
+ */
+ public String getNewLine() {
+ return fEndOfLine;
+ }
+
+ /**
+ * Set a LSSerilizerFilter on the LSSerializer. When set, the filter is
+ * called before each node is serialized which depending on its implemention
+ * determines if the node is to be serialized or not.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#setFilter
+ * @since DOM Level 3
+ * @param filter A LSSerializerFilter to be applied to the stream to serialize.
+ */
+ public void setFilter(LSSerializerFilter filter) {
+ fSerializerFilter = filter;
+ }
+
+ /**
+ * Sets the End-Of-Line sequence of characters to be used in the XML
+ * being serialized. Setting this attribute to null will reset its
+ * value to the default value i.e. "\n".
+ *
+ * @see org.w3c.dom.ls.LSSerializer#setNewLine
+ * @since DOM Level 3
+ * @param newLine a String that is the end-of-line character sequence to be used in
+ * serialization.
+ */
+ public void setNewLine(String newLine) {
+ fEndOfLine = newLine !=null? newLine: fEndOfLine;
+ }
+
+ /**
+ * Serializes the specified node to the specified LSOutput and returns true if the Node
+ * was successfully serialized.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#write(org.w3c.dom.Node, org.w3c.dom.ls.LSOutput)
+ * @since DOM Level 3
+ * @param nodeArg The Node to serialize.
+ * @throws org.w3c.dom.ls.LSException SERIALIZE_ERR: Raised if the
+ * LSSerializer was unable to serialize the node.
+ *
+ */
+ public boolean write(Node nodeArg, LSOutput destination) throws LSException {
+ // If the destination is null
+ if (destination == null) {
+ String msg = Utils.messages
+ .createMessage(
+ MsgKey.ER_NO_OUTPUT_SPECIFIED,
+ null);
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, msg,
+ MsgKey.ER_NO_OUTPUT_SPECIFIED));
+ }
+ throw new LSException(LSException.SERIALIZE_ERR, msg);
+ }
+
+ // If nodeArg is null, return false. Should we throw and LSException instead?
+ if (nodeArg == null ) {
+ return false;
+ }
+
+ // Obtain a reference to the serializer to use
+ // Serializer serializer = getXMLSerializer(xmlVersion);
+ Serializer serializer = fXMLSerializer;
+ serializer.reset();
+
+ // If the node has not been seen
+ if ( nodeArg != fVisitedNode) {
+ // Determine the XML Document version of the Node
+ String xmlVersion = getXMLVersion(nodeArg);
+
+ // Determine the encoding: 1.LSOutput.encoding, 2.Document.inputEncoding, 3.Document.xmlEncoding.
+ fEncoding = destination.getEncoding();
+ if (fEncoding == null ) {
+ fEncoding = getInputEncoding(nodeArg);
+ fEncoding = fEncoding != null ? fEncoding : getXMLEncoding(nodeArg) == null? "UTF-8": getXMLEncoding(nodeArg);
+ }
+
+ // If the encoding is not recognized throw an exception.
+ // Note: The serializer defaults to UTF-8 when created
+ if (!Encodings.isRecognizedEncoding(fEncoding)) {
+ String msg = Utils.messages
+ .createMessage(
+ MsgKey.ER_UNSUPPORTED_ENCODING,
+ null);
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, msg,
+ MsgKey.ER_UNSUPPORTED_ENCODING));
+ }
+ throw new LSException(LSException.SERIALIZE_ERR, msg);
+ }
+
+ serializer.getOutputFormat().setProperty("version", xmlVersion);
+
+ // Set the output encoding and xml version properties
+ fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.S_XML_VERSION, xmlVersion);
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_ENCODING, fEncoding);
+
+ // If the node to be serialized is not a Document, Element, or Entity
+ // node
+ // then the XML declaration, or text declaration, should be never be
+ // serialized.
+ if ( (nodeArg.getNodeType() != Node.DOCUMENT_NODE
+ || nodeArg.getNodeType() != Node.ELEMENT_NODE
+ || nodeArg.getNodeType() != Node.ENTITY_NODE)
+ && ((fFeatures & XMLDECL) != 0)) {
+ fDOMConfigProperties.setProperty(
+ DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ }
+
+ fVisitedNode = nodeArg;
+ }
+
+ // Update the serializer properties
+ fXMLSerializer.setOutputFormat(fDOMConfigProperties);
+
+ //
+ try {
+
+ // The LSSerializer will use the LSOutput object to determine
+ // where to serialize the output to in the following order the
+ // first one that is not null and not an empty string will be
+ // used: 1.LSOutput.characterStream, 2.LSOutput.byteStream,
+ // 3. LSOutput.systemId
+ // 1.LSOutput.characterStream
+ Writer writer = destination.getCharacterStream();
+ if (writer == null ) {
+
+ // 2.LSOutput.byteStream
+ OutputStream outputStream = destination.getByteStream();
+ if ( outputStream == null) {
+
+ // 3. LSOutput.systemId
+ String uri = destination.getSystemId();
+ if (uri == null) {
+ String msg = Utils.messages
+ .createMessage(
+ MsgKey.ER_NO_OUTPUT_SPECIFIED,
+ null);
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, msg,
+ MsgKey.ER_NO_OUTPUT_SPECIFIED));
+ }
+ throw new LSException(LSException.SERIALIZE_ERR, msg);
+
+ } else {
+ // Expand the System Id and obtain an absolute URI for it.
+ String absoluteURI = SystemIDResolver.getAbsoluteURI(uri);
+
+ URL url = new URL(absoluteURI);
+ OutputStream urlOutStream = null;
+ String protocol = url.getProtocol();
+ String host = url.getHost();
+
+ // For file protocols, there is no need to use a URL to get its
+ // corresponding OutputStream
+
+ // Scheme names consist of a sequence of characters. The lower case
+ // letters "a"--"z", digits, and the characters plus ("+"), period
+ // ("."), and hyphen ("-") are allowed. For resiliency, programs
+ // interpreting URLs should treat upper case letters as equivalent to
+ // lower case in scheme names (e.g., allow "HTTP" as well as "http").
+ if (protocol.equalsIgnoreCase("file")
+ && (host == null || host.length() == 0 || host.equals("localhost"))) {
+ // do we also need to check for host.equals(hostname)
+ urlOutStream = new FileOutputStream(new File(url.getPath()));
+
+ } else {
+ // This should support URL's whose schemes are mentioned in
+ // RFC1738 other than file
+
+ URLConnection urlCon = url.openConnection();
+ urlCon.setDoInput(false);
+ urlCon.setDoOutput(true);
+ urlCon.setUseCaches(false);
+ urlCon.setAllowUserInteraction(false);
+
+ // When writing to a HTTP URI, a HTTP PUT is performed.
+ if (urlCon instanceof HttpURLConnection) {
+ HttpURLConnection httpCon = (HttpURLConnection) urlCon;
+ httpCon.setRequestMethod("PUT");
+ }
+ urlOutStream = urlCon.getOutputStream();
+ }
+ // set the OutputStream to that obtained from the systemId
+ serializer.setWriter(new OutputStreamWriter(urlOutStream));
+ }
+ } else {
+ // 2.LSOutput.byteStream
+ serializer.setWriter(new OutputStreamWriter(outputStream, fEncoding));
+ }
+ } else {
+ // 1.LSOutput.characterStream
+ serializer.setWriter(writer);
+ }
+
+ // The associated media type by default is set to text/xml on
+ // org.apache.xml.serializer.SerializerBase.
+
+ // Get a reference to the serializer then lets you serilize a DOM
+ // Use this hack till Xalan support JAXP1.3
+ if (fDOMSerializer == null) {
+ fDOMSerializer = (DOM3Serializer)serializer.asDOM3Serializer();
+ }
+
+ // Set the error handler on the DOM3Serializer interface implementation
+ if (fDOMErrorHandler != null) {
+ fDOMSerializer.setErrorHandler(fDOMErrorHandler);
+ }
+
+ // Set the filter on the DOM3Serializer interface implementation
+ if (fSerializerFilter != null) {
+ fDOMSerializer.setNodeFilter(fSerializerFilter);
+ }
+
+ // Set the NewLine character to be used
+ fDOMSerializer.setNewLine(fEndOfLine);
+
+ // Serializer your DOM, where node is an org.w3c.dom.Node
+ // Assuming that Xalan's serializer can serialize any type of DOM node
+ fDOMSerializer.serializeDOM3(nodeArg);
+
+ } catch( UnsupportedEncodingException ue) {
+
+ String msg = Utils.messages
+ .createMessage(
+ MsgKey.ER_UNSUPPORTED_ENCODING,
+ null);
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, msg,
+ MsgKey.ER_UNSUPPORTED_ENCODING, ue));
+ }
+ throw new LSException(LSException.SERIALIZE_ERR, ue.getMessage());
+ } catch (LSException lse) {
+ // Rethrow LSException.
+ throw lse;
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e!=null?e.getMessage():"NULL Exception") ;
+ } catch (Exception e) {
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, e.getMessage(),
+ null, e));
+ }
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e.toString());
+ }
+ return true;
+ }
+
+ /**
+ * Serializes the specified node and returns a String with the serialized
+ * data to the caller.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#writeToString(org.w3c.dom.Node)
+ * @since DOM Level 3
+ * @param nodeArg The Node to serialize.
+ * @throws org.w3c.dom.ls.LSException SERIALIZE_ERR: Raised if the
+ * LSSerializer was unable to serialize the node.
+ *
+ */
+ public String writeToString(Node nodeArg) throws DOMException, LSException {
+ // return null is nodeArg is null. Should an Exception be thrown instead?
+ if (nodeArg == null) {
+ return null;
+ }
+
+ // Should we reset the serializer configuration before each write operation?
+ // Obtain a reference to the serializer to use
+ Serializer serializer = fXMLSerializer;
+ serializer.reset();
+
+ if (nodeArg != fVisitedNode){
+ // Determine the XML Document version of the Node
+ String xmlVersion = getXMLVersion(nodeArg);
+
+ serializer.getOutputFormat().setProperty("version", xmlVersion);
+
+ // Set the output encoding and xml version properties
+ fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.S_XML_VERSION, xmlVersion);
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_ENCODING, "UTF-16");
+
+ // If the node to be serialized is not a Document, Element, or Entity
+ // node
+ // then the XML declaration, or text declaration, should be never be
+ // serialized.
+ if ((nodeArg.getNodeType() != Node.DOCUMENT_NODE
+ || nodeArg.getNodeType() != Node.ELEMENT_NODE
+ || nodeArg.getNodeType() != Node.ENTITY_NODE)
+ && ((fFeatures & XMLDECL) != 0)) {
+ fDOMConfigProperties.setProperty(
+ DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ }
+
+ fVisitedNode = nodeArg;
+ }
+ // Update the serializer properties
+ fXMLSerializer.setOutputFormat(fDOMConfigProperties);
+
+ // StringWriter to Output to
+ StringWriter output = new StringWriter();
+
+ //
+ try {
+
+ // Set the Serializer's Writer to a StringWriter
+ serializer.setWriter(output);
+
+ // Get a reference to the serializer then lets you serilize a DOM
+ // Use this hack till Xalan support JAXP1.3
+ if (fDOMSerializer == null) {
+ fDOMSerializer = (DOM3Serializer)serializer.asDOM3Serializer();
+ }
+
+ // Set the error handler on the DOM3Serializer interface implementation
+ if (fDOMErrorHandler != null) {
+ fDOMSerializer.setErrorHandler(fDOMErrorHandler);
+ }
+
+ // Set the filter on the DOM3Serializer interface implementation
+ if (fSerializerFilter != null) {
+ fDOMSerializer.setNodeFilter(fSerializerFilter);
+ }
+
+ // Set the NewLine character to be used
+ fDOMSerializer.setNewLine(fEndOfLine);
+
+ // Serializer your DOM, where node is an org.w3c.dom.Node
+ fDOMSerializer.serializeDOM3(nodeArg);
+ } catch (LSException lse) {
+ // Rethrow LSException.
+ throw lse;
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e.toString());
+ } catch (Exception e) {
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, e.getMessage(),
+ null, e));
+ }
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e.toString());
+ }
+
+ // return the serialized string
+ return output.toString();
+ }
+
+ /**
+ * Serializes the specified node to the specified URI and returns true if the Node
+ * was successfully serialized.
+ *
+ * @see org.w3c.dom.ls.LSSerializer#writeToURI(org.w3c.dom.Node, String)
+ * @since DOM Level 3
+ * @param nodeArg The Node to serialize.
+ * @throws org.w3c.dom.ls.LSException SERIALIZE_ERR: Raised if the
+ * LSSerializer was unable to serialize the node.
+ *
+ */
+ public boolean writeToURI(Node nodeArg, String uri) throws LSException {
+ // If nodeArg is null, return false. Should we throw and LSException instead?
+ if (nodeArg == null ) {
+ return false;
+ }
+
+ // Obtain a reference to the serializer to use
+ Serializer serializer = fXMLSerializer;
+ serializer.reset();
+
+ if (nodeArg != fVisitedNode) {
+ // Determine the XML Document version of the Node
+ String xmlVersion = getXMLVersion(nodeArg);
+
+ // Determine the encoding: 1.LSOutput.encoding,
+ // 2.Document.inputEncoding, 3.Document.xmlEncoding.
+ fEncoding = getInputEncoding(nodeArg);
+ if (fEncoding == null ) {
+ fEncoding = fEncoding != null ? fEncoding : getXMLEncoding(nodeArg) == null? "UTF-8": getXMLEncoding(nodeArg);
+ }
+
+ serializer.getOutputFormat().setProperty("version", xmlVersion);
+
+ // Set the output encoding and xml version properties
+ fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.S_XML_VERSION, xmlVersion);
+ fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_ENCODING, fEncoding);
+
+ // If the node to be serialized is not a Document, Element, or Entity
+ // node
+ // then the XML declaration, or text declaration, should be never be
+ // serialized.
+ if ( (nodeArg.getNodeType() != Node.DOCUMENT_NODE
+ || nodeArg.getNodeType() != Node.ELEMENT_NODE
+ || nodeArg.getNodeType() != Node.ENTITY_NODE)
+ && ((fFeatures & XMLDECL) != 0)) {
+ fDOMConfigProperties.setProperty(
+ DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL,
+ DOMConstants.DOM3_DEFAULT_FALSE);
+ }
+
+ fVisitedNode = nodeArg;
+ }
+
+ // Update the serializer properties
+ fXMLSerializer.setOutputFormat(fDOMConfigProperties);
+
+ //
+ try {
+ // If the specified encoding is not supported an
+ // "unsupported-encoding" fatal error is raised. ??
+ if (uri == null) {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_NO_OUTPUT_SPECIFIED, null);
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, msg,
+ MsgKey.ER_NO_OUTPUT_SPECIFIED));
+ }
+ throw new LSException(LSException.SERIALIZE_ERR, msg);
+
+ } else {
+ // REVISIT: Can this be used to get an absolute expanded URI
+ String absoluteURI = SystemIDResolver.getAbsoluteURI(uri);
+
+ URL url = new URL(absoluteURI);
+ OutputStream urlOutStream = null;
+ String protocol = url.getProtocol();
+ String host = url.getHost();
+
+ // For file protocols, there is no need to use a URL to get its
+ // corresponding OutputStream
+
+ // Scheme names consist of a sequence of characters. The lower
+ // case letters "a"--"z", digits, and the characters plus ("+"),
+ // period ("."), and hyphen ("-") are allowed. For resiliency,
+ // programs interpreting URLs should treat upper case letters as
+ // equivalent to lower case in scheme names
+ // (e.g., allow "HTTP" as well as "http").
+ if (protocol.equalsIgnoreCase("file")
+ && (host == null || host.length() == 0 || host
+ .equals("localhost"))) {
+ // do we also need to check for host.equals(hostname)
+ urlOutStream = new FileOutputStream(new File(url.getPath()));
+
+ } else {
+ // This should support URL's whose schemes are mentioned in
+ // RFC1738 other than file
+
+ URLConnection urlCon = url.openConnection();
+ urlCon.setDoInput(false);
+ urlCon.setDoOutput(true);
+ urlCon.setUseCaches(false);
+ urlCon.setAllowUserInteraction(false);
+
+ // When writing to a HTTP URI, a HTTP PUT is performed.
+ if (urlCon instanceof HttpURLConnection) {
+ HttpURLConnection httpCon = (HttpURLConnection) urlCon;
+ httpCon.setRequestMethod("PUT");
+ }
+ urlOutStream = urlCon.getOutputStream();
+ }
+ // set the OutputStream to that obtained from the systemId
+ serializer.setWriter(new OutputStreamWriter(urlOutStream, fEncoding));
+ }
+
+ // Get a reference to the serializer then lets you serilize a DOM
+ // Use this hack till Xalan support JAXP1.3
+ if (fDOMSerializer == null) {
+ fDOMSerializer = (DOM3Serializer)serializer.asDOM3Serializer();
+ }
+
+ // Set the error handler on the DOM3Serializer interface implementation
+ if (fDOMErrorHandler != null) {
+ fDOMSerializer.setErrorHandler(fDOMErrorHandler);
+ }
+
+ // Set the filter on the DOM3Serializer interface implementation
+ if (fSerializerFilter != null) {
+ fDOMSerializer.setNodeFilter(fSerializerFilter);
+ }
+
+ // Set the NewLine character to be used
+ fDOMSerializer.setNewLine(fEndOfLine);
+
+ // Serializer your DOM, where node is an org.w3c.dom.Node
+ // Assuming that Xalan's serializer can serialize any type of DOM
+ // node
+ fDOMSerializer.serializeDOM3(nodeArg);
+
+ } catch (LSException lse) {
+ // Rethrow LSException.
+ throw lse;
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e.toString());
+ } catch (Exception e) {
+ if (fDOMErrorHandler != null) {
+ fDOMErrorHandler.handleError(new DOMErrorImpl(
+ DOMError.SEVERITY_FATAL_ERROR, e.getMessage(),
+ null, e));
+ }
+ e.printStackTrace();
+ throw new LSException(LSException.SERIALIZE_ERR, e.toString());
+ }
+
+ return true;
+ }
+ // ************************************************************************
+
+
+ // ************************************************************************
+ // Implementaion methods
+ // ************************************************************************
+
+ /**
+ * Determines the XML Version of the Document Node to serialize. If the Document Node
+ * is not a DOM Level 3 Node, then the default version returned is 1.0.
+ *
+ * @param nodeArg The Node to serialize
+ * @return A String containing the version pseudo-attribute of the XMLDecl.
+ * @throws Throwable if the DOM implementation does not implement Document.getXmlVersion()
+ */
+ //protected String getXMLVersion(Node nodeArg) throws Throwable {
+ protected String getXMLVersion(Node nodeArg) {
+ Document doc = null;
+
+ // Determine the XML Version of the document
+ if (nodeArg != null) {
+ if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) {
+ // The Document node is the Node argument
+ doc = (Document)nodeArg;
+ } else {
+ // The Document node is the Node argument's ownerDocument
+ doc = nodeArg.getOwnerDocument();
+ }
+
+ // Determine the DOM Version.
+ if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) {
+ try {
+ return doc.getXmlVersion();
+ } catch (AbstractMethodError e) {
+ //ignore, impl does not support the method
+ }
+ }
+ }
+ // The version will be treated as "1.0" which may result in
+ // an ill-formed document being serialized.
+ // If nodeArg does not have an ownerDocument, treat this as XML 1.0
+ return "1.0";
+ }
+
+ /**
+ * Determines the XML Encoding of the Document Node to serialize. If the Document Node
+ * is not a DOM Level 3 Node, then the default encoding "UTF-8" is returned.
+ *
+ * @param nodeArg The Node to serialize
+ * @return A String containing the encoding pseudo-attribute of the XMLDecl.
+ * @throws Throwable if the DOM implementation does not implement Document.getXmlEncoding()
+ */
+ protected String getXMLEncoding(Node nodeArg) {
+ Document doc = null;
+
+ // Determine the XML Encoding of the document
+ if (nodeArg != null) {
+ if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) {
+ // The Document node is the Node argument
+ doc = (Document)nodeArg;
+ } else {
+ // The Document node is the Node argument's ownerDocument
+ doc = nodeArg.getOwnerDocument();
+ }
+
+ // Determine the XML Version.
+ if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) {
+ return doc.getXmlEncoding();
+ }
+ }
+ // The default encoding is UTF-8 except for the writeToString method
+ return "UTF-8";
+ }
+
+ /**
+ * Determines the Input Encoding of the Document Node to serialize. If the Document Node
+ * is not a DOM Level 3 Node, then null is returned.
+ *
+ * @param nodeArg The Node to serialize
+ * @return A String containing the input encoding.
+ */
+ protected String getInputEncoding(Node nodeArg) {
+ Document doc = null;
+
+ // Determine the Input Encoding of the document
+ if (nodeArg != null) {
+ if (nodeArg.getNodeType() == Node.DOCUMENT_NODE) {
+ // The Document node is the Node argument
+ doc = (Document)nodeArg;
+ } else {
+ // The Document node is the Node argument's ownerDocument
+ doc = nodeArg.getOwnerDocument();
+ }
+
+ // Determine the DOM Version.
+ if (doc != null && doc.getImplementation().hasFeature("Core","3.0")) {
+ return doc.getInputEncoding();
+ }
+ }
+ // The default encoding returned is null
+ return null;
+ }
+
+ /**
+ * This method returns the LSSerializer's error handler.
+ *
+ * @return Returns the fDOMErrorHandler.
+ */
+ public DOMErrorHandler getErrorHandler() {
+ return fDOMErrorHandler;
+ }
+
+}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/NamespaceSupport.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/NamespaceSupport.java
new file mode 100644
index 00000000000..611b984f05a
--- /dev/null
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/dom3/NamespaceSupport.java
@@ -0,0 +1,315 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id: $
+ */
+
+package com.sun.org.apache.xml.internal.serializer.dom3;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * Namespace support for XML document handlers. This class doesn't
+ * perform any error checking and assumes that all strings passed
+ * as arguments to methods are unique symbols. The SymbolTable class
+ * can be used for this purpose.
+ *
+ * Derived from org.apache.xerces.util.NamespaceSupport
+ *
+ * @author Andy Clark, IBM
+ *
+ * @version $Id: Exp $
+ */
+public class NamespaceSupport {
+
+ static final String PREFIX_XML = "xml".intern();
+
+ static final String PREFIX_XMLNS = "xmlns".intern();
+
+ /**
+ * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
+ * the Namespace URI that is automatically mapped to the "xml" prefix.
+ */
+ public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
+
+ /**
+ * XML Information Set REC
+ * all namespace attributes (including those named xmlns,
+ * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
+ */
+ public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
+
+ //
+ // Data
+ //
+
+ /**
+ * Namespace binding information. This array is composed of a
+ * series of tuples containing the namespace binding information:
+ * <prefix, uri>. The default size can be set to anything
+ * as long as it is a power of 2 greater than 1.
+ *
+ * @see #fNamespaceSize
+ * @see #fContext
+ */
+ protected String[] fNamespace = new String[16 * 2];
+
+ /** The top of the namespace information array. */
+ protected int fNamespaceSize;
+
+ // NOTE: The constructor depends on the initial context size
+ // being at least 1. -Ac
+
+ /**
+ * Context indexes. This array contains indexes into the namespace
+ * information array. The index at the current context is the start
+ * index of declared namespace bindings and runs to the size of the
+ * namespace information array.
+ *
+ * @see #fNamespaceSize
+ */
+ protected int[] fContext = new int[8];
+
+ /** The current context. */
+ protected int fCurrentContext;
+
+ protected String[] fPrefixes = new String[16];
+
+ //
+ // Constructors
+ //
+
+ /** Default constructor. */
+ public NamespaceSupport() {
+ } // RangeException
as specified in
* their method descriptions.
* DocumentTraversal
will be implemented by
* the same objects that implement the Document interface.
* NodeIterators
are created by calling
* DocumentTraversal
.createNodeIterator()
.
*