示例#1
0
  public Element exec(Element params, ServiceContext context) throws Exception {

    Path harvestingLogoDirectory = Resources.locateHarvesterLogosDir(context);
    Path nodeLogoDirectory = Resources.locateLogosDir(context);

    String file = Util.getParam(params, Params.FNAME);
    String asFavicon = Util.getParam(params, Params.FAVICON, "0");

    if (file.contains("..")) {
      throw new BadParameterEx("Invalid character found in resource name.", file);
    }

    if ("".equals(file)) {
      throw new Exception("Logo name is not defined.");
    }

    SettingManager settingMan = context.getBean(SettingManager.class);
    String nodeUuid = settingMan.getSiteId();

    try {
      Path logoFilePath = harvestingLogoDirectory.resolve(file);
      if (!Files.exists(logoFilePath)) {
        logoFilePath = context.getAppPath().resolve("images/harvesting/" + file);
      }
      try (InputStream inputStream = Files.newInputStream(logoFilePath)) {
        BufferedImage source = ImageIO.read(inputStream);

        if ("1".equals(asFavicon)) {
          createFavicon(source, nodeLogoDirectory.resolve("favicon.png"));
        } else {
          Path logo = nodeLogoDirectory.resolve(nodeUuid + ".png");
          Path defaultLogo = nodeLogoDirectory.resolve("logo.png");

          if (!file.endsWith(".png")) {
            try (OutputStream logoOut = Files.newOutputStream(logo);
                OutputStream defLogoOut = Files.newOutputStream(defaultLogo); ) {
              ImageIO.write(source, "png", logoOut);
              ImageIO.write(source, "png", defLogoOut);
            }
          } else {
            Files.deleteIfExists(logo);
            IO.copyDirectoryOrFile(logoFilePath, logo, false);
            Files.deleteIfExists(defaultLogo);
            IO.copyDirectoryOrFile(logoFilePath, defaultLogo, false);
          }
        }
      }
    } catch (Exception e) {
      throw new Exception(
          "Unable to move uploaded thumbnail to destination directory. Error: " + e.getMessage());
    }

    Element response = new Element("response");
    response.addContent(new Element("status").setText("Logo set."));
    return response;
  }
示例#2
0
  private void updateSources(Dbms dbms, Set<RecordInfo> records, Map<String, String> remoteSources)
      throws SQLException, MalformedURLException {
    log.info("Aligning source logos from for : " + params.name);

    // --- collect all different sources that have been harvested

    Set<String> sources = new HashSet<String>();

    for (RecordInfo ri : records) sources.add(ri.source);

    // --- update local sources and retrieve logos (if the case)

    String siteId = getSiteId();

    for (String sourceUuid : sources)
      if (!siteId.equals(sourceUuid)) {
        String sourceName = remoteSources.get(sourceUuid);

        if (sourceName != null) Lib.sources.retrieveLogo(context, params.host, sourceUuid);
        else {
          sourceName = "(unknown)";
          Resources.copyUnknownLogo(context, sourceUuid);
        }

        Lib.sources.update(dbms, sourceUuid, sourceName, false);
      }
  }