<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import = "java.io.*,java.util.*,com.hexun.wap.zgpack.*,org.jdom.*,org.jdom.input.*,org.jdom.output.*;" %>
<html>
<head>
<title>Basic News Page</title>
<style type="text/css"><!--td {font-size:12px}--></style>
</head>
<body>
<%
String t = request.getParameter("t")!=null?request.getParameter("t"):"";
String s = request.getParameter("s")!=null?request.getParameter("s"):"";
String d = request.getParameter("detail")!=null?request.getParameter("detail"):"";
String delete = request.getParameter("delete")!=null?request.getParameter("delete"):"";
String id = request.getParameter("id")!=null?request.getParameter("id"):"";
SAXBuilder sb = new SAXBuilder();
String indent = " ";
boolean newLines = true;
XMLOutputter outp = new XMLOutputter (indent,newLines,"gb2312");
String flag = request.getParameter("flag")!=null?request.getParameter("flag"):"false";
if(flag.equals("true"))
{
byte[] b = t.getBytes("iso8859-1");
String ti = new String(b,"utf-8");
byte[] b2 = s.getBytes("iso8859-1");
String si = new String(b2,"utf-8");
byte[] b3 = d.getBytes("iso8859-1");
String di = new String(b3,"utf-8");
try
{
Document doc=sb.build(new FileInputStream("/usr/local/stockdata/basic.xml"));
Element root=doc.getRootElement();
List list=root.getChildren();
Element article = new Element("message");
article.setAttribute("id",(list.size()+10001)+"");
article.addContent(new Element("title").setText(ti));
article.addContent(new Element("content").setText(di));
article.addContent(new Element("time").setText(si));
doc.getRootElement().addContent(article);
outp.output(doc,new FileOutputStream("/usr/local/stockdata/basic.xml"));
}
catch(Exception e)
{
e.printStackTrace();
}
s = "";
d = "";
t = "";
}
if(delete.equals("true"))
{
new XMLFile().removeContent("/usr/local/stockdata/basic.xml",Integer.parseInt(id));
}
%>
<form action="OperBasic.jsp" method="post">
<table width=80% border=0 bgcolor=#FFE4C4 cellspacing=1 cellpadding=1 align=center>
<tr><td colspan=2>Add Basic News :</td></tr>
<tr>
<td>Title:</td><td><input type="text" name="t" value="<%=t%>" maxlength="60" format="*N" style="border-width:1; border-color:black; border-style:solid;"/></td></tr>
<tr><td>Time/Author:</td><td><input type="text" name="s" value="<%=s%>" maxlength="20" format="*N" style="border-width:1; border-color:black; border-style:solid;"/></td></tr>
<tr><td>Content:</td><td><textarea name="detail" rows="10" cols="66" style="border-width:1; border-color:black; border-style:solid;"></textarea><br/>
</td>
<tr><td colspan=2 align=center><input type="submit" name="submit" value="Add"/></td>
<input type="hidden" name="flag" value="true" maxlength="20" format="*N"/>
</tr>
</table>
</form>
<table width=80% border=0 bgcolor=000000 cellspacing=1 cellpadding=1 align=center><tr><td bgcolor=FF7Dff>ID</td><td bgcolor=FF7Dff>Title</td><td bgcolor=FF7Dff>Content</td><td bgcolor=FF7Dff>Time / Author</td><td bgcolor=FF7Dff>Delete</td></tr>
<%
try
{
Document doc = sb.build(new FileInputStream("/usr/local/stockdata/basic.xml"));
Element root = doc.getRootElement();
List list = root.getChildren();
out.println("all:"+list.size());
for(int i=0;i<list.size();i++)
{
Element item = (Element)list.get(i);
String name = item.getAttribute("id").getValue();
out.println("<tr><td width=5% height=30 align=left bgcolor=FF7D00>"+name+"</td>");
Element sub = item.getChild("title");
String text = sub.getText();
out.println("<td width=10% height=30 align=left bgcolor=FF7D00>"+ text+"</td>");
Element sub2 = item.getChild("content");
String text2 = sub2.getText();
out.println("<td width=50% align=left bgcolor=FF7D00>"+ text2+"</td>");
Element sub3 = item.getChild("time");
String text3 = sub3.getText();
out.println("<td width=10% align=left bgcolor=FF7D00>"+ text3+ "</td>");
out.println("<td width=5% align=left bgcolor=FF7D00><a href=OperBasic.jsp?delete=true&id="+ i +" οnclick=/"{if(confirm("+"'are you sure?'"+")){return true;}return false;}/">Delete</a></td>");
//out.println("<td width=5% align=left bgcolor=FF7D00><a href=OperBasic.jsp?delete=true&id="+ i + ">Delete</a></td>");
out.println("</tr>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
<br/>
</body>
</html>