protected PalettePreview computePalettePreview(FlavorDescriptor flavor, List<String> flavors) {
   if (flavor != null) {
     PalettePreview localPalette = flavor.getPalettePreview();
     if (localPalette == null) {
       String extendsFlavorName = flavor.getExtendsFlavor();
       if (!StringUtils.isBlank(extendsFlavorName)) {
         if (flavors.contains(extendsFlavorName)) {
           // cyclic dependency => abort
           log.error("Cyclic dependency detected in flavor '" + flavor.getName() + "' hierarchy");
           return null;
         } else {
           // retrieved the extended colors
           flavors.add(flavor.getName());
           FlavorDescriptor extendedFlavor = getFlavor(extendsFlavorName);
           if (extendedFlavor != null) {
             localPalette = computePalettePreview(extendedFlavor, flavors);
           } else {
             log.warn("Extended flavor '" + extendsFlavorName + "' not found");
           }
         }
       }
     }
     return localPalette;
   }
   return null;
 }
 protected List<IconDescriptor> computeIcons(FlavorDescriptor flavor, List<String> flavors) {
   if (flavor != null) {
     List<IconDescriptor> localIcons = flavor.getFavicons();
     if (localIcons == null || localIcons.isEmpty()) {
       String extendsFlavorName = flavor.getExtendsFlavor();
       if (!StringUtils.isBlank(extendsFlavorName)) {
         if (flavors.contains(extendsFlavorName)) {
           // cyclic dependency => abort
           log.error("Cyclic dependency detected in flavor '" + flavor.getName() + "' hierarchy");
           return null;
         } else {
           // retrieved the extended icons
           flavors.add(flavor.getName());
           FlavorDescriptor extendedFlavor = getFlavor(extendsFlavorName);
           if (extendedFlavor != null) {
             localIcons = computeIcons(extendedFlavor, flavors);
           } else {
             log.warn("Extended flavor '" + extendsFlavorName + "' not found");
           }
         }
       }
     }
     return localIcons;
   }
   return null;
 }
 protected LogoDescriptor computeLogo(FlavorDescriptor flavor, List<String> flavors) {
   if (flavor != null) {
     LogoDescriptor localLogo = flavor.getLogo();
     if (localLogo == null) {
       String extendsFlavorName = flavor.getExtendsFlavor();
       if (!StringUtils.isBlank(extendsFlavorName)) {
         if (flavors.contains(extendsFlavorName)) {
           // cyclic dependency => abort
           log.error("Cyclic dependency detected in flavor '" + flavor.getName() + "' hierarchy");
           return null;
         } else {
           // retrieved the extended logo
           flavors.add(flavor.getName());
           FlavorDescriptor extendedFlavor = getFlavor(extendsFlavorName);
           if (extendedFlavor != null) {
             localLogo = computeLogo(extendedFlavor, flavors);
           } else {
             log.warn("Extended flavor '" + extendsFlavorName + "' not found");
           }
         }
       }
     }
     return localLogo;
   }
   return null;
 }
 protected List<FlavorPresets> computePresets(FlavorDescriptor flavor, List<String> flavors) {
   List<FlavorPresets> presets = new ArrayList<FlavorPresets>();
   if (flavor != null) {
     List<FlavorPresets> localPresets = flavor.getPresets();
     if (localPresets != null) {
       presets.addAll(localPresets);
     }
     String extendsFlavorName = flavor.getExtendsFlavor();
     if (!StringUtils.isBlank(extendsFlavorName)) {
       if (flavors.contains(extendsFlavorName)) {
         // cyclic dependency => abort
         log.error("Cyclic dependency detected in flavor '" + flavor.getName() + "' hierarchy");
         return presets;
       } else {
         // retrieve the extended presets
         flavors.add(flavor.getName());
         FlavorDescriptor extendedFlavor = getFlavor(extendsFlavorName);
         if (extendedFlavor != null) {
           List<FlavorPresets> parentPresets = computePresets(extendedFlavor, flavors);
           if (parentPresets != null) {
             presets.addAll(0, parentPresets);
           }
         } else {
           log.warn("Extended flavor '" + extendsFlavorName + "' not found");
         }
       }
     }
   }
   return presets;
 }
 @Override
 public LogoDescriptor getLogo(String flavorName) {
   FlavorDescriptor flavor = getFlavor(flavorName);
   if (flavor != null) {
     return flavor.getLogo();
   }
   return null;
 }
  protected void registerFlavor(FlavorDescriptor flavor, RuntimeContext extensionContext) {
    // set flavor presets files content
    List<FlavorPresets> presets = flavor.getPresets();
    if (presets != null) {
      for (FlavorPresets myPreset : presets) {
        String src = myPreset.getSrc();
        URL url = getUrlFromPath(src, extensionContext);
        if (url == null) {
          log.error(String.format("Could not find resource at '%s'", src));
        } else {
          String content;
          try {
            content = new String(FileUtils.readBytes(url));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
          myPreset.setContent(content);
        }
      }
    }

    // set flavor sass variables
    List<SassImport> sassVars = flavor.getSassImports();
    if (sassVars != null) {
      for (SassImport var : sassVars) {
        String src = var.getSrc();
        URL url = getUrlFromPath(src, extensionContext);
        if (url == null) {
          log.error(String.format("Could not find resource at '%s'", src));
        } else {
          String content;
          try {
            content = new String(FileUtils.readBytes(url));
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
          var.setContent(content);
        }
      }
    }

    flavorReg.addContribution(flavor);
  }
 protected Map<String, Map<String, String>> getPresetsByCat(FlavorDescriptor flavor) {
   String flavorName = flavor.getName();
   List<FlavorPresets> presets = computePresets(flavor, new ArrayList<String>());
   Map<String, Map<String, String>> presetsByCat = new HashMap<String, Map<String, String>>();
   if (presets != null) {
     for (FlavorPresets myPreset : presets) {
       String content = myPreset.getContent();
       if (content == null) {
         log.error(
             "Null content for preset with source '"
                 + myPreset.getSrc()
                 + "' in flavor '"
                 + flavorName
                 + "'");
       } else {
         String cat = myPreset.getCategory();
         Map<String, String> allEntries;
         if (presetsByCat.containsKey(cat)) {
           allEntries = presetsByCat.get(cat);
         } else {
           allEntries = new HashMap<String, String>();
         }
         try {
           Map<String, String> newEntries =
               PaletteParser.parse(content.getBytes(), myPreset.getSrc());
           if (newEntries != null) {
             allEntries.putAll(newEntries);
           }
           if (allEntries.isEmpty()) {
             presetsByCat.remove(cat);
           } else {
             presetsByCat.put(cat, allEntries);
           }
         } catch (PaletteParseException e) {
           log.error(
               String.format(
                   "Could not parse palette for " + "preset with source '%s' in flavor '%s'",
                   myPreset.getSrc(), flavorName),
               e);
         }
       }
     }
   }
   return presetsByCat;
 }
 @Override
 public FlavorDescriptor getFlavor(String flavorName) {
   if (flavorReg != null) {
     FlavorDescriptor flavor = flavorReg.getFlavor(flavorName);
     if (flavor != null) {
       FlavorDescriptor clone = flavor.clone();
       clone.setLogo(computeLogo(flavor, new ArrayList<String>()));
       clone.setPalettePreview(computePalettePreview(flavor, new ArrayList<String>()));
       clone.setFavicons(computeIcons(flavor, new ArrayList<String>()));
       return clone;
     }
   }
   return null;
 }
 @Override
 public void registerContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) {
   if (contribution instanceof FlavorDescriptor) {
     FlavorDescriptor flavor = (FlavorDescriptor) contribution;
     log.info(String.format("Register flavor '%s'", flavor.getName()));
     registerFlavor(flavor, contributor.getContext());
     log.info(String.format("Done registering flavor '%s'", flavor.getName()));
   } else if (contribution instanceof SimpleStyle) {
     SimpleStyle style = (SimpleStyle) contribution;
     log.info(String.format("Register style '%s'", style.getName()));
     String message =
         String.format(
             "Style '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be "
                 + "accurate. Note that the 'flavor' processor should be used with this resource.",
             style.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     ResourceDescriptor resource = getResourceFromStyle(style);
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering style '%s'", style.getName()));
   } else if (contribution instanceof PageDescriptor) {
     PageDescriptor page = (PageDescriptor) contribution;
     log.info(String.format("Register page '%s'", page.getName()));
     if (page.hasResources()) {
       // automatically register a bundle for page resources
       WebResourceManager wrm = Framework.getService(WebResourceManager.class);
       wrm.registerResourceBundle(page.getComputedResourceBundle());
     }
     pageReg.addContribution(page);
     log.info(String.format("Done registering page '%s'", page.getName()));
   } else if (contribution instanceof ResourceDescriptor) {
     ResourceDescriptor resource = (ResourceDescriptor) contribution;
     log.info(String.format("Register resource '%s'", resource.getName()));
     String message =
         String.format(
             "Resource '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be accurate.",
             resource.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     // ensure path is absolute, consider that resource is in the war, and if not, user will have
     // to declare it
     // directly to the WRM endpoint
     String path = resource.getPath();
     if (path != null && !path.startsWith("/")) {
       resource.setUri("/" + path);
     }
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering resource '%s'", resource.getName()));
   } else if (contribution instanceof NegotiationDescriptor) {
     NegotiationDescriptor neg = (NegotiationDescriptor) contribution;
     log.info(String.format("Register negotiation for '%s'", neg.getTarget()));
     negReg.addContribution(neg);
     log.info(String.format("Done registering negotiation for '%s'", neg.getTarget()));
   } else {
     log.error(
         String.format(
             "Unknown contribution to the theme " + "styling service, extension point '%s': '%s",
             extensionPoint, contribution));
   }
 }