Author: olli Date: Tue Apr 29 08:44:12 2014 New Revision: 1590918 URL: http://svn.apache.org/r1590918 Log: style
Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java?rev=1590918&r1=1590917&r2=1590918&view=diff ============================================================================== --- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java (original) +++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java Tue Apr 29 08:44:12 2014 @@ -18,8 +18,6 @@ */ package org.apache.sling.jcr.contentloader.internal; -import static javax.jcr.ImportUUIDBehavior.*; - import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -42,43 +40,44 @@ import org.apache.sling.jcr.contentloade 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: + * The <code>DefaultContentImporter</code> is the default implementation of the ContentImporter service providing the following functionality: * <ul> * <li>Import content into the content repository. * </ul> */ -@Component(metatype=true, immediate=false, label="%content.import.service.name", description="%content.import.service.description") +@Component( + metatype = true, + immediate = false, + label = "%content.import.service.name", + description = "%content.import.service.description" +) @Properties({ - @Property(name="service.vendor", value="The Apache Software Foundation"), - @Property(name="service.description", value="Apache Sling JCR Content Import Service") + @Property(name = "service.vendor", value = "The Apache Software Foundation"), + @Property(name = "service.description", value = "Apache Sling JCR Content Import Service") }) @Service(ContentImporter.class) public class DefaultContentImporter extends BaseImportLoader implements JcrContentHelper, ContentImporter { - /** default log */ private final Logger log = LoggerFactory.getLogger(DefaultContentImporter.class); /** - * The MimeTypeService used by the initial content initialContentLoader to - * resolve MIME types for files to be installed. + * The MimeTypeService used by the initial content initialContentLoader to resolve MIME types for files to be installed. */ @Reference private MimeTypeService mimeTypeService; /* (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) + * @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 { + public void importContent(Node parent, String name, 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(); + boolean replace = (importOptions == null) ? false : importOptions.isOverwrite(); Node node = importSystemView(parent, name, contentStream, replace); if (node != null) { if (importListener != null) { @@ -88,7 +87,7 @@ public class DefaultContentImporter exte } } - DefaultContentCreator contentCreator = new DefaultContentCreator(this); + DefaultContentCreator contentCreator = new DefaultContentCreator(this); List<String> createdPaths = new ArrayList<String>(); contentCreator.init(importOptions, this.defaultImportProviders, createdPaths, importListener); @@ -96,17 +95,17 @@ public class DefaultContentImporter exte final ImportProvider ip = contentCreator.getImportProvider(name); ContentReader reader = ip.getReader(); - reader.parse(contentStream, contentCreator); + reader.parse(contentStream, contentCreator); - //save changes + // save changes Session session = parent.getSession(); - session.save(); + session.save(); // finally checkin versionable nodes for (final Node versionable : contentCreator.getVersionables()) { versionable.checkin(); - if ( importListener != null ) { - importListener.onCheckin(versionable.getPath()); + if (importListener != null) { + importListener.onCheckin(versionable.getPath()); } } } @@ -114,38 +113,32 @@ 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()); + 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 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. + * @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 { + 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; + 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) { @@ -156,17 +149,14 @@ public class DefaultContentImporter exte if (parent.hasNode(nodeName)) { Node existingNode = parent.getNode(nodeName); if (replace) { - log.debug("importSystemView: Removing existing node at {}", - nodeName); + log.debug("importSystemView: Removing existing node at {}", nodeName); existingNode.remove(); } else { - log.debug( - "importSystemView: Node {} for XML already exists, nothing to to", - nodeName); + 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; @@ -181,19 +171,12 @@ public class DefaultContentImporter exte // 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, trying old style; cause: {}", - isde.toString()); + // 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, trying old style; cause: {}", isde.toString()); return null; } catch (RepositoryException re) { - // any other repository related issue... - log.info( - "importSystemView: Repository issue loading XML, trying old style; cause: {}", - re.toString()); + log.info("importSystemView: Repository issue loading XML, trying old style; cause: {}", re.toString()); return null; } finally { if (ins != null) { @@ -206,17 +189,15 @@ public class DefaultContentImporter exte } } - // ---------- JcrContentHelper implementation --------------------------------------------- - /* (non-Javadoc) - * @see org.apache.sling.jcr.contentloader.internal.JcrContentHelper#getMimeType(java.lang.String) - */ - public String getMimeType(String name) { - // local copy to not get NPE despite check for null due to concurrent - // unbind + /* (non-Javadoc) + * @see org.apache.sling.jcr.contentloader.internal.JcrContentHelper#getMimeType(java.lang.String) + */ + public String getMimeType(String name) { + // local copy to not get NPE despite check for null due to concurrent unbind MimeTypeService mts = mimeTypeService; return (mts != null) ? mts.getMimeType(name) : null; - } + } }