1 18 21 package org.apache.roller.ui.authoring.struts.actions; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import javax.servlet.ServletException ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 import org.apache.struts.action.ActionError; 31 import org.apache.struts.action.ActionErrors; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 import org.apache.struts.action.ActionMessage; 36 import org.apache.struts.action.ActionMessages; 37 import org.apache.struts.actions.DispatchAction; 38 import org.apache.roller.RollerException; 39 import org.apache.roller.model.RollerFactory; 40 import org.apache.roller.pojos.WebsiteData; 41 import org.apache.roller.ui.core.RollerRequest; 42 import org.apache.roller.ui.core.RollerSession; 43 import org.apache.roller.util.cache.CacheManager; 44 import org.apache.roller.ui.authoring.struts.formbeans.ImportEntriesForm; 45 import org.apache.commons.lang.StringUtils; 46 47 56 public class ImportEntriesAction extends DispatchAction 57 { 58 public ActionForward importEntries( 59 ActionMapping mapping, 60 ActionForm actionForm, 61 HttpServletRequest request, 62 HttpServletResponse response) 63 throws IOException , ServletException 64 { 65 ActionForward forward = mapping.findForward("importEntries.page"); 66 try 67 { 68 RollerRequest rreq = RollerRequest.getRollerRequest(request); 69 RollerSession rollerSession = RollerSession.getRollerSession(rreq.getRequest()); 70 if ( rreq.getWebsite() == null 71 || !rollerSession.isUserAuthorizedToAdmin(rreq.getWebsite())) 72 { 73 forward = mapping.findForward("access-denied"); 74 } 75 else 76 { 77 getXmlFiles(actionForm, rreq); 78 ImportEntriesForm form = (ImportEntriesForm)actionForm; 79 if (StringUtils.isNotEmpty(form.getImportFileName())) 80 { 81 WebsiteData website = rreq.getWebsite(); 83 84 String dir = RollerFactory.getRoller().getFileManager().getUploadDir(); 86 File f = new File (dir + website.getHandle() + 87 "/" + form.getImportFileName()); 88 89 String parseMessages = null; 93 if (parseMessages.length() > 0) 95 { 96 ActionMessages notices = new ActionMessages(); 97 notices.add(ActionMessages.GLOBAL_MESSAGE, 98 new ActionMessage("weblogEntryImport.importFiles", 99 parseMessages)); 100 saveMessages(request, notices); 101 102 CacheManager.invalidate(website); 105 } 106 else 107 { 108 ActionErrors errors = new ActionErrors(); 109 errors.add(ActionErrors.GLOBAL_ERROR, 110 new ActionError("error.importing.entries", "")); 111 saveErrors(request,errors); 112 } 113 } 114 } 115 } 116 catch (Exception e) 117 { 118 request.getSession().getServletContext().log("ERROR",e); 119 throw new ServletException (e); 120 } 121 return forward; 122 } 123 124 134 public ActionForward edit( 135 ActionMapping mapping, 136 ActionForm actionForm, 137 HttpServletRequest request, 138 HttpServletResponse response) 139 throws IOException , ServletException 140 { 141 ActionForward forward = mapping.findForward("importEntries.page"); 142 try 143 { 144 RollerRequest rreq = RollerRequest.getRollerRequest(request); 145 RollerSession rses = RollerSession.getRollerSession(request); 146 if ( rreq.getWebsite() == null 147 || !rses.isUserAuthorizedToAdmin(rreq.getWebsite()) ) 148 { 149 forward = mapping.findForward("access-denied"); 150 } 151 else 152 { 153 getXmlFiles(actionForm, rreq); 154 } 155 } 156 catch (Exception e) 157 { 158 request.getSession().getServletContext().log("ERROR",e); 159 throw new ServletException (e); 160 } 161 return forward; 162 } 163 164 private void getXmlFiles(ActionForm actionForm, RollerRequest rreq) 165 { 166 String dir = null; 167 try { 168 RollerFactory.getRoller().getFileManager().getUploadDir(); 169 } catch(RollerException re) { 170 } 172 173 File d = new File (dir + rreq.getWebsite().getHandle()); 174 ArrayList xmlFiles = new ArrayList (); 175 if (d.mkdirs() || d.exists()) 176 { 177 File [] files = d.listFiles(); 178 for (int i=0; i<files.length; i++) 179 { 180 if (!files[i].isDirectory() && 181 files[i].getName().toLowerCase().endsWith(".xml")) 182 { 184 xmlFiles.add(files[i].getName()); 185 } 186 } 187 } 188 ImportEntriesForm form = (ImportEntriesForm)actionForm; 189 form.setXmlFiles(xmlFiles); 190 } 191 } 192 | Popular Tags |