List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:com.pureinfo.studio.db.rpms2srm.RPMSImporter4ListNamedValue.java
License:Open Source License
private void doImport(Element _element) throws Exception { int nType = XMLUtil.getAttributeValueAsInt(_element, "id"); String sTypeDesc = _element.attributeValue("desc"); String strSQL;// w w w.j ava2 s . c om strSQL = "delete from {this} where {this.type}=?"; ISession sessionFrom = this.getSessionFrom(); ISession sessionTo = this.getSessionTo(); IStatement statement = null; IObjects objs = null; DolphinObject obj; ListNamedValueRPMS lnv; String sName, sValue, sDescription; try { //1. to delete the old statement = sessionTo.createStatement(strSQL); statement.registerAlias("this", ListNamedValueRPMS.class); statement.setInt(0, nType); statement.executeUpdate(); statement.clear(); //2. to add new strSQL = _element.getTextTrim(); statement = sessionFrom.createQuery(strSQL, DolphinObject.class, 0); objs = statement.executeQuery(); while ((obj = objs.next()) != null) { sName = obj.getStrProperty("NAME"); sValue = obj.getStrProperty("VALUE"); sDescription = obj.getStrProperty("NOTE"); if (sDescription == null || (sDescription = sDescription.trim()).length() == 0) { sDescription = sTypeDesc + "" + sName; } logger.debug("to save: type=" + nType + ", value=" + sValue + ", name=" + sName); lnv = new ListNamedValueRPMS(); lnv.setProperty("type", nType); lnv.setValue(sValue); lnv.setName(sName); lnv.setDescription(sDescription); lnv.setCreateUser("system"); sessionTo.save(lnv); } } catch (Exception ex) { System.out.println("failed to import: type=" + nType + ", desc=" + sTypeDesc); ex.printStackTrace(System.out); } finally { DolphinHelper.clear(objs, statement); } }
From source file:com.pureinfo.studio.db.rpms2srm.RPMSImporter4TreeNamedValue.java
License:Open Source License
private void doImport(Element _element) throws Exception { int nType = XMLUtil.getAttributeValueAsInt(_element, "id"); String sTypeDesc = _element.attributeValue("desc"); String strSQL;//w ww . j a v a 2 s . com strSQL = "delete from {this} where {this.type}=?"; ISession sessionFrom = this.getSessionFrom(); ISession sessionTo = this.getSessionTo(); IStatement statement = null; IObjects objs = null; DolphinObject obj; TreeNamedValueRPMS tnv; String sName, sValue, sParentValue, sDescription; try { //1. to delete the old statement = sessionTo.createStatement(strSQL); statement.registerAlias("this", TreeNamedValueRPMS.class); statement.setInt(0, nType); statement.executeUpdate(); statement.clear(); //2. to add new strSQL = _element.getTextTrim(); statement = sessionFrom.createQuery(strSQL, DolphinObject.class, 0); objs = statement.executeQuery(); while ((obj = objs.next()) != null) { sName = obj.getStrProperty("NAME"); sValue = obj.getStrProperty("VALUE"); sParentValue = obj.getStrProperty("PARENTVALUE"); sDescription = obj.getStrProperty("NOTE"); if (sDescription == null || (sDescription = sDescription.trim()).length() == 0) { sDescription = sTypeDesc + "" + sName; } logger.debug("to save: type=" + nType + ", value=" + sValue + ", name=" + sName); tnv = new TreeNamedValueRPMS(); tnv.setProperty("type", nType); tnv.setValue(sValue); tnv.setName(sName); tnv.setParentValue(sParentValue); tnv.setLevel(1); tnv.setDescription(sDescription); tnv.setCreateUser("system"); try { sessionTo.save(tnv); } catch (Exception ex) { Element ele = DolphinUtil.toXMLElement(tnv, "RPMSTreeNamedValue"); System.out.println(XMLUtil.toString(ele)); throw ex; } } } catch (Exception ex) { System.out.println("failed to import: type=" + nType + ", desc=" + sTypeDesc); throw ex; } finally { DolphinHelper.clear(objs, statement); } }
From source file:com.pureinfo.studio.db.xls2srm.impl.ProjectFinishImportRunner.java
License:Open Source License
/** * Saves the new object into SRM database. * //from w w w . j a va 2 s . c o m * @param _newObj * @throws Exception */ private boolean beforeSave(DolphinObject _newObj, List _errorDataList) throws Exception { List requiredList = new ArrayList(); List containList = new ArrayList(); List lostList = new ArrayList(); boolean bError = false; try { Iterator itr = _newObj.getProperties(false).entrySet().iterator(); Object oKey = null; while (itr.hasNext()) { Map.Entry entryContain = (Map.Entry) itr.next(); oKey = entryContain.getKey(); containList.add(oKey); } PropertyMetadata propertyMetadata, propertyMetadata1; Iterator itrRequied = m_entityMetadata.getProperties().entrySet().iterator(); while (itrRequied.hasNext()) { Map.Entry entry = (Map.Entry) itrRequied.next(); propertyMetadata = m_entityMetadata.lookupPropertyByName(entry.getKey().toString(), true); if (!propertyMetadata.isNullable()) { if (!(entry.getKey().equals("createTime") || entry.getKey().equals("id"))) { requiredList.add(entry.getKey()); } } } // wind.li@2007-05-09 // BEGIN Element requiredProps = m_xmlConfig.element("required-properties"); if (requiredProps != null) { String sValue = requiredProps.getTextTrim(); if (sValue.length() > 0) { String[] arrProps = StrUtil.split(sValue, ","); for (int i = 0; i < arrProps.length; i++) { String sName = arrProps[i]; if (!requiredList.contains(sName)) { requiredList.add(sName); } } } } // END for (int i = requiredList.size(); i > 0; i--) { if (!containList.contains(requiredList.get(i - 1))) { lostList.add(requiredList.get(i - 1)); } } if (lostList.size() > 0) { bError = true; for (int i = lostList.size(); i > 0; i--) { propertyMetadata1 = m_entityMetadata.lookupPropertyByName(lostList.get(i - 1).toString(), true); _errorDataList.add(propertyMetadata1.getDesc().toUpperCase()); } } } catch (Exception ex) { throw ex; } finally { if (requiredList != null) requiredList.clear(); if (containList != null) containList.clear(); if (lostList != null) lostList.clear(); } return bError; }
From source file:com.pureinfo.studio.db.xls2srm.impl.ProjectFinishImportRunner.java
License:Open Source License
/** * wind.li@2007-04-29//from ww w . j a va 2 s . c o m * * * * @return */ private List checkMaybeRequiredCells(DolphinObject _old) throws PureException { Element element = m_xmlConfig.element("maybe-required-cells"); if (element == null) return null; List cells = element.elements(); if (cells == null) return null; Element ele; List lostCellList = new ArrayList(); for (Iterator iter = cells.iterator(); iter.hasNext();) { ele = (Element) iter.next(); Element eleCellName = ele.element("name"); if (eleCellName == null) { throw new PureException(PureException.PROPERTY_VALUE_REQUIRED, "<cell><name>"); } String sCellName = eleCellName.getTextTrim(); Element eleConditions = ele.element("conditions"); if (eleConditions == null) { if (_old.getProperty(sCellName) == null) { lostCellList.add(sCellName); continue; } } List conditions = eleConditions.elements("condition"); if (conditions == null || conditions.size() == 0) { if (_old.getProperty(sCellName) == null) { lostCellList.add(sCellName); continue; } } for (Iterator iter2 = conditions.iterator(); iter2.hasNext();) { Element condition = (Element) iter2.next(); Element eleCell = condition.element("cell"); if (eleCell == null) { throw new PureException(PureException.PROPERTY_VALUE_REQUIRED, "<cell>(name = " + sCellName + ")<condition><cell>"); } Element eleOperator = condition.element("operator"); if (eleOperator == null) { throw new PureException(PureException.PROPERTY_VALUE_REQUIRED, "<cell>(name = " + sCellName + ")<condition><operator>"); } Element eleValue = condition.element("value"); if (eleValue == null) { throw new PureException(PureException.PROPERTY_VALUE_REQUIRED, "<cell>(name = " + sCellName + ")<condition><value>"); } String sCell = eleCell.getTextTrim(); String sOperator = eleOperator.getTextTrim().toUpperCase(); String sValue = eleValue.getTextTrim(); String sCellValue = _old.getPropertyAsString(sCell); if (sCellValue != null && sCellValue.trim().length() > 0) { if ("IN".equals(sOperator)) { if (sValue != null && sValue.indexOf("," + sCellValue + ",") != -1) { if (_old.getProperty(sCellName) == null) { lostCellList.add(sCellName); continue; } } } if ("EQUAL".equals(sOperator)) { if (sValue != null && sValue.equals(sCellValue)) { if (_old.getProperty(sCellName) == null) { lostCellList.add(sCellName); continue; } } } } } } return lostCellList; }
From source file:com.pureinfo.studio.db.xls2srm.impl.XlsImportRunner.java
License:Open Source License
/** properties */ public List getViewSelfProperties() { Element ele = m_xmlConfig.element("view-self-properties"); if (ele == null) return null; String sValue = ele.getTextTrim(); return StrUtil.splitToList(sValue, ','); }
From source file:com.qagen.osfe.programData.ConfigFileLoader.java
License:Apache License
@SuppressWarnings("unchecked") private String getStatement(Element root) { final List<Element> elements = root.elements(); final StringBuilder statement = new StringBuilder(); statement.append("insert ignore into ").append(tableName).append(" ("); int count = 1; for (Element element : elements) { statement.append(element.getName()); if (count++ < elements.size()) { statement.append(COMMA);/*from w w w . j a v a2s .c om*/ } } statement.append(") values("); count = 1; for (Element element : elements) { final String name = element.getName(); final String value = element.getTextTrim(); final ColumnInfo info = columnInfoMap.get(name); if (info.isString()) { statement.append(SINGLE_QUOTE).append(value).append(SINGLE_QUOTE); } else { statement.append(value); } if (count++ < elements.size()) { statement.append(COMMA); } } statement.append(")"); return statement.toString(); }
From source file:com.qagen.osfe.programData.ProgramDataLoader.java
License:Apache License
@SuppressWarnings("unchecked") private void processConfigFiles(final Element root) { final List<Element> elements = root.element(ELEMENT.configFiles.name()).elements(); for (Element element : elements) { final String configFileName = element.getTextTrim(); new ConfigFileLoader(configFileName); }// www . ja v a2s . co m }
From source file:com.smartmarmot.dbforbix.config.Config.java
License:Open Source License
private void buildItemsAndSchedulers(Element e, Map<String, String> itemConfig, String prefix, ZServer zs) { String itemGroupName = itemConfig.get("itemGroupName"); Map<Integer, Scheduler> schedulers = getSchedulersByItemGroupName(itemGroupName); for (Object itm : e.elements()) { if (itm instanceof Element) { Element itmE = (Element) itm; int time = 60; try { time = Integer.parseInt(itmE.attributeValue("time")); } catch (NumberFormatException ex) { LOG.warn("invalid time value: " + itmE.attributeValue("time")); }// w ww . j a v a 2 s . co m if (!schedulers.containsKey(time)) { LOG.debug("creating item scheduler with time " + time); schedulers.put(time, new Scheduler(time)); } Scheduler itemSch = schedulers.get(time); String query = itmE.getTextTrim(); query = substituteMacros(query, zs, itemConfig.get("hostid")); switch (itmE.getName()) { case "discovery": { Discovery item = new Discovery(prefix + itmE.attributeValue("item"), query, itemConfig, zs); String nameList = itmE.attributeValue("names", ""); String names[] = nameList.split("\\|"); if (names != null && names.length > 0) item.setAltNames(names); //if(!item.setZServer(zs)) LOG.debug("buildServerElements: we haven't not actually registered ZServer "+zs.toString()+" for item "+item.getName()); itemSch.addItem(itemGroupName, item); } break; case "query": { Item item = new SimpleItem(prefix + itmE.attributeValue("item"), query, itmE.attributeValue("nodata"), itemConfig, zs); itemSch.addItem(itemGroupName, item); } break; case "multiquery": { String itemList = itmE.attributeValue("items", ""); String items[] = itemList.split("\\|"); Item item; if (itmE.attributeValue("type", "column").equalsIgnoreCase("column")) item = new MultiColumnItem(prefix, items, query, itemConfig, zs); else item = new MultiRowItem(prefix, items, query, itemConfig, zs); itemSch.addItem(itemGroupName, item); } break; } } } }
From source file:com.smartwork.im.utils.XMLProperties.java
License:Open Source License
/** * Returns the value of the specified property. * * @param name the name of the property to get. * @return the value of the specified property. *//*from w w w. j a v a2s . com*/ public synchronized String getProperty(String name) { String value = propertyCache.get(name); if (value != null) { return value; } String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy. Element element = document.getRootElement(); for (int i = 0; i < propName.length; i++) { element = element.element(propName[i]); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return null. return null; } } // At this point, we found a matching property, so return its value. // Empty strings are returned as null. value = element.getTextTrim(); if ("".equals(value)) { return null; } else { // Add to cache so that getting property next time is fast. propertyCache.put(name, value); return value; } }
From source file:com.stardon.carassistant.Activity.BusinessRecordFunctionList_Activity.java
/** * @: request08Q12//w ww. j a va2 s. c o m * @: 08Q12 <br/> * <br/> * Toastmessage <br/> * <br/> * <br/> * <br/> * <br/> * @: null * @: void * @ IOException: * @ NullPointerException: */ private void request08Q12() { String jkid = "08Q12"; StringBuilder xmlData = new StringBuilder(); xmlData.append("<?xml version=\"1.0\" encoding=\"GBK\"?>"); xmlData.append("<root>"); xmlData.append("<QueryCondition>"); xmlData.append("<orgcode>" + orgcode + "</orgcode>"); xmlData.append("</QueryCondition>"); xmlData.append("</root>"); doRequest(METHOD_QUERY, jkid, xmlData.toString(), new VolleyInterface() { @Override public void onMySuccess(JSONObject result) { } @Override public void onMySuccess(String result) { Document doc = null; try { doc = DocumentHelper.parseText(result); Element root = doc.getRootElement(); Element head = root.element("head"); String code = head.elementTextTrim("code"); String message = head.elementTextTrim("message"); if (!"1".equals(code)) {// 1. MyToast.showButtom(getContext(), message); return; } { XStream xstream = new XStream(new DomDriver()); xstream.ignoreUnknownElements(); xstream.alias("root", ResponseRootVo.class); xstream.alias("head", BaseResponseMsgVO.class); xstream.alias("body", BaseResponseBodyVO.class); xstream.aliasField("vehispara", BaseResponseBodyVO.class, "bean08Q12");// xstream.alias("vehispara", Bean08Q12.class);// ResponseRootVo b = (ResponseRootVo) xstream.fromXML(result); bean08Q12 = b.getBody().getBean08Q12(); } Element body = root.element("body"); List<Element> elementList = body.element("vehispara").elements(); data08Q12 = new HashMap<String, String>(); for (Element element : elementList) { data08Q12.put(element.getName(), element.getTextTrim()); } } catch (Exception e) { e.printStackTrace(); } try { user.setOrgrecoedstate(data08Q12.get("reviewstate")); dao.saveUser(user); reviewstate = data08Q12.get("reviewstate"); code = data08Q12.get("code"); ishavephoto = data08Q12.get("ishavephoto"); pic = data08Q12.get("pic"); zzpic = data08Q12.get("zzpic"); refreshStauts(); } catch (Exception e) { } } @Override public void onMyError(VolleyError result) { } }); }