[Yanel-dev] XML resource patch

Evaldas Taroza etaroza at optaros.com
Wed Jan 16 12:05:28 CET 2008


Yes, maybe that would work, but then I am a bit confused how to 
configure all the stuff:
1. in *.xsl I set <output method="text"/>
2. in *.yanel-rc I set mime-type to text/html
3. in *.yanel-rc I set serializer to HTML_TRANSITIONAL (plus all the 
stuff about omitting the declarations)

Is that right?

Why do I have to set so many things? For me it would be natural to set 
everything in the XSLT, i.e. when I set
1. <output method="text"/> then mime-type and serializer are like for text
2. <output method="html"/> then mime-type and serializer are like for html
3. <output method="xml"/> then mime-type and serializer are like for xml

Evaldas

Josias Thöny wrote:
> Evaldas Taroza wrote:
>> Ok, maybe I changed too much. What I need is to be able to serialize 
>> XML resource into pure text. So I introduced TEXT in 
>> SerializerFactory. If I use HTML serializer I get all the DTD stuff 
>> prepended, which I don't want...
> 
> ok, I see.
> Maybe we could add a property "omit-document-type" or something like 
> that, as in the attached patch.
> 
> You could use it in the rc:
> 
> <serializer key="HTML_TRANSITIONAL">
>   <omit-xml-declaration>yes</omit-xml-declaration>
>   <omit-document-type>yes</omit-document-type>
> </serializer>
> 
> Would that solve your problem?
> 
> Or should we implement that empty <doctype-public> and <doctype-system> 
> elements cause the doctype to be removed from the output?
> 
> WDYT?
> 
> josias
> 
>>
>> Evaldas
>>
>> Josias Thöny wrote:
>>> Hi Evaldas,
>>>
>>> please see my comments below.
>>>
>>> Evaldas Taroza wrote:
>>>> Some small changes to BasicXMLResource and SerializerFactory.
>>>>
>>>> Evaldas
>>>>
>>>>
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> Index: 
>>>> core/java/org/wyona/yanel/core/serialization/SerializerFactory.java
>>>> ===================================================================
>>>> --- 
>>>> core/java/org/wyona/yanel/core/serialization/SerializerFactory.java    
>>>> (revision 30347)
>>>> +++ 
>>>> core/java/org/wyona/yanel/core/serialization/SerializerFactory.java    
>>>> (working copy)
>>>> @@ -4,6 +4,7 @@
>>>>  import org.apache.log4j.Category;
>>>>  import org.apache.xml.serializer.OutputPropertiesFactory;
>>>>  import org.apache.xml.serializer.Serializer;
>>>> +import org.apache.xml.serializer.SerializerFactory;
>>>>  
>>>>  /**
>>>>   * Factory to create serializers. @@ -16,10 +17,12 @@
>>>>      public static final int XHTML_STRICT = 1;
>>>>      public static final int HTML_TRANSITIONAL = 2;
>>>>      public static final int XML = 3;
>>>> +    public static final int TEXT = 4;
>>>>           public static final String XHTML_STRICT_KEY = "XHTML_STRICT";
>>>>      public static final String HTML_TRANSITIONAL_KEY = 
>>>> "HTML_TRANSITIONAL";
>>>>      public static final String XML_KEY = "XML";
>>>> +    public static final String TEXT_KEY = "TEXT";
>>>>  
>>>>      public static Serializer getSerializer(Properties format) {
>>>>          Serializer serializer = new HTMLSerializer();
>>>> @@ -32,10 +35,12 @@
>>>>              return getSerializer(XHTML_STRICT);
>>>>          } else if (key.equals(HTML_TRANSITIONAL_KEY)) {
>>>>              return getSerializer(HTML_TRANSITIONAL);
>>>> -        } if (key.equals(XML_KEY)) {
>>>> +        } else if (key.equals(XML_KEY)) {
>>>>              return getSerializer(XML);
>>>> +        } else if (key.equals(TEXT_KEY)) {
>>>> +            return getSerializer(TEXT);
>>>>          }
>>>> -        return null;
>>>> +        return getSerializer(TEXT);
>>>>      }
>>>>           public static Serializer getSerializer(int key) {
>>>> @@ -47,8 +52,7 @@
>>>>              format.setProperty("doctype-public", "-//W3C//DTD XHTML 
>>>> 1.0 Strict//EN");
>>>>              format.setProperty("doctype-system", 
>>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
>>>>              serializer.setOutputFormat(format);
>>>> -        }
>>>> -        if (key == HTML_TRANSITIONAL) {
>>>> +        }else if (key == HTML_TRANSITIONAL) {
>>>>              serializer = new HTMLSerializer();
>>>>              Properties format = 
>>>> OutputPropertiesFactory.getDefaultMethodProperties("html");
>>>>              format.setProperty("indent", "yes");
>>>> @@ -56,12 +60,14 @@
>>>>              format.setProperty("doctype-public", "-//W3C//DTD HTML 
>>>> 4.01 Transitional//EN");
>>>>              format.setProperty("doctype-system", 
>>>> "http://www.w3.org/TR/html4/loose.dtd");
>>>>              serializer.setOutputFormat(format);
>>>> -        }
>>>> -        if (key == XML) {
>>>> +        }else if (key == XML) {
>>>>              serializer = new XMLSerializer();
>>>>              Properties format = 
>>>> OutputPropertiesFactory.getDefaultMethodProperties("xml");
>>>>              format.setProperty("indent", "yes");
>>>>              serializer.setOutputFormat(format);
>>>> +        } else {
>>>> +            Properties format = 
>>>> OutputPropertiesFactory.getDefaultMethodProperties("text");
>>>> +            serializer = SerializerFactory.getSerializer(format);
>>>
>>> I've got a question here: currently we don't have a TextSerializer, 
>>> so SerializerFactory.getSerializer(format) will return a 
>>> HTMLSerializer. I guess this is not intented in the case of text format.
>>> Or what is your intention with the text format?
>>>
>>>>          }
>>>>          return serializer;
>>>>      }
>>>> Index: impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java
>>>> ===================================================================
>>>> --- 
>>>> impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java    
>>>> (revision 30348)
>>>> +++ 
>>>> impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java    
>>>> (working copy)
>>>> @@ -64,10 +64,6 @@
>>>>      protected static String DEFAULT_VIEW_ID = "default";
>>>>      protected static String SOURCE_VIEW_ID = "source";
>>>>  
>>>> -    protected static String SERIALIZER_OMIT_XML_DECLARATION = 
>>>> "serializer-omit-xml-declaration";
>>>> -    protected static String SERIALIZER_DOCTYPE_PUBLIC = 
>>>> "serializer-doctype-public";
>>>> -    protected static String SERIALIZER_DOCTYPE_SYSTEM = 
>>>> "serializer-doctype-system";
>>>> -
>>>>      protected HashMap viewDescriptors;
>>>>  
>>>>      public ViewDescriptor getViewDescriptor(String viewId) {
>>>> @@ -261,10 +257,8 @@
>>>>  
>>>>              if (mimeType.equals("text/html")) {
>>>>                  serializer = 
>>>> SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL);
>>>> -            } else if (mimeType.equals("application/xml")) {
>>>> -                serializer = 
>>>> SerializerFactory.getSerializer(SerializerFactory.XML);
>>>>              } else {
>>>> -                serializer = 
>>>> SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
>>>> +                serializer = 
>>>> SerializerFactory.getSerializer(SerializerFactory.XML);
>>>
>>> I'm afraid we cannot change the default behavior because some 
>>> existing realms rely on this. With this patch, e.g. the yanel-website 
>>> realm doesn't work anymore.
>>>
>>> josias
>>>
>>>>              }
>>>>          }
>>>>          // allow to override xml declaration and doctype:
>>>>
>>>>
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> _______________________________________________
>>>> Yanel-development mailing list
>>>> Yanel-development at wyona.com
>>>> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>>>
>>> _______________________________________________
>>> Yanel-development mailing list
>>> Yanel-development at wyona.com
>>> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>>>
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development


-- 
+41 79 616 53 76
Optaros - www.optaros.com


More information about the Yanel-development mailing list