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/11/07 09:57:54 UTC
[sling-org-apache-sling-repoinit-parser] 05/22: SLING-5355 - parser
service
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.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git
commit 847aa69c8a59e1a77d7ffa56ea7c7eaf9fcdab22
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Dec 23 12:37:23 2015 +0000
SLING-5355 - parser service
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/acldef/parser@1721535 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/acldef/parser/AclDefinitionsParser.java | 29 +++++++++++++
.../sling/acldef/parser/AclParsingException.java | 27 ++++++++++++
.../parser/impl/ACLDefinitionsParserService.java | 49 ++++++++++++++++++++++
.../sling/acldef/parser/operations/AclLine.java | 5 +++
.../acldef/parser/operations/package-info.java | 21 ++++++++++
.../apache/sling/acldef/parser/package-info.java | 21 ++++++++++
src/main/javacc/ACLDefinitions.jjt | 27 +++++-------
.../acldef/parser/test/ParserServiceTest.java | 39 +++++++++++++++++
.../sling/acldef/parser/test/ParserTest.java | 6 +--
.../acldef/parser/test/ParsingErrorsTest.java | 8 ++--
10 files changed, 209 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/sling/acldef/parser/AclDefinitionsParser.java b/src/main/java/org/apache/sling/acldef/parser/AclDefinitionsParser.java
new file mode 100644
index 0000000..11cf6c7
--- /dev/null
+++ b/src/main/java/org/apache/sling/acldef/parser/AclDefinitionsParser.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.acldef.parser;
+
+import java.io.Reader;
+import java.util.List;
+
+import org.apache.sling.acldef.parser.operations.Operation;
+
+/** ACL definitions parser service interface */
+public interface AclDefinitionsParser {
+ List<Operation> parse(Reader r) throws AclParsingException;
+}
diff --git a/src/main/java/org/apache/sling/acldef/parser/AclParsingException.java b/src/main/java/org/apache/sling/acldef/parser/AclParsingException.java
new file mode 100644
index 0000000..1ddc2f0
--- /dev/null
+++ b/src/main/java/org/apache/sling/acldef/parser/AclParsingException.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.acldef.parser;
+
+public class AclParsingException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public AclParsingException(String reason, Throwable cause) {
+ super(reason, cause);
+ }
+}
diff --git a/src/main/java/org/apache/sling/acldef/parser/impl/ACLDefinitionsParserService.java b/src/main/java/org/apache/sling/acldef/parser/impl/ACLDefinitionsParserService.java
new file mode 100644
index 0000000..c78441b
--- /dev/null
+++ b/src/main/java/org/apache/sling/acldef/parser/impl/ACLDefinitionsParserService.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.acldef.parser.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.acldef.parser.AclDefinitionsParser;
+import org.apache.sling.acldef.parser.AclParsingException;
+import org.apache.sling.acldef.parser.operations.Operation;
+
+/** ACL definitions parser service */
+@Component
+@Service(value=AclDefinitionsParser.class)
+public class ACLDefinitionsParserService implements AclDefinitionsParser {
+
+ @Override
+ public List<Operation> parse(Reader r) throws AclParsingException {
+ try {
+ return new ACLDefinitionsParserImpl(r).parse();
+ } catch (ParseException pe) {
+ throw new AclParsingException(pe.getMessage(), pe);
+ } finally {
+ try {
+ r.close();
+ } catch(IOException ignore) {
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java b/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java
index 0e47dcd..cdb39d9 100644
--- a/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java
+++ b/src/main/java/org/apache/sling/acldef/parser/operations/AclLine.java
@@ -29,6 +29,11 @@ public class AclLine {
private final Action action;
private static final List<String> EMPTY_LIST = Collections.unmodifiableList(new ArrayList<String>());
+ public static final String PROP_PATHS = "paths";
+ public static final String PROP_PRINCIPALS = "principals";
+ public static final String PROP_PRIVILEGES = "privileges";
+ public static final String PROP_NODETYPES = "nodetypes";
+
public enum Action {
REMOVE,
REMOVE_ALL,
diff --git a/src/main/java/org/apache/sling/acldef/parser/operations/package-info.java b/src/main/java/org/apache/sling/acldef/parser/operations/package-info.java
new file mode 100644
index 0000000..7587c6d
--- /dev/null
+++ b/src/main/java/org/apache/sling/acldef/parser/operations/package-info.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+@Version("1.0.0")
+package org.apache.sling.acldef.parser.operations;
+
+import aQute.bnd.annotation.Version;
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/acldef/parser/package-info.java b/src/main/java/org/apache/sling/acldef/parser/package-info.java
new file mode 100644
index 0000000..d74cfb7
--- /dev/null
+++ b/src/main/java/org/apache/sling/acldef/parser/package-info.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+@Version("1.0.0")
+package org.apache.sling.acldef.parser;
+
+import aQute.bnd.annotation.Version;
\ No newline at end of file
diff --git a/src/main/javacc/ACLDefinitions.jjt b/src/main/javacc/ACLDefinitions.jjt
index 1de9b00..06ecb48 100644
--- a/src/main/javacc/ACLDefinitions.jjt
+++ b/src/main/javacc/ACLDefinitions.jjt
@@ -8,9 +8,9 @@ options
STATIC=false;
}
-PARSER_BEGIN(ACLDefinitions)
+PARSER_BEGIN(ACLDefinitionsParserImpl)
-package org.apache.sling.acldef.parser;
+package org.apache.sling.acldef.parser.impl;
import java.util.List;
import java.util.ArrayList;
@@ -34,15 +34,10 @@ import org.apache.sling.acldef.parser.operations.*;
* limitations under the License.
*/
-public class ACLDefinitions
+public class ACLDefinitionsParserImpl
{
- public static final String PROP_PATHS = "paths";
- public static final String PROP_PRINCIPALS = "principals";
- public static final String PROP_PRIVILEGES = "privileges";
- public static final String PROP_NODETYPES = "nodetypes";
}
-
-PARSER_END(ACLDefinitions)
+PARSER_END(ACLDefinitionsParserImpl)
SKIP :
{
@@ -178,9 +173,9 @@ void removeStarLine(List<AclLine> lines) :
{
<REMOVE> <STAR>
(
- <FOR> tmp = principalsList() { line.setProperty(PROP_PRINCIPALS, tmp); }
+ <FOR> tmp = principalsList() { line.setProperty(AclLine.PROP_PRINCIPALS, tmp); }
- | <ON> tmp = pathsList() { line.setProperty(PROP_PATHS, tmp); }
+ | <ON> tmp = pathsList() { line.setProperty(AclLine.PROP_PATHS, tmp); }
)
<EOL>
@@ -206,9 +201,9 @@ void userPrivilegesLine(List<AclLine> lines) :
}
{
line = privilegesLineOperation()
- tmp = namespacedItemsList() { line.setProperty(PROP_PRIVILEGES, tmp); }
+ tmp = namespacedItemsList() { line.setProperty(AclLine.PROP_PRIVILEGES, tmp); }
<FOR>
- tmp = principalsList() { line.setProperty(PROP_PRINCIPALS, tmp); }
+ tmp = principalsList() { line.setProperty(AclLine.PROP_PRINCIPALS, tmp); }
<EOL>
{
@@ -223,9 +218,9 @@ void pathPrivilegesLine(List<AclLine> lines) :
}
{
line = privilegesLineOperation()
- tmp = namespacedItemsList() { line.setProperty(PROP_PRIVILEGES, tmp); }
- <ON> tmp = pathsList() { line.setProperty(PROP_PATHS, tmp); }
- ( <NODETYPES> tmp = namespacedItemsList() { line.setProperty(PROP_NODETYPES, tmp); }) ?
+ tmp = namespacedItemsList() { line.setProperty(AclLine.PROP_PRIVILEGES, tmp); }
+ <ON> tmp = pathsList() { line.setProperty(AclLine.PROP_PATHS, tmp); }
+ ( <NODETYPES> tmp = namespacedItemsList() { line.setProperty(AclLine.PROP_NODETYPES, tmp); }) ?
<EOL>
{
diff --git a/src/test/java/org/apache/sling/acldef/parser/test/ParserServiceTest.java b/src/test/java/org/apache/sling/acldef/parser/test/ParserServiceTest.java
new file mode 100644
index 0000000..2c0d27b
--- /dev/null
+++ b/src/test/java/org/apache/sling/acldef/parser/test/ParserServiceTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.sling.acldef.parser.test;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.sling.acldef.parser.AclParsingException;
+import org.apache.sling.acldef.parser.impl.ACLDefinitionsParserService;
+import org.junit.Test;
+
+public class ParserServiceTest {
+ @Test
+ public void noErrors() throws AclParsingException {
+ final Reader r = new StringReader("create service user foo");
+ new ACLDefinitionsParserService().parse(r);
+ }
+
+ @Test(expected = AclParsingException.class)
+ public void syntaxError() throws AclParsingException {
+ final Reader r = new StringReader("not a valid statement");
+ new ACLDefinitionsParserService().parse(r);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/acldef/parser/test/ParserTest.java b/src/test/java/org/apache/sling/acldef/parser/test/ParserTest.java
index c76fe20..5779711 100644
--- a/src/test/java/org/apache/sling/acldef/parser/test/ParserTest.java
+++ b/src/test/java/org/apache/sling/acldef/parser/test/ParserTest.java
@@ -28,8 +28,8 @@ import java.util.Collection;
import java.util.List;
import org.apache.commons.io.IOUtils;
-import org.apache.sling.acldef.parser.ACLDefinitions;
-import org.apache.sling.acldef.parser.ParseException;
+import org.apache.sling.acldef.parser.impl.ACLDefinitionsParserImpl;
+import org.apache.sling.acldef.parser.impl.ParseException;
import org.apache.sling.acldef.parser.operations.Operation;
import org.apache.sling.acldef.parser.operations.OperationVisitor;
import org.junit.Test;
@@ -112,7 +112,7 @@ public class ParserTest {
try {
final StringWriter sw = new StringWriter();
final OperationVisitor v = new OperationToStringVisitor(new PrintWriter(sw));
- final List<Operation> result = new ACLDefinitions(tc.input).parse();
+ final List<Operation> result = new ACLDefinitionsParserImpl(tc.input).parse();
for(Operation o : result) {
o.accept(v);
}
diff --git a/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java b/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
index 37cdbd4..30c4eea 100644
--- a/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
+++ b/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
@@ -26,9 +26,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.sling.acldef.parser.ACLDefinitions;
-import org.apache.sling.acldef.parser.ParseException;
-import org.apache.sling.acldef.parser.TokenMgrError;
+import org.apache.sling.acldef.parser.impl.ACLDefinitionsParserImpl;
+import org.apache.sling.acldef.parser.impl.ParseException;
+import org.apache.sling.acldef.parser.impl.TokenMgrError;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -74,7 +74,7 @@ public class ParsingErrorsTest {
public void checkResult() throws ParseException, IOException {
final StringReader r = new StringReader(input);
try {
- new ACLDefinitions(r).parse();
+ new ACLDefinitionsParserImpl(r).parse();
if(expected != null) {
fail("Expected a " + expected.getSimpleName() + " for [" + input + "]");
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.