📄 form.java
字号:
ArrayList ready = new ArrayList();
String str;
int pos1, pos2;
do {
pos1 = content.indexOf("<%");
pos2 = content.indexOf("%>");
if (pos1 < pos2) {
String tmp = content.substring(0, pos1);
// tmp = StringUtil.replace(tmp, "\"", "\\\"");//
// tmp.replaceAll("\"","\\\"");
// tmp = StringUtil.replace(tmp, "\r\n", "\\r\\n");
// ready.append("$HTML.append(\"");
ready.add(tmp);
// ready.append("\");\r\n");
str = content.substring(pos1 + 2, pos2);
ready.add(new CalculatePart(str));
// ready.append("\r\n");
content = content.substring(pos2 + 2, content.length());
} else {
if (pos2 > 0) {
String tmp = content.substring(0, pos2);
// tmp = StringUtil.replace(tmp, "\"", "\\\"");//
// tmp.replaceAll("\"","\\\"");
// tmp = StringUtil.replace(tmp, "\r\n", "\\r\\n");
// ready.append("$HTML.append(\"");
ready.add(tmp);
// ready.append("\");\r\n");
content = content.substring(pos2, content.length());
}
}
} while (pos1 > 0 && pos2 > 0);
// content = StringUtil.replace(content, "\"", "\\\"");//
// tmp.replaceAll("\"","\\\"");
// content = StringUtil.replace(content, "\r\n", "\\r\\n");
// while (content.length() > 0) {
// ready.append("$HTML.append(\"");
// int posSplit = 20480;
// posSplit = content.indexOf(" ", posSplit);
//
// if (content.length() > posSplit && posSplit > 0) {
// ready.append(content.substring(0, posSplit));
// content = content.substring(posSplit);
// } else {
// ready.append(content);
// content = "";
// }
//
// ready.append("\");\r\n");
//
// }
ready.add(content);
// return ready.toString();
return ready;
}
/**
* 根据输入的String返回Form实例
*
* @param formStr
* @return cn.myapps.core.dynaform.form.ejb.Form
* @roseuid 41EBCFDC020A
*/
public Form newFormInstance(String formStr) {
return null;
}
/**
* 添加Field
*
* @param field
* @roseuid 41EBD8340067
*/
public void addField(FormField field) {
if (field != null) {
if (field.getName() == null || field.getName().length() <= 0) {
try {
field.setName(Sequence.getSequence() + "");
} catch (Exception e) {
}
}
_fields.put(field.getName(), field);
_elements.add(field);
field.set_form(this);
}
}
public void addTextpart(Textpart textpart) {
_textparts.add(textpart);
_elements.add(textpart);
}
public void removeTextpart(Textpart textpart) {
_textparts.remove(textpart);
_elements.remove(textpart);
}
public void removeField(String fieldname) {
if (fieldname != null) {
FormField field = (FormField) _fields.get(fieldname);
if (field != null) {
_fields.remove(field.getName());
_elements.remove(field);
}
}
}
public Collection getFields() {
return _fields.values();
}
public Collection getFieldsIncludeTab() {
Collection rtn = new ArrayList();
Collection fields = _fields.values();
try {
rtn = deepSearchFields(fields);
} catch (Exception e) {
e.printStackTrace();
}
return rtn;
}
public Collection deepSearchFields(Collection fields) throws Exception {
Collection rtn = new ArrayList();
for (Iterator iter = fields.iterator(); iter.hasNext();) {
FormField field = (FormField) iter.next();
if (field instanceof TagField) {
Collection forms = ((TagField) field).getForms();
for (Iterator iterator = forms.iterator(); iterator.hasNext();) {
Form form = (Form) iterator.next();
if (!this.getId().equals(form.getId())) {
rtn.addAll(deepSearchFields(form.getFields()));
}
}
} else {
rtn.add(field);
}
}
return rtn;
}
/**
* 移除field
*
* @param field
* @roseuid 41EBD8890308
*/
public void removeField(FormField field) {
if (field != null) {
_fields.remove(field.getName());
_elements.remove(field);
}
}
/**
* 获取Field
*
* @param fieldname
* @return cn.myapps.core.dynaform.form.ejb.FormField
* @roseuid 41EBDCA70051
*/
public FormField findField(String fieldname) {
return (FormField) _fields.get(fieldname);
}
public Document createDocument(ParamsTable params, WebUser user)
throws Exception {
return createDocument(null, params, user);
}
/**
* 创建新文档
*
* @param params
* @param user
* @return
* @throws Exception
*/
public Document createDocument(Document doc, ParamsTable params,
WebUser user) throws Exception {
return createDocument(doc, params, true, user);
}
public Document createDocument(Document doc, ParamsTable params,
boolean calcAll, WebUser user) throws Exception {
return createDocument(doc, params, true, user, null);
}
public Document createDocument(Document doc, ParamsTable params,
boolean calcAll, WebUser user, BillDefiVO flowVO) throws Exception {
if (doc == null) {
doc = new Document();
}
doc.setLastmodified(new Date());
long start = System.currentTimeMillis();
String p = params.getParameterAsString("id");
if (p != null && CommonUtil.isNumberString(p)) {
doc.setId(p);
}
System.out.println("Create Doc SETP-1 times->"
+ (System.currentTimeMillis() - start) + "(ms)");
doc.setFormid(id);
String formname = getName();
ModuleVO mv = getModule();
if (mv != null) {
formname = mv.getName() + "/" + formname;
while (mv.getSuperior() != null) {
mv = mv.getSuperior();
formname = mv.getName() + "/" + formname;
}
formname = mv.getApplication().getName() + "/" + formname;
}
doc.setFormname(formname);
// 如果为新文档,则给出新序列号
String isnew = params.getParameterAsString("_new");
if (isnew != null && isnew.equals("true"))
doc.set_new(true);
Date auditdate = params.getParameterAsDate("auditdate");
if (auditdate != null) {
doc.setAuditdate(auditdate); // 设置审计日期
}
String audituser = params.getParameterAsString("audituser");
if (audituser != null && audituser.trim().length() > 0) {
doc.setAudituser(audituser); // 设置审计者
}
String auditusers = params.getParameterAsString("auditusers");
if (auditusers != null && auditusers.trim().length() > 0) {
doc.setAuditusers(auditusers); // 设置所有审计者
}
System.out.println("Create Doc SETP-3 times->"
+ (System.currentTimeMillis() - start) + "(ms)");
Collection fields = deepSearchFields(getFields());
// 创建Field
Iterator iter = fields.iterator();
// Collection itemsColls = new ArrayList();
while (iter.hasNext()) {
FormField field = (FormField) iter.next();
// field.setIssubformvalue(this.getIssubform());
if (field == null || field.getFieldtype() == null) {
continue;
}
if (!field.getFieldtype().equals(Item.VALUE_TYPE_INCLUDE)) {
Item item = null;
if (field.getFieldtype().equals(Item.VALUE_TYPE_VARCHAR))
item = field.createItem(doc, params
.getParameterAsString(field.getName()));
else if (field.getFieldtype().equals(Item.VALUE_TYPE_NUMBER))
item = field.createItem(doc, params
.getParameterAsDouble(field.getName()));
else if (field.getFieldtype().equals(Item.VALUE_TYPE_DATE))
item = field.createItem(doc, params
.getParameterAsDate(field.getName()));
else if (field.getFieldtype().equals(Item.VALUE_TYPE_TEXT))
item = field.createItem(doc, params
.getParameterAsText(field.getName()));
else
item = field.createItem(doc, params
.getParameterAsString(field.getName()));
// item.setDocid(doc.getId()); //设置Doc id使其与doc相对应
item.setDocument(doc);
item.setType(field.getFieldtype());
item.setFormname(formname); // 设置item所属的form name
String itemName = item.getName();
Item tmp = doc.findItem(itemName);
if (tmp != null) {
item.setId(tmp.getId());
} else {
if (item.getId() == null || item.getId().length() <= 0) {
try {
item.setId(Sequence.getSequence());
} catch (Exception e) {
}
}
}
doc.addItem(item); // 在doc中增加此item
}
}
System.out.println("Create Doc SETP-4 times->"
+ (System.currentTimeMillis() - start) + "(ms)");
setFieldpermlist(doc, flowVO, user);
System.out.println("Create Doc SETP-5 times->"
+ (System.currentTimeMillis() - start) + "(ms)");
changeFieldType(fields, doc, params, user);
System.out.println("Create Doc SETP-6 times->"
+ (System.currentTimeMillis() - start) + "(ms)");
recalculateDocument(doc, params, calcAll, user);
return doc;
}
/**
* 为Document设置权限
*
* @param doc
* @param flowid
* @param webUser
* @return
* @throws Exception
*/
public static void setFieldpermlist(Document doc, BillDefiVO flowVO,
WebUser user) throws Exception {
NodeRT nodert = null;
String fieldpermlist = "";
if (flowVO != null) {
if (doc.getId() != null && !(doc.getId()).equals("")) {
nodert = StateMachineHelper.getCurrUserNodeRT(doc.getId(),
flowVO.getId(), user);
FlowDiagram fd = flowVO.toFlowDiagram();
if (nodert != null) {
Element element = fd.getElementByID(nodert.getNodeid());
if (element instanceof ManualNode) {
ManualNode node = ((ManualNode) element);
fieldpermlist = node.fieldpermlist;
}
}
} else {
Collection firstNodeList = StateMachine.getFirstNodeList(doc
.getId(), flowVO, user);
Iterator it = firstNodeList.iterator();
if (it.hasNext()) {
ManualNode node = (ManualNode) it.next();
fieldpermlist = node.fieldpermlist;
}
}
if (fieldpermlist != null && fieldpermlist.length() > 0) {
doc.setFieldPermList(FieldPermissionList.parser(fieldpermlist));
}
}
}
/**
* 改变Field类型并清空值(隐藏|原设)
*
* @param fields
* @param doc
* @param params
* @param user
* @return isChange
* @throws Exception
*/
public void changeFieldType(Collection fields, Document doc,
ParamsTable params, WebUser user) throws Exception {
JavaScriptRunner runner = JavaScriptRunner.getInstance();
runner.initBSFManager(doc, params, user, null, user.getApplicationid());
for (Iterator iter = fields.iterator(); iter.hasNext();) {
FormField field = (FormField) iter.next();
Item item = doc.findItem(field.getName());
if (item != null) {
if (field.getHiddenScript() != null
&& field.getHiddenScript().trim().length() > 0) {
boolean isHidden = field.runHiddenScript(runner, doc);
if (isHidden) {
item.setValue("");
item.setHidden(true);
} else {
item.setHidden(false);
}
item.setChanged(true);
continue;
} else if (field.getReadonlyScript() != null
&& field.getReadonlyScript().trim().length() > 0) {
boolean isReadonly = field.runReadonlyScript(runner, doc);
if (isReadonly) {
item.setValue("");
}
item.setChanged(true);
continue;
}
item.setChanged(false);
}
}
}
protected String processListFieldValueText(ParamsTable params,
Document doc, String listFieldName) throws Exception {
//
StringList sl = new StringList();
String command = params.getParameterAsString("COMMAND");
int rowno = StringUtil.isNumber(params.getParameterAsString("ROWNO")) ? Integer
.parseInt(params.getParameterAsString("ROWNO"))
: -1;
String value_item = doc.getItemValueAsString(listFieldName.substring(0,
listFieldName.length() - 1));// item.getVarcharvalue();
String value_list = params.getParameterAsString(listFieldName);// item_list.getVarcharvalue();
if (value_list != null) {
if (value_list.trim().length() > 0) {
sl.add(value_list);
}
}
if (command != null && command.equals("APPEND")) {
sl.add(value_item);
} else if (command != null && command.equals("MODIFY") && rowno >= 0) {
sl.replace(rowno, value_item);
} else if (command != null && command.equals("REMOVE") && rowno >= 0) {
if (rowno >= 0) {
sl.remove(rowno);
}
}
// }
return sl.toString();
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -