Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/standalone editor #60

Merged
merged 5 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -67,7 +67,7 @@ public Page getPage() {
}

public String getUrl() {
return page.getUrl(language, true);
return page.getUrl(language, true, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.composum.pages.commons.service.ThemeManager;
import com.composum.pages.commons.util.LinkUtil;
import com.composum.pages.commons.util.LinkUtil.Parameters;
import com.composum.pages.commons.util.UrlMap;
import com.composum.platform.models.annotations.DetermineResourceStategy;
import com.composum.platform.models.annotations.PropertyDetermineResourceStrategy;
import com.composum.sling.core.BeanContext;
Expand Down Expand Up @@ -534,15 +535,28 @@ public String getCanonicalUrl() {
@Override
public String getUrl() {
if (url == null) {
url = getUrl(getLanguage(), false);
url = getUrl(getLanguage(), false, null);
}
return url;
}

/**
* @return a dynamic helper map to decorate the page url with selectors specified by the a maps key
*/
public Map<String, String> getUrls() {
return new UrlMap(new UrlMap.Builder() {
@Nonnull
@Override
public String buildUrl(@Nonnull String selectors) {
return getUrl(getLanguage(), false, selectors);
}
});
}

@Nonnull
public String getUrl(boolean preserveParameters) {
if (url == null) {
url = getUrl(getLanguage(), preserveParameters);
url = getUrl(getLanguage(), preserveParameters, null);
}
return url;
}
Expand All @@ -552,9 +566,10 @@ public String getUrl(boolean preserveParameters) {
* - decorated with the locale URL parameter if the language is not the default language
*/
@Nonnull
public String getUrl(@Nonnull final Language language, boolean preserveParameters) {
public String getUrl(@Nonnull final Language language, boolean preserveParameters,
@Nullable final String selectors) {
SlingHttpServletRequest request = context.getRequest();
String pageUrl = LinkUtil.getUrl(request, getPath(), null, null);
String pageUrl = LinkUtil.getUrl(request, getPath(), selectors, null);
Parameters parameters = preserveParameters ? new Parameters(request) : new Parameters();
if (language.equals(getPageLanguages().getDefaultLanguage())) {
parameters.remove(LOCALE_REQUEST_PARAM);
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
Loading