Source Code Cross Referenced for WikiTextToXHTMLConverter.java in  » Project-Management » EmForce » ru » emdev » EmForge » wiki » 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 » Project Management » EmForce » ru.emdev.EmForge.wiki 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package ru.emdev.EmForge.wiki;
002:
003:        import java.io.IOException;
004:        import java.io.StringReader;
005:
006:        import javax.faces.component.StateHolder;
007:        import javax.faces.component.UIComponent;
008:        import javax.faces.component.UIComponentBase;
009:        import javax.faces.context.FacesContext;
010:        import javax.faces.convert.Converter;
011:        import javax.faces.el.ValueBinding;
012:
013:        import org.apache.commons.lang.StringUtils;
014:        import org.apache.commons.logging.Log;
015:        import org.apache.commons.logging.LogFactory;
016:
017:        import ru.emdev.EmForge.util.Helper;
018:
019:        import com.ecyrd.jspwiki.WikiContext;
020:        import com.ecyrd.jspwiki.WikiEngine;
021:        import com.ecyrd.jspwiki.WikiPage;
022:        import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser;
023:        import com.ecyrd.jspwiki.parser.MarkupParser;
024:        import com.ecyrd.jspwiki.render.WikiRenderer;
025:
026:        /** Converter to convert from wiki formatted text to XHTML
027:         * 
028:         * This class implements standard JSF Converter interface, so, may be used as 
029:         * converter in JSF Tags (for example h:outputText tags)
030:         * 
031:         * It supports only converting from wiki to XHTML, back convertion is not supported yet
032:         */
033:        public class WikiTextToXHTMLConverter extends UIComponentBase implements 
034:                Converter, StateHolder {
035:            /**
036:             * 
037:             */
038:            private static final long serialVersionUID = 1L;
039:
040:            protected final Log logger = LogFactory.getLog(getClass());
041:
042:            private WikiEngine m_wikiEngine;
043:            private String m_wikiName = null;
044:
045:            public void setWikiName(String i_wikiName) {
046:                m_wikiName = i_wikiName;
047:            }
048:
049:            public String getWikiName() {
050:                if (m_wikiName != null) {
051:                    return m_wikiName;
052:                }
053:
054:                ValueBinding vb = getValueBinding("wikiName");
055:                String v = vb != null ? (String) vb.getValue(getFacesContext())
056:                        : null;
057:                return v;
058:            }
059:
060:            private WikiEngine getWikiEngine(FacesContext context)
061:                    throws Exception {
062:                if (m_wikiEngine != null) {
063:                    return m_wikiEngine;
064:                } else {
065:                    return Helper.getWikiEngine(context);
066:                }
067:            }
068:
069:            public WikiTextToXHTMLConverter() {
070:
071:            }
072:
073:            public WikiTextToXHTMLConverter(WikiEngine i_wikiEngine,
074:                    String i_wikiName) {
075:                m_wikiName = i_wikiName;
076:                m_wikiEngine = i_wikiEngine;
077:            }
078:
079:            /** Back convertions - is not currently supported
080:             * 
081:             * It is not supported because it is not required
082:             */
083:            public Object getAsObject(FacesContext context,
084:                    UIComponent component, String value) {
085:                return value;
086:            }
087:
088:            /** Convert from wiki formatted text to XHTML
089:             * 
090:             * @param value - wiki formatted text
091:             * @return XHTML formatted text
092:             */
093:            public String getAsString(FacesContext context,
094:                    UIComponent component, Object value) {
095:                String result = "";
096:                try {
097:                    // get wiki engine via Spring now
098:                    WikiEngine wikiEngine = getWikiEngine(context);
099:                    WikiPage pageInfo = null;
100:                    String wikiText = null;
101:
102:                    if (value instanceof  WikiPage) {
103:
104:                        pageInfo = (WikiPage) value;
105:                        wikiText = wikiEngine.getPureText(pageInfo);
106:
107:                    } else if (value instanceof  String) {
108:
109:                        if (StringUtils.isNotEmpty(getWikiName())) {
110:
111:                            pageInfo = wikiEngine.getPage(getWikiName());
112:
113:                            // probably a wiki page hasn't been created yet, so
114:                            // create temporary page info
115:                            if (pageInfo == null) {
116:                                pageInfo = new WikiPage(wikiEngine,
117:                                        getWikiName());
118:                            }
119:
120:                        } else {
121:                            // just in case
122:                            pageInfo = new WikiPage(wikiEngine, "DummyPage");
123:                        }
124:
125:                        wikiText = (String) value;
126:                    }
127:
128:                    result = convert(wikiEngine, pageInfo, wikiText);
129:
130:                } catch (Exception ex) {
131:                    logger.error("Cannot convert wiki text:", ex);
132:                    return null;
133:                }
134:                return result;
135:            }
136:
137:            /**
138:             * 
139:             * @param i_wikiEngine
140:             * @param i_pageInfo (the page where a text should be shown )
141:             * @param i_wikiText
142:             * @return
143:             * @throws IOException
144:             */
145:            private String convert(WikiEngine i_wikiEngine,
146:                    WikiPage i_pageInfo, String i_wikiText) throws IOException {
147:
148:                assert i_wikiEngine != null;
149:
150:                // check for null
151:                if (StringUtils.isEmpty(i_wikiText)) {
152:                    return "";
153:                }
154:
155:                WikiContext wikiContext = new WikiContext(i_wikiEngine,
156:                        i_pageInfo);
157:
158:                i_wikiText = new ProcessInstanceLinkFilter()
159:                        .makeLinksToInstanceProcess(
160:                                ProcessInstanceLinkFilter.PROCESS_LINK_MARK,
161:                                i_wikiText);
162:
163:                MarkupParser parser = new JSPWikiMarkupParser(wikiContext,
164:                        new StringReader(i_wikiText));
165:                WikiRenderer renderer = new EmForgeRendererImpl(wikiContext,
166:                        parser.parse());
167:                return renderer.getString();
168:
169:            }
170:
171:            private boolean m_transient = false;
172:
173:            public boolean isTransient() {
174:                return m_transient;
175:            }
176:
177:            public void setTransient(boolean newTransientValue) {
178:                m_transient = newTransientValue;
179:            }
180:
181:            public Object saveState(FacesContext context) {
182:                Object values[] = new Object[1];
183:                values[0] = m_wikiName;
184:                return values;
185:            }
186:
187:            public void restoreState(FacesContext context, Object state) {
188:                Object values[] = (Object[]) state;
189:                m_wikiName = (String) values[0];
190:            }
191:
192:            /** 
193:             * @todo clarify correct value for it
194:             */
195:            @Override
196:            public String getFamily() {
197:                return "EMFORGE_FAMILY";
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.