Search in sources :

Example 36 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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();
    }
}
Also used : InputStream(java.io.InputStream) ProvinceResult(com.wheelview.result.ProvinceResult) SAXParser(javax.xml.parsers.SAXParser) DistrictResult(com.wheelview.result.DistrictResult) SAXParserFactory(javax.xml.parsers.SAXParserFactory) CityResult(com.wheelview.result.CityResult)

Example 37 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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() + "'.");
}
Also used : XMLHandler(com.cosylab.cdb.jdal.XMLHandler) InputSource(org.xml.sax.InputSource) DAOOperations(com.cosylab.CDB.DAOOperations) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) DAOImpl(com.cosylab.cdb.jdal.DAOImpl) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 38 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory 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;
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) CDBXMLErrorEx(alma.cdbErrType.CDBXMLErrorEx) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 39 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project ACS by ACS-Community.

the class CDBDefault method main.

public static void main(String[] args) {
    try {
        strIOR = null;
        if (args.length < 2) {
            System.out.println("Usage: cmd <idl_type> <instance_name> [-d ior -h]");
            return;
        }
        m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("CDBDefault", true);
        String in_type = args[0];
        String in_name = args[1];
        curl_allComponents = "MACI/Components";
        curl = curl_allComponents + "/" + in_name;
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-d")) {
                if (i < args.length - 1) {
                    strIOR = args[++i];
                }
            }
            if (args[i].equals("-h")) {
                System.out.println("Usage: cmd idl_type instance_name [-d ior -h]");
                return;
            }
        }
        if (strIOR == null) {
            strIOR = "corbaloc::" + InetAddress.getLocalHost().getHostName() + ":" + ACSPorts.getCDBPort() + "/CDB";
        }
        // create and initialize the ORB
        orb = ORB.init(new String[0], null);
        WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
        String xml = wdal.get_DAO(curl_allComponents);
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        XMLHandler xmlSolver = new XMLHandler(false, m_logger);
        saxParser.parse(new InputSource(new StringReader(xml)), xmlSolver);
        if (xmlSolver.m_errorString != null) {
            String info = "XML parser error: " + xmlSolver.m_errorString;
            AcsJCDBXMLErrorEx cdbxmlErr = new AcsJCDBXMLErrorEx();
            //XMLerror xmlErr = new XMLerror(info);
            throw cdbxmlErr;
        }
        setDefault(xmlSolver.m_rootNode, in_type, in_name);
    } catch (AcsJCDBXMLErrorEx e) {
        m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
        e.printStackTrace();
    } catch (Exception e) {
        m_logger.log(AcsLogLevel.NOTICE, "Error", e);
        e.printStackTrace();
    }
}
Also used : WDAL(com.cosylab.CDB.WDAL) XMLHandler(com.cosylab.cdb.jdal.XMLHandler) InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) AcsJCDBXMLErrorEx(alma.cdbErrType.wrappers.AcsJCDBXMLErrorEx) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 40 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project spring-security-oauth by spring-projects.

the class SparklrServiceImpl method getSparklrPhotoIds.

public List<String> getSparklrPhotoIds() throws SparklrException {
    try {
        InputStream photosXML = new ByteArrayInputStream(sparklrRestTemplate.getForObject(URI.create(sparklrPhotoListURL), byte[].class));
        final List<String> photoIds = new ArrayList<String>();
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setValidating(false);
        parserFactory.setXIncludeAware(false);
        parserFactory.setNamespaceAware(false);
        SAXParser parser = parserFactory.newSAXParser();
        parser.parse(photosXML, new DefaultHandler() {

            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                if ("photo".equals(qName)) {
                    photoIds.add(attributes.getValue("id"));
                }
            }
        });
        return photoIds;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (SAXException e) {
        throw new IllegalStateException(e);
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attributes(org.xml.sax.Attributes) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SAXParserFactory (javax.xml.parsers.SAXParserFactory)183 SAXParser (javax.xml.parsers.SAXParser)141 InputSource (org.xml.sax.InputSource)76 SAXException (org.xml.sax.SAXException)75 IOException (java.io.IOException)62 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)53 XMLReader (org.xml.sax.XMLReader)37 DefaultHandler (org.xml.sax.helpers.DefaultHandler)27 InputStream (java.io.InputStream)22 File (java.io.File)21 SAXSource (javax.xml.transform.sax.SAXSource)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringReader (java.io.StringReader)15 Unmarshaller (javax.xml.bind.Unmarshaller)13 Attributes (org.xml.sax.Attributes)13 JAXBContext (javax.xml.bind.JAXBContext)12 SAXParseException (org.xml.sax.SAXParseException)10 InputStreamReader (java.io.InputStreamReader)9 ArrayList (java.util.ArrayList)9 ValidationEvent (javax.xml.bind.ValidationEvent)9