001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans.admin.main;
034:
035: import com.flexive.faces.messages.FxFacesMsgErr;
036: import com.flexive.shared.EJBLookup;
037: import com.flexive.shared.interfaces.TemplateEngine;
038: import com.flexive.shared.tree.FxTemplateInfo;
039: import com.flexive.shared.tree.FxTreeMode;
040:
041: import javax.faces.model.SelectItem;
042: import java.util.ArrayList;
043: import java.util.List;
044:
045: public class ContentTemplateBean {
046:
047: private TemplateEngine template = null;
048: private FxTemplateInfo info = null;
049: private String content;
050: private boolean inUse = false;
051:
052: protected String getOverviewPage() {
053: return "contentTemplateOverview";
054: }
055:
056: protected String getEditPage() {
057: return "contentTemplateEdit";
058: }
059:
060: public TemplateEngine.Type getTemplateType() {
061: return TemplateEngine.Type.CONTENT;
062: }
063:
064: public ContentTemplateBean() {
065: template = EJBLookup.getTemplateEngine();
066: }
067:
068: public boolean getIsInUse() {
069: return inUse;
070: }
071:
072: public List<SelectItem> getTypeOptions() {
073: ArrayList<SelectItem> options = new ArrayList<SelectItem>(3);
074: options.add(new SelectItem("html", "html"));
075: options.add(new SelectItem("jsf", "jsf"));
076: options.add(new SelectItem("txt", "txt"));
077: options.add(new SelectItem("xhtml", "xhtml"));
078: options.add(new SelectItem("jsp", "jsp"));
079: return options;
080: }
081:
082: public List<FxTemplateInfo> getList() {
083: try {
084: return template.list(getTemplateType());
085: } catch (Throwable t) {
086: new FxFacesMsgErr(t).addToContext();
087: return new ArrayList<FxTemplateInfo>(0);
088: }
089: }
090:
091: public boolean isNew() {
092: return info == null || info.getId() == -1;
093: }
094:
095: public FxTemplateInfo getInfo() {
096: if (info == null)
097: info = new FxTemplateInfo(getTemplateType(), false, false,
098: false); // TODO
099: return info;
100: }
101:
102: public void setInfo(FxTemplateInfo info) {
103: this .info = info;
104: }
105:
106: public String gotoNewScreen() {
107: return getEditPage();
108: }
109:
110: public String create() {
111: try {
112: long id = template.create(info.getName(),
113: getTemplateType(), info.getContentType(), content);
114: info.setId(id);
115: return load();
116: } catch (Throwable t) {
117: new FxFacesMsgErr(t).addToContext();
118: return getEditPage();
119: }
120: }
121:
122: public String load() {
123: try {
124: this .info = template.getInfo(this .getInfo().getId(),
125: FxTreeMode.Edit); // TODO: LIVE/EDIT
126: this .inUse = template.templateIsReferenced(this .getInfo()
127: .getId());
128: if (this .info != null) {
129: this .content = template.getContent(info.getId(),
130: FxTreeMode.Edit); // TODO: LIVE/EDIT
131: }
132: return getEditPage();
133: } catch (Throwable t) {
134: new FxFacesMsgErr(t).addToContext();
135: return getOverviewPage();
136: }
137: }
138:
139: public String save() {
140: try {
141: template.setContent(info.getId(), content, info
142: .getContentType(), FxTreeMode.Edit); // TODO
143: template.setName(info.getId(), info.getName());
144: return load();
145: } catch (Throwable t) {
146: new FxFacesMsgErr(t).addToContext();
147: return getEditPage();
148: }
149: }
150:
151: public String activate() {
152: try {
153: template.activate(getInfo().getId());
154: } catch (Throwable t) {
155: new FxFacesMsgErr(t).addToContext();
156: }
157: return null;
158: }
159:
160: public String getContent() {
161: return content;
162: }
163:
164: public void setContent(String content) {
165: this.content = content;
166: }
167: }
|