This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git
The following commit(s) were added to refs/heads/master by this push:
new f660b6d mark module as deprecated see
https://lists.apache.org/thread/l4wd9xbk7f88jc6gs1mr2vz1jc7d8yo1
f660b6d is described below
commit f660b6d9be47ac37b24b320742a566232fe83e3a
Author: Stefan Seifert <[email protected]>
AuthorDate: Mon Mar 10 12:23:29 2025 +0100
mark module as deprecated
see https://lists.apache.org/thread/l4wd9xbk7f88jc6gs1mr2vz1jc7d8yo1
---
.asf.yaml | 6 +
CODE_OF_CONDUCT.md | 22 -
CONTRIBUTING.md | 24 -
Jenkinsfile | 20 -
README.md | 11 +-
pom.xml | 101 -----
.../sling/mongodb/impl/ChangeableValueMap.java | 87 ----
.../mongodb/impl/MongoDBCollectionResource.java | 86 ----
.../apache/sling/mongodb/impl/MongoDBContext.java | 120 -----
.../apache/sling/mongodb/impl/MongoDBResource.java | 155 -------
.../mongodb/impl/MongoDBResourceProvider.java | 491 ---------------------
.../impl/MongoDBResourceProviderFactory.java | 146 ------
.../sling/mongodb/impl/ReadableValueMap.java | 225 ----------
.../resources/OSGI-INF/l10n/metatype.properties | 52 ---
14 files changed, 9 insertions(+), 1537 deletions(-)
diff --git a/.asf.yaml b/.asf.yaml
index b8d35f3..b06ab4c 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -1,4 +1,10 @@
github:
+ description: "Apache Sling MongoDB Resource Provider (deprecated)"
+ homepage: "https://sling.apache.org/"
+ labels:
+ - "sling"
+ - "java"
+ - "deprecated"
autolink_jira:
- "SLING"
- "OAK"
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
deleted file mode 100644
index 0fa18e5..0000000
--- a/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ 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.
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
-Apache Software Foundation Code of Conduct
-====
-
-Being an Apache project, Apache Sling adheres to the Apache Software
Foundation's [Code of
Conduct](https://www.apache.org/foundation/policies/conduct.html).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index ac82a1a..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ 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.
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
-Contributing
-====
-
-Thanks for choosing to contribute!
-
-You will find all the necessary details about how you can do this at
https://sling.apache.org/contributing.html.
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index f582519..0000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * 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.
- */
-
-slingOsgiBundleBuild()
diff --git a/README.md b/README.md
index 76cd38f..436413c 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,8 @@
 [](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-mongodb/job/master/) [](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-mongodb) [
-This module is part of the [Apache Sling](https://sling.apache.org) project.
+This module is **obsolete**.
-This is a Sling Resource Provider for MongoDB implementation (from 2012)
-
-The Sling provides also a different implementation based on the Generic NoSQL
Resource Provider for MongoDB:
-https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/mongodb-resourceprovider
-
-Please note that both implementations are not interchangeable because they
store the data in MongoDB in different formats.
+For reference or potential bugfix releases use branch
[maintenance](https://github.com/apache/sling-org-apache-sling-mongodb/tree/maintenance).
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index a8de5f5..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,101 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>26</version>
- <relativePath/>
- </parent>
-
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.mongodb</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>bundle</packaging>
-
- <name>Apache Sling MongoDB Resource Provider</name>
-
- <scm>
-
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git</connection>
-
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git</developerConnection>
- <url>https://github.com/apache/sling-org-apache-sling-mongodb.git</url>
- </scm>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <version>1.26.4</version>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Private-Package>
- org.apache.sling.mongodb.impl
- </Private-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.api</artifactId>
- <version>2.7.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>2.11.3</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git
a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
deleted file mode 100644
index 2061171..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.Map;
-
-import org.apache.sling.api.resource.ModifiableValueMap;
-import org.apache.sling.api.resource.Resource;
-
-public class ChangeableValueMap
- extends ReadableValueMap
- implements ModifiableValueMap {
-
- private final MongoDBResource resource;
-
- public ChangeableValueMap(final MongoDBResource resource) {
- super(resource.getProperties());
- this.resource = resource;
- }
-
- /**
- * @see java.util.Map#clear()
- */
- public void clear() {
- throw new UnsupportedOperationException("clear");
- }
-
- /**
- * @see java.util.Map#put(java.lang.Object, java.lang.Object)
- */
- public Object put(final String name, final Object value) {
- final Object oldValue = this.valueMap.get(name);
- final String key = MongoDBResourceProvider.propNameToKey(name);
-
- this.resource.getProperties().put(key, value);
-
- // update map and resource
- this.createValueMap(this.resource.getProperties());
- this.resource.changed();
-
- return oldValue;
- }
-
- /**
- * @see java.util.Map#putAll(java.util.Map)
- */
- public void putAll(final Map<? extends String, ? extends Object> m) {
- for(final Map.Entry<? extends String, ? extends Object> e :
m.entrySet() ) {
- this.put(e.getKey(), e.getValue());
- }
- }
-
- /**
- * @see java.util.Map#remove(java.lang.Object)
- */
- public Object remove(final Object name) {
- final Object result = this.valueMap.get(name);
- if ( result != null ) {
- final String key =
MongoDBResourceProvider.propNameToKey(name.toString());
-
- this.resource.getProperties().removeField(key);
-
- // update map and resource
- this.createValueMap(this.resource.getProperties());
- this.resource.changed();
- }
- return result;
- }
-
- protected MongoDBResource getResource() {
- return this.resource;
- }
-}
diff --git
a/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
b/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
deleted file mode 100644
index 6b2ae0b..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.sling.api.resource.AbstractResource;
-import org.apache.sling.api.resource.ResourceMetadata;
-import org.apache.sling.api.resource.ResourceResolver;
-
-public class MongoDBCollectionResource extends AbstractResource {
-
- private final String path;
-
- private final ResourceResolver resourceResolver;
-
- private final ResourceMetadata metadata = new ResourceMetadata();
-
- public MongoDBCollectionResource(final ResourceResolver resolver, final
String path) {
- this.resourceResolver = resolver;
- this.path = path;
- this.metadata.setResolutionPath(this.path);
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getPath()
- */
- public String getPath() {
- return this.path;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceType()
- */
- public String getResourceType() {
- return "mongodb:collection";
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
- */
- public String getResourceSuperType() {
- return null;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
- */
- public ResourceMetadata getResourceMetadata() {
- return this.metadata;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceResolver()
- */
- public ResourceResolver getResourceResolver() {
- return this.resourceResolver;
- }
-
- /**
- * @see
org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- @Override
- public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
- if ( type == Map.class ) {
- return (AdapterType) Collections.EMPTY_MAP;
- }
- return super.adaptTo(type);
- }
-}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
deleted file mode 100644
index 0c2e08a..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-
-import org.apache.sling.api.SlingConstants;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-
-import com.mongodb.DB;
-
-public class MongoDBContext {
-
- /** The roots. */
- private final String root;
-
- /** The roots ended by a slash. */
- private final String rootWithSlash;
-
- /** Don't show these collections. */
- private final Set<String> filterCollectionNames = new HashSet<String>();
-
- /** The database to be used. */
- private final DB database;
-
- private final EventAdmin eventAdmin;
-
- public MongoDBContext(final DB database,
- final String configuredRoot,
- final String[] configuredFilterCollectionNames,
- final EventAdmin eventAdmin) {
- this.database = database;
- if ( configuredRoot != null ) {
- final String value = configuredRoot.trim();
- if ( value.length() > 0 ) {
- if ( value.endsWith("/") ) {
- this.rootWithSlash = configuredRoot;
- this.root = configuredRoot.substring(0,
configuredRoot.length() - 1);
- } else {
- this.rootWithSlash = configuredRoot + "/";
- this.root = configuredRoot;
- }
- } else {
- this.root = "";
- this.rootWithSlash = "/";
- }
- } else {
- this.root = "";
- this.rootWithSlash = "/";
- }
- if ( configuredFilterCollectionNames != null ) {
- for(final String name : configuredFilterCollectionNames) {
- this.filterCollectionNames.add(name);
- }
- }
- this.eventAdmin = eventAdmin;
- }
-
- public String getRoot() {
- return root;
- }
-
- public String getRootWithSlash() {
- return this.rootWithSlash;
- }
-
- public boolean isFilterCollectionName(final String name) {
- return this.filterCollectionNames.contains(name);
- }
-
- public Set<String> getFilterCollectionNames() {
- return this.filterCollectionNames;
- }
-
- public DB getDatabase() {
- return this.database;
- }
-
- public void notifyRemoved(final String[] info) {
- final Dictionary<String, Object> props = new Hashtable<String,
Object>();
- props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] +
'/' + info[1]);
- props.put("event.distribute", "");
- final Event event = new Event(SlingConstants.TOPIC_RESOURCE_REMOVED,
props);
- this.eventAdmin.postEvent(event);
- }
-
- public void notifyAddeed(final String[] info) {
- final Dictionary<String, Object> props = new Hashtable<String,
Object>();
- props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] +
'/' + info[1]);
- props.put("event.distribute", "");
- final Event event = new Event(SlingConstants.TOPIC_RESOURCE_ADDED,
props);
- this.eventAdmin.postEvent(event);
- }
-
- public void notifyUpdated(final String[] info) {
- final Dictionary<String, Object> props = new Hashtable<String,
Object>();
- props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] +
'/' + info[1]);
- props.put("event.distribute", "");
- final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED,
props);
- this.eventAdmin.postEvent(event);
- }
-}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
deleted file mode 100644
index a45335b..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.Map;
-
-import org.apache.sling.api.resource.AbstractResource;
-import org.apache.sling.api.resource.ModifiableValueMap;
-import org.apache.sling.api.resource.ResourceMetadata;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.api.wrappers.DeepReadModifiableValueMapDecorator;
-import org.apache.sling.api.wrappers.DeepReadValueMapDecorator;
-
-import com.mongodb.DBObject;
-
-public class MongoDBResource extends AbstractResource {
-
- /** The complete resource path. */
- private final String resourcePath;
-
- /** The collection */
- private final String collection;
-
- /** The resource resolver. */
- private final ResourceResolver resourceResolver;
-
- /** Metadata. */
- protected ResourceMetadata metadata = new ResourceMetadata();
-
- /** The db object. */
- private DBObject dbObject;
-
- /** The MongoDB resource provider. */
- private final MongoDBResourceProvider provider;
-
- public MongoDBResource(final ResourceResolver resolver,
- final String resourcePath,
- final String collection,
- final DBObject dbObject,
- final MongoDBResourceProvider provider) {
- this.resourceResolver = resolver;
- this.resourcePath = resourcePath;
- this.collection = collection;
- this.dbObject = dbObject;
- this.provider = provider;
- }
-
- public MongoDBResource(final MongoDBResource source) {
- this.resourceResolver = source.resourceResolver;
- this.resourcePath = source.resourcePath;
- this.collection = source.collection;
- this.dbObject = source.dbObject;
- this.provider = source.provider;
- }
- /**
- * @see org.apache.sling.api.resource.Resource#getPath()
- */
- public String getPath() {
- return this.resourcePath;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceType()
- */
- public String getResourceType() {
- // get resource type from data
- final Object rt = this.dbObject.get("sling:resourceType");
- if ( rt != null ) {
- return rt.toString();
- }
- return "nt:unstructured";
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
- */
- public String getResourceSuperType() {
- // get resource type from data
- final Object rt = this.dbObject.get("sling:resourceSuperType");
- if ( rt != null ) {
- return rt.toString();
- }
- return null;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
- */
- public ResourceMetadata getResourceMetadata() {
- return this.metadata;
- }
-
- /**
- * @see org.apache.sling.api.resource.Resource#getResourceResolver()
- */
- public ResourceResolver getResourceResolver() {
- return this.resourceResolver;
- }
-
- /**
- * @see
org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- @Override
- public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
- if ( type == ValueMap.class || type == Map.class ) {
- this.dbObject =
this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
- return (AdapterType) new DeepReadValueMapDecorator(this, new
ReadableValueMap(this.dbObject));
- } else if ( type == ModifiableValueMap.class ) {
- this.dbObject =
this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
- return (AdapterType) new DeepReadModifiableValueMapDecorator(this,
new ChangeableValueMap(this));
- }
-
- return super.adaptTo(type);
- }
-
- /**
- * Return the collection.
- */
- public String getCollection() {
- return this.collection;
- }
-
- /**
- * Get the current properties.
- */
- public DBObject getProperties() {
- return this.dbObject;
- }
-
- @Override
- public String toString() {
- return "MongoDBResource [resourcePath=" + resourcePath + ", dbPath=" +
this.dbObject.get(provider.getPROP_PATH()) + ", collection=" + collection
- + ", resourceResolver=" + resourceResolver + "]";
- }
-
- public void changed() {
- this.provider.changed(this);
- }
-}
diff --git
a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
deleted file mode 100644
index 4e73d1f..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.sling.api.resource.ModifyingResourceProvider;
-import org.apache.sling.api.resource.PersistenceException;
-import org.apache.sling.api.resource.QueriableResourceProvider;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceProvider;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ValueMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.CommandResult;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import com.mongodb.QueryBuilder;
-import com.mongodb.util.JSON;
-
-/**
- * The MongoDB resource provider creates resources based on MongoDB entries.
- * The resources contain all properties stored in the MongoDB except those
starting with a "_".
- */
-public class MongoDBResourceProvider implements ResourceProvider,
ModifyingResourceProvider, QueriableResourceProvider {
-
- /** The special path property containing the (relative) path of the
resource in the tree. */
- private static final String PROP_PATH = "_path";
-
- /** The id property. */
- private static final String PROP_ID = "_id";
-
- /** Logger. */
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- /** The global context .*/
- private final MongoDBContext context;
-
- private final Map<String, MongoDBResource> changedResources = new
HashMap<String, MongoDBResource>();
-
- private final Set<String> deletedResources = new HashSet<String>();
-
- public MongoDBResourceProvider(final MongoDBContext context) {
- this.context = context;
- }
-
- public static String propNameToKey(final String name) {
- if ( name.startsWith("_") ) {
- return "_" + name;
- }
- return name;
- }
-
- public static String keyToPropName(final String key) {
- if ( key.startsWith("__") ) {
- return key.substring(1);
- } else if ( key.startsWith("_") ) {
- return null;
- }
- return key;
- }
-
- /**
- * @see
org.apache.sling.api.resource.ModifyingResourceProvider#create(org.apache.sling.api.resource.ResourceResolver,
java.lang.String, java.util.Map)
- */
- public Resource create(final ResourceResolver resolver, final String path,
final Map<String, Object> properties)
- throws PersistenceException {
- final String[] info = this.extractResourceInfo(path);
- if ( info != null && info.length == 2) {
- final boolean deleted = this.deletedResources.remove(path);
- final MongoDBResource oldResource =
(MongoDBResource)this.getResource(resolver, path, info);
- if ( !deleted && oldResource != null ) {
- throw new PersistenceException("Resource already exists at " +
path, null, path, null);
- }
- final DBObject dbObj = new BasicDBObject();
- dbObj.put(getPROP_PATH(), info[1]);
- if ( properties != null ) {
- for(Map.Entry<String, Object> entry : properties.entrySet()) {
- final String key = propNameToKey(entry.getKey());
- dbObj.put(key, entry.getValue());
- }
- }
- if ( deleted && oldResource != null ) {
- dbObj.put(PROP_ID, oldResource.getProperties().get(PROP_ID));
- }
- final MongoDBResource rsrc = new MongoDBResource(resolver, path,
info[0], dbObj, this);
- this.changedResources.put(path, rsrc);
-
- return rsrc;
- }
- throw new PersistenceException("Illegal path - unable to create
resource at " + path, null, path, null);
- }
-
- /**
- * TODO - we should handle delete different and not put all child
resources into the
- * deleted set.
- * Instead when getting resources, the parents of the resource should be
checked
- * first.
- * This minimizes concurrency issues.
- * @see
org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver,
java.lang.String)
- */
- public void delete(final ResourceResolver resolver, final String path)
- throws PersistenceException {
- final String[] info = this.extractResourceInfo(path);
- if ( info != null ) {
- boolean deletedResource = false;
- if ( !deletedResources.contains(path) ) {
- final Resource rsrc = this.getResource(resolver, path, info);
- if ( rsrc instanceof MongoDBResource ) {
- this.deletedResources.add(path);
- this.changedResources.remove(path);
-
- final DBCollection col = this.getCollection(info[0]);
- final String pattern = "^" + Pattern.quote(info[1]) + "/";
-
- final DBObject query =
QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
- final DBCursor cur = col.find(query);
- while ( cur.hasNext() ) {
- final DBObject dbObj = cur.next();
- final String childPath = info[0] + '/' +
dbObj.get(getPROP_PATH());
- this.deletedResources.add(childPath);
- this.changedResources.remove(childPath);
- }
- deletedResource = true;
- }
- } else {
- deletedResource = true;
- }
- if ( deletedResource ) {
- final String prefix = path + "/";
- final Iterator<Map.Entry<String, MongoDBResource>> i =
this.changedResources.entrySet().iterator();
- while ( i.hasNext() ) {
- final Map.Entry<String, MongoDBResource> entry = i.next();
- if ( entry.getKey().startsWith(prefix) ) {
- i.remove();
- }
- }
- return;
- }
-
- }
- throw new PersistenceException("Unable to delete resource at {}" +
path, null, path, null);
- }
-
- /**
- * @see
org.apache.sling.api.resource.ModifyingResourceProvider#revert(ResourceResolver)
- */
- public void revert(final ResourceResolver resolver) {
- this.changedResources.clear();
- this.deletedResources.clear();
- }
-
- /**
- * @see
org.apache.sling.api.resource.ModifyingResourceProvider#commit(ResourceResolver)
- */
- public void commit(final ResourceResolver resolver) throws
PersistenceException {
- try {
- for(final String deleted : this.deletedResources) {
- final String[] info = this.extractResourceInfo(deleted);
-
- // check if the collection still exists
- final DBCollection col = this.getCollection(info[0]);
- if ( col != null ) {
- if (
col.findAndRemove(QueryBuilder.start(getPROP_PATH()).is(info[1]).get()) != null
) {
- this.context.notifyRemoved(info);
- }
- }
- }
- for(final MongoDBResource changed :
this.changedResources.values()) {
-
- final DBCollection col =
this.context.getDatabase().getCollection(changed.getCollection());
- if ( col != null ) {
- final String[] info = new String[]
{changed.getCollection(),
-
changed.getProperties().get(getPROP_PATH()).toString()};
- // create or update?
- if ( changed.getProperties().get(PROP_ID) != null ) {
-
col.update(QueryBuilder.start(getPROP_PATH()).is(changed.getProperties().get(getPROP_PATH())).get(),
- changed.getProperties());
- this.context.notifyUpdated(info);
- } else {
- // create
- col.save(changed.getProperties());
- this.context.notifyUpdated(info);
- }
- } else {
- throw new PersistenceException("Unable to create
collection " + changed.getCollection(), null, changed.getPath(), null);
- }
- }
- } finally {
- this.revert(resolver);
- }
- }
-
- /**
- * @see
org.apache.sling.api.resource.ModifyingResourceProvider#hasChanges(ResourceResolver)
- */
- public boolean hasChanges(final ResourceResolver resolver) {
- return this.changedResources.size() > 0 ||
this.deletedResources.size() > 0;
- }
-
- /**
- * @see
org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver,
java.lang.String)
- */
- public Resource getResource(final ResourceResolver resourceResolver, final
String path) {
- if ( this.deletedResources.contains(path) ) {
- return null;
- }
- if ( this.changedResources.containsKey(path) ) {
- return new MongoDBResource(this.changedResources.get(path));
- }
- final String[] info = this.extractResourceInfo(path);
- if ( info != null ) {
- return this.getResource(resourceResolver, path, info);
- }
- return null;
- }
-
- /**
- * Inform about changes of a resource.
- */
- public void changed(final MongoDBResource resource) {
- this.deletedResources.remove(resource.getPath());
- this.changedResources.put(resource.getPath(), resource);
- }
-
- /**
- * TODO - we have to check for deleted and added resources
- * @see
org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
- */
- public Iterator<Resource> listChildren(final Resource parent) {
- final String[] info = this.extractResourceInfo(parent.getPath());
- if ( info != null ) {
- if ( info.length == 0 ) {
- // all collections
- final Set<String> names = new
HashSet<String>(context.getDatabase().getCollectionNames());
- names.removeAll(this.context.getFilterCollectionNames());
- final Iterator<String> i = names.iterator();
- return new Iterator<Resource>() {
-
- public boolean hasNext() {
- return i.hasNext();
- }
-
- public Resource next() {
- final String name = i.next();
- return new
MongoDBCollectionResource(parent.getResourceResolver(), parent.getPath() + '/'
+ name);
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
-
- };
- }
- final DBCollection col = this.getCollection(info[0]);
- if ( col != null ) {
- final String pattern;
- if ( info.length == 1 ) {
- pattern = "^([^/])*$";
- } else {
- pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
- }
-
- final DBObject query =
QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
- final DBCursor cur = col.find(query).
- sort(BasicDBObjectBuilder.start(getPROP_PATH(),
1).get());
- return new Iterator<Resource>() {
-
- public boolean hasNext() {
- return cur.hasNext();
- }
-
- public Resource next() {
- final DBObject obj = cur.next();
- final String objPath =
obj.get(getPROP_PATH()).toString();
- final int lastSlash = objPath.lastIndexOf('/');
- final String name;
- if (lastSlash == -1) {
- name = objPath;
- } else {
- name = objPath.substring(lastSlash + 1);
- }
- return new
MongoDBResource(parent.getResourceResolver(),
- parent.getPath() + '/' + name,
- info[0],
- obj,
- MongoDBResourceProvider.this);
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
-
- };
- }
- }
- return null;
- }
-
- /**
- * @see
org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver,
javax.servlet.http.HttpServletRequest, java.lang.String)
- */
- @SuppressWarnings("javadoc")
- public Resource getResource(final ResourceResolver resourceResolver,
- final HttpServletRequest request,
- final String path) {
- return this.getResource(resourceResolver, path);
- }
-
- /**
- * Extract info about collection and path
- */
- protected String[] extractResourceInfo(final String path) {
- if ( path.startsWith(this.context.getRootWithSlash()) ) {
- if ( path.length() == this.context.getRootWithSlash().length() ) {
- // special resource - show all collections
- return new String[0];
- }
- final String info =
path.substring(this.context.getRootWithSlash().length());
- final int slashPos = info.indexOf('/');
- if ( slashPos != -1 ) {
- return new String[] {info.substring(0, slashPos),
info.substring(slashPos + 1)};
- }
- // special resource - collection
- return new String[] {info};
- }
-
- if ( path.equals(this.context.getRoot()) ) {
- // special resource - show all collections
- return new String[0];
- }
-
- return null;
- }
-
- /**
- * Check if a collection with a given name exists
- */
- protected boolean hasCollection(final String name) {
- logger.info("Mongo: Getting collection names");
- final Set<String> names =
this.context.getDatabase().getCollectionNames();
- return names.contains(name) &&
!this.context.isFilterCollectionName(name);
- }
-
-
- /**
- * Check if a collection with a given name exists and return it
- */
- protected DBCollection getCollection(final String name) {
- if ( this.hasCollection(name) ) {
- return this.context.getDatabase().getCollection(name);
- }
- return null;
- }
-
- /**
- * Get a resource
- */
- protected Resource getResource(final ResourceResolver resourceResolver,
final String path, final String[] info) {
- if ( info.length == 0 ) {
- // special resource : all collections
- return new MongoDBCollectionResource(resourceResolver, path);
- } else if ( info.length == 1 ) {
- // special resource : collection
- if ( this.hasCollection(info[0]) ) {
- return new MongoDBCollectionResource(resourceResolver, path);
- }
- return null;
- }
- logger.debug("Searching {} in {}", info[1], info[0]);
- final DBCollection col = this.getCollection(info[0]);
- if ( col != null ) {
- final DBObject obj =
col.findOne(QueryBuilder.start(getPROP_PATH()).is(info[1]).get());
- logger.debug("Found {}", obj);
- if ( obj != null ) {
- return new MongoDBResource(resourceResolver,
- path,
- info[0],
- obj,
- this);
- }
- }
-
- return null;
- }
-
- /**
- * Check if there is a newer db object for that path.
- */
- public DBObject getUpdatedDBObject(final String path, final DBObject
dbObj) {
- final MongoDBResource stored = this.changedResources.get(path);
- if ( stored != null ) {
- return stored.getProperties();
- }
- return dbObj;
- }
-
- protected Set<String> getDeletedResources() {
- return this.deletedResources;
- }
-
- protected Map<String, MongoDBResource> getChangedResources() {
- return this.changedResources;
- }
-
- protected MongoDBContext getContext() {
- return this.context;
- }
-
- protected String getPROP_PATH() {
- return PROP_PATH;
- }
-
- public Iterator<Resource> findResources(final ResourceResolver resolver,
String query, String language) {
- if ( !language.equals( "mongodb") || query == null || query.length()
== 0 || query.indexOf( ".find(" ) <= 0 )
- {
- return null;
- }
- Iterator<Resource> returnValue = null;
- final String collectionName = query.substring( 0, query.indexOf(
".find(" ) );
- DBCollection col = this.getCollection( collectionName );
- if ( col != null )
- {
- String criteria = query.trim().substring( query.indexOf( ".find("
) + 6, query.length() - 1 );
- DBObject dbObject = (DBObject) JSON.parse( criteria );
- final DBCursor cur = col.find( dbObject );
- final String rootPath = context.getRootWithSlash();
-
- return new Iterator<Resource>() {
-
- public boolean hasNext() {
- return cur.hasNext();
- }
-
- public Resource next() {
- final DBObject obj = cur.next();
- final String objPath = obj.get(getPROP_PATH()).toString();
- final int lastSlash = objPath.lastIndexOf('/');
- final String name;
- if (lastSlash == -1) {
- name = objPath;
- } else {
- name = objPath.substring(lastSlash + 1);
- }
- return new MongoDBResource(resolver,
- rootPath + collectionName + "/" + name,
- collectionName,
- obj,
- MongoDBResourceProvider.this);
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
-
- };
- }
-
- return returnValue;
- }
-
- public Iterator<ValueMap> queryResources(ResourceResolver resolver, String
query, String language) {
- return null;
- }
-}
diff --git
a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
deleted file mode 100644
index 0f0f670..0000000
---
a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.util.Map;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.PropertyUnbounded;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.ResourceProvider;
-import org.apache.sling.api.resource.QueriableResourceProvider;
-import org.apache.sling.api.resource.ResourceProviderFactory;
-import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.osgi.service.event.EventAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mongodb.DB;
-import com.mongodb.DBAddress;
-import com.mongodb.Mongo;
-import com.mongodb.MongoOptions;
-
-/**
- * The MongoDB resource provider factory allows to provided resources stored
- * in MongoDB.
- */
-@Component(label="%factory.name",
-description="%factory.description",
-configurationFactory=true,
-policy=ConfigurationPolicy.REQUIRE,
-metatype=true)
-@Service(value=ResourceProviderFactory.class)
-@Properties({
- @Property(name=ResourceProvider.ROOTS, value="/mongo"),
- @Property(name=QueriableResourceProvider.LANGUAGES, value="mongodb")
-})
-public class MongoDBResourceProviderFactory implements ResourceProviderFactory
{
-
- private static final String DEFAULT_HOST = "localhost";
-
- private static final int DEFAULT_PORT = 27017;
-
- private static final String DEFAULT_DB = "sling";
-
- @Property(value=DEFAULT_HOST)
- private static final String PROP_HOST = "host";
-
- @Property(intValue=DEFAULT_PORT)
- private static final String PROP_PORT = "port";
-
- @Property(value=DEFAULT_DB)
- private static final String PROP_DB = "db";
-
- @Property(unbounded=PropertyUnbounded.ARRAY, value="system.indexes")
- private static final String PROP_FILTER_COLLECTIONS = "filter.collections";
-
- private static final int DEFAULT_NUMCONNECTIONS = 10;
- @Property(intValue=DEFAULT_NUMCONNECTIONS)
- private static final String PROP_NUM_CONNECTIONS = "numconnections";
-
- private static final int DEFAULT_THREAD_MULTIPLIER= 5;
- @Property(intValue=DEFAULT_THREAD_MULTIPLIER)
- private static final String PROP_THREAD_MULTIPLIER = "threadmultiplier";
-
- /** Logger. */
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- /** The global context passed to each resource provider. */
- private MongoDBContext context;
-
- @Reference
- private EventAdmin eventAdmin;
-
- @Activate
- protected void activate(final Map<String, Object> props) throws Exception {
- final String[] roots =
PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
- if ( roots == null || roots.length == 0 ) {
- throw new Exception("Roots configuration is missing.");
- }
- if ( roots.length > 1 ) {
- throw new Exception("Only a single root should be configured.");
- }
- if ( roots[0] == null || roots[0].trim().length() == 0 ) {
- throw new Exception("Roots configuration is missing.");
- }
- final String host = PropertiesUtil.toString(props.get(PROP_HOST),
DEFAULT_HOST);
- final int port = PropertiesUtil.toInteger(props.get(PROP_PORT),
DEFAULT_PORT);
- final String db = PropertiesUtil.toString(props.get(PROP_DB),
DEFAULT_DB);
- logger.info("Starting MongoDB resource provider with host={}, port={},
db={}",
- new Object[] {host, port, db});
- final DBAddress address = new DBAddress(host, port, db);
- final MongoOptions options = new MongoOptions();
-
- options.connectionsPerHost =
PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS),
DEFAULT_NUMCONNECTIONS);
- options.threadsAllowedToBlockForConnectionMultiplier =
PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER),
DEFAULT_THREAD_MULTIPLIER);
- final Mongo m = new Mongo(address, options);
-
- final DB database = m.getDB( db );
- logger.info("Connected to database {}", database);
-
- this.context = new MongoDBContext(database,
- roots[0],
-
PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)),
- this.eventAdmin);
- }
-
- /**
- * @see
org.apache.sling.api.resource.ResourceProviderFactory#getResourceProvider(java.util.Map)
- */
- public ResourceProvider getResourceProvider(final Map<String, Object>
authenticationInfo) throws LoginException {
- // for now we allow anonymous access
- return new MongoDBResourceProvider(this.context);
- }
-
- /**
- * @see
org.apache.sling.api.resource.ResourceProviderFactory#getAdministrativeResourceProvider(java.util.Map)
- */
- public ResourceProvider getAdministrativeResourceProvider(final
Map<String, Object> authenticationInfo) throws LoginException {
- // for now we allow anonymous access
- return new MongoDBResourceProvider(this.context);
- }
-
- protected MongoDBContext getContext() {
- return this.context;
- }
-}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
deleted file mode 100644
index f3eee76..0000000
--- a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * 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.mongodb.impl;
-
-import java.lang.reflect.Array;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.sling.api.resource.ValueMap;
-
-import com.mongodb.DBObject;
-
-public class ReadableValueMap implements ValueMap {
-
- protected Map<String, Object> valueMap;
-
- public ReadableValueMap(final DBObject dbObject) {
- this.createValueMap(dbObject);
- }
-
- protected void createValueMap(final DBObject dbObject) {
- if (dbObject == null) {
- this.valueMap = Collections.<String, Object> emptyMap();
- } else {
- final Map<String, Object> map = new HashMap<String, Object>();
- for(final String key : dbObject.keySet()) {
- final String name = MongoDBResourceProvider.keyToPropName(key);
- if ( name != null ) {
- map.put(key, dbObject.get(name));
- }
- }
- this.valueMap = Collections.unmodifiableMap(map);
- }
- }
-
- /**
- * @see java.util.Map#containsKey(java.lang.Object)
- */
- public boolean containsKey(final Object key) {
- return this.valueMap.containsKey(key);
- }
-
- /**
- * @see java.util.Map#containsValue(java.lang.Object)
- */
- public boolean containsValue(final Object value) {
- return this.valueMap.containsValue(value);
- }
-
- /**
- * @see java.util.Map#entrySet()
- */
- public Set<java.util.Map.Entry<String, Object>> entrySet() {
- return this.valueMap.entrySet();
- }
-
- /**
- * @see java.util.Map#get(java.lang.Object)
- */
- public Object get(final Object key) {
- return this.valueMap.get(key);
- }
-
- /**
- * @see java.util.Map#isEmpty()
- */
- public boolean isEmpty() {
- return this.valueMap.isEmpty();
- }
-
- /**
- * @see java.util.Map#keySet()
- */
- public Set<String> keySet() {
- return this.valueMap.keySet();
- }
-
- /**
- * @see java.util.Map#size()
- */
- public int size() {
- return this.valueMap.size();
- }
-
- /**
- * @see java.util.Map#values()
- */
- public Collection<Object> values() {
- return this.valueMap.values();
- }
-
- /**
- * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String,
java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- public <T> T get(final String key, final Class<T> type) {
- if (type == null) {
- return (T) get(key);
- }
-
- final Object val = this.get(key);
- if ( val == null ) {
- return null;
- }
- return convertToType(val, type);
- }
-
- /**
- * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String,
java.lang.Object)
- */
- @SuppressWarnings("unchecked")
- public <T> T get(final String key,final T defaultValue) {
- if (defaultValue == null) {
- return (T) get(key);
- }
-
- T value = get(key, (Class<T>) defaultValue.getClass());
- if (value == null) {
- value = defaultValue;
- }
-
- return value;
- }
-
- /**
- * @see java.util.Map#clear()
- */
- public void clear() {
- throw new UnsupportedOperationException("clear");
- }
-
- /**
- * @see java.util.Map#put(java.lang.Object, java.lang.Object)
- */
- public Object put(String key, Object value) {
- throw new UnsupportedOperationException("put");
- }
-
- /**
- * @see java.util.Map#putAll(java.util.Map)
- */
- public void putAll(Map<? extends String, ? extends Object> m) {
- throw new UnsupportedOperationException("putAll");
- }
-
- /**
- * @see java.util.Map#remove(java.lang.Object)
- */
- public Object remove(Object key) {
- throw new UnsupportedOperationException("remove");
- }
-
- /**
- * Converts the object to the given type.
- * @param obj object
- * @param type type
- * @return the converted object
- */
- @SuppressWarnings("unchecked")
- private <T> T convertToType(final Object obj, final Class<T> type) {
- // todo: do smarter checks
- try {
- if (obj == null) {
- return null;
- } else if (type.isAssignableFrom(obj.getClass())) {
- return (T) obj;
- } else if (type.isArray()) {
- return (T) convertToArray(obj, type.getComponentType());
- } else if (type == String.class) {
- return (T) String.valueOf(obj);
- } else if (type == Integer.class) {
- return (T) (Integer) Integer.parseInt(obj.toString());
- } else if (type == Long.class) {
- return (T) (Long) Long.parseLong(obj.toString());
- } else if (type == Double.class) {
- return (T) (Double) Double.parseDouble(obj.toString());
- } else if (type == Boolean.class) {
- return (T) (Boolean) Boolean.parseBoolean(obj.toString());
- } else {
- return null;
- }
- } catch (final NumberFormatException e) {
- return null;
- }
- }
-
- /**
- * Converts the object to an array of the given type
- * @param obj the object or object array
- * @param type the component type of the array
- * @return and array of type T
- */
- private <T> T[] convertToArray(Object obj, Class<T> type) {
- List<T> values = new LinkedList<T>();
- if (obj.getClass().isArray()) {
- for (Object o: (Object[]) obj) {
- values.add(convertToType(o, type));
- }
- } else {
- values.add(convertToType(obj, type));
- }
- @SuppressWarnings("unchecked")
- T[] result = (T[]) Array.newInstance(type, values.size());
- return values.toArray(result);
- }
-}
diff --git a/src/main/resources/OSGI-INF/l10n/metatype.properties
b/src/main/resources/OSGI-INF/l10n/metatype.properties
deleted file mode 100644
index 22bcddd..0000000
--- a/src/main/resources/OSGI-INF/l10n/metatype.properties
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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.
-#
-
-
-#
-# This file contains localization strings for configuration labels and
-# descriptions as used in the metatype.xml descriptor generated by the
-# the Apache Felix SCR plugin
-
-#
-# Localizations for FsResourceProvider configuration
-factory.name = Apache Sling MongoDB Resource Provider
-factory.description = Configure an instance of the MongoDB \
- resource provider in terms of provider root and connection
-
-provider.roots.name = Provider Root
-provider.roots.description = Location in the virtual resource tree where the \
- resources are mapped in. This property must not be an empty string.
-
-host.name = MongoDB Host
-host.description = The host to connect to.
-
-port.name = MongoDB Port
-port.description = The port to connect to.
-
-db.name MongoDB Database
-db.description = The database to use.
-
-filter.collections.name = Filter Collections
-filter.collections.description = These collections are not available as
resources.
-
-numconnections.name = Connections Per Host
-numconnections.description = MongoOptions.connectionsPerHost
-
-threadmultiplier.name = Thread Multiplier
-threadmultiplier.description =
MongoOptions.threadsAllowedToBlockForConnectionMultiplier
\ No newline at end of file