Ejemplo n.º 1
0
  public void store(final DictionaryFile<? extends DictionaryItem> dictFile, final File file) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    getDictionaryFile(dictFile.getId())
        .ifPresent(
            currentFile -> {
              if (currentFile.getTimestamp().getTime() > dictFile.getTimestamp().getTime()) {
                throw new DictionaryException(dictFile.getPath() + " was updated.");
              }

              // TODO use stream
              try (CurlResponse response =
                  Curl.post(fessConfig.getElasticsearchUrl() + "/_configsync/file")
                      .param("path", dictFile.getPath())
                      .body(FileUtil.readUTF8(file))
                      .execute()) {
                final Map<String, Object> contentMap = response.getContentAsMap();
                if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
                  throw new DictionaryException("Failed to update " + dictFile.getPath());
                }
              } catch (final IOException e) {
                throw new DictionaryException("Failed to update " + dictFile.getPath(), e);
              }
            })
        .orElse(
            () -> {
              throw new DictionaryException(dictFile.getPath() + " does not exist.");
            });
  }
Ejemplo n.º 2
0
  private static void generateContents(final File dir, final int count) throws Exception {
    if (count <= 0) {
      return;
    }

    final String content = getHtmlContent(count);

    final File indexFile = new File(dir, "index.html");
    indexFile.deleteOnExit();
    FileUtil.writeBytes(indexFile.getAbsolutePath(), content.getBytes("UTF-8"));

    for (int i = 1; i <= 10; i++) {
      final File file = new File(dir, "file" + count + "-" + i + ".html");
      file.deleteOnExit();
      FileUtil.writeBytes(file.getAbsolutePath(), content.getBytes("UTF-8"));
      final File childDir = new File(dir, "dir" + count + "-" + i);
      childDir.mkdirs();
      generateContents(childDir, count - 1);
    }
  }
Ejemplo n.º 3
0
  protected static File createDocRoot(final int count) {
    try {
      final File tempDir = File.createTempFile("robotDocRoot", "");
      tempDir.delete();
      tempDir.mkdirs();

      final StringBuilder buf = new StringBuilder();
      buf.append("User-agent: *").append('\n');
      buf.append("Disallow: /admin/").append('\n');
      buf.append("Disallow: /websvn/").append('\n');
      final File robotTxtFile = new File(tempDir, "robots.txt");
      FileUtil.writeBytes(robotTxtFile.getAbsolutePath(), buf.toString().getBytes("UTF-8"));
      robotTxtFile.deleteOnExit();

      generateContents(tempDir, count);

      return tempDir;
    } catch (final Exception e) {
      throw new RobotSystemException(e);
    }
  }