Java HTML Jsoup Element getCodeSnippetCLT(Element codeElement, String content, String fqn, String api, String kind, String[] titles)

Here you can find the source of getCodeSnippetCLT(Element codeElement, String content, String fqn, String api, String kind, String[] titles)

Description

get Code Snippet CLT

License

Open Source License

Declaration

public static List<Integer> getCodeSnippetCLT(Element codeElement, String content, String fqn, String api,
            String kind, String[] titles) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.nodes.Element;

public class Main {
    public static List<Integer> getCodeSnippetCLT(Element codeElement, String content, String fqn, String api,
            String kind, String[] titles) {
        List<Integer> indexes = new ArrayList<Integer>();

        if (codeElement.tagName().equals("pre")) {
            if (content.startsWith("M")) {
                content = content.split(":")[2];
            } else if (content.startsWith("F")) {
                content = content.split(":")[3];
            } else {
                String[] tmp = content.split(":")[1].split("\\.");

                if (tmp.length == 1)
                    content = tmp[0];/*  w  ww .  ja va2 s . c o  m*/
                else
                    content = tmp[1];
            }

            Pattern pattern;
            if (!kind.equals("method"))
                pattern = Pattern.compile("(?<=\\W)" + api + "(?=\\W)", Pattern.DOTALL);

            else
                pattern = Pattern.compile("(?<=\\W)" + api + "(?=\\()", Pattern.DOTALL);

            Matcher m = pattern.matcher(codeElement.html());

            while (m.find())
                indexes.add(m.regionStart());

            if (indexes.size() == 0)
                System.out.println("nothing was found");
        }

        return indexes;
    }
}

Related

  1. findRootElement(Element element)
  2. firstElement(final Element element, final String... tags)
  3. getActiveJob(Element element)
  4. getAllNodes(Element element)
  5. getAuthorName(Element authorElement)
  6. getDate(Elements caption)
  7. getDouble(Elements line, int idx)
  8. getElementByXPath(String xpath, Document doc)
  9. getElementsByClass(String className, Element boardElement)