incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1406137 - in /sling/whiteboard/asanso/plugins/eclipse: slingclipse-api/src/org/apache/sling/slingclipse/api/ slingclipse-http/src/org/apache/sling/slingclipse/http/impl/ slingclipse-plugin/src/org/apache/sling/slingclipse/ slingclipse-plug...
Date Tue, 06 Nov 2012 13:45:36 GMT
Author: asanso
Date: Tue Nov  6 13:45:36 2012
New Revision: 1406137

URL: http://svn.apache.org/viewvc?rev=1406137&view=rev
Log:
SLING-2646 - [Tooling] adding support for .content.xml files on save

Added:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/ProtectedNodes.java
Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/SlingclipseHelper.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/ProtectedNodes.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/ProtectedNodes.java?rev=1406137&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/ProtectedNodes.java
(added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/ProtectedNodes.java
Tue Nov  6 13:45:36 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.slingclipse.api;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+public enum ProtectedNodes {
+	
+	JCR_CREATED(Repository.JCR_CREATED),JCR_CREATED_BY(Repository.JCR_CREATED_BY),JCR_PRIMARY_TYPE(Repository.JCR_PRIMARY_TYPE);
+
+	private static final Map<String, ProtectedNodes> nameToValueMap =
+			new HashMap<String, ProtectedNodes>();
+
+	static {
+		for (ProtectedNodes value : EnumSet.allOf(ProtectedNodes.class)) {			 
+			nameToValueMap.put(value.getKey(), value);
+		}
+	}
+
+	public static boolean exists(String key) {
+		return nameToValueMap.containsKey(key);
+	}
+	
+	
+	
+	private final String key;
+
+	private ProtectedNodes(String key) {
+		this.key = key;
+	}
+
+	public String getKey() {
+		return this.key;
+	}
+	
+}

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java?rev=1406137&r1=1406136&r2=1406137&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
Tue Nov  6 13:45:36 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.slingclipse.api;
 
+import java.util.Map;
+
 public interface Repository {
 	
 	public static String JCR_PRIMARY_TYPE= "jcr:primaryType";
@@ -23,13 +25,67 @@ public interface Repository {
 	public static String NT_FOLDER= "nt:folder";
 	public static String JCR_ROOT= "jcr:root";
 	public static String NT_RESOURCE= "nt:resource";
-	
-	
+	public static String JCR_CREATED= "jcr:created";
+	public static String JCR_CREATED_BY= "jcr:createdBy";
+	public static String JCR_ETAG= "jcr:etag";
+	public static String JCR_LIFECYCLE_POLICY= "jcr:lifecyclePolicy";
+	public static String JCR_CURRENT_LIFECYCLE_STATE= "jcr:currentLifecycleState";
+	public static String JCR_LOCK_OWNER= "jcr:lockOwner";
+	public static String JCR_LOCK_IS_DEEP= "jcr:lockIsDeep";
+	public static String JCR_UUID= "jcr:uuid";
+	public static String JCR_IS_CHECKED_OUT= "jcr:isCheckedOut";
+	public static String JCR_VERSION_HISTORY= "jcr:versionHistory";
+	public static String JCR_BASE_VERSION= "jcr:baseVersion";
+	public static String JCR_PREDECESSORS= "jcr:predecessors";
+	public static String JCR_MERGE_FAILED= "jcr:mergeFailed";
+	public static String JCR_ACTIVITY= "jcr:activity";
+	public static String JCR_CONFIGURATION= "jcr:configuration";
+	public static String JCR_ACTIVITY_TITLE= "jcr:activityTitle";
+	//public static String JCR_PRIMARY_TYPE= "jcr:primaryType";
+	public static String JCR_MIXIN_TYPES= "jcr:mixinTypes";
+	public static String JCR_NAME= "jcr:name";
+	public static String JCR_AUTO_CREATED= "jcr:autoCreated";
+	public static String JCR_MANDATORY= "jcr:mandatory";
+	public static String JCR_ON_PARENT_VERSION= "jcr:onParentVersion";
+	public static String JCR_PROTECTED= "jcr:protected";	
+	public static String JCR_REQUIRED_PRIMARY_TYPES= "jcr:requiredPrimaryTypes";
+	public static String JCR_DEFAULT_PRIMARY_TYPE= "jcr:defaultPrimaryType";
+	public static String JCR_SAME_NAME_SIBLINGS= "jcr:sameNameSiblings";
+	//root
+	public static String JCR_FROZEN_PRIMARY_TYPE= "jcr:frozenPrimaryType";
+	public static String JCR_FROZEN_MIXIN_TYPES= "jcr:frozenMixinTypes";
+	public static String JCR_FROZEN_UUID= "jcr:frozenUuid";
+	public static String JCR_NODE_TYPE_NAME= "jcr:nodeTypeName";
+	public static String JCR_SUPER_TYPES= "jcr:supertypes";
+	public static String JCR_IS_ABSTRACT= "jcr:isAbstract";
+	public static String JCR_IS_QUERYABLE= "jcr:isQueryable";
+	public static String JCR_IS_MIXIN= "jcr:isMixin";
+	public static String JCR_HAS_ORDERABLE_CHILD_NODES= "jcr:hasOrderableChildNodes";
+	public static String JCR_PRIMARY_ITEM_NAME= "jcr:primaryItemName";
+	public static String JCR_PROPERTY_DEFINITION= "jcr:propertyDefinition";
+	public static String JCR_CHILD_NODE_DEFINITION= "jcr:childNodeDefinition";
+	public static String JCR_REQUIRED_TYPE= "jcr:requiredType";
+	public static String JCR_VALUE_CONSTRAINTS= "jcr:valueConstraints";
+	public static String JCR_DEFAULT_VALUES= "jcr:defaultValues";
+	public static String JCR_MULTIPLE= "jcr:multiple";
+	public static String JCR_AVAILABLE_QUERY_OPERATORS= "jcr:availableQueryOperators";
+	public static String JCR_IS_FULL_TEXT_SEARCHABLE= "jcr:isFullTextSearchable";
+	public static String JCR_IS_QUERY_ORDERABLE= "jcr:isQueryOrderable";
+	public static String JCR_SUCCESSORS= "jcr:successors";
+	public static String JCR_FROZENNODE= "jcr:frozenNode";
+	public static String JCR_VERSIONABLE_UUID= "jcr:versionableUuid";
+	public static String JCR_COPIED_FROM= "jcr:copiedFrom";
+	public static String JCR_ROOT_VERSION= "jcr:rootVersion";
+	public static String JCR_VERSION_LABELS= "jcr:versionLabels";
+	public static String JCR_CHILD_VERSION_HISTORY= "jcr:childVersionHistory";
+ 	
 	//TODO change with properties
 	public void setRepositoryInfo(RepositoryInfo repositoryInfo);
 
 	public void addNode(FileInfo fileInfo);
 	
+	public void updateContentNode(FileInfo fileInfo,Map<String,String> properties);
+	
 	public void deleteNode(FileInfo fileInfo);
  
 	public String listChildrenNode(String path,ResponseType responseType);

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java?rev=1406137&r1=1406136&r2=1406137&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java
Tue Nov  6 13:45:36 2012
@@ -17,7 +17,7 @@
 package org.apache.sling.slingclipse.http.impl;
 
 import java.io.File;
-
+import java.util.Map;
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
@@ -30,6 +30,7 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.multipart.StringPart;
 import org.apache.sling.slingclipse.api.FileInfo;
 import org.apache.sling.slingclipse.api.ResponseType;
+ 
 
 public class RepositoryImpl extends AbstractRepository{
 	
@@ -133,4 +134,27 @@ public class RepositoryImpl extends Abst
 			get.releaseConnection();
 		}
 	}
+	
+	@Override
+	public void updateContentNode(FileInfo fileInfo,Map<String, String> properties) {
+		PostMethod post = new PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation());
+		try{
+			Part[] parts = new Part[properties.size()];
+			int counter=0;
+			for (Map.Entry <String,String> proerty:properties.entrySet()) {
+				parts[counter]=new StringPart(proerty.getKey(), proerty.getValue());
+				counter++;
+			}
+			post.setRequestEntity(new MultipartRequestEntity(parts,post.getParams()));
+			httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword()));
+			httpClient.getParams().setAuthenticationPreemptive(true);
+			int responseStatus=httpClient.executeMethod(post);
+			//TODO handle the response status	
+		} catch(Exception e){
+			//TODO handle the error
+		}finally{
+			post.releaseConnection();
+		}
+	}
+ 
 }

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java?rev=1406137&r1=1406136&r2=1406137&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipseListener.java
Tue Nov  6 13:45:36 2012
@@ -16,12 +16,21 @@
  */
 package org.apache.sling.slingclipse;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.sling.slingclipse.api.ProtectedNodes;
 import org.apache.sling.slingclipse.api.Repository;
 import org.apache.sling.slingclipse.api.FileInfo;
 import org.apache.sling.slingclipse.api.RepositoryInfo;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
