1 18 19 package org.apache.roller.ui.authoring.struts.actions; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.io.InputStreamReader ; 24 import java.io.OutputStreamWriter ; 25 import java.net.HttpURLConnection ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 import java.net.URLEncoder ; 29 import java.sql.Timestamp ; 30 import java.text.MessageFormat ; 31 import java.util.ArrayList ; 32 import java.util.Date ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Map ; 37 import java.util.ResourceBundle ; 38 import java.util.regex.Matcher ; 39 import java.util.regex.Pattern ; 40 import javax.mail.MessagingException ; 41 import javax.mail.Session ; 42 import javax.naming.InitialContext ; 43 import javax.naming.NamingException ; 44 import javax.servlet.ServletException ; 45 import javax.servlet.http.HttpServletRequest ; 46 import javax.servlet.http.HttpServletResponse ; 47 import javax.servlet.http.HttpSession ; 48 import org.apache.commons.lang.StringEscapeUtils; 49 import org.apache.commons.logging.Log; 50 import org.apache.commons.logging.LogFactory; 51 import org.apache.struts.action.ActionError; 52 import org.apache.struts.action.ActionErrors; 53 import org.apache.struts.action.ActionForm; 54 import org.apache.struts.action.ActionForward; 55 import org.apache.struts.action.ActionMapping; 56 import org.apache.struts.action.ActionMessage; 57 import org.apache.struts.action.ActionMessages; 58 import org.apache.struts.actions.DispatchAction; 59 import org.apache.struts.util.RequestUtils; 60 import org.apache.roller.RollerException; 61 import org.apache.roller.RollerPermissionsException; 62 import org.apache.roller.config.RollerConfig; 63 import org.apache.roller.model.IndexManager; 64 import org.apache.roller.model.PluginManager; 65 import org.apache.roller.model.Roller; 66 import org.apache.roller.model.RollerFactory; 67 import org.apache.roller.model.UserManager; 68 import org.apache.roller.model.WeblogManager; 69 import org.apache.roller.pojos.PermissionsData; 70 import org.apache.roller.pojos.UserData; 71 import org.apache.roller.pojos.WeblogEntryData; 72 import org.apache.roller.pojos.WebsiteData; 73 import org.apache.roller.ui.core.RollerContext; 74 import org.apache.roller.ui.core.RollerRequest; 75 import org.apache.roller.ui.core.RollerSession; 76 import org.apache.roller.util.cache.CacheManager; 77 import org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryFormEx; 78 import org.apache.roller.util.MailUtil; 79 import org.apache.commons.lang.StringUtils; 80 import org.apache.roller.config.RollerRuntimeConfig; 81 import org.apache.roller.ui.core.RequestConstants; 82 import org.apache.roller.util.Utilities; 83 84 85 86 96 public final class WeblogEntryFormAction extends DispatchAction { 97 private static Log mLogger = 98 LogFactory.getFactory().getInstance(WeblogEntryFormAction.class); 99 100 104 public ActionForward create( 105 ActionMapping mapping, 106 ActionForm actionForm, 107 HttpServletRequest request, 108 HttpServletResponse response) 109 throws IOException , ServletException { 110 ActionForward forward = mapping.findForward("weblogEdit.page"); 111 try { 112 RollerSession rses = RollerSession.getRollerSession(request); 113 RollerRequest rreq = RollerRequest.getRollerRequest(request); 114 if (rreq.getWebsite() != null 115 && rses.isUserAuthorized(rreq.getWebsite())) { 116 WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm; 117 form.initNew(request, response); 118 form.setCreatorId(rses.getAuthenticatedUser().getId()); 119 form.setWebsiteId(rreq.getWebsite().getId()); 120 form.setAllowComments(rreq.getWebsite().getDefaultAllowComments()); 121 form.setCommentDays(new Integer (rreq.getWebsite().getDefaultCommentDays())); 122 123 request.setAttribute("model", 124 new WeblogEntryPageModel(request, response, mapping, 125 (WeblogEntryFormEx)actionForm, 126 WeblogEntryPageModel.EDIT_MODE)); 127 } else { 128 forward = mapping.findForward("access-denied"); 129 } 130 } catch (Exception e) { 131 request.getSession().getServletContext().log("ERROR",e); 132 throw new ServletException (e); 133 } 134 return forward; 135 } 136 137 141 public ActionForward edit( 142 ActionMapping mapping, 143 ActionForm actionForm, 144 HttpServletRequest request, 145 HttpServletResponse response) 146 throws IOException , ServletException { 147 ActionForward forward = mapping.findForward("weblogEdit.page"); 148 try { 149 RollerRequest rreq = RollerRequest.getRollerRequest(request); 150 RollerSession rses = RollerSession.getRollerSession(request); 151 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 152 WeblogEntryData entry = rreq.getWeblogEntry(); 153 WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm; 154 if (entry == null && form.getId() != null) { 155 entry = wmgr.getWeblogEntry(form.getId()); 156 } 157 if (entry == null) { 158 ResourceBundle resources = ResourceBundle.getBundle( 159 "ApplicationResources", request.getLocale()); 160 request.setAttribute("javax.servlet.error.message", 161 resources.getString("weblogEntry.notFound")); 162 forward = mapping.findForward("error"); 163 } else if (rses.isUserAuthorized(entry.getWebsite()) 164 || (rses.isUserAuthorized(entry.getWebsite()) && !entry.isPublished())) { 165 form.copyFrom(entry, request.getLocale()); 166 WeblogEntryPageModel pageModel = new WeblogEntryPageModel( 167 request, response, mapping, form, 168 WeblogEntryPageModel.EDIT_MODE); 169 pageModel.setWebsite(entry.getWebsite()); 170 request.setAttribute("model", pageModel); 171 } else { 172 forward = mapping.findForward("access-denied"); 173 } 174 } catch (Exception e) { 175 request.getSession().getServletContext().log("ERROR",e); 176 throw new ServletException (e); 177 } 178 return forward; 179 } 180 181 public ActionForward preview( 183 ActionMapping mapping, 184 ActionForm actionForm, 185 HttpServletRequest request, 186 HttpServletResponse response) 187 throws IOException , ServletException { 188 WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm; 190 if (form.getId() == null) { 191 save(mapping, actionForm, request, response); 192 } 193 return display(WeblogEntryPageModel.PREVIEW_MODE, 194 mapping, actionForm, request, response); 195 } 196 197 public ActionForward returnToEditMode( 199 ActionMapping mapping, 200 ActionForm actionForm, 201 HttpServletRequest request, 202 HttpServletResponse response) 203 throws IOException , ServletException { 204 return display(WeblogEntryPageModel.EDIT_MODE, 205 mapping, actionForm, request, response); 206 } 207 208 private ActionForward display( 210 WeblogEntryPageModel.PageMode mode, 211 ActionMapping mapping, 212 ActionForm actionForm, 213 HttpServletRequest request, 214 HttpServletResponse response) 215 throws IOException , ServletException { 216 ActionForward forward = mapping.findForward("weblogEdit.page"); 217 try { 218 RollerRequest rreq = RollerRequest.getRollerRequest(request); 219 RollerSession rollerSession = 220 RollerSession.getRollerSession(request); 221 WeblogEntryPageModel pageModel = new WeblogEntryPageModel( 222 request, response, mapping, (WeblogEntryFormEx)actionForm, mode); 223 if (rollerSession.isUserAuthorized( 224 pageModel.getWeblogEntry().getWebsite())) { 225 request.setAttribute("model", pageModel); 226 } else { 227 forward = mapping.findForward("access-denied"); 228 } 229 } catch (Exception e) { 230 request.getSession().getServletContext().log("ERROR",e); 231 throw new ServletException (e); 232 } 233 return forward; 234 } 235 236 241 public ActionForward save( 242 ActionMapping mapping, 243 ActionForm actionForm, 244 HttpServletRequest request, 245 HttpServletResponse response) 246 throws IOException , ServletException { 247 248 ActionForward forward = mapping.findForward("weblogEdit.page"); 249 ActionMessages uiMessages = new ActionMessages(); 250 try { 251 WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm; 252 Roller roller = RollerFactory.getRoller(); 253 RollerSession rses = RollerSession.getRollerSession(request); 254 UserManager userMgr = roller.getUserManager(); 255 WeblogManager weblogMgr = roller.getWeblogManager(); 256 UserData ud = userMgr.getUser(form.getCreatorId()); 257 WebsiteData site = userMgr.getWebsite(form.getWebsiteId()); 258 WeblogEntryData entry = null; 259 260 if ( rses.isUserAuthorizedToAuthor(site) 261 || (rses.isUserAuthorized(site) 262 && !form.getStatus().equals(WeblogEntryData.PUBLISHED) )) { 263 264 ActionErrors errors = validateEntry(null, form); 265 if (errors.size() > 0) { 266 saveErrors(request, errors); 267 request.setAttribute("model", 268 new WeblogEntryPageModel(request, response, mapping, 269 (WeblogEntryFormEx)actionForm, 270 WeblogEntryPageModel.EDIT_MODE)); 271 return forward; 272 } 273 274 if (form.getId() == null || form.getId().trim().length()==0) { 275 entry = new WeblogEntryData(); 276 entry.setCreator(ud); 277 entry.setWebsite( site ); 278 } else { 279 entry = weblogMgr.getWeblogEntry(form.getId()); 280 } 281 282 mLogger.debug("setting update time now"); 283 form.setUpdateTime(new Timestamp (new Date ().getTime())); 284 285 if ("PUBLISHED".equals(form.getStatus()) && 286 "0/0/0".equals(form.getDateString())) { 287 mLogger.debug("setting pubtime now"); 288 289 297 form.setPubTime(form.getUpdateTime()); 298 } 299 300 mLogger.debug("copying submitted form data to entry object"); 301 form.copyTo(entry, request.getLocale(),request.getParameterMap()); 302 303 mLogger.debug("Checking MediaCast attributes"); 305 if (!checkMediaCast(entry, uiMessages)) { 306 mLogger.debug("Invalid MediaCast attributes"); 307 } else { 308 mLogger.debug("Validated MediaCast attributes"); 309 } 310 311 entry.setUpdateTime(new Timestamp (new Date ().getTime())); 313 314 if(entry.getAnchor() == null || entry.getAnchor().trim().equals("")) { 316 entry.setAnchor(weblogMgr.createAnchor(entry)); 317 } 318 319 mLogger.debug("Saving entry"); 320 weblogMgr.saveWeblogEntry(entry); 321 RollerFactory.getRoller().flush(); 322 323 mLogger.debug("Populating form"); 324 form.copyFrom(entry, request.getLocale()); 325 326 request.setAttribute( 327 RequestConstants.WEBLOGENTRY_ID, entry.getId()); 328 329 reindexEntry(RollerFactory.getRoller(), entry); 331 mLogger.debug("Removing from cache"); 332 RollerRequest rreq = RollerRequest.getRollerRequest(request); 333 CacheManager.invalidate(entry); 335 336 if(entry.isPublished()) { 338 RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(entry); 339 } 340 341 HttpSession session = request.getSession(true); 343 session.removeAttribute("spellCheckEvents"); 344 session.removeAttribute("entryText"); 345 346 request.setAttribute("model", 348 new WeblogEntryPageModel(request, response, mapping, 349 (WeblogEntryFormEx)actionForm, 350 WeblogEntryPageModel.EDIT_MODE)); 351 352 if (!rses.isUserAuthorizedToAuthor(site) && 353 rses.isUserAuthorized(site) && entry.isPending()) { 354 notifyWebsiteAuthorsOfPendingEntry(request, entry); 356 uiMessages.add(null, 357 new ActionMessage("weblogEdit.submittedForReview")); 358 359 actionForm = new WeblogEntryFormEx(); 361 request.setAttribute(mapping.getName(), actionForm); 362 forward = create(mapping, actionForm, request, response); 363 } else { 364 uiMessages.add(null, 365 new ActionMessage("weblogEdit.changesSaved")); 366 } 367 saveMessages(request, uiMessages); 368 mLogger.debug("operation complete"); 369 370 } else { 371 forward = mapping.findForward("access-denied"); 372 } 373 } catch (RollerPermissionsException e) { 374 ActionErrors errors = new ActionErrors(); 375 errors.add(null, new ActionError("error.permissions.deniedSave")); 376 saveErrors(request, errors); 377 forward = mapping.findForward("access-denied"); 378 } catch (Exception e) { 379 throw new ServletException (e); 380 } 381 return forward; 382 } 383 384 390 private void notifyWebsiteAuthorsOfPendingEntry( 391 HttpServletRequest request, WeblogEntryData entry) { 392 try { 393 Roller roller = RollerFactory.getRoller(); 394 UserManager umgr = roller.getUserManager(); 395 javax.naming.Context ctx = (javax.naming.Context ) 396 new InitialContext ().lookup("java:comp/env"); 397 Session mailSession = 398 (Session )ctx.lookup("mail/Session"); 399 if (mailSession != null) { 400 String userName = entry.getCreator().getUserName(); 401 String from = entry.getCreator().getEmailAddress(); 402 String cc[] = new String [] {from}; 403 String bcc[] = new String [0]; 404 String to[]; 405 String subject; 406 String content; 407 408 ArrayList reviewers = new ArrayList (); 410 List websiteUsers = umgr.getUsers( 411 entry.getWebsite(), Boolean.TRUE, 0, -1); 412 413 Iterator websiteUserIter = websiteUsers.iterator(); 415 while (websiteUserIter.hasNext()) { 416 UserData websiteUser = (UserData)websiteUserIter.next(); 417 if (entry.getWebsite().hasUserPermissions( 418 websiteUser, PermissionsData.AUTHOR) 419 && websiteUser.getEmailAddress() != null) { 420 reviewers.add(websiteUser.getEmailAddress()); 421 } 422 } 423 to = (String [])reviewers.toArray(new String [reviewers.size()]); 424 425 RollerContext rc = RollerContext.getRollerContext(); 427 String rootURL = RollerRuntimeConfig.getAbsoluteContextURL(); 428 if (rootURL == null || rootURL.trim().length()==0) { 429 rootURL = RequestUtils.serverURL(request) 430 + request.getContextPath(); 431 } 432 String editURL = rootURL 433 + "/roller-ui/authoring/weblog.do?method=edit&entryId=" + entry.getId(); 434 435 ResourceBundle resources = ResourceBundle.getBundle( 436 "ApplicationResources", request.getLocale()); 437 StringBuffer sb = new StringBuffer (); 438 sb.append( 439 MessageFormat.format( 440 resources.getString("weblogEntry.pendingEntrySubject"), 441 new Object [] { 442 entry.getWebsite().getName(), 443 entry.getWebsite().getHandle() 444 })); 445 subject = sb.toString(); 446 sb = new StringBuffer (); 447 sb.append( 448 MessageFormat.format( 449 resources.getString("weblogEntry.pendingEntryContent"), 450 new Object [] { userName, userName, editURL }) 451 ); 452 content = sb.toString(); 453 MailUtil.sendTextMessage( 454 mailSession, from, to, cc, bcc, subject, content); 455 } 456 } catch (NamingException e) { 457 mLogger.error("ERROR: Notification email(s) not sent, " 458 + "Roller's mail session not properly configured"); 459 } catch (MessagingException e) { 460 mLogger.error("ERROR: Notification email(s) not sent, " 461 + "due to Roller configuration or mail server problem."); 462 } catch (MalformedURLException e) { 463 mLogger.error("ERROR: Notification email(s) not sent, " 464 + "Roller site URL is malformed?"); 465 } catch (RollerException e) { 466 throw new RuntimeException ( 467 "FATAL ERROR: unable to find Roller object"); 468 } 469 } 470 471 private boolean checkMediaCast(WeblogEntryData entry, ActionMessages uiMessages) { 472 boolean valid = false; 473 String url = entry.findEntryAttribute("att_mediacast_url"); 474 boolean empty = (url == null) || (url.trim().length() == 0); 475 if (!empty) { 476 valid = false; 478 try { 479 mLogger.debug("Sending HTTP HEAD"); 480 HttpURLConnection con = (HttpURLConnection ) 481 new URL (url).openConnection(); 482 mLogger.debug("Getting response code"); 483 con.setRequestMethod("HEAD"); 484 if (con.getResponseCode() != 200) { 485 mLogger.debug("Response code indicates error"); 486 mLogger.error("ERROR " + con.getResponseCode() + " return from MediaCast URL"); 487 uiMessages.add(null,new ActionMessage("weblogEdit.mediaCastResponseError")); 488 } else if (con.getContentType()==null || con.getContentLength()==-1) { 489 mLogger.debug("Content type + (" + con.getContentType() + " is null or content length (" + 490 con.getContentLength() + ") is -1 (indeterminate)."); 491 uiMessages.add(null,new ActionMessage("weblogEdit.mediaCastLacksContentTypeOrLength")); 492 } else { 493 if (mLogger.isDebugEnabled()) { 494 mLogger.debug("Got good response: Content type " + 495 con.getContentType() + " [length = " + con.getContentLength() + "]" ); 496 } 497 entry.putEntryAttribute( 498 "att_mediacast_type", con.getContentType()); 499 entry.putEntryAttribute( 500 "att_mediacast_length", ""+con.getContentLength()); 501 valid = true; 502 } 503 } catch (MalformedURLException mfue) { 504 mLogger.debug("Malformed MediaCast url: " + url); 505 uiMessages.add(null, new ActionMessage("weblogEdit.mediaCastUrlMalformed")); 506 } catch (Exception e) { 507 mLogger.error("ERROR while checking MediaCast URL: " + url + ": " + e.getMessage()); 508 uiMessages.add(null, new ActionMessage("weblogEdit.mediaCastFailedFetchingInfo")); 509 } 510 } else { 511 mLogger.debug("No MediaCast specified, but that is OK"); 512 valid = true; 513 } 514 if (!valid || empty) { 515 mLogger.debug("Removing MediaCast attributes"); 516 try { 517 entry.removeEntryAttribute("att_mediacast_url"); 518 entry.removeEntryAttribute("att_mediacast_type"); 519 entry.removeEntryAttribute("att_mediacast_length"); 520 } catch (RollerException e) { 521 mLogger.error("ERROR removing invalid MediaCast attributes"); 522 } 523 } 524 mLogger.debug("operation complete"); 525 return valid; 526 } 527 528 529 534 public ActionForward removeOk( 535 ActionMapping mapping, 536 ActionForm actionForm, 537 HttpServletRequest request, 538 HttpServletResponse response) 539 throws IOException , ServletException { 540 ActionForward forward = mapping.findForward("weblogEntryRemove.page"); 541 try { 542 Roller roller = RollerFactory.getRoller(); 543 WeblogEntryFormEx wf = (WeblogEntryFormEx)actionForm; 544 WeblogEntryData wd = 545 roller.getWeblogManager().getWeblogEntry(wf.getId()); 546 RollerSession rses = 547 RollerSession.getRollerSession(request); 548 if ( rses.isUserAuthorizedToAuthor(wd.getWebsite()) 549 || (rses.isUserAuthorized(wd.getWebsite()) && wd.isDraft()) ) { 550 wf.copyFrom(wd, request.getLocale()); 551 if (wd == null || wd.getId() == null) { 552 ResourceBundle resources = ResourceBundle.getBundle( 553 "ApplicationResources", request.getLocale()); 554 request.setAttribute("javax.servlet.error.message", 555 resources.getString("weblogEntry.notFound")); 556 forward = mapping.findForward("error"); 557 } 558 } else { 559 forward = mapping.findForward("access-denied"); 560 } 561 } catch (Exception e) { 562 throw new ServletException (e); 563 } 564 return forward; 565 } 566 567 572 public ActionForward remove( 573 ActionMapping mapping, 574 ActionForm actionForm, 575 HttpServletRequest request, 576 HttpServletResponse response) 577 throws IOException , ServletException { 578 try { 579 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 580 WeblogEntryData wd = 581 mgr.getWeblogEntry(request.getParameter("id")); 582 RollerSession rses = 583 RollerSession.getRollerSession(request); 584 if ( rses.isUserAuthorizedToAuthor(wd.getWebsite()) 585 || (rses.isUserAuthorized(wd.getWebsite()) && wd.isDraft()) ) { 586 587 wd.setStatus(WeblogEntryData.DRAFT); 590 reindexEntry(RollerFactory.getRoller(), wd); 591 592 mgr.removeWeblogEntry(wd); 594 RollerFactory.getRoller().flush(); 595 596 CacheManager.invalidate(wd); 598 599 ActionMessages uiMessages = new ActionMessages(); 600 uiMessages.add(null, 601 new ActionMessage("weblogEdit.entryRemoved")); 602 saveMessages(request, uiMessages); 603 604 RollerRequest.getRollerRequest().setWebsite(wd.getWebsite()); 605 } else { 606 return mapping.findForward("access-denied"); 607 } 608 } catch (Exception e) { 609 throw new ServletException (e); 610 } 611 612 actionForm = new WeblogEntryFormEx(); 614 actionForm.reset(mapping, request); 615 request.setAttribute(mapping.getName(), actionForm); 616 return create(mapping, actionForm, request, response); 617 } 618 619 622 public ActionForward sendTrackback( 623 ActionMapping mapping, 624 ActionForm actionForm, 625 HttpServletRequest request, 626 HttpServletResponse response) throws RollerException { 627 ActionMessages resultMsg = new ActionMessages(); 628 ActionForward forward = mapping.findForward("weblogEdit.page"); 629 ActionErrors errors = new ActionErrors(); 630 WeblogEntryData entry = null; 631 try { 632 WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm; 633 String entryid = form.getId(); 634 if ( entryid == null ) { 635 entryid = 636 request.getParameter(RequestConstants.WEBLOGENTRY_ID); 637 } 638 Roller roller = RollerFactory.getRoller(); 639 RollerContext rctx= RollerContext.getRollerContext(); 640 WeblogManager wmgr= roller.getWeblogManager(); 641 entry = wmgr.getWeblogEntry(entryid); 642 643 RollerSession rses = RollerSession.getRollerSession(request); 644 if (rses.isUserAuthorizedToAuthor(entry.getWebsite())) { 645 PluginManager ppmgr = roller.getPagePluginManager(); 647 Map plugins = ppmgr.getWeblogEntryPlugins( 648 entry.getWebsite()); 649 650 String content = ""; 651 if (!StringUtils.isEmpty(entry.getText())) { 652 content = entry.getText(); 653 } else { 654 content = entry.getSummary(); 655 } 656 content = ppmgr.applyWeblogEntryPlugins(plugins, entry, content); 657 658 String title = entry.getTitle(); 659 String excerpt = StringUtils.left( Utilities.removeHTML(content),255 ); 660 661 String url = entry.getPermalink(); 662 String blog_name = entry.getWebsite().getName(); 663 664 if (form.getTrackbackUrl() != null) { 665 boolean allowTrackback = true; 667 668 String allowedURLs = RollerConfig.getProperty("trackback.allowedURLs"); 669 if (allowedURLs != null && allowedURLs.trim().length() > 0) { 670 allowTrackback = false; 673 String [] splitURLs = allowedURLs.split("\\|\\|"); 674 for (int i=0; i<splitURLs.length; i++) { 675 Matcher m = Pattern.compile(splitURLs[i]).matcher(form.getTrackbackUrl()); 676 if (m.matches()) { 677 allowTrackback = true; 678 break; 679 } 680 } 681 } 682 683 if(!allowTrackback) { 684 errors.add(ActionErrors.GLOBAL_ERROR, 685 new ActionError("error.trackbackNotAllowed")); 686 } else { 687 try { 688 690 String data = URLEncoder.encode("title", "UTF-8") 691 +"="+URLEncoder.encode(title, "UTF-8"); 692 693 data += ("&" + URLEncoder.encode("excerpt", "UTF-8") 694 +"="+URLEncoder.encode(excerpt,"UTF-8")); 695 696 data += ("&" + URLEncoder.encode("url", "UTF-8") 697 +"="+URLEncoder.encode(url,"UTF-8")); 698 699 data += ("&" + URLEncoder.encode("blog_name", "UTF-8") 700 +"="+URLEncoder.encode(blog_name,"UTF-8")); 701 702 URL tburl = new URL (form.getTrackbackUrl()); 704 HttpURLConnection conn = (HttpURLConnection )tburl.openConnection(); 705 conn.setDoOutput(true); 706 707 OutputStreamWriter wr = 708 new OutputStreamWriter (conn.getOutputStream()); 709 BufferedReader rd = null; 710 try { 711 wr.write(data); 712 wr.flush(); 713 714 boolean inputAvailable = false; 716 try { 717 rd = new BufferedReader (new InputStreamReader ( 718 conn.getInputStream())); 719 inputAvailable = true; 720 } catch (Throwable e) { 721 mLogger.debug(e); 722 } 723 724 if (inputAvailable) { 726 String line; 727 StringBuffer resultBuff = new StringBuffer (); 728 while ((line = rd.readLine()) != null) { 729 resultBuff.append( 730 StringEscapeUtils.escapeHtml(line)); 731 resultBuff.append("<br />"); 732 } 733 resultMsg.add(ActionMessages.GLOBAL_MESSAGE, 734 new ActionMessage("weblogEdit.trackbackResults", 735 resultBuff)); 736 } 737 738 if (conn.getResponseCode() > 399) { 740 errors.add(ActionErrors.GLOBAL_ERROR, 741 new ActionError("weblogEdit.trackbackStatusCodeBad", 742 new Integer (conn.getResponseCode()))); 743 } else { 744 resultMsg.add(ActionMessages.GLOBAL_MESSAGE, 745 new ActionMessage("weblogEdit.trackbackStatusCodeGood", 746 new Integer (conn.getResponseCode()))); 747 } 748 } finally { 749 if (wr != null) wr.close(); 750 if (rd != null) rd.close(); 751 } 752 } catch (IOException e) { 753 errors.add(ActionErrors.GLOBAL_ERROR, 754 new ActionError("error.trackback",e)); 755 } 756 } 757 } else { 758 errors.add(ActionErrors.GLOBAL_ERROR, 759 new ActionError("error.noTrackbackUrlSpecified")); 760 } 761 762 form.setTrackbackUrl(null); 763 } else { 764 forward = mapping.findForward("access-denied"); 765 } 766 } catch (Exception e) { 768 mLogger.error(e); 769 String msg = e.getMessage(); 770 if ( msg == null ) { 771 msg = e.getClass().getName(); 772 } 773 errors.add(ActionErrors.GLOBAL_ERROR, 774 new ActionError("error.general",msg)); 775 } 776 777 saveErrors(request, errors); 778 saveMessages(request, resultMsg); 779 780 request.setAttribute("model", 781 new WeblogEntryPageModel(request, response, mapping, 782 (WeblogEntryFormEx)actionForm, 783 WeblogEntryPageModel.EDIT_MODE)); 784 785 return forward; 786 } 787 788 public ActionForward cancel( 790 ActionMapping mapping, 791 ActionForm actionForm, 792 HttpServletRequest request, 793 HttpServletResponse response) 794 throws IOException , ServletException { 795 return (mapping.findForward("weblogEdit")); 796 } 797 798 public ActionForward unspecified( 800 ActionMapping mapping, 801 ActionForm actionForm, 802 HttpServletRequest request, 803 HttpServletResponse response) 804 throws Exception { 805 return create(mapping, actionForm, request, response); 806 } 807 808 814 private void reindexEntry(Roller roller, WeblogEntryData entry) 815 throws RollerException { 816 IndexManager manager = roller.getIndexManager(); 817 818 821 if (entry.isPublished()) { 823 manager.addEntryReIndexOperation(entry); 824 } 825 } 826 827 public ActionErrors validateEntry(ActionErrors errors, WeblogEntryFormEx form) { 828 if (errors == null) errors = new ActionErrors(); 829 if (StringUtils.isEmpty(form.getTitle())) { 830 errors.add(null, new ActionError("weblogEdit.error.incompleteEntry")); 831 } 832 return errors; 833 } 834 835 836 } 837 838 839 | Popular Tags |