Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

In this page you can find the example usage for org.dom4j Element getTextTrim.

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatterMgr.java

License:Open Source License

/**
 * @param formatElement//  ww w. ja v a2 s.  c om
 * @param name
 * @param dataClassName
 * @param fieldName
 * @param isSingleField
 * @return
 */
protected AutoNumberIFace createAutoNum(final Element formatElement, final String name,
        final String dataClassName, final String fieldName, final boolean isSingleField) {
    AutoNumberIFace autoNumberObj = null;
    Element autoNumberElement = (Element) formatElement.selectSingleNode("autonumber");
    if (autoNumberElement != null) {
        String autoNumberClassName = autoNumberElement.getTextTrim();
        if (StringUtils.isNotEmpty(autoNumberClassName) && StringUtils.isNotEmpty(dataClassName)
                && StringUtils.isNotEmpty(fieldName)) {
            autoNumberObj = createAutoNumber(autoNumberClassName, dataClassName, fieldName, isSingleField);

        } else {
            throw new RuntimeException("The class cannot be empty for an external formatter! [" + name
                    + "] or missing field name [" + fieldName + "] or missing data Class name [" + dataClassName
                    + "]");
        }
    }
    return autoNumberObj;
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatterMgr.java

License:Open Source License

/**
 * Creates a single UIFieldFormatter from a DOM Element.
 * @param formatElement the element/* w  ww . j av a  2  s  . com*/
 * @return the formatter object
 */
public UIFieldFormatterIFace createFormatterFromXML(final Element formatElement) {
    UIFieldFormatterIFace formatter = null;

    String name = formatElement.attributeValue("name");
    String fType = formatElement.attributeValue("type");
    String fieldName = XMLHelper.getAttr(formatElement, "fieldname", "*");
    String dataClassName = formatElement.attributeValue("class");
    int precision = XMLHelper.getAttr(formatElement, "precision", 12);
    int scale = XMLHelper.getAttr(formatElement, "scale", 2);
    String length = XMLHelper.getAttr(formatElement, "length", null);
    boolean isDefault = XMLHelper.getAttr(formatElement, "default", false);
    boolean isSystem = XMLHelper.getAttr(formatElement, "system", false);

    Element external = (Element) formatElement.selectSingleNode("external");
    if (external != null) {
        String externalClassName = external.getTextTrim();
        if (StringUtils.isNotEmpty(externalClassName)) {
            try {
                formatter = Class.forName(externalClassName).asSubclass(UIFieldFormatterIFace.class)
                        .newInstance();
                formatter.setName(name);
                formatter.setAutoNumber(createAutoNum(formatElement, name, dataClassName, fieldName,
                        formatter.getFields().size() == 1));
                formatter.setDefault(isDefault);
                if (length != null) {
                    formatter.setLength(Integer.valueOf(length));
                }
                hash.put(name, formatter);

            } catch (Exception ex) {
                log.error(ex);
                ex.printStackTrace();
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UIFieldFormatterMgr.class, ex);
            }
        } else {
            throw new RuntimeException("The value cannot be empty for an external formatter! [" + name + "]");
        }
    }

    List<?> fieldsList = formatElement.selectNodes("field");
    Vector<UIFieldFormatterField> fields = new Vector<UIFieldFormatterField>();
    boolean isInc = false;
    String partialDateTypeStr = formatElement.attributeValue("partialdate");
    for (Object fldObj : fieldsList) {
        Element fldElement = (Element) fldObj;

        int size = XMLHelper.getAttr(fldElement, "size", 1);
        String value = fldElement.attributeValue("value");
        String typeStr = fldElement.attributeValue("type");
        boolean increm = XMLHelper.getAttr(fldElement, "inc", false);
        boolean byYear = false;

        UIFieldFormatterField.FieldType type = null;
        try {
            type = UIFieldFormatterField.FieldType.valueOf(typeStr);

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UIFieldFormatterMgr.class, ex);
            log.error("[" + typeStr + "]" + ex.toString());
        }

        if (type == UIFieldFormatterField.FieldType.year) {
            size = 4;
            byYear = XMLHelper.getAttr(fldElement, "byyear", false);
        }

        fields.add(new UIFieldFormatterField(type, size, value, increm, byYear));
        if (increm) {
            isInc = true;
        }
    }

    // set field type
    UIFieldFormatter.FormatterType type = UIFieldFormatter.FormatterType.generic;
    UIFieldFormatter.PartialDateEnum partialDateType = UIFieldFormatter.PartialDateEnum.None;
    if (StringUtils.isNotEmpty(fType) && fType.equals("numeric")) {
        type = UIFieldFormatter.FormatterType.numeric;

    } else if (StringUtils.isNotEmpty(fType) && fType.equals("date")) {
        type = UIFieldFormatter.FormatterType.date;
        if (StringUtils.isNotEmpty(partialDateTypeStr)) {
            partialDateType = UIFieldFormatter.PartialDateEnum.valueOf(partialDateTypeStr);
        } else {
            partialDateType = UIFieldFormatter.PartialDateEnum.Full;
        }
    }

    Class<?> dataClass = null;
    if (StringUtils.isNotEmpty(dataClassName)) {
        try {
            dataClass = Class.forName(dataClassName);
        } catch (Exception ex) {
            log.error("Couldn't load class [" + dataClassName + "] for [" + name + "]");
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UIFieldFormatterMgr.class, ex);
        }

    } else if (StringUtils.isNotEmpty(fType) && fType.equals("date")) {
        dataClass = Date.class;
    }

    if (formatter == null) {
        formatter = new UIFieldFormatter(name, isSystem, fieldName, type, partialDateType, dataClass, isDefault,
                isInc, fields);
        hash.put(name, formatter);
    } else {
        formatter.setPartialDateType(partialDateType);
    }

    if (formatter instanceof UIFieldFormatter) {
        UIFieldFormatter fmt = (UIFieldFormatter) formatter;
        fmt.setType(type);

        if (type == UIFieldFormatter.FormatterType.date && fields.size() == 0) {
            addFieldsForDate(fmt);

        } else if (type == UIFieldFormatter.FormatterType.numeric && fields.size() == 0) {
            fmt.setPrecision(precision);
            fmt.setScale(scale);
            addFieldsForNumeric(fmt);
        }
    }

    formatter.setAutoNumber(
            createAutoNum(formatElement, name, dataClassName, fieldName, formatter.getFields().size() == 1));

    return formatter;
}

