📄 jsourcecodewizardprocessorservlet.java
字号:
/**
* IgaLib -> wizard
* Copyright (C) 2001 Tosiki IGA , IgaLib project member
* (http://homepage2.nifty.com/igat/igapyon/index.html)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jp.ne.nifty.iga.tosiki.wizard;
import jp.ne.nifty.iga.tosiki.string.*;
import java.io.*;
import java.util.*;
/**
* JSourceCodeWizardProcessor 偺僿儖僷乕僋儔僗<BR>
* Servlet晹暘偱偡<BR>
*
* @author Tosiki IGA
*/
public class JSourceCodeWizardProcessorServlet
{
/**
* 僿僢僟傪憓擖偟傑偡丅
*/
public static final void write(
JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
throws IOException
{
out.println(" /**");
out.println(" * "+dataChannel.getName()+"("+dataChannel.getTitle()+") 僋儔僗偺僒乕僽儗僢僩GET僄儞僩儕億僀儞僩<BR>");
out.println(" * ");
out.println(" * @param HttpServletRequest request 儕僋僄僗僩");
out.println(" * @param HttpServletResponse response 儗僗億儞僗");
out.println(" */");
out.println(" public void doGet(javax.servlet.http.HttpServletRequest request,javax.servlet.http.HttpServletResponse response)");
out.println(1," throws javax.servlet.ServletException,java.io.IOException");
out.println(" {");
out.addIndent(2);
writeCommonHead(wizard,dataChannel,vecItem,out);
writeHead(wizard,dataChannel,vecItem,out);
out.println("out.println(\"<BODY>\");");
out.println("out.println(\"<FORM action=\\\""+JSourceCodeWizardProcessor.getMyClassName(wizard,dataChannel)+"\\\" method=\\\"post\\\">\");");
writeCommonTableArea(wizard,dataChannel,vecItem,out);
out.println("out.println(\"<input type=\\\"submit\\\" name=\\\"submit\\\" value=\\\"UpdateData\\\">\");");
out.println("out.println(\"</FORM>\");");
out.println("out.println(\"</BODY></HTML>\");");
out.addIndent(-2);
out.println(" }");
out.println("");
out.println(" /**");
out.println(" * "+dataChannel.getName()+"("+dataChannel.getTitle()+") 僋儔僗偺僒乕僽儗僢僩POST僄儞僩儕億僀儞僩<BR>");
out.println(" * ");
out.println(" * @param HttpServletRequest request 儕僋僄僗僩");
out.println(" * @param HttpServletResponse response 儗僗億儞僗");
out.println(" */");
out.println(" public void doPost(javax.servlet.http.HttpServletRequest request,javax.servlet.http.HttpServletResponse response)");
out.println(1," throws javax.servlet.ServletException,java.io.IOException");
out.println(" {");
out.addIndent(2);
writeCommonHead(wizard,dataChannel,vecItem,out);
out.println("String strSubmit=request.getParameter(\"submit\");");
for(int index=0;index<dataChannel.getFunction().getBind().size();index++)
{
String strCopyTarget=(String)dataChannel.getFunction().getBind().get(index);
JSourceCodeWizard wizardTarget=JSourceCodeWizardField.findWizardFromXmlByClassName(wizard,dataChannel,strCopyTarget);
for(int indexSearchOther=0;indexSearchOther<wizardTarget.getField().size();indexSearchOther++)
{
JSourceCodeWizardField fieldOther=(JSourceCodeWizardField)wizardTarget.getField().get(indexSearchOther);
if(fieldOther.getType().equals("String")
|| fieldOther.getType().equals("int")
|| fieldOther.getType().equals("char")
|| fieldOther.getType().equals("boolean"))
{
out.println(wizardTarget.getChannel().getName()+".set"+JSourceCodeWizardProcessor.getUpper(fieldOther.getName())+"("+WizType.getConvertPatternForType("String",fieldOther.getType(),"request.getParameter(\""+fieldOther.getName()+"\")")+");");
}
}
}
writeHead(wizard,dataChannel,vecItem,out);
out.println("out.println(\"<BODY>\");");
out.println("out.println(\"<P>POST=\"+strSubmit+\"偑棃傑偟偨</P>\");");
out.println("if(strSubmit.equals(\"UpdateData\"))");
out.println("{");
out.println(1,"out.println(\"<P>UpdateData偱偡</P>\");");
out.println("}");
out.println("else");
out.println("{");
out.println(1,"out.println(\"<P>UpdateData偱偼側偔\"+strSubmit+\"偱偡</P>\");");
out.println("}");
out.println("out.println(\"<FORM action=\\\""+JSourceCodeWizardProcessor.getMyClassName(wizard,dataChannel)+"\\\" method=\\\"post\\\">\");");
writeCommonTableArea(wizard,dataChannel,vecItem,out);
out.println("out.println(\"<input type=\\\"submit\\\" name=\\\"submit\\\" value=\\\"UpdateData\\\">\");");
out.println("out.println(\"</FORM>\");");
out.println("out.println(\"</BODY></HTML>\");");
out.addIndent(-2);
out.println(" }");
out.println("");
}
protected static final void writeCommonHead(
JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
throws IOException
{
for(int index=0;index<dataChannel.getFunction().getBind().size();index++)
{
String strCopyTarget=(String)dataChannel.getFunction().getBind().get(index);
JSourceCodeWizard wizardTarget=JSourceCodeWizardField.findWizardFromXmlByClassName(wizard,dataChannel,strCopyTarget);
out.println(JSourceCodeWizardProcessor.getMyClassName(wizardTarget,wizardTarget.getChannel())+" "+wizardTarget.getChannel().getName()+"=null;");
}
out.println("javax.servlet.http.HttpSession session=request.getSession();");
out.println("{");
for(int index=0;index<dataChannel.getFunction().getBind().size();index++)
{
String strCopyTarget=(String)dataChannel.getFunction().getBind().get(index);
JSourceCodeWizard wizardTarget=JSourceCodeWizardField.findWizardFromXmlByClassName(wizard,dataChannel,strCopyTarget);
out.println(1,wizardTarget.getChannel().getName()+"=("+JSourceCodeWizardProcessor.getMyClassName(wizardTarget,wizardTarget.getChannel())+")session.getAttribute(\""+wizardTarget.getChannel().getName()+"\");");
out.println(1,"if("+wizardTarget.getChannel().getName()+"==null)");
out.println(1,"{");
out.println(2,wizardTarget.getChannel().getName()+"=new "+JSourceCodeWizardProcessor.getMyClassName(wizardTarget,wizardTarget.getChannel())+"();");
out.println(2,"session.setAttribute(\""+wizardTarget.getChannel().getName()+"\","+wizardTarget.getChannel().getName()+");");
out.println(1,"}");
}
out.println("}");
}
protected static final void writeHead(
JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
throws IOException
{
out.println("response.setContentType(\"text/html; charset=ISO-2022-JP\");");
out.println("PrintWriter out=response.getWriter();");
out.println("out.println(\"<HTML><HEAD><META http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=ISO-2022-JP\\\"></HEAD>\");");
}
protected static final void writeCommonTableArea(
JSourceCodeWizard wizard,JSourceCodeWizardChannel dataChannel,ArrayList vecItem,IndentWriter out)
throws IOException
{
out.println("out.println(\"<TABLE><TBODY>\");");
for(int index=0;index<dataChannel.getFunction().getBind().size();index++)
{
String strCopyTarget=(String)dataChannel.getFunction().getBind().get(index);
JSourceCodeWizard wizardTarget=JSourceCodeWizardField.findWizardFromXmlByClassName(wizard,dataChannel,strCopyTarget);
for(int indexSearchOther=0;indexSearchOther<wizardTarget.getField().size();indexSearchOther++)
{
JSourceCodeWizardField fieldOther=(JSourceCodeWizardField)wizardTarget.getField().get(indexSearchOther);
out.println("out.println(\"<TR><TD>"+fieldOther.getTitle()+"</TD><TD><input type=\\\"text\\\" name=\\\""+fieldOther.getName()+"\\\" value=\\\"\"+"+wizardTarget.getChannel().getName()+".get"+JSourceCodeWizardProcessor.getUpper(fieldOther.getName())+"()+\"\\\"></TD><TR>\");");
}
}
out.println("out.println(\"</TBODY></TABLE>\");");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -