Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 4 additions & 7 deletions src/main/java/com/celements/ajax/AjaxAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ public String render(XWikiContext context) throws XWikiException {
}

private Optional<String> getAjaxScript(XWikiContext context) {
List<String> pathParts = parseRequestPath(context)
.limit(3).collect(toImmutableList());
List<String> pathParts = parseRequestPath(context).limit(3).collect(toImmutableList());
if ((pathParts.size() > 2) && pathParts.get(0).equals(AJAX_SCRIPT_ACTION)) {
String celAjaxScript = "/" + Stream.concat(
Stream.of(CEL_AJAX_SCRIPT_DIR_PROPERTY),
parseRequestPath(context).skip(1))
String celAjaxScript = "/" + Stream
.concat(Stream.of(CEL_AJAX_SCRIPT_DIR_PROPERTY), parseRequestPath(context).skip(1))
.collect(joining("/"));
LOGGER.debug("ajax: found script path '{}'", celAjaxScript);
return Optional.of(celAjaxScript);
Expand All @@ -78,8 +76,7 @@ private Optional<String> getAjaxScript(XWikiContext context) {
}

private Stream<String> parseRequestPath(XWikiContext context) {
return Splitter.on('/')
.splitToStream(context.getRequest().getPathInfo())
return Splitter.on('/').splitToStream(context.getRequest().getPathInfo())
.filter(not(String::isEmpty));
}

Expand Down
44 changes: 17 additions & 27 deletions src/main/java/com/celements/appScript/AppScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ public class AppScriptService implements IAppScriptService {
private final ConfigurationSource xwikiConfigSource;

@Inject
public AppScriptService(
IEmptyCheckRole emptyCheck,
Execution execution,
EntityReferenceValueProvider defaultEntityReferenceValueProvider,
XWikiProvider wikiProvider,
IModelAccessFacade modelAccess,
ModelUtils modelUtils,
ModelContext mContext,
UrlService urlService,
@Named(XWikiConfigSource.NAME) ConfigurationSource xwikiConfigSource) {
public AppScriptService(IEmptyCheckRole emptyCheck, Execution execution,
EntityReferenceValueProvider defaultEntityReferenceValueProvider, XWikiProvider wikiProvider,
IModelAccessFacade modelAccess, ModelUtils modelUtils, ModelContext mContext,
UrlService urlService, @Named(XWikiConfigSource.NAME) ConfigurationSource xwikiConfigSource) {
this.emptyCheck = emptyCheck;
this.execution = execution;
this.defaultEntityReferenceValueProvider = defaultEntityReferenceValueProvider;
Expand Down Expand Up @@ -140,8 +134,7 @@ public Optional<DocumentReference> getAppScriptDocRef(String scriptName) {
@Override
public Optional<DocumentReference> getAppRecursiveScriptDocRef(String scriptName) {
return findAppScriptRecursivly(scriptName,
sn -> hasLocalAppRecursiveScript(sn)
|| hasCentralAppRecursiveScript(sn),
sn -> hasLocalAppRecursiveScript(sn) || hasCentralAppRecursiveScript(sn),
sn -> sn.lastIndexOf("/") > 0).flatMap(scriptNameFound -> {
if (hasLocalAppRecursiveScript(scriptNameFound)) {
return getLocalAppRecursiveScriptDocRef(scriptNameFound);
Expand Down Expand Up @@ -197,27 +190,25 @@ public boolean isAppScriptAvailable(String scriptName) {

@Override
public Optional<String> getAppRecursiveScript(String scriptName) {
return findAppScriptRecursivly(scriptName,
sn -> isAppScriptAvailable(sn + "++"),
sn -> sn.lastIndexOf("/") > 0)
.map(sNT -> sNT + "++")
return findAppScriptRecursivly(scriptName, sn -> isAppScriptAvailable(sn + "++"),
sn -> sn.lastIndexOf("/") > 0).map(sNT -> sNT + "++")
.filter(sNT -> !Strings.isNullOrEmpty(sNT) && isAppScriptAvailable(sNT));
}

@Override
public Optional<String> getAppRecursiveSetupScript(String scriptName) {
return getAppRecursiveScript(scriptName)
.filter(script -> script.endsWith("++"))
return getAppRecursiveScript(scriptName).filter(script -> script.endsWith("++"))
.map(script -> script.substring(0, script.length() - 2) + "_setup++")
.filter(this::isAppScriptAvailable);
}

private Optional<String> findAppScriptRecursivly(String scriptName,
Predicate<String> hasFound, Predicate<String> hasMore) {
private Optional<String> findAppScriptRecursivly(String scriptName, Predicate<String> hasFound,
Predicate<String> hasMore) {
String scriptNameTest = scriptName;
do {
scriptNameTest = reduceOneDirectory(scriptNameTest);
} while (scriptNameTest != null && !hasFound.test(scriptNameTest) && hasMore.test(scriptNameTest));
} while (scriptNameTest != null && !hasFound.test(scriptNameTest)
&& hasMore.test(scriptNameTest));
if (scriptNameTest != null && hasFound.test(scriptNameTest)) {
return Optional.of(scriptNameTest);
}
Expand Down Expand Up @@ -248,8 +239,8 @@ public String getAppScriptURL(String scriptName, String queryString) {
queryString = "xpage=" + IAppScriptService.APP_SCRIPT_XPAGE + "&s=" + scriptName + queryString;
if (scriptName.split("/").length <= 2) {
return urlService.getURL(
modelUtils.resolveRef(scriptName.replace("/", "."), DocumentReference.class),
"view", queryString);
modelUtils.resolveRef(scriptName.replace("/", "."), DocumentReference.class), "view",
queryString);
} else {
return Util.escapeURL("/app/" + scriptName + "?" + queryString);
}
Expand Down Expand Up @@ -318,8 +309,7 @@ private boolean isAppScriptActionRequest() {

private boolean isAppScriptSpaceRequest() {
return "view".equals(getContext().getAction())
&& mContext.getDocRef().orElseThrow().getSpaceReferences().contains(
getCurrentSpaceRef());
&& mContext.getDocRef().orElseThrow().getSpaceReferences().contains(getCurrentSpaceRef());
}

private SpaceReference getCurrentSpaceRef() {
Expand All @@ -340,8 +330,8 @@ String getAppScriptNameFromRequestURL() {
if (path.startsWith(getContext().getAction())) {
path = path.replaceAll("^" + getContext().getAction() + "/+", "");
}
path = path.replaceFirst("^" + defaultEntityReferenceValueProvider.getDefaultValue(
EntityType.SPACE) + "/", "");
path = path.replaceFirst(
"^" + defaultEntityReferenceValueProvider.getDefaultValue(EntityType.SPACE) + "/", "");
if ("".equals(path)) {
path = defaultEntityReferenceValueProvider.getDefaultValue(EntityType.DOCUMENT);
} else if (path.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class RemoteLoginClass extends AbstractClassDefinition implements AuthCla
public static final String CLASS_NAME = "RemoteLoginClass";
public static final String CLASS_DEF_HINT = AuthClass.CLASS_SPACE + "." + CLASS_NAME;

public static final ClassField<String> FIELD_URL = new StringField.Builder(CLASS_DEF_HINT,
"url").size(30).build();
public static final ClassField<String> FIELD_URL = new StringField.Builder(CLASS_DEF_HINT, "url")
.size(30).build();

public static final ClassField<Integer> FIELD_TIMEOUT = new IntField.Builder(CLASS_DEF_HINT,
"timeout").size(30).build();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/celements/captcha/CaptchaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public boolean checkCaptcha() {
String answer = getContext().getRequest().get("captcha_answer");
if ((answer != null) && (answer.length() > 0)) {
try {
LOGGER.info("Checking answer for user id '" + getCaptchaVerifier().getUserId(
getContext().getRequest()) + "'");
LOGGER.info("Checking answer for user id '"
+ getCaptchaVerifier().getUserId(getContext().getRequest()) + "'");
String anwserCacheKey = "captcha_" + getCaptchaType() + "_anwserCache";
if (!getContext().containsKey(anwserCacheKey)) {
Boolean isAnswerCorrect = getCaptchaVerifier().isAnswerCorrect(
getContext().getRequest().get("captcha_id"), answer);
Boolean isAnswerCorrect = getCaptchaVerifier()
.isAnswerCorrect(getContext().getRequest().get("captcha_id"), answer);
getContext().put(anwserCacheKey, isAnswerCorrect);
}
return (Boolean) getContext().get(anwserCacheKey);
Expand Down
30 changes: 12 additions & 18 deletions src/main/java/com/celements/cells/AbstractRenderStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,21 @@ public final Contextualiser getContextualiser(@Nullable TreeNode node) {
LOGGER.trace("getContextualiser: cell [{}]", node.getDocumentReference());
Optional<String> scopeKey = getRenderScopeKey(node.getDocumentReference());
scopeKey.map(key -> key + EXEC_CTX_KEY_DOC_SUFFIX)
.map(LogUtils.<String, Object>logF(execution.getContext()::getProperty)
.debug(LOGGER).msg("getContextualiser"))
.flatMap(doc -> tryCast(doc, XWikiDocument.class))
.ifPresent(contextualiser::withDoc);
.map(LogUtils.<String, Object>logF(execution.getContext()::getProperty).debug(LOGGER)
.msg("getContextualiser"))
.flatMap(doc -> tryCast(doc, XWikiDocument.class)).ifPresent(contextualiser::withDoc);
scopeKey.map(key -> key + EXEC_CTX_KEY_OBJ_NB_SUFFIX)
.map(LogUtils.<String, Object>logF(execution.getContext()::getProperty)
.debug(LOGGER).msg("getContextualiser"))
.map(LogUtils.<String, Object>logF(execution.getContext()::getProperty).debug(LOGGER)
.msg("getContextualiser"))
.ifPresent(nb -> contextualiser.withExecContext(EXEC_CTX_KEY_OBJ_NB, nb));
}
return contextualiser;
}

private Optional<String> getRenderScopeKey(DocumentReference cellDocRef) {
return XWikiObjectFetcher.on(modelAccess.getOrCreateDocument(cellDocRef))
.filter(KeyValueClass.FIELD_KEY, "cell-render-scope")
.fetchField(KeyValueClass.FIELD_VALUE)
.stream().findFirst()
.map(scope -> EXEC_CTX_KEY + "." + scope);
.filter(KeyValueClass.FIELD_KEY, "cell-render-scope").fetchField(KeyValueClass.FIELD_VALUE)
.stream().findFirst().map(scope -> EXEC_CTX_KEY + "." + scope);
}

@Override
Expand All @@ -153,13 +150,12 @@ public void startRenderCell(@NotNull TreeNode node, boolean isFirstItem, boolean
DocumentReference cellDocRef = node.getDocumentReference();
LOGGER.debug("startRenderCell: cellDocRef [{}]", cellDocRef);
collectCellAttributes(cellDocRef, attrBuilder);
getCellTypeConfig(cellDocRef).ifPresent(cellTypeConfig -> cellTypeConfig
.collectAttributes(attrBuilder, cellDocRef));
getCellTypeConfig(cellDocRef)
.ifPresent(cellTypeConfig -> cellTypeConfig.collectAttributes(attrBuilder, cellDocRef));
cellWriter.openLevel(getTagName(cellDocRef).orElse(null), attrBuilder.build());
}

private void collectCellAttributes(DocumentReference cellDocRef,
AttributeBuilder attrBuilder) {
private void collectCellAttributes(DocumentReference cellDocRef, AttributeBuilder attrBuilder) {
try {
XWikiDocument cellDoc = modelAccess.getDocument(cellDocRef);
XWikiObjectFetcher fetcher = XWikiObjectFetcher.on(cellDoc).filter(CellClass.CLASS_REF);
Expand Down Expand Up @@ -197,10 +193,8 @@ private Optional<String> collectId(DocumentReference cellDocRef, XWikiObjectFetc
.orElseGet(() -> "cell:" + modelUtils.serializeRef(cellDocRef, COMPACT).replace(":", ".."))
+ Stream.of(EXEC_CTX_KEY_OBJ_NB, EXEC_CTX_KEY_GLOBAL_OBJ_NB)
.map(execution.getContext()::getProperty)
.map(val -> Ints.tryParse(Objects.toString(val)))
.filter(Objects::nonNull)
.map(nb -> "_" + nb)
.findFirst().orElse("");
.map(val -> Ints.tryParse(Objects.toString(val))).filter(Objects::nonNull)
.map(nb -> "_" + nb).findFirst().orElse("");
Set<String> ids = execution.getContext().computeIfAbsent(EXEC_CTX_KEY + ".ids", HashSet::new);
if (ids.contains(id)) {
LOGGER.warn("collectId - cell id [{}] generated multiple times for [{}]", id, cellDocRef);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/celements/cells/AbstractWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ protected Optional<Entry<String, Boolean>> getCurrentLevel() {
}

protected Optional<Boolean> hasLevelContentOptional() {
return getCurrentLevel()
.map(Entry::getValue);
return getCurrentLevel().map(Entry::getValue);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/celements/cells/CellsClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ public void getTranslationBoxCellConfigClass() throws XWikiException {
doc = modelAccess.getOrCreateDocument(translationBoxCellConfigClassRef);
BaseClass bclass = doc.getXClass();
bclass.setXClassReference(translationBoxCellConfigClassRef);
needsUpdate |= bclass.addTextField("page_exceptions", "Page Exceptions (FullNames"
+ " comma separated)", 30);
needsUpdate |= bclass.addTextField("pagetype_exceptions", "Page Type Exceptions"
+ " (FullNames comma separated)", 30);
needsUpdate |= bclass.addTextField("page_exceptions",
"Page Exceptions (FullNames" + " comma separated)", 30);
needsUpdate |= bclass.addTextField("pagetype_exceptions",
"Page Type Exceptions" + " (FullNames comma separated)", 30);

setContentAndSaveClassDocument(doc, needsUpdate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/celements/cells/CellsScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public DocumentReference getPageDependentDocRef(DocumentReference currentPageRef
public Document getPageDependentTranslatedDocument(Document currentDoc,
DocumentReference cellDocRef) {
try {
return getPageDepDocRefCmd().getTranslatedDocument(getCurrentXWikiDoc(currentDoc),
cellDocRef).newDocument(getContext());
return getPageDepDocRefCmd().getTranslatedDocument(getCurrentXWikiDoc(currentDoc), cellDocRef)
.newDocument(getContext());
} catch (XWikiException exp) {
LOGGER.error("Failed to get xwiki document for [" + currentDoc.getDocumentReference() + "].",
exp);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/celements/cells/ICellsClassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface ICellsClassConfig {
@Deprecated
String CELEMENTS_CELL_CLASS_NAME = "CellClass";
@Deprecated
String CELEMENTS_CELL_CLASS = CELEMENTS_CELL_CLASS_SPACE + "."
+ CELEMENTS_CELL_CLASS_NAME;
String CELEMENTS_CELL_CLASS = CELEMENTS_CELL_CLASS_SPACE + "." + CELEMENTS_CELL_CLASS_NAME;
@Deprecated
String CELLCLASS_TAGNAME_FIELD = CellClass.FIELD_TAG_NAME.getName();
@Deprecated
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/celements/cells/RenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ void renderCell(TreeNode node, boolean isFirstItem, boolean isLastItem) {
if (renderStrategy.isRenderCell(node)) {
renderStrategy.getContextualiser(node).execute(() -> {
renderStrategy.startRenderCell(node, isFirstItem, isLastItem);
renderSubCells(node, Optional.ofNullable(node)
.map(TreeNode::getDocumentReference)
.orElse(null));
renderSubCells(node,
Optional.ofNullable(node).map(TreeNode::getDocumentReference).orElse(null));
renderStrategy.endRenderCell(node, isFirstItem, isLastItem);
});
}
Expand All @@ -107,8 +106,8 @@ void renderSubCells(TreeNode parentNode, EntityReference parentRef) {
if (renderStrategy.isRenderSubCells(parentRef)) {
List<TreeNode> children = treeNodeService.getSubNodesForParent(parentRef,
renderStrategy.getMenuPart(parentNode));
LOGGER.debug("internal_renderSubCells: for parent [{}] render [{}] children [{}].",
parentRef, children.size(), children);
LOGGER.debug("internal_renderSubCells: for parent [{}] render [{}] children [{}].", parentRef,
children.size(), children);
if (!children.isEmpty()) {
renderStrategy.startRenderChildren(parentRef);
boolean isFirstItem = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
@NotThreadSafe
public class DefaultAttributeBuilder implements AttributeBuilder {

private static final Splitter CSS_CLASS_SPLITTER = Splitter.on(
" ").trimResults().omitEmptyStrings();
private static final Splitter CSS_CLASS_SPLITTER = Splitter.on(" ").trimResults()
.omitEmptyStrings();

private final Map<String, DefaultCellAttribute.Builder> attributeMap = new LinkedHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class CellAttributeClass extends AbstractClassDefinition
public static final String CLASS_DEF_HINT = CelementsClassDefinition.SPACE_NAME + "." + DOC_NAME;
public static final ClassReference CLASS_REF = new ClassReference(SPACE_NAME, DOC_NAME);

public static final ClassField<String> FIELD_NAME = new StringField.Builder(CLASS_REF,
"name").prettyName("name").build();
public static final ClassField<String> FIELD_NAME = new StringField.Builder(CLASS_REF, "name")
.prettyName("name").build();

public static final ClassField<String> FIELD_VALUE = new LargeStringField.Builder(
CLASS_REF, "value").rows(5).prettyName("value (velocity interpreted)").build();
public static final ClassField<String> FIELD_VALUE = new LargeStringField.Builder(CLASS_REF,
"value").rows(5).prettyName("value (velocity interpreted)").build();

public CellAttributeClass() {
super(CLASS_REF);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/celements/cells/classes/CellClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CellClass extends AbstractClassDefinition

public static final ClassField<String> FIELD_EVENT_DATA_ATTR = new LargeStringField.Builder(
CLASS_REF, "event_data_attr").rows(20).size(15).prettyName("celEventJS data attribute")
.build();
.build();

public CellClass() {
super(CLASS_REF);
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/celements/cells/classes/GroupCellClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@
@Singleton
@Immutable
@Component(GroupCellClass.CLASS_DEF_HINT)
public class GroupCellClass extends AbstractClassDefinition
implements CellsClassDefinition {
public class GroupCellClass extends AbstractClassDefinition implements CellsClassDefinition {

public static final String DOC_NAME = "GroupCellClass";
public static final String SPACE_NAME = "Celements";
public static final String CLASS_DEF_HINT = SPACE_NAME + "." + DOC_NAME;
public static final ClassReference CLASS_REF = new ClassReference(SPACE_NAME, DOC_NAME);

public static final ClassField<String> FIELD_RENDER_LAYOUT = new StringField.Builder(CLASS_REF,
"render_layout")
.prettyName("Render Layout")
.size(30)
.build();
"render_layout").prettyName("Render Layout").size(30).build();

public GroupCellClass() {
super(CLASS_REF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ public class PageDepCellConfigClass extends AbstractClassDefinition
public static final ClassReference CLASS_REF = new ClassReference(SPACE_NAME, DOC_NAME);

public static final ClassField<String> FIELD_SPACE_NAME = new StringField.Builder(CLASS_REF,
"space_name")
.prettyName("Space Name")
.size(30)
.build();
"space_name").prettyName("Space Name").size(30).build();

public static final ClassField<Boolean> FIELD_IS_ACTIVE = new BooleanField.Builder(CLASS_REF,
"is_inheritable")
.displayType("yesno")
.prettyName("is inheritable")
.build();
"is_inheritable").displayType("yesno").prettyName("is inheritable").build();

public PageDepCellConfigClass() {
super(CLASS_REF);
Expand Down
Loading