unprefixedName = name;
}
MarinerURL url = new MarinerURL(unprefixedName);
RuntimeProject normalizedProject;
String normalizedName = null;
if (url.isAbsolute()) {
// An absolute URL so try and find the project, look in the
// containing project first and then in the others. If the project
// was not already known then defer loading it until the policy
// has been retrieved as that will reduce the number of times that
// the remote server gets hit.
RuntimeProject project = projectManager.queryProject(unprefixedName,
containingProject);
if (project == null) {
// Assume that it is in the global project for now.
project = projectManager.getGlobalProject();
}
normalizedProject = project;
normalizedName = normalizeURLToName(normalizedProject, url);
// Specifying an absolute URL in the input means that it is not
// brandable.
brandable = false;
} else {
if (url.getPathType() == MarinerURL.HOST_RELATIVE_PATH) {
// A host relative path, i.e. a project relative reference.
normalizedProject = containingProject;
normalizedName = unprefixedName;
} else {
// Resolve against the base URL, the result must be either
// absolute, or host relative.
url = new MarinerURL(baseURL, url);
if (url.isAbsolute()) {
// Get the project for the url.
String urlAsString = url.getExternalForm();
RuntimeProject project =
projectManager.getProject(urlAsString, null);
// Now check to make sure that the resulting URL is still
// within the same project as it started from as document
// relative paths cannot move outside the project.
if (containingProject.getContainsOrphans()) {
// The project is either local default or global
// project so the policies they contain are defined by
// exclusion so in order to determine whether a policy
// is in one of these it is necessary to check to see
// if it is in another project.
if (project == null) {
// The referenced policy is still in the global
// project so use the abolute URL as the normalized
// name.
normalizedName = urlAsString;
} else {
// The referenced policy is in another project which
// is invalid, so set the name to null so an
// appropriate exception will be thrown below.
normalizedName = null;
}
} else {
if (project == containingProject ||
containingProject.extendsProject(project)) {
// Ask the project that contains it to make the
// URL project relative.
normalizedName = project.makeProjectRelativePath(
url, true);
} else {
// The project is not the same as the containing
// one and does is not extended by the containing