From adffaces-commits-return-1323-apmail-incubator-adffaces-commits-archive=incubator.apache.org@incubator.apache.org Fri Nov 17 01:36:22 2006 Return-Path: Delivered-To: apmail-incubator-adffaces-commits-archive@locus.apache.org Received: (qmail 35258 invoked from network); 17 Nov 2006 01:36:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Nov 2006 01:36:21 -0000 Received: (qmail 74261 invoked by uid 500); 17 Nov 2006 01:36:31 -0000 Delivered-To: apmail-incubator-adffaces-commits-archive@incubator.apache.org Received: (qmail 74204 invoked by uid 500); 17 Nov 2006 01:36:30 -0000 Mailing-List: contact adffaces-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: adffaces-dev@incubator.apache.org Delivered-To: mailing list adffaces-commits@incubator.apache.org Received: (qmail 74195 invoked by uid 99); 17 Nov 2006 01:36:30 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Nov 2006 17:36:30 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Nov 2006 17:36:19 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id DF9541A9846; Thu, 16 Nov 2006 17:35:47 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r476022 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style: cache/FileSystemStyleCache.java util/CSSGenerationUtils.java Date: Fri, 17 Nov 2006 01:35:47 -0000 To: adffaces-commits@incubator.apache.org From: jwaldman@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061117013547.DF9541A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jwaldman Date: Thu Nov 16 17:35:46 2006 New Revision: 476022 URL: http://svn.apache.org/viewvc?view=rev&rev=476022 Log: ADFFACES-250 Need to be able to have other prefixes in css file besides af|. We now allow any namespace prefix in our xss/css files and the parsing will work. Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java?view=diff&rev=476022&r1=476021&r2=476022 ============================================================================== --- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java (original) +++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/cache/FileSystemStyleCache.java Thu Nov 16 17:35:46 2006 @@ -1,12 +1,12 @@ /* * Copyright 2000-2006 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,8 +23,10 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; + import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.Locale; @@ -71,9 +73,9 @@ * @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/style/cache/FileSystemStyleCache.java#0 $) $Date: 10-nov-2005.18:58:54 $ * @author The Oracle ADF Faces Team */ -// -= Simon Lessard =- -// TODO: Synchronization does not seem to be needed since there's -// synchronized blocks in the code, using HashMap hence +// -= Simon Lessard =- +// TODO: Synchronization does not seem to be needed since there's +// synchronized blocks in the code, using HashMap hence // looks like a better choice than Hashtable. public class FileSystemStyleCache implements StyleProvider { @@ -353,6 +355,7 @@ Hashtable entryCache = null; StyleSheetDocument document = null; Map shortStyleClassMap = null; + String[] namespacePrefixes = null; boolean checkModified = context.checkStylesModified(); @@ -374,6 +377,7 @@ _entryCache = null; _document = null; _shortStyleClassMap = null; + _namespacePrefixes = null; } // We get references to our two caches (the "normal" cache, @@ -399,11 +403,13 @@ entryCache = _entryCache; // Get the document up front too. + // this sets up _shortStyleClassMap and _namespacePrefixes document = _getStyleSheetDocument(context); if (document == null) return null; shortStyleClassMap = _shortStyleClassMap; + namespacePrefixes = _namespacePrefixes; } // Look up the style sheet @@ -429,6 +435,7 @@ key, entryCache, shortStyleClassMap, + namespacePrefixes, checkModified); } @@ -470,6 +477,7 @@ Key key, Hashtable entryCache, Map shortStyleClassMap, + String[] namespacePrefixes, boolean checkModified ) { @@ -486,6 +494,7 @@ document, styles, shortStyleClassMap, + namespacePrefixes, checkModified); _LOG.fine("Finished processing stylesheet {0}", uri); @@ -547,7 +556,7 @@ // Entries with the same style sheet derivation are compatible. // Get the style sheet derivation list. Iterator e = document.getStyleSheets(context); - // -= Simon Lessard =- + // -= Simon Lessard =- // TODO: Check if synchronization is truly required Vector v = _copyIterator(e); StyleSheetNode[] styleSheets; @@ -586,8 +595,10 @@ if (_document == null) _document = document; + // Re-initialize our Array of namespace prefixes that are in the selectors // Re-initialize our Map of short style class names - _shortStyleClassMap = _getShortStyleClassMap(context, _document); + _namespacePrefixes = _getNamespacePrefixes(context, _document); + _shortStyleClassMap = _getShortStyleClassMap(context, _document, _namespacePrefixes); return document; } @@ -607,7 +618,7 @@ return null; } - // -= Simon Lessard =- + // -= Simon Lessard =- // TODO: Check if synchronization is truly required Vector v = new Vector(); while (e.hasNext()) @@ -626,6 +637,7 @@ StyleSheetDocument document, StyleNode[] styles, Map shortStyleClassMap, + String[] namespacePrefixes, boolean checkModified) { // Get a name for the new style sheet @@ -686,7 +698,7 @@ styles, out, shortStyleClassMap, - _NS_PREFIX_ARRAY, + namespacePrefixes, _STYLE_KEY_MAP ); @@ -841,10 +853,40 @@ return source + target; } + // Create an array of all the namespace prefixes in the xss/css file. E.g., "af|" or "tr|" + private static String[] _getNamespacePrefixes( + StyleContext context, + StyleSheetDocument document) + { + + assert (document != null); + Iterator styleSheets = document.getStyleSheets(context); + assert (styleSheets != null); + Set namespacePrefixesSet = new HashSet(); + while (styleSheets.hasNext()) + { + StyleSheetNode styleSheet = styleSheets.next(); + Iterator styles = styleSheet.getStyles(); + assert (styles != null); + while (styles.hasNext()) + { + StyleNode style = styles.next(); + String selector = style.getSelector(); + + if (selector != null) + { + CSSGenerationUtils.getNamespacePrefixes(namespacePrefixesSet, selector); + } + } + } + return namespacePrefixesSet.toArray(_EMPTY_STRING_ARRAY); + } + // Create the map of full style classes to short style classes private static Map _getShortStyleClassMap( StyleContext context, - StyleSheetDocument document) + StyleSheetDocument document, + String[] namespacePrefixes) { // Use a HashMap to avoid unnecessary synchronization of Hashtable Map map = new HashMap(); @@ -879,9 +921,9 @@ } else { - Iterator styleClasses = + Iterator styleClasses = CSSGenerationUtils.getStyleClasses(selector); - + if (styleClasses != null) { while (styleClasses.hasNext()) @@ -892,13 +934,12 @@ map.put(styleClass, _getShortStyleClass(map.size())); } } - - // now go through the selectors and get the list of selectors - // with the namespace prefix and put those into the shortend map - int numNSPrefixes = _NS_PREFIX_ARRAY.length; - for (int prefixIndex=0; prefixIndex< numNSPrefixes; prefixIndex++) + + int length = namespacePrefixes.length; + + for (int i=0; i < length; i++) { - String nsPrefix = _NS_PREFIX_ARRAY[prefixIndex]; + String nsPrefix = namespacePrefixes[i]; Iterator afSelectors = CSSGenerationUtils.getNamespacedSelectors(selector, nsPrefix, @@ -908,7 +949,7 @@ while (afSelectors.hasNext()) { String styleClass = afSelectors.next(); - + if (!map.containsKey(styleClass)) map.put(styleClass, _getShortStyleClass(map.size())); } @@ -1287,7 +1328,7 @@ // Our local Style maps - // -= Simon Lessard =- + // -= Simon Lessard =- // TODO: Check if synchronization is truly needed private Hashtable _selectorMap; private Hashtable _classMap; @@ -1380,6 +1421,7 @@ // Map which maps from full style class names to // our compressed names. private Map _shortStyleClassMap; + private String[] _namespacePrefixes; // Constants @@ -1392,7 +1434,7 @@ // Table of shared FileSystemStyleCaches, hashed by path. // Note on table size: We don't expect to have very many instances // running in a single VM - table can be small. - private static final Hashtable _sSharedCaches = + private static final Hashtable _sSharedCaches = new Hashtable(19); // Java name for UTF8 encoding @@ -1409,7 +1451,7 @@ // Prefix to use for short style classes private static final String _SHORT_CLASS_PREFIX = "x"; - // -= Simon Lessard =- + // -= Simon Lessard =- // TODO: Check if synchronization is truly needed private static final Hashtable _sCanonicalPaths = new Hashtable(19); private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileSystemStyleCache.class); @@ -1422,7 +1464,7 @@ // selector names to the css file. // jmw. @todo Need to find a better spot for this, like the skin? private static final Map _STYLE_KEY_MAP; - + static { _STYLE_KEY_MAP = new HashMap(); @@ -1531,7 +1573,7 @@ "af|panelTabbed::tab-selected A"); } - private static final String _AF_STYLE_NAMESPACE = "af|"; - private static String[] _NS_PREFIX_ARRAY = new String[] {_AF_STYLE_NAMESPACE}; + + private static final String[] _EMPTY_STRING_ARRAY = new String[0]; } Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java?view=diff&rev=476022&r1=476021&r2=476022 ============================================================================== --- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java (original) +++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/util/CSSGenerationUtils.java Thu Nov 16 17:35:46 2006 @@ -457,6 +457,43 @@ return afSelectorList.iterator(); } + + /** + * Add to the namespacePrefixes Set any namespace prefixes found in this selector. + * @param namespacePrefixes + * @param selector + */ + public static void getNamespacePrefixes( + Set namespacePrefixes, + String selector) + { + + int length = selector.length(); + int startSubstringIndex = 0; + // Loop through each character of the selector looking for namespace prefixes. + for (int i = 0; i < length; i++) + { + char c = selector.charAt(i); + if (c == '|') + { + String prefix = selector.substring(startSubstringIndex, i+1); + startSubstringIndex = i+1; + // protect against just | in the prefix by checking length. + if (prefix.length() > 1) + namespacePrefixes.add(prefix); + } + else if(!_isStyleClassTerminator(c)) + { + // keep going if it isn't a terminating character + } + else + { + // update the startSubstring index. + startSubstringIndex = i+1; + } + } + return; + } /** * Called from getNamespacedSelectors. @@ -1151,6 +1188,7 @@ _BUILT_IN_PSEUDO_CLASSES.add(":active"); _BUILT_IN_PSEUDO_CLASSES.add(":focus"); } + private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(CSSGenerationUtils.class); }