use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class FeedServlet method doGet.
/* (non-Javadoc)
*
* @see com.willshex.service.ContextAwareServlet#doGet() */
@Override
protected void doGet() throws ServletException, IOException {
super.doGet();
Property generateRss = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.GENERATE_RSS_FEED);
if (PropertyHelper.isEmpty(generateRss) || Boolean.valueOf(generateRss.value).booleanValue()) {
HttpServletRequest request = REQUEST.get();
HttpServletResponse response = RESPONSE.get();
try {
SyndFeed feed = getFeed(request);
String feedType = request.getParameter(FEED_TYPE);
feedType = (feedType != null) ? feedType : defaultFeedType;
feed.setFeedType(feedType);
response.setContentType(MIME_TYPE);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
} catch (FeedException ex) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not generate feed");
}
}
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class UpdatePropertiesActionHandler method handle.
/* (non-Javadoc)
*
* @see
* com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
* gson.web.service.shared.Request,
* com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(UpdatePropertiesRequest input, UpdatePropertiesResponse output) throws Exception {
ApiValidator.request(input, UpdatePropertiesRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
UserValidator.authorisation(input.session.user, null, "input.session.user");
List<Property> updatedProperties = PropertyValidator.validateAll(input.properties, "input.properties");
Property existingProperty = null;
boolean found;
for (Property property : updatedProperties) {
found = false;
try {
existingProperty = PropertyValidator.lookup(property, "input.properties[n]");
found = true;
} catch (InputValidationException ex) {
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Property [" + property.name + "] does not exist. Will add with value [" + property.value + "].");
}
}
if (found) {
existingProperty.value = property.value;
PropertyServiceProvider.provide().updateProperty(existingProperty);
} else {
PropertyServiceProvider.provide().addProperty(property);
}
}
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class MainServlet method processRequest.
/**
* @throws IOException
*/
private void processRequest() throws IOException {
IPropertyService propertyService = PropertyServiceProvider.provide();
StringBuffer scriptVariables = new StringBuffer();
Property title = propertyService.getNamedProperty(PropertyHelper.TITLE);
List<Property> properties = null;
Map<String, Property> propertyLookup = null;
if (title != null) {
appendSession(scriptVariables);
properties = appendProperties(scriptVariables);
appendPages(scriptVariables);
appendTags(scriptVariables);
appendArchiveEntries(scriptVariables);
}
String pageTitle = (title == null ? "Blogwt" : title.value);
String rssLink = "", faviconLink = null, googleAnalyticsSnippet = "", googleAdSenseSnippet = "";
String rssPropertyValue = null, faviconPropertyValue = null, googleAnalyticsPropertyValue = null, googleAdSensePropertyValue = null;
if (properties != null) {
propertyLookup = PropertyHelper.toLookup(properties);
rssPropertyValue = PropertyHelper.value(propertyLookup.get(PropertyHelper.GENERATE_RSS_FEED));
faviconPropertyValue = PropertyHelper.value(propertyLookup.get(PropertyHelper.FAVICON_URL));
googleAnalyticsPropertyValue = PropertyHelper.value(propertyLookup.get(PropertyHelper.GOOGLE_ANALYTICS_KEY));
googleAdSensePropertyValue = PropertyHelper.value(propertyLookup.get(PropertyHelper.GOOGLE_AD_SENSE_KEY));
}
if (rssPropertyValue == null || Boolean.TRUE.toString().equals(rssPropertyValue)) {
rssLink = String.format(RSS_LINK_FORMAT, pageTitle + " (RSS feed)");
}
if (faviconPropertyValue == null || PropertyHelper.NONE_VALUE.equals(faviconPropertyValue)) {
faviconLink = String.format(FAVICON_FORMAT, "favicon.ico");
} else {
faviconLink = String.format(FAVICON_FORMAT, faviconPropertyValue);
}
if (googleAnalyticsPropertyValue != null && !PropertyHelper.NONE_VALUE.equals(googleAnalyticsPropertyValue)) {
googleAnalyticsSnippet = "<script>\n" + "window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;\n" + "ga('create', '" + googleAnalyticsPropertyValue + "', 'auto');\n" + "</script>\n" + "<script async src='https://www.google-analytics.com/analytics.js'></script>\n";
}
if (googleAdSensePropertyValue != null && !PropertyHelper.NONE_VALUE.equals(googleAdSensePropertyValue)) {
googleAdSenseSnippet = "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>\n" + "<script>\n" + " (adsbygoogle = window.adsbygoogle || []).push({\n" + " google_ad_client: \"" + googleAdSensePropertyValue + "\",\n" + " enable_page_level_ads: true\n" + " });\n" + "</script>";
}
String css = InlineHelper.css("https://fonts.googleapis.com/css?family=Noto+Sans") + "\n" + InlineHelper.css("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
RESPONSE.get().getOutputStream().write(String.format(PAGE_FORMAT, googleAnalyticsSnippet, googleAdSenseSnippet, css, rssLink, faviconLink, pageTitle, scriptVariables.toString()).getBytes());
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class GetPropertiesResponse method fromJson.
@Override
public void fromJson(JsonObject jsonObject) {
super.fromJson(jsonObject);
if (jsonObject.has("properties")) {
JsonElement jsonProperties = jsonObject.get("properties");
if (jsonProperties != null) {
properties = new ArrayList<Property>();
Property item = null;
for (int i = 0; i < jsonProperties.getAsJsonArray().size(); i++) {
if (jsonProperties.getAsJsonArray().get(i) != null) {
(item = new Property()).fromJson(jsonProperties.getAsJsonArray().get(i).getAsJsonObject());
properties.add(item);
}
}
}
}
if (jsonObject.has("pager")) {
JsonElement jsonPager = jsonObject.get("pager");
if (jsonPager != null) {
pager = new Pager();
pager.fromJson(jsonPager.getAsJsonObject());
}
}
}
use of com.willshex.blogwt.shared.api.datatype.Property in project blogwt by billy1380.
the class EmailHelper method sendEmail.
public static boolean sendEmail(String to, String name, String subject, String body, boolean isHtml, Map<String, byte[]> attachments) {
boolean sent = false;
Property email = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.OUTGOING_EMAIL);
if (!PropertyHelper.isEmpty(email) && !PropertyHelper.NONE_VALUE.equals(email.value)) {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
InternetAddress address = new InternetAddress(email.value, PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE).value);
msg.setFrom(address);
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to, name));
msg.setSubject(subject);
if (attachments == null || attachments.size() == 0) {
if (isHtml) {
msg.setContent(body, "text/html");
} else {
msg.setText(body);
}
} else {
Multipart mp = new MimeMultipart();
MimeBodyPart content = new MimeBodyPart();
if (isHtml) {
content.setContent(body, "text/html");
} else {
content.setText(body);
}
mp.addBodyPart(content);
for (String key : attachments.keySet()) {
MimeBodyPart attachment = new MimeBodyPart();
InputStream attachmentDataStream = new ByteArrayInputStream(attachments.get(key));
attachment.setFileName(key);
attachment.setContent(attachmentDataStream, "application/pdf");
mp.addBodyPart(attachment);
}
msg.setContent(mp);
}
Transport.send(msg);
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Email sent successfully.");
}
sent = true;
} catch (MessagingException | UnsupportedEncodingException e) {
LOG.log(Level.WARNING, "Error sending email [" + content(to, name, subject, body) + "]", e);
}
} else {
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Property [" + PropertyHelper.OUTGOING_EMAIL + "] not configured.");
}
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Email [" + content(to, name, subject, body) + "]");
}
return sent;
}
Aggregations