use of org.javlo.context.ContentContext in project javlo by Javlo.
the class DynamicComponentCreator method getViewXHTMLCode.
@Override
public String getViewXHTMLCode(ContentContext ctx) throws Exception {
if (ctx.getCurrentUser() == null) {
return "";
}
ctx.getRequest().setAttribute(REQUEST_KEY, true);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
PrintStream out = new PrintStream(outStream);
RequestService rs = RequestService.getInstance(ctx.getRequest());
out.println("<form action=\"" + URLHelper.createURL(ctx) + "\" method=\"post\" enctype=\"multipart/form-data\">");
I18nAccess i18nAccess = I18nAccess.getInstance(ctx.getRequest());
if (rs.getParameter("new", null) == null && rs.getParameter("id", null) == null && rs.getParameter("edit", null) == null || rs.getParameter("valid", null) != null || rs.getParameter("cancel", null) != null || rs.getParameter("delete", null) != null) {
out.println("<div class=\"form-group\">");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"new\">" + i18nAccess.getViewText("global.create") + ' ' + getValue() + "</button>");
out.println("</div>");
} else if (rs.getParameter("new", null) != null || rs.getParameter("edit", null) != null) {
ContentService contentService = ContentService.getInstance(ctx.getRequest());
DynamicComponent compDef = (DynamicComponent) contentService.getComponent(ctx, rs.getParameter("id", null));
String id = StringHelper.getRandomId();
if (compDef == null) {
compDef = (DynamicComponent) ComponentFactory.getComponentWithType(ctx, getValue());
if (compDef == null) {
return "<div class=\"alert alert-danger\" role=\"alert\">technical error : '" + getValue() + "' not found.</div>";
}
} else {
id = compDef.getId();
}
compDef.getComponentBean().setId(id);
out.println("<div class=\"card\"><div class=\"card-body\"><h4 class=\"card-title\">" + i18nAccess.getViewText("global.new") + "</h4>");
ContentContext editCtx = new ContentContext(ctx);
i18nAccess.forceReloadEdit(ctx.getGlobalContext(), ctx.getRequest().getSession(), ctx.getRequestContentLanguage());
editCtx.setContextRequestLanguage(ctx.getRequestContentLanguage());
editCtx.setRenderMode(ContentContext.EDIT_MODE);
out.println(compDef.getEditXHTMLCode(editCtx));
i18nAccess.resetForceEditLg();
out.println("<div><input type=\"hidden\" name=\"type\" value=\"" + getValue() + "\" />");
out.println("<input type=\"hidden\" name=\"id\" value=\"" + id + "\" />");
out.println("<input type=\"hidden\" name=\"webaction\" value=\"" + getActionGroupName() + ".createcomponent\" />");
out.println("</div>");
out.println("<div class=\"form-group pull-right\">");
out.println("<button class=\"btn btn-primary\" type=\"submit\" name=\"create\">" + i18nAccess.getViewText("global.ok") + "</button>");
out.println("<button class=\"btn btn-warning\" type=\"submit\" name=\"delete\" value=\"1\">" + i18nAccess.getViewText("global.delete") + "</button>");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"cancel\">" + i18nAccess.getViewText("global.cancel") + "</button>");
out.println("</div></div>");
} else if (rs.getParameter("id", null) != null) {
ContentService contentService = ContentService.getInstance(ctx.getRequest());
IContentVisualComponent comp = contentService.getComponent(ctx, rs.getParameter("id", null));
if (comp == null) {
logger.severe("component not found : " + rs.getParameter("id", null));
return "component not found : " + rs.getParameter("id", null);
}
ctx.getRequest().setAttribute(EDIT_KEY, true);
out.println(comp.getXHTMLCode(ctx));
ctx.getRequest().removeAttribute(EDIT_KEY);
out.println("<div class=\"form-group\">");
out.println("<input type=\"hidden\" name=\"id\" value=\"" + rs.getParameter("id", null) + "\" />");
out.println("<button class=\"btn btn-primary\" type=\"submit\" name=\"valid\">" + i18nAccess.getViewText("global.ok") + "</button>");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"edit\" >" + i18nAccess.getViewText("global.edit") + "</button>");
out.println("</div>");
}
out.println("</form>");
out.close();
return new String(outStream.toByteArray());
}
use of org.javlo.context.ContentContext in project javlo by Javlo.
the class AbstractVisualComponent method getHelpURL.
@Override
public final String getHelpURL(ContentContext ctx) {
User user = AdminUserFactory.createUserFactory(ctx.getGlobalContext(), ctx.getRequest().getSession()).getCurrentUser(ctx.getRequest().getSession());
if (user == null) {
return null;
}
String lang = "en";
if (user.getUserInfo().getPreferredLanguage().length > 0) {
lang = user.getUserInfo().getPreferredLanguage()[0];
}
if (getBaseHelpURL(ctx) == null || getBaseHelpURL(ctx).trim().length() == 0) {
return null;
}
String baseURL = getBaseHelpURL(ctx);
ContentContext lgCtx = new ContentContext(ctx);
lgCtx.setAllLanguage(lang);
String url = URLHelper.mergePath(baseURL, getHelpURI(ctx));
return url;
}
use of org.javlo.context.ContentContext in project javlo by Javlo.
the class LanguageCopy method getComponents.
private Collection<IContentVisualComponent> getComponents(ContentContext ctx) {
ContentContext refContext = new ContentContext(ctx);
refContext.setRequestContentLanguage(getRefLanguage(ctx));
ContentElementList refContent;
try {
refContent = ctx.getCurrentPage().getContent(refContext);
Collection<IContentVisualComponent> outComps = new LinkedList<IContentVisualComponent>();
while (refContent.hasNext(refContext)) {
IContentVisualComponent comp = refContent.next(refContext);
if (comp.getType().equals(getRefType())) {
outComps.add(comp);
}
}
return outComps;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.javlo.context.ContentContext in project javlo by Javlo.
the class AbstractVisualComponent method getReferenceComponent.
/**
* search the equivalent component in the default language content.
*
* @throws Exception
*/
@Override
public IContentVisualComponent getReferenceComponent(ContentContext ctx) throws Exception {
if (ctx.getRequestContentLanguage().equals(ctx.getGlobalContext().getDefaultLanguage())) {
return this;
}
int componentPosition = ComponentHelper.getComponentPosition(ctx, this);
if (componentPosition == -1) {
logger.severe("bad component position : " + componentPosition + " type=" + getType() + " area=" + this.getArea());
}
ContentContext lgCtx = ctx.getContextForDefaultLanguage();
IContentVisualComponent refComp = ComponentHelper.getComponentWidthPosition(lgCtx, getPage(), getArea(), getType(), componentPosition);
if (refComp == null) {
logger.warning("ref component not found : type=" + getType() + " position=" + componentPosition);
return null;
} else {
return refComp;
}
}
use of org.javlo.context.ContentContext in project javlo by Javlo.
the class RendererReferenceComponent method getRenderer.
@Override
public String getRenderer(ContentContext ctx) {
ContentContext notAbsCtx = new ContentContext(ctx);
notAbsCtx.setAbsoluteURL(false);
try {
return URLHelper.createStaticTemplateURLWithoutContext(notAbsCtx, ctx.getCurrentTemplate(), getComponentBean().getRenderer());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations