Example usage for org.w3c.dom NamedNodeMap item

List of usage examples for org.w3c.dom NamedNodeMap item

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap item.

Prototype

public Node item(int index);

Source Link

Document

Returns the indexth item in the map.

Usage

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parseUsingCondition(Node n, Object template) {
    Condition cond = null;//w  ww  .  j ava2  s  .  c om

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parseUsingCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <using> condition");

    return cond;
}

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionParser.java

private Condition parseGameCondition(Node n, Object template) {
    Condition cond = null;/*  w ww  . j av  a2 s. co  m*/

    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node a = attrs.item(i);

        Condition condOr = null;

        for (String nodeValue : StringUtils.split(getNodeValue(a.getNodeValue(), template), "|"))
            condOr = joinOr(condOr, parseGameCondition(a.getNodeName(), nodeValue));

        cond = joinAnd(cond, condOr);
    }

    if (cond == null)
        throw new IllegalStateException("Empty <game> condition");

    return cond;
}

From source file:XMLReader.java

/** Writes node and all child nodes into System.out
 * @param node XML node from from XML tree wrom which will output statement start
 * @param indent number of spaces used to indent output
 *//*from w  ww.  ja v a  2s  . c  o m*/
private void writeDocumentToOutput(Node node, int indent) {
    // get element name
    String nodeName = node.getNodeName();
    // get element value
    String nodeValue = getElementValue(node);
    // get attributes of element
    NamedNodeMap attributes = node.getAttributes();
    System.out.println(getIndentSpaces(indent) + "NodeName: " + nodeName + ", NodeValue: " + nodeValue);
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        System.out.println(getIndentSpaces(indent + 2) + "AttributeName: " + attribute.getNodeName()
                + ", attributeValue: " + attribute.getNodeValue());
    }
    // write all child nodes recursively
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            writeDocumentToOutput(child, indent + 2);
        }
    }
}

From source file:com.websystique.springmvc.youtube_api.Function.java

@SuppressWarnings({ "static-access", "unchecked" })

