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.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java (-3 / +3 lines)
Lines 77-83 Link Here
77
        if (!"classpath".equals(classpathEl.getLocalName())) { // NOI18N
77
        if (!"classpath".equals(classpathEl.getLocalName())) { // NOI18N
78
            return empty();
78
            return empty();
79
        }
79
        }
80
        List<Element> classpathEntryEls = Util.findSubElements(classpathEl);
80
        List<Element> classpathEntryEls = XMLUtil.findSubElements(classpathEl);
81
        if (classpathEntryEls == null) {
81
        if (classpathEntryEls == null) {
82
            return empty();
82
            return empty();
83
        }
83
        }
Lines 113-119 Link Here
113
                }
113
                }
114
                props.put(key, value);
114
                props.put(key, value);
115
            }
115
            }
116
            Element entryAttrs = Util.findElement(classpathEntry, "attributes", null); //NOI18N
116
            Element entryAttrs = XMLUtil.findElement(classpathEntry, "attributes", null); //NOI18N
117
            if (entryAttrs != null) {
117
            if (entryAttrs != null) {
118
                /*
118
                /*
119
                <classpathentry kind="lib" path="/home/dev/hibernate-annotations-3.3.1.GA/lib/hibernate-commons-annotations.jar" sourcepath="/home/dev/hibernate-annotations-3.3.1.GA/src">
119
                <classpathentry kind="lib" path="/home/dev/hibernate-annotations-3.3.1.GA/lib/hibernate-commons-annotations.jar" sourcepath="/home/dev/hibernate-annotations-3.3.1.GA/src">
Lines 122-128 Link Here
122
                    </attributes>
122
                    </attributes>
123
                </classpathentry>
123
                </classpathentry>
124
                 */
124
                 */
125
                List<Element> attrsList = Util.findSubElements(entryAttrs);
125
                List<Element> attrsList = XMLUtil.findSubElements(entryAttrs);
126
                if (attrsList != null) {
126
                if (attrsList != null) {
127
                    for (Element e : attrsList) {
127
                    for (Element e : attrsList) {
128
                        props.put(e.getAttribute("name"), e.getAttribute("value")); //NOI18N
128
                        props.put(e.getAttribute("name"), e.getAttribute("value")); //NOI18N
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/ProjectParser.java (-11 / +11 lines)
Lines 75-83 Link Here
75
            throw new IllegalStateException("given file is not eclipse .project file"); // NOI18N
75
            throw new IllegalStateException("given file is not eclipse .project file"); // NOI18N
76
        }
76
        }
77
        
77
        
78
        Element naturesEl = Util.findElement(projectDescriptionEl, "natures", null); // NOI18N
78
        Element naturesEl = XMLUtil.findElement(projectDescriptionEl, "natures", null); // NOI18N
79
        if (naturesEl != null) {
79
        if (naturesEl != null) {
80
            List<Element> natureEls = Util.findSubElements(naturesEl);
80
            List<Element> natureEls = XMLUtil.findSubElements(naturesEl);
81
            if (natureEls != null) {
81
            if (natureEls != null) {
82
                for (Element nature : natureEls) {
82
                for (Element nature : natureEls) {
83
                    natures.add(nature.getTextContent());
83
                    natures.add(nature.getTextContent());
Lines 85-114 Link Here
85
            }
85
            }
86
        }
86
        }
87
        
87
        
88
        Element linksEl = Util.findElement(projectDescriptionEl, "linkedResources", null); // NOI18N
88
        Element linksEl = XMLUtil.findElement(projectDescriptionEl, "linkedResources", null); // NOI18N
89
        if (linksEl != null) {
89
        if (linksEl != null) {
90
            List<Element> linkEls = Util.findSubElements(linksEl);
90
            List<Element> linkEls = XMLUtil.findSubElements(linksEl);
91
            if (linkEls != null) {
91
            if (linkEls != null) {
92
                for (Element link : linkEls) {
92
                for (Element link : linkEls) {
93
                    Element locationElement = Util.findElement(link, "location", null); // NOI18N
93
                    Element locationElement = XMLUtil.findElement(link, "location", null); // NOI18N
94
                    String loc;
94
                    String loc;
95
                    if (locationElement == null) {
95
                    if (locationElement == null) {
96
                        assert Util.findElement(link, "locationURI", null) != null : Util.findSubElements(link); // NOI18N
96
                        assert XMLUtil.findElement(link, "locationURI", null) != null : XMLUtil.findSubElements(link); // NOI18N
97
                        // XXX external source root can be defined using IDE variable. For some reason (in Eclipse)
97
                        // XXX external source root can be defined using IDE variable. For some reason (in Eclipse)
98
                        // these variables are stored/managed separately from variables which can be used
98
                        // these variables are stored/managed separately from variables which can be used
99
                        // in classpath. For now these variables are not transfer to NetBeans and normalized
99
                        // in classpath. For now these variables are not transfer to NetBeans and normalized
100
                        // path will be returned instead.
100
                        // path will be returned instead.
101
                        loc = resolveLink(Util.findElement(link, "locationURI", null).getTextContent(), variables); // NOI18N
101
                        loc = resolveLink(XMLUtil.findElement(link, "locationURI", null).getTextContent(), variables); // NOI18N
102
                    } else {
102
                    } else {
103
                        loc = locationElement.getTextContent();
103
                        loc = locationElement.getTextContent();
104
                    }
104
                    }
105
                    links.add(new Link(Util.findElement(link, "name", null).getTextContent(),  // NOI18N
105
                    links.add(new Link(XMLUtil.findElement(link, "name", null).getTextContent(),  // NOI18N
106
                            "1".equals(Util.findElement(link, "type", null).getTextContent()), // NOI18N
106
                            "1".equals(XMLUtil.findElement(link, "type", null).getTextContent()), // NOI18N
107
                            loc));
107
                            loc));
108
                }
108
                }
109
            }
109
            }
110
        }
110
        }
111
        return Util.findElement(projectDescriptionEl, "name", null).getTextContent(); //NOI18N
111
        return XMLUtil.findElement(projectDescriptionEl, "name", null).getTextContent(); //NOI18N
112
    }
112
    }
113
    
113
    
114
    public static Facets readProjectFacets(File projectDir, Set<String> natures) throws IOException {
114
    public static Facets readProjectFacets(File projectDir, Set<String> natures) throws IOException {
Lines 132-138 Link Here
132
        }
132
        }
133
        
133
        
134
        List<Facets.Facet> facets = new ArrayList<Facets.Facet>();
134
        List<Facets.Facet> facets = new ArrayList<Facets.Facet>();
135
        List<Element> elements = Util.findSubElements(root);
135
        List<Element> elements = XMLUtil.findSubElements(root);
136
        for (Element element : elements) {
136
        for (Element element : elements) {
137
            if (!"installed".equals(element.getNodeName())) { // NOI18N
137
            if (!"installed".equals(element.getNodeName())) { // NOI18N
138
                continue;
138
                continue;
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/UserLibraryParser.java (-3 / +3 lines)
Lines 73-79 Link Here
73
        if (!"userlibrary".equals(root.getLocalName())) { //NOI18N
73
        if (!"userlibrary".equals(root.getLocalName())) { //NOI18N
74
            return false;
74
            return false;
75
        }
75
        }
76
        for (Element el : Util.findSubElements(root)) {
76
        for (Element el : XMLUtil.findSubElements(root)) {
77
            if (!el.getNodeName().equals("archive")) { //NOI18N
77
            if (!el.getNodeName().equals("archive")) { //NOI18N
78
                continue;
78
                continue;
79
            }
79
            }
Lines 82-92 Link Here
82
            if (src.length() > 0) {
82
            if (src.length() > 0) {
83
                sources.add(src);
83
                sources.add(src);
84
            }
84
            }
85
            Element el2 = Util.findElement(el, "attributes", null); //NOI18N
85
            Element el2 = XMLUtil.findElement(el, "attributes", null); //NOI18N
86
            if (el2 == null) {
86
            if (el2 == null) {
87
                continue;
87
                continue;
88
            }
88
            }
89
            for (Element el3 : Util.findSubElements(el2)) {
89
            for (Element el3 : XMLUtil.findSubElements(el2)) {
90
                if (el3.getNodeName().equals("attribute") && "javadoc_location".equals(el3.getAttribute("name"))) { //NOI18N
90
                if (el3.getNodeName().equals("attribute") && "javadoc_location".equals(el3.getAttribute("name"))) { //NOI18N
91
                    String javadoc = el3.getAttribute("value"); //NOI18N
91
                    String javadoc = el3.getAttribute("value"); //NOI18N
92
                    if (javadoc != null) {
92
                    if (javadoc != null) {
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/Util.java (-78 lines)
Lines 68-151 Link Here
68
    private Util() {}
68
    private Util() {}
69
69
70
    /**
70
    /**
71
     * Search for an XML element in the direct children of a parent.
72
     * DOM provides a similar method but it does a recursive search
73
     * which we do not want. It also gives a node list and we want
74
     * only one result.
75
     * @param parent a parent element
76
     * @param name the intended local name
77
     * @param namespace the intended namespace
78
     * @return the one child element with that name, or null if none or more than one
79
     */
80
    public static Element findElement(Element parent, String name, String namespace) {
81
        Element result = null;
82
        NodeList l = parent.getChildNodes();
83
        int len = l.getLength();
84
        for (int i = 0; i < len; i++) {
85
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
86
                Element el = (Element)l.item(i);
87
                if (name.equals(el.getLocalName()) && 
88
                        ((namespace != null && namespace.equals(el.getNamespaceURI())) || namespace == null)) {
89
                    if (result == null) {
90
                        result = el;
91
                    } else {
92
                        return null;
93
                    }
94
                }
95
            }
96
        }
97
        return result;
98
    }
99
    
100
    /**
101
     * Extract nested text from an element.
102
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
103
     * @param parent a parent element
104
     * @return the nested text, or null if none was found
105
     */
106
    public static String findText(Element parent) {
107
        NodeList l = parent.getChildNodes();
108
        for (int i = 0; i < l.getLength(); i++) {
109
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
110
                Text text = (Text)l.item(i);
111
                return text.getNodeValue();
112
            }
113
        }
114
        return null;
115
    }
116
    
117
    /**
118
     * Find all direct child elements of an element.
119
     * More useful than {@link Element#getElementsByTagNameNS} because it does
120
     * not recurse into recursive child elements.
121
     * Children which are all-whitespace text nodes are ignored; others cause
122
     * an exception to be thrown.
123
     * @param parent a parent element in a DOM tree
124
     * @return a list of direct child elements (may be empty)
125
     * @throws IllegalArgumentException if there are non-element children besides whitespace
126
     */
127
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
128
        NodeList l = parent.getChildNodes();
129
        List<Element> elements = new ArrayList<Element>(l.getLength());
130
        for (int i = 0; i < l.getLength(); i++) {
131
            Node n = l.item(i);
132
            if (n.getNodeType() == Node.ELEMENT_NODE) {
133
                elements.add((Element)n);
134
            } else if (n.getNodeType() == Node.TEXT_NODE) {
135
                String text = ((Text)n).getNodeValue();
136
                if (text.trim().length() > 0) {
137
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
138
                }
139
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
140
                // skip
141
            } else {
142
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
143
            }
144
        }
145
        return elements;
146
    }
147
    
148
    /**
149
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
71
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
150
     * @return a standard error handler
72
     * @return a standard error handler
151
     */
73
     */
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java (-2 / +2 lines)
Lines 156-165 Link Here
156
            !JSF_LIB_NS.equals(root.getNamespaceURI())) {
156
            !JSF_LIB_NS.equals(root.getNamespaceURI())) {
157
            return;
157
            return;
158
        }
158
        }
159
        for (Element el : Util.findSubElements(root)) {
159
        for (Element el : XMLUtil.findSubElements(root)) {
160
            String libraryName = el.getAttribute("Name"); // NOI18N
160
            String libraryName = el.getAttribute("Name"); // NOI18N
161
            List<String> jars = new ArrayList<String>();
161
            List<String> jars = new ArrayList<String>();
162
            for (Element file : Util.findSubElements(el)) {
162
            for (Element file : XMLUtil.findSubElements(el)) {
163
                String path = file.getAttribute("SourceLocation"); // NOI18N
163
                String path = file.getAttribute("SourceLocation"); // NOI18N
164
                if (!"false".equals(file.getAttribute("RelativeToWorkspace"))) { // NOI18N
164
                if (!"false".equals(file.getAttribute("RelativeToWorkspace"))) { // NOI18N
165
                    path = new File(workspace.getDirectory(), path).getPath();
165
                    path = new File(workspace.getDirectory(), path).getPath();

Return to bug 136595