<%-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --%> <%@ page import="java.util.*, java.io.*, java.net.*" %> <%@ page import="org.w3c.dom.*" %> <%@ page import="org.ofbiz.security.*, org.ofbiz.entity.*, org.ofbiz.base.util.*, org.ofbiz.webapp.pseudotag.*" %> <%@ page import="org.ofbiz.entity.model.*, org.ofbiz.entity.util.*, org.ofbiz.entity.transaction.*, org.ofbiz.entity.condition.*" %> <%@ taglib uri="ofbizTags" prefix="ofbiz" %> <% String outpath = request.getParameter("outpath"); String filename = request.getParameter("filename"); String maxRecStr = request.getParameter("maxrecords"); String entitySyncId = request.getParameter("entitySyncId"); String[] entityName = request.getParameterValues("entityName"); String entityFrom = request.getParameter("entityFrom"); String entityThru = request.getParameter("entityThru"); // get the max records per file setting and convert to a int int maxRecordsPerFile = 0; if (UtilValidate.isNotEmpty(maxRecStr)) { try { maxRecordsPerFile = Integer.parseInt(maxRecStr); } catch (Exception e) { } } Set passedEntityNames = new TreeSet(); if (entityName != null && entityName.length > 0) { for(int inc=0; inc <%if (tobrowser) { session.setAttribute("xmlrawdump_entitylist", entityName); session.setAttribute("entityDateCond", entityDateCond); %>
XML Export from DataSource(s)
This page can be used to export data from the database. The exported documents will have a root tag of "<entity-engine-xml>".

<%if(security.hasPermission("ENTITY_MAINT", session)) {%> Click Here to Get Data (or save to file) <%} else {%>
You do not have permission to use this page (ENTITY_MAINT needed)
<%}%> <%} else {%> <% EntityFindOptions efo = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); ModelReader reader = delegator.getModelReader(); Collection ec = reader.getEntityNames(); TreeSet entityNames = new TreeSet(ec); int numberOfEntities = passedEntityNames.size(); long numberWritten = 0; // single file if(filename != null && filename.length() > 0 && numberOfEntities > 0) { PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"))); writer.println(""); writer.println(""); Iterator i = passedEntityNames.iterator(); while(i.hasNext()) { boolean beganTransaction = TransactionUtil.begin(3600); try { String curEntityName = (String)i.next(); EntityListIterator values = delegator.find(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(""); 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.find(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(""); writer.println(""); isFirst = false; } value.writeXmlText(writer, ""); numberWritten++; // split into small files if ((maxRecordsPerFile > 0) && (numberWritten % maxRecordsPerFile == 0)) { fileSplitNumber++; // close the file writer.println(""); 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(""); writer.println(""); } if (numberWritten % 500 == 0 || numberWritten == 1) { Debug.log("Records written [" + curEntityName + "]: " + numberWritten); } } if (writer != null) { writer.println(""); 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++; } } } %>
XML Export from DataSource(s)
This page can be used to export data from the database. The exported documents will have a root tag of "<entity-engine-xml>".

<%if(security.hasPermission("ENTITY_MAINT", session)) {%>
Results:
<%if(filename != null && filename.length() > 0 && numberOfEntities > 0) {%>
Wrote XML for all data in <%=numberOfEntities%> entities.
Wrote <%=numberWritten%> records to XML file <%=filename%>
<%} else if (outpath != null && numberOfEntities > 0) {%> <%Iterator re = results.iterator();%> <%while (re.hasNext()){%>
<%=(String)re.next()%>
<%}%> <%} else {%>
No filename specified or no entity names specified, doing nothing.
<%}%>
Export:
Output Directory :
Max Records Per File :
Single Filename  :
Records Updated Since  : Click here For Calendar
Records Updated Before  : Click here For Calendar
OR Out to Browser: >

Entity Names:
Check All Un-Check All
Entity Sync Dump:
Pre-configured set:
<%Iterator iter = entityNames.iterator();%> <%int entCount = 0;%> <%while(iter.hasNext()) {%> <%String curEntityName = (String)iter.next();%> <%if(entCount % 3 == 0) {%><%}%> <%entCount++;%> <%-- don't check view entities... --%> <%boolean check = checkAll;%> <%if (check) {%> <%ModelEntity curModelEntity = delegator.getModelEntity(curEntityName);%> <%if (curModelEntity instanceof ModelViewEntity) check = false;%> <%}%> <%}%>
/><%=curEntityName%>
Check All Un-Check All
<%} else {%>
You do not have permission to use this page (ENTITY_MAINT needed)
<%}%> <%}%>