001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/CssTaskWebHandler.java,v 1.3 2008/01/29 10:19:45 phuongpdd Exp $
003: * $Author: phuongpdd $
004: * $Revision: 1.3 $
005: * $Date: 2008/01/29 10:19:45 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: */
040: package com.mvnforum.admin;
041:
042: import java.io.FileNotFoundException;
043: import java.io.IOException;
044:
045: import net.myvietnam.mvncore.exception.BadInputException;
046: import net.myvietnam.mvncore.exception.DatabaseException;
047: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
048: import net.myvietnam.mvncore.util.FileUtil;
049: import net.myvietnam.mvncore.util.GenericParamUtil;
050: import net.myvietnam.mvncore.web.GenericRequest;
051:
052: import com.mvnforum.MVNForumGlobal;
053: import com.mvnforum.auth.*;
054:
055: public class CssTaskWebHandler {
056:
057: private OnlineUserManager onlineUserManager = OnlineUserManager
058: .getInstance();
059:
060: public CssTaskWebHandler() {
061: }
062:
063: public void prepareEditCSS(GenericRequest request)
064: throws AuthenticationException, DatabaseException,
065: IOException, FileNotFoundException {
066:
067: OnlineUser onlineUser = onlineUserManager
068: .getOnlineUser(request);
069: MVNForumPermission permission = onlineUser.getPermission();
070: permission.ensureCanAdminSystem();
071:
072: String cssFileName = request
073: .getRealPath(MVNForumGlobal.CSS_FULLPATH);
074: String cssContent = FileUtil.readFile(cssFileName, "UTF-8");
075: cssContent = DisableHtmlTagFilter.filter(cssContent);
076:
077: request.setAttribute("CSSBody", cssContent);
078: }
079:
080: public void processEditCSS(GenericRequest request)
081: throws AuthenticationException, DatabaseException,
082: IOException, FileNotFoundException, BadInputException {
083:
084: OnlineUser onlineUser = onlineUserManager
085: .getOnlineUser(request);
086: MVNForumPermission permission = onlineUser.getPermission();
087: permission.ensureCanAdminSystem();
088:
089: boolean isPreviewing = GenericParamUtil.getParameterBoolean(
090: request, "preview");
091: String cssContent = GenericParamUtil.getParameterSafe(request,
092: "body", true);
093:
094: String CSSFile = (isPreviewing) ? MVNForumGlobal.CSS_PREVIEW_FULLPATH
095: : MVNForumGlobal.CSS_FULLPATH;
096: String CSSPath = request.getRealPath(CSSFile);
097: FileUtil.touch(CSSPath);// make sure we create this file and update the timestamp of this file
098: FileUtil.writeFile(cssContent, CSSPath, "UTF-8");
099:
100: request.setAttribute("IsPreviewing", Boolean
101: .valueOf(isPreviewing));
102: }
103:
104: public void processEditCSS_forRender(GenericRequest request)
105: throws FileNotFoundException, IOException {
106:
107: boolean isPreviewing = ((Boolean) request
108: .getAttribute("IsPreviewing")).booleanValue();
109:
110: String cssFile = (isPreviewing) ? MVNForumGlobal.CSS_PREVIEW_FULLPATH
111: : MVNForumGlobal.CSS_FULLPATH;
112: String cssFileName = request.getRealPath(cssFile);
113: String cssContent = FileUtil.readFile(cssFileName, "UTF-8");
114: cssContent = DisableHtmlTagFilter.filter(cssContent);
115:
116: request.setAttribute("CSSBody", cssContent);
117:
118: if (isPreviewing) {
119: request.setAttribute("csspreview", "yes");
120: } else {
121: request.setAttribute("Success", "yes");
122: }
123: }
124:
125: public void processRestoreCSS(GenericRequest request)
126: throws AuthenticationException, DatabaseException,
127: IOException, FileNotFoundException, BadInputException {
128:
129: OnlineUser onlineUser = onlineUserManager
130: .getOnlineUser(request);
131: MVNForumPermission permission = onlineUser.getPermission();
132: permission.ensureCanAdminSystem();
133:
134: String cssBackup = request
135: .getRealPath(MVNForumGlobal.CSS_BACKUP_FULLPATH);
136: String fileBackup = FileUtil.readFile(cssBackup, "UTF-8");
137: String cssFileName = request
138: .getRealPath(MVNForumGlobal.CSS_FULLPATH);
139: FileUtil.writeFile(fileBackup, cssFileName, "UTF-8");
140: }
141:
142: }
|