Source Code Cross Referenced for RenderMaker.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » assessment » devtools » 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 » ERP CRM Financial » sakai » org.sakaiproject.tool.assessment.devtools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/devtools/RenderMaker.java $
003:         * $Id: RenderMaker.java 14180 2006-08-31 23:09:00Z ktsao@stanford.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007:         *
008:         * Licensed under the Educational Community License, Version 1.0 (the"License");
009:         * you may not use this file except in compliance with the License.
010:         * You may obtain a copy of the License at
011:         *
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         *
014:         * Unless required by applicable law or agreed to in writing, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.tool.assessment.devtools;
021:
022:        import java.io.BufferedReader;
023:        import java.io.FileReader;
024:        import java.io.IOException;
025:        import java.io.Reader;
026:        import java.io.StringReader;
027:        import java.util.StringTokenizer;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        public class RenderMaker {
033:            private static Log log = LogFactory.getLog(RenderMaker.class);
034:            // either run this application from the command line with the input file as an
035:            // argument, or edit this name to suit your fancy.
036:            //  private static String fileName = "c:\\Navigo\\webapp\\html\\picker.html";
037:            private static String fileName = "c:\\divstart.html";
038:
039:            private static final String QUOTE = "\"";
040:            private static final String ESCAPEDQUOTE = "\\" + "\"";
041:
042:            // this provides for the notation to place a variable in the input
043:            private static final String VARIABLEESCAPE = "%";
044:
045:            private static final String PLUS = " + ";
046:
047:            private static String WRITETEXT = "      writer.write(\"";
048:            private static String ENDWRITETEXT = "\");\n";
049:            private static String JAVADOC = "/**\n"
050:                    + " * <p>Faces render output method .</p>\n"
051:                    + " * <p>Method Generator: "
052:                    + "org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>\n"
053:                    + " *\n"
054:                    + " *  @param context   <code>FacesContext</code> for the current request\n"
055:                    + " *  @param component <code>UIComponent</code> being rendered\n"
056:                    + " *\n"
057:                    + " * @throws IOException if an input/output error occurs\n"
058:                    + " *" + "/\n";
059:            private static String METHODSIGNATURE = "  public void ";
060:            private static String METHODSIGNATUREEND = "(FacesContext context, UIComponent component)\n"
061:                    + "    throws IOException {\n\n";
062:            private static String GETAWRITER = "      ResponseWriter writer = context.getResponseWriter();\n\n";
063:
064:            private static String METHODEND = "  }\n\n";
065:
066:            private static String[] validMethods = { "encodeBegin",
067:                    "encodeChildren", "encodeEnd" };
068:
069:            public RenderMaker() {
070:            }
071:
072:            public static void main(String[] args) {
073:                if (args.length > 0) {
074:                    fileName = args[0];
075:                }
076:                try {
077:                    if (args.length > 2) {
078:                        log.debug(makeMethodFromFile(fileName, args[1]));
079:                    } else {
080:                        log.debug(makeMethodFromFile(fileName, "encodeBegin"));
081:                    }
082:                } catch (IOException ex) {
083:                    log.error("ooops");
084:                }
085:            }
086:
087:            public static void stringTest() {
088:                StringReader sr = new StringReader(
089:                        "<table bgcolor=\"#000000\" width=\"100%\" border=\"0\" cellpadding=\"0\"");
090:                StringReader sr2 = new StringReader(
091:                        "<a href=\"%xxx%\">100%%%</a>");
092:                try {
093:                    log.debug(makeMethod(sr, "encodeBegin"));
094:                    log.debug(makeMethod(sr2, "encodeChildren"));
095:                } catch (Exception ex) {
096:                    log
097:                            .error("\n\n***********\n\nError in makeMethod(): "
098:                                    + ex);
099:                }
100:            }
101:
102:            public static void fileTest() {
103:                try {
104:                    log.debug(makeMethodFromFile(fileName, "encodeBegin"));
105:                } catch (Exception ex) {
106:                    log
107:                            .error("\n\n***********\n\nError in makeMethodFromFile(): "
108:                                    + ex);
109:                }
110:            }
111:
112:            public static String makeMethodFromFile(String fileName,
113:                    String methodName) throws IOException {
114:                return "\n/* *** GENERATOR FILE: "
115:                        + fileName
116:                        + "*** */\n"
117:                        + "\n/* *** IF SOURCE DOCUMENT CHANGES YOU NEED TO REGENERATE THIS METHOD"
118:                        + "*** */\n"
119:                        + makeMethod(new FileReader(fileName), methodName);
120:            }
121:
122:            public static String makeMethod(Reader reader, String methodName)
123:                    throws IOException {
124:                // validate you are making a valid method source
125:                boolean valid = false;
126:                for (int i = 0; i < validMethods.length; i++) {
127:                    if (validMethods[i].equals(methodName)) {
128:                        valid = true;
129:                        break;
130:                    }
131:                }
132:                if (!valid)
133:                    throw new IllegalArgumentException(methodName);
134:
135:                BufferedReader br = new BufferedReader(reader);
136:                StringBuffer sb = new StringBuffer();
137:
138:                sb.append(JAVADOC + METHODSIGNATURE + methodName
139:                        + METHODSIGNATUREEND);
140:                sb.append(GETAWRITER);
141:
142:                String buf;
143:
144:                while ((buf = br.readLine()) != null) {
145:                    sb.append(makeLine(buf));
146:                }
147:
148:                sb.append(METHODEND);
149:
150:                return sb.toString();
151:            }
152:
153:            private static String makeLine(String s) {
154:                return makeWriterWriteText(normalize(s));
155:            }
156:
157:            private static String normalize(String abnormal) {
158:                StringBuffer normal = new StringBuffer();
159:                StringTokenizer st = new StringTokenizer(abnormal, QUOTE
160:                        + VARIABLEESCAPE, true);
161:
162:                while (st.hasMoreTokens()) {
163:                    String token = st.nextToken();
164:                    if (QUOTE.equals(token)) {
165:                        normal.append(ESCAPEDQUOTE);
166:                    } else if (VARIABLEESCAPE.equals(token)) {
167:                        //        normal.append(token);
168:                        normal.append(getEscapedVariableToken(st));
169:                    } else {
170:                        normal.append(token);
171:                    }
172:                }
173:
174:                return normal.toString();
175:            }
176:
177:            /**
178:             * take variable expressed inside "%" escapes
179:             *
180:             *
181:             *  this provides for the notation to place a variable in the input
182:             *  you MUST add code to initialize the variables
183:             *  usage:
184:             *  <a href="%variableName%">%variableName%</a>'  ==>
185:             *  'writer.writeText("<a href=\""+variableName+"\">" + variableName + "</a>", null);'
186:             *
187:             *  escaping out the escape:
188:             *  '%%%' => '%'
189:             *
190:             * @param st a StringTokeinzer tokenizing on the escapes and hitting one
191:             * @return the concatentation of the variable into the writer
192:             *
193:             */
194:            private static String getEscapedVariableToken(StringTokenizer st) {
195:                String token = "";
196:                String returnToken = "";
197:
198:                if (st.hasMoreTokens()) {
199:                    token = st.nextToken();
200:
201:                    // if it is an escape it is an escaped escape so we return an escape
202:                    if (VARIABLEESCAPE.equals(token)) {
203:                        returnToken = token;
204:                    } else // well, it's not an escape, so we need to concatenate it in
205:                    {
206:                        returnToken = QUOTE + PLUS + token + PLUS + QUOTE;
207:                    }
208:
209:                    // now we throw away the end token
210:                    if (st.hasMoreTokens()) {
211:                        st.nextToken();
212:                    }
213:                }
214:                return returnToken;//QUOTE + PLUS + token + PLUS + QUOTE;
215:            }
216:
217:            private static String makeWriterWriteText(String s) {
218:                return WRITETEXT + s + ENDWRITETEXT;
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.