1 5 package org.exoplatform.services.portal.impl; 6 7 import java.util.* ; 8 import java.util.jar.* ; 9 import java.io.* ; 10 import org.exoplatform.commons.utils.IOUtil; 11 import org.exoplatform.services.backup.ImporterExporter; 12 import org.exoplatform.services.portal.model.*; 13 14 import com.thoughtworks.xstream.XStream; 15 16 import net.sf.hibernate.Hibernate; 17 import net.sf.hibernate.Session; 18 19 25 public class PortalConfigImporterExporter implements ImporterExporter { 26 private XStream xstream_ ; 27 28 public PortalConfigImporterExporter() { 29 xstream_ = PortalConfigServiceImpl.getXStreamInstance() ; 30 } 31 32 public String getName() { return "portal-config" ;} 33 34 public String getDescription() { 35 return "Export portal config and pages" ; 36 } 37 38 public void exportUserData(String userName, Object transaction, 39 OutputStream out, JarEntry entry) throws Exception { 40 Session session = (Session) transaction; 41 PortalConfigData data = 42 (PortalConfigData) session.get(PortalConfigData.class, userName) ; 43 PortalConfig pconfig = data.getPortalConfig() ; 44 List l = session.find(PortalConfigServiceImpl.queryPageDataByOwner, userName, Hibernate.STRING) ; 45 List pages = new ArrayList(l.size()) ; 46 for(int i = 0 ; i < l.size(); i++) { 47 PageData pageData = (PageData) l.get(i) ; 48 pages.add(pageData.getPage()) ; 49 } 50 Backup backup = new Backup(pconfig, pages, null) ; 51 String xml = xstream_.toXML(backup) ; 52 out.write(xml.getBytes()) ; 53 } 54 55 public void importUserData(String userName, Object transaction, 56 InputStream is, JarEntry entry) throws Exception { 57 Session session = (Session) transaction; 58 String xml = IOUtil.getStreamContentAsString(is) ; 59 Backup backup = (Backup)xstream_.fromXML(xml) ; 60 PortalConfig pconfig = backup.getPortalConfig() ; 61 List pages = backup.getPages() ; 62 session.saveOrUpdateCopy(new PortalConfigData(pconfig)) ; 63 for(int i = 0; i < pages.size(); i++) { 64 Page page = (Page)pages.get(i) ; 65 session.saveOrUpdateCopy(new PageData(page)) ; 66 } 67 } 68 69 public void exportServiceData(Object transaction, JarOutputStream out) throws Exception { 70 JarEntry entry = new JarEntry("data.xml") ; 71 out.putNextEntry(entry) ; 72 out.write("no data available".getBytes()); 73 out.closeEntry() ; 74 } 75 76 public void importServiceData(Object transaction, JarFile jar) throws Exception { 77 78 } 79 } | Popular Tags |