/** * @return an {@link ElementFinderFactory} this Factory is how you select which XML elements to parse as what java types * see it's javadoc for more */ public static ElementFinderFactory getElementFinderFactory() { return new ElementFinderFactory(); }
public ChannelImageParser(ElementFinderFactory factory) { this.titleFinder = factory.getStringFinder(); this.linkFinder = factory.getStringFinder(); this.urlFinder = factory.getStringFinder(); this.widthFinder = factory.getIntegerFinder(); this.heightFinder = factory.getIntegerFinder(); }
@Override public T popResultOrThrow() { validateResult(); return popResult(); }
@Override public void create(RootElement element) { elementFinder.find(element, elementTag); }
public ListParser(String tag, ElementFinderFactory factory, BodyMarshaller<T> bodyMarshaller) { this.tag = tag; this.listCreator = factory.getListElementFinder(bodyMarshaller, this); }
/** * 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))); }
public PodcastItemParser(ElementFinderFactory factory) { this.titleFinder = factory.getStringWrapperTypeFinder(Title.class); this.authorFinder = factory.getStringWrapperTypeFinder(Author.class); this.linkFinder = factory.getStringWrapperTypeFinder(Link.class); itunesDurationFinder = factory.getStringWrapperTypeFinder(ItunesDuration.class); itunesImageFinder = factory.getAttributeFinder(new ImageAttributeMarshaller(), TAG_ITUNES_IMAGE_ATTR); }
public EntryParser(ElementFinderFactory factory) { idFinder = factory.getStringFinder(); titleFinder = factory.getStringFinder(); summaryFinder = factory.getStringFinder(); updatedFinder = factory.getStringFinder(); linkFinder = factory.getListAttributeFinder(new LinkAttributeMarshaller(), linkParseWatcher, ATTR_HREF, ATTR_REL, ATTR_TITLE, ATTR_TYPE); }
/** * 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 onFinish() { System.out.println("Found : " + elementFinder.getResultOrThrow()); } };
/** * Will parse an XML tag using the passed {@link Parser} * This can be used when you want to parse attributes as well as the body into your object * * @param parser The parser you wish to parse the XML with * @param <T> The type you wish to create from the XML body * @return {@link ElementFinder} */ public <T> ElementFinder<T> getTypeFinder(Parser<T> parser) { return new BasicElementFinder<T>(parser); }
/** * Will parse 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} * This can be used when you want to parse attributes as well as the XML body into your object * * @param parser The parser you wish to parse the XML with * @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(Parser<T> parser, ParseWatcher<T> watcher) { return new ListElementFinder<T>(parser, watcher); }
public AuthorParser(ElementFinderFactory factory) { nameFinder = factory.getStringFinder(); }
@Override public T getResultOrThrow() { validateResult(); return result; }
private void validateResult() { if (result == null) { throw new ResultNotFoundException(); } }
@Override public void create(RootElement rootElement) { elementFinder.find(rootElement, "name"); }
/** * 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 onFinish() { System.out.println("Found : " + elementFinder.getResultOrThrow()); } };
public void parse(Element element) { feedHolder = new FeedHolder(); idFinder.find(element, TAG_ID); titleFinder.find(element, TAG_TITLE); updatedFinder.find(element, TAG_UPDATED); authorFinder.find(element, TAG_AUTHOR); logoFinder.find(element, TAG_LOGO); generatorFinder.find(element, TAG_GENERATOR); linkFinder.find(element, TAG_LINK); entryFinder.find(element, TAG_ENTRY); }
@Override public void parse(Element element, ParseWatcher<SexpMediumXmlBenchmark.Author> listener) { this.listener = listener; element.setElementListener(authorListener); nameFinder.find(element, TAG_NAME); }