/*
* 创建日期 2005-8-9
*/
package com.yc.ycportal.util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import com.yc.base.util.UtilString;
import com.yc.ycportal.sourcedata.OriginField;
import com.yc.ycportal.view.InteractionconfView;
/**
* @author Administrator
*/
public class RWxmlFile {
private static Log log = LogFactory.getLog(RWxmlFile.class);
public List readXmlFile(String inFile) {
List list=new ArrayList();
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
db=dbf.newDocumentBuilder();
}
catch(ParserConfigurationException pce){
System.err.println(pce);
System.exit(1);
}
Document doc=null;
try{
doc=db.parse(inFile);
}
catch(Exception dom){
System.err.println(dom.getMessage());
System.exit(1);
}
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("field");
for(int i=0;i<nl.getLength();i++){
Element el=(Element)nl.item(i);
Object[] origin = new Object[9];
origin[0]=el.getAttribute("id");
origin[1]=el.getAttribute("cname");
origin[2]=el.getAttribute("dbtype");
origin[3]=el.getAttribute("javatype");
origin[4]=el.getAttribute("dblength");
origin[5]=el.getAttribute("showformat");
origin[6]=el.getAttribute("intomode");
origin[7]=el.getAttribute("showlength");
origin[8]=el.getAttribute("checkfunction");
list.add(origin);
}
return list;
}
public static String readXmlString(String inFile,String value,String tostr,String wantstr)throws Exception{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
String returnValue="";
try{
List list=new ArrayList();
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("field");
for(int i=0;i<nl.getLength();i++){
Element el=(Element)nl.item(i);
String[] str=new String[2];
str[0]=el.getAttribute(tostr);
str[1]=el.getAttribute(wantstr);
list.add(str);
}
for(int i=0;i<list.size();i++){
String[] str=(String[])list.get(i);
if(value.equals(str[0])){
returnValue=str[1];
}
}
}
catch(Exception e){
System.err.println(e);
return returnValue;
}
return returnValue;
}
public static List readAllXml(String inFile,String tagname,List str)throws Exception {
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
List list=new ArrayList();
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
int listsize=str.size();
NodeList nl=root.getElementsByTagName(tagname);
for(int i=0;i<nl.getLength();i++){
Element el=(Element)nl.item(i);
String[] returnstr=new String[listsize];
for(int j=0;j<listsize;j++){
returnstr[j]=el.getAttribute(str.get(j).toString());
}
list.add(returnstr);
}
return list;
}
catch(Exception e){
System.err.println(e);
return null;
}
}
public static List readAllXmlForInteraction(String inFile,String tagname,List str,List field)throws Exception {//读取所有interactions.xml
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
List list=new ArrayList();
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
int listsize=str.size();
int fieldsize=field.size();
NodeList nl=root.getElementsByTagName(tagname);
for(int i=0;i<nl.getLength();i++){
Element el=(Element)nl.item(i);
String[] returnstr=new String[listsize];
String[] fieldstr=new String[fieldsize];
for(int j=0;j<listsize;j++){
returnstr[j]=el.getAttribute(str.get(j).toString());
}
if(el.hasChildNodes()){
NodeList nodelist=el.getChildNodes();
for(int g=0;g<nodelist.getLength();g++){
Element e=(Element)nodelist.item(g);
fieldstr[g]=e.getAttribute(field.get(g).toString());
}
}
list.add(returnstr);
list.add(fieldstr);
}
return list;
}
catch(Exception e){
System.err.println(e);
return null;
}
}
public static InteractionconfView detailinterxml(String appnumber)throws Exception {//专为交互类明细用
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
String inFile=com.yc.ycportal.BaseConfig.getBasepath()+"/WEB-INF/classes/interations.xml";
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("interaction");
InteractionconfView view=new InteractionconfView();
int nlleng=nl.getLength();
for(int i=0;i<nlleng;i++){
Element el=(Element)nl.item(i);
if(el.getAttribute("appnumber").equals(appnumber)){
view.setAppnumber(el.getAttribute("appnumber"));
view.setAppcname(el.getAttribute("appname"));
view.setAppdescript(el.getAttribute("appdescript"));
view.setEntityname(el.getAttribute("entityname"));
view.setEntitycname(el.getAttribute("entitycname"));
view.setIsremark(el.getAttribute("isremark"));
view.setIscheckup(el.getAttribute("ischeckup"));
view.setBlockrows(el.getAttribute("blockrows"));
view.setPagerows(el.getAttribute("pagerows"));
view.setOrderfield(el.getAttribute("orderfield"));
view.setOrder(el.getAttribute("order"));
view.setLinkfield(el.getAttribute("linkfield"));
view.setInterblock(el.getAttribute("interblock"));
view.setInterlist(el.getAttribute("interlist"));
view.setInterdetail(el.getAttribute("interdetail"));
view.setIntereditdetail(el.getAttribute("intereditdetail"));
view.setPrimarykey(el.getAttribute("primarykey"));
view.setViewinfofilter(el.getAttribute("viewinfofilter"));
view.setEditinfofilter(el.getAttribute("editinfofilter"));
String fields="";
String childtabledata = "";
if(el.hasChildNodes()){
NodeList nodes = el.getChildNodes();
for(int j=0;j<nodes.getLength();j++){
Element fieldnode = (Element)nodes.item(j);
if ( "field".equals( fieldnode.getNodeName() ) ){
String ename="";
String cname="";
String isblocklist="";
String ispagelist="";
String isdetail="";
String iseditfield="";
String ishidden="";
String isnull="";
String fieldtype="";
String datatype="";
ename=fieldnode.getAttribute("fieldname");
cname=fieldnode.getAttribute("cname");
isblocklist=fieldnode.getAttribute("isblocklist");
ispagelist=fieldnode.getAttribute("ispagelist");
isdetail=fieldnode.getAttribute("isdetail");
iseditfield=fieldnode.getAttribute("iseditfield");
ishidden=fieldnode.getAttribute("ishidden");
isnull=fieldnode.getAttribute("isnull");
fieldtype=fieldnode.getAttribute("fieldtype");
datatype=fieldnode.getAttribute("datatype");
String comparestr="";
String queryfield="";
if(fieldnode.getAttribute("comparestr")!=null){
comparestr=fieldnode.getAttribute("comparestr");
queryfield=fieldnode.getAttribute("queryfield");
}
if("".equals(fields))
fields=ename+"|"+cname+"|"+isblocklist+"|"+ispagelist+
"|"+isdetail+"|"+
iseditfield+"|"+ishidden+"|"+isnull+"|"+fieldtype+"|"+datatype+"|"+comparestr+"|"+queryfield;
else fields=fields+","+ename+"|"+cname+"|"+isblocklist+"|"+ispagelist+
"|"+isdetail+"|"+
iseditfield+"|"+ishidden+"|"+isnull+"|"+fieldtype+"|"+datatype+"|"+comparestr+"|"+queryfield;
}
if ( "childtable".equals( fieldnode.getNodeName() ) ) {
NodeList childnodes = fieldnode.getChildNodes();
childtabledata += "★" + ((Element)childnodes).getAttribute("ename") +"-"+ ((Element)childnodes).getAttribute("cname") + "◆";
for(int g = 0 ; g < childnodes.getLength(); g ++ ) {
Element childfieldnodes = (Element) childnodes.item(g);
String ename="";
String cname="";
String isblocklist="";
String ispagelist="";
String isdetail="";
String iseditfield="";
String ishidden="";
String isnull="";
String fieldtype="";
String datatype="";
ename=childfieldnodes.getAttribute("fieldname");
cname=childfieldnodes.getAttribute("cname");
isblocklist=childfieldnodes.getAttribute("isblocklist");
ispagelist=childfieldnodes.getAttribute("ispagelist");
isdetail=childfieldnodes.getAttribute("isdetail");
iseditfield=childfieldnodes.getAttribute("iseditfield");
ishidden=childfieldnodes.getAttribute("ishidden");
isnull=childfieldnodes.getAttribute("isnull");
fieldtype=childfieldnodes.getAttribute("fieldtype");
datatype=childfieldnodes.getAttribute("datatype");
String comparestr="";
String queryfield="";
if(childfieldnodes.getAttribute("comparestr")!=null){
comparestr=childfieldnodes.getAttribute("comparestr");
queryfield=childfieldnodes.getAttribute("queryfield");
}
childtabledata +=ename+"|"+cname+"|"+isblocklist+"|"+ispagelist+
"|"+isdetail+"|"+
iseditfield+"|"+ishidden+"|"+isnull+"|"+fieldtype+"|"+datatype+"|"+comparestr+"|"+queryfield+",";
}
}
}
}
view.setFields(fields);
String tablesstr[] = new RWxmlFile().toTable(childtabledata);
view.setChildtabledata(tablesstr[0]);
view.setChildtables(tablesstr[1]);
}
}
return view;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
public String[] toTable ( String childtabledat ) {//拼接成界面上的表格
String tablesstr[] = new String[2];
tablesstr[1] = "";
StringBuffer tablestr = new StringBuffer();
tablestr .append ( "<table id=childentitytable border=0 width=100% class='divTiSkin' style='border-collapse:collapse;' cellpadding=0 cellspacing=0><tr><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>字段名1</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>中文名称</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>栏目列表字段</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>分页列表字段</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>内容展示字段</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>查询条件</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>内容编辑字段</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>隐藏</span></td><td style='background-color:#ccddff;border-top:1 solid white;border-right:1 solid #99B3CC'><span style='width:100%;height:100%;border-left:1 solid white'>非空</span></td></tr>" );
String childtabledata [] = UtilString.split( childtabledat , "★" );
for ( int j = 0 ; j < childtabledata.length ; j ++ ) {
String childtabledatas [] = UtilString.split( childtabledata[ j ] , "◆" );
if ( childtabledatas != null && childtabledatas.length>1 ) {
String tablename = childtabledatas[0];
tablesstr[1] += tablename+",";
tablestr.append("<tr id=");
tablestr.append(UtilString.split(tablename,"-")[0]);
tablestr.append(" name=");
tablestr.append(UtilString.split(tablename,"-")[0]);
tablestr.append(">");
tablestr.append("<td colSpan=9>");
tablestr.append("表名:");
tablestr.append(tablename);
tablestr.append("</td></tr>");
String[] newfields=UtilString.split(childtabledatas[1],",");
for(int i=0;i<newfields.length;i++){
String[] field=UtilString.split(newfields[i],"|");
String ename=field[0];
String cname=field[1];
String isblocklist=field[2];
if("1".equals(isblocklist)) isblocklist="checked";
String ispagelist=field[3];
if("1".equals(ispagelist)) ispagelist="checked";
String isdetail=field[4];
if("1".equals(isdetail)) isdetail="checked";
String iseditfield=field[5];
if("1".equals(iseditfield)) iseditfield="checked";
String ishidden=field[6];
if("1".equals(ishidden)) ishidden="checked";
String isnull=field[7];
if("1".equals(isnull)) isnull="checked";
String comparestr=" ";
String queryfield=" ";
String isquery=" ";
if(field.length>11){
comparestr=field[10];
queryfield=field[11];
isquery="checked";
}
String fieldtype=field[8];
String datatype=field[9];
tablestr.append("<tr id=");
tablestr.append(UtilString.split(tablename,"-")[0]);
tablestr.append(" name=");
tablestr.append(UtilString.split(tablename,"-")[0]);
tablestr.append(">");
if( !"autoid".equals(ename) ) {
tablestr.append("<td>");
tablestr.append(ename);
tablestr.append("</td>");
tablestr.append("<td>");
tablestr.append(cname);
tablestr.append("</td>");
tablestr.append("<td><input type=checkbox name=isblocklist ");
tablestr.append(isblocklist);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=ispagelist ");
tablestr.append(ispagelist);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=isdetail ");
tablestr.append(isdetail);
tablestr.append("></td>");
if( !" ".equals(isquery) ) {
tablestr.append("<td><input type=checkbox name=query onclick=changequery() ");
tablestr.append(isquery);
tablestr.append("><input type=button value=选项 onclick=selectquery()><input type=hidden name=queryvalue value=");
tablestr.append(comparestr);
tablestr.append("*");
tablestr.append(queryfield);
tablestr.append("></td>");
}
else {
tablestr.append("<td><input type=checkbox name=query onclick=changequery() disabled><input type=button value=选项 onclick=selectquery() disabled><input type=hidden name=queryvalue value=></td>");
}
tablestr.append("<td><input type=checkbox name=iseditfield ");
tablestr.append(iseditfield);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=ishidden ");
tablestr.append(ishidden);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=isnull ");
tablestr.append(isnull);
tablestr.append("></td>");
tablestr.append("<td><input type=hidden name=fieldtype value=");
tablestr.append(fieldtype);
tablestr.append("></td>");
tablestr.append("<td><input type=hidden name=datatype value=");
tablestr.append(datatype);
tablestr.append("></td>");
}
else {
tablestr.append("<td>");
tablestr.append(ename);
tablestr.append("</td>");
tablestr.append("<td>");
tablestr.append(cname);
tablestr.append("</td>");
tablestr.append("<td><input type=checkbox name=isblocklist disabled ");
tablestr.append(isblocklist);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=ispagelist disabled ");
tablestr.append(ispagelist);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=isdetail disabled ");
tablestr.append(isdetail);
tablestr.append("></td>");
if( !" ".equals(isquery) ) {
tablestr.append("<td><input type=checkbox name=query onclick=changequery() disabled ");
tablestr.append(isquery);
tablestr.append("><input type=button value=选项 onclick=selectquery() disabled ><input type=hidden name=queryvalue value=");
tablestr.append(comparestr);
tablestr.append("*");
tablestr.append(queryfield);
tablestr.append("></td>");
}
else {
tablestr.append("<td><input type=checkbox name=query onclick=changequery() disabled><input type=button value=选项 onclick=selectquery() disabled><input type=hidden name=queryvalue value=></td>");
}
tablestr.append("<td><input type=checkbox name=iseditfield disabled ");
tablestr.append(iseditfield);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=ishidden disabled ");
tablestr.append(ishidden);
tablestr.append("></td>");
tablestr.append("<td><input type=checkbox name=isnull disabled ");
tablestr.append(isnull);
tablestr.append("></td>");
tablestr.append("<td><input type=hidden name=fieldtype value=");
tablestr.append(fieldtype);
tablestr.append("></td>");
tablestr.append("<td><input type=hidden name=datatype value=");
tablestr.append(datatype);
tablestr.append("></td>");
}
tablestr.append("</tr>");
}
}
}
tablestr.append("</table>");
tablesstr[0] = tablestr.toString();
return tablesstr;
}
public static String GetEntityname(String appnumber)throws Exception {//得到实体名
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
String inFile=com.yc.ycportal.BaseConfig.getBasepath()+"/WEB-INF/classes/interations.xml";
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("interaction");
int nlleng=nl.getLength();
String entityname="";
for(int i=0;i<nlleng;i++){
Element el=(Element)nl.item(i);
if(el.getAttribute("appnumber").equals(appnumber)){
entityname=el.getAttribute("entityname");
}
}
return entityname;
}
catch(Exception e){
e.printStackTrace();
return "";
}
}
public static List queryinterxml() {//专为交互类列表页用
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
String inFile=com.yc.ycportal.BaseConfig.getBasepath()+"/WEB-INF/classes/interations.xml";
List list=new ArrayList();
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(inFile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("interaction");
int nlleng=nl.getLength();
for(int i=0;i<nlleng;i++){
Element el=(Element)nl.item(i);
InteractionconfView view=new InteractionconfView();
view.setAppnumber(el.getAttribute("appnumber"));
view.setAppcname(el.getAttribute("appname"));
view.setAppdescript(el.getAttribute("appdescript"));
view.setEntityname(el.getAttribute("entityname"));
view.setEntitycname(el.getAttribute("entitycname"));
view.setIsremark(el.getAttribute("isremark"));
view.setIscheckup(el.getAttribute("ischeckup"));
view.setBlockrows(el.getAttribute("blockrows"));
view.setPagerows(el.getAttribute("pagerows"));
view.setOrderfield(el.getAttribute("orderfield"));
view.setOrder(el.getAttribute("order"));
view.setLinkfield(el.getAttribute("linkfield"));
view.setInterinsert(el.getAttribute("interinsert"));
view.setInterblock(el.getAttribute("interblock"));
view.setInterlist(el.getAttribute("interlist"));
view.setInterdetail(el.getAttribute("interdetail"));
view.setIntereditdetail(el.getAttribute("intereditdetail"));
view.setPrimarykey(el.getAttribute("primarykey"));
view.setViewinfofilter(el.getAttribute("viewinfofilter"));
view.setEditinfofilter(el.getAttribute("editinfofilter"));
String fields="";
if(el.hasChildNodes()){
NodeList nodes=el.getChildNodes();
for(int j=0;j<nodes.getLength();j++){
Element fieldnode=(Element)nodes.item(j);
String ename="";
String cname="";
String isblocklist="";
String ispagelist="";
String isdetail="";
String iseditfield="";
String ishidden="";
String isnull="";
String fieldtype="";
String datatype="";
ename=fieldnode.getAttribute("fieldname");
cname=fieldnode.getAttribute("cname");
isblocklist=fieldnode.getAttribute("isblocklist");
ispagelist=fieldnode.getAttribute("ispagelist");
isdetail=fieldnode.getAttribute("isdetail");
iseditfield=fieldnode.getAttribute("iseditfield");
ishidden=fieldnode.getAttribute("ishidden");
isnull=fieldnode.getAttribute("isnull");
fieldtype=fieldnode.getAttribute("fieldtype");
datatype=fieldnode.getAttribute("datatype");
String comparestr="";
String queryfield="";
String queryed="0";
if(fieldnode.getAttribute("comparestr")!=null){
comparestr=fieldnode.getAttribute("comparestr");
queryfield=fieldnode.getAttribute("queryfield");
queryed="1";
}
if("".equals(fields))
fields=ename+"|"+cname+"|"+isblocklist+"|"+ispagelist+
"|"+isdetail+"|"+queryed+"|"+
iseditfield+"|"+ishidden+"|"+isnull+"|"+fieldtype+"|"+datatype+"|"+comparestr+"*"+queryfield;
else fields=fields+","+ename+"|"+cname+"|"+isblocklist+"|"+ispagelist+
"|"+isdetail+"|"+queryed+"|"+
iseditfield+"|"+ishidden+"|"+isnull+"|"+fieldtype+"|"+datatype+"|"+comparestr+"*"+queryfield;
}
}
view.setFields(fields);
list.add(view);
}
return list;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
public static void writexml(String outFile,InteractionconfView view){
DocumentBuilder parser=null;
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
try {
parser=factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document doc = null;
try {
doc = parser.parse(outFile);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Element newlink=doc.createElement("interaction");
newlink.setAttribute("appnumber",view.getAppnumber());
newlink.setAttribute("appname",view.getAppcname());
newlink.setAttribute("appdescript",view.getAppdescript());
newlink.setAttribute("entityname",view.getEntityname());
newlink.setAttribute("entitycname",view.getEntitycname());
newlink.setAttribute("isremark",view.getIsremark());
newlink.setAttribute("ischeckup",view.getIscheckup());
newlink.setAttribute("blockrows",view.getBlockrows());
newlink.setAttribute("pagerows",view.getPagerows());
newlink.setAttribute("orderfield",view.getOrderfield());
newlink.setAttribute("order",view.getOrder());
newlink.setAttribute("linkfield",view.getLinkfield());
String appnumber=view.getAppnumber();
newlink.setAttribute("interinsert","interinsert_"+appnumber+".vm");
newlink.setAttribute("interblock","interblock_"+appnumber+".vm");
newlink.setAttribute("interlist","interlist_"+appnumber+".vm");
newlink.setAttribute("interdetail","interdetail_"+appnumber+".vm");
newlink.setAttribute("intereditdetail","intereditdetail_"+appnumber+".vm");
newlink.setAttribute("primarykey",view.getPrimarykey());
newlink.setAttribute("viewinfofilter",view.getViewinfofilter());
newlink.setAttribute("editinfofilter",view.getEditinfofilter());
String att=view.getFields();
String[] atts=UtilString.split(att,",");
for(int i=0;i<atts.length;i++){
String[] attss=UtilString.split(atts[i],"|");
Element field=doc.createElementNS("field","field");
field.setAttribute("fieldname",attss[0]);
field.setAttribute("cname",attss[1]);
field.setAttribute("isblocklist",attss[2]);
field.setAttribute("ispagelist",attss[3]);
field.setAttribute("isdetail",attss[4]);
field.setAttribute("iseditfield",attss[6]);
field.setAttribute("ishidden",attss[7]);
field.setAttribute("isnull",attss[8]);
field.setAttribute("fieldtype",attss[9]);
field.setAttribute("datatype",attss[10]);
String datatype=attss[10];
String queryed=attss[5];
String queryvalue=attss[11];
if("1".equals(queryed)){
if(queryvalue==null||" ".equals(queryvalue)){
if("refentity".equals(datatype))
queryvalue="equals*browsetext";
else if("enumeration".equals(datatype)){
queryvalue="equals*selectquery";
}
else {
queryvalue="equals*text";
}
}
String queryvalues[]=UtilString.split(queryvalue,"*");
field.setAttribute("comparestr",queryvalues[0]);
field.setAttribute("queryfield",queryvalues[1]);
}
newlink.appendChild(field);
}
String childtabledata [] = UtilString.split( view.getChildtabledata() , "★" );
for ( int i = 0 ; i < childtabledata.length ; i ++ ) {
String childtabledatas [] = UtilString.split( childtabledata[ i ] , "◆" );
if ( childtabledatas != null && childtabledatas.length>1 ) {
Element childtable = doc.createElementNS( "childtable", "childtable" );
String enamecnames[] = UtilString.split(childtabledatas[0],"-");
childtable.setAttribute( "ename", enamecnames[1] );
childtable.setAttribute( "cname", enamecnames[0] );
String childtablefield [] = UtilString.split( childtabledatas[1] , "," );
for ( int j = 0 ; j < childtablefield.length ; j ++ ) {
String childtablefields [] = UtilString.split( childtablefield [ j ] , "|" );
Element field = doc.createElementNS("childfield","childfield");
field.setAttribute("fieldname",childtablefields[0]);
field.setAttribute("cname",childtablefields[1]);
field.setAttribute("isblocklist",childtablefields[2]);
field.setAttribute("ispagelist",childtablefields[3]);
field.setAttribute("isdetail",childtablefields[4]);
field.setAttribute("iseditfield",childtablefields[6]);
field.setAttribute("ishidden",childtablefields[7]);
field.setAttribute("isnull",childtablefields[8]);
field.setAttribute("fieldtype",childtablefields[9]);
field.setAttribute("datatype",childtablefields[10]);
String datatype=childtablefields[10];
String queryed=childtablefields[5];
String queryvalue=childtablefields[11];
if("1".equals(queryed)){
if(queryvalue==null||" ".equals(queryvalue)){
if("refentity".equals(datatype))
queryvalue="equals*browsetext";
else if("enumeration".equals(datatype)){
queryvalue="equals*selectquery";
}
else {
queryvalue="equals*text";
}
}
String queryvalues[]=UtilString.split(queryvalue,"*");
field.setAttribute("comparestr",queryvalues[0]);
field.setAttribute("queryfield",queryvalues[1]);
}
childtable.appendChild(field);
}
newlink.appendChild(childtable);
}
}
doc.getDocumentElement().appendChild(newlink);
DOMSource doms=new DOMSource(doc);
File file=new File(outFile);
StreamResult sr=new StreamResult(file);
TransformerFactory tf=TransformerFactory.newInstance();
Transformer t = null;
try {
t = tf.newTransformer();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
try {
t.transform(doms,sr);
} catch (TransformerException e) {
e.printStackTrace();
}
}
public static void updatexml(String infile,InteractionconfView view){
DocumentBuilder parser=null;
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
try{
parser=factory.newDocumentBuilder();
Document doc=parser.parse(infile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("interaction");
int nlleng=nl.getLength();
for(int i=0;i<nlleng;i++){
Element newlink=(Element)nl.item(i);
if(newlink.getAttribute("appnumber").equals(view.getAppnumber())){
newlink.setAttribute("appnumber",view.getAppnumber());
newlink.setAttribute("appname",view.getAppcname());
newlink.setAttribute("appdescript",view.getAppdescript());
newlink.setAttribute("entityname",view.getEntityname());
newlink.setAttribute("entitycname",view.getEntitycname());
newlink.setAttribute("isremark",view.getIsremark());
newlink.setAttribute("ischeckup",view.getIscheckup());
newlink.setAttribute("blockrows",view.getBlockrows());
newlink.setAttribute("pagerows",view.getPagerows());
newlink.setAttribute("orderfield",view.getOrderfield());
newlink.setAttribute("order",view.getOrder());
newlink.setAttribute("linkfield",view.getLinkfield());
newlink.setAttribute("interblock",view.getInterblock());
newlink.setAttribute("interlist",view.getInterlist());
newlink.setAttribute("interdetail",view.getInterdetail());
newlink.setAttribute("intereditdetail",view.getIntereditdetail());
newlink.setAttribute("viewinfofilter",view.getViewinfofilter());
newlink.setAttribute("editinfofilter",view.getEditinfofilter());
String att=view.getFields();
String[] atts=UtilString.split(att,",");
NodeList list=newlink.getChildNodes();
for(int j=0;j<atts.length;j++){
String[] attss=UtilString.split(atts[j],"|");
Element field=(Element)list.item(0);
field.setAttribute("fieldname",attss[0]);
field.setAttribute("cname",attss[1]);
field.setAttribute("isblocklist",attss[2]);
field.setAttribute("ispagelist",attss[3]);
field.setAttribute("isdetail",attss[4]);
field.setAttribute("iseditfield",attss[6]);
field.setAttribute("ishidden",attss[7]);
field.setAttribute("isnull",attss[8]);
String datatype=field.getAttribute("datatype");
String queryed=attss[5];
if("1".equals(queryed)){
String queryvalue="";
if(attss.length>11){
if(" ".equals(attss[11])){
if("refentity".equals(datatype))
queryvalue="equals*browsetext";
else if("enumeration".equals(datatype)){
queryvalue="equals*selectquery";
}
else {
queryvalue="equals*text";
}
}
else queryvalue=attss[11];
}
else{
if("refentity".equals(datatype))
queryvalue="equals*browsetext";
else if("enumeration".equals(datatype)){
queryvalue="equals*selectquery";
}
else {
queryvalue="equals*text";
}
}
String queryvalues[]=UtilString.split(queryvalue,"*");
field.setAttribute("comparestr",queryvalues[0]);
field.setAttribute("queryfield",queryvalues[1]);
}
else {
field.removeAttribute("comparestr");
field.removeAttribute("queryfield");
}
newlink.appendChild(field);
}
for( int m = list.getLength()-1 ; m > -1 ; m -- ){
Element fieldnode = (Element)list.item(m);
NodeList childnodes = fieldnode.getChildNodes();
if( "childtable".equals(((Element)childnodes).getNodeName()) ) {
((Element)childnodes).getParentNode().removeChild(fieldnode);
}
}
String childtabledata [] = UtilString.split( view.getChildtabledata() , "★" );
for ( int m = 0 ; m < childtabledata.length ; m ++ ) {
String childtabledatas [] = UtilString.split( childtabledata[ m ] , "◆" );
if ( childtabledatas != null && childtabledatas.length>1 ) {
String enamecnames[] = UtilString.split(childtabledatas[0],"-");
Element childtable = doc.createElementNS( "childtable", "childtable" );
childtable.setAttribute( "ename", enamecnames[1] );
childtable.setAttribute( "cname", enamecnames[0] );
String childtablefield [] = UtilString.split( childtabledatas[1] , "," );
for ( int j = 0 ; j < childtablefield.length ; j ++ ) {
String childtablefields [] = UtilString.split( childtablefield [ j ] , "|" );
Element field = doc.createElementNS("childfield","childfield");
field.setAttribute("fieldname",childtablefields[0]);
field.setAttribute("cname",childtablefields[1]);
field.setAttribute("isblocklist",childtablefields[2]);
field.setAttribute("ispagelist",childtablefields[3]);
field.setAttribute("isdetail",childtablefields[4]);
field.setAttribute("iseditfield",childtablefields[6]);
field.setAttribute("ishidden",childtablefields[7]);
field.setAttribute("isnull",childtablefields[8]);
field.setAttribute("fieldtype",childtablefields[9]);
field.setAttribute("datatype",childtablefields[10]);
String datatype=childtablefields[10];
String queryed=childtablefields[5];
String queryvalue=childtablefields[11];
if("1".equals(queryed)){
if(queryvalue==null||" ".equals(queryvalue)){
if("refentity".equals(datatype))
queryvalue="equals*browsetext";
else if("enumeration".equals(datatype)){
queryvalue="equals*selectquery";
}
else {
queryvalue="equals*text";
}
}
String queryvalues[]=UtilString.split(queryvalue,"*");
field.setAttribute("comparestr",queryvalues[0]);
field.setAttribute("queryfield",queryvalues[1]);
}
childtable.appendChild(field);
}
newlink.appendChild(childtable);
}
}
doc.getDocumentElement().appendChild(newlink);
}
}
DOMSource doms=new DOMSource(doc);
File file=new File(infile);
StreamResult sr=new StreamResult(file);
TransformerFactory tf=TransformerFactory.newInstance();
Transformer t=tf.newTransformer();
t.transform(doms,sr);
}
catch(Exception e){
e.printStackTrace();
}
}
public static void deletexml(String appnumber){
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=null;
try{
String infile=com.yc.ycportal.BaseConfig.getBasepath()+"/WEB-INF/classes/interations.xml";
db =dbf.newDocumentBuilder();
Document doc=null;
doc=db.parse(infile);
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("interaction");
int nlleng=nl.getLength();
for(int i=0;i<nlleng;i++){
Element el=(Element)nl.item(i);
if(appnumber==null) log.error("传入的参数不能为空!");
else{
if(el!=null){
if(appnumber.equals(el.getAttribute("appnumber"))){
el.getParentNode().removeChild(el);
}
}
}
}
DOMSource doms=new DOMSource(doc);
File file=new File(infile);
StreamResult sr=new StreamResult(file);
TransformerFactory tf=TransformerFactory.newInstance();
Transformer t=tf.newTransformer();
t.transform(doms,sr);
}
catch(Exception e){
e.printStackTrace();
}
}
public static List readFieldtype() {
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
String inFile=com.yc.ycportal.BaseConfig.getFieldtypepath();
Document doc = null;
try {
doc = db.parse(inFile);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Element root=doc.getDocumentElement();
NodeList nl=root.getElementsByTagName("field");
int nlleng=nl.getLength();
List list=new ArrayList();
for(int i=0;i<nlleng;i++){
Element el=(Element)nl.item(i);
OriginField field=new OriginField();
field.setId(el.getAttribute("id"));
field.setCname(el.getAttribute("cname"));
field.setDbtype(el.getAttribute("dbtype"));
field.setJavatype(el.getAttribute("javatype"));
field.setDblength(el.getAttribute("dblength"));
field.setShowformat(el.getAttribute("showformat"));
field.setIntomode(el.getAttribute("intomode"));
field.setShowlength(el.getAttribute("showlength"));
field.setCheckfunction(el.getAttribute("checkfunction"));
list.add(field);
}
return list;
}
}