Search in sources :

Example 1 with IPropertyService

use of com.willshex.blogwt.server.service.property.IPropertyService 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 2 with IPropertyService

use of com.willshex.blogwt.server.service.property.IPropertyService in project blogwt by billy1380.

the class SetupBlogActionHandler 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(SetupBlogRequest input, SetupBlogResponse output) throws Exception {
    ApiValidator.request(input, SetupBlogRequest.class);
    IPropertyService propertyService = PropertyServiceProvider.provide();
    if (propertyService.getNamedProperty(PropertyHelper.TITLE) != null)
        ApiValidator.throwServiceError(ServiceException.class, ApiError.ExistingSetup, "input.properties");
    ApiValidator.request(input, SetupBlogRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    ApiValidator.notNull(input.properties, Property.class, "input.properties");
    ApiValidator.notNull(input.users, User.class, "input.users");
    input.properties = PropertyValidator.setup(input.properties, "input.properties");
    propertyService.addPropertyBatch(input.properties);
    RoleServiceProvider.provide().addRole(RoleHelper.createFull(RoleHelper.ADMIN, RoleHelper.ADMIN_NAME, RoleHelper.ADMIN_DESCRIPTION));
    for (Permission permission : PermissionHelper.createAll()) {
        PermissionServiceProvider.provide().addPermission(permission);
    }
    input.users = UserValidator.validateAll(input.users, "input.users");
    for (User user : input.users) {
        // users are either admins or nothing
        user.roles = RoleValidator.lookupAll(user.roles, "input.users[n].roles");
        // users added at startup are verified
        user.verified = Boolean.TRUE;
    }
    UserServiceProvider.provide().addUserBatch(input.users);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) ServiceException(com.willshex.gson.web.service.server.ServiceException) IPropertyService(com.willshex.blogwt.server.service.property.IPropertyService) Permission(com.willshex.blogwt.shared.api.datatype.Permission)

Aggregations

IPropertyService (com.willshex.blogwt.server.service.property.IPropertyService)2 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1 Property (com.willshex.blogwt.shared.api.datatype.Property)1 User (com.willshex.blogwt.shared.api.datatype.User)1 ServiceException (com.willshex.gson.web.service.server.ServiceException)1