You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2015/03/19 23:58:20 UTC
svn commit: r1667897 [2/2] - in /sling/whiteboard/olli/contentloader: ./
src/main/java/org/apache/sling/jcr/contentloader/
src/main/java/org/apache/sling/jcr/contentloader/internal/
src/main/java/org/apache/sling/jcr/contentloader/internal/readers/ src...
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java Thu Mar 19 22:58:19 2015
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -54,6 +53,7 @@ import org.apache.jackrabbit.api.securit
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.apache.sling.jcr.contentloader.ContentCreator;
+import org.apache.sling.jcr.contentloader.ContentHelper;
import org.apache.sling.jcr.contentloader.ContentImportListener;
import org.apache.sling.jcr.contentloader.ImportOptions;
import org.slf4j.Logger;
@@ -102,12 +102,7 @@ public class DefaultContentCreator imple
/**
* Helper class to get the mime type of a file.
*/
- private final JcrContentHelper jcrContentHelper;
-
- /**
- * List of active import providers mapped by extension.
- */
- private Map<String, ImportProvider> importProviders;
+ private final ContentHelper contentHelper;
/**
* Optional list of created nodes (for uninstall)
@@ -132,30 +127,20 @@ public class DefaultContentCreator imple
/**
* Constructor.
*
- * @param jcrContentHelper Helper class to get the mime type of a file
+ * @param contentHelper Helper class to get the mime type of a file
*/
- public DefaultContentCreator(JcrContentHelper jcrContentHelper) {
- this.jcrContentHelper = jcrContentHelper;
+ public DefaultContentCreator(final ContentHelper contentHelper) {
+ this.contentHelper = contentHelper;
}
/**
* Initialize this component.
*
* @param pathEntry The configuration for this import.
- * @param defaultImportProviders List of all import providers.
* @param createdNodes Optional list to store new nodes (for uninstall)
*/
- public void init(final ImportOptions pathEntry, final Map<String, ImportProvider> defaultImportProviders, final List<String> createdNodes, final ContentImportListener importListener) {
+ public void init(final ImportOptions pathEntry, final List<String> createdNodes, final ContentImportListener importListener) {
this.configuration = pathEntry;
- // create list of allowed import providers
- this.importProviders = new HashMap<String, ImportProvider>();
- final Iterator<Map.Entry<String, ImportProvider>> entryIter = defaultImportProviders.entrySet().iterator();
- while (entryIter.hasNext()) {
- final Map.Entry<String, ImportProvider> current = entryIter.next();
- if (!configuration.isIgnoredImportProvider(current.getKey())) {
- importProviders.put(current.getKey(), current.getValue());
- }
- }
this.createdNodes = createdNodes;
this.importListener = importListener;
}
@@ -191,10 +176,10 @@ public class DefaultContentCreator imple
/**
* Set the ignore overwrite flag.
*
- * @param flag
+ * @param ignoreOverwriteFlag
*/
- public void setIgnoreOverwriteFlag(boolean flag) {
- this.ignoreOverwriteFlag = flag;
+ public void setIgnoreOverwriteFlag(boolean ignoreOverwriteFlag) {
+ this.ignoreOverwriteFlag = ignoreOverwriteFlag;
}
/**
@@ -205,53 +190,9 @@ public class DefaultContentCreator imple
}
/**
- * Get all active import providers.
- *
- * @return A map of providers
- */
- public Map<String, ImportProvider> getImportProviders() {
- return this.importProviders;
- }
-
- /**
- * Return the import provider for the name
- *
- * @param name The file name.
- * @return The provider or <code>null</code>
- */
- public ImportProvider getImportProvider(String name) {
- ImportProvider provider = null;
- final Iterator<String> ipIter = importProviders.keySet().iterator();
- while (provider == null && ipIter.hasNext()) {
- final String ext = ipIter.next();
- if (name.endsWith(ext)) {
- provider = importProviders.get(ext);
- }
- }
- return provider;
- }
-
- /**
- * Get the extension of the file name.
- *
- * @param name The file name.
- * @return The extension a provider is registered for - or <code>null</code>
- */
- public String getImportProviderExtension(String name) {
- String providerExt = null;
- final Iterator<String> ipIter = importProviders.keySet().iterator();
- while (providerExt == null && ipIter.hasNext()) {
- final String ext = ipIter.next();
- if (name.endsWith(ext)) {
- providerExt = ext;
- }
- }
- return providerExt;
- }
-
- /**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createNode(java.lang.String, java.lang.String, java.lang.String[])
*/
+ @Override
public void createNode(String name, String primaryNodeType, String[] mixinNodeTypes) throws RepositoryException {
final Node parentNode = this.parentNodeStack.peek();
boolean isParentImport = (name == null && isParentNodeImport);
@@ -318,6 +259,7 @@ public class DefaultContentCreator imple
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createProperty(java.lang.String, int, java.lang.String)
*/
+ @Override
public void createProperty(String name, int propertyType, String value) throws RepositoryException {
final Node node = this.parentNodeStack.peek();
// check if the property already exists and isPropertyOverwrite() is false, don't overwrite it in this case
@@ -372,6 +314,7 @@ public class DefaultContentCreator imple
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createProperty(java.lang.String, int, java.lang.String[])
*/
+ @Override
public void createProperty(String name, int propertyType, String[] values) throws RepositoryException {
final Node node = this.parentNodeStack.peek();
// check if the property already exists and isPropertyOverwrite() is false, don't overwrite it in this case
@@ -455,6 +398,7 @@ public class DefaultContentCreator imple
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createProperty(java.lang.String, java.lang.Object)
*/
+ @Override
public void createProperty(String name, Object value) throws RepositoryException {
createProperty(name, value, false);
}
@@ -462,6 +406,7 @@ public class DefaultContentCreator imple
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#createProperty(java.lang.String, java.lang.Object[])
*/
+ @Override
public void createProperty(String name, Object[] values) throws RepositoryException {
createProperty(name, values, false);
}
@@ -469,13 +414,14 @@ public class DefaultContentCreator imple
/**
* @see org.apache.sling.jcr.contentloader.ContentCreator#finishNode()
*/
+ @Override
public void finishNode() throws RepositoryException {
final Node node = this.parentNodeStack.pop();
// resolve REFERENCE property values pointing to this node
resolveReferences(node);
}
- private void addNodeToCreatedList(Node node) throws RepositoryException {
+ private void addNodeToCreatedList(final Node node) throws RepositoryException {
if (this.createdNodes != null) {
this.createdNodes.add(node.getSession().getWorkspace().getName() + ":" + node.getPath());
}
@@ -498,7 +444,7 @@ public class DefaultContentCreator imple
return node.getPath() + "/" + path;
}
- private String getUUID(Session session, String propPath, String referencePath) throws RepositoryException {
+ private String getUUID(final Session session, final String propPath, final String referencePath) throws RepositoryException {
if (session.itemExists(referencePath)) {
Item item = session.getItem(referencePath);
if (item.isNode()) {
@@ -521,7 +467,7 @@ public class DefaultContentCreator imple
return null;
}
- private void resolveReferences(Node node) throws RepositoryException {
+ private void resolveReferences(final Node node) throws RepositoryException {
List<String> props = delayedReferences.remove(node.getPath());
if (props == null || props.size() == 0) {
return;
@@ -583,7 +529,7 @@ public class DefaultContentCreator imple
* @param path The path from which to extract the name part.
* @return The name part.
*/
- private String getName(String path) {
+ private String getName(final String path) {
int lastSlash = path.lastIndexOf('/');
String name = (lastSlash < 0) ? path : path.substring(lastSlash + 1);
return name;
@@ -712,7 +658,7 @@ public class DefaultContentCreator imple
// ensure content type
if (mimeType == null) {
- mimeType = jcrContentHelper.getMimeType(name);
+ mimeType = contentHelper.getMimeType(name);
if (mimeType == null) {
log.info("createFile: Cannot find content type for {}, using {}", name, DEFAULT_CONTENT_TYPE);
mimeType = DEFAULT_CONTENT_TYPE;
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java Thu Mar 19 22:58:19 2015
@@ -23,27 +23,29 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import javax.jcr.InvalidSerializedDataException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.jcr.contentloader.ContentHelper;
import org.apache.sling.jcr.contentloader.ContentImportListener;
import org.apache.sling.jcr.contentloader.ContentImporter;
import org.apache.sling.jcr.contentloader.ContentReader;
import org.apache.sling.jcr.contentloader.ImportOptions;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static javax.jcr.ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING;
-import static javax.jcr.ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW;
-
/**
* The <code>DefaultContentImporter</code> is the default implementation of the ContentImporter service providing the following functionality:
* <ul>
@@ -51,14 +53,18 @@ import static javax.jcr.ImportUUIDBehavi
* </ul>
*/
@Component
+@Service(ContentImporter.class)
@Properties({
- @Property(name = "service.vendor", value = "The Apache Software Foundation"),
- @Property(name = "service.description", value = "Apache Sling JCR Content Import Service")
+ @Property(
+ name = Constants.SERVICE_VENDOR,
+ value = "The Apache Software Foundation"
+ ),
+ @Property(
+ name = Constants.SERVICE_DESCRIPTION,
+ value = "Apache Sling JCR Content Loader Import Service"
+ )
})
-@Service(ContentImporter.class)
-public class DefaultContentImporter extends BaseImportLoader implements JcrContentHelper, ContentImporter {
-
- private final Logger log = LoggerFactory.getLogger(DefaultContentImporter.class);
+public class DefaultContentImporter extends BaseContentComponent implements ContentHelper, ContentImporter {
/**
* The MimeTypeService used by the initial content initialContentLoader to resolve MIME types for files to be installed.
@@ -66,32 +72,63 @@ public class DefaultContentImporter exte
@Reference
private MimeTypeService mimeTypeService;
+ private final Logger logger = LoggerFactory.getLogger(DefaultContentImporter.class);
+
+ public DefaultContentImporter() {
+ }
+
+ @Activate
+ protected void activate(final ComponentContext componentContext) {
+ openContentReaderTracker(componentContext.getBundleContext());
+ }
+
+ @Deactivate
+ protected void deactivate(final ComponentContext componentContext) {
+ closeContentReaderTracker();
+ }
+
/* (non-Javadoc)
* @see org.apache.sling.jcr.contentloader.ContentImporter#importContent(javax.jcr.Node, java.lang.String, java.io.InputStream, org.apache.sling.jcr.contentloader.ImportOptions, org.apache.sling.jcr.contentloader.ContentImportListener)
- */
- public void importContent(Node parent, String name, InputStream contentStream, ImportOptions importOptions, ContentImportListener importListener) throws RepositoryException, IOException {
+ */
+ @Override
+ public void importContent(Node parent, String filename, InputStream contentStream, ImportOptions importOptions, ContentImportListener importListener) throws RepositoryException, IOException {
// special treatment for system view imports
- if (name.endsWith(EXT_JCR_XML)) {
- boolean replace = (importOptions == null) ? false : importOptions.isOverwrite();
- final Node node = importSystemView(parent, name, contentStream, replace);
- if (node != null) {
- if (importListener != null) {
- importListener.onCreate(node.getPath());
- }
- }
+ if (filename.endsWith(EXT_JCR_XML)) {
+ importJcrXml(parent, filename, contentStream, importOptions, importListener);
return;
}
- DefaultContentCreator contentCreator = new DefaultContentCreator(this);
- List<String> createdPaths = new ArrayList<String>();
- contentCreator.init(importOptions, this.defaultImportProviders, createdPaths, importListener);
+ final DefaultContentCreator contentCreator = new DefaultContentCreator(this);
+
+ final String name = FilenameUtils.getName(filename);
+ final String extension = FilenameUtils.getExtension(filename);
+ final ContentReader contentReader = getContentReaderForExtension(extension);
- contentCreator.prepareParsing(parent, toPlainName(contentCreator, name));
+ importContent(contentCreator, contentReader, parent, name, contentStream, importOptions, importListener);
+ }
+
+ @Override
+ public void importContent(final Node parent, final String name, final String contentType, final InputStream contentStream, final ImportOptions importOptions, final ContentImportListener importListener) throws RepositoryException, IOException {
- final ImportProvider ip = contentCreator.getImportProvider(name);
- ContentReader reader = ip.getReader();
- reader.parse(contentStream, contentCreator);
+ // special treatment for system view imports
+ if (TYPE_JCR_XML.equalsIgnoreCase(contentType)) {
+ importJcrXml(parent, name, contentStream, importOptions, importListener);
+ return;
+ }
+
+ final DefaultContentCreator contentCreator = new DefaultContentCreator(this);
+
+ final ContentReader contentReader = getContentReaderForContentType(contentType);
+
+ importContent(contentCreator, contentReader, parent, name, contentStream, importOptions, importListener);
+ }
+
+ private void importContent(final DefaultContentCreator contentCreator, final ContentReader contentReader, final Node parent, final String name, final InputStream contentStream, final ImportOptions importOptions, final ContentImportListener importListener) throws RepositoryException, IOException {
+ List<String> createdPaths = new ArrayList<String>();
+ contentCreator.init(importOptions, createdPaths, importListener);
+ contentCreator.prepareParsing(parent, name);
+ contentReader.parse(contentStream, contentCreator);
// save changes
Session session = parent.getSession();
@@ -106,90 +143,23 @@ public class DefaultContentImporter exte
}
}
- private String toPlainName(DefaultContentCreator contentCreator, String name) {
- final String providerExt = contentCreator.getImportProviderExtension(name);
- if (providerExt != null) {
- if (name.length() == providerExt.length()) {
- return null; // no name is provided
- }
- return name.substring(0, name.length() - providerExt.length());
- }
- return name;
- }
-
- /**
- * Import the XML file as JCR system or document view import. If the XML
- * file is not a valid system or document view export/import file,
- * <code>false</code> is returned.
- *
- * @param parent The parent node below which to import
- * @param name the name of the import resource
- * @param contentStream The XML content to import
- * @param replace Whether or not to replace the subtree at name if the
- * node exists.
- * @return <code>true</code> if the import succeeds, <code>false</code> if the import fails due to XML format errors.
- * @throws IOException If an IO error occurrs reading the XML file.
- */
- private Node importSystemView(Node parent, String name, InputStream contentStream, boolean replace) throws IOException {
- InputStream ins = null;
- try {
- // check whether we have the content already, nothing to do then
- final String nodeName = (name.endsWith(EXT_JCR_XML)) ? name.substring(0, name.length() - EXT_JCR_XML.length()) : name;
-
- // ensure the name is not empty
- if (nodeName.length() == 0) {
- throw new IOException("Node name must not be empty (or extension only)");
- }
-
- // check for existence/replacement
- if (parent.hasNode(nodeName)) {
- Node existingNode = parent.getNode(nodeName);
- if (replace) {
- log.debug("importSystemView: Removing existing node at {}", nodeName);
- existingNode.remove();
- } else {
- log.debug("importSystemView: Node {} for XML already exists, nothing to to", nodeName);
- return existingNode;
- }
- }
-
- final int uuidBehavior;
- if (replace) {
- uuidBehavior = IMPORT_UUID_COLLISION_REPLACE_EXISTING;
- } else {
- uuidBehavior = IMPORT_UUID_CREATE_NEW;
- }
-
- ins = contentStream;
- Session session = parent.getSession();
- session.importXML(parent.getPath(), ins, uuidBehavior);
-
- // additionally check whether the expected child node exists
- return (parent.hasNode(nodeName)) ? parent.getNode(nodeName) : null;
- } catch (InvalidSerializedDataException isde) {
- // the xml might not be System or Document View export, fall back to old-style XML reading
- log.info("importSystemView: XML does not seem to be system view export; cause: {}", isde.toString());
- return null;
- } catch (RepositoryException re) {
- // any other repository related issue...
- log.info("importSystemView: Repository issue loading XML; cause: {}", re.toString());
- return null;
- } finally {
- if (ins != null) {
- try {
- ins.close();
- } catch (IOException ignore) {
- // ignore
- }
+ private void importJcrXml(final Node parent, final String name, final InputStream contentStream, final ImportOptions importOptions, final ContentImportListener importListener) throws IOException, RepositoryException {
+ logger.debug("import JCR XML: '{}'", name);
+ boolean replace = (importOptions == null) ? false : importOptions.isOverwrite();
+ final Node node = importJcrXml(parent, name, contentStream, replace);
+ if (node != null) {
+ if (importListener != null) {
+ importListener.onCreate(node.getPath());
}
}
}
- // ---------- JcrContentHelper implementation ---------------------------------------------
+ // ---------- ContentHelper implementation ---------------------------------------------
/* (non-Javadoc)
- * @see org.apache.sling.jcr.contentloader.internal.JcrContentHelper#getMimeType(java.lang.String)
+ * @see org.apache.sling.jcr.contentloader.ContentHelper#getMimeType(java.lang.String)
*/
+ @Override
public String getMimeType(String name) {
// local copy to not get NPE despite check for null due to concurrent unbind
MimeTypeService mts = mimeTypeService;
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java Thu Mar 19 22:58:19 2015
@@ -19,8 +19,10 @@
package org.apache.sling.jcr.contentloader.internal;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
import org.apache.sling.commons.osgi.ManifestHeader;
@@ -74,7 +76,7 @@ public class PathEntry extends ImportOpt
public static final String AUTOCHECKOUT_DIRECTIVE = "autoCheckout";
/**
- * The ignore import providers directive specifying whether the available {@link ImportProvider}s
+ * The ignore import providers directive specifying whether the available {@link org.apache.sling.jcr.contentloader.ContentReader}s
* should be used during content loading. This is a string value that defaults to the empty
* string..
* @since 2.0.4
@@ -100,7 +102,7 @@ public class PathEntry extends ImportOpt
private final boolean autoCheckout;
/** Which import providers should be ignored? @since 2.0.4 */
- private final List<String> ignoreImportProviders;
+ private final Set<String> ignoreImportProviders;
/**
* Target path where initial content will be loaded. If it´s null then
@@ -190,7 +192,7 @@ public class PathEntry extends ImportOpt
}
// expand directive
- this.ignoreImportProviders = new ArrayList<String>();
+ this.ignoreImportProviders = new HashSet<String>();
final String expandValue = entry.getDirectiveValue(IGNORE_IMPORT_PROVIDERS_DIRECTIVE);
if ( expandValue != null && expandValue.length() > 0 ) {
final StringTokenizer st = new StringTokenizer(expandValue, ",");
@@ -219,6 +221,7 @@ public class PathEntry extends ImportOpt
/* (non-Javadoc)
* @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isOverwrite()
*/
+ @Override
public boolean isOverwrite() {
return this.overwrite;
}
@@ -238,6 +241,7 @@ public class PathEntry extends ImportOpt
/* (non-Javadoc)
* @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isCheckin()
*/
+ @Override
public boolean isCheckin() {
return this.checkin;
}
@@ -250,14 +254,9 @@ public class PathEntry extends ImportOpt
return this.autoCheckout;
}
- /* (non-Javadoc)
- * @see org.apache.sling.jcr.contentloader.internal.ImportOptions#isIgnoredImportProvider(java.lang.String)
- */
- public boolean isIgnoredImportProvider(String extension) {
- if ( extension.startsWith(".") ) {
- extension = extension.substring(1);
- }
- return this.ignoreImportProviders.contains(extension);
+ @Override
+ public Set<String> getIgnoreImportProviders() {
+ return ignoreImportProviders;
}
public String getTarget() {
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java Thu Mar 19 22:58:19 2015
@@ -31,12 +31,22 @@ import java.util.regex.Pattern;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+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.Service;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.jcr.contentloader.BaseContentReader;
import org.apache.sling.jcr.contentloader.ContentCreator;
import org.apache.sling.jcr.contentloader.ContentReader;
-import org.apache.sling.jcr.contentloader.internal.ImportProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
/**
* The <code>JsonReader</code> Parses a Json document on content load and creates the
@@ -87,7 +97,43 @@ import org.apache.sling.jcr.contentloade
*
* </pre>
*/
-public class JsonReader implements ContentReader {
+@Component(
+ label = "Apache Sling JCR Content Loader JsonReader",
+ description = "parses JSON content with Sling Commons JSON",
+ immediate = true,
+ metatype = true
+)
+@Service
+@Properties({
+ @Property(
+ name = Constants.SERVICE_VENDOR,
+ value = "The Apache Software Foundation"
+ ),
+ @Property(
+ name = Constants.SERVICE_DESCRIPTION,
+ value = "Apache Sling JCR Content Loader JsonReader"
+ ),
+ @Property(
+ name = Constants.SERVICE_RANKING,
+ intValue = 0,
+ propertyPrivate = false
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_EXTENSIONS,
+ value = {
+ "json"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_CONTENTTYPES,
+ value = {
+ "application/json"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ )
+})
+public class JsonReader extends BaseContentReader implements ContentReader {
private static final Pattern jsonDate = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}[-+]{1}[0-9]{2}[:]{0,1}[0-9]{2}$");
private static final String REFERENCE = "jcr:reference:";
@@ -118,16 +164,24 @@ public class JsonReader implements Conte
private static final String SECURITY_PRINCIPLES = "security:principals";
private static final String SECURITY_ACL = "security:acl";
- public static final ImportProvider PROVIDER = new ImportProvider() {
- private JsonReader jsonReader;
+ public JsonReader() {
+ }
+
+ @Activate
+ protected void activate(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
- public ContentReader getReader() {
- if (jsonReader == null) {
- jsonReader = new JsonReader();
- }
- return jsonReader;
- }
- };
+ @Modified
+ protected void modified(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
+
+ @Deactivate
+ protected void deactivate(final ComponentContext componentContext) {
+ extensions = null;
+ contentTypes = null;
+ }
/**
* @see org.apache.sling.jcr.contentloader.ContentReader#parse(java.net.URL, org.apache.sling.jcr.contentloader.ContentCreator)
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReader.java Thu Mar 19 22:58:19 2015
@@ -49,10 +49,20 @@ import javax.xml.transform.TransformerFa
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+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.Service;
+import org.apache.sling.jcr.contentloader.BaseContentReader;
import org.apache.sling.jcr.contentloader.ContentCreator;
import org.apache.sling.jcr.contentloader.ContentReader;
-import org.apache.sling.jcr.contentloader.internal.ImportProvider;
import org.kxml2.io.KXmlParser;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
@@ -94,7 +104,44 @@ import org.xmlpull.v1.XmlPullParserExcep
* If you want to include a binary file in your loaded content, you may specify it using a
* {@link org.apache.sling.jcr.contentloader.internal.readers.XmlReader.FileDescription <code><nt:file></code>} element.
*/
-public class XmlReader implements ContentReader {
+@Component(
+ label = "Apache Sling JCR Content Loader XmlReader",
+ description = "parses XML content with kXML",
+ immediate = true,
+ metatype = true
+)
+@Service
+@Properties({
+ @Property(
+ name = Constants.SERVICE_VENDOR,
+ value = "The Apache Software Foundation"
+ ),
+ @Property(
+ name = Constants.SERVICE_DESCRIPTION,
+ value = "Apache Sling JCR Content Loader XmlReader"
+ ),
+ @Property(
+ name = Constants.SERVICE_RANKING,
+ intValue = 0,
+ propertyPrivate = false
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_EXTENSIONS,
+ value = {
+ "xml"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_CONTENTTYPES,
+ value = {
+ "application/xml",
+ "text/xml"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ )
+})
+public class XmlReader extends BaseContentReader implements ContentReader {
/*
* <node> <primaryNodeType>type</primaryNodeType> <mixinNodeTypes>
@@ -130,23 +177,9 @@ public class XmlReader implements Conten
private static final String ELEM_FILE_NAMESPACE = "http://www.jcp.org/jcr/nt/1.0";
private static final String ELEM_FILE_NAME = "file";
- public static final ImportProvider PROVIDER = new ImportProvider() {
- private XmlReader xmlReader;
-
- public ContentReader getReader() throws IOException {
- if (xmlReader == null) {
- try {
- xmlReader = new XmlReader();
- } catch (Throwable t) {
- throw (IOException) new IOException(t.getMessage()).initCause(t);
- }
- }
- return xmlReader;
- }
- };
private KXmlParser xmlParser;
- XmlReader() {
+ public XmlReader() {
this.xmlParser = new KXmlParser();
try {
// Make namespace-aware
@@ -156,8 +189,23 @@ public class XmlReader implements Conten
}
}
- // ---------- XML content access -------------------------------------------
+ @Activate
+ protected void activate(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
+ @Modified
+ protected void modified(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
+
+ @Deactivate
+ protected void deactivate(final ComponentContext componentContext) {
+ extensions = null;
+ contentTypes = null;
+ }
+
+ // ---------- XML content access -------------------------------------------
/**
* @see org.apache.sling.jcr.contentloader.ContentReader#parse(URL, org.apache.sling.jcr.contentloader.ContentCreator)
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/ZipReader.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/ZipReader.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/ZipReader.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/ZipReader.java Thu Mar 19 22:58:19 2015
@@ -20,59 +20,97 @@ package org.apache.sling.jcr.contentload
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.jcr.RepositoryException;
import org.apache.commons.io.input.CloseShieldInputStream;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+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.Service;
+import org.apache.sling.jcr.contentloader.BaseContentReader;
import org.apache.sling.jcr.contentloader.ContentCreator;
import org.apache.sling.jcr.contentloader.ContentReader;
-import org.apache.sling.jcr.contentloader.internal.ImportProvider;
-
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
/**
- * The <code>ZipReader</code> TODO
+ * The <code>ZipReader</code>
*
* @since 2.0.4
*/
-public class ZipReader implements ContentReader {
+@Component(
+ label = "Apache Sling JCR Content Loader ZipReader",
+ description = "parses ZIP and Java archives with standard Java ZIP utils",
+ immediate = true,
+ metatype = true
+)
+@Service
+@Properties({
+ @Property(
+ name = Constants.SERVICE_VENDOR,
+ value = "The Apache Software Foundation"
+ ),
+ @Property(
+ name = Constants.SERVICE_DESCRIPTION,
+ value = "Apache Sling JCR Content Loader ZipReader"
+ ),
+ @Property(
+ name = Constants.SERVICE_RANKING,
+ intValue = 0,
+ propertyPrivate = false
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_EXTENSIONS,
+ value = {
+ "zip",
+ "jar"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ ),
+ @Property(
+ name = ContentReader.PROPERTY_CONTENTTYPES,
+ value = {
+ "application/zip",
+ "application/java-archive"
+ },
+ unbounded = PropertyUnbounded.ARRAY
+ )
+})
+public class ZipReader extends BaseContentReader implements ContentReader {
private static final String NT_FOLDER = "nt:folder";
- public static final ImportProvider ZIP_PROVIDER = new ImportProvider() {
- private ZipReader zipReader;
+ public ZipReader() {
+ }
- public ContentReader getReader() {
- if (zipReader == null) {
- zipReader = new ZipReader(false);
- }
- return zipReader;
- }
- };
-
- public static final ImportProvider JAR_PROVIDER = new ImportProvider() {
- private ZipReader zipReader;
-
- public ContentReader getReader() {
- if (zipReader == null) {
- zipReader = new ZipReader(true);
- }
- return zipReader;
- }
- };
+ @Activate
+ protected void activate(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
- /** Is this a jar reader? */
- //private final boolean jarReader;
+ @Modified
+ protected void modified(final ComponentContext componentContext) {
+ configure(componentContext);
+ }
- public ZipReader(boolean jarReader) {
- //this.jarReader = jarReader;
+ @Deactivate
+ protected void deactivate(final ComponentContext componentContext) {
+ extensions = null;
+ contentTypes = null;
}
/**
* @see org.apache.sling.jcr.contentloader.ContentReader#parse(java.net.URL, org.apache.sling.jcr.contentloader.ContentCreator)
*/
- public void parse(java.net.URL url, ContentCreator creator)
+ public void parse(URL url, ContentCreator creator)
throws IOException, RepositoryException {
parse(url.openStream(), creator);
}
Modified: sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/package-info.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/package-info.java (original)
+++ sling/whiteboard/olli/contentloader/src/main/java/org/apache/sling/jcr/contentloader/package-info.java Thu Mar 19 22:58:19 2015
@@ -17,10 +17,7 @@
* under the License.
*/
-@Export(optional = "provide:=true")
-@Version("0.2")
+@Version("1.0.0")
package org.apache.sling.jcr.contentloader;
-import aQute.bnd.annotation.Export;
import aQute.bnd.annotation.Version;
-
Modified: sling/whiteboard/olli/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/olli/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java?rev=1667897&r1=1667896&r2=1667897&view=diff
==============================================================================
--- sling/whiteboard/olli/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java (original)
+++ sling/whiteboard/olli/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreatorTest.java Thu Mar 19 22:58:19 2015
@@ -1,6 +1,26 @@
+/*
+ * 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.contentloader.internal;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -24,7 +44,6 @@ public class DefaultContentCreatorTest {
Node parentNode;
Property prop;
-
@org.junit.Test public void willRewriteUndefinedPropertyType() throws RepositoryException {
contentCreator = new DefaultContentCreator(null);
parentNode = mockery.mock(Node.class);
@@ -41,9 +60,9 @@ public class DefaultContentCreatorTest {
return true;
}
- @Override
- public boolean isIgnoredImportProvider(String extension) {
- return false;
+ @Override
+ public Set<String> getIgnoreImportProviders() {
+ return Collections.emptySet();
}
@Override
@@ -54,7 +73,7 @@ public class DefaultContentCreatorTest {
@Override
public boolean isPropertyOverwrite() {
return true;
- } }, new HashMap<String, ImportProvider>(), null, null);
+ } }, null, null);
contentCreator.prepareParsing(parentNode, null);
this.mockery.checking(new Expectations() {{
@@ -83,8 +102,8 @@ public class DefaultContentCreatorTest {
}
@Override
- public boolean isIgnoredImportProvider(String extension) {
- return false;
+ public Set<String> getIgnoreImportProviders() {
+ return Collections.emptySet();
}
@Override
@@ -95,7 +114,7 @@ public class DefaultContentCreatorTest {
@Override
public boolean isPropertyOverwrite() {
return false;
- } }, new HashMap<String, ImportProvider>(), null, null);
+ } }, null, null);
contentCreator.prepareParsing(parentNode, null);
this.mockery.checking(new Expectations() {{