Package org.apache.myfaces.trinidad.share.io

Examples of org.apache.myfaces.trinidad.share.io.NameResolver


    ParseContext context,
    String       sourceName,
    Class<?>     expectedType) throws IOException, SAXException
  {
    // Step 1. Find the name resolver.
    NameResolver resolver = getResolver(context);
    if (resolver == null)
    {
      _log(context, "Internal error: couldn't find NameResolver");
      return null;
    }

    // Step 2. Find an InputStreamProvider.  Mark a dependency on the base
    // provider (if necessary)
    InputStreamProvider provider = resolver.getProvider(sourceName);
    InputStreamProvider baseProvider = getInputStreamProvider(context);
    if (baseProvider instanceof CachingInputStreamProvider)
    {
      // set the dependency; hasSourceChanged also checks if the
      // dependencies have changed
      ((CachingInputStreamProvider) baseProvider).addCacheDependency(provider);
    }

    // Step 3. Detect if this will be a circular include.
    ArrayList<Object> list =
      (ArrayList<Object>) context.getProperty(_SHARE_NAMESPACE, "_includeStack");
    Object identifier = provider.getIdentifier();
   
    if ((list != null) && (list.contains(identifier)))
    {
      // =-=AEW Just logging an error isn't really enough - the include
      // will fail, but parsing continues.  So, instead, we throw
      // an exception...
      throw new SAXParseException(_LOG.getMessage(
        "CIRCULAR_INCLUDE_DETECTED", sourceName), context.getLocator());
    }

    // Step 4. Try to get a cached version
    // =-=jmw I don't see when this cached gets a non-null value other than if the same file
    // is included twice.
    Object cached = provider.getCachedResult();
    if ((cached != null) && expectedType.isInstance(cached))
      return cached;


    // Step 5. Set up the new context;  first, clone the original
    ParseContext newContext = (ParseContext) context.clone();

    // Add the current identifer to the stack (used for detecting
    // circular includes) placed on the ParseContext
    if (list == null)
      list = new ArrayList<Object>();
    else
      list = (ArrayList<Object>) list.clone();
    list.add(identifier);
    newContext.setProperty(_SHARE_NAMESPACE, "_includeStack", list);


    ParserManager parserManager =context.getParserManager();
    TreeBuilder builder = new TreeBuilder(parserManager,
                                          expectedType);
    InputStream stream = provider.openInputStream();

    try
    {
      InputSource source = new InputSource(stream);
      source.setSystemId(sourceName);

      setResolver(newContext, resolver.getResolver(sourceName));
      setInputStreamProvider(newContext, provider);

      // Step 6. Parse!
      Object value = builder.parse(context.getXMLProvider(),
                                   source,
View Full Code Here


  /**
   * Gets the NameResolver stored on the ParseContext.
   */
  static public NameResolver getResolver(ParseContext context)
  {
    NameResolver source = (NameResolver)
      context.getProperty(_SHARE_NAMESPACE, "_nameResolver");
    if (source == null)
      source = new DefaultNameResolver(null, null);

    return source;
View Full Code Here

    )
  {
    // In order to create the StyleSheetEntry, we need to locate and
    // parse the style sheet file.  We use a NameResolver to use to
    // find the style sheet.
    NameResolver resolver = _getNameResolver(context, styleSheetName);
    if (resolver == null)
      return null;

    // a private static inner class to store the document, icon, and skin properties
    // =-=jmw @todo Should I just create a StyleSheetEntry directly,
View Full Code Here

    if ((localStylesDir == null))
    {
      _LOG.warning(_STYLES_DIR_ERROR);
      return null;
    }
    NameResolver resolver = null;

    try
    {
      resolver =
          _getNameResolverForStyleSheetFile(context, localStylesDir, styleSheetName);
View Full Code Here

    if (provider != null)
      return StyleSheetNameResolver.createResolver(context, localStylesDir, provider);

    // If we still can't locate the file at this point, then look for a custom
    // NameResolver specified as a META-INF\services.
    NameResolver servicesNameResolver = _loadNameResolverFromServices(filename);
    if (servicesNameResolver != null)
    {
      if (_LOG.isFine())
      {
        _LOG.fine("Using the InputStreamProvider from META-INF\\services");
View Full Code Here

    // We don't want to check services every time, so instead store it on the applicationMap.
    FacesContext context = FacesContext.getCurrentInstance();
    Map<String, Object> appMap = context.getExternalContext().getApplicationMap();

    // Is it stored on the application map already? If so, use it.
    NameResolver savedResolver = (NameResolver)appMap.get(_SERVICES_RESOLVER_KEY);
    if (savedResolver != null)
      return savedResolver;

    List<NameResolver> resolvers = ClassLoaderUtils.getServices(
                                      _NAME_RESOLVER_CLASS_NAME);
View Full Code Here

        _provider = null;
        __setDocument(null);

        // Get a new NameResolver
        String name = getStyleSheetName();
        NameResolver resolver = _getNameResolver(context, name);
        if (resolver != null)
        {
         

          // Recreate the StyleSheetEntry for the styleSheet using the new NameResolver
View Full Code Here

    String        sourceName,
    Class<?>      expectedType)
    throws IOException, ParseException
  {
    // Step 1. Find the name resolver 
    NameResolver resolver = XMLUtils.getResolver(context);
    if (resolver == null)
    {
      if (_LOG.isWarning())
         _LOG.warning("Internal error: couldn't find NameResolver");
     
      return Collections.emptyList();
    }
   
    // Step 2. Find an InputStreamProvider. Mark a dependency on the base provider (if necessary)
    InputStreamProvider importProvider = resolver.getProvider(sourceName);
    InputStreamProvider baseProvider = XMLUtils.getInputStreamProvider(context);
    if (baseProvider instanceof CachingInputStreamProvider)
    {
      // important: hasSourceChanged takes into account this dependency
      ((CachingInputStreamProvider)baseProvider).addCacheDependency(importProvider);
    }
   
    // Step 3. Detect if this will be a circular include
    ArrayList<Object> list = (ArrayList<Object>) context.getProperty(_SHARE_NAMESPACE,
                                                                     _INCLUDE_STACK);
    Object identifier = importProvider.getIdentifier();
   
    if ((list != null) && (list.contains(identifier)))
    {
      // Just logging an error isn't really enough - the include
      // will fail, but parsing continues and you'll get a stack overflow.  So, instead, we throw
      // an exception...
     throw new ParseException(_LOG.getMessage(
      "CIRCULAR_INCLUDE_DETECTED", sourceName), 0);
    }

    // Step 4. Try to get a cached version
    // =-=jmw  I don't know when the cached returns non-null other than when
    // the same import is included twice. This step (and Step 7) might not be worth it.
    // comment out caching code
    //Object cached = importProvider.getCachedResult();
    //if ((cached != null) && expectedType.isInstance(cached))
    //{
     //return (List<List<SkinStyleSheetNode>>)cached;
    //}
   
    // Step 5. Set up the new context; first, clone the original
    ParseContext newContext = (ParseContext)context.clone();
   
    // Add the current identifier to the stack (used for detecting circular includes)
    // placed on the ParseContext
    // cloning ParseContext does a shallow copy. It doesn't copy this list.
    if (list == null)
      list = new ArrayList<Object>();
    else
      list = new ArrayList<Object>(list);
    list.add(identifier);
    newContext.setProperty(_SHARE_NAMESPACE, _INCLUDE_STACK, list);
   
    InputStream stream = importProvider.openInputStream();
    try
    {

      // Store a resolver relative to the file we're about to parse. This will be used for imports.
      // Store the inputStreamProvider on the context;
      // this will be used to get the document's timestamp later on
      XMLUtils.setResolver(newContext, resolver.getResolver(sourceName));
      XMLUtils.setInputStreamProvider(newContext, importProvider);

      // PARSE!
      // create a SkinStyleSheetNode
      // (contains a namespaceMap and a List of SkinSelectorPropertiesNodes
View Full Code Here

   * resolver that can only support absolute names.
   * @param name the name of the target
   */
  final public NameResolver getRootResolver(String name)
  {
    NameResolver resolver = getResolver(name);
    if (resolver instanceof DefaultNameResolver)
    {
      ((DefaultNameResolver) resolver).__setRootResolver(null);
    }

View Full Code Here

   * resolver that can only support absolute names.
   * @param name the name of the target
   */
  public NameResolver getResolver(String name)
  {
    NameResolver resolver = _base.getResolver(name);
    return new CachingNameResolver(resolver,
                                   _cachedFiles,
                                   _msBetweenChecks);
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.trinidad.share.io.NameResolver

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.