本文整理汇总了Java中com.johan.vertretungsplan.parser.BaseParser.setUsername方法的典型用法代码示例。如果您正苦于以下问题:Java BaseParser.setUsername方法的具体用法?Java BaseParser.setUsername怎么用?Java BaseParser.setUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.johan.vertretungsplan.parser.BaseParser
的用法示例。
在下文中一共展示了BaseParser.setUsername方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkLogin
import com.johan.vertretungsplan.parser.BaseParser; //导入方法依赖的package包/类
public static void checkLogin(String schoolId, String login, String password) throws Exception {
Schule school = getSchoolById(schoolId);
BaseParser parser = BaseParser.getInstance(school);
parser.setUsername(login);
parser.setPassword(password);
Vertretungsplan v = parser.getVertretungsplan();
if (v.getTage().size() == 0)
throw new Exception("kein Vertretungsplanabruf möglich");
}
示例2: parse
import com.johan.vertretungsplan.parser.BaseParser; //导入方法依赖的package包/类
public ParseResult parse() throws IOException, NoCredentialsAvailableException {
JSONObject json = new JSONObject(schoolData);
Schule schule = Schule.fromJSON(schoolId, json);
DBCollection cookiesColl = db.getCollection("cookies");
String login = null;
String password = null;
DBObject reg = null;
DBCollection regColl = null;
if (schule.getData().has("login") && !test) {
regColl = db.getCollection("registrations");
BasicDBObject query2 = new BasicDBObject("schoolId", schoolId);
query2.append("login", new BasicDBObject("$ne", ""));
query2.append("password", new BasicDBObject("$ne", ""));
query2.append("password_invalid", new BasicDBObject("$ne", "true"));
DBCursor regs = regColl.find(query2);
int n = regs.count();
if (n == 0) {
throw new NoCredentialsAvailableException();
}
int rand = (int) Math.floor(Math.random() * (n-1));
regs.skip(rand);
reg = regs.next();
regs.close();
login = (String) reg.get("login");
password = (String) reg.get("password");
}
BaseParser parser = BaseParser.getInstance(schule);
if (login != null && password != null) {
parser.setUsername(login);
parser.setPassword(password);
}
try {
Vertretungsplan v = parser.getVertretungsplan();
v.setSchoolName(schule.getName());
v.setCity(schule.getCity());
List<BaseAdditionalInfoParser> additionalInfoParsers = new ArrayList<BaseAdditionalInfoParser>();
for(String type:schule.getAdditionalInfos()) {
additionalInfoParsers.add(BaseAdditionalInfoParser.getInstance(type));
}
for(BaseAdditionalInfoParser additionalInfoParser:additionalInfoParsers) {
v.getAdditionalInfos().add(additionalInfoParser.getAdditionalInfo());
}
ParseResult result = new ParseResult();
result.v = v;
result.classes = parser.getAllClasses();
if (reg != null) {
regColl.remove(reg);
reg.put("password_invalid", false);
regColl.insert(reg);
}
return result;
} catch (IOException e) {
if (e.getMessage() != null) {
String msg = e.getMessage().toLowerCase();
if (reg != null && (msg.contains("login") || msg.contains("authorization"))) {
regColl.remove(reg);
reg.put("password_invalid", true);
regColl.insert(reg);
}
}
cookiesColl.remove(new BasicDBObject("_id", schule.getId()));
throw e;
}
}