Package org.atomojo.www.app.edit

Source Code of org.atomojo.www.app.edit.ClassResourceFinder

/*
* ClassResourceFinder.java
*
* Created on September 7, 2007, 11:19 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package org.atomojo.www.app.edit;

import java.util.logging.Level;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.resource.Finder;
import org.restlet.resource.ServerResource;

/**
*
* @author alex
*/
public class ClassResourceFinder extends Finder
{

   ClassLoader classLoader;
   String packageName;
  
   /** Creates a new instance of ClassResourceFinder */
   public ClassResourceFinder(Context context,ClassLoader classLoader,String path)
   {
      super(context);
      this.classLoader = classLoader;
      this.packageName = path;
      if (!this.packageName.endsWith("/")) {
         this.packageName += "/";
      }
   }
  
   /** Creates a new instance of ClassResourceFinder */
   public ClassResourceFinder(Context context,ClassLoader classLoader,Class baseClass)
   {
      super(context);
      this.classLoader = classLoader;
      this.packageName = baseClass.getPackage().getName().replace('.','/')+"/";
      if (!this.packageName.endsWith("/")) {
         this.packageName += "/";
      }
   }
   public ServerResource find(Request request,Response response)
   {
      String path = packageName+request.getResourceRef().getRemainingPart();
      if (path.charAt(path.length()-1)=='/') {
         path += "index.html";
      }
      if (getLogger().isLoggable(Level.FINE)) {
         getLogger().fine("path="+path);
      }
      ServerResource r = new ClassResource(classLoader,path);
      return r;
   }
  
}
TOP

Related Classes of org.atomojo.www.app.edit.ClassResourceFinder

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.