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/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java (-53 / +3 lines)
Lines 60-65 Link Here
60
import org.netbeans.spi.project.support.ant.EditableProperties;
60
import org.netbeans.spi.project.support.ant.EditableProperties;
61
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileUtil;
62
import org.openide.filesystems.FileUtil;
63
import org.openide.xml.XMLUtil;
63
import org.w3c.dom.Comment;
64
import org.w3c.dom.Comment;
64
import org.w3c.dom.Document;
65
import org.w3c.dom.Document;
65
import org.w3c.dom.NamedNodeMap;
66
import org.w3c.dom.NamedNodeMap;
Lines 159-165 Link Here
159
            if(oldRoot != null) {
160
            if(oldRoot != null) {
160
                Document doc = oldRoot.getOwnerDocument();
161
                Document doc = oldRoot.getOwnerDocument();
161
                Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
162
                Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
162
                copyDocument(doc, oldRoot, newRoot);
163
                XMLUtil.copyDocument(doc, oldRoot, newRoot, EarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
163
                
164
                
164
                //update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/>
165
                //update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/>
165
//                NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries");
166
//                NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries");
Lines 173-179 Link Here
173
                        Element library = (Element) libList.item(i);
174
                        Element library = (Element) libList.item(i);
174
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
175
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
175
                        //remove ${ and } from the beginning and end
176
                        //remove ${ and } from the beginning and end
176
                        String webFileText = findText(webFile);
177
                        String webFileText = XMLUtil.findText(webFile);
177
                        webFileText = webFileText.substring(2, webFileText.length() - 1);
178
                        webFileText = webFileText.substring(2, webFileText.length() - 1);
178
                        if (webFileText.startsWith("libs.")) {
179
                        if (webFileText.startsWith("libs.")) {
179
                            String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N
180
                            String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N
Lines 209-265 Link Here
209
        return cachedElement;
210
        return cachedElement;
210
    }
211
    }
211
212
212
    private static void copyDocument (Document doc, Element from, Element to) {
213
        NodeList nl = from.getChildNodes();
214
        int length = nl.getLength();
215
        for (int i=0; i< length; i++) {
216
            Node node = nl.item (i);
217
            Node newNode = null;
218
            switch (node.getNodeType()) {
219
                case Node.ELEMENT_NODE:
220
                    Element oldElement = (Element) node;
221
                    newNode = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
222
                    NamedNodeMap m = oldElement.getAttributes();
223
                    Element newElement = (Element) newNode;
224
                    for (int index = 0; index < m.getLength(); index++) {
225
                        Node attr = m.item(index);
226
                        newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
227
                    }
228
                    copyDocument(doc,oldElement,(Element)newNode);
229
                    break;
230
                case Node.TEXT_NODE:
231
                    Text oldText = (Text) node;
232
                    newNode = doc.createTextNode(oldText.getData());
233
                    break;
234
                case Node.COMMENT_NODE:
235
                    Comment oldComment = (Comment) node;
236
                    newNode = doc.createComment(oldComment.getData());
237
                    break;
238
            }
239
            if (newNode != null) {
240
                to.appendChild (newNode);
241
            }
242
        }
243
    }
244
245
    /**
246
     * Extract nested text from a node.
247
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
248
     * @param parent a parent node
249
     * @return the nested text, or null if none was found
250
     */
251
    private static String findText(Node parent) {
252
        NodeList l = parent.getChildNodes();
253
        for (int i = 0; i < l.getLength(); i++) {
254
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
255
                Text text = (Text)l.item(i);
256
                return text.getNodeValue();
257
            }
258
        }
259
        return null;
260
    }
261
262
    
263
    public EditableProperties getUpdatedProjectProperties() {
213
    public EditableProperties getUpdatedProjectProperties() {
264
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
214
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
265
    }
215
    }
(-)a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/classpath/ClassPathSupportCallbackImpl.java (-15 / +3 lines)
Lines 41-60 Link Here
41
41
42
package org.netbeans.modules.j2ee.earproject.classpath;
42
package org.netbeans.modules.j2ee.earproject.classpath;
43
43
44
import java.util.ArrayList;
45
import java.util.LinkedHashMap;
44
import java.util.LinkedHashMap;
46
import java.util.List;
45
import java.util.List;
47
import java.util.Map;
46
import java.util.Map;
48
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
47
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
49
import org.netbeans.modules.j2ee.common.project.ui.J2EEProjectProperties;
50
import org.netbeans.modules.j2ee.earproject.EarProjectType;
48
import org.netbeans.modules.j2ee.earproject.EarProjectType;
51
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
49
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.openide.xml.XMLUtil;
53
import org.w3c.dom.Document;
52
import org.w3c.dom.Document;
54
import org.w3c.dom.Element;
53
import org.w3c.dom.Element;
55
import org.w3c.dom.Node;
54
import org.w3c.dom.Node;
56
import org.w3c.dom.NodeList;
55
import org.w3c.dom.NodeList;
57
import org.w3c.dom.Text;
58
56
59
/**
57
/**
60
 * Defines the various class paths for a web project.
58
 * Defines the various class paths for a web project.
Lines 135-142 Link Here
135
                        Element library = (Element) ch.item(i);
133
                        Element library = (Element) ch.item(i);
136
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
134
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
137
                        NodeList pathInEarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_EAR);
135
                        NodeList pathInEarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_EAR);
138
                        earIncludesMap.put(findText(webFile), pathInEarElements.getLength() > 0 ?
136
                        earIncludesMap.put(XMLUtil.findText(webFile), pathInEarElements.getLength() > 0 ?
139
                            findText(pathInEarElements.item(0)) : null);
137
                            XMLUtil.findText(pathInEarElements.item(0)) : null);
140
                    }
138
                    }
141
                }
139
                }
142
            }
140
            }
Lines 144-158 Link Here
144
        return earIncludesMap;
142
        return earIncludesMap;
145
    }
143
    }
146
144
147
    private static String findText(Node parent) {
148
        NodeList l = parent.getChildNodes();
149
        for (int i = 0; i < l.getLength(); i++) {
150
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
151
                Text text = (Text)l.item(i);
152
                return text.getNodeValue();
153
            }
154
        }
155
        return null;
156
    }
157
}
145
}
158
146

Return to bug 136595