Ejemplo n.º 1
0
    /**
     * @param href
     * @param base
     * @return
     * @throws TransformerException
     */
    public Source resolve(String href, String base) throws TransformerException {
      Resolver resolver = ResolverWrapper.getInstance();
      CatalogResolver catResolver = resolver.getCatalogResolver();
      if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
        Log.debug(Log.XML_RESOLVER, "Trying to resolve " + href + ":" + base);
      }
      String decodedBase;
      try {
        decodedBase = URLDecoder.decode(base, Jeeves.ENCODING);
      } catch (UnsupportedEncodingException e1) {
        decodedBase = base;
      }
      String decodedHref;
      try {
        decodedHref = URLDecoder.decode(href, Jeeves.ENCODING);
      } catch (UnsupportedEncodingException e1) {
        decodedHref = href;
      }
      Source s = catResolver.resolve(decodedHref, decodedBase);
      // If resolver has a blank XSL file to replace non existing resolved file ...
      String blankXSLFile = resolver.getBlankXSLFile();
      if (blankXSLFile != null && s.getSystemId().endsWith(".xsl")) {
        // The resolved resource does not exist, set it to blank file path to not trigger
        // FileNotFound Exception
        try {
          if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
            Log.debug(Log.XML_RESOLVER, "  Check if exist " + s.getSystemId());
          }
          File f;
          if (SystemUtils.IS_OS_WINDOWS) {
            String path = s.getSystemId();
            // fxp
            path = path.replaceAll("file:\\/", "");
            // heikki
            path = path.replaceAll("file:", "");

            f = new File(path);
          } else {
            f = new File(new URI(s.getSystemId()));
          }
          if (!(f.exists())) {
            if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
              Log.debug(
                  Log.XML_RESOLVER,
                  "  Resolved resource "
                      + s.getSystemId()
                      + " does not exist. blankXSLFile returned instead.");
            }
            s.setSystemId(blankXSLFile);
          }
        } catch (URISyntaxException e) {
          e.printStackTrace();
        }
      }

      if (Log.isDebugEnabled(Log.XML_RESOLVER) && s != null) {
        Log.debug(Log.XML_RESOLVER, "Resolved as " + s.getSystemId());
      }
      return s;
    }