incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1405037 - in /sling/whiteboard/asanso/plugins/eclipse: slingclipse-api/src/org/apache/sling/slingclipse/api/ slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/
Date Fri, 02 Nov 2012 16:32:52 GMT
Author: asanso
Date: Fri Nov  2 16:32:51 2012
New Revision: 1405037

URL: http://svn.apache.org/viewvc?rev=1405037&view=rev
Log:
SLING-2636 - [Tooling] Add ability to Import from Sling Repository. Adding some import content
logic

Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-api/src/org/apache/sling/slingclipse/api/Repository.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java

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=1405037&r1=1405036&r2=1405037&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
Fri Nov  2 16:32:51 2012
@@ -20,6 +20,10 @@ public interface Repository {
 	
 	public static String JCR_PRIMARY_TYPE= "jcr:primaryType";
 	public static String NT_FILE= "nt:file";
+	public static String NT_FOLDER= "nt:folder";
+	public static String JCR_ROOT= "jcr:root";
+	public static String NT_RESOURCE= "nt:resource";
+	
 	
 	//TODO change with properties
 	public void setRepositoryInfo(RepositoryInfo repositoryInfo);

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=1405037&r1=1405036&r2=1405037&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
Fri Nov  2 16:32:51 2012
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Iterator;
 
 import org.apache.sling.slingclipse.SlingclipsePlugin;
 import org.apache.sling.slingclipse.api.Repository;
@@ -38,6 +39,7 @@ import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.IImportWizard;
 import org.eclipse.ui.IWorkbench;
 import org.json.JSONException;
+import org.json.JSONML;
 import org.json.JSONObject;
 
 /**
@@ -131,31 +133,67 @@ public class ImportWizard extends Wizard
 				mainPage.getPassword(),
 				mainPage.getRepositoryUrl());
 		repository.setRepositoryInfo(repositoryInfo);
-		
+ 
+		String destinationPath= mainPage.getIntoFolderPath();
+				
 		String repositoryPath=mainPage.getRepositoryPath();
-		
-		if (SlingclipseHelper.isFolderPath(repositoryPath)){
-			//handle the folder
-			String children=repository.listChildrenNode(repositoryPath,ResponseType.JSON);
-			//TODO add XML support			
+ 		crawlChildrenAndImport(repository, repositoryPath,destinationPath);
+	}
+	
+	private void crawlChildrenAndImport(Repository repository,String path,String destinationPath)
throws JSONException, IOException{
+		String children=repository.listChildrenNode(path,ResponseType.JSON); 
+		JSONObject json = new JSONObject(children);
+		String primaryType= json.optString(Repository.JCR_PRIMARY_TYPE);
+ 
+		if (Repository.NT_FILE.equals(primaryType)){
+			importFile(repository, path,destinationPath);
+		}else if (Repository.NT_FOLDER.equals(primaryType)){
+			//TODO create folder
+		}else if(Repository.NT_RESOURCE.equals(primaryType)){
+			//DO NOTHING
 		}else{
-			//handle the file
-			String  nodeContent= repository.getNodeContent(repositoryPath, ResponseType.JSON);
-
-			JSONObject json = new JSONObject(nodeContent);
-			String primaryType= json.optString(Repository.JCR_PRIMARY_TYPE);
-			if (Repository.NT_FILE.equals(primaryType)){
-				byte [] node= repository.getNode(repositoryPath);
-				//TODO create file
-			}else{
-				//TODO
-				//handle the case that is not ntfile
-			} 			
+			//TODO create folder plus .content.xml
+			String content=repository.getNodeContent(path, ResponseType.JSON);
+			JSONObject jsonContent = new JSONObject(content);
+			jsonContent.append("tagName", Repository.JCR_ROOT);
+			String contentXml = JSONML.toString(jsonContent);		
 		}
  		
+		for (Iterator<String> keys = json.keys(); keys.hasNext();) {
+			String key = keys.next();
+			JSONObject innerjson=json.optJSONObject(key);
+			if (innerjson!=null){
+				crawlChildrenAndImport(repository, path+"/"+key,destinationPath);
+			}
+		}
+	}	
+	
+	private void importFile(Repository repository,String path,String destinationPath) throws
JSONException, IOException{ 
+			byte [] node= repository.getNode(path);
+			createFile(path, node,destinationPath);
 	}
 	
-	private void createFile(String name, byte[] content) throws IOException{				
+	
+	private void createFile(String path, byte[] content,String destinationPath) throws IOException{
	
+		FileOutputStream fop = null;
+		try{
+			File file = new File (destinationPath+path);
+			if (!file.getParentFile().exists()){
+				file.getParentFile().mkdirs();
+			}				
+			if (!file.exists()){
+				file.createNewFile();
+			}			
+			fop = new FileOutputStream(file);
+			fop.write(content);
+			fop.flush();
+		}finally{
+			if (fop!=null){
+				fop.close();
+			}
+		}
 	}
+	
+	
 
 }

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java?rev=1405037&r1=1405036&r2=1405037&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
(original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java
Fri Nov  2 16:32:51 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.sling.slingclipse.ui.wizards;
 
+import java.util.List;
+
 import org.apache.sling.slingclipse.SlingclipsePlugin;
 import org.apache.sling.slingclipse.helper.SlingclipseHelper;
 import org.apache.sling.slingclipse.preferences.PreferencesMessages;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -132,7 +135,7 @@ public class ImportWizardPage extends Wi
 		password.setText(store.getString(PreferencesMessages.PASSWORD.getKey()));
 		password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
 		password.addModifyListener(modifyListener);
-
+ 		
 		createOptionsGroupButtons(optionsGroup);
 
 	}
@@ -226,6 +229,14 @@ public class ImportWizardPage extends Wi
 	public String getUsername() {
 		return user != null ? user.getText() : null;
 	}
+	
+	
+	public String getIntoFolderPath(){ 
+		IPath containerNameField= super.getResourcePath();  
+		String workspacePath=((IResource)selection.getFirstElement()).getWorkspace().getRoot().getLocation().toOSString();
+ 		return workspacePath+"/"+containerNameField.toOSString();
+	}
+	
 
 	public void handleEvent(Event event) {
 		super.handleEvent(event);



Mime
View raw message