KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > datatypes > processors > xml > Modes


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.datatypes.processors.xml;
11 import org.mmbase.util.logging.*;
12
13 /**
14  * XML-modes. XML-modes can be attributed to a Cloud (using {@link org.mmbase.bridge.Cloud#setProperty}
15  * and {@link org.mmbase.bridge.Cloud#PROP_XMLMODE}) and influence how an XML field must behave
16  * itself. XML is all about flexibility of presentation, and this mode regulates that.
17  *
18  * It boils down to the fact that 'processors' can be plugged on XML fields which can use
19  * this 'mode' to behave differently.
20  *
21  * Most modes will influence especially {@link org.mmbase.bridge.Node#setStringValue(String,
22  * String)} and {@link org.mmbase.bridge.Node#getStringValue(String)}. (depending on the
23  * datatypes.xml), but some modes could also set/get XMLValue.
24  *
25  * @author Michiel Meeuwissen
26  * @version $Id: Modes.java,v 1.4 2006/04/11 23:46:06 michiel Exp $
27  * @since MMBase-1.8
28  */

29
30 public abstract class Modes {
31     private static final Logger log = Logging.getLoggerInstance(Modes.class);
32
33     /**
34      * The 'XML' mode should mean that the XML will be sent and expected as 'pure' as possible. E.g.
35      * getString of an XML value in 'XML' mode should normally return a straight-forward
36      * stringification of the XML.
37      */

38     public static final int XML = 0;
39
40
41     /**
42      * PRETTYXML is like XML, but one could expect extra indentation and newlines to make the XML
43      * more readable for humans. So, on getString you could expect a String which is not quite the
44      * XML from the database, but chances are that it is equivalent.
45      */

46     public static final int PRETTYXML = 1;
47
48     /**
49      * FLAT would return only the text from an XML field, so plain text without all XML
50      * markup. Setting an XML value in 'FLAT' mode would generally be far from perfect.
51      */

52     public static final int FLAT = 2;
53
54     /**
55      * WIKI is a bit like FLAT, but effort is made to give a better representation of the XML in
56      * plain text. This mode could probably even be used when setting the field (This works e.g. quite
57      * well for 'mmxf' fields).
58      */

59     public static final int WIKI = 3;
60
61     /**
62      * KUPU-mode should trigger relations to be followed (on get) and be created (on set), and
63      * should give and receive XHTML which will be (on get) or was (on set) edited by the 'kupu'
64      * editor. See <a HREF="http://kupu.oscom.org">kupu</a>.
65      */

66     public static final int KUPU = 4;
67
68
69     /**
70      * Makes the field look like Docbook XML. So, this could be implemented on get/set XMLValue as well.
71      */

72     public static final int DOCBOOK = 5;
73
74
75     /**
76      * Converts a String identifier to one of the constants in this class
77      */

78     public static int getMode(Object JavaDoc m) {
79         if (m == null) return XML;
80         String JavaDoc mode = ("" + m).toLowerCase();
81         if ("xml".equals(mode)) {
82             return XML;
83         } else if ("prettyxml".equals(mode)) {
84             return PRETTYXML;
85         } else if ("flat".equals(mode)) {
86             return FLAT;
87         } else if ("wiki".equals(mode)) {
88             return WIKI;
89         } else if ("kupu".equals(mode)) {
90             return KUPU;
91         } else if ("docbook".equals(mode)) {
92             return DOCBOOK;
93         } else {
94             log.warn("Unknown mode " + mode, new Exception JavaDoc());
95             return XML;
96         }
97     }
98 }
99
Popular Tags