1 4 package org.roller.presentation.weblog.actions; 5 6 import java.io.File ; 7 import java.io.IOException ; 8 import java.util.ArrayList ; 9 10 import javax.servlet.ServletContext ; 11 import javax.servlet.ServletException ; 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpServletResponse ; 14 15 import org.apache.struts.action.ActionError; 16 import org.apache.struts.action.ActionErrors; 17 import org.apache.struts.action.ActionForm; 18 import org.apache.struts.action.ActionForward; 19 import org.apache.struts.action.ActionMapping; 20 import org.apache.struts.action.ActionMessage; 21 import org.apache.struts.action.ActionMessages; 22 import org.apache.struts.actions.DispatchAction; 23 import org.roller.pojos.UserData; 24 import org.roller.presentation.MainPageAction; 25 import org.roller.presentation.RollerContext; 26 import org.roller.presentation.RollerRequest; 27 import org.roller.presentation.pagecache.PageCacheFilter; 28 import org.roller.presentation.weblog.formbeans.ImportEntriesForm; 29 import org.roller.util.StringUtils; 30 31 40 public class ImportEntriesAction extends DispatchAction 41 { 42 public ActionForward importEntries( 43 ActionMapping mapping, 44 ActionForm actionForm, 45 HttpServletRequest request, 46 HttpServletResponse response) 47 throws IOException , ServletException 48 { 49 ActionForward forward = mapping.findForward("importEntries.page"); 50 try 51 { 52 RollerRequest rreq = RollerRequest.getRollerRequest(request); 53 if ( !rreq.isUserAuthorizedToEdit() ) 54 { 55 forward = mapping.findForward("access-denied"); 56 } 57 else 58 { 59 getXmlFiles(actionForm, rreq); 60 ImportEntriesForm form = (ImportEntriesForm)actionForm; 61 if (StringUtils.isNotEmpty(form.getImportFileName())) 62 { 63 UserData user = rreq.getUser(); 65 66 ServletContext app = this.getServlet().getServletConfig().getServletContext(); 68 String dir = RollerContext.getUploadDir( app ); 69 File f = new File (dir + user.getUserName() + 70 "/" + form.getImportFileName()); 71 72 String parseMessages = null; 76 if (parseMessages.length() > 0) 78 { 79 ActionMessages notices = new ActionMessages(); 80 notices.add(ActionMessages.GLOBAL_MESSAGE, 81 new ActionMessage("weblogEntryImport.importFiles", 82 parseMessages)); 83 saveMessages(request, notices); 84 85 PageCacheFilter.removeFromCache( request, user ); 87 MainPageAction.flushMainPageCache(); 89 } 90 else 91 { 92 ActionErrors errors = new ActionErrors(); 93 errors.add(ActionErrors.GLOBAL_ERROR, 94 new ActionError("error.importing.entries", "")); 95 saveErrors(request,errors); 96 } 97 } 98 } 99 } 100 catch (Exception e) 101 { 102 request.getSession().getServletContext().log("ERROR",e); 103 throw new ServletException (e); 104 } 105 return forward; 106 } 107 108 118 public ActionForward edit( 119 ActionMapping mapping, 120 ActionForm actionForm, 121 HttpServletRequest request, 122 HttpServletResponse response) 123 throws IOException , ServletException 124 { 125 ActionForward forward = mapping.findForward("importEntries.page"); 126 try 127 { 128 RollerRequest rreq = RollerRequest.getRollerRequest(request); 129 if ( !rreq.isUserAuthorizedToEdit() ) 130 { 131 forward = mapping.findForward("access-denied"); 132 } 133 else 134 { 135 getXmlFiles(actionForm, rreq); 136 } 137 } 138 catch (Exception e) 139 { 140 request.getSession().getServletContext().log("ERROR",e); 141 throw new ServletException (e); 142 } 143 return forward; 144 } 145 146 private void getXmlFiles(ActionForm actionForm, RollerRequest rreq) 147 { 148 ServletContext app = this.getServlet().getServletConfig().getServletContext(); 149 String dir = RollerContext.getUploadDir( app ); 150 File d = new File (dir + rreq.getUser().getUserName()); 151 ArrayList xmlFiles = new ArrayList (); 152 if (d.mkdirs() || d.exists()) 153 { 154 File [] files = d.listFiles(); 155 for (int i=0; i<files.length; i++) 156 { 157 if (!files[i].isDirectory() && 158 files[i].getName().toLowerCase().endsWith(".xml")) 159 { 161 xmlFiles.add(files[i].getName()); 162 } 163 } 164 } 165 ImportEntriesForm form = (ImportEntriesForm)actionForm; 166 form.setXmlFiles(xmlFiles); 167 } 168 } 169 | Popular Tags |