Package org.apache.myfaces.tobago.context

Examples of org.apache.myfaces.tobago.context.Theme


      final ClientPropertiesKey clientkey, final String prefix, final String subDir, final String name,
      final String suffix, final boolean reverseOrder, final boolean single, final boolean returnKey, final String key,
      final boolean returnStrings, final boolean ignoreMissing) {
    final List matches = new ArrayList();
    final String contentType = clientkey.getContentType();
    final Theme theme = clientkey.getTheme();
    final UserAgent browser = clientkey.getUserAgent();
    final List<String> locales = LocaleUtils.getLocaleSuffixList(clientkey.getLocale());

    // check first the local web application directory
    for (final String localeSuffix : locales) {
      if (production) {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
        if (!found) {
          found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
              name, null, localeSuffix, suffix, key);
          if (found && (single || !returnStrings)) {
            return matches;
          }
        }
      } else {
        final boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, null, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
      }
    }

    // after that check the whole resources tree
    // e.g. 1. application, 2. library or renderkit
    for (final Theme currentTheme : theme.getFallbackList()) {// theme loop
      for (final String resourceDirectory : tobagoConfig.getResourceDirs()) {
        for (final String browserType : browser.getFallbackList()) { // browser loop
          for (final String localeSuffix : locales) { // locale loop
            if (production) {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, MINIMIZE_SUFFIX,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
              if (!found) {
                found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                    resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                    localeSuffix, suffix, key);
                if (found && (single || !returnStrings)) {
                  return matches;
                }
              }
            } else {
              final boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
            }
          }
        }
      }
    }

    if (matches.isEmpty()) {
      if (!ignoreMissing) {
        LOG.error("Path not found, and no fallback. Using empty string.\n"
            + "resourceDirs = '" + tobagoConfig.getResourceDirs()
            + "' contentType = '" + contentType
            + "' theme = '" + theme.getName()
            + "' browser = '" + browser
            + "' subDir = '" + subDir
            + "' name = '" + name
            + "' suffix = '" + suffix
            + "' key = '" + key
View Full Code Here


        LOG.debug("defaultTheme = '{}'", defaultTheme);
      }
    } else {
      int deep = 0;
      for (final Map.Entry<String, Theme> entry : availableThemes.entrySet()) {
        final Theme theme = entry.getValue();
        if (theme.getFallbackList().size() > deep) {
          defaultTheme = theme;
          deep = theme.getFallbackList().size();
        }
      }
      if (defaultTheme == null) {
        final String error = "Did not found any theme! "
            + "Please ensure you have a tobago-config.xml with a theme-definition in your "
            + "theme JAR. Please add a theme JAR to your WEB-INF/lib";
        LOG.error(error);
        throw new RuntimeException(error);
      } else {
        if (LOG.isInfoEnabled()) {
          LOG.info("Using default Theme {}", defaultTheme.getName());
        }
      }
    }
    if (!supportedThemeNames.isEmpty()) {
      for (final String name : supportedThemeNames) {
        final Theme theme = availableThemes.get(name);
        checkThemeIsAvailable(name, theme);
        supportedThemes.add(theme);
        if (LOG.isDebugEnabled()) {
          LOG.debug("name = '{}'",  name);
          LOG.debug("supportedThemes.last() = '{}'", supportedThemes.get(supportedThemes.size() - 1));
View Full Code Here

        LOG.debug("defaultTheme = '{}'", defaultTheme);
      }
    } else {
      int deep = 0;
      for (Map.Entry<String, Theme> entry : availableThemes.entrySet()) {
        Theme theme = entry.getValue();
        if (theme.getFallbackList().size() > deep) {
          defaultTheme = theme;
          deep = theme.getFallbackList().size();
        }
      }
      if (defaultTheme == null) {
        String error = "Did not found any theme! "
            + "Please ensure you have a tobago-config.xml with a theme-definition in your "
            + "theme JAR. Please add a theme JAR to your WEB-INF/lib";
        LOG.error(error);
        throw new RuntimeException(error);
      } else {
        if (LOG.isInfoEnabled()) {
          LOG.info("Using default Theme {}", defaultTheme.getName());
        }
      }
    }
    if (!supportedThemeNames.isEmpty()) {
      for (String name : supportedThemeNames) {
        Theme theme = availableThemes.get(name);
        checkThemeIsAvailable(name, theme);
        supportedThemes.add(theme);
        if (LOG.isDebugEnabled()) {
          LOG.debug("name = '{}'",  name);
          LOG.debug("supportedThemes.last() = '{}'", supportedThemes.get(supportedThemes.size() - 1));
View Full Code Here

      ClientPropertiesKey clientkey, String prefix, String subDir, String name, String suffix,
      boolean reverseOrder, boolean single, boolean returnKey, String key, boolean returnStrings,
      boolean ignoreMissing) {
    List matches = new ArrayList();
    String contentType = clientkey.getContentType();
    Theme theme = clientkey.getTheme();
    UserAgent browser = clientkey.getUserAgent();
    List<String> locales = LocaleUtils.getLocaleSuffixList(clientkey.getLocale());

    // check first the local web application directory
    for (String localeSuffix : locales) {
      if (production) {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
        if (!found) {
          found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
              name, null, localeSuffix, suffix, key);
          if (found && (single || !returnStrings)) {
            return matches;
          }
        }
      } else {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, null, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
      }
    }

    // after that check the whole resources tree
    // e.g. 1. application, 2. library or renderkit
    for (Theme currentTheme : theme.getFallbackList()) {// theme loop
      for (String resourceDirectory : tobagoConfig.getResourceDirs()) {
        for (String browserType : browser.getFallbackList()) { // browser loop
          for (String localeSuffix : locales) { // locale loop
            if (production) {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, MINIMIZE_SUFFIX,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
              if (!found) {
                found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                    resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                    localeSuffix, suffix, key);
                if (found && (single || !returnStrings)) {
                  return matches;
                }
              }
            } else {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
            }
          }
        }
      }
    }

    if (matches.isEmpty()) {
      if (!ignoreMissing) {
        LOG.error("Path not found, and no fallback. Using empty string.\n"
            + "resourceDirs = '" + tobagoConfig.getResourceDirs()
            + "' contentType = '" + contentType
            + "' theme = '" + theme.getName()
            + "' browser = '" + browser
            + "' subDir = '" + subDir
            + "' name = '" + name
            + "' suffix = '" + suffix
            + "' key = '" + key
View Full Code Here

      // title
      writer.startElement(HtmlElements.TITLE, null);
      writer.writeText(title != null ? title : "");
      writer.endElement(HtmlElements.TITLE);
      final Theme theme = client.getTheme();

      // style files
      for (String styleFile : theme.getStyleResources(productionMode)) {
        writeStyle(facesContext, writer, styleFile);
      }

      for (String styleFile : facesContext.getStyleFiles()) {
        writeStyle(facesContext, writer, styleFile);
      }

      String icon = page.getApplicationIcon();
      if (icon != null) {
        // XXX unify with image renderer
        if (ResourceManagerUtils.isAbsoluteResource(icon)) {
          // absolute Path to image : nothing to do
        } else {
          icon = ResourceManagerUtils.getImageWithPath(facesContext, icon);
        }

        writer.startElement(HtmlElements.LINK, null);
        if (icon.endsWith(".ico")) {
          writer.writeAttribute(HtmlAttributes.REL, "shortcut icon", false);
          writer.writeAttribute(HtmlAttributes.HREF, icon, false);
        } else {
          // XXX IE only supports ICO files for favicons
          writer.writeAttribute(HtmlAttributes.REL, "icon", false);
          writer.writeAttribute(HtmlAttributes.TYPE, MimeTypeUtils.getMimeTypeForFile(icon), false);
          writer.writeAttribute(HtmlAttributes.HREF, icon, false);
        }
        writer.endElement(HtmlElements.LINK);
      }

      // style sniplets
      Set<String> styleBlocks = facesContext.getStyleBlocks();
      if (styleBlocks.size() > 0) {
        writer.startElement(HtmlElements.STYLE, null);
        for (String cssBlock : styleBlocks) {
          writer.write(cssBlock);
        }
        writer.endElement(HtmlElements.STYLE);
      }

      if (debugMode) {
        boolean hideClientLogging = true;
        String severity = (String) facesContext.getExternalContext().getRequestMap().get(CLIENT_DEBUG_SEVERITY);
        LOG.info("get " + CLIENT_DEBUG_SEVERITY + " = " + severity);
        if (severity != null) {
          try {
            int index = severity.indexOf(';');
            if (index == -1) {
              index = severity.length();
            }
            clientLogSeverity = Integer.parseInt(severity.substring(0, index));
          } catch (NumberFormatException e) {/* ignore; use default*/ }
          hideClientLogging = !severity.contains("show");
        }
        // the jquery ui is used in moment only for the logging area...
        facesContext.getOnloadScripts().add(0, "new LOG.LogArea({hide: " + hideClientLogging + "});");
      }

      // render remaining script tags
      for (String scriptFile: theme.getScriptResources(productionMode)) {
        encodeScript(facesContext, writer, scriptFile);
      }

      for (String scriptFile : facesContext.getScriptFiles()) {
        encodeScript(facesContext, writer, scriptFile);
View Full Code Here

      LOG.debug("name = '" + defaultThemeName + "'");
      LOG.debug("defaultTheme = '" + defaultTheme + "'");
    }

    for (String name : supportedThemeNames) {
      Theme theme = availableTheme.get(name);
      checkThemeIsAvailable(name, theme);
      supportedThemes.add(theme);
      if (LOG.isDebugEnabled()) {
        LOG.debug("name = '" + name + "'");
        LOG.debug("supportedThemes.last() = '" + supportedThemes.get(supportedThemes.size() - 1) + "'");
View Full Code Here

      // title
      writer.startElement(HtmlElements.TITLE, null);
      writer.writeText(title != null ? title : "");
      writer.endElement(HtmlElements.TITLE);
      final Theme theme = client.getTheme();

      if (frameKiller) {
        writer.writeJavascript("if (self == top) {\n  var forms = document.forms;\n"
            + "  for(var i=0;i<forms.length;i++) {\n    if (forms[i].style.display == 'none') {"
            + "      forms[i].style.display = 'block';}\n  }\n} else { "
            + "  top.location = self.location; }\n");
      }
      if (debugMode) {
        // This tag must not be earlier, because the
        // IE doesn't accept some META tags, when they are not the first ones.
        writer.writeJavascript("var TbgHeadStart = new Date();");
      }

      // style files
      for (String styleFile : theme.getStyleResources(productionMode)) {
        writeStyle(facesContext, writer, styleFile);
      }

      for (String styleFile : FacesContextUtils.getStyleFiles(facesContext)) {
        writeStyle(facesContext, writer, styleFile);
      }

      String icon = page.getApplicationIcon();
      if (icon != null) {
        // XXX unify with image renderer
        if (ResourceManagerUtils.isAbsoluteResource(icon)) {
          // absolute Path to image : nothing to do
        } else {
          icon = ResourceManagerUtils.getImageWithPath(facesContext, icon);
        }

        writer.startElement(HtmlElements.LINK, null);
        if (icon.endsWith(".ico")) {
          writer.writeAttribute(HtmlAttributes.REL, "shortcut icon", false);
          writer.writeAttribute(HtmlAttributes.HREF, icon, false);
        } else {
          // XXX IE only supports ICO files for favicons
          writer.writeAttribute(HtmlAttributes.REL, "icon", false);
          writer.writeAttribute(HtmlAttributes.TYPE, MimeTypeUtils.getMimeTypeForFile(icon), false);
          writer.writeAttribute(HtmlAttributes.HREF, icon, false);
        }
        writer.endElement(HtmlElements.LINK);
      }

      // style sniplets
      Set<String> styleBlocks = FacesContextUtils.getStyleBlocks(facesContext);
      if (styleBlocks.size() > 0) {
        writer.startElement(HtmlElements.STYLE, null);
        writer.flush(); // is needed in some cases, e. g. TOBAGO-1094
        for (String cssBlock : styleBlocks) {
          writer.write(cssBlock);
        }
        writer.endElement(HtmlElements.STYLE);
      }

      if (debugMode) {
        boolean hideClientLogging = true;
        String severity = (String) facesContext.getExternalContext().getRequestMap().get(CLIENT_DEBUG_SEVERITY);
        if (LOG.isDebugEnabled()) {
          LOG.debug("get " + CLIENT_DEBUG_SEVERITY + " = " + severity);
        }
        if (severity != null) {
          try {
            int index = severity.indexOf(';');
            if (index == -1) {
              index = severity.length();
            }
            clientLogSeverity = Integer.parseInt(severity.substring(0, index));
          } catch (NumberFormatException e) {/* ignore; use default*/ }
          hideClientLogging = !severity.contains("show");
        }
        // the jquery ui is used in moment only for the logging area...
        FacesContextUtils.addOnloadScript(facesContext, 0, "new LOG.LogArea({hide: " + hideClientLogging + "});");
      }

      // render remaining script tags
      for (String scriptFile: theme.getScriptResources(productionMode)) {
        encodeScript(facesContext, writer, scriptFile);
      }

      for (String scriptFile : FacesContextUtils.getScriptFiles(facesContext)) {
        encodeScript(facesContext, writer, scriptFile);
View Full Code Here

      ClientPropertiesKey clientkey, String prefix, String subDir, String name, String suffix,
      boolean reverseOrder, boolean single, boolean returnKey, String key, boolean returnStrings,
      boolean ignoreMissing) {
    List matches = new ArrayList();
    String contentType = clientkey.getContentType();
    Theme theme = clientkey.getTheme();
    UserAgent browser = clientkey.getUserAgent();
    List<String> locales = LocaleUtils.getLocaleSuffixList(clientkey.getLocale());

    // check first the local web application directory
    for (String localeSuffix : locales) {
      if (production) {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
        if (!found) {
          found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
              name, null, localeSuffix, suffix, key);
          if (found && (single || !returnStrings)) {
            return matches;
          }
        }
      } else {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, null, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
      }
    }

    // after that check the whole resources tree
    // e.g. 1. application, 2. library or renderkit
    for (Theme currentTheme : theme.getFallbackList()) {// theme loop
      for (String resourceDirectory : tobagoConfig.getResourceDirs()) {
        for (String browserType : browser.getFallbackList()) { // browser loop
          for (String localeSuffix : locales) { // locale loop
            if (production) {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, MINIMIZE_SUFFIX,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
              if (!found) {
                found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                    resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                    localeSuffix, suffix, key);
                if (found && (single || !returnStrings)) {
                  return matches;
                }
              }
            } else {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
            }
          }
        }
      }
    }

    if (matches.isEmpty()) {
      if (!ignoreMissing) {
        LOG.error("Path not found, and no fallback. Using empty string.\n"
            + "resourceDirs = '" + tobagoConfig.getResourceDirs()
            + "' contentType = '" + contentType
            + "' theme = '" + theme.getName()
            + "' browser = '" + browser
            + "' subDir = '" + subDir
            + "' name = '" + name
            + "' suffix = '" + suffix
            + "' key = '" + key
View Full Code Here

        LOG.debug("defaultTheme = '{}'", defaultTheme);
      }
    } else {
      int deep = 0;
      for (Map.Entry<String, Theme> entry : availableThemes.entrySet()) {
        Theme theme = entry.getValue();
        if (theme.getFallbackList().size() > deep) {
          defaultTheme = theme;
          deep = theme.getFallbackList().size();
        }
      }
      if (defaultTheme == null) {
        String error = "Did not found any theme! "
            + "Please ensure you have a tobago-theme.xml file in your "
            + "theme jar. Please add a theme jar to your WEB-INF/lib";
        LOG.error(error);
        throw new RuntimeException(error);
      } else {
        if (LOG.isInfoEnabled()) {
          LOG.info("Using default Theme {}", defaultTheme.getName());
        }
      }
    }
    if (!supportedThemeNames.isEmpty()) {
      for (String name : supportedThemeNames) {
        Theme theme = availableThemes.get(name);
        checkThemeIsAvailable(name, theme);
        supportedThemes.add(theme);
        if (LOG.isDebugEnabled()) {
          LOG.debug("name = '{}'",  name);
          LOG.debug("supportedThemes.last() = '{}'", supportedThemes.get(supportedThemes.size() - 1));
View Full Code Here

      final ClientPropertiesKey clientkey, final String prefix, final String subDir, final String name,
      final String suffix, final boolean reverseOrder, final boolean single, final boolean returnKey, final String key,
      final boolean returnStrings, boolean ignoreMissing) {
    final List matches = new ArrayList();
    final String contentType = clientkey.getContentType();
    final Theme theme = clientkey.getTheme();
    final UserAgent browser = clientkey.getUserAgent();
    final List<String> locales = LocaleUtils.getLocaleSuffixList(clientkey.getLocale());

    // check first the local web application directory
    for (final String localeSuffix : locales) {
      if (production) {
        boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
        if (!found) {
          found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
              name, null, localeSuffix, suffix, key);
          if (found && (single || !returnStrings)) {
            return matches;
          }
        }
      } else {
        final boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
            name, null, localeSuffix, suffix, key);
        if (found && (single || !returnStrings)) {
          return matches;
        }
      }
    }

    // after that check the whole resources tree
    // e.g. 1. application, 2. library or renderkit
    for (final Theme currentTheme : theme.getFallbackList()) {// theme loop
      for (final String resourceDirectory : tobagoConfig.getResourceDirs()) {
        for (final String browserType : browser.getFallbackList()) { // browser loop
          for (final String localeSuffix : locales) { // locale loop
            if (production) {
              boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, MINIMIZE_SUFFIX,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
              if (!found) {
                found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                    resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                    localeSuffix, suffix, key);
                if (found && (single || !returnStrings)) {
                  return matches;
                }
              }
            } else {
              final boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
                  resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
                  localeSuffix, suffix, key);
              if (found && (single || !returnStrings)) {
                return matches;
              }
            }
          }
        }
      }
    }

    if (matches.isEmpty()) {

      // XXX hack for Tobago 2.0.x backward compatibility: renaming of style.css to tobago.css
      // XXX style.css should be collected, but missing should be ignored
      if ("style/style".equals(name) && ".css".equals(suffix)) {
        ignoreMissing = true;
      }

      if (!ignoreMissing) {
        LOG.error("Path not found, and no fallback. Using empty string.\n"
            + "resourceDirs = '" + tobagoConfig.getResourceDirs()
            + "' contentType = '" + contentType
            + "' theme = '" + theme.getName()
            + "' browser = '" + browser
            + "' subDir = '" + subDir
            + "' name = '" + name
            + "' suffix = '" + suffix
            + "' key = '" + key
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.context.Theme

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.