mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	OC-2678: Parse XML Response from Create New Share
This commit is contained in:
		
							parent
							
								
									974e55a2b9
								
							
						
					
					
						commit
						f3453f138f
					
				| @ -55,6 +55,7 @@ public class OCShare implements Parcelable{ | ||||
|     private boolean mIsDirectory; | ||||
|     private long mUserId; | ||||
|     private long mIdRemoteShared; | ||||
|     private String mShareLink; | ||||
|      | ||||
|     public OCShare() { | ||||
|     	super(); | ||||
| @ -87,7 +88,8 @@ public class OCShare implements Parcelable{ | ||||
|         mSharedWithDisplayName = null; | ||||
|         mIsDirectory = false; | ||||
|         mUserId = -1; | ||||
|         mIdRemoteShared = -1;         | ||||
|         mIdRemoteShared = -1; | ||||
|         mShareLink = null; | ||||
|     }	 | ||||
|      | ||||
|     /// Getters and Setters | ||||
| @ -203,7 +205,15 @@ public class OCShare implements Parcelable{ | ||||
|     public void setIdRemoteShared(long idRemoteShared) { | ||||
|         this.mIdRemoteShared = idRemoteShared; | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public String getShareLink() { | ||||
|     	return this.mShareLink; | ||||
|     } | ||||
|      | ||||
|     public void setShareLink(String shareLink) { | ||||
|     	this.mShareLink = shareLink; | ||||
|     } | ||||
|      | ||||
|     /**  | ||||
|      * Parcelable Methods | ||||
|      */ | ||||
| @ -248,6 +258,7 @@ public class OCShare implements Parcelable{ | ||||
|         mIsDirectory = source.readInt() == 0; | ||||
|         mUserId = source.readLong(); | ||||
|         mIdRemoteShared = source.readLong(); | ||||
|         mShareLink = source.readString(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| @ -273,6 +284,7 @@ public class OCShare implements Parcelable{ | ||||
|         dest.writeInt(mIsDirectory ? 1 : 0); | ||||
|         dest.writeLong(mUserId); | ||||
|         dest.writeLong(mIdRemoteShared); | ||||
|         dest.writeString(mShareLink); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -26,6 +26,7 @@ package com.owncloud.android.lib.operations.remote; | ||||
| 
 | ||||
| import java.io.ByteArrayInputStream; | ||||
| import java.io.InputStream; | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.methods.PostMethod; | ||||
| import org.apache.http.HttpStatus; | ||||
| @ -58,7 +59,8 @@ public class CreateShareRemoteOperation extends RemoteOperation { | ||||
| 	private static final String PARAM_PASSWORD = "password"; | ||||
| 	private static final String PARAM_PERMISSIONS = "permissions"; | ||||
| 
 | ||||
| 	private OCShare mShare; | ||||
| 	private ArrayList<OCShare> mShares;  // List of shares for result, one share in this case | ||||
| 	 | ||||
| 	private String mPath; | ||||
| 	private ShareType mShareType; | ||||
| 	private String mShareWith; | ||||
| @ -125,6 +127,16 @@ public class CreateShareRemoteOperation extends RemoteOperation { | ||||
| 				// convert String into InputStream | ||||
| 				InputStream is = new ByteArrayInputStream(response.getBytes()); | ||||
| 				ShareXMLParser xmlParser = new ShareXMLParser(); | ||||
| 				mShares = xmlParser.parseXMLResponse(is); | ||||
| 				if (mShares != null) { | ||||
| 					Log.d(TAG, "Shares: " + mShares.size()); | ||||
| 					result = new RemoteOperationResult(ResultCode.OK); | ||||
| 					ArrayList<Object> sharesObjects = new ArrayList<Object>(); | ||||
| 					for (OCShare share: mShares) { | ||||
| 						sharesObjects.add(share); | ||||
| 					} | ||||
| 					result.setData(sharesObjects); | ||||
| 				} | ||||
| 
 | ||||
| 			} | ||||
| 		} catch (Exception e) { | ||||
| @ -133,9 +145,6 @@ public class CreateShareRemoteOperation extends RemoteOperation { | ||||
| 		} finally { | ||||
| 			post.releaseConnection(); | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 		return result; | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -76,9 +76,12 @@ public class ShareXMLParser { | ||||
| 	private static final String NODE_STORAGE = "storage"; | ||||
| 	private static final String NODE_MAIL_SEND = "mail_send"; | ||||
| 	private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_display_name"; | ||||
| 	 | ||||
| 	private static final String NODE_URL = "url"; | ||||
| 
 | ||||
| 	private static final String TYPE_FOLDER = "folder"; | ||||
| 
 | ||||
| 
 | ||||
| 	private String mStatus; | ||||
| 	private int mStatusCode; | ||||
| 
 | ||||
| @ -206,8 +209,12 @@ public class ShareXMLParser { | ||||
| 			String name = parser.getName(); | ||||
| 			if (name.equalsIgnoreCase(NODE_ELEMENT)) { | ||||
| 				shares.add(readElement(parser)); | ||||
| 			} else { | ||||
| 				skip(parser); | ||||
| 			}  else { | ||||
| 				//skip(parser); | ||||
| 				OCShare share = tryReadCreateXMLResponse(parser); | ||||
| 				if (share.getIdRemoteShared() > -1) { | ||||
| 					shares.add(share); | ||||
| 				} | ||||
| 			}  | ||||
| 		} | ||||
| 
 | ||||
| @ -215,6 +222,38 @@ public class ShareXMLParser { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	/**  | ||||
| 	 * Parse Create XML Response | ||||
| 	 * @param parser | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	private OCShare tryReadCreateXMLResponse(XmlPullParser parser) throws XmlPullParserException, IOException { | ||||
| 		OCShare share = new OCShare(); | ||||
| 	 | ||||
| 		Log.d(TAG, "---- Create Share Response ---"); | ||||
| 		while (parser.next() != XmlPullParser.END_TAG) { | ||||
| 			if (parser.getEventType() != XmlPullParser.START_TAG) { | ||||
| 	            continue; | ||||
| 	        } | ||||
| 			 | ||||
| 			String name = parser.getName(); | ||||
| 
 | ||||
| 			if (name.equalsIgnoreCase(NODE_ID)) { | ||||
| 				share.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID))); | ||||
| 			 | ||||
| 			} else if (name.equalsIgnoreCase(NODE_URL)) { | ||||
| 				share.setShareLink(readNode(parser, NODE_URL)); | ||||
| 
 | ||||
| 			}  else if (name.equalsIgnoreCase(NODE_TOKEN)) { | ||||
| 				share.setToken(readNode(parser, NODE_TOKEN)); | ||||
| 			} else { | ||||
| 				skip(parser); | ||||
| 			}  | ||||
| 		} | ||||
| 		 | ||||
| 		return share; | ||||
| 	} | ||||
| 
 | ||||
| 	/**  | ||||
| 	 * Parse Element node | ||||
| 	 * @param parser | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user