use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class LoginAction method login.
@Execute
public HtmlResponse login(final LoginForm form) {
validate(form, messages -> {
}, () -> asIndexPage(form));
verifyToken(() -> asIndexPage(form));
final String username = form.username;
final String password = form.password;
form.clearSecurityInfo();
try {
return fessLoginAssist.loginRedirect(new UserPasswordCredential(username, password), op -> {
}, () -> {
activityHelper.login(getUserBean());
userInfoHelper.deleteUserCodeFromCookie(request);
return getHtmlResponse();
});
} catch (final LoginFailureException lfe) {
throwValidationError(messages -> messages.addErrorsLoginError(GLOBAL), () -> asIndexPage(form));
}
return redirect(getClass());
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class SearchAction method doSearch.
protected HtmlResponse doSearch(final SearchForm form) {
validate(form, messages -> {
}, () -> asHtml(virtualHost(path_SearchJsp)));
if (isLoginRequired()) {
return redirectToLogin();
}
if (viewHelper.isUseSession()) {
final HttpSession session = request.getSession(false);
if (session != null) {
final Object resultsPerPage = session.getAttribute(Constants.RESULTS_PER_PAGE);
if (resultsPerPage instanceof Integer) {
form.num = (Integer) resultsPerPage;
}
}
}
if (StringUtil.isBlank(form.q) && form.fields.isEmpty()) {
// redirect to index page
form.q = null;
return redirectToRoot();
}
try {
buildFormParams(form);
form.lang = searchService.getLanguages(request, form);
request.setAttribute(Constants.REQUEST_LANGUAGES, form.lang);
request.setAttribute(Constants.REQUEST_QUERIES, form.q);
final WebRenderData renderData = new WebRenderData();
searchService.search(form, renderData, getUserBean());
return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
renderData.register(data);
if (favoriteSupport || thumbnailSupport) {
final String queryId = renderData.getQueryId();
final List<Map<String, Object>> documentItems = renderData.getDocumentItems();
userInfoHelper.storeQueryId(queryId, documentItems);
if (thumbnailSupport) {
thumbnailManager.storeRequest(queryId, documentItems);
}
}
RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH)));
createPagingQuery(form);
});
} catch (final InvalidQueryException e) {
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
saveError(e.getMessageCode());
return redirectToRoot();
} catch (final ResultOffsetExceededException e) {
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
saveError(messages -> {
messages.addErrorsResultSizeExceeded(GLOBAL);
});
return redirectToRoot();
}
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminElevatewordAction method details.
// -----------------------------------------------------
// Details
// -------
@Execute
public HtmlResponse details(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DETAILS);
saveToken();
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
return asHtml(path_AdminElevateword_AdminElevatewordDetailsJsp).useForm(EditForm.class, op -> op.setup(form -> {
elevateWordService.getElevateWord(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
copyOp.exclude(Constants.PERMISSIONS);
});
form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
form.crudMode = crudMode;
}).orElse(() -> throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml()));
})).renderWith(data -> registerLabels(data));
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminDesignAction method upload.
@Execute
public HtmlResponse upload(final UploadForm form) {
validate(form, messages -> {
}, () -> asListHtml(form));
verifyToken(() -> asListHtml());
final String uploadedFileName = form.designFile.getFileName();
String fileName = form.designFileName;
if (StringUtil.isBlank(fileName)) {
fileName = uploadedFileName;
try {
int pos = fileName.indexOf('/');
if (pos >= 0) {
fileName = fileName.substring(pos + 1);
}
pos = fileName.indexOf('\\');
if (pos >= 0) {
fileName = fileName.substring(pos + 1);
}
} catch (final Exception e) {
throwValidationError(messages -> messages.addErrorsDesignFileNameIsInvalid("designFile"), () -> asListHtml());
}
}
if (StringUtil.isBlank(fileName)) {
throwValidationError(messages -> messages.addErrorsDesignFileNameIsNotFound("designFile"), () -> asListHtml());
}
File uploadFile;
// normalize filename
if (checkFileType(fileName, fessConfig.getSupportedUploadedMediaExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedMediaExtentionsAsArray())) {
uploadFile = new File(getServletContext().getRealPath("/images/" + fileName));
} else if (checkFileType(fileName, fessConfig.getSupportedUploadedCssExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedCssExtentionsAsArray())) {
uploadFile = new File(getServletContext().getRealPath("/css/" + fileName));
} else if (checkFileType(fileName, fessConfig.getSupportedUploadedJsExtentionsAsArray()) && checkFileType(uploadedFileName, fessConfig.getSupportedUploadedJsExtentionsAsArray())) {
uploadFile = new File(getServletContext().getRealPath("/js/" + fileName));
} else if (fessConfig.isSupportedUploadedFile(fileName) || fessConfig.isSupportedUploadedFile(uploadedFileName)) {
uploadFile = ResourceUtil.getResourceAsFileNoException(fileName);
if (uploadFile == null) {
throwValidationError(messages -> messages.addErrorsDesignFileNameIsNotFound("designFileName"), () -> asListHtml());
return null;
}
} else {
throwValidationError(messages -> messages.addErrorsDesignFileIsUnsupportedType("designFileName"), () -> asListHtml());
return null;
}
final File parentFile = uploadFile.getParentFile();
if (!parentFile.exists() && !parentFile.mkdirs()) {
logger.warn("Could not create " + parentFile.getAbsolutePath());
}
try {
write(uploadFile.getAbsolutePath(), form.designFile.getFileData());
final String currentFileName = fileName;
saveInfo(messages -> messages.addSuccessUploadDesignFile(GLOBAL, currentFileName));
} catch (final Exception e) {
logger.error("Failed to write an image file: {}", fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToWriteDesignImageFile(GLOBAL), () -> asListHtml());
}
return redirect(getClass());
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminLabeltypeAction method details.
// -----------------------------------------------------
// Details
// -------
@Execute
public HtmlResponse details(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DETAILS);
saveToken();
return asHtml(path_AdminLabeltype_AdminLabeltypeDetailsJsp).useForm(EditForm.class, op -> {
op.setup(form -> {
labelTypeService.getLabelType(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
copyOp.exclude(Constants.PERMISSIONS);
});
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
form.crudMode = crudMode;
}).orElse(() -> {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
});
});
}).renderWith(data -> {
registerRoleTypeItems(data);
});
}
Aggregations