B
bmcdougald
I am having a problem presenting some HTML that is the result of an XSL
transformation, due to the placement of some mysterious CR/LF
characters peppered in the HTML. These chars tend to appear in the
middle of HTML tags, like this table cell tag: <tCRLFd>, and it really
mucks up the formatting of the page.
I have taken esults of the transformation, and did a search replace on
all occurrences of a \n or \r character in the result string, but they
still appear. When I do a view source from the browser, the HTML
appears to have removed any "explicit" CRLF's in the file, but there
are still CR/LF chars peppered throughout the file.
I am using a PrintWriter object to write out the results. Could that
be adding in the extra CR/LF's?
I'm stumped.
*****************************************************
CODE
*****************************************************
import lotus.domino.*;
// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
// Imported java classes
import java.io.*;
import java.lang.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
int i,j,k,t, y,x,z;
String str;
String valStr;
String prmStr;
// Get the parameter values entered on form
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document req = agentContext.getDocumentContext();
String qStr = req.getItemValueString("Query_String");
String xmlsrc "d:\\tpr.xml";
String xslsrc = "http://localhost/web/xbb.nsf/tprs.xsl";
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource strSrc = new StreamSource(xslsrc);
Transformer transformer = tFactory.newTransformer(strSrc);
StringWriter rw = new StringWriter();
StreamResult tout = new StreamResult(rw);
transformer.transform ( new StreamSource(xmlsrc), tout);
String szHtml = rw.toString();
String outStr = "";
int icnt=0;
String inString;
byte [] data = szHtml.getBytes ("8859_1");
ByteArrayInputStream bais = new ByteArrayInputStream(data);
PrintWriter pw = new PrintWriter(getAgentOutput());
BufferedReader ir = new BufferedReader(
new InputStreamReader(bais));
while ( (inString = ir.readLine()) != null ) {
inString=replace(inString,"\r","");
inString=replace(inString,"\n","");
pw.write(inString);
}
pw.flush();
ir.close();
} catch(Exception e) {
getAgentOutput().println("Content-type: text/html");
getAgentOutput().println("<html><head><title>Taymac</title></head><body>");
getAgentOutput().println("<font size=+1>No Matching Records Found for
the Specified Vendor.<br></br></font>");
getAgentOutput().println(e);
e.printStackTrace();
getAgentOutput().println("</body></html>");
}
}
///////////////////////////////////////////////////////
static String replace( String str, String replace, String with ){
///////////////////////////////////////////////////////
StringBuffer sb = null;
String temp = str;
boolean found = false;
int start = 0;
int stop = 0;
while( ( start = temp.indexOf( replace , stop )) != -1 )
{
found = true;
stop = start + replace.length();
sb = new StringBuffer( temp.length() + with.length() -
replace.length() );
sb.append( temp.substring( 0 , start ) );
sb.append( with );
sb.append( temp.substring( stop , temp.length() ));
temp = sb.toString();
stop += with.length() - replace.length();
}
if( ! found ){
return str;
}else{
return sb.toString();
}
}
}
transformation, due to the placement of some mysterious CR/LF
characters peppered in the HTML. These chars tend to appear in the
middle of HTML tags, like this table cell tag: <tCRLFd>, and it really
mucks up the formatting of the page.
I have taken esults of the transformation, and did a search replace on
all occurrences of a \n or \r character in the result string, but they
still appear. When I do a view source from the browser, the HTML
appears to have removed any "explicit" CRLF's in the file, but there
are still CR/LF chars peppered throughout the file.
I am using a PrintWriter object to write out the results. Could that
be adding in the extra CR/LF's?
I'm stumped.
*****************************************************
CODE
*****************************************************
import lotus.domino.*;
// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
// Imported java classes
import java.io.*;
import java.lang.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
int i,j,k,t, y,x,z;
String str;
String valStr;
String prmStr;
// Get the parameter values entered on form
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document req = agentContext.getDocumentContext();
String qStr = req.getItemValueString("Query_String");
String xmlsrc "d:\\tpr.xml";
String xslsrc = "http://localhost/web/xbb.nsf/tprs.xsl";
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource strSrc = new StreamSource(xslsrc);
Transformer transformer = tFactory.newTransformer(strSrc);
StringWriter rw = new StringWriter();
StreamResult tout = new StreamResult(rw);
transformer.transform ( new StreamSource(xmlsrc), tout);
String szHtml = rw.toString();
String outStr = "";
int icnt=0;
String inString;
byte [] data = szHtml.getBytes ("8859_1");
ByteArrayInputStream bais = new ByteArrayInputStream(data);
PrintWriter pw = new PrintWriter(getAgentOutput());
BufferedReader ir = new BufferedReader(
new InputStreamReader(bais));
while ( (inString = ir.readLine()) != null ) {
inString=replace(inString,"\r","");
inString=replace(inString,"\n","");
pw.write(inString);
}
pw.flush();
ir.close();
} catch(Exception e) {
getAgentOutput().println("Content-type: text/html");
getAgentOutput().println("<html><head><title>Taymac</title></head><body>");
getAgentOutput().println("<font size=+1>No Matching Records Found for
the Specified Vendor.<br></br></font>");
getAgentOutput().println(e);
e.printStackTrace();
getAgentOutput().println("</body></html>");
}
}
///////////////////////////////////////////////////////
static String replace( String str, String replace, String with ){
///////////////////////////////////////////////////////
StringBuffer sb = null;
String temp = str;
boolean found = false;
int start = 0;
int stop = 0;
while( ( start = temp.indexOf( replace , stop )) != -1 )
{
found = true;
stop = start + replace.length();
sb = new StringBuffer( temp.length() + with.length() -
replace.length() );
sb.append( temp.substring( 0 , start ) );
sb.append( with );
sb.append( temp.substring( stop , temp.length() ));
temp = sb.toString();
stop += with.length() - replace.length();
}
if( ! found ){
return str;
}else{
return sb.toString();
}
}
}