Author: justin
Date: Fri Feb 12 17:16:42 2010
New Revision: 909503
URL: http://svn.apache.org/viewvc?rev=909503&view=rev
Log:
re-adding test for SLING-1366 and interface for SLING-1363
Added:
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/NamespaceMapper.java
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/NamespaceTestServlet.java
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NamespaceMappingTest.java
Modified:
sling/trunk/bundles/jcr/api/pom.xml
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
sling/trunk/launchpad/test-services/pom.xml
Modified: sling/trunk/bundles/jcr/api/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/api/pom.xml?rev=909503&r1=909502&r2=909503&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/api/pom.xml (original)
+++ sling/trunk/bundles/jcr/api/pom.xml Fri Feb 12 17:16:42 2010
@@ -57,8 +57,8 @@
</Bundle-Category>
<Export-Package>
<!-- Export provider API selectively -->
- org.apache.sling.jcr.api;version=2.0.2
- </Export-Package>
+ org.apache.sling.jcr.api;version=2.1.0
+ </Export-Package>
</instructions>
</configuration>
</plugin>
Added:
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/NamespaceMapper.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/NamespaceMapper.java?rev=909503&view=auto
==============================================================================
---
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/NamespaceMapper.java
(added)
+++
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/NamespaceMapper.java
Fri Feb 12 17:16:42 2010
@@ -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.jcr.api;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * This interface is used to customize the namespace mapping of
+ * a session.
+ * @since 2.1
+ */
+public interface NamespaceMapper {
+
+ /**
+ * This method is invoked whenever a new session is created.
+ * It allows the service to add own namespace prefixes.
+ * @param session The new session
+ * @throws RepositoryException If anything goes wrong
+ */
+ void defineNamespacePrefixes(Session session)
+ throws RepositoryException;
+}
Modified:
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java?rev=909503&r1=909502&r2=909503&view=diff
==============================================================================
---
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
(original)
+++
sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
Fri Feb 12 17:16:42 2010
@@ -34,6 +34,12 @@
* Implementations of this interface will generally provide configurability of
* the default workspace name as well as the access details for the
* administrative session.
+ * <p>
+ * Implementations of SlingRepository are expected to invoke any available
+ * implementations of the {...@link SessionConfigurer} interface <b>before</b>
+ * returning <b>any</b> {...@link Session} to callers. This includes the
methods
+ * defined in the {...@link Repository} interface.
+ *
*/
public interface SlingRepository extends Repository {
Modified: sling/trunk/launchpad/test-services/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/pom.xml?rev=909503&r1=909502&r2=909503&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/pom.xml (original)
+++ sling/trunk/launchpad/test-services/pom.xml Fri Feb 12 17:16:42 2010
@@ -57,6 +57,9 @@
<Private-Package>
org.apache.sling.launchpad.testservices.*
</Private-Package>
+ <Sling-Namespaces>
+ test1=http://sling.apache.org/test/one
+ </Sling-Namespaces>
<Sling-Nodetypes>
SLING-INF/nodetypes/test.cnd
</Sling-Nodetypes>
@@ -93,6 +96,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
</dependencies>
</project>
Added:
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/NamespaceTestServlet.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/NamespaceTestServlet.java?rev=909503&view=auto
==============================================================================
---
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/NamespaceTestServlet.java
(added)
+++
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/NamespaceTestServlet.java
Fri Feb 12 17:16:42 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.launchpad.testservices.servlets;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+
+/**
+ * Test Servlet which outputs the current namespace mappings.
+ *
+ * @scr.component immediate="true" metatype="no"
+ * @scr.service interface="javax.servlet.Servlet"
+ *
+ * @scr.property name="service.description"
+ * value="NamespaceMapping Test Servlet"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ *
+ * @scr.property name="sling.servlet.paths"
+ * values.0="/testing/NamespaceTestServlet/output"
+ *
+ */
+...@suppresswarnings("serial")
+public class NamespaceTestServlet extends SlingSafeMethodsServlet {
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
+ IOException {
+ try {
+ response.setContentType("text/plain");
+ Session session =
request.getResourceResolver().adaptTo(Session.class);
+
+ response.getWriter().printf("userid=%s", session.getUserID());
+ response.getWriter().println();
+
+ for (String prefix : session.getNamespacePrefixes()) {
+ response.getWriter().printf("%s=%s", prefix,
session.getNamespaceURI(prefix));
+ response.getWriter().println();
+ }
+ response.getWriter().flush();
+ } catch (RepositoryException e) {
+ throw new ServletException("Unable to output namespace mappings",
e);
+ }
+ }
+
+}
Added:
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NamespaceMappingTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NamespaceMappingTest.java?rev=909503&view=auto
==============================================================================
---
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NamespaceMappingTest.java
(added)
+++
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/NamespaceMappingTest.java
Fri Feb 12 17:16:42 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.launchpad.webapp.integrationtest;
+
+import java.io.IOException;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/**
+ * Test that Namespace Mappings are working properly.
+ */
+public class NamespaceMappingTest extends HttpTestBase {
+
+ /**
+ * Verify that Sling-Namespaces works.
+ */
+ public void testNamespaceFromManifest() throws IOException {
+ final String expected = "test1=http://sling.apache.org/test/one";
+ final String content = getContent(HTTP_BASE_URL +
"/testing/NamespaceTestServlet/output",
+ CONTENT_TYPE_PLAIN);
+ assertTrue("Content contains " + expected + " (" + content + ")",
content.contains(expected));
+ }
+}