diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
commit | 3c7c4a749baafcf375f4785a7668d3a25c9063e3 (patch) | |
tree | a66b8b031c5dc6c7744f44b44b6bcd371bd0b8df /branches/sca-java-1.x/samples/store-android | |
parent | eb03ff672236cddf65533f39b83ddd5e2984a2bb (diff) |
Moving 1.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/samples/store-android')
21 files changed, 0 insertions, 1312 deletions
diff --git a/branches/sca-java-1.x/samples/store-android/.classpath b/branches/sca-java-1.x/samples/store-android/.classpath deleted file mode 100644 index 79a84816b6..0000000000 --- a/branches/sca-java-1.x/samples/store-android/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> - <classpathentry kind="src" path="gen"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/branches/sca-java-1.x/samples/store-android/.project b/branches/sca-java-1.x/samples/store-android/.project deleted file mode 100644 index be88b01c5a..0000000000 --- a/branches/sca-java-1.x/samples/store-android/.project +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>sample-store-android</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>com.android.ide.eclipse.adt.ApkBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>com.android.ide.eclipse.adt.AndroidNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml b/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml deleted file mode 100644 index 4a26dd27c6..0000000000 --- a/branches/sca-java-1.x/samples/store-android/AndroidManifest.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="store.android" - android:versionCode="1" - android:versionName="1.0.0"> - <application android:icon="@drawable/icon" android:label="@string/app_name"> - <activity android:name=".catalog" - android:label="@string/app_name"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> - -<uses-permission android:name="android.permission.INTERNET"></uses-permission> - -</manifest>
\ No newline at end of file diff --git a/branches/sca-java-1.x/samples/store-android/default.properties b/branches/sca-java-1.x/samples/store-android/default.properties deleted file mode 100644 index 0a007ab5e2..0000000000 --- a/branches/sca-java-1.x/samples/store-android/default.properties +++ /dev/null @@ -1,22 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "build.properties", and override values to adapt the script to your -# project structure. - -# Project target. -target=android-3 -# apk configurations. This property allows creation of APK files with limited -# resources. For example, if your application contains many locales and -# you wish to release multiple smaller apks instead of a large one, you can -# define configuration to create apks with limited language sets. -# Format is a comma separated list of configuration names. For each -# configuration, a property will declare the resource configurations to -# include. Example: -# apk-configurations=european,northamerica -# apk-config-european=en,fr,it,de,es -# apk-config-northamerica=en,es -apk-configurations= diff --git a/branches/sca-java-1.x/samples/store-android/gen/store/android/R.java b/branches/sca-java-1.x/samples/store-android/gen/store/android/R.java deleted file mode 100644 index 2484da82dc..0000000000 --- a/branches/sca-java-1.x/samples/store-android/gen/store/android/R.java +++ /dev/null @@ -1,60 +0,0 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package store.android; - -public final class R { - public static final class attr { - } - public static final class drawable { - public static final int addc=0x7f020000; - public static final int icon=0x7f020001; - public static final int rems=0x7f020002; - } - public static final class id { - public static final int ListView01=0x7f050001; - public static final int ListView02=0x7f050007; - public static final int btnClean=0x7f050006; - public static final int tab02=0x7f050002; - public static final int txtEmpty=0x7f050004; - public static final int txtItemC=0x7f050000; - public static final int txtItemS=0x7f050008; - public static final int txtThx=0x7f050003; - public static final int txtTotal=0x7f050005; - } - public static final class layout { - public static final int cat_row=0x7f030000; - public static final int main=0x7f030001; - public static final int shop_row=0x7f030002; - } - public static final class string { - public static final int add_entry_ko=0x7f04000f; - public static final int add_entry_ok=0x7f04000e; - public static final int alert_cancel=0x7f040013; - public static final int alert_yes=0x7f040012; - public static final int app_name=0x7f040001; - public static final int app_tag=0x7f040002; - public static final int btn_add_del1=0x7f040004; - public static final int btn_add_del2=0x7f040005; - public static final int btn_clean=0x7f040003; - public static final int del_all_ok=0x7f040014; - public static final int del_entry_ko=0x7f040011; - public static final int del_entry_ok=0x7f040010; - public static final int get_tag=0x7f04000b; - public static final int hello=0x7f040000; - public static final int howto_del=0x7f040017; - public static final int start_tag=0x7f04000c; - public static final int tab_catalog=0x7f040007; - public static final int tab_shop=0x7f040008; - public static final int title_catalog=0x7f040009; - public static final int title_order=0x7f040016; - public static final int title_shop=0x7f04000a; - public static final int title_thx=0x7f040015; - public static final int txt_empty=0x7f040006; - public static final int txt_total=0x7f04000d; - } -} diff --git a/branches/sca-java-1.x/samples/store-android/res/drawable/addc.png b/branches/sca-java-1.x/samples/store-android/res/drawable/addc.png Binary files differdeleted file mode 100644 index 17259450d8..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/drawable/addc.png +++ /dev/null diff --git a/branches/sca-java-1.x/samples/store-android/res/drawable/icon.png b/branches/sca-java-1.x/samples/store-android/res/drawable/icon.png Binary files differdeleted file mode 100644 index 75024841d3..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/drawable/icon.png +++ /dev/null diff --git a/branches/sca-java-1.x/samples/store-android/res/drawable/rems.png b/branches/sca-java-1.x/samples/store-android/res/drawable/rems.png Binary files differdeleted file mode 100644 index 378690fad4..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/drawable/rems.png +++ /dev/null diff --git a/branches/sca-java-1.x/samples/store-android/res/layout/cat_row.xml b/branches/sca-java-1.x/samples/store-android/res/layout/cat_row.xml deleted file mode 100644 index e7f71cb0b6..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/layout/cat_row.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="horizontal" - android:layout_width="fill_parent" - android:padding="10px" - android:layout_height="50px"> - <TextView - android:id="@+id/txtItemC" - android:layout_width="250px" - android:layout_height="30px" - android:textSize="20px" - - /> - - <ImageView android:src="@drawable/addc" - android:layout_width="30px" - android:layout_height="30px" - /> -</LinearLayout>
\ No newline at end of file diff --git a/branches/sca-java-1.x/samples/store-android/res/layout/main.xml b/branches/sca-java-1.x/samples/store-android/res/layout/main.xml deleted file mode 100644 index 7f296e9ac0..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/layout/main.xml +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<TabHost xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@android:id/tabhost" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - <LinearLayout - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - <TabWidget - android:id="@android:id/tabs" - android:layout_width="fill_parent" - android:layout_height="wrap_content" /> - <FrameLayout - android:id="@android:id/tabcontent" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - - - <ListView android:id="@+id/ListView01" - android:layout_width="fill_parent" - android:layout_height="wrap_content" /> - - <LinearLayout - android:id="@+id/tab02" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent"> - - <TextView - android:id="@+id/txtThx" - android:layout_width="fill_parent" - android:layout_height="30px" - android:text="@string/title_thx" - /> - <TextView - android:id="@+id/txtEmpty" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> - <LinearLayout - android:orientation="horizontal" - android:layout_width="fill_parent" - android:layout_height="41px"> - - <TextView - android:id="@+id/txtTotal" - android:layout_width="200px" - android:layout_height="30px" - android:text="@string/title_order" - /> - - <Button android:id="@+id/btnClean" - android:layout_width="100px" - android:layout_height="40px" - /> - </LinearLayout> - - <ListView android:id="@+id/ListView02" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> - - </LinearLayout> - </FrameLayout> - </LinearLayout> - -</TabHost> - diff --git a/branches/sca-java-1.x/samples/store-android/res/layout/shop_row.xml b/branches/sca-java-1.x/samples/store-android/res/layout/shop_row.xml deleted file mode 100644 index a2ffeea56f..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/layout/shop_row.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="horizontal" - android:layout_width="fill_parent" - android:layout_height="50px" - android:padding="10px"> - <TextView - android:id="@+id/txtItemS" - android:layout_width="250px" - android:layout_height="30px" - android:textSize="20px" - - /> - - <ImageView android:src="@drawable/rems" - android:layout_width="30px" - android:layout_height="30px" - - /> -</LinearLayout>
\ No newline at end of file diff --git a/branches/sca-java-1.x/samples/store-android/res/values/strings.xml b/branches/sca-java-1.x/samples/store-android/res/values/strings.xml deleted file mode 100644 index 33f936b510..0000000000 --- a/branches/sca-java-1.x/samples/store-android/res/values/strings.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="hello">Hello World, catalog</string> - <string name="app_name">store</string> - <string name="app_tag">Tuscany</string> - <string name="btn_clean">Erase cart</string> - <string name="btn_add_del1">Delete</string> - <string name="btn_add_del2">Add</string> - <string name="txt_empty">Nothing to display. The cart is currently empty</string> - <string name="tab_catalog">catalog_tab</string> - <string name="tab_shop">shopping_cart_tab</string> - <string name="title_catalog">Catalog Items</string> - <string name="title_shop">Shopping Cart</string> - <string name="get_tag">Catalog GET!!</string> - <string name="start_tag">Activity started</string> - <string name="txt_total">Total: </string> - <string name="add_entry_ok">Entry added: </string> - <string name="add_entry_ko">Unable to add entry: </string> - <string name="del_entry_ok">Entry removed: </string> - <string name="del_entry_ko">Unable to delete item: </string> - <string name="alert_yes">Yes</string> - <string name="alert_cancel">Cancel</string> - <string name="del_all_ok">All entries have been removed</string> - <string name="title_thx">Thanks for Shopping With Us!</string> - <string name="title_order">Your order</string> - <string name="howto_del">Click on an item below to remove it</string> - -</resources> diff --git a/branches/sca-java-1.x/samples/store-android/src/services/Catalog.java b/branches/sca-java-1.x/samples/store-android/src/services/Catalog.java deleted file mode 100644 index 9105f1047c..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/Catalog.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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; - -public interface Catalog { - Item[] get(); -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/CatalogProxy.java b/branches/sca-java-1.x/samples/store-android/src/services/CatalogProxy.java deleted file mode 100644 index 7851ac6713..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/CatalogProxy.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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; - -import java.util.ArrayList; -import java.util.List; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import services.json.rpc.JSONRpc; - -public class CatalogProxy implements Catalog { - // see http://developer.android.com/guide/developing/tools/emulator.html - private static final String jsonRPCServiceURI = "http://10.0.2.2:8080/Catalog"; - private static final String jsonRPCRequest = "{\"id\": 3, \"method\": \"Service.get\", \"params\": []}"; - - private List<Item> catalog = new ArrayList<Item>(); - - public CatalogProxy() { - initialize(); - } - - public void initialize() { - JSONObject json = null; - - try { - json = JSONRpc.invoke(jsonRPCServiceURI, jsonRPCRequest); - - if(json == null) { - return; - } - - JSONArray result = json.getJSONArray("result"); - for(int i = 0; i < result.length(); i++) { - Item item = new Item(); - item.setName(result.getJSONObject(i).getString("name")); - item.setPrice(result.getJSONObject(i).getString("price")); - - catalog.add(item); - } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - - public Item[] get() { - Item[] catalogArray = new Item[catalog.size()]; - catalog.toArray(catalogArray); - return catalogArray; - } - -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/Commons.java b/branches/sca-java-1.x/samples/store-android/src/services/Commons.java deleted file mode 100644 index 9da89c8fec..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/Commons.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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; - -/** - * - */ -public class Commons { - - public static final String TAG="Tuscany"; - public static final String DEL="HTTP DELETE "; - public static final String PST="HTTP POST "; - - -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/Item.java b/branches/sca-java-1.x/samples/store-android/src/services/Item.java deleted file mode 100644 index 1881dd4d11..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/Item.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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; - - -public class Item { - private String name; - private String price; - private String key; - - /** - * @return the key - */ - public String getKey() { - return key; - } - - /** - * @param key the key to set - */ - public void setKey(String key) { - this.key = key; - } - - - - - - - - - - public Item() { - } - - - - - - - - - - /** - * Parses a string entry to an Item object - * @param s - * @return Item - */ - public static Item parseItem(String s) - { - Item i=new Item(); - i.setName(s.split("-")[0].trim()); - i.setPrice(s.split("-")[1].trim()); - return i; - - } - - public Item(String name, String price) { - this.name = name; - this.price = price; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Item(String name, String price, String key) { - super(); - this.name = name; - this.price = price; - this.key = key; - } - - public String getPrice() { - return price; - } - - public void setPrice(String price) { - this.price = price; - } - - public String toString() - { - return name + " - " + price; - } - -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java b/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java deleted file mode 100644 index c01edfbe2f..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/ShoppingCartProxy.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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; - -import org.json.JSONException; -import org.json.JSONObject; - -import services.atom.xml.AtomXML; -import services.json.rpc.JSONRpc; -import android.util.Log; - -public class ShoppingCartProxy { - private static final String jsonRPCTotalServiceURI = "http://10.0.2.2:8080/ShoppingCart/Total"; - private static final String jsonRPCTotalRequest = "{\"id\": 4, \"method\": \"Service.getTotal\", \"params\": []}"; - private static final String atomXMLCartServiceURI="http://10.0.2.2:8080/ShoppingCart/Cart"; - - - public Item[] getItems() { - return AtomXML.getItems(atomXMLCartServiceURI); - } - - public boolean addItem(Item item) { - String content="<entry xmlns=\"http://www.w3.org/2005/Atom\">" + - "<title>item</title>" + - "<content type=\"text/xml\">" + - "<Item xmlns=\"http://services/\">" + - "<name xmlns=\"\">" + item.getName()+ "</name>" + - "<price xmlns=\"\">" +item.getPrice()+"</price>" + - "</Item></content></entry>"; - - String key =AtomXML.postItem(atomXMLCartServiceURI, content); - if(key==null) { - return false; - } - item.setKey(key); - Log.i("TUSCANY shopping cart proxy", key); - return true; - } - - public boolean removeItem(Item item) { - Log.e("Sent key",item.getKey()); - String uri=atomXMLCartServiceURI+"/"+item.getKey(); - return AtomXML.performdelete(uri); - } - - public boolean clearCartContent() { - return AtomXML.performdelete(atomXMLCartServiceURI); - } - - public void checkOut() { - - } - - public String getTotal() { - String total = ""; - JSONObject json = null; - Log.e("TUSC", "getting total"); - - try { - json = JSONRpc.invoke(jsonRPCTotalServiceURI, jsonRPCTotalRequest); - Log.e("TUSC", "Request OK"); - - if (json != null) { - total = json.getString("result"); - Log.e("TUSC", "Total: " + total); - } - } catch (JSONException e) { - Log.e("TUSC", e.getMessage()); - } - return total; - } -} 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 deleted file mode 100644 index 69f4409ed9..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/AtomXML.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * 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.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -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.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.DefaultHttpClient; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -import services.Commons; -import services.Item; -import android.util.Log; - -/** - * - */ -public class AtomXML { - - public static String postItem(String ServiceURI, final String content) - { - DefaultHttpClient client=new DefaultHttpClient(); - HttpPost httpost = new HttpPost(ServiceURI); - - httpost.setEntity(new HttpEntity(){ - - String entry=content; - - 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 posted via atom/xml"); - } - - }); - - try { - HttpResponse response = client.execute(httpost); - InputStream is =response.getEntity().getContent(); - - //Human readable atom response from servlet - int read; - StringBuffer sb=new StringBuffer(); - while((read=is.read())>0) - { - sb.append((char)read); - } - Log.i("Tuscany", "Atom entry post status: "+response.getStatusLine().toString()); - //Log.i("Tuscany", "Response: "+sb.toString()); - //Try now to parse the consumed data - try { - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser sp; - sp = spf.newSAXParser(); - XMLReader xr = sp.getXMLReader(); - CartItemHandler cih=new CartItemHandler(); - xr.setContentHandler(cih); - - xr.parse(new InputSource(new ByteArrayInputStream(sb.toString().getBytes()))); - is.close(); - - return cih.getCurrentKey(); - - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (SAXException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getLocalizedMessage()); - } - - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (IOException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } - - return null; - } - - public static boolean performdelete(String uri) - { - DefaultHttpClient client=new DefaultHttpClient(); - Log.i(Commons.TAG,Commons.DEL+uri); - HttpDelete del=new HttpDelete(uri); - - try { - client.execute(del); - return true; - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (IOException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } - - return false; - - - } - - public static Item[] getItems(String uri) - { - DefaultHttpClient client=new DefaultHttpClient(); - HttpGet hg=new HttpGet(uri); - HttpResponse hr; - HttpEntity he; - try { - hr=client.execute(hg); - InputStream is =hr.getEntity().getContent(); - - //Human readable atom response from servlet - int read; - StringBuffer sb=new StringBuffer(); - while((read=is.read())>0) - { - sb.append((char)read); - } - Log.i("Tuscany", "Atom get content: "+sb.toString()); - - SAXParserFactory spf = SAXParserFactory.newInstance(); - SAXParser sp; - sp = spf.newSAXParser(); - XMLReader xr = sp.getXMLReader(); - CartItemHandler cih=new CartItemHandler(); - xr.setContentHandler(cih); - - xr.parse(new InputSource(new ByteArrayInputStream(sb.toString().getBytes()))); - is.close(); - Log.e(Commons.TAG,String.valueOf(cih.getItemsCollection().length)); - return cih.getItemsCollection(); - - - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (IOException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } catch (SAXException e) { - // TODO Auto-generated catch block - Log.e(Commons.TAG,e.getMessage()); - } - return null; - } - - - - -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java b/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java deleted file mode 100644 index ed29839795..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/atom/xml/CartItemHandler.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.util.ArrayList; -import java.util.List; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import android.util.Log; - -import services.Item; - - -/** - * @author Lookouster - * - */ -public class CartItemHandler extends DefaultHandler { - - private boolean in_entry = false; - private boolean in_id = false; - private boolean in_title = false; - private boolean in_content=false; - private boolean in_item=false; - private boolean in_link=false; - private boolean in_name=false; - private boolean in_price=false; - private String currentKey,currentName,currentPrice; - private List<Item> items=new ArrayList<Item>(); - - /** - * @return the currentName - */ - public String getCurrentName() { - return currentName; - } - - - /** - * @return the currentPrice - */ - public String getCurrentPrice() { - return currentPrice; - } - - - public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { - if (localName.equalsIgnoreCase("entry")) { - this.in_entry = true; - } else if (localName.equalsIgnoreCase("id")) { - this.in_id = true; - } else if (localName.equalsIgnoreCase("title")) { - this.in_title = true; - } else if (localName.equalsIgnoreCase("content")) { - this.in_content = true; - } else if (localName.equalsIgnoreCase("item")) { - this.in_item = true; - } else if (localName.equals("link")) { - this.in_link = true; - } else if (localName.equalsIgnoreCase("name")) { - this.in_name = true; - } else if (localName.equalsIgnoreCase("price")) { - this.in_price = true; - } - } - - - public void endElement(String namespaceURI, String localName, String qName) throws SAXException { - if (localName.equalsIgnoreCase("id")) - this.in_id = false; - if (localName.equalsIgnoreCase("entry")) { - this.in_entry = false; - } else if (localName.equalsIgnoreCase("id")) { - this.in_id = false; - } else if (localName.equalsIgnoreCase("title")) { - this.in_title = false; - } else if (localName.equalsIgnoreCase("content")) { - this.in_content = false; - } else if (localName.equalsIgnoreCase("item")) { - this.in_item = false; - items.add(new Item(currentName, currentPrice, currentKey)); - } else if (localName.equalsIgnoreCase("link")) { - this.in_link = false; - } else if (localName.equalsIgnoreCase("name")) { - this.in_name = false; - } else if (localName.equalsIgnoreCase("price")) { - this.in_price = false; - } - } - - - public void characters(char ch[], int start, int length) { - if (this.in_id) { - if (this.in_entry) { - currentKey = new String(ch, start, length); - Log.e("kjhkh", currentKey); - } - - } - if (this.in_name) { - currentName = new String(ch, start, length); - } - if (this.in_price) { - currentPrice = new String(ch, start, length); - } - - } - - /** - * @return the key - */ - public String getCurrentKey() { - return currentKey; - } - - public Item[] getItemsCollection() - { - return items.toArray(new Item[items.size()]); - } - - - -} diff --git a/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java b/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java deleted file mode 100644 index b803ac6470..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/services/json/rpc/JSONRpc.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.json.rpc; - -import java.io.IOException; - -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; -import org.json.JSONException; -import org.json.JSONObject; - -public class JSONRpc { - - protected JSONRpc() { - - } - - public static JSONObject invoke(String serviceURI, String rpcRequest) throws JSONException{ - HttpClient httpClient = new DefaultHttpClient(); - HttpPost httpPost = new HttpPost(serviceURI); - - JSONObject result = null; - try { - httpPost.setHeader("Content-Type", "text/xml"); - httpPost.setEntity(new StringEntity(rpcRequest)); - - HttpResponse httpResponse = httpClient.execute(httpPost); - if (httpResponse.getStatusLine().getStatusCode() == 200) { - String jsonResult = EntityUtils.toString(httpResponse.getEntity()); - result = new JSONObject(jsonResult); - } else { - String errorMessage = httpResponse.getStatusLine() - .getReasonPhrase(); - System.out.println(errorMessage); - } - } catch (IOException e) { - e.printStackTrace(); - } - - return result; - } -} diff --git a/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java b/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java deleted file mode 100644 index 834362352a..0000000000 --- a/branches/sca-java-1.x/samples/store-android/src/store/android/catalog.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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 store.android; - -import java.util.ArrayList; -import java.util.List; - -import services.Catalog; -import services.CatalogProxy; -import services.Item; -import services.ShoppingCartProxy; -import android.app.AlertDialog; -import android.app.TabActivity; -import android.content.DialogInterface; -import android.graphics.Typeface; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.ListView; -import android.widget.TabHost; -import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.TabHost.OnTabChangeListener; -import android.widget.TabHost.TabSpec; - - - -public class catalog extends TabActivity { - private Catalog catalogProxy = new CatalogProxy(); - private ShoppingCartProxy shoppingCartProxy = new ShoppingCartProxy(); - - private TabHost mTabHost; - private ListView itemsList, cartList; - private TextView txtTotal,txtEmpty; - private TabSpec catalogTab, cartTab; - private Button btnClean; - private Item[] items; - private List<Item> cartItems=new ArrayList<Item>(); - - - private void getCatalogItems() { - items=catalogProxy.get(); - } - - private void getCartItems() { - Item[] i = shoppingCartProxy.getItems(); - if (i != null) { - for (Item item : i) { - cartItems.add(item); - } - } - Log.e(getString(R.string.app_tag), String.valueOf(cartItems.size()) + " cart items retrieved"); - } - - /** Called when the activity is first created. */ - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Log.e(getString(R.string.app_tag), getString(R.string.start_tag)); - // Load UI from layout file - setContentView(R.layout.main); - - findViews(); - - // Get data to be loaded to UI - getCatalogItems(); - getCartItems(); - - // Load UI with data - itemsList.setAdapter(new ArrayAdapter<Item>(this, R.layout.cat_row, R.id.txtItemC, items)); - itemsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - itemsList.setClickable(true); - reloadShoppingCart(); - - // Set Listeners - listen(); - } - - - - /** - * Retrieve UI Content - */ - public void findViews() - { - mTabHost = getTabHost(); - mTabHost.addTab(mTabHost.newTabSpec(getString(R.string.tab_catalog)).setIndicator(getString(R.string.title_catalog)).setContent(R.id.ListView01)); - mTabHost.addTab(mTabHost.newTabSpec(getString(R.string.tab_shop)).setIndicator(getString(R.string.title_shop)).setContent(R.id.tab02)); - mTabHost.setCurrentTab(0); - itemsList=(ListView)findViewById(R.id.ListView01); - cartList=(ListView)findViewById(R.id.ListView02); - btnClean=(Button)findViewById(R.id.btnClean); - btnClean.setText(R.string.btn_clean); - txtTotal=(TextView)findViewById(R.id.txtTotal); - txtTotal.setTextSize((float) 15.0); - txtTotal.setTypeface(Typeface.DEFAULT_BOLD); - txtEmpty=(TextView)findViewById(R.id.txtEmpty); - txtEmpty.setTypeface(null, Typeface.ITALIC); - - } - - /** - * Implements all needed listeners for the UI - */ - public void listen() { - // Handles total display between tab switching - mTabHost.setOnTabChangedListener(new OnTabChangeListener() { - - public void onTabChanged(String tabId) { - // TODO Auto-generated method stub - if (tabId.compareTo("shopping_cart_tab") == 0) { - reloadShoppingCart(); - } - } - }); - - btnClean.setOnClickListener(new OnClickListener(){ - public void onClick(View arg0) { - // TODO Auto-generated method stub - new AlertDialog.Builder(catalog.this) - .setTitle("Tuscany Android Store") - .setMessage("You're about to erase all items. Proceed ?") - .setIcon(R.drawable.icon) - .setPositiveButton(R.string.alert_yes, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - if(shoppingCartProxy.clearCartContent()) - { - cartItems.clear(); - Log.i(getString(R.string.app_tag), getString(R.string.del_all_ok)); - reloadShoppingCart(); - } - }}) - .setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener(){ - - public void onClick(DialogInterface dialog, int which) { - // TODO Auto-generated method stub - } - }) - .show(); - - - - } - - }); - - itemsList.setOnItemClickListener(new OnItemClickListener(){ - - public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, - long arg3) { - // TODO Auto-generated method stub - addItemAction(items[(int)arg3]); - - } - - }); - - cartList.setOnItemClickListener(new OnItemClickListener(){ - - - public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, - long arg3) { - // TODO Auto-generated method stub - removeItemAction(cartItems.get((int)arg3)); - } - - }); - - } - - public void addItemAction(Item item) - { - //add item to shopping cart. - Item tmp=new Item(item.getName(), item.getPrice()); - if(shoppingCartProxy.addItem(tmp)) - { - cartItems.add(tmp); - Log.i(getString(R.string.app_tag), getString(R.string.add_entry_ok)+item); - } - - else - Log.e(getString(R.string.app_tag), getString(R.string.add_entry_ko)+item); - - } - - public void removeItemAction(Item item) - { - if(shoppingCartProxy.removeItem(item) && cartItems.remove(item)) - { - Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ok)+item); - } - else - Log.i(getString(R.string.app_tag), getString(R.string.del_entry_ko)+item); - reloadShoppingCart(); - - } - - /** - * Refreshes the Shopping cart list when the adapter behind is updated - */ - public void reloadShoppingCart() - { - Item[] cartArray=new Item[cartItems.size()]; - cartList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - cartList.setClickable(true); - cartList.setAdapter(new ArrayAdapter<Item>(this, - R.layout.shop_row, R.id.txtItemS, cartItems.toArray(cartArray))); - if(!cartList.getAdapter().isEmpty()) - { - txtTotal.setVisibility(TextView.VISIBLE); - txtEmpty.setText("Click on an item below to remove it"); - btnClean.setVisibility(Button.VISIBLE); - } - else - { - txtTotal.setVisibility(TextView.INVISIBLE); - txtEmpty.setVisibility(TextView.VISIBLE); - txtEmpty.setText(R.string.txt_empty); - btnClean.setVisibility(Button.INVISIBLE); - } - String tt=shoppingCartProxy.getTotal(); - txtTotal.setText(getString(R.string.title_order)+": "+(tt.length()>5?tt.substring(0,5):tt)); - - } - - - -}
\ No newline at end of file |