Author: asanso
Date: Wed Nov  7 14:00:03 2012
New Revision: 1406638

URL: http://svn.apache.org/viewvc?rev=1406638&view=rev
Log:
SLING-2634 - Slingclipse should expose the operations it performs and their 
results. Applied patch from Robert Munteanu. Thanks!!

Added:
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Command.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryException.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Result.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/AbstractResult.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/.options
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/Tracer.java
Modified:
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java
    
sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/build.properties
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
    
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/SlingclipsePlugin.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/Command.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Command.java?rev=1406638&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Command.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Command.java
 Wed Nov  7 14:00:03 2012
@@ -0,0 +1,22 @@
+/*
+ * 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;
+
+public interface Command<T> {
+
+       Result<T> execute();
+}

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=1406638&r1=1406637&r2=1406638&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
 Wed Nov  7 14:00:03 2012
@@ -41,7 +41,6 @@ public interface Repository {
        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";
@@ -51,7 +50,6 @@ public interface Repository {
        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";
@@ -82,15 +80,15 @@ public interface Repository {
        //TODO change with properties
        public void setRepositoryInfo(RepositoryInfo repositoryInfo);
 
-       public void addNode(FileInfo fileInfo);
+       Command<Void> newAddNodeCommand(FileInfo fileInfo);
        
-       public void updateContentNode(FileInfo fileInfo,Map<String,String> 
properties);
+       Command<Void> newUpdateContentNodeCommand(FileInfo 
fileInfo,Map<String,String> properties);
        
-       public void deleteNode(FileInfo fileInfo);
+       Command<Void> newDeleteNodeCommand(FileInfo fileInfo);
  
-       public String listChildrenNode(String path,ResponseType responseType);
+       Command<String> newListChildrenNodeCommand(String path,ResponseType 
responseType);
        
-       public String getNodeContent(String path,ResponseType responseType);
+       Command<String> newGetNodeContentCommand(String path,ResponseType 
responseType);
 
-       public byte[] getNode(String path);
+       Command<byte[]> newGetNodeCommand(String path);
 }

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryException.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryException.java?rev=1406638&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryException.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryException.java
 Wed Nov  7 14:00:03 2012
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Signals an error when communicating with a Sling repository
+ */
+public class RepositoryException extends Exception {
+
+       private static final long serialVersionUID = -6613542630470583643L;
+
+       public RepositoryException() {
+
+       }
+
+       public RepositoryException(String message) {
+               super(message);
+       }
+
+       public RepositoryException(Throwable cause) {
+               super(cause);
+       }
+
+       public RepositoryException(String message, Throwable cause) {
+               super(message, cause);
+       }
+
+}

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java?rev=1406638&r1=1406637&r2=1406638&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java
 (original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/RepositoryInfo.java
 Wed Nov  7 14:00:03 2012
@@ -49,5 +49,10 @@ public class RepositoryInfo {
        public int getPort(){
                String host=url.substring(7);
                return Integer.parseInt(host.split(":")[1]);
-       }       
+       }
+
+       @Override
+       public String toString() {
+               return "RepositoryInfo [username=" + username + ", url=" + url 
+ "]";
+       }
 }

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Result.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Result.java?rev=1406638&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Result.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Result.java
 Wed Nov  7 14:00:03 2012
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+public interface Result<T> {
+       
+       boolean isSuccess();
+       
+       T get() throws RepositoryException;
+
+}

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/AbstractResult.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/AbstractResult.java?rev=1406638&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/AbstractResult.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/AbstractResult.java
 Wed Nov  7 14:00:03 2012
