Search in sources :

Example 11 with TableTagParseException

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

the class TableTagParser method parser.

public Table parser(String file) throws TableTagParseException {
    Table table = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        SchemaFactory schfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schfactory.setErrorHandler(null);
        Schema schema = schfactory.newSchema(new StreamSource(MifosResourceUtil.getClassPathResourceAsURIString(FilePaths.CUSTOMTABLETAGXSD)));
        factory.setNamespaceAware(false);
        factory.setValidating(false);
        factory.setSchema(schema);
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsURIString(file));
        table = createTable(document);
    } catch (Exception e) {
        throw new TableTagParseException(e);
    }
    return table;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException)

Example 12 with TableTagParseException

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

the class TableTagParser method createTable.

protected Table createTable(Document document) throws TableTagParseException {
    NodeList tableNode = document.getChildNodes();
    if (tableNode.getLength() == 0) {
        throw new TableTagParseException(tableNode.toString());
    }
    Table table = new Table();
    table.setHeaderDetails(createHeaderDetails(tableNode.item(0)));
    table.setRow(createRow(tableNode.item(0)));
    return table;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList)

Example 13 with TableTagParseException

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

the class TableTagParser method createColumnDetails.

protected ColumnDetails createColumnDetails(Node column) throws TableTagParseException {
    NodeList columnDetailsNodeList = ((Element) column).getElementsByTagName(TableTagConstants.COLUMNDETAILS);
    if (columnDetailsNodeList.getLength() == 0) {
        throw new TableTagParseException(columnDetailsNodeList.toString());
    }
    ColumnDetails columnDetails = new ColumnDetails();
    columnDetails.setRowStyle(columnDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ROWSTYLE).getNodeValue());
    columnDetails.setColWidth(columnDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.COLWIDTH).getNodeValue());
    columnDetails.setAlign(columnDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ALIGN).getNodeValue());
    return columnDetails;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 14 with TableTagParseException

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

the class TableTagParser method createRow.

protected Row[] createRow(Node table) throws TableTagParseException {
    NodeList rowNodeList = ((Element) table).getElementsByTagName(TableTagConstants.ROW);
    if (rowNodeList.getLength() == 0) {
        throw new TableTagParseException(rowNodeList.toString());
    }
    Row[] row = new Row[rowNodeList.getLength()];
    for (int i = 0; i < rowNodeList.getLength(); i++) {
        row[i] = new Row();
        row[i].setColumn(createColumn(rowNodeList.item(i)));
        row[i].setTdrequired((rowNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.TDREQUIRED).getNodeValue()));
        row[i].setSuppressrow((rowNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.SUPRESSROW).getNodeValue()));
    }
    return row;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 15 with TableTagParseException

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

the class TableTagParser method createColumn.

protected Column[] createColumn(Node row) throws TableTagParseException {
    NodeList columnNodeList = ((Element) row).getElementsByTagName(TableTagConstants.COLUMN);
    if (columnNodeList.getLength() == 0) {
        throw new TableTagParseException(TableTagConstants.UNEXPECTED_ERROR);
    }
    Column[] column = new Column[columnNodeList.getLength()];
    for (int i = 0; i < columnNodeList.getLength(); i++) {
        column[i] = new Column();
        setColumnAttributes(column[i], columnNodeList.item(i).getAttributes());
        column[i].setDisplayname(createDisplayName(columnNodeList.item(i)));
        column[i].setParameters(createParameters(columnNodeList.item(i)));
        if ("link".equals(column[i].getType())) {
            if (null == column[i].getAction()) {
                throw new TableTagParseException(TableTagConstants.UNEXPECTED_ERROR);
            }
        }
    }
    return column;
}
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