├── .classpath ├── .gitattributes ├── .gitignore ├── .lock ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── .travis.yml ├── Dockerfile ├── LICENSE ├── Procfile ├── README.md ├── bin ├── dispatcher └── dispatcher.cmd ├── build.xml ├── example.png ├── favicon.png ├── mover.log ├── mvnw ├── mvnw.cmd ├── pom.xml ├── scripts ├── bootstrap │ ├── bootstrap.min.css │ ├── bootstrap.min.js │ ├── fileinput │ │ ├── fileinput.js │ │ └── loading.gif │ ├── ie-emulation-modes-warning.js │ └── ie10-viewport-bug-workaround.js ├── firebug-lite.js ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 ├── jquery-1.11.3.min.js ├── jquery-2.0.3.js ├── jquery.level.js ├── jquery.menu.css ├── jquery.menu.js ├── struct.js ├── timer.js └── tools.js └── src ├── main ├── java │ ├── ApplicationGenerator.java │ ├── custom │ │ └── objects │ │ │ ├── Account.java │ │ │ ├── User.java │ │ │ ├── article.java │ │ │ └── book.java │ └── tinystruct │ │ └── examples │ │ ├── RequestMerger.java │ │ ├── bible.java │ │ ├── dateConverter.java │ │ ├── distributedLockApp.java │ │ ├── error.java │ │ ├── example.java │ │ ├── firstApplication.java │ │ ├── hello.java │ │ ├── image2.java │ │ ├── rabbitmq.java │ │ ├── redirectChecker.java │ │ ├── redis.java │ │ ├── startup.java │ │ └── time.java └── resources │ ├── application.properties │ └── themes │ ├── hello.view │ ├── reading.view │ ├── smalltalk.view │ ├── startup.view │ ├── time.view │ └── tinyeditor.view ├── test └── tinystruct │ └── examples │ └── rabbitmqTest.java └── tinystruct └── examples └── smalltalk.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.java linguist-detectable=true 2 | *.js linguist-detectable=false 3 | *.html linguist-detectable=false 4 | *.xml linguist-detectable=false 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath -------------------------------------------------------------------------------- /.lock: -------------------------------------------------------------------------------- 1 | {"installed":{"smile":"tinystruct.examples.hello","users":"tinystruct.examples.firstApplication","version":"tinystruct.examples.firstApplication","tinyeditor":"tinystruct.examples.tinyeditor","user":"tinystruct.examples.firstApplication","youhappy":"tinystruct.examples.firstApplication","info":"tinystruct.examples.error","time/update":"tinystruct.examples.time","read":"tinystruct.examples.firstApplication","startup":"tinystruct.examples.startup","generate":"tinystruct.examples.firstApplication","time/start":"tinystruct.examples.time","time":"tinystruct.examples.time","say":"tinystruct.examples.firstApplication","tinyeditor/version":"tinystruct.examples.tinyeditor","time/stop":"tinystruct.examples.time","tinyeditor/update":"tinystruct.examples.tinyeditor","praise":"tinystruct.examples.firstApplication","tinyeditor/save":"tinystruct.examples.tinyeditor","error":"tinystruct.examples.error"},"updated":true} -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain RequestMerger copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.5"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain RequestMerger downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains RequestMerger custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tinystruct2.0 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Mar 11 10:10:37 CST 2013 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Tue Feb 19 12:46:19 CST 2013 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | VOLUME /tmp 3 | ADD master.zip /example/ 4 | WORKDIR /example/ 5 | RUN unzip master.zip 6 | WORKDIR /example/tinystruct2.0-master 7 | CMD ["./bin/dispatcher","--import-applications=org.tinystruct.system.TomcatServer", "--server-port=777", "--start-server"] 8 | EXPOSE 777 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 James Zhou 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bin/dispatcher --start-server --import-applications=org.tinystruct.system.TomcatServer --server-port=$PORT 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | tinystruct framework 4 | ========= 5 | [![Build Status](https://travis-ci.org/m0ver/tinystruct-examples.svg?branch=master)](https://travis-ci.org/m0ver/tinystruct2.0) 6 | 7 | This is an example project based on tinystruct framework, it supports both C/S application and B/S web application development. 8 | 9 | 10 | 11 | To execute it in CLI mode 12 | --- 13 | ```tcsh 14 | $ bin/dispatcher --version 15 | 16 | _/ ' _ _/ _ _ _/ 17 | / / /) (/ _) / / (/ ( / 1.4.5 18 | / 19 | ``` 20 | ```tcsh 21 | $ bin/dispatcher --help 22 | Usage: bin/dispatcher COMMAND [OPTIONS] 23 | Commands: 24 | download Download a resource from other servers 25 | exec To execute native command(s) 26 | generate POJO object generator 27 | install Install a package 28 | open Start a default browser to open the specific URL 29 | say Output words 30 | set Set system property 31 | sql-execute Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. 32 | sql-query Executes the given SQL statement, which returns a single ResultSet object. 33 | update Update for latest version 34 | 35 | Options: 36 | --allow-remote-access Allow to be accessed remotely 37 | --help Help command 38 | --host Host name / IP 39 | --import Import application 40 | --logo Print logo 41 | --settings Print settings 42 | --version Print version 43 | 44 | Run 'bin/dispatcher COMMAND --help' for more information on a command. 45 | 46 | $ bin/dispatcher say/"Praise to the Lord" 47 | Praise to the Lord 48 | ``` 49 | 50 | Run it in a servlet container 51 | --- 52 | ```tcsh 53 | # bin/dispatcher start --import org.tinystruct.system.TomcatServer 54 | ``` 55 | Run it in docker container 56 | --- 57 | ```tcsh 58 | # wget https://github.com/tinystruct/tinystruct2.0/archive/master.zip 59 | # unzip master.zip 60 | # mv tinystruct2.0-master/Dockerfile . 61 | # docker build -t tinystruct-based:1.0 -f Dockerfile . 62 | # docker run -d -p 777:777 tinystruct-based:1.0 63 | ``` 64 | 65 | You can access the below URLs after deployed the project in Tomcat 6.0+ : 66 | 67 | * http://localhost:777/?q=say/Praise%20to%20the%20Lord!
68 | * http://localhost:777/?q=praise
69 | * http://localhost:777/?q=youhappy
70 | * http://localhost:777/?q=say/%E4%BD%A0%E7%9F%A5%E9%81%93%E5%85%A8%E4%B8%96%E7%95%8C%E6%9C%80%E7%95%85%E9%94%80%E7%9A%84%E4%B9%A6%E6%98%AF%E5%93%AA%E4%B8%80%E6%9C%AC%E4%B9%A6%E5%90%97%EF%BC%9F 71 | 72 | A demonstration for comet technology, without any websocket and support any web browser: 73 | * https://tinystruct.herokuapp.com/?q=talk
74 | 75 |
76 | 77 | Live Demo Site: 78 | * https://tinystruct.herokuapp.com/ 79 | * https://tinystruct.herokuapp.com/?q=say/Praise%20to%20the%20Lord!
80 | * https://tinystruct.herokuapp.com/?q=praise
81 | * https://tinystruct.herokuapp.com/?q=youhappy
82 | * https://tinystruct.herokuapp.com/?q=say/%E4%BD%A0%E7%9F%A5%E9%81%93%E5%85%A8%E4%B8%96%E7%95%8C%E6%9C%80%E7%95%85%E9%94%80%E7%9A%84%E4%B9%A6%E6%98%AF%E5%93%AA%E4%B8%80%E6%9C%AC%E4%B9%A6%E5%90%97%EF%BC%9F 83 | 84 | Results in your browser should be: 85 | 86 |
87 |

Praise to the Lord!

88 | Praise to the Lord! 89 | true 90 |

你知道全世界最畅销的书是哪一本书吗?

