当前位置: 首页>>代码示例>>Java>>正文


Java Resource类代码示例

本文整理汇总了Java中org.mortbay.resource.Resource的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Resource类属于org.mortbay.resource包,在下文中一共展示了Resource类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendDirectory

import org.mortbay.resource.Resource; //导入依赖的package包/类
protected void sendDirectory(HttpServletRequest request,
  HttpServletResponse response, Resource resource, boolean parent)
  throws IOException
{
  byte[] data=null;
  String base = URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH);
  // Use customized getListHTML
  String dir = getListHTML(resource, base, parent);
  if (dir==null)
  {
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "No directory");
    return;
  }
  data=dir.getBytes("UTF-8");
  response.setContentType("text/html; charset=UTF-8");
  response.setContentLength(data.length);
  response.getOutputStream().write(data);
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:19,代码来源:StaticServlet.java

示例2: configure

import org.mortbay.resource.Resource; //导入依赖的package包/类
/**
 * Configures Jetty server before adding any web applications to it.
 */
private void configure()
{
    // Applies external configuration via jetty.xml
    applyJettyXml();

    // Configures connectores for this server instance.
    Iterator connectorIterator = connectors.iterator();
    while (connectorIterator.hasNext())
    {
        Connector jettyConnector = (Connector) connectorIterator.next();
        server.addConnector(jettyConnector);
    }

    // Configures user realms
    Iterator realmsIterator = userRealms.iterator();
    while (realmsIterator.hasNext())
    {
        UserRealm realm = (UserRealm) realmsIterator.next();
        server.addUserRealm(realm);
    }

    // Does not cache resources, to prevent Windows from locking files
    Resource.setDefaultUseCaches(false);

    // Set default server handlers
    configureHandlers();
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:31,代码来源:ServerProxyImpl.java

示例3: createWebAppContext

import org.mortbay.resource.Resource; //导入依赖的package包/类
protected WebAppContext createWebAppContext() {
    try {
        Resource jettyEnv = Resource.newResource(String.format("%s/WEB-INF/jetty-env.xml", mojo.getAppDir()));
        XmlConfiguration conf = new XmlConfiguration(jettyEnv.getInputStream());
        WebAppContext webapp = (WebAppContext) conf.configure();
        webapp.setWar(mojo.getAppDir());
        System.setProperty("java.naming.factory.url.pkgs", "org.mortbay.naming");
        System.setProperty("java.naming.factory.initial", "org.mortbay.naming.InitialContextFactory");
        return webapp;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:feroult,项目名称:yawp,代码行数:14,代码来源:WebAppContextHelper.java

示例4: go

import org.mortbay.resource.Resource; //导入依赖的package包/类
public void go() {
  QueuedThreadPool pool = new QueuedThreadPool();
  pool.setMinThreads(2); // debug server doesn't need many threads.
  pool.setMaxThreads(10);
  pool.setName("DebugServer(port" + port + ")");
  pool.setDaemon(true);
  server.setThreadPool(pool);
  SocketConnector connector = new SocketConnector();

  connector.setPort(port);
  connector.setHost(host);
  connector.setMaxIdleTime(60000); // 1 min
  server.addConnector(connector);

  context.setContextPath("/");
  context.setBaseResource(Resource.newClassPathResource("/org/cloudera/stethoscope"));
  server.setHandler(context);

  addServlet(new DefaultServlet(), "/");
  addServlet(new DataServlet(), "/json/*");
  addServlet(new TracerServlet(inst), "/tracer/*");
  addServlet(new EvaluateServlet(), "/evaluate");
  addServlet(new PoorMansProfileServlet(), "/poorMansProfiler");
  addServlet(new JMXJsonServlet(), "/jmx");
  
  // addServlet(new LoggerServlet(), "/logging");
  
  try {
    server.start();
  } catch (Exception e) {
    // avoiding logging in this context.
    e.printStackTrace(System.err);
  }
}
 
开发者ID:philz,项目名称:stethoscope,代码行数:35,代码来源:StethoscopeWebServer.java

示例5: getRootResource

import org.mortbay.resource.Resource; //导入依赖的package包/类
private Resource getRootResource(Bundle bundle, WebAppContext wac) throws Exception {
	// decide whether we unpack or not
	// unpack the war somewhere
	File unpackFolder = unpackBundle(bundle, wac);

	return Resource.newResource(unpackFolder.getCanonicalPath());

	//		else {
	//			((OsgiWebAppContext) wac).setBundle(bundle);
	//			// if it's unpacked, use the bundle API directly
	//			return new BundleSpaceJettyResource(bundle, "/");
	//		}
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:14,代码来源:JettyWarDeployer.java

示例6: handleIt

import org.mortbay.resource.Resource; //导入依赖的package包/类
public void handleIt() throws IOException {
  response.setContentType(IMAGE_PNG);
  if (favicon == null) {
    favicon = Resource.newClassPathResource(JS_TEST_DRIVER_PNG);
  }
  favicon.writeTo(response.getOutputStream(), 0, favicon.length());
}
 
开发者ID:BladeRunnerJS,项目名称:brjs-JsTestDriver,代码行数:8,代码来源:FaviconHandler.java

示例7: serve

import org.mortbay.resource.Resource; //导入依赖的package包/类
public void serve(String path, OutputStream out) throws IOException {
  if (!resourceCache.containsKey(baseResourceLocation + path)) {
    Resource resource = newClassPathResource(baseResourceLocation + path);
    if (resource == null) {
      throw new IllegalArgumentException(baseResourceLocation + path + ": resource is null");
    }
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    resource.writeTo(outputStream, 0, resource.length());
    resourceCache.put(baseResourceLocation + path, outputStream.toByteArray());
  }
  out.write(resourceCache.get(baseResourceLocation + path));
}
 
开发者ID:BladeRunnerJS,项目名称:brjs-JsTestDriver,代码行数:13,代码来源:SlaveResourceService.java

示例8: makeHandlers

import org.mortbay.resource.Resource; //导入依赖的package包/类
/**
 * Make the handlers for the HTTP server to test against
 * @return the handlers
 * @throws IOException if the handlers could not be created
 */
protected Handler[] makeHandlers() throws IOException {
    //serve resources from temporary folder
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newResource(
            folder.getRoot().getAbsolutePath()));
    return new Handler[] { resourceHandler, new DefaultHandler() };
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:13,代码来源:TestBase.java

示例9: Jetty6PluginServer

import org.mortbay.resource.Resource; //导入依赖的package包/类
public Jetty6PluginServer() {
    this.server = new Server();
    this.server.setStopAtShutdown(true);
    //make sure Jetty does not use URLConnection caches with the plugin
    Resource.setDefaultUseCaches(false);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:7,代码来源:Jetty6PluginServer.java

示例10: getListHTML

import org.mortbay.resource.Resource; //导入依赖的package包/类
public String getListHTML(Resource resource, String base, boolean parent)
    throws IOException
{
    base=URIUtil.canonicalPath(base);
    if (base==null || !resource.isDirectory())
      return null;
    
    String[] ls = resource.list();
    if (ls==null)
        return null;
    Arrays.sort(ls);
    
    String decodedBase = URIUtil.decodePath(base);
    String title = "Directory: "+deTag(decodedBase);

    StringBuffer buf=new StringBuffer(4096);
    buf.append("<HTML><HEAD><TITLE>");
    buf.append(title);
    buf.append("</TITLE></HEAD><BODY>\n<H1>");
    buf.append(title);
    buf.append("</H1>\n<TABLE BORDER=0>\n");
    
    if (parent)
    {
        buf.append("<TR><TD><A HREF=\"");
        buf.append(URIUtil.addPaths(base,"../"));
        buf.append("\">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n");
    }
    
    String defangedBase = defangURI(base);
    
    DateFormat dfmt=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                                                   DateFormat.MEDIUM);
    for (int i=0 ; i< ls.length ; i++)
    {
        Resource item = resource.addPath(ls[i]);
        
        buf.append("\n<TR><TD><A HREF=\"");
        String path=URIUtil.addPaths(defangedBase,URIUtil.encodePath(ls[i]));
        buf.append(URIUtil.encodePath(ls[i]));
        
        if (item.isDirectory() && !path.endsWith("/"))
            buf.append(URIUtil.SLASH);
        
        // URIUtil.encodePath(buf,path);
        buf.append("\">");
        buf.append(deTag(ls[i]));
        buf.append("&nbsp;");
        buf.append("</TD><TD ALIGN=right>");
        buf.append(item.length());
        buf.append(" bytes&nbsp;</TD><TD>");
        buf.append(dfmt.format(new Date(item.lastModified())));
        buf.append("</TD></TR>");
    }
    buf.append("</TABLE>\n");
    buf.append("</BODY></HTML>\n");
    
    return buf.toString();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:60,代码来源:StaticServlet.java

示例11: createJettyWebContext

import org.mortbay.resource.Resource; //导入依赖的package包/类
/**
 * Creates the Jetty specific web context for the given OSGi bundle.
 * 
 * @param bundle
 * @return
 * @throws Exception
 */
private WebAppContext createJettyWebContext(Bundle bundle, String contextPath) throws Exception {

	WebAppContext wac = new WebAppContext();

	// create a jetty web app context

	// the server is being used to generate the temp folder (so we have to set it)
	wac.setServer(serverService);
	// set the war string since it's used to generate the temp path
	wac.setWar(OsgiStringUtils.nullSafeName(bundle));
	// same goes for the context path (add leading "/" -> w/o the context will not work)
	wac.setContextPath(contextPath);
	// no hot deployment (at least not through directly Jetty)
	wac.setCopyWebDir(false);
	wac.setExtractWAR(true);

	//
	// 1. resource settings
	//

	// start with the slow, IO activity
	Resource rootResource = getRootResource(bundle, wac);

	// wac needs access to the WAR root
	// we have to make sure we don't trigger any direct file lookup
	// so instead of calling .setWar()
	// we set the base resource directly
	wac.setBaseResource(rootResource);
	// reset the war setting (so that the base resource is used)
	wac.setWar(null);

	// 
	// 2. class-loading behaviour
	//

	// obey the servlet spec class-loading contract
	wac.setSystemClasses(systemClasses);
	wac.setServerClasses(serverClasses);

	// no java 2 loading compliance
	wac.setParentLoaderPriority(false);
	// create special classloader
	wac.setClassLoader(Utils.createWebAppClassLoader(bundle, Server.class));

	return wac;
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:54,代码来源:JettyWarDeployer.java

示例12: createServer

import org.mortbay.resource.Resource; //导入依赖的package包/类
/**
 * Starts the server for end-to-end tests.
 */
private Server createServer(int port) throws Exception {
  Server newServer = new Server(port);

  // Attach the test resources in /endtoend as static content for the test
  ResourceHandler resources = new ResourceHandler();
  URL resource = EndToEndTest.class.getResource("/endtoend");
  resources.setBaseResource(Resource.newResource(resource));
  newServer.addHandler(resources);

  Context context = new Context(newServer, "/", Context.SESSIONS);
  context.addEventListener(new GuiceServletContextListener());

  Map<String, String> initParams = Maps.newHashMap();
  String modules = Joiner.on(":")
      .join(SampleModule.class.getName(), DefaultGuiceModule.class.getName(),
          PropertiesModule.class.getName(), OAuthModule.class.getName());

  initParams.put(GuiceServletContextListener.MODULES_ATTRIBUTE, modules);
  context.setInitParams(initParams);

  // Attach the gadget rendering servlet
  ServletHolder gadgetServletHolder = new ServletHolder(new GadgetRenderingServlet());
  context.addServlet(gadgetServletHolder, GADGET_BASE);

  // Attach DataServiceServlet, wrapped in a proxy to fake errors
  ServletHolder restServletHolder = new ServletHolder(new ForceErrorServlet(
      new DataServiceServlet()));
  restServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers");
  context.addServlet(restServletHolder, REST_BASE);
  context.addFilter(AuthenticationServletFilter.class, REST_BASE, 0);

  // Attach JsonRpcServlet, wrapped in a proxy to fake errors
  ServletHolder rpcServletHolder = new ServletHolder(new ForceErrorServlet(
      new JsonRpcServlet()));
  rpcServletHolder.setInitParameter("handlers", "org.apache.shindig.social.handlers");
  context.addServlet(rpcServletHolder, JSON_RPC_BASE);
  context.addFilter(AuthenticationServletFilter.class, JSON_RPC_BASE, 0);

  // Attach the ConcatProxyServlet - needed for rewritten JS
  ServletHolder concatHolder = new ServletHolder(new ConcatProxyServlet());
  context.addServlet(concatHolder, CONCAT_BASE);

  // Attach the JsServlet - needed for rewritten JS
  ServletHolder jsHolder = new ServletHolder(new JsServlet());
  context.addServlet(jsHolder, JS_BASE);

  // Attach MakeRequestServlet
  ServletHolder makeRequestHolder = new ServletHolder(new MakeRequestServlet());
  context.addServlet(makeRequestHolder, MAKE_REQUEST_BASE);
  
  // Attach an EchoServlet, used to test proxied rendering
  ServletHolder echoHolder = new ServletHolder(new EchoServlet());
  context.addServlet(echoHolder, "/echo");
  
  return newServer;
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:60,代码来源:EndToEndServer.java


注:本文中的org.mortbay.resource.Resource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。