本文整理汇总了Java中com.johan.vertretungsplan.parser.BaseParser类的典型用法代码示例。如果您正苦于以下问题:Java BaseParser类的具体用法?Java BaseParser怎么用?Java BaseParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseParser类属于com.johan.vertretungsplan.parser包,在下文中一共展示了BaseParser类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doInBackground
import com.johan.vertretungsplan.parser.BaseParser; //导入依赖的package包/类
@Override
protected Object doInBackground(Void... params) {
BaseParser parser = ((VertretungsplanApplication) getApplication())
.getParser();
if (parser == null)
return null;
try {
Vertretungsplan v = parser.getVertretungsplan();
settings.edit()
.putString("Vertretungsplan", new Gson().toJson(v))
.commit();
AppWidgetManager mgr = AppWidgetManager
.getInstance(StartActivity.this);
int[] ids = mgr
.getAppWidgetIds(new ComponentName(StartActivity.this,
VertretungsplanWidgetProvider.class));
new VertretungsplanWidgetProvider().onUpdate(
StartActivity.this, mgr, ids);
return v;
} catch (Exception e) {
e.printStackTrace();
return e;
}
}
示例3: doInBackground
import com.johan.vertretungsplan.parser.BaseParser; //导入依赖的package包/类
@Override
protected Object doInBackground(Void... params) {
BaseParser parser = ((VertretungsplanApplication) getApplication())
.getParser();
if (parser == null)
return null;
try {
Vertretungsplan v = parser.getVertretungsplan();
settings.edit()
.putString("Vertretungsplan", new Gson().toJson(v))
.commit();
AppWidgetManager mgr = AppWidgetManager
.getInstance(StartActivity.this);
int[] ids = mgr
.getAppWidgetIds(new ComponentName(StartActivity.this,
VertretungsplanWidgetProvider.class));
new VertretungsplanWidgetProvider().onUpdate(
StartActivity.this, mgr, ids);
return v;
} catch (Exception e) {
e.printStackTrace();
return e;
}
}
示例4: 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;
}
}