sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-repoinit-parser] 03/10: SLING-5842 - add 'register nodetypes' statement to repoinit parser
Date Tue, 07 Nov 2017 09:58:20 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.repoinit.parser-1.0.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git

commit 4563ff6ea16b1b374fa2fc36576f1dbbdf1d3158
Author: Bertrand Delacretaz <bdelacretaz@apache.org>
AuthorDate: Mon Jul 18 15:08:18 2016 +0000

    SLING-5842 - add 'register nodetypes' statement to repoinit parser
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/repoinit/parser@1753237
13f79535-47bb-0310-9956-ffa450edef68
---
 .../parser/operations/OperationVisitor.java        |  1 +
 ...perationVisitor.java => RegisterNodetypes.java} | 35 ++++++++++++++++-----
 src/main/javacc/RepoInitGrammar.jjt                | 36 ++++++++++++++++++++++
 .../parser/test/OperationToStringVisitor.java      |  6 ++++
 src/test/resources/testcases/test-50-output.txt    | 27 ++++++++++++++++
 src/test/resources/testcases/test-50.txt           | 31 +++++++++++++++++++
 src/test/resources/testcases/test-99-output.txt    |  8 +++++
 src/test/resources/testcases/test-99.txt           |  9 ++++++
 8 files changed, 146 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
index d7d2682..8693a99 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
@@ -24,4 +24,5 @@ public interface OperationVisitor {
     void visitSetAclPaths(SetAclPaths s);
     void visitCreatePath(CreatePath cp);
     void visitRegisterNamespace(RegisterNamespace rn);
+    void visitRegisterNodetypes(RegisterNodetypes b);
 }
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
b/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNodetypes.java
similarity index 53%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
copy to src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNodetypes.java
index d7d2682..3266900 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/OperationVisitor.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNodetypes.java
@@ -17,11 +17,32 @@
 
 package org.apache.sling.repoinit.parser.operations;
 
-public interface OperationVisitor {
-    void visitCreateServiceUser(CreateServiceUser s);
-    void visitDeleteServiceUser(DeleteServiceUser s);
-    void visitSetAclPrincipal(SetAclPrincipals s);
-    void visitSetAclPaths(SetAclPaths s);
-    void visitCreatePath(CreatePath cp);
-    void visitRegisterNamespace(RegisterNamespace rn);
+/** An embedded block of text */
+public class RegisterNodetypes extends Operation {
+    private final String cndStatements;
+    
+    public RegisterNodetypes(String cndStatements) {
+        this.cndStatements = cndStatements;
+    }
+    
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ":\n" + getParametersDescription();
+    }
+    
+    @Override
+    protected String getParametersDescription() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append(getCndStatements());
+        return sb.toString();
+    }
+    
+    @Override
+    public void accept(OperationVisitor v) {
+        v.visitRegisterNodetypes(this);
+    }
+    
+    public String getCndStatements() {
+        return cndStatements;
+    }
 }
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index 1f887b5..f1191eb 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -69,6 +69,7 @@ TOKEN:
 |   < NODETYPES: "nodetypes" >
 |   < REGISTER: "register" >
 |   < NAMESPACE: "namespace" >
+|   < START_TEXTBLOCK: "<<<===" > : TEXTBLOCK
 |   < LPAREN: "(" >
 |   < RPAREN: ")" >
 |   < COMMA: "," >
@@ -81,6 +82,17 @@ TOKEN:
 |   < EOL: "\n" >
 }
 
+<TEXTBLOCK> SKIP : 
+{
+    "\r"
+}
+
+<TEXTBLOCK> TOKEN :
+{
+    < TEXT : ~[] > 
+|   < END_TEXTBLOCK: "===>>>" > : DEFAULT
+} 
+
 List<Operation> parse() :
 {}
 {
@@ -92,6 +104,7 @@ List<Operation> parse() :
         | setAclPrincipals(result)
         | createPathStatement(result)
         | registerNamespaceStatement(result)
+        | registerNodetypesStatement(result)
         | blankLine() 
     ) * 
     <EOF>
@@ -302,3 +315,26 @@ void registerNamespaceStatement(List<Operation> result) :
     
     (<EOL> | <EOF>)
 }
