JavaDocUtils { public String getTagContent(String tagName, Element element) { String comment = elements.getDocComment(element); if (StringUtils.isBlank(comment)) { return ""; } StringTokenizer st = new StringTokenizer(comment.trim(), "\n\r"); boolean insideTag = false; StringBuilder tagContent = new StringBuilder(); while (st.hasMoreTokens()) { String nextToken = st.nextToken().trim(); if (nextToken.startsWith("@" + tagName)) { return StringUtils.difference("@" + tagName, nextToken).trim(); } if (nextToken.startsWith("{@" + tagName)) { if (nextToken.endsWith("}")) { return StringUtils.difference("{@" + tagName, nextToken).replaceAll("}", "").trim(); } else { tagContent.append(StringUtils.difference("{@" + tagName, nextToken).replaceAll("}", "").trim()); insideTag = true; } } else if (insideTag) { if (nextToken.endsWith("}")) { tagContent.append(' ').append(nextToken.replaceAll("}", "")); insideTag = false; } else { tagContent.append(' ').append(nextToken); } } } return tagContent.toString(); } JavaDocUtils(Elements elements); String getSummary(Element element); boolean hasTag(String tagName, Element element); String getTagContent(String tagName, Element element); String getParameterSummary(String paramName, Element element);  }
@Test public void getTagContentMultiLineSampleTag() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Updates the given map of customer address attributes, for the given customer address\n" + " <p/>\n" + " {@sample.xml " + "../../../doc/magento-connector.xml.sample\n " + "magento:updateCustomerAddress}\n" + " \n" + " @param addressId the customer address to update\n" + " @param attributes the address attributes to update"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); String sample = javaDocUtils.getTagContent("sample.xml", executableElement); assertEquals("../../../doc/magento-connector.xml.sample magento:updateCustomerAddress", sample); }
@Test public void getTagContentSingleLineSampleTag() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Updates the given map of customer address attributes, for the given customer address\n" + " <p/>\n" + " {@sample.xml ../../../doc/magento-connector.xml.sample magento:updateCustomerAddress}\n" + " \n" + " @param addressId the customer address to update\n" + " @param attributes the address attributes to update"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); String sample = javaDocUtils.getTagContent("sample.xml", executableElement); assertEquals("../../../doc/magento-connector.xml.sample magento:updateCustomerAddress", sample); }