private String printNote(NodeList nodeList) {
    List<VideoSub> listsub = new ArrayList<VideoSub>();
    List<VideoSub> savelistsub = new ArrayList<VideoSub>();
    for (int count = 0; count < nodeList.getLength(); count++) {
        VideoSub v = new VideoSub();
        Node tempNode = nodeList.item(count);
        if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
            v.setTextsb(replace_all(replacetext(tempNode.getTextContent().replace("...", "."))));
            if (tempNode.hasAttributes()) {
                NamedNodeMap nodeMap = tempNode.getAttributes();
                for (int i = 0; i < nodeMap.getLength(); i++) {
                    Node node = nodeMap.item(i);
                    if (i == 0) {
                        v.setEnd(node.getNodeValue());
                    } else {
                        v.setStart(node.getNodeValue());
                    }/*w  w  w .  j  a va 2 s.  c o m*/
                }
            }
        }
        listsub.add(v);
    }
    String savetext = "";
    double sodu = 0;
    double savedur = 0;
    String dutext = "";
    double start = 0;
    String kq = "";
    boolean flag = true;// vo lan dau
    boolean flagchamcuoi = false;// vo lan dau
    for (int i = 0; i < listsub.size(); i++) {
        String cau = listsub.get(i).getTextsb();
        if (flag || flagchamcuoi == true) {
            start = Double.parseDouble(listsub.get(i).getStart());
            savedur = Double.parseDouble(listsub.get(i).getEnd());
            flag = false;
            flagchamcuoi = false;
        }

        double dur = Double.parseDouble(listsub.get(i).getEnd());
        if (sodu != 0) {
            savetext += dutext;
            start = Double.parseDouble(listsub.get(i).getStart());
            start -= sodu;
            System.out.println(sodu + "So du" + start);
            dutext = "";
            sodu = 0;
        }
        if (cau.contains("####") == true) {
            float sogiay = (float) dur;
            float phantram = 0;
            int socau = 0;
            int sotu = demsotu(cau);
            String[] savecau = new String[100];
            int[] savesotu = new int[1000];
            double[] phantramsotu = new double[1000];
            for (String retval : cau.split("####")) { // split("\\|;\\s*|\\.\\s*|\\?\\s*")
                if (retval != "" && retval.length() > 0) {
                    savecau[socau] = retval;
                    savesotu[socau] = (1 + StringUtils.countMatches(retval.trim(), " "));
                    double pt = 0.0;
                    double so1 = (double) savesotu[socau];
                    double so2 = (double) sotu;
                    pt = so1 / so2;
                    phantramsotu[socau] = pt * sogiay;
                    socau++;
                }
            }

            // *******************************
            char[] array = cau.toCharArray();
            // save cau 1
            VideoSub cau1 = new VideoSub();
            cau1.setTextsb((savetext + " " + savecau[0]).replace("\n", " ").replace("'", " ").trim());
            cau1.setStart(start + "");
            String end = (savedur + phantramsotu[0]) + "";
            cau1.setEnd(end + "");
            if (savecau[0] != ".")
                savelistsub.add(cau1);
            // add vao
            savetext = "";
            // cap nhat start
            start += Double.parseDouble(cau1.getEnd());

            savedur = 0;
            // save cau giua
            for (int i1 = 1; i1 < socau - 1; i1++) {
                // add vao
                VideoSub Cau2 = new VideoSub();
                Cau2.setTextsb(savecau[i1].replace("\n", " ").replace("'", " ").trim());
                Cau2.setStart(start + "");
                Cau2.setEnd(phantramsotu[i1] + "");
                if (savecau[i1] != ".")
                    savelistsub.add(Cau2);

                start += phantramsotu[i1];
            }

            // save cau cuoi
            if (array[cau.length() - 5] == '.' || array[cau.length() - 5] == '?'
                    || array[cau.length() - 5] == ';') {
                flagchamcuoi = true;

            }

            System.out.println(cau);
            if (array[cau.length() - 5] == '.' || array[cau.length() - 5] == ';'
                    || array[cau.length() - 5] == '?') {
                if (socau - 1 != 0) {
                    VideoSub Cau3 = new VideoSub();
                    Cau3.setTextsb(savecau[socau - 1].replace("\n", " ").replace("'", "-").trim());
                    Cau3.setStart(start + "");
                    Cau3.setEnd(phantramsotu[socau - 1] + "");
                    if (savecau[socau - 1] != ".")
                        savelistsub.add(Cau3);

                    start += phantramsotu[socau - 1];
                }
            } else {
                dutext = savecau[socau - 1];
                sodu = phantramsotu[socau - 1];
            }
        } else {
            savetext += " " + cau;
            savedur += dur;
        }
    }
    // ================Xuat File Json===============
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < savelistsub.size(); i++) {
        JSONObject obj = new JSONObject();
        if (savelistsub.get(i).getTextsb() != ".") {
            String startadd = savelistsub.get(i).getStart();
            String duradd = savelistsub.get(i).getEnd();
            String textadd = savelistsub.get(i).getTextsb();
            obj.put("start", startadd);
            obj.put("dur", duradd);
            obj.put("text", textadd);
            jsonArray.add(obj);
        }

    }
    String out_String = jsonArray.toJSONString();
    out_String = out_String.toString();

    // ================Xuat File Json===============

    return out_String;
}

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

