@Override public void end() { parseFinishWatcher.onFinish(); } }
@Override public void end() { listener.onParsed(list); } }
@Override public void start(Attributes attributes) { String[] values = getAttributeValues(attributes); listener.onParsed(attributeMarshaller.marshal(values)); }
@Test public void informListener_whenElementIsParsed() throws Exception { BasicParser<Object> basicParser = new BasicParser<Object>(mockMarshaller); mockParse(basicParser, mockListener); verify(mockListener).onParsed(any()); }
/** * Will parse the body of an XML tag into {@link Object} using the supplied {@link BodyMarshaller} * * @param bodyMarshaller The marshaller to parse the body into your required type * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getTypeFinder(BodyMarshaller<T> bodyMarshaller) { return getTypeFinder(new BasicParser<T>(bodyMarshaller)); }
@Override public void find(Element from, String uri, String tag) { parser.parse(from.getChild(uri, tag), this); }
/** * Will parse the attributes off an XML tag, into {@link Object} then inform the {@link ParseWatcher} * The idea is to have a callback for a number of elements to create a {@link java.util.List} * * @param attributeMarshaller The marshaller to parse the attributes into your required type * @param watcher The watcher on elements to be informed of object creation * @param attrTags The tags of the attributes you wish to parse * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getListAttributeFinder(AttributeMarshaller<T> attributeMarshaller, ParseWatcher<T> watcher, String... attrTags) { return new ListElementFinder<T>(new BasicAttributeParser<T>(attributeMarshaller, attrTags), watcher); }
/** * Will parse the body of all XML tags with the {@code tag} argument * into a {@link java.util.List} of {@link Object}. This is a simple Integer wrapper class that * has a constructor that takes a single {@link Integer} parameter.<br/> * See {@link #getIntegerWrapperTypeFinder(Class)} for more info. * * @param tag The tag to parse the body for each list element * @param clazz The class of the wrapper type you wish your List to be made of * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<List<T>> getIntegerWrapperTypeListFinder(String tag, Class<T> clazz) { return getTypeFinder(new ListParser<T>(tag, this, getIntegerWrapperMarshaller(clazz))); }
public static void mockParse(Parser<Object> parser, ParseWatcher<Object> mockListener) throws SAXException { mockParse(parser, mockListener, ""); }
@Override public void onParsed(T body) { parseWatcher.onParsed(body); }
/** * Will parse the body of an XML tag into {@link Object} then inform the {@link ParseWatcher} * The idea is to have a callback for a number of elements to create a {@link java.util.List} * * @param bodyMarshaller The marshaller to create an object from the XML body * @param watcher The watcher on elements to be informed of object creation * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getListElementFinder(BodyMarshaller<T> bodyMarshaller, ParseWatcher<T> watcher) { return getListElementFinder(new BasicParser<T>(bodyMarshaller), watcher); }
@Override public void find(Element from, String uri, String tag) { parser.parse(from.getChild(uri, tag), this); }
@Override public void end(String body) { elementFinder.onParsed(body); parseFinishWatcher.onFinish(); } }
/** * Will parse the attributes off an XML tag, these are then passed to your {@link AttributeMarshaller} * to create an object of type {@link Object}. * * @param attributeMarshaller The marshaller to parse the attributes into your required type * @param attrTags The tags of the attributes you wish to parse * @param <T> The type you wish to create from the attributes * @return {@link ElementFinder} */ public <T> ElementFinder<T> getAttributeFinder(AttributeMarshaller<T> attributeMarshaller, String... attrTags) { return getTypeFinder(new BasicAttributeParser<T>(attributeMarshaller, attrTags)); }
@Override public void end(String body) { listener.onParsed(bodyMarshaller.marshal(body)); } }
/** * Will parse the body of an XML tag into a simple {@link Integer} wrapper class. This is a class that * has a constructor that takes a single primitive int parameter. * * @param clazz The class of your Integer Wrapper Class * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getIntegerWrapperTypeFinder(Class<T> clazz) { return getTypeFinder(new BasicParser<T>(getIntegerWrapperMarshaller(clazz))); }
@Override public void find(Element from, String tag) { parser.parse(from.getChild(tag), this); }
/** * Will parse the body of an XML tag into a simple {@link String} wrapper class. This is a class that * has a constructor that takes a single {@link String} parameter. * * @param clazz The class of your String Wrapper Class * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getStringWrapperTypeFinder(Class<T> clazz) { return getTypeFinder(new BasicParser<T>(getStringWrapperMarshaller(clazz))); }
@Override public void find(Element from, String tag) { parser.parse(from.getChild(tag), this); }