xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject cvs commit: xml-xerces/java/src/org/apache/xml/serialize HTMLSerializer.java XHTMLSerializer.java
Date Mon, 16 Feb 2004 05:24:55 GMT
mrglavas    2004/02/15 21:24:55

  Modified:    java/src/org/apache/xml/serialize HTMLSerializer.java
                        XHTMLSerializer.java
  Log:
  Deprecating HTML/XHTML serializers. Also, fixing long standing Bug #2248. Have had this
fixed locally for almost a year, might as well apply it.
  
  Revision  Changes    Path
  1.26      +24 -14    xml-xerces/java/src/org/apache/xml/serialize/HTMLSerializer.java
  
  Index: HTMLSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/HTMLSerializer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- HTMLSerializer.java	10 Feb 2004 17:25:26 -0000	1.25
  +++ HTMLSerializer.java	16 Feb 2004 05:24:55 -0000	1.26
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -123,7 +123,7 @@
    * <li>Contents of SCRIPT and STYLE elements serialized as CDATA
    * </ul>
    *
  - *
  + * @deprecated
    * @version $Revision$ $Date$
    * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
    * @see Serializer
  @@ -253,7 +253,8 @@
                   // the document's DOCTYPE. Space preserving defaults
                   // to that of the output format.
                   if ( ! _started )
  -                    startDocument( localName == null ? rawName : localName );
  +                    startDocument( (localName == null || localName.length() == 0) 
  +                        ? rawName : localName );
               } else {
                   // For any other element, if first in parent, then
                   // close parent's opening tag and use the parnet's
  @@ -271,18 +272,25 @@
   
               // Do not change the current element state yet.
               // This only happens in endElement().
  -
  -            if ( rawName == null ) {
  +            
  +            // As per SAX2, the namespace URI is an empty string if the element has no
  +            // namespace URI, or namespaces is turned off. The check against null protects
  +            // against broken SAX implementations, so I've left it there. - mrglavas
  +            boolean hasNamespaceURI = (namespaceURI != null && namespaceURI.length()
!= 0);
  +
  +            // SAX2: rawName (QName) could be empty string if 
  +            // namespace-prefixes property is false.
  +            if ( rawName == null || rawName.length() == 0) {
                   rawName = localName;
  -                if ( namespaceURI != null ) {
  +                if ( hasNamespaceURI ) {
                       String prefix;
                       prefix = getPrefix( namespaceURI );
  -                    if ( prefix.length() > 0 )
  +                    if ( prefix != null && prefix.length() != 0 )
                           rawName = prefix + ":" + localName;
                   }
                   addNSAttr = true;
               }
  -            if ( namespaceURI == null )
  +            if ( !hasNamespaceURI )
                   htmlName = rawName;
               else {
                   if ( namespaceURI.equals( XHTMLNamespace ) ||
  @@ -306,9 +314,9 @@
               if ( attrs != null ) {
                   for ( i = 0 ; i < attrs.getLength() ; ++i ) {
                       _printer.printSpace();
  -                    name = attrs.getQName( i ).toLowerCase(Locale.ENGLISH);;
  +                    name = attrs.getQName( i ).toLowerCase(Locale.ENGLISH);
                       value = attrs.getValue( i );
  -                    if ( _xhtml || namespaceURI != null ) {
  +                    if ( _xhtml || hasNamespaceURI ) {
                           // XHTML: print empty string for null values.
                           if ( value == null ) {
                               _printer.printText( name );
  @@ -425,7 +433,7 @@
           _printer.unindent();
           state = getElementState();
   
  -        if ( state.namespaceURI == null )
  +        if ( state.namespaceURI == null || state.namespaceURI.length() == 0 )
               htmlName = state.rawName;
           else {
               if ( state.namespaceURI.equals( XHTMLNamespace ) ||
  @@ -558,7 +566,7 @@
               if ( attrs != null ) {
                   for ( i = 0 ; i < attrs.getLength() ; ++i ) {
                       _printer.printSpace();
  -                    name = attrs.getName( i ).toLowerCase(Locale.ENGLISH);;
  +                    name = attrs.getName( i ).toLowerCase(Locale.ENGLISH);
                       value = attrs.getValue( i );
                       if ( _xhtml ) {
                           // XHTML: print empty string for null values.
  @@ -675,10 +683,12 @@
               }
   
               if ( ! _format.getOmitDocumentType() ) {
  -                // XHTML: If public idnentifier and system identifier
  +                // XHTML: If public identifier and system identifier
                   //  specified, print them, else print just system identifier
                   // HTML: If public identifier specified, print it with
                   //  system identifier, if specified.
  +                // XHTML requires that all element names are lower case, so the
  +                // root on the DOCTYPE must be 'html'. - mrglavas
                   if ( _docTypePublicId != null && ( ! _xhtml || _docTypeSystemId
!= null )  ) {
                       if (_xhtml) {
                           _printer.printText( "<!DOCTYPE html PUBLIC " );
  
  
  
  1.10      +3 -3      xml-xerces/java/src/org/apache/xml/serialize/XHTMLSerializer.java
  
  Index: XHTMLSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xml/serialize/XHTMLSerializer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XHTMLSerializer.java	13 May 2003 13:23:49 -0000	1.9
  +++ XHTMLSerializer.java	16 Feb 2004 05:24:55 -0000	1.10
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2004 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -68,7 +68,7 @@
    * pretty serializing. For usage instructions see either {@link
    * Serializer} or {@link BaseMarkupSerializer}.
    *
  - *
  + * @deprecated
    * @version $Revision$ $Date$
    * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
    * @see Serializer
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org


Mime
View raw message