--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+/**
+ * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.pentila.entSavoie.portlets.blog;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.naming.NamingException;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.json.JSONArray;
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.kernel.repository.model.FileEntry;
+import com.liferay.portal.kernel.repository.model.Folder;
+import com.liferay.portal.kernel.util.ContentTypes;
+import com.liferay.portal.kernel.util.FileUtil;
+import com.liferay.portal.kernel.util.HttpUtil;
+import com.liferay.portal.kernel.util.ObjectValuePair;
+import com.liferay.portal.kernel.util.ParamUtil;
+import com.liferay.portal.kernel.util.Validator;
+import com.liferay.portal.kernel.util.WebKeys;
+import com.liferay.portal.model.CompanyConstants;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.liferay.portal.theme.ThemeDisplay;
+import com.liferay.portal.util.PortalUtil;
+import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;
+import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
+import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
+import com.pentila.entSavoie.blog.model.BlogCategory;
+import com.pentila.entSavoie.blog.model.BlogChannel;
+import com.pentila.entSavoie.blog.model.BlogItem;
+import com.pentila.entSavoie.blog.service.BlogCategoryLocalServiceUtil;
+import com.pentila.entSavoie.blog.service.BlogChannelLocalServiceUtil;
+import com.pentila.entSavoie.blog.service.BlogItemLocalServiceUtil;
+import com.pentila.entSavoie.cartable.service.CasierEntryLocalServiceUtil;
+import com.pentila.entSavoie.service.DiskUsageUserLocalServiceUtil;
+import com.pentila.entSavoie.utils.DLAppUtil;
+import com.pentila.entSavoie.utils.DLEntryUtil;
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
+import com.pentila.entSavoie.utils.FoldersUtil;
+import com.pentila.entSavoie.utils.JSPPortletUtil;
+import com.pentila.entSavoie.utils.PortletConstant;
+
+/**
+ * <a href="JSPPortlet.java.html"><b><i>View Source</i></b></a>
+ *
+ * @author Brian Wing Shun Chan
+ *
+ */
+public class JSPPortlet extends GenericPortlet {
+
+ public void init() throws PortletException {
+ editJSP = getInitParameter("edit-jsp");
+ helpJSP = getInitParameter("help-jsp");
+ viewJSP = getInitParameter("view-jsp");
+ }
+
+ public void doDispatch(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ String jspPage = renderRequest.getParameter("jspPage");
+
+ if (jspPage != null) {
+ include(jspPage, renderRequest, renderResponse);
+ }
+ else {
+ super.doDispatch(renderRequest, renderResponse);
+ }
+ }
+
+ public void doEdit(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ if (renderRequest.getPreferences() == null) {
+ super.doEdit(renderRequest, renderResponse);
+ }
+ else {
+ include(editJSP, renderRequest, renderResponse);
+ }
+ }
+
+ public void doHelp(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(helpJSP, renderRequest, renderResponse);
+ }
+
+ public void doView(
+ RenderRequest renderRequest, RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ include(viewJSP, renderRequest, renderResponse);
+ }
+
+ @Override
+ public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
+ throws PortletException, IOException {
+
+ final String cmd = ParamUtil.getString(resourceRequest, "cmd");
+
+ HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(resourceResponse);
+ httpResponse.setContentType(ContentTypes.APPLICATION_JSON);
+
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+ result.put("success", false);
+
+ // Chargement des donnees initiales
+ if(cmd.equals("loadData")){
+ try{
+ result = this.loadData(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Chargement des stores categories et archives
+ else if(cmd.equals("loadTagStores")){
+ try{
+ result = this.loadTagStores(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Ajout d'une nouvelle categorie
+ else if(cmd.equals("addCategory")){
+ try{
+ result = this.addCategory(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Edition d'une categorie
+ else if(cmd.equals("editCategory")){
+ try{
+ result = this.editCategory(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Suppression d'une categorie
+ else if(cmd.equals("deleteCategory")){
+ try{
+ result = this.deleteCategory(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Deplacement d'une categorie
+ else if(cmd.equals("moveCategoryNode")){
+ try{
+ result = this.moveCategory(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Ajout d'un nouveau billet
+ else if(cmd.equals("addItem")){
+ try{
+ result = this.addItem(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Edition d'un billet
+ else if(cmd.equals("editItem")){
+ try{
+ result = this.editItem(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Suppression d'un billet
+ else if(cmd.equals("deleteItem")){
+ try{
+ result = this.deleteItem(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Edition du channel
+ else if(cmd.equals("editChannel")){
+ try{
+ result = this.editChannel(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Activation/Desactivation du channel
+ else if(cmd.equals("activateChannel")){
+ try{
+ result = this.activateChannel(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Ajout d'un nouveau fichier depuis le disk
+ else if (cmd.equals("addFileEntry")) {
+ try {
+ result = this.addFileEntry(resourceRequest);
+ } catch (Exception e) {
+ //File Size Exception
+ _log.error("File size exception in blog addFileEntry", e);
+ }
+ }
+ //Ajout d'une image pour le CKEditor
+ else if(cmd.equals("uploadPictureCKEditor")){
+ try {
+ result = this.uploadPictureCKEditor(resourceRequest);
+ } catch (Exception e) {
+ //File Size Exception
+ _log.error("File size exception in blog uploadPictureCKEditor", e);
+ }
+ }
+ //Ajout d'une image sur le ckeditor depuis le cartable
+ else if(cmd.equals("pictureChoosedCKEditor")){
+ try{
+ result = this.pictureChoosedCKEditor(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Envoie dans le casier
+ else if(cmd.equals("sendToCasier")){
+ try{
+ result = this.sendToCasier(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ // Creation d'un nouveau message
+ else if (cmd.equals("createMessage")) {
+ try {
+ result = this.createMessage(resourceRequest);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+ //get the max file upload size
+ else if (cmd.equals("getMaxFileUploadSize")) {
+ try {
+ User user = PortalUtil.getUser(resourceRequest);
+ long uploadMaxSize = ENTMainUtilsLocalServiceUtil.getUploadServletRequestMaxSize(user.getCompanyId());
+ result.put("uploadMaxSize", JSPPortletUtil.getSizeInMegaOctet(uploadMaxSize));
+ result.put("success", true);
+ } catch(Exception e){
+ _log.error(e);
+ }
+ }
+
+ httpResponse.getWriter().write(result.toString());
+ }
+
+ public void processAction(
+ ActionRequest actionRequest, ActionResponse actionResponse)
+ throws IOException, PortletException {
+
+ }
+
+ static SimpleDateFormat classicDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ static SimpleDateFormat frenchDateFormat = new SimpleDateFormat("dd-MM-yyyy");
+
+ // Chargement des donnees initiales
+ private JSONObject loadData(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ final boolean isIntranet = ParamUtil.getBoolean(resourceRequest, "isIntranet");
+ final long itemId = ParamUtil.getLong(resourceRequest, "itemId");
+ final boolean isIE = ParamUtil.getBoolean(resourceRequest, "isIE");
+
+ BlogChannel channel = BlogChannelLocalServiceUtil.getBlogChannel(channelId);
+ result.put("channel", StoreUtil.getChannelAsJson(channel, themeDisplay));
+ result.put("itemStore", StoreUtil.getItemStore(channelId, categoryId, itemId, "0", themeDisplay, isIntranet, 0, 6, isIE));
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryId, "0", isIntranet));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(channelId, categoryId, isIntranet));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Chargement des stores categories et archive
+ private JSONObject loadTagStores(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ final boolean isIntranet = ParamUtil.getBoolean(resourceRequest, "isIntranet");
+ long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+
+ final boolean loadCategoryTagStore = ParamUtil.getBoolean(resourceRequest, "loadCategoryTagStore");
+ final boolean loadArchiveListStore = ParamUtil.getBoolean(resourceRequest, "loadArchiveListStore");
+
+ if(categoryId == channelId){
+ categoryId = 0;
+ }
+
+ if(loadCategoryTagStore){
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryId, month, isIntranet));
+ }
+ if(loadArchiveListStore){
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(channelId, categoryId, isIntranet));
+ }
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Ajout d'une nouvelle categorie
+ private JSONObject addCategory(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ final long parentCategoryId = ParamUtil.getLong(resourceRequest, "parentCategoryId");
+ String title = ParamUtil.getString(resourceRequest, "title");
+ long categoryFilterId = ParamUtil.getLong(resourceRequest, "categoryFilterId");
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+ final User user = PortalUtil.getUser(resourceRequest);
+
+ if(Validator.isNull(title)){
+ title = "Catégorie";
+ }
+
+ BlogCategory category = BlogCategoryLocalServiceUtil.addBlogCategory(parentCategoryId, channelId, user.getGroup().getGroupId(), user.getUserId(), title);
+
+ result.put("categoryId", category.getCategoryId());
+ result.put("title", category.getTitle());
+
+ if(categoryFilterId == channelId){
+ categoryFilterId = 0;
+ }
+
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryFilterId, month, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Edition d'une categorie
+ private JSONObject editCategory(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ String title = ParamUtil.getString(resourceRequest, "title");
+ long categoryFilterId = ParamUtil.getLong(resourceRequest, "categoryFilterId");
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+
+ if(Validator.isNull(title)){
+ title = "Catégorie";
+ }
+
+ BlogCategory category = BlogCategoryLocalServiceUtil.getBlogCategory(categoryId);
+ category.setTitle(title);
+ BlogCategoryLocalServiceUtil.updateBlogCategory(category, false);
+
+ result.put("title", category.getTitle());
+
+ if(categoryFilterId == channelId){
+ categoryFilterId = 0;
+ }
+
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryFilterId, month, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Suppression d'une categorie
+ private JSONObject deleteCategory(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ long parentCategoryId = BlogCategoryLocalServiceUtil.getBlogCategory(categoryId).getParentCategoryId();
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+ final boolean isIE = ParamUtil.getBoolean(resourceRequest, "isIE");
+
+ this.deleteBlogCategory(categoryId);
+
+ if(parentCategoryId == channelId){
+ parentCategoryId = 0;
+ }
+
+ result.put("itemStore", StoreUtil.getItemStore(channelId, parentCategoryId, 0, month, themeDisplay, true, 0, 6, isIE));
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, parentCategoryId, month, true));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(channelId, parentCategoryId, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ private void deleteBlogCategory(long categoryId) throws PortalException, SystemException {
+
+ // Suppression des sous categories
+ List<BlogCategory> lbc = BlogCategoryLocalServiceUtil.getBlogCategoryByParentCategoryId(categoryId);
+ for(BlogCategory bc: lbc){
+ deleteBlogCategory(bc.getCategoryId());
+ }
+
+ // Remove item and the disk used by them
+ List<BlogItem> blogItems = BlogItemLocalServiceUtil.getBlogItemByCategoryId(categoryId);
+ long repositoryId = CompanyConstants.SYSTEM;
+
+ for(BlogItem anItem: blogItems){
+ long totalFileSizeToDelete = 0;
+ totalFileSizeToDelete += StoreUtil.getMediaDiskUsageFromBlogItem(anItem,anItem.getCompanyId(),repositoryId);
+ totalFileSizeToDelete += StoreUtil.getImagesDiskUsageFromBlogItem(anItem,anItem.getCompanyId(),repositoryId);
+ totalFileSizeToDelete += StoreUtil.getAttachedFilesDiskUsageFromBlogItem(anItem,anItem.getCompanyId(),repositoryId);
+ DiskUsageUserLocalServiceUtil.substractDiskUsage(totalFileSizeToDelete, anItem.getUserId(), PortletConstant.BLOG_PORTLET_ID);
+ }
+
+ BlogItemLocalServiceUtil.deleteBlogItemByCategoryId(categoryId);
+
+ // Suppression de la categorie courante
+ BlogCategoryLocalServiceUtil.deleteBlogCategory(categoryId);
+ }
+
+ // Deplacement d'une categorie
+ private JSONObject moveCategory(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+
+ long parentCategoryId = ParamUtil.getLong(resourceRequest, "parentCategoryId");
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+ final User user = PortalUtil.getUser(resourceRequest);
+ final boolean isIE = ParamUtil.getBoolean(resourceRequest, "isIE");
+
+ BlogCategory category = BlogCategoryLocalServiceUtil.getBlogCategory(categoryId);
+ category.setParentCategoryId(parentCategoryId);
+ BlogCategoryLocalServiceUtil.updateBlogCategory(category, false);
+
+ long channelId = BlogChannelLocalServiceUtil.getBlogChannelByUserId(user.getUserId()).getChannelId();
+
+ result.put("itemStore", StoreUtil.getItemStore(channelId, categoryId, 0, month, themeDisplay, true, 0, 6, isIE));
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryId, month, true));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(channelId, categoryId, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Ajout d'un nouveau billet
+ private JSONObject addItem(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ String title = ParamUtil.getString(resourceRequest, "title");
+ final String description = ParamUtil.getString(resourceRequest, "description");
+ final String pubDate = ParamUtil.getString(resourceRequest, "pubDate");
+ final long imageId = ParamUtil.getLong(resourceRequest, "imageId");
+ final long mediaFileId = ParamUtil.getLong(resourceRequest, "mediaFileId");
+ JSONArray attachFiles = JSONFactoryUtil.createJSONArray(ParamUtil.getString(resourceRequest, "attachFiles"));
+ final String monthFilter = ParamUtil.getString(resourceRequest, "month", "0");
+ long categoryFilterId = ParamUtil.getLong(resourceRequest, "categoryFilterId");
+ final boolean isIE = ParamUtil.getBoolean(resourceRequest, "isIE");
+
+ final User user = PortalUtil.getUser(resourceRequest);
+
+ if(Validator.isNull(title)){
+ title = "Billet";
+ }
+
+ String[] date = pubDate.substring(0, 10).split("-");
+ Calendar cal = GregorianCalendar.getInstance(Locale.FRANCE);
+ cal.setTime(new Date());
+ cal.set(Integer.valueOf(date[0]), Integer.valueOf(date[1]) - 1, Integer.valueOf(date[2]));
+
+ BlogChannel channel = BlogChannelLocalServiceUtil.getBlogChannelByUserId(user.getUserId());
+ channel.setLastBuildDate(new Date());
+ BlogChannelLocalServiceUtil.updateBlogChannel(channel, false);
+
+ BlogItem item = BlogItemLocalServiceUtil.addBlogItem(user.getCompanyId(), channel.getChannelId(), user.getGroup().getGroupId(), user.getUserId(), categoryId, title, description, cal.getTime());
+
+ // Image
+ if(imageId>0){
+ try {
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), imageId, "");
+ // Add image to disk usage of user
+ DiskUsageUserLocalServiceUtil.addDiskUsage(DLAppLocalServiceUtil.getFileEntry(imageId), user.getUserId(), PortalUtil.getPortletId(resourceRequest));
+ BlogItemLocalServiceUtil.updateImageFile(item.getItemId(), ovp, "");
+ } catch (Exception e){
+ result.put("addImageException", "En raison d'un dysfonctionnement réseau, l'image n'a pas pu être correctement ajoutée.");
+ }
+ }
+
+ // Media
+ if(mediaFileId>0){
+ try {
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), mediaFileId, "");
+ // Add media to disk usage of user
+ DiskUsageUserLocalServiceUtil.addDiskUsage(DLAppLocalServiceUtil.getFileEntry(mediaFileId), user.getUserId(), PortalUtil.getPortletId(resourceRequest));
+ BlogItemLocalServiceUtil.updateMediaOriginalFile(item.getItemId(),ovp, "");
+ } catch (Exception e){
+ result.put("addMediaException", "En raison d'un dysfonctionnement réseau, le média n'a pas pu être correctement ajouté.");
+ }
+ }
+
+ // Pieces jointes
+ if(attachFiles.length()>0){
+ ArrayList<ObjectValuePair<String, byte[]>> listPJ = new ArrayList<ObjectValuePair<String, byte[]>>();
+ for (int i=0; i<attachFiles.length(); i++) {
+ try{
+ long fileId = attachFiles.getLong(i);
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), fileId, "");
+ // Add files to disk usage of user
+ DiskUsageUserLocalServiceUtil.addDiskUsage(DLAppLocalServiceUtil.getFileEntry(fileId), user.getUserId(), PortalUtil.getPortletId(resourceRequest));
+ listPJ.add(ovp);
+ } catch (Exception e){
+ result.put("addPJException", "En raison d'un dysfonctionnement réseau, toutes les pièces jointes n'ont pas pu être correctement ajoutées.");
+ }
+ }
+ BlogItemLocalServiceUtil.updateAttachements(item.getItemId(), listPJ, new ArrayList<String>());
+ }
+
+
+ result.put("itemId", item.getItemId());
+ result.put("title", item.getTitle());
+ result.put("description", item.getDescription());
+ result.put("author", UserLocalServiceUtil.getUser(item.getUserId()).getFullName());
+
+ Date d = new Date();
+ Calendar calendarNow = GregorianCalendar.getInstance(Locale.FRANCE);
+ calendarNow.setTime(d);
+ result.put("active", calendarNow.after(cal));
+
+ result.put("pubDate", classicDateFormat.format(item.getPubDate()));
+ result.put("pubDateFormat", frenchDateFormat.format(item.getPubDate()));
+ JSONObject category = JSONFactoryUtil.createJSONObject();
+ category.put("categoryId", categoryId);
+ if(categoryId == channel.getChannelId()){
+ category.put("categoryName", "Toutes");
+ } else {
+ BlogCategory categ = BlogCategoryLocalServiceUtil.getBlogCategory(categoryId);
+ category.put("categoryName", categ.getTitle());
+ }
+ result.put("category", category);
+
+ // Image
+ String imageFileName = FileUtil.getShortFileName(item.getImageFile(item.getCompanyId()));
+ if(!imageFileName.isEmpty()){
+ result.put("image", PortalUtil.getPortalProperties().getProperty("absolute.url") + themeDisplay.getPathMain()+"/blog/get_item_file?itemId="+item.getItemId()+"&fileName="+HttpUtil.encodeURL(imageFileName)+"&fileType=image");
+ } else {
+ result.put("image", "");
+ }
+
+ // Media
+ String mediaFileName = FileUtil.getShortFileName(item.getMediaOriginalFile(item.getCompanyId()));
+ result.put("mediaFileName", mediaFileName);
+ if(!mediaFileName.isEmpty()){
+ result.put("mediaOriginal", themeDisplay.getPathMain()+"/blog/get_item_file?itemId="+item.getItemId()+"&fileName=" +
+ HttpUtil.encodeURL(mediaFileName)+"&fileType=mediaOriginal");
+ String mediaConvertedFileName = FileUtil.getShortFileName(item.getMediaConvertedFile(item.getCompanyId()));
+ if(mediaConvertedFileName.isEmpty()){
+ result.put("mediaConvertedViewer", "<i style='color: red;'>Le média est actuellement en cours de conversion.</i>");
+ }
+ else {
+ result.put("mediaConverted", themeDisplay.getPathMain()+"/blog/get_item_file?itemId=" + item.getItemId() + "&fileName=" +
+ HttpUtil.encodeURL(mediaConvertedFileName)+"&fileType=mediaConverted");
+ String mediaConvertedExtension = DLEntryUtil.splitFileName(mediaConvertedFileName)[1];
+ result.put("mediaConvertedExtension", mediaConvertedExtension);
+ }
+ } else {
+ result.put("mediaOriginal", "");
+ result.put("mediaConvertedViewer", "");
+ }
+
+ // Pieces jointes
+ final JSONArray attachements = JSONFactoryUtil.createJSONArray();
+ String[] attachementsFiles = item.getAttachmentsFiles(item.getCompanyId());
+ for (int k = 0; k < attachementsFiles.length; k++) {
+ final JSONObject fileDescriptor = JSPPortletUtil.formatAttachment(themeDisplay, attachementsFiles[k], item.getItemId(), PortletConstant.BLOG);
+ attachements.put(fileDescriptor);
+ }
+ result.put("attachments", attachements.toString());
+
+ // Pour la mise a jour du store
+ int month = cal.get(Calendar.MONTH);
+ int year = cal.get(Calendar.YEAR);
+ result.put("month", year + "" + month);
+ JSONArray categories = StoreUtil.getItemCategoryList(channel.getChannelId(), categoryId);
+ if(!categories.toString().contains(String.valueOf(categoryFilterId))){
+ categoryFilterId = categoryId;
+ result.put("treePath", StoreUtil.getCategoryTreePath(channel.getChannelId(), categoryId));
+ result.put("itemStore", StoreUtil.getItemStore(channel.getChannelId(), categoryFilterId, 0, monthFilter, themeDisplay, true, 0, 6, isIE));
+ }
+ result.put("categories", categories);
+
+
+ // Pour le tri
+ result.put("sort", item.getPubDate().getTime());
+
+ // Mise a jour du store des categories et des archives
+ if(categoryFilterId == channel.getChannelId()){
+ categoryFilterId = 0;
+ }
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(item.getChannelId(), categoryFilterId, monthFilter, true));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(item.getChannelId(), categoryFilterId, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Edition d'un billet
+ private JSONObject editItem(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+
+ final long itemId = ParamUtil.getLong(resourceRequest, "itemId");
+ final long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ String title = ParamUtil.getString(resourceRequest, "title");
+ final String description = ParamUtil.getString(resourceRequest, "description");
+ final String pubDate = ParamUtil.getString(resourceRequest, "pubDate");
+ final long imageId = ParamUtil.getLong(resourceRequest, "imageId");
+ final String image = ParamUtil.getString(resourceRequest, "imageId");
+ final long mediaFileId = ParamUtil.getLong(resourceRequest, "mediaFileId");
+ final String media = ParamUtil.getString(resourceRequest, "mediaFileId");
+ JSONArray attachFiles = JSONFactoryUtil.createJSONArray(ParamUtil.getString(resourceRequest, "attachFiles"));
+ JSONArray existingAttachFiles = JSONFactoryUtil.createJSONArray(ParamUtil.getString(resourceRequest, "existingAttachFiles"));
+ final String monthFilter = ParamUtil.getString(resourceRequest, "month", "0");
+ long categoryFilterId = ParamUtil.getLong(resourceRequest, "categoryFilterId");
+ final User user = PortalUtil.getUser(resourceRequest);
+
+ if(Validator.isNull(title)){
+ title = "Billet";
+ }
+
+ BlogChannel channel = BlogChannelLocalServiceUtil.getBlogChannelByUserId(user.getUserId());
+ channel.setLastBuildDate(new Date());
+ BlogChannelLocalServiceUtil.updateBlogChannel(channel, false);
+
+ BlogItem item = BlogItemLocalServiceUtil.getBlogItem(itemId);
+ item.setTitle(title);
+ item.setDescription(description);
+ item.setCategoryId(categoryId);
+ long repositoryId = CompanyConstants.SYSTEM;
+ long companyId = item.getCompanyId();
+
+ String[] date = pubDate.substring(0, 10).split("-");
+ Calendar cal = GregorianCalendar.getInstance(Locale.FRANCE);
+ cal.setTime(item.getPubDate());
+ cal.set(Integer.valueOf(date[0]), Integer.valueOf(date[1]) - 1, Integer.valueOf(date[2]));
+ item.setPubDate(cal.getTime());
+
+ BlogItemLocalServiceUtil.updateBlogItem(item, false);
+ /**
+ * Delete current disk usage for blog item, the new usage will be added during process
+ */
+ long totalFileSizeToDelete = 0;
+ long totalFileSizeToAdd = 0;
+
+ // Image
+ if(imageId>0){
+ try {
+ /**
+ * Management disk usage image
+ */
+ totalFileSizeToDelete += StoreUtil.getImagesDiskUsageFromBlogItem(item,companyId,repositoryId);
+ totalFileSizeToAdd += DLAppLocalServiceUtil.getFileEntry(imageId).getSize();
+
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), imageId,"");
+ BlogItemLocalServiceUtil.updateImageFile(item.getItemId(), ovp, item.getImageFile(item.getCompanyId()));
+ } catch (Exception e){
+ result.put("addImageException", "En raison d'un dysfonctionnement réseau, l'image n'a pas pu être correctement ajoutée.");
+ }
+ } else if(image.isEmpty()){
+ totalFileSizeToDelete += StoreUtil.getImagesDiskUsageFromBlogItem(item,companyId,repositoryId);
+ BlogItemLocalServiceUtil.updateImageFile(item.getItemId(), null, item.getImageFile(item.getCompanyId()));
+ }
+
+ // Media
+ if(mediaFileId>0){
+ try {
+ /**
+ * Management disk usage media
+ */
+ totalFileSizeToDelete += StoreUtil.getMediaDiskUsageFromBlogItem(item,companyId,repositoryId);
+ totalFileSizeToAdd += DLAppLocalServiceUtil.getFileEntry(mediaFileId).getSize();
+
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), mediaFileId, "");
+ // Suppression l'ancien media convertit
+ totalFileSizeToDelete += StoreUtil.getMediaDiskUsageFromBlogItem(item,companyId,repositoryId);
+ BlogItemLocalServiceUtil.updateMediaConvertedFile(item.getItemId(), null, item.getMediaConvertedFile(item.getCompanyId()));
+ // Mise a jour du media --> puis conversion
+ BlogItemLocalServiceUtil.updateMediaOriginalFile(item.getItemId(),ovp, item.getMediaOriginalFile(item.getCompanyId()));
+ } catch (Exception e){
+ result.put("addMediaException", "En raison d'un dysfonctionnement réseau, le média n'a pas pu être correctement ajouté.");
+ }
+ } else if(media.isEmpty()){
+ totalFileSizeToDelete += StoreUtil.getMediaDiskUsageFromBlogItem(item,companyId,repositoryId);
+ BlogItemLocalServiceUtil.updateMediaOriginalFile(item.getItemId(), null, item.getMediaOriginalFile(item.getCompanyId()));
+ BlogItemLocalServiceUtil.updateMediaConvertedFile(item.getItemId(), null, item.getMediaConvertedFile(item.getCompanyId()));
+ }
+
+ // Pieces jointes
+ ArrayList<ObjectValuePair<String, byte[]>> listPJ = new ArrayList<ObjectValuePair<String, byte[]>>();
+ for (int i=0; i<attachFiles.length(); i++) {
+ try{
+ long fileId = attachFiles.getLong(i);
+ /**
+ * add new files to disk usage
+ */
+ totalFileSizeToAdd += DLAppLocalServiceUtil.getFileEntry(fileId).getSize();
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), fileId, "");
+ listPJ.add(ovp);
+ } catch (Exception e){
+ result.put("addPJException", "En raison d'un dysfonctionnement réseau, toutes les pièces jointes n'ont pas pu être correctement ajoutées.");
+ }
+ }
+ ArrayList<String> existingFiles = new ArrayList<String>();
+ for (int i=0; i<existingAttachFiles.length(); i++) {
+ String name = existingAttachFiles.getString(i);
+ existingFiles.add(name);
+ }
+
+ try{
+ String dirName = item.getAttachmentsDir();
+ String[] fileNames = DLStoreUtil.getFileNames(
+ companyId, repositoryId, dirName);
+ for (String fileName: fileNames) {
+ if (!existingFiles.contains(fileName)) {
+ /**
+ * remove old file to disk usage
+ */
+ totalFileSizeToDelete += DLStoreUtil.getFileSize(companyId,repositoryId, fileName);
+ }
+ }
+ }
+ catch(NoSuchDirectoryException e) {
+ // no attached file
+ }
+
+ BlogItemLocalServiceUtil.updateAttachements(item.getItemId(), listPJ, existingFiles);
+
+ //remove the size of removed file from disk usage
+ DiskUsageUserLocalServiceUtil.substractDiskUsage(totalFileSizeToDelete,user.getUserId(),PortalUtil.getPortletId(resourceRequest));
+ //remove the size of removed file from disk usage
+ DiskUsageUserLocalServiceUtil.addDiskUsage(totalFileSizeToAdd,user.getUserId(),PortalUtil.getPortletId(resourceRequest));
+
+
+ result.put("itemId", item.getItemId());
+ result.put("title", item.getTitle());
+ result.put("description", item.getDescription());
+ result.put("author", UserLocalServiceUtil.getUser(item.getUserId()).getFullName());
+
+ Date d = new Date();
+ Calendar calendarNow = GregorianCalendar.getInstance(Locale.FRANCE);
+ calendarNow.setTime(d);
+ result.put("active", calendarNow.after(cal));
+ result.put("pubDate", classicDateFormat.format(item.getPubDate()));
+ result.put("pubDateFormat", frenchDateFormat.format(item.getPubDate()));
+ JSONObject category = JSONFactoryUtil.createJSONObject();
+ category.put("categoryId", categoryId);
+ if(categoryId == channel.getChannelId()){
+ category.put("categoryName", "Toutes");
+ } else {
+ BlogCategory categ = BlogCategoryLocalServiceUtil.getBlogCategory(categoryId);
+ category.put("categoryName", categ.getTitle());
+ }
+ result.put("category", category);
+
+ // Image
+ String imageFileName = FileUtil.getShortFileName(item.getImageFile(item.getCompanyId()));
+ if(!imageFileName.isEmpty()){
+ result.put("image", PortalUtil.getPortalProperties().getProperty("absolute.url") + themeDisplay.getPathMain()+"/blog/get_item_file?itemId="+item.getItemId()+"&fileName="+HttpUtil.encodeURL(imageFileName)+"&fileType=image");
+ } else {
+ result.put("image", "");
+ }
+
+ // Media
+ String mediaFileName = FileUtil.getShortFileName(item.getMediaOriginalFile(item.getCompanyId()));
+ result.put("mediaFileName", mediaFileName);
+ if(!mediaFileName.isEmpty()){
+ result.put("mediaOriginal", themeDisplay.getPathMain()+"/blog/get_item_file?itemId="+item.getItemId()+"&fileName=" +
+ HttpUtil.encodeURL(mediaFileName)+"&fileType=attachment");
+ String mediaConvertedFileName = FileUtil.getShortFileName(item.getMediaConvertedFile(item.getCompanyId()));
+ if(mediaConvertedFileName.isEmpty()) {
+ result.put("mediaConvertedViewer", "<i style='color: red;'>Le média est actuellement en cours de conversion.</i>");
+ }
+ else {
+ result.put("mediaConverted", themeDisplay.getPathMain()+"/blog/get_item_file?itemId="+item.getItemId()+"&fileName=" +
+ HttpUtil.encodeURL(mediaFileName)+"&fileType=mediaConverted");
+ String mediaConvertedExtension = DLEntryUtil.splitFileName(mediaConvertedFileName)[1];
+ result.put("mediaConvertedExtension", mediaConvertedExtension);
+ }
+ } else {
+ result.put("mediaOriginal", "");
+ result.put("mediaConvertedViewer", "");
+ }
+
+ // Pieces jointes
+ final JSONArray attachements = JSONFactoryUtil.createJSONArray();
+ String[] attachementsFiles = item.getAttachmentsFiles(item.getCompanyId());
+ for (int k = 0; k < attachementsFiles.length; k++) {
+ final JSONObject fileDescriptor = JSPPortletUtil.formatAttachment(themeDisplay, attachementsFiles[k], item.getItemId(), PortletConstant.BLOG);
+ attachements.put(fileDescriptor);
+ }
+ result.put("attachments", attachements.toString());
+
+ // Pour la mise a jour du store
+ int month = cal.get(Calendar.MONTH);
+ int year = cal.get(Calendar.YEAR);
+ result.put("month", year + "" + month);
+ result.put("categories", StoreUtil.getItemCategoryList(channel.getChannelId(), categoryId));
+
+ // Pour le tri
+ result.put("sort", item.getPubDate().getTime());
+
+ // Mise a jour du store des categories et des archives
+ if(categoryFilterId == channel.getChannelId()){
+ categoryFilterId = 0;
+ }
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(item.getChannelId(), categoryFilterId, monthFilter, true));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(item.getChannelId(), categoryFilterId, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Suppression d'un billet
+ private JSONObject deleteItem(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ final long itemId = ParamUtil.getLong(resourceRequest, "itemId");
+ long categoryId = ParamUtil.getLong(resourceRequest, "categoryId");
+ final String month = ParamUtil.getString(resourceRequest, "month", "0");
+
+ long channelId = BlogItemLocalServiceUtil.getBlogItem(itemId).getChannelId();
+
+ /**
+ * BEGIN :Delete the disk used by a blog ticket
+ */
+ long repositoryId = CompanyConstants.SYSTEM;
+ BlogItem item = BlogItemLocalServiceUtil.getBlogItem(itemId);
+ long companyId = item.getCompanyId();
+ long totalFileSizeToDelete = 0;
+
+ totalFileSizeToDelete += StoreUtil.getMediaDiskUsageFromBlogItem(item,companyId,repositoryId);
+ totalFileSizeToDelete += StoreUtil.getImagesDiskUsageFromBlogItem(item,companyId,repositoryId);
+ totalFileSizeToDelete += StoreUtil.getAttachedFilesDiskUsageFromBlogItem(item,companyId,repositoryId);
+ DiskUsageUserLocalServiceUtil.substractDiskUsage(totalFileSizeToDelete, PortalUtil.getUserId(resourceRequest), PortalUtil.getPortletId(resourceRequest));
+ /**
+ * END :Delete the disk used by a blog ticket
+ */
+
+ BlogItemLocalServiceUtil.deleteBlogItem(itemId);
+
+
+ // Mise a jour du store des archives
+ if(categoryId == channelId){
+ categoryId = 0;
+ }
+ result.put("categoryTagStore", StoreUtil.getCategoryTagStore(channelId, categoryId, month, true));
+ result.put("archiveListStore", StoreUtil.getArchiveListStore(channelId, categoryId, true));
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Edition du channel
+ private JSONObject editChannel(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
+
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+ String title = ParamUtil.getString(resourceRequest, "title");
+ final String description = ParamUtil.getString(resourceRequest, "description");
+ final long imageId = ParamUtil.getLong(resourceRequest, "imageId");
+ final String image = ParamUtil.getString(resourceRequest, "imageId");
+ final long imageInternetId = ParamUtil.getLong(resourceRequest, "imageInternetId");
+ String imageInternet = ParamUtil.getString(resourceRequest, "imageInternetId", "");
+ String imageInternetName = ParamUtil.getString(resourceRequest, "imageInternetName", "");
+ final String defaultImageInternet = ParamUtil.getString(resourceRequest, "defaultImageInternet");
+ final int height = ParamUtil.getInteger(resourceRequest, "heightImageInternet");
+ final int width = ParamUtil.getInteger(resourceRequest, "widthImageInternet");
+ final boolean repeat = ParamUtil.getBoolean(resourceRequest, "repeatImageInternet", false);
+ final String color = ParamUtil.getString(resourceRequest, "color");
+ final boolean showCategoryTree = ParamUtil.getBoolean(resourceRequest, "showCategoryTree", false);
+ final boolean showCategoryTag = ParamUtil.getBoolean(resourceRequest, "showCategoryTag", false);
+ final boolean showArchiveList = ParamUtil.getBoolean(resourceRequest, "showArchiveList", false);
+ final User user = PortalUtil.getUser(resourceRequest);
+
+ BlogChannel channel = BlogChannelLocalServiceUtil.getBlogChannel(channelId);
+ channel.setTitle(title);
+ channel.setDescription(description);
+
+ // Image
+ if(imageId>0){
+ try {
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), imageId, "");
+ BlogChannelLocalServiceUtil.updateImageFile(channel.getChannelId(), ovp, channel.getImageFile(user.getCompanyId()));
+ } catch (Exception e){
+ result.put("addImageException", "En raison d'un dysfonctionnement réseau, l'image n'a pas pu être correctement ajoutée.");
+ }
+ } else if(image.isEmpty()){
+ BlogChannelLocalServiceUtil.updateImageFile(channel.getChannelId(), null, channel.getImageFile(user.getCompanyId()));
+ }
+
+ // Image Internet
+ if(imageInternetId>0){
+ try {
+ ObjectValuePair<String, byte[]> ovp = JSPPortletUtil.getFileAsOVP(user.getCompanyId(), imageInternetId, "");
+ BlogChannelLocalServiceUtil.updateImageInternetFile(channel.getChannelId(), ovp, channel.getImageInternetFile(user.getCompanyId()));
+ } catch (Exception e){
+ result.put("addImageException", "En raison d'un dysfonctionnement réseau, l'image n'a pas pu être correctement ajoutée.");
+ }
+ } else if(imageInternet.isEmpty()){
+ BlogChannelLocalServiceUtil.updateImageInternetFile(channel.getChannelId(), null, channel.getImageInternetFile(user.getCompanyId()));
+ }
+
+ JSONObject topBand = JSONFactoryUtil.createJSONObject();
+ topBand.put("imageInternet", imageInternet);
+ topBand.put("defaultImageInternet", defaultImageInternet);
+ topBand.put("imageInternetName", imageInternetName);
+ topBand.put("height", height);
+ topBand.put("width", width);
+ topBand.put("repeat", repeat);
+ channel.setTopBand(topBand.toString());
+
+ JSONObject configuration = JSONFactoryUtil.createJSONObject();
+ configuration.put("color", color);
+ configuration.put("showCategoryTree", showCategoryTree);
+ configuration.put("showCategoryTag", showCategoryTag);
+ configuration.put("showArchiveList", showArchiveList);
+ channel.setConfiguration(configuration.toString());
+
+ BlogChannelLocalServiceUtil.updateBlogChannel(channel, false);
+
+ result.put("title", title);
+ result.put("description", description);
+
+ // Image
+ String imageFileName = FileUtil.getShortFileName(channel.getImageFile(themeDisplay.getCompanyId()));
+ if(!imageFileName.isEmpty()){
+ result.put("image", PortalUtil.getPortalProperties().getProperty("absolute.url") + themeDisplay.getPathMain()+"/blog/get_channel_file?channelId="+channel.getChannelId()+"&fileName="+HttpUtil.encodeURL(imageFileName)+"&fileType=image");
+ } else {
+ result.put("image", "");
+ }
+
+ // Bandeau Haut
+ result.put("topBand", topBand);
+
+ // Configuration
+ result.put("configuration", configuration);
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Activation/Desactivation du channel
+ private JSONObject activateChannel(ResourceRequest resourceRequest) throws PortalException, SystemException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ final long channelId = ParamUtil.getLong(resourceRequest, "channelId");
+
+ BlogChannel channel = BlogChannelLocalServiceUtil.getBlogChannel(channelId);
+ channel.setActive_(!channel.isActive_());
+ BlogChannelLocalServiceUtil.updateBlogChannel(channel, false);
+
+ result.put("success", true);
+ return result;
+ }
+
+ // Ajout d'un nouveau fichier depluis le disk
+ private JSONObject addFileEntry(ResourceRequest resourceRequest) throws PortalException, SystemException, IOException {
+ final User user = PortalUtil.getUser(resourceRequest);
+ ResourceBundle messages = ResourceBundle.getBundle("content.Language", user.getLocale());
+
+ return JSPPortletUtil.addFileEntry(resourceRequest, messages, true);
+ }
+
+ //Ajout d'une image sur le ckeditor depuis le cartable
+ private JSONObject pictureChoosedCKEditor(ResourceRequest resourceRequest) throws PortalException, SystemException, IOException {
+ return JSPPortletUtil.pictureChoosedCKEditor(resourceRequest);
+ }
+
+ //Ajout d'une image pour le CKEditor
+ private JSONObject uploadPictureCKEditor(ResourceRequest resourceRequest) throws PortalException, SystemException, IOException {
+ return JSPPortletUtil.uploadPictureCKEditor(resourceRequest);
+ }
+
+ //Envoie de la piece jointe dans le casier du user
+ private JSONObject sendToCasier(ResourceRequest resourceRequest) throws SystemException, PortalException {
+ JSONObject result = JSONFactoryUtil.createJSONObject();
+
+ User user = PortalUtil.getUser(resourceRequest);
+
+ final Folder receiverDropBox = FoldersUtil.getDropBox(user.getUserId());
+
+ JSONArray attachFiles = JSONFactoryUtil.createJSONArray(ParamUtil.getString(resourceRequest, "attachFiles"));
+
+ long attachFilesSize = 0;
+
+ for (int i=0; i<attachFiles.length(); i++) {
+ JSONObject pjobj = attachFiles.getJSONObject(i);
+
+ BlogItem item = BlogItemLocalServiceUtil.getBlogItem(pjobj.getLong("itemId"));
+
+ try {
+ FileEntry fileEntry = DLAppUtil.addFileEntry(user, receiverDropBox, item.getAttachmentsDir(), pjobj.getString("name"));
+ attachFilesSize += fileEntry.getSize();
+ CasierEntryLocalServiceUtil.addCasierEntry(receiverDropBox.getCompanyId(), receiverDropBox.getGroupId(), fileEntry.getFileEntryId(), user.getUserId(), "", true);
+ } catch(Exception e){
+ _log.error(e);
+ result.put("success", false);
+ return result;
+ }
+ }
+
+ DiskUsageUserLocalServiceUtil.addDiskUsage(attachFilesSize, user.getUserId(), PortletConstant.CARTABLE_PORTLET_ID);
+ result.put("success", true);
+ return result;
+ }
+
+ // Creation d'un nouveau message
+ private JSONObject createMessage(ResourceRequest resourceRequest) throws NamingException, Exception {
+ return JSPPortletUtil.createMessage(resourceRequest);
+ }
+
+ private static final String PLAIN_ASCII =
+ "AaEeIiOoUu" // grave
+ + "AaEeIiOoUuYy" // acute
+ + "AaEeIiOoUuYy" // circumflex
+ + "AaOoNn" // tilde
+ + "AaEeIiOoUuYy" // umlaut
+ + "Aa" // ring
+ + "Cc" // cedilla
+ + "OoUu" // double acute
+ ;
+
+ private static final String UNICODE =
+ "\u00C0\u00E0\u00C8\u00E8\u00CC\u00EC\u00D2\u00F2\u00D9\u00F9"
+ + "\u00C1\u00E1\u00C9\u00E9\u00CD\u00ED\u00D3\u00F3\u00DA\u00FA\u00DD\u00FD"
+ + "\u00C2\u00E2\u00CA\u00EA\u00CE\u00EE\u00D4\u00F4\u00DB\u00FB\u0176\u0177"
+ + "\u00C3\u00E3\u00D5\u00F5\u00D1\u00F1"
+ + "\u00C4\u00E4\u00CB\u00EB\u00CF\u00EF\u00D6\u00F6\u00DC\u00FC\u0178\u00FF"
+ + "\u00C5\u00E5"
+ + "\u00C7\u00E7"
+ + "\u0150\u0151\u0170\u0171"
+ ;
+
+ // remove accentued from a string and replace with ascii equivalent
+ public static String convertNonAscii(String s) {
+ if (s == null) return null;
+ StringBuilder sb = new StringBuilder();
+ int n = s.length();
+ for (int i = 0; i < n; i++) {
+ char c = s.charAt(i);
+ int pos = UNICODE.indexOf(c);
+ if (pos > -1){
+ sb.append(PLAIN_ASCII.charAt(pos));
+ }
+ else {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
+
+ protected void include(
+ String path, RenderRequest renderRequest,
+ RenderResponse renderResponse)
+ throws IOException, PortletException {
+
+ PortletRequestDispatcher portletRequestDispatcher =
+ getPortletContext().getRequestDispatcher(path);
+
+ if (portletRequestDispatcher == null) {
+ _log.error(path + " is not a valid include");
+ }
+ else {
+ portletRequestDispatcher.include(renderRequest, renderResponse);
+ }
+ }
+
+ protected String editJSP;
+ protected String helpJSP;
+ protected String viewJSP;
+
+ private static Log _log = LogFactoryUtil.getLog(JSPPortlet.class);
+
+}