Author: ross.gardler
Date: Sat Sep 6 11:31:24 2008
New Revision: 1267
Added:
trunk/uk.ac.osswatch.simal.core/findbugs-exclude.xml
Modified:
trunk/uk.ac.osswatch.simal.core/pom.xml
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/ModelSupport.java
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/Person.java
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/AbstractSimalRepository.java
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/jena/SimalRepository.java
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/tools/PTSWImport.java
Log:
Fix some FindBugs warnings
Added: trunk/uk.ac.osswatch.simal.core/findbugs-exclude.xml
==============================================================================
--- (empty file)
+++ trunk/uk.ac.osswatch.simal.core/findbugs-exclude.xml Sat Sep 6
11:31:24 2008
@@ -0,0 +1,7 @@
+<FindBugsFilter>
+ <!-- allow the CLI to exit -->
+ <Match>
+ <Class name="uk.ac.osswatch.simal.Simal" />
+ <Bug pattern="DM_EXIT" />
+ </Match>
+</FindBugsFilter>
\ No newline at end of file
Modified: trunk/uk.ac.osswatch.simal.core/pom.xml
==============================================================================
--- trunk/uk.ac.osswatch.simal.core/pom.xml (original)
+++ trunk/uk.ac.osswatch.simal.core/pom.xml Sat Sep 6 11:31:24 2008
@@ -340,6 +340,7 @@
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<xmlOutput>true</xmlOutput>
+ <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
Modified:
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/ModelSupport.java
==============================================================================
---
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/ModelSupport.java
(original)
+++
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/ModelSupport.java
Sat Sep 6 11:31:24 2008
@@ -19,6 +19,7 @@
*/
+import java.net.MalformedURLException;
import java.net.URL;
import org.slf4j.Logger;
@@ -76,11 +77,13 @@
repo.addProject(new URL(
"http://simal.oss-watch.ac.uk/projectDetails/codegoo.rdf"),
"http://simal.oss-watch.ac.uk");
- } catch (Exception e) {
+ } catch (SimalRepositoryException e) {
logger.error("Can't add the test data, there's no point in carrying
on");
e.printStackTrace();
- System.exit(1);
-
+ throw new RuntimeException("Unable to add test data, aborting", e);
+ } catch (MalformedURLException e) {
+ logger.error("Malformed URL in test data, should never happen as it
is hard coded", e);
+ throw new RuntimeException("Unable to add test data, aborting", e);
}
}
}
Modified:
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/Person.java
==============================================================================
---
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/Person.java
(original)
+++
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/model/jena/Person.java
Sat Sep 6 11:31:24 2008
@@ -202,12 +202,8 @@
Set<String> names = getNames();
if (names.size() == 0) {
names = getGivennames();
- }
- if (names == null) {
- return toString();
- } else {
if (names.size() == 0) {
- return getURI();
+ return toString();
}
}
int maxLength = 0;
Modified:
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/AbstractSimalRepository.java
==============================================================================
---
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/AbstractSimalRepository.java
(original)
+++
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/AbstractSimalRepository.java
Sat Sep 6 11:31:24 2008
@@ -228,16 +228,8 @@
logger
.error("addxmldirectory requires a directory name as the first
parameter");
}
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- if (name.endsWith(".xml") || name.endsWith(".rdf")) {
- return true;
- } else {
- return false;
- }
- }
-
- };
+ FilenameFilter filter = new RDFFilenameFilter();
+
File[] files = dir.listFiles(filter);
for (int i = 0; i < files.length; i++) {
try {
@@ -320,5 +312,16 @@
public boolean isTest() {
return isTest;
+ }
+
+ static class RDFFilenameFilter implements FilenameFilter {
+
+ public boolean accept(File dir, String name) {
+ if (name.endsWith(".xml") || name.endsWith(".rdf")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
}
Modified:
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/jena/SimalRepository.java
==============================================================================
---
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/jena/SimalRepository.java
(original)
+++
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/rdf/jena/SimalRepository.java
Sat Sep 6 11:31:24 2008
@@ -1,7 +1,8 @@
package uk.ac.osswatch.simal.rdf.jena;
+
/*
*
-Copyright 2007 University of Oxford *
+ Copyright 2007 University of Oxford *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -17,7 +18,6 @@
*
*/
-
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -78,6 +78,7 @@
*/
private SimalRepository() {
super();
+ model = null;
}
/**
@@ -97,8 +98,9 @@
/**
* Initialise the repository.
*
- * @param directory the directory for the database if
- * it is a persistent repository (i.e. not a test repo)
+ * @param directory
+ * the directory for the database if it is a persistent
repository
+ * (i.e. not a test repo)
* @throws SimalRepositoryException
*/
public void initialise(String directory) throws SimalRepositoryException
{
@@ -111,8 +113,8 @@
model = ModelFactory.createDefaultModel();
} else {
String className = "org.apache.derby.jdbc.EmbeddedDriver"; // path of
- // driver
- // class
+ // driver
+ // class
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
@@ -120,9 +122,20 @@
}
String DB_URL;
if (directory != null) {
- DB_URL = "jdbc:derby:" + directory + "/" +
SimalProperties.getProperty(SimalProperties.PROPERTY_RDF_DATA_FILENAME)
+ ";create=true";
+ DB_URL = "jdbc:derby:"
+ + directory
+ + "/"
+ + SimalProperties
+ .getProperty(SimalProperties.PROPERTY_RDF_DATA_FILENAME)
+ + ";create=true";
} else {
- DB_URL = "jdbc:derby:" +
SimalProperties.getProperty(SimalProperties.PROPERTY_RDF_DATA_DIR) + "/" +
SimalProperties.getProperty(SimalProperties.PROPERTY_RDF_DATA_FILENAME)
+ ";create=true";
+ DB_URL = "jdbc:derby:"
+ + SimalProperties
+ .getProperty(SimalProperties.PROPERTY_RDF_DATA_DIR)
+ + "/"
+ + SimalProperties
+ .getProperty(SimalProperties.PROPERTY_RDF_DATA_FILENAME)
+ + ";create=true";
}
String DB_USER = "";
String DB_PASSWD = "";
@@ -139,7 +152,7 @@
// Close the database connection
// conn.close();
}
-
+
initialised = true;
if (isTest) {
@@ -170,12 +183,12 @@
logger.debug("Adding RDF data string:\n\t" + data);
File file = new File("testingAddData.rdf");
+ FileWriter fw = null;
+ BufferedWriter bw = null;
try {
- FileWriter fw = new FileWriter(file);
- BufferedWriter bw = new BufferedWriter(fw);
+ fw = new FileWriter(file);
+ bw = new BufferedWriter(fw);
bw.write(data);
- bw.close();
-
addProject(file.toURI().toURL(), "");
} catch (MalformedURLException mue) {
// should never happen as we created the file here
@@ -186,6 +199,20 @@
"Unable to write file from data string", e);
} finally {
file.delete();
+ if (bw != null) {
+ try {
+ bw.close();
+ } catch (IOException e) {
+ throw new SimalRepositoryException("Unable to close the writer",
e);
+ }
+ }
+ if (fw != null) {
+ try {
+ fw.close();
+ } catch (IOException e) {
+ throw new SimalRepositoryException("Unable to close the
filewriter", e);
+ }
+ }
}
}
@@ -248,13 +275,13 @@
}
}
- public IDoapCategory findCategoryById(String id) throws
SimalRepositoryException {
+ public IDoapCategory findCategoryById(String id)
+ throws SimalRepositoryException {
String queryStr = "PREFIX doap: <" + SimalRepository.DOAP_NAMESPACE_URI
- + "> " + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
- + "PREFIX simal: <" + SimalRepository.SIMAL_NAMESPACE_URI + ">"
- + "SELECT DISTINCT ?category WHERE { "
- + "?category simal:categoryId \"" + id
- + "\"}";
+ + "> " + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
+ + "PREFIX simal: <" + SimalRepository.SIMAL_NAMESPACE_URI + ">"
+ + "SELECT DISTINCT ?category WHERE { "
+ + "?category simal:categoryId \"" + id + "\"}";
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
@@ -271,17 +298,20 @@
return category;
}
-
+
public IPerson findPersonById(String id) throws SimalRepositoryException
{
if (!isValidSimalID(id)) {
- throw new SimalRepositoryException("Attempt to find a person using
an invalid Simal ID of " + id + " are you sure that's a world unique
identifier? You may need to call RDFUtils.getUniqueSimalID(id)");
+ throw new SimalRepositoryException(
+ "Attempt to find a person using an invalid Simal ID of "
+ + id
+ + " are you sure that's a world unique identifier? You may
need to call RDFUtils.getUniqueSimalID(id)");
}
String queryStr = "PREFIX xsd: <" + SimalRepository.XSD_NAMESPACE_URI
- + "> " + "PREFIX foaf: <" + SimalRepository.FOAF_NAMESPACE_URI
- + "> " + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
+ + "> " + "PREFIX foaf: <" + SimalRepository.FOAF_NAMESPACE_URI
+ "> "
+ + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
+ "PREFIX simal: <" + SimalRepository.SIMAL_NAMESPACE_URI + ">"
- + "SELECT DISTINCT ?person WHERE { "
- + "?person simal:personId \"" + id + "\"^^xsd:string }";
+ + "SELECT DISTINCT ?person WHERE { " + "?person simal:personId \""
+ id
+ + "\"^^xsd:string }";
IPerson person = findPersonBySPARQL(queryStr);
return person;
@@ -302,8 +332,7 @@
}
/**
- * Find a single person by executing a SPARQL
- * query.
+ * Find a single person by executing a SPARQL query.
*
* @param queryStr
* @return
@@ -329,8 +358,7 @@
throws SimalRepositoryException {
String queryStr = "PREFIX foaf: <" + SimalRepository.FOAF_NAMESPACE_URI
+ "> " + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
- + "SELECT DISTINCT ?person WHERE { "
- + "?person foaf:mbox_sha1sum \""
+ + "SELECT DISTINCT ?person WHERE { " + "?person foaf:mbox_sha1sum
\""
+ sha1sum + "\"}";
IPerson person = findPersonBySPARQL(queryStr);
@@ -353,14 +381,16 @@
public IProject findProjectById(String id) throws
SimalRepositoryException {
if (!isValidSimalID(id)) {
- throw new SimalRepositoryException("Attempt to find a project using
an invalid Simal ID of " + id + " are you sure that is a unique ID? You may
need to call RDFUtils.getUniqueSimalID(id)");
+ throw new SimalRepositoryException(
+ "Attempt to find a project using an invalid Simal ID of "
+ + id
+ + " are you sure that is a unique ID? You may need to call
RDFUtils.getUniqueSimalID(id)");
}
String queryStr = "PREFIX xsd: <" + SimalRepository.XSD_NAMESPACE_URI
- + "> " + "PREFIX doap: <" + SimalRepository.DOAP_NAMESPACE_URI
- + "> " + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
+ + "> " + "PREFIX doap: <" + SimalRepository.DOAP_NAMESPACE_URI
+ "> "
+ + "PREFIX rdf: <" + SimalRepository.RDF_NAMESPACE_URI + ">"
+ "PREFIX simal: <" + SimalRepository.SIMAL_NAMESPACE_URI + ">"
- + "SELECT DISTINCT ?project WHERE { "
- + "?project simal:projectId \""
+ + "SELECT DISTINCT ?project WHERE { " + "?project simal:projectId
\""
+ id + "\"^^xsd:string }";
IProject project = findProjectBySPARQL(queryStr);
@@ -382,8 +412,7 @@
}
/**
- * Find a single project by executing a PARQL
- * query.
+ * Find a single project by executing a PARQL query.
*
* @param queryStr
* @return
@@ -502,7 +531,8 @@
}
public void initialise() throws SimalRepositoryException {
-
initialise(SimalProperties.getProperty(SimalProperties.PROPERTY_RDF_DATA_DIR));
+ initialise(SimalProperties
+ .getProperty(SimalProperties.PROPERTY_RDF_DATA_DIR));
}
public void removeAllData() {
@@ -510,7 +540,8 @@
}
/**
- * Get a Jena Resource.
+ * Get a Jena Resource.
+ *
* @param uri
* @return
*/
@@ -521,5 +552,5 @@
public IResource getResource(String uri) {
return new Resource(model.getResource(uri));
}
-
+
}
Modified:
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/tools/PTSWImport.java
==============================================================================
---
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/tools/PTSWImport.java
(original)
+++
trunk/uk.ac.osswatch.simal.core/src/main/java/uk/ac/osswatch/simal/tools/PTSWImport.java
Sat Sep 6 11:31:24 2008
@@ -15,6 +15,7 @@
*/
package uk.ac.osswatch.simal.tools;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -35,6 +36,7 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
import uk.ac.osswatch.simal.rdf.SimalException;
import uk.ac.osswatch.simal.rdf.io.RDFUtils;
@@ -145,7 +147,9 @@
seeAlso.setAttributeNS(RDFUtils.RDF_NS, "rdf:resource",
ping.toURL().toExternalForm());
importedProjectNode.appendChild(seeAlso);
root.appendChild(importedProjectNode);
- } catch (Exception e) {
+ } catch (IOException e) {
+ logger.warn("Ignoring illegal XML document loaded from " + ping,
e);
+ } catch (SAXException e) {
logger.warn("Ignoring illegal XML document loaded from " + ping,
e);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Simal Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/simal-commits?hl=en
-~----------~----~----~----~------~----~------~--~---