Clean up formatting so I can read the code

This commit is contained in:
Mark H. Wood
2012-06-29 13:20:46 -04:00
parent f05ceff8e8
commit c9820a3bbd

View File

@@ -55,7 +55,7 @@ import org.dspace.core.SelfNamedPlugin;
public class DSpaceControlledVocabulary extends SelfNamedPlugin implements ChoiceAuthority public class DSpaceControlledVocabulary extends SelfNamedPlugin implements ChoiceAuthority
{ {
private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class); private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class);
private static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]"; private static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]";
private static String idTemplate = "//node[@id = '%s']"; private static String idTemplate = "//node[@id = '%s']";
private static String pluginNames[] = null; private static String pluginNames[] = null;
@@ -85,22 +85,24 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
{ {
if (pluginNames == null) if (pluginNames == null)
{ {
class xmlFilter implements java.io.FilenameFilter class xmlFilter implements java.io.FilenameFilter
{ {
public boolean accept(File dir, String name) @Override
public boolean accept(File dir, String name)
{ {
return name.endsWith(".xml"); return name.endsWith(".xml");
} }
} }
String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir") + "/config/controlled-vocabularies/"; String vocabulariesPath = ConfigurationManager.getProperty("dspace.dir")
String[] xmlFiles = (new File(vocabulariesPath)).list(new xmlFilter()); + "/config/controlled-vocabularies/";
List<String> names = new ArrayList<String>(); String[] xmlFiles = (new File(vocabulariesPath)).list(new xmlFilter());
for (String filename : xmlFiles) List<String> names = new ArrayList<String>();
for (String filename : xmlFiles)
{ {
names.add((new File(filename)).getName().replace(".xml","")); names.add((new File(filename)).getName().replace(".xml", ""));
} }
pluginNames = names.toArray(new String[names.size()]); pluginNames = names.toArray(new String[names.size()]);
log.info("Got plugin names = "+Arrays.deepToString(pluginNames)); log.info("Got plugin names = " + Arrays.deepToString(pluginNames));
} }
} }
@@ -154,6 +156,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
} }
} }
@Override
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale) public Choices getMatches(String field, String text, int collection, int start, int limit, String locale)
{ {
init(); init();
@@ -162,47 +165,50 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
XPath xpath = XPathFactory.newInstance().newXPath(); XPath xpath = XPathFactory.newInstance().newXPath();
Choice[] choices; Choice[] choices;
try { try {
NodeList results = (NodeList)xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); NodeList results = (NodeList) xpath.evaluate(xpathExpression,
String[] authorities = new String[results.getLength()]; vocabulary, XPathConstants.NODESET);
String[] values = new String[results.getLength()]; String[] authorities = new String[results.getLength()];
String[] labels = new String[results.getLength()]; String[] values = new String[results.getLength()];
for (int i=0; i<results.getLength(); i++) String[] labels = new String[results.getLength()];
for (int i = 0; i < results.getLength(); i++)
{ {
Node node = results.item(i); Node node = results.item(i);
String hierarchy = this.buildString(node); String hierarchy = this.buildString(node);
if (this.suggestHierarchy) if (this.suggestHierarchy)
{ {
labels[i] = hierarchy; labels[i] = hierarchy;
} }
else else
{ {
labels[i] = node.getAttributes().getNamedItem("label").getNodeValue(); labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
} }
if (this.storeHierarchy) if (this.storeHierarchy)
{ {
values[i] = hierarchy; values[i] = hierarchy;
} }
else else
{ {
values[i] = node.getAttributes().getNamedItem("label").getNodeValue(); values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
} }
authorities[i] = node.getAttributes().getNamedItem("id").getNodeValue(); authorities[i] = node.getAttributes().getNamedItem("id").getNodeValue();
} }
int resultCount = Math.min(labels.length-start, limit); int resultCount = Math.min(labels.length - start, limit);
choices = new Choice[resultCount]; choices = new Choice[resultCount];
if (resultCount > 0) if (resultCount > 0)
{ {
for (int i=0; i<resultCount; i++) for (int i = 0; i < resultCount; i++)
{ {
choices[i] = new Choice(authorities[start+i],values[start+i],labels[start+i]); choices[i] = new Choice(authorities[start + i], values[start
} + i], labels[start + i]);
} }
}
} catch(XPathExpressionException e) { } catch(XPathExpressionException e) {
choices = new Choice[0]; choices = new Choice[0];
} }
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false); return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
} }
@Override
public Choices getBestMatch(String field, String text, int collection, String locale) public Choices getBestMatch(String field, String text, int collection, String locale)
{ {
init(); init();
@@ -210,6 +216,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
return getMatches(field, text, collection, 0, 2, locale); return getMatches(field, text, collection, 0, 2, locale);
} }
@Override
public String getLabel(String field, String key, String locale) public String getLabel(String field, String key, String locale)
{ {
init(); init();