Package org.apache.myfaces.trinidadinternal.style.xml.parse

Examples of org.apache.myfaces.trinidadinternal.style.xml.parse.StyleNode


    // at this point the styles StyleNode[] can contain both Styles with
    // non-null selector or non-null name(aka alias). We only generate
    // the styles where getSelector is non-null.
    for (int i = 0; i < styles.length; i++)
    {
      StyleNode style = styles[i];

      if (style.getSelector() != null)
      {
        // Get the property string (properties are sorted so that
        // the order doesn't affect whether styles match).
        String propertyString = _getSortedPropertyString(style);

        // See if we already have a StyleNode with the same properties
        StyleNode[] matchingStyles = matchingStylesMap.get(propertyString);

        if (matchingStyles == null)
        {
          // If we don't already have matching StyleNodes, add this
          // StyleNode to the map.
          propertyStrings[i] = propertyString;
          matchingStyles = new StyleNode[1];
          matchingStyles[0] = style;
        }
        else
        {
          // If we already have matching StyleNodes, add this StyleNode
          // to the end of the list of matching StyleNodes.
          int length = matchingStyles.length;

          StyleNode[] newMatchingStyles = new StyleNode[length + 1];
          System.arraycopy(matchingStyles,
                           0,
                           newMatchingStyles,
                           0,
                           length);
          newMatchingStyles[length] = style;
          matchingStyles = newMatchingStyles;
        }

        // Rehash with the new value
        matchingStylesMap.put(propertyString, matchingStyles);
      }
    }

    // We'll start writing the CSS file now.  First
    // write out the header with a time stamp
    Date date = new Date();
    if (!compressStyles)
      out.println("/* This CSS file generated on " + date + " */");

    // Keep track of the number of selectors written out. The reason? IE has a 4095 limit,
    // and we want to warn when we get to that limit.
    int numberSelectorsWritten = 0;

    // This is the second pass in which we write out the style rules
    // Get the baseURI up front so we don't have to recalculate it every time we find
    // a property value that contains url() and need to resolve the uri.
    String baseURI = CSSUtils.getBaseSkinStyleSheetURI(styleSheetName);
    for (int i = 0; i < styles.length; i++)
    {
      StyleNode style = styles[i];
      String propertyString = propertyStrings[i];

      // We only write out styles for which we have a property string.
      // All other entries correspond to styles which don't have selectors -
      // or styles which will be rendered as a "matching" style.
      if (propertyString != null && !(propertyString.equals("")))
      {
        // Get all of the styles which share this property string.
        StyleNode[] matchingStyles = matchingStylesMap.get(propertyString);

        // Actually, we should always have at least one StyleNode here
        assert (matchingStyles != null);

        // determine if the current CSS file can fit all of the CSS selectors, or if a new
        // one will be needed.
        // TODO: figure out why we write both the uncompressed & compressed styles for styles
        // without a '|' character, shouldn't the uncompressed be enough on its own? This results
        // in some ugly code here.
        int stylesToBeWritten = 0;
        String[] selectors = new String[matchingStyles.length];
        String[] mappedSelectors = new String[matchingStyles.length];

        for (int j = 0; j < matchingStyles.length; j++)
        {
          selectors[j] = matchingStyles[j].getSelector();

          // We should always have a selector at this point
          assert (selectors[j] != null);

          mappedSelectors[j] = getMappedSelector(afSelectorMap,
                                                 namespacePrefixArray,
                                                 selectors[j]);

          if (compressStyles && (mappedSelectors[j].indexOf('|') == -1))
          {
            stylesToBeWritten += 2;
          }
          else
          {
            stylesToBeWritten++;
          }
        }

        if (numberSelectorsWritten + matchingStyles.length >= _MSIE_SELECTOR_LIMIT
          && TrinidadAgent.Application.IEXPLORER == context.getAgent().getAgentApplication())
        {
          out.println("/* The number of CSS selectors in this file is " +
                      numberSelectorsWritten + " */");
          out = writerFactory.createWriter();
          if (out == null)
          {
            return;
          }
          numberSelectorsWritten = 0;
        }

        // Write out all of the style selectors for this property string
        for (int j = 0; j < matchingStyles.length; j++)
        {
          String validFullNameSelector = null;

          // write out the full selector if we aren't compressing styles or
          // it doesn't have a '|' in the name which means it may be a user's public styleclass
          // and we don't want to compress those; we will also write out the compressed
          // version the public styleclasses in the next step.
          if (!compressStyles || (mappedSelectors[j].indexOf('|') == -1))
          {
            validFullNameSelector =
              getValidFullNameSelector(mappedSelectors[j], namespacePrefixArray);

            if (validFullNameSelector != null)
            {
              out.print(validFullNameSelector);
              numberSelectorsWritten++;
            }
          }



          if (compressStyles)
          {
            String shortSelector =
              getShortSelector(shortStyleClassMap, namespacePrefixArray, mappedSelectors[j]);

            // if the transformed full name is different than the shortSelector
            // then write out the shortSelector, too.
            if (shortSelector != null)
            {
              String validShortSelector =
                getValidFullNameSelector(shortSelector, namespacePrefixArray);

              // if we wrote out a full style, check to see if we need to write out the short, too.
              // if it is something different, write out the short, too.
              if (validFullNameSelector != null)
              {
                //Since validFullNameSelector is not null, we know we wrote out a full style
                // we write out a short style too in this case if it is different
                // example: .PublicStyleClass is written out fully even in compressed mode, but
                // it is different in compressed mode, so we write that out, too.
                if (!validFullNameSelector.equals(validShortSelector))
                {
                  out.print(',');
                  out.print(validShortSelector);
                  numberSelectorsWritten++;
                }
              }
              else
              {
                out.print(validShortSelector);
                numberSelectorsWritten++;
              }
            }
          }

          // Write out a separator between matching selectors
          if (j < (matchingStyles.length - 1))
            out.print(",");
        }

        // Now that we have written out the selectors, write out
        // the properties
        out.print(" {");

        // At this point, we could just write out the property string
        // that we already created, but this string contains the properties
        // in sorted order.  We prefer to attempt to preserve the order
        // of the properties as specified in the XSS document.  So,
        // we get the properties from the StyleNode object instead of
        // using the propertyString
        Iterable<PropertyNode> properties = style.getProperties();
        boolean first = true;

        for (PropertyNode property : properties)
        {
          String propName = property.getName();
View Full Code Here


    }

    if (selectorName != null)
    {
      // Create a styleNode that we will add to the IconNode.
      StyleNode styleNode =
        new StyleNode(null, // name
                      selectorName,
                      propertyNodeArray,
                      null, //TODO jmw trSkinPropertyNodes for icons
                      includeStyleNodes.toArray(new IncludeStyleNode[0]),
                      null, //TODO jmw includePropertyNodes for icons
View Full Code Here

    Set<String>               inhibitedProperties,
    boolean                   trTextAntialias,
    List<StyleNode>           styleNodeList)
  {

    StyleNode styleNode = _createStyleNode(selectorName, propertyNodeList, skinPropertyNodeList,
                                           trRuleRefList,
                                           includePropertyNodes,
                                           includeCompactPropertyNodes,
                                           inhibitedProperties,
                                           trTextAntialias);
View Full Code Here

      }
    }

    // create a StyleNode
    StyleNode styleNode =
      new StyleNode(name,
                    selector,
                    propertyArray,
                    skinPropertyNodeList.isEmpty() ?
                      null : skinPropertyNodeList.toArray(new PropertyNode[0]),
                    includeStyleNodes.toArray(new IncludeStyleNode[0]),
View Full Code Here

      }
    }

    // create a StyleNode
    StyleNode styleNode =
      new StyleNode(name,
                    selector,
                    propertyArray,
                    null,
                    includeStyleNodes.toArray(new IncludeStyleNode[0]),
                    null,
View Full Code Here

      StyleSheetNode styleSheet = styleSheets.next();
      Iterator<StyleNode> styles = styleSheet.getStyles();
      assert (styles != null);
      while (styles.hasNext())
      {
        StyleNode style = styles.next();
        String selector = style.getSelector();

        if (selector != null)
        {
          CSSGenerationUtils.getNamespacePrefixes(namespacePrefixesSet, selector);
        }
View Full Code Here

      StyleSheetNode styleSheet = styleSheets.next();
      Iterator<StyleNode> styles = styleSheet.getStyles();
      assert (styles != null);
      while (styles.hasNext())
      {
        StyleNode style = styles.next();
        String selector = style.getSelector();

        if (selector != null)
        {
          // If we've got a single style class selector, add it
          // to the map. Otherwise, we need to search the selector
          // for style classes.
          if (CSSGenerationUtils.isSingleStyleClassSelector(selector))
          {
            String styleClass = selector.substring(1);
            if (!map.containsKey(styleClass))
              map.put(styleClass, _getShortStyleClass(map.size()));
           
            if (style.isEmpty())
              emptySelectors.add(styleClass);
            else
              nonEmptySelectors.add(styleClass);
          }
          else
          {
            Iterator<String> styleClasses =
              CSSGenerationUtils.getStyleClasses(selector);

            if (styleClasses != null)
            {
              while (styleClasses.hasNext())
              {
                String styleClass = styleClasses.next();
               
                if (!map.containsKey(styleClass))
                  map.put(styleClass, _getShortStyleClass(map.size()));
               
                // Don't remove any styleclass that is referred to
                nonEmptySelectors.add(styleClass);
              }
            }
           
            int length = namespacePrefixes.length;
           
            for (int i=0; i < length; i++)
            {
              String nsPrefix = namespacePrefixes[i];
              Iterator<String> afSelectors =
                CSSGenerationUtils.getNamespacedSelectors(selector,
                                                          nsPrefix,
                                                          _STYLE_KEY_MAP);
              if (afSelectors != null)
              {
                boolean isFirst = true;
                while (afSelectors.hasNext())
                {
                  String styleClass = afSelectors.next();
                 
                  if (!map.containsKey(styleClass))
                    map.put(styleClass, _getShortStyleClass(map.size()));
                  if (isFirst && !afSelectors.hasNext() && style.isEmpty())
                  {
                    emptySelectors.add(styleClass);
                  }
                  else
                  {
View Full Code Here

      // Next, try getting the Style from the StyleSheetDocument
      StyleSheetDocument document = __getStyleSheetDocument();
      if (document == null)
        return null;

      StyleNode styleNode = null;

      if (isName)
      {
        styleNode = document.getStyleByName(context, id);
      }
      else
      {
        styleNode = document.getStyleBySelector(context, prefix + id);
      }

      if (styleNode == null)
      {
        map.put(id, _MISS);
        return null;
      }

      // Convert the styleNode into a Style
      style = new CSSStyle();

      // Add in the properties for the style
      Iterator<PropertyNode> e = styleNode.getProperties();
      while (e.hasNext())
      {
        PropertyNode property = e.next();
        String name = property.getName();
        String value = property.getValue();
View Full Code Here

     // and we want to warn when we get to that limit.
     int numberSelectorsWritten = 0;

    for (int i = 0; i < styles.length; i++)
    {
      StyleNode style = styles[i];

      if (style.getSelector() != null)
      {
        // Get the property string (properties are sorted so that
        // the order doesn't affect whether styles match).
        String propertyString = _getSortedPropertyString(style);

        // See if we already have a StyleNode with the same properties
        StyleNode[] matchingStyles = matchingStylesMap.get(propertyString);

        if (matchingStyles == null)
        {
          // If we don't already have matching StyleNodes, add this
          // StyleNode to the map.
          propertyStrings[i] = propertyString;
          matchingStyles = new StyleNode[1];
          matchingStyles[0] = style;
        }
        else
        {
          // If we already have matching StyleNodes, add this StyleNode
          // to the end of the list of matching StyleNodes.
          int length = matchingStyles.length;

          StyleNode[] newMatchingStyles = new StyleNode[length + 1];
          System.arraycopy(matchingStyles,
                           0,
                           newMatchingStyles,
                           0,
                           length);
          newMatchingStyles[length] = style;
          matchingStyles = newMatchingStyles;
        }

        // Rehash with the new value
        matchingStylesMap.put(propertyString, matchingStyles);
      }
    }

    // We'll start writing the CSS file now.  First
    // write out the header with a time stamp
    Date date = new Date();
    out.println("/* CSS file generated on " + date + " */");

    // This is the second pass in which we write out the style rules
    for (int i = 0; i < styles.length; i++)
    {
      StyleNode style = styles[i];
      String propertyString = propertyStrings[i];

      // We only write out styles for which we have a property string.
      // All other entries correspond to styles which don't have selectors -
      // or styles which will be rendered as a "matching" style.
      if (propertyString != null)
      {
        // Get all of the styles which share this property string.
        StyleNode[] matchingStyles = matchingStylesMap.get(propertyString);

        // Actually, we should always have at least one StyleNode here
        assert (matchingStyles != null);

        // Write out all of the style selectors for this property string
        for (int j = 0; j < matchingStyles.length; j++)
        {
          StyleNode matchingStyle = matchingStyles[j];
          String selector = matchingStyle.getSelector();

          // We should always have a selector at this point
          assert (selector != null);

          // map selectors, if needed
View Full Code Here

    }

    if (selectorName != null)
    {
      // Create a styleNode that we will add to the IconNode.
      StyleNode styleNode =
        new StyleNode(null, // name
                      selectorName,
                      propertyNodeArray,
                      null, //TODO jmw trSkinPropertyNodes for icons
                      includeStyleNodes.toArray(new IncludeStyleNode[0]),
                      null, //TODO jmw includePropertyNodes for icons
View Full Code Here

TOP

Related Classes of org.apache.myfaces.trinidadinternal.style.xml.parse.StyleNode

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.