You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by un...@apache.org on 2004/07/09 15:05:43 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/extractor SimpleXmlExtractor.java
unico 2004/07/09 06:05:43
Modified: src/share/org/apache/slide/extractor SimpleXmlExtractor.java
Log:
allow SimpleXmlExtractor behavior to be overridden in subclasses
Revision Changes Path
1.4 +33 -14 jakarta-slide/src/share/org/apache/slide/extractor/SimpleXmlExtractor.java
Index: SimpleXmlExtractor.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/extractor/SimpleXmlExtractor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SimpleXmlExtractor.java 1 Mar 2004 10:04:55 -0000 1.3
+++ SimpleXmlExtractor.java 9 Jul 2004 13:05:43 -0000 1.4
@@ -54,11 +54,14 @@
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(content);
for (Iterator i = instructions.iterator(); i.hasNext();) {
- Instruction instruction = (Instruction)i.next();
+ Instruction instruction = (Instruction) i.next();
XPath xPath = instruction.getxPath();
List nodeList = xPath.selectNodes(document);
if ( nodeList.get(0) instanceof Text ) {
- properties.put(instruction.getPropertyName(), ((Text)nodeList.get(0)).getText());
+ Object propertyValue = filter((Text) nodeList.get(0), instruction);
+ if (propertyValue != null) {
+ properties.put(instruction.getPropertyName(), propertyValue);
+ }
}
}
} catch (IOException e) {
@@ -72,22 +75,38 @@
public void configure(Configuration configuration) throws ConfigurationException {
Enumeration instructions = configuration.getConfigurations("instruction");
while (instructions.hasMoreElements()) {
- Configuration extract = (Configuration)instructions.nextElement();
- try {
- String property = extract.getAttribute("property");
- XPath xPath = XPath.newInstance(extract.getAttribute("xpath"));
- addInstruction(new Instruction(xPath, property));
- } catch (JDOMException e) {
- throw new ConfigurationException("Could not create xPath from given attribute", extract);
- }
+ Configuration instruction = (Configuration) instructions.nextElement();
+ addInstruction(createInstruction(instruction));
}
}
+ /**
+ * Allow subclasses to apply filtering to property values before they are written.
+ * Returning null signals that the extractor ignors this value. The default
+ * implementation just returns the string value of the text node.
+ *
+ * @param text the Text identified by the xpath instruction.
+ * @return the property value to be set, <code>null</codee> if to be ignored.
+ */
+ protected Object filter(Text text, Instruction instruction) throws ExtractorException {
+ return text.getText();
+ }
+
protected void addInstruction(Instruction instruction) {
instructions.add(instruction);
}
- class Instruction {
+ protected Instruction createInstruction(Configuration instruction) throws ConfigurationException {
+ try {
+ String property = instruction.getAttribute("property");
+ XPath xPath = XPath.newInstance(instruction.getAttribute("xpath"));
+ return new Instruction(xPath, property);
+ } catch (JDOMException e) {
+ throw new ConfigurationException("Could not create xPath from given attribute", instruction);
+ }
+ }
+
+ protected static class Instruction {
private XPath xPath;
private String propertyName;
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org