use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class AdminBadwordAction method upload.
@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
validate(form, messages -> {
}, this::asUploadHtml);
verifyToken(this::asUploadHtml);
CommonPoolUtil.execute(() -> {
try (Reader reader = new BufferedReader(new InputStreamReader(form.badWordFile.getInputStream(), getCsvEncoding()))) {
badWordService.importCsv(reader);
suggestHelper.storeAllBadWords(false);
} catch (final Exception e) {
throw new FessSystemException("Failed to import data.", e);
}
});
saveInfo(messages -> messages.addSuccessUploadBadWord(GLOBAL));
return redirect(getClass());
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ApiAdminBadwordAction method post$upload.
// POST /api/admin/badword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
validateApi(body, messages -> {
});
CommonPoolUtil.execute(() -> {
try (Reader reader = new BufferedReader(new InputStreamReader(body.badWordFile.getInputStream(), getCsvEncoding()))) {
badWordService.importCsv(reader);
suggestHelper.storeAllBadWords(false);
} catch (final Exception e) {
throw new FessSystemException("Failed to import data.", e);
}
});
return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ThumbnailManager method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
final String thumbnailPath = System.getProperty(Constants.FESS_THUMBNAIL_PATH);
if (thumbnailPath != null) {
baseDir = new File(thumbnailPath);
} else {
final String varPath = System.getProperty(Constants.FESS_VAR_PATH);
if (varPath != null) {
baseDir = new File(varPath, THUMBNAILS_DIR_NAME);
} else {
baseDir = ResourceUtil.getThumbnailPath().toFile();
}
}
if (baseDir.mkdirs()) {
logger.info("Created: {}", baseDir.getAbsolutePath());
}
if (!baseDir.isDirectory()) {
throw new FessSystemException("Not found: " + baseDir.getAbsolutePath());
}
if (logger.isDebugEnabled()) {
logger.debug("Thumbnail Directory: {}", baseDir.getAbsolutePath());
}
thumbnailTaskQueue = new LinkedBlockingQueue<>(thumbnailTaskQueueSize);
generating = !Constants.TRUE.equalsIgnoreCase(System.getProperty("fess.thumbnail.process"));
thumbnailQueueThread = new Thread((Runnable) () -> {
final List<Tuple3<String, String, String>> taskList = new ArrayList<>();
while (generating) {
try {
final Tuple3<String, String, String> task = thumbnailTaskQueue.poll(thumbnailTaskQueueTimeout, TimeUnit.MILLISECONDS);
if (task == null) {
if (!taskList.isEmpty()) {
storeQueue(taskList);
}
} else if (!taskList.contains(task)) {
taskList.add(task);
if (taskList.size() > thumbnailTaskBulkSize) {
storeQueue(taskList);
}
}
} catch (final InterruptedException e) {
if (logger.isDebugEnabled()) {
logger.debug("Interupted task.", e);
}
} catch (final Exception e) {
if (generating) {
logger.warn("Failed to generate thumbnail.", e);
}
}
}
if (!taskList.isEmpty()) {
storeQueue(taskList);
}
}, "ThumbnailGenerator");
thumbnailQueueThread.start();
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class PrunedTag method parse.
public static PrunedTag[] parse(final String value) {
return split(value, ",").get(stream -> stream.filter(StringUtil::isNotBlank).map(v -> {
final Pattern pattern = Pattern.compile("(\\w+)(\\[[^\\]]+\\])?(\\.[\\w\\-]+)?(#[\\w\\-]+)?");
final Matcher matcher = pattern.matcher(v.trim());
if (matcher.matches()) {
final PrunedTag tag = new PrunedTag(matcher.group(1));
if (matcher.group(2) != null) {
final String attrPair = matcher.group(2).substring(1, matcher.group(2).length() - 1);
final Matcher equalMatcher = Pattern.compile("([\\w\\-]+)=(\\S+)").matcher(attrPair);
if (equalMatcher.matches()) {
tag.setAttr(equalMatcher.group(1), equalMatcher.group(2));
}
}
if (matcher.group(3) != null) {
tag.setCss(matcher.group(3).substring(1));
}
if (matcher.group(4) != null) {
tag.setId(matcher.group(4).substring(1));
}
return tag;
}
throw new FessSystemException("Invalid pruned tag: " + v);
}).toArray(n -> new PrunedTag[n]));
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class PluginHelperTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
pluginHelper = new PluginHelper() {
protected String[] getRepositories() {
return new String[] { "plugin/repo1/", "plugin/repo2/" };
}
protected String getRepositoryContent(String url) {
if (url.endsWith("/")) {
url = url + "index.html";
}
if (url.contains("plugin/repo1")) {
try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
} catch (Exception e) {
return "";
}
} else if (url.contains("plugin/repo2")) {
try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
} catch (Exception e) {
return "";
}
} else if (url.contains("plugin/repo.yaml")) {
try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
} catch (Exception e) {
return "";
}
}
throw new FessSystemException("unknown");
}
protected boolean isTargetPluginVersion(final String version) {
return true;
}
};
}
Aggregations