Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApiParser.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package uk.co.md87.evetool.api.parser;
  6. import java.io.IOException;
  7. import java.io.StringReader;
  8. import java.util.List;
  9. import org.jdom.Document;
  10. import org.jdom.Element;
  11. import org.jdom.JDOMException;
  12. import org.jdom.input.SAXBuilder;
  13. /**
  14. *
  15. * @author chris
  16. */
  17. public class ApiParser {
  18. public ApiResult parseResult(final String data) throws IOException, JDOMException,
  19. ParserException {
  20. return parseResult(new SAXBuilder().build(new StringReader(data)));
  21. }
  22. public ApiResult parseResult(final Document doc) throws IOException, JDOMException,
  23. ParserException {
  24. final Element root = doc.getRootElement();
  25. if (!"eveapi".equals(root.getName())) {
  26. throw new ParserException("Unexpected response; root element is not <eveapi/>");
  27. }
  28. final ApiResult result = new ApiResult();
  29. addElements(result, root);
  30. return result;
  31. }
  32. @SuppressWarnings("unchecked")
  33. protected void addElements(final ApiElement result, final Element element) {
  34. for (Element child : (List<Element>) element.getChildren()) {
  35. final ApiElement apiElement = new NamedApiElement(child.getName());
  36. // TODO: Parse rowsets correctly
  37. // TODO: Include content and attributes
  38. result.addChild(apiElement);
  39. addElements(apiElement, child);
  40. }
  41. }
  42. }