Package org.apache.uima.resource

Examples of org.apache.uima.resource.FileResourceSpecifier


    // aSpecifier must be a FileResourceSpecifier
    if (!(aSpecifier instanceof FileResourceSpecifier))
      return false;

    // If we get here, aSpecifier is supported by this implementation.
    FileResourceSpecifier spec = (FileResourceSpecifier) aSpecifier;

    // Get Relative Path Resolver
    RelativePathResolver relPathResolver = null;
    if (aAdditionalParams != null) {
      relPathResolver = (RelativePathResolver) aAdditionalParams.get(PARAM_RELATIVE_PATH_RESOLVER);
    }
    if (relPathResolver == null) {
      relPathResolver = new RelativePathResolver_impl();
    }
     
    // Get the file URL, resolving relative path as necessary
    IOException ioEx = null;
    try {
      // Get the file URL from the specifier.  If the user has passed a file path
      // (e.g. c:\Program Files\...) instead of a URL, be lenient and convert it to
      // a URL
      URL relativeUrl;
      try {
        relativeUrl = new URL(spec.getFileUrl());
      }
      catch (MalformedURLException e) {
        //try to treat the URL as a file name. 
        File file = new File(spec.getFileUrl());
        if (file.isAbsolute()) {
          //for absolute paths, use File.toURL(), which handles
          //windows absolute paths correctly
          relativeUrl = file.toURL();
        } else {
          //for relative paths, we can' use File.toURL() because it always
          //produces an absolute URL.  Instead we do the following, which
          //won't work for windows absolute paths (but that's OK, since we
          //know we're working with a relative path)
          relativeUrl = new URL("file", "", spec.getFileUrl());
        }
      }
     
      //resolve relative paths
      mFileUrl = relPathResolver.resolveRelativePath(relativeUrl);

      // Store local cache info, even though it is not used
      if (spec.getLocalCache() == null) {
        mLocalCache = null;
      } else {
        mLocalCache = new File(spec.getLocalCache());
      }

    } catch (IOException e) {
      ioEx = e;
    }
    if (mFileUrl == null) {
      throw new ResourceInitializationException(
              ResourceInitializationException.COULD_NOT_ACCESS_DATA, new Object[] { spec
                      .getFileUrl() }, ioEx);
    }

    return true;
  }
View Full Code Here


          throw new ResourceInitializationException(e);
        }
        URL absUrl = getRelativePathResolver().resolveRelativePath(relativeUrl);
        if (absUrl != null) {
          // found - create a DataResource object and store it in the mResourceMap
          FileResourceSpecifier spec = new FileResourceSpecifier_impl();
          spec.setFileUrl(absUrl.toString());
          resource = UIMAFramework.produceResource(spec, null);
          mResourceMap.put(qname, resource);
        }
      }
      if (resource == null) // still no resource found - throw exception if required
