Skip to content

Commit

Permalink
TEIIDDES-1118 - additional fix for handling windows UNC path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Sep 14, 2012
1 parent 1d3be2f commit 618ebca
Showing 1 changed file with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
Expand All @@ -27,6 +28,7 @@
import net.jcip.annotations.ThreadSafe;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -558,7 +560,7 @@ void synchronizeModelEntry( final IProgressMonitor monitor ) {
}
}

if (importedEntry == null) importedEntry = getVdb().addModelEntry(name, monitor);
if (importedEntry==null && name!=null) importedEntry = getVdb().addModelEntry(name, monitor);
imports.add(importedEntry);
importedEntry.importedBy.add(this);
}
Expand All @@ -580,15 +582,56 @@ private IFile getFile(Resource resource) {
IFile resultFile = null;
if (resource != null)
{
URI uri = resource.getURI();
// Get the list of names of projects in the workspace
IProject[] allProj = ModelerCore.getWorkspace().getRoot().getProjects();
List<String> projNameList = new ArrayList();
for(int i=0; i<allProj.length; i++) {
projNameList.add(allProj[i].getName());
}

// Find the IFile for the supplied Resource
URI uri = resource.getURI(); // URI of the resource
uri = validateURI(uri,projNameList); // Validate the URI - ensure it starts at the project
String fileString = URI.decode(uri.path());

resultFile = ModelerCore.getWorkspace().getRoot().getFileForLocation(new Path(fileString));

// Find the IFile resource in the workspace
IResource iResc = ModelerCore.getWorkspace().getRoot().findMember(new Path(fileString));
if(iResc instanceof IFile) {
resultFile = (IFile)iResc;
}
}
return resultFile;
}

/*
* Validate method, verifies that the supplied URI starts with the modelProject segment. If not, the leading
* segments are stripped off until it starts with the modelProject.
* @param uri the supplied uri
* @param projectNames the existing project names in the workspace
* @return the rewritten uri
*/
private URI validateURI(URI uri, List<String> projectNames) {
// Get all URI segments
String[] segments = uri.segments();
// valid segments should be 2 or more - project plus model
if(segments.length<2) return uri;

// Create new URI with all segments removed
URI newUri = uri.trimSegments(segments.length);

// start with first segment, looking for project
// If the first segment is not a project, strip it
if(!projectNames.contains(segments[0])) {
for(int i=1; i<segments.length; i++) {
newUri = newUri.appendSegment(segments[i]);
}
// recursively strips until it gets to the project
return validateURI(newUri,projectNames);
// If the first segment is a project, URI is valid - return original
} else {
return uri;
}
}

/**
* {@inheritDoc}
Expand Down

0 comments on commit 618ebca

Please sign in to comment.