@@ -0,0 +1,62 @@
+/*
+ * 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.http.impl;
+
+import org.apache.sling.slingclipse.api.RepositoryException;
+import org.apache.sling.slingclipse.api.Result;
+
+public class AbstractResult<T> implements Result<T> {
+
+       public static <T> Result<T> success(T payload) {
+               
+               return new AbstractResult<T>(true, payload, null);
+       }
+
+       public static <T> Result<T> failure(RepositoryException e) {
+               
+               return new AbstractResult<T>(false, null, e);
+       }
+       
+       private final boolean success;
+       private final RepositoryException exception;
+       private final T payload;
+
+       private AbstractResult(boolean success, T payload, RepositoryException 
exception) {
+               this.success = success;
+               this.exception = exception;
+               this.payload = payload;
+       }
+       
+       @Override
+       public T get() throws RepositoryException {
+               
+               if ( success )
+                       return payload;
+               
+               throw exception;
+       }
+       
+       public boolean isSuccess() {
+               return success;
+       }
+       
+       @Override
+       public String toString() {
+               
+               return String.format("%4s %s", success ? "OK" : "FAIL", success 
? "" : exception.getMessage() );
+       }
+}

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=1406638&r1=1406637&r2=1406638&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
 Wed Nov  7 14:00:03 2012
@@ -28,133 +28,232 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
 import org.apache.commons.httpclient.methods.multipart.Part;
 import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.sling.slingclipse.api.Command;
 import org.apache.sling.slingclipse.api.FileInfo;
+import org.apache.sling.slingclipse.api.RepositoryException;
 import org.apache.sling.slingclipse.api.ResponseType;
- 
+import org.apache.sling.slingclipse.api.Result;
 
 public class RepositoryImpl extends AbstractRepository{
        
        private final HttpClient httpClient = new HttpClient(); 
 
-       @Override
-       public void addNode(FileInfo fileInfo) {
-               PostMethod post = new 
PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation());
-               try{
-                       File f=new File(fileInfo.getLocation());
-                       Part[] parts ={ new FilePart(fileInfo.getName(), f)};
-                       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();
-               }
+       /* (non-Javadoc)
+        * @see 
org.apache.sling.slingclipse.api.Repository#newAddNodeCommand(org.apache.sling.slingclipse.api.FileInfo)
+        */
+       @Override
+       public Command<Void> newAddNodeCommand(final FileInfo fileInfo) {
+               return new Command<Void>() {
+                       @Override
+                       public Result<Void> execute() {
+                               PostMethod post = new 
PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation());
+                               try{
+                                       File f=new File(fileInfo.getLocation());
+                                       Part[] parts ={ new 
FilePart(fileInfo.getName(), f)};
+                                       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);
+                                       
+                                       return 
resultForResponseStatus(responseStatus);
+                                               
+                               } catch(Exception e){
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       post.releaseConnection();
+                               }
+                       }
+
+                       @Override
+                       public String toString() {
+                               
+                               return String.format("%8s %s", "ADD", 
fileInfo.getRelativeLocation() + "/" + fileInfo.getName());
+                       }
+               };
        }
 
-       @Override
-       public void deleteNode(FileInfo fileInfo) {
-               PostMethod post = new 
PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation()+"/"+fileInfo.getName());
-               try{
-                       Part[] parts ={new StringPart(":operation", "delete")};
-                       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();
-               }
+       private Result<Void> resultForResponseStatus(int responseStatus) {
+               if ( isSuccessStatus(responseStatus) )
+                       return AbstractResult.success(null);
                
+               return failureResultForStatusCode(responseStatus);
+       }
+
+       private <T> Result<T> failureResultForStatusCode(int responseStatus) {
+               return AbstractResult.failure(new 
RepositoryException("Repository has returned status code " + responseStatus));
+       }
+
+       private boolean isSuccessStatus(int responseStatus) {
+               
+               // TODO - consider all 2xx and possibly 3xx as success?
+               
+               return responseStatus == 200 /* OK */ || responseStatus == 201 
/* CREATED */;
+       }
+
+       @Override
+       public Command<Void> newDeleteNodeCommand(final FileInfo fileInfo) {
+               return new Command<Void>() {
+                       @Override
+                       public Result<Void> execute() {
+                               PostMethod post = new 
PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation()+"/"+fileInfo.getName());
+                               try{
+                                       Part[] parts ={new 
StringPart(":operation", "delete")};
+                                       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);
+                                       
+                                       return 
resultForResponseStatus(responseStatus);
+                               } catch(Exception e){
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       post.releaseConnection();
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               return String.format("%8s %s", "DELETE", 
fileInfo.getRelativeLocation() + "/" + fileInfo.getName());
+                       }
+               };
        }
        
        @Override
