This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 136595
Collapse All | Expand All

(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/modules/project/rake/RakeBasedProjectFactorySingleton.java (-2 / +3 lines)
Lines 53-58 Link Here
53
import java.util.Set;
53
import java.util.Set;
54
import java.util.WeakHashMap;
54
import java.util.WeakHashMap;
55
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.Project;
56
import org.netbeans.modules.ruby.spi.project.support.rake.ProjectGenerator;
56
import org.netbeans.spi.project.ProjectFactory;
57
import org.netbeans.spi.project.ProjectFactory;
57
import org.netbeans.spi.project.ProjectState;
58
import org.netbeans.spi.project.ProjectState;
58
import org.netbeans.modules.ruby.spi.project.support.rake.RakeBasedProjectType;
59
import org.netbeans.modules.ruby.spi.project.support.rake.RakeBasedProjectType;
Lines 178-188 Link Here
178
        if (!"project".equals(projectEl.getLocalName()) || !PROJECT_NS.equals(projectEl.getNamespaceURI())) { // NOI18N
179
        if (!"project".equals(projectEl.getLocalName()) || !PROJECT_NS.equals(projectEl.getNamespaceURI())) { // NOI18N
179
            return null;
180
            return null;
180
        }
181
        }
181
        Element typeEl = Util.findElement(projectEl, "type", PROJECT_NS); // NOI18N
182
        Element typeEl = XMLUtil.findElement(projectEl, "type", PROJECT_NS); // NOI18N
182
        if (typeEl == null) {
183
        if (typeEl == null) {
183
            return null;
184
            return null;
184
        }
185
        }
185
        String type = Util.findText(typeEl);
186
        String type = XMLUtil.findText(typeEl);
186
        if (type == null) {
187
        if (type == null) {
187
            return null;
188
            return null;
188
        }
189
        }
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/modules/project/rake/Util.java (-83 lines)
Lines 41-53 Link Here
41
41
42
package org.netbeans.modules.ruby.modules.project.rake;
42
package org.netbeans.modules.ruby.modules.project.rake;
43
43
44
import java.util.ArrayList;
45
import java.util.List;
46
import org.openide.ErrorManager;
44
import org.openide.ErrorManager;
47
import org.w3c.dom.Element;
48
import org.w3c.dom.Node;
49
import org.w3c.dom.NodeList;
50
import org.w3c.dom.Text;
51
import org.xml.sax.ErrorHandler;
45
import org.xml.sax.ErrorHandler;
52
import org.xml.sax.SAXException;
46
import org.xml.sax.SAXException;
53
import org.xml.sax.SAXParseException;
47
import org.xml.sax.SAXParseException;
Lines 61-143 Link Here
61
    private Util() {}
55
    private Util() {}
62
56
63
    /**
57
    /**
64
     * Search for an XML element in the direct children of a parent.
65
     * DOM provides a similar method but it does a recursive search
66
     * which we do not want. It also gives a node list and we want
67
     * only one result.
68
     * @param parent a parent element
69
     * @param name the intended local name
70
     * @param namespace the intended namespace
71
     * @return the one child element with that name, or null if none or more than one
72
     */
73
    public static Element findElement(Element parent, String name, String namespace) {
74
        Element result = null;
75
        NodeList l = parent.getChildNodes();
76
        int len = l.getLength();
77
        for (int i = 0; i < len; i++) {
78
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
79
                Element el = (Element)l.item(i);
80
                if (name.equals(el.getLocalName()) && namespace.equals(el.getNamespaceURI())) {
81
                    if (result == null) {
82
                        result = el;
83
                    } else {
84
                        return null;
85
                    }
86
                }
87
            }
88
        }
89
        return result;
90
    }
91
    
92
    /**
93
     * Extract nested text from an element.
94
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
95
     * @param parent a parent element
96
     * @return the nested text, or null if none was found
97
     */
98
    public static String findText(Element parent) {
99
        NodeList l = parent.getChildNodes();
100
        for (int i = 0; i < l.getLength(); i++) {
101
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
102
                Text text = (Text)l.item(i);
103
                return text.getNodeValue();
104
            }
105
        }
106
        return null;
107
    }
108
    
109
    /**
110
     * Find all direct child elements of an element.
111
     * More useful than {@link Element#getElementsByTagNameNS} because it does
112
     * not recurse into recursive child elements.
113
     * Children which are all-whitespace text nodes are ignored; others cause
114
     * an exception to be thrown.
115
     * @param parent a parent element in a DOM tree
116
     * @return a list of direct child elements (may be empty)
117
     * @throws IllegalArgumentException if there are non-element children besides whitespace
118
     */
119
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
120
        NodeList l = parent.getChildNodes();
121
        List<Element> elements = new ArrayList<Element>(l.getLength());
122
        for (int i = 0; i < l.getLength(); i++) {
123
            Node n = l.item(i);
124
            if (n.getNodeType() == Node.ELEMENT_NODE) {
125
                elements.add((Element)n);
126
            } else if (n.getNodeType() == Node.TEXT_NODE) {
127
                String text = ((Text)n).getNodeValue();
128
                if (text.trim().length() > 0) {
129
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
130
                }
131
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
132
                // skip
133
            } else {
134
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
135
            }
136
        }
137
        return elements;
138
    }
139
    
140
    /**
141
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
58
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
142
     * @return a standard error handler
59
     * @return a standard error handler
143
     */
60
     */
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/spi/project/support/rake/RakeProjectHelper.java (-4 / +4 lines)
Lines 389-395 Link Here
389
        Document doc = getConfigurationXml(shared);
389
        Document doc = getConfigurationXml(shared);
390
        if (shared) {
390
        if (shared) {
391
            Element project = doc.getDocumentElement();
391
            Element project = doc.getDocumentElement();
392
            Element config = Util.findElement(project, "configuration", PROJECT_NS); // NOI18N
392
            Element config = XMLUtil.findElement(project, "configuration", PROJECT_NS); // NOI18N
393
            assert config != null;
393
            assert config != null;
394
            return config;
394
            return config;
395
        } else {
395
        } else {
Lines 828-834 Link Here
828
            public Element run() {
828
            public Element run() {
829
                synchronized (modifiedMetadataPaths) {
829
                synchronized (modifiedMetadataPaths) {
830
                    Element root = getConfigurationDataRoot(shared);
830
                    Element root = getConfigurationDataRoot(shared);
831
                    Element data = Util.findElement(root, elementName, namespace);
831
                    Element data = XMLUtil.findElement(root, elementName, namespace);
832
                    if (data != null) {
832
                    if (data != null) {
833
                        return cloneSafely(data);
833
                        return cloneSafely(data);
834
                    } else {
834
                    } else {
Lines 866-872 Link Here
866
            public Void run() {
866
            public Void run() {
867
                synchronized (modifiedMetadataPaths) {
867
                synchronized (modifiedMetadataPaths) {
868
                    Element root = getConfigurationDataRoot(shared);
868
                    Element root = getConfigurationDataRoot(shared);
869
                    Element existing = Util.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
869
                    Element existing = XMLUtil.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
870
                    // XXX first compare to existing and return if the same
870
                    // XXX first compare to existing and return if the same
871
                    if (existing != null) {
871
                    if (existing != null) {
872
                        root.removeChild(existing);
872
                        root.removeChild(existing);
Lines 908-914 Link Here
908
            public Boolean run() {
908
            public Boolean run() {
909
                synchronized (modifiedMetadataPaths) {
909
                synchronized (modifiedMetadataPaths) {
910
                    Element root = getConfigurationDataRoot(shared);
910
                    Element root = getConfigurationDataRoot(shared);
911
                    Element data = Util.findElement(root, elementName, namespace);
911
                    Element data = XMLUtil.findElement(root, elementName, namespace);
912
                    if (data != null) {
912
                    if (data != null) {
913
                        root.removeChild(data);
913
                        root.removeChild(data);
914
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
914
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/spi/project/support/rake/ReferenceHelper.java (-10 / +9 lines)
Lines 66-72 Link Here
66
import org.netbeans.modules.ruby.api.project.rake.RakeArtifactQuery;
66
import org.netbeans.modules.ruby.api.project.rake.RakeArtifactQuery;
67
import org.netbeans.api.queries.CollocationQuery;
67
import org.netbeans.api.queries.CollocationQuery;
68
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
68
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
69
import org.netbeans.modules.ruby.modules.project.rake.Util;
70
import org.netbeans.spi.project.AuxiliaryConfiguration;
69
import org.netbeans.spi.project.AuxiliaryConfiguration;
71
import org.netbeans.spi.project.SubprojectProvider;
70
import org.netbeans.spi.project.SubprojectProvider;
72
import org.openide.ErrorManager;
71
import org.openide.ErrorManager;
Lines 546-552 Link Here
546
        // Linear search; always keeping references sorted first by foreign project
545
        // Linear search; always keeping references sorted first by foreign project
547
        // name, then by target name.
546
        // name, then by target name.
548
        Element nextRefEl = null;
547
        Element nextRefEl = null;
549
        Iterator<Element> it = Util.findSubElements(references).iterator();
548
        Iterator<Element> it = XMLUtil.findSubElements(references).iterator();
550
        while (it.hasNext()) {
549
        while (it.hasNext()) {
551
            Element testRefEl = it.next();
550
            Element testRefEl = it.next();
552
            RawReference testRef = RawReference.create(testRefEl);
551
            RawReference testRef = RawReference.create(testRefEl);
Lines 793-799 Link Here
793
    
792
    
794
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
793
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
795
        // As with addRawReference, do a linear search through.
794
        // As with addRawReference, do a linear search through.
796
        for (Element testRefEl : Util.findSubElements(references)) {
795
        for (Element testRefEl : XMLUtil.findSubElements(references)) {
797
            RawReference testRef = RawReference.create(testRefEl);
796
            RawReference testRef = RawReference.create(testRefEl);
798
            String refID = testRef.getID();
797
            String refID = testRef.getID();
799
            String refName = testRef.getForeignProjectName();
798
            String refName = testRef.getForeignProjectName();
Lines 846-852 Link Here
846
    }
845
    }
847
    
846
    
848
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
847
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
849
        List<Element> subEls = Util.findSubElements(references);
848
        List<Element> subEls = XMLUtil.findSubElements(references);
850
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
849
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
851
        for (Element subEl : subEls) {
850
        for (Element subEl : subEls) {
852
            refs.add(RawReference.create(subEl));
851
            refs.add(RawReference.create(subEl));
Lines 888-894 Link Here
888
    }
887
    }
889
    
888
    
890
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
889
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
891
        for (Element subEl : Util.findSubElements(references)) {
890
        for (Element subEl : XMLUtil.findSubElements(references)) {
892
            RawReference ref = RawReference.create(subEl);
891
            RawReference ref = RawReference.create(subEl);
893
            String refID = ref.getID();
892
            String refID = ref.getID();
894
            String refName = ref.getForeignProjectName();
893
            String refName = ref.getForeignProjectName();
Lines 1513-1519 Link Here
1513
                if (idx == -1) {
1512
                if (idx == -1) {
1514
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1513
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1515
                }
1514
                }
1516
                String val = Util.findText(el);
1515
                String val = XMLUtil.findText(el);
1517
                if (val == null) {
1516
                if (val == null) {
1518
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1517
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1519
                }
1518
                }
Lines 1531-1537 Link Here
1531
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1530
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1532
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1531
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1533
            }
1532
            }
1534
            List nl = Util.findSubElements(xml);
1533
            List nl = XMLUtil.findSubElements(xml);
1535
            if (nl.size() < 6) {
1534
            if (nl.size() < 6) {
1536
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1535
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1537
            }
1536
            }
Lines 1546-1552 Link Here
1546
                if (idx == -1) {
1545
                if (idx == -1) {
1547
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1546
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1548
                }
1547
                }
1549
                String val = Util.findText(el);
1548
                String val = XMLUtil.findText(el);
1550
                if (val == null) {
1549
                if (val == null) {
1551
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1550
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1552
                }
1551
                }
Lines 1564-1572 Link Here
1564
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1563
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1565
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1564
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1566
                }
1565
                }
1567
                for (Element el2 : Util.findSubElements(el)) {
1566
                for (Element el2 : XMLUtil.findSubElements(el)) {
1568
                    String key = el2.getAttribute("name");
1567
                    String key = el2.getAttribute("name");
1569
                    String value = Util.findText(el2);
1568
                    String value = XMLUtil.findText(el2);
1570
                    // #53553: NPE
1569
                    // #53553: NPE
1571
                    if (value == null) {
1570
                    if (value == null) {
1572
                        value = ""; // NOI18N
1571
                        value = ""; // NOI18N

Return to bug 136595