Package com.piki.server

Source Code of com.piki.server.FormatServiceImpl

package com.piki.server;

import info.bliki.wiki.model.WikiModel;

import com.piki.client.rpc.FormatService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class FormatServiceImpl extends RemoteServiceServlet implements
    FormatService {

  private ThreadLocal<WikiModel> wikiModel = null;

  public String format(String titleBaseUrl, String input)
      throws IllegalArgumentException {

    if (input == null)
      throw new IllegalArgumentException("missing argument inpit");

    WikiModel wikiModel = getWikiModel(titleBaseUrl);
    try {
      wikiModel.setUp();
      return wikiModel.render(input);
    } finally {
      wikiModel.tearDown();
    }

  }

  private synchronized WikiModel getWikiModel(String titleBaseUrl) {

    if (wikiModel == null)
      wikiModel = new ThreadLocal<WikiModel>();

    WikiModel wm = wikiModel.get();
    if (wm == null) {
      wm = new MyWikiModel(titleBaseUrl + "image/${image}", titleBaseUrl
          + "#wiki:${title}");
      wikiModel.set(wm);
    }
    return wm;
  }

}
TOP

Related Classes of com.piki.server.FormatServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.