001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.webengine.jaxrs.servlet.config; 013 014import java.net.URL; 015 016import org.nuxeo.common.xmap.annotation.XNode; 017import org.nuxeo.common.xmap.annotation.XObject; 018import org.osgi.framework.Bundle; 019 020/** 021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 022 */ 023@XObject("resources") 024public class ResourcesDescriptor { 025 026 @XNode("@servlet") 027 protected String servlet; 028 029 @XNode("@path") 030 protected String path; 031 032 private Bundle bundle; 033 034 private String id; 035 036 private ResourceResolver resolver; 037 038 void setBundle(Bundle bundle) { 039 this.bundle = bundle; 040 if (path.startsWith("file:")) { 041 resolver = new FileResourceResolver(path.substring("file:".length())); 042 } else { 043 resolver = new BundleResourceResolver(bundle, path); 044 } 045 id = bundle.getSymbolicName() + ":" + servlet + ":" + path; 046 } 047 048 public void setResolver(ResourceResolver resolver) { 049 this.resolver = resolver; 050 } 051 052 public Bundle getBundle() { 053 return bundle; 054 } 055 056 public String getPath() { 057 return path; 058 } 059 060 public String getServlet() { 061 return servlet; 062 } 063 064 public String getId() { 065 return id; 066 } 067 068 public URL getResource(String name) { 069 return resolver.getResource(name); 070 } 071 072 @Override 073 public boolean equals(Object obj) { 074 if (obj == this) { 075 return true; 076 } 077 if (obj instanceof ResourcesDescriptor) { 078 return id.equals(((ResourcesDescriptor) obj).id); 079 } 080 return false; 081 } 082 083 @Override 084 public String toString() { 085 return id; 086 } 087}