📄 navlinkmanager.java
字号:
package com.jdon.cms.xml;
import com.jdon.cms.model.MenuModel;
import com.jdon.cms.model.NavlinkModel;
import com.jdon.cms.PageFactory;
import com.jdon.cms.Navlink;
import com.jdon.cms.NavlinkException;
import com.jdon.cms.Menu;
import com.jdon.cms.Page;
import com.jdon.util.Debug;
import com.jdon.util.PropsUtil;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p>Company: </p>
* @author banq
* @version 1.0
*/
public class NavlinkManager {
public final static String module = NavlinkManager.class.getName();
private static PropsUtil propsUtil = PropsUtil.getInstance();
private final static XmlUtil xmlUtil = XmlUtil.getInstance();
private final static PageFactory pageFactory = PageFactory.getInstance();
private String navlink_xmlfile = null;
private String navlink_xmlfile_template = null;
public NavlinkManager() {
navlink_xmlfile = XmlUtil.getConfDirStr(Navlink.NAME);
navlink_xmlfile_template = propsUtil.getConfFile(Navlink.TEMPLATE);
}
/**
* get the NavlinkModel from xml file;
* @return NavlinkModel
*/
public NavlinkModel getNavlinkFromFile() {
NavlinkModel navlink = null;
File file = new File(navlink_xmlfile);
if (!file.exists()) {
navlink = initNavlink();
} else {
try {
Debug.logVerbose(" .... try to get the exsited file :" +
navlink_xmlfile, module);
navlink = (NavlinkModel) CastorHandler.read(
"com.jdon.cms.model.NavlinkModel",
navlink_xmlfile);
} catch (Exception ex) {
Debug.logError(navlink_xmlfile + "existes, can't read from it" + ex,
module);
}
}
navlink.setNew(false);
navlink.setModified(false);
return navlink;
}
/**
* init the navlink
* @return NavlinkModel
*/
private NavlinkModel initNavlink() {
Debug.logVerbose(" .... enter init navlinlk", module);
NavlinkModel navlink = new NavlinkModel();
try {
Debug.logVerbose(" wrtie navlink to xmfile:" + navlink_xmlfile, module);
CastorHandler.write(navlink, navlink_xmlfile);
} catch (Exception ex) {
Debug.logError(" create navlink file error:" + ex, module);
}
return navlink;
}
/**
* create new Menu object
* @param pageEvent
* @return Menu
*/
public Menu createMenu(Integer Id) {
Menu menu = new MenuModel(Id);
return menu;
}
/**
* find a Menu
* @param Id
* @return
* @throws BodyException
*/
public MenuModel findByPrimaryKey(Integer Id, Navlink navlink) {
Debug.logVerbose(" find the menu id = " + Id, module);
List menus = navlink.getMenus();
Iterator iter = menus.iterator();
while (iter.hasNext()) {
MenuModel menu = (MenuModel) iter.next();
if (menu.getId().intValue() == Id.intValue()) {
Debug.logVerbose(" found the menu name is " + menu.getName(), module);
return menu;
}
}
return null;
}
public void deleteMenu(Menu menu, Navlink navlink) {
List menus = navlink.getMenus();
menus.remove(menu);
}
public Menu updateMenu(Menu menu, Page page) {
menu.setName(page.getName());
// menu.setIcon("");
// it is jsp url
menu.setLink(xmlUtil.getJspUrlStr(menu.getId().toString()));
// it is the url of body's data html
menu.setDataLink(xmlUtil.getDataUrlStr(menu.getId().toString()));
return menu;
}
/**
* write the Body object to XML File
* @param body
* @param bodyFile
* @throws BodyException
*/
public void write(NavlinkModel navlink) throws NavlinkException {
Debug.logVerbose(" --- write navlink to file" + navlink_xmlfile, module);
try {
CastorHandler.write(navlink, navlink_xmlfile);
navlink.setNew(false);
navlink.setModified(false);
} catch (Exception e) {
throw new NavlinkException(" create new page error!" + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -