If you think the Android project dccsched listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2010 Google Inc./*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.underhilllabs.dccsched.io;
import com.underhilllabs.dccsched.io.XmlHandler.HandlerException;
import com.underhilllabs.dccsched.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import java.io.IOException;
import java.io.InputStream;
/**
* Opens a local {@link Resources#getXml(int)} and passes the resulting
* {@link XmlPullParser} to the given {@link XmlHandler}.
*/publicclass LocalExecutor {
private Resources mRes;
private ContentResolver mResolver;
public LocalExecutor(Resources res, ContentResolver resolver) {
mRes = res;
mResolver = resolver;
}
publicvoid execute(Context context, String assetName, XmlHandler handler)
throws HandlerException {
try {
final InputStream input = context.getAssets().open(assetName);
final XmlPullParser parser = ParserUtils.newPullParser(input);
handler.parseAndApply(parser, mResolver);
} catch (HandlerException e) {
throw e;
} catch (XmlPullParserException e) {
thrownew HandlerException("Problem parsing local asset: " + assetName, e);
} catch (IOException e) {
thrownew HandlerException("Problem parsing local asset: " + assetName, e);
}
}
publicvoid execute(int resId, XmlHandler handler) throws HandlerException {
final XmlResourceParser parser = mRes.getXml(resId);
try {
handler.parseAndApply(parser, mResolver);
} finally {
parser.close();
}
}
}