Search in sources :

Example 1 with Property

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");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) FeedException(com.rometools.rome.io.FeedException) HttpServletResponse(javax.servlet.http.HttpServletResponse) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 2 with Property

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);
        }
    }
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 3 with 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());
}
Also used : IPropertyService(com.willshex.blogwt.server.service.property.IPropertyService) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 4 with Property

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());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Pager(com.willshex.blogwt.shared.api.Pager) Property(com.willshex.blogwt.shared.api.datatype.Property)

Example 5 with Property

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;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) Property(com.willshex.blogwt.shared.api.datatype.Property) Session(javax.mail.Session)

Aggregations

Property (com.willshex.blogwt.shared.api.datatype.Property)19 JsonElement (com.google.gson.JsonElement)4 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)4 IPropertyService (com.willshex.blogwt.server.service.property.IPropertyService)2 HTTPMethod (com.google.appengine.api.urlfetch.HTTPMethod)1 JsonArray (com.google.gson.JsonArray)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Widget (com.google.gwt.user.client.ui.Widget)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 FeedException (com.rometools.rome.io.FeedException)1 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)1 GetPropertiesFailure (com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesFailure)1 GetPropertiesSuccess (com.willshex.blogwt.client.api.blog.event.GetPropertiesEventHandler.GetPropertiesSuccess)1 UpdatePropertiesFailure (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesFailure)1 UpdatePropertiesSuccess (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess)1 HttpHelper (com.willshex.blogwt.server.helper.HttpHelper)1 InlineHelper (com.willshex.blogwt.server.helper.InlineHelper)1 PersistenceHelper (com.willshex.blogwt.server.helper.PersistenceHelper)1 ServletHelper (com.willshex.blogwt.server.helper.ServletHelper)1 ArchiveEntryServiceProvider (com.willshex.blogwt.server.service.archiveentry.ArchiveEntryServiceProvider)1