001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.jsp; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.flex.CmsFlexController; 033import org.opencms.main.CmsException; 034import org.opencms.pdftools.CmsPdfThumbnailLink; 035 036import javax.servlet.ServletRequest; 037import javax.servlet.jsp.tagext.TagSupport; 038 039/** 040 * JSP tag to generate a link to a PDF produced from a given XML content.<p> 041 */ 042public class CmsJspTagPdfThumbnail extends TagSupport { 043 044 /** Serial version id. */ 045 private static final long serialVersionUID = 1L; 046 047 /** The path of the content resource for which the PDF link should be generated. */ 048 private String m_file; 049 050 /** The image format. */ 051 private String m_format = "png"; 052 053 /** The image height. */ 054 private int m_height = -1; 055 056 /** The image width. */ 057 private int m_width = -1; 058 059 /** 060 * The implementation of the tag.<p> 061 * 062 * @param request the current request 063 * @param file the path to the PDF 064 * @param width the thumbnail width 065 * @param height the thumbnail height 066 * @param format the image format 067 * 068 * @throws CmsException if something goes wrong 069 * 070 * @return the link to the PDF thumbnail 071 */ 072 public static String pdfTagAction(ServletRequest request, String file, int width, int height, String format) 073 throws CmsException { 074 075 CmsFlexController controller = CmsFlexController.getController(request); 076 CmsObject cms = controller.getCmsObject(); 077 CmsResource pdfRes = cms.readResource(file); 078 CmsPdfThumbnailLink linkObj = new CmsPdfThumbnailLink(cms, pdfRes, width, height, format); 079 return linkObj.getLinkWithOptions(); 080 } 081 082 /** 083 * @see javax.servlet.jsp.tagext.Tag#doStartTag() 084 */ 085 @Override 086 public int doStartTag() { 087 088 try { 089 pageContext.getOut().print(pdfTagAction(pageContext.getRequest(), m_file, m_width, m_height, m_format)); 090 } catch (Exception e) { 091 throw new RuntimeException(e); 092 } 093 return SKIP_BODY; 094 } 095 096 /** 097 * Sets the path to the PDF.<p> 098 * 099 * @param file the PDF path 100 */ 101 public void setFile(String file) { 102 103 m_file = file; 104 } 105 106 /** 107 * Setter for the format path.<p> 108 * 109 * @param format the format path 110 */ 111 public void setFormat(String format) { 112 113 m_format = format; 114 } 115 116 /** 117 * Sets the height.<p> 118 * 119 * @param height the height to set 120 */ 121 public void setHeight(String height) { 122 123 try { 124 m_height = Integer.parseInt(height); 125 } catch (NumberFormatException e) { 126 m_height = -1; 127 } 128 129 } 130 131 /** 132 * Sets the width.<p> 133 * 134 * @param width the width to set 135 */ 136 public void setWidth(String width) { 137 138 try { 139 m_width = Integer.parseInt(width); 140 } catch (NumberFormatException e) { 141 m_width = -1; 142 } 143 } 144 145}