Examples of ParsedXML


Examples of gd.xml.tiny.ParsedXML

            Enumeration<?> children = node.elements();
            String name = null;
            Object value = null;

            while (children.hasMoreElements()) {
                ParsedXML child = (ParsedXML) children.nextElement();

                if (child.getName().equals("optionname")) { //$NON-NLS-1$
                    name = ((ParsedXML) child.elements().nextElement())
                            .getContent();
                } else if (child.getName().equals("optionvalue")) { //$NON-NLS-1$
                    value = ((ParsedXML) child.elements().nextElement())
                            .getContent();
                }
            }

            if ((null != name) && (null != value)) {
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        return 0;
    }

    public void readXMLOptions(ParsedXML node) {
        for (Enumeration<?> e = node.elements(); e.hasMoreElements();) {
            ParsedXML child = (ParsedXML) e.nextElement();
            if (child.getName().equals(CEIL_WEIGHT)) {
                readCeilWeight(child);
            } else if (child.getName().equals(MAX_OVERWEIGHT)) {
                maxOverweight = getContentAsFloat(child);
            } else if (child.getName().equals(SHOW_OVERWEIGHTED)) {
                showOverweighted = getContentAsBoolean(child);
            } else if (child.getName().equals(MIN_UNDERWEIGHT)) {
                minUnderweight = getContentAsFloat(child);
            } else if (child.getName().equals(SHOW_UNDERWEIGHTED)) {
                showUnderweighted = getContentAsBoolean(child);
            } else if (child.getName().equals(SHOW_CORRECTARMOR)) {
                showCorrectArmor = getContentAsBoolean(child);
            } else if (child.getName().equals(SHOW_CORRECTCRITICAL)) {
                showCorrectCritical = getContentAsBoolean(child);
            } else if (child.getName().equals(SHOW_FAILEDEQUIP)) {
                showFailedEquip = getContentAsBoolean(child);
            } else if (child.getName().equals(IGNORE_FAILED_EQUIP)) {
                StringTokenizer st = new StringTokenizer(getContent(child), ",");
                while (st.hasMoreTokens()) {
                    ignoreFailedEquip.addElement(st.nextToken());
                }

                for (int i = 0; i < ignoreFailedEquip.size(); i++) {
                    ignoreFailedEquip.setElementAt(ignoreFailedEquip.elementAt(
                            i).trim(), i);
                }
            } else if (child.getName().equals(SKIP)) {
                skip = getContentAsBoolean(child);
            } else if (child.getName().equals(TARGCOMP_CRITS)) {
                targCompCrits = getContentAsInteger(child);
            } else if (child.getName().equals(PRINTSIZE)) {
                printSize = getContentAsInteger(child);
            }
        }
    }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        }
    }

    private void readCeilWeight(ParsedXML node) {
        for (Enumeration<?> e = node.elements(); e.hasMoreElements();) {
            ParsedXML child = (ParsedXML) e.nextElement();
            String name = child.getName();
            if (name.equals(ENGINE)) {
                ceilEngine = 1 / getContentAsFloat(child);
            } else if (name.equals(STRUCTURE)) {
                ceilStructure = 1 / getContentAsFloat(child);
            } else if (name.equals(ARMOR)) {
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

            if (loc == -1) {
                throw new EntityLoadingException("   Bad Mech location: "
                        + node.getAttribute(NAME));
            }
            while (children.hasMoreElements()) {
                ParsedXML critSlotNode = (ParsedXML) children.nextElement();
                critData[loc][i][0] = ((ParsedXML) critSlotNode.elements()
                        .nextElement()).getContent();
                if (clanTC && critData[loc][i][0].equals("Targeting Computer")) {
                    critData[loc][i][0] = "(C) " + critData[loc][i][0];
                }
                critData[loc][i++][1] = critSlotNode.getAttribute(ITEM_INDEX);
            }
        } else if (children != null) {
            // Use recursion to process all the children
            while (children.hasMoreElements()) {
                parseCritNode((ParsedXML) children.nextElement());
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        output.write(CommonConstants.NL);
    }

    @SuppressWarnings("unchecked")
    public void load(InputStream is) {
        ParsedXML root = null;
        try {
            root = TinyParser.parseXML(is);
        } catch (ParseException e) {
            System.err.println("Error parsing map settings xml file."); //$NON-NLS-1$
            e.printStackTrace();
            return;
        }
        Enumeration rootChildren = root.elements();
        ParsedXML enivoronmentNode = (ParsedXML) rootChildren.nextElement();

        if (enivoronmentNode.getName().equals("ENVIRONMENT")) { //$NON-NLS-1$
            Enumeration children = enivoronmentNode.elements();

            while (children.hasMoreElements()) {
                try {
                    parseEnvironmentNode((ParsedXML) children.nextElement());
                } catch (Exception ex) {
                    System.err.println("error in map settings file:");
                    ex.printStackTrace();
                }
            }

        } else {
            System.out
                    .println("Root node of map settings file is incorrectly named. Name should be 'ENVIRONMENT' but name is '" + enivoronmentNode.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

    private void parseEnvironmentNode(ParsedXML node) {
        Enumeration values = node.elements();
        if (!(values.hasMoreElements())) {
            return;
        }
        ParsedXML value = (ParsedXML) values.nextElement();
        String param = value.getContent();
        if (null == param) {
            return;
        }
        String key = node.getName();
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

            // Encode the board in XML.
            BoardEncoder.encode(board, to);
            to.close();

            // Decode the board from XML.
            ParsedXML root = TinyParser.parseXML(new ByteArrayInputStream(to
                    .toString().getBytes()));
            Enumeration<?> rootChildren = root.elements();
            if (!rootChildren.hasMoreElements()) {
                throw new ParseException("No children of the root.");
            }
            ParsedXML rootNode = (ParsedXML) rootChildren.nextElement();
            board = BoardEncoder.decode(rootNode, game);

            // Save a copy of the board before XML encoding.
            aoos.writeObject(board);
            aoos.close();
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        // TODO : perform version checking.

        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            if (childName.equals("cf")) {
                String cf = child.getContent().trim();
                try {
                    ge.setConstructionFactor(Integer.parseInt(cf));
                } catch (NumberFormatException nfe) {
                    throw new IllegalStateException(
                            "Invalid integer value for cf element: " + cf);
                }
            } else if (childName.equals("turretLocked")) {
                String facing = child.getAttribute("facing");
                ge.setTurretLocked(true);
                try {
                    ge.setSecondaryFacing(Integer.parseInt(facing));
                } catch (NumberFormatException nfe) {
                    throw new IllegalStateException(
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        entity = new BipedMech();

        // Walk the board node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the stunnedTurns node?
            else if (childName.equals("mascTurns")) {

                // Get the Mech's stunned turns.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the mascTurns for a BipedMech unit.");
                }

                // Try to pull the number from the attribute string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }
                entity.setMASCTurns(attrVal);
            }

            // Did we find the mascUsed node?
            else if (childName.equals("mascUsed")) {

                // See if the Mech used MASC.
                attrStr = child.getAttribute("value");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode mascUsed for a BipedMech unit.");
                }
View Full Code Here

Examples of gd.xml.tiny.ParsedXML

        int height = 0;
        int width = 0;
        IHex[] hexes = null;
        Coords coords = null;
        Enumeration<?> subnodes = null;
        ParsedXML subnode = null;

        // Did we get a null node?
        if (null == node) {
            throw new IllegalArgumentException("The board is null.");
        }

        // Make sure that the node is for a Board object.
        if (!node.getName().equals("board")) {
            throw new IllegalStateException("Not passed a board node.");
        }

        // TODO : perform version checking.

        // Walk the board node's children.
        Enumeration<?> children = node.elements();
        while (children.hasMoreElements()) {
            ParsedXML child = (ParsedXML) children.nextElement();
            String childName = child.getName();

            // Handle null child names.
            if (null == childName) {

                // No-op.
            }

            // Did we find the boardData node?
            else if (childName.equals("boardData")) {

                // There should be only one boardData node.
                if (null != hexes) {
                    throw new IllegalStateException(
                            "More than one 'boardData' node in a board node.");
                }

                // Get the number of boardData.
                attrStr = child.getAttribute("height");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the boardData for a board node.");
                }

                // Try to pull the height from the attribute string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }
                height = attrVal;

                // Do we have a valid value?
                if (height < 0 || height > Board.BOARD_MAX_HEIGHT) {
                    throw new IllegalStateException(
                            "Illegal value for height: " + attrStr);
                }

                // Get the number of boardData.
                attrStr = child.getAttribute("width");
                if (null == attrStr) {
                    throw new IllegalStateException(
                            "Couldn't decode the boardData for a board node.");
                }

                // Try to pull the width from the attribute string
                try {
                    attrVal = Integer.parseInt(attrStr);
                } catch (NumberFormatException exp) {
                    throw new IllegalStateException(
                            "Couldn't get an integer from " + attrStr);
                }
                width = attrVal;

                // Do we have a valid value?
                if (width < 0 || width > Board.BOARD_MAX_WIDTH) {
                    throw new IllegalStateException("Illegal value for width: "
                            + attrStr);
                }

                // Read the "roadsAutoExit" attribute.
                // unused, and therefore removed.
                // roadsAutoExit = StringUtil.parseBoolean(
                // child.getAttribute("roadsAutoExit") );

                // Create an array to hold all the boardData.
                hexes = new IHex[height * width];

                // Walk through the subnodes, parsing out hex nodes.
                int numHexes = 0;
                subnodes = child.elements();
                while (subnodes.hasMoreElements()) {

                    // Is this a "hex" node?
                    subnode = (ParsedXML) subnodes.nextElement();
                    if (subnode.getName().equals("hex")) {

                        // Are there too many hex nodes?
                        if (hexes.length == numHexes) {
                            throw new IllegalStateException(
                                    "Too many hexes in a board node.");
                        }

                        // Parse out this hex node.
                        hexes[numHexes] = HexEncoder.decode(subnode, game);

                        // Increment the number of boardData.
                        numHexes++;

                    } // End found-"hex"-node

                } // Look at the next subnode.

                // Have we found enough hex nodes?
                if (numHexes < hexes.length) {
                    throw new IllegalStateException(
                            "Not enough hexes in a board node.");
                }

            } // End found-"boardData"-node

            // Did we find the infernos node?
            else if (childName.equals("infernos")) {
                subnodes = child.elements();
                while (subnodes.hasMoreElements()) {
                    subnode = (ParsedXML) subnodes.nextElement();
                    if (subnode.getName().equals("inferno")) {
                        coords = null;
                        InfernoTracker tracker = new InfernoTracker();

                        // Try to find the inferno detail nodes.
                        Enumeration<?> details = subnode.elements();
                        while (details.hasMoreElements()) {
                            ParsedXML detail = (ParsedXML) details
                                    .nextElement();

                            // Have we found the coords detail?
                            if (detail.getName().equals("coords")) {
                                coords = CoordsEncoder.decode(detail, game);
                            }

                            // Have we found the Arrow IV inferno detail?
                            else if (detail.getName().equals("arrowiv")) {

                                // Get the burn turns attribute.
                                attrStr = detail.getAttribute("turns");
                                if (null == attrStr) {
                                    throw new IllegalStateException(
                                            "Couldn't decode the burn turns for an Arrow IV inferno round.");
                                }

                                // Try to pull the value from the string
                                try {
                                    attrVal = Integer.parseInt(attrStr);
                                } catch (NumberFormatException exp) {
                                    throw new IllegalStateException(
                                            "Couldn't get an integer from "
                                                    + attrStr);
                                }

                                // Add the number of Arrow IV burn turns.
                                tracker.add(InfernoTracker.INFERNO_IV_TURN,
                                        attrVal);

                            } // End found-arrowiv-detail

                            // Have we found the standard inferno entry?
                            else if (detail.getName().equals("standard")) {

                                // Get the burn turns attribute.
                                attrStr = detail.getAttribute("turns");
                                if (null == attrStr) {
                                    throw new IllegalStateException(
                                            "Couldn't decode the burn turns for a standard inferno round.");
                                }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.