View Full Code Here

    if (rs instanceof FileLanguageResourceSpecifier) {
      FileLanguageResourceSpecifier flrs = (FileLanguageResourceSpecifier) rs;
      text.append("  URL_Prefix: ").append(flrs.getFileUrlPrefix()).append("  URL_Suffix: ")
              .append(flrs.getFileUrlSuffix());
    } else if (rs instanceof FileResourceSpecifier) {
      FileResourceSpecifier frs = (FileResourceSpecifier) rs;
      text.append("  URL: ").append(frs.getFileUrl());
    } else {
      text.append("  Custom Resource Specifier");
    }
    String implName = xrd.getImplementationName();
    if (null != implName && !implName.equals("")) {
View Full Code Here

            .setImplementationName(setValueChanged(dialog.xrImplementation, xrd
                    .getImplementationName()));

    ResourceSpecifier rs = xrd.getResourceSpecifier();
    if (null == dialog.xrUrlSuffix || "".equals(dialog.xrUrlSuffix)) {
      FileResourceSpecifier frs;
      if (null != rs && rs instanceof FileResourceSpecifier) {
        frs = (FileResourceSpecifier) rs;
      } else {
        frs = new FileResourceSpecifier_impl();
      }
      frs.setFileUrl(setValueChanged(dialog.xrUrl, frs.getFileUrl()));
      xrd.setResourceSpecifier(frs);
    } else {
      FileLanguageResourceSpecifier flrs;
      if (null != rs && rs instanceof FileLanguageResourceSpecifier) {
        flrs = (FileLanguageResourceSpecifier) rs;
View Full Code Here

   */
  public static ExternalResourceDescription createExternalResourceDescription(final String aName,
          String aUrl) {
    ExternalResourceDescription extRes = new ExternalResourceDescription_impl();
    extRes.setName(aName);
    FileResourceSpecifier frs = new FileResourceSpecifier_impl();
    frs.setFileUrl(aUrl);
    extRes.setResourceSpecifier(frs);
    return extRes;
  }
View Full Code Here

    // aSpecifier must be a FileResourceSpecifier
    if (!(aSpecifier instanceof FileResourceSpecifier))
      return false;

    // If we get here, aSpecifier is supported by this implementation.
    FileResourceSpecifier spec = (FileResourceSpecifier) aSpecifier;

    // Get Relative Path Resolver
    RelativePathResolver relPathResolver = null;
    if (aAdditionalParams != null) {
      relPathResolver = (RelativePathResolver) aAdditionalParams.get(PARAM_RELATIVE_PATH_RESOLVER);
    }
    if (relPathResolver == null) {
      relPathResolver = new RelativePathResolver_impl();
    }
     
    // Get the file URL, resolving relative path as necessary
    IOException ioEx = null;
    try {
      // Get the file URL from the specifier.  If the user has passed a file path
      // (e.g. c:\Program Files\...) instead of a URL, be lenient and convert it to
      // a URL
      URL relativeUrl;
      try {
        relativeUrl = new URL(spec.getFileUrl());
      }
      catch (MalformedURLException e) {
        //try to treat the URL as a file name. 
        File file = new File(spec.getFileUrl());
        if (file.isAbsolute()) {
          //for absolute paths, use File.toURL(), which handles
          //windows absolute paths correctly
          relativeUrl = file.toURL();
        } else {
          //for relative paths, we can' use File.toURL() because it always
          //produces an absolute URL.  Instead we do the following, which
          //won't work for windows absolute paths (but that's OK, since we
          //know we're working with a relative path)
          relativeUrl = new URL("file", "", spec.getFileUrl());
        }
      }
     
      //resolve relative paths
      mFileUrl = relPathResolver.resolveRelativePath(relativeUrl);

      // Store local cache info, even though it is not used
      if (spec.getLocalCache() == null) {
        mLocalCache = null;
      } else {
        mLocalCache = new File(spec.getLocalCache());
      }

    } catch (IOException e) {
      ioEx = e;
    }
    if (mFileUrl == null) {
      throw new ResourceInitializationException(
              ResourceInitializationException.COULD_NOT_ACCESS_DATA, new Object[] { spec
                      .getFileUrl() }, ioEx);
    }

    return true;
  }
View Full Code Here

    // aSpecifier must be a FileResourceSpecifier
    if (!(aSpecifier instanceof FileResourceSpecifier))
      return false;

    // If we get here, aSpecifier is supported by this implementation.
    FileResourceSpecifier spec = (FileResourceSpecifier) aSpecifier;

    // Get Relative Path Resolver
    RelativePathResolver relPathResolver = null;
    if (aAdditionalParams != null) {
      relPathResolver = (RelativePathResolver) aAdditionalParams.get(PARAM_RELATIVE_PATH_RESOLVER);
    }
    if (relPathResolver == null) {
      relPathResolver = new RelativePathResolver_impl();
    }
     
    // Get the file URL, resolving relative path as necessary
    IOException ioEx = null;
    try {
      // Get the file URL from the specifier.  If the user has passed a file path
      // (e.g. c:\Program Files\...) instead of a URL, be lenient and convert it to
      // a URL
      URL relativeUrl;
      try {
        relativeUrl = new URL(spec.getFileUrl());
      }
      catch (MalformedURLException e) {
        //try to treat the URL as a file name. 
        File file = new File(spec.getFileUrl());
        if (file.isAbsolute()) {
          //for absolute paths, use File.toURL(), which handles
          //windows absolute paths correctly
          relativeUrl = file.toURL();
        } else {
          //for relative paths, we can' use File.toURL() because it always
          //produces an absolute URL.  Instead we do the following, which
          //won't work for windows absolute paths (but that's OK, since we
          //know we're working with a relative path)
          relativeUrl = new URL("file", "", spec.getFileUrl());
        }
      }
     
      //resolve relative paths
      mFileUrl = relPathResolver.resolveRelativePath(relativeUrl);

      // Store local cache info, even though it is not used
      if (spec.getLocalCache() == null) {
        mLocalCache = null;
      } else {
        mLocalCache = new File(spec.getLocalCache());
      }

    } catch (IOException e) {
      ioEx = e;
    }
    if (mFileUrl == null) {
      throw new ResourceInitializationException(
              ResourceInitializationException.COULD_NOT_ACCESS_DATA, new Object[] { spec
                      .getFileUrl() }, ioEx);
    }

    return true;
  }
View Full Code Here

    while (resource == null && lang != null) {
      // build URL
      String urlString = mFileUrlPrefix + lang + mFileUrlSuffix;
      // build FileResource specifier and attempt to create DataResource
      FileResourceSpecifier fileSpec = UIMAFramework.getResourceSpecifierFactory()
              .createFileResourceSpecifier();
      fileSpec.setFileUrl(urlString);

      try {
        resource = (DataResource) UIMAFramework.produceResource(DataResource.class, fileSpec,
                mResourceInitParams);
      } catch (ResourceInitializationException e) {
View Full Code Here

          throw new ResourceInitializationException(e);
        }
        URL absUrl = getRelativePathResolver().resolveRelativePath(relativeUrl);
        if (absUrl != null) {
          // found - create a DataResource object and store it in the mResourceMap
          FileResourceSpecifier spec = new FileResourceSpecifier_impl();
          spec.setFileUrl(absUrl.toString());
          resource = UIMAFramework.produceResource(spec, null);
          mResourceMap.put(qname, resource);
        }
      }
      if (resource == null) // still no resource found - throw exception if required
View Full Code Here

          throw new ResourceInitializationException(e);
        }
        URL absUrl = getRelativePathResolver().resolveRelativePath(relativeUrl);
        if (absUrl != null) {
          // found - create a DataResource object and store it in the mResourceMap
          FileResourceSpecifier spec = new FileResourceSpecifier_impl();
          spec.setFileUrl(absUrl.toString());
          resource = UIMAFramework.produceResource(spec, null);
          mResourceMap.put(qname, resource);
        }
      }
      if (resource == null) // still no resource found - throw exception if required
View Full Code Here

TOP

Related Classes of org.apache.uima.resource.FileResourceSpecifier

Copyright © 2018 www.massapicom. 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.