You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/20 14:39:47 UTC
[sling-org-apache-sling-repoinit-parser] 38/46: SLING-7066 -
Support mixins in repoinit "create path" statements
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git
commit 488a7e6f0a238c25f6e70bc9d7b14200866fd78a
Author: Timothée Maret <tm...@apache.org>
AuthorDate: Fri Sep 15 08:27:58 2017 +0000
SLING-7066 - Support mixins in repoinit "create path" statements
* Add parser support for creating paths with mixins
* Add JCR implementation
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1808431 13f79535-47bb-0310-9956-ffa450edef68
---
.../repoinit/parser/operations/CreatePath.java | 18 +++++++++---
.../parser/operations/PathSegmentDefinition.java | 33 +++++++++++++++++++---
src/main/javacc/RepoInitGrammar.jjt | 9 ++++--
src/test/resources/testcases/test-20-output.txt | 7 ++++-
src/test/resources/testcases/test-20.txt | 5 ++++
5 files changed, 61 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java b/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
index d1b87d0..8775a05 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/CreatePath.java
@@ -44,8 +44,12 @@ public class CreatePath extends Operation {
public void accept(OperationVisitor v) {
v.visitCreatePath(this);
}
-
+
public void addSegment(String path, String primaryType) {
+ addSegment(path, primaryType, null);
+ }
+
+ public void addSegment(String path, String primaryType, List<String> mixins) {
// We might get a path like /var/discovery, in which case
// the specified primary type applies to the last
// segment only
@@ -55,10 +59,16 @@ public class CreatePath extends Operation {
continue;
}
String pt = defaultPrimaryType;
- if(i == segments.length -1 && primaryType != null) {
- pt = primaryType;
+ List<String> ms = null;
+ if(i == segments.length -1) {
+ if (primaryType != null) {
+ pt = primaryType;
+ }
+ if (mixins != null && ! mixins.isEmpty()) {
+ ms = mixins;
+ }
}
- pathDef.add(new PathSegmentDefinition(segments[i], pt));
+ pathDef.add(new PathSegmentDefinition(segments[i], pt, ms));
}
}
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java b/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
index 62f95b8..c4206a5 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/PathSegmentDefinition.java
@@ -17,23 +17,44 @@
package org.apache.sling.repoinit.parser.operations;
-/** Defines a segment of a path to be created,
- * with its name and an optional primary type
+import java.util.List;
+
+/** Defines a segment of a path to be created,
+ * with its name and an optional primary type and optional mixins
*/
public class PathSegmentDefinition {
private final String segment;
private final String primaryType;
+ private final List<String> mixins;
public PathSegmentDefinition(String segment, String primaryType) {
+ this(segment, primaryType, null);
+ }
+
+ public PathSegmentDefinition(String segment, String primaryType, List<String> mixins) {
this.segment = segment;
this.primaryType = primaryType;
+ this.mixins = mixins;
}
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(segment);
- if(primaryType != null) {
- sb.append("(").append(primaryType).append(")");
+ boolean hasPrimaryType = primaryType != null;
+ boolean hasMixin = mixins != null && ! mixins.isEmpty();
+ if (hasPrimaryType || hasMixin) {
+ sb.append("(");
+ if (hasPrimaryType) {
+ sb.append(primaryType);
+ }
+ if (hasPrimaryType && hasMixin) {
+ sb.append(" ");
+ }
+ if (hasMixin) {
+ sb.append("mixin ");
+ sb.append(mixins.toString());
+ }
+ sb.append(")");
}
return sb.toString();
}
@@ -45,4 +66,8 @@ public class PathSegmentDefinition {
public String getPrimaryType() {
return primaryType;
}
+
+ public List<String> getMixins() {
+ return mixins;
+ }
}
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index b599e8e..6d30fdf 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -65,6 +65,7 @@ TOKEN:
| < DELETE: "delete" >
| < DISABLE: "disable" >
| < SERVICE: "service" >
+| < MIXIN: "mixin" >
| < PATH: "path" >
| < END: "end" >
| < USER: "user" >
@@ -207,18 +208,22 @@ void createPathStatement(List<Operation> result) :
String defaultPrimaryType = null;
Token t1 = null;
Token t2 = null;
+ List<String> t3 = null;
}
{
<CREATE> <PATH>
( <LPAREN> t1 = <NAMESPACED_ITEM> <RPAREN> { defaultPrimaryType = t1.image; } ) ?
( t1 = <PATH_STRING> ( <LPAREN> t2 = <NAMESPACED_ITEM> <RPAREN> ) ?
+ ( <LPAREN> <MIXIN> t3 = namespacedItemsList() <RPAREN>) ?
+ ( <LPAREN> t2 = <NAMESPACED_ITEM> <MIXIN> t3 = namespacedItemsList() <RPAREN>) ?
{
if(cp == null) {
cp = new CreatePath(defaultPrimaryType);
}
- cp.addSegment(t1.image, t2 == null ? null : t2.image);
- t2 = null;
+ cp.addSegment(t1.image, t2 == null ? null : t2.image, t3);
+ t2 = null;
+ t3 = null;
}
) +
diff --git a/src/test/resources/testcases/test-20-output.txt b/src/test/resources/testcases/test-20-output.txt
index 68fa997..bd8029b 100644
--- a/src/test/resources/testcases/test-20-output.txt
+++ b/src/test/resources/testcases/test-20-output.txt
@@ -1,4 +1,9 @@
CreatePath [var(sling:Folder), discovery(nt:unstructured), somefolder(sling:Folder)]
CreatePath [one, two, three]
CreatePath [three, four(nt:folk), five(nt:jazz), six]
-CreatePath [seven(nt:x), eight(nt:x), nine(nt:x)]
\ No newline at end of file
+CreatePath [seven(nt:x), eight(nt:x), nine(nt:x)]
+CreatePath [one(mixin [nt:art]), step(mixin [nt:dance]), two, steps]
+CreatePath [one(nt:foxtrot), step(nt:foxtrot mixin [nt:dance]), two(nt:foxtrot), steps(nt:foxtrot)]
+CreatePath [one, step(mixin [nt:dance, nt:art]), two, steps]
+CreatePath [one, step(nt:foxtrot mixin [nt:dance]), two, steps]
+CreatePath [one, step(nt:foxtrot mixin [nt:dance, nt:art]), two, steps]
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-20.txt b/src/test/resources/testcases/test-20.txt
index 30f1355..fce57bf 100644
--- a/src/test/resources/testcases/test-20.txt
+++ b/src/test/resources/testcases/test-20.txt
@@ -3,3 +3,8 @@ create path (sling:Folder) /var/discovery(nt:unstructured)/somefolder
create path /one/two/three
create path /three/four(nt:folk)/five(nt:jazz)/six
create path (nt:x) /seven/eight/nine
+create path /one(mixin nt:art)/step(mixin nt:dance)/two/steps
+create path (nt:foxtrot) /one/step(mixin nt:dance)/two/steps
+create path /one/step(mixin nt:dance,nt:art)/two/steps
+create path /one/step(nt:foxtrot mixin nt:dance)/two/steps
+create path /one/step(nt:foxtrot mixin nt:dance,nt:art)/two/steps
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.