BrightSide Workbench Full Report + Source Code
ElephantInclude.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zul.portal.content;
19 
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.servlet.ServletException;
26 import org.jdom.Element;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.zul.portal.IPortalContent;
31 import org.zkoss.zul.Html;
32 
37 public class ElephantInclude extends Html implements IPortalContent {
38 
39  private String path, stopper;
40 
41  @Override
42  public void setConfiguration(Element root) {
43  root.setAttribute("path", path);
44  root.setAttribute("stopper", stopper);
45  }
46 
47  @Override
48  public void getConfiguration(Element root) {
49  try {
50  path = root.getAttributeValue("path");
51  stopper = root.getAttributeValue("stopper", "true");
53  StringWriter sw = new StringWriter();
54  constructor.setOut(new PrintWriter(sw));
55  if(path.matches(".*\\.(htm|html|txt)")) {
56  constructor.includeContent(path);
57  } else {
58  constructor.renderContext(path, stopper);
59  }
60  setWidth("100%");
61  setHeight("100%");
62  setContent(sw.toString());
63  } catch (ServletException | IOException ex) {
64  Logger.getLogger(ElephantInclude.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
65  }
66  }
67 
68 }
void renderContext(String path, String stopper)