@Test public void testGetMatches() throws IOException, ClassNotFoundException { System.out.println("getMatches"); final String PLUGIN_INTERFACE = "org.dspace.content.authority.ChoiceAuthority"; String field = null; String text = "north 40"; Collection collection = null; int start = 0; int limit = 10; String locale = null; DSpaceControlledVocabulary instance = (DSpaceControlledVocabulary) CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm"); assertNotNull(instance); Choices result = instance.getMatches(text, start, limit, locale); assertEquals("the farm::north 40", result.values[0].value); }
@Override public Choices getMatches(String text, int start, int limit, String locale) { init(); log.debug("Getting matches for '" + text + "'"); String xpathExpression = ""; String[] textHierarchy = text.split(hierarchyDelimiter, -1); for (int i = 0; i < textHierarchy.length; i++) { xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase()); } XPath xpath = XPathFactory.newInstance().newXPath(); int total = 0; List<Choice> choices = new ArrayList<Choice>(); try { NodeList results = (NodeList) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); total = results.getLength(); choices = getChoicesFromNodeList(results, start, limit); } catch (XPathExpressionException e) { log.warn(e.getMessage(), e); return new Choices(true); } return new Choices(choices.toArray(new Choice[choices.size()]), start, total, Choices.CF_AMBIGUOUS, total > start + limit); }
DSpaceControlledVocabulary extends SelfNamedPlugin implements HierarchicalAuthority { @Override public Choices getMatches(String text, int start, int limit, String locale) { init(); log.debug("Getting matches for '" + text + "'"); String xpathExpression = ""; String[] textHierarchy = text.split(hierarchyDelimiter, -1); for (int i = 0; i < textHierarchy.length; i++) { xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase()); } XPath xpath = XPathFactory.newInstance().newXPath(); int total = 0; List<Choice> choices = new ArrayList<Choice>(); try { NodeList results = (NodeList) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); total = results.getLength(); choices = getChoicesFromNodeList(results, start, limit); } catch (XPathExpressionException e) { log.warn(e.getMessage(), e); return new Choices(true); } return new Choices(choices.toArray(new Choice[choices.size()]), start, total, Choices.CF_AMBIGUOUS, total > start + limit); } }
DSpaceControlledVocabulary extends SelfNamedPlugin implements HierarchicalAuthority { @Override public Choices getMatches(String text, int start, int limit, String locale) { init(); log.debug("Getting matches for '" + text + "'"); String xpathExpression = ""; String[] textHierarchy = text.split(hierarchyDelimiter, -1); for (int i = 0; i < textHierarchy.length; i++) { xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase()); } XPath xpath = XPathFactory.newInstance().newXPath(); int total = 0; List<Choice> choices = new ArrayList<Choice>(); try { NodeList results = (NodeList) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); total = results.getLength(); choices = getChoicesFromNodeList(results, start, limit); } catch (XPathExpressionException e) { log.warn(e.getMessage(), e); return new Choices(true); } return new Choices(choices.toArray(new Choice[choices.size()]), start, total, Choices.CF_AMBIGUOUS, total > start + limit); } DSpaceControlledVocabulary(); }
DSpaceControlledVocabulary extends SelfNamedPlugin implements HierarchicalAuthority { @Override public Choices getMatches(String text, int start, int limit, String locale) { init(); log.debug("Getting matches for '" + text + "'"); String xpathExpression = ""; String[] textHierarchy = text.split(hierarchyDelimiter, -1); for (int i = 0; i < textHierarchy.length; i++) { xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase()); } XPath xpath = XPathFactory.newInstance().newXPath(); int total = 0; List<Choice> choices = new ArrayList<Choice>(); try { NodeList results = (NodeList) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); total = results.getLength(); choices = getChoicesFromNodeList(results, start, limit); } catch (XPathExpressionException e) { log.warn(e.getMessage(), e); return new Choices(true); } return new Choices(choices.toArray(new Choice[choices.size()]), start, total, Choices.CF_AMBIGUOUS, total > start + limit); } DSpaceControlledVocabulary(); @Override boolean storeAuthorityInMetadata(); static String[] getPluginNames(); @Override Choices getMatches(String text, int start, int limit, String locale); @Override Choices getBestMatch(String text, String locale); @Override String getLabel(String key, String locale); @Override String getValue(String key, String locale); @Override Choice getChoice(String authKey, String locale); @Override boolean isHierarchical(); @Override Choices getTopChoices(String authorityName, int start, int limit, String locale); @Override Choices getChoicesByParent(String authorityName, String parentId, int start, int limit, String locale); @Override Choice getParentChoice(String authorityName, String childId, String locale); @Override Integer getPreloadLevel(); }
DSpaceControlledVocabulary extends SelfNamedPlugin implements HierarchicalAuthority { @Override public Choices getMatches(String text, int start, int limit, String locale) { init(); log.debug("Getting matches for '" + text + "'"); String xpathExpression = ""; String[] textHierarchy = text.split(hierarchyDelimiter, -1); for (int i = 0; i < textHierarchy.length; i++) { xpathExpression += String.format(xpathTemplate, textHierarchy[i].replaceAll("'", "&apos;").toLowerCase()); } XPath xpath = XPathFactory.newInstance().newXPath(); int total = 0; List<Choice> choices = new ArrayList<Choice>(); try { NodeList results = (NodeList) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODESET); total = results.getLength(); choices = getChoicesFromNodeList(results, start, limit); } catch (XPathExpressionException e) { log.warn(e.getMessage(), e); return new Choices(true); } return new Choices(choices.toArray(new Choice[choices.size()]), start, total, Choices.CF_AMBIGUOUS, total > start + limit); } DSpaceControlledVocabulary(); @Override boolean storeAuthorityInMetadata(); static String[] getPluginNames(); @Override Choices getMatches(String text, int start, int limit, String locale); @Override Choices getBestMatch(String text, String locale); @Override String getLabel(String key, String locale); @Override String getValue(String key, String locale); @Override Choice getChoice(String authKey, String locale); @Override boolean isHierarchical(); @Override Choices getTopChoices(String authorityName, int start, int limit, String locale); @Override Choices getChoicesByParent(String authorityName, String parentId, int start, int limit, String locale); @Override Choice getParentChoice(String authorityName, String childId, String locale); @Override Integer getPreloadLevel();  }