Search in sources :

Example 1 with ContentContext

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());
}
Also used : PrintStream(java.io.PrintStream) I18nAccess(org.javlo.i18n.I18nAccess) IContentVisualComponent(org.javlo.component.core.IContentVisualComponent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContentService(org.javlo.service.ContentService) ContentContext(org.javlo.context.ContentContext) RequestService(org.javlo.service.RequestService)

Example 2 with ContentContext

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;
}
Also used : User(org.javlo.user.User) ContentContext(org.javlo.context.ContentContext)

Example 3 with ContentContext

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;
    }
}
Also used : IContentVisualComponent(org.javlo.component.core.IContentVisualComponent) ContentContext(org.javlo.context.ContentContext) ContentElementList(org.javlo.component.core.ContentElementList) LinkedList(java.util.LinkedList)

Example 4 with ContentContext

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;
    }
}
Also used : ContentContext(org.javlo.context.ContentContext)

Example 5 with ContentContext

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;
    }
}
Also used : ContentContext(org.javlo.context.ContentContext)

Aggregations

ContentContext (org.javlo.context.ContentContext)331 GlobalContext (org.javlo.context.GlobalContext)124 IContentVisualComponent (org.javlo.component.core.IContentVisualComponent)119 MenuElement (org.javlo.navigation.MenuElement)73 ContentElementList (org.javlo.component.core.ContentElementList)69 LinkedList (java.util.LinkedList)60 ContentService (org.javlo.service.ContentService)54 I18nAccess (org.javlo.i18n.I18nAccess)40 HashMap (java.util.HashMap)33 RequestService (org.javlo.service.RequestService)32 IOException (java.io.IOException)31 GenericMessage (org.javlo.message.GenericMessage)30 File (java.io.File)28 Date (java.util.Date)27 ServletException (javax.servlet.ServletException)23 StaticInfo (org.javlo.ztatic.StaticInfo)21 IContentComponentsList (org.javlo.component.core.IContentComponentsList)19 PersistenceService (org.javlo.service.PersistenceService)19 HashSet (java.util.HashSet)18 StringWriter (java.io.StringWriter)16