Skip to content

Commit

Permalink
Merge pull request #60 from ist-dresden/feature/standalone-editor
Browse files Browse the repository at this point in the history
Feature/standalone editor
  • Loading branch information
ist-rw authored Nov 18, 2020
2 parents ed4d39c + 6404505 commit a24fafe
Show file tree
Hide file tree
Showing 48 changed files with 1,193 additions and 353 deletions.
6 changes: 3 additions & 3 deletions commons/bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
com.composum.pages.commons.*
</Export-Package>
<Import-Package>
com.composum.sling.core.*;version="[1.11,2.1)",
com.composum.sling.clientlibs.*;version="[1.11,2.1)",
com.composum.sling.cpnl.*;version="[1.11,2.1)",
com.composum.sling.core.*;version="[1.11,3)",
com.composum.sling.clientlibs.*;version="[1.11,3)",
com.composum.sling.cpnl.*;version="[1.11,3)",
javax.annotation.*;version="[0,4)",
*
</Import-Package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public interface PagesConstants {
String COMPOSUM_PREFIX = "composum-";
String PAGES_PREFIX = COMPOSUM_PREFIX + "pages-";

/** request attributes */
/**
* request attributes
*/

String RA_CONTEXT_PATH = "contextPath";
String RA_RESOURCE_REF = "resourceRef";
String RA_CURRENT_PAGE = "currentPage";
String RA_CURRENT_SITE = "currentSite";
String RA_CURRENT_THEME = "currentTheme";

/** I18N */
/**
* I18N
*/

String PROP_PAGE_LANGUAGES = "pageLanguages";
String LANGUAGES_PATH = "jcr:content/languages";
Expand All @@ -48,7 +52,9 @@ public interface PagesConstants {
String LANGUAGES_ATTR = PAGES_PREFIX + "declared-languages";
String LANGUAGE_CSS_KEY = PAGES_PREFIX + "language";

/** request aspects */
/**
* request aspects
*/

String ACCESS_MODE_REQ_PARAM = PlatformAccessFilter.ACCESS_MODE_PARAM;
String DISPLAY_MODE_SELECT_PARAM = "pages.mode";
Expand All @@ -62,8 +68,12 @@ public interface PagesConstants {
String RA_STICKY_LOCALE = "composum-pages-sticky-locale";

String PAGES_FRAME_PATH = "/bin/pages";
String PAGES_EDITOR_PATH = "/bin/edit";
String PAGES_EDITOR_SELECTOR = "standalone";

/** Component declarations */
/**
* Component declarations
*/

String NT_COMPONENT = CPP_PREFIX + "Component";
String PN_COMPONENT_TYPE = "componentType";
Expand All @@ -72,9 +82,13 @@ public interface PagesConstants {

/* Content elements */

/** the reference path property name of a reference component (for the referrers query) */
/**
* the reference path property name of a reference component (for the referrers query)
*/
String PN_CONTENT_REFERENCE = "contentReference";
/** the key part of a reference component type (for the referrers query) */
/**
* the key part of a reference component type (for the referrers query)
*/
String RES_TYPE_KEY_REFERENCE = "/reference";

String NODE_TYPE_SOMETHING = "nt:unstructured";
Expand All @@ -84,7 +98,9 @@ public interface PagesConstants {
String PROP_ALLOWED_CONTAINERS = "allowedContainers";
String PROP_ALLOWED_ELEMENTS = "allowedElements";

/** Page */
/**
* Page
*/

String NODE_TYPE_PAGE = CPP_PREFIX + "Page";
String NODE_TYPE_PAGE_CONTENT = CPP_PREFIX + "PageContent";
Expand All @@ -111,18 +127,24 @@ public interface PagesConstants {
String DEFAULT_EDIT_CATEGORY = "composum.pages.components.edit";

String SEARCH_PROPS = "search/";
/** Property of a page that, if true, hides the page in search results. */
/**
* Property of a page that, if true, hides the page in search results.
*/
String PROP_IGNORE_IN_SEARCH = SEARCH_PROPS + "ignoreInSearch";

/** Site */
/**
* Site
*/

String DEFAULT_SITES_ROOT = "sites";
String NODE_TYPE_SITE = CPP_PREFIX + "Site";
String NODE_TYPE_SITE_CONFIGURATION = CPP_PREFIX + "SiteConfiguration";
String PROP_HOMEPAGE = "homepage";
String DEFAULT_HOMEPAGE_PATH = "home";

/** Template */
/**
* Template
*/

String PROP_TEMPLATE = "template";
String PROP_IS_TEMPLATE = "isTemplate";
Expand All @@ -145,12 +167,16 @@ public interface PagesConstants {
String PROP_ALLOWED_PATHS = "allowedPaths";
String PROP_FORBIDDEN_PATHS = "forbiddenPaths";

/** Widget */
/**
* Widget
*/

String NODE_TYPE_WIDGET = CPP_PREFIX + "Widget";
String PROP_WIDGET_TYPE = "widgetType";

/** general properties */
/**
* general properties
*/

String PN_TITLE = "title";
String PN_JCR_TITLE = ResourceUtil.PROP_TITLE;
Expand All @@ -165,13 +191,17 @@ public interface PagesConstants {

String NP_SETTINGS = "settings";

/** release & version */
/**
* release & version
*/

String KEY_CURRENT_RELEASE = "current";
String VERSION_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
Pattern RELEASE_LABEL_PATTERN = Pattern.compile("^composum-release-(.+)$");

/** date & time */
/**
* date & time
*/

String PP_FORMAT = "format/";

Expand All @@ -185,7 +215,9 @@ public interface PagesConstants {
String DEF_DATE_FMT = "yyyy-MM-dd";
String DEF_DATETIME_FMT = DEF_DATE_FMT + " " + DEF_TIME_FMT;

/** general rendering */
/**
* general rendering
*/

Pattern TILE_TITLE_URL = Pattern.compile("^(.*/)?([^/?#;]+)([^?#;].*)?");

Expand All @@ -196,7 +228,7 @@ enum ComponentType {

site, page, container, element, something;

public static ComponentType typeOf( @Nullable String string) {
public static ComponentType typeOf(@Nullable String string) {
ComponentType type = something;
if (StringUtils.isNotBlank(string)) {
if (string.startsWith(CPP_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Locale;
import java.util.Objects;

import static com.composum.pages.commons.PagesConstants.PAGES_FRAME_PATH;
import static com.composum.pages.commons.PagesConstants.PROP_TEMPLATE;

/**
Expand Down Expand Up @@ -103,7 +104,7 @@ protected String getCssBaseType() {
public String getEditUrl() {
if (editUrl == null) {
SlingHttpServletRequest request = context.getRequest();
editUrl = LinkUtil.getUrl(request, "/bin/pages.html" + getPath(), null, null);
editUrl = LinkUtil.getUrl(request, PAGES_FRAME_PATH + ".html" + getPath(), null, null);
}
return editUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public String getOpenUri() {
// assuming insufficient permissions (no content access) if homepage is the site itself
return getSiteManager().getPreviewUrl(this);
} else {
return "/bin/pages.html" + getPath();
return PAGES_FRAME_PATH + ".html" + getPath();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.composum.pages.commons.request;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;

import java.util.Locale;

/**
* the rquest wrapper to declare the requets locale
*/
public class LocaleRequestWrapper extends SlingHttpServletRequestWrapper {

protected final Locale locale;

public LocaleRequestWrapper(SlingHttpServletRequest wrappedRequest, Locale locale) {
super(wrappedRequest);
this.locale = locale;
}

@Override
public Locale getLocale() {
return locale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class EditServlet extends PagesContentServlet {
public static final String PAGE_COMPONENT_TYPES = "composum-pages-page-component-types";
public static final String PAGE_COMPONENT_TYPES_SCOPE = PAGE_COMPONENT_TYPES + "_scope";

public static final String STANDALONE_STATIC_RES_TYPE = "composum/pages/stage/edit/sidebar/standalone/static";
public static final String STANDALONE_CONTEXT_RES_TYPE = "composum/pages/stage/edit/sidebar/standalone/context";
public static final String CONTEXT_TOOLS_RES_TYPE = "composum/pages/stage/edit/sidebar/context";

@Reference
Expand Down Expand Up @@ -171,7 +173,7 @@ public enum Operation {
refreshElement, insertElement, moveElement, copyElement,
createPage, deletePage, moveContent, renameContent, copyContent,
createSite, deleteSite,
contextTools, context
standaloneStaticTools, standaloneContextTools, contextTools, context
}

protected PagesEditOperationSet operations = new PagesEditOperationSet();
Expand Down Expand Up @@ -218,6 +220,10 @@ public void init() throws ServletException {
Operation.context, new GetContextResource());
operations.setOperation(ServletOperationSet.Method.GET, Extension.html,
Operation.contextTools, new GetContextTools());
operations.setOperation(ServletOperationSet.Method.GET, Extension.html,
Operation.standaloneStaticTools, new GetStandaloneStaticTools());
operations.setOperation(ServletOperationSet.Method.GET, Extension.html,
Operation.standaloneContextTools, new GetStandaloneContextTools());
operations.setOperation(ServletOperationSet.Method.GET, Extension.html,
Operation.refreshElement, new RefreshElementOperation());
operations.setOperation(ServletOperationSet.Method.GET, Extension.json,
Expand Down Expand Up @@ -1166,18 +1172,42 @@ public void doIt(@Nonnull SlingHttpServletRequest request,
ResourceHandle resource)
throws ServletException, IOException {

String selectors = RequestUtil.getSelectorString(request, null, 1);
String selectors = getSelectors(request);
if (LOG.isDebugEnabled()) {
LOG.debug("GetContextTools({},{})...", resource, selectors);
}

String paramType = request.getParameter(PARAM_TYPE);

RequestDispatcherOptions options = new RequestDispatcherOptions();
options.setForceResourceType(CONTEXT_TOOLS_RES_TYPE);
options.setForceResourceType(getResourecType());
options.setReplaceSelectors(selectors);

forward(request, response, resource, paramType, options);
}

protected String getResourecType() {
return CONTEXT_TOOLS_RES_TYPE;
}

protected String getSelectors(@Nonnull SlingHttpServletRequest request) {
return RequestUtil.getSelectorString(request, null, 1);
}
}

protected class GetStandaloneStaticTools extends GetContextTools {

@Override
protected String getResourecType() {
return STANDALONE_STATIC_RES_TYPE;
}
}

protected class GetStandaloneContextTools extends GetContextTools {

@Override
protected String getResourecType() {
return STANDALONE_CONTEXT_RES_TYPE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.composum.pages.commons.model.Page;
import com.composum.pages.commons.model.PageContent;
import com.composum.pages.commons.request.DisplayMode;
import com.composum.pages.commons.request.LocaleRequestWrapper;
import com.composum.pages.commons.service.PageManager;
import com.composum.pages.commons.service.Theme;
import com.composum.pages.commons.util.ThemeUtil;
Expand Down Expand Up @@ -34,6 +35,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

@Component(service = Servlet.class,
property = {
Expand All @@ -58,7 +60,7 @@ private void activate(final BundleContext bundleContext) {
}

@Override
protected void doGet(@Nonnull final SlingHttpServletRequest request,
protected void doGet(@Nonnull SlingHttpServletRequest request,
@Nonnull final SlingHttpServletResponse response)
throws ServletException, IOException {

Expand All @@ -84,6 +86,13 @@ protected void doGet(@Nonnull final SlingHttpServletRequest request,
}
}

// adjust the requests locale to the locale of the requested page if necessary
// to synchroinze the systems I18N support with the pages locale
Locale pageLocale = page.getLocale();
if (!pageLocale.equals(request.getLocale())) {
request = new LocaleRequestWrapper(request, pageLocale);
}

// determine the page content resource to use for the request forward
for (PageDispatcher dispatcher : pageDispatchers) {
page = dispatcher.getForwardPage(page);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.composum.pages.commons.servlet;

import com.composum.sling.core.BeanContext;
import org.apache.sling.api.request.RequestDispatcherOptions;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.ServletResolverConstants;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import java.util.regex.Pattern;

import static com.composum.pages.commons.PagesConstants.PAGES_EDITOR_PATH;
import static com.composum.pages.commons.PagesConstants.PAGES_EDITOR_SELECTOR;

/**
* The general hook (servlet) for the Pages edit stage; provides the path '/bin/edit.html/...'.
*/
@Component(service = Servlet.class,
property = {
Constants.SERVICE_DESCRIPTION + "=Composum Pages Standalone Servlet",
ServletResolverConstants.SLING_SERVLET_PATHS + "=" + PAGES_EDITOR_PATH,
ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_GET
})
public class PagesStandaloneServlet extends PagesFrameServlet {

public static final Pattern PATH_PATTERN = Pattern.compile("^(" + PAGES_EDITOR_PATH + "(\\.[^/]+)?\\.html)(/.*)?$");

@Override
protected String getServletPath(BeanContext context) {
return PAGES_EDITOR_PATH;
}

@Override
protected Pattern getPathPattern(BeanContext context) {
return PATH_PATTERN;
}

@Override
protected void prepareForward(BeanContext context, RequestDispatcherOptions options) {
super.prepareForward(context, options);
options.setReplaceSelectors(PAGES_EDITOR_SELECTOR);
}

@Override
protected String getConsolePath(BeanContext context) {
return null;
}
}
Loading

0 comments on commit a24fafe

Please sign in to comment.