Search in sources :

Example 1 with TableTagException

use of org.mifos.framework.exceptions.TableTagException in project head by mifos.

the class TableTag method doStartTag.

/**
     * Function to render the tag
     */
@Override
public int doStartTag() throws JspException {
    // call the helper method to display the result.
    try {
        // Value of the list which we are getting from the Cache
        List list = getList();
        if (list == null) {
            return super.doStartTag();
        }
        if (list.size() == 0) {
            JspWriter out = pageContext.getOut();
            XmlBuilder result;
            result = noResults((String) SessionUtils.getAttribute(Constants.OFFICE_NAME, (HttpServletRequest) pageContext.getRequest()), (String) SessionUtils.getAttribute(Constants.BRANCH_ID, (HttpServletRequest) pageContext.getRequest()), (String) SessionUtils.getAttribute(Constants.SEARCH_STRING, (HttpServletRequest) pageContext.getRequest()));
            out.write(result.getOutput());
            return super.doStartTag();
        }
        getTableData(list);
    } catch (TableTagException tte) {
        throw new JspException(tte);
    } catch (TableTagParseException ttpe) {
        throw new JspException(ttpe);
    } catch (TableTagTypeParserException tttpe) {
        throw new JspException(tttpe);
    } catch (IOException ioe) {
        throw new JspException(ioe);
    } catch (HibernateSearchException hse) {
        throw new JspException(hse);
    } catch (PageExpiredException e) {
        throw new JspException(e);
    }
    return super.doStartTag();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TableTagException(org.mifos.framework.exceptions.TableTagException) JspException(javax.servlet.jsp.JspException) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) XmlBuilder(org.mifos.framework.struts.tags.XmlBuilder) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) TableTagTypeParserException(org.mifos.framework.exceptions.TableTagTypeParserException)

Example 2 with TableTagException

use of org.mifos.framework.exceptions.TableTagException in project head by mifos.

the class Text method getNonLocalizedFileLookupDatabase.

private static Properties getNonLocalizedFileLookupDatabase() throws TableTagException {
    Properties resource = null;
    if (null == nonLocalizedFileLookupDatabase) {
        ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
        resource = new Properties();
        try {
            resource.load(fileLookupDatabase.getInputStream());
        } catch (IOException e) {
            throw new TableTagException(e);
        }
    }
    return resource;
}
Also used : TableTagException(org.mifos.framework.exceptions.TableTagException) IOException(java.io.IOException) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 3 with TableTagException

use of org.mifos.framework.exceptions.TableTagException in project head by mifos.

the class TableTag method getTableData.

private void getTableData(List list) throws TableTagException, TableTagParseException, JspException, TableTagTypeParserException, IOException, PageExpiredException {
    Locale locale = getLocale();
    String currentPage = ((HttpServletRequest) pageContext.getRequest()).getParameter("current");
    Integer currentValue = null;
    if (currentPage != null && !currentPage.equals("")) {
        currentValue = Integer.valueOf(currentPage);
    } else {
        currentValue = 1;
    }
    if (type.equalsIgnoreCase("single")) {
        getSingleData(list, locale, currentValue);
    } else if (type.equalsIgnoreCase("multiple")) {
        getMultipleData(list, locale, currentValue);
    } else {
        throw new TableTagException(MessageLookup.getLocalizedMessage(TableTagConstants.WRONGTYPE_ERROR));
    }
}
Also used : Locale(java.util.Locale) HttpServletRequest(javax.servlet.http.HttpServletRequest) TableTagException(org.mifos.framework.exceptions.TableTagException)

Example 4 with TableTagException

use of org.mifos.framework.exceptions.TableTagException in project head by mifos.

the class Parameters method getParameters.

/**
     * Function to get the parameters.
     *
     * @param obj
     * @return string string array of parameters.
     * @throws TableTagException
     */
