18 package org.turro.zul.portal;
21 import java.io.IOException;
22 import java.io.OutputStreamWriter;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.jdom.Document;
26 import org.jdom.Element;
27 import org.jdom.JDOMException;
28 import org.jdom.input.SAXBuilder;
29 import org.jdom.output.Format;
30 import org.jdom.output.XMLOutputter;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.context.IConstructor;
34 import org.turro.elephant.impl.util.FileUtil;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.ext.AfterCompose;
38 import org.zkoss.zkmax.ui.event.Events;
39 import org.zkoss.zkmax.zul.Portallayout;
48 private File userFile, confFile;
52 setSclass(
"portalContainer");
54 addEventListener(Events.ON_PORTAL_MOVE,
new EventListener() {
56 public void onEvent(Event event)
throws Exception {
62 public void setFiles(File userFile, File confFile) {
63 this.userFile = userFile;
64 this.confFile = confFile;
65 if(userFile.exists()) {
66 this.confFile = userFile;
79 private void load(Element root) {
80 label = root.getAttributeValue(
"label");
87 private void readConfiguration() {
88 SAXBuilder builder =
new SAXBuilder();
90 if(confFile.exists()) {
91 Document doc = builder.build(confFile);
92 load(doc.getRootElement());
94 }
catch (IOException ex) {
95 Logger.getLogger(
PortalContainer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
96 }
catch (JDOMException ex) {
97 Logger.getLogger(
PortalContainer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
101 private void save(Element root) {
102 root.setAttribute(
"label", label);
103 columns.
save(root,
this);
106 private void writeConfiguration(IConstructor constructor) {
107 Document doc =
new Document(
new Element(
"elephant-portal"));
108 save(doc.getRootElement());
109 if(!userFile.exists())
new File(org.amic.util.file.FileUtil.getParentPath(userFile.getAbsolutePath())).mkdirs();
111 OutputStreamWriter fw = FileUtil.getFileWriter(userFile);
112 Format fm = Format.getPrettyFormat();
113 fm.setEncoding(ElephantContext.getEncoding());
114 XMLOutputter xo =
new XMLOutputter(fm);
117 }
catch (IOException ex) {
118 Logger.getLogger(
PortalContainer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
125 column.afterCompose();
IConstructor getConstructor()
static Application getApplication()
void save(Element root, PortalContainer container)
void setFiles(File userFile, File confFile)