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


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/util/TextFormat.java $
003:         * $Id: TextFormat.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 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.util;
021:
022:        import java.io.UnsupportedEncodingException;
023:        import java.net.URLEncoder;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.Vector;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:
031:        /**
032:         * <p>Copyright: Copyright (c) 2003-5</p>
033:         * <p>Organization: Sakai Project</p>
034:         * @author jlannan
035:         * @author Ed Smiley esmiley@stanford.edu
036:         * @version $Id: TextFormat.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
037:         */
038:        public class TextFormat {
039:            private static Log log = LogFactory.getLog(TextFormat.class);
040:            private static final String HTML;
041:            private static final String SMART;
042:            private static final String PLAIN;
043:            private static final Vector vProtocols;
044:            //private String upperText;
045:            private StringBuffer returnText;
046:            private StringBuffer resource;
047:            private ArrayList arrLst;
048:
049:            static {
050:                HTML = "HTML";
051:                SMART = "SMART";
052:                PLAIN = "PLAIN";
053:
054:                vProtocols = new Vector();
055:                vProtocols.add("http://");
056:                vProtocols.add("https://");
057:                vProtocols.add("ftp://");
058:                vProtocols.add("www.");
059:                vProtocols.add("telent:");
060:                vProtocols.add("mailto:");
061:            }
062:
063:            /**
064:             * DOCUMENTATION PENDING
065:             *
066:             * @param text TEXT TO BE MODIFIED
067:             * @param texttype TYPE OF TEXT -- PLAIN, HTML, OR SMART
068:             * @param iconPath PATH TO ICON IMAGES IN APPLICATION
069:             *
070:             * @return DOCUMENTATION PENDING
071:             */
072:            public String formatText(String text, String texttype,
073:                    String iconPath) {
074:                if (log.isDebugEnabled()) {
075:                    log.debug("formatText(String " + text + ", String "
076:                            + texttype + ", String " + iconPath + ")");
077:                }
078:
079:                returnText = new StringBuffer();
080:
081:                if ((texttype == null) || (text == null)) {
082:                    return text;
083:                } else if (texttype.equals(TextFormat.PLAIN)) {
084:                    return text;
085:                } else if (texttype.equals(TextFormat.HTML)) {
086:                    return text;
087:                } else if (texttype.equals(TextFormat.SMART)) {
088:                    int start = 0;
089:                    int end = 0;
090:
091:                    while (true) {
092:                        arrLst = new ArrayList();
093:
094:                        // traverse vector of protocol strings
095:                        Iterator i = vProtocols.iterator();
096:                        Integer retVal;
097:                        while (i.hasNext()) {
098:                            String str = (String) i.next();
099:                            arrLst.add(retVal = indexOfIgnoreCase(text, str));
100:                            if (retVal.intValue() == -1) {
101:                                i.remove();
102:                            }
103:                        }
104:
105:                        start = minimum(arrLst);
106:                        log.debug("start: " + String.valueOf(start));
107:                        if ((start == -1) || vProtocols.isEmpty()) {
108:                            break;
109:                        }
110:
111:                        // find either the next space or the end of string whichever comes first
112:                        if ((end = text.indexOf(" ", start)) == -1) {
113:                            end = text.length();
114:                        }
115:
116:                        // extract text and resource text from StringBuffer
117:                        if (start != 0) {
118:                            returnText.append(text.substring(0, start));
119:                            log.debug("adding pre-resource text: "
120:                                    + text.substring(0, start));
121:                        }
122:
123:                        log.debug("end: " + String.valueOf(end));
124:
125:                        resource = new StringBuffer();
126:                        String upper = text.substring(start, end).toUpperCase();
127:                        try {
128:                            if (upper.startsWith("HTTPS://")) {
129:                                resource.append("https://");
130:                                resource.append(URLEncoder.encode(text
131:                                        .substring(start + 8, end), "UTF-8"));
132:                                log.debug("hi" + resource);
133:                            } else if (upper.startsWith("HTTP://")
134:                                    || upper.startsWith("MAILTO:")
135:                                    || upper.startsWith("TELNET:")) {
136:                                resource.append("http://");
137:                                resource.append(URLEncoder.encode(text
138:                                        .substring(start + 7, end), "UTF-8"));
139:                            } else if (upper.startsWith("FTP://")) {
140:                                resource.append("ftp://");
141:                                resource.append(URLEncoder.encode(text
142:                                        .substring(start + 6, end), "UTF-8"));
143:                            } else if (upper.startsWith("WWW.")) {
144:                                resource.append("www.");
145:                                resource.append(URLEncoder.encode(text
146:                                        .substring(start + 4, end), "UTF-8"));
147:                            } else {
148:                                ;
149:                            }
150:                        } catch (UnsupportedEncodingException e) {
151:                            log.error(e.getMessage(), e);
152:                        }
153:
154:                        String temp = resource.toString();
155:                        resource.insert(resource.length(), "', target=_new>"
156:                                + temp + "</a>");
157:                        resource.insert(0, "<a href='");
158:
159:                        //stringParts.add(resource.toString());
160:                        returnText.append(resource);
161:                        log.debug("add ing resource: " + resource.toString());
162:
163:                        // delete resource string
164:                        text = text.substring(end);
165:                    }
166:
167:                    // add remaining characters to buffer
168:                    if (text.length() != 0) {
169:                        returnText.append(text);
170:                    }
171:
172:                    int temp = 0;
173:
174:                    // replace emoticons with images
175:                    while ((temp = returnText.indexOf(":-)")) != -1) {
176:                        returnText.replace(temp, temp + 3, "<img src='"
177:                                + iconPath + "smile.gif'/>");
178:                    }
179:
180:                    while ((temp = returnText.indexOf(":-(")) != -1) {
181:                        returnText.replace(temp, temp + 3, "<img src='"
182:                                + iconPath + "frown.gif'/>");
183:                    }
184:
185:                    while ((temp = returnText.indexOf(":-o")) != -1) {
186:                        returnText.replace(temp, temp + 3, "<img src='"
187:                                + iconPath + "suprise.gif'/>");
188:                    }
189:
190:                    while ((temp = returnText.indexOf(";-)")) != -1) {
191:                        returnText.replace(temp, temp + 3, "<img src='"
192:                                + iconPath + "wink.gif'/>");
193:                    }
194:
195:                    while ((temp = returnText.indexOf(":)")) != -1) {
196:                        returnText.replace(temp, temp + 2, "<img src='"
197:                                + iconPath + "smile.gif'/>");
198:                    }
199:
200:                    while ((temp = returnText.indexOf(":(")) != -1) {
201:                        returnText.replace(temp, temp + 2, "<img src='"
202:                                + iconPath + "frown.gif'/>");
203:                    }
204:
205:                    while ((temp = returnText.indexOf(":o")) != -1) {
206:                        returnText.replace(temp, temp + 2, "<img src='"
207:                                + iconPath + "suprise.gif'/>");
208:                    }
209:
210:                    while ((temp = returnText.indexOf(";)")) != -1) {
211:                        returnText.replace(temp, temp + 2, "<img src='"
212:                                + iconPath + "wink.gif'/>");
213:                    }
214:
215:                    if (returnText != null) {
216:                        return returnText.toString();
217:                    } else {
218:                        return "";
219:                    }
220:                } else {
221:                    return "";
222:                }
223:            }
224:
225:            /**
226:             * DOCUMENTATION PENDING
227:             *
228:             * @param str STRING TO BE SEARCHED
229:             * @param searchString STRING TO SEARCH FOR WITHIN str
230:             *
231:             * @return INDEX LOCATION OF searchString within str
232:             */
233:            public Integer indexOfIgnoreCase(String str, String searchString) {
234:                if (log.isDebugEnabled()) {
235:                    log.debug("indexOfIgnoreCase(String " + str + ", String "
236:                            + searchString + ")");
237:                }
238:
239:                return new Integer(str.toUpperCase().indexOf(
240:                        searchString.toUpperCase()));
241:            }
242:
243:            /**
244:             * DOCUMENTATION PENDING
245:             *
246:             * @param a LIST OF INDICIES OF OCCURANCES OF HYPERLINKS WITHIN TEXT
247:             *
248:             * @return MINIMUM OF ALL OCCURANCES OR -1 IF NO OCCURANCES
249:             */
250:            public int minimum(ArrayList a) {
251:                if (log.isDebugEnabled()) {
252:                    log.debug("minimum(ArrayList " + a + ")");
253:                }
254:
255:                boolean firstNumber = true;
256:                int tmp = 0;
257:                int min = -1;
258:
259:                Iterator i = a.iterator();
260:                while (i.hasNext()) {
261:                    tmp = ((Integer) i.next()).intValue();
262:
263:                    if (firstNumber && (tmp != -1)) {
264:                        firstNumber = false;
265:                        min = tmp;
266:                    }
267:
268:                    if ((tmp != -1) && (tmp < min)) {
269:                        min = tmp;
270:                    }
271:                }
272:
273:                return min;
274:            }
275:
276:            /**
277:             * test
278:             *
279:             * @param args
280:             */
281:            public static void main(String[] args) {
282:                TextFormat tf = new TextFormat();
283:                log
284:                        .info(tf
285:                                .formatText(
286:                                        "www.cs.iupui.edu ui.edu dd dd dd:):-) ff telnet:dd dddddupui.edu",
287:                                        "SMART",
288:                                        ("http://oncourse.iu.edu/images/icons/")));
289:                log.info(tf.formatText(
290:                        "http://www.iupui.edu:80 www.ui.edu :( ::-( ddd",
291:                        "SMART", ("http://oncourse.iu.edu/images/icons/")));
292:
293:                log.debug(String.valueOf(System.identityHashCode(tf)));
294:            }
295:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.