1 package org.exoplatform.services.portal.skin.converter; 2 3 import java.util.* ; 4 import org.exoplatform.services.portal.skin.model.*; 5 6 import com.thoughtworks.xstream.converters.Converter; 7 import com.thoughtworks.xstream.converters.MarshallingContext; 8 import com.thoughtworks.xstream.converters.UnmarshallingContext; 9 import com.thoughtworks.xstream.io.HierarchicalStreamReader; 10 import com.thoughtworks.xstream.io.HierarchicalStreamWriter; 11 12 15 public class SkinConfigConverter implements Converter { 16 17 public boolean canConvert(Class type) { 18 return type.equals(SkinConfig.class) ; 19 } 20 21 public void marshal(Object source, HierarchicalStreamWriter w, MarshallingContext context) { 22 SkinConfig config = (SkinConfig) source ; 23 throw new Error ("Not support marshall yet") ; 24 } 25 26 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { 27 SkinConfig config = new SkinConfig() ; 28 while (reader.hasMoreChildren()) { 29 reader.moveDown(); 30 String nodeName = reader.getNodeName() ; 31 if("portal-decorators".equals(nodeName)) { 32 config.setPortalDecorators((List)context.convertAnother(config, List.class)) ; 33 } else if("page-decorators".equals(nodeName)) { 34 config.setPageDecorators((List)context.convertAnother(config, List.class)) ; 35 } else if("container-decorators".equals(nodeName)) { 36 config.setContainerDecorators((List)context.convertAnother(config, List.class)) ; 37 } else if("portlet-decorators".equals(nodeName)) { 38 config.setPortletDecorators((List)context.convertAnother(config, List.class)) ; 39 } else { 40 Object o = context.convertAnother(config, PortletStyleConfig.class) ; 41 config.getPortletStyleConfig().add(o) ; 42 } 43 reader.moveUp(); 44 } 45 return config ; 46 } 47 } | Popular Tags |