use of org.jsoup.select.Elements in project flow by vaadin.
the class TemplateParser method getRootElement.
private static Element getRootElement(Document bodyFragment, TemplateResolver templateResolver) {
Elements children = bodyFragment.body().children();
int childNodeSize = children.size();
if (childNodeSize != 1) {
if (childNodeSize == 0) {
throw new TemplateParseException("AngularTemplate must not be empty. " + ROOT_CLARIFICATION);
} else {
throw new TemplateParseException("AngularTemplate must not have multiple root elements. " + ROOT_CLARIFICATION);
}
}
Element rootElement = children.get(0);
populateIncludes(rootElement, templateResolver);
return rootElement;
}
use of org.jsoup.select.Elements in project flow by vaadin.
the class TemplateDataAnalyzer method parseTemplate.
/**
* Gets the template data for the template initializer.
*
* @return the template data
*/
ParserData parseTemplate() {
TemplateData templateData = parser.getTemplateContent(templateClass, tag);
templateRoot = templateData.getTemplateElement();
htmlImportUri = templateData.getHtmlImportUri();
Elements templates = templateRoot.getElementsByTag("template");
for (org.jsoup.nodes.Element element : templates) {
org.jsoup.nodes.Element parent = element.parent();
if (parent != null && tag.equals(parent.id())) {
inspectCustomElements(element, element);
inspectTwoWayBindings(element);
}
}
collectInjectedIds(templateClass);
return readData();
}
use of org.jsoup.select.Elements in project flow by vaadin.
the class TemplateDataAnalyzer method indexOf.
/**
* Returns the index of the {@code child} in the collection of
* {@link org.jsoup.nodes.Element} children of the {@code parent} ignoring
* "style" elements.
* <p>
* "style" elements are handled differently depending on ES5/ES6. Also
* "style" tag can be moved on the top in the resulting client side DOM
* regardless of its initial position (e.g. Chrome does this).
*
* @param parent
* the parent of the {@code child}
* @param child
* the child element whose index is calculated
* @return the index of the {@code child} in the {@code parent}
*/
private static int indexOf(org.jsoup.nodes.Element parent, org.jsoup.nodes.Element child) {
Elements children = parent.children();
int index = -1;
for (org.jsoup.nodes.Element nextChild : children) {
if (!"style".equals(nextChild.tagName())) {
index++;
}
if (nextChild.equals(child)) {
break;
}
}
return index;
}
use of org.jsoup.select.Elements in project EhViewer by seven332.
the class EhEngine method commentGallery.
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, String comment) throws Exception {
FormBody.Builder builder = new FormBody.Builder().add("commenttext_new", comment);
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
Document document = Jsoup.parse(body);
Elements elements = document.select("#chd + p");
if (elements.size() > 0) {
throw new EhException(elements.get(0).text());
}
return GalleryDetailParser.parseComments(document);
} catch (Exception e) {
throwException(call, code, headers, body, e);
throw e;
}
}
use of org.jsoup.select.Elements in project EhViewer by seven332.
the class FavoritesParser method parse.
public static Result parse(String body) throws Exception {
if (body.contains("This page requires you to log on.</p>")) {
throw new EhException(GetText.getString(R.string.need_sign_in));
}
String[] catArray = new String[10];
int[] countArray = new int[10];
try {
Document d = Jsoup.parse(body);
Element ido = JsoupUtils.getElementByClass(d, "ido");
// noinspection ConstantConditions
Elements fps = ido.getElementsByClass("fp");
// Last one is "fp fps"
Assert.assertEquals(11, fps.size());
for (int i = 0; i < 10; i++) {
Element fp = fps.get(i);
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
catArray[i] = ParserUtils.trim(fp.child(2).text());
}
} catch (Exception e) {
e.printStackTrace();
throw new ParseException("Parse favorites error", body);
}
GalleryListParser.Result result = GalleryListParser.parse(body);
Result re = new Result();
re.catArray = catArray;
re.countArray = countArray;
re.pages = result.pages;
re.galleryInfoList = result.galleryInfoList;
return re;
}
Aggregations