-       public String listChildrenNode(String path,ResponseType responseType) {
-               //TODO handle the response type
-               GetMethod get= new 
GetMethod(repositoryInfo.getUrl()+path+".1.json");
-               try{
-                       
httpClient.getParams().setAuthenticationPreemptive(true);
-                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
-                   //TODO
-                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds);
-                       int responseStatus=httpClient.executeMethod(get);
-                       //TODO change responseAsString with something like
-                       //return EncodingUtil.getString(rawdata, 
m.getResponseCharSet());
-                       return get.getResponseBodyAsString();
-                       //TODO handle the response status
-               } catch (Exception e) {
-                       return null;
-                       //TODO handle the error
-               }finally{
-                       get.releaseConnection();
-               }
+       public Command<String> newListChildrenNodeCommand(final String 
path,final ResponseType responseType) {
+               return new Command<String>() {
+                       @Override
+                       public Result<String> execute() {
+                               //TODO handle the response type
+                               GetMethod get= new 
GetMethod(repositoryInfo.getUrl()+path+".1.json");
+                               try{
+                                       
httpClient.getParams().setAuthenticationPreemptive(true);
+                                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
+                                   //TODO
+                                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds);
+                                       int 
responseStatus=httpClient.executeMethod(get);
+
+                                       //TODO change responseAsString with 
something like
+                                       //return 
EncodingUtil.getString(rawdata, m.getResponseCharSet());
+                                       if ( isSuccessStatus(responseStatus) )
+                                               return 
AbstractResult.success(get.getResponseBodyAsString());
+                                       
+                                       return 
failureResultForStatusCode(responseStatus);
+                               } catch (Exception e) {
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       get.releaseConnection();
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               
+                               return String.format("%8s %s (%s)", "LISTCH", 
path, responseType);
+                       }
+               };
        }
 
        @Override
-       public byte[] getNode(String path) {
-               GetMethod get= new GetMethod(repositoryInfo.getUrl()+path);
-               try{
-                       
httpClient.getParams().setAuthenticationPreemptive(true);
-                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
-                   //TODO
-                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds);
-                       int responseStatus=httpClient.executeMethod(get);
-                       return get.getResponseBody(); 
-                       //TODO handle the response status
-               } catch (Exception e) {
-                       return null;
-                       //TODO handle the error
-               }finally{
-                       get.releaseConnection();
-               }
+       public Command<byte[]> newGetNodeCommand(final String path) {
+               
+               return new Command<byte[]>() {
+                       @Override
+                       public Result<byte[]> execute() {
+                               
+                               GetMethod get= new 
GetMethod(repositoryInfo.getUrl()+path);
+                               
+                               try{
+                                       
httpClient.getParams().setAuthenticationPreemptive(true);
+                                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
+                                   //TODO
+                                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds);
+                                       int 
responseStatus=httpClient.executeMethod(get);
+                                       
+                                       if ( isSuccessStatus(responseStatus) )
+                                               return 
AbstractResult.success(get.getResponseBody());
+                                       
+                                       return 
failureResultForStatusCode(responseStatus);
+                               } catch (Exception e) {
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       get.releaseConnection();
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               
+                               return String.format("%8s %s", "GETNODE", path);
+                       }
+               };
        }
        
-       
        @Override
-       public String getNodeContent(String path,ResponseType responseType) {
-               //TODO handle the response type
-               GetMethod get= new 
GetMethod(repositoryInfo.getUrl()+path+".json");
-               try{
-                       
httpClient.getParams().setAuthenticationPreemptive(true);
-                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
-                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds); 
-                       int responseStatus=httpClient.executeMethod(get);
-                       //TODO change responseAsString with something like
-                       // return EncodingUtil.getString(rawdata, 
m.getResponseCharSet());
-                       return get.getResponseBodyAsString(); 
-                       //TODO handle the response status
-               } catch (Exception e) {
-                       return null;
-                       //TODO handle the error
-               }finally{
-                       get.releaseConnection();
-               }
+       public Command<String> newGetNodeContentCommand(final String path, 
final ResponseType responseType) {
+               return new Command<String>() {
+                       @Override
+                       public Result<String> execute() {
+                               //TODO handle the response type
+                               GetMethod get= new 
GetMethod(repositoryInfo.getUrl()+path+".json");
+                               try{
+                                       
httpClient.getParams().setAuthenticationPreemptive(true);
+                                   Credentials defaultcreds = new 
UsernamePasswordCredentials(repositoryInfo.getUsername(), 
repositoryInfo.getPassword());
+                                   httpClient.getState().setCredentials(new 
AuthScope(repositoryInfo.getHost(),repositoryInfo.getPort(), 
AuthScope.ANY_REALM), defaultcreds); 
+                                       int 
responseStatus=httpClient.executeMethod(get);
+                                       //TODO change responseAsString with 
something like
+                                       // return 
EncodingUtil.getString(rawdata, m.getResponseCharSet());
+                                       if ( isSuccessStatus(responseStatus) )
+                                               return 
AbstractResult.success(get.getResponseBodyAsString()); 
+                                       
+                                       return 
failureResultForStatusCode(responseStatus);
+                               } catch (Exception e) {
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       get.releaseConnection();
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               
+                               return String.format("%8s %s (%s)", "GETCONT", 
path, responseType);
+                       }
+               };
        }
        
        @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();
-               }
+       public Command<Void> newUpdateContentNodeCommand(final FileInfo 
fileInfo, final Map<String, String> properties) {
+               
+               return new Command<Void>() {
+                       @Override
+                       public Result<Void> execute() {
+                               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);
+                                       
+                                       return 
resultForResponseStatus(responseStatus);
+                               } catch(Exception e){
+                                       return AbstractResult.failure(new 
RepositoryException(e));
+                               }finally{
+                                       post.releaseConnection();
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               
+                               return String.format("%8s %s", "UPDATE", 
fileInfo.getRelativeLocation() + "/" + fileInfo.getName());
+                       }
+               };
        }
  
 }

Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/.options
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/.options?rev=1406638&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/.options (added)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/.options Wed Nov 
 7 14:00:03 2012
