📄 report.java
字号:
package com.power.pipeengine.Report;
import java.io.*;
import com.power.pipeengine.InputData.*;
import java.net.*;
import com.power.pipe.*;
import com.power.pipeengine.*;
import com.power.util.urltools.*;
import com.power.util.Message.*;
import java.util.ResourceBundle;
/**
*
* <p>Title: PIPE Engine</p>
* <p>Description: Global Planning Optimization Engine</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Paraster, Inc.</p>
* @author Wei Tan
* @version 1.0
*/
/**
* Report is the super class of all report generators. It handles the communication
* between the client and the servlet.
*/
public class Report
{
/**
* the FileWriter used when only local file interface is desired.
*/
static ResourceBundle res = ResourceBundle.getBundle("com.power.pipeengine.Res",
EngineConfig.getInstance().getLocale() );
protected FileWriter _myFileWriter; //initialized in subclass
/**
* the name of file to generate.
*/
protected String _fileName;
/**
* the URL address to where the report is written.
*/
//private String urlAddr = GlobalConfig.getInstance().getURL();
private String urlAddr = GlobalConfig.getInstance().getFileReadWriteURL();
private String outputDir = GlobalConfig.getInstance().getDirectOutputDir();
/**
* the token used to separate fields.
*/
private String token = ",";
/**
* the URL used in report writing.
*/
private URL url = null;
/**
* the content of the report (multi-lined text).
*/
protected String _content = "";
/**
* Sole class constructor.
*/
public Report() {
}
/**
* Writes one line (record) to file.
* @param line the line to be written to file.
* @throws IOException I/O related exceptions.
*/
protected void writeRecord( String line )
throws IOException
{
_myFileWriter.write( line );
}
/**
* Initializes a FileWriter for the report using global input directory and
* local file name.
*/
protected void initFileWriter() {
String outDir = GlobalConfig.getInstance().getOutputDirectory();
try {
_myFileWriter = new FileWriter( outDir + _fileName + ".csv" );
} catch (IOException e ) {
System.out.println( e.getMessage() );
}
}
private boolean flushURL( String content ) {
try {
url = new URL(urlAddr);
} catch(MalformedURLException e) {
System.out.println(res.getString("URL_Error_") + e);
return false;
}
HttpURLConnection urlconn = null;
OutputStream out = null;
PrintStream writer;
try {
urlconn = (HttpURLConnection)(url.openConnection());
urlconn.setRequestMethod("POST");
urlconn.setDoOutput(true);
urlconn.setDoInput(true);
out = urlconn.getOutputStream();
writer = new PrintStream(out);
writer.print("fileName=" + _fileName + ".csv" +
"&cmd=LoadOutput&fileContent=" +
content );
writer.flush();
BufferedReader d = null;
InputStream in = in = urlconn.getInputStream();
d = new BufferedReader(new InputStreamReader(in));
String status = d.readLine();
urlconn.disconnect();
return true;
}
catch(IOException e) {
System.out.println("Error:" + e);
return false;
}
}
private boolean flushFile( String content ) {
try{
_myFileWriter.write( content );
_myFileWriter.flush();
} catch ( IOException e ) {
System.out.println("Error:" + e.getMessage() );
return false;
}
return true;
}
/**
* Flushes the entire content through the URL at once.
* @param content the content to be flushed.
* @return <code>true</code> if successul;
* <code>false</code> otherwise.
*/
protected boolean flush( String content ) {
String msg = res.getString("Engine3010") + res.getString( _fileName ) + "\n";
MessageArea.getInstance().addMessage( msg );
boolean status = true;
/*if( GlobalConfig.getInstance().isStandAloneApp() != true ) {
status = flushURL( content );
} else {
initFileWriter();
status = flushFile( content );
}*/
/*URLFileWriter.getInstance().deleteFile( urlAddr,
outputDir + _fileName + ".csv",
"WriteModel" );*/
URLFileWriter.getInstance().write( urlAddr,
outputDir + _fileName + ".csv",
"WriteModel",
content );
return status;
}
public void reset() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -