KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > impl > PortalConfigImporterExporter


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.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 /**
20  * May 27, 2004
21  * @author: Tuan Nguyen
22  * @email: tuan08@users.sourceforge.net
23  * @version: $ID$
24  **/

25 public class PortalConfigImporterExporter implements ImporterExporter {
26   private XStream xstream_ ;
27   
28   public PortalConfigImporterExporter() {
29     xstream_ = PortalConfigServiceImpl.getXStreamInstance() ;
30   }
31   
32   public String JavaDoc getName() { return "portal-config" ;}
33   
34   public String JavaDoc getDescription() {
35     return "Export portal config and pages" ;
36   }
37   
38   public void exportUserData(String JavaDoc userName, Object JavaDoc transaction,
39                              OutputStream out, JarEntry entry) throws Exception JavaDoc {
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 JavaDoc xml = xstream_.toXML(backup) ;
52     out.write(xml.getBytes()) ;
53   }
54   
55   public void importUserData(String JavaDoc userName, Object JavaDoc transaction,
56                              InputStream is, JarEntry entry) throws Exception JavaDoc {
57     Session session = (Session) transaction;
58     String JavaDoc 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 JavaDoc transaction, JarOutputStream out) throws Exception JavaDoc {
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 JavaDoc transaction, JarFile jar) throws Exception JavaDoc {
77     
78   }
79 }
Popular Tags