18 package org.turro.publication.zul.portal;
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import javax.servlet.ServletException;
28 import org.turro.string.ObjectString;
29 import org.turro.string.Strings;
30 import org.jdom.Element;
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.Parser;
35 import org.turro.mail.recipients.MailContact;
36 import org.turro.publication.db.PublicationPU;
37 import org.turro.publication.entity.Publication;
38 import org.turro.publication.util.PublicationCategories;
39 import org.turro.zul.portal.IPortalContent;
40 import org.zkoss.zul.Html;
41 import org.zkoss.zul.Style;
42 import org.zkoss.zul.Window;
51 private long groupId, categoryId, publicationId;
52 private boolean accepted, title =
true, details =
true, summary =
true, body =
true;
54 private String sclass, contactId;
58 if(contactId !=
null) {
59 root.setAttribute(
"contactId", contactId);
61 root.removeAttribute(
"contactId");
63 root.setAttribute(
"groupId", groupId +
"");
64 root.setAttribute(
"categoryId", categoryId +
"");
65 root.setAttribute(
"publicationId", publicationId +
"");
66 root.setAttribute(
"accepted", Boolean.toString(accepted));
67 root.setAttribute(
"title", Boolean.toString(title));
68 root.setAttribute(
"details", Boolean.toString(details));
69 root.setAttribute(
"summary", Boolean.toString(summary));
70 root.setAttribute(
"body", Boolean.toString(body));
71 root.setAttribute(
"max", max +
"");
72 root.setAttribute(
"sclass", sclass);
77 contactId = root.getAttributeValue(
"contactId");
78 groupId = Long.valueOf(root.getAttributeValue(
"groupId"));
79 categoryId = Long.valueOf(root.getAttributeValue(
"categoryId"));
80 publicationId = (Long) ObjectString.parseNativeString(root.getAttributeValue(
"publicationId"), Long.class,
true);
81 accepted = Boolean.valueOf(root.getAttributeValue(
"accepted"));
82 title = Boolean.valueOf(root.getAttributeValue(
"title"));
83 details = Boolean.valueOf(root.getAttributeValue(
"details"));
84 summary = Boolean.valueOf(root.getAttributeValue(
"summary"));
85 body = Boolean.valueOf(root.getAttributeValue(
"body"));
86 max = Integer.valueOf(root.getAttributeValue(
"max"));
87 sclass = root.getAttributeValue(
"sclass");
89 if(publicationId != 0) {
94 max, groupId, categoryId, contactId, accepted));
104 html.setContent(
getPublicationsStr(publications, sclass, title, details, summary, body,
114 String sclass,
boolean title,
boolean details,
115 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
118 sclass, title, details, summary, body, path, asMail, readAll, constructor);
122 String sclass,
boolean title,
boolean details,
123 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
125 StringBuilder sb =
new StringBuilder();
126 boolean firstOne =
false;
131 sb.append(
"<div class='divider'></div>");
133 writePublication(
template, sb, pub, sclass, title, details, summary, body, path, asMail, readAll, constructor);
135 return sb.toString();
139 String sclass,
boolean title,
boolean details,
140 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
143 sclass, title, details, summary, body, path, asMail, readAll, constructor);
147 String sclass,
boolean title,
boolean details,
148 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
150 StringBuilder sb =
new StringBuilder();
151 boolean firstOne =
false;
156 sb.append(
"<div class='divider'></div>");
158 writePublication(sb, pub, sclass, title, details, summary, body, path, asMail, readAll, constructor);
160 return sb.toString();
165 StringBuilder sb =
new StringBuilder();
166 writeAsPublication(sb, publication, sclass, constructor);
167 return sb.toString();
172 StringBuilder sb =
new StringBuilder();
173 writeAsPublication(sb, publication, sclass, constructor);
174 return sb.toString();
177 private static void writeAsPublication(StringBuilder sb, String publication,
181 writePublication(sb, pub, sclass,
false,
false,
true,
false,
null,
false,
null, constructor);
184 private static void writePublication(StringBuilder sb, Publication pub,
185 String sclass,
boolean title,
boolean details,
186 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
187 IConstructor constructor) {
188 sb.append(
"<div class='publication" +
189 (Strings.isBlank(sclass) ?
"" :
" " + sclass) +
193 sb.append(
"<h1 class='title'>");
194 if(asMail && path !=
null) {
195 sb.append(MailContact.createLink(pub.getTitle(), path +
"?pubid=" + pub.getId() +
"&item=" + pub.getId(),
false));
198 sb.append(
"<a href='" + path +
"?pubid=" + pub.getId() +
"&item=" + pub.getId() +
"'>");
200 sb.append(pub.getTitle());
208 if(details && pub.getPublicationGroup().isSomeDetailToShow()) {
209 sb.append(
"<div class='details'>");
210 if(pub.getPublicationGroup().isShowCategory()) {
211 sb.append(
"<span class='category'>" + pub.getPublicationCategory().getName() +
"</span>");
213 if(pub.getPublicationGroup().isShowDate()) {
214 sb.append(
"<span class='date'>" + pub.getDateStr() +
"</span>");
216 if(pub.getPublicationGroup().isShowAuthor()) {
217 sb.append(
"<span class='author'>" + pub.getAuthor() +
"</span>");
219 if(pub.getPublicationGroup().isShowReads()) {
220 sb.append(
"<span class='reads'>" + pub.getReadings() +
"</span>");
225 if(summary && !Strings.isBlank(pub.getSummary())) sb.append(
"<div class='summary'>" + processOutput(constructor, pub.getSummary()) +
"</div>");
227 if(body && !Strings.isBlank(pub.getBody())) sb.append(
"<div class='body'>" + processOutput(constructor, pub.getBody()) +
"</div>");
229 if(!body && path !=
null && readAll !=
null) {
230 sb.append(
"<div class='readallpub'><a href='" + path +
"?pubid=" + pub.getId() +
"&item=" + pub.getId() +
"'>");
238 private static void writePublication(String
template, StringBuilder sb, Publication pub,
239 String sclass,
boolean title,
boolean details,
240 boolean summary,
boolean body, String path,
boolean asMail, String readAll,
241 IConstructor constructor) {
243 if(asMail && path !=
null) {
244 template =
template.replaceAll(
"#title", Parser.escapeGrouping(MailContact.createLink(pub.getTitle(),
245 path +
"?pubid=" + pub.getId() +
"&item=" + pub.getId(),
false)));
248 template =
template.replaceAll(
"#path", path +
"?pubid=" + pub.getId() +
"&item=" + pub.getId());
250 template =
template.replaceAll(
"#title", Parser.escapeGrouping(pub.getTitle()));
253 if(details && pub.getPublicationGroup().isSomeDetailToShow()) {
254 template =
template.replaceAll(
"#category", Parser.escapeGrouping(pub.getPublicationCategory().getName()));
255 if(pub.getPublicationGroup().isShowDate()) {
256 template =
template.replaceAll(
"#date", pub.getDateStr());
258 if(pub.getPublicationGroup().isShowAuthor()) {
259 template =
template.replaceAll(
"#author", Parser.escapeGrouping(pub.getAuthor()));
261 if(pub.getPublicationGroup().isShowReads()) {
262 template =
template.replaceAll(
"#readings", pub.getReadings() +
"");
266 if(summary && !Strings.isBlank(pub.getSummary())) {
267 template =
template.replaceAll(
"#summary", Parser.escapeGrouping(processOutput(constructor, pub.getSummary())));
270 if(body && !Strings.isBlank(pub.getBody())) {
271 template =
template.replaceAll(
"#body", Parser.escapeGrouping(processOutput(constructor, pub.getBody())));
274 template =
template.replaceAll(
"#title",
"");
275 template =
template.replaceAll(
"#path",
"");
276 template =
template.replaceAll(
"#category",
"");
277 template =
template.replaceAll(
"#date",
"");
278 template =
template.replaceAll(
"#author",
"");
279 template =
template.replaceAll(
"#readings",
"");
280 template =
template.replaceAll(
"#comments",
"");
281 template =
template.replaceAll(
"#summary",
"");
282 template =
template.replaceAll(
"#body",
"");
288 private void addDefaults() {
289 appendChild(
new Style(
"/_internal/css/default.css"));
290 appendChild(
new Style(
"/_internal/css/default-site.css"));
291 appendChild(
new Style(
"/_internal/css/publication.css"));
292 appendChild(
new Style(
"/_internal/css/publication-site.css"));
294 html.setWidth(
"100%");
295 html.setHeight(
"100%");
297 setContentStyle(
"overflow:auto");
300 private static String processOutput(IConstructor constructor, String
string) {
302 StringWriter sw =
new StringWriter();
303 PrintWriter pw =
new PrintWriter(sw);
304 constructor.processOutput(pw,
string);
305 return sw.toString();
306 }
catch (ServletException | IOException ex) {
307 Logger.getLogger(PublicationContent.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
IConstructor getConstructor()
static Application getApplication()
void setSummary(String summary)
static List< Publication > getPublicationsBy(int max, long group, long category, String idContact, boolean accepted)
static String getPublicationTemplateStr(String template, Publication publication, String sclass, boolean title, boolean details, boolean summary, boolean body, String path, boolean asMail, String readAll, IConstructor constructor)
void getConfiguration(Element root)
void setPublication(Publication publication)
static String getPublicationsStr(List< Publication > publications, String sclass, boolean title, boolean details, boolean summary, boolean body, String path, boolean asMail, String readAll, IConstructor constructor)
void setPublication(String publication)
void setPublications(List< Publication > publications)
static String getPublicationsTemplateStr(String template, List< Publication > publications, String sclass, boolean title, boolean details, boolean summary, boolean body, String path, boolean asMail, String readAll, IConstructor constructor)
static String getPublicationStr(Publication publication, String sclass, boolean title, boolean details, boolean summary, boolean body, String path, boolean asMail, String readAll, IConstructor constructor)
static String getPublicationTemplateStr(String publication, String sclass, IConstructor constructor)
static String getPublicationStr(String publication, String sclass, IConstructor constructor)
void setConfiguration(Element root)