List of usage examples for javax.servlet.jsp JspException JspException
public JspException(String message, Throwable cause)
JspException
with the specified detail message and cause. From source file:org.apache.struts.tiles.taglib.util.TagUtils.java
/** * Get component definition by its name. * @param name Definition name.// w w w . jav a2 s .co m * @param pageContext The PageContext for the current page. * @throws JspException - */ public static ComponentDefinition getComponentDefinition(String name, PageContext pageContext) throws JspException { try { return TilesUtil.getDefinition(name, pageContext.getRequest(), pageContext.getServletContext()); } catch (NoSuchDefinitionException ex) { throw new JspException("Error : Can't get component definition for '" + name + "'. Check if this name exist in component definitions.", ex); } catch (FactoryNotFoundException ex) { // factory not found. throw new JspException(ex); } catch (DefinitionsFactoryException ex) { if (debug) ex.printStackTrace(); // Save exception to be able to show it later saveException(pageContext, ex); throw new JspException(ex); } }
From source file:org.codehaus.groovy.grails.web.taglib.jsp.JspRenderInputTag.java
@Override protected int doStartTagInternal() throws Exception { if (StringUtils.isBlank(property)) { throw new JspTagException("Tag [renderInput] missing required attribute [property]"); }// www .j av a 2 s. co m if (StringUtils.isBlank(bean)) { throw new JspTagException("Tag [renderInput] missing required attribute [bean]"); } if (!ExpressionEvaluationUtils.isExpressionLanguage(bean)) { throw new JspTagException("Attribute [bean] of tag [renderInput] must be a JSTL expression"); } @SuppressWarnings("unused") Writer out = pageContext.getOut(); try { Object beanInstance = ExpressionEvaluationUtils.evaluate("bean", bean, Object.class, pageContext); if (beanInstance == null) { throw new JspTagException("Bean [" + bean + "] referenced by tag [renderInput] cannot be null"); } GrailsTagRegistry tagRegistry = GrailsTagRegistry.getInstance(); Map<String, Object> tagContext = new HashMap<String, Object>(); tagContext.put(GroovyPage.REQUEST, pageContext.getRequest()); tagContext.put(GroovyPage.RESPONSE, pageContext.getResponse()); tagContext.put(GroovyPage.SERVLET_CONTEXT, pageContext.getServletContext()); RenderInputTag tag = (RenderInputTag) tagRegistry.newTag(RenderInputTag.TAG_NAME); tag.init(tagContext); tag.setBean(beanInstance); tag.setProperty(property); tag.doStartTag(); } catch (InvalidPropertyException ipe) { throw new JspException("Attribute [property] with value [" + property + "] is not a valid property of bean [" + bean + "] in tag [renderInput]", ipe); } return SKIP_BODY; }
From source file:org.displaytag.export.FopExportView.java
/** * Don't forget to enable debug if you want to see the raw FO. * * @param out output writer//from w w w . j a va 2 s . c om * @throws IOException Signals that an I/O exception has occurred. * @throws JspException the jsp exception */ @Override public void doExport(OutputStream out) throws IOException, JspException { String xmlResults = getXml(); FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); Source xslt = new StreamSource(getStyleSheet()); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = factory.newTransformer(xslt); } catch (TransformerConfigurationException e) { throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$ } boolean outputForDebug = log.isDebugEnabled(); if (outputForDebug) { logXsl(xmlResults, transformer, null); } Fop fop; try { fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, out); } catch (FOPException e) { throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$ } StreamSource src = new StreamSource(new StringReader(xmlResults)); Result res; try { res = new SAXResult(fop.getDefaultHandler()); } catch (FOPException e) { throw new JspException("error setting up transform ", e); //$NON-NLS-1$ } try { transformer.transform(src, res); } catch (TransformerException e) { if (e.getCause() instanceof ValidationException) { // recreate the errant fo ValidationException ve = (ValidationException) e.getCause(); logXsl(xmlResults, transformer, ve); } else { throw new JspException("error creating pdf output", e); //$NON-NLS-1$ } } }
From source file:org.displaytag.export.FopExportView.java
/** * log it./*from w w w .j a v a2 s . c om*/ * @param xmlResults raw * @param transformer the transformer * @param e the optional exception * @throws JspException wrapping an existing error */ protected void logXsl(String xmlResults, Transformer transformer, Exception e) throws JspException { StreamResult debugRes = new StreamResult(new StringWriter()); StreamSource src = new StreamSource(new StringReader(xmlResults)); try { transformer.transform(src, debugRes); if (e != null) { log.error("xslt-fo error " + e.getMessage(), e); //$NON-NLS-1$ log.error("xslt-fo result of " + debugRes.getWriter()); //$NON-NLS-1$ throw new JspException("Stylesheet produced invalid xsl-fo result", e); //$NON-NLS-1$ } else { log.info("xslt-fo result of " + debugRes.getWriter()); //$NON-NLS-1$ } } catch (TransformerException ee) { throw new JspException("error creating pdf output " + ee.getMessage(), ee); //$NON-NLS-1$ } }
From source file:org.displaytag.export.FopExportView.java
/** * If you are authoring a stylesheet locally, this is highly recommended as a way to test your stylesheet against * dummy data.//from w ww. ja v a2 s . c o m * * @param xmlSrc xml as string * @param styleSheetPath the path to the stylesheet * @param f the f * @throws Exception if trouble */ public static void transform(String xmlSrc, String styleSheetPath, File f) throws Exception { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); InputStream styleSheetStream = FopExportView.class.getResourceAsStream(styleSheetPath); Source xslt = new StreamSource(styleSheetStream); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = factory.newTransformer(xslt); } catch (TransformerConfigurationException e) { throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$ } Fop fop; try { FileOutputStream fw = new FileOutputStream(f); fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, fw); } catch (FOPException e) { throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$ } Source src = new StreamSource(new StringReader(xmlSrc)); Result res; try { res = new SAXResult(fop.getDefaultHandler()); } catch (FOPException e) { throw new JspException("error setting up transform ", e); //$NON-NLS-1$ } try { transformer.transform(src, res); } catch (TransformerException e) { throw new JspException("error creating pdf output " + e.getMessage(), e); //$NON-NLS-1$ } }
From source file:org.dspace.app.webui.jsptag.BrowseListTag.java
private String getScalingAttr(HttpServletRequest hrq, Bitstream bitstream) throws JspException { BufferedImage buf;//from w w w .java 2 s .c om try { Context c = UIUtil.obtainContext(hrq); InputStream is = BitstreamStorageManager.retrieve(c, bitstream.getID()); //AuthorizeManager.authorizeAction(bContext, this, Constants.READ); // read in bitstream's image buf = ImageIO.read(is); is.close(); } catch (SQLException sqle) { throw new JspException(sqle.getMessage(), sqle); } catch (IOException ioe) { throw new JspException(ioe.getMessage(), ioe); } // now get the image dimensions float xsize = (float) buf.getWidth(null); float ysize = (float) buf.getHeight(null); // scale by x first if needed if (xsize > (float) thumbItemListMaxWidth) { // calculate scaling factor so that xsize * scale = new size (max) float scaleFactor = (float) thumbItemListMaxWidth / xsize; // now reduce x size and y size xsize = xsize * scaleFactor; ysize = ysize * scaleFactor; } // scale by y if needed if (ysize > (float) thumbItemListMaxHeight) { float scaleFactor = (float) thumbItemListMaxHeight / ysize; // now reduce x size // and y size xsize = xsize * scaleFactor; ysize = ysize * scaleFactor; } StringBuffer sb = new StringBuffer("width=\"").append(xsize).append("\" height=\"").append(ysize) .append("\""); return sb.toString(); }
From source file:org.dspace.app.webui.jsptag.BrowseListTag.java
private String getThumbMarkup(HttpServletRequest hrq, BrowseItem item) throws JspException { try {//from w ww .jav a2s. c o m Context c = UIUtil.obtainContext(hrq); Thumbnail thumbnail = ItemService.getThumbnail(c, item.getID(), linkToBitstream); if (thumbnail == null) { return ""; } StringBuffer thumbFrag = new StringBuffer(); if (linkToBitstream) { Bitstream original = thumbnail.getOriginal(); String link = hrq.getContextPath() + "/bitstream/" + item.getHandle() + "/" + original.getSequenceID() + "/" + UIUtil.encodeBitstreamName(original.getName(), Constants.DEFAULT_ENCODING); thumbFrag.append("<a target=\"_blank\" href=\"" + link + "\" />"); } else { String link = hrq.getContextPath() + "/handle/" + item.getHandle(); thumbFrag.append("<a href=\"" + link + "\" />"); } Bitstream thumb = thumbnail.getThumb(); String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" + UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING); String alt = thumb.getName(); String scAttr = getScalingAttr(hrq, thumb); thumbFrag.append("<img src=\"").append(img).append("\" alt=\"").append(alt).append("\" ").append(scAttr) .append("/ border=\"0\"></a>"); return thumbFrag.toString(); } catch (SQLException sqle) { throw new JspException(sqle.getMessage(), sqle); } catch (UnsupportedEncodingException e) { throw new JspException("Server does not support DSpace's default encoding. ", e); } }
From source file:org.dspace.app.webui.jsptag.ItemListTag.java
private String getScalingAttr(HttpServletRequest hrq, Bitstream bitstream) throws JspException { BufferedImage buf;//from w w w. j ava 2 s . c o m try { Context c = UIUtil.obtainContext(hrq); InputStream is = BitstreamStorageManager.retrieve(c, bitstream.getID()); //AuthorizeManager.authorizeAction(bContext, this, Constants.READ); // read in bitstream's image buf = ImageIO.read(is); is.close(); } catch (SQLException sqle) { throw new JspException(sqle.getMessage(), sqle); } catch (IOException ioe) { throw new JspException(ioe.getMessage(), ioe); } // now get the image dimensions float xsize = (float) buf.getWidth(null); float ysize = (float) buf.getHeight(null); // scale by x first if needed if (xsize > (float) thumbItemListMaxWidth) { // calculate scaling factor so that xsize * scale = new size (max) float scale_factor = (float) thumbItemListMaxWidth / xsize; // now reduce x size and y size xsize = xsize * scale_factor; ysize = ysize * scale_factor; } // scale by y if needed if (ysize > (float) thumbItemListMaxHeight) { float scale_factor = (float) thumbItemListMaxHeight / ysize; // now reduce x size // and y size xsize = xsize * scale_factor; ysize = ysize * scale_factor; } StringBuffer sb = new StringBuffer("width=\"").append(xsize).append("\" height=\"").append(ysize) .append("\""); return sb.toString(); }
From source file:org.dspace.app.webui.jsptag.ItemListTag.java
private String getThumbMarkup(HttpServletRequest hrq, Item item) throws JspException { try {//from w w w .j a v a2s .c om Context c = UIUtil.obtainContext(hrq); Thumbnail thumbnail = ItemService.getThumbnail(c, item.getID(), linkToBitstream); if (thumbnail == null) { return ""; } StringBuffer thumbFrag = new StringBuffer(); if (linkToBitstream) { Bitstream original = thumbnail.getOriginal(); String link = hrq.getContextPath() + "/bitstream/" + item.getHandle() + "/" + original.getSequenceID() + "/" + UIUtil.encodeBitstreamName(original.getName(), Constants.DEFAULT_ENCODING); thumbFrag.append("<a target=\"_blank\" href=\"" + link + "\" />"); } else { String link = hrq.getContextPath() + "/handle/" + item.getHandle(); thumbFrag.append("<a href=\"" + link + "\" />"); } Bitstream thumb = thumbnail.getThumb(); String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" + UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING); String alt = thumb.getName(); String scAttr = getScalingAttr(hrq, thumb); thumbFrag.append("<img src=\"").append(img).append("\" alt=\"").append(alt).append("\" ").append(scAttr) .append("/ border=\"0\"></a>"); return thumbFrag.toString(); } catch (SQLException sqle) { throw new JspException(sqle.getMessage(), sqle); } catch (UnsupportedEncodingException e) { throw new JspException("Server does not support DSpace's default encoding. ", e); } }
From source file:org.eclipse.sw360.portal.tags.OutTag.java
@Override public int doStartTag() throws JspException { if (value instanceof String) { boolean abbreviated = false; String candidate = (String) this.value; String originalValue = candidate; if (maxChar > 4) { candidate = StringUtils.abbreviate(candidate, maxChar); if (!originalValue.equals(candidate)) { abbreviated = true;//from w w w.j a va 2 s. co m } } if (stripNewlines) { candidate = candidate.replaceAll("[\r\n]+", " "); } if ("'".equals(jsQuoting)) { candidate = escapeInSingleQuote(candidate); } else if ("\"".equals(jsQuoting)) { candidate = escapeInDoubleQuote(candidate); } this.value = candidate; if (abbreviated) { try { this.pageContext.getOut().write("<span title=\"" + escapeInDoubleQuote(originalValue) + "\">"); int i = super.doStartTag(); this.pageContext.getOut().write("</span>"); return i; } catch (IOException e) { throw new JspException(e.toString(), e); } } } return super.doStartTag(); }