Package org.apache.devicemap.loader.parser

Examples of org.apache.devicemap.loader.parser.XMLParser


    /*
     * loads device data from an InputStreamReader
     */
    private void loadDeviceData(Reader in) throws IOException {
        XMLParser parser = new XMLParser(in);
        String tag;
        Device device = new Device();
        Map<String, String> attributes = new HashMap<String, String>();

        while (!(tag = parser.getNextTag()).isEmpty()) {
            //new device found
            if (tag.startsWith("<device ")) {
                device.setId(XMLParser.getAttribute(tag, "id"));
                device.setParentId(XMLParser.getAttribute(tag, "parentId"));
            } else if (tag.equals("</device>")) {
View Full Code Here


    /*
     * loads patterns from an InputStreamReader
     */
    private void loadDevicePatterns(Reader in) throws IOException {
        XMLParser parser = new XMLParser(in);
        String tag;
        String builder = "";
        Device device = null;
        String id = "";
        List<String> patterns = new ArrayList<String>();

        while (!(tag = parser.getNextTag()).isEmpty()) {
            //new builder found
            if (tag.startsWith("<builder ")) {
                builder = XMLParser.getAttribute(tag, "class");

                if (builder.lastIndexOf(".") >= 0) {
                    builder = builder.substring(builder.lastIndexOf(".") + 1);
                }
            } else if (tag.startsWith("<device ")) {
                //new device found
                id = XMLParser.getAttribute(tag, "id");
                device = devices.get(id);
            } else if (tag.equals("</device>")) {
                //add the device
                if (device != null) {
                    //TwoStep is an AND pattern, also index the unigram
                    if (builder.equals("TwoStepDeviceBuilder")) {
                        device.getPatterns().setAndPattern(patterns);

                        String unigram = "";

                        for (String pattern : patterns) {
                            if (pattern.contains(unigram)) {
                                unigram = pattern;
                            } else {
                                unigram += pattern;
                            }
                        }

                        device.getPatterns().setPattern(unigram);
                    } else {
                        device.getPatterns().setOrPattern(patterns);
                    }

                    if (builder.equals("SimpleDeviceBuilder")) {
                        device.setType("simple");
                    } else {
                        device.setType("weak");
                    }
                } else {
                    Util.debugLog("ERROR: device not found: '" + id + "'");
                }

                //reset the device
                device = null;
                id = "";
                patterns = new ArrayList<String>();
            } else if (tag.equals("<value>")) {
                //add the pattern to the device
                String pattern = Util.normalize(parser.getTagValue());

                if (pattern.isEmpty()) {
                    continue;
                }

View Full Code Here

TOP

Related Classes of org.apache.devicemap.loader.parser.XMLParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.