Example usage for javax.swing.text.html.parser DTD getDTD

List of usage examples for javax.swing.text.html.parser DTD getDTD

Introduction

In this page you can find the example usage for javax.swing.text.html.parser DTD getDTD.

Prototype

public static DTD getDTD(String name) throws IOException 

Source Link

Document

Returns a DTD with the specified name.

Usage

From source file:Main.java

public static void main(String[] args) {

    try {/* w  w  w  . j av a2  s.c om*/
        DTD d1 = DTD.getDTD("html");
        for (int i = 0; i < 14; i++) {
            System.out.println(d1.getElement(i).getName());
        }

    } catch (IOException e) {
        System.err.println(e);
        e.printStackTrace();
    }

}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from w  w  w  . j a  v a 2s  .  c om*/
        URL u = new URL("http://www.java2s.com");
        OutputStream out = new FileOutputStream("test.htm");
        InputStream in = u.openStream();
        DTD html = DTD.getDTD("html");
        System.out.println(html.getName());
        in.close();
        out.flush();
        out.close();
    } catch (Exception e) {
        System.err.println("Usage: java PageSaver url local_file");
    }

}

From source file:org.apache.camel.maven.JavadocApiMethodGeneratorMojo.java

@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("\\.", "/") + ".html";

        // read javadoc html text for class
        InputStream inputStream = null;
        try {//from   w  w w .  j av  a 2 s . c  om
            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) {
                        final StringBuilder signature = new StringBuilder(resultType);
                        signature.append(" ").append(name).append(methodMap.get(method));
                        result.put(method, signature.toString());
                    }
                }
            }
        } 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());
}