Source Code Cross Referenced for ConfigTemplate.java in  » RSS-RDF » sesame » org » openrdf » console » 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 » RSS RDF » sesame » org.openrdf.console 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.console;
007:
008:        import java.util.Arrays;
009:        import java.util.Collections;
010:        import java.util.LinkedHashMap;
011:        import java.util.List;
012:        import java.util.Map;
013:        import java.util.regex.Matcher;
014:        import java.util.regex.Pattern;
015:
016:        /**
017:         * @author Arjohn Kampman
018:         */
019:        class ConfigTemplate {
020:
021:            /*-----------*
022:             * Constants *
023:             *-----------*/
024:
025:            private static final Pattern TOKEN_PATTERN = Pattern
026:                    .compile("\\{%[\\p{Print}&&[^\\}]]+%\\}");
027:
028:            /*-----------*
029:             * Variables *
030:             *-----------*/
031:
032:            private String template;
033:
034:            private Map<String, List<String>> variableMap = new LinkedHashMap<String, List<String>>();
035:
036:            /*--------------*
037:             * Constructors *
038:             *--------------*/
039:
040:            public ConfigTemplate(String template) {
041:                setTemplate(template);
042:            }
043:
044:            /*---------*
045:             * Methods *
046:             *---------*/
047:
048:            public String getTemplate() {
049:                return template;
050:            }
051:
052:            public void setTemplate(String template) {
053:                if (template == null) {
054:                    throw new IllegalArgumentException(
055:                            "template must not be null");
056:                }
057:
058:                this .template = template;
059:
060:                parseTemplate();
061:            }
062:
063:            private void parseTemplate() {
064:                Matcher matcher = TOKEN_PATTERN.matcher(template);
065:                while (matcher.find()) {
066:                    String group = matcher.group();
067:                    String[] tokensArray = group.substring(2,
068:                            group.length() - 2).split("\\|");
069:                    List<String> tokens = Arrays.asList(tokensArray);
070:
071:                    String var = tokens.get(0).trim();
072:                    List<String> values = tokens.subList(1, tokens.size());
073:
074:                    if (var.length() == 0) {
075:                        throw new IllegalArgumentException(
076:                                "Illegal template token: " + matcher.group());
077:                    }
078:
079:                    if (!variableMap.containsKey(var)) {
080:                        variableMap.put(var, values);
081:                    }
082:                }
083:            }
084:
085:            public Map<String, List<String>> getVariableMap() {
086:                return Collections.unmodifiableMap(variableMap);
087:            }
088:
089:            public String render(Map<String, String> valueMap) {
090:                StringBuffer result = new StringBuffer(template.length());
091:
092:                Matcher matcher = TOKEN_PATTERN.matcher(template);
093:                while (matcher.find()) {
094:                    String group = matcher.group();
095:                    String[] tokensArray = group.substring(2,
096:                            group.length() - 2).split("\\|");
097:
098:                    String var = tokensArray[0].trim();
099:
100:                    String value = valueMap.get(var);
101:                    if (value == null) {
102:                        List<String> values = variableMap.get(var);
103:                        if (!values.isEmpty()) {
104:                            value = values.get(0);
105:                        } else {
106:                            value = "";
107:                        }
108:                    }
109:
110:                    //			if (value == null) {
111:                    //				throw new IllegalArgumentException("No value specified for variable " + var);
112:                    //			}
113:
114:                    matcher.appendReplacement(result, value);
115:                }
116:
117:                matcher.appendTail(result);
118:
119:                return result.toString();
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.