List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator(QName qName);
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Creates the view.//from w w w. j ava 2 s .c om * @param element the element to build the View from * @param altViewsViewDefName the hashtable to track the AltView's ViewDefName * @return the View * @throws Exception */ protected static ViewIFace createView(final Element element, final Hashtable<AltViewIFace, String> altViewsViewDefName) throws Exception { String name = element.attributeValue(NAME); String objTitle = getAttr(element, "objtitle", null); String className = element.attributeValue(CLASSNAME); String desc = getDesc(element); String businessRules = getAttr(element, "busrules", null); boolean isInternal = getAttr(element, "isinternal", true); DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(className); if (ti != null && StringUtils.isEmpty(objTitle)) { objTitle = ti.getTitle(); } View view = new View(instance.viewSetName, name, objTitle, className, businessRules != null ? businessRules.trim() : null, getAttr(element, "usedefbusrule", true), isInternal, desc); // Later we should get this from a properties file. if (ti != null) { view.setTitle(ti.getTitle()); } /*if (!isInternal) { System.err.println(StringUtils.replace(name, " ", "_")+"="+UIHelper.makeNamePretty(name)); }*/ Element altviews = (Element) element.selectSingleNode("altviews"); if (altviews != null) { AltViewIFace defaultAltView = null; AltView.CreationMode defaultMode = AltView.parseMode(getAttr(altviews, "mode", ""), AltViewIFace.CreationMode.VIEW); String selectorName = altviews.attributeValue("selector"); view.setDefaultMode(defaultMode); view.setSelectorName(selectorName); Hashtable<String, Boolean> nameCheckHash = new Hashtable<String, Boolean>(); // iterate through child elements for (Iterator<?> i = altviews.elementIterator("altview"); i.hasNext();) { Element altElement = (Element) i.next(); AltView.CreationMode mode = AltView.parseMode(getAttr(altElement, "mode", ""), AltViewIFace.CreationMode.VIEW); String altName = altElement.attributeValue(NAME); String viewDefName = altElement.attributeValue("viewdef"); String title = altElement.attributeValue(TITLE); boolean isValidated = getAttr(altElement, "validated", mode == AltViewIFace.CreationMode.EDIT); boolean isDefault = getAttr(altElement, "default", false); // Make sure we only have one default view if (defaultAltView != null && isDefault) { isDefault = false; } // Check to make sure all the AlViews have different names. Boolean nameExists = nameCheckHash.get(altName); if (nameExists == null) // no need to check the boolean { AltView altView = new AltView(view, altName, title, mode, isValidated, isDefault, null); // setting a null viewdef altViewsViewDefName.put(altView, viewDefName); if (StringUtils.isNotEmpty(selectorName)) { altView.setSelectorName(selectorName); String selectorValue = altElement.attributeValue("selector_value"); if (StringUtils.isNotEmpty(selectorValue)) { altView.setSelectorValue(selectorValue); } else { FormDevHelper.appendFormDevError("Selector Value is missing for viewDefName[" + viewDefName + "] altName[" + altName + "]"); } } if (defaultAltView == null && isDefault) { defaultAltView = altView; } view.addAltView(altView); nameCheckHash.put(altName, true); } else { log.error("The altView name[" + altName + "] already exists!"); } nameCheckHash.clear(); // why not? } // No default Alt View was indicated, so choose the first one (if there is one) if (defaultAltView == null && view.getAltViews() != null && view.getAltViews().size() > 0) { view.getAltViews().get(0).setDefault(true); } } return view; }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Fill the Vector with all the views from the DOM document * @param doc the DOM document conforming to form.xsd * @param views the list to be filled/*from w w w . jav a 2 s. c o m*/ * @throws Exception for duplicate view set names or if a Form ID is not unique */ public static String getViews(final Element doc, final Hashtable<String, ViewIFace> views, final Hashtable<AltViewIFace, String> altViewsViewDefName) throws Exception { instance.viewSetName = doc.attributeValue(NAME); /* System.err.println("#################################################"); System.err.println("# "+instance.viewSetName); System.err.println("#################################################"); */ Element viewsElement = (Element) doc.selectSingleNode("views"); if (viewsElement != null) { for (Iterator<?> i = viewsElement.elementIterator("view"); i.hasNext();) { Element element = (Element) i.next(); // assume element is NOT null, if it is null it will cause an exception ViewIFace view = createView(element, altViewsViewDefName); if (view != null) { if (views.get(view.getName()) == null) { views.put(view.getName(), view); } else { String msg = "View Set [" + instance.viewSetName + "] [" + view.getName() + "] is not unique."; log.error(msg); FormDevHelper.appendFormDevError(msg); } } } } return instance.viewSetName; }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Fill the Vector with all the views from the DOM document * @param doc the DOM document conforming to form.xsd * @param viewDefs the list to be filled * @param doMapDefinitions tells it to map and clone the definitions for formtables (use false for the FormEditor) * @return the viewset name// w w w . ja va2s . c o m * @throws Exception for duplicate view set names or if a ViewDef name is not unique */ public static String getViewDefs(final Element doc, final Hashtable<String, ViewDefIFace> viewDefs, @SuppressWarnings("unused") final Hashtable<String, ViewIFace> views, final boolean doMapDefinitions) throws Exception { colDefType = AppPreferences.getLocalPrefs().get("ui.formatting.formtype", UIHelper.getOSTypeAsStr()); instance.viewSetName = doc.attributeValue(NAME); Element viewDefsElement = (Element) doc.selectSingleNode("viewdefs"); if (viewDefsElement != null) { for (Iterator<?> i = viewDefsElement.elementIterator("viewdef"); i.hasNext();) { Element element = (Element) i.next(); // assume element is NOT null, if it is null it will cause an exception ViewDef viewDef = createViewDef(element); if (viewDef != null) { if (viewDefs.get(viewDef.getName()) == null) { viewDefs.put(viewDef.getName(), viewDef); } else { String msg = "View Set [" + instance.viewSetName + "] the View Def Name [" + viewDef.getName() + "] is not unique."; log.error(msg); FormDevHelper.appendFormDevError(msg); } } } if (doMapDefinitions) { mapDefinitionViewDefs(viewDefs); } } return instance.viewSetName; }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Processes all the AltViews//w ww . j a v a 2 s. c om * @param aFormView the form they should be associated with * @param aElement the element to process */ public static Hashtable<String, String> getEnableRules(final Element element) { Hashtable<String, String> rulesList = new Hashtable<String, String>(); if (element != null) { Element enableRules = (Element) element.selectSingleNode("enableRules"); if (enableRules != null) { // iterate through child elements of root with element name "foo" for (Iterator<?> i = enableRules.elementIterator("rule"); i.hasNext();) { Element ruleElement = (Element) i.next(); String id = getAttr(ruleElement, ID, ""); if (isNotEmpty(id)) { rulesList.put(id, ruleElement.getTextTrim()); } else { String msg = "The name is missing for rule[" + ruleElement.getTextTrim() + "] is missing."; log.error(msg); FormDevHelper.appendFormDevError(msg); } } } } else { log.error("View Set [" + instance.viewSetName + "] element [" + element + "] is null."); } return rulesList; }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Processes all the rows//from w ww . j a v a 2 s .c om * @param element the parent DOM element of the rows * @param cellRows the list the rows are to be added to */ protected static void processRows(final Element element, final List<FormRowIFace> cellRows, final DBTableInfo tableinfo) { Element rowsElement = (Element) element.selectSingleNode("rows"); if (rowsElement != null) { byte rowNumber = 0; for (Iterator<?> i = rowsElement.elementIterator("row"); i.hasNext();) { Element rowElement = (Element) i.next(); FormRow formRow = new FormRow(); formRow.setRowNumber(rowNumber); for (Iterator<?> cellIter = rowElement.elementIterator("cell"); cellIter.hasNext();) { Element cellElement = (Element) cellIter.next(); String cellId = getAttr(cellElement, ID, ""); String cellName = getAttr(cellElement, NAME, cellId); // let the name default to the id if it doesn't have a name int colspan = getAttr(cellElement, "colspan", 1); int rowspan = getAttr(cellElement, "rowspan", 1); /*boolean isReq = getAttr(cellElement, ISREQUIRED, false); if (isReq) { System.err.println(String.format("%s\t%s\t%s\t%s", gViewDef.getName(), cellId, cellName, tableinfo != null ? tableinfo.getTitle() : "N/A")); }*/ FormCell.CellType cellType = null; FormCellIFace cell = null; try { cellType = FormCellIFace.CellType.valueOf(cellElement.attributeValue(TYPE)); } catch (java.lang.IllegalArgumentException ex) { FormDevHelper.appendFormDevError(ex.toString()); FormDevHelper.appendFormDevError(String.format("Cell Name[%s] Id[%s] Type[%s]", cellName, cellId, cellElement.attributeValue(TYPE))); return; } if (doFieldVerification && fldVerTableInfo != null && cellType == FormCellIFace.CellType.field && StringUtils.isNotEmpty(cellId) && !cellName.equals("this")) { processFieldVerify(cellName, cellId, rowNumber); } switch (cellType) { case label: { cell = formRow.addCell(new FormCellLabel(cellId, cellName, getLabel(cellElement), getAttr(cellElement, "labelfor", ""), getAttr(cellElement, "icon", null), getAttr(cellElement, "recordobj", false), colspan)); String initialize = getAttr(cellElement, INITIALIZE, null); if (StringUtils.isNotEmpty(initialize)) { cell.setProperties(UIHelper.parseProperties(initialize)); } break; } case separator: { cell = formRow.addCell(new FormCellSeparator(cellId, cellName, getLabel(cellElement), getAttr(cellElement, "collapse", ""), colspan)); String initialize = getAttr(cellElement, INITIALIZE, null); if (StringUtils.isNotEmpty(initialize)) { cell.setProperties(UIHelper.parseProperties(initialize)); } break; } case field: { String uitypeStr = getAttr(cellElement, "uitype", ""); String format = getAttr(cellElement, "format", ""); String formatName = getAttr(cellElement, "formatname", ""); String uiFieldFormatterName = getAttr(cellElement, "uifieldformatter", ""); int cols = getAttr(cellElement, "cols", DEFAULT_COLS); // XXX PREF for default width of text field int rows = getAttr(cellElement, "rows", DEFAULT_ROWS); // XXX PREF for default heightof text area String validationType = getAttr(cellElement, "valtype", "Changed"); String validationRule = getAttr(cellElement, VALIDATION, ""); String initialize = getAttr(cellElement, INITIALIZE, ""); boolean isRequired = getAttr(cellElement, ISREQUIRED, false); String pickListName = getAttr(cellElement, "picklist", ""); if (isNotEmpty(format) && isNotEmpty(formatName)) { String msg = "Both format and formatname cannot both be set! [" + cellName + "] ignoring format"; log.error(msg); FormDevHelper.appendFormDevError(msg); format = ""; } Properties properties = UIHelper.parseProperties(initialize); if (isEmpty(uitypeStr)) { // XXX DEBUG ONLY PLease REMOVE LATER //log.debug("***************************************************************************"); //log.debug("***** Cell Id["+cellId+"] Name["+cellName+"] uitype is empty and should be 'text'. (Please Fix!)"); //log.debug("***************************************************************************"); uitypeStr = "text"; } // THis switch is used to get the "display type" and // set up other vars needed for creating the controls FormCellFieldIFace.FieldType uitype = null; try { uitype = FormCellFieldIFace.FieldType.valueOf(uitypeStr); } catch (java.lang.IllegalArgumentException ex) { FormDevHelper.appendFormDevError(ex.toString()); FormDevHelper.appendFormDevError(String.format( "Cell Name[%s] Id[%s] uitype[%s] is in error", cellName, cellId, uitypeStr)); uitype = FormCellFieldIFace.FieldType.text; // default to text } String dspUITypeStr = null; switch (uitype) { case textarea: dspUITypeStr = getAttr(cellElement, DSPUITYPE, "dsptextarea"); break; case textareabrief: dspUITypeStr = getAttr(cellElement, DSPUITYPE, "textareabrief"); break; case querycbx: { dspUITypeStr = getAttr(cellElement, DSPUITYPE, "textfieldinfo"); String fmtName = TypeSearchForQueryFactory.getInstance() .getDataObjFormatterName(properties.getProperty("name")); if (isEmpty(formatName) && isNotEmpty(fmtName)) { formatName = fmtName; } break; } case formattedtext: { validationRule = getAttr(cellElement, VALIDATION, "formatted"); // XXX Is this OK? dspUITypeStr = getAttr(cellElement, DSPUITYPE, "formattedtext"); //------------------------------------------------------- // This part should be moved to the ViewFactory // because it is the only part that need the Schema Information //------------------------------------------------------- if (isNotEmpty(uiFieldFormatterName)) { UIFieldFormatterIFace uiFormatter = UIFieldFormatterMgr.getInstance() .getFormatter(uiFieldFormatterName); if (uiFormatter == null) { String msg = "Couldn't find formatter[" + uiFieldFormatterName + "]"; log.error(msg); FormDevHelper.appendFormDevError(msg); uiFieldFormatterName = ""; uitype = FormCellFieldIFace.FieldType.text; } } else // ok now check the schema for the UI formatter { if (tableinfo != null) { DBFieldInfo fieldInfo = tableinfo.getFieldByName(cellName); if (fieldInfo != null) { if (fieldInfo.getFormatter() != null) { uiFieldFormatterName = fieldInfo.getFormatter().getName(); } else if (fieldInfo.getDataClass().isAssignableFrom(Date.class) || fieldInfo.getDataClass().isAssignableFrom(Calendar.class)) { String msg = "Missing Date Formatter for [" + cellName + "]"; log.error(msg); FormDevHelper.appendFormDevError(msg); uiFieldFormatterName = "Date"; UIFieldFormatterIFace uiFormatter = UIFieldFormatterMgr.getInstance() .getFormatter(uiFieldFormatterName); if (uiFormatter == null) { uiFieldFormatterName = ""; uitype = FormCellFieldIFace.FieldType.text; } } else { uiFieldFormatterName = ""; uitype = FormCellFieldIFace.FieldType.text; } } } } break; } case url: dspUITypeStr = getAttr(cellElement, DSPUITYPE, uitypeStr); properties = UIHelper.parseProperties(initialize); break; case list: case image: case tristate: case checkbox: case password: dspUITypeStr = getAttr(cellElement, DSPUITYPE, uitypeStr); break; case plugin: case button: dspUITypeStr = getAttr(cellElement, DSPUITYPE, uitypeStr); properties = UIHelper.parseProperties(initialize); String ttl = properties.getProperty(TITLE); if (ttl != null) { properties.put(TITLE, getResourceLabel(ttl)); } break; case spinner: dspUITypeStr = getAttr(cellElement, DSPUITYPE, "dsptextfield"); properties = UIHelper.parseProperties(initialize); break; case combobox: dspUITypeStr = getAttr(cellElement, DSPUITYPE, "textpl"); if (tableinfo != null) { DBFieldInfo fieldInfo = tableinfo.getFieldByName(cellName); if (fieldInfo != null) { if (StringUtils.isNotEmpty(pickListName)) { fieldInfo.setPickListName(pickListName); } else { pickListName = fieldInfo.getPickListName(); } } } break; default: dspUITypeStr = getAttr(cellElement, DSPUITYPE, "dsptextfield"); break; } //switch FormCellFieldIFace.FieldType dspUIType = FormCellFieldIFace.FieldType.valueOf(dspUITypeStr); try { dspUIType = FormCellFieldIFace.FieldType.valueOf(dspUITypeStr); } catch (java.lang.IllegalArgumentException ex) { FormDevHelper.appendFormDevError(ex.toString()); FormDevHelper.appendFormDevError(String.format( "Cell Name[%s] Id[%s] dspuitype[%s] is in error", cellName, cellId, dspUIType)); uitype = FormCellFieldIFace.FieldType.label; // default to text } // check to see see if the validation is a node in the cell if (isEmpty(validationRule)) { Element valNode = (Element) cellElement.selectSingleNode(VALIDATION); if (valNode != null) { String str = valNode.getTextTrim(); if (isNotEmpty(str)) { validationRule = str; } } } boolean isEncrypted = getAttr(cellElement, "isencrypted", false); boolean isReadOnly = uitype == FormCellFieldIFace.FieldType.dsptextfield || uitype == FormCellFieldIFace.FieldType.dsptextarea || uitype == FormCellFieldIFace.FieldType.label; FormCellField field = new FormCellField(FormCellIFace.CellType.field, cellId, cellName, uitype, dspUIType, format, formatName, uiFieldFormatterName, isRequired, cols, rows, colspan, rowspan, validationType, validationRule, isEncrypted); String labelStr = uitype == FormCellFieldIFace.FieldType.checkbox ? getLabel(cellElement) : getAttr(cellElement, "label", ""); field.setLabel(labelStr); field.setReadOnly(getAttr(cellElement, "readonly", isReadOnly)); field.setDefaultValue(getAttr(cellElement, "default", "")); field.setPickListName(pickListName); field.setChangeListenerOnly(getAttr(cellElement, "changesonly", true) && !isRequired); field.setProperties(properties); cell = formRow.addCell(field); break; } case command: { cell = formRow.addCell(new FormCellCommand(cellId, cellName, getLabel(cellElement), getAttr(cellElement, "commandtype", ""), getAttr(cellElement, "action", ""))); String initialize = getAttr(cellElement, INITIALIZE, null); if (StringUtils.isNotEmpty(initialize)) { cell.setProperties(UIHelper.parseProperties(initialize)); } break; } case panel: { FormCellPanel cellPanel = new FormCellPanel(cellId, cellName, getAttr(cellElement, "paneltype", ""), getAttr(cellElement, "coldef", "p"), getAttr(cellElement, "rowdef", "p"), colspan, rowspan); String initialize = getAttr(cellElement, INITIALIZE, null); if (StringUtils.isNotEmpty(initialize)) { cellPanel.setProperties(UIHelper.parseProperties(initialize)); } processRows(cellElement, cellPanel.getRows(), tableinfo); fixLabels(cellPanel.getName(), cellPanel.getRows(), tableinfo); cell = formRow.addCell(cellPanel); break; } case subview: { Properties properties = UIHelper.parseProperties(getAttr(cellElement, INITIALIZE, null)); String svViewSetName = cellElement.attributeValue("viewsetname"); if (isEmpty(svViewSetName)) { svViewSetName = null; } if (instance.doingResourceLabels && properties != null) { String title = properties.getProperty(TITLE); if (title != null) { properties.setProperty(TITLE, UIRegistry.getResourceString(title)); } } String viewName = getAttr(cellElement, "viewname", null); cell = formRow.addCell(new FormCellSubView(cellId, cellName, svViewSetName, viewName, cellElement.attributeValue("class"), getAttr(cellElement, "desc", ""), getAttr(cellElement, "defaulttype", null), getAttr(cellElement, "rows", DEFAULT_SUBVIEW_ROWS), colspan, rowspan, getAttr(cellElement, "single", false))); cell.setProperties(properties); break; } case iconview: { String vsName = cellElement.attributeValue("viewsetname"); if (isEmpty(vsName)) { vsName = instance.viewSetName; } String viewName = getAttr(cellElement, "viewname", null); cell = formRow.addCell(new FormCellSubView(cellId, cellName, vsName, viewName, cellElement.attributeValue("class"), getAttr(cellElement, "desc", ""), colspan, rowspan)); break; } case statusbar: { cell = formRow.addCell( new FormCell(FormCellIFace.CellType.statusbar, cellId, cellName, colspan, rowspan)); break; } default: { // what is this? log.error("Encountered unknown cell type"); continue; } } // switch cell.setIgnoreSetGet(getAttr(cellElement, "ignore", false)); } cellRows.add(formRow); rowNumber++; } } }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * Creates a Table Form View/*from ww w .j a v a2 s . c o m*/ * @param typeName the type of form to be built * @param element the DOM element for building the form * @param name the name of the form * @param className the class name of the data object * @param gettableClassName the class name of the getter * @param settableClassName the class name of the setter * @param desc the description * @param useResourceLabels whether to use resource labels * @return a form view of type "table" */ protected static TableViewDefIFace createTableView(final Element element, final String name, final String className, final String gettableClassName, final String settableClassName, final String desc, final boolean useResourceLabels) { TableViewDefIFace tableView = new TableViewDef(name, className, gettableClassName, settableClassName, desc, useResourceLabels); //tableView.setResourceLabels(resLabels); Element columns = (Element) element.selectSingleNode("columns"); if (columns != null) { for (Iterator<?> i = columns.elementIterator("column"); i.hasNext();) { Element colElement = (Element) i.next(); FormColumn column = new FormColumn(colElement.attributeValue(NAME), colElement.attributeValue(LABEL), getAttr(colElement, "dataobjformatter", null), getAttr(colElement, "format", null)); tableView.addColumn(column); } } return tableView; }
From source file:edu.ku.brc.af.ui.forms.ViewSetMgr.java
License:Open Source License
/** * Reads the Form Registry. The forms are loaded when needed and onlu one ViewSet can be the "core" ViewSet which is where most of the forms * reside. This could also be thought of as the "default" set of forms. * //from w w w . jav a 2 s.com * @param contextDir the directory in which load the view sets */ protected void init(final Element rootDOM) { if (rootDOM != null) { for (Iterator<?> i = rootDOM.elementIterator("file"); i.hasNext();) { Element fileElement = (Element) i.next(); String fName = getAttr(fileElement, "name", null); if (!isViewSetNameInUse(fName)) { String typeStr = getAttr(fileElement, "type", "system"); String title = getAttr(fileElement, "title", null); String fileName = getAttr(fileElement, "file", null); // these can go away once we validate the XML if (StringUtils.isEmpty(typeStr)) { FormDevHelper.appendFormDevError("ViewSet type cannot be null!"); return; } if (StringUtils.isEmpty(title)) { FormDevHelper.appendFormDevError("ViewSet title cannot be null!"); return; } if (StringUtils.isEmpty(fileName)) { FormDevHelper.appendFormDevError("ViewSet file cannot be null!"); return; } // else File viewSetFile = new File(contextDir.getAbsoluteFile() + File.separator + fileName); if (!viewSetFile.exists()) { FormDevHelper.appendFormDevError( "ViewSet file cannot be found at[" + viewSetFile.getAbsolutePath() + "]"); return; } ViewSet viewSet = new ViewSet(ViewSet.parseType(typeStr), fName, title, fileName, contextDir); viewsHash.put(viewSet.getName(), viewSet); } else { String msg = "ViewSet Name[" + fName + "] is in use."; log.error(msg); FormDevHelper.appendFormDevError(msg); } } } else { String msg = "The root element for the document was null!"; log.error(msg); FormDevHelper.appendFormDevError(msg); } }
From source file:edu.ku.brc.dbsupport.DatabaseDriverInfo.java
License:Open Source License
/** * Reads the Form Registry. The forms are loaded when needed and onlu one ViewSet can be the "core" ViewSet which is where most of the forms * reside. This could also be thought of as the "default" set of forms. * @return the list of info objects/* w w w. j a v a 2 s. c om*/ */ protected static Vector<DatabaseDriverInfo> loadDatabaseDriverInfo() { Vector<DatabaseDriverInfo> dbDrivers = new Vector<DatabaseDriverInfo>(); try { Element root = XMLHelper .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("dbdrivers.xml"))); //$NON-NLS-1$ if (root != null) { Hashtable<String, String> hash = new Hashtable<String, String>(); for (Iterator<?> i = root.elementIterator("db"); i.hasNext();) //$NON-NLS-1$ { Element dbElement = (Element) i.next(); String name = getAttr(dbElement, "name", null); //$NON-NLS-1$ if (hash.get(name) == null) { hash.put(name, name); String driver = getAttr(dbElement, "driver", null); //$NON-NLS-1$ String dialect = getAttr(dbElement, "dialect", null); //$NON-NLS-1$ String port = getAttr(dbElement, "port", null); //$NON-NLS-1$ boolean isEmbedded = getAttr(dbElement, "embedded", false); //$NON-NLS-1$ if (UIRegistry.isEmbedded() || UIRegistry.isMobile()) // Application is Embedded { if (!isEmbedded) { continue; } } else if (isEmbedded) { continue; } // these can go away once we validate the XML if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Driver cannot be null!"); //$NON-NLS-1$ } if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Dialect cannot be null!"); //$NON-NLS-1$ } DatabaseDriverInfo drv = new DatabaseDriverInfo(name, driver, dialect, isEmbedded, port); // Load up the Connection Types for (Iterator<?> connIter = dbElement.elementIterator("connection"); connIter.hasNext();) //$NON-NLS-1$ { Element connElement = (Element) connIter.next(); String typeStr = getAttr(connElement, "type", null); //$NON-NLS-1$ String connFormat = connElement.getTextTrim(); ConnectionType type = ConnectionType.valueOf(StringUtils.capitalize(typeStr)); drv.addFormat(type, connFormat); } /*if (drv.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, " ", " ", " ", " ", " ") == null) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ { log.error("Meg might've screwed up generating connection strings, contact her if you get this error"); //$NON-NLS-1$ throw new RuntimeException("Dialect ["+name+"] has no 'Open' connection type!"); //$NON-NLS-1$ //$NON-NLS-2$ }*/ dbDrivers.add(drv); } else { log.error("Database Driver Name[" + name + "] is in use."); //$NON-NLS-1$ //$NON-NLS-2$ } } } else { String msg = "The root element for the document was null!"; //$NON-NLS-1$ log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatabaseDriverInfo.class, ex); ex.printStackTrace(); log.error(ex); } Collections.sort(dbDrivers); return dbDrivers; }
From source file:edu.ku.brc.specify.config.DisciplineType.java
License:Open Source License
/** * Reads in the disciplines file (is loaded when the class is loaded). *//*from w w w . ja v a 2s . co m*/ protected static Vector<DisciplineType> loadDisciplineList() { Vector<DisciplineType> list = new Vector<DisciplineType>(); try { Element root = XMLHelper .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("disciplines.xml"))); if (root != null) { for (Iterator<?> i = root.elementIterator("discipline"); i.hasNext();) { Element disciplineNode = (Element) i.next(); String name = getAttr(disciplineNode, "name", null); String title = getAttr(disciplineNode, "title", null); String abbrev = getAttr(disciplineNode, "abbrev", ""); String folder = getAttr(disciplineNode, "folder", name); int type = getAttr(disciplineNode, "type", 0); boolean isEmbedCE = getAttr(disciplineNode, "isembedce", true); DisciplineType disciplineType = new DisciplineType(name, title, abbrev, folder, type, isEmbedCE); list.add(disciplineType); } } else { String msg = "The root element for the document was null!"; log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { ex.printStackTrace(); //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DisciplineType.class, ex); //log.error(ex); } Collections.sort(list); return list; }
From source file:edu.ku.brc.specify.config.UserGroupType.java
License:Open Source License
/** * Reads in the user types file (is loaded when the class is loaded). *//* ww w. j a v a2 s .co m*/ protected static Vector<UserGroupType> loadUserTypeList() { Vector<UserGroupType> list = new Vector<UserGroupType>(); try { Element root = XMLHelper .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("usertypes.xml"))); if (root != null) { for (Iterator<?> i = root.elementIterator("UserType"); i.hasNext();) { Element disciplineNode = (Element) i.next(); String name = getAttr(disciplineNode, "name", null); UserGroupType UserType = new UserGroupType(name); list.add(UserType); } } else { String msg = "The root element for the document was null!"; log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UserGroupType.class, ex); ex.printStackTrace(); log.error(ex); } Collections.sort(list); return list; }