📄 xmldsdump.jsp
字号:
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"))); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.println("<entity-engine-xml>"); Iterator i = passedEntityNames.iterator(); while(i.hasNext()) { boolean beganTransaction = TransactionUtil.begin(3600); try { String curEntityName = (String)i.next(); EntityListIterator values = delegator.findListIteratorByCondition(curEntityName, entityDateCond, null, null, UtilMisc.toList("-createdTxStamp"), efo); GenericValue value = null; long curNumberWritten = 0; while ((value = (GenericValue) values.next()) != null) { value.writeXmlText(writer, ""); numberWritten++; curNumberWritten++; if (curNumberWritten % 500 == 0 || curNumberWritten == 1) { Debug.log("Records written [" + curEntityName + "]: " + curNumberWritten + " Total: " + numberWritten); } } values.close(); Debug.log("Wrote [" + curNumberWritten + "] from entity : " + curEntityName); TransactionUtil.commit(beganTransaction); } catch (Exception e) { String errMsg = "Error reading data for XML export:"; Debug.logError(e, errMsg, "JSP"); TransactionUtil.rollback(beganTransaction, errMsg, e); } } writer.println("</entity-engine-xml>"); writer.close(); Debug.log("Total records written from all entities: " + numberWritten); } // multiple files in a directory Collection results = new ArrayList(); int fileNumber = 1; if (outpath != null){ File outdir = new File(outpath); if(!outdir.exists()){ outdir.mkdir(); } if(outdir.isDirectory() && outdir.canWrite()) { Iterator i= passedEntityNames.iterator(); while(i.hasNext()) { numberWritten = 0; String curEntityName = (String)i.next(); String fileName = preConfiguredSetName != null ? UtilFormatOut.formatPaddedNumber((long) fileNumber, 3) + "_" : ""; fileName = fileName + curEntityName; EntityListIterator values = null; boolean beganTransaction = false; try{ beganTransaction = TransactionUtil.begin(3600); ModelEntity me = delegator.getModelEntity(curEntityName); if (me instanceof ModelViewEntity) { results.add("["+fileNumber +"] [vvv] " + curEntityName + " skipping view entity"); continue; } values = delegator.findListIteratorByCondition(curEntityName, entityDateCond, null, null, me.getPkFieldNames(), efo); boolean isFirst = true; PrintWriter writer = null; int fileSplitNumber = 1; GenericValue value = null; while ((value = (GenericValue) values.next()) != null) { //Don't bother writing the file if there's nothing //to put into it if (isFirst) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, fileName +".xml")), "UTF-8"))); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.println("<entity-engine-xml>"); isFirst = false; } value.writeXmlText(writer, ""); numberWritten++; // split into small files if ((maxRecordsPerFile > 0) && (numberWritten % maxRecordsPerFile == 0)) { fileSplitNumber++; // close the file writer.println("</entity-engine-xml>"); writer.close(); // create a new file String splitNumStr = UtilFormatOut.formatPaddedNumber((long) fileSplitNumber, 3); writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, fileName + "_" + splitNumStr +".xml")), "UTF-8"))); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.println("<entity-engine-xml>"); } if (numberWritten % 500 == 0 || numberWritten == 1) { Debug.log("Records written [" + curEntityName + "]: " + numberWritten); } } if (writer != null) { writer.println("</entity-engine-xml>"); writer.close(); String thisResult = "["+fileNumber +"] [" + numberWritten + "] " + curEntityName + " wrote " + numberWritten + " records"; Debug.log(thisResult); results.add(thisResult); } else { String thisResult = "["+fileNumber +"] [---] " + curEntityName + " has no records, not writing file"; Debug.log(thisResult); results.add(thisResult); } values.close(); } catch (Exception ex) { if (values != null) { values.close(); } String thisResult = "["+fileNumber +"] [xxx] Error when writing " + curEntityName + ": " + ex; Debug.log(thisResult); results.add(thisResult); TransactionUtil.rollback(beganTransaction, thisResult, ex); } finally { // only commit the transaction if we started one... this will throw an exception if it fails TransactionUtil.commit(beganTransaction); } fileNumber++; } } }%> <div class="head1">XML Export from DataSource(s)</div> <div class="tabletext">This page can be used to export data from the database. The exported documents will have a root tag of "<entity-engine-xml>".</div> <hr/> <%if(security.hasPermission("ENTITY_MAINT", session)) {%> <div class="head2">Results:</div> <%if(filename != null && filename.length() > 0 && numberOfEntities > 0) {%> <div class="tabletext">Wrote XML for all data in <%=numberOfEntities%> entities.</div> <div class="tabletext">Wrote <%=numberWritten%> records to XML file <%=filename%></div> <%} else if (outpath != null && numberOfEntities > 0) {%> <%Iterator re = results.iterator();%> <%while (re.hasNext()){%> <div class="tabletext"><%=(String)re.next()%> </div> <%}%> <%} else {%> <div class="tabletext">No filename specified or no entity names specified, doing nothing.</div> <%}%> <hr/> <div class="head2">Export:</div> <form method="post" action="<ofbiz:url>/xmldsdump</ofbiz:url>" name="entityExport"> <div class="tabletext">Output Directory : <input type="text" class="inputBox" size="60" name="outpath" value="<%=UtilFormatOut.checkNull(outpath)%>"/></div> <div class="tabletext">Max Records Per File : <input type="text" class="inputBox" size="10" name="maxrecords"/></div> <div class="tabletext">Single Filename : <input type="text" class="inputBox" size="60" name="filename" value="<%=UtilFormatOut.checkNull(filename)%>"/></div> <div class="tabletext">Records Updated Since : <input type="text" class="inputBox" size="25" name="entityFrom" /> <a href="javascript:call_cal(document.entityExport.entityFrom, null);"><img src='/images/cal.gif' width='16' height='16' border='0' alt='Click here For Calendar'></a> </div> <div class="tabletext">Records Updated Before : <input type="text" class="inputBox" size="25" name="entityThru" /> <a href="javascript:call_cal(document.entityExport.entityThru, null);"><img src='/images/cal.gif' width='16' height='16' border='0' alt='Click here For Calendar'></a> </div> <div class="tabletext">OR Out to Browser: <input type="checkbox" name="tobrowser" <%=tobrowser?"checked":""%>></div> <br/> <div class="tabletext">Entity Names:</div> <input type="submit" value="Export"/> <a href="<ofbiz:url>/xmldsdump?checkAll=true</ofbiz:url>" class="buttontext">Check All</a> <a href="<ofbiz:url>/xmldsdump</ofbiz:url>" class="buttontext">Un-Check All</a> <div class="tabletext">Entity Sync Dump: <input name="entitySyncId" class="inputBox" size="30" value="<%=UtilFormatOut.checkNull(entitySyncId)%>"/> </div> Pre-configured set: <select name="preConfiguredSetName"> <option value="">None</option> <option value="CatalogExport">Catalog Export</option> <option value="Product1">Product Part 1</option> <option value="Product2">Product Part 2</option> <option value="Product3">Product Part 3</option> <option value="Product4">Product Part 4</option> </select> <br/> <table> <tr> <%Iterator iter = entityNames.iterator();%> <%int entCount = 0;%> <%while(iter.hasNext()) {%> <%String curEntityName = (String)iter.next();%> <%if(entCount % 3 == 0) {%></TR><TR><%}%> <%entCount++;%> <%-- don't check view entities... --%> <%boolean check = checkAll;%> <%if (check) {%> <%ModelEntity curModelEntity = delegator.getModelEntity(curEntityName);%> <%if (curModelEntity instanceof ModelViewEntity) check = false;%> <%}%> <td><div class="tabletext"><input type="checkbox" name="entityName" value="<%=curEntityName%>" <%=check?"checked":""%>/><%=curEntityName%></div></td> <%}%> </tr> </table> <input type="submit" value="Export"> <A href="<ofbiz:url>/xmldsdump?checkAll=true</ofbiz:url>" class="buttontext">Check All</A> <A href="<ofbiz:url>/xmldsdump</ofbiz:url>" class="buttontext">Un-Check All</A> </form> <%} else {%> <div class="tabletext">You do not have permission to use this page (ENTITY_MAINT needed)</div> <%}%><%}%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -