📄 webprint.java
字号:
int iEnd=0;
String sRet="";
while (iStart<mainStr.length()) {
iEnd=mainStr.indexOf(findStr,iStart);
if (iEnd<0) {
iEnd=mainStr.length();
sRet=sRet+mainStr.substring(iStart,iEnd);
}
else {
sRet=sRet+mainStr.substring(iStart,iEnd)+replaceStr;
}
iStart=iEnd+findStr.length();
}
return sRet;
}
private String rTrim(String str){
String rstr = str;
if(str == null)
{
rstr = "";
}
else
{
if(str.length() == 0) rstr = "";
if(str.length() > 0)
{
for(int i = str.length() ; i > 0 ; i--)
{
if(str.substring(i-1,i).equals(" "))
rstr = rstr.substring(0,i-1);
else break;
}
}
}
return rstr;
}
//--------------------------------------------
private String XmlOut(ResultSet oRs , String sRowEntityName,long EntFormat )
{
String sSet="";
try {
//oRs.first();
while (oRs.next())
{
sSet = sSet + RecordToXMLEntity(oRs, sRowEntityName, EntFormat) ;
}
}
catch (Exception e)
{
return e.getMessage();
}
return sSet ;
}
private String RecordToXMLEntity(ResultSet oRs , String EntityName,long EntFormat)
{
String sEty ="";
int iField=1;
int iCount=1;
try {
ResultSetMetaData rsmd=oRs.getMetaData();
iCount=rsmd.getColumnCount();
if (EntFormat==1)
{
//属性
sEty = "<" + EntityName ;
for (iField = 1 ; iField<=iCount ;iField++ )
{
sEty = sEty + " " + rsmd.getColumnName(iField) +"='" + oRs.getString(iField) +"'" ;
}
sEty = sEty + "/>" + "\n";
}
else
{
//节点
sEty = "<" + EntityName +">" +"\n" ;
for (iField = 1 ; iField<=iCount ; iField++)
{
sEty = sEty +"<" + rsmd.getColumnName(iField) +">" + oRs.getString(iField) +"</" + rsmd.getColumnName(iField) +">";
}
sEty = sEty +"\n" +"</" + EntityName +">" +"\n";
}
}
catch (Exception e)
{
}
return sEty;
}
//-----------------------------------------------------
private Attr[] sortAttributes(NamedNodeMap attrs) {
int len = (attrs != null) ? attrs.getLength() : 0;
Attr array[] = new Attr[len];
for ( int i = 0; i < len; i++ ) {
array[i] = (Attr)attrs.item(i);
}
for ( int i = 0; i < len - 1; i++ ) {
String name = array[i].getNodeName();
int index = i;
for ( int j = i + 1; j < len; j++ ) {
String curName = array[j].getNodeName();
if ( curName.compareTo(name) < 0 ) {
name = curName;
index = j;
}
}
if ( index != i ) {
Attr temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}
return(array);
} // sortAttributes(NamedNodeMap):Attr[]
//--------------------------------------------
//WebCode中用
private String sqltoxml()
{
Node root=document.getChildNodes().item(0);
String strpage=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
String strsql=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
strsql=fcTrans(strsql);
String strsearch=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
String strrownum=root.getChildNodes().item(3).getChildNodes().item(0).getNodeValue();
String showcheckbox=root.getChildNodes().item(4).getChildNodes().item(0).getNodeValue();
String blnempty=root.getChildNodes().item(5).getChildNodes().item(0).getNodeValue();
//加空行
showcheckbox=showcheckbox.toUpperCase();
int intpage=Integer.parseInt(strpage);//开始页
int intrownum=Integer.parseInt(strrownum);//页尺寸
String strX="";
try {
//建立数据库连接
/*
strDataSource="webgrid";
strUserName="sa";
strPassword="";
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:"+strDataSource;
Class.forName(sDBDriver);
Connection con1 = DriverManager.getConnection(sConnStr,strUserName,strPassword);
Statement stmt = con1.createStatement();
*/
//原来的
Statement stmt = con.createStatement();
//执行查询建立结果集
//-----------------
//System.out.print(strsearch);
int i=1;
if (strsearch.compareTo("###")!=0){
rs = stmt.executeQuery(strsql);
boolean bfind=false;
while(rs.next()){
String searchone=rs.getString(1);
//out.print(searchone);
if (searchone.equals(strsearch)){
bfind=true;
break;
}
i=i+1;
}
rs.close();
if (bfind==true){
if (i<=intrownum){
intpage=1;
}
else {
if (i%intrownum>0){
intpage=i/intrownum+1;
}
else {
intpage=i/intrownum;
}
}
}
//自动定位到当前选择所在值的页
}
//out.print("intpage="+intpage);
//-----------------
// System.out.print(intpage);
rs = stmt.executeQuery(strsql);
ResultSetMetaData rsmd=rs.getMetaData();
strX="<root>";
String sLabel="";
int k=0;
int thisrow=0;
int pagenumber=0;//总页数
int iFind=0; //控制在开始处插入一个空白行
while (rs.next()) {
if (blnempty.equals("true") && iFind==0) {
//插入一个空白行
strX=strX+"<tr height='16'>";
for (i=1;i<=rsmd.getColumnCount();i++) {
strX = strX + "<td></td>";
}
strX=strX+"</tr>";
iFind=1;
}
if (k>=(intpage-1)*intrownum && k<(intpage)*intrownum){
strX = strX + "<tr>";
for (i=1;i<=rsmd.getColumnCount();i++) {
sLabel=rsmd.getColumnLabel(i);
//System.out.println(rsmd.getColumnTypeName(i));
String sT=rs.getString(i);
if (sT==null) sT="";
strX = strX + "<td>" + sT + "</td>";
}
if (showcheckbox.equals("TRUE"))
strX = strX + "<td width='30'><input type='checkbox'></input></td>"+"</tr>";
else
strX = strX + "</tr>";
}
k=k+1;
}
if (k%intrownum>0)
pagenumber=k/intrownum+1;
else
pagenumber=k/intrownum;
strX=strX+"<pagenumber>"+pagenumber+"</pagenumber><intpage>"+intpage+"</intpage></root>";
} catch (Exception e){
strX=e.getMessage();
}
return strX;
}
private String fcTrans(String sSource)
{
// GB2312
//XML节点中的汉字经8859_1==>UTF-8转换后用System.out.println输出正常
/*
UTF-8 ==> GB2312 1
UTF-8 ==> 8859_1 2
GB2312 ==> UTF-8 3
8859_1 ==> UTF-8 4
GB2312 ==> 8859_1 5
8859_1 ==> GB2312 6
*/
String unicodesR ="";
try {
//byte [] by = sSource.getBytes("8859_1"); //
//unicodesR = new String(by,"UTF-8");
//System.out.println("b:"+sSource);
unicodesR=unescape(sSource);
}
catch (Exception e){
}
//System.out.println("a:"+unicodesR);
return unicodesR;
// return sSource;
///
}
/**
* 将用javascript的escape()函数编码的字符串解码回来 throws Exception
*/
public String unescape( String src )
{
if ( src == null ) return src;
if ( src.equals( "" ) ) return src;
int pos = src.indexOf( "%u" );
if ( pos < 0 ) return tmptrans( src );
String tmp = src.substring( 0, pos );
String result = tmptrans( tmp );
String rest = "";
if ( pos + 6 < src.length() )
{
tmp = src.substring( pos, pos + 6 );
rest = src.substring( pos + 6 );
}
else
{
tmp = src.substring( pos );
rest = "";
}
tmp = tmp.replace( '%', '\\' );
result += unicode2String( tmp );
return result + unescape( rest );
}
public String unicode2String( String theString )
{
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer( len );
for( int x=0; x<len; )
{
aChar = theString.charAt( x++ );
if ( aChar == '\\' )
{
aChar = theString.charAt( x++ );
if ( aChar == 'u' )
{
// Read the xxxx
int value = 0;
for ( int i = 0; i < 4; i++ )
{
aChar = theString.charAt( x++ );
switch ( aChar )
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
value = ( value << 4 ) + aChar - '0';
break;
case 'a': case 'b': case 'c':
case 'd': case 'e': case 'f':
value = ( value << 4 ) + 10 + aChar - 'a';
break;
case 'A': case 'B': case 'C':
case 'D': case 'E': case 'F':
value = ( value << 4 ) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException( "Malformed \\uxxxx encoding.");
}
}
//System.out.println(value);
outBuffer.append( (char)value );
}
}
else
outBuffer.append( aChar );
}
return outBuffer.toString();
}
/**
*escape字符转换 %20 ==>空
*@date 2003-12-01
**/
public String tmptrans( String theString ){
char aChar;
int len=theString.length();
String s1="";
String s2="";
String s3="";
String sRet="";
for( int i=0; i<len; ){
s1=theString.substring(i,i+1);
if(s1.equals("%")){
s2=theString.substring(i,i+3);
//if(s2.equals("%5C")) s3="\";
//if(s2.equals("%22")) s3='"';
if(s2.equals("%27")) s3="'";
if(s2.equals("%21")) s3="!";
if(s2.equals("%23")) s3="#";
if(s2.equals("%24")) s3="$";
if(s2.equals("%25")) s3="%";
if(s2.equals("%5E")) s3="^";
if(s2.equals("%26")) s3="&";
if(s2.equals("%28")) s3="(";
if(s2.equals("%29")) s3=")";
if(s2.equals("%3D")) s3="=";
if(s2.equals("%7B")) s3="{";
if(s2.equals("%7D")) s3="}";
if(s2.equals("%5B")) s3="[";
if(s2.equals("%5D")) s3="]";
if(s2.equals("%20")) s3=" ";
if(s2.equals("%2C")) s3=",";
if(s2.equals("%3F")) s3="?";
if(s2.equals("%7C")) s3="|";
if(s2.equals("%60")) s3="`";
if(s2.equals("%7E")) s3="~";
if(s2.equals("%0A")) s3=" ";
if(s2.equals("%0D")) s3=" ";
if(s2.equals("%09")) s3=" ";
sRet=sRet+s3;
i=i+3;
}else{
sRet=sRet+s1 ;
i=i+1;
}
}
return sRet;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -