From 14853e776bb354cfb72f9d8c65c8a7a745b14217 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 20 May 2009 21:30:11 +0000 Subject: TUSCANY-3025 - Missed files from Store-android patch from Sanni Lookman git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776866 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/services/atom/xml/AtomXML.java | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java (limited to 'branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java') diff --git a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java b/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java new file mode 100644 index 0000000000..d5bb7f151e --- /dev/null +++ b/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java @@ -0,0 +1,148 @@ +/* + * 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 services.atom.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.http.Header; +import org.apache.http.HeaderElement; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.ParseException; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.DefaultHttpClient; + +import services.Item; +import android.util.Log; + +/** + * + */ +public class AtomXML { + + public static boolean postItem(String ServiceURI, final Item item) + { + DefaultHttpClient client=new DefaultHttpClient(); + HttpPost httpost = new HttpPost(ServiceURI); + + httpost.setEntity(new HttpEntity(){ + + String entry="" + + "item" + + "" + + "" + + "" + item.getName()+ "" + + "" +item.getPrice()+"" + + ""; + + class mHeader implements Header + { + public HeaderElement[] getElements() throws ParseException { + // TODO Auto-generated method stub + return null; + } + + public String getName() { + // TODO Auto-generated method stub + return "Content-type"; + } + + public String getValue() { + // TODO Auto-generated method stub + return "application/atom+xml;type=entry"; + } + } + + public void consumeContent() throws IOException { + // TODO Auto-generated method stub + + } + + public InputStream getContent() throws IOException, + IllegalStateException { + // TODO Auto-generated method stub + return new InputStream(){ + + public int read() throws IOException { + // TODO Auto-generated method stub + return this.available(); + } + + }; + } + + public Header getContentEncoding() { + // TODO Auto-generated method stub + return new mHeader(); + } + + public long getContentLength() { + // TODO Auto-generated method stub + return entry.length(); + } + + public Header getContentType() { + // TODO Auto-generated method stub + return new mHeader(); + } + + public boolean isChunked() { + // TODO Auto-generated method stub + return false; + } + + public boolean isRepeatable() { + // TODO Auto-generated method stub + return true; + } + + public boolean isStreaming() { + // TODO Auto-generated method stub + return false; + } + + public void writeTo(OutputStream arg0) throws IOException { + // TODO Auto-generated method stub + + arg0.write(entry.getBytes()); + arg0.flush(); + Log.i("Tuscany", "Entry: "+item+" posted via atom/xml"); + } + + }); + + try { + HttpResponse response = client.execute(httpost); + Log.i("Tuscany", "Atom entry post status: "+response.getStatusLine().toString()); + return true; + } catch (ClientProtocolException e) { + // TODO Auto-generated catch block + Log.e("Tuscany",e.getMessage()); + } catch (IOException e) { + // TODO Auto-generated catch block + Log.e("Tuscany",e.getMessage()); + } + + return false; + } + +} -- cgit v1.2.3