Skip to content

Commit

Permalink
Implemented isWellFormed()
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Sep 23, 2009
1 parent 97598ca commit 713cfa6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/net.bioclipse.xml/META-INF/MANIFEST.MF
Expand Up @@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.ui,
net.bioclipse.scripting,
org.springframework.bundle.spring.aop,
net.sf.cglib,
org.springframework.osgi.aopalliance.osgi
org.springframework.osgi.aopalliance.osgi,
net.bioclipse.xom;bundle-version="1.1.0",
org.eclipse.core.resources
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.apache.log4j
Bundle-ActivationPolicy: lazy
Expand Up @@ -10,9 +10,18 @@
******************************************************************************/
package net.bioclipse.xml.business;

import java.io.IOException;

import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;
import nu.xom.Builder;
import nu.xom.ParsingException;
import nu.xom.ValidityException;

import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

public class XmlManager implements IBioclipseManager {

Expand All @@ -25,4 +34,29 @@ public class XmlManager implements IBioclipseManager {
public String getManagerName() {
return "xml";
}

public boolean isWellFormed(IFile file, IProgressMonitor monitor)
throws BioclipseException, CoreException {
logger.debug("Checking for well-formedness");
try {
Builder parser = new Builder(true);
parser.build(file.getContents());
} catch (ValidityException exception) {
return false;
} catch (ParsingException exception) {
return false;
} catch (IOException exception) {
throw new BioclipseException(
"Error while opening file",
exception
);
} catch (CoreException exception) {
throw new BioclipseException(
"Error while opening file",
exception
);
}
return true;
}

}

0 comments on commit 713cfa6

Please sign in to comment.