KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > config > XMLSerializer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portletcontainer.impl.config;
6
7 import java.io.StringWriter JavaDoc;
8 import java.util.List JavaDoc;
9 import org.exoplatform.commons.xml.ExoXMLSerializer;
10
11 /**
12  * Jul 8, 2004
13  * @author: Tuan Nguyen
14  * @email: tuan08@users.sourceforge.net
15  * @version: $Id: XMLSerializer.java,v 1.1 2004/07/08 19:11:45 tuan08 Exp $
16  */

17 public class XMLSerializer {
18   static private String JavaDoc NS = "" ;
19   
20     static public void toXML(ExoXMLSerializer ser, PortletContainer pc) throws Exception JavaDoc {
21     List JavaDoc list ;
22         ser.startTag(NS, "global"); toXML(ser, pc.getGlobal()); ser.endTag(NS, "global");
23     ser.startTag(NS, "object-pool"); toXML(ser, pc.getObjectPool()); ser.endTag(NS, "object-pool");
24     ser.startTag(NS, "cache"); toXML(ser, pc.getCache()); ser.endTag(NS, "cache");
25     list = pc.getSupportedContent();
26     for(int i = 0; i < list.size(); i++) {
27       ser.startTag(NS, "supported-content");
28       ser.element(NS, "name", ((SupportedContent)list.get(i)).getName());
29       ser.endTag(NS, "supported-content");
30     }
31     list = pc.getCustomMode();
32     for(int i = 0; i < list.size(); i++) {
33       ser.startTag(NS, "custom-mode");
34       toXML(ser, (CustomMode)list.get(i));
35       ser.endTag(NS, "custom-mode");
36     }
37     list = pc.getCustomWindowState();
38     for(int i = 0; i < list.size(); i++) {
39       ser.startTag(NS, "custom-window-state");
40       toXML(ser, (CustomWindowState)list.get(i));
41       ser.endTag(NS, "custom-window-state");
42     }
43     list = pc.getProperties();
44     for(int i = 0; i < list.size(); i++) {
45       ser.startTag(NS, "properties");
46       toXML(ser, (Properties)list.get(i));
47       ser.endTag(NS, "properties");
48     }
49   }
50     
51   static public void toXML(ExoXMLSerializer ser, Global global) throws Exception JavaDoc {
52     ser.element(NS, "name", global.getName()) ;
53     ser.element(NS, "description", global.getDescription()) ;
54     ser.element(NS, "major-version", Integer.toString(global.getMajorVersion())) ;
55     ser.element(NS, "minor-version", Integer.toString(global.getMinorVersion())) ;
56   }
57   
58   static public void toXML(ExoXMLSerializer ser, ObjectPool op) throws Exception JavaDoc {
59     ser.element(NS, "instances-in-pool", Integer.toString(op.getInstancesInPool())) ;
60   }
61   
62   static public void toXML(ExoXMLSerializer ser, Cache cache) throws Exception JavaDoc {
63     ser.element(NS, "enable", cache.getEnable()) ;
64   }
65   
66   static public void toXML(ExoXMLSerializer ser, CustomMode mode) throws Exception JavaDoc {
67     ser.element(NS, "name", mode.getName()) ;
68     List JavaDoc descs = mode.getDescription();
69     for(int i = 0; i < descs.size(); i++) {
70       toXML(ser,(Description)descs.get(i));
71     }
72   }
73   
74   static public void toXML(ExoXMLSerializer ser, CustomWindowState state) throws Exception JavaDoc {
75     ser.element(NS, "name", state.getName()) ;
76     List JavaDoc descs = state.getDescription();
77     for(int i = 0; i < descs.size(); i++) {
78       toXML(ser,(Description)descs.get(i));
79     }
80   }
81   
82   static public void toXML(ExoXMLSerializer ser, Properties props) throws Exception JavaDoc {
83     ser.element(NS, "description", props.getName()) ;
84     ser.element(NS, "name", props.getName()) ;
85     ser.element(NS, "value", props.getValue()) ;
86   }
87   
88   static public void toXML(ExoXMLSerializer ser, Description desc) throws Exception JavaDoc {
89     ser.startTag(NS, "description"); ser.attribute(NS, "lang", desc.getLang()) ;
90     ser.text(desc.getDescription()) ;
91     ser.endTag(NS, "description") ;
92   }
93   
94   static public String JavaDoc toXML(PortletContainer pc) throws Exception JavaDoc {
95     ExoXMLSerializer ser = ExoXMLSerializer.getInstance() ;
96     StringWriter JavaDoc sw = new StringWriter JavaDoc() ;
97     ser.setOutput(sw);
98     ser.startDocument("UTF-8", null); ser.text("\n") ;
99     ser.startTag(NS, "portlet-container") ;
100     toXML(ser, pc) ;
101     ser.endTag(NS, "portlet-container") ;
102     ser.endDocument();
103     return sw.getBuffer().toString() ;
104   }
105 }
Popular Tags