Example usage for javax.servlet.jsp JspException JspException

List of usage examples for javax.servlet.jsp JspException JspException

Introduction

In this page you can find the example usage for javax.servlet.jsp JspException JspException.

Prototype

public JspException(Throwable cause) 

Source Link

Document

Constructs a new JspException with the specified cause.

Usage

From source file:com.ultrapower.eoms.common.plugin.ecside.tag.ColumnsTag.java

    @Override
   public int doEndTag() throws JspException {
        try {/*from  www . ja v  a  2 s.  co m*/
            TableModel model = TagUtils.getModel(this);

            if (!TagUtils.isIteratingBody(this)) {
                if (StringUtils.isNotBlank(titles)){
                   String[] titlesA=(" "+titles+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_TITLES_KEY,titlesA);
                }
                
                if (StringUtils.isNotBlank(widths)){
                   String[] cellWidthsA=(" "+widths+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_WIDTHS_KEY,cellWidthsA);
                }
                
                if (StringUtils.isNotBlank(cellValues)){
                   String[] cellValuesA=(" "+cellValues+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_CELL_VALUES_KEY,cellValuesA);
                }
                
//                if (StringUtils.isNotBlank(cellNames)){
//                   String[] cellNamesA=(" "+cellNames+" ").split(",");
//                    model.getTable().setAttribute(ECSideConstants.TABLE_CELLNAMES_KEY,cellNamesA);
//                }
                
                if (StringUtils.isNotBlank(editEvents)){
                   String[] cellEventsA=(" "+editEvents+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_EDIT_EVENTS_KEY,cellEventsA);

                }

                if (StringUtils.isNotBlank(editTemplates)){
                   String[] cellTemplatesA=(" "+editTemplates+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_EDIT_TEMPLATES_KEY,cellTemplatesA);

                }
                if (StringUtils.isNotBlank(editables)){
                   String[] cellEditablesA=(" "+editables+" ").split(",");
                    model.getTable().setAttribute(ECSideConstants.TABLE_EDITABLES_KEY,cellEditablesA);

                }
                
                
                
               String autoGenerateColumns = TagUtils.evaluateExpressionAsString("autoGenerateColumns", this.autoGenerateColumns, this, pageContext);
                if (StringUtils.isBlank(autoGenerateColumns)){
                   
                   autoGenerateColumns=TableConstants.DEFAULT_AUTOGENERATECOLUMNS;
                }
               
               model.addColumns(autoGenerateColumns);


            } else {
                model.setColumnValues();
            }

            
        } catch (Exception e) {
           LogHandler.errorLog(logger, e);
            throw new JspException("ColumnsTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
        }finally{
           
        }
        return EVAL_PAGE;
    }

From source file:org.openmrs.module.htmlwidgets.web.taglib.WidgetTag.java

/**
 * @see TagSupport#doStartTag()//  w  ww  .jav a  2s.  c  o m
 */
@Override
public int doStartTag() throws JspException {

    // TODO: Figure out why this is necessary.
    Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance());

    // Retrieve the type, depending on either an object/property combination or a class type
    Class<?> fieldType = null;
    Type[] genericFieldTypes = null;
    Object propertyValue = null;

    if (getObject() != null && getProperty() != null) {

        Field f = ReflectionUtil.getField(getObject().getClass(), getProperty());
        fieldType = ReflectionUtil.getFieldType(f);
        genericFieldTypes = ReflectionUtil.getGenericTypes(f);
        propertyValue = ReflectionUtil.getPropertyValue(object, property);

        if (fieldType == null) {
            throw new IllegalArgumentException(
                    "Property <" + property + "> is invalid for object <" + object + ">");
        }
        if (getType() != null && getType() != fieldType.getName()) {
            throw new IllegalArgumentException(
                    "The specified type is not compatible with the specified property.");
        }
    } else if (getType() != null) {
        try {
            fieldType = Context.loadClass(getType());
            if (StringUtils.hasText(getGenericTypes())) {
                List<Type> genericTypeList = new ArrayList<Type>();
                for (String s : getGenericTypes().split(",")) {
                    genericTypeList.add(Context.loadClass(s));
                }
                genericFieldTypes = genericTypeList.toArray(new Type[genericTypeList.size()]);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("The type <" + getType() + "> is not a valid type.", e);
        }
    } else {
        throw new IllegalArgumentException("You must specify an object/property or type attribute.");
    }

    // Ensure that we have an appropriate Handler
    WidgetHandler handler = HandlerUtil.getPreferredHandler(WidgetHandler.class, fieldType);
    if (handler == null) {
        throw new JspException("No Preferred Handler found for: " + type);
    }

    // Setup Widget Configuration
    WidgetConfig config = new WidgetConfig();
    config.setPageContext(pageContext);
    config.setId(getId());
    config.setName(getName());
    config.setType(fieldType);
    config.setGenericTypes(genericFieldTypes);
    config.setFormat(getFormat());

    Object defaultValue = propertyValue;
    if (defaultValue == null) {
        defaultValue = getDefaultValue();
        try {
            if (defaultValue != null && defaultValue instanceof String) {
                defaultValue = handler.parse((String) defaultValue, fieldType);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException(
                    "The default value of " + defaultValue + " is not valid for handler " + handler.getClass(),
                    e);
        }
    }
    config.setDefaultValue(defaultValue);

    config.setFixedAttribute("id", getId());
    config.setFixedAttribute("name", getName());
    if (getAttributes() != null) {
        Map<String, String> attMap = OpenmrsUtil.parseParameterList(getAttributes());
        for (String attName : attMap.keySet()) {
            config.setConfiguredAttribute(attName, attMap.get(attName));
        }
    }

    // Run the Handler with this Configuration 
    try {
        handler.render(config, pageContext.getOut());
    } catch (Exception e) {
        log.warn("Error handling Widget: " + type, e);
        throw new JspException("Error handling Widget: " + type, e);
    }

    resetValues();
    return SKIP_BODY;
}

From source file:org.shredzone.cilla.web.tag.FormatTag.java

@Override
public int doEndTag() throws JspException {
    CharSequence result;//from  ww w  .  j a  va2  s.c  o  m
    TextFormat txtFormat;

    if (text != null && text instanceof FormattedText) {
        if (format != null) {
            throw new IllegalArgumentException("text contains FormattedText, format must not be set");
        }
        result = ((FormattedText) text).getText();
        txtFormat = ((FormattedText) text).getFormat();
    } else {
        if (format != null && format instanceof TextFormat) {
            txtFormat = (TextFormat) format;
        } else if (format != null) {
            txtFormat = TextFormat.valueOf(format.toString());
        } else if (text == null) {
            // if no text and no format was set, render the body as HTML
            txtFormat = TextFormat.HTML;
        } else {
            throw new IllegalArgumentException("format not set");
        }

        if (text != null) {
            result = text.toString();
        } else if (bodyContent != null) {
            result = bodyContent.toString().trim();
        } else {
            result = "";
        }
    }

    if (result == null)
        result = "";

    result = textFormatter.format(result, txtFormat, () -> linkService.linkTo().page(page));

    if (stripHtml) {
        result = textFormatter.stripHtml(result);
    }

    if (truncate != null && result.length() > truncate) {
        StringBuilder trunc = new StringBuilder(result);
        int truncpos = trunc.lastIndexOf(" ", truncate);
        if (truncpos < truncate - 30) {
            truncpos = truncate;
        }
        trunc.setLength(truncpos);
        trunc.append("\u2026");
        result = trunc;
    }

    if (var != null) {
        TagUtils.setScopedAttribute(pageContext, var, result, scope);

    } else {
        try {
            pageContext.getOut().print(result);
        } catch (IOException ex) {
            throw new JspException(ex);
        }
    }

    return EVAL_PAGE;
}

From source file:net.jcreate.e3.table.html.tag.ColumnTag.java

public int doEndTag() throws JspException {
    TableTag tableTag = getTableTag();//from   w w w. j  a v a2 s . c  om
    if (tableTag == null) {
        throw new JspException("column  table?");
    }
    boolean isCreatedTable = tableTag.isCreatedTable();
    if (isCreatedTable == false) {//
        return super.doEndTag();
    }

    boolean isCreatedHeader = tableTag.isCreatedHeader();
    if (isCreatedHeader == false) {
        //column
        HTMLColumn column = (HTMLColumn) tableTag.getTable().getColumn(this.property);
        column.setTitle(this.title);
        column.setWidth(this.width);
        column.setHidden(this.hidden);
        column.setAlign(this.align);
        column.setSortable(this.sortable == null ? getDefaultSortable() : this.sortable.booleanValue());
        column.setTitleKey(this.titleKey);
        column.setStyle(this.style);
        column.setStyleClass(this.styleClass);
        column.setHeaderStyle(headerStyle);
        SortInfo sortInfo = tableTag.getSortInfo();
        if (sortInfo != null) {//??
            String sortColumn = sortInfo.getSortProperty();
            if (this.property.equals(sortColumn)) {//??
                column.setSortDir(sortInfo.getSortDir());//??
            }
        }
        column.setSortName(this.sortName);
        ColumnGroupTag groupTag = (ColumnGroupTag) findAncestorWithClass(this, ColumnGroupTag.class);
        if (groupTag != null) {//
            groupTag.addColumn(column);
        }
        /**
         * @todo:column
         */
        return super.doEndTag();
    }

    BodyContent content = this.bodyContent;
    if (content != null) {
        String bodyContext = content.getString();//?body?
        /**
         * @fixme: bodyContent???bodyContent.
         * ???"",.
         * 
         */
        if ("".equals(bodyContext) == false) {
            //??,body context??.?body content.
            //jsp2.0?
            if (((CompositeCellDecorator) currCell.getCellDecorator()).getSize() == 0) {
                JspDecorator jsp = new JspDecorator();
                jsp.setJsp(bodyContext);
                content.clearBody();
                this.addCellDecorator(jsp);
            }
        }
        super.setBodyContent(null);//tomcat5.028?,nulll               
    }

    cleanUp();
    return super.doEndTag();
}

From source file:com.xhsoft.framework.common.page.WebappPageTag.java

/**
 * <p>Description: build up goto text area and print</p>
 * @param request   //  w w w. j ava 2  s.  c  o  m
 * @param pageNo 
 * @param totalPages 
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
@SuppressWarnings("unused")
private void buildGoto(HttpServletRequest request, int pageNo, int totalPages) throws JspException {
    try {
        JspWriter out = pageContext.getOut();
        if (StringUtils.isEmpty(pageSizeList)) {
            pageSizeList = INIT_PAGE_SIZE_LIST;
        }
        String[] pageSizes = pageSizeList.split(",");
        String rand = UUID.randomUUID().toString();
        String outString = "<input name=\"gotoText" + rand + "\" type=\"text\"  size=\"5\"  value=\"" + pageNo
                + "\" onkeydown=\"return gotoPage(this.value,'" + pageNo + "','" + totalPages + "','" + targets
                + "');\">"
                + "<input type=\"button\" name=\"go\" value=\"GO\" class=\"button2\" onclick=\"return gotoPageDirect(dojo.byId('gotoText"
                + rand + "').value,'" + pageNo + "','" + totalPages + "','" + targets + "');\">";
        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }
}

From source file:net.sf.ginp.tags.NavFilmStrip.java

/**
 *  called when the start tag is processed.
 *
 *@return                   Description of the Return Value
 *@exception  JspException  Description of the Exception
 *//*from   w  w  w.j a  v a 2 s .  c o  m*/
public final int doStartTag() throws JspException {
    try {
        model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
    } catch (Exception e) {
        log.error(e);
        throw new JspException(e);
    }

    if (model.getCollection() != null) {
        count = 0;

        int columbs = (model.getPageWidth() - boderhorizontal)
                / (Configuration.getFilmStripThumbSize() + boderpicture);

        String[] picNames = model.getCollection().getPictures();
        String currPic = ((HttpServletRequest) pageContext.getRequest()).getParameter("name");

        for (int i = 0; i < picNames.length; i++) {
            if (picNames[i].equals(currPic)) {
                count = i - (columbs / 2) + 1;

                if (count < 0) {
                    count = 0;
                }
            }
        }

        end = count + columbs;

        // Limit end to less than array lendth.
        if (end > picNames.length) {
            count = picNames.length - columbs;
            end = picNames.length;

            if (count < 0) {
                count = 0;
            }
        }

        if (end > count) {
            // get the position of the reqested name and set start at. Loop
            // until end of pictures getting count++ until cols reached.
            collAbsPath = model.getCollection().getRoot() + model.getCollection().getPath();

            pageContext.setAttribute("maxsize", "" + Configuration.getFilmStripThumbSize());

            pic = new Picture(collAbsPath, model.getCollection().getPicture(count));

            // Set Picture Attributes
            pageContext.setAttribute("filename", pic.getFileName());
            pageContext.setAttribute("date", pic.getDate(dateformatpattern, model.getLocale()));
            pageContext.setAttribute("time", pic.getTime());
            pageContext.setAttribute("number", "" + (count + 1));
            pageContext.setAttribute("title", pic.getTitle());
            pageContext.setAttribute("description", pic.getDescription(model.getLocale()));

            pageContext.setAttribute("link",
                    "ginpservlet?cmd=showpicture&colid=" + model.getCurrCollectionId() + "&path="
                            + model.getCollection().getPath() + "&name="
                            + model.getCollection().getPicture(count));
            pageContext.setAttribute("src",
                    ((HttpServletRequest) pageContext.getRequest()).getContextPath() + "/ginppic?name="
                            + model.getCollection().getPicture(count) + "&maxsize="
                            + Configuration.getFilmStripThumbSize());

            return EVAL_BODY_INCLUDE;
        } else {
            return SKIP_BODY;
        }
    } else {
        return SKIP_BODY;
    }
}

From source file:com.trailmagic.image.ui.ImageTag.java

public int doStartTag() throws JspException {
    StringBuffer html = new StringBuffer();
    ImageManifestation mf;/*from w w w .j a v  a  2  s.c om*/

    try {
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
        // XXX: maybe this should be a parameter of the tag instead?

        // XXX: this is sort of a kludge for setting a default label
        String defaultLabel = req.getParameter(DEFAULT_LABEL_ATTR);
        HttpSession session = req.getSession();
        if (defaultLabel != null) {
            session.setAttribute(DEFAULT_LABEL_ATTR, defaultLabel);
        }

        // XXX: end kludge

        String size = req.getParameter(SIZE_ATTR);
        String originalp = req.getParameter("original");
        if (size != null) {
            mf = WebSupport.getMFBySize(m_image, Integer.parseInt(size), Boolean.parseBoolean(originalp));
        } else {
            // get label by precedence: req param, tag spec, sess attr
            String label = req.getParameter(LABEL_ATTR);
            if (label == null) {
                label = m_sizeLabel;
            }
            if (label == null) {
                label = (String) session.getAttribute(DEFAULT_LABEL_ATTR);
            }
            if (label != null) {
                mf = WebSupport.getMFByLabel(m_image, label);
            } else {
                mf = WebSupport.getDefaultMF((User) pageContext.findAttribute(USER_ATTR), m_image);
            }
        }

        if (mf != null) {
            // XXX: resume kludge
            pageContext.setAttribute("currentLabel", getLabel(mf));
            // XXX: end kludge
            // XXX: end kludge
            html.append("<img src=\"");

            //XXX: yeek?
            /*
            LinkHelper helper =
            new LinkHelper((HttpServletRequest)pageContext.getRequest());
            */
            WebApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(pageContext.getServletContext());
            LinkHelper helper = (LinkHelper) ctx.getBean("linkHelper");

            html.append(helper.getImageMFUrl((HttpServletRequest) pageContext.getRequest(), mf));
            html.append("\" height=\"");
            html.append(mf.getHeight());
            html.append("\" width=\"");
            html.append(mf.getWidth());
            html.append("\" alt=\"");
            if (m_alt != null) {
                html.append(m_alt);
            } else if (m_image.getCaption() != null) {
                html.append(Util.escapeXml(m_image.getCaption()));
            } else {
                html.append(Util.escapeXml(m_image.getDisplayName()));
            }

            html.append("\" class=\"");
            if (mf.getWidth() > mf.getHeight()) {
                html.append("landscape");
            } else {
                html.append("portrait");
            }
            if (m_cssClass != null) {
                html.append(" ");
                html.append(m_cssClass);
            }

            html.append("\"/>");
        } else {
            html.append("No manifestations found for the specified " + "image.");
        }
        pageContext.getOut().write(html.toString());
        return SKIP_BODY;
    } catch (IOException e) {
        throw new JspException(e);
    }
}

From source file:net.sf.ginp.tags.TreeMenu.java

/**
 *  Called when a Start tag is processed.
 *
 *@return                   Description of the Return Value
 *@exception  JspException  Description of the Exception
 *///from  ww w .j a  va2s. co m
public final int doStartTag() throws JspException {
    try {
        model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
    } catch (Exception e) {
        log.error(e);
        throw new JspException(e);
    }

    // get Currest collection root
    grid = new Vector();

    if (model.getCollections().length > 0) {
        selectedFolder = model.getCollection().getPath();
        currentPath = selectedFolder;
        gotMoreNodes = false;

        if (shownodes && selectedFolder.equals("/") && (ModelUtil.getFolderManager()
                .getPicturesInDirectoryLength(model.getCollection(), selectedFolder) > 0)) {
            gotMoreNodes = true;
        }

        doFolders(ModelUtil.getFolderManager().getFoldersInDirectory(model.getCollection(), "/"));

        if (gotMoreNodes) {
            doNodes("/");
        }
    }

    return SKIP_BODY;
}

From source file:de.laures.cewolf.taglib.tags.ChartMapTag.java

public int doEndTag() throws JspException {
    // print out image map end
    Writer out = pageContext.getOut();
    try {/*  w w  w .ja va  2 s.c o  m*/
        out.write("</MAP>");
    } catch (IOException ioex) {
        log.error(ioex);
        throw new JspException(ioex.getMessage());
    }
    return doAfterEndTag(EVAL_PAGE);
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.OptionsTag.java

/**
 * Process the end of this tag.//w w w  . j  a va2s  .  com
 * 
 * @exception JspException
 *                if a JSP exception has occurred
 */
@Override
public int doEndTag() throws JspException {

    // Acquire the select tag we are associated with
    SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
    if (selectTag == null) {
        throw new JspException(messages.getMessage("optionsTag.select"));
    }
    StringBuilder sb = new StringBuilder();

    // If a collection was specified, use that mode to render options
    if (collection != null) {
        Iterator collIterator = getIterator(collection, null);
        while (collIterator.hasNext()) {

            Object bean = collIterator.next();
            Object value = null;
            Object label = null;

            try {
                value = PropertyUtils.getProperty(bean, property);
                if (value == null) {
                    value = "";
                }
            } catch (IllegalAccessException e) {
                throw new JspException(messages.getMessage("getter.access", property, collection));
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
                throw new JspException(messages.getMessage("getter.result", property, t.toString()));
            } catch (NoSuchMethodException e) {
                throw new JspException(messages.getMessage("getter.method", property, collection));
            }

            try {
                if (labelProperty != null) {
                    label = PropertyUtils.getProperty(bean, labelProperty);
                } else {
                    label = value;
                }
                if (label == null) {
                    label = "";
                }
            } catch (IllegalAccessException e) {
                throw new JspException(messages.getMessage("getter.access", labelProperty, collection));
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
                throw new JspException(messages.getMessage("getter.result", labelProperty, t.toString()));
            } catch (NoSuchMethodException e) {
                throw new JspException(messages.getMessage("getter.method", labelProperty, collection));
            }

            String stringValue = value.toString();
            addOption(sb, stringValue, label.toString(), selectTag.isMatched(stringValue));

        }

    }

    // Otherwise, use the separate iterators mode to render options
    else {

        // Construct iterators for the values and labels collections
        Iterator valuesIterator = getIterator(name, property);
        Iterator labelsIterator = null;
        if ((labelName == null) && (labelProperty == null)) {
            labelsIterator = getIterator(name, property); // Same coll.
        } else {
            labelsIterator = getIterator(labelName, labelProperty);
        }

        // Render the options tags for each element of the values coll.
        while (valuesIterator.hasNext()) {
            String value = valuesIterator.next().toString();
            String label = value;
            if (labelsIterator.hasNext()) {
                label = labelsIterator.next().toString();
            }
            addOption(sb, value, label, selectTag.isMatched(value));
        }
    }

    // Render this element to our writer
    ResponseUtils.write(pageContext, sb.toString());

    // Evaluate the remainder of this page
    return EVAL_PAGE;

}