Search in sources :

Example 1 with TableTagParseException

use of org.mifos.framework.exceptions.TableTagParseException 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 TableTagParseException

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

the class TableTagParser method parser.

public Table parser(String filename) throws TableTagParseException {
    Table table = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "tabletag.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsURIString(filename));
        /*
             * NodeList tableNodeList =
             * document.getElementsByTagName(TableTagConstants.TABLE); table =
             * new Table[tableNodeList.getLength()];
             *
             * for (int i = 0; i < table.length; i++) { table[i] = new Table();
             * table[i].setRow(createRow(tableNodeList.item(i))); }
             */
        Node tableNode = document.getFirstChild();
        table = new Table();
        table.setPath(createPath(tableNode));
        table.setPageRequirements(createPageRequirements(tableNode));
        table.setRow(createRow(tableNode));
    } catch (Exception e) {
        throw new TableTagParseException(e);
    }
    return table;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException)

Example 3 with TableTagParseException

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

the class TableTagParser method createPath.

protected Path[] createPath(Node table) throws TableTagParseException {
    NodeList pathNodeList = ((Element) table).getElementsByTagName(TableTagConstants.PATH);
    if (pathNodeList.getLength() == 0) {
        throw new TableTagParseException(TableTagConstants.UNEXPECTED_ERROR);
    }
    Path[] path = new Path[pathNodeList.getLength()];
    for (int i = 0; i < pathNodeList.getLength(); i++) {
        path[i] = new Path();
        path[i].setKey((pathNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.KEY).getNodeValue()));
        path[i].setAction((pathNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.PATHACTION).getNodeValue()));
        path[i].setForwardkey((pathNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.FORWARDKEY).getNodeValue()));
    }
    return path;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 4 with TableTagParseException

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

the class TableTag method doStartTag.

@SuppressWarnings("unchecked")
@Override
public int doStartTag() throws JspException {
    try {
        table = TableTagParser.getInstance().parser(moduleName + "/" + xmlFileName);
        Column[] column = table.getRow().getColumn();
        for (int i = 0; i < column.length; ++i) {
            if (column[i].getLinkDetails() != null) {
                if (randomNUm == null || currentFlowKey == null) {
                    column[i] = null;
                    if (i < column.length - 1) {
                        int j = i;
                        for (; j < column.length - 1; ++j) {
                            column[j] = column[j + 1];
                        }
                    }
                    column = Arrays.copyOf(column, column.length - 1);
                    table.getRow().setColumn(column);
                } else {
                    LinkDetails linkDetails = column[i].getLinkDetails();
                    for (ActionParam param : linkDetails.getActionParam()) {
                        if (param.getValueType().equalsIgnoreCase(TableTagConstants.INBUILD)) {
                            if (param.getName().equalsIgnoreCase("randomNUm")) {
                                param.setValue(randomNUm);
                            } else if (param.getName().equalsIgnoreCase("currentFlowKey")) {
                                param.setValue(currentFlowKey);
                            } else if (param.getName().equalsIgnoreCase("accountId")) {
                                param.setValue(accountId);
                            } else if (param.getName().equalsIgnoreCase("globalAccountNum")) {
                                param.setValue(globalAccountNum);
                            }
                        }
                    }
                }
            }
        }
        tableInfo = new StringBuilder();
        if (source == null || scope == null) {
            throw new JspException();
        }
        List obj = null;
        if (scope.equalsIgnoreCase("session")) {
            obj = (List) pageContext.getSession().getAttribute(source);
        } else if (scope.equalsIgnoreCase("request")) {
            obj = (List) pageContext.getRequest().getAttribute(source);
        }
        if (obj == null) {
            try {
                obj = (List) SessionUtils.getAttribute(source, (HttpServletRequest) pageContext.getRequest());
            } catch (PageExpiredException e) {
            }
        }
        if (obj == null || obj.isEmpty()) {
            return super.doStartTag();
        }
        if (passLocale != null && passLocale.equalsIgnoreCase("true")) {
            UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
            populateLocale(userContext);
        }
        table.getTable(source, tableInfo, obj, locale, mfiLocale, pageContext, getResourcebundleName(), glMode);
    } catch (TableTagParseException ex) {
        throw new JspException(ex);
    }
    try {
        pageContext.getOut().print(tableInfo.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }
    return super.doStartTag();
}
Also used : JspException(javax.servlet.jsp.JspException) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) UserContext(org.mifos.security.util.UserContext) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) List(java.util.List) IOException(java.io.IOException)

Example 5 with TableTagParseException

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

the class TableTagParser method createHeaderDetails.

protected HeaderDetails createHeaderDetails(Node table) throws TableTagParseException {
    NodeList headerNodeList = ((Element) table).getElementsByTagName(TableTagConstants.HEADERDETAILS);
    if (headerNodeList.getLength() == 0) {
        throw new TableTagParseException(headerNodeList.toString());
    }
    HeaderDetails headerDetails = new HeaderDetails();
    headerDetails.setHeaderStyle(headerNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.HEADERSTYLE).getNodeValue());
    return headerDetails;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Aggregations

TableTagParseException (org.mifos.framework.exceptions.TableTagParseException)15 NodeList (org.w3c.dom.NodeList)10 Element (org.w3c.dom.Element)9 IOException (java.io.IOException)2 List (java.util.List)2 JspException (javax.servlet.jsp.JspException)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)2 Document (org.w3c.dom.Document)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspWriter (javax.servlet.jsp.JspWriter)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1