incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1520584 - in /sling/branches/tooling-ide-vlt/tooling/ide: impl-vlt/META-INF/ impl-vlt/src/org/apache/sling/ide/impl/vlt/ impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ vlt-wrapper/META-INF/
Date Fri, 06 Sep 2013 14:36:54 GMT
Author: rombert
Date: Fri Sep  6 14:36:53 2013
New Revision: 1520584

URL: http://svn.apache.org/r1520584
Log:
SLING-2989 - [Tooling] integrate with vlt once available

Basic support for writing back property values from a .content.xml file.
The support is not based on FileVault's support classes, since I can't
find an isolated enough support class. It's limited, as it supports
String properties only, and does not support nested node properties
inside a .content.xml file.

Added:
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
  (with props)
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
  (with props)
Modified:
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/VltRepository.java
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
    sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF

Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF?rev=1520584&r1=1520583&r2=1520584&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF Fri Sep  6 14:36:53
2013
@@ -7,6 +7,7 @@ Bundle-RequiredExecutionEnvironment: Jav
 Require-Bundle: org.eclipse.equinox.ds;bundle-version="1.2.1",
  org.eclipse.osgi.services;bundle-version="3.2.100"
 Import-Package: javax.jcr,
+ javax.jcr.nodetype,
  org.apache.jackrabbit.vault.fs,
  org.apache.jackrabbit.vault.fs.api,
  org.apache.jackrabbit.vault.fs.config,

Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java?rev=1520584&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
(added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
Fri Sep  6 14:36:53 2013
@@ -0,0 +1,72 @@
+/*
+ * 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.ide.impl.vlt;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.vault.util.PathUtil;
+import org.apache.sling.ide.transport.FileInfo;
+
+public class UpdateNodePropertiesCommand extends JcrCommand<Void> {
+
+    private final Map<String, Object> serializationData;
+
+    public UpdateNodePropertiesCommand(Repository jcrRepo, Credentials credentials, FileInfo
fileInfo,
+            Map<String, Object> serializationData) {
+
+        // intention since the fileInfo refers to the .content.xml file ( TODO - should we
change that )?
+        super(jcrRepo, credentials, PathUtil.makePath(fileInfo.getRelativeLocation(), ""));
+
+        this.serializationData = serializationData;
+    }
+
+    @Override
+    protected Void execute0(Session session) throws RepositoryException, IOException {
+
+        Node node = session.getNode(getPath());
+
+        for (Map.Entry<String, Object> entry : serializationData.entrySet()) {
+
+            if (node.hasProperty(entry.getKey())) {
+
+                Property prop = node.getProperty(entry.getKey());
+                if (prop.getDefinition().isProtected()) {
+                    continue;
+                }
+
+                if (prop.getType() != PropertyType.STRING)
+                    throw new UnsupportedOperationException("Unable to set value of property
'" + prop.getName()
+                            + "' since its type is '" + prop.getType() + "'");
+            }
+
+            node.setProperty(entry.getKey(), entry.getValue().toString());
+        }
+
+        return null;
+
+    }
+
+}

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/VltRepository.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/VltRepository.java?rev=1520584&r1=1520583&r2=1520584&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/VltRepository.java
(original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/VltRepository.java
Fri Sep  6 14:36:53 2013
@@ -54,7 +54,8 @@ public class VltRepository implements Re
     @Override
     public Command<Void> newUpdateContentNodeCommand(FileInfo fileInfo, Map<String,
Object> serializationData) {
         // TODO implement
-        return new NoOpCommand<Void>(jcrRepo, credentials);
+        return TracingCommand.wrap(new UpdateNodePropertiesCommand(jcrRepo, credentials,
fileInfo, serializationData),
+                eventAdmin);
     }
 
     @Override

Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java?rev=1520584&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
(added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
Fri Sep  6 14:36:53 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.ide.impl.vlt.serialization;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class ContextXmlHandler extends DefaultHandler {
+
+    private final Map<String, Object> properties = new HashMap<String, Object>();
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
+        if (!qName.equals("jcr:root")) {
+            return;
+        }
+
+        for (int i = 0; i < attributes.getLength(); i++) {
+
+            String attributeQName = attributes.getQName(i);
+            String value = attributes.getValue(i);
+
+            properties.put(attributeQName, value);
+        }
+    }
+
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+}

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java?rev=1520584&r1=1520583&r2=1520584&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
(original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
Fri Sep  6 14:36:53 2013
@@ -26,6 +26,9 @@ import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.jackrabbit.vault.fs.api.Aggregate;
 import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
@@ -39,6 +42,7 @@ import org.apache.sling.ide.impl.vlt.Vau
 import org.apache.sling.ide.serialization.SerializationManager;
 import org.apache.sling.ide.transport.RepositoryInfo;
 import org.apache.sling.ide.transport.ResourceProxy;
+import org.xml.sax.SAXException;
 
 public class VltSerializationManager implements SerializationManager {
 
@@ -122,6 +126,26 @@ public class VltSerializationManager imp
 
     @Override
     public Map<String, Object> readSerializationData(InputStream source) throws IOException
{
-        return null;
+
+        if (source == null)
+            return null;
+
+        try {
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
+            SAXParser parser = factory.newSAXParser();
+            ContextXmlHandler handler = new ContextXmlHandler();
+            parser.parse(source, handler);
+
+            return handler.getProperties();
+        } catch (SAXException e) {
+            // TODO proper error handling
+            throw new IOException(e);
+        } catch (ParserConfigurationException e) {
+            // TODO proper error handling
+            throw new IOException(e);
+        }
+
     }
 }

Modified: sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF?rev=1520584&r1=1520583&r2=1520584&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF Fri Sep  6
14:36:53 2013
@@ -16,6 +16,7 @@ Bundle-ClassPath: .,
  lib/jackrabbit-spi-commons-2.4.0.jar,
  lib/jackrabbit-webdav-2.4.0.jar
 Export-Package: javax.jcr,
+ javax.jcr.nodetype,
  org.apache.jackrabbit.vault.davex,
  org.apache.jackrabbit.vault.fs,
  org.apache.jackrabbit.vault.fs.api,



Mime
View raw message