[Yanel-dev] XML resource patch
Josias Thöny
josias.thoeny at wyona.com
Wed Jan 16 11:03:48 CET 2008
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
More information about the Yanel-development
mailing list