⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entitysaxreader.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (currentFieldValue == null) {                currentFieldValue = value;            } else {                currentFieldValue = Text.valueOf(currentFieldValue).concat(value);            }        }    }    public void endDocument() throws org.xml.sax.SAXException {}    public void endElement(CharSequence namespaceURI, CharSequence localName, CharSequence fullName) throws org.xml.sax.SAXException {        if (Debug.verboseOn()) Debug.logVerbose("endElement: localName=" + localName + ", fullName=" + fullName + ", numberRead=" + numberRead, module);        String fullNameString = fullName.toString();        if ("entity-engine-xml".equals(fullNameString)) {            return;        }        if ("entity-engine-transform-xml".equals(fullNameString)) {            // transform file & parse it, then return            URL templateUrl = UtilURL.fromResource(templatePath.toString());            if (templateUrl == null) {                throw new SAXException("Could not find transform template with resource path: " + templatePath);            } else {                try {                    Reader templateReader = new InputStreamReader(templateUrl.openStream());                    StringWriter outWriter = new StringWriter();                    Configuration config = new Configuration();                    config.setObjectWrapper(BeansWrapper.getDefaultInstance());                    config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");                    Template template = new Template("FMImportFilter", templateReader, config);                    NodeModel nodeModel = NodeModel.wrap(this.rootNodeForTemplate);                    Map context = FastMap.newInstance();                    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();                    TemplateHashModel staticModels = wrapper.getStaticModels();                    context.put("Static", staticModels);                    context.put("doc", nodeModel);                    template.process(context, outWriter);                    String s = outWriter.toString();                    if (Debug.verboseOn()) Debug.logVerbose("transformed xml: " + s, module);                    EntitySaxReader reader = new EntitySaxReader(delegator);                    reader.setUseTryInsertMethod(this.useTryInsertMethod);                    try {                        reader.setTransactionTimeout(this.transactionTimeout);                    } catch (GenericTransactionException e1) {                        // couldn't set tx timeout, shouldn't be a big deal                    }                    numberRead += reader.parse(s);                } catch (TemplateException e) {                    throw new SAXException("Error storing value", e);                } catch(IOException e) {                    throw new SAXException("Error storing value", e);                }            }            return;        }        if (isParseForTemplate) {            this.currentNodeForTemplate = this.currentNodeForTemplate.getParentNode();            return;        }        if (currentValue != null) {            if (currentFieldName != null) {                if (currentFieldValue != null && currentFieldValue.length() > 0) {                    if (currentValue.getModelEntity().isField(currentFieldName.toString())) {                        ModelEntity modelEntity = currentValue.getModelEntity();                        ModelField modelField = modelEntity.getField(currentFieldName.toString());                        String type = modelField.getType();                        if (type != null && type.equals("blob")) {                            byte strData[] = new byte[currentFieldValue.length()];                            strData = currentFieldValue.toString().getBytes();                            byte binData[] = new byte[currentFieldValue.length()];                            binData = Base64.base64Decode(strData);                            currentValue.setBytes(currentFieldName.toString(), binData);                        } else {                            currentValue.setString(currentFieldName.toString(), currentFieldValue.toString());                        }                    } else {                        Debug.logWarning("Ignoring invalid field name [" + currentFieldName + "] found for the entity: " + currentValue.getEntityName() + " with value=" + currentFieldValue, module);                    }                    currentFieldValue = null;                }                currentFieldName = null;            } else {                // before we write currentValue check to see if PK is there, if not and it is one field, generate it from a sequence using the entity name                if (!currentValue.containsPrimaryKey()) {                    if (currentValue.getModelEntity().getPksSize() == 1) {                        ModelField modelField = currentValue.getModelEntity().getOnlyPk();                        String newSeq = delegator.getNextSeqId(currentValue.getEntityName());                        currentValue.setString(modelField.getName(), newSeq);                    } else {                        throw new SAXException("Cannot store value with incomplete primary key with more than 1 primary key field: " + currentValue);                    }                }                try {                    if (useTryInsertMethod) {                        // this technique is faster for data sets where most, if not all, values do not already exist in the database                        try {                            currentValue.create();                        } catch (GenericEntityException e1) {                            // create failed, try a store, if that fails too we have a real error and the catch outside of this should handle it                            currentValue.store();                        }                    } else {                        valuesToWrite.add(currentValue);                        if (valuesToWrite.size() >= valuesPerWrite) {                            writeValues(valuesToWrite);                            valuesToWrite.clear();                        }                    }                    numberRead++;                    if ((numberRead % valuesPerMessage) == 0) {                        Debug.logImportant("Another " + valuesPerMessage + " values imported: now up to " + numberRead, module);                    }                    currentValue = null;                } catch (GenericEntityException e) {                    String errMsg = "Error storing value";                    Debug.logError(e, errMsg, module);                    throw new SAXException(errMsg, e);                }            }        }    }    public void endPrefixMapping(CharSequence prefix) throws org.xml.sax.SAXException {}    public void ignorableWhitespace(char[] values, int offset, int count) throws org.xml.sax.SAXException {        // String value = new String(values, offset, count);        // Debug.logInfo("ignorableWhitespace: value=" + value, module);    }    public void processingInstruction(CharSequence target, CharSequence instruction) throws org.xml.sax.SAXException {}    public void setDocumentLocator(org.xml.sax.Locator locator) {        this.locator = locator;    }    public void skippedEntity(CharSequence name) throws org.xml.sax.SAXException {}    public void startDocument() throws org.xml.sax.SAXException {}    public void startElement(CharSequence namepsaceURI, CharSequence localName, CharSequence fullName, Attributes attributes) throws org.xml.sax.SAXException {        if (Debug.verboseOn()) Debug.logVerbose("startElement: localName=" + localName + ", fullName=" + fullName + ", attributes=" + attributes, module);        String fullNameString = fullName.toString();        if ("entity-engine-xml".equals(fullNameString)) {            // check the maintain-timestamp flag            CharSequence maintainTx = attributes.getValue("maintain-timestamps");            if (maintainTx != null) {                this.setMaintainTxStamps("true".equalsIgnoreCase(maintainTx.toString()));            }            // check the do-cache-clear flag            CharSequence doCacheClear = attributes.getValue("do-cache-clear");            if (doCacheClear != null) {                this.setDoCacheClear("true".equalsIgnoreCase(doCacheClear.toString()));            }            // check the disable-eeca flag            CharSequence ecaDisable = attributes.getValue("disable-eeca");            if (ecaDisable != null) {                this.setDisableEeca("true".equalsIgnoreCase(ecaDisable.toString()));            }            // check the use-dummy-fk flag            CharSequence dummyFk = attributes.getValue("create-dummy-fk");            if (dummyFk != null) {                this.setCreateDummyFks("true".equalsIgnoreCase(dummyFk.toString()));            }            return;        }        if ("entity-engine-transform-xml".equals(fullNameString)) {            templatePath = attributes.getValue("template");            isParseForTemplate = true;            documentForTemplate = UtilXml.makeEmptyXmlDocument();            return;        }        if (isParseForTemplate) {            Element newElement = this.documentForTemplate.createElement(fullNameString);            int length = attributes.getLength();            for (int i = 0; i < length; i++) {                CharSequence name = attributes.getLocalName(i);                CharSequence value = attributes.getValue(i);                if (name == null || name.length() == 0) {                    name = attributes.getQName(i);                }                newElement.setAttribute(name.toString(), value.toString());            }            if (this.currentNodeForTemplate == null) {                this.currentNodeForTemplate = newElement;                this.rootNodeForTemplate = newElement;            } else {                this.currentNodeForTemplate.appendChild(newElement);                this.currentNodeForTemplate = newElement;            }            return;        }        if (currentValue != null) {            // we have a nested value/CDATA element            currentFieldName = fullName;        } else {            String entityName = fullNameString;            // if a dash or colon is in the tag name, grab what is after it            if (entityName.indexOf('-') > 0) {                entityName = entityName.substring(entityName.indexOf('-') + 1);            }            if (entityName.indexOf(':') > 0) {                entityName = entityName.substring(entityName.indexOf(':') + 1);            }            try {                currentValue = delegator.makeValue(entityName, null);                // TODO: do we really want this? it makes it so none of the values imported have create/update timestamps set                // DEJ 10/16/04 I think they should all be stamped, so commenting this out                // JAZ 12/10/04 I think it should be specified when creating the reader                if (this.maintainTxStamps) {                    currentValue.setIsFromEntitySync(true);                }            } catch (Exception e) {                Debug.logError(e, module);            }            if (currentValue != null) {                int length = attributes.getLength();                for (int i = 0; i < length; i++) {                    CharSequence name = attributes.getLocalName(i);                    CharSequence value = attributes.getValue(i);                    if (name == null || name.length() == 0) {                        name = attributes.getQName(i);                    }                    try {                        // treat empty strings as nulls                        if (value != null && value.length() > 0) {                            if (currentValue.getModelEntity().isField(name.toString())) {                                currentValue.setString(name.toString(), value.toString());                            } else {                                Debug.logWarning("Ignoring invalid field name [" + name + "] found for the entity: " + currentValue.getEntityName() + " with value=" + value, module);                            }                        }                    } catch (Exception e) {                        Debug.logWarning(e, "Could not set field " + entityName + "." + name + " to the value " + value, module);                    }                }            }        }    }    //public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException {}    public void startPrefixMapping(CharSequence arg0, CharSequence arg1) throws SAXException {}    // ======== ErrorHandler interface implementations ========    public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException {        Debug.logWarning(exception, "Error reading XML on line " + exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);    }    public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException {        Debug.logError(exception, "Fatal Error reading XML on line " + exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);        throw new SAXException("Fatal Error reading XML on line " + exception.getLineNumber() + ", column " + exception.getColumnNumber(), exception);    }    public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException {        Debug.logWarning(exception, "Warning reading XML on line " + exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -