/** * 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)); }
/** * Will parse the body of an XML tag into an {@link Boolean} * * @return {@link ElementFinder} */ public ElementFinder<Boolean> getBooleanFinder() { return getTypeFinder(new BooleanBodyMarshaller()); }
/** * 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)); }
/** * Will parse the body of an XML tag into a {@link String} * * @return {@link ElementFinder} */ public ElementFinder<String> getStringFinder() { return getTypeFinder(new StringBodyMarshaller()); }
/** * Will parse the body of an XML tag into an {@link Integer} * * @return {@link ElementFinder} */ public ElementFinder<Integer> getIntegerFinder() { return getTypeFinder(new IntegerBodyMarshaller()); }
/** * Will parse the body of all XML tags with the {@code tag} argument * into a {@link java.util.List} of {@link Object} using the supplied {@link BodyMarshaller}. * <pre> * {@code <names> * <name>Paul</name> * <name>Peter</name> * </names> * * ElementFinder<T> finder = getListFinder("name", marshallerOfT); * finder.find(element, "names"); * List<T> names = finder.getResultOrThrow(); * } * </pre> * * @param tag The tag to parse the body for each list element * @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<List<T>> getListFinder(String tag, BodyMarshaller<T> bodyMarshaller) { return getTypeFinder(new ListParser<T>(tag, this, bodyMarshaller)); }
/** * 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))); }
/** * 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))); }
/** * 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))); }
/** * 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 String wrapper class that * has a constructor that takes a single {@link String} parameter.<br/> * See {@link #getStringWrapperTypeFinder(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>> getStringWrapperTypeListFinder(String tag, Class<T> clazz) { return getTypeFinder(new ListParser<T>(tag, this, getStringWrapperMarshaller(clazz))); }
@Override public void execute() { ElementFinderFactory factory = SimpleEasyXmlParser.getElementFinderFactory(); elementFinder = factory.getTypeFinder(new PodcastChannelParser(factory)); Instigator instigator = new PodcastInstigator(elementFinder, finishWatcher); SimpleEasyXmlParser.parse(PodcastExampleHelper.SINGLE_PODCAST_ITEM, instigator); }
public PodcastChannelParser(ElementFinderFactory factory) { this.podcastItemFinder = factory.getListElementFinder(new PodcastItemParser(factory), parseWatcher); this.titleFinder = factory.getStringWrapperTypeFinder(Title.class); this.linkFinder = factory.getStringWrapperTypeFinder(Link.class); this.imageFinder = factory.getTypeFinder(new ChannelImageParser(factory)); }
public FeedParser(ElementFinderFactory factory) { this.idFinder = factory.getStringFinder(); this.titleFinder = factory.getStringFinder(); this.updatedFinder = factory.getStringFinder(); this.authorFinder = factory.getTypeFinder(new AuthorParser(factory)); this.logoFinder = factory.getStringFinder(); this.generatorFinder = factory.getStringFinder(); this.linkFinder = factory.getAttributeFinder(new LinkAttributeMarshaller(), ATTR_HREF, ATTR_REL, ATTR_TITLE, ATTR_TYPE); this.entryFinder = factory.getListElementFinder(new EntryParser(factory), parseWatcher); }