public static InputStream buildStream(HTMLPage htmlPage, boolean EDIT_MODE) throws DotStateException, DotDataException { Identifier identifier = APILocator.getIdentifierAPI().find(htmlPage); try { return buildStream(htmlPage, identifier, EDIT_MODE); } catch (Exception e) { Logger.error(PageServices.class, e.getMessage(), e); throw new DotRuntimeException(e.getMessage()); } }
@SuppressWarnings("unchecked") public static InputStream buildStream(HTMLPage htmlPage, Identifier identifier, boolean EDIT_MODE) throws DotDataException, DotSecurityException { String folderPath = (!EDIT_MODE) ? "live/" : "working/"; InputStream result; StringBuilder sb = new StringBuilder(); ContentletAPI conAPI = APILocator.getContentletAPI(); Template cmsTemplate = com.dotmarketing.portlets.htmlpages.factories.HTMLPageFactory.getHTMLPageTemplate( htmlPage, EDIT_MODE); if (cmsTemplate == null || !InodeUtils.isSet(cmsTemplate.getInode())) { Logger.error( This.class, "PAGE DOES NOT HAVE A VALID TEMPLATE (template unpublished?) : page id " + htmlPage.getIdentifier() + ":" + identifier.getURI()); } // gets pageChannel for this path java.util.StringTokenizer st = new java.util.StringTokenizer(String.valueOf(identifier.getURI()), "/"); String pageChannel = null; if (st.hasMoreTokens()) { pageChannel = st.nextToken(); } // set the page cache var if (htmlPage.getCacheTTL() > 0 && LicenseUtil.getLevel() > 99) { sb.append("#set($dotPageCacheDate = \"").append(new java.util.Date()).append("\")"); sb.append("#set($dotPageCacheTTL = \"").append(htmlPage.getCacheTTL()).append("\")"); } // set the host variables HTMLPageAPI htmlPageAPI = APILocator.getHTMLPageAPI(); Host host = htmlPageAPI.getParentHost(htmlPage); sb.append("#if(!$doNotParseTemplate)"); sb.append("$velutil.mergeTemplate('") .append(folderPath) .append(host.getIdentifier()) .append(".") .append(Config.getStringProperty("VELOCITY_HOST_EXTENSION")) .append("')"); sb.append(" #end "); // creates the context where to place the variables // Build a context to pass to the page sb.append("#if(!$doNotSetPageInfo)"); sb.append("#set ( $quote = '\"' )"); sb.append("#set ($HTMLPAGE_INODE = \"") .append(String.valueOf(htmlPage.getInode())) .append("\" )"); sb.append("#set ($HTMLPAGE_IDENTIFIER = \"") .append(String.valueOf(htmlPage.getIdentifier())) .append("\" )"); sb.append("#set ($HTMLPAGE_TITLE = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getTitle())) .append("\" )"); sb.append( "#set ($HTMLPAGE_FRIENDLY_NAME = \"" + UtilMethods.espaceForVelocity(htmlPage.getFriendlyName())) .append("\" )"); sb.append("#set ($TEMPLATE_INODE = \"") .append(String.valueOf(cmsTemplate.getInode())) .append("\" )"); sb.append("#set ($HTMLPAGE_META = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getMetadata())) .append("\" )"); sb.append("#set ($HTMLPAGE_META = \"#fixBreaks($HTMLPAGE_META)\")"); sb.append("#set ($HTMLPAGE_DESCRIPTION = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getSeoDescription())) .append("\" )"); sb.append("#set ($HTMLPAGE_DESCRIPTION = \"#fixBreaks($HTMLPAGE_DESCRIPTION)\")"); sb.append("#set ($HTMLPAGE_KEYWORDS = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getSeoKeywords())) .append("\" )"); sb.append("#set ($HTMLPAGE_KEYWORDS = \"#fixBreaks($HTMLPAGE_KEYWORDS)\")"); sb.append("#set ($HTMLPAGE_SECURE = \"") .append(String.valueOf(htmlPage.isHttpsRequired())) .append("\" )"); sb.append("#set ($VTLSERVLET_URI = \"") .append(UtilMethods.encodeURIComponent(identifier.getURI())) .append("\" )"); sb.append("#set ($HTMLPAGE_REDIRECT = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getRedirect())) .append("\" )"); sb.append("#set ($pageTitle = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getTitle())) .append("\" )"); sb.append("#set ($pageChannel = \"").append(pageChannel).append("\" )"); sb.append("#set ($friendlyName = \"") .append(UtilMethods.espaceForVelocity(htmlPage.getFriendlyName())) .append("\" )"); Date moddate = null; if (UtilMethods.isSet(htmlPage.getModDate())) { moddate = htmlPage.getModDate(); } else { moddate = htmlPage.getStartDate(); } moddate = new Timestamp(moddate.getTime()); sb.append("#set ($HTML_PAGE_LAST_MOD_DATE= $date.toDate(\"yyyy-MM-dd HH:mm:ss.SSS\", \"") .append(moddate) .append("\"))"); sb.append("#set ($HTMLPAGE_MOD_DATE= $date.toDate(\"yyyy-MM-dd HH:mm:ss.SSS\", \"") .append(moddate) .append("\"))"); sb.append(" #end "); // get the containers for the page and stick them in context // List identifiers = InodeFactory.getChildrenClass(cmsTemplate, Identifier.class); List<Container> containerList = APILocator.getTemplateAPI() .getContainersInTemplate(cmsTemplate, APILocator.getUserAPI().getSystemUser(), false); Iterator i = containerList.iterator(); while (i.hasNext()) { Container ident = (Container) i.next(); Container c = null; if (EDIT_MODE) { c = (Container) APILocator.getVersionableAPI() .findWorkingVersion( ident.getIdentifier(), APILocator.getUserAPI().getSystemUser(), false); } else { c = (Container) APILocator.getVersionableAPI() .findLiveVersion( ident.getIdentifier(), APILocator.getUserAPI().getSystemUser(), false); } // sets container to load the container file sb.append("#set ($container") .append(ident.getIdentifier()) .append(" = \"") .append(folderPath) .append(ident.getIdentifier()) .append(".") .append(Config.getStringProperty("VELOCITY_CONTAINER_EXTENSION")) .append("\" )"); String sort = (c.getSortContentletsBy() == null) ? "tree_order" : c.getSortContentletsBy(); boolean dynamicContainer = UtilMethods.isSet(c.getLuceneQuery()); int langCounter = 0; List<Contentlet> contentlets = new ArrayList<Contentlet>(); List<Contentlet> contentletsFull = new ArrayList<Contentlet>(); if (!dynamicContainer) { Identifier idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage); Identifier idenContainer = APILocator.getIdentifierAPI().find(c); // The container doesn't have categories try { contentlets = conAPI.findPageContentlets( idenHtmlPage.getId(), idenContainer.getId(), sort, EDIT_MODE, -1, APILocator.getUserAPI().getSystemUser(), false); if (EDIT_MODE) contentletsFull = contentlets; else contentletsFull = conAPI.findPageContentlets( idenHtmlPage.getId(), idenContainer.getId(), sort, true, -1, APILocator.getUserAPI().getSystemUser(), false); } catch (Exception e) { Logger.error(PageServices.class, "Unable to retrive contentlets on page", e); } Logger.debug( PageServices.class, "HTMLPage= " + htmlPage.getInode() + " Container=" + c.getInode() + " Language=-1 Contentlets=" + contentlets.size()); } // this is to filter the contentlets list removing the repited identifiers if (contentlets.size() > 0) { Set<String> contentletIdentList = new HashSet<String>(); List<Contentlet> contentletsFilter = new ArrayList<Contentlet>(); for (Contentlet cont : contentlets) { if (!contentletIdentList.contains(cont.getIdentifier())) { contentletIdentList.add(cont.getIdentifier()); contentletsFilter.add(cont); } } contentlets = contentletsFilter; } if (contentletsFull.size() > 0) { Set<String> contentletIdentList = new HashSet<String>(); List<Contentlet> contentletsFilter = new ArrayList<Contentlet>(); for (Contentlet cont : contentletsFull) { if (!contentletIdentList.contains(cont.getIdentifier())) { contentletIdentList.add(cont.getIdentifier()); contentletsFilter.add(cont); } } contentletsFull = contentletsFilter; } StringBuilder widgetpree = new StringBuilder(); StringBuilder widgetpreeFull = new StringBuilder(); StringBuilder contentletList = new StringBuilder(); int count = 0; for (Contentlet contentlet : contentlets) { contentletList .append(count == 0 ? "" : ",") .append('"') .append(contentlet.getIdentifier()) .append('"'); if (contentlet.getStructure().getStructureType() == Structure.STRUCTURE_TYPE_WIDGET) { Field field = contentlet.getStructure().getFieldVar("widgetPreexecute"); if (field != null && UtilMethods.isSet(field.getValues())) widgetpree.append(field.getValues().trim()); } if (++count >= c.getMaxContentlets()) break; } StringBuilder contentletListFull = new StringBuilder(); int countFull = 0; for (Contentlet contentlet : contentletsFull) { contentletListFull .append(countFull == 0 ? "" : ",") .append('"') .append(contentlet.getIdentifier()) .append('"'); if (contentlet.getStructure().getStructureType() == Structure.STRUCTURE_TYPE_WIDGET) { Field field = contentlet.getStructure().getFieldVar("widgetPreexecute"); if (field != null && UtilMethods.isSet(field.getValues())) widgetpreeFull.append(field.getValues().trim()); } if (++countFull >= c.getMaxContentlets()) break; } sb.append("#if($request.session.getAttribute(\"tm_date\"))"); sb.append(widgetpreeFull); sb.append("#set ($contentletList") .append(ident.getIdentifier()) .append(" = [") .append(contentletListFull.toString()) .append("] )"); sb.append("#set ($totalSize") .append(ident.getIdentifier()) .append("=") .append(countFull) .append(")"); sb.append("#else "); sb.append(widgetpree); sb.append("#set ($contentletList") .append(ident.getIdentifier()) .append(" = [") .append(contentletList.toString()) .append("] )"); sb.append("#set ($totalSize") .append(ident.getIdentifier()) .append("=") .append(count) .append(")"); sb.append("#end "); langCounter++; } if (htmlPage.isHttpsRequired()) { sb.append(" #if(!$ADMIN_MODE && !$request.isSecure())"); sb.append(" #if($request.getQueryString())"); sb.append( " #set ($REDIRECT_URL = \"https://${request.getServerName()}$request.getAttribute('javax.servlet.forward.request_uri')?$request.getQueryString()\")"); sb.append(" #else "); sb.append( " #set ($REDIRECT_URL = \"https://${request.getServerName()}$request.getAttribute('javax.servlet.forward.request_uri')\")"); sb.append(" #end "); sb.append(" $response.sendRedirect(\"$REDIRECT_URL\")"); sb.append(" #end "); } sb.append("#if($HTMLPAGE_REDIRECT != \"\")"); sb.append(" $response.sendRedirect(\"$HTMLPAGE_REDIRECT\")"); sb.append("#end"); Identifier iden = APILocator.getIdentifierAPI().find(cmsTemplate); sb.append("#if(!$doNotParseTemplate)"); if (cmsTemplate.isDrawed()) { // We have a designed template // Setting some theme variables sb.append("#set ($dotTheme = $templatetool.theme(\"") .append(cmsTemplate.getTheme()) .append("\",\"") .append(host.getIdentifier()) .append("\"))"); sb.append("#set ($dotThemeLayout = $templatetool.themeLayout(\"") .append(cmsTemplate.getInode()) .append("\" ))"); // Merging our template sb.append("$velutil.mergeTemplate(\"$dotTheme.templatePath\")"); } else { sb.append("$velutil.mergeTemplate('") .append(folderPath) .append(iden.getInode()) .append(".") .append(Config.getStringProperty("VELOCITY_TEMPLATE_EXTENSION")) .append("')"); } sb.append("#end"); try { if (Config.getBooleanProperty("SHOW_VELOCITYFILES", false)) { String realFolderPath = (!EDIT_MODE) ? "live" + java.io.File.separator : "working" + java.io.File.separator; String velocityRootPath = Config.getStringProperty("VELOCITY_ROOT"); String filePath = realFolderPath + identifier.getInode() + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION"); if (velocityRootPath.startsWith("/WEB-INF")) { velocityRootPath = com.liferay.util.FileUtil.getRealPath(velocityRootPath); } velocityRootPath += java.io.File.separator; java.io.BufferedOutputStream tmpOut = new java.io.BufferedOutputStream( new java.io.FileOutputStream( new java.io.File( ConfigUtils.getDynamicVelocityPath() + java.io.File.separator + filePath))); // Specify a proper character encoding OutputStreamWriter out = new OutputStreamWriter(tmpOut, UtilMethods.getCharsetConfiguration()); out.write(sb.toString()); out.flush(); out.close(); tmpOut.close(); } } catch (Exception e) { Logger.error(PageServices.class, e.toString(), e); } try { result = new ByteArrayInputStream(sb.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e1) { result = new ByteArrayInputStream(sb.toString().getBytes()); Logger.error(ContainerServices.class, e1.getMessage(), e1); } return result; }
/** * Updates the assets in the given bundle with the publish/expire dates and destination * environments and set them ready to be pushed * * @param request HttpRequest * @param response HttpResponse * @throws WorkflowActionFailureException If fails trying to Publish the bundle contents */ public void pushBundle(HttpServletRequest request, HttpServletResponse response) throws WorkflowActionFailureException, IOException { response.setContentType("text/plain"); try { PublisherAPI publisherAPI = PublisherAPI.getInstance(); // Read the form values String bundleId = request.getParameter("assetIdentifier"); String _contentPushPublishDate = request.getParameter("remotePublishDate"); String _contentPushPublishTime = request.getParameter("remotePublishTime"); String _contentPushExpireDate = request.getParameter("remotePublishExpireDate"); String _contentPushExpireTime = request.getParameter("remotePublishExpireTime"); String _iWantTo = request.getParameter("iWantTo"); String whoToSendTmp = request.getParameter("whoToSend"); List<String> whereToSend = Arrays.asList(whoToSendTmp.split(",")); List<Environment> envsToSendTo = new ArrayList<Environment>(); // Lists of Environments to push to for (String envId : whereToSend) { Environment e = APILocator.getEnvironmentAPI().findEnvironmentById(envId); if (e != null && APILocator.getPermissionAPI() .doesUserHavePermission(e, PermissionAPI.PERMISSION_USE, getUser())) { envsToSendTo.add(e); } } if (envsToSendTo.isEmpty()) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } // Put the selected environments in session in order to have the list of the last selected // environments request.getSession().setAttribute(WebKeys.SELECTED_ENVIRONMENTS, envsToSendTo); // Clean up the selected bundle request.getSession().removeAttribute(WebKeys.SELECTED_BUNDLE); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-H-m"); Date publishDate = dateFormat.parse(_contentPushPublishDate + "-" + _contentPushPublishTime); Bundle bundle = APILocator.getBundleAPI().getBundleById(bundleId); APILocator.getBundleAPI().saveBundleEnvironments(bundle, envsToSendTo); if (_iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH)) { bundle.setPublishDate(publishDate); APILocator.getBundleAPI().updateBundle(bundle); publisherAPI.publishBundleAssets(bundle.getId(), publishDate); } else if (_iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_EXPIRE)) { if ((!"".equals(_contentPushExpireDate.trim()) && !"".equals(_contentPushExpireTime.trim()))) { Date expireDate = dateFormat.parse(_contentPushExpireDate + "-" + _contentPushExpireTime); bundle.setExpireDate(expireDate); APILocator.getBundleAPI().updateBundle(bundle); publisherAPI.unpublishBundleAssets(bundle.getId(), expireDate); } } else if (_iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE)) { if ((!"".equals(_contentPushExpireDate.trim()) && !"".equals(_contentPushExpireTime.trim()))) { Date expireDate = dateFormat.parse(_contentPushExpireDate + "-" + _contentPushExpireTime); bundle.setPublishDate(publishDate); bundle.setExpireDate(expireDate); APILocator.getBundleAPI().updateBundle(bundle); publisherAPI.publishAndExpireBundleAssets( bundle.getId(), publishDate, expireDate, getUser()); } } } catch (Exception e) { Logger.error(RemotePublishAjaxAction.class, e.getMessage(), e); response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Push Publishing Bundle: " + e.getMessage()); } }
/** * Adds to an specific given bundle a given asset. <br> * If the given bundle does not exist a new onw will be created with that name * * @param request HttpRequest * @param response HttpResponse */ public void addToBundle(HttpServletRequest request, HttpServletResponse response) throws IOException { PublisherAPI publisherAPI = PublisherAPI.getInstance(); String _assetId = request.getParameter("assetIdentifier"); String _contentFilterDate = request.getParameter("remoteFilterDate"); String bundleName = request.getParameter("bundleName"); String bundleId = request.getParameter("bundleSelect"); try { Bundle bundle; if (bundleId == null || bundleName.equals(bundleId)) { // if the user has a unsent bundle with that name just add to it bundle = null; for (Bundle b : APILocator.getBundleAPI() .getUnsendBundlesByName(getUser().getUserId(), bundleName, 1000, 0)) { if (b.getName().equalsIgnoreCase(bundleName)) { bundle = b; } } if (bundle == null) { bundle = new Bundle(bundleName, null, null, getUser().getUserId()); APILocator.getBundleAPI().saveBundle(bundle); } } else { bundle = APILocator.getBundleAPI().getBundleById(bundleId); } // Put the selected bundle in session in order to have last one selected request.getSession().setAttribute(WebKeys.SELECTED_BUNDLE, bundle); List<String> ids; if (_assetId.startsWith("query_")) { // Support for lucene queries String luceneQuery = _assetId.replace("query_", ""); List<String> queries = new ArrayList<String>(); queries.add(luceneQuery); ids = PublisherUtil.getContentIds(queries); } else { String[] _assetsIds = _assetId.split(","); // Support for multiple ids in the assetIdentifier parameter List<String> assetsIds = Arrays.asList(_assetsIds); ids = getIdsToPush(assetsIds, _contentFilterDate, new SimpleDateFormat("yyyy-MM-dd-H-m")); } Map<String, Object> responseMap = publisherAPI.saveBundleAssets(ids, bundle.getId(), getUser()); // If we have errors lets return them in order to feedback the user if (responseMap != null && !responseMap.isEmpty()) { // Error messages JSONArray jsonErrors = new JSONArray((ArrayList) responseMap.get("errorMessages")); // Prepare the Json response JSONObject jsonResponse = new JSONObject(); jsonResponse.put("errorMessages", jsonErrors.toArray()); jsonResponse.put("errors", responseMap.get("errors")); jsonResponse.put("total", responseMap.get("total")); // And send it back to the user response.getWriter().println(jsonResponse.toString()); } } catch (Exception e) { Logger.error(RemotePublishAjaxAction.class, e.getMessage(), e); response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Adding content to Bundle: " + e.getMessage()); } }
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, String> map = getURIParams(); String cmd = map.get("cmd"); Method dispatchMethod = null; User user = getUser(); try { // Check permissions if the user has access to the CMS Maintenance Portlet if (user == null) { String userName = map.get("u") != null ? map.get("u") : map.get("user") != null ? map.get("user") : null; String password = map.get("p") != null ? map.get("p") : map.get("passwd") != null ? map.get("passwd") : null; LoginFactory.doLogin(userName, password, false, request, response); user = (User) request.getSession().getAttribute(WebKeys.CMS_USER); // Set the logged user in order to make it available from this action using the getUser() // method if (user != null) { setUser(user); } if (user == null) { setUser(request); user = getUser(); } if (user == null) { response.sendError(401); return; } } } catch (Exception e) { Logger.error(this.getClass(), e.getMessage()); response.sendError(401); return; } if (null != cmd) { try { dispatchMethod = this.getClass() .getMethod(cmd, new Class[] {HttpServletRequest.class, HttpServletResponse.class}); } catch (Exception e) { try { dispatchMethod = this.getClass() .getMethod( "action", new Class[] {HttpServletRequest.class, HttpServletResponse.class}); } catch (Exception e1) { Logger.error(this.getClass(), "Trying to get method:" + cmd); Logger.error(this.getClass(), e1.getMessage(), e1.getCause()); throw new DotRuntimeException(e1.getMessage()); } } try { dispatchMethod.invoke(this, new Object[] {request, response}); } catch (Exception e) { Logger.error(this.getClass(), "Trying to invoke method:" + cmd); Logger.error(this.getClass(), e.getMessage(), e.getCause()); throw new DotRuntimeException(e.getMessage()); } } }
/** * Send to the publisher queue a list of assets for a given Operation (Publish/Unpublish) and * {@link Environment Environment} * * @param request HttpRequest * @param response HttpResponse * @throws WorkflowActionFailureException If fails adding the content for Publish * @see com.dotcms.publisher.business.PublisherQueueJob * @see Environment */ public void publish(HttpServletRequest request, HttpServletResponse response) throws IOException, WorkflowActionFailureException { try { PublisherAPI publisherAPI = PublisherAPI.getInstance(); // Read the form values String _assetId = request.getParameter("assetIdentifier"); String _contentPushPublishDate = request.getParameter("remotePublishDate"); String _contentPushPublishTime = request.getParameter("remotePublishTime"); String _contentPushExpireDate = request.getParameter("remotePublishExpireDate"); String _contentPushExpireTime = request.getParameter("remotePublishExpireTime"); String _contentFilterDate = request.getParameter("remoteFilterDate"); String _iWantTo = request.getParameter("iWantTo"); String whoToSendTmp = request.getParameter("whoToSend"); String forcePushStr = request.getParameter("forcePush"); boolean forcePush = (forcePushStr != null && forcePushStr.equals("true")); List<String> whereToSend = Arrays.asList(whoToSendTmp.split(",")); List<Environment> envsToSendTo = new ArrayList<Environment>(); // Lists of Environments to push to for (String envId : whereToSend) { Environment e = APILocator.getEnvironmentAPI().findEnvironmentById(envId); if (e != null) { envsToSendTo.add(e); } } // Put the selected environments in session in order to have the list of the last selected // environments request.getSession().setAttribute(WebKeys.SELECTED_ENVIRONMENTS, envsToSendTo); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-H-m"); Date publishDate = dateFormat.parse(_contentPushPublishDate + "-" + _contentPushPublishTime); List<String> ids; if (_assetId.startsWith("query_")) { // Support for lucene queries String luceneQuery = _assetId.replace("query_", ""); List<String> queries = new ArrayList<String>(); queries.add(luceneQuery); ids = PublisherUtil.getContentIds(queries); } else { String[] _assetsIds = _assetId.split(","); // Support for multiple ids in the assetIdentifier parameter List<String> assetsIds = Arrays.asList(_assetsIds); ids = getIdsToPush(assetsIds, _contentFilterDate, dateFormat); } // Response map with the status of the addContents operation (error messages and counts ) Map<String, Object> responseMap = null; if (_iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH) || _iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE)) { Bundle bundle = new Bundle(null, publishDate, null, getUser().getUserId(), forcePush); APILocator.getBundleAPI().saveBundle(bundle, envsToSendTo); responseMap = publisherAPI.addContentsToPublish(ids, bundle.getId(), publishDate, getUser()); } if (_iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_EXPIRE) || _iWantTo.equals(RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH_AND_EXPIRE)) { if ((!"".equals(_contentPushExpireDate.trim()) && !"".equals(_contentPushExpireTime.trim()))) { Date expireDate = dateFormat.parse(_contentPushExpireDate + "-" + _contentPushExpireTime); Bundle bundle = new Bundle(null, publishDate, expireDate, getUser().getUserId(), forcePush); APILocator.getBundleAPI().saveBundle(bundle, envsToSendTo); responseMap = publisherAPI.addContentsToUnpublish(ids, bundle.getId(), expireDate, getUser()); } } // If we have errors lets return them in order to feedback the user if (responseMap != null && !responseMap.isEmpty()) { // Error messages JSONArray jsonErrors = new JSONArray((ArrayList) responseMap.get("errorMessages")); // Prepare the Json response JSONObject jsonResponse = new JSONObject(); jsonResponse.put("errorMessages", jsonErrors.toArray()); jsonResponse.put("errors", responseMap.get("errors")); jsonResponse.put("total", responseMap.get("total")); jsonResponse.put("bundleId", responseMap.get("bundleId")); // And send it back to the user response.getWriter().println(jsonResponse.toString()); } } catch (Exception e) { Logger.error(RemotePublishAjaxAction.class, e.getMessage(), e); response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Publishing Bundle: " + e.getMessage()); } }