KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > admin > SetupTheme


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002,2003 Fraunhofer Gesellschaft
5  * Fraunhofer Institut for Computer Architecture and Software Technology
6  * All Rights Reserved.
7  *
8  * Please visit http://snipsnap.org/ for updates and contact.
9  *
10  * --LICENSE NOTICE--
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  * --LICENSE NOTICE--
25  */

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 JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37 import java.io.File JavaDoc;
38 import java.io.FileInputStream JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.util.Arrays JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.Map JavaDoc;
43
44 public class SetupTheme implements SetupHandler {
45   public String JavaDoc getName() {
46     return "theme";
47   }
48
49   List JavaDoc ignoreElements = Arrays.asList(new String JavaDoc[]{
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 JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
63     String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc themeFile = (File JavaDoc) ThemeHelper.getThemeDocuments(config, ThemeHelper.FILES).get(themeName);
81           XMLSnipImport.load(new FileInputStream JavaDoc(themeFile), XMLSnipImport.OVERWRITE | XMLSnipImport.IMPORT_SNIPS);
82         } catch (IOException JavaDoc 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