@@ -0,0 +1 @@
+org.apache.sling.slingclipse/debug=false
\ No newline at end of file

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/build.properties
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/build.properties?rev=1406638&r1=1406637&r2=1406638&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/build.properties 
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/build.properties 
Wed Nov  7 14:00:03 2012
@@ -2,7 +2,8 @@ output.. = bin/
 bin.includes = plugin.xml,\
                META-INF/,\
                .,\
-               OSGI-INF/
+               OSGI-INF/,\
+               .options
 jars.compile.order = .,\
                      commons-httpclient.jar
 source.. = src/

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml?rev=1406638&r1=1406637&r2=1406638&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml 
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml Wed 
Nov  7 14:00:03 2012
@@ -41,5 +41,4 @@
          </description>
       </wizard>
    </extension>
-
 </plugin>

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=1406638&r1=1406637&r2=1406638&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
 Wed Nov  7 14:00:03 2012
@@ -25,10 +25,13 @@ import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+
+import org.apache.sling.slingclipse.api.Command;
 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.api.Result;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
 import org.eclipse.core.resources.IResource;
@@ -114,7 +117,7 @@ public class SlingclipseListener impleme
                                        
repository.setRepositoryInfo(repositoryInfo);
                                        
                                        if (delta.getKind() == 
IResourceDelta.REMOVED) {
-                                               repository.deleteNode(fileInfo);
+                                               
executeCommand(repository.newDeleteNodeCommand(fileInfo));
                                        } else {
                                                addNode(repository,fileInfo);
                                        }
@@ -128,15 +131,28 @@ public class SlingclipseListener impleme
        }
        
        private void addNode(Repository repository,FileInfo fileInfo) throws 
IOException, JSONException{
+               
+               Command<Void> command;
+               
                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);
+                       command = 
repository.newUpdateContentNodeCommand(fileInfo, properties);
+               }else{
+                       
+                       command = repository.newAddNodeCommand(fileInfo);
                }
