List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:de.tud.kom.p2psim.impl.scenario.DOMScenarioFactory.java
License:Open Source License
public void parse(Element elem, Configurator config) { // create the scenario wright now. ExtendedScenario scenario = newScenario(); // List<OperationBasedScenarioAction> actions = new // LinkedList<OperationBasedScenarioAction>(); try {/*from ww w.ja va2 s . c om*/ int actionCounter = 0; for (Iterator it = elem.elementIterator(Configurator.ACTION_TAG); it.hasNext();) { Element actionElem = (Element) it.next(); String hostId = actionElem.attributeValue("hostID"); String time = actionElem.attributeValue("time"); String line = actionElem.getTextTrim(); String[] tokens = line.split(paramsDelimiter); assert tokens.length >= 1 : Arrays.asList(tokens); String method = tokens[0]; String[] params = new String[tokens.length - 1]; System.arraycopy(tokens, 1, params, 0, params.length); scenario.createActions(hostId, time, method, params); actionCounter++; } log.debug("Created " + actionCounter + " actions"); } catch (Exception e) { throw new ConfigurationException("Failed to parse DOM element " + elem.asXML() + " reason: ", e); } }
From source file:de.xwic.sandbox.server.installer.XmlImport.java
License:Apache License
/** * @param root//from w ww.j a v a 2s . com */ private void importConfig(Element root) { IPicklisteDAO dao = (IPicklisteDAO) DAOSystem.getDAO(IPicklisteDAO.class); for (Iterator<?> it = root.elementIterator("key"); it.hasNext();) { Element element = (Element) it.next(); String id = element.attributeValue("id"); Element elValue = element.element("value"); Element elPl = element.element("picklistentry"); if (elValue != null) { ServerConfig.set(id, elValue.getTextTrim()); } else if (elPl != null) { String list = elPl.attributeValue("list"); String lang = elPl.attributeValue("lang"); String text = elPl.getTextTrim(); if (list != null && lang != null && text != null) { IPickliste pListe = dao.getPicklisteByKey(list); if (pListe != null) { PicklistTextQuery tquery = new PicklistTextQuery(); tquery.setLanguageId(lang); tquery.setBezeichnung(text); tquery.setPicklisteID(pListe.getId()); List<?> result = dao.getEntities(null, tquery); if (result.isEmpty()) { log.info("WARNING: Picklistentry not found specified for " + id); log.info("Creating entry '" + text + "'"); IPicklistEntry entry = dao.createPickListEntry(pListe); for (Iterator<?> itLang = ConfigurationManager.getSetup().getLanguages() .iterator(); itLang.hasNext();) { Language language = (Language) itLang.next(); dao.createBezeichnung(entry, language.getId(), text); } ServerConfig.set(id, entry.getId()); } else { IPicklistText pText = (IPicklistText) result.get(0); ServerConfig.set(id, pText.getPicklistEntry().getId()); if (result.size() > 1) { log.info("WARNING: Found more then one picklistentries that match for ID " + id); } } } } } } }
From source file:de.xwic.sandbox.server.installer.XmlImport.java
License:Apache License
/** * @param root/*from w w w. j a v a 2s .com*/ */ private void importPicklists(Element data) { IPicklisteDAO dao = (IPicklisteDAO) DAOSystem.getDAO(IPicklisteDAO.class); for (Iterator<?> it = data.elementIterator(); it.hasNext();) { Element elPl = (Element) it.next(); if (elPl.getName().equals("pickliste")) { String key = elPl.attributeValue("key"); IPickliste pickliste = (IPickliste) dao.createEntity(); pickliste.setKey(key); Element elBeschr = elPl.element("beschreibung"); if (elBeschr != null) { pickliste.setBeschreibung(elBeschr.getTextTrim()); } Element elTitle = elPl.element("title"); if (elTitle != null) { pickliste.setTitle(elTitle.getTextTrim()); } dao.update(pickliste); Element elEntries = elPl.element("entries"); if (elEntries != null) { for (Iterator<?> itEn = elEntries.elementIterator(); itEn.hasNext();) { Element elEntry = (Element) itEn.next(); if (elEntry.getName().equals("entry")) { IPicklistEntry entry = dao.createPickListEntry(pickliste); String oldId = elEntry.attributeValue("id"); if (oldId != null) { importedEntities.put( new EntityKey(IPicklistEntry.class.getName(), Integer.parseInt(oldId)), Integer.valueOf(entry.getId())); } boolean modified = false; if (elEntry.attributeValue("key") != null) { entry.setKey(elEntry.attributeValue("key")); modified = true; } if (elEntry.attributeValue("sortindex") != null) { entry.setSortIndex(Integer.parseInt(elEntry.attributeValue("sortindex"))); modified = true; } if (modified) { dao.update(entry); } for (Iterator<?> itT = elEntry.elementIterator(); itT.hasNext();) { Element elText = (Element) itT.next(); String langId = elText.attributeValue("lang"); dao.createBezeichnung(entry, langId, elText.getTextTrim()); } } } } } } }
From source file:edu.ku.brc.af.core.expresssearch.ERTIJoinColInfo.java
License:Open Source License
/** * @param element/*from w w w . j a va 2 s. c o m*/ */ public ERTIJoinColInfo(final Element element) { joinTableId = getAttr(element, "tableid", null); //$NON-NLS-1$ joinTableIdAsInt = getAttr(element, "tableid", -1); //$NON-NLS-1$ colName = element.getTextTrim(); isPrimary = getAttr(element, "primary", false); //$NON-NLS-1$ }
From source file:edu.ku.brc.af.core.expresssearch.SearchConfigService.java
License:Open Source License
/** * Loads the changes.// w w w . jav a2s . c o m */ protected void loadConfig() { Element root = XMLHelper.readDOMFromConfigDir("es_skipfields.xml"); //$NON-NLS-1$ for (Object tblObj : root.selectNodes("/tables/table")) //$NON-NLS-1$ { Element tbl = (Element) tblObj; String name = XMLHelper.getAttr(tbl, "name", null); //$NON-NLS-1$ Hashtable<String, Boolean> fields = new Hashtable<String, Boolean>(); for (Object fldObj : tbl.selectNodes("field")) //$NON-NLS-1$ { Element fld = (Element) fldObj; fields.put(fld.getTextTrim().toLowerCase(), true); } skipFieldHash.put(name, fields); } XStream xstream = new XStream(); SearchConfig.configXStream(xstream); String xmlStr = null; AppResourceIFace escAppRes = AppContextMgr.getInstance().getResourceFromDir("Personal", resourceName); //$NON-NLS-1$ if (escAppRes != null) { xmlStr = escAppRes.getDataAsString(); } else { // Get the default resource by name and copy it to a new User Area Resource AppResourceIFace newAppRes = AppContextMgr.getInstance().copyToDirAppRes("Personal", resourceName); //$NON-NLS-1$ if (newAppRes != null) { // Save it in the User Area AppContextMgr.getInstance().saveResource(newAppRes); xmlStr = newAppRes.getDataAsString(); } else { log.error("copyToDirAppRes(\"Personal\", " + resourceName + ")"); } } //log.debug(xmlStr); searchConfig = (SearchConfig) xstream.fromXML(xmlStr); if (searchConfig == null) { searchConfig = new SearchConfig(); } else { searchConfig.initialize(); } }
From source file:edu.ku.brc.af.core.TaskMgr.java
License:Open Source License
/** * Get the command definitions for a class * @param classObj a class object//from ww w. j av a2 s.co m * @return the lst of commands for the class */ public static List<TaskCommandDef> getCommandDefinitions(final Class<?> classObj) { List<TaskCommandDef> list = new ArrayList<TaskCommandDef>(); try { if (instance.commandDOMRoot == null) { instance.commandDOMRoot = readDOMFromConfigDir("command_registry.xml"); //$NON-NLS-1$ } List<?> cmds = instance.commandDOMRoot .selectNodes("/commands/command[@class='" + classObj.getName() + "']"); //$NON-NLS-1$ //$NON-NLS-2$ for (Iterator<?> iter = cmds.iterator(); iter.hasNext();) { Element cmdElement = (Element) iter.next(); String cmdName = getAttr(cmdElement, "name", null); //$NON-NLS-1$ String cmdIconName = getAttr(cmdElement, "icon", null); //$NON-NLS-1$ if (StringUtils.isNotEmpty(cmdName) && StringUtils.isNotEmpty(cmdIconName)) { Properties params = null; List<?> paramsList = cmdElement.selectNodes("param"); //$NON-NLS-1$ for (Iterator<?> iterServices = paramsList.iterator(); iterServices.hasNext();) { Element paramElement = (Element) iterServices.next(); String name = getAttr(paramElement, UIRegistry.getResourceString("TaskMgr.0"), null); //$NON-NLS-1$ String value = paramElement.getTextTrim(); if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(value)) { if (params == null) { params = new Properties(); } params.put(name, value); } } TaskCommandDef tcd = new TaskCommandDef(cmdName, cmdIconName, params); list.add(tcd); } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaskMgr.class, ex); ex.printStackTrace(); log.error(ex); } return list; }
From source file:edu.ku.brc.af.tasks.subpane.StatsPane.java
License:Open Source License
/** * @param boxElement//w ww .j a v a 2 s. com * @param title * @param colNames * @return */ protected StatGroupTable processGroupItems(final Element boxElement, final String title, final String[] colNames, final boolean hasResBundle) { StatGroupTable groupTable = null; List<?> items = boxElement.selectNodes("item"); //$NON-NLS-1$ if (items != null) { groupTable = new StatGroupTable(title, colNames, useSeparatorTitles, items.size()); for (Object io : items) { Element itemElement = (Element) io; String itemTitle = getStrFromAttr(itemElement, "title", hasResBundle); //$NON-NLS-1$ String formatStr = null; Element formatNode = (Element) itemElement.selectSingleNode("sql/format"); //$NON-NLS-1$ if (formatNode != null) { formatStr = formatNode.getTextTrim(); } Element command = (Element) itemElement.selectSingleNode("command"); //$NON-NLS-1$ CommandAction cmdAction = null; if (command != null) { cmdAction = createCommandActionFromElement(command); } Element subSqlEl = (Element) itemElement.selectSingleNode("sql"); //$NON-NLS-1$ QueryType queryType = getQueryType(getAttr(subSqlEl, "type", "sql")); //$NON-NLS-1$ //$NON-NLS-2$ CustomQueryIFace customQuery = null; if (queryType == QueryType.CUSTOM) { String customQueryName = getAttr(subSqlEl, "name", null); //$NON-NLS-1$ if (StringUtils.isNotEmpty(customQueryName)) { customQuery = CustomQueryFactory.getInstance().getQuery(customQueryName); if (customQuery == null) { return null; } if (!isPermissionOK(customQuery.getTableIds())) { return null; } } else { log.error("Name is empty for box item [" + getAttr(itemElement, "title", "N/A") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ return null; } } else { List<Integer> tableIds = getTabledIds(subSqlEl); if (!isPermissionOK(tableIds)) { return null; } } StatDataItem statItem = new StatDataItem(itemTitle, cmdAction, getAttr(itemElement, "useprogress", false)); //$NON-NLS-1$ //System.out.println("["+queryType+"]"); switch (queryType) { case SQL: { List<?> statements = itemElement.selectNodes("sql/statement"); //$NON-NLS-1$ if (statements.size() == 1) { String sql = QueryAdjusterForDomain.getInstance() .adjustSQL(((Element) statements.get(0)).getText()); statItem.add(sql, 1, 1, StatDataItem.VALUE_TYPE.Value, formatStr); } else if (statements.size() > 0) { int cnt = 0; for (Object stObj : statements) { Element stElement = (Element) stObj; int vRowInx = getAttr(stElement, "row", -1); //$NON-NLS-1$ int vColInx = getAttr(stElement, "col", -1); //$NON-NLS-1$ String format = getAttr(stElement, "format", null); //$NON-NLS-1$ String sql = QueryAdjusterForDomain.getInstance().adjustSQL(stElement.getText()); if (vRowInx == -1 || vColInx == -1) { statItem.add(sql, format); // ignore return object } else { statItem.add(sql, vRowInx, vColInx, StatDataItem.VALUE_TYPE.Value, format); // ignore return object } cnt++; } } } break; case JPA: { List<?> statements = itemElement.selectNodes("sql/statement"); //$NON-NLS-1$ String sql = QueryAdjusterForDomain.getInstance() .adjustSQL(((Element) statements.get(0)).getText()); statItem.addCustomQuery(new JPAQuery(sql), formatStr); } break; case CUSTOM: statItem.addCustomQuery(customQuery, formatStr); break; } groupTable.addDataItem(statItem); statItem.startUp(); } groupTable.relayout(); } return groupTable; }
From source file:edu.ku.brc.af.tasks.subpane.StatsPane.java
License:Open Source License
/** * @param item/*from ww w . j a v a 2 s. co m*/ * @return */ protected static List<Integer> getTabledIds(final Element item) { if (item != null) { List<?> tables = item.selectNodes("tables/id");//$NON-NLS-1$ if (tables != null) { List<Integer> list = new Vector<Integer>(); for (Object obj : tables) { Element tbl = (Element) obj; list.add(Integer.parseInt(tbl.getTextTrim())); } return list; } } return null; }
From source file:edu.ku.brc.af.ui.forms.DataGetterForDOM.java
License:Open Source License
public Object getFieldValue(Object dataObj, String fieldName) { if (dataObj == null) { return null; }//from w w w .j a v a2 s . co m if (!(dataObj instanceof Element)) { throw new RuntimeException("DataGetterForDOM the dataObj is NOT an a dom4j Element! " + dataObj.getClass().getSimpleName()); } String fldName; String attr; if (fieldName.indexOf('#') > -1) { String[] tokens = StringUtils.split(fieldName, "#"); fldName = tokens[0]; attr = tokens[1]; } else { fldName = fieldName; attr = null; } Element domRoot = (Element) dataObj; Element element = (Element) domRoot.selectSingleNode(fldName); if (element != null) { if (attr != null) { return XMLHelper.getAttr(element, attr, null); } // else return element.getTextTrim(); } return null; }
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMgr.java
License:Open Source License
/** * Loads formats from config file/*www .j a va2s . c o m*/ * */ public void load() { resetInternal(); try { Element root = getDOM(); if (root != null) { domFound = true; List<?> formatters = root.selectNodes("/formatters/format"); for (Object formatObj : formatters) { Element formatElement = (Element) formatObj; String name = formatElement.attributeValue("name"); String title = formatElement.attributeValue("title"); String className = formatElement.attributeValue("class"); String format = formatElement.attributeValue("format"); boolean isDefault = XMLHelper.getAttr(formatElement, "default", false); if (StringUtils.isEmpty(title)) { title = name; } Class<?> dataClass = null; if (StringUtils.isNotEmpty(className)) { try { dataClass = Class.forName(className); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(DataObjFieldFormatMgr.class, ex); log.error("Couldn't load class [" + className + "]"); } } else { log.error("Class name [" + className + "] is empty and can't be. Skipping."); continue; } Element switchElement = (Element) formatElement.selectObject("switch"); if (switchElement != null) { boolean isSingle = getAttr(switchElement, "single", false); String switchField = getAttr(switchElement, "field", null); DataObjSwitchFormatter switchFormatter = new DataObjSwitchFormatter(name, title, isSingle, isDefault, dataClass, switchField); if (formatHash.get(name) == null) { formatHash.put(name, switchFormatter); } else { throw new RuntimeException("Duplicate formatter name[" + name + "]"); } DataObjSwitchFormatter sf = formatClassHash.get(dataClass); if (sf == null || isDefault) { if (isDefault) { DataObjSwitchFormatter curDO = formatClassHash.get(dataClass); if (curDO != null && curDO.isDefault()) { throw new RuntimeException( "There are two default DataObjectFormatters current [" + curDO.getName() + "] adding[" + sf.getName() + "] for class " + dataClass.getSimpleName()); } } formatClassHash.put(dataClass, switchFormatter); } Element external = (Element) switchElement.selectSingleNode("external"); if (external != null) { String externalClassName = getAttr(external, "class", (String) null); if (StringUtils.isNotEmpty(externalClassName)) { Properties props = new Properties(); List<?> paramElements = external.selectNodes("param"); for (Object param : paramElements) { String nameStr = getAttr((Element) param, "name", null); String val = ((Element) param).getTextTrim(); if (StringUtils.isNotEmpty(nameStr) && StringUtils.isNotEmpty(val)) { props.put(nameStr, val); } } try { DataObjDataFieldFormatIFace fmt = Class.forName(externalClassName) .asSubclass(DataObjDataFieldFormatIFace.class).newInstance(); fmt.init(name, props); switchFormatter.add(fmt); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(DataObjFieldFormatMgr.class, ex); log.error(ex); ex.printStackTrace(); } } else { throw new RuntimeException( "The 'class' attribute cannot be empty for an external formatter! [" + name + "]"); } } else { DBTableInfo tableInfo = switchFormatter.getTableInfo(); List<?> fieldsElements = switchElement.selectNodes("fields"); for (Object fieldsObj : fieldsElements) { Element fieldsElement = (Element) fieldsObj; String valueStr = getAttr(fieldsElement, "value", null); List<?> fldList = fieldsElement.selectNodes("field"); DataObjDataField[] fields = new DataObjDataField[fldList.size()]; int inx = 0; for (Object fldObj : fldList) { Element fieldElement = (Element) fldObj; String fieldName = fieldElement.getTextTrim(); String dataTypeStr = getAttr(fieldElement, "type", null); String formatStr = getAttr(fieldElement, "format", null); String sepStr = getAttr(fieldElement, "sep", null); String formatterName = getAttr(fieldElement, "formatter", null); String uifieldformatter = getAttr(fieldElement, "uifieldformatter", null); DBFieldInfo fieldInfo = tableInfo.getFieldByName(fieldName); DBRelationshipInfo relInfo = fieldInfo == null ? tableInfo.getRelationshipByName(fieldName) : null; Class<?> classObj; if (dataTypeStr == null) { if (fieldInfo != null) { classObj = fieldInfo.getDataClass(); } else { classObj = String.class; } } else { classObj = typeHash.get(dataTypeStr); } if (classObj == null) { log.error("Couldn't map standard type[" + dataTypeStr + "]"); } fields[inx] = new DataObjDataField(fieldName, classObj, formatStr, sepStr, formatterName, uifieldformatter); fields[inx].setDbInfo(tableInfo, fieldInfo, relInfo, true); inx++; } switchFormatter.add(new DataObjDataFieldFormat(name, dataClass, isDefault, format, valueStr, fields)); } } } else { log.error("No switch element! [" + name + "]"); // not needed once we start using a DTD/Schema } } for (Object aggObj : root.selectNodes("/formatters/aggregators/aggregator")) { Element aggElement = (Element) aggObj; String name = aggElement.attributeValue("name"); String title = aggElement.attributeValue("title"); String separator = aggElement.attributeValue("separator"); String countStr = aggElement.attributeValue("count"); String ending = aggElement.attributeValue("ending"); String format = aggElement.attributeValue("format"); String ordFldName = XMLHelper.getAttr(aggElement, "orderfieldname", null); boolean isDefault = XMLHelper.getAttr(aggElement, "default", true); String dataClassName = XMLHelper.getAttr(aggElement, "class", null); Integer count = StringUtils.isNotEmpty(countStr) && StringUtils.isNumeric(countStr) ? Integer.parseInt(countStr) : null; Class<?> dataClass = null; if (StringUtils.isNotEmpty(dataClassName)) { try { dataClass = Class.forName(dataClassName); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(DataObjFieldFormatMgr.class, ex); log.error("Couldn't load class [" + dataClassName + "]"); } } else { log.error("Class name [" + dataClassName + "] is empty and can't be. Skipping."); continue; } // TODO check for duplicates! aggHash.put(name, new DataObjAggregator(name, title, dataClass, isDefault, separator, count, ending, format, ordFldName)); } } else { log.debug("Couldn't get resource [DataObjFormatters]"); } // This needs to be refactored so we don't have to do this here // I think it is because 'load' is being called from the constructor. if (instance.get() == null) { instance.set(this); } // now that all formats have been loaded, set table/field/formatter info\ // must be executed after the instance is set for (DataObjSwitchFormatter format : instance.get().formatHash.values()) { format.setTableAndFieldInfo(); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataObjFieldFormatMgr.class, ex); ex.printStackTrace(); log.error(ex); } }