private String sourceURL(String url) {
    File baseDirectory = dataDir().getResourceLoader().getBaseDirectory();

    File file = Files.url(baseDirectory, url);
    if (file != null) {
      return Paths.convert(baseDirectory, file);
    }
    return url;
  }
 /**
  * Gets an SLD resource for the given style.
  *
  * @param style
  * @return
  */
 private Resource getStyleResource(StyleInfo style) {
   String[] prefix = new String[0];
   if (style.getWorkspace() != null) {
     prefix = new String[] {"workspaces", style.getWorkspace().getName()};
   }
   String fileName = style.getFilename();
   String[] pathParts = (String[]) ArrayUtils.addAll(prefix, new String[] {"styles", fileName});
   String path = Paths.path(pathParts);
   return loader.get(path);
 }
  private String source(URL url) {
    File baseDirectory = dataDir().getResourceLoader().getBaseDirectory();

    if (url.getProtocol().equals("file")) {
      File file = Files.url(baseDirectory, url.toExternalForm());
      if (file != null && !file.isAbsolute()) {
        return Paths.convert(baseDirectory, file);
      }
    }
    return url.toExternalForm();
  }
  private String sourceFile(String file) {
    File baseDirectory = dataDir().getResourceLoader().getBaseDirectory();

    File f = new File(file);
    return f.isAbsolute() ? file : Paths.convert(baseDirectory, f);
  }
 private String source(File file) {
   File baseDirectory = dataDir().getResourceLoader().getBaseDirectory();
   return file.isAbsolute() ? file.toString() : Paths.convert(baseDirectory, file);
 }
Exemple #6
0
  public static void initLogging(
      GeoServerResourceLoader resourceLoader,
      String configFileName,
      boolean suppressStdOutLogging,
      String logFileName)
      throws Exception {
    // to initialize logging we need to do a couple of things:
    // 1)  Figure out whether the user has 'overridden' some configuration settings
    // in the logging system (not using log4j in commons-logging.properties or perhaps
    // has set up their own 'custom' log4j.properties file.
    // 2)  If they *have*, then we don't worry about configuring logging
    // 3)  If they haven't, then we configure logging to use the log4j config file
    // specified, and remove console appenders if the suppressstdoutlogging is true.
    LoggingInitializer.LOGGER.fine("CONFIGURING GEOSERVER LOGGING -------------------------");

    if (configFileName == null) {
      configFileName = "DEFAULT_LOGGING.properties";
      LoggingInitializer.LOGGER.warning(
          "No log4jConfigFile defined in services.xml:  using 'DEFAULT_LOGGING.properties'");
    }
    Resource resource = resourceLoader.get(Paths.path("logs", configFileName));
    if (resource == null || resource.getType() == Type.UNDEFINED) {
      // hmm, well, we don't have a log4j config file and this could be due to the fact
      // that this is a data-dir upgrade.  We can count on the DEFAULT_LOGGING.properties file
      // being present on the classpath, so we'll upgrade their data_dir and then use the
      // default DEFAULT_LOGGING.properties configuration.
      LoggingInitializer.LOGGER.warning(
          "log4jConfigFile '"
              + configFileName
              + "' couldn't be found in the data dir, so GeoServer will "
              + "install the various logging config file into the data dir, and then try to find it again.");

      Resource logs = resourceLoader.get("logs");
      File lcdir = logs.dir();

      // now we copy in the various logging config files from the base repo location on the
      // classpath
      final String[] lcfiles =
          new String[] {
            "DEFAULT_LOGGING.properties",
            "GEOSERVER_DEVELOPER_LOGGING.properties",
            "GEOTOOLS_DEVELOPER_LOGGING.properties",
            "PRODUCTION_LOGGING.properties",
            "QUIET_LOGGING.properties",
            "TEST_LOGGING.properties",
            "VERBOSE_LOGGING.properties"
          };

      for (int i = 0; i < lcfiles.length; i++) {
        File target = new File(lcdir.getAbsolutePath(), lcfiles[i]);
        if (!target.exists()) {
          resourceLoader.copyFromClassPath(lcfiles[i], target);
        }
      }

      // ok, the possibly-new 'logs' directory is in-place, with all the various configs there.
      // Is the originally configured log4jconfigfile there now?
      if (resource.getType() != Type.RESOURCE) {
        LoggingInitializer.LOGGER.warning(
            "Still couldn't find log4jConfigFile '"
                + configFileName
                + "'.  Using DEFAULT_LOGGING.properties instead.");
      }

      resource = resourceLoader.get(Paths.path("logs", "DEFAULT_LOGGING.properties"));
    }

    if (resource == null || resource.getType() != Type.RESOURCE) {
      throw new ConfigurationException(
          "Unable to load logging configuration '"
              + configFileName
              + "'.  In addition, an attempt "
              + "was made to create the 'logs' directory in your data dir, and to use the DEFAULT_LOGGING configuration, but"
              + "this failed as well.  Is your data dir writeable?");
    }

    // reconfiguring log4j logger levels by resetting and loading a new set of configuration
    // properties
    InputStream loggingConfigStream = resource.in();
    if (loggingConfigStream == null) {
      LoggingInitializer.LOGGER.warning("Couldn't open Log4J configuration file '" + resource);
      return;
    } else {
      LoggingInitializer.LOGGER.fine(
          "GeoServer logging profile '" + resource.name() + "' enabled.");
    }

    configureGeoServerLogging(
        resourceLoader, loggingConfigStream, suppressStdOutLogging, false, logFileName);
  }