コード例 #1
0
  /** Visit all files to keep only XML files. */
  @Override
  protected void visit() {
    final ParameterValue<URL> paramUrl =
        (ParameterValue<URL>)
            getSourceConfiguration(getSource()).parameter(URL.getName().getCode());

    if (paramUrl == null || paramUrl.getValue() == null) {
      getLogger().log(Level.WARNING, "Provided File path is not defined.");
      return;
    }

    final URL urlPath = paramUrl.getValue();

    try {
      path = new File(urlPath.toURI());
    } catch (URISyntaxException e) {
      getLogger().log(Level.INFO, "Fails to convert path url to file.");
      path = new File(urlPath.getPath());
    }

    List<File> candidates = new ArrayList<>();

    if (path.isDirectory()) {
      candidates.addAll(
          FileUtilities.scanDirectory(
              path,
              new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                  final String fullName = pathname.getName();
                  final int idx = fullName.lastIndexOf('.');
                  final String extension = fullName.substring(idx + 1);
                  return extension.equalsIgnoreCase("xml");
                }
              }));
    } else {
      candidates.add(path);
    }

    index = new HashMap<>();
    for (final File candidate : candidates) {
      try {
        final MapContext mapContext =
            MapContextIO.readMapContextFile(candidate, "", "", styleBusiness);
        if (mapContext != null) {
          final GenericName name = NamesExt.create(mapContext.getName());
          index.put(name, candidate);
        }
      } catch (JAXBException e) {
        getLogger()
            .log(
                Level.WARNING,
                "Candidate MapContext file can't be read : " + candidate.getAbsolutePath(),
                e);
      }
    }

    super.visit();
  }
コード例 #2
0
  /**
   * @param key layer name
   * @param login used if one or more layer of MapContext come from secured map service
   * @param password used if one or more layer of MapContext come from secured map service
   * @return MapContext or null if layer name doesn't exist.
   * @throws JAXBException
   */
  public MapContext getMapContext(final GenericName key, final String login, final String password)
      throws JAXBException {
    if (index == null) {
      visit();
    }

    final File mapContextFile = index.get(key);
    return MapContextIO.readMapContextFile(mapContextFile, login, password, styleBusiness);
  }