brandable = false;
} else {
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
// one so set the name to null so that it fails
// further on.
normalizedName = null;
}
}
} else if (url.containsHostRelativePath()) {
// The base URL must have been host relative so the
// resolved URL is also host relative and so it must
// belong in the current project.
//
// Note: This relies on the MarinerURL detecting when a
// relative path is invalid, i.e. contains .. that attempt
// to take it above the root URL. Apparently there is a
// problem with that.
normalizedName = url.getExternalForm();
} else {
throw new IllegalStateException("Resolving " +
unprefixedName +
" against " + baseURL + " resulted in " +
url.getExternalForm() + " which is not absolute");
}
// If the resulting URL could not be mapped to a project
// relative URL, because it moved to another project, then
// fail.
if (normalizedName == null) {
throw new IllegalStateException(
"Document relative path " +
"cannot move outside project, when '" +
unprefixedName + "' is resolved relative to '" +
baseURL.getExternalForm() + "' the result '" +
url.getExternalForm() +
"' is not within project '" + containingProject +
"'");
}
// The normalized project is the same as the containing