From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java

License:Open Source License

/**
 * Gets the optional description text// ww  w . ja v a  2s  .  c  o  m
 * @param element the parent element of the desc node
 * @return the string of the text or null
 */
protected static String getDesc(final Element element) {
    String desc = null;
    Element descElement = (Element) element.selectSingleNode(DESC);
    if (descElement != null) {
        desc = descElement.getTextTrim();
    }
    return desc;
}

From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java

License:Open Source License

/**
 * Processes all the AltViews//from  w ww  .j  a v  a  2s  . c o m
 * @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  .ja  va2s . 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.validation.TypeSearchForQueryFactory.java

License:Open Source License

/**
 * Loads the formats from the config file.
 *
 *//*from   w w  w  .j  av a  2 s .co m*/
public void load() {
    if (hash.size() == 0) {
        try {
            Element root = getDOM();
            if (root != null) {
                List<?> typeSearches = root.selectNodes("/typesearches/typesearch");
                for (Object fObj : typeSearches) {
                    Element tsElement = (Element) fObj;
                    String name = tsElement.attributeValue("name");
                    if (StringUtils.isNotBlank(name)) {
                        TypeSearchInfo tsi = new TypeSearchInfo(XMLHelper.getAttr(tsElement, "tableid", -1),
                                name, tsElement.attributeValue("displaycols"),
                                tsElement.attributeValue("searchfield"),
                                XMLHelper.getAttr(tsElement, "format", null),
                                XMLHelper.getAttr(tsElement, "uifieldformatter", null),
                                XMLHelper.getAttr(tsElement, "dataobjformatter", null),
                                XMLHelper.getAttr(tsElement, "system", true));
                        hash.put(name, tsi);

                        String sqlTemplate = tsElement.getTextTrim();
                        if (StringUtils.isNotEmpty(sqlTemplate)) {
                            tsi.setSqlTemplate(sqlTemplate);
                        }
                    } else {
                        log.error("TypeSearchInfo element is missing or has a blank name!");
                    }
                }
            } else {
                log.debug("Couldn't open typesearch_def.xml");
            }
        } catch (Exception ex) {
            log.error(ex);
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TypeSearchForQueryFactory.class, ex);
            ex.printStackTrace();
        }
    }
}

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/*from ww w .j  ava2s .c  o m*/
 */
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.helpers.XMLHelper.java