-import org.eclipse.core.internal.resources.Resource;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceChangeEvent;
 import org.eclipse.core.resources.IResourceChangeListener;
@@ -31,6 +40,9 @@ import org.eclipse.core.runtime.CoreExce
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.json.JSONException;
+import org.json.JSONML;
+import org.json.JSONObject;
 
 /**
  * @author asanso
@@ -56,12 +68,12 @@ public class SlingclipseListener impleme
 				
 				try {
 					return visitInternal(delta);
-				} catch ( RuntimeException e) {
+				} catch ( Exception e) {
 					throw new CoreException(new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Failed
visiting resource based on delta " + delta, e));
 				}
 			}
 
-			private boolean visitInternal(IResourceDelta delta) {
+			private boolean visitInternal(IResourceDelta delta) throws IOException, JSONException
{
 				IPreferenceStore store = SlingclipsePlugin.getDefault().getPreferenceStore();
 				
 				// since the listener is disabled, instruct it not to recurse for changes
@@ -115,11 +127,42 @@ public class SlingclipseListener impleme
 		return result;
 	}
 	
-	private void addNode(Repository repository,FileInfo fileInfo){
-		if (SlingclipseHelper.CONTENT_XML.equals(fileInfo.getName())){
+	private void addNode(Repository repository,FileInfo fileInfo) throws IOException, JSONException{
+		if (SlingclipseHelper.CONTENT_XML.equals(fileInfo.getName())){ 
+			String fileContent = readFile(fileInfo.getLocation());
+			Map <String ,String>properties= getModifiedProperties(fileContent);
+			repository.updateContentNode(fileInfo, properties);
+			 
 			//DO NOTHING FOR NOW
 		}else{	
 			repository.addNode(fileInfo);
 		}
 	}
+	
+	private static String readFile(String path) throws IOException {
+		FileInputStream stream = new FileInputStream(new File(path));
+		try {
+			FileChannel fc = stream.getChannel();
+			MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+			/* Instead of using default, pass in a decoder. */
+			return Charset.defaultCharset().decode(bb).toString();
+		}
+		finally {
+			stream.close();
+		}
+	}
+	
+	private Map <String ,String>getModifiedProperties(String fileContent) throws JSONException{
+		Map<String ,String> properties= new HashMap<String ,String>();
+		JSONObject json=JSONML.toJSONObject(fileContent);
+		System.out.println(json);
+		json.remove(SlingclipseHelper.TAG_NAME);
+		for (Iterator<String> keys = json.keys(); keys.hasNext();) {
+			String key=keys.next(); 				 
+			if (!ProtectedNodes.exists(key) && !key.contains("xmlns")){
+				properties.put(key, json.optString(key));			
+			}
+		}
+		return properties;
+	}
 }

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/SlingclipseHelper.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/SlingclipseHelper.java?rev=1406137&r1=1406136&r2=1406137&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/SlingclipseHelper.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/SlingclipseHelper.java
Tue Nov  6 13:45:36 2012
@@ -18,6 +18,7 @@ package org.apache.sling.slingclipse.hel
 
 public class SlingclipseHelper {
 	
+	public static final String TAG_NAME= "tagName";
 	public static final String JCR_ROOT= "jcr_root";
 	public static final String CONTENT_XML= ".content.xml";
 	

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java?rev=1406137&r1=1406136&r2=1406137&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
Tue Nov  6 13:45:36 2012
@@ -164,7 +164,7 @@ public class ImportWizard extends Wizard
 			createFolder(path, destinationPath);
 			String content=repository.getNodeContent(path, ResponseType.JSON);
 			JSONObject jsonContent = new JSONObject(content);
-			jsonContent.append("tagName", Repository.JCR_ROOT);
+			jsonContent.put(SlingclipseHelper.TAG_NAME, Repository.JCR_ROOT);
 			String contentXml = JSONML.toString(jsonContent);		
 			createFile(path+"/"+SlingclipseHelper.CONTENT_XML, contentXml, destinationPath);
 		}



Mime
View raw message