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

136 lines
3.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");
}
}
// ////////////////////////////////////////////////////////////////////////