private static void copyNodeWithoutNamespace(Document document, Node parentNode, Node sourceNode) {
    Node destinationNode;/* w w w. ja  v a 2s.c om*/
    if (sourceNode instanceof Document) {
        destinationNode = parentNode;
    } else {
        if (sourceNode instanceof Element) {
            String localName = XMLUtils.getLocalName(sourceNode);
            destinationNode = document.createElement(localName);

            // Copy attributes
            NamedNodeMap attributes = sourceNode.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                Node sourceAttribute = attributes.item(i);

                String prefix = XMLUtils.getPrefix(sourceAttribute);

                if (!prefix.equalsIgnoreCase("xmlns")) {
                    ((Element) destinationNode).setAttribute(XMLUtils.getLocalName(sourceAttribute),
                            sourceAttribute.getNodeValue());
                }
            }
        } else {
            destinationNode = document.importNode(sourceNode, false);
        }

        parentNode.appendChild(destinationNode);
    }

    NodeList childNodes = sourceNode.getChildNodes();
    int len = childNodes.getLength();
    for (int i = 0; i < len; i++) {
        XMLUtils.copyNodeWithoutNamespace(document, destinationNode, childNodes.item(i));
    }
}

From source file:com.nridge.core.base.io.xml.DocumentOpXML.java

private void loadOperation(Element anElement) throws IOException {
    Attr nodeAttr;/*  w w  w.  jav  a  2 s.c  o m*/
    Node nodeItem;
    Document document;
    Element nodeElement;
    DocumentXML documentXML;
    DSCriteriaXML criteriaXML;
    String nodeName, nodeValue;

    mCriteria = null;
    mDocumentList.clear();
    mField.clearFeatures();

    String attrValue = anElement.getAttribute(Doc.FEATURE_OP_NAME);
    if (StringUtils.isNotEmpty(attrValue)) {
        mField.setName(attrValue);
        NamedNodeMap namedNodeMap = anElement.getAttributes();
        int attrCount = namedNodeMap.getLength();
        for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
            nodeAttr = (Attr) namedNodeMap.item(attrOffset);
            nodeName = nodeAttr.getNodeName();
            nodeValue = nodeAttr.getNodeValue();

            if (StringUtils.isNotEmpty(nodeValue)) {
                if ((!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_NAME))
                        && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT)))
                    mField.addFeature(nodeName, nodeValue);
            }
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (nodeName.equalsIgnoreCase(IO.XML_CRITERIA_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            criteriaXML = new DSCriteriaXML();
            criteriaXML.load(nodeElement);
            mCriteria = criteriaXML.getCriteria();
        } else if (StringUtils.startsWithIgnoreCase(nodeName, IO.XML_DOCUMENT_NODE_NAME)) {
            nodeElement = (Element) nodeItem;
            documentXML = new DocumentXML();
            documentXML.load(nodeElement);
            document = documentXML.getDocument();
            if (document != null)
                mDocumentList.add(document);
        }
    }
}

From source file:com.bstek.dorado.config.xml.DispatchableXmlParser.java

/**
 * ??<br>//from w  w  w  .  j  av  a 2  s  . c  o  m
 * XML(Attribute)???
 * <code><Property name="xxx">XXXX</Property></code>
 * ??
 * 
 * @param element
 *            XML
 * @param context
 *            ?
 * @return ?Map???
 *         ??????
 * @throws Exception
 */
protected Map<String, Object> parseProperties(Element element, ParseContext context) throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();

    for (Element propertyElement : DomUtils.getChildrenByTagName(element, XmlConstants.PROPERTY)) {
        String name = propertyElement.getAttribute(XmlConstants.ATTRIBUTE_NAME);
        if (StringUtils.isNotEmpty(name)) {
            properties.put(name, propertyElement);
        }
    }

    NamedNodeMap attributes = element.getAttributes();
    int attributeNum = attributes.getLength();
    for (int i = 0; i < attributeNum; i++) {
        Node node = attributes.item(i);
        String property = node.getNodeName();
        properties.put(property, node);
    }

    for (Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator(); it.hasNext();) {
        Map.Entry<String, Object> entry = it.next();
        String property = entry.getKey();
        Node node = (Node) entry.getValue();
        Object value = parseProperty(property, node, context);
        if (value != ConfigUtils.IGNORE_VALUE) {
            entry.setValue(value);
        } else {
            it.remove();
        }
    }
    return properties;
}

From source file:edu.lternet.pasta.datapackagemanager.LevelOneEMLFactory.java

