Source Code Cross Referenced for JFigConverter.java in  » Development » jfig » org » igfay » jfig » 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 » Development » jfig » org.igfay.jfig 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.igfay.jfig;
002:
003:        import java.io.File;
004:        import java.io.InputStream;
005:        import java.util.regex.Matcher;
006:        import java.util.regex.Pattern;
007:
008:        import org.apache.log4j.Logger;
009:        import org.igfay.util.FileUtility;
010:        import org.igfay.util.PropertyUtility;
011:
012:        /**
013:         * @author conrad4
014:         *
015:         * Perform JFig substitution on an InputStream.
016:         * 
017:         */
018:        public class JFigConverter {
019:
020:            private static Logger log = Logger.getLogger(JFigParser.class);
021:            private static Logger logDetail = Logger
022:                    .getLogger("ConverterDetail");
023:
024:            public String convert(File file) throws JFigException {
025:                String string = FileUtility.contentsOfFile(file);
026:                return convert(string);
027:            }
028:
029:            public String convert(File file, File outputFile)
030:                    throws JFigException {
031:                String string = FileUtility.contentsOfFile(file);
032:                //log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
033:                //log.info("~string \n"+string);
034:                string = convert(string);
035:                FileUtility.stringToFile(string, outputFile);
036:                return string;
037:            }
038:
039:            public String convert(InputStream inputStream) throws JFigException {
040:                String string = FileUtility.streamToString(inputStream);
041:                return convert(string);
042:            }
043:
044:            public String convert(String value) throws JFigException {
045:                value = resolveSymbolicValues(value);
046:                value = resolvePropertyVariables(value);
047:                return value;
048:            }
049:
050:            public void convert(InputStream inputStream, File file) {
051:                return;
052:            }
053:
054:            /**
055:             *  Replace all occurances of symbolic references with actual values. A
056:             *  symbolic reference looks like "&(section)key".
057:             *
058:             *@param  section  Description of Parameter
059:             *@param  key      Description of Parameter
060:             *@param  value    Description of Parameter
061:             */
062:            private String resolveSymbolicValues(String value)
063:                    throws JFigException {
064:                logDetail.debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n  value "
065:                        + value);
066:                if (value == null) {
067:                    return null;
068:                }
069:
070:                String replacementValue = null;
071:                String replacementSection = null;
072:                String replacementKey = null;
073:                String start = null;
074:                String rest = null;
075:                logDetail.debug("~~~~~~~~~~~~~~~~~~~~~~~~~\n ");
076:
077:                // Loop through value while it has a symbolic reference
078:                Pattern reGlobal = JFigParser.getRegexSubstitution();
079:                Matcher matcher = reGlobal.matcher(value);
080:                while ((value.indexOf(JFigConstants.SECTION_START_DELIMITER) >= 0)
081:                        && matcher.find()) {
082:                    logDetail.debug("~!foundMatch ");
083:
084:                    // Get the values that we matched in our regular expression
085:                    int index3 = matcher.start(3) - 1;
086:                    start = value.substring(0, index3);
087:
088:                    replacementSection = matcher.group(3);
089:                    replacementKey = matcher.group(5);
090:
091:                    int index6 = matcher.end(6);
092:                    rest = value.substring(index6);
093:
094:                    // Get the value for the section/key that we are referencing
095:                    replacementValue = JFig.getInstance().getValue(
096:                            replacementSection, replacementKey, "null");
097:                    logDetail.debug("~  rValue " + replacementValue);
098:
099:                    // Substitute the reference with the new value.
100:                    value = start + replacementValue + rest;
101:                    logDetail.debug("~ value " + value);
102:                    matcher = reGlobal.matcher(value);
103:                } // end while
104:
105:                return value;
106:            }
107:
108:            /**
109:             *  Replace all occurances of Property variables with properties.
110:             *  Property variable looks like "$PropertyVariable$".
111:             *
112:             *@param  section  Description of Parameter
113:             *@param  key      Description of Parameter
114:             *@param  value    Description of Parameter
115:             */
116:            private String resolvePropertyVariables(String value) {
117:                if (value == null) {
118:                    return null;
119:                }
120:                String replacementValue = null;
121:                String replacementKey = null;
122:                String start = null;
123:                String rest = null;
124:
125:                // Loop through value while it has a symbolic reference
126:                Matcher matcher = JFigParser.getRegexPropertyVariable()
127:                        .matcher(value);
128:                while ((value.indexOf(JFigConstants.PROPERTY_DELIMITER) >= 0)
129:                        && matcher.find()) {
130:                    logDetail.debug("~ value " + value);
131:
132:                    // Get the values that we matched in our regular expression
133:                    int index3 = matcher.start(3) - 1;
134:                    start = value.substring(0, index3);
135:
136:                    // Get the value for the property that we are referencing
137:                    replacementKey = matcher.group(3);
138:                    replacementValue = PropertyUtility.getProperty(
139:                            replacementKey, "");
140:
141:                    int indexRest = matcher.end(4);
142:                    rest = value.substring(indexRest);
143:                    logDetail.debug("~ --   rKey " + replacementKey
144:                            + "  rest: " + rest);
145:
146:                    // Substitute the reference with the new value.
147:                    value = start + replacementValue + rest;
148:                    logDetail.debug("~ value " + value);
149:                    matcher = JFigParser.getRegexPropertyVariable().matcher(
150:                            value);
151:
152:                }// end while
153:
154:                return value;
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.