+               
+               executeCommand(command);
+       }
+
+       private <T> Result<T> executeCommand(Command<T> command) {
+               
+               Result<T> result = command.execute();
+               
+               SlingclipsePlugin.getDefault().getTracer().trace("{0} : {1}.", 
command, result);
+               
+               return result;
        }
        
        private static String readFile(String path) throws IOException {
@@ -155,7 +171,6 @@ public class SlingclipseListener impleme
        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();                                 
 

Modified: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java?rev=1406638&r1=1406637&r2=1406638&view=diff
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
 (original)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/SlingclipsePlugin.java
 Wed Nov  7 14:00:03 2012
@@ -17,6 +17,7 @@
 package org.apache.sling.slingclipse;
 
 import org.apache.sling.slingclipse.api.Repository;
+import org.apache.sling.slingclipse.helper.Tracer;
 import org.eclipse.core.resources.IResourceChangeListener;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -38,6 +39,8 @@ public class SlingclipsePlugin extends A
 
        //TODO is fine to be static?
        private static Repository repository;
+       
+       private Tracer tracer;
 
        /**
         * The constructor
@@ -54,6 +57,8 @@ public class SlingclipsePlugin extends A
                super.start(context);
                plugin = this;
                
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
+               tracer = new Tracer();
+               tracer.register(getBundle().getBundleContext());
        }
 
        /*
@@ -64,6 +69,7 @@ public class SlingclipsePlugin extends A
                plugin = null;
                super.stop(context);
                
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
+               tracer.unregister();
        }
 
        /**
@@ -98,4 +104,8 @@ public class SlingclipsePlugin extends A
        public Repository getRepository() {
                return this.repository;
        }
+
+       public Tracer getTracer() {
+               return tracer;
+       }
 }

Added: 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/Tracer.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/Tracer.java?rev=1406638&view=auto
==============================================================================
--- 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/Tracer.java
 (added)
+++ 
sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/helper/Tracer.java
 Wed Nov  7 14:00:03 2012
@@ -0,0 +1,66 @@
+ /*
+ * 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.helper;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.slingclipse.SlingclipsePlugin;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.osgi.service.debug.DebugOptionsListener;
+import org.eclipse.osgi.service.debug.DebugTrace;
+import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Tracer implements DebugOptionsListener {
+
+    private boolean debugEnabled;
+    private DebugTrace trace;
+       private ServiceRegistration<?> serviceRegistration;
+    
+    public void register(BundleContext bundleContext) {
+        
+        Dictionary<String, String> properties = new Hashtable<String, 
String>(1);
+        properties.put(DebugOptions.LISTENER_SYMBOLICNAME, 
SlingclipsePlugin.PLUGIN_ID);
+        
+        serviceRegistration = 
bundleContext.registerService(DebugOptionsListener.class.getName(), this, 
properties );
+    }
+    
+    public void unregister() {
+       
+       if ( serviceRegistration != null )
+               serviceRegistration.unregister();
+    }
+    
+    @Override
+    public void optionsChanged(DebugOptions options) {
+       
+       debugEnabled = options.getBooleanOption(SlingclipsePlugin.PLUGIN_ID + 
"/debug", false);
+       trace = options.newDebugTrace(SlingclipsePlugin.PLUGIN_ID, getClass());
+    }
+    
+    public void trace(String message, Object... arguments) {
+       if ( !debugEnabled )
+               return;
+       
+       if ( arguments.length > 0 )
+               message = NLS.bind(message, arguments);
+       
+       trace.trace("/debug", message);
+    }
+}

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=1406638&r1=1406637&r2=1406638&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
 Wed Nov  7 14:00:03 2012
@@ -24,6 +24,7 @@ import java.util.Iterator;
 
 import org.apache.sling.slingclipse.SlingclipsePlugin;
 import org.apache.sling.slingclipse.api.Repository;
+import org.apache.sling.slingclipse.api.RepositoryException;
 import org.apache.sling.slingclipse.api.RepositoryInfo;
 import org.apache.sling.slingclipse.api.ResponseType;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
@@ -149,8 +150,8 @@ public class ImportWizard extends Wizard
        }
        
        // TODO: This probably should be pushed into the service layer
-       private void crawlChildrenAndImport(Repository repository,String 
path,String destinationPath) throws JSONException, IOException{
-               String 
children=repository.listChildrenNode(path,ResponseType.JSON); 
+       private void crawlChildrenAndImport(Repository repository,String 
path,String destinationPath) throws JSONException, IOException, 
RepositoryException{
+               String 
children=repository.newListChildrenNodeCommand(path,ResponseType.JSON).execute().get();
 
                JSONObject json = new JSONObject(children);
                String primaryType= json.optString(Repository.JCR_PRIMARY_TYPE);
  
@@ -162,7 +163,7 @@ public class ImportWizard extends Wizard
                        //DO NOTHING
                }else{          
                        createFolder(path, destinationPath);
-                       String content=repository.getNodeContent(path, 
ResponseType.JSON);
+                       String 
content=repository.newGetNodeContentCommand(path, 
ResponseType.JSON).execute().get();
                        JSONObject jsonContent = new JSONObject(content);
                        jsonContent.put(SlingclipseHelper.TAG_NAME, 
Repository.JCR_ROOT);
                        String contentXml = JSONML.toString(jsonContent);       
        
@@ -178,8 +179,8 @@ public class ImportWizard extends Wizard
                }
        }       
        
-       private void importFile(Repository repository,String path,String 
destinationPath) throws JSONException, IOException{ 
-                       byte [] node= repository.getNode(path);
+       private void importFile(Repository repository,String path,String 
destinationPath) throws JSONException, IOException, RepositoryException{ 
+                       byte [] node= 
repository.newGetNodeCommand(path).execute().get();
                        createFile(path, node,destinationPath);
        }
        


Reply via email to