private void modifyAccessElementAttributes(Document emlDocument) throws TransformerException {
    CachedXPathAPI xpathapi = new CachedXPathAPI();

    // Parse the access elements
    NodeList accessNodeList = xpathapi.selectNodeList(emlDocument, ACCESS_PATH);
    if (accessNodeList != null) {
        for (int i = 0; i < accessNodeList.getLength(); i++) {
            boolean hasSystemAttribute = false;
            Element accessElement = (Element) accessNodeList.item(i);
            NamedNodeMap accessAttributesList = accessElement.getAttributes();

            for (int j = 0; j < accessAttributesList.getLength(); j++) {
                Node attributeNode = accessAttributesList.item(j);
                String nodeName = attributeNode.getNodeName();
                String nodeValue = attributeNode.getNodeValue();
                if (nodeName.equals("authSystem")) {
                    attributeNode.setNodeValue(LEVEL_ONE_AUTH_SYSTEM_ATTRIBUTE);
                } else if (nodeName.equals("system")) {
                    attributeNode.setNodeValue(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                    hasSystemAttribute = true;
                }/*from w w w .jav a2 s.c  o  m*/
            }

            /*
             * No @system attribute was found in the access element, so we
             * need to add one.
             */
            if (!hasSystemAttribute) {
                Attr systemAttribute = emlDocument.createAttribute("system");
                systemAttribute.setTextContent(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                accessElement.setAttributeNode(systemAttribute);
            }
        }
    }
}

From source file:com.diversityarrays.dalclient.DalUtil.java

/**
 * <p>/* w w  w.  j  ava2 s  .c  om*/
 * Extract the &lt;Error Message="..." /&gt; from the XML response.
 * In fact it will retrieve all of the attributes from the 'Error' element
 * because some DAL responses use the attribute name as part of the message!
 * <p>
 * Note that if the Message attribute is missing, this will still produce
 * an error so it is <b>not</b> the same as just calling:
 * <code>
 * getElementAttributeValue(doc, "Error", "Message");
 * </code>
 * <br>
 * Any other attributes of the <i>Error</i> element will also be returned. This caters
 * for diagnostic errors which are returned by some of the DAL "update" operations.
 * @param doc
 * @return error message as a String or null
 */
static public String getXmlDalErrorMessage(Document doc) {
    String result = null;
    NodeList errorElements = doc.getElementsByTagName(DALClient.TAG_ERROR);
    if (errorElements.getLength() > 0) {
        Node item = errorElements.item(0);
        NamedNodeMap attributes = item.getAttributes();
        if (attributes == null) {
            result = String.format("No attributes available in '%s' element", //$NON-NLS-1$
                    DALClient.TAG_ERROR);
        } else {
            // We will get them *all*.
            StringBuilder sb = new StringBuilder();
            String sep = ""; //$NON-NLS-1$
            int nAttributes = attributes.getLength();
            for (int ai = 0; ai < nAttributes; ++ai) {
                Node attr = attributes.item(ai);
                if (attr != null) {
                    sb.append(sep).append(attr.getNodeName()).append('=').append(attr.getTextContent());
                    sep = ", "; //$NON-NLS-1$
                }
            }
            result = sb.toString();
        }
    }
    return result;
}

From source file:DOMWriter.java

/** Returns a sorted list of attributes. */
protected Attr[] sortAttributes(NamedNodeMap attrs) {

    int len = (attrs != null) ? attrs.getLength() : 0;
    Attr array[] = new Attr[len];
    for (int i = 0; i < len; i++) {
        array[i] = (Attr) attrs.item(i);
    }/*from   w w w  . ja v  a  2  s.c om*/
    for (int i = 0; i < len - 1; i++) {
        String name = array[i].getNodeName();
        int index = i;
        for (int j = i + 1; j < len; j++) {
            String curName = array[j].getNodeName();
            if (curName.compareTo(name) < 0) {
                name = curName;
                index = j;
            }
        }
        if (index != i) {
            Attr temp = array[i];
            array[i] = array[index];
            array[index] = temp;
        }
    }

    return array;

}