Author: rombert
Date: Tue Jan 27 21:28:56 2015
New Revision: 1655167

URL: http://svn.apache.org/r1655167
Log:
SLING-4105 -  Content Navigator should not read all the jcr_root when
initialized

Delegate detection of serialization files to the SerializationManager,
which is more lightweight.

This is a workaround rather than the proper fix, but it does seem to
improve the responsiveness quite a lot.

There is a slight behaviour change as the SerializationManager considers
any file named .content.xml a FileVault file, but at least the behaviour
is more consistent.

Modified:
    
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java

Modified: 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1655167&r1=1655166&r2=1655167&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
 (original)
+++ 
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java
 Tue Jan 27 21:28:56 2015
@@ -34,8 +34,6 @@ import javax.jcr.PropertyType;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.util.ISO9075;
@@ -92,10 +90,7 @@ import org.eclipse.ui.part.ResourceTrans
 import org.eclipse.ui.views.properties.IPropertySource;
 import 
org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
 import org.eclipse.wst.server.core.IServer;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
 
 import de.pdark.decentxml.Attribute;
 import de.pdark.decentxml.Document;
@@ -108,32 +103,6 @@ import de.pdark.decentxml.XMLTokenizer.T
 /** WIP: model object for a jcr node shown in the content package view in 
project explorer **/
 public class JcrNode implements IAdaptable {
 
-    private final class JcrRootHandler extends DefaultHandler {
-               boolean firstElement = true;
-               boolean isVaultFile = false;
-
-               public boolean isVaultFile() {
-                       return isVaultFile;
-               }
-
-               @Override
-               public void startElement(String uri, String localName,
-                               String qName, Attributes attributes)
-                               throws SAXException {
-                       if (!firstElement) {
-                               return;
-                       }
-                       firstElement = false;
-                       if ("jcr:root".equals(qName)) {
-                               String ns = attributes.getValue("xmlns:jcr");
-                               if (ns!=null && 
ns.startsWith("http://www.jcp.org/jcr";)) {
-                                       // then this is a vault file with a 
jcr:root at the beginning
-                                       isVaultFile = true;
-                               }
-                       }
-               }
-       }
-
        private final static WorkbenchLabelProvider workbenchLabelProvider = 
new WorkbenchLabelProvider();
        
        final GenericJcrRootFile underlying;
@@ -437,28 +406,10 @@ public class JcrNode implements IAdaptab
         return res.getType() == IResource.FILE && res.getName().equals(".vlt");
     }
 
-    private boolean isVaultFile(IResource iResource)
-                       throws ParserConfigurationException, SAXException, 
IOException,
-                       CoreException {
-               if (iResource.getName().endsWith(".xml")) {
-                       // then it could potentially be a vlt file. 
-                       // let's check if it contains a jcr:root element with 
the appropriate namespace
-                       
-                       IFile file = (IFile)iResource;
-                       
-                   SAXParserFactory factory = SAXParserFactory.newInstance();
-                   SAXParser saxParser = factory.newSAXParser();
+    private boolean isVaultFile(IResource iResource) {
 
-                   JcrRootHandler h = new JcrRootHandler();
-                       InputStream contents = file.getContents();
-            try {
-                saxParser.parse(new InputSource(contents), h);
-                return h.isVaultFile();
-            } finally {
-                IOUtils.closeQuietly(contents);
-            }
-               }
-               return false;
+        return Activator.getDefault().getSerializationManager()
+                .isSerializationFile(iResource.getLocation().toOSString());
        }
 
        public void setResource(IResource resource) {
@@ -479,12 +430,7 @@ public class JcrNode implements IAdaptab
                typeFile |= (resource!=null && primaryType==null);
                boolean typeUnstructured = primaryType!=null && 
((primaryType.equals("nt:unstructured")));
                
-               boolean isVaultFile = false;
-               try {
-                       isVaultFile = resource!=null && isVaultFile(resource);
-               } catch (Exception e) {
-                       // this empty catch is okay
-               }
+        boolean isVaultFile = resource != null && isVaultFile(resource);
                
                String mimeType = null;
                mimeType = getJcrContentProperty("jcr:mimeType");


Reply via email to