Pulled from trunk. Changes from SVN revision r698020.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@699942 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
169561a340
commit
4d02d6cb27
5 changed files with 1326 additions and 5 deletions
|
@ -34,9 +34,9 @@ public class CatalogImpl implements Catalog {
|
|||
|
||||
@Init
|
||||
public void init() {
|
||||
catalog.add("Apple - US$ 2.99");
|
||||
catalog.add("Orange - US$ 3.55");
|
||||
catalog.add("Pear - US$ 1.55");
|
||||
catalog.add("Apple - $ 2.99");
|
||||
catalog.add("Orange - $ 3.55");
|
||||
catalog.add("Pear - $ 1.55");
|
||||
}
|
||||
|
||||
public String[] get() {
|
||||
|
|
|
@ -47,7 +47,6 @@ public class ShoppingCartImpl implements Collection {
|
|||
for (Entry entry : cart.values()) {
|
||||
feed.addEntry(entry);
|
||||
}
|
||||
|
||||
return feed;
|
||||
}
|
||||
|
||||
|
@ -83,7 +82,7 @@ public class ShoppingCartImpl implements Collection {
|
|||
entry.addLink(id, "edit");
|
||||
entry.addLink(id, "alternate");
|
||||
|
||||
entry.setEdited(new Date());
|
||||
entry.setUpdated(new Date());
|
||||
|
||||
cart.put(id, entry);
|
||||
return entry;
|
||||
|
@ -106,6 +105,7 @@ public class ShoppingCartImpl implements Collection {
|
|||
String currencySymbol = "";
|
||||
if (!cart.isEmpty()) {
|
||||
String item = ((Entry)cart.values().iterator().next()).getContent();
|
||||
// Select first symbol after dash.
|
||||
currencySymbol = item.substring(item.indexOf("-") + 2, item.indexOf("-") + 3);
|
||||
}
|
||||
for (Entry entry : cart.values()) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,144 @@
|
|||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Store</TITLE>
|
||||
|
||||
<!-- one js include per sca component -->
|
||||
<script type="text/javascript" src="storeJS.js"></script>
|
||||
|
||||
<!-- Include Tuscany JavaScript client model for Atom.
|
||||
Using this JavaScript model, users can use syntax such as:
|
||||
item += "name=" + entry.getName() + ", price=" + entry.getContent()
|
||||
rather than
|
||||
item += entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
|
||||
-->
|
||||
<script type="text/javascript" src="atomModel.js"></script>
|
||||
|
||||
<script language="JavaScript">
|
||||
|
||||
//@Reference
|
||||
var catalog = new Reference("Catalog");
|
||||
|
||||
//@Reference
|
||||
var shoppingCart = new Reference("ShoppingCart");
|
||||
|
||||
//@Property
|
||||
var locale = Property("locale");
|
||||
|
||||
function catalog_getResponse(items,exception) {
|
||||
if(exception){
|
||||
alert(exception.message);
|
||||
return;
|
||||
}
|
||||
var catalog = "";
|
||||
for (var i=0; i<items.length; i++)
|
||||
catalog += '<input name="items" type="checkbox" value="' +
|
||||
items[i] + '">' + items[i]+ ' <br>';
|
||||
document.getElementById('catalog').innerHTML=catalog;
|
||||
}
|
||||
|
||||
function shoppingCart_getResponse(feedDoc) {
|
||||
// var xmlString = new XMLSerializer().serializeToString(feed);
|
||||
// alert("shoppingCart_getResponse feed xml=" + xmlString);
|
||||
var feed = new Feed( feedDoc );
|
||||
|
||||
if (feed != null) {
|
||||
// var entries = feed.getElementsByTagName("entry");
|
||||
var entries = feed.getEntries();
|
||||
var list = "";
|
||||
for (var i=0; i<entries.length; i++) {
|
||||
// var item = entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
|
||||
var item = entries[i].getContent().getText();
|
||||
list += item + ' <br>';
|
||||
}
|
||||
document.getElementById("shoppingCart").innerHTML = list;
|
||||
// document.getElementById('total').innerHTML = feed.getElementsByTagName("subtitle")[0].firstChild.nodeValue;
|
||||
var text = feed.getSubTitle().getText();
|
||||
document.getElementById('total').innerHTML = text;
|
||||
}
|
||||
}
|
||||
|
||||
function shoppingCart_postResponse(entry) {
|
||||
shoppingCart.get("", shoppingCart_getResponse);
|
||||
}
|
||||
|
||||
function addToCart() {
|
||||
var items = document.catalogForm.items;
|
||||
var j = 0;
|
||||
for (var i=0; i<items.length; i++)
|
||||
if (items[i].checked) {
|
||||
var entry = '<entry xmlns="http://www.w3.org/2005/Atom"><title>cart-item</title><content type="text">'+items[i].value+'</content></entry>'
|
||||
shoppingCart.post(entry, shoppingCart_postResponse);
|
||||
items[i].checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkoutCart() {
|
||||
document.getElementById('store').innerHTML='<h2>' +
|
||||
'Thanks for Shopping With Us!</h2>'+
|
||||
'<h2>Your Order</h2>'+
|
||||
'<form name="orderForm" action="/ufs/store.html">'+
|
||||
document.getElementById('shoppingCart').innerHTML+
|
||||
'<br>'+
|
||||
document.getElementById('total').innerHTML+
|
||||
'<br>'+
|
||||
'<br>'+
|
||||
'<input type="submit" value="Continue Shopping">'+
|
||||
'</form>';
|
||||
shoppingCart.del("", null);
|
||||
}
|
||||
function deleteCart() {
|
||||
shoppingCart.del("", null);
|
||||
document.getElementById('shoppingCart').innerHTML = "";
|
||||
document.getElementById('total').innerHTML = "";
|
||||
}
|
||||
|
||||
//alert(locale);
|
||||
catalog.get(catalog_getResponse);
|
||||
shoppingCart.get("", shoppingCart_getResponse);
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Store</h1>
|
||||
<div id="store">
|
||||
<h2>Catalog</h2>
|
||||
<form name="catalogForm">
|
||||
<div id="catalog" ></div>
|
||||
<br>
|
||||
<input type="button" onClick="addToCart()" value="Add to Cart">
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<h2>Your Shopping Cart</h2>
|
||||
<form name="shoppingCartForm">
|
||||
<div id="shoppingCart"></div>
|
||||
<br>
|
||||
<div id="total"></div>
|
||||
<br>
|
||||
<input type="button" onClick="checkoutCart()" value="Checkout">
|
||||
<input type="button" onClick="deleteCart()" value="Empty">
|
||||
<a href="../ShoppingCart/">(feed)</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
|
||||
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
|
||||
targetNamespace="http://sample/resource"
|
||||
xmlns:sr="http://sample/resource"
|
||||
name="resource">
|
||||
|
||||
<component name="storeJS">
|
||||
<!-- Note: the store.html and storeJS.html clients are similar
|
||||
except that store.html edits the client document using JavaScript
|
||||
and many node queries, and storeJS.html uses the client Atom
|
||||
JavaScript mode (fewer node queries and less XML knowledge needed.-->
|
||||
<tuscany:implementation.widget location="content/storeJS.html"/>
|
||||
<property name="locale">en</property>
|
||||
<service name="Widget">
|
||||
<tuscany:binding.http uri="/storeJS"/>
|
||||
</service>
|
||||
<reference name="Catalog" target="Catalog">
|
||||
<tuscany:binding.jsonrpc uri="/Catalog"/>
|
||||
</reference>
|
||||
<reference name="ShoppingCart" target="ShoppingCart">
|
||||
<tuscany:binding.atom uri="/ShoppingCart"/>
|
||||
</reference>
|
||||
</component>
|
||||
|
||||
<component name="Catalog">
|
||||
<implementation.java class="store.CatalogImpl"/>
|
||||
<service name="Catalog">
|
||||
<tuscany:binding.jsonrpc uri="/Catalog"/>
|
||||
</service>
|
||||
</component>
|
||||
|
||||
<component name="ShoppingCart">
|
||||
<implementation.java class="store.ShoppingCartImpl"/>
|
||||
<service name="Collection">
|
||||
<tuscany:binding.atom uri="/ShoppingCart"/>
|
||||
</service>
|
||||
</component>
|
||||
|
||||
</composite>
|
Loading…
Reference in a new issue