xidyn/webapp-examples/WEB-INF/classes/xid/Test.java

165 lines
4 KiB
Java
Raw Normal View History

2007-01-12 06:35:01 +01:00
/*
*
*/
package xid;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import xid.*;
/**
*
*/
public class Test extends HttpServlet
{
static private org.apache.log4j.Logger log;
static
{
log = org.apache.log4j.Logger.getLogger (Test.class.getName());
}
/**
*
*/
public void doPost (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
doGet (req, res);
}
/**
*
*/
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
log.info ("Enter");
Presenter xid = new Presenter (getServletContext ().getRealPath ("/"), "testXid.html");
//
TagsData datas = new TagsData ();
TextTagData text;
// Populate attributes of Test 03.
text = new TextTagData ();
datas.put ("test03", text);
text.setText ("mummy");
text.getAttributes ().appendAttribute ("style", "background: blue;");
text.getAttributes ().appendAttribute ("style", "foreground: red;");
text.getAttributes ().setAttribute ("class", "totoClass");
// Populate attributes of Test 04.
text = new TextTagData ();
text.getAttributes ().setAttribute ("title", "another title");
datas.put ("test04", text);
// Populate attributes of Test 05.
text = new TextTagData ();
datas.put ("test05", text);
text.getAttributes ().appendAttribute ("style", "background: blue;");
text.getAttributes ().appendAttribute ("style", "foreground: red;");
text.getAttributes ().setAttribute ("class", "aClass");
// Populate attributes of Test 06.
text = new TextTagData ();
text.getAttributes ().appendAttribute ("style", "foreground: red;");
text.getAttributes ().setAttribute ("class", "aClass");
datas.put ("test06", text);
// Populate attributes of Test 07.
text = new TextTagData ();
text.getAttributes ().setAttribute ("width", "50%");
datas.put ("test07", text);
// Populate attributes of Test 09.
text = new TextTagData ();
text.getAttributes ().setAttribute ("class", "xid:nodisplay");
datas.put ("test09", text);
StringBuffer html;
StringBuffer errorMessage;
errorMessage = new StringBuffer ();
html = xid.doXid (datas, errorMessage);
// Display page.
response.setContentType ("text/html");
PrintWriter out = response.getWriter();
out.println ("<html>");
out.println ("<head>");
out.println ("<title>XID TEST</title>");
out.println ("</head>");
out.println ("<body bgcolor=\"orange\">");
out.println ("<hr />");
out.println ("XID TEST<br/>");
if (errorMessage.length () != 0)
{
out.println ("An error occured in Xid treatment.<br/>");
out.println ("<pre>");
out.println (errorMessage);
out.println ("</pre>");
out.println ("<hr />");
out.println ("<pre>" + Presenter.restoreEntities (html) + "</pre>");
out.println ("<hr />");
}
else
{
out.println ("<pre>" + Presenter.restoreEntities (html) + "</pre>");
}
out.println ("</body>");
out.println ("</html>");
log.info ("Exit");
}
/*
*
*/
static public String extractBody (StringBuffer data)
{
String result = null;
// Extraire le contenu du body.
String dataLowerCase = data.toString ().toLowerCase ();
int startBody = dataLowerCase.indexOf ("<body>") + 6;
int endBody = dataLowerCase.indexOf ("</body>");
// Note: as failed search is improbable, no care about complexity
// in failed search case.
if ((startBody == -1) || (endBody == -1))
{
result = null;
}
else
{
result = data.substring (startBody, endBody).trim ();
}
//
return (result);
}
}
// ////////////////////////////////////////////////////////////////////////