本文整理汇总了Java中jodd.jerry.Jerry类的典型用法代码示例。如果您正苦于以下问题:Java Jerry类的具体用法?Java Jerry怎么用?Java Jerry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Jerry类属于jodd.jerry包,在下文中一共展示了Jerry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: completeLogin
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Attempt to complete the login process
*/
private void completeLogin() {
Log.d(TAG, "completing login...");
mRequestFactory.get(mAuthUrl, true, new RequestListener() {
@Override
public void onSucceeded(URL url, String data) {
mListener.authProgress(80);
if (url.getPath().equals("/account/prompt")) {
Jerry doc = jerry(data);
mSessionId = doc.$("input[name=session]").attr("value");
mSessionFkey = doc.$("input[name=fkey]").attr("value");
if (mSessionId == null || mSessionId.isEmpty() ||
mSessionFkey == null || mSessionId.isEmpty()) {
mListener.authFailed(mContext.getResources().getText(R.string.se_auth_unable_to_read_session).toString());
} else {
confirmOpenId();
}
} else if (url.getPath().equals("/")) {
mListener.authSucceeded(mRequestFactory.cookies());
}
}
});
}
示例2: getPartnerNameFromTransparencyRegister
import jodd.jerry.Jerry; //导入依赖的package包/类
private String getPartnerNameFromTransparencyRegister(String string) {
try {
File file = new File(SystemUtil.tempDir(), "partner.html");
NetUtil.downloadFile(
"http://ec.europa.eu/transparencyregister/public/consultation/displaylobbyist.do?id=" + string,
file);
name = "";
// create Jerry, i.e. document context
Jerry doc = Jerry.jerry(FileUtil.readString(file));
// parse
doc.$("div.panel-body h4").each(new JerryFunction() {
public boolean onNode(Jerry $this, int index) {
name = $this.$("b").text();
return true;
}
});
} catch (IOException e) {
e.printStackTrace();
}
log.info(name);
return name;
}
示例3: webFullName
import jodd.jerry.Jerry; //导入依赖的package包/类
public static String webFullName(final String firstName, final String href) {
String _xblockexpression = null;
{
Jerry _parts = TungParser.parts(href, ".listbox1 .listbox1_text");
String _text = _parts.text();
String[] _split = _text.split(firstName);
final Function1<String, Boolean> _function = (String it) -> {
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it);
return Boolean.valueOf((!_isNullOrEmpty));
};
Iterable<String> _filter = IterableExtensions.<String>filter(((Iterable<String>)Conversions.doWrapArray(_split)), _function);
final List<String> lastNames = IterableExtensions.<String>toList(_filter);
double _random = Math.random();
int _size = lastNames.size();
double _multiply = (_random * _size);
final int lastNameIndex = ((int) _multiply);
final String lastName = lastNames.get(lastNameIndex);
_xblockexpression = (firstName + lastName);
}
return _xblockexpression;
}
示例4: createTest
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* 创建测试邮件
* @param books
*/
public static String createTest(Map<String,String> books){
try {
Jerry doc = jerry(FileUtil.readString(Thread.currentThread().getContextClassLoader().getResource("/templateTest").getFile()));
for(Map.Entry<String,String> book:books.entrySet()){
doc.$("#booksContent").append(createNode(book));
}
return doc.htmlAll(true);
} catch (IOException e) {
e.printStackTrace();
System.out.println("未找到文件");
}
return null;
}
示例5: parse
import jodd.jerry.Jerry; //导入依赖的package包/类
public static List<Book> parse(String page, final String username){
books.clear();
Jerry doc = Jerry.jerry(page);
// final List<Book> books = new ArrayList<Book>();
doc.$(CLASSNAME).each(new JerryFunction() {
Book book = new Book(username);
@Override
public boolean onNode(Jerry $this, int index) {
if (index % 8 == 0) {
book = new Book(username);
books.add(book);
}
BookInjection.init(book, index, $this.text());
return true;
}
});
return books;
}
示例6: parseDocuments
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Parses a Jerry node and returns the documents found within
* @param page A Jerry node containing documents
* @return A list of documents
*/
private static List<Document> parseDocuments(Jerry page) {
List<Document> documents = new ArrayList<Document>();
String head = page.$("head").first().html();
if(head != null){
Matcher m = DOCUMENT_REGEX.matcher(head);
if(m.find()){
String json = m.group(2).trim().substring(0, m.group(2).trim().length() - 1).trim();
JSONDocument jsonDocument = new Gson().fromJson(json, JSONDocument.class);
if(jsonDocument!= null && jsonDocument.getType().equals(Constants.TYPE_ROOT)){
if(jsonDocument.getItems() != null) {
documents.addAll(parseDirectory(jsonDocument.getItems()));
}
}
}
}
return documents;
}
示例7: parseCourses
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Parses a given Jerry node and returns the courses
* @param page The Jerry node to be parsed
* @return A list of parsed courses
*/
private static List<Course> parseCourses(Jerry page) {
final List<Course> courses = new ArrayList<Course>();
Node node = page.$(Constants.COURSE_LIST).get(0);
if (node != null) {
page.$(Constants.COURSE).each(new JerryFunction() {
public boolean onNode(Jerry jerry, int i) {
String[] cName = jerry.text().split("\n");
String[] href = jerry.attr("href").split("/");
Course course = new Course(href[href.length - 1].trim(), cName[1].trim());
courses.add(course);
return true;
}
});
}
return courses;
}
示例8: extract
import jodd.jerry.Jerry; //导入依赖的package包/类
@Override
public String extract(String data) {
Jerry doc = jerry(data);
String result = "";
switch (outType) {
case TYPE_TEXT:
result = parse(doc.$(query).first().text());
break;
case TYPE_HTML:
result = parse(doc.$(query).first().html());
break;
default:
result = parse(doc.$(query).first().attr(outType));
break;
}
return result;
}
示例9: extractList
import jodd.jerry.Jerry; //导入依赖的package包/类
@Override
public List<String> extractList(String data) {
List<String> strings = new LinkedList<>();
Jerry doc = jerry(data);
Node[] nodes = doc.$(query).get();
for (Node node : nodes) {
switch (outType) {
case TYPE_TEXT:
strings.add(parse(node.getTextContent()));
break;
case TYPE_HTML:
strings.add(parse(node.getHtml()));
break;
default:
strings.add(parse(node.getAttribute(outType)));
break;
}
}
return strings;
}
示例10: parse
import jodd.jerry.Jerry; //导入依赖的package包/类
private Page parse(String data)
{
// Begin by parsing the page
Jerry doc = jerry(data);
// Extract the room name and icon
String name = doc.$("#roomname").text();
String icon = doc.$("link[rel=shortcut icon]").attr("href");
// TODO: Extract a suitable color for the page
int color = 1;
return new Page(name, icon, color);
}
示例11: getTitle
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* getTitle receives a url parameter and return a Response object that hoold the page title
* @param url The HTML page url
* @return Response
*/
static Response getTitle(String url) {
HttpBrowser browser = new HttpBrowser();
HttpRequest request = HttpRequest.get(url);
browser.sendRequest(request);
String page = browser.getPage();
Jerry doc = Jerry.jerry(page);
return new Response(doc.$("title").text());
}
示例12: verifyLogin
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Verifies login for the user after calling connect
* @return Returns true if the login was correct
* @throws LoginFailedException Is thrown if the login was incorrect
*/
public boolean verifyLogin() throws LoginFailedException, IOException {
// Check index page
String response = _browser.get(Constants.INDEX_URL);
// Check to see if we find a course list
if (response != null) {
Jerry i = Jerry.jerry(response);
Node node = i.$(Constants.COURSE_LIST).get(0);
if (node != null) {
return true;
}
}
throw new LoginFailedException();
}
示例13: getDocuments
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Returns a list of documents for the given course
* @param client An instance of the MinervaClient client
* @param course The course of which the documents need to be retrieved
* @return A list of documents
*/
public static List<Document> getDocuments(MinervaClient client, Course course) throws IOException {
String response = client.getClient().get(Constants.COURSE_URL + course.getCode() + Constants.DOCUMENT);
Jerry page;
try {
page = Jerry.jerry(new String(response.getBytes(), "UTF8"));
} catch (UnsupportedEncodingException ex){
page = Jerry.jerry(response);
}
client.checkLogin(client);
return parseDocuments(page);
}
示例14: getAnnouncements
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Parses the course page for the given course and returns the announcements
* @param course The course for which the announcements need to be retrieved
* @param client The MinervaClient instance
* @return Returns a list of announcements for this course
*/
public static List<Announcement> getAnnouncements(MinervaClient client, Course course) throws IOException {
String response = client.getClient().get(Constants.COURSE_URL + course.getCode() + Constants.ANNOUNCEMENT);
Jerry coursePage;
try {
coursePage = Jerry.jerry(new String(response.getBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
coursePage = Jerry.jerry(response);
}
client.checkLogin(client);
return parseAnnouncements(coursePage);
}
示例15: parseAnnouncements
import jodd.jerry.Jerry; //导入依赖的package包/类
/**
* Parses the given Jerry object to a list of announcements
* @param page The Jerry object to be parsed
* @return A list of announcements
*/
private static List<Announcement> parseAnnouncements(Jerry page) {
final List<Announcement> announcements = new ArrayList<Announcement>();
page.$(Constants.ANNOUNCEMENT_LIST).each(new JerryFunction() {
public boolean onNode(Jerry jerry, int i) {
Announcement announcement = parseAnnouncement(jerry);
if(announcement != null) {
announcements.add(announcement);
}
return true;
}
});
return announcements;
}