📄 createbuilder.java
字号:
package com.jdon.cms.pagebuilder;
import com.jdon.cms.PageBuilder;
import com.jdon.cms.template.JspMaker;
import com.jdon.cms.PageBuilder;
import com.jdon.cms.Navlink;
import com.jdon.cms.Menu;
import com.jdon.cms.Body;
import com.jdon.cms.Page;
import com.jdon.cms.PageFactory;
import com.jdon.cms.events.PageEvent;
import com.jdon.util.Debug;
import com.jdon.cms.xml.XmlUtil;
public class CreateBuilder implements PageBuilder {
private final static String module = CreateBuilder.class.getName();
private final static XmlUtil xmlUtil = XmlUtil.getInstance();
private final static PageFactory pageFactory = PageFactory.getInstance();
private Page page = null;
private int actionType;
public CreateBuilder(PageEvent pageEvent) {
this.page = pageEvent.getPage();
this.actionType = pageEvent.getActionType();
}
/**
* 1. create new Menu Object
* 2. save the object to the persistence
* @param pageEvent
* @return Menu
*/
public Menu buildMenu(Integer Id) {
Debug.logVerbose(" -->> enter build menu:" + page.getName(), module);
Menu menu = pageFactory.createMenu(Id);
pageFactory.updateMenu(menu, page);
Debug.logVerbose("menu object created, ID is " + menu.getId(), module);
Navlink navlink = page.getNavlink();
navlink.setId(Id);
//add the menu to the navlink
navlink.addMenu(menu);
try {
//write Obejct to XML file;
pageFactory.saveNavlink(navlink);
Debug.logVerbose(" --> >build Menu ok", module);
page.setNavlink(navlink);
} catch (Exception ex) {
Debug.logError(" build Menu error:" + ex, module);
menu = null;
}
return menu;
}
public String buildContent(Integer Id) {
String output = null;
try {
output = pageFactory.saveContent(Id, page.getHtmlText());
//htmlText was even the content of the page,
//now it is the file name that contains the content of the page
page.setHtmlText(output);
} catch (Exception ex) {
Debug.logError("buildContent error:" + ex, module);
}
return output;
}
public Body buildBody(Integer Id) {
Debug.logVerbose(" -->> enter build Body " + page.getTitle(), module);
String author = "";
String title = page.getTitle();
//body's content is the file name that contains the content of the page
String content = page.getHtmlText();
Integer hits = new Integer(0);
Integer status = new Integer(0);
Body body = null;
try {
body = pageFactory.createBody(Id);
body.setAuthor(author);
body.setTitle(title);
body.setContent(content);
body.setHits(hits);
body.setStatus(status);
pageFactory.updateBody(body);
} catch (Exception e) {
Debug.logError(" build body error in :" + e);
}
return body;
}
public boolean buildTemplate(Integer Id) {
boolean success = false;
Menu menu = null;
try {
Debug.logVerbose("--> find the menu by the Id: " + Id, module);
menu = pageFactory.getMenu(Id, page.getNavlink());
if (menu == null)
return success;
String titleValue = menu.getName();
String bodyValue = menu.getDataLink();
Debug.logVerbose("--> jspFileName =" + menu.getLink() + " bodyValue=" +
bodyValue, module);
String jspPathName = XmlUtil.getJspDirStr(menu.getId().toString());
success = JspMaker.generate(jspPathName, titleValue, bodyValue);
} catch (Exception ex) {
Debug.logError(" nof get the menu id =" + Id, module);
return success;
}
return success;
}
public Page getPage() {
return this.page;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -