@Test public void testGetMethods() throws Exception { final DTD dtd = DTD.getDTD("html.dtd"); final String javaDocPath = String.class.getName().replaceAll("\\.", "/") + ".html"; final JavadocParser htmlParser = new JavadocParser(dtd, javaDocPath); htmlParser.parse(new InputStreamReader(new URL(JAVA6_STRING).openStream(), "UTF-8")); assertNull("Java6 getErrorMessage", htmlParser.getErrorMessage()); assertEquals("Java6 getMethods", 65, htmlParser.getMethods().size()); htmlParser.reset(); htmlParser.parse(new InputStreamReader(new URL(JAVA7_STRING).openStream(), "UTF-8")); assertNull("Java7 getErrorMessage", htmlParser.getErrorMessage()); assertEquals("Java7 getMethods", 65, htmlParser.getMethods().size()); htmlParser.reset(); htmlParser.parse(new InputStreamReader(new URL(JAVA8_STRING).openStream(), "UTF-8")); assertNull("Java8 getErrorMessage", htmlParser.getErrorMessage()); assertEquals("Java8 getMethods", 67, htmlParser.getMethods().size()); }
public static void main(String[] args) throws Exception { final DTD html32 = DTD.getDTD("html32"); ContentModel contentModel = new ContentModel('&', new ContentModel()); Element elem1 = html32.getElement("html-element"); contentModel.first(elem1); Element elem2 = html32.getElement("test-element"); // Shouldn't throw ArrayIndexOutOfBoundsException contentModel.first(elem2); }
private static node optionalTransform(ContentModel c, DTD dtd) { node n; if (c.content instanceof ContentModel) n = transform((ContentModel) c.content, dtd); else /* A single token with the specified operation */ n = new node((char) 0, (char) 0, c.content); return n; }
private static DTD getDTD() { if (dtd == null) { try { dtd = DTD.getDTD("writer"); dtd.read(new DataInputStream( dtd.getClass().getResourceAsStream("transitional401.bdtd"))); } catch (IOException e) { e.printStackTrace(); } } return dtd; }
public void testAttributeGetter() throws Exception { // Create a chain of 24 attributes: AttributeList list = new AttributeList("heading"); AttributeList head = list; list.value = null; for (int i = 0; i < 24; i++) { AttributeList a = new AttributeList("a" + i); a.value = "v" + i; list.next = a; list = a; } Element e = DTD.getDTD("test").getElement("e"); e.atts = head; for (int i = 0; i < 24; i++) { // Check if the name is found. assertEquals(e.getAttribute("a" + i).toString(), "a" + i); // Check if the attribute value is correct. assertEquals(e.getAttribute("a" + i).value, "v" + i); // Check if the attribute can be found by value. assertEquals(e.getAttributeByValue("v" + i).name, "a" + i); } // Check is the null value is searched correctly. assertEquals(e.getAttributeByValue(null).toString(), "heading"); // Check for unknown attribute assertEquals(e.getAttribute("audrius"), null); // Check for unknown value assertEquals(e.getAttributeByValue("audrius"), null); }
gnuParser(DTD d) { super(d); }
DTD getDTD() { // Accessing the inherited gnu.javax.swing.text.html.parser.support.Parser // field. super. is a workaround, required to support JDK1.3's javac. return super.dtd; }
/** * Create the parser that uses the given DTD to parse the document. * * @param theDtd the DTD */ public GnuParserDelegator(DTD theDtd) { this.theDtd = theDtd; gnu = new gnuParser(theDtd); }
/** * Transform into internal representation. * @param c a model to transform * @return a transformed model * @throws Error if the model structure contains errors. */ public static node transform(ContentModel c, DTD dtd) { // Handle the special cases first. if (c.content instanceof node) return (node) c.content; // Do the typical transform. node n; /* Case with the single token */ if (c.next == null) { n = optionalTransform(c, dtd); } else /* Case with the chain of the multiple tokens. */ { node[] l = new node[ measureChainLength(c) ]; ContentModel m = c; for (int i = 0; i < l.length; i++) { if (m.content instanceof ContentModel) { ContentModel nested = (ContentModel) m.content; if (nested.next == null && !(nested.content instanceof ContentModel) ) { l [ i ] = new node((char) m.type, (char) nested.type, nested.content); } else { l [ i ] = transform(nested, dtd); } } else l [ i ] = new node((char) 0, (char) 0, m.content); addtype(l [ i ], (char) m.type); m = m.next; } if (isBinary(c.type)) for (int i = 0; i < l.length; i++) { l [ i ].binary = (char) c.type; } n = new list(l); } addtype(n, (char) c.type); return n; }
public TableRowContentModel(DTD dtd) { super((char) 0, (char) 0, null); TD = dtd.getElement("TD"); }
/** * Creates a new Parser that uses the given * {@link javax.swing.text.html.parser.DTD }. The only standard way * to get an instance of DTD is to construct it manually, filling in * all required fields. * @param a_dtd The DTD to use. The parser behaviour after passing null * as an argument is not documented and may vary between implementations. */ public Parser(DTD a_dtd) { if (a_dtd == null) dtd = gnu.javax.swing.text.html.parser.HTML_401F.getInstance(); else dtd = a_dtd; defaulter = new parameterDefaulter(dtd); validator = new htmlValidator(dtd) { /** * Handles the error message. This method must be overridden to pass * the message where required. * @param msg The message text. */ protected void s_error(String msg) { error(msg); } /** * The method is called when the tag validator decides to close the * tag on its own initiative. After reaching the end of stream, * The tag validator closes all unclosed elements that are required * to have the end (closing) tag. * * @param tElement The tag being fictionally (forcibly) closed. */ protected void handleSupposedEndTag(Element tElement) { // The tag is cloned as the original tElement is the // element from the starting tag - may be accidently used // somewhere else. TagElement tag = makeTag(tElement, true); _handleEndTag_remaining(tag); } /** * The method is called when the the tag validator decides to open * the new tag on its own initiative. The tags, opened in this * way, are HTML, HEAD and BODY. The attribute set is temporary * assigned to the empty one, the previous value is * restored before return. * * @param tElement The tag being fictionally (forcibly) closed. */ protected void handleSupposedStartTag(Element tElement) { TagElement tag = makeTag(tElement, true); htmlAttributeSet were = attributes; attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; _handleStartTag(tag); attributes = were; } }; }
@Override public List<String> getSignatureList() throws MojoExecutionException { // signatures as map from signature with no arg names to arg names from JavadocParser Map<String, String> result = new HashMap<String, String>(); final Pattern packagePatterns = Pattern.compile(excludePackages); final Pattern classPatterns = (excludeClasses != null) ? Pattern.compile(excludeClasses) : null; final Pattern includeMethodPatterns = (includeMethods != null) ? Pattern.compile(includeMethods) : null; final Pattern excludeMethodPatterns = (excludeMethods != null) ? Pattern.compile(excludeMethods) : null; // for proxy class and super classes not matching excluded packages or classes for (Class<?> aClass = getProxyType(); aClass != null && !packagePatterns.matcher(aClass.getPackage().getName()).matches() && (classPatterns == null || !classPatterns.matcher(aClass.getSimpleName()).matches()); aClass = aClass.getSuperclass()) { log.debug("Processing " + aClass.getName()); final String javaDocPath = aClass.getName().replaceAll("\\.", "/").replace('$', '.') + ".html"; // read javadoc html text for class InputStream inputStream = null; try { inputStream = getProjectClassLoader().getResourceAsStream(javaDocPath); if (inputStream == null) { log.debug("JavaDoc not found on classpath for " + aClass.getName()); break; } // transform the HTML to get method summary as text // dummy DTD final DTD dtd = DTD.getDTD("html.dtd"); final JavadocParser htmlParser = new JavadocParser(dtd, javaDocPath); htmlParser.parse(new InputStreamReader(inputStream, "UTF-8")); // look for parse errors final String parseError = htmlParser.getErrorMessage(); if (parseError != null) { throw new MojoExecutionException(parseError); } // get public method signature final Map<String, String> methodMap = htmlParser.getMethodText(); for (String method : htmlParser.getMethods()) { if (!result.containsKey(method) && (includeMethodPatterns == null || includeMethodPatterns.matcher(method).find()) && (excludeMethodPatterns == null || !excludeMethodPatterns.matcher(method).find())) { final int leftBracket = method.indexOf('('); final String name = method.substring(0, leftBracket); final String args = method.substring(leftBracket + 1, method.length() - 1); String[] types; if (args.isEmpty()) { types = new String[0]; } else { // get raw types from args final List<String> rawTypes = new ArrayList<String>(); final Matcher argTypesMatcher = RAW_ARGTYPES_PATTERN.matcher(args); while (argTypesMatcher.find()) { rawTypes.add(argTypesMatcher.group(1)); } types = rawTypes.toArray(new String[rawTypes.size()]); } final String resultType = getResultType(aClass, name, types); if (resultType != null) { result.put(method, resultType + " " + name + methodMap.get(method)); } } } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtil.close(inputStream); } } if (result.isEmpty()) { throw new MojoExecutionException("No public non-static methods found, " + "make sure Javadoc is available as project test dependency"); } return new ArrayList<String>(result.values()); }
public JavadocParser(DTD dtd, String docPath) { super(dtd); this.hrefPattern = docPath + "#"; parserState = ParserState.INIT; }
HTMLParser() throws IOException { DTD dtd = DTD.getDTD("reader"); dtd.read(new DataInputStream(dtd.getClass().getResourceAsStream("html32.bdtd")));//transitional401.bdtd"))); parser = new ParserImpl(dtd); }
public ParserImpl(DTD dtd) { super(dtd); }
@Override protected void setUp() throws Exception { super.setUp(); dtd = DTD.getDTD("testDTD"); }