use of javax.xml.parsers.SAXParser in project jangaroo-tools by CoreMedia.
the class ExmlValidator method setupSAXParser.
private SAXParser setupSAXParser() throws IOException {
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
ExmlSchemaResolver exmlSchemaResolver = new ExmlSchemaResolver();
schemaFactory.setResourceResolver(exmlSchemaResolver);
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(getClass().getResourceAsStream(Exmlc.EXML_SCHEMA_LOCATION), "exml"));
schemas.add(new StreamSource(getClass().getResourceAsStream(Exmlc.EXML_UNTYPED_SCHEMA_LOCATION), "untyped"));
Collection<ExmlSchemaSource> exmlSchemaSources = exmlSchemaSourceByNamespace.values();
for (ExmlSchemaSource exmlSchemaSource : exmlSchemaSources) {
schemas.add(exmlSchemaSource.newStreamSource());
}
Schema exmlSchema = schemaFactory.newSchema(schemas.toArray(new Source[schemas.size()]));
final SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
saxFactory.setSchema(exmlSchema);
SAXParser saxParser = saxFactory.newSAXParser();
saxParser.getXMLReader().setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
});
return saxParser;
} catch (ParserConfigurationException e) {
throw new IllegalStateException("A default dom builder should be provided.", e);
} catch (SAXParseException e) {
// SAX parser error while parsing EXML schemas: log only, will cause error or warning, depending on configuration:
logSAXParseException(null, e, true);
return null;
} catch (SAXException e) {
throw new IllegalStateException("SAX parser does not support validation.", e);
}
}
use of javax.xml.parsers.SAXParser in project smali by JesusFreke.
the class BaksmaliOptions method loadResourceIds.
/**
* Load the resource ids from a set of public.xml files.
*
* @param resourceFiles A map of resource prefixes -> public.xml files
*/
public void loadResourceIds(Map<String, File> resourceFiles) throws SAXException, IOException {
for (Map.Entry<String, File> entry : resourceFiles.entrySet()) {
try {
SAXParser saxp = SAXParserFactory.newInstance().newSAXParser();
final String prefix = entry.getKey();
saxp.parse(entry.getValue(), new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attr) throws SAXException {
if (qName.equals("public")) {
String resourceType = attr.getValue("type");
String resourceName = attr.getValue("name").replace('.', '_');
Integer resourceId = Integer.decode(attr.getValue("id"));
String qualifiedResourceName = String.format("%s.%s.%s", prefix, resourceType, resourceName);
resourceIds.put(resourceId, qualifiedResourceName);
}
}
});
} catch (ParserConfigurationException ex) {
throw new RuntimeException(ex);
}
}
}
use of javax.xml.parsers.SAXParser in project AndroidDevelop by 7449.
the class XmlManager method initProvinceDatas.
public void initProvinceDatas(AssetManager assetManager) {
try {
InputStream input = assetManager.open(PROVINCE_DATA);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = spf.newSAXParser();
XmlParserHandler handler = new XmlParserHandler();
parser.parse(input, handler);
input.close();
List<ProvinceResult> provinceList = handler.getDataList();
// 初始化默认选中的省、市、区
if (provinceList != null && !provinceList.isEmpty()) {
mCurrentProviceName = provinceList.get(0).getName();
List<CityResult> cityList = provinceList.get(0).getCityList();
if (cityList != null && !cityList.isEmpty()) {
mCurrentCityName = cityList.get(0).getName();
List<DistrictResult> districtList = cityList.get(0).getDistrictList();
mCurrentDistrictName = districtList.get(0).getName();
mCurrentZipCode = districtList.get(0).getZipcode();
}
mProvinceDatas = new String[provinceList.size()];
for (int i = 0; i < provinceList.size(); i++) {
// 遍历所有省的数据
mProvinceDatas[i] = provinceList.get(i).getName();
cityList = provinceList.get(i).getCityList();
String[] cityNames = new String[cityList.size()];
for (int j = 0; j < cityList.size(); j++) {
// 遍历省下面的所有市的数据
cityNames[j] = cityList.get(j).getName();
List<DistrictResult> districtList = cityList.get(j).getDistrictList();
String[] distrinctNameArray = new String[districtList.size()];
DistrictResult[] distrinctArray = new DistrictResult[districtList.size()];
for (int k = 0; k < districtList.size(); k++) {
// 遍历市下面所有区/县的数据
DistrictResult districtResult = new DistrictResult(districtList.get(k).getName(), districtList.get(k).getZipcode());
// 区/县对于的邮编,保存到mZipcodeDatasMap
mZipcodeDatasMap.put(districtList.get(k).getName(), districtList.get(k).getZipcode());
distrinctArray[k] = districtResult;
distrinctNameArray[k] = districtResult.getName();
}
// 市-区/县的数据,保存到mDistrictDatasMap
mDistrictDatasMap.put(cityNames[j], distrinctNameArray);
}
// 省-市的数据,保存到mCitisDatasMap
mCitisDatasMap.put(provinceList.get(i).getName(), cityNames);
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
use of javax.xml.parsers.SAXParser in project ACS by ACS-Community.
the class CDBAccess method internalConnect.
/**
* Performs the connect of the specified DAO.
*
* @param proxy the proxy to connect, non-<code>null</code>
*/
private void internalConnect(DAOProxy proxy) {
String curl = null;
try {
checkDALConnection();
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("Failed to obtain DAO for proxy '" + proxy + "'.", th);
throw re;
}
DAOOperations dao = null;
try {
curl = proxy.getCURL();
if (remoteDAO) {
dao = dalReference.get_DAO_Servant(curl);
} else {
String xml = dalReference.get_DAO(curl);
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
// use CDB XML handler which does not creates strings...
XMLHandler xmlSolver = new XMLHandler(false, logger);
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
if (xmlSolver.m_errorString != null) {
AcsJCDBXMLErrorEx e = new AcsJCDBXMLErrorEx();
e.setErrorString("XML parser error: " + xmlSolver.m_errorString);
throw e;
//throw new XMLerror("XML parser error: " + xmlSolver.m_errorString);
}
// create non-CORBA related, silent DAO
dao = new DAOImpl(curl, xmlSolver.m_rootNode, null, logger, true);
proxy.setElementName(xmlSolver.m_rootNode.getName());
}
// register listener, if not already registered
if (changeListener != null) {
if (!changeListener.isRegistered(curl))
changeListener.handle(dalReference, curl, proxy);
}
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("Failed to obtain DAO object for proxy '" + proxy + "'.", th);
throw re;
}
try {
proxy.initialize(dao);
} catch (Throwable th) {
// TODO @todo replace
RuntimeException re = new RuntimeException("The proxy '" + proxy + "' rejects the DAO.", th);
throw re;
}
logger.config("Connected to DAO '" + proxy.getCURL() + "'.");
}
use of javax.xml.parsers.SAXParser in project ACS by ACS-Community.
the class WDALImpl method parseXML.
private void parseXML(String xml, XMLHandler xmlSolver) throws CDBXMLErrorEx {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
if (xmlSolver.m_errorString != null) {
String info = "XML parser error: " + xmlSolver.m_errorString;
CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr;
}
} catch (Throwable t) {
String info = "SAXException " + t;
CDBXMLErrorEx xmlErr = new CDBXMLErrorEx();
logger.log(AcsLogLevel.NOTICE, info);
throw xmlErr;
}
}
Aggregations