use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method addArticle.
/**
* Adds an article.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-article", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void addArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final String userName = request.getParameter(User.USER_NAME);
final JSONObject author = userQueryService.getUserByName(userName);
if (null == author) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, langPropsService.get("notFoundUserLabel"));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
final String timeStr = request.getParameter(Common.TIME);
final String articleTitle = request.getParameter(Article.ARTICLE_TITLE);
final String articleTags = request.getParameter(Article.ARTICLE_TAGS);
final String articleContent = request.getParameter(Article.ARTICLE_CONTENT);
String rewardContent = request.getParameter(Article.ARTICLE_REWARD_CONTENT);
final String rewardPoint = request.getParameter(Article.ARTICLE_REWARD_POINT);
long time = System.currentTimeMillis();
try {
final Date date = DateUtils.parseDate(timeStr, new String[] { "yyyy-MM-dd'T'HH:mm" });
time = date.getTime();
final int random = RandomUtils.nextInt(9999);
time += random;
} catch (final ParseException e) {
LOGGER.log(Level.ERROR, "Parse time failed, using current time instead");
}
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, articleTitle);
article.put(Article.ARTICLE_TAGS, articleTags);
article.put(Article.ARTICLE_CONTENT, articleContent);
article.put(Article.ARTICLE_REWARD_CONTENT, rewardContent);
article.put(Article.ARTICLE_REWARD_POINT, Integer.valueOf(rewardPoint));
article.put(User.USER_NAME, userName);
article.put(Common.TIME, time);
try {
articleMgmtService.addArticleByAdmin(article);
} catch (final ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/articles");
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method addDomain.
/**
* Adds a domain.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-domain", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void addDomain(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final String domainTitle = request.getParameter(Domain.DOMAIN_TITLE);
if (StringUtils.isBlank(domainTitle)) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, langPropsService.get("invalidDomainTitleLabel"));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
if (null != domainQueryService.getByTitle(domainTitle)) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, langPropsService.get("duplicatedDomainLabel"));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
String domainId;
try {
final JSONObject domain = new JSONObject();
domain.put(Domain.DOMAIN_TITLE, domainTitle);
domain.put(Domain.DOMAIN_URI, domainTitle);
domain.put(Domain.DOMAIN_DESCRIPTION, domainTitle);
domain.put(Domain.DOMAIN_STATUS, Domain.DOMAIN_STATUS_C_VALID);
domainId = domainMgmtService.addDomain(domain);
} catch (final ServiceException e) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/error.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put(Keys.MSG, e.getMessage());
dataModelService.fillHeaderAndFooter(request, response, dataModel);
return;
}
response.sendRedirect(Latkes.getServePath() + "/admin/domain/" + domainId);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showAddArticle.
/**
* Shows add article.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/add-article", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showAddArticle(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/add-article.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method updateReservedWord.
/**
* Updates a reserved word.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param id the specified reserved wordid
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/reserved-word/{id}", method = HTTPRequestMethod.POST)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void updateReservedWord(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String id) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/reserved-word.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final JSONObject word = optionQueryService.getOption(id);
dataModel.put(Common.WORD, word);
final Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
final String name = parameterNames.nextElement();
final String value = request.getParameter(name);
word.put(name, value);
}
optionMgmtService.updateOption(id, word);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class AdminProcessor method showTag.
/**
* Shows a tag.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param tagId the specified tag id
* @throws Exception exception
*/
@RequestProcessing(value = "/admin/tag/{tagId}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, PermissionCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showTag(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String tagId) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("admin/tag.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final JSONObject tag = tagQueryService.getTag(tagId);
dataModel.put(Tag.TAG, tag);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
}
Aggregations