final Node body = nodes.item(0);
// build endpoint definitions
if (body.hasChildNodes()) {
ResourceDefinition currentEndpoint = null;
for (int i = 0; i < body.getChildNodes().getLength(); i++) {
final Node child = body.getChildNodes().item(i);
LOGGER.debug("Found {}: {}", child.getNodeName(), child.getTextContent());
if (child.getNodeType() == Node.ELEMENT_NODE) {
// <h1>My API</h1>
if (isApiTitle(child.getNodeName())) {
definition.setName(child.getTextContent());
LOGGER.info("Found API: {}", definition.getName());
}
// <h2>GET /message</h2>
if (isEndpointHTTP(child.getNodeName())) {
// start of a new endpoint
currentEndpoint = new ResourceDefinition();
definition.addEndpoint(currentEndpoint);
LOGGER.info("Found endpoint: {}", currentEndpoint.getName());
final String[] http = child.getTextContent().split(" ");
currentEndpoint.setUrl(http[1]);
final RequestDefinition request = new RequestDefinition();
currentEndpoint.getRequests().add(request);
request.setVerb(http[0]);
}
// <ul><li><p>Response 200 (text/plain)</p>
if (isEndpointResponse(child.getNodeName())) {
final ResponseDefinition response = parseResponseDefinition(child);
populateResponseBody(response, child);
currentEndpoint.getResponses().put(response.getCode(), response);
}
}
}
}