├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── LICENSE
├── README.md
├── assets
└── tmpl
│ ├── buildprop.html
│ ├── features.html
│ ├── index.html
│ ├── jquery-1.11.2.min.js
│ ├── layout.css
│ ├── layout.tmpl
│ ├── libraries.html
│ ├── locales.html
│ ├── logo.svg
│ ├── main-menu.js
│ └── paths.html
├── build.gradle
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── ic_action_share.png
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── ic_action_share.png
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── ic_action_share.png
│ └── ic_launcher.png
├── drawable-xxhdpi
│ ├── ic_action_share.png
│ └── ic_launcher.png
├── layout
│ └── activity_main.xml
├── menu
│ └── main.xml
├── values-cs
│ └── strings.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-w820dp
│ └── dimens.xml
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── xml
│ └── file_paths.xml
└── src
├── com
└── floreysoft
│ └── jmte
│ ├── AnnotationProcessor.java
│ ├── DefaultModelAdaptor.java
│ ├── Engine.java
│ ├── ErrorHandler.java
│ ├── ModelAdaptor.java
│ ├── ModelBuilder.java
│ ├── NamedRenderer.java
│ ├── ProcessListener.java
│ ├── Processor.java
│ ├── RenderFormatInfo.java
│ ├── Renderer.java
│ ├── RendererRegistry.java
│ ├── ScopedMap.java
│ ├── TemplateContext.java
│ ├── encoder
│ ├── Encoder.java
│ └── XMLEncoder.java
│ ├── message
│ ├── AbstractErrorHandler.java
│ ├── DefaultErrorHandler.java
│ ├── InternalErrorHandler.java
│ ├── Message.java
│ ├── MessageException.java
│ ├── NoLogErrorHandler.java
│ ├── ParseException.java
│ ├── ProductionErrorHandler.java
│ ├── ResourceBundleMessage.java
│ ├── SilentErrorHandler.java
│ └── messages.properties
│ ├── package.html
│ ├── renderer
│ ├── DefaultCollectionRenderer.java
│ ├── DefaultIterableRenderer.java
│ ├── DefaultMapRenderer.java
│ ├── DefaultObjectRenderer.java
│ ├── OptionRenderFormatInfo.java
│ └── RawRenderer.java
│ ├── template
│ ├── AbstractCompiledTemplate.java
│ ├── AbstractTemplate.java
│ ├── InterpretedTemplate.java
│ ├── Template.java
│ └── TemplateCompiler.java
│ ├── token
│ ├── AbstractToken.java
│ ├── AnnotationToken.java
│ ├── ElseToken.java
│ ├── EndToken.java
│ ├── ExpressionToken.java
│ ├── ForEachToken.java
│ ├── IfCmpToken.java
│ ├── IfToken.java
│ ├── InvalidToken.java
│ ├── Lexer.java
│ ├── PlainTextToken.java
│ ├── StringToken.java
│ ├── Token.java
│ └── TokenStream.java
│ └── util
│ ├── MiniParser.java
│ ├── NestedParser.java
│ ├── StartEndPair.java
│ ├── Tool.java
│ ├── UniqueNameGenerator.java
│ └── Util.java
└── de
└── onyxbits
└── droidentify
├── Devices.java
├── Interceptor.java
├── LocalBinder.java
├── MainActivity.java
├── MainService.java
├── ProxyReceiver.java
├── ReportProvider.java
├── ReporterTask.java
├── Tuple.java
└── ZippedReportFilter.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | *~
3 | DEADJOE
4 | .#*
5 | *.jar
6 | *.zip
7 | *.apk
8 | bin/
9 | gen/
10 | bin/*
11 | gen/*
12 | libs/
13 | libs/*
14 | compiled/
15 | compiled/*
16 | local.properties
17 | build.xml
18 | assets/build.properties
19 | .settings/
20 | .settings/*
21 | .gradle/
22 | local.properties
23 | .idea
24 | .idea/workspace.xml
25 | .idea/libraries
26 | .DS_Store
27 | build/
28 | build/*
29 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Droidentify
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
20 |
21 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
37 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Droidentify - Android spec sheet generator
2 | ------------------------------------------
3 |
4 | Droidentify is an Android app that makes it easy for users to generate
5 | an HTML formated description of their device and transfer this report
6 | over to their desktop computer for further processing.
--------------------------------------------------------------------------------
/assets/tmpl/buildprop.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | mavenCentral()
5 | }
6 |
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.1.3'
9 |
10 | }
11 | }
12 |
13 |
14 |
15 | apply plugin: 'com.android.application'
16 |
17 | android {
18 | compileSdkVersion 22
19 | buildToolsVersion "19.1"
20 |
21 | sourceSets {
22 | main {
23 | manifest.srcFile 'AndroidManifest.xml'
24 | java.srcDirs = ['src']
25 | resources.srcDirs = ['src']
26 | aidl.srcDirs = ['src']
27 | renderscript.srcDirs = ['src']
28 | res.srcDirs = ['res']
29 | assets.srcDirs = ['assets']
30 | }
31 | debug.setRoot('build-types/debug')
32 | release.setRoot('build-types/release')
33 | }
34 |
35 | signingConfigs {
36 | release {
37 | storeFile file(RELEASE_STORE_FILE)
38 | storePassword RELEASE_STORE_PASSWORD
39 | keyAlias RELEASE_KEY_ALIAS
40 | keyPassword RELEASE_KEY_PASSWORD
41 | }
42 | }
43 | buildTypes {
44 | release {
45 | signingConfig signingConfigs.release
46 | }
47 | }
48 | }
49 |
50 |
51 | dependencies {
52 | compile 'com.android.support:support-v4:22.1.0'
53 | compile 'com.android.support:appcompat-v7:22.1.0'
54 | }
55 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-22
15 | android.library.reference.1=../appcompat_v7
16 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_action_share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-hdpi/ic_action_share.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_action_share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-mdpi/ic_action_share.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_action_share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-xhdpi/ic_action_share.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_action_share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-xxhdpi/ic_action_share.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onyxbits/Droidentify/75bbf0ed5ee45778a641e2f26fd4fb943d191ba5/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/res/values-cs/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Droidentify
5 | Sdílet
6 | Report Droidentify
7 | Sdílet report přes
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Droidentify
5 | Share
6 | Droidentify Report
7 | Share report via
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/AnnotationProcessor.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import com.floreysoft.jmte.token.AnnotationToken;
4 |
5 | /**
6 | * Processor for an annotation, like ${@type String simple}.
7 | *
8 | * @param
9 | * what the processor produces
10 | */
11 | public interface AnnotationProcessor {
12 |
13 | String getType();
14 | /**
15 | * Processes the annotation and possible returns a value.
16 | *
17 | * @param token
18 | * the annotation token triggering this processor
19 | *
20 | * @param context
21 | * current context during template evaluation
22 | * @return the produced value
23 | */
24 | T eval(AnnotationToken token, TemplateContext context);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/DefaultModelAdaptor.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Member;
5 | import java.lang.reflect.Method;
6 | import java.lang.reflect.Modifier;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Map.Entry;
11 | import java.util.concurrent.Callable;
12 |
13 | import com.floreysoft.jmte.token.Token;
14 |
15 | /**
16 | * Default implementation of the model adapter.
17 | *
18 | * Does the object traversal using the "." operator. Resolved value will be
19 | * checked if it is either a {@link Processor} or a {@link Callable} in which
20 | * case the final resolved value is computed by calling those executable
21 | * objects.
22 | *
23 | *
24 | *
25 | * Inherit from this adapter if you want a slight change of this behavior and
26 | * set your new adaptor on the engine
27 | * {@link Engine#setModelAdaptor(ModelAdaptor)} .
28 | *
29 | */
30 | public class DefaultModelAdaptor implements ModelAdaptor {
31 |
32 | protected Map, Map> cache = new HashMap, Map>();
33 |
34 | @Override
35 | @SuppressWarnings("rawtypes")
36 | public Object getValue(TemplateContext context, Token token,
37 | List segments, String expression) {
38 | Object value = traverse(segments, context.model, context.errorHandler, token);
39 | // if value implements both, we use the more specialized implementation
40 | if (value instanceof Processor) {
41 | value = ((Processor) value).eval(context);
42 | } else if (value instanceof Callable) {
43 | try {
44 | value = ((Callable) value).call();
45 | } catch (Exception e) {
46 | }
47 | }
48 | return value;
49 | }
50 |
51 | protected Object traverse(List segments, Map model,
52 | ErrorHandler errorHandler, Token token) {
53 | if (segments.size() == 0) {
54 | return null;
55 | }
56 | String objectName = segments.get(0);
57 | Object value = model.get(objectName);
58 |
59 | value = traverse(value, segments, 1, errorHandler, token);
60 | return value;
61 | }
62 |
63 | protected Object traverse(Object o, List attributeNames, int index,
64 | ErrorHandler errorHandler, Token token) {
65 | Object result;
66 | if (index >= attributeNames.size()) {
67 | result = o;
68 | } else {
69 | if (o == null) {
70 | return null;
71 | }
72 | String attributeName = attributeNames.get(index);
73 | Object nextStep = nextStep(o, attributeName, errorHandler, token);
74 | result = traverse(nextStep, attributeNames, index + 1,
75 | errorHandler, token);
76 | }
77 | return result;
78 | }
79 |
80 | @SuppressWarnings("rawtypes")
81 | protected Object nextStep(Object o, String attributeName,
82 | ErrorHandler errorHandler, Token token) {
83 | Object result;
84 | if (o instanceof String) {
85 | errorHandler.error("no-call-on-string", token, new ModelBuilder(
86 | "receiver", o.toString()).build());
87 | return o;
88 | } else if (o instanceof Map) {
89 | Map map = (Map) o;
90 | result = map.get(attributeName);
91 | } else {
92 | try {
93 | result = getPropertyValue(o, attributeName);
94 | } catch (Exception e) {
95 | errorHandler.error("property-access-error", token,
96 | new ModelBuilder("property", attributeName, "object",
97 | o, "exception", e).build());
98 | result = "";
99 | }
100 | }
101 | return result;
102 | }
103 |
104 | @SuppressWarnings("rawtypes")
105 | protected Object getPropertyValue(Object o, String propertyName) {
106 | try {
107 | // XXX this is so strange, can not call invoke on key and value for
108 | // Map.Entry, so we have to get this done like this:
109 | if (o instanceof Map.Entry) {
110 | final Map.Entry entry = (Entry) o;
111 | if (propertyName.equals("key")) {
112 | final Object result = entry.getKey();
113 | return result;
114 | } else if (propertyName.equals("value")) {
115 | final Object result = entry.getValue();
116 | return result;
117 | }
118 |
119 | }
120 | boolean valueSet = false;
121 | Object value = null;
122 | Member member = null;
123 | final Class> clazz = o.getClass();
124 | Map members = cache.get(clazz);
125 | if (members == null) {
126 | members = new HashMap();
127 | cache.put(clazz, members);
128 | } else {
129 | member = members.get(propertyName);
130 | if (member != null) {
131 | if (member.getClass() == Method.class)
132 | return ((Method) member).invoke(o);
133 | if (member.getClass() == Field.class)
134 | return ((Field) member).get(o);
135 | }
136 | }
137 |
138 | final String suffix = Character.toUpperCase(propertyName.charAt(0))
139 | + propertyName.substring(1);
140 | final Method[] declaredMethods = clazz.getMethods();
141 | for (Method method : declaredMethods) {
142 | if (Modifier.isPublic(method.getModifiers())
143 | && (method.getName().equals("get" + suffix) || method
144 | .getName().equals("is" + suffix))) {
145 | value = method.invoke(o, (Object[]) null);
146 | valueSet = true;
147 | member = method;
148 | break;
149 |
150 | }
151 | }
152 | if (!valueSet) {
153 | final Field field = clazz.getField(propertyName);
154 | if (Modifier.isPublic(field.getModifiers())) {
155 | value = field.get(o);
156 | member = field;
157 | valueSet = true;
158 | }
159 | }
160 | if (valueSet) {
161 | members.put(propertyName, member);
162 | }
163 | return value;
164 | } catch (Exception e) {
165 | throw new RuntimeException(e);
166 | }
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/Engine.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import java.util.Collection;
4 | import java.util.Collections;
5 | import java.util.HashMap;
6 | import java.util.HashSet;
7 | import java.util.List;
8 | import java.util.Locale;
9 | import java.util.Map;
10 | import java.util.Set;
11 |
12 | import org.apache.http.MethodNotSupportedException;
13 |
14 | import com.floreysoft.jmte.encoder.Encoder;
15 | import com.floreysoft.jmte.message.DefaultErrorHandler;
16 | import com.floreysoft.jmte.message.SilentErrorHandler;
17 | import com.floreysoft.jmte.renderer.DefaultCollectionRenderer;
18 | import com.floreysoft.jmte.renderer.DefaultIterableRenderer;
19 | import com.floreysoft.jmte.renderer.DefaultMapRenderer;
20 | import com.floreysoft.jmte.renderer.DefaultObjectRenderer;
21 | import com.floreysoft.jmte.template.InterpretedTemplate;
22 | import com.floreysoft.jmte.template.Template;
23 | import com.floreysoft.jmte.template.TemplateCompiler;
24 | import com.floreysoft.jmte.token.IfToken;
25 | import com.floreysoft.jmte.token.Token;
26 | import com.floreysoft.jmte.util.Tool;
27 | import com.floreysoft.jmte.util.Util;
28 |
29 | /**
30 | *
31 | * The template engine - THIS IS WHERE YOU START LOOKING.
32 | *
33 | *
34 | *
35 | * Usually this is the only class you need calling
36 | * {@link #transform(String, Map)}. Like this
37 | *
57 | *
58 | * where input contains the template and model the
59 | * model.
60 | *
61 | *
62 | * Use {@link #setUseCompilation(boolean)} to switch on compilation mode. This
63 | * will compile the template into Java byte code before execution. Especially
64 | * when the template is used often this will speed up the execution by a factor
65 | * between 2 and 10. However, each compiled template results in a new class
66 | * definition and a new globally cached singleton instance of it.
67 | *
68 | *
69 | *
70 | * This class is thread safe.
71 | *
72 | *
73 | * @see ErrorHandler
74 | * @see Tool
75 | * @see Renderer
76 | * @see NamedRenderer
77 | * @see ModelAdaptor
78 | * @see ProcessListener
79 | */
80 | public final class Engine implements RendererRegistry {
81 |
82 | public final static String VERSION = "@version@";
83 |
84 | public static Engine createCachingEngine() {
85 | Engine engine = new Engine();
86 | engine.setEnabledInterpretedTemplateCache(true);
87 | return engine;
88 | }
89 |
90 | public static Engine createNonCachingEngine() {
91 | Engine engine = new Engine();
92 | engine.setEnabledInterpretedTemplateCache(false);
93 | return engine;
94 | }
95 |
96 | public static Engine createCompilingEngine() {
97 | Engine engine = new Engine();
98 | engine.setUseCompilation(true);
99 | return engine;
100 | }
101 |
102 | public static Engine createDefaultEngine() {
103 | Engine engine = new Engine();
104 | return engine;
105 | }
106 |
107 | private String exprStartToken = "${";
108 | private String exprEndToken = "}";
109 | private double expansionSizeFactor = 2;
110 | private ErrorHandler errorHandler = new DefaultErrorHandler();
111 | private boolean useCompilation = false;
112 | private boolean enabledInterpretedTemplateCache = true;
113 | private ModelAdaptor modelAdaptor = new DefaultModelAdaptor();
114 | private Encoder encoder = null;
115 |
116 | // compiler plus all compiled classes live as long as this engine
117 | private TemplateCompiler compiler;
118 |
119 | // compiled templates cache lives as long as this engine
120 | private final Map compiledTemplates = new HashMap();
121 |
122 | // interpreted templates cache lives as long as this engine
123 | private final Map interpretedTemplates = new HashMap();
124 |
125 | private final Map, Renderer>> renderers = new HashMap, Renderer>>();
126 | private final Map, Renderer>> resolvedRendererCache = new HashMap, Renderer>>();
127 |
128 | private final Map> annotationProcessors = new HashMap>();
129 |
130 | private final Map namedRenderers = new HashMap();
131 | private final Map, Set> namedRenderersForClass = new HashMap, Set>();
132 |
133 | /**
134 | * Creates a new engine having ${ and } as start
135 | * and end strings for expressions.
136 | */
137 | public Engine() {
138 | init();
139 | }
140 |
141 | private void init() {
142 | registerRenderer(Object.class, new DefaultObjectRenderer());
143 | registerRenderer(Map.class, new DefaultMapRenderer());
144 | registerRenderer(Collection.class, new DefaultCollectionRenderer());
145 | registerRenderer(Iterable.class, new DefaultIterableRenderer());
146 | }
147 |
148 | /**
149 | * Checks if all given variables are there and if so, that they evaluate to true inside an if.
150 | */
151 | public boolean variablesAvailable(Map model, String... vars) {
152 | final TemplateContext context = new TemplateContext(null, null, null, new ScopedMap(model), modelAdaptor, this,
153 | new SilentErrorHandler(), null);
154 | for (String var : vars) {
155 | final IfToken token = new IfToken(var, false);
156 | if (!(Boolean) token.evaluate(context)) {
157 | return false;
158 | }
159 | }
160 | return true;
161 | }
162 |
163 | /**
164 | * Transforms a template into an expanded output using the given model.
165 | *
166 | * @param template
167 | * the template to expand
168 | * @param locale
169 | * the locale being passed into renderers in
170 | * {@link TemplateContext}
171 | * @param sourceName
172 | * the name of the current template (if there is anything like
173 | * that)
174 | * @param model
175 | * the model used to evaluate expressions inside the template
176 | * @return the expanded output
177 | */
178 | public synchronized String transform(String template, Locale locale, String sourceName, Map model,
179 | ProcessListener processListener) {
180 | return transformInternal(template, locale, sourceName, model, getModelAdaptor(), processListener);
181 | }
182 |
183 | public synchronized String transform(String template, String sourceName, Map model,
184 | ProcessListener processListener) {
185 | return transformInternal(template, sourceName, model, getModelAdaptor(), processListener);
186 | }
187 |
188 | public synchronized String transform(String template, Locale locale, String sourceName, Map model) {
189 | return transformInternal(template, locale, sourceName, model, getModelAdaptor(), null);
190 | }
191 |
192 | public synchronized String transform(String template, String sourceName, Map model) {
193 | return transformInternal(template, sourceName, model, getModelAdaptor(), null);
194 | }
195 |
196 | public synchronized String transform(String template, Locale locale, Map model) {
197 | return transformInternal(template, locale, null, model, getModelAdaptor(), null);
198 | }
199 |
200 | public synchronized String transform(String template, Map model) {
201 | return transformInternal(template, null, model, getModelAdaptor(), null);
202 | }
203 |
204 | public synchronized String transform(String template, Map model, ProcessListener processListener) {
205 | return transformInternal(template, null, model, getModelAdaptor(), processListener);
206 | }
207 |
208 | public synchronized String transform(String template, Locale locale, Map model,
209 | ProcessListener processListener) {
210 | return transformInternal(template, locale, null, model, getModelAdaptor(), processListener);
211 | }
212 |
213 | String transformInternal(String template, String sourceName, Map model, ModelAdaptor modelAdaptor,
214 | ProcessListener processListener) {
215 | Locale locale = Locale.getDefault();
216 | return transformInternal(template, locale, sourceName, model, modelAdaptor, processListener);
217 | }
218 |
219 | String transformInternal(String template, Locale locale, String sourceName, Map model,
220 | ModelAdaptor modelAdaptor, ProcessListener processListener) {
221 | Template templateImpl = getTemplate(template, sourceName);
222 | String output = templateImpl.transform(model, locale, modelAdaptor, processListener);
223 | return output;
224 | }
225 |
226 | /**
227 | * Replacement for {@link java.lang.String.format}. All arguments will be
228 | * put into the model having their index starting from 1 as their name.
229 | *
230 | * @param pattern
231 | * the template
232 | * @param args
233 | * any number of arguments
234 | * @return the expanded template
235 | */
236 | public synchronized String format(final String pattern, final Object... args) {
237 | Map model = Collections.emptyMap();
238 | ModelAdaptor modelAdaptor = new ModelAdaptor() {
239 |
240 | @Override
241 | public Object getValue(TemplateContext context, Token token, List segments, String expression) {
242 | int index = Integer.parseInt(expression) - 1;
243 | return args[index];
244 | }
245 |
246 | };
247 |
248 | String output = transformInternal(pattern, null, model, modelAdaptor, null);
249 | return output;
250 | }
251 |
252 | /**
253 | * Gets all variables used in the given template.
254 | */
255 | public synchronized Set getUsedVariables(String template) {
256 | Template templateImpl = getTemplate(template, null);
257 | return templateImpl.getUsedVariables();
258 | }
259 |
260 | @Override
261 | public synchronized Engine registerNamedRenderer(NamedRenderer renderer) {
262 | namedRenderers.put(renderer.getName(), renderer);
263 | Set> supportedClasses = Util.asSet(renderer.getSupportedClasses());
264 | for (Class> clazz : supportedClasses) {
265 | Class> classInHierarchy = clazz;
266 | while (classInHierarchy != null) {
267 | addSupportedRenderer(classInHierarchy, renderer);
268 | classInHierarchy = classInHierarchy.getSuperclass();
269 | }
270 | }
271 | return this;
272 | }
273 |
274 | @Override
275 | public synchronized Engine deregisterNamedRenderer(NamedRenderer renderer) {
276 | namedRenderers.remove(renderer.getName());
277 | Set> supportedClasses = Util.asSet(renderer.getSupportedClasses());
278 | for (Class> clazz : supportedClasses) {
279 | Class> classInHierarchy = clazz;
280 | while (classInHierarchy != null) {
281 | Set renderers = namedRenderersForClass.get(classInHierarchy);
282 | renderers.remove(renderer);
283 | classInHierarchy = classInHierarchy.getSuperclass();
284 | }
285 | }
286 | return this;
287 | }
288 |
289 | private void addSupportedRenderer(Class> clazz, NamedRenderer renderer) {
290 | Collection compatibleRenderers = getCompatibleRenderers(clazz);
291 | compatibleRenderers.add(renderer);
292 | }
293 |
294 | @Override
295 | public synchronized Collection getCompatibleRenderers(Class> inputType) {
296 | Set renderers = namedRenderersForClass.get(inputType);
297 | if (renderers == null) {
298 | renderers = new HashSet();
299 | namedRenderersForClass.put(inputType, renderers);
300 | }
301 | return renderers;
302 | }
303 |
304 | @Override
305 | public synchronized Collection getAllNamedRenderers() {
306 | Collection values = namedRenderers.values();
307 | return values;
308 | }
309 |
310 | @Override
311 | public NamedRenderer resolveNamedRenderer(String rendererName) {
312 | return namedRenderers.get(rendererName);
313 | }
314 |
315 | public synchronized Engine registerAnnotationProcessor(AnnotationProcessor> annotationProcessor) {
316 | annotationProcessors.put(annotationProcessor.getType(), annotationProcessor);
317 | return this;
318 | }
319 |
320 | public synchronized Engine deregisterAnnotationProcessor(AnnotationProcessor> annotationProcessor) {
321 | annotationProcessors.remove(annotationProcessor.getType());
322 | return this;
323 | }
324 |
325 | AnnotationProcessor> resolveAnnotationProcessor(String type) {
326 | return annotationProcessors.get(type);
327 | }
328 |
329 | @Override
330 | public synchronized Engine registerRenderer(Class clazz, Renderer renderer) {
331 | renderers.put(clazz, renderer);
332 | resolvedRendererCache.clear();
333 | return this;
334 | }
335 |
336 | @Override
337 | public synchronized Engine deregisterRenderer(Class> clazz) {
338 | renderers.remove(clazz);
339 | resolvedRendererCache.clear();
340 | return this;
341 | }
342 |
343 | @SuppressWarnings({ "unchecked", "rawtypes" })
344 | @Override
345 | public Renderer resolveRendererForClass(Class clazz) {
346 | Renderer resolvedRenderer = resolvedRendererCache.get(clazz);
347 | if (resolvedRenderer != null) {
348 | return resolvedRenderer;
349 | }
350 |
351 | resolvedRenderer = renderers.get(clazz);
352 | if (resolvedRenderer == null) {
353 | Class>[] interfaces = clazz.getInterfaces();
354 | for (Class> interfaze : interfaces) {
355 | resolvedRenderer = resolveRendererForClass(interfaze);
356 | if (resolvedRenderer != null) {
357 | break;
358 | }
359 | }
360 | }
361 | if (resolvedRenderer == null) {
362 | Class> superclass = clazz.getSuperclass();
363 | if (superclass != null) {
364 | resolvedRenderer = resolveRendererForClass(superclass);
365 | }
366 | }
367 | if (resolvedRenderer != null) {
368 | resolvedRendererCache.put(clazz, resolvedRenderer);
369 | }
370 | return resolvedRenderer;
371 | }
372 |
373 | public synchronized void setEncoder(Encoder encoder) {
374 | this.encoder = encoder;
375 | }
376 |
377 | public synchronized Encoder getEncoder() {
378 | return encoder;
379 | }
380 |
381 | public synchronized void setErrorHandler(ErrorHandler errorHandler) {
382 | this.errorHandler = errorHandler;
383 | }
384 |
385 | public synchronized ErrorHandler getErrorHandler() {
386 | return errorHandler;
387 | }
388 |
389 | public synchronized String getExprStartToken() {
390 | return exprStartToken;
391 | }
392 |
393 | public synchronized String getExprEndToken() {
394 | return exprEndToken;
395 | }
396 |
397 | public synchronized void setExprStartToken(String exprStartToken) {
398 | this.exprStartToken = exprStartToken;
399 | }
400 |
401 | public synchronized void setExprEndToken(String exprEndToken) {
402 | this.exprEndToken = exprEndToken;
403 | }
404 |
405 | public synchronized void setExpansionSizeFactor(double expansionSizeFactor) {
406 | this.expansionSizeFactor = expansionSizeFactor;
407 | }
408 |
409 | public synchronized double getExpansionSizeFactor() {
410 | return expansionSizeFactor;
411 | }
412 |
413 | public synchronized boolean isUseCompilation() {
414 | return useCompilation;
415 | }
416 |
417 | public synchronized void setUseCompilation(boolean useCompilation) {
418 | throw new RuntimeException("This part has been removed to cut down dependencies!");
419 | //this.useCompilation = useCompilation;
420 | }
421 |
422 | public synchronized void setModelAdaptor(ModelAdaptor modelAdaptor) {
423 | this.modelAdaptor = modelAdaptor;
424 | }
425 |
426 | public synchronized ModelAdaptor getModelAdaptor() {
427 | return modelAdaptor;
428 | }
429 |
430 | public synchronized boolean isEnabledInterpretedTemplateCache() {
431 | return enabledInterpretedTemplateCache;
432 | }
433 |
434 | public synchronized void setEnabledInterpretedTemplateCache(boolean enabledInterpretedTemplateCache) {
435 | this.enabledInterpretedTemplateCache = enabledInterpretedTemplateCache;
436 | }
437 |
438 | /**
439 | * Gets a template for a certain source.
440 | *
441 | * @param template
442 | * the template source
443 | * @return the prepared template
444 | */
445 | public Template getTemplate(String template) {
446 | return getTemplate(template, null);
447 | }
448 |
449 | /**
450 | * Gets a template for a certain source.
451 | *
452 | * @param template
453 | * the template source
454 | * @param sourceName
455 | * the template name
456 | * @return the prepared template
457 | */
458 | public Template getTemplate(String template, String sourceName) {
459 | Template templateImpl;
460 | if (useCompilation) {
461 | templateImpl = compiledTemplates.get(template);
462 | if (templateImpl == null) {
463 | templateImpl = compiler.compile(template, sourceName, this);
464 | compiledTemplates.put(template, templateImpl);
465 | }
466 | return templateImpl;
467 | } else {
468 | if (enabledInterpretedTemplateCache) {
469 | templateImpl = interpretedTemplates.get(template);
470 | if (templateImpl == null) {
471 | templateImpl = new InterpretedTemplate(template, sourceName, this);
472 | interpretedTemplates.put(template, templateImpl);
473 | }
474 | } else {
475 | templateImpl = new InterpretedTemplate(template, sourceName, this);
476 | }
477 | }
478 | return templateImpl;
479 | }
480 |
481 | public void setCompiler(TemplateCompiler compiler) {
482 | this.compiler = compiler;
483 | }
484 |
485 | public TemplateCompiler getCompiler() {
486 | return compiler;
487 | }
488 | }
489 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/ErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import java.util.Map;
4 |
5 | import com.floreysoft.jmte.message.ParseException;
6 | import com.floreysoft.jmte.token.Lexer;
7 | import com.floreysoft.jmte.token.Token;
8 |
9 | /**
10 | * Interface used to handle errors while expanding a template.
11 | */
12 | public interface ErrorHandler {
13 |
14 | /**
15 | * Handles an error while interpreting a template in an appropriate way.
16 | * This might contain logging the error or even throwing an exception.
17 | *
18 | * @param messageKey
19 | * key for the error message
20 | * @param token
21 | * the token this error occurred on
22 | * @param parameters
23 | * additional parameters to be filled into message or
24 | * null if you do not have additional parameters
25 | */
26 | public void error(String messageKey, Token token,
27 | Map parameters) throws ParseException;
28 |
29 | /**
30 | * Handles an error while interpreting a template in an appropriate way.
31 | * This might contain logging the error or even throwing an exception.
32 | *
33 | * @param messageKey
34 | * key for the error message
35 | * @param token
36 | * the token this error occurred on
37 | */
38 | public void error(String messageKey, Token token) throws ParseException;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/ModelAdaptor.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import java.util.List;
4 |
5 | import com.floreysoft.jmte.token.Token;
6 |
7 | /**
8 | * Adaptor between engine and model.
9 | *
10 | */
11 | public interface ModelAdaptor {
12 | /**
13 | * Gets a value from the model.
14 | *
15 | * @param context
16 | * the current context including the scoped model
17 | * @param token
18 | * the token that asks for this value (e.g. used for error
19 | * reporting)
20 | * @param segments
21 | * an already split version of the expression for faster
22 | * processing
23 | * @param expression
24 | * the expression describing the desired value
25 | * @return the value
26 | */
27 | public Object getValue(TemplateContext context, Token token,
28 | List segments, String expression);
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/floreysoft/jmte/ModelBuilder.java:
--------------------------------------------------------------------------------
1 | package com.floreysoft.jmte;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Convenience class for simple model creation.
10 | *
11 | *
12 | * Sample usage
13 | *
14 | *
15 | * Map<String, Object> model = new ModelBuilder("1", "arg1", "2", "arg2").build();
16 | *
17 | *
18 | *
19 | */
20 | public final class ModelBuilder {
21 | private final Map model = new HashMap();
22 |
23 | public ModelBuilder(String name1, Object value1) {
24 | model.put(name1, value1);
25 | }
26 |
27 | public ModelBuilder(String name1, Object value1, String name2, Object value2) {
28 | model.put(name1, value1);
29 | model.put(name2, value2);
30 | }
31 |
32 | public ModelBuilder(String name1, Object value1, String name2,
33 | Object value2, String name3, Object value3) {
34 | model.put(name1, value1);
35 | model.put(name2, value2);
36 | model.put(name3, value3);
37 | }
38 |
39 | public ModelBuilder(String name1, Object value1, String name2,
40 | Object value2, String name3, Object value3, String name4,
41 | Object value4) {
42 | model.put(name1, value1);
43 | model.put(name2, value2);
44 | model.put(name3, value3);
45 | model.put(name4, value4);
46 | }
47 |
48 | public ModelBuilder(String name1, Object value1, String name2,
49 | Object value2, String name3, Object value3, String name4,
50 | Object value4, String name5, Object value5) {
51 | model.put(name1, value1);
52 | model.put(name2, value2);
53 | model.put(name3, value3);
54 | model.put(name4, value4);
55 | model.put(name5, value4);
56 | }
57 |
58 | /**
59 | * Transforms an array to a model using the index of the elements (starting
60 | * from 1) in the array and a prefix to form their names.
61 | *
62 | * @param prefix
63 | * the prefix to add to the index or null if none
64 | * shall be applied
65 | * @param args
66 | * the array to be transformed into the model
67 | * @return the model containing the arguments
68 | */
69 | public ModelBuilder(String prefix, Object... args) {
70 | if (prefix == null) {
71 | prefix = "";
72 | }
73 | for (int i = 0; i < args.length; i++) {
74 | Object value = args[i];
75 | String name = prefix + (i + 1);
76 | model.put(name, value);
77 | }
78 | }
79 |
80 | /**
81 | * Merges any number of named lists into a single one containing their
82 | * combined values. Can be very handy in case of a servlet request which
83 | * might contain several lists of parameters that you want to iterate over
84 | * in a combined way.
85 | *
86 | * @param names
87 | * the names of the variables in the following lists
88 | * @param lists
89 | * the lists containing the values for the named variables
90 | * @return a merge list containing the combined values of the lists
91 | */
92 | public static List