KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > grammar > wiki > impl > WikiEngineServiceImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.grammar.wiki.impl;
6
7 import org.exoplatform.services.grammar.wiki.WikiEngineService ;
8 import org.apache.commons.pool.ObjectPool;
9 import org.apache.commons.pool.BasePoolableObjectFactory;
10 import org.apache.commons.pool.impl.StackObjectPool ;
11 import org.exoplatform.commons.utils.ExceptionUtil;
12 import org.exoplatform.container.configuration.*;
13 /**
14  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
15  * @since Dec 17, 2004
16  * @version $Id$
17  */

18 public class WikiEngineServiceImpl implements WikiEngineService {
19   private ObjectPool pool;
20   
21   public WikiEngineServiceImpl(ConfigurationManager manager) throws Exception JavaDoc {
22     ServiceConfiguration sconf = manager.getServiceConfiguration(WikiEngineService.class) ;
23     pool = new StackObjectPool(new ParsingContextFactory(sconf)) ;
24     
25   }
26   
27   public String JavaDoc toXHTML(String JavaDoc text) {
28     ParsingContext context = null ;
29     String JavaDoc result = null ;
30     try {
31       context = (ParsingContext) pool.borrowObject() ;
32       context.transform(text) ;
33       result = context.getOutputBuffer().toString() ;
34     } catch (Exception JavaDoc ex) {
35       result = text + "<br/><br/>=========-CANNOT CONVERT WIKI TO HTML===========<br/>" +
36                ExceptionUtil.getStackTrace(ex, 15) ;
37     }
38     return result;
39   }
40   
41   static class ParsingContextFactory extends BasePoolableObjectFactory {
42     ServiceConfiguration sconf_ ;
43     
44     ParsingContextFactory(ServiceConfiguration sconf) {
45       sconf_ = sconf ;
46     }
47     
48     public Object JavaDoc makeObject() {
49       return new ParsingContext(sconf_);
50     }
51     
52     public void passivateObject(Object JavaDoc obj) {
53     }
54   }
55 }
56
Popular Tags