Source Code Cross Referenced for JspWikiEngineBean.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.File;
004:        import java.io.IOException;
005:        import java.io.InputStream;
006:        import java.io.InputStreamReader;
007:        import java.security.Security;
008:        import java.util.Properties;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.jbpm.util.ClassLoaderUtil;
013:        import org.springframework.beans.factory.FactoryBean;
014:        import org.springframework.beans.factory.InitializingBean;
015:        import org.springframework.context.ApplicationContext;
016:        import org.springframework.context.ApplicationContextAware;
017:        import org.springframework.core.io.Resource;
018:        import org.springframework.transaction.PlatformTransactionManager;
019:        import org.springframework.transaction.TransactionStatus;
020:        import org.springframework.transaction.support.TransactionCallback;
021:        import org.springframework.transaction.support.TransactionTemplate;
022:        import org.springframework.util.FileCopyUtils;
023:
024:        import com.ecyrd.jspwiki.WikiContext;
025:        import com.ecyrd.jspwiki.WikiEngine;
026:        import com.ecyrd.jspwiki.WikiException;
027:        import com.ecyrd.jspwiki.WikiPage;
028:
029:        /** This is Bean for making JspWiki WikiEngine via Spring Configuration
030:         * 
031:         * @author akakunin
032:         *
033:         */
034:        public class JspWikiEngineBean implements  FactoryBean,
035:                InitializingBean, ApplicationContextAware {
036:            protected final Log logger = LogFactory.getLog(getClass());
037:            public static final String SPRING_CONTEXT_PROPERTY = "jspwiki.spring.context";
038:
039:            private WikiEngine m_engine;
040:
041:            /// properties
042:            private Properties m_props;
043:
044:            private Resource m_initWikiPagesFolder;
045:            private TransactionTemplate transactionTemplate;
046:
047:            ApplicationContext m_appContext;
048:
049:            public void setApplicationContext(ApplicationContext i_appContext) {
050:                m_appContext = i_appContext;
051:            }
052:
053:            /// setter for properties
054:            public void setWikiProperties(Properties i_props) {
055:                m_props = i_props;
056:            }
057:
058:            public void setInitWikiPagesFolder(Resource i_initWikiPagesFolder) {
059:                m_initWikiPagesFolder = i_initWikiPagesFolder;
060:            }
061:
062:            /// Created WikiEngine
063:            //private WikiEngine	m_engine;
064:
065:            public void setTxManager(PlatformTransactionManager i_txManager) {
066:                transactionTemplate = new TransactionTemplate(i_txManager);
067:            }
068:
069:            /** Gets the WikiEngine
070:             * 
071:             * @return WikiEngine
072:             */
073:            public WikiEngine getEngine() throws Exception {
074:                return (WikiEngine) getObject();
075:            }
076:
077:            public Object getObject() throws Exception {
078:                if (m_engine == null) {
079:                    m_engine = createEngine();
080:                }
081:
082:                assert m_engine != null;
083:                return m_engine;
084:            }
085:
086:            public Class<?> getObjectType() {
087:                return WikiEngine.class;
088:            }
089:
090:            public boolean isSingleton() {
091:                return true;
092:            }
093:
094:            public void afterPropertiesSet() throws Exception {
095:                if (m_props == null) {
096:                    throw new IllegalArgumentException(
097:                            "wikiProperties should be specified for wikiEngine bean");
098:                }
099:
100:                //add spring context into properties to access it from bean wrappers
101:                m_props.put(SPRING_CONTEXT_PROPERTY, m_appContext);
102:            }
103:
104:            /** Creates WikiEngine object
105:             * 
106:             * @throws Exception
107:             */
108:            protected WikiEngine createEngine() throws Exception {
109:                return (WikiEngine) transactionTemplate
110:                        .execute(new TransactionCallback() {
111:
112:                            // the code in this method executes in a transactional context
113:                            public Object doInTransaction(
114:                                    TransactionStatus status) {
115:                                try {
116:                                    assert m_props != null;
117:                                    assert m_engine == null;
118:
119:                                    Security
120:                                            .setProperty("policy.provider",
121:                                                    "ru.emdev.EmForge.wiki.security.PolicyImpl");
122:
123:                                    WikiEngine engine = new WikiEngine(m_props);
124:                                    assert engine != null;
125:
126:                                    initPages(engine);
127:                                    return engine;
128:                                } catch (Exception ex) {
129:                                    logger.error("Cannot create wiki engine",
130:                                            ex);
131:                                    status.setRollbackOnly();
132:                                    return null;
133:                                }
134:                            }
135:                        });
136:            }
137:
138:            private void initPages(WikiEngine i_engine) {
139:                assert m_initWikiPagesFolder != null;
140:
141:                try {
142:                    File directory = m_initWikiPagesFolder.getFile();
143:                    String[] files = directory.list();
144:
145:                    for (int i = 0; i < files.length; i++) {
146:                        if (files[i].endsWith(".txt")) {
147:                            String pageName = files[i].substring(0, files[i]
148:                                    .length() - 4);
149:
150:                            // check - is this name exists in wikiEngine
151:                            WikiPage page = i_engine.getPage(pageName);
152:
153:                            if (page == null) {
154:                                logger.info("Create " + pageName + " page");
155:                                // create EditPageHelp page if it is not exists
156:                                page = new WikiPage(i_engine, pageName);
157:
158:                                WikiContext wikiContext = new WikiContext(
159:                                        i_engine, page);
160:
161:                                InputStream pageStream = ClassLoaderUtil
162:                                        .getStream("ru/emdev/EmForge/wiki/pages/"
163:                                                + files[i]);
164:                                String pageText = FileCopyUtils
165:                                        .copyToString(new InputStreamReader(
166:                                                pageStream));
167:
168:                                i_engine.saveText(wikiContext, pageText);
169:
170:                            }
171:                        }
172:                    }
173:                } catch (IOException ioEx) {
174:                    logger.error("Cannot load wikiPages from resources", ioEx);
175:                } catch (WikiException wikiEx) {
176:                    logger.error("Cannot store wikiPages ", wikiEx);
177:                }
178:
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.