[Yanel-dev] XML resource patch
Josias Thöny
josias.thoeny at wyona.com
Wed Jan 16 11:56:34 CET 2008
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=3D"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=F6ny 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
>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>>> --- =
>>> 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 =3D 1;
>>> public static final int HTML_TRANSITIONAL =3D 2;
>>> public static final int XML =3D 3;
>>> + public static final int TEXT =3D 4;
>>> public static final String XHTML_STRICT_KEY =3D "XHTML_STRICT=
";
>>> public static final String HTML_TRANSITIONAL_KEY =3D =
>>> "HTML_TRANSITIONAL";
>>> public static final String XML_KEY =3D "XML";
>>> + public static final String TEXT_KEY =3D "TEXT";
>>> =
>>> public static Serializer getSerializer(Properties format) {
>>> Serializer serializer =3D 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 =3D=3D HTML_TRANSITIONAL) {
>>> + }else if (key =3D=3D HTML_TRANSITIONAL) {
>>> serializer =3D new HTMLSerializer();
>>> Properties format =3D =
>>> 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 =3D=3D XML) {
>>> + }else if (key =3D=3D XML) {
>>> serializer =3D new XMLSerializer();
>>> Properties format =3D =
>>> OutputPropertiesFactory.getDefaultMethodProperties("xml");
>>> format.setProperty("indent", "yes");
>>> serializer.setOutputFormat(format);
>>> + } else {
>>> + Properties format =3D =
>>> OutputPropertiesFactory.getDefaultMethodProperties("text");
>>> + serializer =3D 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
>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>>> --- 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 =3D "default";
>>> protected static String SOURCE_VIEW_ID =3D "source";
>>> =
>>> - protected static String SERIALIZER_OMIT_XML_DECLARATION =3D =
>>> "serializer-omit-xml-declaration";
>>> - protected static String SERIALIZER_DOCTYPE_PUBLIC =3D =
>>> "serializer-doctype-public";
>>> - protected static String SERIALIZER_DOCTYPE_SYSTEM =3D =
>>> "serializer-doctype-system";
>>> -
>>> protected HashMap viewDescriptors;
>>> =
>>> public ViewDescriptor getViewDescriptor(String viewId) {
>>> @@ -261,10 +257,8 @@
>>> =
>>> if (mimeType.equals("text/html")) {
>>> serializer =3D =
>>> SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL);
>>> - } else if (mimeType.equals("application/xml")) {
>>> - serializer =3D =
>>> SerializerFactory.getSerializer(SerializerFactory.XML);
>>> } else {
>>> - serializer =3D =
>>> SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
>>> + serializer =3D =
>>> 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
>>
> =
> =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_omit_document_type.diff
Type: text/x-patch
Size: 2156 bytes
Desc: not available
Url : http://lists.wyona.org/pipermail/yanel-development/attachments/200801=
16/789e0859/patch_omit_document_type.bin
More information about the Yanel-development
mailing list