📄 categoryhelper.java
字号:
package com.eline.wap.resource.client;
import java.util.List;
import com.eline.wap.common.model.Page;
import com.eline.wap.resource.dao.CategoryDAO;
import com.eline.wap.resource.dao.ResourceDAOFactory;
import com.eline.wap.resource.exceptions.ResourceDAOSysException;
import com.eline.wap.resource.exceptions.ResourceException;
import com.eline.wap.resource.model.Category;
import com.eline.wap.resource.model.CategoryCondition;
public class CategoryHelper {
private CategoryDAO dao = null;
public Category getCategory(int categoryId) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
return dao.getCategory(categoryId);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
public Page searchCategories(CategoryCondition condition, int start, int count) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
return dao.searchCategories(condition, start, count);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
public void createCategory(Category item) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
dao.createCategory(item);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
public void updateCategory(Category item) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
dao.updateCategory(item);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
public void deleteCategory(int categoryId) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
dao.deleteCategory(categoryId);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
/*public void buildCategoryXmlTree(int type) throws ResourceException {
try {
// 获取所有的指定类型的类目(按parentId排序)
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
List list = dao.getCategoriesForXmlTree(type);
// 建立xml文档
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element categories = doc.createElement("categories");
doc.appendChild(categories);
// 建立根目录
Element rootCategory = doc.createElement("category");
rootCategory.setAttribute("id", "0");
rootCategory.setAttribute("title", "书籍目录");
rootCategory.setAttribute("type", ""+0);
categories.appendChild(rootCategory);
// 将List中记录转换成xml节点
for (int i = 0; i < list.size(); i++) {
Category item = (Category) list.get(i);
Element parent = null;
// 获取父节点
NodeList nodes = categories.getElementsByTagName("category");
for (int j = 0; j < nodes.getLength(); j ++) {
Element e1 = (Element) nodes.item(j);
if (e1.getAttribute("id") != null && e1.getAttribute("id").equals("" + item.getParentId())) {
parent = e1;
}
}
if (parent == null) // sorry, we have to ignore this node. because can't found their parent node.
continue;
Element category = doc.createElement("category");
category.setAttribute("id", ""+item.getIndexId());
category.setAttribute("title", item.getDisplayTitle());
category.setAttribute("type", ""+item.getCategoryAttribute());
parent.appendChild(category);
}
String xmlBodyOut = XMLUtils.toXmlString(doc.getDocumentElement());
System.out.println("buildCategoryXmlTree: xmlBody=" + xmlBodyOut);
} catch (Exception e) {
e.printStackTrace();
throw new ResourceException(e.getMessage());
}
}*/
public List getCategoriesForXmlTree(int type) throws ResourceException {
try {
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
return dao.getCategoriesForXmlTree(type);
} catch (ResourceDAOSysException e) {
throw new ResourceException(e.getMessage());
}
}
/*
public String buildCategoryXmlTree(int type) throws ResourceException {
try {
// 获取所有的指定类型的类目(按parentId排序)
if (dao == null)
dao = ResourceDAOFactory.getCategoryDAO();
List list = dao.getCategoriesForXmlTree(type);
// 建立xml文档
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element frameTable = doc.createElement("table");
frameTable.setAttribute("cellspacing", "0");
frameTable.setAttribute("cellpadding", "0");
frameTable.setAttribute("border", "0");
frameTable.setAttribute("width", "300");
doc.appendChild(frameTable);
// 建立根目录
Category rootItem = new Category();
rootItem.setIndexId(0);
rootItem.setName("根节点");
rootItem.setType(Category.TYPE_BOOK);
frameTable.appendChild(newTreeElement(doc, rootItem));
System.out.println("STEP 1:"+XMLUtils.toXmlString(frameTable));
// 将List中记录转换成xml节点
for (int i = 0; i < list.size(); i++) {
Category item = (Category) list.get(i);
Element parent = null;
// 获取父节点
NodeList nodes = frameTable.getElementsByTagName("td");
for (int j = 0; j < nodes.getLength(); j ++) {
Element e1 = (Element) nodes.item(j);
if (e1.getAttribute("id") != null && e1.getAttribute("id").equals("t_" + item.getParentId())) {
parent = e1;
}
}
if (parent == null) // sorry, we have to ignore this node. because can't found their parent node.
continue;
parent.appendChild(newTreeElement(doc, item));
}
String xmlBodyOut = XMLUtils.toXmlString(doc.getDocumentElement());
System.out.println("buildCategoryXmlTree: xmlBody=" + xmlBodyOut);
return xmlBodyOut;
} catch (Exception e) {
e.printStackTrace();
throw new ResourceException(e.getMessage());
}
}
public Element newTreeElement(Document doc, Category item) throws Exception {
// 框架表
Element table = doc.createElement("table");
table.setAttribute("cellspacing", "0");
table.setAttribute("cellpadding", "0");
table.setAttribute("border", "0");
table.setAttribute("width", "100%");
// 第一个tr: 按钮
Element tr1 = doc.createElement("tr");
table.appendChild(tr1);
Element td1 = doc.createElement("td");
td1.setAttribute("onclick", "javascript:treeViewItem_onclick(" + item.getIndexId() + ")");
tr1.appendChild(td1);
Text t1 = doc.createTextNode(item.getDisplayTitle());
td1.appendChild(t1);
System.out.println("OK");
// 第二个tr: 子菜单
Element tr2 = doc.createElement("tr");
table.appendChild(tr2);
Element td2 = doc.createElement("td");
td2.setAttribute("id", "t_" + item.getIndexId());
td2.setAttribute("style", "display: none");
tr2.appendChild(td2);
return table;
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -