├── .gitignore ├── .idea ├── .name ├── codeStyleSettings.xml ├── copyright │ ├── Webx_License.xml │ └── profiles_settings.xml ├── dictionaries │ └── baobao.xml ├── encodings.xml ├── scopes │ └── scope_settings.xml ├── uiDesigner.xml └── vcs.xml ├── DEPLOY.txt ├── archetype-webx-quickstart ├── pom.xml └── src │ └── main │ └── resources │ ├── META-INF │ └── maven │ │ └── archetype-metadata.xml │ └── archetype-resources │ ├── .gitignore │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── app1 │ │ ├── Visitor.java │ │ └── module │ │ ├── action │ │ └── RegisterAction.java │ │ └── screen │ │ ├── form │ │ └── Welcome.java │ │ ├── list │ │ └── Default.java │ │ ├── multievent │ │ ├── SayHello1.java │ │ └── SayHello2.java │ │ └── simple │ │ ├── Count.java │ │ ├── Download.java │ │ ├── SayHi.java │ │ └── SayHiImage.java │ └── webapp │ ├── WEB-INF │ ├── app1 │ │ └── form.xml │ ├── common │ │ ├── pipeline-exception.xml │ │ ├── pipeline.xml │ │ ├── resources.xml │ │ ├── uris.xml │ │ ├── webx-component-and-root.xml │ │ └── webx-component.xml │ ├── logback.xml │ ├── web.xml │ ├── webx-app1.xml │ └── webx.xml │ ├── app1 │ └── templates │ │ ├── layout │ │ └── default.vm │ │ └── screen │ │ ├── form │ │ ├── register.vm │ │ └── welcome.vm │ │ ├── index.vm │ │ └── list │ │ ├── asHtml.vm │ │ ├── asJson.vm │ │ └── asXml.vm │ └── common │ └── templates │ ├── layout │ └── default.vm │ ├── macros.vm │ └── screen │ └── error.vm ├── petstore ├── biz │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── sample │ │ │ │ └── petstore │ │ │ │ └── biz │ │ │ │ ├── DuplicatedProductException.java │ │ │ │ ├── DuplicatedUserException.java │ │ │ │ ├── StoreManager.java │ │ │ │ ├── StoreManagerException.java │ │ │ │ ├── UserManager.java │ │ │ │ ├── UserManagerException.java │ │ │ │ └── impl │ │ │ │ ├── StoreManagerImpl.java │ │ │ │ └── UserManagerImpl.java │ │ └── resources │ │ │ └── petstore │ │ │ └── biz │ │ │ └── manager.xml │ │ └── test │ │ ├── config │ │ └── resources.xml │ │ └── java │ │ └── com │ │ └── alibaba │ │ └── sample │ │ └── petstore │ │ └── biz │ │ ├── AbstractBizManagerTests.java │ │ ├── StoreManagerTests.java │ │ └── UserManagerTests.java ├── dal │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── sample │ │ │ │ └── petstore │ │ │ │ └── dal │ │ │ │ ├── dao │ │ │ │ ├── CategoryDao.java │ │ │ │ ├── OrderDao.java │ │ │ │ ├── ProductDao.java │ │ │ │ ├── ProductItemDao.java │ │ │ │ ├── SequenceDao.java │ │ │ │ ├── UserDao.java │ │ │ │ └── ibatis │ │ │ │ │ ├── IbatisCategoryDao.java │ │ │ │ │ ├── IbatisOrderDao.java │ │ │ │ │ ├── IbatisProductDao.java │ │ │ │ │ ├── IbatisProductItemDao.java │ │ │ │ │ ├── IbatisSequenceDao.java │ │ │ │ │ └── IbatisUserDao.java │ │ │ │ └── dataobject │ │ │ │ ├── Account.java │ │ │ │ ├── Cart.java │ │ │ │ ├── CartItem.java │ │ │ │ ├── Category.java │ │ │ │ ├── Order.java │ │ │ │ ├── OrderItem.java │ │ │ │ ├── Product.java │ │ │ │ ├── ProductItem.java │ │ │ │ ├── Profile.java │ │ │ │ ├── Sequence.java │ │ │ │ └── User.java │ │ └── resources │ │ │ └── petstore │ │ │ └── dal │ │ │ ├── dao.xml │ │ │ ├── data-source.xml │ │ │ ├── sql │ │ │ ├── hsqldb-init-data.sql │ │ │ └── hsqldb-schema.sql │ │ │ ├── sqlmap-config.xml │ │ │ └── sqlmap │ │ │ ├── Category.xml │ │ │ ├── Order.xml │ │ │ ├── OrderItem.xml │ │ │ ├── Product.xml │ │ │ ├── ProductItem.xml │ │ │ ├── Sequence.xml │ │ │ └── User.xml │ │ └── test │ │ ├── config │ │ └── resources.xml │ │ └── java │ │ └── com │ │ └── alibaba │ │ └── sample │ │ └── petstore │ │ └── dal │ │ ├── dao │ │ ├── AbstractDataAccessTests.java │ │ ├── CategoryDaoTests.java │ │ ├── OrderDaoTests.java │ │ ├── ProductDaoTests.java │ │ ├── ProductItemDaoTests.java │ │ ├── SequenceDaoTests.java │ │ └── UserDaoTests.java │ │ └── dataobject │ │ └── CartTests.java ├── pom.xml └── web │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── alibaba │ │ └── sample │ │ └── petstore │ │ └── web │ │ ├── common │ │ ├── PetstoreConstant.java │ │ ├── PetstoreUser.java │ │ ├── PetstoreUserAuth.java │ │ └── util │ │ │ └── PetstoreUserTool.java │ │ ├── home │ │ └── module │ │ │ └── screen │ │ │ └── Redirect.java │ │ ├── servlet │ │ └── GetLoginUser.java │ │ ├── store │ │ └── module │ │ │ ├── action │ │ │ ├── AddProductAction.java │ │ │ └── CartAction.java │ │ │ ├── control │ │ │ └── CategoryList.java │ │ │ └── screen │ │ │ ├── AddProduct.java │ │ │ ├── CategoryList.java │ │ │ ├── ItemList.java │ │ │ └── ViewCart.java │ │ └── user │ │ └── module │ │ ├── action │ │ ├── LoginAction.java │ │ └── RegisterAction.java │ │ └── screen │ │ ├── Account.java │ │ └── RegisterAccount.java │ └── webapp │ ├── META-INF │ └── autoconf │ │ └── auto-config.xml │ ├── WEB-INF │ ├── common │ │ ├── pipeline-exception.xml │ │ ├── pipeline.xml │ │ ├── resources.xml │ │ ├── template-data.xml │ │ ├── uris.xml │ │ ├── webx-component-and-root.xml │ │ └── webx-component.xml │ ├── home │ │ └── form.xml │ ├── logback.xml │ ├── store │ │ └── form.xml │ ├── user │ │ └── form.xml │ ├── web.xml │ ├── webx-home.xml │ ├── webx-store.xml │ ├── webx-user.xml │ └── webx.xml │ ├── common │ └── templates │ │ ├── layout │ │ └── default.vm │ │ ├── macros.vm │ │ └── screen │ │ └── error.vm │ ├── home │ ├── css │ │ ├── petstore-common.css │ │ └── petstore-homepage.css │ ├── images │ │ ├── bg_topline.png │ │ ├── btn_login.png │ │ ├── cart.png │ │ ├── dot_transparent.png │ │ ├── logo_alibaba.gif │ │ ├── logo_petstore_big.png │ │ ├── logo_petstore_small.png │ │ ├── logo_webx.png │ │ ├── logo_webx_small.png │ │ ├── petstore_title.png │ │ ├── tab_left.png │ │ ├── tab_mid.png │ │ ├── tab_right.png │ │ ├── tab_selected_left.png │ │ ├── tab_selected_mid.png │ │ └── tab_selected_right.png │ └── templates │ │ ├── control │ │ ├── bottom.vm │ │ ├── nav.vm │ │ ├── tabs.vm │ │ ├── top.vm │ │ └── topNoLogo.vm │ │ ├── layout │ │ └── default.vm │ │ └── screen │ │ └── homepage.vm │ ├── store │ ├── css │ │ └── petstore-store.css │ ├── images │ │ ├── bird1.jpg │ │ ├── bird4.jpg │ │ ├── cat1.jpg │ │ ├── cat3.jpg │ │ ├── cat_bird.jpg │ │ ├── cat_cat.jpg │ │ ├── cat_dog.jpg │ │ ├── cat_fish.jpg │ │ ├── cat_reptile.jpg │ │ ├── dog1.jpg │ │ ├── dog2.jpg │ │ ├── dog4.jpg │ │ ├── dog5.jpg │ │ ├── dog6.jpg │ │ ├── fish1.jpg │ │ ├── fish2.jpg │ │ ├── fish3.jpg │ │ ├── fish4.jpg │ │ ├── lizard2.jpg │ │ └── lizard3.jpg │ └── templates │ │ ├── control │ │ └── categoryList.vm │ │ ├── layout │ │ └── default.vm │ │ └── screen │ │ ├── categoryList.vm │ │ ├── edit │ │ ├── addProduct.vm │ │ ├── categoryList.vm │ │ └── itemList.vm │ │ ├── itemList.vm │ │ └── viewCart.vm │ └── user │ ├── css │ └── petstore-user.css │ └── templates │ ├── control │ └── login.vm │ ├── layout │ └── default.vm │ └── screen │ ├── account.vm │ ├── login.vm │ ├── register.vm │ └── registerAccount.vm └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | target 3 | dependency-reduced-pom.xml 4 | .settings 5 | .project 6 | .classpath 7 | .svn 8 | 9 | *.iml 10 | /out 11 | /.idea/ant.xml 12 | /.idea/misc.xml 13 | /.idea/workspace.xml 14 | /.idea/compiler.xml 15 | /.idea/modules.xml 16 | /.idea/libraries/Maven*.xml 17 | /.idea/artifacts/*.xml 18 | /*.iws 19 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | citrus-sample -------------------------------------------------------------------------------- /.idea/copyright/Webx_License.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 19 | 20 | 23 | 24 | 27 | 28 | 30 | 31 | 33 | 34 | 36 | 37 | 40 | 41 | -------------------------------------------------------------------------------- /.idea/dictionaries/baobao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DEPLOY.txt: -------------------------------------------------------------------------------- 1 | 发布指南 2 | 3 | 请先阅读 4 | ======= 5 | 6 | https://github.com/webx/citrus/blob/master/DEPLOY.txt 7 | 8 | 发布步骤 9 | ======== 10 | 11 | 1. 确保所有源代码提交 12 | 2. 发布 13 | 14 | cd citrus-sample 15 | mvn clean deploy -Pdeployment 16 | 17 | 确保使用deployment profile,以便生成sonatype所需要的数字签名。 18 | 并非所有子项目都会被发布,只有那些 maven-deploy-plugin.skip=false 的项目才会被发布。 19 | 20 | 3. 测试petstore 21 | 22 | 删除$HOME/.m2/repository/com/alibaba/citrus 23 | cd petstore 24 | mvn clean install -Psonatype 25 | cd web 26 | mvn jetty:run-war 27 | 28 | 4. 测试archetype 29 | 30 | mvn archetype:generate \ 31 | -DgroupId=com.alibaba.webx \ 32 | -DartifactId=tutorial1 \ 33 | -Dversion=1.0-SNAPSHOT \ 34 | -Dpackage=com.alibaba.webx.tutorial1 \ 35 | -DarchetypeArtifactId=archetype-webx-quickstart \ 36 | -DarchetypeGroupId=com.alibaba.citrus.sample \ 37 | -DarchetypeVersion=1.5 \ 38 | -DinteractiveMode=false \ 39 | -Psonatype 40 | 41 | cd tutorial1 42 | mvn jetty:run 43 | 44 | 5. 在sonatype管理界面中promote项目到central maven repository 45 | 6. 对发布版本创建tags 46 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alibaba.citrus.sample 7 | citrus-sample-parent 8 | 1.2 9 | ../pom.xml 10 | 11 | archetype-webx-quickstart 12 | maven-archetype 13 | 1.8 14 | Maven archetype for Webx application 15 | 4.0.0 16 | 17 | 18 | 19 | org.apache.maven.archetype 20 | archetype-packaging 21 | 22 | 23 | 24 | 25 | maven-deploy-plugin 26 | 27 | 28 | false 29 | 30 | 31 | 32 | maven-archetype-plugin 33 | true 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/META-INF/maven/archetype-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 3.2.4 9 | 10 | 11 | 3.2.7.RELEASE 12 | 13 | 14 | 15 | 16 | 17 | 18 | **/* 19 | 20 | 21 | pom.xml 22 | src/main/java/** 23 | src/main/webapp/WEB-INF/webx*.xml 24 | src/main/webapp/WEB-INF/logback.xml 25 | 26 | 27 | 28 | src/main/webapp/WEB-INF 29 | 30 | webx*.xml 31 | logback.xml 32 | 33 | 34 | 35 | src/main/java 36 | 37 | **/* 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | target 3 | .settings 4 | .project 5 | .classpath 6 | .svn 7 | 8 | *.iml 9 | /out 10 | /.idea/ant.xml 11 | /.idea/misc.xml 12 | /.idea/workspace.xml 13 | /.idea/modules.xml 14 | /.idea/compiler.xml 15 | /.idea/libraries/Maven*.xml 16 | /.idea/artifacts/*.xml 17 | /*.iws 18 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/Visitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1; 19 | 20 | public class Visitor { 21 | private String name; 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/action/RegisterAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.action; 19 | 20 | import com.alibaba.citrus.turbine.Navigator; 21 | import com.alibaba.citrus.turbine.dataresolver.FormGroup; 22 | 23 | import ${package}.app1.Visitor; 24 | 25 | public class RegisterAction { 26 | public void doRegister(@FormGroup("register") Visitor visitor, Navigator nav) { 27 | String name = visitor.getName(); 28 | nav.redirectTo("app1Link").withTarget("form/welcome").withParameter("name", name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/form/Welcome.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.form; 19 | 20 | import com.alibaba.citrus.turbine.Context; 21 | import com.alibaba.citrus.turbine.dataresolver.Param; 22 | 23 | public class Welcome { 24 | public void execute(@Param("name") String name, Context context) { 25 | context.put("name", name); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/list/Default.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.list; 19 | 20 | import com.alibaba.citrus.turbine.Context; 21 | 22 | public class Default { 23 | public void execute(Context context) { 24 | context.put("list", new String[] { 25 | "Adobe Photoshop", 26 | "Adobe Acrobat", 27 | "Adobe Lightroom", 28 | "Apple Aperture", 29 | "Microsoft Office", 30 | "IntelliJ IDEA", 31 | "<<\"Objective-C\"指南>>" 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/multievent/SayHello1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.multievent; 19 | 20 | import java.io.IOException; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | 25 | /** 26 | * 这个例子演示了用一个screen类处理多个事件的方法。 27 | * 28 | * @author Michael Zhou 29 | */ 30 | public class SayHello1 { 31 | @Autowired 32 | private HttpServletResponse response; 33 | 34 | /** 此方法会在所有的event handler之前执行。 */ 35 | public void beforeExecution() { 36 | response.setContentType("text/plain"); 37 | } 38 | 39 | /** 此方法会在所有的event handler之后执行。 */ 40 | public void afterExecution() throws IOException { 41 | response.flushBuffer(); // 此调用并非必须,只是用来演示afterExecution方法而已 42 | } 43 | 44 | /** 默认语言:英文 */ 45 | public void doPerform() throws IOException { 46 | doEnglish(); 47 | } 48 | 49 | /** 英文 */ 50 | public void doEnglish() throws IOException { 51 | response.getWriter().println("English: Hello"); 52 | } 53 | 54 | /** 中文 */ 55 | public void doChinese() throws IOException { 56 | response.getWriter().println("Chinese: 你好"); 57 | } 58 | 59 | /** 法语 */ 60 | public void doFrench() throws IOException { 61 | response.getWriter().println("French: Bonjour"); 62 | } 63 | 64 | /** 西班牙语 */ 65 | public void doSpanish() throws IOException { 66 | response.getWriter().println("Spanish: Hola"); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/multievent/SayHello2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.multievent; 19 | 20 | import java.io.IOException; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | 25 | /** 26 | * Screen方法可带有返回值。 27 | *

28 | * 这个screen所返回的对象将被转换成json格式,并输出到用户浏览器。 29 | * 30 | * @author Michael Zhou 31 | */ 32 | public class SayHello2 { 33 | /** 英文 */ 34 | public Hello doEnglish() { 35 | return new Hello("English", "Hello"); 36 | } 37 | 38 | /** 中文 */ 39 | public Hello doChinese() { 40 | return new Hello("Chinese", "你好"); 41 | } 42 | 43 | /** 法语 */ 44 | public Hello doFrench() { 45 | return new Hello("French", "Bonjour"); 46 | } 47 | 48 | /** 西班牙语 */ 49 | public Hello doSpanish() { 50 | return new Hello("Spanish", "Hola"); 51 | } 52 | 53 | public static class Hello { 54 | private String language; 55 | private String howToSay; 56 | 57 | public Hello(String language, String howToSay) { 58 | this.language = language; 59 | this.howToSay = howToSay; 60 | } 61 | 62 | public String getLanguage() { 63 | return language; 64 | } 65 | 66 | public void setLanguage(String language) { 67 | this.language = language; 68 | } 69 | 70 | public String getHowToSay() { 71 | return howToSay; 72 | } 73 | 74 | public void setHowToSay(String howToSay) { 75 | this.howToSay = howToSay; 76 | } 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/simple/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.simple; 19 | 20 | import static com.alibaba.citrus.util.StringEscapeUtil.*; 21 | 22 | import java.io.PrintWriter; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import com.alibaba.citrus.service.requestcontext.buffered.BufferedRequestContext; 26 | import com.alibaba.citrus.turbine.dataresolver.Param; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | 29 | /** 30 | * 在浏览器上显示计数。 31 | *

32 | * 多数动态WEB页面是这样的:先在内存中生成整个页面,然后一次性提交给浏览器。这样,在页面完全生成之前,用户必须等待。 33 | *

34 | * 此程序展示了一种技术,能让页面一边生成、一边展示给用户。虽然页面还没有完全生成,但用户已经能够看到部分页面。 35 | * 这不仅改善了用户的体验,也使浏览器处理页面、下载、服务器生成页面三者实现了并发,从而加快了显示页面的总时间。 36 | * 37 | * @author Michael Zhou 38 | */ 39 | public class Count { 40 | @Autowired 41 | private HttpServletResponse response; 42 | 43 | @Autowired 44 | private BufferedRequestContext brc; 45 | 46 | public void execute(@Param("to") int toNumber) throws Exception { 47 | // 必须关闭buffering,未完成的页面才会被显示在浏览器上。 48 | brc.setBuffering(false); 49 | 50 | // 设置content type,但不需要设置charset,框架会设置正确的charset。 51 | response.setContentType("text/html"); 52 | 53 | PrintWriter out = response.getWriter(); 54 | 55 | out.println(""); 56 | out.println(""); 57 | out.println(" Count to " + toNumber + ""); 58 | out.println(""); 59 | out.println(""); 60 | 61 | for (int i = 1; i <= toNumber; i++) { 62 | for (int j = 0; j < 10000; j++) { 63 | out.print(i); 64 | } 65 | 66 | out.println(); 67 | out.flush(); // 将当前的结果立即显示到浏览器上 68 | 69 | Thread.sleep(1000); // 特意等待1秒,仅用于演示。 70 | } 71 | 72 | out.println(""); 73 | out.println(""); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/simple/Download.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.simple; 19 | 20 | import static com.alibaba.citrus.util.ObjectUtil.*; 21 | import static com.alibaba.citrus.util.StringEscapeUtil.*; 22 | import static org.apache.commons.lang.StringUtils.*; 23 | 24 | import java.io.PrintWriter; 25 | import javax.servlet.http.HttpServletResponse; 26 | 27 | import com.alibaba.citrus.service.requestcontext.buffered.BufferedRequestContext; 28 | import com.alibaba.citrus.turbine.dataresolver.Param; 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | 31 | /** 32 | * 动态生成下载文件。 33 | * 34 | * @author Michael Zhou 35 | */ 36 | public class Download { 37 | @Autowired 38 | private HttpServletResponse response; 39 | 40 | @Autowired 41 | private BufferedRequestContext brc; 42 | 43 | public void execute(@Param("filename") String filename) throws Exception { 44 | // 为了增强用户体验,关闭buffering,让下载立即开始,而不是等待整个文件生成完才通知用户下载。 45 | brc.setBuffering(false); 46 | 47 | // 设置headers,下载文件名必须避免非us-ascii字符,因为各浏览器的兼容程度不同。 48 | filename = defaultIfNull(trimToNull(filename), "image") + ".txt"; 49 | filename = "\"" + escapeURL(filename) + "\""; 50 | 51 | response.setHeader("Content-disposition", "attachment; filename=" + filename); 52 | 53 | // 只要设置了正确的content type,你就可以让用户下载任何文本或二进制的内容: 54 | // HTML、JSON、JavaScript、JPG、PDF、EXCEL等。 55 | response.setContentType("text/plain"); 56 | 57 | PrintWriter out = response.getWriter(); 58 | 59 | for (int i = 0; i < 100; i++) { 60 | out.flush(); // 立即提示用户下载 61 | 62 | for (int j = 0; j < 100000; j++) { 63 | out.print(i); 64 | } 65 | 66 | out.println(); 67 | 68 | Thread.sleep(100); // 故意延迟,以减缓下载速度 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/simple/SayHi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.simple; 19 | 20 | import java.io.PrintWriter; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | 25 | /** 26 | * 这是最简单的页面:不需要模板,直接输出到浏览器,就像最简单的servlet一样。 27 | * 28 | * @author Michael Zhou 29 | */ 30 | public class SayHi { 31 | @Autowired 32 | private HttpServletResponse response; 33 | 34 | public void execute() throws Exception { 35 | // 设置content type,但不需要设置charset。框架会设置正确的charset。 36 | response.setContentType("text/plain"); 37 | 38 | // 如同servlet一样:取得输出流。 39 | PrintWriter out = response.getWriter(); 40 | 41 | out.println("Hi there, how are you doing today?"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/java/app1/module/screen/simple/SayHiImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package ${package}.app1.module.screen.simple; 19 | 20 | import static com.alibaba.citrus.util.ObjectUtil.*; 21 | import static com.alibaba.citrus.util.StringEscapeUtil.*; 22 | import static org.apache.commons.lang.StringUtils.*; 23 | 24 | import java.awt.*; 25 | import java.awt.image.BufferedImage; 26 | import java.io.IOException; 27 | import java.io.OutputStream; 28 | import javax.imageio.ImageIO; 29 | import javax.servlet.http.HttpServletResponse; 30 | 31 | import com.alibaba.citrus.service.requestcontext.buffered.BufferedRequestContext; 32 | import com.alibaba.citrus.turbine.dataresolver.Param; 33 | import org.springframework.beans.factory.annotation.Autowired; 34 | 35 | /** 36 | * 动态创建二进制图片。 37 | * 38 | * @author Michael Zhou 39 | */ 40 | public class SayHiImage { 41 | @Autowired 42 | private HttpServletResponse response; 43 | 44 | @Autowired 45 | private BufferedRequestContext brc; 46 | 47 | public void execute() throws Exception { 48 | // 为了节省内存,关闭buffering。 49 | brc.setBuffering(false); 50 | 51 | // 只要设置了正确的content type,你就可以输出任何文本或二进制的内容: 52 | // HTML、JSON、JavaScript、JPG、PDF、EXCEL等。 53 | response.setContentType("image/jpeg"); 54 | 55 | OutputStream out = response.getOutputStream(); 56 | 57 | writeImage(out); 58 | } 59 | 60 | private void writeImage(OutputStream out) throws IOException { 61 | BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); 62 | Graphics2D g2d = img.createGraphics(); 63 | 64 | g2d.setPaint(Color.red); 65 | g2d.setFont(new Font("Serif", Font.BOLD, 36)); 66 | g2d.drawString("Hi there, how are you doing today?", 5, g2d.getFontMetrics().getHeight()); 67 | g2d.dispose(); 68 | 69 | ImageIO.write(img, "jpg", out); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/app1/form.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | 提交的数据已过期 25 | 26 | 27 | 28 | 33 | 34 | 35 | 36 | 必须填写 ${displayName} 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/common/pipeline-exception.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/common/pipeline.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/common/resources.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/common/uris.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | / 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/common/webx-component.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | System.out 6 | ${loggingCharset} 7 | 8 | INFO 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | System.err 19 | ${loggingCharset} 20 | 21 | WARN 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | com.alibaba.citrus.logconfig.LogConfiguratorListener 11 | 12 | 13 | 14 | 15 | com.alibaba.citrus.webx.context.WebxContextLoaderListener 16 | 17 | 18 | 19 | mdc 20 | com.alibaba.citrus.webx.servlet.SetLoggingContextFilter 21 | 22 | 23 | 24 | webx 25 | com.alibaba.citrus.webx.servlet.WebxFrameworkFilter 26 | 27 | excludes 28 | 29 | 30 | 31 | passthru 32 | 34 | 35 | 36 | 37 | 38 | mdc 39 | /* 40 | 41 | 42 | 43 | webx 44 | /* 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/webx-app1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | 16 | 17 | 18 | app1 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #showHead ("My Simple Webx Application") 5 | 6 | 7 | 8 | 9 | $screen_placeholder 10 | 11 |


12 |

[Home] [Dev Home]

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/form/register.vm: -------------------------------------------------------------------------------- 1 | $page.setTitle("Register") 2 | 3 |
4 | $csrfToken.hiddenField 5 | 6 | 7 | #set ($group = $form.register.defaultInstance) 8 | 9 |

Hello, what's your name?

10 | 11 | #if (!$group.name.valid) 12 |

$group.name.message

13 | #end 14 | 15 |

16 | 17 | 18 |

19 | 20 |
21 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/form/welcome.vm: -------------------------------------------------------------------------------- 1 | $page.setTitle("Welcome, $name") 2 |

Welcome, $name!

3 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/index.vm: -------------------------------------------------------------------------------- 1 | $page.setTitle("It works.") 2 | 3 |

It works.

4 | 5 |
    6 |
  1. 7 |

    Simple Page without Template

    8 | 9 | #set($url = "$app1Link.setTarget('simple/SayHi.do')") 10 | $url 11 |
  2. 12 | 13 |
  3. 14 |

    Simple Image

    15 | 16 | #set($url = "$app1Link.setTarget('simple/sayHiImage.do')") 17 | $url 18 |
  4. 19 | 20 |
  5. 21 |

    Show a SLOW Page

    22 | 23 | #set($url = "$app1Link.setTarget('simple/count.do').addQueryData('to', 10)") 24 | $url 25 |
  6. 26 | 27 |
  7. 28 |

    Download a Large File

    29 | 30 | #set($url = "$app1Link.setTarget('simple/download.do').addQueryData('filename', 'blob')") 31 | $url 32 |
  8. 33 | 34 |
  9. 35 |

    Form Validation

    36 | 37 | #set($url = "$app1Link.setTarget('form/register')") 38 | $url 39 |
  10. 40 | 41 |
  11. 42 |

    Single Screen for Multiple Templates

    43 | 44 | 57 |
  12. 58 | 59 |
  13. 60 |

    Single Screen with Multiple Event Handlers

    61 | 62 | 79 |
  14. 80 | 81 |
  15. 82 |

    JSON

    83 | 84 | 101 |
  16. 102 | 103 | 104 |
-------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/list/asHtml.vm: -------------------------------------------------------------------------------- 1 |

Product List

2 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/list/asJson.vm: -------------------------------------------------------------------------------- 1 | $rundata.response.setContentType("application/json") 2 | $rundata.setLayoutEnabled(false) 3 | #escape("javascript") 4 | { 5 | "productList":[ 6 | #foreach ($item in $list) 7 | {"name":"$item"}, 8 | #end 9 | ] 10 | } 11 | #end -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/app1/templates/screen/list/asXml.vm: -------------------------------------------------------------------------------- 1 | $rundata.response.setContentType("text/xml") 2 | $rundata.setLayoutEnabled(false) 3 | #escape("xml") 4 | 5 | #foreach ($item in $list) 6 | 7 | #end 8 | 9 | #end -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/common/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $error 5 | 6 | 7 |

$error

8 | $screen_placeholder 9 | 10 | 11 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/common/templates/macros.vm: -------------------------------------------------------------------------------- 1 | #** ------------------------------------------- 2 | * 显示所有headers 3 | * -------------------------------------------- *# 4 | #macro (showHead $defaultTitle) 5 | 6 | #showTitle ($defaultTitle) 7 | #showMetaTags () 8 | #showHttpEquiv () 9 | #showStylesheets () 10 | #showJavascripts () 11 | 12 | #end 13 | 14 | #** ------------------------------------------- 15 | * 显示标题,如果未提供标题,则使用默认值 16 | * -------------------------------------------- *# 17 | #macro (showTitle $defaultTitle) 18 | 19 | #if( $page.title != "" ) 20 | $page.title 21 | #else 22 | $!defaultTitle 23 | #end 24 | 25 | #end 26 | 27 | #** ------------------------------------------- 28 | * 显示meta tags 29 | * -------------------------------------------- *# 30 | #macro (showMetaTags) 31 | 32 | #foreach($metaTag in $page.metaTags.keySet()) 33 | 34 | #end 35 | 36 | #end 37 | 38 | #** ------------------------------------------- 39 | * 显示meta http-equiv 40 | * -------------------------------------------- *# 41 | #macro (showHttpEquiv) 42 | 43 | #foreach($httpEquiv in $page.httpEquivs.keySet()) 44 | 45 | #end 46 | 47 | #end 48 | 49 | #** ------------------------------------------- 50 | * 显示stylesheets 51 | * -------------------------------------------- *# 52 | #macro (showStylesheets) 53 | 54 | #foreach( $styleSheet in $page.styleSheets ) 55 | 59 | #end 60 | 61 | #end 62 | 63 | #** ------------------------------------------- 64 | * 显示javascripts 65 | * -------------------------------------------- *# 66 | #macro (showJavascripts) 67 | 68 | #foreach( $script in $page.scripts ) 69 | 70 | #end 71 | 72 | #end 73 | 74 | 75 | #** ------------------------------------------- 76 | * 显示body attributes 77 | * -------------------------------------------- *# 78 | #macro (bodyAttributes) 79 | 80 | #foreach( $attributeName in $page.bodyAttributes.keySet() ) 81 | $attributeName="$page.bodyAttributes.get($attributeName)" 82 | #end 83 | 84 | #end 85 | 86 | #** ------------------------------------------- 87 | * 显示select box 88 | * -------------------------------------------- *# 89 | #macro (select $name $map $selected $hint) 90 | 91 | #set ($_map = $map) 92 | #set ($_selected = $selected) 93 | 101 | 102 | #end 103 | -------------------------------------------------------------------------------- /archetype-webx-quickstart/src/main/resources/archetype-resources/src/main/webapp/common/templates/screen/error.vm: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /petstore/biz/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | com.alibaba.citrus.sample 6 | petstore-parent 7 | 1.0 8 | ../pom.xml 9 | 10 | 4.0.0 11 | petstore-biz 12 | Pet Store Biz Logic 13 | jar 14 | 15 | 16 | com.alibaba.citrus 17 | citrus-webx-all 18 | 19 | 20 | ch.qos.logback 21 | logback-classic 22 | 23 | 24 | com.alibaba.citrus.sample 25 | petstore-dal 26 | 27 | 28 | com.alibaba.citrus 29 | citrus-test-all 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/DuplicatedProductException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | public class DuplicatedProductException extends StoreManagerException { 21 | private static final long serialVersionUID = 8001823899691787517L; 22 | 23 | public DuplicatedProductException() { 24 | } 25 | 26 | public DuplicatedProductException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | public DuplicatedProductException(String message) { 31 | super(message); 32 | } 33 | 34 | public DuplicatedProductException(Throwable cause) { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/DuplicatedUserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | public class DuplicatedUserException extends UserManagerException { 21 | private static final long serialVersionUID = 3328402083382671054L; 22 | 23 | public DuplicatedUserException() { 24 | super(); 25 | } 26 | 27 | public DuplicatedUserException(String message) { 28 | super(message); 29 | } 30 | 31 | public DuplicatedUserException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | public DuplicatedUserException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/StoreManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.Cart; 23 | import com.alibaba.sample.petstore.dal.dataobject.Category; 24 | import com.alibaba.sample.petstore.dal.dataobject.Product; 25 | import com.alibaba.sample.petstore.dal.dataobject.ProductItem; 26 | import org.apache.commons.fileupload.FileItem; 27 | 28 | public interface StoreManager { 29 | Category getCategory(String categoryId); 30 | 31 | void addProduct(Product product, String categoryId, FileItem picture) throws StoreManagerException; 32 | 33 | List getAllCategories(); 34 | 35 | List getAllProductItems(String productId); 36 | 37 | ProductItem getProductItem(String itemId); 38 | 39 | Cart getCartItems(Cart cart); 40 | } 41 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/StoreManagerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | public class StoreManagerException extends RuntimeException { 21 | private static final long serialVersionUID = 8897703961393145194L; 22 | 23 | public StoreManagerException() { 24 | } 25 | 26 | public StoreManagerException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | public StoreManagerException(String message) { 31 | super(message); 32 | } 33 | 34 | public StoreManagerException(Throwable cause) { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/UserManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | import com.alibaba.sample.petstore.dal.dataobject.User; 21 | 22 | /** 23 | * 有关用户的操作。 24 | * 25 | * @author Michael Zhou 26 | */ 27 | public interface UserManager { 28 | /** 29 | * 登录用户,如果用户名和密码正确,则返回相应的用户信息。 30 | * 31 | * @param userId 用户名 32 | * @param password 密码 33 | * @return 用户信息,如果用户名或密码不正确,则返回null 34 | */ 35 | User login(String userId, String password); 36 | 37 | /** 38 | * 注册用户。 39 | * 40 | * @param user 用户对象 41 | */ 42 | void register(User user) throws DuplicatedUserException; 43 | 44 | /** 45 | * 更新用户的信息。 46 | * 47 | * @param user 用户对象 48 | */ 49 | void update(User user); 50 | 51 | /** 52 | * 取得指定id的用户。 53 | * 54 | * @param userId 用户id 55 | * @return 指定id的用户 56 | */ 57 | User getUser(String userId); 58 | } 59 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/UserManagerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | public class UserManagerException extends RuntimeException { 21 | private static final long serialVersionUID = -8196055690022375153L; 22 | 23 | public UserManagerException() { 24 | super(); 25 | } 26 | 27 | public UserManagerException(String message) { 28 | super(message); 29 | } 30 | 31 | public UserManagerException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | public UserManagerException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /petstore/biz/src/main/java/com/alibaba/sample/petstore/biz/impl/UserManagerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz.impl; 19 | 20 | import com.alibaba.sample.petstore.biz.DuplicatedUserException; 21 | import com.alibaba.sample.petstore.biz.UserManager; 22 | import com.alibaba.sample.petstore.dal.dao.UserDao; 23 | import com.alibaba.sample.petstore.dal.dataobject.User; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | 26 | /** 27 | * 有关用户的操作。 28 | * 29 | * @author Michael Zhou 30 | */ 31 | public class UserManagerImpl implements UserManager { 32 | @Autowired 33 | private UserDao userDao; 34 | 35 | /** 36 | * 登录用户,如果用户名和密码正确,则返回相应的用户信息。 37 | * 38 | * @param userId 用户名 39 | * @param password 密码 40 | * @return 用户信息,如果用户名或密码不正确,则返回null 41 | */ 42 | public User login(String userId, String password) { 43 | return userDao.getAuthenticatedUser(userId, password); 44 | } 45 | 46 | /** 47 | * 注册用户。 48 | * 49 | * @param user 用户对象 50 | * @return 新的用户信息 51 | */ 52 | public void register(User user) throws DuplicatedUserException { 53 | User dupuser = userDao.getUserById(user.getUserId()); 54 | 55 | if (dupuser != null) { 56 | throw new DuplicatedUserException("duplicated user: " + user.getUserId()); 57 | } 58 | 59 | userDao.insertUser(user); 60 | } 61 | 62 | /** 63 | * 更新用户的信息。 64 | * 65 | * @param user 用户对象 66 | * @return 新的用户信息 67 | */ 68 | public void update(User user) { 69 | userDao.updateUser(user); 70 | } 71 | 72 | /** 73 | * 取得指定id的用户。 74 | * 75 | * @param userId 用户id 76 | * @return 指定id的用户 77 | */ 78 | public User getUser(String userId) { 79 | return userDao.getUserById(userId); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /petstore/biz/src/main/resources/petstore/biz/manager.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /petstore/biz/src/test/config/resources.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /petstore/biz/src/test/java/com/alibaba/sample/petstore/biz/AbstractBizManagerTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.biz; 19 | 20 | import com.alibaba.citrus.test.context.SpringextContextLoader; 21 | import org.junit.runner.RunWith; 22 | import org.springframework.test.context.ContextConfiguration; 23 | import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; 24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 25 | 26 | @RunWith(SpringJUnit4ClassRunner.class) 27 | @ContextConfiguration(locations = { "/resources.xml", "/classpath/petstore/dal/data-source.xml", 28 | "/classpath/petstore/dal/dao.xml", "/classpath/petstore/biz/manager.xml" }, loader = SpringextContextLoader.class) 29 | public abstract class AbstractBizManagerTests extends AbstractTransactionalJUnit4SpringContextTests { 30 | } 31 | -------------------------------------------------------------------------------- /petstore/dal/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | com.alibaba.citrus.sample 6 | petstore-parent 7 | 1.0 8 | ../pom.xml 9 | 10 | 4.0.0 11 | petstore-dal 12 | Pet Store Data Access 13 | jar 14 | 15 | 16 | com.alibaba.citrus 17 | citrus-webx-all 18 | 19 | 20 | ch.qos.logback 21 | logback-classic 22 | 23 | 24 | org.apache.ibatis 25 | ibatis-sqlmap 26 | 27 | 28 | commons-dbcp 29 | commons-dbcp 30 | 31 | 32 | hsqldb 33 | hsqldb 34 | 35 | 36 | com.alibaba.citrus 37 | citrus-test-all 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/CategoryDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.Category; 23 | 24 | public interface CategoryDao { 25 | List getCategoryList(); 26 | 27 | Category getCategoryById(String categoryId); 28 | } 29 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.Order; 23 | 24 | public interface OrderDao { 25 | List getOrdersByUserId(String username); 26 | 27 | Order getOrderById(int orderId); 28 | 29 | void insertOrder(Order order); 30 | } 31 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ProductDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.Product; 23 | 24 | public interface ProductDao { 25 | List getProductListByCategoryId(String categoryId); 26 | 27 | Product getProductById(String productId); 28 | 29 | List searchProductsByKeywords(String keywords); 30 | 31 | void insertProduct(Product product); 32 | } 33 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ProductItemDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.Order; 23 | import com.alibaba.sample.petstore.dal.dataobject.ProductItem; 24 | 25 | public interface ProductItemDao { 26 | List getItemListByProductId(String productId); 27 | 28 | ProductItem getItemById(String itemId); 29 | 30 | boolean isItemInStock(String itemId); 31 | 32 | void updateQuantity(Order order); 33 | } 34 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/SequenceDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | public interface SequenceDao { 21 | public int getNextId(String name); 22 | } 23 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dataobject.User; 23 | 24 | public interface UserDao { 25 | User getUserById(String userId); 26 | 27 | User getAuthenticatedUser(String userId, String password); 28 | 29 | List getUserIdList(); 30 | 31 | void insertUser(User user); 32 | 33 | void updateUser(User user); 34 | } 35 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisCategoryDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dao.CategoryDao; 23 | import com.alibaba.sample.petstore.dal.dataobject.Category; 24 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 25 | 26 | public class IbatisCategoryDao extends SqlMapClientDaoSupport implements CategoryDao { 27 | @SuppressWarnings("unchecked") 28 | public List getCategoryList() { 29 | return getSqlMapClientTemplate().queryForList("getCategoryList", null); 30 | } 31 | 32 | public Category getCategoryById(String categoryId) { 33 | return (Category) getSqlMapClientTemplate().queryForObject("getCategory", categoryId); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisOrderDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.sample.petstore.dal.dao.OrderDao; 23 | import com.alibaba.sample.petstore.dal.dataobject.Order; 24 | import com.alibaba.sample.petstore.dal.dataobject.OrderItem; 25 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 26 | 27 | public class IbatisOrderDao extends SqlMapClientDaoSupport implements OrderDao { 28 | @SuppressWarnings("unchecked") 29 | public List getOrdersByUserId(String username) { 30 | return getSqlMapClientTemplate().queryForList("getOrdersByUserId", username); 31 | } 32 | 33 | @SuppressWarnings("unchecked") 34 | public Order getOrderById(int orderId) { 35 | Order order = null; 36 | Object parameterObject = new Integer(orderId); 37 | 38 | order = (Order) getSqlMapClientTemplate().queryForObject("getOrder", parameterObject); 39 | order.setOrderItems(getSqlMapClientTemplate().queryForList("getOrderItemsByOrderId", 40 | new Integer(order.getOrderId()))); 41 | 42 | return order; 43 | } 44 | 45 | public void insertOrder(Order order) { 46 | getSqlMapClientTemplate().update("insertOrder", order); 47 | getSqlMapClientTemplate().update("insertOrderStatus", order); 48 | 49 | for (OrderItem orderItem : order.getOrderItems()) { 50 | orderItem.setOrderId(order.getOrderId()); 51 | getSqlMapClientTemplate().update("insertOrderItem", orderItem); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisProductDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import static com.alibaba.citrus.util.CollectionUtil.*; 21 | import static com.alibaba.citrus.util.StringUtil.*; 22 | 23 | import java.util.List; 24 | 25 | import com.alibaba.sample.petstore.dal.dao.ProductDao; 26 | import com.alibaba.sample.petstore.dal.dataobject.Product; 27 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 28 | 29 | public class IbatisProductDao extends SqlMapClientDaoSupport implements ProductDao { 30 | @SuppressWarnings("unchecked") 31 | public List getProductListByCategoryId(String categoryId) { 32 | return getSqlMapClientTemplate().queryForList("getProductListByCategory", categoryId); 33 | } 34 | 35 | public Product getProductById(String productId) { 36 | return (Product) getSqlMapClientTemplate().queryForObject("getProduct", productId); 37 | } 38 | 39 | @SuppressWarnings("unchecked") 40 | public List searchProductsByKeywords(String keywords) { 41 | return getSqlMapClientTemplate().queryForList("searchProductList", new ProductSearch(keywords)); 42 | } 43 | 44 | public void insertProduct(Product product) { 45 | getSqlMapClientTemplate().update("insertProduct", product); 46 | } 47 | 48 | public static class ProductSearch { 49 | private List keywordList = createLinkedList(); 50 | 51 | public ProductSearch(String keywords) { 52 | if (keywords != null) { 53 | for (String keyword : split(keywords, ", ")) { 54 | keywordList.add("%" + keyword + "%"); 55 | } 56 | } 57 | } 58 | 59 | public List getKeywordList() { 60 | return keywordList; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisProductItemDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import static com.alibaba.citrus.util.CollectionUtil.*; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import com.alibaba.sample.petstore.dal.dao.ProductItemDao; 26 | import com.alibaba.sample.petstore.dal.dataobject.Order; 27 | import com.alibaba.sample.petstore.dal.dataobject.OrderItem; 28 | import com.alibaba.sample.petstore.dal.dataobject.ProductItem; 29 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 30 | 31 | public class IbatisProductItemDao extends SqlMapClientDaoSupport implements ProductItemDao { 32 | @SuppressWarnings("unchecked") 33 | public List getItemListByProductId(String productId) { 34 | return getSqlMapClientTemplate().queryForList("getItemListByProduct", productId); 35 | } 36 | 37 | public ProductItem getItemById(String itemId) { 38 | Integer i = (Integer) getSqlMapClientTemplate().queryForObject("getInventoryQuantity", itemId); 39 | ProductItem item = (ProductItem) getSqlMapClientTemplate().queryForObject("getItem", itemId); 40 | 41 | if (item != null && i != null) { 42 | item.setQuantity(i.intValue()); 43 | } 44 | 45 | return item; 46 | } 47 | 48 | public boolean isItemInStock(String itemId) { 49 | Integer i = (Integer) getSqlMapClientTemplate().queryForObject("getInventoryQuantity", itemId); 50 | 51 | return i != null && i.intValue() > 0; 52 | } 53 | 54 | public void updateQuantity(Order order) { 55 | for (OrderItem orderItem : order.getOrderItems()) { 56 | String itemId = orderItem.getProductItemId(); 57 | int quantity = orderItem.getQuantity(); 58 | 59 | Map params = createHashMap(); 60 | 61 | params.put("itemId", itemId); 62 | params.put("quantity", quantity); 63 | 64 | getSqlMapClientTemplate().update("updateInventoryQuantity", params); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisSequenceDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import static com.alibaba.citrus.util.Assert.*; 21 | 22 | import com.alibaba.sample.petstore.dal.dao.SequenceDao; 23 | import com.alibaba.sample.petstore.dal.dataobject.Sequence; 24 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 25 | 26 | public class IbatisSequenceDao extends SqlMapClientDaoSupport implements SequenceDao { 27 | public synchronized int getNextId(String name) { 28 | Sequence sequence = new Sequence(name, -1); 29 | 30 | sequence = (Sequence) getSqlMapClientTemplate().queryForObject("getSequence", sequence); 31 | 32 | assertNotNull(sequence, "unknown sequence name: {}", name); 33 | 34 | Object parameterObject = new Sequence(name, sequence.getNextId() + 1); 35 | 36 | getSqlMapClientTemplate().update("updateSequence", parameterObject); 37 | 38 | return sequence.getNextId(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dao/ibatis/IbatisUserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao.ibatis; 19 | 20 | import static com.alibaba.citrus.util.StringUtil.*; 21 | 22 | import java.util.List; 23 | 24 | import com.alibaba.sample.petstore.dal.dao.UserDao; 25 | import com.alibaba.sample.petstore.dal.dataobject.User; 26 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 27 | 28 | public class IbatisUserDao extends SqlMapClientDaoSupport implements UserDao { 29 | public User getUserById(String userId) { 30 | return (User) getSqlMapClientTemplate().queryForObject("getUserByUserId", userId); 31 | } 32 | 33 | public User getAuthenticatedUser(String userId, String password) { 34 | User user = new User(); 35 | 36 | user.setUserId(userId); 37 | user.setPassword(password); 38 | 39 | return (User) getSqlMapClientTemplate().queryForObject("getUserByUserIdAndPassword", user); 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | public List getUserIdList() { 44 | return getSqlMapClientTemplate().queryForList("getUserIdList", null); 45 | } 46 | 47 | public void insertUser(User user) { 48 | getSqlMapClientTemplate().update("insertUser", user); 49 | getSqlMapClientTemplate().update("insertAccount", user); 50 | getSqlMapClientTemplate().update("insertProfile", user); 51 | } 52 | 53 | public void updateUser(User user) { 54 | getSqlMapClientTemplate().update("updateAccount", user); 55 | getSqlMapClientTemplate().update("updateProfile", user); 56 | 57 | if (!isEmpty(user.getPassword())) { 58 | getSqlMapClientTemplate().update("updateUser", user); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | import static com.alibaba.citrus.util.CollectionUtil.*; 21 | 22 | import java.io.Serializable; 23 | import java.math.BigDecimal; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | /** 28 | * 存放在session中的shopping cart对象。 29 | * 30 | * @author Michael Zhou 31 | */ 32 | public class Cart implements Serializable { 33 | private static final long serialVersionUID = 43557847549256390L; 34 | private Map cartItems = createLinkedHashMap(); 35 | 36 | public CartItem getCartItem(String itemId) { 37 | return cartItems.get(itemId); 38 | } 39 | 40 | public List getCartItemList() { 41 | return createArrayList(cartItems.values()); 42 | } 43 | 44 | public void addCartItem(String itemId) { 45 | CartItem cartItem = cartItems.get(itemId); 46 | 47 | if (cartItem == null) { 48 | cartItem = new CartItem(itemId); 49 | 50 | cartItems.put(itemId, cartItem); 51 | } 52 | 53 | cartItem.incrementQuantity(); 54 | } 55 | 56 | public void removeCartItem(String itemId) { 57 | cartItems.remove(itemId); 58 | } 59 | 60 | public void setQuantity(String itemId, int quantity) { 61 | CartItem cartItem = cartItems.get(itemId); 62 | 63 | if (cartItem == null) { 64 | addCartItem(itemId); 65 | cartItem = cartItems.get(itemId); 66 | } 67 | 68 | cartItem.setQuantity(quantity); 69 | } 70 | 71 | public BigDecimal getTotal() { 72 | BigDecimal total = new BigDecimal("0"); 73 | 74 | for (CartItem cartItem : getCartItemList()) { 75 | total = total.add(cartItem.getTotal()); 76 | } 77 | 78 | return total; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | import java.io.Serializable; 21 | import java.math.BigDecimal; 22 | 23 | public class CartItem implements Serializable { 24 | private static final long serialVersionUID = -8518016753555699796L; 25 | private String productItemId; 26 | private int quantity; 27 | private transient ProductItem item; 28 | 29 | public CartItem(String productItemId) { 30 | this.productItemId = productItemId; 31 | } 32 | 33 | public String getProductItemId() { 34 | return productItemId; 35 | } 36 | 37 | public ProductItem getProductItem() { 38 | return item; 39 | } 40 | 41 | public void setProductItem(ProductItem item) { 42 | this.item = item; 43 | } 44 | 45 | public int getQuantity() { 46 | return quantity; 47 | } 48 | 49 | public void setQuantity(int quantity) { 50 | this.quantity = quantity; 51 | } 52 | 53 | public void incrementQuantity() { 54 | quantity++; 55 | } 56 | 57 | public BigDecimal getTotal() { 58 | if (item == null) { 59 | return new BigDecimal(0); 60 | } 61 | 62 | return item.getListPrice().multiply(new BigDecimal(quantity)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/Category.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | import java.util.List; 21 | 22 | public class Category { 23 | private String categoryId; 24 | private String name; 25 | private String logo; 26 | private String description; 27 | private List productList; 28 | 29 | public String getCategoryId() { 30 | return categoryId; 31 | } 32 | 33 | public void setCategoryId(String categoryId) { 34 | this.categoryId = categoryId.trim(); 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String getDescription() { 46 | return description; 47 | } 48 | 49 | public void setDescription(String description) { 50 | this.description = description; 51 | } 52 | 53 | public String getLogo() { 54 | return logo; 55 | } 56 | 57 | public void setLogo(String logo) { 58 | this.logo = logo; 59 | } 60 | 61 | public List getProductList() { 62 | return productList; 63 | } 64 | 65 | public void setProductList(List productList) { 66 | this.productList = productList; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return getCategoryId(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | public class Product { 21 | private String productId; 22 | private String categoryId; 23 | private String name; 24 | private String logo; 25 | private String description; 26 | private Category category; 27 | 28 | public String getProductId() { 29 | return productId; 30 | } 31 | 32 | public void setProductId(String productId) { 33 | this.productId = productId.trim(); 34 | } 35 | 36 | public String getCategoryId() { 37 | return categoryId; 38 | } 39 | 40 | public void setCategoryId(String categoryId) { 41 | this.categoryId = categoryId; 42 | } 43 | 44 | public Category getCategory() { 45 | return category; 46 | } 47 | 48 | public void setCategory(Category category) { 49 | this.category = category; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public String getDescription() { 61 | return description; 62 | } 63 | 64 | public void setDescription(String description) { 65 | this.description = description; 66 | } 67 | 68 | public String getLogo() { 69 | return logo; 70 | } 71 | 72 | public void setLogo(String logo) { 73 | this.logo = logo; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return getName(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/Profile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | public class Profile { 21 | private final User user; 22 | private String favoriteCategoryId; 23 | private String languagePreference; 24 | private boolean listOption; 25 | 26 | public Profile(User user) { 27 | this.user = user; 28 | } 29 | 30 | public User getUser() { 31 | return user; 32 | } 33 | 34 | public String getFavoriteCategoryId() { 35 | return favoriteCategoryId; 36 | } 37 | 38 | public void setFavoriteCategoryId(String favoriteCategoryId) { 39 | this.favoriteCategoryId = favoriteCategoryId; 40 | } 41 | 42 | public String getLanguagePreference() { 43 | return languagePreference; 44 | } 45 | 46 | public void setLanguagePreference(String languagePreference) { 47 | this.languagePreference = languagePreference; 48 | } 49 | 50 | public boolean isListOption() { 51 | return listOption; 52 | } 53 | 54 | public void setListOption(boolean listOption) { 55 | this.listOption = listOption; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/Sequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | public class Sequence { 21 | private String name; 22 | private int nextId; 23 | 24 | public Sequence() { 25 | } 26 | 27 | public Sequence(String name, int nextId) { 28 | this.name = name; 29 | this.nextId = nextId; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public int getNextId() { 41 | return nextId; 42 | } 43 | 44 | public void setNextId(int nextId) { 45 | this.nextId = nextId; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /petstore/dal/src/main/java/com/alibaba/sample/petstore/dal/dataobject/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dataobject; 19 | 20 | import static com.alibaba.citrus.util.StringUtil.*; 21 | 22 | public class User { 23 | private String userId; 24 | private String password; 25 | private String[] roles; 26 | private final Account account = new Account(this); 27 | private final Profile profile = new Profile(this); 28 | 29 | public String getUserId() { 30 | return userId; 31 | } 32 | 33 | public void setUserId(String userId) { 34 | this.userId = userId; 35 | } 36 | 37 | public String getPassword() { 38 | return password; 39 | } 40 | 41 | public void setPassword(String password) { 42 | this.password = password; 43 | } 44 | 45 | public String[] getRoles() { 46 | return roles; 47 | } 48 | 49 | public void setRoles(String[] roles) { 50 | this.roles = roles; 51 | } 52 | 53 | public String getRole() { 54 | return join(roles, ", "); 55 | } 56 | 57 | public void setRole(String roles) { 58 | this.roles = split(roles, ", "); 59 | } 60 | 61 | public Account getAccount() { 62 | return account; 63 | } 64 | 65 | public Profile getProfile() { 66 | return profile; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/data-source.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap/Category.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 17 | 18 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap/OrderItem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap/Product.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 18 | 30 | 45 | 46 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap/ProductItem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 31 | 37 | 40 | 43 | 44 | -------------------------------------------------------------------------------- /petstore/dal/src/main/resources/petstore/dal/sqlmap/Sequence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /petstore/dal/src/test/config/resources.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /petstore/dal/src/test/java/com/alibaba/sample/petstore/dal/dao/AbstractDataAccessTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import com.alibaba.citrus.test.context.SpringextContextLoader; 21 | import org.junit.runner.RunWith; 22 | import org.springframework.test.context.ContextConfiguration; 23 | import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; 24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 25 | 26 | @RunWith(SpringJUnit4ClassRunner.class) 27 | @ContextConfiguration(locations = { "/resources.xml", "/classpath/petstore/dal/data-source.xml", 28 | "/classpath/petstore/dal/dao.xml" }, loader = SpringextContextLoader.class) 29 | public abstract class AbstractDataAccessTests extends AbstractTransactionalJUnit4SpringContextTests { 30 | } 31 | -------------------------------------------------------------------------------- /petstore/dal/src/test/java/com/alibaba/sample/petstore/dal/dao/CategoryDaoTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import static org.junit.Assert.*; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | 25 | import com.alibaba.sample.petstore.dal.dataobject.Category; 26 | import org.junit.Test; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | 29 | public class CategoryDaoTests extends AbstractDataAccessTests { 30 | @Autowired 31 | private CategoryDao categoryDao; 32 | 33 | @Test 34 | public void getCategoryList() { 35 | assertCategoryList(categoryDao.getCategoryList(), "BIRDS", "CATS", "DOGS", "FISH", "REPTILES"); 36 | } 37 | 38 | @Test 39 | public void getCategoryById() { 40 | Category cat = categoryDao.getCategoryById("BIRDS"); 41 | 42 | assertEquals("BIRDS", cat.getCategoryId()); 43 | assertEquals("Birds", cat.getName()); 44 | assertEquals("Birds", cat.getDescription()); 45 | assertEquals("cat_bird.jpg", cat.getLogo()); 46 | } 47 | 48 | private void assertCategoryList(List cats, String... ids) { 49 | String[] result = new String[cats.size()]; 50 | 51 | int i = 0; 52 | for (Category cat : cats) { 53 | result[i++] = cat.getCategoryId(); 54 | } 55 | 56 | Arrays.sort(result); 57 | Arrays.sort(ids); 58 | 59 | assertArrayEquals(ids, result); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /petstore/dal/src/test/java/com/alibaba/sample/petstore/dal/dao/SequenceDaoTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.dal.dao; 19 | 20 | import static org.junit.Assert.*; 21 | 22 | import org.junit.Test; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | 25 | public class SequenceDaoTests extends AbstractDataAccessTests { 26 | @Autowired 27 | private SequenceDao sequenceDao; 28 | 29 | @Test(expected = IllegalArgumentException.class) 30 | public void getNextId_illegalName() { 31 | sequenceDao.getNextId("nonexist"); 32 | } 33 | 34 | @Test 35 | public void getNextId() { 36 | assertEquals(1000, sequenceDao.getNextId("ordernum")); 37 | assertEquals(1001, sequenceDao.getNextId("ordernum")); 38 | assertEquals(1002, sequenceDao.getNextId("ordernum")); 39 | 40 | assertEquals(1000, sequenceDao.getNextId("orderitemnum")); 41 | assertEquals(1001, sequenceDao.getNextId("orderitemnum")); 42 | assertEquals(1002, sequenceDao.getNextId("orderitemnum")); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/common/PetstoreConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.common; 19 | 20 | /** 21 | * Petstore WEB层的常量。 22 | * 23 | * @author Michael Zhou 24 | */ 25 | public interface PetstoreConstant { 26 | /** 在session中保存petstore用户对象的key。 */ 27 | String PETSTORE_USER_SESSION_KEY = "petstoreUser"; 28 | 29 | /** 在session中保存shopping cart对象的key。 */ 30 | String PETSTORE_CART_KEY = "petstoreCart"; 31 | 32 | /** Login页面返回URL的key。 */ 33 | String LOGIN_RETURN_KEY = "return"; 34 | 35 | /** 如果未指定return,登录以后就跳到该URL。 */ 36 | String LOGIN_RETURN_DEFAULT_LINK = "petstoreHomeLink"; 37 | 38 | /** 登录URL的名字。 */ 39 | String PETSTORE_LOGIN_LINK = "petstoreLoginLink"; 40 | 41 | /** 登记用户URL的名字。 */ 42 | String PETSTORE_REGISTER_LINK = "petstoreRegisterLink"; 43 | 44 | /** 登记用户信息URL的名字。 */ 45 | String PETSTORE_REGISTER_ACCOUNT_LINK = "petstoreRegisterAccountLink"; 46 | 47 | /** 查看用户信息URL的名字。 */ 48 | String PETSTORE_ACCOUNT_LINK = "petstoreAccountLink"; 49 | } 50 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/common/PetstoreUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.common; 19 | 20 | import static com.alibaba.citrus.util.Assert.*; 21 | import static com.alibaba.citrus.util.BasicConstant.*; 22 | import static com.alibaba.citrus.util.ObjectUtil.*; 23 | import static com.alibaba.citrus.util.StringUtil.*; 24 | 25 | import java.io.Serializable; 26 | 27 | public class PetstoreUser implements Serializable { 28 | private static final long serialVersionUID = -7507510429755782596L; 29 | private static final ThreadLocal userHolder = new ThreadLocal(); 30 | private String userId; 31 | private String[] roles; 32 | 33 | public static final PetstoreUser getCurrentUser() { 34 | return userHolder.get(); 35 | } 36 | 37 | public static final void setCurrentUser(PetstoreUser user) { 38 | userHolder.set(user); 39 | } 40 | 41 | /** 创建匿名用户。 */ 42 | public PetstoreUser() { 43 | } 44 | 45 | /** 创建用户。 */ 46 | public PetstoreUser(String userId) { 47 | this.userId = trimToNull(userId); 48 | } 49 | 50 | public String getId() { 51 | return userId; 52 | } 53 | 54 | public String[] getRoles() { 55 | return defaultIfNull(roles, EMPTY_STRING_ARRAY); 56 | } 57 | 58 | public void setRoles(String[] roles) { 59 | this.roles = roles; 60 | } 61 | 62 | public void upgrade(String userId, String[] roles) { 63 | assertTrue(!hasLoggedIn(), ExceptionType.ILLEGAL_STATE, "already logged in"); 64 | 65 | userId = assertNotNull(trimToNull(userId), "no user id"); 66 | 67 | this.userId = userId; 68 | this.roles = roles; 69 | } 70 | 71 | public boolean hasLoggedIn() { 72 | return userId != null; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "PetstoreUser[" + defaultIfNull(userId, "anonymous") + ", roles=" + join(getRoles(), ":") + "]"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/common/util/PetstoreUserTool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.common.util; 19 | 20 | import com.alibaba.citrus.service.pull.ToolFactory; 21 | import com.alibaba.sample.petstore.web.common.PetstoreUser; 22 | 23 | public class PetstoreUserTool implements ToolFactory { 24 | public boolean isSingleton() { 25 | return false; 26 | } 27 | 28 | public Object createTool() throws Exception { 29 | return PetstoreUser.getCurrentUser(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/home/module/screen/Redirect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.home.module.screen; 19 | 20 | import com.alibaba.citrus.turbine.Navigator; 21 | import com.alibaba.citrus.turbine.dataresolver.Param; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | /** 26 | * 外部重定向,用来示范redirect token的使用方法。 27 | * 28 | * @author Michael Zhou 29 | */ 30 | public class Redirect { 31 | private final static Logger log = LoggerFactory.getLogger(Redirect.class); 32 | 33 | public void execute(@Param("location") String location, Navigator nav) { 34 | if (location != null) { 35 | log.info("Redirect to location which is not in whitelist: {}", location); 36 | nav.redirectToLocation(location); 37 | } else { 38 | nav.forwardTo("homepage"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/servlet/GetLoginUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.servlet; 19 | 20 | import static com.alibaba.sample.petstore.web.common.PetstoreConstant.*; 21 | 22 | import java.io.IOException; 23 | import java.io.PrintWriter; 24 | import javax.servlet.ServletException; 25 | import javax.servlet.http.HttpServlet; 26 | import javax.servlet.http.HttpServletRequest; 27 | import javax.servlet.http.HttpServletResponse; 28 | 29 | import com.alibaba.sample.petstore.web.common.PetstoreUser; 30 | 31 | /** 32 | * 这个简单的servlet用来演示如何在普通的servlet中访问webx所管理的request/response/session等对象。你需要在webx 33 | * framework filter的配置中,为这个servlet添加一个passthru过滤。 34 | * 35 | * @author Michael Zhou 36 | */ 37 | public class GetLoginUser extends HttpServlet { 38 | private static final long serialVersionUID = 8852358774890544749L; 39 | 40 | @Override 41 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 42 | throws ServletException, IOException { 43 | response.setContentType("text/plain; charset=UTF-8"); 44 | 45 | PrintWriter out = response.getWriter(); 46 | PetstoreUser user = (PetstoreUser) request.getSession().getAttribute(PETSTORE_USER_SESSION_KEY); 47 | 48 | if (user != null && user.hasLoggedIn()) { 49 | out.print(user.getId()); 50 | } else { 51 | out.print("guest"); 52 | } 53 | 54 | out.flush(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/action/AddProductAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.action; 19 | 20 | import com.alibaba.citrus.service.form.Group; 21 | import com.alibaba.citrus.turbine.Navigator; 22 | import com.alibaba.citrus.turbine.dataresolver.FormGroup; 23 | import com.alibaba.citrus.turbine.dataresolver.Param; 24 | import com.alibaba.sample.petstore.biz.DuplicatedProductException; 25 | import com.alibaba.sample.petstore.biz.StoreManager; 26 | import com.alibaba.sample.petstore.dal.dataobject.Product; 27 | import org.apache.commons.fileupload.FileItem; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | 30 | public class AddProductAction { 31 | @Autowired 32 | private StoreManager storeManager; 33 | 34 | public void doAdd(@FormGroup("addProduct") Group group, @Param("categoryId") String catId, Navigator nav) 35 | throws Exception { 36 | Product product = new Product(); 37 | FileItem picture = group.getField("picture").getFileItem(); 38 | 39 | group.setProperties(product); 40 | 41 | try { 42 | storeManager.addProduct(product, catId, picture); 43 | nav.redirectTo("storeModule").withTarget("edit/categoryList"); 44 | } catch (DuplicatedProductException e) { 45 | group.getField("productId").setMessage("duplicatedProductId"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/control/CategoryList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.control; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.citrus.turbine.Context; 23 | import com.alibaba.sample.petstore.biz.StoreManager; 24 | import com.alibaba.sample.petstore.dal.dataobject.Category; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | 27 | public class CategoryList { 28 | @Autowired 29 | private StoreManager storeManager; 30 | 31 | public void execute(Context context) throws Exception { 32 | List cats = storeManager.getAllCategories(); 33 | 34 | context.put("cats", cats); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/screen/AddProduct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.screen; 19 | 20 | import com.alibaba.citrus.turbine.Context; 21 | import com.alibaba.citrus.turbine.dataresolver.Param; 22 | import com.alibaba.sample.petstore.biz.StoreManager; 23 | import com.alibaba.sample.petstore.dal.dataobject.Category; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | 26 | public class AddProduct { 27 | @Autowired 28 | private StoreManager storeManager; 29 | 30 | public void execute(@Param("categoryId") String categoryId, Context context) throws Exception { 31 | Category category = storeManager.getCategory(categoryId); 32 | 33 | context.put("category", category); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/screen/CategoryList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.screen; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.citrus.turbine.Context; 23 | import com.alibaba.sample.petstore.biz.StoreManager; 24 | import com.alibaba.sample.petstore.dal.dataobject.Category; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | 27 | public class CategoryList { 28 | @Autowired 29 | private StoreManager storeManager; 30 | 31 | public void execute(Context context) throws Exception { 32 | List cats = storeManager.getAllCategories(); 33 | 34 | context.put("cats", cats); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/screen/ItemList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.screen; 19 | 20 | import java.util.List; 21 | 22 | import com.alibaba.citrus.turbine.Context; 23 | import com.alibaba.citrus.turbine.dataresolver.Param; 24 | import com.alibaba.sample.petstore.biz.StoreManager; 25 | import com.alibaba.sample.petstore.dal.dao.CategoryDao; 26 | import com.alibaba.sample.petstore.dal.dao.ProductDao; 27 | import com.alibaba.sample.petstore.dal.dataobject.Category; 28 | import com.alibaba.sample.petstore.dal.dataobject.Product; 29 | import com.alibaba.sample.petstore.dal.dataobject.ProductItem; 30 | import org.springframework.beans.factory.annotation.Autowired; 31 | 32 | public class ItemList { 33 | @Autowired 34 | private StoreManager storeManager; 35 | 36 | @Autowired 37 | private ProductDao productDao; 38 | 39 | @Autowired 40 | private CategoryDao categoryDao; 41 | 42 | public void execute(@Param("productId") String productId, Context context) throws Exception { 43 | List items = storeManager.getAllProductItems(productId); 44 | Product product = productDao.getProductById(productId); 45 | Category category = categoryDao.getCategoryById(product.getCategoryId()); 46 | 47 | context.put("category", category); 48 | context.put("product", product); 49 | context.put("items", items); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/store/module/screen/ViewCart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.store.module.screen; 19 | 20 | import static com.alibaba.sample.petstore.web.common.PetstoreConstant.*; 21 | 22 | import javax.servlet.http.HttpSession; 23 | 24 | import com.alibaba.citrus.turbine.Context; 25 | import com.alibaba.sample.petstore.biz.StoreManager; 26 | import com.alibaba.sample.petstore.dal.dataobject.Cart; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | 29 | public class ViewCart { 30 | @Autowired 31 | private StoreManager storeManager; 32 | 33 | public void execute(HttpSession session, Context context) throws Exception { 34 | Cart cart = (Cart) session.getAttribute(PETSTORE_CART_KEY); 35 | 36 | if (cart == null) { 37 | cart = new Cart(); 38 | } 39 | 40 | cart = storeManager.getCartItems(cart); 41 | 42 | context.put("cart", cart); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/user/module/screen/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.user.module.screen; 19 | 20 | import com.alibaba.citrus.turbine.Context; 21 | import com.alibaba.sample.petstore.biz.UserManager; 22 | import com.alibaba.sample.petstore.dal.dataobject.User; 23 | import com.alibaba.sample.petstore.web.common.PetstoreUser; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | 26 | public class Account { 27 | @Autowired 28 | private UserManager userManager; 29 | 30 | public void execute(Context context) throws Exception { 31 | User user = userManager.getUser(PetstoreUser.getCurrentUser().getId()); 32 | context.put("user", user); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /petstore/web/src/main/java/com/alibaba/sample/petstore/web/user/module/screen/RegisterAccount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2012 Alibaba Group Holding Limited. 3 | * All rights reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.alibaba.sample.petstore.web.user.module.screen; 19 | 20 | import com.alibaba.citrus.turbine.Context; 21 | import com.alibaba.sample.petstore.biz.UserManager; 22 | import com.alibaba.sample.petstore.dal.dataobject.User; 23 | import com.alibaba.sample.petstore.web.common.PetstoreUser; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | 26 | public class RegisterAccount { 27 | @Autowired 28 | private UserManager userManager; 29 | 30 | public void execute(Context context) throws Exception { 31 | User user = userManager.getUser(PetstoreUser.getCurrentUser().getId()); 32 | context.put("user", user); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/META-INF/autoconf/auto-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/common/pipeline-exception.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/common/resources.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/common/webx-component.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/home/form.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | 提交的数据已过期 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | System.out 5 | ${loggingCharset} 6 | 7 | 10 | 11 | 12 | INFO 13 | 14 | 15 | 16 | 17 | System.err 18 | ${loggingCharset} 19 | 20 | 23 | 24 | 25 | WARN 26 | 27 | 28 | 29 | 30 | ${loggingRoot}/${localHost}/petstore.log 31 | ${loggingCharset} 32 | false 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | loggingRoot 10 | ${petstore.loggingRoot} 11 | 12 | 13 | loggingLevel 14 | ${petstore.loggingLevel} 15 | 16 | 17 | loggingCharset 18 | UTF-8 19 | 20 | 21 | 22 | com.alibaba.citrus.logconfig.LogConfiguratorListener 23 | 24 | 25 | 26 | 27 | com.alibaba.citrus.webx.context.WebxContextLoaderListener 28 | 29 | 30 | 31 | mdc 32 | com.alibaba.citrus.webx.servlet.SetLoggingContextFilter 33 | 34 | 35 | 36 | webx 37 | com.alibaba.citrus.webx.servlet.WebxFrameworkFilter 38 | 39 | 43 | excludes 44 | *.html, *.jpg, *.gif, *.png, !/petstore/images 45 | 46 | 47 | 52 | passthru 53 | /getloginuser 54 | 55 | 56 | 57 | 58 | mdc 59 | /* 60 | 61 | 62 | 63 | webx 64 | /* 65 | 66 | 67 | 68 | getLoginUser 69 | com.alibaba.sample.petstore.web.servlet.GetLoginUser 70 | 71 | 72 | 73 | getLoginUser 74 | /getloginuser 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/webx-home.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | home 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/webx-store.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | store 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 | 46 | action.* 47 | 48 | 49 | action.CartAction.* 50 | 51 | 52 | 53 | 54 | * 55 | 56 | 57 | * 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/WEB-INF/webx-user.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | user 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 48 | 49 | 50 | 51 | 52 | * 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/common/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $error 5 | 6 | 7 |

$error

8 | $screen_placeholder 9 | 10 | 11 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/common/templates/macros.vm: -------------------------------------------------------------------------------- 1 | #** ------------------------------------------- 2 | * 显示所有headers 3 | * -------------------------------------------- *# 4 | #macro (showHead $defaultTitle) 5 | 6 | #showTitle ($defaultTitle) 7 | #showMetaTags () 8 | #showHttpEquiv () 9 | #showStylesheets () 10 | #showJavascripts () 11 | 12 | #end 13 | 14 | #** ------------------------------------------- 15 | * 显示标题,如果未提供标题,则使用默认值 16 | * -------------------------------------------- *# 17 | #macro (showTitle $defaultTitle) 18 | 19 | #if( $page.title != "" ) 20 | $page.title 21 | #else 22 | $!defaultTitle 23 | #end 24 | 25 | #end 26 | 27 | #** ------------------------------------------- 28 | * 显示meta tags 29 | * -------------------------------------------- *# 30 | #macro (showMetaTags) 31 | 32 | #foreach($metaTag in $page.metaTags.keySet()) 33 | 34 | #end 35 | 36 | #end 37 | 38 | #** ------------------------------------------- 39 | * 显示meta http-equiv 40 | * -------------------------------------------- *# 41 | #macro (showHttpEquiv) 42 | 43 | #foreach($httpEquiv in $page.httpEquivs.keySet()) 44 | 45 | #end 46 | 47 | #end 48 | 49 | #** ------------------------------------------- 50 | * 显示stylesheets 51 | * -------------------------------------------- *# 52 | #macro (showStylesheets) 53 | 54 | #foreach( $styleSheet in $page.styleSheets ) 55 | 59 | #end 60 | 61 | #end 62 | 63 | #** ------------------------------------------- 64 | * 显示javascripts 65 | * -------------------------------------------- *# 66 | #macro (showJavascripts) 67 | 68 | #foreach( $script in $page.scripts ) 69 | 70 | #end 71 | 72 | #end 73 | 74 | 75 | #** ------------------------------------------- 76 | * 显示body attributes 77 | * -------------------------------------------- *# 78 | #macro (bodyAttributes) 79 | 80 | #foreach( $attributeName in $page.bodyAttributes.keySet() ) 81 | $attributeName="$page.bodyAttributes.get($attributeName)" 82 | #end 83 | 84 | #end 85 | 86 | #** ------------------------------------------- 87 | * 显示select box 88 | * -------------------------------------------- *# 89 | #macro (select $name $map $selected $hint) 90 | 91 | #set ($_map = $map) 92 | #set ($_selected = $selected) 93 | 101 | 102 | #end 103 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/common/templates/screen/error.vm: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/css/petstore-common.css: -------------------------------------------------------------------------------- 1 | body, p, th, td, input, select, textarea { 2 | font-size: 12px; 3 | color: #111111; 4 | } 5 | 6 | body { 7 | margin: 20px; 8 | padding: 0px 10px 0px 10px; 9 | text-align: center; 10 | } 11 | 12 | table { 13 | text-align: left; 14 | } 15 | 16 | p { 17 | margin: 15px 0px 15px 0px; 18 | padding: 3px 0px 3px 0px; 19 | } 20 | 21 | hr { 22 | border: #000000 0px solid; 23 | border-top: #D1D7DC 1px solid; 24 | height: 0px; 25 | } 26 | 27 | img { 28 | border: 0px; 29 | } 30 | 31 | form { 32 | margin: 0; 33 | padding: 0; 34 | } 35 | 36 | a:Link, a:Visited { 37 | color: #0044DD; 38 | text-decoration: none; 39 | } 40 | 41 | a:Hover, a:Active { 42 | color: #FF5500; 43 | text-decoration: underline; 44 | } -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/css/petstore-homepage.css: -------------------------------------------------------------------------------- 1 | .box { 2 | border-top: 2px solid #ff9000; 3 | border-bottom: 1px solid #ff9000; 4 | border-left: 1px solid #ff9000; 5 | border-right: 1px solid #ff9000; 6 | background-image: url(../images/bg_topline.png); 7 | background-repeat: repeat-x; 8 | } 9 | 10 | .selected { 11 | text-align: left; 12 | vertical-align: bottom; 13 | } 14 | 15 | .selected .tabLeft { 16 | background-image: url(../images/tab_selected_left.png); 17 | background-repeat: no-repeat; 18 | background-position: right bottom; 19 | } 20 | 21 | .selected .tabMid { 22 | background-image: url(../images/tab_selected_mid.png); 23 | background-repeat: repeat-x; 24 | vertical-align: bottom; 25 | font-weight: bold; 26 | color: #ffffff; 27 | background-position: bottom; 28 | } 29 | 30 | .selected .tabRight { 31 | background-image: url(../images/tab_selected_right.png); 32 | background-repeat: no-repeat; 33 | background-position: left bottom; 34 | } 35 | 36 | .unselected { 37 | text-align: left; 38 | vertical-align: bottom; 39 | } 40 | 41 | .unselected .tabLeft { 42 | background-image: url(../images/tab_left.png); 43 | background-repeat: no-repeat; 44 | background-position: right bottom; 45 | } 46 | 47 | .unselected .tabMid { 48 | background-image: url(../images/tab_mid.png); 49 | background-repeat: repeat-x; 50 | vertical-align: bottom; 51 | background-position: bottom; 52 | color: #ff9000 53 | } 54 | 55 | .unselected .tabRight { 56 | background-image: url(../images/tab_right.png); 57 | background-repeat: no-repeat; 58 | background-position: left bottom; 59 | } 60 | 61 | .shortcut { 62 | color: #0000FF; 63 | white-space: nowrap; 64 | } 65 | 66 | .errorMessage { 67 | color: #FF0000; 68 | white-space: nowrap; 69 | font-weight: bold; 70 | } -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/bg_topline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/bg_topline.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/btn_login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/btn_login.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/cart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/cart.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/dot_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/dot_transparent.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/logo_alibaba.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/logo_alibaba.gif -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/logo_petstore_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/logo_petstore_big.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/logo_petstore_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/logo_petstore_small.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/logo_webx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/logo_webx.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/logo_webx_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/logo_webx_small.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/petstore_title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/petstore_title.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_left.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_mid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_mid.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_right.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_selected_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_selected_left.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_selected_mid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_selected_mid.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/images/tab_selected_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/home/images/tab_selected_right.png -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/control/bottom.vm: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 |
6 |

7 | 网上贸易 尽在阿里巴巴: 中国站 | 国际站 | 日文站 | 淘宝站 | 支付宝 8 |

9 |

10 | Copyright © 1999-2005 Alibaba.com Corporation and its licensors. All rights reserved. 11 |

12 |
19 |
20 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/control/nav.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | 16 | 19 | 22 | 25 | 28 | 31 | 34 | 35 |
4 | 注册 5 | 7 |    |    8 | 10 | #if ($petstoreUser.hasLoggedIn()) 11 | 退出 $petstoreUser.id 12 | #else 13 | 登录 14 | #end 15 | 17 |    |    18 | 20 | 用户信息 21 | 23 |    |    24 | 26 | 我的购物车 27 | 29 |    |    30 | 32 | 库存管理 33 |
36 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/control/tabs.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 17 | 18 |
4 | 5 | 6 | 7 | 8 | 9 |
宠物类目
11 | 12 | 13 | 14 | 15 | 16 |
搜索宠物
19 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/control/top.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
$control.setTemplate("nav")

 
-------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/control/topNoLogo.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
$control.setTemplate("nav")

 
13 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #showHead ("Petstore Sample") 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 25 | 26 | 40 | 41 | 42 | 43 | 44 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
 
$control.setTemplate("user:login")
27 | $control.setTemplate("topNoLogo") 28 | 29 | 30 | 31 | 32 | 33 | 38 | 39 |
$control.setTemplate("tabs")
34 | 35 | 36 | 37 |
$screen_placeholder
$control.setTemplate("bottom")
45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/home/templates/screen/homepage.vm: -------------------------------------------------------------------------------- 1 | $page.setTitle("Welcome to Petstore!") 2 | 3 | $control.setTemplate("store:categoryList") 4 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/css/petstore-store.css: -------------------------------------------------------------------------------- 1 | .categoryName { 2 | FONT-WEIGHT: bold; 3 | FONT-SIZE: x-large; 4 | COLOR: #000099; 5 | FONT-FAMILY: "Times New Roman", Times, serif; 6 | border-top-width: 1px; 7 | border-right-width: 1px; 8 | border-bottom-width: 1px; 9 | border-left-width: 1px; 10 | border-top-style: none; 11 | border-right-style: none; 12 | border-bottom-style: solid; 13 | border-left-style: none; 14 | border-top-color: #999999; 15 | border-right-color: #999999; 16 | border-bottom-color: #999999; 17 | border-left-color: #999999; 18 | padding-bottom: 10px; 19 | } 20 | 21 | .subcategoryName { 22 | FONT-WEIGHT: normal; 23 | FONT-SIZE: small; 24 | COLOR: #333333; 25 | FONT-FAMILY: Arial, Helvetica, sans-serif 26 | } 27 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/bird1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/bird1.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/bird4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/bird4.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat1.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat3.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat_bird.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat_bird.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat_cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat_cat.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat_dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat_dog.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat_fish.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat_fish.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/cat_reptile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/cat_reptile.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/dog1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/dog1.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/dog2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/dog2.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/dog4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/dog4.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/dog5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/dog5.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/dog6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/dog6.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/fish1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/fish1.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/fish2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/fish2.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/fish3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/fish3.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/fish4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/fish4.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/lizard2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/lizard2.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/images/lizard3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webx/citrus-sample/12543a11d6ce61327bcfdcb7c5836adabc85f136/petstore/web/src/main/webapp/store/images/lizard3.jpg -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/control/categoryList.vm: -------------------------------------------------------------------------------- 1 | $page.addStyleSheet("$storeContent.getURI('css/petstore-store.css')") 2 | 3 | #foreach ($cat in $cats) 4 | 5 | 6 | 7 | 15 | 16 |
8 |
$cat.name
9 |
10 | #foreach ( $prod in $cat.productList) 11 | #if($velocityCount > 1) | #end 12 | $prod.name 13 | #end 14 |
17 | #end -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #showHead ("Petstore Sample") 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 24 | 25 | 26 | 27 | 28 |
$control.setTemplate("home:top")
18 | 19 | 20 | 21 | 22 |
$screen_placeholder
23 |
$control.setTemplate("home:bottom")
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/categoryList.vm: -------------------------------------------------------------------------------- 1 | $control.setTemplate("categoryList") -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/edit/addProduct.vm: -------------------------------------------------------------------------------- 1 | #macro (addProductMessage $field) 2 | #if (!$field.valid) $field.message #end 3 | #end 4 | 5 |
6 | $csrfToken.hiddenField 7 | 8 | 9 | 10 | #set ($group = $form.addProduct.defaultInstance) 11 | 12 | 13 | 14 | 17 | 18 | 19 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
添加产品
15 |
16 |
20 | 21 | 22 | 25 | 26 | 27 | 28 | 31 | 34 | 35 | 36 | 37 | 40 | 43 | 44 | 45 | 46 | 49 | 52 | 53 | 54 | 55 | 58 | 61 | 62 |
产品类别: 23 | $category.name 24 |
产品ID: 29 | 30 | 32 | #addProductMessage ($group.productId) 33 |
产品名称: 38 | 39 | 41 | #addProductMessage ($group.name) 42 |
产品描述: 47 | 48 | 50 | #addProductMessage ($group.description) 51 |
产品图片: 56 | 57 | 59 | #addProductMessage ($group.picture) 60 |

71 | 72 |
73 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/edit/categoryList.vm: -------------------------------------------------------------------------------- 1 | $page.addStyleSheet("$storeContent.getURI('css/petstore-store.css')") 2 | 3 | #foreach ($cat in $cats) 4 | 5 | 6 | 7 | 23 | 24 |
8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 |
$cat.name
14 | #foreach ( $prod in $cat.productList) 15 | #if($velocityCount > 1) | #end 16 | $prod.name 17 | #end 18 |
22 |
25 | #end 26 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/edit/itemList.vm: -------------------------------------------------------------------------------- 1 | $page.addStyleSheet("$storeContent.getURI('css/petstore-store.css')") 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 32 | 33 |
$category.name
$product.name - $product.description
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | #foreach($item in $items) 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | #end 30 |
ID单价描述库存数量 
$item.productItemId$item.listPrice$item.attribute1$item.quantity[修改]
31 |
34 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/itemList.vm: -------------------------------------------------------------------------------- 1 | $page.addStyleSheet("$storeContent.getURI('css/petstore-store.css')") 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 | 42 | 43 |
$category.name
$product.name - $product.description 10 | #if ($itemAdded) 11 | | 已加入购物车,您可以 [继续购物] 12 | #end 13 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | #foreach($item in $items) 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | #end 34 | 35 | 36 | 39 | 40 |
ID单价描述库存数量 
$item.productItemId$item.listPrice$item.attribute1$item.quantity
37 | 38 |
41 |
44 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/store/templates/screen/viewCart.vm: -------------------------------------------------------------------------------- 1 | $page.addStyleSheet("$storeContent.getURI('css/petstore-store.css')") 2 | 3 | 4 | 5 | 6 | 7 | 8 | 72 | 73 |
我的购物车
9 |
10 | $csrfToken.hiddenField 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | #if ($cart.cartItemList.empty) 25 | 26 | 27 | 28 | #else 29 | #foreach($cartItem in $cart.cartItemList) 30 | #set ($item = $cartItem.productItem) 31 | #set ($group = $form.cartItem.getInstance($item.productItemId)) 32 | 33 | $group.mapTo($cartItem) 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 50 | 51 | #end 52 | 53 | 54 | 55 | 56 | 57 | #end 58 | 59 | 60 | 68 | 69 |
图片ID名称描述单价数量小计 
购物车是空的。
$item.productItemId$item.product.category.description,$item.product.description$item.attribute1$item.listPrice 42 | #if (!$group.quantity.valid) $group.quantity.message
#end 43 | 44 |
$messageUtil.formatMessage("{0,number}", $cartItem.total) 47 | #set ($removeURL = $storeModule.setTarget("viewCart").setAction("cartAction").addQueryData("itemId", $item.productItemId).addQueryData("eventSubmitDoRemoveItem", "true")) 48 | 49 |
 

总计:$messageUtil.formatMessage("{0,number}", $cart.total)
 
61 | 62 | #if (!$cart.cartItemList.empty) 63 | 64 | 65 | 66 | #end 67 |
70 |
71 |
74 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/user/css/petstore-user.css: -------------------------------------------------------------------------------- 1 | .subtitle { 2 | FONT-WEIGHT: bold; 3 | FONT-SIZE: large; 4 | COLOR: #000000; 5 | FONT-FAMILY: "Times New Roman", Times, serif; 6 | background-color: #CCCCCC; 7 | padding: 5px; 8 | } 9 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/user/templates/control/login.vm: -------------------------------------------------------------------------------- 1 | #macro (loginMessage $field) 2 | #if (!$field.valid) $field.message #end 3 | #end 4 | 5 |
6 | $csrfToken.hiddenField 7 | 8 | 9 | 10 | #set ($group = $form.login.defaultInstance) 11 | 12 | 13 | 14 | 20 | 21 | 22 | 42 | 43 | 44 | 45 | 46 | 47 | 53 | 54 |
用户登录
15 |
16 |
17 | #loginMessage ($group.loginError) 18 |
19 |
23 | 24 | 25 | 28 | 31 | 32 | 33 | 34 | 37 | 40 | 41 |
用户名: 26 | 27 | 29 | #loginMessage ($group.userId) 30 |
密码: 35 | 36 | 38 | #loginMessage ($group.password) 39 |

48 | 49 | 50 | 51 | 52 |
还没有注册过吗?
赶快注册!
55 | 56 |
57 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/user/templates/layout/default.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #showHead ("Petstore Sample") 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
$control.setTemplate("home:top")
$screen_placeholder
$control.setTemplate("home:bottom")
23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/user/templates/screen/login.vm: -------------------------------------------------------------------------------- 1 | $control.setTemplate("login") -------------------------------------------------------------------------------- /petstore/web/src/main/webapp/user/templates/screen/register.vm: -------------------------------------------------------------------------------- 1 | #macro (registerMessage $field) 2 | #if (!$field.valid) $field.message #end 3 | #end 4 | 5 |
6 | $csrfToken.hiddenField 7 | 8 | 9 | #set ($group = $form.register.defaultInstance) 10 | 11 | 12 | 13 | 19 | 20 | 21 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
用户注册
14 |
15 |
16 | #registerMessage ($group.registerError) 17 |
18 |
22 | 23 | 24 | 27 | 30 | 31 | 32 | 33 | 36 | 39 | 40 | 41 | 42 | 45 | 48 | 49 |
用户名: 25 | 26 | 28 | #registerMessage ($group.userId) 29 |
密码: 34 | 35 | 37 | #registerMessage ($group.password) 38 |
再输一遍密码: 43 | 44 | 46 | #registerMessage ($group.passwordConfirm) 47 |

58 | 59 |
60 | --------------------------------------------------------------------------------