+
+void textBlock(StringBuilder b) : 
+{
+    Token t;
+}
+{
+    <START_TEXTBLOCK>
+    ( t = <TEXT> { b.append(t.image); } )*
+    <END_TEXTBLOCK>
+}
+     
+void registerNodetypesStatement(List<Operation> result) :
+{
+    StringBuilder b = new StringBuilder();
+}
+{
+    <REGISTER> <NODETYPES> <EOL> 
+    textBlock(b) 
+    (<EOL> | <EOF>)
+    {
+        result.add(new RegisterNodetypes(b.toString()));
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
index a25128a..ede1c58 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/OperationToStringVisitor.java
@@ -24,6 +24,7 @@ import org.apache.sling.repoinit.parser.operations.AclLine;
 import org.apache.sling.repoinit.parser.operations.CreatePath;
 import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
 import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
 import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
 import org.apache.sling.repoinit.parser.operations.SetAclPaths;
@@ -84,6 +85,11 @@ class OperationToStringVisitor implements OperationVisitor {
         out.println(rn.toString());
     }
 
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes nt) {
+        out.println(nt.toString());
+    }
+
     private void dumpAclLines(Collection<AclLine> c) {
         for(AclLine line : c) {
             out.print("  ");
diff --git a/src/test/resources/testcases/test-50-output.txt b/src/test/resources/testcases/test-50-output.txt
new file mode 100644
index 0000000..dfa1efd
--- /dev/null
+++ b/src/test/resources/testcases/test-50-output.txt
@@ -0,0 +1,27 @@
+RegisterNodetypes:
+
+    <slingevent='http://sling.apache.org/jcr/event/1.0'>
+    <nt='http://www.jcp.org/jcr/nt/1.0'>
+    <mix='http://www.jcp.org/jcr/mix/1.0'>
+    
+    [slingevent:Event] > nt:unstructured, nt:hierarchyNode
+      - slingevent:topic (string)
+      - slingevent:application (string)
+      - slingevent:created (date)
+      - slingevent:properties (binary)
+      
+    [slingevent:Job] > slingevent:Event, mix:lockable
+      - slingevent:processor (string)
+      - slingevent:id (string)
+      - slingevent:finished (date)
+     
+    [slingevent:TimedEvent] > slingevent:Event, mix:lockable
+      - slingevent:processor (string)
+      - slingevent:id (string)
+      - slingevent:expression (string)
+      - slingevent:date (date)
+      - slingevent:period (long)
+
+RegisterNodetypes:
+
+Just one line, not indented
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-50.txt b/src/test/resources/testcases/test-50.txt
new file mode 100644
index 0000000..230a071
--- /dev/null
+++ b/src/test/resources/testcases/test-50.txt
@@ -0,0 +1,31 @@
+# Test parsing embedded CNDs
+
+register nodetypes
+<<<===
+    <slingevent='http://sling.apache.org/jcr/event/1.0'>
+    <nt='http://www.jcp.org/jcr/nt/1.0'>
+    <mix='http://www.jcp.org/jcr/mix/1.0'>
+    
+    [slingevent:Event] > nt:unstructured, nt:hierarchyNode
+      - slingevent:topic (string)
+      - slingevent:application (string)
+      - slingevent:created (date)
+      - slingevent:properties (binary)
+      
+    [slingevent:Job] > slingevent:Event, mix:lockable
+      - slingevent:processor (string)
+      - slingevent:id (string)
+      - slingevent:finished (date)
+     
+    [slingevent:TimedEvent] > slingevent:Event, mix:lockable
+      - slingevent:processor (string)
+      - slingevent:id (string)
+      - slingevent:expression (string)
+      - slingevent:date (date)
+      - slingevent:period (long)
+===>>>
+
+register nodetypes
+<<<===
+Just one line, not indented
+===>>>
diff --git a/src/test/resources/testcases/test-99-output.txt b/src/test/resources/testcases/test-99-output.txt
index fcbe63c..1fe2f1a 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -17,4 +17,12 @@ SetAclPrincipals for alice bob fred
   AclLine DENY {paths=[/content/example.com], privileges=[jcr:write]}
   AclLine DENY {nodetypes=[example:Page], paths=[/], privileges=[jcr:all]}
 RegisterNamespace (NSprefix) uri:someURI/v1.42
+RegisterNodetypes:
+
+    <slingevent='http://sling.apache.org/jcr/event/1.0'>
+    
+    [slingevent:Event] > nt:unstructured, nt:hierarchyNode
+      - slingevent:topic (string)
+      - slingevent:properties (binary)
+
 CreateServiceUser the-last-one
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 54927c4..a2f200a 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -33,4 +33,13 @@ end
 
 register namespace ( NSprefix ) uri:someURI/v1.42
 
+register nodetypes
+<<<===
+    <slingevent='http://sling.apache.org/jcr/event/1.0'>
+    
+    [slingevent:Event] > nt:unstructured, nt:hierarchyNode
+      - slingevent:topic (string)
+      - slingevent:properties (binary)
+===>>>
+
 create service user the-last-one
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message