91 |
92 | 93 | Explore it 94 | -- 95 | * Please read more example code in the project. 96 | * Also please see this project: 97 | https://github.com/m0ver/mobile1.0 98 | http://ingod.asia 99 | 100 | 101 | License 102 | -- 103 | 104 | Licensed under the Apache License, Version 2.0 (the "License"); 105 | you may not use this file except in compliance with the License. 106 | You may obtain a copy of the License at 107 | 108 | http://www.apache.org/licenses/LICENSE-2.0 109 | 110 | Unless required by applicable law or agreed to in writing, software 111 | distributed under the License is distributed on an "AS IS" BASIS, 112 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 113 | See the License for the specific language governing permissions and 114 | limitations under the License. 115 | 116 | 117 | [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/m0ver/tinystruct2.0/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 118 | -------------------------------------------------------------------------------- /bin/dispatcher: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ROOT="$(pwd)" 3 | VERSION="1.4.5" 4 | cd "$(dirname "$0")" || exit 5 | cd "../" 6 | # Navigate to the root directory 7 | cd "$ROOT" || exit 8 | 9 | # Java options initialization 10 | JAVA_OPTS="" 11 | 12 | # Arguments initialization 13 | args="" 14 | 15 | # Loop through each argument 16 | for arg; do 17 | # Extract the first two characters of the argument 18 | # str=${arg:0:2} 19 | str=$(echo "$arg" | awk '{ string=substr($0, 0, 2); print string; }' ) 20 | 21 | # Check if it starts with '-D' or '-X' 22 | if [ "$str" = "-D" ] || [ "$str" = "-X" ]; then 23 | JAVA_OPTS="$JAVA_OPTS $arg" 24 | else 25 | args="$args $arg" 26 | fi 27 | done 28 | 29 | # Check if the JAR file exists 30 | JAR_FILE="$ROOT/lib/tinystruct-$VERSION-jar-with-dependencies.jar" 31 | [ -f "$JAR_FILE" ] && JAR_FILE="$JAR_FILE:" 32 | 33 | # Check if additional JAR files exist and add them to the classpath 34 | # shellcheck disable=SC2043 35 | for jar_file in "$ROOT"/lib/tinystruct-"$VERSION".jar; do 36 | [ -f "$jar_file" ] && JAR_FILE="$JAR_FILE$jar_file:" 37 | done 38 | 39 | # OS specific support. $var _must_ be set to either true or false. 40 | cygwin=false; 41 | darwin=false; 42 | mingw=false 43 | case "`uname`" in 44 | CYGWIN*) cygwin=true ;; 45 | MINGW*) mingw=true;; 46 | Darwin*) darwin=true 47 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 48 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 49 | if [ -z "$JAVA_HOME" ]; then 50 | if [ -x "/usr/libexec/java_home" ]; then 51 | export JAVA_HOME="`/usr/libexec/java_home`" 52 | else 53 | export JAVA_HOME="/Library/Java/Home" 54 | fi 55 | fi 56 | ;; 57 | esac 58 | 59 | if [ -z "$JAVA_HOME" ] ; then 60 | if [ -r /etc/gentoo-release ] ; then 61 | JAVA_HOME=`java-config --jre-home` 62 | fi 63 | fi 64 | 65 | if [ -z "$M2_HOME" ] ; then 66 | ## resolve links - $0 may be a link to maven's home 67 | PRG="$0" 68 | 69 | # need this for relative symlinks 70 | while [ -h "$PRG" ] ; do 71 | ls=`ls -ld "$PRG"` 72 | link=`expr "$ls" : '.*-> \(.*\)$'` 73 | if expr "$link" : '/.*' > /dev/null; then 74 | PRG="$link" 75 | else 76 | PRG="`dirname "$PRG"`/$link" 77 | fi 78 | done 79 | 80 | saveddir=`pwd` 81 | 82 | M2_HOME=`dirname "$PRG"`/.. 83 | 84 | # make it fully qualified 85 | M2_HOME=`cd "$M2_HOME" && pwd` 86 | 87 | cd "$saveddir" 88 | # echo Using m2 at $M2_HOME 89 | fi 90 | 91 | # For Cygwin, ensure paths are in UNIX format before anything is touched 92 | if $cygwin ; then 93 | [ -n "$M2_HOME" ] && 94 | M2_HOME=`cygpath --unix "$M2_HOME"` 95 | [ -n "$JAVA_HOME" ] && 96 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 97 | [ -n "$CLASSPATH" ] && 98 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 99 | fi 100 | 101 | # For Migwn, ensure paths are in UNIX format before anything is touched 102 | if $mingw ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 107 | # TODO classpath? 108 | fi 109 | 110 | if [ -z "$JAVA_HOME" ]; then 111 | javaExecutable="`which javac`" 112 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 113 | # readlink(1) is not available as standard on Solaris 10. 114 | readLink=`which readlink` 115 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 116 | if $darwin ; then 117 | javaHome="`dirname \"$javaExecutable\"`" 118 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 119 | else 120 | javaExecutable="`readlink -f \"$javaExecutable\"`" 121 | fi 122 | javaHome="`dirname \"$javaExecutable\"`" 123 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 124 | JAVA_HOME="$javaHome" 125 | export JAVA_HOME 126 | fi 127 | fi 128 | fi 129 | 130 | if [ -z "$JAVACMD" ] ; then 131 | if [ -n "$JAVA_HOME" ] ; then 132 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 133 | # IBM's JDK on AIX uses strange locations for the executables 134 | JAVACMD="$JAVA_HOME/jre/sh/java" 135 | else 136 | JAVACMD="$JAVA_HOME/bin/java" 137 | fi 138 | else 139 | JAVACMD="`which java`" 140 | fi 141 | fi 142 | 143 | if [ ! -x "$JAVACMD" ] ; then 144 | echo "Error: JAVA_HOME is not defined correctly." >&2 145 | echo " We cannot execute $JAVACMD" >&2 146 | exit 1 147 | fi 148 | 149 | if [ -z "$JAVA_HOME" ] ; then 150 | echo "Warning: JAVA_HOME environment variable is not set." 151 | fi 152 | 153 | # For Cygwin, switch paths to Windows format before running java 154 | if $cygwin; then 155 | [ -n "$M2_HOME" ] && 156 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 157 | [ -n "$JAVA_HOME" ] && 158 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 159 | [ -n "$CLASSPATH" ] && 160 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 161 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 162 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 163 | fi 164 | 165 | # Check if M2_HOME is not set or is equal to the current project path 166 | if [ -z "$M2_HOME" ] || [ "$M2_HOME" = "$(pwd)" ]; then 167 | # Set M2_HOME to the .m2 folder under the user's home directory 168 | M2_HOME="$HOME/.m2" 169 | fi 170 | 171 | # Add all JAR files under the lib folder to the classpath 172 | for jar_file in "$ROOT"/lib/*.jar; do 173 | CLASSPATH="$CLASSPATH:$jar_file" 174 | done 175 | 176 | # Java execution 177 | $JAVACMD \ 178 | $JAVA_OPTS \ 179 | -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/ \ 180 | -cp "$ROOT/target/classes:$JAR_FILE$CLASSPATH:$ROOT/WEB-INF/lib/*:$ROOT/WEB-INF/classes:$M2_HOME/repository/org/tinystruct/tinystruct/$VERSION/tinystruct-$VERSION-jar-with-dependencies.jar" org.tinystruct.system.Dispatcher "$@" 181 | -------------------------------------------------------------------------------- /bin/dispatcher.cmd: -------------------------------------------------------------------------------- 1 | @rem *************************************************************************** 2 | @rem Copyright (c) 2023 James Mover Zhou 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http:\\www.apache.org\licenses\LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem *************************************************************************** 16 | @echo off 17 | 18 | @REM Check if JAVA_HOME is set and valid 19 | if "%JAVA_HOME%" == "" ( 20 | echo Error: JAVA_HOME not found in your environment. >&2 21 | echo Please set the JAVA_HOME variable in your environment to match the location of your Java installation. >&2 22 | exit /B 1 23 | ) 24 | 25 | if not exist "%JAVA_HOME%\bin\java.exe" ( 26 | echo Error: JAVA_HOME is set to an invalid directory. >&2 27 | echo JAVA_HOME = "%JAVA_HOME%" >&2 28 | echo Please set the JAVA_HOME variable in your environment to match the location of your Java installation. >&2 29 | exit /B 1 30 | ) 31 | 32 | set "JAVA_CMD=%JAVA_HOME%\bin\java.exe" 33 | 34 | @REM Consolidate classpath entries, initialize ROOT and VERSION 35 | set "ROOT=%~dp0..\" 36 | set "VERSION=1.4.5" 37 | set "classpath=%ROOT%target\classes;%ROOT%lib\tinystruct-%VERSION%-jar-with-dependencies.jar;%ROOT%lib\*;%ROOT%WEB-INF\lib\*;%ROOT%WEB-INF\classes;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%-jar-with-dependencies.jar" 38 | 39 | @REM Run Java application 40 | %JAVA_CMD% -cp "%classpath%" org.tinystruct.system.Dispatcher %* 41 | -------------------------------------------------------------------------------- /build.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 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/example.png -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/favicon.png -------------------------------------------------------------------------------- /mover.log: -------------------------------------------------------------------------------- 1 | 2013-06-11 12:18:11 2 | Welcome to use tinystruct 2.0 3 | 4 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | org.tinystruct 6 | examples 7 | 1.0.0-SNAPSHOT 8 | 9 | 10 | org.tinystruct 11 | tinystruct 12 | 1.4.5 13 | jar-with-dependencies 14 | 15 | 16 | 17 | javax.servlet 18 | javax.servlet-api 19 | 3.1.0 20 | provided 21 | 22 | 23 | 24 | 25 | org.apache.tomcat.embed 26 | tomcat-embed-core 27 | 8.5.78 28 | 29 | 30 | 31 | org.apache.httpcomponents 32 | httpclient 33 | 4.5.12 34 | 35 | 36 | 37 | com.google.api-client 38 | google-api-client 39 | 1.15.0-rc 40 | 41 | 42 | com.google.http-client 43 | google-http-client 44 | 1.15.0-rc 45 | 46 | 47 | 48 | com.google.http-client 49 | google-http-client-gson 50 | 1.15.0-rc 51 | 52 | 53 | com.google.http-client 54 | google-http-client-jackson2 55 | 1.15.0-rc 56 | 57 | 58 | 59 | com.google.http-client 60 | google-http-client-jackson 61 | 1.15.0-rc 62 | 63 | 64 | com.google.oauth-client 65 | google-oauth-client-java6 66 | 1.15.0-rc 67 | 68 | 69 | 70 | 71 | com.itextpdf 72 | itextpdf 73 | 5.5.13.1 74 | 75 | 76 | 77 | com.sun.mail 78 | javax.mail 79 | 1.6.2 80 | 81 | 82 | com.rabbitmq 83 | amqp-client 84 | 5.6.0 85 | 86 | 87 | io.jsonwebtoken 88 | jjwt 89 | 0.5.1 90 | 91 | 92 | javax.enterprise 93 | cdi-api 94 | 1.0 95 | 96 | 97 | 98 | UTF-8 99 | 11 100 | 1.8 101 | 1.8 102 | 103 | 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-compiler-plugin 109 | 110 | 111 | org.apache.maven.plugins 112 | maven-dependency-plugin 113 | 114 | 115 | copy-dependencies 116 | compile 117 | 118 | copy-dependencies 119 | 120 | 121 | ${project.basedir}/lib 122 | false 123 | false 124 | true 125 | 126 | 127 | 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-jar-plugin 132 | 133 | 134 | 135 | true 136 | lib/ 137 | org.tinystruct.system.Dispatcher 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /scripts/bootstrap/fileinput/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/scripts/bootstrap/fileinput/loading.gif -------------------------------------------------------------------------------- /scripts/bootstrap/ie-emulation-modes-warning.js: -------------------------------------------------------------------------------- 1 | // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT 2 | // IT'S JUST JUNK FOR OUR DOCS! 3 | // ++++++++++++++++++++++++++++++++++++++++++ 4 | /*! 5 | * Copyright 2014-2015 Twitter, Inc. 6 | * 7 | * Licensed under the Creative Commons Attribution 3.0 Unported License. For 8 | * details, see https://creativecommons.org/licenses/by/3.0/. 9 | */ 10 | // Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes. 11 | (function () { 12 | 'use strict'; 13 | 14 | function emulatedIEMajorVersion() { 15 | var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent) 16 | if (groups === null) { 17 | return null 18 | } 19 | var ieVersionNum = parseInt(groups[1], 10) 20 | var ieMajorVersion = Math.floor(ieVersionNum) 21 | return ieMajorVersion 22 | } 23 | 24 | function actualNonEmulatedIEMajorVersion() { 25 | // Detects the actual version of IE in use, even if it's in an older-IE emulation mode. 26 | // IE JavaScript conditional compilation docs: https://msdn.microsoft.com/library/121hztk3%28v=vs.94%29.aspx 27 | // @cc_on docs: https://msdn.microsoft.com/library/8ka90k2e%28v=vs.94%29.aspx 28 | var jscriptVersion = new Function('/*@cc_on return @_jscript_version; @*/')() // jshint ignore:line 29 | if (jscriptVersion === undefined) { 30 | return 11 // IE11+ not in emulation mode 31 | } 32 | if (jscriptVersion < 9) { 33 | return 8 // IE8 (or lower; haven't tested on IE<8) 34 | } 35 | return jscriptVersion // IE9 or IE10 in any mode, or IE11 in non-IE11 mode 36 | } 37 | 38 | var ua = window.navigator.userAgent 39 | if (ua.indexOf('Opera') > -1 || ua.indexOf('Presto') > -1) { 40 | return // Opera, which might pretend to be IE 41 | } 42 | var emulated = emulatedIEMajorVersion() 43 | if (emulated === null) { 44 | return // Not IE 45 | } 46 | var nonEmulated = actualNonEmulatedIEMajorVersion() 47 | 48 | if (emulated !== nonEmulated) { 49 | window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!') 50 | } 51 | })(); 52 | -------------------------------------------------------------------------------- /scripts/bootstrap/ie10-viewport-bug-workaround.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * IE10 viewport hack for Surface/desktop Windows 8 bug 3 | * Copyright 2014-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | 7 | // See the Getting Started docs for more information: 8 | // http://getbootstrap.com/getting-started/#support-ie10-width 9 | 10 | (function () { 11 | 'use strict'; 12 | 13 | if (navigator.userAgent.match(/IEMobile\/10\.0/)) { 14 | var msViewportStyle = document.createElement('style') 15 | msViewportStyle.appendChild( 16 | document.createTextNode( 17 | '@-ms-viewport{width:auto!important}' 18 | ) 19 | ) 20 | document.querySelector('head').appendChild(msViewportStyle) 21 | } 22 | 23 | })(); 24 | -------------------------------------------------------------------------------- /scripts/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/scripts/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /scripts/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/scripts/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /scripts/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/scripts/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /scripts/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinystruct/tinystruct-examples/7b40faaa8d09a7333f990fbcf66922da2565ad83/scripts/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /scripts/jquery.level.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A set level of UL plugin for jQuery 3 | * @author: Mover Zhou 4 | * @url http://ingod.asia 5 | * Version: 1.0 6 | * Updated: November 9th, 2011 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | (function($){ 23 | $.fn.setLevel=function(i){ 24 | $this = $(this); 25 | $this.data("level",i+1); 26 | $(this).removeClass("level-"+i); 27 | $(this).addClass("level-"+$this.data("level")); 28 | 29 | $this.children("li").each(function(){ 30 | $(this).children("ul").each(function(){ 31 | $(this).setLevel($(this).data("level")); 32 | }); 33 | }); 34 | 35 | return this; 36 | } 37 | 38 | $.fn.level=function(){ 39 | return $(this).data("level");; 40 | } 41 | })(jQuery);; -------------------------------------------------------------------------------- /scripts/jquery.menu.css: -------------------------------------------------------------------------------- 1 | #toolbar { 2 | position: absolute; 3 | top: 0; 4 | left: 0; 5 | background: #000; 6 | width: 100%; 7 | border-bottom: 1px solid; 8 | } 9 | 10 | body { 11 | margin-top: 30px !important; 12 | } 13 | 14 | ul.tinystruct_menu { 15 | margin: 0; 16 | } 17 | 18 | ul.tinystruct_menu ul { 19 | margin: 0; 20 | } 21 | 22 | ul.tinystruct_menu>li { 23 | display: block; 24 | margin: 0; 25 | padding: 0; 26 | float: left !important; 27 | } 28 | 29 | ul.tinystruct_menu li a { 30 | padding: 5px 10px; 31 | color: #ccc 32 | } 33 | 34 | ul.tinystruct_menu ul li a:hover,ul.tinystruct_menu ul li a.selected { 35 | 36 | } 37 | 38 | ul.tinystruct_menu li.hover>a { 39 | color: #b32018; 40 | } 41 | 42 | ul.tinystruct_menu ul.tinystruct_menu { 43 | position: absolute; 44 | background: #000; 45 | z-index: 999; 46 | margin: 0; 47 | border: 1px solid #ccc 48 | } 49 | 50 | ul.tinystruct_menu ul.tinystruct_menu li { 51 | display: block; 52 | float: none !important; 53 | background: #000; 54 | margin: 0; 55 | padding: 0; 56 | } 57 | 58 | ul.tinystruct_menu ul.tinystruct_menu li a { 59 | padding: 5px 15px; 60 | } 61 | 62 | ul.tinystruct_menu ul.tinystruct_menu li a:hover,ul.tinystruct_menu ul.tinystruct_menu li.hover>a 63 | { 64 | background: #b32018; 65 | color: #ffffff; 66 | text-decoration: none; 67 | } -------------------------------------------------------------------------------- /scripts/jquery.menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A slide Menu plugin for Jquery. 3 | * @author: Mover Zhou 4 | * @url http://development.ingod.asia 5 | * 6 | * @depends jquery.level.js, timer.js 7 | * Version: 1.0 8 | * Updated: November 9th, 2011 9 | * 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | **/ 22 | 23 | (function($){ 24 | $.settings = { 25 | defaultHandler: "mouseover" 26 | }; 27 | 28 | $.fn.start = function(func){ 29 | 30 | if($(this).data("timer")) { 31 | $(this).data("timer").start(); 32 | } 33 | else { 34 | $this = $(this); 35 | $timer = new Timer(0.1,function(){ 36 | func(); 37 | }).start(); 38 | 39 | $this.data("timer", $timer); 40 | } 41 | } 42 | 43 | $.fn.stop = function(){ 44 | if($(this).data("timer")) { 45 | $(this).data("timer").stop(); 46 | } 47 | } 48 | 49 | $.fn.renderMenu = function(){ 50 | 51 | if($(this).data("rendered")==true){ 52 | $(this).find('> li > a').each(function(i){ 53 | if($(this).next("ul").length>0) { 54 | $(this).siblings().hide(); 55 | 56 | if($(this).siblings().level() > 2) 57 | $(this).siblings().css({"margin-left":$(this).parent().width(),"margin-top":"-"+(parseInt($(this).parent().height())+2)+"px"}); 58 | } 59 | }); 60 | 61 | return; 62 | } 63 | 64 | settings = typeof arguments[0] != undefined ? arguments[0]:$.settings; 65 | $parent = $(this); 66 | $(this).data("timer",null); 67 | $(this).addClass("tinystruct_menu").removeClass("menu").setLevel(0); 68 | 69 | $(this).find('> li > a').each(function(i){ 70 | 71 | if($(this).next("ul").length>0) { 72 | 73 | $(this).data("event",settings); 74 | $(this).siblings().hide(); 75 | if($(this).siblings().level() > 2) 76 | $(this).siblings().css({"margin-left":$(this).parent().width(),"margin-top":"-"+(parseInt($(this).parent().height())+2)+"px"}); 77 | 78 | if($(this).data("event").defaultHandler == 'mouseover') { 79 | 80 | $(this).parent().hover( 81 | function(){ 82 | $(this).addClass("hover"); 83 | 84 | $(this).find(">ul").slideDown("fast"); 85 | $(this).find(">ul").renderMenu({defaultHandler:"mouseover"}); 86 | }, 87 | function(){ 88 | $(this).find(">ul").slideUp("fast"); 89 | $(this).removeClass("hover"); 90 | } 91 | ); 92 | } 93 | else { 94 | $(this).unbind("click"); 95 | $(this).parent().unbind("hover"); 96 | 97 | $(this).click(function(event){ 98 | event.preventDefault(); 99 | 100 | $(this).next("ul").slideToggle("slow"); 101 | $(this).next("ul").renderMenu({defaultHandler:"click"}); 102 | }); 103 | 104 | $(this).parent().hover( 105 | function(){ 106 | $(this).addClass("hover"); 107 | $(this).stop(); 108 | } 109 | , 110 | function(){ 111 | $(this).removeClass("hover"); 112 | 113 | $this = $(this); 114 | $(this).start(function(){ 115 | $this.find(">ul").slideUp("fast"); 116 | $this.removeClass("hover"); 117 | }); 118 | } 119 | ); 120 | } 121 | 122 | } 123 | }); 124 | 125 | $(this).data("rendered",true); 126 | }; 127 | })(jQuery);; -------------------------------------------------------------------------------- /scripts/struct.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A standard timer for Java script. 3 | * 4 | * @author: Mover Zhou 5 | * @url http://development.ingod.asia 6 | * 7 | * Version: 1.0 Updated: November 9th, 2011 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 10 | * use this file except in compliance with the License. You may obtain a copy of 11 | * the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 18 | * License for the specific language governing permissions and limitations under 19 | * the License. 20 | */ 21 | var struct = { 22 | baseId : "__base__" 23 | }; 24 | 25 | struct.attachOnLoadEvent = function() { 26 | if (typeof window.addEventListener != "undefined") { 27 | window.addEventListener("load", arguments[0], false); 28 | } else if (typeof window.attachEvent != "undefined") { 29 | window.attachEvent("onload", arguments[0]); 30 | } else { 31 | if (window.onload != null) { 32 | var _attach = arguments[0]; 33 | var _onloaded = window.onload; 34 | window.onload = function(e) { 35 | _onloaded(e); 36 | window[_attach](); 37 | }; 38 | } else { 39 | window.onload = arguments[0]; 40 | } 41 | } 42 | } 43 | 44 | struct.attachOnLoadEvent(function() { 45 | if (typeof (document.getElementById(struct.baseId)) == 'undefined') { 46 | struct.base = document.createElement("DIV"); 47 | struct.base.setAttribute("id", struct.baseId); 48 | struct.base.setAttribute("class", struct.baseId); 49 | struct.base.style.display = "none"; 50 | document.body.appendChild(struct.base); 51 | } 52 | else 53 | struct.base = document.getElementById(struct.baseId); 54 | }); 55 | 56 | struct.message = function() { 57 | this.panel = struct.base?struct.base:document.getElementById(struct.baseId); 58 | 59 | var $this_message = this; 60 | this.timer = new Timer(3, function() { 61 | $this_message.hide(); 62 | }); 63 | 64 | this.showMessage = function() { 65 | this.panel.innerHTML = arguments[0]; 66 | this.panel.style.cssText = "padding-left:2px;padding-right:2px;background:#AF3233;color:#ffffff;font-size:12px;text-align:center"; 67 | this.panel.style.display = 'block'; 68 | this.timer.start(); 69 | struct.fixed(this.panel, 0, 0); 70 | }; 71 | this.hide = function() { 72 | this.panel.innerHTML = ''; 73 | this.panel.style.display = 'none'; 74 | 75 | this.timer.stop(); 76 | }; 77 | } 78 | 79 | struct.Event = { 80 | KEY : { 81 | DOWN : "keydown", 82 | UP : "keyup" 83 | }, 84 | MOUSE : { 85 | DOWN : "mousedown", 86 | UP : "mouseup", 87 | CLICK : "click", 88 | DBLCLICK : "dblclick", 89 | OVER : "mouseover", 90 | OUT : "mouseout" 91 | }, 92 | ELEMENT : { 93 | LOAD : "load", 94 | UNLOAD : "unload" 95 | } 96 | } 97 | 98 | struct.setAttribute = function(element, name, value) { 99 | if (typeof (element.addEventListener) != "undefined") 100 | element[name] = value; 101 | else 102 | element.setAttribute(name, value); 103 | } 104 | 105 | struct.getAttribute = function(element, name) { 106 | if (typeof (element.addEventListener) != "undefined") 107 | return element.attributes[name].nodeValue; 108 | else 109 | element.getAttribute(name); 110 | } 111 | 112 | /* 113 | * attachEvent(element,event,func) 114 | */ 115 | struct.attachEvent = function(element, event, func, attributes) { 116 | if (typeof (element.addEventListener) != "undefined") { 117 | element.addEventListener(event, func, false); 118 | } else if (typeof (element.attachEvent) != "undefined") { 119 | element.attachEvent("on" + event, func); 120 | } 121 | } 122 | 123 | struct.save = function(name, value) { 124 | var argv = arguments; 125 | var argc = arguments.length; 126 | var expires = (argc > 2) ? argv[2] : null; 127 | var path = (argc > 3) ? argv[3] : '/'; 128 | var domain = (argc > 4) ? argv[4] : null; 129 | var secure = (argc > 5) ? argv[5] : false; 130 | document.cookie = name + "=" + escape(value) 131 | + ((expires == null) ? "" : ("; expires=" + expires)) 132 | + ((path == null) ? "" : ("; path=" + path)) 133 | + ((domain == null) ? "" : ("; domain=" + domain)) 134 | + ((secure == true) ? "; secure" : ""); 135 | }; 136 | 137 | struct.get = function(name) { 138 | var arg = name + "="; 139 | var alen = arg.length; 140 | var clen = document.cookie.length; 141 | var i = 0; 142 | var j = 0; 143 | while (i < clen) { 144 | j = i + alen; 145 | if (document.cookie.substring(i, j) == arg) 146 | return struct.getValue(j); 147 | i = document.cookie.indexOf(" ", i) + 1; 148 | if (i == 0) 149 | break; 150 | } 151 | return null; 152 | }; 153 | 154 | struct.clear = function(name) { 155 | if (struct.get(name)) { 156 | var expdate = new Date(); 157 | expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 158 | struct.set(name, "", expdate); 159 | } 160 | }; 161 | 162 | struct.getValue = function(offset) { 163 | var endstr = document.cookie.indexOf(";", offset); 164 | if (endstr == -1) { 165 | endstr = document.cookie.length; 166 | } 167 | return unescape(document.cookie.substring(offset, endstr)); 168 | }; 169 | 170 | struct.dateFormat = function(date, format) { 171 | if (!format) 172 | format = 'yyyy-mm-dd HH:MM:ss'; 173 | 174 | if (date instanceof Date) { 175 | return date.format(format); 176 | } else { 177 | return struct.parseDate(date).format(format); 178 | } 179 | }; 180 | 181 | struct.parseDate = function() { 182 | if (typeof arguments[0] == 'string') { 183 | var results = arguments[0].match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/); 184 | 185 | if (results && results.length > 3) 186 | return new Date(parseInt(results[1]), parseInt(results[2]) - 1, 187 | parseInt(results[3])); 188 | 189 | results = arguments[0] 190 | .match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/); 191 | if (results && results.length > 6) 192 | return new Date(parseInt(results[1]), parseInt(results[2]) - 1, 193 | parseInt(results[3]), parseInt(results[4]), 194 | parseInt(results[5]), parseInt(results[6])); 195 | 196 | results = arguments[0] 197 | .match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/); 198 | if (results && results.length > 7) 199 | return new Date(parseInt(results[1]), parseInt(results[2]) - 1, 200 | parseInt(results[3]), parseInt(results[4]), 201 | parseInt(results[5]), parseInt(results[6]), 202 | parseInt(results[7])); 203 | } 204 | 205 | return new Date(Date.parse(arguments[0])); 206 | } 207 | 208 | struct.loading = function() { 209 | this.id = "loading"; 210 | this.icon = document.getElementById(this.id); 211 | this.element = typeof (arguments[0]) != undefined ? arguments[0] 212 | : document.body; 213 | this.start = function() { 214 | if (!this.icon) { 215 | var icon = document.createElement("img"); 216 | icon.setAttribute("src", "/themes/images/loading.gif"); 217 | icon.setAttribute("id", "loading"); 218 | this.element.appendChild(icon); 219 | } else 220 | this.icon.style.display = 'block'; 221 | 222 | this.element.style.display = 'block'; 223 | }, this.stop = function() { 224 | if (this.element) 225 | this.element.style.display = 'none'; 226 | } 227 | }; 228 | 229 | /* 230 | * 感谢网友淡新举 231 | */ 232 | var inited = false; 233 | struct.fixed = function(element, top, left) { 234 | 235 | this.inited = inited; 236 | element.style.display = "block"; 237 | if (!window.XMLHttpRequest && window.ActiveXObject) { 238 | element.style.position = "absolute"; 239 | 240 | this.setGlobal(); 241 | } else { 242 | element.style.position = "fixed"; 243 | } 244 | 245 | element.style.top = top + "px"; 246 | element.style.left = left + "px"; 247 | 248 | this.addCSSRule = function(key, value) { 249 | var css = document.styleSheets[document.styleSheets.length - 1]; 250 | css.cssRules ? (css.insertRule(key + "{" + value + "}", 251 | css.cssRules.length)) : (css.addRule(key, value)); 252 | }; 253 | 254 | this.setGlobal = function() { 255 | if (window.navigator.appVersion.indexOf("IE 6.0") == -1) 256 | if (!this.inited) { 257 | document.body.style.height = "100%"; 258 | document.body.style.overflow = "auto"; 259 | this.addCSSRule("*html", "overflow-x:auto;overflow-y:hidden;"); 260 | inited = this.inited = true; 261 | } 262 | }; 263 | 264 | }; 265 | 266 | struct.getStyle = function(className, attr) { 267 | 268 | var CSSSheets, value = "", currentRule; 269 | CSSSheets = document.styleSheets; 270 | 271 | for (j = 0; j < CSSSheets.length; j++) { 272 | for (i = 0; i < CSSSheets[j].cssRules.length; i++) { 273 | currentRule = CSSSheets[j].cssRules[i].selectorText; 274 | 275 | if (currentRule && currentRule.indexOf(className) != -1) 276 | if (document.querySelectorAll(currentRule).length) { 277 | return CSSSheets[j].cssRules[i].style[attr]; 278 | } 279 | } 280 | } 281 | 282 | return value; 283 | } -------------------------------------------------------------------------------- /scripts/timer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A standard timer for Java script. 3 | * @author: Mover Zhou 4 | * @url http://development.ingod.asia 5 | * 6 | * Version: 1.0 7 | * Updated: November 9th, 2011 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | **/ 21 | 22 | if (!Function.prototype.bind) { 23 | Function.prototype.bind = function(oThis) { 24 | if (typeof this !== 'function') { 25 | // closest thing possible to the ECMAScript 5 26 | // internal IsCallable function 27 | throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); 28 | } 29 | 30 | var aArgs = Array.prototype.slice.call(arguments, 1), 31 | fToBind = this, 32 | fNOP = function() {}, 33 | fBound = function() { 34 | return fToBind.apply(this instanceof fNOP 35 | ? this 36 | : oThis, 37 | aArgs.concat(Array.prototype.slice.call(arguments))); 38 | }; 39 | 40 | fNOP.prototype = this.prototype; 41 | fBound.prototype = new fNOP(); 42 | 43 | return fBound; 44 | }; 45 | } 46 | // Above code was copied from mozilla community. 47 | var Timer = function() { 48 | if (arguments.length > 1) { 49 | this.limit = arguments[0]; 50 | this.action = typeof (arguments[1]) == 'undefined' ? function() { 51 | } : arguments[1]; 52 | } else { 53 | this.limit = 1; 54 | this.action = arguments[0]; 55 | } 56 | 57 | list = [ 'started', 'running', 'stopped', 'completed' ]; 58 | this.timer = null; 59 | this.times = 0; 60 | this.end = 0; 61 | this.done = null; 62 | this.status = list[0]; 63 | 64 | this.setAction = function() { 65 | this.action = arguments[0]; 66 | }; 67 | 68 | this.start = function() { 69 | if (this.timer) { 70 | this.stop(); 71 | } 72 | 73 | if (this.status != list[3]) { 74 | this.timer = setTimeout(this.action.bind(this), this.limit * 1000); 75 | this.times++; 76 | this.status = list[1]; 77 | } 78 | 79 | return this; 80 | }; 81 | 82 | this.stop = function() { 83 | if (typeof (arguments[0]) == 'number') { 84 | this.end = arguments[0]; 85 | return this; 86 | } 87 | 88 | clearTimeout(this.timer); 89 | this.timer = null; 90 | this.status = list[2]; 91 | 92 | if (this.times > 0 && this.times === this.end) { 93 | this.times = 0; 94 | this.complete(); 95 | } 96 | 97 | return this; 98 | }; 99 | 100 | this.complete = function() { 101 | if (typeof (arguments[0]) == 'function') { 102 | this.done = arguments[0]; 103 | return this; 104 | } 105 | 106 | if (typeof (this.done) == 'function') { 107 | this.done(); 108 | this.status = list[3]; 109 | } 110 | }; 111 | 112 | this.status = function() { 113 | return this.status; 114 | }; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /scripts/tools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Date Format 1.2.3 3 | * (c) 2007-2009 Steven Levithan 4 | * MIT license 5 | * 6 | * Includes enhancements by Scott Trenda 7 | * and Kris Kowal 8 | * 9 | * Accepts a date, a mask, or a date and a mask. 10 | * Returns a formatted version of the given date. 11 | * The date defaults to the current date/time. 12 | * The mask defaults to dateFormat.masks.default. 13 | */ 14 | 15 | var dateFormat = function () { 16 | var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, 17 | timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, 18 | timezoneClip = /[^-+\dA-Z]/g, 19 | pad = function (val, len) { 20 | val = String(val); 21 | len = len || 2; 22 | while (val.length < len) val = "0" + val; 23 | return val; 24 | }; 25 | 26 | // Regexes and supporting functions are cached through closure 27 | return function (date, mask, utc) { 28 | var dF = dateFormat; 29 | 30 | // You can't provide utc if you skip other args (use the "UTC:" mask prefix) 31 | if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { 32 | mask = date; 33 | date = undefined; 34 | } 35 | 36 | // Passing date through Date applies Date.parse, if necessary 37 | date = date ? new Date(date) : new Date; 38 | if (isNaN(date)) throw SyntaxError("invalid date"); 39 | 40 | mask = String(dF.masks[mask] || mask || dF.masks["default"]); 41 | 42 | // Allow setting the utc argument via the mask 43 | if (mask.slice(0, 4) == "UTC:") { 44 | mask = mask.slice(4); 45 | utc = true; 46 | } 47 | 48 | var _ = utc ? "getUTC" : "get", 49 | d = date[_ + "Date"](), 50 | D = date[_ + "Day"](), 51 | m = date[_ + "Month"](), 52 | y = date[_ + "FullYear"](), 53 | H = date[_ + "Hours"](), 54 | M = date[_ + "Minutes"](), 55 | s = date[_ + "Seconds"](), 56 | L = date[_ + "Milliseconds"](), 57 | o = utc ? 0 : date.getTimezoneOffset(), 58 | flags = { 59 | d: d, 60 | dd: pad(d), 61 | ddd: dF.i18n.dayNames[D], 62 | dddd: dF.i18n.dayNames[D + 7], 63 | m: m + 1, 64 | mm: pad(m + 1), 65 | mmm: dF.i18n.monthNames[m], 66 | mmmm: dF.i18n.monthNames[m + 12], 67 | yy: String(y).slice(2), 68 | yyyy: y, 69 | h: H % 12 || 12, 70 | hh: pad(H % 12 || 12), 71 | H: H, 72 | HH: pad(H), 73 | M: M, 74 | MM: pad(M), 75 | s: s, 76 | ss: pad(s), 77 | l: pad(L, 3), 78 | L: pad(L > 99 ? Math.round(L / 10) : L), 79 | t: H < 12 ? "a" : "p", 80 | tt: H < 12 ? "am" : "pm", 81 | T: H < 12 ? "A" : "P", 82 | TT: H < 12 ? "AM" : "PM", 83 | Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), 84 | o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), 85 | S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] 86 | }; 87 | 88 | return mask.replace(token, function ($0) { 89 | return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); 90 | }); 91 | }; 92 | }(); 93 | 94 | // Some common format strings 95 | dateFormat.masks = { 96 | "default": "ddd mmm dd yyyy HH:MM:ss", 97 | shortDate: "m/d/yy", 98 | mediumDate: "mmm d, yyyy", 99 | longDate: "mmmm d, yyyy", 100 | fullDate: "dddd, mmmm d, yyyy", 101 | shortTime: "h:MM TT", 102 | mediumTime: "h:MM:ss TT", 103 | longTime: "h:MM:ss TT Z", 104 | isoDate: "yyyy-mm-dd", 105 | isoTime: "HH:MM:ss", 106 | isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", 107 | isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" 108 | }; 109 | 110 | // Internationalization strings 111 | dateFormat.i18n = { 112 | dayNames: [ 113 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 114 | "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" 115 | ], 116 | monthNames: [ 117 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 118 | "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" 119 | ] 120 | }; 121 | 122 | // For convenience... 123 | Date.prototype.format = function (mask, utc) { 124 | return dateFormat(this, mask, utc); 125 | }; 126 | 127 | var Tips=function() 128 | { 129 | this.id=typeof(arguments[0])!='undefined'?arguments[0].id:"$__TIPS"; 130 | this.message=typeof(arguments[0])!='undefined'?arguments[0].message:''; 131 | this.panel={}; 132 | 133 | this.getPanel=function(){ 134 | return this.panel; 135 | }; 136 | if(!document.getElementById(this.id)) 137 | { 138 | this.panel=document.createElement("div"); 139 | this.panel.setAttribute("id",this.id); 140 | this.panel.setAttribute("style","padding:3px; border: 1px solid #a3a3a3; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;background:#fff;"); 141 | this.panel.style.display="none"; 142 | 143 | document.body.appendChild(this.panel); 144 | } 145 | else 146 | { 147 | this.panel=document.getElementById(this.id); 148 | } 149 | 150 | this.sameContent=true; 151 | 152 | this.onshow=function(){}; 153 | this.onhide=function(){}; 154 | 155 | if(typeof(arguments[0])!='undefined') 156 | { 157 | this.onshow=typeof(arguments[0].onshow)=='undefined'?function(){}:arguments[0].onshow; 158 | this.onhide=typeof(arguments[0].onhide)=='undefined'?function(){}:arguments[0].onhide; 159 | } 160 | 161 | var $this_tips=this; 162 | this.timer=new Timer(2,function(){$this_tips.hide();}); 163 | 164 | this.setId=function(id) 165 | { 166 | this.id=id; 167 | this.panel=document.getElementById(this.id); 168 | this.panel.setAttribute("style","display:none; padding:3px; border: 1px solid #a3a3a3; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px;background:#fff;"); 169 | }; 170 | this.getId=function() 171 | { 172 | return this.id; 173 | }; 174 | this.append=function(item) 175 | { 176 | this.panel.appendChild(item); 177 | this.sameContent=false; 178 | }; 179 | this.update=function(item) 180 | { 181 | this.panel.innerHTML=''; 182 | this.panel.appendChild(item); 183 | //this.panel.innerHTML+="
"; 184 | }; 185 | this.style=function() 186 | { 187 | if(typeof(arguments[0])!='undefined') 188 | this.panel.setAttribute("style",arguments[0]); 189 | }; 190 | this.show=function(){ 191 | var event,element,message,top=0,left=0; 192 | if(typeof(arguments[0])=='undefined') 193 | { 194 | alert('Event Object is null!'); 195 | return; 196 | } 197 | else 198 | event=arguments[0]; 199 | 200 | if(!event.target) 201 | { 202 | event=window.event; 203 | element=currentElement=event.srcElement; 204 | 205 | do 206 | { 207 | top+=element.offsetTop; 208 | left+=element.offsetLeft; 209 | } 210 | while(element=element.offsetParent); 211 | } 212 | else 213 | { 214 | currentElement=event.target; 215 | top=currentElement.offsetTop; 216 | left=currentElement.offsetLeft; 217 | } 218 | 219 | //alert(target); 220 | if(typeof(arguments[1])!='undefined') 221 | { 222 | message=arguments[1]; 223 | if(this.message!=message) 224 | { 225 | this.sameContent=false; 226 | this.message=message; 227 | } 228 | } 229 | 230 | this.panel.style.top=(top+currentElement.offsetHeight)+"px"; 231 | this.panel.style.left=left+"px"; 232 | this.panel.style.position="absolute"; 233 | this.panel.style.zIndex="1000"; 234 | this.panel.style.display="block"; 235 | 236 | this.onshow(); 237 | 238 | this.timer.start(); 239 | var $this=this; 240 | struct.attachEvent(this.panel,"mouseover",function(){ 241 | $this.timer.stop(); 242 | }); 243 | 244 | struct.attachEvent(this.panel,"mouseout",function(){ 245 | $this.timer.start(); 246 | }); 247 | }; 248 | this.hide=function(){ 249 | this.panel.style.display="none"; 250 | this.onhide(); 251 | this.timer.stop(); 252 | }; 253 | } 254 | 255 | var Menu=function(){ 256 | this.items=document.createElement("ul"); 257 | this.id=(typeof(arguments[0])=='undefined'?'menu':arguments[0]); 258 | this.panel=function(){ 259 | if(!document.getElementById(this.id)) 260 | { 261 | var $panel=document.createElement("div"); 262 | $panel.setAttribute("id",this.id); 263 | $panel.style.display="none"; 264 | 265 | document.body.appendChild($panel); 266 | return $panel; 267 | } 268 | 269 | return document.getElementById(this.id); 270 | } 271 | 272 | $_this_menu=this; 273 | this.timer=new Timer(1, function(){ 274 | $_this_menu.hide(); 275 | }); 276 | 277 | this.itemlist=new Array(); 278 | 279 | this.appendItem=function(){ 280 | var currentItem; 281 | if(arguments[0]=='undefined') 282 | { 283 | alert("the arguments cannot be null!"); 284 | return; 285 | } 286 | else 287 | { 288 | currentItem=arguments[0]; 289 | } 290 | 291 | var o=new Object(); 292 | o.caption=currentItem.caption; 293 | o.action=currentItem.action; 294 | 295 | this.itemlist[this.itemlist.length]=o; 296 | } 297 | 298 | this.show=function(){ 299 | var event,top=0,left=0,element,sid; 300 | 301 | if(typeof(arguments[0])=='undefined') 302 | { 303 | alert("the arguments[0] cannot be null!"); 304 | return; 305 | } 306 | else 307 | { 308 | event=arguments[0]; 309 | } 310 | 311 | if(typeof(arguments[1])=='undefined') 312 | { 313 | alert("the arguments[1] cannot be null!"); 314 | return; 315 | } 316 | else 317 | { 318 | sid=arguments[1]; 319 | } 320 | 321 | if(window.event) 322 | { 323 | event=window.event; 324 | element=currentElement=event.srcElement; 325 | 326 | do 327 | { 328 | top+=element.offsetTop; 329 | left+=element.offsetLeft; 330 | } 331 | while(element=element.offsetParent); 332 | } 333 | else 334 | { 335 | element = currentElement = event.target; 336 | 337 | if(currentElement.offsetParent!=null && struct.getStyle("."+currentElement.offsetParent.className,"position")=="absolute") 338 | { 339 | do 340 | { 341 | top+=element.offsetTop; 342 | left+=element.offsetLeft; 343 | } 344 | while(element=element.offsetParent); 345 | } 346 | else { 347 | top=currentElement.offsetTop; 348 | left=currentElement.offsetLeft; 349 | } 350 | 351 | } 352 | 353 | var text=""; 354 | for(var i=1;i 1) { 416 | this.limit = arguments[0]; 417 | this.action = typeof (arguments[1]) == 'undefined' ? function() { 418 | } : arguments[1]; 419 | } else { 420 | this.limit = 1; 421 | this.action = arguments[0]; 422 | } 423 | 424 | this.timer=null; 425 | 426 | this.setAction=function() 427 | { 428 | this.action=arguments[0]; 429 | }; 430 | this.start=function(){ 431 | if(this.timer)this.stop(); 432 | this.timer=setTimeout(this.action,this.limit*1000); 433 | // document.title="started"; 434 | }; 435 | this.stop=function(){ 436 | clearTimeout(this.timer); 437 | // document.title="stopped"; 438 | }; 439 | this.excute=function() 440 | { 441 | this.action(); 442 | }; 443 | } 444 | var Dialog=function(){ 445 | this.id='dialog'; 446 | this.sid=-1; 447 | this.title='Default Title'; 448 | this.width=300; 449 | this.height=0; 450 | this.action=null; 451 | this.panel=document.createElement("div"); 452 | this.value=''; 453 | 454 | var $this_dialog=this; 455 | this.timer=new Timer(0.1,function(){$this_dialog.reposition();}); 456 | 457 | if(typeof(arguments[0])!='undefined'){ 458 | this.id=typeof(arguments[0].id)!='undefined'?arguments[0].id:'dialog'; 459 | this.title=typeof(arguments[0].title)!='undefined'?arguments[0].title:this.title; 460 | this.width=typeof(arguments[0].width)!='undefined'?arguments[0].width:this.width; 461 | this.height=typeof(arguments[0].height)!='undefined'?arguments[0].height:this.height; 462 | this.action=typeof(arguments[0].action)!='undefined'?arguments[0].action:this.action; 463 | 464 | this.okLabel=typeof(arguments[0].okLabel)!='undefined'? arguments[0].okLabel : "确定"; 465 | this.cancelLabel=typeof(arguments[0].cancelLabel)!='undefined'? arguments[0].cancelLabel : "取消"; 466 | } 467 | 468 | this.show=function(){ 469 | this.parameters=typeof(arguments[0]!='undefined')?arguments[0]:{}; 470 | 471 | var dialog=document.createElement('ul'); 472 | var dialog_title=document.createElement('li'); 473 | dialog_title.appendChild(document.createTextNode(this.title)); 474 | dialog.appendChild(dialog_title); 475 | 476 | var dialog_textarea=document.createElement('li'); 477 | var textarea=document.createElement('textarea'); 478 | textarea.setAttribute("cols",48); 479 | textarea.setAttribute("rows",5); 480 | textarea.setAttribute("id","content"); 481 | textarea.setAttribute("name","content"); 482 | textarea.appendChild(document.createTextNode(this.parameters.value?this.parameters.value:'')); 483 | dialog_textarea.appendChild(textarea); 484 | dialog.appendChild(dialog_textarea); 485 | 486 | var dialog_control=document.createElement('li'); 487 | dialog_control.setAttribute("style","text-align:right"); 488 | var save_button=document.createElement("a"); 489 | save_button.href="javascript:void(0)"; 490 | save_button.appendChild(document.createTextNode(this.okLabel)); 491 | 492 | var close_button=document.createElement("a"); 493 | close_button.href="javascript:void(0)"; 494 | close_button.setAttribute("style","margin-left:10px;"); 495 | close_button.appendChild(document.createTextNode(this.cancelLabel)); 496 | 497 | dialog_control.appendChild(save_button); 498 | dialog_control.appendChild(close_button); 499 | 500 | var $this=this; 501 | struct.attachEvent(save_button,"click",function(){$this.save()}); 502 | struct.attachEvent(close_button,"click",function(){$this.close()}); 503 | 504 | dialog.appendChild(dialog_control); 505 | this.panel.innerHTML=''; 506 | this.panel.appendChild(dialog); 507 | 508 | this.panel.style.display="block"; 509 | this.panel.setAttribute("id","dialog"); 510 | this.panel.setAttribute("onmousedown",""); 511 | this.panel.setAttribute("ondragstart",""); 512 | 513 | document.body.appendChild(this.panel); 514 | this.reposition(); 515 | }; 516 | this.close=function(){ 517 | this.panel.style.display='none'; 518 | this.timer.stop(); 519 | }; 520 | this.reposition=function(){ 521 | var x=0,y=0; 522 | this.panel.style.position="absolute"; 523 | 524 | var ie=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; 525 | if(!document.all) 526 | { 527 | x-=window.pageXOffset; 528 | y-=window.pageYOffset; 529 | } 530 | 531 | this.panel.style.right=x+"px"; 532 | this.panel.style.bottom=y+"px"; 533 | 534 | this.timer.start(1); 535 | }; 536 | this.save=function(){ 537 | if(this.action!=null && typeof(this.action)=='function') 538 | { 539 | this.action(); 540 | 541 | return; 542 | } 543 | else 544 | { 545 | alert('请设定功能!'); 546 | return; 547 | } 548 | } 549 | } 550 | 551 | var TDialog=function(){ 552 | this.id='tdialog'; 553 | this.sid=-1; 554 | this.title='Default Title'; 555 | this.width=300; 556 | this.height=0; 557 | this.action=null; 558 | this.panel=document.createElement("div"); 559 | this.value=''; 560 | 561 | var $this_dialog=this; 562 | this.timer=new Timer(0.1,function(){$this_dialog.reposition();}); 563 | 564 | if(typeof(arguments[0])!='undefined'){ 565 | this.id=typeof(arguments[0].id)!='undefined'?arguments[0].id:'tdialog'; 566 | this.title=typeof(arguments[0].title)!='undefined'?arguments[0].title:this.title; 567 | this.width=typeof(arguments[0].width)!='undefined'?arguments[0].width:this.width; 568 | this.height=typeof(arguments[0].height)!='undefined'?arguments[0].height:this.height; 569 | this.action=typeof(arguments[0].action)!='undefined'?arguments[0].action:this.action; 570 | 571 | this.okLabel=typeof(arguments[0].okLabel)!='undefined'? arguments[0].okLabel : "确定"; 572 | this.cancelLabel=typeof(arguments[0].cancelLabel)!='undefined'? arguments[0].cancelLabel : "取消"; 573 | } 574 | 575 | this.show=function(){ 576 | this.html=typeof(arguments[0]!='undefined')?arguments[0]:""; 577 | 578 | var dialog=document.createElement('ul'); 579 | var dialog_title=document.createElement('li'); 580 | dialog_title.appendChild(document.createTextNode(this.title)); 581 | dialog.appendChild(dialog_title); 582 | 583 | var dialog_textarea=document.createElement('li'); 584 | var textarea=document.createElement('DIV'); 585 | textarea.setAttribute("class","text"); 586 | textarea.innerHTML=(this.html); 587 | 588 | dialog_textarea.appendChild(textarea); 589 | dialog.appendChild(dialog_textarea); 590 | 591 | var dialog_control=document.createElement('li'); 592 | dialog_control.setAttribute("style","text-align:right"); 593 | var save_button=document.createElement("a"); 594 | save_button.href="javascript:void(0)"; 595 | save_button.appendChild(document.createTextNode(this.okLabel)); 596 | 597 | var close_button=document.createElement("a"); 598 | close_button.href="javascript:void(0)"; 599 | close_button.setAttribute("style","margin-left:10px;"); 600 | close_button.appendChild(document.createTextNode(this.cancelLabel)); 601 | 602 | dialog_control.appendChild(save_button); 603 | dialog_control.appendChild(close_button); 604 | 605 | var $this=this; 606 | struct.attachEvent(save_button,"click",function(){$this.save()}); 607 | struct.attachEvent(close_button,"click",function(){$this.close()}); 608 | 609 | dialog.appendChild(dialog_control); 610 | this.panel.innerHTML=''; 611 | this.panel.appendChild(dialog); 612 | 613 | this.panel.style.display="block"; 614 | this.panel.setAttribute("id","tdialog"); 615 | this.panel.setAttribute("onmousedown",""); 616 | this.panel.setAttribute("ondragstart",""); 617 | 618 | document.body.appendChild(this.panel); 619 | this.reposition(); 620 | }; 621 | this.close=function(){ 622 | this.panel.style.display='none'; 623 | this.timer.stop(); 624 | }; 625 | this.reposition=function(){ 626 | var x=0,y=0; 627 | this.panel.style.position="absolute"; 628 | 629 | var ie=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body; 630 | if(!document.all) 631 | { 632 | x-=window.pageXOffset; 633 | y-=window.pageYOffset; 634 | } 635 | 636 | this.panel.style.right=x+"px"; 637 | this.panel.style.bottom=y+"px"; 638 | 639 | this.timer.start(1); 640 | }; 641 | this.save=function(){ 642 | if(this.action!=null && typeof(this.action)=='function') 643 | { 644 | this.action(); 645 | 646 | return; 647 | } 648 | else 649 | { 650 | alert('请设定功能!'); 651 | return; 652 | } 653 | } 654 | } 655 | 656 | function copyToClipboard(txt) { 657 | if(window.clipboardData) { 658 | window.clipboardData.clearData(); 659 | window.clipboardData.setData("Text", txt); 660 | alert("复制成功!"); 661 | } else if(navigator.userAgent.indexOf("Opera") != -1) { 662 | window.location = txt; 663 | } else if (window.netscape) { 664 | try 665 | { 666 | netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 667 | } catch (e) { 668 | alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'"); 669 | } 670 | var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 671 | if (!clip) 672 | return; 673 | var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 674 | if (!trans) 675 | return; 676 | trans.addDataFlavor('text/unicode'); 677 | var str = new Object(); 678 | var len = new Object(); 679 | var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 680 | var copytext = txt; 681 | str.data = copytext; 682 | trans.setTransferData("text/unicode",str,copytext.length*2); 683 | var clipid = Components.interfaces.nsIClipboard; 684 | if (!clip) 685 | return false; 686 | clip.setData(trans,null,clipid.kGlobalClipboard); 687 | alert("复制成功!"); 688 | } 689 | } 690 | 691 | function subscribe() 692 | { 693 | var email=document.getElementById('toemail').value; 694 | var bible=document.getElementById('bible').value, article=document.getElementById('article').value; 695 | var submit=document.getElementById('subscribe_button'); 696 | var loading=new struct.loading(document.getElementById('subscribe-message')); 697 | if(email && submit) 698 | { 699 | submit.disabled="disabled"; 700 | 701 | loading.start(); 702 | $.ajax({url:"?q=services/subscribe",data:{toemail:email,bible:bible,article:article}}) 703 | .success(function(data,textStatus,transport){ 704 | loading.stop(); 705 | if(transport.responseText.indexOf("true")==0) 706 | { 707 | new struct.message().showMessage("订阅成功!"); 708 | } 709 | else if(transport.responseText.indexOf("false")==0) 710 | { 711 | new struct.message().showMessage("订阅失败!"); 712 | } 713 | else if(transport.responseText.indexOf("invalid")==0) 714 | { 715 | new struct.message().showMessage("邮件地址不正确!例如:example@ingod.asia"); 716 | } 717 | else if(transport.responseText.indexOf("error")==0) 718 | { 719 | new struct.message().showMessage("无法发送邮件,请检查是否正确连接到邮箱服务器!"); 720 | } 721 | else if(transport.getResponseHeader("Status")=="0000") 722 | { 723 | new struct.message().showMessage("你没有足够的权限执行此项操作!"); 724 | } 725 | else if(transport.responseText.indexOf('<')==0) 726 | { 727 | new struct.message().showMessage("你需要登录以后才可以使用此项功能!"); 728 | } 729 | else 730 | { 731 | new struct.message().showMessage("邮件服务目前比较忙,无法发送邮件,请稍后重试!"); 732 | } 733 | 734 | submit.disabled=""; 735 | }).error(function(transport){ 736 | submit.disabled=""; 737 | loading.stop(); 738 | }); 739 | } 740 | return false; 741 | } 742 | 743 | function invite() 744 | { 745 | var email=document.getElementById('email').value; 746 | var submit=document.getElementById('invite_button'); 747 | var loading=new struct.loading(document.getElementById('invite-message')); 748 | if(email && submit) 749 | { 750 | submit.disabled="disabled"; 751 | 752 | loading.start(); 753 | $.ajax({ 754 | url:"?q=friends/invite", 755 | data:{mailto:email} 756 | }).error(function(){ 757 | submit.disabled=""; 758 | loading.stop(); 759 | }).success(function(data,textStatus,transport){ 760 | loading.stop(); 761 | if(data.indexOf("true")==0) 762 | { 763 | new struct.message().showMessage("邀请成功!"); 764 | } 765 | else if(data.indexOf("false")==0) 766 | { 767 | new struct.message().showMessage("邀请失败!"); 768 | } 769 | else if(data.indexOf("invalid")==0) 770 | { 771 | new struct.message().showMessage("邮件地址不正确!例如:example@ingod.asia"); 772 | } 773 | else if(data.indexOf("error")==0) 774 | { 775 | new struct.message().showMessage("无法发送邮件,请检查是否正确连接到邮箱服务器!"); 776 | } 777 | else if(transport.getResponseHeader("Status")=="0000") 778 | { 779 | new struct.message().showMessage("你没有足够的权限执行此项操作!"); 780 | } 781 | else if(data.indexOf('<')==0) 782 | { 783 | new struct.message().showMessage("你需要登录以后才可以使用此项功能!"); 784 | } 785 | else 786 | { 787 | new struct.message().showMessage("邮件服务目前比较忙,无法发送邮件,请稍后重试!"); 788 | } 789 | 790 | submit.disabled=""; 791 | }); 792 | } 793 | return false; 794 | } 795 | 796 | var ImageBox=function(){ 797 | this.start=typeof(arguments[0])!=undefined?arguments[0].start:0; 798 | this.end=typeof(arguments[0])!=undefined?arguments[0].end:0; 799 | this.panel=typeof(arguments[0])!=undefined?arguments[0].panel:document.createElement("div"); 800 | 801 | this.pagesize=21; 802 | this.image_list=null; 803 | 804 | this.click=typeof(arguments[0])!=undefined?arguments[0].click:function(){alert("Undefined Function!")}; 805 | this.close=typeof(arguments[0])!=undefined?arguments[0].onclose:function(){alert("Undefined Function!")}; 806 | 807 | this.selectedImage=""; 808 | this.hide=function(){ 809 | this.panel.style.display="none"; 810 | }; 811 | this.getImages=function() 812 | { 813 | var $this=this; 814 | 815 | this.image_list=document.createElement("table"); 816 | var image_line=document.createElement("tr"); 817 | var size=this.start+this.pagesize; 818 | 819 | if(size>this.end)size=this.end; 820 | for(var i=this.start;i$this.end?0:$this.start+$this.pagesize,end:$this.end,panel:$this.panel,click:$this.click,onclose:$this.close}).getImages(); 876 | $this.panel.innerHTML=''; 877 | $this.panel.appendChild($this.image_list); 878 | }); 879 | } 880 | 881 | struct.attachEvent(page_back_button,"click",function(event){ 882 | $this.image_list=new ImageBox({start:($this.start-$this.pagesize)<0?0:$this.start-$this.pagesize,end:$this.end,panel:$this.panel,click:$this.click,onclose:$this.close}).getImages(); 883 | $this.panel.innerHTML=''; 884 | $this.panel.appendChild($this.image_list); 885 | }); 886 | 887 | page_button_panel.appendChild(page_back_button); 888 | page_button_panel.appendChild(page_next_button); 889 | page_button_panel.appendChild(page_close_button); 890 | 891 | page_controller.appendChild(page_button_panel); 892 | 893 | this.image_list.appendChild(page_controller); 894 | 895 | return this.image_list; 896 | } 897 | } -------------------------------------------------------------------------------- /src/main/java/ApplicationGenerator.java: -------------------------------------------------------------------------------- 1 | 2 | import org.tinystruct.ApplicationException; 3 | import org.tinystruct.data.tools.Generator; 4 | import org.tinystruct.data.tools.MySQLGenerator; 5 | 6 | public class ApplicationGenerator { 7 | public static void main(String[]arguments) 8 | { 9 | 10 | System.out.println("Please type the command like this:ApplicationGenerator className tableName"); 11 | 12 | try { 13 | String[] list=new String[]{"book"}; 14 | // String[] list=new String[]{"Member","User","Rights","Role"}; 15 | for(String className:list) 16 | { 17 | Generator generator=new MySQLGenerator(); 18 | generator.setPath("src/custom/objects/"); 19 | generator.setPackageName("custom.objects"); 20 | generator.importPackages("java.util.Date"); 21 | generator.create(className,className); 22 | System.out.println("class:"+className+" table:"+className); 23 | } 24 | } catch (ApplicationException e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | System.out.println("OK!"); 29 | System.out.close(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/custom/objects/Account.java: -------------------------------------------------------------------------------- 1 | package custom.objects; 2 | 3 | import org.tinystruct.data.component.AbstractData; 4 | import org.tinystruct.data.component.Row; 5 | 6 | public class Account extends AbstractData { 7 | 8 | public String getUsername() { 9 | return username; 10 | } 11 | 12 | public void setUsername(String username) { 13 | this.username = username; 14 | } 15 | 16 | public String getPassword() { 17 | return password; 18 | } 19 | 20 | public void setPassword(String password) { 21 | this.password = password; 22 | } 23 | 24 | private String username; 25 | private String password; 26 | 27 | public String getEmail() { 28 | return email; 29 | } 30 | 31 | public void setEmail(String email) { 32 | this.email = email; 33 | } 34 | 35 | private String email; 36 | 37 | @Override 38 | public void setData(Row row) { 39 | if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); 40 | if(row.getFieldInfo("email")!=null) this.setEmail(row.getFieldInfo("email").stringValue()); 41 | if(row.getFieldInfo("username")!=null) this.setUsername(row.getFieldInfo("username").stringValue()); 42 | if(row.getFieldInfo("password")!=null) this.setPassword(row.getFieldInfo("password").stringValue()); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | StringBuffer buffer=new StringBuffer(); 48 | buffer.append("{"); 49 | buffer.append("\"Id\":\""+this.getId()+"\""); 50 | buffer.append(",\"email\":\""+this.getEmail()+"\""); 51 | buffer.append(",\"username\":\""+this.getUsername()+"\""); 52 | buffer.append(",\"password\":\""+this.getPassword()+"\""); 53 | buffer.append("}"); 54 | return buffer.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/custom/objects/User.java: -------------------------------------------------------------------------------- 1 | package custom.objects; 2 | 3 | import java.util.Date; 4 | 5 | import org.tinystruct.data.component.Row; 6 | import org.tinystruct.data.component.AbstractData; 7 | 8 | public class User extends AbstractData { 9 | private String email; 10 | private String username; 11 | private String password; 12 | private String nickname; 13 | private String introduce; 14 | private int gender; 15 | private String firstName; 16 | private String lastName; 17 | private String country; 18 | private String city; 19 | private String telephone; 20 | private String postcode; 21 | private String lastloginIP; 22 | private Date lastloginTime; 23 | private Date registrationTime; 24 | private String logo; 25 | private boolean status; 26 | 27 | public String getId() 28 | { 29 | return String.valueOf(this.Id); 30 | } 31 | 32 | public void setEmail(String email) 33 | { 34 | this.email=this.setFieldAsString("email",email); 35 | } 36 | 37 | public String getEmail() 38 | { 39 | return this.email; 40 | } 41 | 42 | public void setUsername(String username) 43 | { 44 | this.username=this.setFieldAsString("username",username); 45 | } 46 | 47 | public String getUsername() 48 | { 49 | return this.username; 50 | } 51 | 52 | public void setPassword(String password) 53 | { 54 | this.password=this.setFieldAsString("password",password); 55 | } 56 | 57 | public String getPassword() 58 | { 59 | return this.password; 60 | } 61 | 62 | public void setNickname(String nickname) 63 | { 64 | this.nickname=this.setFieldAsString("nickname",nickname); 65 | } 66 | 67 | public String getNickname() 68 | { 69 | return this.nickname; 70 | } 71 | 72 | public void setIntroduce(String introduce) 73 | { 74 | this.introduce=this.setFieldAsString("introduce",introduce); 75 | } 76 | 77 | public String getIntroduce() 78 | { 79 | return this.introduce; 80 | } 81 | 82 | public void setGender(int gender) 83 | { 84 | this.gender=this.setFieldAsInt("gender",gender); 85 | } 86 | 87 | public int getGender() 88 | { 89 | return this.gender; 90 | } 91 | 92 | public void setFirstName(String firstName) 93 | { 94 | this.firstName=this.setFieldAsString("firstName",firstName); 95 | } 96 | 97 | public String getFirstName() 98 | { 99 | return this.firstName; 100 | } 101 | 102 | public void setLastName(String lastName) 103 | { 104 | this.lastName=this.setFieldAsString("lastName",lastName); 105 | } 106 | 107 | public String getLastName() 108 | { 109 | return this.lastName; 110 | } 111 | 112 | public void setCountry(String country) 113 | { 114 | this.country=this.setFieldAsString("country",country); 115 | } 116 | 117 | public String getCountry() 118 | { 119 | return this.country; 120 | } 121 | 122 | public void setCity(String city) 123 | { 124 | this.city=this.setFieldAsString("city",city); 125 | } 126 | 127 | public String getCity() 128 | { 129 | return this.city; 130 | } 131 | 132 | public void setTelephone(String telephone) 133 | { 134 | this.telephone=this.setFieldAsString("telephone",telephone); 135 | } 136 | 137 | public String getTelephone() 138 | { 139 | return this.telephone; 140 | } 141 | 142 | public void setPostcode(String postcode) 143 | { 144 | this.postcode=this.setFieldAsString("postcode",postcode); 145 | } 146 | 147 | public String getPostcode() 148 | { 149 | return this.postcode; 150 | } 151 | 152 | public void setLastloginIP(String lastloginIP) 153 | { 154 | this.lastloginIP=this.setFieldAsString("lastloginIP",lastloginIP); 155 | } 156 | 157 | public String getLastloginIP() 158 | { 159 | return this.lastloginIP; 160 | } 161 | 162 | public void setLastloginTime(Date lastloginTime) 163 | { 164 | this.lastloginTime=this.setFieldAsDate("lastloginTime",lastloginTime); 165 | } 166 | 167 | public Date getLastloginTime() 168 | { 169 | return this.lastloginTime; 170 | } 171 | 172 | public void setRegistrationTime(Date registrationTime) 173 | { 174 | this.registrationTime=this.setFieldAsDate("registrationTime",registrationTime); 175 | } 176 | 177 | public Date getRegistrationTime() 178 | { 179 | return this.registrationTime; 180 | } 181 | 182 | public void setLogo(String logo) 183 | { 184 | this.logo=this.setFieldAsString("logo",logo); 185 | } 186 | 187 | public String getLogo() 188 | { 189 | return this.logo; 190 | } 191 | 192 | public void setStatus(boolean status) 193 | { 194 | this.status=this.setFieldAsBoolean("status",status); 195 | } 196 | 197 | public boolean getStatus() 198 | { 199 | return this.status; 200 | } 201 | 202 | 203 | @Override 204 | public void setData(Row row) { 205 | if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); 206 | if(row.getFieldInfo("email")!=null) this.setEmail(row.getFieldInfo("email").stringValue()); 207 | if(row.getFieldInfo("username")!=null) this.setUsername(row.getFieldInfo("username").stringValue()); 208 | if(row.getFieldInfo("password")!=null) this.setPassword(row.getFieldInfo("password").stringValue()); 209 | if(row.getFieldInfo("nickname")!=null) this.setNickname(row.getFieldInfo("nickname").stringValue()); 210 | if(row.getFieldInfo("introduce")!=null) this.setIntroduce(row.getFieldInfo("introduce").stringValue()); 211 | if(row.getFieldInfo("gender")!=null) this.setGender(row.getFieldInfo("gender").intValue()); 212 | if(row.getFieldInfo("first_name")!=null) this.setFirstName(row.getFieldInfo("first_name").stringValue()); 213 | if(row.getFieldInfo("last_name")!=null) this.setLastName(row.getFieldInfo("last_name").stringValue()); 214 | if(row.getFieldInfo("country")!=null) this.setCountry(row.getFieldInfo("country").stringValue()); 215 | if(row.getFieldInfo("city")!=null) this.setCity(row.getFieldInfo("city").stringValue()); 216 | if(row.getFieldInfo("telephone")!=null) this.setTelephone(row.getFieldInfo("telephone").stringValue()); 217 | if(row.getFieldInfo("postcode")!=null) this.setPostcode(row.getFieldInfo("postcode").stringValue()); 218 | if(row.getFieldInfo("lastlogin_IP")!=null) this.setLastloginIP(row.getFieldInfo("lastlogin_IP").stringValue()); 219 | if(row.getFieldInfo("lastlogin_time")!=null) this.setLastloginTime(row.getFieldInfo("lastlogin_time").dateValue()); 220 | if(row.getFieldInfo("registration_time")!=null) this.setRegistrationTime(row.getFieldInfo("registration_time").dateValue()); 221 | if(row.getFieldInfo("logo")!=null) this.setLogo(row.getFieldInfo("logo").stringValue()); 222 | if(row.getFieldInfo("status")!=null) this.setStatus(row.getFieldInfo("status").booleanValue()); 223 | } 224 | 225 | @Override 226 | public String toString() { 227 | StringBuffer buffer=new StringBuffer(); 228 | buffer.append("{"); 229 | buffer.append("\"Id\":\""+this.getId()+"\""); 230 | buffer.append(",\"email\":\""+this.getEmail()+"\""); 231 | buffer.append(",\"username\":\""+this.getUsername()+"\""); 232 | buffer.append(",\"password\":\""+this.getPassword()+"\""); 233 | buffer.append(",\"nickname\":\""+this.getNickname()+"\""); 234 | buffer.append(",\"introduce\":\""+this.getIntroduce()+"\""); 235 | buffer.append(",\"gender\":"+this.getGender()); 236 | buffer.append(",\"firstName\":\""+this.getFirstName()+"\""); 237 | buffer.append(",\"lastName\":\""+this.getLastName()+"\""); 238 | buffer.append(",\"country\":\""+this.getCountry()+"\""); 239 | buffer.append(",\"city\":\""+this.getCity()+"\""); 240 | buffer.append(",\"telephone\":\""+this.getTelephone()+"\""); 241 | buffer.append(",\"postcode\":\""+this.getPostcode()+"\""); 242 | buffer.append(",\"lastloginIP\":\""+this.getLastloginIP()+"\""); 243 | buffer.append(",\"lastloginTime\":\""+this.getLastloginTime()+"\""); 244 | buffer.append(",\"registrationTime\":\""+this.getRegistrationTime()+"\""); 245 | buffer.append(",\"logo\":\""+this.getLogo()+"\""); 246 | buffer.append(",\"status\":"+this.getStatus()); 247 | buffer.append("}"); 248 | return buffer.toString(); 249 | } 250 | 251 | } -------------------------------------------------------------------------------- /src/main/java/custom/objects/article.java: -------------------------------------------------------------------------------- 1 | package custom.objects; 2 | 3 | import org.tinystruct.data.component.AbstractData; 4 | import org.tinystruct.data.component.Row; 5 | 6 | public class article extends AbstractData { 7 | private String bookId; 8 | private int chapterId; 9 | private int sectionId; 10 | private String content; 11 | 12 | public Integer getId() 13 | { 14 | return Integer.parseInt(this.Id.toString()); 15 | } 16 | 17 | public void setBookId(String bookId) 18 | { 19 | this.bookId=this.setFieldAsString("bookId",bookId); 20 | } 21 | 22 | public String getBookId() 23 | { 24 | return this.bookId; 25 | } 26 | 27 | public void setChapterId(int chapterId) 28 | { 29 | this.chapterId=this.setFieldAsInt("chapterId",chapterId); 30 | } 31 | 32 | public int getChapterId() 33 | { 34 | return this.chapterId; 35 | } 36 | 37 | public void setSectionId(int sectionId) 38 | { 39 | this.sectionId=this.setFieldAsInt("sectionId",sectionId); 40 | } 41 | 42 | public int getSectionId() 43 | { 44 | return this.sectionId; 45 | } 46 | 47 | public void setContent(String content) 48 | { 49 | this.content=this.setFieldAsString("content",content); 50 | } 51 | 52 | public String getContent() 53 | { 54 | return this.content; 55 | } 56 | 57 | 58 | @Override 59 | public void setData(Row row) { 60 | if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").intValue()); 61 | if(row.getFieldInfo("book_id")!=null) this.setBookId(row.getFieldInfo("book_id").stringValue()); 62 | if(row.getFieldInfo("chapter_id")!=null) this.setChapterId(row.getFieldInfo("chapter_id").intValue()); 63 | if(row.getFieldInfo("section_id")!=null) this.setSectionId(row.getFieldInfo("section_id").intValue()); 64 | if(row.getFieldInfo("content")!=null) this.setContent(row.getFieldInfo("content").stringValue()); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | StringBuffer buffer=new StringBuffer(); 70 | buffer.append("{"); 71 | buffer.append("\"Id\":"+this.getId()); 72 | buffer.append(",\"bookId\":\""+this.getBookId()+"\""); 73 | buffer.append(",\"chapterId\":"+this.getChapterId()); 74 | buffer.append(",\"sectionId\":"+this.getSectionId()); 75 | buffer.append(",\"content\":\""+this.getContent()+"\""); 76 | buffer.append("}"); 77 | return buffer.toString(); 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /src/main/java/custom/objects/book.java: -------------------------------------------------------------------------------- 1 | package custom.objects; 2 | 3 | import java.util.Date; 4 | 5 | import org.tinystruct.data.component.Row; 6 | import org.tinystruct.data.component.AbstractData; 7 | 8 | public class book extends AbstractData { 9 | private String name; 10 | private String cover; 11 | private String author; 12 | private String translator; 13 | private String publisher; 14 | private Date publishDate; 15 | private String language; 16 | 17 | public String getId() 18 | { 19 | return String.valueOf(this.Id); 20 | } 21 | 22 | public void setName(String name) 23 | { 24 | this.name=this.setFieldAsString("name",name); 25 | } 26 | 27 | public String getName() 28 | { 29 | return this.name; 30 | } 31 | 32 | public void setCover(String cover) 33 | { 34 | this.cover=this.setFieldAsString("cover",cover); 35 | } 36 | 37 | public String getCover() 38 | { 39 | return this.cover; 40 | } 41 | 42 | public void setAuthor(String author) 43 | { 44 | this.author=this.setFieldAsString("author",author); 45 | } 46 | 47 | public String getAuthor() 48 | { 49 | return this.author; 50 | } 51 | 52 | public void setTranslator(String translator) 53 | { 54 | this.translator=this.setFieldAsString("translator",translator); 55 | } 56 | 57 | public String getTranslator() 58 | { 59 | return this.translator; 60 | } 61 | 62 | public void setPublisher(String publisher) 63 | { 64 | this.publisher=this.setFieldAsString("publisher",publisher); 65 | } 66 | 67 | public String getPublisher() 68 | { 69 | return this.publisher; 70 | } 71 | 72 | public void setPublishDate(Date publishDate) 73 | { 74 | this.publishDate=this.setFieldAsDate("publishDate",publishDate); 75 | } 76 | 77 | public Date getPublishDate() 78 | { 79 | return this.publishDate; 80 | } 81 | 82 | public void setLanguage(String language) 83 | { 84 | this.language=this.setFieldAsString("language",language); 85 | } 86 | 87 | public String getLanguage() 88 | { 89 | return this.language; 90 | } 91 | 92 | 93 | @Override 94 | public void setData(Row row) { 95 | if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); 96 | if(row.getFieldInfo("name")!=null) this.setName(row.getFieldInfo("name").stringValue()); 97 | if(row.getFieldInfo("cover")!=null) this.setCover(row.getFieldInfo("cover").stringValue()); 98 | if(row.getFieldInfo("author")!=null) this.setAuthor(row.getFieldInfo("author").stringValue()); 99 | if(row.getFieldInfo("translator")!=null) this.setTranslator(row.getFieldInfo("translator").stringValue()); 100 | if(row.getFieldInfo("publisher")!=null) this.setPublisher(row.getFieldInfo("publisher").stringValue()); 101 | if(row.getFieldInfo("publish_date")!=null) this.setPublishDate(row.getFieldInfo("publish_date").dateValue()); 102 | if(row.getFieldInfo("language")!=null) this.setLanguage(row.getFieldInfo("language").stringValue()); 103 | } 104 | 105 | @Override 106 | public String toString() { 107 | StringBuffer buffer=new StringBuffer(); 108 | buffer.append("{"); 109 | buffer.append("\"Id\":\""+this.getId()+"\""); 110 | buffer.append(",\"name\":\""+this.getName()+"\""); 111 | buffer.append(",\"cover\":\""+this.getCover()+"\""); 112 | buffer.append(",\"author\":\""+this.getAuthor()+"\""); 113 | buffer.append(",\"translator\":\""+this.getTranslator()+"\""); 114 | buffer.append(",\"publisher\":\""+this.getPublisher()+"\""); 115 | buffer.append(",\"publishDate\":\""+this.getPublishDate()+"\""); 116 | buffer.append(",\"language\":\""+this.getLanguage()+"\""); 117 | buffer.append("}"); 118 | return buffer.toString(); 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/RequestMerger.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import org.tinystruct.AbstractApplication; 4 | 5 | import java.util.HashMap; 6 | import java.util.concurrent.*; 7 | 8 | @SuppressWarnings("unchecked") 9 | public class RequestMerger extends AbstractApplication { 10 | private static RequestMerger ourInstance = new RequestMerger(); 11 | private LinkedBlockingQueue queue = new LinkedBlockingQueue(); 12 | private ScheduledThreadPoolExecutor executorService; 13 | 14 | public static RequestMerger getInstance() { 15 | return ourInstance; 16 | } 17 | 18 | private RequestMerger() { 19 | } 20 | 21 | @Override 22 | public void init() { 23 | executorService = new ScheduledThreadPoolExecutor(1); 24 | executorService.scheduleAtFixedRate(new Runnable() { 25 | @Override 26 | public void run() { 27 | int size = queue.size(); 28 | for(int i = 0 ; i < size; i++) { 29 | AsyncRequest req = queue.poll(); 30 | } 31 | 32 | 33 | 34 | /* 35 | HashMap> responses = new HashMap(); 36 | for(Map response : responses) { 37 | String requestId = response.get("requestId").toString(); 38 | responses.put(requestId, response); 39 | } 40 | */ 41 | 42 | 43 | } 44 | }, 0, 10, TimeUnit.MILLISECONDS); 45 | } 46 | 47 | public HashMap take(AsyncRequest request) throws InterruptedException, ExecutionException { 48 | request.future = new CompletableFuture(); 49 | queue.put(request); 50 | 51 | return request.future.get(); 52 | } 53 | 54 | private void workon(AsyncRequest request) { 55 | 56 | } 57 | 58 | @Override 59 | public String version() { 60 | return null; 61 | } 62 | } 63 | 64 | class AsyncRequest { 65 | public String requestId; 66 | public Future> future; 67 | } 68 | 69 | interface Result { 70 | T get(); 71 | } -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/bible.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | 6 | import org.tinystruct.AbstractApplication; 7 | import org.tinystruct.ApplicationContext; 8 | import org.tinystruct.ApplicationException; 9 | import org.tinystruct.ApplicationRuntimeException; 10 | import org.tinystruct.system.ApplicationManager; 11 | import org.tinystruct.system.Dispatcher; 12 | import org.tinystruct.system.annotation.Action; 13 | import org.tinystruct.system.util.URLResourceLoader; 14 | 15 | public class bible extends AbstractApplication { 16 | 17 | @Override 18 | public void init() { 19 | // TODO Auto-generated method stub 20 | } 21 | 22 | @Override 23 | public String version() { 24 | return "v1.0"; 25 | } 26 | 27 | @Action("bible") 28 | public String open(String pattern) throws ApplicationException { 29 | pattern = pattern.replace('.', '/'); // To avoid the conflict with the path query 30 | URL uri; 31 | try { 32 | uri = new URL("http://rcuv.hkbs.org.hk/bb/info/CUNPs_1/"+pattern+"/"); 33 | URLResourceLoader loader = new URLResourceLoader(uri ); 34 | StringBuilder buffer = loader.getContent(); 35 | 36 | return this.preprocess(buffer.toString()); 37 | } catch (MalformedURLException e) { 38 | throw new ApplicationException(e.getMessage(), e.getCause()); 39 | } 40 | } 41 | 42 | protected String preprocess(String text) { 43 | return text.split("[\r\n]")[4].replace('「', '“').replace('『', '‘').replace('」', '”').replace('』', '’'); 44 | } 45 | 46 | public static void main(String[] args) throws ApplicationException { 47 | ApplicationContext ctx = new ApplicationContext(); 48 | ctx.setAttribute("--http.proxyHost", "135.245.48.34"); 49 | ctx.setAttribute("--http.proxyPort", "8000"); 50 | 51 | ApplicationManager.install(new Dispatcher()); 52 | ApplicationManager.install(new bible()); 53 | 54 | ApplicationManager.call("set/--http.proxyHost", ctx); 55 | ApplicationManager.call("set/--http.proxyPort", ctx); 56 | 57 | System.out.println(ApplicationManager.call("bible/GEN.3", ctx)); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/dateConverter.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.text.DateFormat; 7 | import java.text.ParseException; 8 | import java.text.SimpleDateFormat; 9 | 10 | import org.tinystruct.AbstractApplication; 11 | import org.tinystruct.system.annotation.Action; 12 | import org.tinystruct.system.annotation.Argument; 13 | 14 | public class dateConverter extends AbstractApplication { 15 | 16 | @Override 17 | public void init() { 18 | // TODO Auto-generated method stub 19 | } 20 | 21 | @Override 22 | public String version() { 23 | // TODO Auto-generated method stub 24 | return null; 25 | } 26 | 27 | @Action(value = "convert", arguments = { 28 | @Argument(key = "from", description = "From date"), 29 | @Argument(key = "to", description = "To date") 30 | }) 31 | public String convert() throws IOException, ParseException { 32 | String from = getContext().getAttribute("from").toString(); 33 | String to = getContext().getAttribute("to").toString(); 34 | return this.convert(from, to); 35 | } 36 | /** 37 | 26/01/2018 11:09:51 38 | 26/01/2018 15:09:10 39 | 29/01/2018 09:14:44 40 | 30/01/2018 09:14:53 41 | 30/01/2018 13:11:53 42 | 01/02/2018 10:38:44 43 | 01/02/2018 11:18:31 44 | 01/02/2018 12:38:54 45 | * 46 | * @return 47 | * @throws IOException 48 | * @throws ParseException 49 | */ 50 | public String convert(String from, String to) throws IOException, ParseException { 51 | StringBuffer list = new StringBuffer(); 52 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 53 | System.out.println("Enter some date list or press enter to quit:"); 54 | 55 | DateFormat t = new SimpleDateFormat(to); 56 | DateFormat f = new SimpleDateFormat(from); 57 | String input; 58 | while (true) { 59 | input = br.readLine().trim(); 60 | if (input.length() == 0) { 61 | break; 62 | } 63 | list.append(t.format(f.parse(input))).append("\n"); 64 | } 65 | 66 | return list.toString(); 67 | } 68 | 69 | public static void main(String[]args) throws IOException, ParseException { 70 | System.out.println(new dateConverter().convert("dd/MM/yyyy HH:mm", "yyyy/MM/dd HH:mm:ss")); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/distributedLockApp.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import org.tinystruct.AbstractApplication; 4 | import org.tinystruct.ApplicationException; 5 | import org.tinystruct.system.ApplicationManager; 6 | import org.tinystruct.system.annotation.Action; 7 | import org.tinystruct.valve.DistributedLock; 8 | import org.tinystruct.valve.Lock; 9 | import org.tinystruct.valve.Watcher; 10 | 11 | import java.util.concurrent.TimeUnit; 12 | 13 | public class distributedLockApp extends AbstractApplication { 14 | 15 | @Override 16 | public void init() { 17 | // TODO Auto-generated method stub 18 | } 19 | 20 | @Override 21 | public String version() { 22 | // TODO Auto-generated method stub 23 | return null; 24 | } 25 | 26 | @Action("lock") 27 | public void lock() throws ApplicationException { 28 | Lock lock = Watcher.getInstance().acquire(); 29 | 30 | if (lock != null) { 31 | System.out.println("Lock Id:" + lock.id()); 32 | lock.lock(); 33 | } 34 | } 35 | 36 | @Action("unlock") 37 | public void unlock(String lockId) throws ApplicationException { 38 | Lock lock = new DistributedLock(lockId.getBytes()); 39 | System.out.println("UnLock Id:" + lock.id()); 40 | lock.unlock(); 41 | } 42 | 43 | @Action("unlock") 44 | public void unlock() throws ApplicationException { 45 | Lock lock = Watcher.getInstance().acquire(); 46 | if (lock != null) { 47 | System.out.println("UnLock Id:" + lock.id()); 48 | lock.unlock(); 49 | } else { 50 | System.out.println("No task is locked."); 51 | } 52 | } 53 | 54 | public static void main(String[] args) throws ApplicationException, InterruptedException { 55 | ApplicationManager.init(); 56 | ApplicationManager.install(new distributedLockApp()); 57 | try { 58 | System.out.println("Lock started..."); 59 | ApplicationManager.call("lock", null); 60 | Thread.sleep(5000); 61 | System.out.println("Hello, I executed this printing after lock released."); 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | } finally { 65 | ApplicationManager.call("unlock", null); 66 | } 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/error.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | 4 | import org.tinystruct.AbstractApplication; 5 | import org.tinystruct.ApplicationException; 6 | import org.tinystruct.dom.Element; 7 | import org.tinystruct.handler.Reforward; 8 | import org.tinystruct.http.Request; 9 | import org.tinystruct.http.Response; 10 | import org.tinystruct.http.Session; 11 | import org.tinystruct.system.annotation.Action; 12 | 13 | public class error extends AbstractApplication { 14 | 15 | private Request request; 16 | private Response response; 17 | private Reforward reforward; 18 | 19 | @Override 20 | public void init() { 21 | // TODO Auto-generated method stub 22 | } 23 | 24 | @Override 25 | public String version() { 26 | // TODO Auto-generated method stub 27 | return null; 28 | } 29 | 30 | @Action("error") 31 | public Object process() throws ApplicationException { 32 | this.request = (Request) getContext().getAttribute("HTTP_REQUEST"); 33 | this.response = (Response) getContext().getAttribute("HTTP_RESPONSE"); 34 | 35 | this.reforward = new Reforward(this.request, this.response); 36 | 37 | this.setVariable("from", this.reforward.getFromURL()); 38 | 39 | Session session = this.request.getSession(); 40 | 41 | if (session.getAttribute("error") != null) { 42 | ApplicationException exception = (ApplicationException) session.getAttribute("error"); 43 | 44 | String message = exception.getRootCause().getMessage(); 45 | if (message != null) this.setVariable("exception.message", message); 46 | else this.setVariable("exception.message", "Unknown error"); 47 | 48 | this.setVariable("exception.details", this.getDetail(exception).toString()); 49 | return this.getVariable("exception.message").getValue().toString() + this.getVariable("exception.details").getValue(); 50 | } else { 51 | this.reforward.forward(); 52 | } 53 | 54 | return "This request is forbidden!"; 55 | } 56 | 57 | private Element getDetail(ApplicationException exception) { 58 | Element errors = new Element("ul"); 59 | int i = 0; 60 | 61 | Throwable ex = exception.getRootCause(); 62 | 63 | StackTraceElement[] trace = ex.getStackTrace(); 64 | 65 | while (i < trace.length) { 66 | Element element = new Element("li"); 67 | element.setData(trace[i++].toString()); 68 | errors.addElement(element); 69 | } 70 | 71 | return errors; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/example.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | 4 | import org.tinystruct.AbstractApplication; 5 | import org.tinystruct.ApplicationException; 6 | 7 | public class example extends AbstractApplication { 8 | 9 | @Override 10 | public void init() { 11 | // TODO Auto-generated method stub 12 | this.setAction("praise", "praise"); 13 | this.setAction("say", "say"); 14 | this.setAction("smile", "smile"); 15 | } 16 | 17 | @Override 18 | public String version() { 19 | return "1.0"; 20 | } 21 | 22 | public String praise() { 23 | return "Praise to the Lord!"; 24 | } 25 | 26 | public String say() throws ApplicationException { 27 | if (null != getContext().getAttribute("--words")) 28 | return getContext().getAttribute("--words").toString(); 29 | 30 | throw new ApplicationException("Could not find the parameter words."); 31 | } 32 | 33 | public String say(String words) { 34 | return words; 35 | } 36 | 37 | public String smile() { 38 | return ":)"; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/firstApplication.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | import org.tinystruct.AbstractApplication; 3 | import org.tinystruct.Application; 4 | import org.tinystruct.ApplicationContext; 5 | import org.tinystruct.ApplicationException; 6 | import org.tinystruct.data.component.Builder; 7 | import org.tinystruct.data.component.Table; 8 | import org.tinystruct.data.tools.Generator; 9 | import org.tinystruct.data.tools.MySQLGenerator; 10 | import org.tinystruct.system.ApplicationManager; 11 | 12 | import custom.objects.User; 13 | import org.tinystruct.system.Dispatcher; 14 | import org.tinystruct.system.annotation.Action; 15 | import org.tinystruct.system.annotation.Argument; 16 | 17 | public class firstApplication extends AbstractApplication { 18 | 19 | @Override 20 | public void init() { 21 | // TODO Auto-generated method stub 22 | } 23 | 24 | @Action("praise") 25 | public String praise(){ 26 | return "Praise to the Lord!"; 27 | } 28 | 29 | @Action("youhappy") 30 | public boolean happy(){ 31 | return true; 32 | } 33 | 34 | @Action("read") 35 | public Object read(String json,String name){ 36 | Builder builder = new Builder(); 37 | try { 38 | builder.parse(json); 39 | } catch (ApplicationException e) { 40 | // TODO Auto-generated catch block 41 | e.printStackTrace(); 42 | } 43 | 44 | return builder.get(name); 45 | } 46 | 47 | @Action("say") 48 | public String say() throws ApplicationException { 49 | if(null != getContext().getAttribute("words")) 50 | return getContext().getAttribute("words").toString(); 51 | 52 | throw new ApplicationException("Could not find the parameter words."); 53 | } 54 | 55 | @Action("say") 56 | public String say(String words){ 57 | return words; 58 | } 59 | 60 | @Action("version") 61 | @Override 62 | public String version() { 63 | // TODO Auto-generated method stub 64 | return getContext().getAttribute("name") + getContext().getAttribute("number").toString(); 65 | } 66 | 67 | @Action(value = "version", options = { 68 | @Argument(key = "POST", description = "POST method"), 69 | }) 70 | public void setVersion(float number){ 71 | getContext().setAttribute("name", "struct"); 72 | getContext().setAttribute("number", number); 73 | Dispatcher d; 74 | } 75 | 76 | @Action("generate") 77 | public void generate_with_user_table(){ 78 | try { 79 | String[] list=new String[]{"User"}; 80 | Generator generator=new MySQLGenerator(); 81 | for(String className:list) 82 | { 83 | generator.setPath("src/custom/objects/"); 84 | generator.setPackageName("custom.objects"); 85 | generator.importPackages("java.util.Date"); 86 | generator.create(className,className); 87 | System.out.println("class:"+className+" table:"+className); 88 | System.out.println("Done!"); 89 | } 90 | } catch (ApplicationException e) { 91 | // TODO Auto-generated catch block 92 | e.printStackTrace(); 93 | } 94 | } 95 | 96 | @Action("user") 97 | public User findUser(Object userId) throws ApplicationException{ 98 | 99 | if(userId!=null){ 100 | User user = new User(); 101 | user.setId(userId); 102 | user.findOneById(); 103 | 104 | return user; 105 | } 106 | 107 | return null; 108 | } 109 | 110 | @Action("users") 111 | public Table findUsers() throws ApplicationException{ 112 | return new User().findAll(); 113 | } 114 | 115 | /** 116 | * The following example code only for you to reference. 117 | * @param args 118 | * @throws ApplicationException 119 | */ 120 | public static void main(String[]args) throws ApplicationException { 121 | ApplicationManager.install(new firstApplication()); 122 | 123 | System.out.println(ApplicationManager.call("praise", null)); // Praise to the Lord! 124 | System.out.println("I am "+ApplicationManager.call("youhappy", null)+"ly happy"); // I am truely happy 125 | 126 | ApplicationManager.call("say/Hello World", null); // Hello World 127 | 128 | Application app=ApplicationManager.get( firstApplication.class.getName()); 129 | app.invoke("say", new Object[]{"

Hello, World!

"}); //

Hello, World!

130 | app.invoke("say", new Object[]{"

Bye!

"}); //

Bye!

131 | 132 | ApplicationContext context=new ApplicationContext(); 133 | context.setAttribute("name", "struct"); 134 | context.setAttribute("number", 2.0); 135 | 136 | context.setAttribute("METHOD", "GET"); 137 | System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct2.0 138 | 139 | context.setAttribute("METHOD", "POST"); 140 | ApplicationManager.call("version/3", context); 141 | 142 | context.setAttribute("METHOD", "GET"); 143 | System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct3.0 144 | 145 | Object name = app.invoke("read", new Object[]{"{\"name\":\"Mover\",\"age\":30}","name"}); 146 | System.out.println(name); 147 | 148 | ApplicationManager.call("generate", null); 149 | 150 | System.out.println(ApplicationManager.call("user/1", null)); // http://localhost:8080/user/1 151 | System.out.println(ApplicationManager.call("users", null)); // http://localhost:8080/users 152 | } 153 | } -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/hello.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import custom.objects.Account; 4 | import org.tinystruct.AbstractApplication; 5 | import org.tinystruct.Application; 6 | import org.tinystruct.ApplicationException; 7 | import org.tinystruct.data.DatabaseOperator; 8 | import org.tinystruct.system.ApplicationManager; 9 | import org.tinystruct.system.ClassFileLoader; 10 | import org.tinystruct.system.Configuration; 11 | import org.tinystruct.system.Settings; 12 | import org.tinystruct.system.annotation.Action; 13 | 14 | import javax.servlet.ServletException; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import java.sql.PreparedStatement; 18 | 19 | public class hello extends AbstractApplication { 20 | 21 | private static final String AUTH_HEADER_KEY = "Authorization"; 22 | private static final String AUTH_HEADER_VALUE_PREFIX = "Bearer "; // with trailing space to separate token 23 | private static final int STATUS_CODE_UNAUTHORIZED = 401; 24 | 25 | @Override 26 | public void init() { 27 | // TODO Auto-generated method stub 28 | } 29 | 30 | @Override 31 | public String version() { 32 | System.out.println("tinystruct version 2.0.1"); 33 | return null; 34 | } 35 | 36 | @Action("login") 37 | public String login() throws ServletException { 38 | HttpServletRequest request = (HttpServletRequest) getContext().getAttribute("HTTP_REQUEST"); 39 | HttpServletResponse response = (HttpServletResponse) getContext().getAttribute("HTTP_RESPONSE"); 40 | 41 | String bearer = this.getBearerToken(request); 42 | 43 | if (null != bearer) { 44 | request.login("James", "0123456"); 45 | } 46 | else { 47 | response.setContentLength( 0 ); 48 | response.setStatus( STATUS_CODE_UNAUTHORIZED ); 49 | } 50 | 51 | return bearer; 52 | } 53 | 54 | @Action("render") 55 | public hello render() { 56 | return this; 57 | } 58 | 59 | /** 60 | * @param args 61 | * @throws ApplicationException 62 | * @throws IllegalAccessException 63 | * @throws InstantiationException 64 | */ 65 | public static void main(String[] args) throws ApplicationException, InstantiationException, IllegalAccessException { 66 | // Praise to the Lord! 67 | ApplicationManager.install(new hello()); 68 | 69 | // to print 'Hello World' 70 | ApplicationManager.call("say/Hello World", null); // Hello World 71 | 72 | // or... 73 | Application app = ApplicationManager.get(hello.class.getName()); 74 | app.invoke("say", new Object[]{"

Hello, World!

"}); //

Hello, World!

75 | app.invoke("say", new Object[]{"

Bye!

"}); //

Bye!

76 | 77 | // or... 78 | // http://localhost:8080/?q=say/Hello World 79 | 80 | // to run nothing 81 | ApplicationManager.call("smile", null); // Looks nothing 82 | 83 | // What will be happened? 84 | System.out.println(ApplicationManager.call("smile", null)); // Will render the default template 85 | 86 | // Use ClassFileLoader to load Java class 87 | ClassFileLoader loader = ClassFileLoader.getInstance(); 88 | 89 | Configuration config = new Settings("/application.properties"); 90 | config.set("default.apps.path", "WEB-INF/classes"); 91 | config.set("default.apps.package", "tinystruct.examples"); 92 | 93 | Class clz = loader.findClass("hello"); 94 | if (clz != null && clz.getSuperclass().equals(AbstractApplication.class)) { 95 | ApplicationManager.install((Application) clz.newInstance()); 96 | ApplicationManager.call("say/Merry Christmas!", null); 97 | } 98 | } 99 | 100 | /** 101 | * Get the bearer token from the HTTP request. 102 | * The token is in the HTTP request "Authorization" header in the form of: "Bearer [token]" 103 | */ 104 | private String getBearerToken(HttpServletRequest request) { 105 | String authHeader = request.getHeader(AUTH_HEADER_KEY); 106 | if (authHeader != null && authHeader.startsWith(AUTH_HEADER_VALUE_PREFIX)) { 107 | return authHeader.substring(AUTH_HEADER_VALUE_PREFIX.length()); 108 | } 109 | return null; 110 | } 111 | 112 | @Action("account") 113 | public void createAccount() { 114 | try (DatabaseOperator operator = new DatabaseOperator()){ 115 | String sql = "DROP TABLE ACCOUNT IF EXISTS; CREATE TABLE ACCOUNT(ID VARCHAR, USERNAME VARCHAR, PASSWORD VARCHAR, EMAIL VARCHAR);"; 116 | PreparedStatement ps = operator.preparedStatement(sql, new Object[]{}); 117 | operator.executeUpdate(ps); 118 | } catch (ApplicationException e) { 119 | e.printStackTrace(); 120 | } 121 | 122 | Account account = new Account(); 123 | account.setUsername("James"); 124 | account.setPassword("******"); 125 | account.setEmail("your@email.com"); 126 | try { 127 | account.append(); 128 | System.out.println("account = " + account); 129 | account.findOneById(); 130 | System.out.println("account = " + account); 131 | } catch (ApplicationException e) { 132 | e.printStackTrace(); 133 | } 134 | 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/image2.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.util.Base64; 10 | 11 | import org.tinystruct.AbstractApplication; 12 | import org.tinystruct.ApplicationContext; 13 | import org.tinystruct.ApplicationException; 14 | import org.tinystruct.system.ApplicationManager; 15 | 16 | /** 17 | * Image to Base64 conversion 18 | * Usage: dispatcher --image-path=/path/to/image image2base64 19 | * @author m0ver 20 | */ 21 | public class image2 extends AbstractApplication { 22 | 23 | private String imagePath; 24 | @Override 25 | public void init() { 26 | this.setAction("image2base64", "image2base64"); 27 | } 28 | 29 | @Override 30 | public String version() { 31 | return "1.0"; 32 | } 33 | 34 | public String image2base64() throws ApplicationException { 35 | if(getContext().getAttribute("--image-path")==null || getContext().getAttribute("--image-path").toString().trim().length()==0) { 36 | throw new ApplicationException("Invalid file"); 37 | } 38 | 39 | this.imagePath = getContext().getAttribute("--image-path").toString(); 40 | return this.image2base64(this.imagePath); 41 | } 42 | 43 | public String image2base64(String f) throws ApplicationException { 44 | File file = new File(f); 45 | String name = file.getName(); 46 | if(!name.endsWith(".jpeg") && !name.endsWith(".jpg")&& !name.endsWith(".png")&& !name.endsWith(".gif")&& !name.endsWith(".bmp")) 47 | { 48 | throw new ApplicationException("Invalid file"); 49 | } 50 | 51 | ByteArrayOutputStream ous = null; 52 | FileInputStream fs = null; 53 | byte[] data = new byte[]{}; 54 | try { 55 | byte[] buffer = new byte[4096]; 56 | ous = new ByteArrayOutputStream(); 57 | int read = 0; 58 | fs = new FileInputStream(file); 59 | while ((read = fs.read(buffer)) != -1) { 60 | ous.write(buffer, 0, read); 61 | } 62 | 63 | data = ous.toByteArray(); 64 | if(data.length > 0) 65 | return ""; 67 | } catch (FileNotFoundException e) { 68 | throw new ApplicationException(e.getMessage(), e); 69 | } catch (IOException e) { 70 | throw new ApplicationException(e.getMessage(), e); 71 | } finally { 72 | try { 73 | if (ous != null) 74 | ous.close(); 75 | 76 | if (fs != null) 77 | fs.close(); 78 | } catch (IOException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | return null; 84 | } 85 | 86 | public static void main(String[]args) throws ApplicationException { 87 | ApplicationContext ctx = new ApplicationContext(); 88 | 89 | ApplicationManager.install(new image2()); 90 | 91 | ApplicationManager.call("image2base64", ctx); 92 | 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/rabbitmq.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.IOException; 4 | import java.io.UnsupportedEncodingException; 5 | import java.util.concurrent.TimeoutException; 6 | 7 | import org.tinystruct.AbstractApplication; 8 | 9 | import com.rabbitmq.client.Channel; 10 | import com.rabbitmq.client.Connection; 11 | import com.rabbitmq.client.ConnectionFactory; 12 | import com.rabbitmq.client.MessageProperties; 13 | 14 | public class rabbitmq extends AbstractApplication { 15 | 16 | @Override 17 | public void init() { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | public void test() throws UnsupportedEncodingException, IOException, TimeoutException { 23 | ConnectionFactory factory = new ConnectionFactory(); 24 | factory.setHost("localhost"); 25 | 26 | factory.setUsername("guest"); 27 | factory.setPassword("guest"); 28 | factory.setVirtualHost("/"); 29 | factory.setPort(5672); 30 | 31 | try (Connection connection = factory.newConnection(); Channel channel = connection.createChannel()) { 32 | channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null); 33 | 34 | String message = "Hello, James."; 35 | 36 | channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, 37 | message.getBytes("UTF-8")); 38 | System.out.println(" [x] Sent '" + message + "'"); 39 | } 40 | } 41 | 42 | @Override 43 | public String version() { 44 | // TODO Auto-generated method stub 45 | return null; 46 | } 47 | 48 | public static final String TASK_QUEUE_NAME = "hello"; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/redirectChecker.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.net.HttpURLConnection; 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.Map.Entry; 14 | import java.util.Set; 15 | 16 | import org.tinystruct.AbstractApplication; 17 | import org.tinystruct.ApplicationException; 18 | 19 | public class redirectChecker extends AbstractApplication { 20 | 21 | @Override 22 | public void init() { 23 | // TODO Auto-generated method stub 24 | this.setAction("check", "start"); 25 | } 26 | 27 | /** 28 | HTTP/1.1 301 Moved Permanently 29 | Server:[nginx] 30 | X-Request-ID:[v-34c8ab26-3140-11e6-8d1f-22000aab1671] 31 | X-Content-Type-Options:[nosniff] 32 | X-Age:[158593] 33 | Connection:[keep-alive] 34 | Date:[Wed, 15 Jun 2016 04:27:24 GMT] 35 | X-Varnish:[2128902194 2128190039] 36 | Cache-Control:[max-age=1209600] 37 | Content-Encoding:[gzip] 38 | Vary:[Accept-Encoding] 39 | Expires:[Mon, 27 Jun 2016 08:24:11 GMT] 40 | Content-Length:[217] 41 | X-Cache-Hits:[168] 42 | Location:[http://domain.com/path] 43 | Content-Type:[text/html; charset=iso-8859-1] 44 | * @throws ApplicationException 45 | */ 46 | public void start() throws ApplicationException{ 47 | try 48 | { 49 | FileInputStream fileInput = new FileInputStream("url-rules.txt"); 50 | InputStreamReader reader = new InputStreamReader(fileInput); 51 | BufferedReader bufferReader = new BufferedReader(reader); 52 | 53 | String line, destinationURL, currentURL; 54 | String[] parts; 55 | URL from; 56 | while((line = bufferReader.readLine()) != null) 57 | { 58 | parts = line.split("\\t|\\s"); 59 | destinationURL = parts[1]; 60 | from = new URL(parts[0]); 61 | 62 | boolean follow = false, redirected = false; 63 | do { 64 | HttpURLConnection connection = (HttpURLConnection) from.openConnection(); 65 | connection.setInstanceFollowRedirects(follow); 66 | connection.connect(); 67 | currentURL = connection.getHeaderField("Location").trim(); 68 | 69 | int responseCode = connection.getResponseCode(); 70 | 71 | redirected = (responseCode == 302); 72 | 73 | if(!destinationURL.trim().equalsIgnoreCase(currentURL)) { 74 | Map> list = connection.getHeaderFields(); 75 | Set>> set = list.entrySet(); 76 | Iterator>> iterator = set.iterator(); 77 | Entry> entity; 78 | while(iterator.hasNext()) { 79 | entity = iterator.next(); 80 | System.out.println(entity.getKey()+":"+entity.getValue()); 81 | } 82 | } 83 | if(redirected) from = new URL(currentURL); 84 | System.out.println("Status:\t"+ connection.getHeaderField(0) +"\t"+ (destinationURL.trim().equalsIgnoreCase(currentURL)?"OK":"Failure")); 85 | System.out.println("From:\t"+from+"\r\nTo:\t"+currentURL+"\r\n"); 86 | } while (redirected); 87 | 88 | System.out.println(); 89 | } 90 | bufferReader.close(); 91 | reader.close(); 92 | fileInput.close(); 93 | } catch (MalformedURLException e) { 94 | throw new ApplicationException(e.getMessage(), e.getCause()); 95 | } catch (IOException e) { 96 | throw new ApplicationException(e.getMessage(), e.getCause()); 97 | } 98 | } 99 | 100 | @Override 101 | public String version() { 102 | // TODO Auto-generated method stub 103 | return null; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/redis.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.MalformedURLException; 5 | import java.net.URISyntaxException; 6 | import java.net.URL; 7 | import java.util.HashMap; 8 | 9 | import org.tinystruct.AbstractApplication; 10 | import org.tinystruct.ApplicationContext; 11 | import org.tinystruct.ApplicationException; 12 | import org.tinystruct.application.Context; 13 | import org.tinystruct.system.ApplicationManager; 14 | import org.tinystruct.system.security.Credential; 15 | import org.tinystruct.system.security.oauth2.OAuth2Client; 16 | import org.tinystruct.system.security.oauth2.UserCredential; 17 | 18 | public class redis extends AbstractApplication { 19 | 20 | @Override 21 | public void init() { 22 | // TODO Auto-generated method stub 23 | this.setAction("operations", "callback"); 24 | } 25 | 26 | @Override 27 | public String version() { 28 | // TODO Auto-generated method stub 29 | return null; 30 | } 31 | 32 | public String callback() 33 | throws ApplicationException, MalformedURLException, URISyntaxException, UnsupportedEncodingException { 34 | OAuth2Client client = new OAuth2Client(); 35 | Credential credential = new UserCredential(); 36 | HashMap parameters = new HashMap(); 37 | // parameters.put("grant_type", "client_credentials"); // disabled for applicationId 38 | 39 | parameters.put("username", "James"); 40 | parameters.put("password", "0123456"); 41 | 42 | // parameters.put("username", "james"); 43 | // parameters.put("password", "rinnazamcpjF9_msg7Fd"); 44 | 45 | parameters.put("grant_type", "password"); 46 | client.identify(credential, parameters); 47 | if (client.approved() && client.grant() != null) { 48 | URL uri = new URL("http://localhost:8000/api/redis/list/pop/languages"); 49 | // client.requestResource(uri, null); 50 | uri = new URL("http://localhost:8000/api/redis/list/languages"); 51 | return new String(client.resource(uri, null), "utf-8"); 52 | } 53 | 54 | return null; 55 | } 56 | 57 | public static void main(String[] args) throws ApplicationException { 58 | Context context = new ApplicationContext(); 59 | ApplicationManager.install(new redis()); 60 | System.out.println(ApplicationManager.call("operations", context)); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/startup.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.IOException; 4 | import java.util.Date; 5 | 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.tinystruct.AbstractApplication; 9 | import org.tinystruct.system.annotation.Action; 10 | 11 | public class startup extends AbstractApplication { 12 | 13 | private static boolean stop; 14 | 15 | @Override 16 | public void init() { 17 | // TODO Auto-generated method stub 18 | } 19 | 20 | @Action("startup") 21 | public startup index() { 22 | return this; 23 | } 24 | 25 | public void start() { 26 | stop=false; 27 | } 28 | 29 | public void update() throws IOException, InterruptedException { 30 | 31 | HttpServletResponse response = (HttpServletResponse) getContext() 32 | .getAttribute("HTTP_RESPONSE"); 33 | while(true) 34 | if (!stop) { 35 | response.getWriter().println( 36 | ""); 38 | response.getWriter().flush(); 39 | 40 | Thread.sleep(1000); 41 | }else { 42 | break; 43 | } 44 | } 45 | 46 | public String stop() { 47 | stop = true; 48 | return "stopped!"; 49 | } 50 | 51 | @Override 52 | public String version() { 53 | // TODO Auto-generated method stub 54 | return null; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/tinystruct/examples/time.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import java.io.IOException; 4 | import java.util.Date; 5 | 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.tinystruct.AbstractApplication; 9 | import org.tinystruct.system.annotation.Action; 10 | 11 | public class time extends AbstractApplication { 12 | 13 | private static boolean stop; 14 | 15 | @Override 16 | public void init() { 17 | // TODO Auto-generated method stub 18 | } 19 | 20 | @Action("time") 21 | public time index() { 22 | return this; 23 | } 24 | 25 | @Action("time/start") 26 | public void start() { 27 | stop=false; 28 | } 29 | 30 | @Action("time/update") 31 | public void update() throws IOException, InterruptedException { 32 | 33 | HttpServletResponse response = (HttpServletResponse) getContext() 34 | .getAttribute("HTTP_RESPONSE"); 35 | while(true) 36 | if (!stop) { 37 | response.getWriter().println( 38 | ""); 40 | response.getWriter().flush(); 41 | 42 | Thread.sleep(1000); 43 | }else { 44 | break; 45 | } 46 | } 47 | 48 | @Action("time/stop") 49 | public String stop() { 50 | stop = true; 51 | return "stopped!"; 52 | } 53 | 54 | @Override 55 | public String version() { 56 | // TODO Auto-generated method stub 57 | return null; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #driver = org.sqlite.JDBC 2 | #database.url = jdbc:sqlite:/Users/mover/applications/mobile1.0/data/tiny.sqlite 3 | #database.user = 4 | #database.password = 5 | #database.connections.max = 1 6 | 7 | [database] 8 | #MySQL 9 | #driver=com.mysql.jdbc.Driver 10 | #database.url=jdbc:mysql://localhost:3306/database?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8 11 | #database.user=root 12 | #database.password=****** 13 | #database.connections.max=10 14 | 15 | #h2 16 | driver=org.h2.Driver 17 | database.url=jdbc:h2:~/test 18 | database.user= 19 | database.password= 20 | database.connections.max=10 21 | 22 | [default] 23 | default.file.encoding=UTF-8 24 | default.login.page=user/login 25 | default.home.page=praise 26 | default.reload.mode=true 27 | default.date.format=yyyy-MM-dd HH:mm:ss 28 | default.import.applications=tinystruct.examples.error;tinystruct.examples.firstApplication;tinystruct.examples.time;tinystruct.examples.hello;tinystruct.examples.image2; 29 | default.url_rewrite=disabled 30 | ssl.enabled=false 31 | 32 | [error] 33 | default.error.process=false 34 | default.error.page=error 35 | 36 | [event] 37 | log.status=off 38 | log.file= 39 | system.directory=/development/tinystruct2.0 40 | 41 | [mail] 42 | mail.ssl.on = true 43 | mail.smtp.host=smtp.126.com 44 | mail.pop3.host=pop.gmail.com 45 | #mail.smtp.host=localhost 46 | mail.smtp.port=25 47 | mail.pop3.port=995 48 | mail.smtp.auth=true 49 | mail.pop3.auth=true 50 | mail.store.protocol = pop3 51 | #mail.smtp.auth=false 52 | #smtp.auth.user=*******@ingod.asia 53 | #smtp.auth.user=*******@gmail.com 54 | smtp.auth.user=*******@gmail.com 55 | smtp.auth.pwd=******* 56 | -------------------------------------------------------------------------------- /src/main/resources/themes/hello.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello 5 | 6 | 7 |

8 | :) 9 |

10 |
11 | 
12 | //5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));\n\
21 | }\n\
22 | ");
23 | 
24 | println('What the result will be? see the below result.');
25 | println(Array(10).join('--'));
26 | for(var i=1;i<10;i++) {
27 | 	println((i>5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));
28 | }
29 | println(Array(10).join('--'));
30 | 
31 |  //]]>
32 | 
33 | 
34 | 35 | 36 | -------------------------------------------------------------------------------- /src/main/resources/themes/reading.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | {%book.name%} 14 | 15 | 16 | 17 | 18 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 94 | 95 | 96 |
97 | 99 |

{%book.name%}

100 |
[%book.info%]
101 | 102 | 103 |
{%content%}
104 | 105 | 106 |
107 | 108 |
109 |
110 |

© 2015

111 |
112 |
113 | 114 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /src/main/resources/themes/smalltalk.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Small Talk 11 | 12 | 13 | 14 | 298 | 299 | 300 | 301 | 302 | 306 | 307 | 308 | 309 | 310 | 624 | 625 | 626 | 627 | 653 | 654 | 655 |
656 | 657 |

Welcome to use smalltalk application!

658 |

{%topic%}

659 |
660 |
    661 |
    662 |
    663 |
    Share the link to invite others join this conversation: [%LINK:talk/join%]/{%meeting_code%}
    664 |
    665 |
    666 | 667 | 668 | 669 | 670 |
    671 | 672 | 673 |
    674 | 675 | 676 |
    677 |
    678 | 679 | 680 | 697 | 698 | 715 | 716 |
    717 |
    718 |

    © 2017

    719 |
    720 |
    721 | 722 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | -------------------------------------------------------------------------------- /src/main/resources/themes/startup.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | "Welcome to use CDT!" 6 | 7 | 11 | 19 | 20 | 21 | 22 | 59 | 60 | 61 |
    62 |
    63 | Please change my style. 64 | 65 | 68 |
    69 | 70 | -------------------------------------------------------------------------------- /src/main/resources/themes/time.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/resources/themes/tinyeditor.view: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tinyeditor 6 | 12 | 13 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/test/tinystruct/examples/rabbitmqTest.java: -------------------------------------------------------------------------------- 1 | package tinystruct.examples; 2 | 3 | import org.tinystruct.AbstractApplication; 4 | 5 | import com.rabbitmq.client.AMQP; 6 | import com.rabbitmq.client.Channel; 7 | import com.rabbitmq.client.Connection; 8 | import com.rabbitmq.client.ConnectionFactory; 9 | import com.rabbitmq.client.Consumer; 10 | import com.rabbitmq.client.DefaultConsumer; 11 | import com.rabbitmq.client.Envelope; 12 | import com.rabbitmq.client.ShutdownListener; 13 | import com.rabbitmq.client.ShutdownSignalException; 14 | 15 | public class rabbitmqTest extends AbstractApplication { 16 | 17 | @Override 18 | public void init() { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | @Override 24 | public String version() { 25 | // TODO Auto-generated method stub 26 | return null; 27 | } 28 | 29 | public static void main(String[] args) throws IOException, TimeoutException { 30 | // TODO Auto-generated method stub 31 | /* 32 | * Stream stream = Stream.iterate(1, i -> i); // 33 | * stream.forEach(System.out::println); System.out.println(stream.anyMatch(i -> 34 | * i > 5)); 35 | */ 36 | 37 | ConnectionFactory factory = new ConnectionFactory(); 38 | factory.setHost("localhost"); 39 | factory.setUsername("guest"); 40 | factory.setPassword("guest"); 41 | factory.setVirtualHost("/"); 42 | factory.setPort(5672); 43 | final CountDownLatch countDown = new CountDownLatch(1); 44 | System.out.println("Waiting for messages..."); 45 | Connection connection = factory.newConnection(); 46 | connection.addShutdownListener(new ShutdownListener() { 47 | @Override 48 | public void shutdownCompleted(ShutdownSignalException cause) { 49 | countDown.countDown(); 50 | } 51 | }); 52 | Channel channel = connection.createChannel(); 53 | try { 54 | channel.queueDeclare(rabbitmq.TASK_QUEUE_NAME, false, false, false, null); 55 | channel.basicQos(1); 56 | Consumer consumer = new DefaultConsumer(channel) { 57 | @Override 58 | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, 59 | byte[] body) throws IOException { 60 | try { 61 | String message = new String(body, StandardCharsets.UTF_8); 62 | // process the message 63 | System.out.println("[x] Received:" + message); 64 | } 65 | catch(Exception e) { 66 | e.printStackTrace(); 67 | channel.basicNack(envelope.getDeliveryTag(), false, true); 68 | } 69 | finally { 70 | countDown.countDown(); 71 | } 72 | channel.basicAck(envelope.getDeliveryTag(), false); 73 | } 74 | }; 75 | channel.basicConsume(rabbitmq.TASK_QUEUE_NAME, false, consumer); 76 | countDown.await(5, TimeUnit.SECONDS); 77 | 78 | // Assert.assertEquals(0, countDown.getCount()); 79 | } catch (InterruptedException e) { 80 | // TODO Auto-generated catch block 81 | e.printStackTrace(); 82 | } finally { 83 | channel.close(); 84 | } 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/tinystruct/examples/smalltalk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The file has been moved to the new location: 3 | * 4 | * https://github.com/tinystruct/tinystruct2.0/blob/master/src/main/java/tinystruct/examples/smalltalk.java 5 | **/ 6 | --------------------------------------------------------------------------------