private void loadDefaultStyles() { VirtualFile defaultsCSSFile = resolveDefaultsCssFile(); // Load the per SWC default styles first for (Iterator it = configuration.getDefaultsCssFiles().iterator(); it.hasNext(); ) { VirtualFile swcDefaultsCssFile = (VirtualFile) it.next(); // Make sure that we resolve things relative to the SWC. ThreadLocalToolkit.getPathResolver().addSinglePathResolver(0, swcDefaultsCssFile); processStyleSheet(swcDefaultsCssFile); ThreadLocalToolkit.getPathResolver().removeSinglePathResolver(swcDefaultsCssFile); } // Load the default styles next, so they can override the SWC defaults if (defaultsCSSFile != null) { // Only load the defaults if it's not a SwcFile. If it's // a SwcFile, it should have already been loaded. if (!(defaultsCSSFile instanceof SwcFile)) { processStyleSheet(defaultsCSSFile); } } else { ThreadLocalToolkit.log(new DefaultCSSFileNotFound()); } // Load the theme styles next, so they can override the defaults for (Iterator it = configuration.getThemeCssFiles().iterator(); it.hasNext(); ) { VirtualFile themeCssFile = (VirtualFile) it.next(); // Make sure that we resolve things in the theme relative // to the theme SWC first. ThreadLocalToolkit.getPathResolver().addSinglePathResolver(0, themeCssFile); processStyleSheet(themeCssFile); ThreadLocalToolkit.getPathResolver().removeSinglePathResolver(themeCssFile); } }
private Source createSource(String fileName, SourceCodeBuffer sourceCodeBuffer) { Source result = null; if (sourceCodeBuffer.getBuffer() != null) { String sourceCode = sourceCodeBuffer.toString(); if (configuration.keepGeneratedActionScript()) { try { FileUtil.writeFile(fileName, sourceCode); } catch (IOException e) { ThreadLocalToolkit.log( new VelocityException.UnableToWriteGeneratedFile(fileName, e.getMessage())); } } VirtualFile genFile = new TextFile(sourceCode, fileName, null, MimeMappings.AS, Long.MAX_VALUE); String shortName = fileName.substring(0, fileName.lastIndexOf('.')); result = new Source(genFile, "", shortName, null, false, false, false); result.setPathResolver(compilationUnit.getSource().getPathResolver()); Iterator iterator = implicitIncludes.iterator(); while (iterator.hasNext()) { VirtualFile virtualFile = (VirtualFile) iterator.next(); result.addFileInclude(virtualFile); } } return result; }
public void checkForUnusedTypeSelectors(Set defNames) { Iterator iterator = selectors.entrySet().iterator(); Set unqualifiedDefNames = new HashSet(); Iterator defNameIterator = defNames.iterator(); while (defNameIterator.hasNext()) { String defName = (String) defNameIterator.next(); unqualifiedDefNames.add(defName.replaceFirst(".*:", "")); } while (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); String styleName = (String) entry.getKey(); StyleDef styleDef = (StyleDef) entry.getValue(); String typeName = StyleDef.dehyphenize(styleName); if (styleDef.isTypeSelector() && localStyleTypeNames.contains(styleName) && !unqualifiedDefNames.contains(typeName) && !styleName.equals("global")) { if (configuration.showUnusedTypeSelectorWarnings()) { ThreadLocalToolkit.log( new UnusedTypeSelector( compilationUnit.getSource().getName(), styleDef.getLineNumber(), styleName)); } } } }
private void processStyleSheet(VirtualFile cssFile) { implicitIncludes.add(cssFile); try { FontManager fontManager = configuration.getFontsConfiguration().getTopLevelManager(); StyleSheet styleSheet = new StyleSheet(); styleSheet.checkDeprecation(configuration.showDeprecationWarnings()); styleSheet.parse( cssFile.getName(), cssFile.getInputStream(), ThreadLocalToolkit.getLogger(), fontManager); extractStyles(styleSheet, false); } catch (Exception exception) { CompilerMessage m = new ParseError(exception.getLocalizedMessage()); m.setPath(cssFile.getName()); ThreadLocalToolkit.log(m); } }
private VirtualFile resolveDefaultsCssFile() { VirtualFile defaultsCSSFile = configuration.getDefaultsCssUrl(); if (defaultsCSSFile == null) { PathResolver resolver = ThreadLocalToolkit.getPathResolver(); String version = configuration.getCompatibilityVersionString(); if (version != null) { defaultsCSSFile = resolver.resolve("defaults-" + version + ".css"); } if (defaultsCSSFile == null) { defaultsCSSFile = resolver.resolve("defaults.css"); } } return defaultsCSSFile; }
private String generateFontFaceRuleSourceName() { String genFileName; String genDir = configuration.getGeneratedDirectory(); if (genDir != null) { genFileName = genDir + File.separatorChar + "_FontFaceRules.as"; } else { genFileName = "_FontFaceRules.as"; } return genFileName; }
private String generateStyleSourceName(StyleDef styleDef) { String genFileName; String genDir = configuration.getGeneratedDirectory(); if (genDir != null) { genFileName = genDir + File.separatorChar + "_" + styleDef.getName() + "Style.as"; } else { genFileName = "_" + styleDef.getName() + "Style.as"; } return genFileName; }
public List processDependencies(Set defNames, ResourceContainer resources) { List extraSources = new ArrayList(); if (!fontFaceRules.isEmpty()) { // C: mixins in the generated FlexInit class are referred to by "names". that's why // extraClasses // is necessary. compilationUnit.extraClasses.add(_FONTFACERULES); compilationUnit.mixins.add(_FONTFACERULES); extraSources.add(generateFontFaceRules(resources)); } Set unqualifiedDefNames = new HashSet(); Iterator defNameIterator = defNames.iterator(); while (defNameIterator.hasNext()) { String defName = (String) defNameIterator.next(); unqualifiedDefNames.add(defName.replaceFirst(".*:", "")); } Iterator iterator = selectors.entrySet().iterator(); while (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); String styleName = (String) entry.getKey(); StyleDef styleDef = (StyleDef) entry.getValue(); String typeName = StyleDef.dehyphenize(styleName); if (!styleDef.isTypeSelector() || (unqualifiedDefNames.contains(typeName) || configuration.keepAllTypeSelectors()) || styleName.equals("global")) { String className = "_" + typeName + "Style"; // C: mixins in the generated FlexInit class are referred to by "names". that's why // extraClasses // is necessary. compilationUnit.extraClasses.add(className); compilationUnit.mixins.add(className); extraSources.add(generateStyleSource(styleDef, resources)); } } return extraSources; }
private Source generateStyleSource(StyleDef styleDef, ResourceContainer resources) { String genFileName = generateStyleSourceName(styleDef); Source styleSource = resources.findSource(genFileName); if (styleSource != null) { if (styleSource.getCompilationUnit() == null) { // if no compilationUnit, then we need to generate source so we can recompile. styleSource = null; } else { // C: it is safe to return because this method deals with per-app styles, like defaults.css // and themes. // ResourceContainer will not have anything if any of the theme files is touched. return styleSource; } } // load template Template template; try { template = VelocityManager.getTemplate(STYLEDEF_TEMPLATE); } catch (Exception exception) { ThreadLocalToolkit.log(new VelocityException.TemplateNotFound(STYLEDEF_TEMPLATE)); return null; } SourceCodeBuffer out = new SourceCodeBuffer(); try { VelocityUtil util = new VelocityUtil(TEMPLATE_PATH, configuration.debug(), out, null); VelocityContext vc = VelocityManager.getCodeGenContext(util); vc.put(STYLEDEF_KEY, styleDef); template.merge(vc, out); } catch (Exception e) { ThreadLocalToolkit.log( new VelocityException.GenerateException( compilationUnit.getSource().getRelativePath(), e.getLocalizedMessage())); return null; } return resources.addResource(createSource(genFileName, out)); }