1 26 package org.snipsnap.net.admin; 27 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.container.Components; 30 import org.snipsnap.snip.SnipSpace; 31 import org.snipsnap.snip.XMLSnipExport; 32 import org.snipsnap.snip.XMLSnipImport; 33 import org.snipsnap.snip.storage.SnipSerializer; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.io.File ; 38 import java.io.FileInputStream ; 39 import java.io.IOException ; 40 import java.util.Arrays ; 41 import java.util.List ; 42 import java.util.Map ; 43 44 public class SetupTheme implements SetupHandler { 45 public String getName() { 46 return "theme"; 47 } 48 49 List ignoreElements = Arrays.asList(new String []{ 50 SnipSerializer.SNIP_APPLICATION, 51 SnipSerializer.SNIP_BACKLINKS, 52 SnipSerializer.SNIP_CUSER, 53 SnipSerializer.SNIP_MUSER, 54 SnipSerializer.SNIP_OUSER, 55 SnipSerializer.SNIP_PARENT, 56 SnipSerializer.SNIP_COMMENTED, 57 SnipSerializer.SNIP_SNIPLINKS, 58 SnipSerializer.SNIP_VERSION, 59 SnipSerializer.SNIP_VIEWCOUNT 60 }); 61 62 public Map setup(HttpServletRequest request, HttpServletResponse response, Configuration config, Map errors) { 63 String themeName = request.getParameter(Configuration.APP_THEME); 64 65 if (config.isConfigured() ) { 66 if (request.getParameter("export") != null && ThemeHelper.getInstalledThemes().containsKey(themeName)) { 67 SnipSpace space = (SnipSpace) Components.getComponent(SnipSpace.class); 68 List snips = Arrays.asList(space.match("SnipSnap/themes/" + themeName)); 69 70 response.setContentType("text/xml"); 71 try { 72 XMLSnipExport.store(response.getOutputStream(), snips, null, null, ignoreElements, config.getFilePath()); 73 return null; 74 } catch (IOException e) { 75 errors.put("config.theme.export", "config.theme.export"); 76 return errors; 77 } 78 } else if(!ThemeHelper.getInstalledThemes().containsKey(themeName)) { 79 try { 80 File themeFile = (File ) ThemeHelper.getThemeDocuments(config, ThemeHelper.FILES).get(themeName); 81 XMLSnipImport.load(new FileInputStream (themeFile), XMLSnipImport.OVERWRITE | XMLSnipImport.IMPORT_SNIPS); 82 } catch (IOException e) { 83 errors.put(Configuration.APP_THEME, Configuration.APP_THEME); 84 e.printStackTrace(); 85 return errors; 86 } 87 } 88 } 89 90 config.setTheme(themeName); 91 return errors; 92 } 93 94 } 95 | Popular Tags |