public class PHPProject implements IProjectNature, PHPElement {
protected IProject fProject;
- protected List loadPathEntries;
- protected boolean scratched;
+ // protected IndexFileReader fIndexManager;
+ protected List fLoadPathEntries;
+ protected boolean fScratched;
public PHPProject() {
}
+ public void addLoadPathEntry(IProject anotherPHPProject) {
+ fScratched = true;
+
+ LoadPathEntry newEntry = new LoadPathEntry(anotherPHPProject);
+ getLoadPathEntries().add(newEntry);
+ }
+
public void configure() throws CoreException {
// get project description and then the associated build commands
IProjectDescription desc = fProject.getDescription();
public void deconfigure() throws CoreException {
}
- public IProject getProject() {
- return fProject;
- }
-
- protected IProject getProject(String name) {
- return PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
- }
-
- public void setProject(IProject aProject) {
- fProject = aProject;
- }
-
- public void addLoadPathEntry(IProject anotherPHPProject) {
- scratched = true;
-
- LoadPathEntry newEntry = new LoadPathEntry(anotherPHPProject);
- getLoadPathEntries().add(newEntry);
- }
-
- public void removeLoadPathEntry(IProject anotherPHPProject) {
- Iterator entries = getLoadPathEntries().iterator();
- while (entries.hasNext()) {
- LoadPathEntry entry = (LoadPathEntry) entries.next();
- if (entry.getType() == LoadPathEntry.TYPE_PROJECT
- && entry.getProject().getName().equals(anotherPHPProject.getName())) {
- getLoadPathEntries().remove(entry);
- scratched = true;
- break;
- }
- }
- }
-
public List getLoadPathEntries() {
- if (loadPathEntries == null) {
+ if (fLoadPathEntries == null) {
loadLoadPathEntries();
}
- return loadPathEntries;
- }
-
- public List getReferencedProjects() {
- List referencedProjects = new ArrayList();
-
- Iterator iterator = getLoadPathEntries().iterator();
- while (iterator.hasNext()) {
- LoadPathEntry pathEntry = (LoadPathEntry) iterator.next();
- if (pathEntry.getType() == LoadPathEntry.TYPE_PROJECT)
- referencedProjects.add(pathEntry.getProject());
- }
-
- return referencedProjects;
- }
-
- protected void loadLoadPathEntries() {
- loadPathEntries = new ArrayList();
-
- IFile loadPathsFile = getLoadPathEntriesFile();
-
- XMLReader reader = null;
- try {
- reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
- reader.setContentHandler(getLoadPathEntriesContentHandler());
- reader.parse(new InputSource(loadPathsFile.getContents()));
- } catch (Exception e) {
- //the file is nonextant or unreadable
- }
+ return fLoadPathEntries;
}
protected ContentHandler getLoadPathEntriesContentHandler() {
return new ContentHandler() {
- public void characters(char[] arg0, int arg1, int arg2)
- throws SAXException {
+ public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
}
public void endDocument() throws SAXException {
}
- public void endElement(String arg0, String arg1, String arg2)
- throws SAXException {
+ public void endElement(String arg0, String arg1, String arg2) throws SAXException {
}
public void endPrefixMapping(String arg0) throws SAXException {
}
- public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
- throws SAXException {
+ public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
}
- public void processingInstruction(String arg0, String arg1)
- throws SAXException {
+ public void processingInstruction(String arg0, String arg1) throws SAXException {
}
public void setDocumentLocator(Locator arg0) {
public void startDocument() throws SAXException {
}
- public void startElement(
- String namespaceURI,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if ("pathentry".equals(qName))
if ("project".equals(atts.getValue("type"))) {
IPath referencedProjectPath = new Path(atts.getValue("path"));
- IProject referencedProject =
- getProject(referencedProjectPath.lastSegment());
- loadPathEntries.add(new LoadPathEntry(referencedProject));
+ IProject referencedProject = getProject(referencedProjectPath.lastSegment());
+ fLoadPathEntries.add(new LoadPathEntry(referencedProject));
}
}
- public void startPrefixMapping(String arg0, String arg1)
- throws SAXException {
+ public void startPrefixMapping(String arg0, String arg1) throws SAXException {
}
};
}
return fProject.getFile(".loadpath");
}
- public void save() throws CoreException {
- if (scratched) {
- InputStream xmlPath =
- new ByteArrayInputStream(getLoadPathXML().getBytes());
- IFile loadPathsFile = getLoadPathEntriesFile();
- if (!loadPathsFile.exists())
- loadPathsFile.create(xmlPath, true, null);
- else
- loadPathsFile.setContents(xmlPath, true, false, null);
-
- scratched = false;
- }
- }
-
protected String getLoadPathXML() {
StringBuffer buffer = new StringBuffer();
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><loadpath>");
- Iterator pathEntriesIterator = loadPathEntries.iterator();
+ Iterator pathEntriesIterator = fLoadPathEntries.iterator();
while (pathEntriesIterator.hasNext()) {
LoadPathEntry entry = (LoadPathEntry) pathEntriesIterator.next();
return buffer.toString();
}
+ public IProject getProject() {
+ return fProject;
+ }
+
+ protected IProject getProject(String name) {
+ return PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
+ }
+
+ public List getReferencedProjects() {
+ List referencedProjects = new ArrayList();
+
+ Iterator iterator = getLoadPathEntries().iterator();
+ while (iterator.hasNext()) {
+ LoadPathEntry pathEntry = (LoadPathEntry) iterator.next();
+ if (pathEntry.getType() == LoadPathEntry.TYPE_PROJECT)
+ referencedProjects.add(pathEntry.getProject());
+ }
+
+ return referencedProjects;
+ }
+
public IResource getUnderlyingResource() {
return fProject;
}
+ protected void loadLoadPathEntries() {
+ fLoadPathEntries = new ArrayList();
+
+ IFile loadPathsFile = getLoadPathEntriesFile();
+
+ XMLReader reader = null;
+ try {
+ reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ reader.setContentHandler(getLoadPathEntriesContentHandler());
+ reader.parse(new InputSource(loadPathsFile.getContents()));
+ } catch (Exception e) {
+ //the file is nonextant or unreadable
+ }
+ }
+
+ public void removeLoadPathEntry(IProject anotherPHPProject) {
+ Iterator entries = getLoadPathEntries().iterator();
+ while (entries.hasNext()) {
+ LoadPathEntry entry = (LoadPathEntry) entries.next();
+ if (entry.getType() == LoadPathEntry.TYPE_PROJECT && entry.getProject().getName().equals(anotherPHPProject.getName())) {
+ getLoadPathEntries().remove(entry);
+ fScratched = true;
+ break;
+ }
+ }
+ }
+
+ public void save() throws CoreException {
+ if (fScratched) {
+ InputStream xmlPath = new ByteArrayInputStream(getLoadPathXML().getBytes());
+ IFile loadPathsFile = getLoadPathEntriesFile();
+ if (!loadPathsFile.exists())
+ loadPathsFile.create(xmlPath, true, null);
+ else
+ loadPathsFile.setContents(xmlPath, true, false, null);
+
+ fScratched = false;
+ }
+ }
+
+ public void setProject(IProject aProject) {
+ fProject = aProject;
+ }
+
}