You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2006/11/17 01:35:47 UTC
svn commit: r476022 - in
/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style:
cache/FileSystemStyleCache.java util/CSSGenerationUtils.java
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<Object, Entry> entryCache = null;
StyleSheetDocument document = null;
Map<String, String> 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<Object, Entry> entryCache,
Map<String, String> 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<StyleSheetNode> e = document.getStyleSheets(context);
- // -= Simon Lessard =-
+ // -= Simon Lessard =-
// TODO: Check if synchronization is truly required
Vector<StyleSheetNode> 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<StyleNode> v = new Vector<StyleNode>();
while (e.hasNext())
@@ -626,6 +637,7 @@
StyleSheetDocument document,
StyleNode[] styles,
Map<String, String> 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<StyleSheetNode> styleSheets = document.getStyleSheets(context);
+ assert (styleSheets != null);
+ Set<String> namespacePrefixesSet = new HashSet<String>();
+ while (styleSheets.hasNext())
+ {
+ 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);
+ }
+ }
+ }
+ return namespacePrefixesSet.toArray(_EMPTY_STRING_ARRAY);
+ }
+
// Create the map of full style classes to short style classes
private static Map<String, String> _getShortStyleClassMap(
StyleContext context,
- StyleSheetDocument document)
+ StyleSheetDocument document,
+ String[] namespacePrefixes)
{
// Use a HashMap to avoid unnecessary synchronization of Hashtable
Map<String, String> map = new HashMap<String, String>();
@@ -879,9 +921,9 @@
}
else
{
- Iterator<String> styleClasses =
+ Iterator<String> 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<String> 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<String, Style> _selectorMap;
private Hashtable<String, Style> _classMap;
@@ -1380,6 +1421,7 @@
// Map which maps from full style class names to
// our compressed names.
private Map<String, String> _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<String, StyleProvider> _sSharedCaches =
+ private static final Hashtable<String, StyleProvider> _sSharedCaches =
new Hashtable<String, StyleProvider>(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<String, String> _sCanonicalPaths = new Hashtable<String, String>(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<String, String> _STYLE_KEY_MAP;
-
+
static
{
_STYLE_KEY_MAP = new HashMap<String, String>();
@@ -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<String> 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);
}