Package ch.entwine.weblounge.common.site

Examples of ch.entwine.weblounge.common.site.Site


    logger.info("");
    logger.info("------------------------------------------------------------------------");
    logger.info("Running test '" + test + "'");
    logger.info("------------------------------------------------------------------------");
    try {
      Site site = test.getSite();
      if (site == null) {
        logger.warn("Test {} has no site associated", test.getName());
        return false;
      }
      test.init(environment);
View Full Code Here


  @Override
  public void init(FilterConfig config) throws ServletException {
    this.sites.addSiteListener(this);
    Iterator<Site> si = sites.sites();
    while (si.hasNext()) {
      Site site = si.next();
      Bundle siteBundle = sites.getSiteBundle(site);
      registerSecurity(site, siteBundle);
    }
  }
View Full Code Here

   */
  @Override
  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {

    Site site = null;
    if (!(request instanceof HttpServletRequest)) {
      logger.warn("Received plain servlet request and don't know what to do with it");
      return;
    }

    // Try to map the request to a site
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    URL url = UrlUtils.toURL(httpRequest, false, false);
    site = sites.findSiteByURL(url);
    if (site == null) {
      logger.debug("Request for {} cannot be mapped to any site", httpRequest.getRequestURL());
      ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // Set the site in the security service
    try {
      logger.trace("Request to {} mapped to site '{}'", httpRequest.getRequestURL(), site.getIdentifier());
      securityService.setSite(site);

      // Select appropriate security filter and apply it
      Filter siteSecurityFilter = siteFilters.get(site);
      if (siteSecurityFilter != null) {
View Full Code Here

   * {@inheritDoc}
   *
   * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
   */
  public int doStartTag() throws JspException {
    Site site = request.getSite();
    Language language = request.getLanguage();

    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
      logger.debug("Unable to load content repository for site '{}'", site);
      response.invalidate();
      return SKIP_BODY;
    }
View Full Code Here

    String identifier = XPathHelper.valueOf(config, "@id", xpathProcessor);
    if (identifier == null)
      throw new IllegalStateException("Unable to create sites without identifier");

    // class
    Site site = null;
    String className = XPathHelper.valueOf(config, "ns:class", xpathProcessor);
    if (className != null) {
      try {
        Class<? extends Site> c = (Class<? extends Site>) classLoader.loadClass(className);
        site = c.newInstance();
        site.setIdentifier(identifier);
      } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Implementation " + className + " for site '" + identifier + "' not found", e);
      } catch (InstantiationException e) {
        throw new IllegalStateException("Error instantiating impelementation " + className + " for site '" + identifier + "'", e);
      } catch (IllegalAccessException e) {
        throw new IllegalStateException("Access violation instantiating implementation " + className + " for site '" + identifier + "'", e);
      } catch (Throwable t) {
        throw new IllegalStateException("Error loading implementation " + className + " for site '" + identifier + "'", t);
      }

    } else {
      site = new SiteImpl();
      site.setIdentifier(identifier);
    }

    // name
    String name = XPathHelper.valueOf(config, "ns:name", xpathProcessor);
    if (name == null)
      throw new IllegalStateException("Site '" + identifier + " has no name");
    site.setName(name);

    // domains
    NodeList urlNodes = XPathHelper.selectList(config, "ns:domains/ns:url", xpathProcessor);
    if (urlNodes.getLength() == 0)
      throw new IllegalStateException("Site '" + identifier + " has no hostname");
    String url = null;
    try {
      for (int i = 0; i < urlNodes.getLength(); i++) {
        Node urlNode = urlNodes.item(i);
        url = urlNode.getFirstChild().getNodeValue();
        boolean defaultUrl = ConfigurationUtils.isDefault(urlNode);
        Environment environment = Environment.Production;
        Node environmentAttribute = urlNode.getAttributes().getNamedItem("environment");
        if (environmentAttribute != null && environmentAttribute.getNodeValue() != null)
          environment = Environment.valueOf(StringUtils.capitalize(environmentAttribute.getNodeValue()));

        SiteURLImpl siteURL = new SiteURLImpl(new URL(url));
        siteURL.setDefault(defaultUrl);
        siteURL.setEnvironment(environment);

        site.addHostname(siteURL);
      }
    } catch (MalformedURLException e) {
      throw new IllegalStateException("Site '" + identifier + "' defines malformed url: " + url);
    }

    // languages
    NodeList languageNodes = XPathHelper.selectList(config, "ns:languages/ns:language", xpathProcessor);
    if (languageNodes.getLength() == 0)
      throw new IllegalStateException("Site '" + identifier + " has no languages");
    for (int i = 0; i < languageNodes.getLength(); i++) {
      Node languageNode = languageNodes.item(i);
      Node defaultAttribute = languageNode.getAttributes().getNamedItem("default");
      String languageId = languageNode.getFirstChild().getNodeValue();
      try {
        Language language = LanguageUtils.getLanguage(languageId);
        if (ConfigurationUtils.isTrue(defaultAttribute))
          site.setDefaultLanguage(language);
        else
          site.addLanguage(language);
      } catch (UnknownLanguageException e) {
        throw new IllegalStateException("Site '" + identifier + "' defines unknown language: " + languageId);
      }
    }

    // templates
    NodeList templateNodes = XPathHelper.selectList(config, "ns:templates/ns:template", xpathProcessor);
    PageTemplate firstTemplate = null;
    for (int i = 0; i < templateNodes.getLength(); i++) {
      PageTemplate template = PageTemplateImpl.fromXml(templateNodes.item(i), xpathProcessor);
      boolean isDefault = ConfigurationUtils.isDefault(templateNodes.item(i));
      if (isDefault && site.getDefaultTemplate() != null) {
        logger.warn("Site '{}' defines more than one default templates", site.getIdentifier());
      } else if (isDefault) {
        site.setDefaultTemplate(template);
        logger.debug("Site '{}' uses default template '{}'", site.getIdentifier(), template.getIdentifier());
      } else {
        site.addTemplate(template);
        logger.debug("Added template '{}' to site '{}'", template.getIdentifier(), site.getIdentifier());
      }
      if (firstTemplate == null)
        firstTemplate = template;
    }

    // Make sure we have a default template
    if (site.getDefaultTemplate() == null) {
      if (firstTemplate == null)
        throw new IllegalStateException("Site '" + site.getIdentifier() + "' does not specify any page templates");
      logger.warn("Site '{}' does not specify a default template. Using '{}'", site.getIdentifier(), firstTemplate.getIdentifier());
      site.setDefaultTemplate(firstTemplate);
    }

    // security
    String securityConfiguration = XPathHelper.valueOf(config, "ns:security/ns:configuration", xpathProcessor);
    if (securityConfiguration != null) {
      URL securityConfig = null;

      // If converting the path into a URL fails, we are assuming that the
      // configuration is part of the bundle
      try {
        securityConfig = new URL(securityConfiguration);
      } catch (MalformedURLException e) {
        logger.debug("Security configuration {} is pointing to the bundle", securityConfiguration);
        securityConfig = SiteImpl.class.getResource(securityConfiguration);
        if (securityConfig == null) {
          throw new IllegalStateException("Security configuration " + securityConfig + " of site '" + site.getIdentifier() + "' cannot be located inside of bundle", e);
        }
      }
      site.setSecurity(securityConfig);
    }

    // administrator
    Node adminNode = XPathHelper.select(config, "ns:security/ns:administrator", xpathProcessor);
    if (adminNode != null) {
      site.setAdministrator(SiteAdminImpl.fromXml(adminNode, site, xpathProcessor));
    }

    // digest policy
    Node digestNode = XPathHelper.select(config, "ns:security/ns:digest", xpathProcessor);
    if (digestNode != null) {
      site.setDigestType(DigestType.valueOf(digestNode.getFirstChild().getNodeValue()));
    }

    // role definitions
    NodeList roleNodes = XPathHelper.selectList(config, "ns:security/ns:roles/ns:*", xpathProcessor);
    for (int i = 0; i < roleNodes.getLength(); i++) {
      Node roleNode = roleNodes.item(i);
      String roleName = roleNode.getLocalName();
      String localRoleName = roleNode.getFirstChild().getNodeValue();
      if (Security.SITE_ADMIN_ROLE.equals(roleName))
        site.addLocalRole(Security.SITE_ADMIN_ROLE, localRoleName);
      if (Security.PUBLISHER_ROLE.equals(roleName))
        site.addLocalRole(Security.PUBLISHER_ROLE, localRoleName);
      if (Security.EDITOR_ROLE.equals(roleName))
        site.addLocalRole(Security.EDITOR_ROLE, localRoleName);
      if (Security.GUEST_ROLE.equals(roleName))
        site.addLocalRole(Security.GUEST_ROLE, localRoleName);
    }

    // options
    Node optionsNode = XPathHelper.select(config, "ns:options", xpathProcessor);
    OptionsHelper.fromXml(optionsNode, site, xpathProcessor);
View Full Code Here

   *
   * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
   */
  @Override
  public int doStartTag() throws JspException {
    Site site = request.getSite();

    repository = site.getContentRepository();
    if (repository == null) {
      logger.debug("Unable to load content repository for site '{}'", site);
      response.invalidate();
      return SKIP_BODY;
    }
View Full Code Here

    String suffix = FilenameUtils.getExtension(filename);
    if (StringUtils.isBlank(suffix))
      suffix = DEFAULT_PREVIEW_FORMAT;

    // If needed, create the scaled file's parent directory
    Site site = resource.getURI().getSite();
    File dir = new File(PathUtils.concat(System.getProperty("java.io.tmpdir"), "sites", site.getIdentifier(), "images", style.getIdentifier(), resource.getIdentifier(), Long.toString(resource.getVersion()), language.getIdentifier()));

    // Create the filename
    StringBuffer scaledFilename = new StringBuffer(FilenameUtils.getBaseName(filename));
    scaledFilename.append("-").append(style.getIdentifier());
View Full Code Here

   *
   * @param module
   *          The module to set.
   */
  public void setModule(String module) throws JspTagException {
    Site site = request.getSite();
    this.module = site.getModule(module);
    if (this.module == null) {
      String msg = "Module '" + module + "' not found!";
      throw new JspTagException(msg);
    }
  }
View Full Code Here

    // Fix handling of potential loss of original language. If the original
    // language has been deleted, the underlying implementation will switch the
    // resource to a random default language.
    if (useOriginalLanguage && !Original.equals(behavior)) {
      Site site = uri.getSite();
      if (supportsLanguage(site.getDefaultLanguage())) {
        logger.trace("Switching default language of localizable object {} to site default language {}", this, defaultLanguage);
        setOriginalLanguage(site.getDefaultLanguage());
      }
    }

    return content.remove(language);
View Full Code Here

    // Don't do work if not needed (which is the case during precompilation)
    if (RequestUtils.isPrecompileRequest(request))
      return SKIP_BODY;

    Site site = request.getSite();

    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
      logger.debug("Unable to load content repository for site '{}'", site);
      response.invalidate();
      return SKIP_BODY;
    }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.site.Site

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.