Exemple #1
0
  /**
   * Find a classpath resource. The {@link java.lang.Class#getResource(String)} method is used to
   * lookup the resource. If it is not found, then the {@link Loader#getResource(Class, String)}
   * method is used. If it is still not found, then {@link ClassLoader#getSystemResource(String)} is
   * used. Unlike {@link ClassLoader#getSystemResource(String)} this method does not check for
   * normal resources.
   *
   * @param name The relative name of the resource
   * @param useCaches True if URL caches are to be used.
   * @param checkParents True if forced searching of parent Classloaders is performed to work around
   *     loaders with inverted priorities
   * @return Resource or null
   */
  public static Resource newClassPathResource(
      String name, boolean useCaches, boolean checkParents) {
    URL url = Resource.class.getResource(name);

    if (url == null) url = Loader.getResource(Resource.class, name);
    if (url == null) return null;
    return newResource(url, useCaches);
  }
 /**
  * Parse the given classes
  *
  * @param classNames
  * @param resolver
  * @throws Exception
  */
 public void parse(List<String> classNames, ClassNameResolver resolver) throws Exception {
   for (String s : classNames) {
     if ((resolver == null)
         || (!resolver.isExcluded(s) && (!isParsed(s) || resolver.shouldOverride(s)))) {
       s = s.replace('.', '/') + ".class";
       URL resource = Loader.getResource(this.getClass(), s, false);
       if (resource != null) {
         Resource r = Resource.newResource(resource);
         scanClass(r.getInputStream());
       }
     }
   }
 }
  /**
   * Parse a given class
   *
   * @param className
   * @param resolver
   * @throws Exception
   */
  public void parse(String className, ClassNameResolver resolver) throws Exception {
    if (className == null) return;

    if (!resolver.isExcluded(className)) {
      if (!isParsed(className) || resolver.shouldOverride(className)) {
        className = className.replace('.', '/') + ".class";
        URL resource = Loader.getResource(this.getClass(), className, false);
        if (resource != null) {
          Resource r = Resource.newResource(resource);
          scanClass(r.getInputStream());
        }
      }
    }
  }
 /**
  * Parse the given class, optionally walking its inheritance hierarchy
  *
  * @param clazz
  * @param resolver
  * @param visitSuperClasses
  * @throws Exception
  */
 public void parse(Class<?> clazz, ClassNameResolver resolver, boolean visitSuperClasses)
     throws Exception {
   Class<?> cz = clazz;
   while (cz != null) {
     if (!resolver.isExcluded(cz.getName())) {
       if (!isParsed(cz.getName()) || resolver.shouldOverride(cz.getName())) {
         String nameAsResource = cz.getName().replace('.', '/') + ".class";
         URL resource = Loader.getResource(this.getClass(), nameAsResource, false);
         if (resource != null) {
           Resource r = Resource.newResource(resource);
           scanClass(r.getInputStream());
         }
       }
     }
     if (visitSuperClasses) cz = cz.getSuperclass();
     else cz = null;
   }
 }
Exemple #5
0
  public XmlParser newParser() throws ClassNotFoundException {
    XmlParser xmlParser = new XmlParser();
    // set up cache of DTDs and schemas locally
    URL dtd22 = Loader.getResource(Servlet.class, "javax/servlet/resources/web-app_2_2.dtd", true);
    URL dtd23 = Loader.getResource(Servlet.class, "javax/servlet/resources/web-app_2_3.dtd", true);
    URL j2ee14xsd = Loader.getResource(Servlet.class, "javax/servlet/resources/j2ee_1_4.xsd", true);
    URL webapp24xsd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/web-app_2_4.xsd", true);
    URL webapp25xsd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/web-app_2_5.xsd", true);
    URL webapp30xsd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/web-app_3_0.xsd", true);
    URL webcommon30xsd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/web-common_3_0.xsd", true);
    URL webfragment30xsd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/web-fragment_3_0.xsd", true);
    URL schemadtd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/XMLSchema.dtd", true);
    URL xmlxsd = Loader.getResource(Servlet.class, "javax/servlet/resources/xml.xsd", true);
    URL webservice11xsd =
        Loader.getResource(
            Servlet.class, "javax/servlet/resources/j2ee_web_services_client_1_1.xsd", true);
    URL webservice12xsd =
        Loader.getResource(
            Servlet.class, "javax/servlet/resources/javaee_web_services_client_1_2.xsd", true);
    URL datatypesdtd =
        Loader.getResource(Servlet.class, "javax/servlet/resources/datatypes.dtd", true);

    URL jsp20xsd = null;
    URL jsp21xsd = null;

    try {
      Class<?> jsp_page = Loader.loadClass(WebXmlConfiguration.class, "javax.servlet.jsp.JspPage");
      jsp20xsd = jsp_page.getResource("/javax/servlet/resources/jsp_2_0.xsd");
      jsp21xsd = jsp_page.getResource("/javax/servlet/resources/jsp_2_1.xsd");
    } catch (Exception e) {
      LOG.ignore(e);
    } finally {
      if (jsp20xsd == null)
        jsp20xsd = Loader.getResource(Servlet.class, "javax/servlet/resources/jsp_2_0.xsd", true);
      if (jsp21xsd == null)
        jsp21xsd = Loader.getResource(Servlet.class, "javax/servlet/resources/jsp_2_1.xsd", true);
    }

    redirect(xmlParser, "web-app_2_2.dtd", dtd22);
    redirect(xmlParser, "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", dtd22);
    redirect(xmlParser, "web.dtd", dtd23);
    redirect(xmlParser, "web-app_2_3.dtd", dtd23);
    redirect(xmlParser, "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", dtd23);
    redirect(xmlParser, "XMLSchema.dtd", schemadtd);
    redirect(xmlParser, "http://www.w3.org/2001/XMLSchema.dtd", schemadtd);
    redirect(xmlParser, "-//W3C//DTD XMLSCHEMA 200102//EN", schemadtd);
    redirect(xmlParser, "jsp_2_0.xsd", jsp20xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/j2ee/jsp_2_0.xsd", jsp20xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/javaee/jsp_2_1.xsd", jsp21xsd);
    redirect(xmlParser, "j2ee_1_4.xsd", j2ee14xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd", j2ee14xsd);
    redirect(xmlParser, "web-app_2_4.xsd", webapp24xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", webapp24xsd);
    redirect(xmlParser, "web-app_2_5.xsd", webapp25xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd", webapp25xsd);
    redirect(xmlParser, "web-app_3_0.xsd", webapp30xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd", webapp30xsd);
    redirect(xmlParser, "web-common_3_0.xsd", webcommon30xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/javaee/web-common_3_0.xsd", webcommon30xsd);
    redirect(xmlParser, "web-fragment_3_0.xsd", webfragment30xsd);
    redirect(xmlParser, "http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd", webfragment30xsd);
    redirect(xmlParser, "xml.xsd", xmlxsd);
    redirect(xmlParser, "http://www.w3.org/2001/xml.xsd", xmlxsd);
    redirect(xmlParser, "datatypes.dtd", datatypesdtd);
    redirect(xmlParser, "http://www.w3.org/2001/datatypes.dtd", datatypesdtd);
    redirect(xmlParser, "j2ee_web_services_client_1_1.xsd", webservice11xsd);
    redirect(
        xmlParser,
        "http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd",
        webservice11xsd);
    redirect(xmlParser, "javaee_web_services_client_1_2.xsd", webservice12xsd);
    redirect(
        xmlParser,
        "http://www.ibm.com/webservices/xsd/javaee_web_services_client_1_2.xsd",
        webservice12xsd);
    return xmlParser;
  }