public String[] getParameters(PageContext pageContext, Param[] param, Object obj, Locale locale) throws TableTagException {
    // Used to store the value of label if it is a string
    String[] stringArray = new String[param.length];
    // Used to store the value of label if it is a collection
    Collection paramCollection = null;
    // Used to store the value of parameter
    String[] paramString = null;
    for (int i = 0; i < param.length; i++) {
        Object object = TableTagUtils.getInstance().helper(pageContext, param[i].getParameterValue(), param[i].getParameterValueType(), obj, locale);
        if (object instanceof Collection) {
            // Used to store the value of collection if object is a
            // collection
            paramCollection = (Collection) object;
            // Used to store the value of string if object is a string
            stringArray[i] = null;
        } else // if object is a string only then store the value of string in
        // a string array.
        // also check whether the string is empty or not.
        // if the string is empty then store null.
        {
            String stringObject = null;
            if (object != null) {
                stringObject = object.toString();
            }
            if (stringObject != null && !(stringObject.trim().equals("")) && !(stringObject.trim().equalsIgnoreCase("null"))) {
                stringArray[i] = stringObject;
            } else {
                stringArray[i] = null;
            }
        }
    }
    if (paramCollection != null) {
        paramString = new String[paramCollection.size()];
        Iterator it = paramCollection.iterator();
        for (int k = 0; it.hasNext(); k++) {
            StringBuilder stringbuilder = new StringBuilder();
            String collValue = (String) it.next();
            if (collValue != null && !(collValue.trim().equals("")) && !(collValue.trim().equalsIgnoreCase("null"))) {
                for (int i = 0; i < param.length; i++) {
                    try {
                        stringbuilder.append(param[i].getParameterName()).append("=").append(URLEncoder.encode((stringArray[i] == null ? collValue : stringArray[i]), "UTF-8")).append((i == (param.length - 1)) ? "" : "&");
                    } catch (UnsupportedEncodingException uee) {
                        throw new TableTagException(uee);
                    }
                }
                paramString[k] = stringbuilder.toString();
            } else {
                paramString[k] = null;
            }
        }
    } else {
        paramString = new String[1];
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < stringArray.length; i++) {
            try {
                str.append(param[i].getParameterName()).append("=").append(URLEncoder.encode((stringArray[i] != null ? stringArray[i] : ""), "UTF-8")).append((i == (param.length - 1)) ? "" : "&");
            } catch (UnsupportedEncodingException uee) {
                throw new TableTagException(uee);
            }
        }
        paramString[0] = str.toString();
    }
    return paramString;
}
Also used : TableTagException(org.mifos.framework.exceptions.TableTagException) Iterator(java.util.Iterator) Collection(java.util.Collection) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with TableTagException

use of org.mifos.framework.exceptions.TableTagException in project head by mifos.

the class TableTagUtils method helper.

/**
     * Function to get the label.
     *
     * @param label
     *            label to be displayed.
     * @param labelType
     *            label type of the label.
     * @param obj
     * @return string return the label
     * @throws TableTagException
     */
public Object helper(PageContext pageContext, String label, String labelType, Object obj, Locale locale) throws TableTagException {
    /** variable to hold the getlist method */
    Method getList = null;
    /** variable to hold the value of the label */
    Object labelValue = null;
    /**
         * if label type is key then we are picking the label from resource
         * bundle. if label type is a string then we are taking it as it is. if
         * label type is a method then we are calling the get method on that
         * using reflection.
         */
    if ("key".equalsIgnoreCase(labelType)) {
        try {
            labelValue = LabelTagUtils.getInstance().getLabel(pageContext, "Resources", LabelTagUtils.getInstance().getUserPreferredLocale(), label, null);
        } catch (MissingResourceException mre) {
            throw new TableTagException(mre);
        } catch (JspException je) {
            throw new TableTagException(je);
        }
    } else if ("string".equalsIgnoreCase(labelType)) {
        labelValue = label;
    } else if ("method".equalsIgnoreCase(labelType)) {
        String c = label.substring(0, 1);
        try {
            getList = obj.getClass().getDeclaredMethod("get" + c.toUpperCase() + label.substring(1), (Class[]) null);
            labelValue = getList.invoke(obj, (Object[]) null);
        } catch (SecurityException se) {
            throw new TableTagException(se);
        } catch (NoSuchMethodException nsme) {
            throw new TableTagException(nsme);
        } catch (IllegalArgumentException iae) {
            throw new TableTagException(iae);
        } catch (IllegalAccessException iae) {
            throw new TableTagException(iae);
        } catch (InvocationTargetException ite) {
            throw new TableTagException(ite);
        }
    } else if ("date".equalsIgnoreCase(labelType)) {
        String c = label.substring(0, 1);
        try {
            getList = obj.getClass().getDeclaredMethod("get" + c.toUpperCase() + label.substring(1), (Class[]) null);
            labelValue = getList.invoke(obj, (Object[]) null);
            if (null != labelValue) {
                labelValue = DateUtils.getUserLocaleDate(locale, labelValue.toString());
            }
        } catch (SecurityException se) {
            throw new TableTagException(se);
        } catch (NoSuchMethodException nsme) {
            throw new TableTagException(nsme);
        } catch (IllegalArgumentException iae) {
            throw new TableTagException(iae);
        } catch (IllegalAccessException iae) {
            throw new TableTagException(iae);
        } catch (InvocationTargetException ite) {
            throw new TableTagException(ite);
        }
    } else if ("parameter".equalsIgnoreCase(labelType)) {
        labelValue = pageContext.getRequest().getParameter(label);
    }
    return labelValue;
}
Also used : TableTagException(org.mifos.framework.exceptions.TableTagException) JspException(javax.servlet.jsp.JspException) MissingResourceException(java.util.MissingResourceException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TableTagException (org.mifos.framework.exceptions.TableTagException)7 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Locale (java.util.Locale)2 Properties (java.util.Properties)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 JspWriter (javax.servlet.jsp.JspWriter)1 Test (org.junit.Test)1 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 TableTagParseException (org.mifos.framework.exceptions.TableTagParseException)1 TableTagTypeParserException (org.mifos.framework.exceptions.TableTagTypeParserException)1