├── .classpath
├── .gitignore
├── .project
├── LICENSE
├── META-INF
├── LICENSE
├── NOTICE.txt
└── README.md
├── README.md
├── lib
├── fluent-hc-4.3.6.jar
├── httpclient-4.3.6.jar
├── httpcore-4.3.3.jar
├── httpmime-4.3.6.jar
└── log4j-1.2.14.jar
├── pom.xml
├── src
└── org
│ └── sword
│ └── lang
│ ├── DateTime.java
│ ├── DateTimeUtil.java
│ ├── HttpUtils.java
│ ├── JaxbParser.java
│ └── StreamUtils.java
└── test
└── org
└── sword
└── lang
├── DateTimeTest.java
├── DateTimeUtilTest.java
└── HttpUtilsTest.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.war
8 | *.ear
9 |
10 | #eclipse file
11 | .settings/
12 |
13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
14 | hs_err_pid*
15 | /bin
16 | /target
17 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | sword-lang
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.m2e.core.maven2Nature
21 | org.eclipse.jdt.core.javanature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/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 {yyyy} {name of copyright owner}
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 |
203 |
--------------------------------------------------------------------------------
/META-INF/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 {yyyy} {name of copyright owner}
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 |
203 |
--------------------------------------------------------------------------------
/META-INF/NOTICE.txt:
--------------------------------------------------------------------------------
1 |
2 | ====project home
3 | https://github.com/sword-org/sword-lang
4 |
5 |
6 | ====need jar
7 | commons-lang3
8 | Log4j
9 |
--------------------------------------------------------------------------------
/META-INF/README.md:
--------------------------------------------------------------------------------
1 | chengn-lang
2 | =========
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | sword-lang
2 | ===========
3 |
4 | language addition for java
5 |
--------------------------------------------------------------------------------
/lib/fluent-hc-4.3.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sword-org/sword-lang/e603268e32748d415f361754367e39240cf06227/lib/fluent-hc-4.3.6.jar
--------------------------------------------------------------------------------
/lib/httpclient-4.3.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sword-org/sword-lang/e603268e32748d415f361754367e39240cf06227/lib/httpclient-4.3.6.jar
--------------------------------------------------------------------------------
/lib/httpcore-4.3.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sword-org/sword-lang/e603268e32748d415f361754367e39240cf06227/lib/httpcore-4.3.3.jar
--------------------------------------------------------------------------------
/lib/httpmime-4.3.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sword-org/sword-lang/e603268e32748d415f361754367e39240cf06227/lib/httpmime-4.3.6.jar
--------------------------------------------------------------------------------
/lib/log4j-1.2.14.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sword-org/sword-lang/e603268e32748d415f361754367e39240cf06227/lib/log4j-1.2.14.jar
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | org.sword.lang
5 | sword-lang
6 | 1.0.1
7 | sword-lang
8 |
9 |
10 |
11 | maven-compiler-plugin
12 | 3.1
13 |
14 | 1.5
15 | 1.5
16 |
17 |
18 |
19 |
20 |
21 |
22 | log4j
23 | log4j
24 | 1.2.14
25 |
26 |
27 | org.apache.httpcomponents
28 | fluent-hc
29 | 4.3.6
30 |
31 |
32 | org.apache.httpcomponents
33 | httpclient
34 | 4.3.6
35 |
36 |
37 | org.apache.httpcomponents
38 | httpcore
39 | 4.3.3
40 |
41 |
42 | org.apache.httpcomponents
43 | httpmime
44 | 4.3.6
45 |
46 |
47 | junit
48 | junit
49 | 4.11
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/org/sword/lang/DateTime.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.sword.lang;
5 |
6 | import java.util.Calendar;
7 | import java.util.Date;
8 |
9 | /**
10 | * @author ChengNing
11 | * @date 2014年10月30日
12 | */
13 | public class DateTime extends Date {
14 |
15 |
16 | public static final DateTime MAX_DATE_TIME = new DateTime(9999, 12, 31, 23, 59, 59);
17 | public static final DateTime MIN_DATE_TIME = new DateTime(0001, 1, 1, 00, 00, 0);
18 |
19 | private static final long serialVersionUID = 1L;
20 | private Date date;
21 | private Calendar calendar;
22 |
23 | public DateTime(long ticks){
24 | this.date = new Date(ticks);
25 | }
26 |
27 | public DateTime(int year,int month,int day){
28 | calendar.set(year, month, day);
29 | this.date = calendar.getTime();
30 | }
31 |
32 | public DateTime(int year,int month,int day,int hour,int minute,int second){
33 | calendar.set(year, month, day,hour,minute,second);
34 | this.date = calendar.getTime();
35 | }
36 |
37 | public DateTime(String dateString){
38 | this.date = DateTimeUtil.getDate(dateString);
39 | }
40 |
41 | public String toString(){
42 | return DateTimeUtil.toDateTimeStr(this.date);
43 | }
44 |
45 | public String toString(String format){
46 | return DateTimeUtil.toDateString(this.date, format);
47 | }
48 |
49 | public Date toDate(){
50 | return this.date;
51 | }
52 |
53 |
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/org/sword/lang/DateTimeUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.sword.lang;
5 |
6 | import java.text.ParseException;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 |
10 | /**
11 | * @author ChengNing
12 | * @date 2014年10月30日
13 | */
14 | public class DateTimeUtil {
15 | public static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
16 | public static final String DEFAULT_FORMAT_TIME = "HH:mm:ss";
17 | public static final String DEFAULT_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";
18 |
19 | /**
20 | * 字符串转换为日期
21 | * @param dateString 日期字符串
22 | * @param format 格式化字符串
23 | * @return
24 | */
25 | public static Date getDateTime(String dateString,String format){
26 | SimpleDateFormat sf = new SimpleDateFormat(format);
27 | Date date = null;
28 | try {
29 | date = sf.parse(dateString);
30 | } catch (ParseException e) {
31 | e.printStackTrace();
32 | }
33 | return date;
34 | }
35 |
36 | /**
37 | * 通过时间字符串得到一个Date
38 | * @param dateString eg:2010-01-01 10:10:00
39 | * @return
40 | */
41 | public static Date getDateTime(String dateTimeString){
42 | return getDateTime(dateTimeString,DEFAULT_FORMAT_DATETIME);
43 | }
44 |
45 | /**
46 | * 转换一个日期串为Date
47 | * @param date eg:2010-01-01
48 | * @return
49 | */
50 | public static Date getDate(String date){
51 | return getDateTime(date, DEFAULT_FORMAT_DATE);
52 | }
53 |
54 | /**
55 | * 转换一个时间串为Date
56 | * @param time 10:10:00
57 | * @return
58 | */
59 | public static Date getTime(String time){
60 | return getDateTime(time,DEFAULT_FORMAT_TIME);
61 | }
62 |
63 |
64 | /**
65 | * 将给定日期转换为日期字符串
66 | * @param date
67 | * @param format
68 | * @return
69 | */
70 | public static String toDateString(Date date,String format) {
71 | SimpleDateFormat sf = new SimpleDateFormat(format);
72 | return sf.format(date);
73 | }
74 |
75 | /**
76 | * 将给定的日期时间输出为默认字符串格式
77 | * @param date eg:2010-01-01 10:10:00
78 | * @return
79 | */
80 | public static String toDateTimeStr(Date date){
81 | return toDateString(date, DEFAULT_FORMAT_DATETIME);
82 | }
83 |
84 | /**
85 | * 将给定的日期时间输出为默认格式日期字符串
86 | * @param date eg:2010-01-01
87 | * @return
88 | */
89 | public static String toDateStr(Date date){
90 | return toDateString(date, DEFAULT_FORMAT_DATE);
91 | }
92 |
93 | /**
94 | * 将给定的日期时间输出为默认格式时间字符串
95 | * @param date eg:10:10:00
96 | * @return
97 | */
98 | public static String toTimeStr(Date date){
99 | return toDateString(date, DEFAULT_FORMAT_TIME);
100 | }
101 |
102 | /**
103 | * 今天的日期字符串
104 | * @return
105 | */
106 | public static String todayStr(){
107 | return currentDateStr();
108 | }
109 |
110 | /**
111 | * 今天的日期字符串
112 | * @return
113 | */
114 | public static Date today(){
115 | return current();
116 | }
117 |
118 | /**
119 | * 获得今天指定时间的Date
120 | * @param time
121 | * @return
122 | */
123 | public static Date getToday(String time){
124 | String today = todayStr();
125 | return getDateTime(today + " " + time,DEFAULT_FORMAT_DATETIME);
126 | }
127 |
128 | /**
129 | * 获取当前时间
130 | * @return eg:2012-01-01 01:01:00
131 | */
132 | public static Date now(){
133 | return current();
134 | }
135 |
136 | /**
137 | * 获取当前时间
138 | * @return eg:2012-01-01 01:01:00
139 | */
140 | public static String nowStr(){
141 | return currentStr();
142 | }
143 |
144 | /**
145 | * 获取当前的时间
146 | * @return eg:10:30:00
147 | */
148 | public static String currentTimeStr(){
149 | return toDateString(new Date(), DEFAULT_FORMAT_TIME);
150 | }
151 |
152 | /**
153 | * 获取当期日期
154 | * @return eg:2012-01-01
155 | */
156 | public static String currentDateStr(){
157 | return toDateString(new Date(), DEFAULT_FORMAT_DATE);
158 | }
159 |
160 | /**
161 | * 当前的日期和时间,等于now()
162 | * @return
163 | */
164 | public static String currentStr(){
165 | return toDateString(new Date(), DEFAULT_FORMAT_DATETIME);
166 | }
167 |
168 | /**
169 | * 系统当前日期
170 | * @return
171 | */
172 | public static Date current(){
173 | return new Date();
174 | }
175 |
176 | /**
177 | * 格式化字符串,使用指定Date替换其中的时间参数,时间段使用{yyyy-mm-dd}标识
178 | * @param text
179 | * @param date
180 | * @return
181 | */
182 | public static String format(String text,Date date){
183 | int start = text.indexOf("{");
184 | int end = text.indexOf("}");
185 | while(start > 0 && end > 0){
186 | String subStr = text.substring(start, end+1);
187 | String format = text.substring(start+1, end);
188 | String dateStr = toDateString(date, format);
189 | text = text.replace(subStr, dateStr);
190 |
191 | start = text.indexOf("{");
192 | end = text.indexOf("}");
193 | }
194 | return text;
195 | }
196 |
197 | /**
198 | * 是否一个合法的日期
199 | * @param date
200 | * @return
201 | */
202 | public static boolean isDate(String dateString){
203 | return tryParse(dateString);
204 | }
205 |
206 | /**
207 | * 是否可以解析
208 | * @param date
209 | * @return
210 | */
211 | public static boolean tryParse(String dateString){
212 | Date date = getDateTime(dateString);
213 | return (date == null? false:true);
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/org/sword/lang/HttpUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.sword.lang;
5 |
6 |
7 |
8 | import java.io.File;
9 | import java.io.InputStream;
10 |
11 | import org.apache.http.Consts;
12 | import org.apache.http.HttpEntity;
13 | import org.apache.http.client.fluent.Request;
14 | import org.apache.http.entity.ContentType;
15 | import org.apache.http.entity.mime.MultipartEntityBuilder;
16 | import org.apache.http.util.EntityUtils;
17 | import org.apache.log4j.Logger;
18 |
19 |
20 | /**
21 | *
22 | * @author chengn
23 | * @date 2014年12月12日
24 | */
25 | public class HttpUtils {
26 | private static Logger logger = Logger.getLogger(HttpUtils.class);
27 |
28 | public static final int timeout = 10;
29 |
30 | /**
31 | * post 请求
32 | *
33 | * @param url
34 | * @return
35 | */
36 | public static String post(String url) {
37 | return post(url, "");
38 | }
39 |
40 | /**
41 | * post请求
42 | * @param url
43 | * @param data
44 | * @return
45 | */
46 | public static String post(String url, String data){
47 | return httpPost(url, data);
48 | }
49 |
50 | /**
51 | * 发送http post请求
52 | * @param url url
53 | * @param instream post数据的字节流
54 | * @return
55 | */
56 | public static String post(String url, InputStream instream){
57 | try {
58 | HttpEntity entity = Request.Post(url)
59 | .bodyStream(instream,ContentType.create("text/html", Consts.UTF_8))
60 | .execute().returnResponse().getEntity();
61 | return entity != null ? EntityUtils.toString(entity) : null;
62 | } catch (Exception e) {
63 | logger.error("post请求异常," + e.getMessage() + "\n post url:" + url);
64 | e.printStackTrace();
65 | }
66 | return null;
67 | }
68 |
69 | /**
70 | * get请求
71 | * @param url
72 | * @return
73 | */
74 | public static String get(String url){
75 | return httpGet(url);
76 | }
77 |
78 | /**
79 | * post 请求
80 | *
81 | * @param url
82 | * @param data
83 | * @return
84 | */
85 | private static String httpPost(String url, String data) {
86 | try {
87 | HttpEntity entity = Request.Post(url)
88 | .bodyString(data,ContentType.create("text/html", Consts.UTF_8))
89 | .execute().returnResponse().getEntity();
90 | return entity != null ? EntityUtils.toString(entity) : null;
91 | } catch (Exception e) {
92 | logger.error("post请求异常," + e.getMessage() + "\n post url:" + url);
93 | e.printStackTrace();
94 | }
95 | return null;
96 | }
97 |
98 | /**
99 | * 上传文件
100 | * @param url URL
101 | * @param file 需要上传的文件
102 | * @return
103 | */
104 | public static String postFile(String url,File file){
105 | return postFile(url, null, file);
106 | }
107 |
108 | /**
109 | * 上传文件
110 | * @param url URL
111 | * @param name 文件的post参数名称
112 | * @param file 上传的文件
113 | * @return
114 | */
115 | public static String postFile(String url,String name,File file){
116 | try {
117 | HttpEntity reqEntity = MultipartEntityBuilder.create().addBinaryBody(name, file).build();
118 | Request request = Request.Post(url);
119 | request.body(reqEntity);
120 | HttpEntity resEntity = request.execute().returnResponse().getEntity();
121 | return resEntity != null ? EntityUtils.toString(resEntity) : null;
122 | } catch (Exception e) {
123 | logger.error("postFile请求异常," + e.getMessage() + "\n post url:" + url);
124 | e.printStackTrace();
125 | }
126 | return null;
127 | }
128 |
129 |
130 | /**
131 | * 下载文件
132 | * @param url URL
133 | * @return 文件的二进制流,客户端使用outputStream输出为文件
134 | */
135 | public static byte[] getFile(String url){
136 | try {
137 | Request request = Request.Get(url);
138 | HttpEntity resEntity = request.execute().returnResponse().getEntity();
139 | return EntityUtils.toByteArray(resEntity);
140 | } catch (Exception e) {
141 | logger.error("postFile请求异常," + e.getMessage() + "\n post url:" + url);
142 | e.printStackTrace();
143 | }
144 | return null;
145 | }
146 |
147 | /**
148 | * 发送get请求
149 | *
150 | * @param url
151 | * @return
152 | */
153 | private static String httpGet(String url) {
154 | try {
155 | HttpEntity entity = Request.Get(url).
156 | execute().returnResponse().getEntity();
157 | return entity != null ? EntityUtils.toString(entity) : null;
158 | } catch (Exception e) {
159 | logger.error("get请求异常," + e.getMessage() + "\n get url:" + url);
160 | e.printStackTrace();
161 | }
162 | return null;
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/org/sword/lang/JaxbParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.sword.lang;
5 |
6 | import java.io.ByteArrayInputStream;
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 | import java.io.StringWriter;
10 |
11 | import javax.xml.bind.JAXBContext;
12 | import javax.xml.bind.Marshaller;
13 | import javax.xml.bind.Unmarshaller;
14 |
15 | import org.apache.log4j.Logger;
16 |
17 |
18 | import com.sun.org.apache.xml.internal.serialize.OutputFormat;
19 | import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
20 | import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
21 |
22 | /**
23 | * @author ChengNing
24 | * @date 2014年12月7日
25 | */
26 | public class JaxbParser {
27 |
28 | private static Logger logger = Logger.getLogger(JaxbParser.class);
29 |
30 | private Class clazz;
31 | private String[] cdataNode;
32 |
33 | /**
34 | *
35 | * @param clazz
36 | */
37 | public JaxbParser(Class clazz){
38 | this.clazz = clazz;
39 | }
40 |
41 | /**
42 | * 设置需要包含CDATA的节点
43 | * @param cdataNode
44 | */
45 | public void setCdataNode(String[] cdataNode) {
46 | this.cdataNode = cdataNode;
47 | }
48 |
49 | /**
50 | * 转为xml串
51 | * @param obj
52 | * @return
53 | */
54 | public String toXML(Object obj){
55 | String result = null;
56 | try {
57 | JAXBContext context = JAXBContext.newInstance(obj.getClass());
58 | Marshaller m = context.createMarshaller();
59 | m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
60 | m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
61 | m.setProperty(Marshaller.JAXB_FRAGMENT, true);// 去掉报文头
62 | OutputStream os = new ByteOutputStream();
63 | StringWriter writer = new StringWriter();
64 | XMLSerializer serializer = getXMLSerializer(os);
65 | m.marshal(obj, serializer.asContentHandler());
66 | result = os.toString();
67 | } catch (Exception e) {
68 | e.printStackTrace();
69 | }
70 | logger.info("response text:" + result);
71 | return result;
72 | }
73 |
74 |
75 | /**
76 | * 转为对象
77 | * @param is
78 | * @return
79 | */
80 | public Object toObj(InputStream is){
81 | JAXBContext context;
82 | try {
83 | context = JAXBContext.newInstance(clazz);
84 | Unmarshaller um = context.createUnmarshaller();
85 | Object obj = um.unmarshal(is);
86 | return obj;
87 | } catch (Exception e) {
88 | logger.error("post data parse error");
89 | e.printStackTrace();
90 | }
91 | return null;
92 | }
93 |
94 | /**
95 | * XML转为对象
96 | * @param xmlStr
97 | * @return
98 | */
99 | public Object toObj(String xmlStr){
100 | InputStream is = new ByteArrayInputStream(xmlStr.getBytes());
101 | return toObj(is);
102 | }
103 |
104 | /**
105 | * 设置属性
106 | * @param os
107 | * @return
108 | */
109 | private XMLSerializer getXMLSerializer(OutputStream os) {
110 | OutputFormat of = new OutputFormat();
111 | formatCDataTag();
112 | of.setCDataElements(cdataNode);
113 | of.setPreserveSpace(true);
114 | of.setIndenting(true);
115 | of.setOmitXMLDeclaration(true);
116 | XMLSerializer serializer = new XMLSerializer(of);
117 | serializer.setOutputByteStream(os);
118 | return serializer;
119 | }
120 |
121 | /**
122 | * 适配cdata tag
123 | */
124 | private void formatCDataTag(){
125 | for(int i=0;i