Source Code Cross Referenced for YAML.java in  » Scripting » jruby » org » jvyamlb » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jruby » org.jvyamlb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***** BEGIN LICENSE BLOCK *****
002:         * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003:         *
004:         * The contents of this file are subject to the Common Public
005:         * License Version 1.0 (the "License"); you may not use this file
006:         * except in compliance with the License. You may obtain a copy of
007:         * the License at http://www.eclipse.org/legal/cpl-v10.html
008:         *
009:         * Software distributed under the License is distributed on an "AS
010:         * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011:         * implied. See the License for the specific language governing
012:         * rights and limitations under the License.
013:         *
014:         * Copyright (C) 2007 Ola Bini <ola@ologix.com>
015:         * 
016:         * Alternatively, the contents of this file may be used under the terms of
017:         * either of the GNU General Public License Version 2 or later (the "GPL"),
018:         * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
019:         * in which case the provisions of the GPL or the LGPL are applicable instead
020:         * of those above. If you wish to allow use of your version of this file only
021:         * under the terms of either the GPL or the LGPL, and not to allow others to
022:         * use your version of this file under the terms of the CPL, indicate your
023:         * decision by deleting the provisions above and replace them with the notice
024:         * and other provisions required by the GPL or the LGPL. If you do not delete
025:         * the provisions above, a recipient may use your version of this file under
026:         * the terms of any one of the CPL, the GPL or the LGPL.
027:         ***** END LICENSE BLOCK *****/package org.jvyamlb;
028:
029:        import java.io.InputStream;
030:        import java.io.ByteArrayOutputStream;
031:        import java.io.OutputStream;
032:
033:        import java.util.Iterator;
034:        import java.util.Map;
035:        import java.util.HashMap;
036:        import java.util.List;
037:        import java.util.ArrayList;
038:
039:        import org.jruby.util.ByteList;
040:
041:        /**
042:         * The combinatorial explosion class.
043:         *
044:         * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
045:         */
046:        public class YAML {
047:            public static final String DEFAULT_SCALAR_TAG = "tag:yaml.org,2002:str";
048:            public static final String DEFAULT_SEQUENCE_TAG = "tag:yaml.org,2002:seq";
049:            public static final String DEFAULT_MAPPING_TAG = "tag:yaml.org,2002:map";
050:
051:            public static final Map ESCAPE_REPLACEMENTS = new HashMap();
052:
053:            static {
054:                ESCAPE_REPLACEMENTS.put(new Character('\0'), "0");
055:                ESCAPE_REPLACEMENTS.put(new Character('\u0007'), "a");
056:                ESCAPE_REPLACEMENTS.put(new Character('\u0008'), "b");
057:                ESCAPE_REPLACEMENTS.put(new Character('\u0009'), "t");
058:                ESCAPE_REPLACEMENTS.put(new Character('\n'), "n");
059:                ESCAPE_REPLACEMENTS.put(new Character('\u000B'), "v");
060:                ESCAPE_REPLACEMENTS.put(new Character('\u000C'), "f");
061:                ESCAPE_REPLACEMENTS.put(new Character('\r'), "r");
062:                ESCAPE_REPLACEMENTS.put(new Character('\u001B'), "e");
063:                ESCAPE_REPLACEMENTS.put(new Character('"'), "\"");
064:                ESCAPE_REPLACEMENTS.put(new Character('\\'), "\\");
065:                ESCAPE_REPLACEMENTS.put(new Character('\u0085'), "N");
066:                ESCAPE_REPLACEMENTS.put(new Character('\u00A0'), "_");
067:            }
068:
069:            public static YAMLConfig config() {
070:                return defaultConfig();
071:            }
072:
073:            public static YAMLConfig defaultConfig() {
074:                return new DefaultYAMLConfig();
075:            }
076:
077:            public static ByteList dump(final Object data) {
078:                return dump(data, config());
079:            }
080:
081:            public static ByteList dump(final Object data,
082:                    final YAMLFactory fact) {
083:                return dump(data, fact, config());
084:            }
085:
086:            public static ByteList dump(final Object data, final YAMLConfig cfg) {
087:                final List lst = new ArrayList(1);
088:                lst.add(data);
089:                return dumpAll(lst, cfg);
090:            }
091:
092:            public static ByteList dump(final Object data,
093:                    final YAMLFactory fact, final YAMLConfig cfg) {
094:                final List lst = new ArrayList(1);
095:                lst.add(data);
096:                return dumpAll(lst, fact, cfg);
097:            }
098:
099:            public static ByteList dumpAll(final List data) {
100:                return dumpAll(data, config());
101:            }
102:
103:            public static ByteList dumpAll(final List data,
104:                    final YAMLFactory fact) {
105:                return dumpAll(data, fact, config());
106:            }
107:
108:            public static ByteList dumpAll(final List data, final YAMLConfig cfg) {
109:                final ByteArrayOutputStream swe = new ByteArrayOutputStream();
110:                dumpAll(data, swe, cfg);
111:                return new ByteList(swe.toByteArray(), false);
112:            }
113:
114:            public static ByteList dumpAll(final List data,
115:                    final YAMLFactory fact, final YAMLConfig cfg) {
116:                final ByteArrayOutputStream swe = new ByteArrayOutputStream();
117:                dumpAll(data, swe, fact, cfg);
118:                return new ByteList(swe.toByteArray(), false);
119:            }
120:
121:            public static void dump(final Object data, final OutputStream output) {
122:                dump(data, output, config());
123:            }
124:
125:            public static void dump(final Object data,
126:                    final OutputStream output, YAMLFactory fact) {
127:                dump(data, output, fact, config());
128:            }
129:
130:            public static void dump(final Object data,
131:                    final OutputStream output, final YAMLConfig cfg) {
132:                final List lst = new ArrayList(1);
133:                lst.add(data);
134:                dumpAll(lst, output, cfg);
135:            }
136:
137:            public static void dump(final Object data,
138:                    final OutputStream output, final YAMLFactory fact,
139:                    final YAMLConfig cfg) {
140:                final List lst = new ArrayList(1);
141:                lst.add(data);
142:                dumpAll(lst, output, fact, cfg);
143:            }
144:
145:            public static void dumpAll(final List data,
146:                    final OutputStream output) {
147:                dumpAll(data, output, config());
148:            }
149:
150:            public static void dumpAll(final List data,
151:                    final OutputStream output, final YAMLFactory fact) {
152:                dumpAll(data, output, fact, config());
153:            }
154:
155:            public static void dumpAll(final List data,
156:                    final OutputStream output, final YAMLConfig cfg) {
157:                dumpAll(data, output, new DefaultYAMLFactory(), cfg);
158:            }
159:
160:            public static void dumpAll(final List data,
161:                    final OutputStream output, final YAMLFactory fact,
162:                    final YAMLConfig cfg) {
163:                final Serializer s = fact.createSerializer(fact.createEmitter(
164:                        output, cfg), fact.createResolver(), cfg);
165:                try {
166:                    s.open();
167:                    final Representer r = fact.createRepresenter(s, cfg);
168:                    for (final Iterator iter = data.iterator(); iter.hasNext();) {
169:                        r.represent(iter.next());
170:                    }
171:                } catch (final java.io.IOException e) {
172:                    throw new YAMLException(e);
173:                } finally {
174:                    try {
175:                        s.close();
176:                    } catch (final java.io.IOException e) {
177:                    }
178:                }
179:            }
180:
181:            public static Object load(final ByteList io) {
182:                return load(io, new DefaultYAMLFactory(), config());
183:            }
184:
185:            public static Object load(final InputStream io) {
186:                return load(io, new DefaultYAMLFactory(), config());
187:            }
188:
189:            public static Object load(final ByteList io, final YAMLConfig cfg) {
190:                return load(io, new DefaultYAMLFactory(), cfg);
191:            }
192:
193:            public static Object load(final InputStream io, final YAMLConfig cfg) {
194:                return load(io, new DefaultYAMLFactory(), cfg);
195:            }
196:
197:            public static Object load(final ByteList io,
198:                    final YAMLFactory fact, final YAMLConfig cfg) {
199:                final Constructor ctor = fact
200:                        .createConstructor(fact.createComposer(fact
201:                                .createParser(fact.createScanner(io), cfg),
202:                                fact.createResolver()));
203:                if (ctor.checkData()) {
204:                    return ctor.getData();
205:                } else {
206:                    return null;
207:                }
208:            }
209:
210:            public static Object load(final InputStream io,
211:                    final YAMLFactory fact, final YAMLConfig cfg) {
212:                final Constructor ctor = fact
213:                        .createConstructor(fact.createComposer(fact
214:                                .createParser(fact.createScanner(io), cfg),
215:                                fact.createResolver()));
216:                if (ctor.checkData()) {
217:                    return ctor.getData();
218:                } else {
219:                    return null;
220:                }
221:            }
222:
223:            public static List loadAll(final ByteList io) {
224:                return loadAll(io, new DefaultYAMLFactory(), config());
225:            }
226:
227:            public static List loadAll(final InputStream io) {
228:                return loadAll(io, new DefaultYAMLFactory(), config());
229:            }
230:
231:            public static List loadAll(final ByteList io, final YAMLConfig cfg) {
232:                return loadAll(io, new DefaultYAMLFactory(), cfg);
233:            }
234:
235:            public static List loadAll(final InputStream io,
236:                    final YAMLConfig cfg) {
237:                return loadAll(io, new DefaultYAMLFactory(), cfg);
238:            }
239:
240:            public static List loadAll(final ByteList io,
241:                    final YAMLFactory fact, final YAMLConfig cfg) {
242:                final List result = new ArrayList();
243:                final Constructor ctor = fact
244:                        .createConstructor(fact.createComposer(fact
245:                                .createParser(fact.createScanner(io), cfg),
246:                                fact.createResolver()));
247:                while (ctor.checkData()) {
248:                    result.add(ctor.getData());
249:                }
250:                return result;
251:            }
252:
253:            public static List loadAll(final InputStream io,
254:                    final YAMLFactory fact, final YAMLConfig cfg) {
255:                final List result = new ArrayList();
256:                final Constructor ctor = fact
257:                        .createConstructor(fact.createComposer(fact
258:                                .createParser(fact.createScanner(io), cfg),
259:                                fact.createResolver()));
260:                while (ctor.checkData()) {
261:                    result.add(ctor.getData());
262:                }
263:                return result;
264:            }
265:
266:            public static void main(final String[] args) {
267:                System.err.println(YAML.load(new ByteList(
268:                        "%YAML 1.0\n---\n!str str".getBytes())));
269:            }
270:        }// YAML
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.