1 5 package org.exoplatform.services.portletcontainer.impl.config; 6 7 import java.io.StringWriter ; 8 import java.util.List ; 9 import org.exoplatform.commons.xml.ExoXMLSerializer; 10 11 17 public class XMLSerializer { 18 static private String NS = "" ; 19 20 static public void toXML(ExoXMLSerializer ser, PortletContainer pc) throws Exception { 21 List 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 { 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 { 59 ser.element(NS, "instances-in-pool", Integer.toString(op.getInstancesInPool())) ; 60 } 61 62 static public void toXML(ExoXMLSerializer ser, Cache cache) throws Exception { 63 ser.element(NS, "enable", cache.getEnable()) ; 64 } 65 66 static public void toXML(ExoXMLSerializer ser, CustomMode mode) throws Exception { 67 ser.element(NS, "name", mode.getName()) ; 68 List 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 { 75 ser.element(NS, "name", state.getName()) ; 76 List 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 { 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 { 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 toXML(PortletContainer pc) throws Exception { 95 ExoXMLSerializer ser = ExoXMLSerializer.getInstance() ; 96 StringWriter sw = new StringWriter () ; 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 |