//Java IO
import java.io.File;
import java.io.FilenameFilter;
//Java IO Out
import java.io.OutputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
//Java IO In
import java.io.FileInputStream;
import java.nio.channels.FileChannel;
import java.nio.MappedByteBuffer;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.lang.String;
import java.util.Calendar;
import java.net.URI;
import java.util.zip.*;
import java.util.Enumeration;
import java.io.IOException;
import java.io.FileNotFoundException;
public class WriteReport
{
private InspectorData[] objInspData;
private InspectionData[] objInspecData;
private String[] strFileNames;
private int intIndex;
private String strCurrentValue = "";
private String strWriteDirectory;
private String strPathToResourcesDir;
WriteReport(InspectorData[] objInspector, InspectionData[] objInspection, String strNewWriteDirectory, String strNewPathToResourcesDir, String[] strNewFileNames)
{
////System.out.println("In WriteReport");
//Load passed data into variables
objInspData = objInspector;
objInspecData = objInspection;
strWriteDirectory = strNewWriteDirectory;
strPathToResourcesDir = strNewPathToResourcesDir;
strFileNames = strNewFileNames;
}
void writeRelsFile()
{
OutputStreamWriter objWriter = null;
try
{
File myFile = new File(new URI("file:///home//files//Drives//Internal//document.xml.rels"));
OutputStream fos = new BufferedOutputStream (new FileOutputStream (myFile));
objWriter = new OutputStreamWriter(fos);
String strFileContents = null;
strFileContents = "";
strFileContents += "";
strFileContents += "";
strFileContents += "";
strFileContents += "";
strFileContents += "";
strFileContents += "";
strFileContents += "";
for (int i=0; i";
}
//strFileContents += ""
//strFileContents += ""
//strFileContents += ""
strFileContents += "";
char[] chars = strFileContents.toCharArray();
objWriter.write(chars, 0, chars.length);
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
catch (java.net.URISyntaxException e)
{
e.printStackTrace();
}
finally
{
try
{
objWriter.flush();
objWriter.close();
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
}
}
void write()
{
////System.out.println("In write");
String strFileContents = "";
FileInputStream fis = null;
try
{
fis = new FileInputStream(new File(new URI("file://" + strPathToResourcesDir + "Java/Header.xml")));
FileChannel fc = fis.getChannel();
MappedByteBuffer mbf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
byte[] barray = new byte[(int)(fc.size())];
mbf.get(barray);
strFileContents = new String(barray); //one big string
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
catch (java.net.URISyntaxException e)
{
e.printStackTrace();
}
finally
{
try
{
fis.close();
}
catch (java.io.IOException e)
{
e.printStackTrace();
}
}
OutputStream objWriter = null;
try
{
File myFile = new File(new URI("file:///home//files//Drives//Internal//document.xml"));
objWriter = new FileOutputStream (myFile);
//Header modification currently not needed. ****
//This section replaces place holder text & removes/modifiers headers/footers
//strFileContents = strFileContents.replaceFirst(
//strFileContents.substring(strFileContents.indexOf("")),
//"");
strFileContents = strFileContents.replaceFirst("", "");
strFileContents = strFileContents.replaceFirst("Var_serial", objInspData[0].getSerial() );
strFileContents = strFileContents.replaceFirst("Var_customer", objInspData[0].getCustomer() );
strFileContents = strFileContents.replaceFirst("Var_site", objInspData[0].getSite() );
strFileContents = strFileContents.replaceFirst("Var_inspector", objInspData[0].getInspector() );
strFileContents = strFileContents.replaceFirst("Var_model", objInspData[0].getModel() );
strFileContents = strFileContents.replaceFirst("Var_comments", objInspData[0].getComments() );
strFileContents = strFileContents.replaceFirst("Var_unit", objInspData[0].getUnitNumber() );
strFileContents = strFileContents.replaceFirst("Var_frame", objInspData[0].getFrame() );
strFileContents = strFileContents.replaceFirst("Var_series", objInspData[0].getSeries() );
strFileContents = strFileContents.replaceFirst("Var_event", objInspData[0].getEvent() );
strFileContents = strFileContents.replaceFirst("Var_firedhours", objInspData[0].getFiredHours() );
strFileContents = strFileContents.replaceFirst("Var_firedstarts", objInspData[0].getFiredStarts() );
strFileContents = strFileContents.replaceFirst("Var_factored", objInspData[0].getFactoredStarts() );
strFileContents = strFileContents.replaceFirst("Var_trips", objInspData[0].getTrips() );
strFileContents = strFileContents.replaceFirst("Var_cpm", objInspData[0].getCPM() );
strFileContents = strFileContents.replaceFirst("Var_location", objInspData[0].getLocation() );
strFileContents += writeTable();
strFileContents += "";
////System.out.println(strFileContents);
//Writing the file
byte[] bytes = strFileContents.getBytes();
////System.out.println("*************" + chars[chars.length-1]);
objWriter.write(bytes);
////System.out.println("The length of the array = " + ((int)strFileNames.length+(int)11));
String[] strNewTest = new String[strFileNames.length+13];
strNewTest[0] = "/" + strWriteDirectory + "/report/[Content_Types].xml";
strNewTest[1] = "/" + strWriteDirectory + "/report/word/fontTable.xml";
strNewTest[2] = "/" + strWriteDirectory + "/report/word/settings.xml";
strNewTest[3] = "/" + strWriteDirectory + "/report/word/styles.xml";
strNewTest[4] = "/" + strWriteDirectory + "/report/word/webSettings.xml";
strNewTest[5] = "/home/files/Drives/Internal/document.xml";
strNewTest[6] = "/" + strWriteDirectory + "/report/_rels/.rels";
strNewTest[7] = "/" + strWriteDirectory + "/report/docProps/app.xml";
strNewTest[8] = "/" + strWriteDirectory + "/report/docProps/core.xml";
strNewTest[9] = "/" + strWriteDirectory + "/report/word/theme/theme1.xml";
strNewTest[10] = "/" + strWriteDirectory + "/report/word/media/header.png";
strNewTest[11] = "/" + strWriteDirectory + "/report/word/media/fan.jpeg";
strNewTest[12] = "/home/files/Drives/Internal/document.xml.rels";
for (int i=0; i")+10), objInspecData[i].getImage() );
//strTemp[i] = strTemp[i].replaceAll("Var_imglink", "wordml://" + i + ".jpg" );
//System.out.println(strTemp[i]);
}
for (int i=0; i