List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.pureinfo.studio.db.rpms2srm.RPMSImporter4ListNamedValue.java
License:Open Source License
public void run() throws Exception { final String SQL_RESETID = "update dpn_sequence set NEXT_VALUE=? WHERE SEQ_KEY='" + ListNamedValueRPMS.class.getName() + ":id'"; try {/* w w w . ja va 2 s .c o m*/ //1. to load config String sFile = RPMSImporter.class.getResource(RESOURCE).getFile(); Element config = XMLUtil.fileToElement(sFile); //2. to prepare ISession sessionTo = this.getSessionTo(); IStatement statement = sessionTo.createStatement(SQL_RESETID); statement.setInt(0, 0); statement.executeUpdate(); statement.clear(false); //3. to do import List items = config.elements("type"); for (int i = 0; i < items.size(); i++) { doImport((Element) items.get(i)); } //3. to reset id statement = sessionTo.createStatement(SQL_RESETID); statement.setInt(0, 10001); statement.executeUpdate(); statement.clear(false); } finally { this.clear(); } }
From source file:com.pureinfo.studio.db.rpms2srm.RPMSImporter4TreeNamedValue.java
License:Open Source License
public void run() throws Exception { final String SQL_RESETID = "update dpn_sequence set NEXT_VALUE=? WHERE SEQ_KEY='" + TreeNamedValueRPMS.class.getName() + ":id'"; try {//from ww w. jav a 2 s . c o m //1. to load config String sFile = RPMSImporter.class.getResource(RESOURCE).getFile(); Element config = XMLUtil.fileToElement(sFile); //2. to prepare ISession sessionTo = this.getSessionTo(); IStatement statement = sessionTo.createStatement(SQL_RESETID); statement.setInt(0, 1); statement.executeUpdate(); statement.clear(false); //3. to do import List items = config.elements("type"); for (int i = 0; i < items.size(); i++) { doImport((Element) items.get(i)); } //3. to reset id statement = sessionTo.createStatement(SQL_RESETID); statement.setInt(0, 10001); statement.executeUpdate(); statement.clear(false); } finally { this.clear(); } }
From source file:com.pureinfo.studio.db.txt2SRM.impl.SchoolSCITxtImportRunner.java
License:Open Source License
/** * Converts the properties whose type are different from SRM. * /*from www . ja v a2 s. co m*/ * @param _oldObj * @param _newObj * @throws Exception */ private boolean convert(DolphinObject _oldObj, DolphinObject _newObj, List _errorDataList) throws Exception { Element convert = m_xmlConfig.element("data"); List properties = convert.element("convert").elements(); Element element; String sFrom, sTo, sRef, sForeignKey; Object value = null; boolean bConvertError = false; boolean bvalidate = true; for (int i = 0; i < properties.size(); i++) { bvalidate = true; element = (Element) properties.get(i); if (element.attributeValue("provider") != null) continue; sFrom = element.attributeValue("from"); sTo = element.attributeValue("to"); sRef = element.attributeValue("ref"); // to convert property value if (!_oldObj.hasProperty(sFrom)) { continue; // throw new PureException(PureException.PROPERTY_NOTFOUND, // sFrom); } if (isPropertySet(_newObj, sTo)) continue; // skip // else try { sForeignKey = element.attributeValue("fk"); String expandCondition = null, expandPropertyDebug = null; StringBuffer expandConditionBuffer = new StringBuffer(); StringBuffer expandPropertyDebugBuffer = new StringBuffer(); Element expandElement; List expands = element.elements("expand"); if (expands.size() > 0) { for (int j = 0; j < expands.size(); j++) { expandElement = (Element) expands.get(i); String expandPropertyValue = _oldObj.getProperty(expandElement.attributeValue("from")) .toString(); expandConditionBuffer.append(" " + expandElement.attributeValue("to")); expandConditionBuffer.append('='); expandConditionBuffer.append(expandPropertyValue); expandConditionBuffer.append(" and "); expandPropertyDebugBuffer.append("(" + expandElement.attributeValue("from") + "\"" + expandPropertyValue + '\"' + ')'); } } if (expandConditionBuffer.length() > 0) { expandCondition = expandConditionBuffer.toString(); expandPropertyDebug = expandPropertyDebugBuffer.toString(); } expandConditionBuffer.setLength(0); if (element.attributeValue("validate") != null && element.attributeValue("validate").equals("false")) bvalidate = false; value = this.lookupRefValue(sRef, _oldObj.getProperty(sFrom), sForeignKey, sFrom, _errorDataList, expandCondition, expandPropertyDebug, bvalidate); if (value == null) { bConvertError = true; } else { _newObj.setProperty(sTo, value); } } catch (Exception ex) { throw new PureException(PureException.INVALID_VALUE, "convert " + sFrom + "[" + value + "] to " + sTo, ex); } } return bConvertError; }
From source file:com.pureinfo.studio.db.txt2SRM.impl.SchoolSCITxtImportRunner.java
License:Open Source License
private void executeSQLElement(String _sName) throws Exception { Element ele = m_xmlConfig.element(_sName); if (ele == null || "false".equals(ele.attributeValue("enabled"))) { return;//from w ww . ja va 2s. c o m } // else List eleSQLs = ele.elements("sql"); if (eleSQLs.isEmpty()) return; // else, to execute the SQLs String strSQL; ISession session = this.getSession(); for (int i = 0; i < eleSQLs.size(); i++) { strSQL = ((Element) eleSQLs.get(i)).getTextTrim(); try { logger.debug("to execute: " + strSQL); IStatement statement = session.createStatement(strSQL); this.registerAlias(statement, ele.elements("alias")); statement.executeUpdate(); statement.clear(); } catch (Exception ex) { throw new PureException(PureException.DATABASE_ACCESS, strSQL, ex); } } }
From source file:com.pureinfo.studio.db.xls2rpms.XlsImporter.java
License:Open Source License
private void executeSQLElement(String _sName) throws Exception { Element ele = m_xmlConfig.element(_sName); if (ele == null || "false".equals(ele.attributeValue("enabled"))) { return;/* w w w.ja v a2 s . c o m*/ } //else List eleSQLs = ele.elements("sql"); if (eleSQLs.isEmpty()) return; //else, to execute the SQLs String strSQL; ISession session = this.getSession(); for (int i = 0; i < eleSQLs.size(); i++) { strSQL = ((Element) eleSQLs.get(i)).getTextTrim(); try { System.out.println("to execute: " + strSQL); IStatement statement = session.createStatement(strSQL); this.registerAlias(statement, ele.elements("alias")); statement.executeUpdate(); statement.clear(); } catch (Exception ex) { throw new PureException(PureException.DATABASE_ACCESS, strSQL, ex); } } }
From source file:com.pureinfo.studio.db.xls2srm.impl.PatentImportRunner.java
License:Open Source License
private void executeSQLElement(String _sName) throws Exception { Element ele = m_xmlConfig.element(_sName); if (ele == null || "false".equals(ele.attributeValue("enabled"))) { return;//from w ww . ja va2 s . c o m } // else List eleSQLs = ele.elements("sql"); if (eleSQLs.isEmpty()) return; // else, to execute the SQLs String strSQL; ISession session = this.getSession(); for (int i = 0; i < eleSQLs.size(); i++) { strSQL = ((Element) eleSQLs.get(i)).getTextTrim(); try { System.out.println("to execute: " + strSQL); IStatement statement = session.createStatement(strSQL); this.registerAlias(statement, ele.elements("alias")); statement.executeUpdate(); statement.clear(); } catch (Exception ex) { throw new PureException(PureException.DATABASE_ACCESS, strSQL, ex); } } }
From source file:com.pureinfo.studio.db.xls2srm.impl.ProjectBatchImportRunner.java
License:Open Source License
/** * Converts the properties whose type are different from SRM. * /*from ww w . j ava 2 s .c o m*/ * @param _oldObj * @param _newObj * @throws Exception */ private boolean convert(DolphinObject _oldObj, DolphinObject _newObj, List _errorDataList, int _nChooseIfRepeat) throws Exception { Element convert = m_xmlConfig.element("data"); List properties = convert.element("convert").elements(); Element element; String sFrom, sTo, sRef, sForeignKey; Object value = null; Object valueFrom = null; boolean bConvertError = false; boolean bvalidate = true; for (int i = 0; i < properties.size(); i++) { element = (Element) properties.get(i); if (element.attributeValue("provider") != null) { sRef = element.attributeValue("ref"); sFrom = element.attributeValue("from"); sTo = element.attributeValue("to"); if (sRef != null && sRef.charAt(0) == '#') { // if ( _nChooseIfRepeat != Xls2srmForm.JUSTFORCHECK IImportorRef ref = (IImportorRef) PureFactory.getBean(sRef.substring(1)); value = ref.convert(_oldObj, _newObj, sFrom, String.valueOf(_nChooseIfRepeat), null, LocalContextHelper.currentSession("Local"), m_entityMetadata, null, null); _newObj.setProperty(sTo, value); continue; } continue; } // sFrom = element.attributeValue("from").toUpperCase(); sFrom = element.attributeValue("from"); sTo = element.attributeValue("to"); sRef = element.attributeValue("ref"); // to convert property value if (!_oldObj.hasProperty(sFrom)) { continue; // throw new PureException(PureException.PROPERTY_NOTFOUND, // sFrom); } if (isPropertySet(_newObj, sTo)) continue; // skip // else try { sForeignKey = element.attributeValue("fk"); String expandCondition = null, expandPropertyDebug = null; StringBuffer expandConditionBuffer = new StringBuffer(); StringBuffer expandPropertyDebugBuffer = new StringBuffer(); Element expandElement; List expands = element.elements("expand"); if (expands.size() > 0) { for (int j = 0; j < expands.size(); j++) { expandElement = (Element) expands.get(i); String expandPropertyValue = _oldObj.getProperty(expandElement.attributeValue("from")) .toString(); expandConditionBuffer.append(" " + expandElement.attributeValue("to")); expandConditionBuffer.append("="); expandConditionBuffer.append(expandPropertyValue); expandConditionBuffer.append(" and "); expandPropertyDebugBuffer.append("(" + expandElement.attributeValue("from") + "\"" + expandPropertyValue + "\"" + ")"); } } if (expandConditionBuffer.length() > 0) { expandCondition = expandConditionBuffer.toString(); expandPropertyDebug = expandPropertyDebugBuffer.toString(); } expandConditionBuffer.setLength(0); valueFrom = _oldObj.getProperty(sFrom); if (element.attributeValue("subString") != null) { String sSubStringValue = element.attributeValue("subString"); int nBeganIndex = 0; int nEndIndex = sSubStringValue.length() - 1; if (sSubStringValue.indexOf(",") > 0) { String sBeganIndex = sSubStringValue.substring(0, sSubStringValue.indexOf(",")); nBeganIndex = Integer.parseInt(sBeganIndex); String sEndIndex = sSubStringValue.substring(sSubStringValue.indexOf(",") + 1); nEndIndex = Integer.parseInt(sEndIndex); // logger.debug(""+nBeganIndex+""+nEndIndex); } if (valueFrom != null && ((String) valueFrom).length() >= nEndIndex) { valueFrom = ((String) valueFrom).substring(nBeganIndex, nEndIndex); // logger.debug(" "+valueFrom); } } if (element.attributeValue("validate") != null && element.attributeValue("validate").equals("false")) bvalidate = false; value = this.lookupRefValue(sRef, valueFrom, sForeignKey, sFrom, _errorDataList, expandCondition, expandPropertyDebug, bvalidate); if (value == null) { bConvertError = true; } else { _newObj.setProperty(sTo, value); } } catch (Exception ex) { throw new PureException(PureException.INVALID_VALUE, "convert " + sFrom + "[" + value + "] to " + sTo, ex); } } // bConvertError = validateAdminExist(_errorDataList, _oldObj.getStrProperty("")); return bConvertError; }
From source file:com.pureinfo.studio.db.xls2srm.impl.ProjectFinishImportRunner.java
License:Open Source License
/** * Converts the properties whose type are different from SRM. * //from w w w . j a v a 2 s . co m * @param _oldObj * @param _newObj * @throws Exception */ private boolean convert(DolphinObject _oldObj, DolphinObject _newObj, List _errorDataList, int _nChooseIfRepeat) throws Exception { Element convert = m_xmlConfig.element("data"); List properties = convert.element("convert").elements(); Element element; String sFrom, sTo, sRef, sForeignKey; Object value = null; Object valueFrom = null; boolean bConvertError = false; boolean bvalidate = true; for (int i = 0; i < properties.size(); i++) { element = (Element) properties.get(i); System.out.println(element.attributeValue("from") + "-ddddddddd------->" + _oldObj.getProperty(element.attributeValue("from")) + "|"); if (element.attributeValue("provider") != null) { sRef = element.attributeValue("ref"); sFrom = element.attributeValue("from"); sTo = element.attributeValue("to"); if (sRef != null && sRef.charAt(0) == '#') { // if ( _nChooseIfRepeat != Xls2srmForm.JUSTFORCHECK IImportorRef ref = (IImportorRef) PureFactory.getBean(sRef.substring(1)); value = ref.convert(_oldObj, _newObj, sFrom, String.valueOf(_nChooseIfRepeat), null, LocalContextHelper.currentSession("Local"), m_entityMetadata, m_xmlConfig.elementTextTrim("match-properties"), m_xmlConfig.attributeValue("temp")); _newObj.setProperty(sTo, value); continue; } continue; } // sFrom = element.attributeValue("from").toUpperCase(); sFrom = element.attributeValue("from"); sTo = element.attributeValue("to"); sRef = element.attributeValue("ref"); // to convert property value if (!_oldObj.hasProperty(sFrom)) { continue; // throw new PureException(PureException.PROPERTY_NOTFOUND, // sFrom); } if (isPropertySet(_newObj, sTo)) continue; // skip // else try { sForeignKey = element.attributeValue("fk"); String expandCondition = null, expandPropertyDebug = null; StringBuffer expandConditionBuffer = new StringBuffer(); StringBuffer expandPropertyDebugBuffer = new StringBuffer(); Element expandElement; List expands = element.elements("expand"); if (expands.size() > 0) { for (int j = 0; j < expands.size(); j++) { expandElement = (Element) expands.get(i); String expandPropertyValue = _oldObj.getProperty(expandElement.attributeValue("from")) .toString(); expandConditionBuffer.append(" " + expandElement.attributeValue("to")); expandConditionBuffer.append("="); expandConditionBuffer.append(expandPropertyValue); expandConditionBuffer.append(" and "); expandPropertyDebugBuffer.append("(" + expandElement.attributeValue("from") + "\"" + expandPropertyValue + "\"" + ")"); } } if (expandConditionBuffer.length() > 0) { expandCondition = expandConditionBuffer.toString(); expandPropertyDebug = expandPropertyDebugBuffer.toString(); } expandConditionBuffer.setLength(0); valueFrom = _oldObj.getProperty(sFrom); if (element.attributeValue("subString") != null) { String sSubStringValue = element.attributeValue("subString"); int nBeganIndex = 0; int nEndIndex = sSubStringValue.length() - 1; if (sSubStringValue.indexOf(",") > 0) { String sBeganIndex = sSubStringValue.substring(0, sSubStringValue.indexOf(",")); nBeganIndex = Integer.parseInt(sBeganIndex); String sEndIndex = sSubStringValue.substring(sSubStringValue.indexOf(",") + 1); nEndIndex = Integer.parseInt(sEndIndex); // logger.debug(""+nBeganIndex+""+nEndIndex); } if (valueFrom != null && ((String) valueFrom).length() >= nEndIndex) { valueFrom = ((String) valueFrom).substring(nBeganIndex, nEndIndex); // logger.debug(" "+valueFrom); } } if (element.attributeValue("validate") != null && element.attributeValue("validate").equals("false")) bvalidate = false; value = this.lookupRefValue(sRef, valueFrom, sForeignKey, sFrom, _errorDataList, expandCondition, expandPropertyDebug, bvalidate); if (value == null) { bConvertError = true; } else { _newObj.setProperty(sTo, value); System.out.println("=======" + _newObj.getProperty(sTo)); } } catch (Exception ex) { throw new PureException(PureException.INVALID_VALUE, "convert " + sFrom + "[" + value + "] to " + sTo, ex); } } return bConvertError; }