Logo Search packages:      
Sourcecode: libloader version File versions  Download package

static String org::jfree::resourceloader::loader::LoaderUtils::mergePaths ( final String  parent,
final String  child 
) throws ResourceKeyCreationException [inline, static]

Merges two paths. A path is recognized as an absolute path, if it has an URL-schema definition attached. A parent is recognized as container path (a directory, in the common language), if it ends with a slash.

Todo: Introduce escaping using "\" as escape char.

Parameters:
parent
child
Returns:
Exceptions:
ResourceKeyCreationException

Definition at line 63 of file LoaderUtils.java.

References parseName().

Referenced by org::jfree::resourceloader::loader::zip::ZipResourceLoader::deriveKey(), and org::jfree::resourceloader::loader::resource::ClassloaderResourceLoader::deriveKey().

  {
    final int childPrefix = child.indexOf("://");
    if (childPrefix > 0)
    {
      return child;
    }

    final String parentResource;
    final String parentPrefix;
    final int parentPrefixPos = parent.indexOf("://");
    if (parentPrefixPos > 0)
    {
      parentResource = parent.substring(parentPrefixPos + 3);
      parentPrefix = parent.substring(0, parentPrefixPos + 3);
    }
    else
    {
      parentResource = parent;
      parentPrefix = "";
    }

    final List parentList;
    if (parentResource.endsWith("/"))
    {
      parentList = parseName(parentResource, false);
    }
    else
    {
      parentList = parseName(parentResource, true);
    }
    // construct the full name ...
    parentList.addAll(parseName(child, false));
    // and normalize it by removing all '.' and '..' elements.
    final ArrayList normalizedList = new ArrayList();
    for (int i = 0; i < parentList.size(); i++)
    {
      final String o = (String) parentList.get(i);
      if (".".equals(o))
      {
        continue;
      }
      if ("..".equals(o))
      {
        if (normalizedList.isEmpty() == false)
        {
          // remove last element
          normalizedList.remove(normalizedList.size() - 1);
        }
      }
      else
      {
        normalizedList.add(o);
      }
    }

    if (normalizedList.isEmpty())
    {
      throw new ResourceKeyCreationException("Unable to build a valid key.");
    }
    final StringBuffer buffer = new StringBuffer();
    buffer.append(parentPrefix);

    for (int i = 0; i < normalizedList.size(); i++)
    {
      final String s = (String) normalizedList.get(i);
      if (i > 0)
      {
        buffer.append('/');
      }
      buffer.append(s);
    }
    return buffer.toString();
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index