1 5 package org.exoplatform.services.portletcontainer.impl.config; 6 7 import java.io.InputStream ; 8 import org.exoplatform.commons.xml.ExoXPPParser; 9 10 11 17 public class XMLParser { 18 19 static public PortletContainer readPortletContainer(ExoXPPParser xpp ) throws Exception { 20 PortletContainer pc = new PortletContainer() ; 21 xpp.mandatoryNode("global"); pc.setGlobal(readGlobal(xpp)) ; 22 if(xpp.node("shared-session")) pc.setSharedSession(readSharedSession(xpp)) ; 23 24 if(xpp.node("delegated-bundle")) pc.setDelegatedBundle(readDelegatedBundle(xpp)) ; 25 if(xpp.node("object-pool")) pc.setObjectPool(readObjectPool(xpp)) ; 26 if(xpp.node("cache")) pc.setCache(readCache(xpp)) ; 27 while(xpp.node("supported-content")) pc.addSupportedContent(readSupportedContent(xpp)) ; 28 while(xpp.node("custom-mode")) pc.addCustomMode(readCustomMode(xpp)) ; 29 while(xpp.node("custom-window-state")) pc.addCustomWindowState(readCustomWindowState(xpp)) ; 30 while(xpp.node("properties")) pc.addProperties(readProperties(xpp)) ; 31 return pc ; 32 } 33 34 35 36 static public Global readGlobal(ExoXPPParser xpp) throws Exception { 37 Global global = new Global() ; 38 xpp.mandatoryNode("name"); global.setName(xpp.getContent()) ; 39 if(xpp.node("description")) global.setDescription(xpp.getContent()) ; 40 xpp.mandatoryNode("major-version"); global.setMajorVersion(Integer.parseInt(xpp.getContent())) ; 41 xpp.mandatoryNode("minor-version"); global.setMinorVersion(Integer.parseInt(xpp.getContent())) ; 42 return global ; 43 } 44 45 static public SharedSession readSharedSession(ExoXPPParser xpp) throws Exception { 46 SharedSession ss = new SharedSession() ; 47 xpp.mandatoryNode("enable"); ss.setEnable(xpp.getContent()) ; 48 return ss ; 49 } 50 51 public static DelegatedBundle readDelegatedBundle(ExoXPPParser xpp) throws Exception { 52 DelegatedBundle dB = new DelegatedBundle(); 53 xpp.mandatoryNode("enable"); dB.setEnable(xpp.getContent()); 54 return dB; 55 } 56 57 static public ObjectPool readObjectPool(ExoXPPParser xpp) throws Exception { 58 ObjectPool op = new ObjectPool() ; 59 xpp.mandatoryNode("instances-in-pool"); op.setInstancesInPool(Integer.parseInt(xpp.getContent())); 60 return op ; 61 } 62 63 static public Cache readCache(ExoXPPParser xpp) throws Exception { 64 Cache cache = new Cache() ; 65 xpp.mandatoryNode("enable"); cache.setEnable(xpp.getContent()) ; 66 return cache ; 67 } 68 69 static public Description readDescription(ExoXPPParser xpp) throws Exception { 70 Description desc = new Description() ; 71 desc.setLang(xpp.getNodeAttributeValue("lang")) ; 72 desc.setDescription(xpp.getContent()) ; 73 return desc ; 74 } 75 76 static public SupportedContent readSupportedContent(ExoXPPParser xpp) throws Exception { 77 SupportedContent supportedContent = new SupportedContent() ; 78 xpp.mandatoryNode("name"); supportedContent.setName(xpp.getContent()) ; 79 return supportedContent ; 80 } 81 82 static public CustomMode readCustomMode(ExoXPPParser xpp) throws Exception { 83 CustomMode cmode = new CustomMode() ; 84 xpp.mandatoryNode("name"); cmode.setName(xpp.getContent()) ; 85 while(xpp.node("description")) { 86 cmode.addDescription(readDescription(xpp)); 87 } 88 return cmode ; 89 } 90 91 static public Properties readProperties(ExoXPPParser xpp) throws Exception { 92 Properties props = new Properties() ; 93 xpp.mandatoryNode("description") ; props.setDescription(xpp.getContent()) ; 94 xpp.mandatoryNode("name"); props.setName(xpp.getContent()) ; 95 xpp.mandatoryNode("value"); props.setValue(xpp.getContent()) ; 96 return props ; 97 } 98 99 static public CustomWindowState readCustomWindowState(ExoXPPParser xpp) throws Exception { 100 CustomWindowState state = new CustomWindowState() ; 101 xpp.mandatoryNode("name"); state.setName(xpp.getContent()) ; 102 while(xpp.node("description")) { 103 state.addDescription(readDescription(xpp)); 104 } 105 return state ; 106 } 107 108 static public PortletContainer parse(InputStream is) throws Exception { 109 ExoXPPParser xpp = ExoXPPParser.getInstance() ; 110 xpp.setInput (is, "UTF8"); 111 xpp.mandatoryNode("portlet-container") ; 112 return readPortletContainer(xpp) ; 113 } 114 } | Popular Tags |