use of org.w3c.dom.Element in project head by mifos.
the class TableTagParser method createActionParams.
protected ActionParam[] createActionParams(Node linkDetail) throws TableTagParseException {
NodeList actionParamNodeList = ((Element) linkDetail).getElementsByTagName(TableTagConstants.ACTIONPARAM);
if (actionParamNodeList.getLength() == 0) {
throw new TableTagParseException(actionParamNodeList.toString());
}
ActionParam[] actionParam = new ActionParam[actionParamNodeList.getLength()];
for (int i = 0; i < actionParamNodeList.getLength(); i++) {
actionParam[i] = new ActionParam();
actionParam[i].setName(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.NAME).getNodeValue());
actionParam[i].setValueType(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.VALUETYPE).getNodeValue());
if (!actionParam[i].getValueType().equalsIgnoreCase(TableTagConstants.INBUILD)) {
actionParam[i].setValue(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.VALUE).getNodeValue());
}
}
return actionParam;
}
use of org.w3c.dom.Element 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(columnNodeList.toString());
}
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].setColumnDetials(createColumnDetails(columnNodeList.item(i)));
if (TableTagConstants.LINK.equalsIgnoreCase(column[i].getColumnType())) {
column[i].setLinkDetails(createLinkDetails(columnNodeList.item(i)));
}
}
return column;
}
use of org.w3c.dom.Element in project head by mifos.
the class TableTagParser method createLinkDetails.
protected LinkDetails createLinkDetails(Node column) throws TableTagParseException {
NodeList linkDetailsNodeList = ((Element) column).getElementsByTagName(TableTagConstants.LINKDETAILS);
if (linkDetailsNodeList.getLength() == 0) {
throw new TableTagParseException(linkDetailsNodeList.toString());
}
LinkDetails linkDetails = new LinkDetails();
if (linkDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ACTION).getNodeValue() == null) {
throw new TableTagParseException(linkDetailsNodeList.toString());
}
linkDetails.setAction(linkDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ACTION).getNodeValue());
linkDetails.setActionParam(createActionParams(linkDetailsNodeList.item(0)));
return linkDetails;
}
use of org.w3c.dom.Element in project head by mifos.
the class MenuParser method createMenuItems.
/**
* Method to build crude MenuItem objects for a MenuGroup
*
* @param menuGroup
* is the root node for MenuGroup.
* @return array of MenuItem objects
*/
static MenuItem[] createMenuItems(Node menuGroup) throws SystemException {
NodeList menuItemNodeList = ((Element) menuGroup).getElementsByTagName(MenuConstants.MENUITEM);
MenuItem[] menuItem = new MenuItem[menuItemNodeList.getLength()];
int hiddenItems = 0;
for (int i = 0, j = 0; i < menuItemNodeList.getLength(); i++) {
if (isMenuItemVisible((Element) menuItemNodeList.item(i))) {
menuItem[j] = new MenuItem();
menuItem[j].setDisplayName(getDisplayName((Element) menuItemNodeList.item(i)));
menuItem[j].setLinkValue(getLinkValue((Element) menuItemNodeList.item(i)));
j++;
} else {
hiddenItems++;
}
}
if (hiddenItems > 0) {
menuItem = removeEmptyMenuItems(menuItem, hiddenItems);
}
return menuItem;
}
use of org.w3c.dom.Element in project head by mifos.
the class StateXMLParser method loadMapFromXml.
public Map<StateEntity, List<StateEntity>> loadMapFromXml(String filename, String configurationName) {
Map<StateEntity, List<StateEntity>> transitionMap = new HashMap<StateEntity, List<StateEntity>>();
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", "StateMachine.xsd");
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
Node mapToprocess = null;
/*
* String configurationName = ""; if
* (stateConfiguration=="configuration1") configurationName = "1";
* else configurationName = "2";
*/
NodeList configMaps = document.getElementsByTagName("stateConfiguration");
for (int m = 0; m < configMaps.getLength(); m++) {
Node stateConfiguration = configMaps.item(m);
if (configurationName.equals(stateConfiguration.getAttributes().getNamedItem("configurationName").getNodeValue())) {
mapToprocess = stateConfiguration;
}
}
// NodeList stateList = firstChild.getChildNodes();
NodeList stateList = mapToprocess.getChildNodes();
for (int i = 0; i < stateList.getLength(); i++) {
// each state has state id and possiblestates as childern
Node state = stateList.item(i);
// iterate for each child of state
NodeList stateInfoList = state.getChildNodes();
StateEntity currentState = null;
List<StateEntity> currntPossibleStates = new ArrayList<StateEntity>();
for (int j = 0; j < stateInfoList.getLength(); j++) {
Node info = stateInfoList.item(j);
if ("stateid".equals(info.getLocalName())) {
Element ele = (Element) info;
currentState = new StateEntity(Short.valueOf(((Text) ele.getFirstChild()).getData()));
}
if ("possiblestates".equals(info.getLocalName())) {
// get all the childern
NodeList allStates = info.getChildNodes();
currntPossibleStates = new ArrayList<StateEntity>();
for (int k = 0; k < allStates.getLength(); k++) {
Node infoState = allStates.item(k);
NodeList eachPossiblechild = infoState.getChildNodes();
for (int l = 0; l < eachPossiblechild.getLength(); l++) {
Node eachPossiblechildelement = eachPossiblechild.item(l);
if ("stateid".equals(eachPossiblechildelement.getLocalName())) {
Element element = (Element) eachPossiblechildelement;
Short possibleTrantionId = Short.valueOf(((Text) element.getFirstChild()).getData());
currntPossibleStates.add(new StateEntity(possibleTrantionId));
}
}
}
}
}
if (currentState != null) {
transitionMap.put(currentState, currntPossibleStates);
}
}
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SAXParseException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
}
return transitionMap;
}
Aggregations