📄 uisqlfilewriter.java
字号:
/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.ui;
import com.sourcetap.sfa.util.StringHelper;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelField;
import org.ofbiz.entity.model.ModelUtil;
import org.ofbiz.base.util.Debug;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
/**
* DOCUMENT ME!
*
*/
public class UISQLFileWriter {
public static final String module = UISQLFileWriter.class.getName();
/* public static void main (String[] argument) {
if (argument.length != 3) {
Debug.logError("Usage:", module);
Debug.logError("UIGenerateSQL <party ID> <screen name like> <path>", module);
return;
}
String partyId = argument[0];
String screenName = argument[1];
String filePath = argument[2];
UIGenerateScreenSQL uIGenerateScreenSQL = new UIGenerateScreenSQL();
GenericDelegator delegator = new GenericDelegator("UIGenerateScreenSQLDelegator");
uIGenerateScreenSQL.writeUiScreenSql(delegator, partyId, screenName, filePath);
return;
}
*/
public String writeUiScreenFile(GenericDelegator delegator, String partyId,
String screenId, String filePath) {
HashMap findHashMap = new HashMap();
ArrayList findOrder = null;
ModelEntity modelEntity = null;
GenericValue genericValue = null;
String entityName = "";
String resultString = "";
try {
// Open the file, and replace any existing contents.
FileWriter tempFile = new FileWriter(filePath, false);
BufferedWriter outputFile = new BufferedWriter(tempFile);
////////////////////
// Write out the SQL for inserting the screen.
////////////////////
List screenGVL = null;
findHashMap = new HashMap();
findHashMap.put("screenId", screenId);
findOrder = new ArrayList();
findOrder.add("screenId");
screenGVL = writeSqlInserts("UiScreen", findHashMap, findOrder,
delegator, outputFile);
if (screenGVL.size() <= 0) {
return "No screen found with ID \"" + screenId + "\"";
} else {
resultString += (String.valueOf(screenGVL.size()) +
" screens<BR>\n");
}
////////////////////
// Write out the SQL for inserting the screen sections.
////////////////////
// Loop through the screens. (Should be only one.)
Iterator screenGVI = screenGVL.iterator();
List screenSectionGVL = new LinkedList();
while (screenGVI.hasNext()) {
GenericValue screenGV = (GenericValue) screenGVI.next();
findHashMap = new HashMap();
findHashMap.put("screenId", screenGV.getString("screenId"));
findOrder = new ArrayList();
findOrder.add("sectionId");
screenSectionGVL.addAll(writeSqlInserts("UiScreenSection",
findHashMap, findOrder, delegator, outputFile));
}
resultString += (String.valueOf(screenSectionGVL.size()) +
" sections<BR>\n");
screenGVI = null;
////////////////////
// Write out the SQL for inserting the screen section entities and screen section infos (fields).
////////////////////
Iterator screenSectionGVI = screenSectionGVL.iterator();
List screenSectionEntityGVL = new LinkedList();
List screenSectionInfoGVL = new LinkedList();
while (screenSectionGVI.hasNext()) {
GenericValue screenSectionGV = (GenericValue) screenSectionGVI.next();
findHashMap = new HashMap();
findHashMap.put("sectionId",
screenSectionGV.getString("sectionId"));
findOrder = new ArrayList();
findOrder.add("entityId");
screenSectionEntityGVL.addAll(writeSqlInserts(
"UiScreenSectionEntity", findHashMap, findOrder,
delegator, outputFile));
findHashMap = new HashMap();
findHashMap.put("sectionId",
screenSectionGV.getString("sectionId"));
findHashMap.put("partyId", partyId);
findOrder = new ArrayList();
findOrder.add("attributeId");
screenSectionInfoGVL.addAll(writeSqlInserts(
"UiScreenSectionInfo", findHashMap, findOrder,
delegator, outputFile));
}
resultString += (String.valueOf(screenSectionEntityGVL.size()) +
" section entities<BR>\n");
resultString += (String.valueOf(screenSectionInfoGVL.size()) +
" section fields");
screenSectionGVI = null;
outputFile.close();
return resultString;
} catch (IOException e) {
Debug.logError(
"[UISQLFileWriter.writeUiScreenSql]: IO Exception - Error was:", module);
Debug.logError(e.getMessage(), module);
return e.getMessage();
} catch (SecurityException se) {
Debug.logError(
"[UISQLFileWriter.writeUiScreenSql]: Security Exception - Error was:", module);
Debug.logError(se.getMessage(), module);
return se.getMessage();
}
}
/**
* DOCUMENT ME!
*
* @param delegator
* @param displayObjectId
* @param filePath
*
* @return
*/
public String writeUiDisplayObjectFile(GenericDelegator delegator,
String displayObjectId, String filePath) {
HashMap findHashMap = new HashMap();
ArrayList findOrder = null;
ModelEntity modelEntity = null;
GenericValue genericValue = null;
String entityName = "";
String resultString = "";
try {
// Open the file, and replace any existing contents.
FileWriter tempFile = new FileWriter(filePath, false);
BufferedWriter outputFile = new BufferedWriter(tempFile);
////////////////////
// Write out the SQL for inserting the display object.
////////////////////
List uiDisplayObjectGVL = null;
findHashMap = new HashMap();
findHashMap.put("displayObjectId", displayObjectId);
findOrder = new ArrayList();
findOrder.add("displayObjectId");
uiDisplayObjectGVL = writeSqlInserts("UiDisplayObject",
findHashMap, findOrder, delegator, outputFile);
if (uiDisplayObjectGVL.size() <= 0) {
return "No display object found with ID \"" + displayObjectId +
"\"";
} else {
resultString += (String.valueOf(uiDisplayObjectGVL.size()) +
" display objects<BR>\n");
}
////////////////////
// Write out the SQL for inserting the display object attributes.
////////////////////
// Loop through the display objects. (Should be only one).
Iterator displayObjectGVI = uiDisplayObjectGVL.iterator();
List uiDisplayObjectAttribGVL = new LinkedList();
while (displayObjectGVI.hasNext()) {
GenericValue uiDisplayObjectGV = (GenericValue) displayObjectGVI.next();
findHashMap = new HashMap();
findHashMap.put("displayObjectId",
uiDisplayObjectGV.getString("displayObjectId"));
findOrder = new ArrayList();
findOrder.add("displayObjectId");
findOrder.add("displayAttribId");
uiDisplayObjectAttribGVL.addAll(writeSqlInserts(
"UiDisplayObjectAttrib", findHashMap, findOrder,
delegator, outputFile));
}
resultString += (String.valueOf(uiDisplayObjectAttribGVL.size()) +
" display object attributes<BR>\n");
displayObjectGVI = null;
outputFile.close();
return resultString;
} catch (IOException e) {
Debug.logError(
"[UISQLFileWriter.writeUiDisplayObjectSql]: IO Exception - Error was:", module);
Debug.logError(e.getMessage(), module);
return e.getMessage();
} catch (SecurityException se) {
Debug.logError(
"[UISQLFileWriter.writeUiDisplayObjectSql]: Security Exception - Error was:", module);
Debug.logError(se.getMessage(), module);
return se.getMessage();
}
}
/**
* DOCUMENT ME!
*
* @param delegator
* @param displayTypeId
* @param filePath
*
* @return
*/
public String writeUiDisplayTypeFile(GenericDelegator delegator,
String displayTypeId, String filePath) {
HashMap findHashMap = new HashMap();
ArrayList findOrder = null;
ModelEntity modelEntity = null;
GenericValue genericValue = null;
String entityName = "";
String resultString = "";
try {
// Open the file, and replace any existing contents.
FileWriter tempFile = new FileWriter(filePath, false);
BufferedWriter outputFile = new BufferedWriter(tempFile);
////////////////////
// Write out the SQL for inserting the display type.
////////////////////
List uiDisplayTypeGVL = null;
findHashMap = new HashMap();
findHashMap.put("displayTypeId", displayTypeId);
findOrder = new ArrayList();
findOrder.add("displayTypeId");
uiDisplayTypeGVL = writeSqlInserts("UiDisplayType", findHashMap,
findOrder, delegator, outputFile);
if (uiDisplayTypeGVL.size() <= 0) {
return "No display type found with ID \"" + displayTypeId +
"\"";
} else {
resultString += (String.valueOf(uiDisplayTypeGVL.size()) +
" display types<BR>\n");
}
////////////////////
// Write out the SQL for inserting the display attributes.
////////////////////
// Loop through the display types. (Should be only one).
Iterator displayTypeGVI = uiDisplayTypeGVL.iterator();
List uiDisplayAttribGVL = new LinkedList();
while (displayTypeGVI.hasNext()) {
GenericValue displayTypeGV = (GenericValue) displayTypeGVI.next();
findHashMap = new HashMap();
findHashMap.put("displayTypeId",
displayTypeGV.getString("displayTypeId"));
findOrder = new ArrayList();
findOrder.add("displayTypeId");
findOrder.add("displayAttribId");
uiDisplayAttribGVL.addAll(writeSqlInserts("UiDisplayAttrib",
findHashMap, findOrder, delegator, outputFile));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -