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/projectimport.eclipse.web/src/org/netbeans/modules/projectimport/eclipse/web/Util.java (-78 lines)
Lines 63-146 Link Here
63
    private Util() {}
63
    private Util() {}
64
64
65
    /**
65
    /**
66
     * Search for an XML element in the direct children of a parent.
67
     * DOM provides a similar method but it does a recursive search
68
     * which we do not want. It also gives a node list and we want
69
     * only one result.
70
     * @param parent a parent element
71
     * @param name the intended local name
72
     * @param namespace the intended namespace
73
     * @return the one child element with that name, or null if none or more than one
74
     */
75
    public static Element findElement(Element parent, String name, String namespace) {
76
        Element result = null;
77
        NodeList l = parent.getChildNodes();
78
        int len = l.getLength();
79
        for (int i = 0; i < len; i++) {
80
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
81
                Element el = (Element)l.item(i);
82
                if (name.equals(el.getLocalName()) && 
83
                        ((namespace != null && namespace.equals(el.getNamespaceURI())) || namespace == null)) {
84
                    if (result == null) {
85
                        result = el;
86
                    } else {
87
                        return null;
88
                    }
89
                }
90
            }
91
        }
92
        return result;
93
    }
94
    
95
    /**
96
     * Extract nested text from an element.
97
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
98
     * @param parent a parent element
99
     * @return the nested text, or null if none was found
100
     */
101
    public static String findText(Element parent) {
102
        NodeList l = parent.getChildNodes();
103
        for (int i = 0; i < l.getLength(); i++) {
104
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
105
                Text text = (Text)l.item(i);
106
                return text.getNodeValue();
107
            }
108
        }
109
        return null;
110
    }
111
    
112
    /**
113
     * Find all direct child elements of an element.
114
     * More useful than {@link Element#getElementsByTagNameNS} because it does
115
     * not recurse into recursive child elements.
116
     * Children which are all-whitespace text nodes are ignored; others cause
117
     * an exception to be thrown.
118
     * @param parent a parent element in a DOM tree
119
     * @return a list of direct child elements (may be empty)
120
     * @throws IllegalArgumentException if there are non-element children besides whitespace
121
     */
122
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
123
        NodeList l = parent.getChildNodes();
124
        List<Element> elements = new ArrayList<Element>(l.getLength());
125
        for (int i = 0; i < l.getLength(); i++) {
126
            Node n = l.item(i);
127
            if (n.getNodeType() == Node.ELEMENT_NODE) {
128
                elements.add((Element)n);
129
            } else if (n.getNodeType() == Node.TEXT_NODE) {
130
                String text = ((Text)n).getNodeValue();
131
                if (text.trim().length() > 0) {
132
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
133
                }
134
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
135
                // skip
136
            } else {
137
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
138
            }
139
        }
140
        return elements;
141
    }
142
    
143
    /**
144
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
66
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
145
     * @return a standard error handler
67
     * @return a standard error handler
146
     */
68
     */
(-)a/projectimport.eclipse.web/src/org/netbeans/modules/projectimport/eclipse/web/WebProjectFactory.java (-4 / +4 lines)
Lines 245-253 Link Here
245
                return null;
245
                return null;
246
            }
246
            }
247
            WebContentData data = new WebContentData();
247
            WebContentData data = new WebContentData();
248
            Element moduleEl = Util.findElement(modulesEl, "wb-module", null); //NOI18N
248
            Element moduleEl = XMLUtil.findElement(modulesEl, "wb-module", null); //NOI18N
249
            if (moduleEl != null) { // #175364
249
            if (moduleEl != null) { // #175364
250
            for (Element el : Util.findSubElements(moduleEl)) {
250
            for (Element el : XMLUtil.findSubElements(moduleEl)) {
251
                if ("wb-resource".equals(el.getNodeName())) { //NOI18N
251
                if ("wb-resource".equals(el.getNodeName())) { //NOI18N
252
                    if ("/".equals(el.getAttribute("deploy-path"))) { //NOI18N
252
                    if ("/".equals(el.getAttribute("deploy-path"))) { //NOI18N
253
                        data.webRoot = el.getAttribute("source-path"); //NOI18N
253
                        data.webRoot = el.getAttribute("source-path"); //NOI18N
Lines 281-289 Link Here
281
            if ("5.0".equals(specVer)) {
281
            if ("5.0".equals(specVer)) {
282
                specVer = "1.5"; // NOI18N
282
                specVer = "1.5"; // NOI18N
283
            }
283
            }
284
            Element attrsEl = Util.findElement(modulesEl, "attributes", null); //NOI18N
284
            Element attrsEl = XMLUtil.findElement(modulesEl, "attributes", null); //NOI18N
285
            if (attrsEl != null) {
285
            if (attrsEl != null) {
286
                for (Element el : Util.findSubElements(attrsEl)) {
286
                for (Element el : XMLUtil.findSubElements(attrsEl)) {
287
                    if ("attribute".equals(el.getNodeName())) { //NOI18N
287
                    if ("attribute".equals(el.getNodeName())) { //NOI18N
288
                        if ("webrootdir".equals(el.getAttribute("name"))) { //NOI18N
288
                        if ("webrootdir".equals(el.getAttribute("name"))) { //NOI18N
289
                            data.webRoot = el.getAttribute("value"); //NOI18N
289
                            data.webRoot = el.getAttribute("value"); //NOI18N

Return to bug 136595