License:Open Source License

/**
 * Get the value of the XML element with the given name that is a child of the given element.
 * // w w  w . ja  v a 2s.  c o  m
 * @param element the parent XML element
 * @param name the name of the child element to get the value for
 * @return the data the child element's value
 */
public static String getValue(final Element element, final String name) {
    Element node = (Element) element.selectSingleNode(name);
    if (node != null) {
        String data = node.getTextTrim();
        int inx = data.indexOf("("); //$NON-NLS-1$
        if (inx != -1) {
            int einx = data.indexOf(")"); //$NON-NLS-1$
            return data.substring(inx + 1, einx);
        }
        return data;
    }

    // else
    // Although the name may not have been found it could be because no results came back
    log.debug("****** [" + name + "] was not found."); //$NON-NLS-1$ //$NON-NLS-2$
    return ""; //$NON-NLS-1$
}

From source file:edu.ku.brc.specify.datamodel.SpQuery.java

License:Open Source License

/**
 * @param element/*from   w ww  . j ava  2  s  .c  o  m*/
 */
public void fromXML(final Element element) {
    name = getAttr(element, "name", null);
    contextName = getAttr(element, "contextName", null);
    contextTableId = getAttr(element, "contextTableId", (short) 0);
    isFavorite = getAttr(element, "isFavorite", false);
    named = getAttr(element, "named", false);
    ordinal = getAttr(element, "ordinal", (short) 0);
    smushed = getAttr(element, "smushed", false);
    searchSynonymy = getAttr(element, "searchSynonymy", false);
    selectDistinct = getAttr(element, "selectDistinct", false);
    countOnly = getAttr(element, "countOnly", false);

    Element sqlNode = (Element) element.selectSingleNode("sqlStr");
    sqlStr = sqlNode != null ? sqlNode.getTextTrim() : null;

    for (Object obj : element.selectNodes("fields/field")) {
        Element fieldEl = (Element) obj;
        SpQueryField field = new SpQueryField();
        field.initialize();
        field.fromXML(fieldEl);
        field.setQuery(this);
        fields.add(field);
    }

    Element mapping = (Element) element.selectSingleNode("spexportschemamapping");
    if (mapping != null) {
        SpExportSchemaMapping esm = new SpExportSchemaMapping();
        esm.initialize();
        esm.fromXML(mapping, this);
    }
}

From source file:edu.ku.brc.specify.extras.FishBaseInfoGetter.java

License:Open Source License

public void run() {
    if (type == InfoType.Summary) {
        urlStr = "http://www.fishbase.org.ph/webservice/Species/SpeciesSummary.asp?Genus=" + genus + "&Species="
                + species;//from www .  j a  v  a 2 s.c  o  m
        getDOMDoc(urlStr, type);

    } else if (type == InfoType.Thumbnail || type == InfoType.Image) {
        urlStr = "http://www.fishbase.org/webservice/Photos/FishPicsList.php?Genus=" + genus + "&Species="
                + species;
        getDOMDoc(urlStr, InfoType.PictureList);

        if (status == ErrorCode.NoError) {
            Element speciesElement = (Element) dom.selectSingleNode("/fishbase/species");
            if (speciesElement != null) {
                int numPictures = XMLHelper.getAttr(speciesElement, "total_adult", 0);
                if (numPictures > 0) {
                    List<?> adults = dom.selectNodes("/fishbase/pictures[@type='adult']");
                    for (Iterator<?> iter = adults.iterator(); iter.hasNext();) {
                        Element pictureElement = (Element) iter.next();
                        Element nameElement = (Element) pictureElement
                                .selectSingleNode(type == InfoType.Thumbnail ? "thumbnail" : "actual");
                        if (nameElement != null) {
                            String fileURL = nameElement.getTextTrim();
                            //System.out.println(fileURL);
                            if (StringUtils.isNotEmpty(fileURL)) {
                                String shortName = "";
                                int inx = fileURL.lastIndexOf("/");
                                if (inx > -1) {
                                    shortName = fileURL.substring(inx + 1, fileURL.length());
                                }
                                //System.out.println("*["+shortName+"]["+fileURL+"]");
                                image = getImage(shortName, fileURL);
                                if (image != null) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

        }
    }

    if (consumer != null) {
        if (status == ErrorCode.NoError) {
            consumer.infoArrived(this);

        } else {
            consumer.infoGetWasInError(this);
        }
    }
    stop();
}