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/ant.freeform/nbproject/project.xml (-1 / +1 lines)
Lines 160-166 Link Here
160
                    <build-prerequisite/>
160
                    <build-prerequisite/>
161
                    <compile-dependency/>
161
                    <compile-dependency/>
162
                    <run-dependency>
162
                    <run-dependency>
163
                        <specification-version>8.0</specification-version>
163
                        <specification-version>8.4</specification-version>
164
                    </run-dependency>
164
                    </run-dependency>
165
                </dependency>
165
                </dependency>
166
                <dependency>
166
                <dependency>
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/Actions.java (-38 / +34 lines)
Lines 67-84 Link Here
67
import javax.swing.JMenuItem;
67
import javax.swing.JMenuItem;
68
import javax.swing.JSeparator;
68
import javax.swing.JSeparator;
69
import org.apache.tools.ant.module.api.support.ActionUtils;
69
import org.apache.tools.ant.module.api.support.ActionUtils;
70
import org.netbeans.modules.ant.freeform.spi.support.Util;
71
import org.netbeans.modules.ant.freeform.ui.TargetMappingPanel;
70
import org.netbeans.modules.ant.freeform.ui.TargetMappingPanel;
72
import org.netbeans.modules.ant.freeform.ui.UnboundTargetAlert;
71
import org.netbeans.modules.ant.freeform.ui.UnboundTargetAlert;
73
import org.netbeans.spi.project.ActionProvider;
72
import org.netbeans.spi.project.ActionProvider;
74
import org.netbeans.spi.project.support.ant.AntProjectHelper;
73
import org.netbeans.spi.project.support.ant.AntProjectHelper;
75
import org.netbeans.spi.project.ui.support.CommonProjectActions;
76
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
74
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
77
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
75
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
78
import org.openide.DialogDisplayer;
76
import org.openide.DialogDisplayer;
79
import org.openide.ErrorManager;
77
import org.openide.ErrorManager;
80
import org.openide.NotifyDescriptor;
78
import org.openide.NotifyDescriptor;
81
import org.openide.actions.FindAction;
82
import org.openide.awt.DynamicMenuContent;
79
import org.openide.awt.DynamicMenuContent;
83
import org.openide.filesystems.FileObject;
80
import org.openide.filesystems.FileObject;
84
import org.openide.filesystems.FileUtil;
81
import org.openide.filesystems.FileUtil;
Lines 86-94 Link Here
86
import org.openide.util.ContextAwareAction;
83
import org.openide.util.ContextAwareAction;
87
import org.openide.util.Lookup;
84
import org.openide.util.Lookup;
88
import org.openide.util.NbBundle;
85
import org.openide.util.NbBundle;
89
import org.openide.util.Utilities;
90
import org.openide.util.actions.Presenter;
86
import org.openide.util.actions.Presenter;
91
import org.openide.util.actions.SystemAction;
87
import org.openide.xml.XMLUtil;
92
import org.w3c.dom.Element;
88
import org.w3c.dom.Element;
93
89
94
/**
90
/**
Lines 141-153 Link Here
141
    
137
    
142
    public String[] getSupportedActions() {
138
    public String[] getSupportedActions() {
143
        Element genldata = project.getPrimaryConfigurationData();
139
        Element genldata = project.getPrimaryConfigurationData();
144
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
140
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
145
        if (actionsEl == null) {
141
        if (actionsEl == null) {
146
            return new String[0];
142
            return new String[0];
147
        }
143
        }
148
        // Use a set, not a list, since when using context you can define one action several times:
144
        // Use a set, not a list, since when using context you can define one action several times:
149
        Set<String> names = new LinkedHashSet<String>();
145
        Set<String> names = new LinkedHashSet<String>();
150
        for (Element actionEl : Util.findSubElements(actionsEl)) {
146
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
151
            names.add(actionEl.getAttribute("name")); // NOI18N
147
            names.add(actionEl.getAttribute("name")); // NOI18N
152
        }
148
        }
153
        // #46886: also always enable all common global actions, in case they should be selected:
149
        // #46886: also always enable all common global actions, in case they should be selected:
Lines 174-189 Link Here
174
        }
170
        }
175
        
171
        
176
        Element genldata = project.getPrimaryConfigurationData();
172
        Element genldata = project.getPrimaryConfigurationData();
177
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
173
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
178
        if (actionsEl == null) {
174
        if (actionsEl == null) {
179
            throw new IllegalArgumentException("No commands supported"); // NOI18N
175
            throw new IllegalArgumentException("No commands supported"); // NOI18N
180
        }
176
        }
181
        boolean foundAction = false;
177
        boolean foundAction = false;
182
        for (Element actionEl : Util.findSubElements(actionsEl)) {
178
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
183
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
179
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
184
                foundAction = true;
180
                foundAction = true;
185
                // XXX perhaps check also existence of script
181
                // XXX perhaps check also existence of script
186
                Element contextEl = Util.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
182
                Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
187
                if (contextEl != null) {
183
                if (contextEl != null) {
188
                    // Check whether the context contains files all in this folder,
184
                    // Check whether the context contains files all in this folder,
189
                    // matching the pattern if any, and matching the arity (single/multiple).
185
                    // matching the pattern if any, and matching the arity (single/multiple).
Lines 194-202 Link Here
194
                        return true;
190
                        return true;
195
                    } else if (!selection.isEmpty()) {
191
                    } else if (!selection.isEmpty()) {
196
                        // Multiple selection; check arity.
192
                        // Multiple selection; check arity.
197
                        Element arityEl = Util.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
193
                        Element arityEl = XMLUtil.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
198
                        assert arityEl != null : "No <arity> in <context> for " + command;
194
                        assert arityEl != null : "No <arity> in <context> for " + command;
199
                        if (Util.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL) != null) { // NOI18N
195
                        if (XMLUtil.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL) != null) { // NOI18N
200
                            // Supports multiple selection, take it.
196
                            // Supports multiple selection, take it.
201
                            return true;
197
                            return true;
202
                        }
198
                        }
Lines 238-249 Link Here
238
        }
234
        }
239
        
235
        
240
        Element genldata = project.getPrimaryConfigurationData();
236
        Element genldata = project.getPrimaryConfigurationData();
241
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
237
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
242
        if (actionsEl == null) {
238
        if (actionsEl == null) {
243
            throw new IllegalArgumentException("No commands supported"); // NOI18N
239
            throw new IllegalArgumentException("No commands supported"); // NOI18N
244
        }
240
        }
245
        boolean foundAction = false;
241
        boolean foundAction = false;
246
        for (Element actionEl : Util.findSubElements(actionsEl)) {
242
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
247
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
243
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
248
                foundAction = true;
244
                foundAction = true;
249
                runConfiguredAction(project, actionEl, context);
245
                runConfiguredAction(project, actionEl, context);
Lines 278-286 Link Here
278
            _files.add(d.getPrimaryFile());
274
            _files.add(d.getPrimaryFile());
279
        }
275
        }
280
        Collection<? extends FileObject> files = _files;
276
        Collection<? extends FileObject> files = _files;
281
        Element folderEl = Util.findElement(contextEl, "folder", FreeformProjectType.NS_GENERAL); // NOI18N
277
        Element folderEl = XMLUtil.findElement(contextEl, "folder", FreeformProjectType.NS_GENERAL); // NOI18N
282
        assert folderEl != null : "Must have <folder> in <context>";
278
        assert folderEl != null : "Must have <folder> in <context>";
283
        String rawtext = Util.findText(folderEl);
279
        String rawtext = XMLUtil.findText(folderEl);
284
        assert rawtext != null : "Must have text contents in <folder>";
280
        assert rawtext != null : "Must have text contents in <folder>";
285
        String evaltext = project.evaluator().evaluate(rawtext);
281
        String evaltext = project.evaluator().evaluate(rawtext);
286
        if (evaltext == null) {
282
        if (evaltext == null) {
Lines 291-299 Link Here
291
            return Collections.emptyMap();
287
            return Collections.emptyMap();
292
        }
288
        }
293
        Pattern pattern = null;
289
        Pattern pattern = null;
294
        Element patternEl = Util.findElement(contextEl, "pattern", FreeformProjectType.NS_GENERAL); // NOI18N
290
        Element patternEl = XMLUtil.findElement(contextEl, "pattern", FreeformProjectType.NS_GENERAL); // NOI18N
295
        if (patternEl != null) {
291
        if (patternEl != null) {
296
            String text = Util.findText(patternEl);
292
            String text = XMLUtil.findText(patternEl);
297
            assert text != null : "Must have text contents in <pattern>";
293
            assert text != null : "Must have text contents in <pattern>";
298
            try {
294
            try {
299
                pattern = Pattern.compile(text);
295
                pattern = Pattern.compile(text);
Lines 322-330 Link Here
322
     */
318
     */
323
    private static void runConfiguredAction(FreeformProject project, Element actionEl, Lookup context) {
319
    private static void runConfiguredAction(FreeformProject project, Element actionEl, Lookup context) {
324
        String script;
320
        String script;
325
        Element scriptEl = Util.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
321
        Element scriptEl = XMLUtil.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
326
        if (scriptEl != null) {
322
        if (scriptEl != null) {
327
            script = Util.findText(scriptEl);
323
            script = XMLUtil.findText(scriptEl);
328
        } else {
324
        } else {
329
            script = "build.xml"; // NOI18N
325
            script = "build.xml"; // NOI18N
330
        }
326
        }
Lines 340-352 Link Here
340
            DialogDisplayer.getDefault().notify(nd);
336
            DialogDisplayer.getDefault().notify(nd);
341
            return;
337
            return;
342
        }
338
        }
343
        List<Element> targets = Util.findSubElements(actionEl);
339
        List<Element> targets = XMLUtil.findSubElements(actionEl);
344
        List<String> targetNames = new ArrayList<String>(targets.size());
340
        List<String> targetNames = new ArrayList<String>(targets.size());
345
        for (Element targetEl : targets) {
341
        for (Element targetEl : targets) {
346
            if (!targetEl.getLocalName().equals("target")) { // NOI18N
342
            if (!targetEl.getLocalName().equals("target")) { // NOI18N
347
                continue;
343
                continue;
348
            }
344
            }
349
            targetNames.add(Util.findText(targetEl));
345
            targetNames.add(XMLUtil.findText(targetEl));
350
        }
346
        }
351
        String[] targetNameArray;
347
        String[] targetNameArray;
352
        if (!targetNames.isEmpty()) {
348
        if (!targetNames.isEmpty()) {
Lines 356-362 Link Here
356
            targetNameArray = null;
352
            targetNameArray = null;
357
        }
353
        }
358
        Properties props = new Properties();
354
        Properties props = new Properties();
359
        Element contextEl = Util.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
355
        Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
360
        if (contextEl != null) {
356
        if (contextEl != null) {
361
            Map<String,FileObject> selection = findSelection(contextEl, context, project);
357
            Map<String,FileObject> selection = findSelection(contextEl, context, project);
362
            if (selection.isEmpty()) {
358
            if (selection.isEmpty()) {
Lines 365-382 Link Here
365
            String separator = null;
361
            String separator = null;
366
            if (selection.size() > 1) {
362
            if (selection.size() > 1) {
367
                // Find the right separator.
363
                // Find the right separator.
368
                Element arityEl = Util.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
364
                Element arityEl = XMLUtil.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
369
                assert arityEl != null : "No <arity> in <context> for " + actionEl.getAttribute("name");
365
                assert arityEl != null : "No <arity> in <context> for " + actionEl.getAttribute("name");
370
                Element sepFilesEl = Util.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
366
                Element sepFilesEl = XMLUtil.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
371
                if (sepFilesEl == null) {
367
                if (sepFilesEl == null) {
372
                    // Only handles single files -> skip it.
368
                    // Only handles single files -> skip it.
373
                    return;
369
                    return;
374
                }
370
                }
375
                separator = Util.findText(sepFilesEl);
371
                separator = XMLUtil.findText(sepFilesEl);
376
            }
372
            }
377
            Element formatEl = Util.findElement(contextEl, "format", FreeformProjectType.NS_GENERAL); // NOI18N
373
            Element formatEl = XMLUtil.findElement(contextEl, "format", FreeformProjectType.NS_GENERAL); // NOI18N
378
            assert formatEl != null : "No <format> in <context> for " + actionEl.getAttribute("name");
374
            assert formatEl != null : "No <format> in <context> for " + actionEl.getAttribute("name");
379
            String format = Util.findText(formatEl);
375
            String format = XMLUtil.findText(formatEl);
380
            StringBuffer buf = new StringBuffer();
376
            StringBuffer buf = new StringBuffer();
381
            Iterator<Map.Entry<String,FileObject>> it = selection.entrySet().iterator();
377
            Iterator<Map.Entry<String,FileObject>> it = selection.entrySet().iterator();
382
            while (it.hasNext()) {
378
            while (it.hasNext()) {
Lines 427-435 Link Here
427
                    buf.append(separator);
423
                    buf.append(separator);
428
                }
424
                }
429
            }
425
            }
430
            Element propEl = Util.findElement(contextEl, "property", FreeformProjectType.NS_GENERAL); // NOI18N
426
            Element propEl = XMLUtil.findElement(contextEl, "property", FreeformProjectType.NS_GENERAL); // NOI18N
431
            assert propEl != null : "No <property> in <context> for " + actionEl.getAttribute("name");
427
            assert propEl != null : "No <property> in <context> for " + actionEl.getAttribute("name");
432
            String prop = Util.findText(propEl);
428
            String prop = XMLUtil.findText(propEl);
433
            assert prop != null : "Must have text contents in <property>";
429
            assert prop != null : "Must have text contents in <property>";
434
            props.setProperty(prop, buf.toString());
430
            props.setProperty(prop, buf.toString());
435
        }
431
        }
Lines 437-443 Link Here
437
            if (!propEl.getLocalName().equals("property")) { // NOI18N
433
            if (!propEl.getLocalName().equals("property")) { // NOI18N
438
                continue;
434
                continue;
439
            }
435
            }
440
            String rawtext = Util.findText(propEl);
436
            String rawtext = XMLUtil.findText(propEl);
441
            if (rawtext == null) {
437
            if (rawtext == null) {
442
                // Legal to have e.g. <property name="intentionally-left-blank"/>
438
                // Legal to have e.g. <property name="intentionally-left-blank"/>
443
                rawtext = ""; // NOI18N
439
                rawtext = ""; // NOI18N
Lines 503-514 Link Here
503
    static Action[] contextMenuCustomActions(FreeformProject p) {
499
    static Action[] contextMenuCustomActions(FreeformProject p) {
504
        List<Action> actions = new ArrayList<Action>();
500
        List<Action> actions = new ArrayList<Action>();
505
        Element genldata = p.getPrimaryConfigurationData();
501
        Element genldata = p.getPrimaryConfigurationData();
506
        Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
502
        Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
507
        if (viewEl != null) {
503
        if (viewEl != null) {
508
            Element contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
504
            Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
509
            if (contextMenuEl != null) {
505
            if (contextMenuEl != null) {
510
                actions.add(null);
506
                actions.add(null);
511
                for (Element actionEl : Util.findSubElements(contextMenuEl)) {
507
                for (Element actionEl : XMLUtil.findSubElements(contextMenuEl)) {
512
                    if (actionEl.getLocalName().equals("ide-action")) { // NOI18N
508
                    if (actionEl.getLocalName().equals("ide-action")) { // NOI18N
513
                        String cmd = actionEl.getAttribute("name");
509
                        String cmd = actionEl.getAttribute("name");
514
                        String displayName;
510
                        String displayName;
Lines 547-555 Link Here
547
        
543
        
548
        public boolean isEnabled() {
544
        public boolean isEnabled() {
549
            String script;
545
            String script;
550
            Element scriptEl = Util.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
546
            Element scriptEl = XMLUtil.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
551
            if (scriptEl != null) {
547
            if (scriptEl != null) {
552
                script = Util.findText(scriptEl);
548
                script = XMLUtil.findText(scriptEl);
553
            } else {
549
            } else {
554
                script = "build.xml"; // NOI18N
550
                script = "build.xml"; // NOI18N
555
            }
551
            }
Lines 559-566 Link Here
559
        
555
        
560
        public Object getValue(String key) {
556
        public Object getValue(String key) {
561
            if (key.equals(Action.NAME)) {
557
            if (key.equals(Action.NAME)) {
562
                Element labelEl = Util.findElement(actionEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
558
                Element labelEl = XMLUtil.findElement(actionEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
563
                return Util.findText(labelEl);
559
                return XMLUtil.findText(labelEl);
564
            } else {
560
            } else {
565
                return super.getValue(key);
561
                return super.getValue(key);
566
            }
562
            }
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/ArtifactProvider.java (-17 / +16 lines)
Lines 47-62 Link Here
47
import java.util.ArrayList;
47
import java.util.ArrayList;
48
import java.util.HashMap;
48
import java.util.HashMap;
49
import java.util.HashSet;
49
import java.util.HashSet;
50
import java.util.Iterator;
51
import java.util.LinkedHashSet;
50
import java.util.LinkedHashSet;
52
import java.util.List;
51
import java.util.List;
53
import java.util.Set;
52
import java.util.Set;
54
import org.netbeans.api.project.Project;
53
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.ant.AntArtifact;
54
import org.netbeans.api.project.ant.AntArtifact;
56
import org.netbeans.modules.ant.freeform.spi.support.Util;
57
import org.netbeans.spi.project.ant.AntArtifactProvider;
55
import org.netbeans.spi.project.ant.AntArtifactProvider;
58
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
56
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
59
import org.openide.ErrorManager;
57
import org.openide.ErrorManager;
58
import org.openide.xml.XMLUtil;
60
import org.w3c.dom.Element;
59
import org.w3c.dom.Element;
61
60
62
/**
61
/**
Lines 76-82 Link Here
76
        List<AntArtifact> artifacts = new ArrayList<AntArtifact>();
75
        List<AntArtifact> artifacts = new ArrayList<AntArtifact>();
77
        Set<String> ids = new HashSet<String>();
76
        Set<String> ids = new HashSet<String>();
78
        HashMap<String,FreeformArtifact> uniqueArtifacts = new HashMap<String,FreeformArtifact>();
77
        HashMap<String,FreeformArtifact> uniqueArtifacts = new HashMap<String,FreeformArtifact>();
79
        for (Element export : Util.findSubElements(data)) {
78
        for (Element export : XMLUtil.findSubElements(data)) {
80
            if (!export.getLocalName().equals("export")) { // NOI18N
79
            if (!export.getLocalName().equals("export")) { // NOI18N
81
                continue;
80
                continue;
82
            }
81
            }
Lines 112-120 Link Here
112
    }
111
    }
113
    
112
    
114
    public static URI readArtifactLocation(Element export, PropertyEvaluator eval) {
113
    public static URI readArtifactLocation(Element export, PropertyEvaluator eval) {
115
        Element locEl = Util.findElement(export, "location", FreeformProjectType.NS_GENERAL); // NOI18N
114
        Element locEl = XMLUtil.findElement(export, "location", FreeformProjectType.NS_GENERAL); // NOI18N
116
        assert locEl != null;
115
        assert locEl != null;
117
        String loc = Util.findText(locEl);
116
        String loc = XMLUtil.findText(locEl);
118
        assert loc != null;
117
        assert loc != null;
119
        String locationResolved = eval.evaluate(loc);
118
        String locationResolved = eval.evaluate(loc);
120
        if (locationResolved == null) {
119
        if (locationResolved == null) {
Lines 154-193 Link Here
154
        }
153
        }
155
154
156
        public String getType() {
155
        public String getType() {
157
            Element typeEl = Util.findElement(export, "type", FreeformProjectType.NS_GENERAL); // NOI18N
156
            Element typeEl = XMLUtil.findElement(export, "type", FreeformProjectType.NS_GENERAL); // NOI18N
158
            assert typeEl != null;
157
            assert typeEl != null;
159
            String type = Util.findText(typeEl);
158
            String type = XMLUtil.findText(typeEl);
160
            assert type != null;
159
            assert type != null;
161
            return type;
160
            return type;
162
        }
161
        }
163
162
164
        public String getTargetName() {
163
        public String getTargetName() {
165
            Element targetEl = Util.findElement(export, "build-target", FreeformProjectType.NS_GENERAL); // NOI18N
164
            Element targetEl = XMLUtil.findElement(export, "build-target", FreeformProjectType.NS_GENERAL); // NOI18N
166
            assert targetEl != null;
165
            assert targetEl != null;
167
            String target = Util.findText(targetEl);
166
            String target = XMLUtil.findText(targetEl);
168
            assert target != null;
167
            assert target != null;
169
            return target;
168
            return target;
170
        }
169
        }
171
170
172
        public String getCleanTargetName() {
171
        public String getCleanTargetName() {
173
            Element targetEl = Util.findElement(export, "clean-target", FreeformProjectType.NS_GENERAL); // NOI18N
172
            Element targetEl = XMLUtil.findElement(export, "clean-target", FreeformProjectType.NS_GENERAL); // NOI18N
174
            if (targetEl != null) {
173
            if (targetEl != null) {
175
                String target = Util.findText(targetEl);
174
                String target = XMLUtil.findText(targetEl);
176
                assert target != null;
175
                assert target != null;
177
                return target;
176
                return target;
178
            } else {
177
            } else {
179
                // Guess based on configured target for 'clean' command, if any.
178
                // Guess based on configured target for 'clean' command, if any.
180
                String target = null;
179
                String target = null;
181
                Element genldata = project.getPrimaryConfigurationData();
180
                Element genldata = project.getPrimaryConfigurationData();
182
                Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
181
                Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
183
                if (actionsEl != null) {
182
                if (actionsEl != null) {
184
                    for (Element actionEl : Util.findSubElements(actionsEl)) {
183
                    for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
185
                        if (actionEl.getAttribute("name").equals("clean")) { // NOI18N
184
                        if (actionEl.getAttribute("name").equals("clean")) { // NOI18N
186
                            for (Element actionTargetEl : Util.findSubElements(actionEl)) {
185
                            for (Element actionTargetEl : XMLUtil.findSubElements(actionEl)) {
187
                                if (!actionTargetEl.getLocalName().equals("target")) { // NOI18N
186
                                if (!actionTargetEl.getLocalName().equals("target")) { // NOI18N
188
                                    continue;
187
                                    continue;
189
                                }
188
                                }
190
                                String possibleTarget = Util.findText(actionTargetEl);
189
                                String possibleTarget = XMLUtil.findText(actionTargetEl);
191
                                assert possibleTarget != null;
190
                                assert possibleTarget != null;
192
                                if (target == null) {
191
                                if (target == null) {
193
                                    // OK, probably use it (unless there is another target for this command).
192
                                    // OK, probably use it (unless there is another target for this command).
Lines 213-221 Link Here
213
212
214
        public File getScriptLocation() {
213
        public File getScriptLocation() {
215
            String loc = null;
214
            String loc = null;
216
            Element scriptEl = Util.findElement(export, "script", FreeformProjectType.NS_GENERAL); // NOI18N
215
            Element scriptEl = XMLUtil.findElement(export, "script", FreeformProjectType.NS_GENERAL); // NOI18N
217
            if (scriptEl != null) {
216
            if (scriptEl != null) {
218
                String script = Util.findText(scriptEl);
217
                String script = XMLUtil.findText(scriptEl);
219
                assert script != null;
218
                assert script != null;
220
                loc = project.evaluator().evaluate(script);
219
                loc = project.evaluator().evaluate(script);
221
            }
220
            }
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformEvaluator.java (-5 / +5 lines)
Lines 52-58 Link Here
52
import java.util.List;
52
import java.util.List;
53
import java.util.Map;
53
import java.util.Map;
54
import java.util.Set;
54
import java.util.Set;
55
import org.netbeans.modules.ant.freeform.spi.support.Util;
56
import org.netbeans.spi.project.support.ant.AntProjectEvent;
55
import org.netbeans.spi.project.support.ant.AntProjectEvent;
57
import org.netbeans.spi.project.support.ant.AntProjectListener;
56
import org.netbeans.spi.project.support.ant.AntProjectListener;
58
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
Lines 60-65 Link Here
60
import org.netbeans.spi.project.support.ant.PropertyUtils;
59
import org.netbeans.spi.project.support.ant.PropertyUtils;
61
import org.openide.ErrorManager;
60
import org.openide.ErrorManager;
62
import org.openide.util.Parameters;
61
import org.openide.util.Parameters;
62
import org.openide.xml.XMLUtil;
63
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
64
64
65
/**
65
/**
Lines 105-122 Link Here
105
        PropertyProvider preprovider = project.helper().getStockPropertyPreprovider();
105
        PropertyProvider preprovider = project.helper().getStockPropertyPreprovider();
106
        List<PropertyProvider> defs = new ArrayList<PropertyProvider>();
106
        List<PropertyProvider> defs = new ArrayList<PropertyProvider>();
107
        Element genldata = project.getPrimaryConfigurationData();
107
        Element genldata = project.getPrimaryConfigurationData();
108
        Element properties = Util.findElement(genldata, "properties", FreeformProjectType.NS_GENERAL); // NOI18N
108
        Element properties = XMLUtil.findElement(genldata, "properties", FreeformProjectType.NS_GENERAL); // NOI18N
109
        if (properties != null) {
109
        if (properties != null) {
110
            for (Element e : Util.findSubElements(properties)) {
110
            for (Element e : XMLUtil.findSubElements(properties)) {
111
                if (e.getLocalName().equals("property")) { // NOI18N
111
                if (e.getLocalName().equals("property")) { // NOI18N
112
                    String val = Util.findText(e);
112
                    String val = XMLUtil.findText(e);
113
                    if (val == null) {
113
                    if (val == null) {
114
                        val = "";
114
                        val = "";
115
                    }
115
                    }
116
                    defs.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap(e.getAttribute("name"), val))); // NOI18N
116
                    defs.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap(e.getAttribute("name"), val))); // NOI18N
117
                } else {
117
                } else {
118
                    assert e.getLocalName().equals("property-file") : e;
118
                    assert e.getLocalName().equals("property-file") : e;
119
                    String fname = Util.findText(e);
119
                    String fname = XMLUtil.findText(e);
120
                    if (fname.contains("${")) { // NOI18N
120
                    if (fname.contains("${")) { // NOI18N
121
                        // Tricky (#48230): need to listen to changes in the location of the file as well as its contents.
121
                        // Tricky (#48230): need to listen to changes in the location of the file as well as its contents.
122
                        PropertyEvaluator intermediate = PropertyUtils.sequentialPropertyEvaluator(preprovider, defs.toArray(new PropertyProvider[defs.size()]));
122
                        PropertyEvaluator intermediate = PropertyUtils.sequentialPropertyEvaluator(preprovider, defs.toArray(new PropertyProvider[defs.size()]));
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformFileEncodingQueryImpl.java (-6 / +7 lines)
Lines 60-65 Link Here
60
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
60
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
61
import org.openide.util.Exceptions;
61
import org.openide.util.Exceptions;
62
import org.openide.util.Mutex;
62
import org.openide.util.Mutex;
63
import org.openide.xml.XMLUtil;
63
64
64
/**
65
/**
65
 * Implementation of FileEncodingQuery for Freeform project, its instance can be 
66
 * Implementation of FileEncodingQuery for Freeform project, its instance can be 
Lines 114-136 Link Here
114
    private void computeEncodingsCache() {
115
    private void computeEncodingsCache() {
115
        Map<FileObject,Charset> cache = new HashMap<FileObject,Charset>(3);
116
        Map<FileObject,Charset> cache = new HashMap<FileObject,Charset>(3);
116
        Element data = Util.getPrimaryConfigurationData(helper);
117
        Element data = Util.getPrimaryConfigurationData(helper);
117
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
118
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
118
        if (foldersEl != null) {
119
        if (foldersEl != null) {
119
            for (Element sourceFolderEl : Util.findSubElements(foldersEl)) {
120
            for (Element sourceFolderEl : XMLUtil.findSubElements(foldersEl)) {
120
                if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
121
                if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
121
                    continue;
122
                    continue;
122
                }
123
                }
123
                FileObject srcRoot = null;
124
                FileObject srcRoot = null;
124
                Element locationEl = Util.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
125
                Element locationEl = XMLUtil.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
125
                if (locationEl != null) {
126
                if (locationEl != null) {
126
                    String location = evaluator.evaluate(Util.findText(locationEl));
127
                    String location = evaluator.evaluate(XMLUtil.findText(locationEl));
127
                    if (location != null) {
128
                    if (location != null) {
128
                        srcRoot = helper.resolveFileObject(location);
129
                        srcRoot = helper.resolveFileObject(location);
129
                    }
130
                    }
130
                }
131
                }
131
                Element encodingEl = Util.findElement(sourceFolderEl, "encoding", Util.NAMESPACE); // NOI18N
132
                Element encodingEl = XMLUtil.findElement(sourceFolderEl, "encoding", Util.NAMESPACE); // NOI18N
132
                if (encodingEl != null && srcRoot != null) {
133
                if (encodingEl != null && srcRoot != null) {
133
                    String encoding = evaluator.evaluate(Util.findText(encodingEl));
134
                    String encoding = evaluator.evaluate(XMLUtil.findText(encodingEl));
134
                    Charset charset = null;
135
                    Charset charset = null;
135
                    if (encoding != null) {
136
                    if (encoding != null) {
136
                        try {
137
                        try {
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java (-3 / +3 lines)
Lines 46-52 Link Here
46
import java.util.logging.Level;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
47
import java.util.logging.Logger;
48
import javax.swing.Icon;
48
import javax.swing.Icon;
49
import javax.swing.ImageIcon;
50
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
51
import org.netbeans.api.project.ProjectInformation;
50
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectManager;
51
import org.netbeans.api.project.ProjectManager;
Lines 66-71 Link Here
66
import org.openide.util.Lookup;
65
import org.openide.util.Lookup;
67
import org.openide.util.Mutex;
66
import org.openide.util.Mutex;
68
import org.openide.util.lookup.Lookups;
67
import org.openide.util.lookup.Lookups;
68
import org.openide.xml.XMLUtil;
69
import org.w3c.dom.Element;
69
import org.w3c.dom.Element;
70
import org.w3c.dom.NodeList;
70
import org.w3c.dom.NodeList;
71
71
Lines 196-207 Link Here
196
            return ProjectManager.mutex().readAccess(new Mutex.Action<String>() {
196
            return ProjectManager.mutex().readAccess(new Mutex.Action<String>() {
197
                public String run() {
197
                public String run() {
198
                    Element genldata = getPrimaryConfigurationData();
198
                    Element genldata = getPrimaryConfigurationData();
199
                    Element nameEl = Util.findElement(genldata, "name", FreeformProjectType.NS_GENERAL); // NOI18N
199
                    Element nameEl = XMLUtil.findElement(genldata, "name", FreeformProjectType.NS_GENERAL); // NOI18N
200
                    if (nameEl == null) {
200
                    if (nameEl == null) {
201
                        // Corrupt. Cf. #48267 (cause unknown).
201
                        // Corrupt. Cf. #48267 (cause unknown).
202
                        return "???"; // NOI18N
202
                        return "???"; // NOI18N
203
                    }
203
                    }
204
                    return Util.findText(nameEl);
204
                    return XMLUtil.findText(nameEl);
205
                }
205
                }
206
            });
206
            });
207
        }
207
        }
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformProjectGenerator.java (-39 / +40 lines)
Lines 63-68 Link Here
63
import org.openide.filesystems.FileStateInvalidException;
63
import org.openide.filesystems.FileStateInvalidException;
64
import org.openide.filesystems.FileUtil;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.util.NbBundle;
65
import org.openide.util.NbBundle;
66
import org.openide.xml.XMLUtil;
66
import org.w3c.dom.Document;
67
import org.w3c.dom.Document;
67
import org.w3c.dom.Element;
68
import org.w3c.dom.Element;
68
import org.w3c.dom.Node;
69
import org.w3c.dom.Node;
Lines 196-242 Link Here
196
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
197
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
197
        List<TargetMapping> list = new ArrayList<TargetMapping>();
198
        List<TargetMapping> list = new ArrayList<TargetMapping>();
198
        Element genldata = Util.getPrimaryConfigurationData(helper);
199
        Element genldata = Util.getPrimaryConfigurationData(helper);
199
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
200
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
200
        if (actionsEl == null) {
201
        if (actionsEl == null) {
201
            return list;
202
            return list;
202
        }
203
        }
203
        for (Element actionEl : Util.findSubElements(actionsEl)) {
204
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
204
            TargetMapping tm = new TargetMapping();
205
            TargetMapping tm = new TargetMapping();
205
            tm.name = actionEl.getAttribute("name"); // NOI18N
206
            tm.name = actionEl.getAttribute("name"); // NOI18N
206
            List<String> targetNames = new ArrayList<String>();
207
            List<String> targetNames = new ArrayList<String>();
207
            EditableProperties props = new EditableProperties(false);
208
            EditableProperties props = new EditableProperties(false);
208
            for (Element subEl : Util.findSubElements(actionEl)) {
209
            for (Element subEl : XMLUtil.findSubElements(actionEl)) {
209
                if (subEl.getLocalName().equals("target")) { // NOI18N
210
                if (subEl.getLocalName().equals("target")) { // NOI18N
210
                    targetNames.add(Util.findText(subEl));
211
                    targetNames.add(XMLUtil.findText(subEl));
211
                    continue;
212
                    continue;
212
                }
213
                }
213
                if (subEl.getLocalName().equals("script")) { // NOI18N
214
                if (subEl.getLocalName().equals("script")) { // NOI18N
214
                    tm.script = Util.findText(subEl);
215
                    tm.script = XMLUtil.findText(subEl);
215
                    continue;
216
                    continue;
216
                }
217
                }
217
                if (subEl.getLocalName().equals("context")) { // NOI18N
218
                if (subEl.getLocalName().equals("context")) { // NOI18N
218
                    TargetMapping.Context ctx = new TargetMapping.Context();
219
                    TargetMapping.Context ctx = new TargetMapping.Context();
219
                    for (Element contextSubEl : Util.findSubElements(subEl)) {
220
                    for (Element contextSubEl : XMLUtil.findSubElements(subEl)) {
220
                        if (contextSubEl.getLocalName().equals("property")) { // NOI18N
221
                        if (contextSubEl.getLocalName().equals("property")) { // NOI18N
221
                            ctx.property = Util.findText(contextSubEl);
222
                            ctx.property = XMLUtil.findText(contextSubEl);
222
                            continue;
223
                            continue;
223
                        }
224
                        }
224
                        if (contextSubEl.getLocalName().equals("format")) { // NOI18N
225
                        if (contextSubEl.getLocalName().equals("format")) { // NOI18N
225
                            ctx.format = Util.findText(contextSubEl);
226
                            ctx.format = XMLUtil.findText(contextSubEl);
226
                            continue;
227
                            continue;
227
                        }
228
                        }
228
                        if (contextSubEl.getLocalName().equals("folder")) { // NOI18N
229
                        if (contextSubEl.getLocalName().equals("folder")) { // NOI18N
229
                            ctx.folder = Util.findText(contextSubEl);
230
                            ctx.folder = XMLUtil.findText(contextSubEl);
230
                            continue;
231
                            continue;
231
                        }
232
                        }
232
                        if (contextSubEl.getLocalName().equals("pattern")) { // NOI18N
233
                        if (contextSubEl.getLocalName().equals("pattern")) { // NOI18N
233
                            ctx.pattern = Util.findText(contextSubEl);
234
                            ctx.pattern = XMLUtil.findText(contextSubEl);
234
                            continue;
235
                            continue;
235
                        }
236
                        }
236
                        if (contextSubEl.getLocalName().equals("arity")) { // NOI18N
237
                        if (contextSubEl.getLocalName().equals("arity")) { // NOI18N
237
                            Element sepFilesEl = Util.findElement(contextSubEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
238
                            Element sepFilesEl = XMLUtil.findElement(contextSubEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
238
                            if (sepFilesEl != null) {
239
                            if (sepFilesEl != null) {
239
                                ctx.separator = Util.findText(sepFilesEl);
240
                                ctx.separator = XMLUtil.findText(sepFilesEl);
240
                            }
241
                            }
241
                            continue;
242
                            continue;
242
                        }
243
                        }
Lines 259-265 Link Here
259
    
260
    
260
    private static void readProperty(Element propertyElement, EditableProperties props) {
261
    private static void readProperty(Element propertyElement, EditableProperties props) {
261
        String key = propertyElement.getAttribute("name"); // NOI18N
262
        String key = propertyElement.getAttribute("name"); // NOI18N
262
        String value = Util.findText(propertyElement);
263
        String value = XMLUtil.findText(propertyElement);
263
        props.setProperty(key, value);
264
        props.setProperty(key, value);
264
    }
265
    }
265
266
Lines 273-279 Link Here
273
        //assert ProjectManager.mutex().isWriteAccess();
274
        //assert ProjectManager.mutex().isWriteAccess();
274
        Element data = Util.getPrimaryConfigurationData(helper);
275
        Element data = Util.getPrimaryConfigurationData(helper);
275
        Document doc = data.getOwnerDocument();
276
        Document doc = data.getOwnerDocument();
276
        Element actions = Util.findElement(data, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
277
        Element actions = XMLUtil.findElement(data, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
277
        if (actions != null) {
278
        if (actions != null) {
278
            data.removeChild(actions);
279
            data.removeChild(actions);
279
        }
280
        }
Lines 331-337 Link Here
331
            }
332
            }
332
            actions.appendChild(action);
333
            actions.appendChild(action);
333
        }
334
        }
334
        Util.appendChildElement(data, actions, rootElementsOrder);
335
        XMLUtil.appendChildElement(data, actions, rootElementsOrder);
335
        Util.putPrimaryConfigurationData(helper, data);
336
        Util.putPrimaryConfigurationData(helper, data);
336
    }
337
    }
337
    
338
    
Lines 357-373 Link Here
357
        //assert ProjectManager.mutex().isWriteAccess();
358
        //assert ProjectManager.mutex().isWriteAccess();
358
        Element data = Util.getPrimaryConfigurationData(helper);
359
        Element data = Util.getPrimaryConfigurationData(helper);
359
        Document doc = data.getOwnerDocument();
360
        Document doc = data.getOwnerDocument();
360
        Element viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
361
        Element viewEl = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
361
        if (viewEl == null) {
362
        if (viewEl == null) {
362
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
363
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
363
            Util.appendChildElement(data, viewEl, rootElementsOrder);
364
            XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
364
        }
365
        }
365
        Element contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
366
        Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
366
        if (contextMenuEl == null) {
367
        if (contextMenuEl == null) {
367
            contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
368
            contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
368
            Util.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
369
            XMLUtil.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
369
        }
370
        }
370
        for (Element ideActionEl : Util.findSubElements(contextMenuEl)) {
371
        for (Element ideActionEl : XMLUtil.findSubElements(contextMenuEl)) {
371
            if (!ideActionEl.getLocalName().equals("ide-action")) { // NOI18N
372
            if (!ideActionEl.getLocalName().equals("ide-action")) { // NOI18N
372
                continue;
373
                continue;
373
            }
374
            }
Lines 380-386 Link Here
380
            }
381
            }
381
            Element ideAction = doc.createElementNS(FreeformProjectType.NS_GENERAL, "ide-action"); //NOI18N
382
            Element ideAction = doc.createElementNS(FreeformProjectType.NS_GENERAL, "ide-action"); //NOI18N
382
            ideAction.setAttribute("name", tm.name); // NOI18N
383
            ideAction.setAttribute("name", tm.name); // NOI18N
383
            Util.appendChildElement(contextMenuEl, ideAction, contextMenuElementsOrder);
384
            XMLUtil.appendChildElement(contextMenuEl, ideAction, contextMenuElementsOrder);
384
        }
385
        }
385
        Util.putPrimaryConfigurationData(helper, data);
386
        Util.putPrimaryConfigurationData(helper, data);
386
    }
387
    }
Lines 394-425 Link Here
394
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
395
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
395
        List<CustomTarget> list = new ArrayList<CustomTarget>();
396
        List<CustomTarget> list = new ArrayList<CustomTarget>();
396
        Element genldata = Util.getPrimaryConfigurationData(helper);
397
        Element genldata = Util.getPrimaryConfigurationData(helper);
397
        Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
398
        Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
398
        if (viewEl == null) {
399
        if (viewEl == null) {
399
            return list;
400
            return list;
400
        }
401
        }
401
        Element contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
402
        Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
402
        if (contextMenuEl == null) {
403
        if (contextMenuEl == null) {
403
            return list;
404
            return list;
404
        }
405
        }
405
        for (Element actionEl : Util.findSubElements(contextMenuEl)) {
406
        for (Element actionEl : XMLUtil.findSubElements(contextMenuEl)) {
406
            if (!actionEl.getLocalName().equals("action")) { // NOI18N
407
            if (!actionEl.getLocalName().equals("action")) { // NOI18N
407
                continue;
408
                continue;
408
            }
409
            }
409
            CustomTarget ct = new CustomTarget();
410
            CustomTarget ct = new CustomTarget();
410
            List<String> targetNames = new ArrayList<String>();
411
            List<String> targetNames = new ArrayList<String>();
411
            EditableProperties props = new EditableProperties(false);
412
            EditableProperties props = new EditableProperties(false);
412
            for (Element subEl : Util.findSubElements(actionEl)) {
413
            for (Element subEl : XMLUtil.findSubElements(actionEl)) {
413
                if (subEl.getLocalName().equals("target")) { // NOI18N
414
                if (subEl.getLocalName().equals("target")) { // NOI18N
414
                    targetNames.add(Util.findText(subEl));
415
                    targetNames.add(XMLUtil.findText(subEl));
415
                    continue;
416
                    continue;
416
                }
417
                }
417
                if (subEl.getLocalName().equals("script")) { // NOI18N
418
                if (subEl.getLocalName().equals("script")) { // NOI18N
418
                    ct.script = Util.findText(subEl);
419
                    ct.script = XMLUtil.findText(subEl);
419
                    continue;
420
                    continue;
420
                }
421
                }
421
                if (subEl.getLocalName().equals("label")) { // NOI18N
422
                if (subEl.getLocalName().equals("label")) { // NOI18N
422
                    ct.label = Util.findText(subEl);
423
                    ct.label = XMLUtil.findText(subEl);
423
                    continue;
424
                    continue;
424
                }
425
                }
425
                if (subEl.getLocalName().equals("property")) { // NOI18N
426
                if (subEl.getLocalName().equals("property")) { // NOI18N
Lines 448-464 Link Here
448
        //assert ProjectManager.mutex().isWriteAccess();
449
        //assert ProjectManager.mutex().isWriteAccess();
449
        Element data = Util.getPrimaryConfigurationData(helper);
450
        Element data = Util.getPrimaryConfigurationData(helper);
450
        Document doc = data.getOwnerDocument();
451
        Document doc = data.getOwnerDocument();
451
        Element viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
452
        Element viewEl = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
452
        if (viewEl == null) {
453
        if (viewEl == null) {
453
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
454
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
454
            Util.appendChildElement(data, viewEl, rootElementsOrder);
455
            XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
455
        }
456
        }
456
        Element contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
457
        Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
457
        if (contextMenuEl == null) {
458
        if (contextMenuEl == null) {
458
            contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
459
            contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
459
            Util.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
460
            XMLUtil.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
460
        }
461
        }
461
        for (Element actionEl : Util.findSubElements(contextMenuEl)) {
462
        for (Element actionEl : XMLUtil.findSubElements(contextMenuEl)) {
462
            if (!actionEl.getLocalName().equals("action")) { // NOI18N
463
            if (!actionEl.getLocalName().equals("action")) { // NOI18N
463
                continue;
464
                continue;
464
            }
465
            }
Lines 484-490 Link Here
484
            if (ct.properties != null) {
485
            if (ct.properties != null) {
485
                writeProperties(ct.properties, doc, action);
486
                writeProperties(ct.properties, doc, action);
486
            }
487
            }
487
            Util.appendChildElement(contextMenuEl, action, contextMenuElementsOrder);
488
            XMLUtil.appendChildElement(contextMenuEl, action, contextMenuElementsOrder);
488
        }
489
        }
489
        Util.putPrimaryConfigurationData(helper, data);
490
        Util.putPrimaryConfigurationData(helper, data);
490
    }
491
    }
Lines 523-543 Link Here
523
    private static void putBuildXMLSourceFile(AntProjectHelper helper, String antPath) {
524
    private static void putBuildXMLSourceFile(AntProjectHelper helper, String antPath) {
524
        Element data = Util.getPrimaryConfigurationData(helper);
525
        Element data = Util.getPrimaryConfigurationData(helper);
525
        Document doc = data.getOwnerDocument();
526
        Document doc = data.getOwnerDocument();
526
        Element viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
527
        Element viewEl = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
527
        if (viewEl == null) {
528
        if (viewEl == null) {
528
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
529
            viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
529
            Util.appendChildElement(data, viewEl, rootElementsOrder);
530
            XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
530
        }
531
        }
531
        Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
532
        Element itemsEl = XMLUtil.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
532
        if (itemsEl == null) {
533
        if (itemsEl == null) {
533
            itemsEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "items"); // NOI18N
534
            itemsEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "items"); // NOI18N
534
            Util.appendChildElement(viewEl, itemsEl, viewElementsOrder);
535
            XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder);
535
        }
536
        }
536
        Element fileEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "source-file"); // NOI18N
537
        Element fileEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "source-file"); // NOI18N
537
        Element el = doc.createElementNS(FreeformProjectType.NS_GENERAL, "location"); // NOI18N
538
        Element el = doc.createElementNS(FreeformProjectType.NS_GENERAL, "location"); // NOI18N
538
        el.appendChild(doc.createTextNode(antPath)); // NOI18N
539
        el.appendChild(doc.createTextNode(antPath)); // NOI18N
539
        fileEl.appendChild(el);
540
        fileEl.appendChild(el);
540
        Util.appendChildElement(itemsEl, fileEl, viewItemElementsOrder);
541
        XMLUtil.appendChildElement(itemsEl, fileEl, viewItemElementsOrder);
541
        Util.putPrimaryConfigurationData(helper, data);
542
        Util.putPrimaryConfigurationData(helper, data);
542
    }
543
    }
543
544
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformProjectOperations.java (-8 / +5 lines)
Lines 45-62 Link Here
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.util.ArrayList;
46
import java.util.ArrayList;
47
import java.util.Collections;
47
import java.util.Collections;
48
import java.util.Iterator;
49
import java.util.List;
48
import java.util.List;
50
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
51
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.modules.ant.freeform.spi.support.Util;
53
import org.netbeans.spi.project.CopyOperationImplementation;
50
import org.netbeans.spi.project.CopyOperationImplementation;
54
import org.netbeans.spi.project.DeleteOperationImplementation;
51
import org.netbeans.spi.project.DeleteOperationImplementation;
55
import org.netbeans.spi.project.MoveOperationImplementation;
52
import org.netbeans.spi.project.MoveOperationImplementation;
56
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
53
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
57
import org.openide.ErrorManager;
58
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileUtil;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.xml.XMLUtil;
60
import org.w3c.dom.Element;
57
import org.w3c.dom.Element;
61
58
62
/**
59
/**
Lines 90-97 Link Here
90
    
87
    
91
    public List<FileObject> getDataFiles() {
88
    public List<FileObject> getDataFiles() {
92
        Element genldata = project.getPrimaryConfigurationData();
89
        Element genldata = project.getPrimaryConfigurationData();
93
        Element foldersEl = Util.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
90
        Element foldersEl = XMLUtil.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
94
        List<Element> folders = foldersEl != null ? Util.findSubElements(foldersEl) : Collections.<Element>emptyList();
91
        List<Element> folders = foldersEl != null ? XMLUtil.findSubElements(foldersEl) : Collections.<Element>emptyList();
95
        List<FileObject> result = new ArrayList<FileObject>();
92
        List<FileObject> result = new ArrayList<FileObject>();
96
93
97
        for (Element el : folders) {
94
        for (Element el : folders) {
Lines 106-119 Link Here
106
    }
103
    }
107
    
104
    
108
    private void addFile(Element folder, List<FileObject> result) {
105
    private void addFile(Element folder, List<FileObject> result) {
109
        Element location = Util.findElement(folder, "location", FreeformProjectType.NS_GENERAL); // NOI18N
106
        Element location = XMLUtil.findElement(folder, "location", FreeformProjectType.NS_GENERAL); // NOI18N
110
        
107
        
111
        if (location == null) {
108
        if (location == null) {
112
            return ;
109
            return ;
113
        }
110
        }
114
        
111
        
115
        PropertyEvaluator evaluator = project.evaluator();
112
        PropertyEvaluator evaluator = project.evaluator();
116
        String val = evaluator.evaluate(Util.findText(location));
113
        String val = evaluator.evaluate(XMLUtil.findText(location));
117
        
114
        
118
        if (val == null) {
115
        if (val == null) {
119
            return ;
116
            return ;
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformSharabilityQuery.java (-4 / +2 lines)
Lines 54-62 Link Here
54
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.xml.XMLUtil;
55
import org.openide.xml.XMLUtil;
56
import org.w3c.dom.Element;
56
import org.w3c.dom.Element;
57
import org.w3c.dom.Node;
58
import org.w3c.dom.NodeList;
57
import org.w3c.dom.NodeList;
59
import org.w3c.dom.Text;
60
58
61
/**
59
/**
62
 *
60
 *
Lines 117-125 Link Here
117
                    final NodeList exports = root.getElementsByTagNameNS(FreeformProjectType.NS_GENERAL, "export"); //NOI18N
115
                    final NodeList exports = root.getElementsByTagNameNS(FreeformProjectType.NS_GENERAL, "export"); //NOI18N
118
                    for (int i=0; i< exports.getLength(); i++) {
116
                    for (int i=0; i< exports.getLength(); i++) {
119
                        final Element export = (Element) exports.item(i);
117
                        final Element export = (Element) exports.item(i);
120
                        final Element location = Util.findElement(export, "location", FreeformProjectType.NS_GENERAL);   //NOI18N
118
                        final Element location = XMLUtil.findElement(export, "location", FreeformProjectType.NS_GENERAL);   //NOI18N
121
                        if (location != null) {
119
                        if (location != null) {
122
                            final String path = Util.findText(location);
120
                            final String path = XMLUtil.findText(location);
123
                            if (path != null) {
121
                            if (path != null) {
124
                                final File exportedFile = Util.resolveFile(project.evaluator(), FileUtil.toFile(project.getProjectDirectory()), path);
122
                                final File exportedFile = Util.resolveFile(project.evaluator(), FileUtil.toFile(project.getProjectDirectory()), path);
125
                                if (exportedFile != null) {
123
                                if (exportedFile != null) {
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformSources.java (-13 / +13 lines)
Lines 46-57 Link Here
46
import org.netbeans.api.project.ProjectManager;
46
import org.netbeans.api.project.ProjectManager;
47
import org.netbeans.api.project.SourceGroup;
47
import org.netbeans.api.project.SourceGroup;
48
import org.netbeans.api.project.Sources;
48
import org.netbeans.api.project.Sources;
49
import org.netbeans.modules.ant.freeform.spi.support.Util;
50
import org.netbeans.spi.project.support.ant.AntProjectEvent;
49
import org.netbeans.spi.project.support.ant.AntProjectEvent;
51
import org.netbeans.spi.project.support.ant.AntProjectListener;
50
import org.netbeans.spi.project.support.ant.AntProjectListener;
52
import org.netbeans.spi.project.support.ant.SourcesHelper;
51
import org.netbeans.spi.project.support.ant.SourcesHelper;
53
import org.openide.util.ChangeSupport;
52
import org.openide.util.ChangeSupport;
54
import org.openide.util.Mutex;
53
import org.openide.util.Mutex;
54
import org.openide.xml.XMLUtil;
55
import org.w3c.dom.Element;
55
import org.w3c.dom.Element;
56
56
57
/**
57
/**
Lines 86-117 Link Here
86
    private Sources initSources() {
86
    private Sources initSources() {
87
        SourcesHelper h = new SourcesHelper(project, project.helper(), project.evaluator());
87
        SourcesHelper h = new SourcesHelper(project, project.helper(), project.evaluator());
88
        Element genldata = project.getPrimaryConfigurationData();
88
        Element genldata = project.getPrimaryConfigurationData();
89
        Element foldersE = Util.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
89
        Element foldersE = XMLUtil.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
90
        if (foldersE != null) {
90
        if (foldersE != null) {
91
            for (Element folderE : Util.findSubElements(foldersE)) {
91
            for (Element folderE : XMLUtil.findSubElements(foldersE)) {
92
                Element locationE = Util.findElement(folderE, "location", FreeformProjectType.NS_GENERAL); // NOI18N
92
                Element locationE = XMLUtil.findElement(folderE, "location", FreeformProjectType.NS_GENERAL); // NOI18N
93
                String location = Util.findText(locationE);
93
                String location = XMLUtil.findText(locationE);
94
                if (folderE.getLocalName().equals("build-folder")) { // NOI18N
94
                if (folderE.getLocalName().equals("build-folder")) { // NOI18N
95
                    h.addNonSourceRoot(location);
95
                    h.addNonSourceRoot(location);
96
                } else if (folderE.getLocalName().equals("build-file")) { // NOI18N
96
                } else if (folderE.getLocalName().equals("build-file")) { // NOI18N
97
                    h.addOwnedFile(location);
97
                    h.addOwnedFile(location);
98
                } else {
98
                } else {
99
                    assert folderE.getLocalName().equals("source-folder") : folderE;
99
                    assert folderE.getLocalName().equals("source-folder") : folderE;
100
                    Element nameE = Util.findElement(folderE, "label", FreeformProjectType.NS_GENERAL); // NOI18N
100
                    Element nameE = XMLUtil.findElement(folderE, "label", FreeformProjectType.NS_GENERAL); // NOI18N
101
                    String name = Util.findText(nameE);
101
                    String name = XMLUtil.findText(nameE);
102
                    Element typeE = Util.findElement(folderE, "type", FreeformProjectType.NS_GENERAL); // NOI18N
102
                    Element typeE = XMLUtil.findElement(folderE, "type", FreeformProjectType.NS_GENERAL); // NOI18N
103
                    String includes = null;
103
                    String includes = null;
104
                    Element includesE = Util.findElement(folderE, "includes", FreeformProjectType.NS_GENERAL); // NOI18N
104
                    Element includesE = XMLUtil.findElement(folderE, "includes", FreeformProjectType.NS_GENERAL); // NOI18N
105
                    if (includesE != null) {
105
                    if (includesE != null) {
106
                        includes = Util.findText(includesE);
106
                        includes = XMLUtil.findText(includesE);
107
                    }
107
                    }
108
                    String excludes = null;
108
                    String excludes = null;
109
                    Element excludesE = Util.findElement(folderE, "excludes", FreeformProjectType.NS_GENERAL); // NOI18N
109
                    Element excludesE = XMLUtil.findElement(folderE, "excludes", FreeformProjectType.NS_GENERAL); // NOI18N
110
                    if (excludesE != null) {
110
                    if (excludesE != null) {
111
                        excludes = Util.findText(excludesE);
111
                        excludes = XMLUtil.findText(excludesE);
112
                    }
112
                    }
113
                    if (typeE != null) {
113
                    if (typeE != null) {
114
                        String type = Util.findText(typeE);
114
                        String type = XMLUtil.findText(typeE);
115
                        h.addTypedSourceRoot(location, includes, excludes, type, name, null, null);
115
                        h.addTypedSourceRoot(location, includes, excludes, type, name, null, null);
116
                    } else {
116
                    } else {
117
                        h.addPrincipalSourceRoot(location, includes, excludes, name, null, null);
117
                        h.addPrincipalSourceRoot(location, includes, excludes, name, null, null);
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/FreeformTemplateAttributesProvider.java (-2 / +3 lines)
Lines 51-56 Link Here
51
import org.openide.loaders.CreateFromTemplateAttributesProvider;
51
import org.openide.loaders.CreateFromTemplateAttributesProvider;
52
import org.openide.loaders.DataFolder;
52
import org.openide.loaders.DataFolder;
53
import org.openide.loaders.DataObject;
53
import org.openide.loaders.DataObject;
54
import org.openide.xml.XMLUtil;
54
import org.w3c.dom.Element;
55
import org.w3c.dom.Element;
55
56
56
/**
57
/**
Lines 77-90 Link Here
77
    
78
    
78
    public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) {
79
    public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) {
79
        Element primData = Util.getPrimaryConfigurationData(helper);
80
        Element primData = Util.getPrimaryConfigurationData(helper);
80
        Element licenseEl = Util.findElement(primData, "project-license", Util.NAMESPACE); // NOI18N
81
        Element licenseEl = XMLUtil.findElement(primData, "project-license", Util.NAMESPACE); // NOI18N
81
        Charset charset = encodingQuery.getEncoding(target.getPrimaryFile());
82
        Charset charset = encodingQuery.getEncoding(target.getPrimaryFile());
82
        if (licenseEl == null && charset == null) {
83
        if (licenseEl == null && charset == null) {
83
            return null;
84
            return null;
84
        } else {
85
        } else {
85
            Map<String, String> values = new HashMap<String, String>();
86
            Map<String, String> values = new HashMap<String, String>();
86
            if (licenseEl != null) {
87
            if (licenseEl != null) {
87
                values.put("license", evaluator.evaluate(Util.findText(licenseEl))); // NOI18N
88
                values.put("license", evaluator.evaluate(XMLUtil.findText(licenseEl))); // NOI18N
88
            }
89
            }
89
            if (charset != null) {
90
            if (charset != null) {
90
                values.put("encoding", charset.name()); // NOI18N
91
                values.put("encoding", charset.name()); // NOI18N
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/Subprojects.java (-5 / +4 lines)
Lines 46-60 Link Here
46
import java.util.Collections;
46
import java.util.Collections;
47
import java.util.HashSet;
47
import java.util.HashSet;
48
import java.util.Iterator;
48
import java.util.Iterator;
49
import java.util.List;
50
import java.util.Set;
49
import java.util.Set;
51
import javax.swing.event.ChangeListener;
50
import javax.swing.event.ChangeListener;
52
import org.netbeans.api.project.Project;
51
import org.netbeans.api.project.Project;
53
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.api.project.ProjectManager;
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
55
import org.netbeans.spi.project.SubprojectProvider;
53
import org.netbeans.spi.project.SubprojectProvider;
56
import org.openide.ErrorManager;
54
import org.openide.ErrorManager;
57
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
56
import org.openide.xml.XMLUtil;
58
import org.w3c.dom.Element;
57
import org.w3c.dom.Element;
59
58
60
/**
59
/**
Lines 88-98 Link Here
88
     */
87
     */
89
    private Set<Project> createSubprojects(Set<Project> subprojects) {
88
    private Set<Project> createSubprojects(Set<Project> subprojects) {
90
        Element config = project.getPrimaryConfigurationData();
89
        Element config = project.getPrimaryConfigurationData();
91
        Element subprjsEl = Util.findElement(config, "subprojects", FreeformProjectType.NS_GENERAL); // NOI18N
90
        Element subprjsEl = XMLUtil.findElement(config, "subprojects", FreeformProjectType.NS_GENERAL); // NOI18N
92
        if (subprjsEl != null) {
91
        if (subprjsEl != null) {
93
            for (Element prjEl : Util.findSubElements(subprjsEl)) {
92
            for (Element prjEl : XMLUtil.findSubElements(subprjsEl)) {
94
                assert prjEl.getLocalName().equals("project") : "Bad element " + prjEl + " in <subprojects> for " + project;
93
                assert prjEl.getLocalName().equals("project") : "Bad element " + prjEl + " in <subprojects> for " + project;
95
                String rawtext = Util.findText(prjEl);
94
                String rawtext = XMLUtil.findText(prjEl);
96
                assert rawtext != null : "Need text content for <project> in " + project;
95
                assert rawtext != null : "Need text content for <project> in " + project;
97
                String evaltext = project.evaluator().evaluate(rawtext);
96
                String evaltext = project.evaluator().evaluate(rawtext);
98
                if (evaltext == null) {
97
                if (evaltext == null) {
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java (-139 / +3 lines)
Lines 43-52 Link Here
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.Iterator;
49
import java.util.List;
50
import javax.xml.XMLConstants;
46
import javax.xml.XMLConstants;
51
import javax.xml.validation.Schema;
47
import javax.xml.validation.Schema;
52
import javax.xml.validation.SchemaFactory;
48
import javax.xml.validation.SchemaFactory;
Lines 71-80 Link Here
71
import org.w3c.dom.DOMException;
67
import org.w3c.dom.DOMException;
72
import org.w3c.dom.Document;
68
import org.w3c.dom.Document;
73
import org.w3c.dom.Element;
69
import org.w3c.dom.Element;
74
import org.w3c.dom.NamedNodeMap;
75
import org.w3c.dom.Node;
76
import org.w3c.dom.NodeList;
77
import org.w3c.dom.Text;
78
import org.w3c.dom.ls.DOMImplementationLS;
70
import org.w3c.dom.ls.DOMImplementationLS;
79
import org.w3c.dom.ls.LSSerializer;
71
import org.w3c.dom.ls.LSSerializer;
80
import org.xml.sax.SAXException;
72
import org.xml.sax.SAXException;
Lines 87-170 Link Here
87
    
79
    
88
    private Util() {}
80
    private Util() {}
89
    
81
    
90
    // XXX XML methods copied from ant/project... make a general API of these instead?
91
    
92
    /**
93
     * Search for an XML element in the direct children of a parent.
94
     * DOM provides a similar method but it does a recursive search
95
     * which we do not want. It also gives a node list and we want
96
     * only one result.
97
     * @param parent a parent element
98
     * @param name the intended local name
99
     * @param namespace the intended namespace
100
     * @return the one child element with that name, or null if none or more than one
101
     */
102
    public static Element findElement(Element parent, String name, String namespace) {
103
        Element result = null;
104
        NodeList l = parent.getChildNodes();
105
        for (int i = 0; i < l.getLength(); i++) {
106
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
107
                Element el = (Element)l.item(i);
108
                if (name.equals(el.getLocalName()) && namespace.equals(el.getNamespaceURI())) {
109
                    if (result == null) {
110
                        result = el;
111
                    } else {
112
                        return null;
113
                    }
114
                }
115
            }
116
        }
117
        return result;
118
    }
119
    
120
    /**
121
     * Extract nested text from an element.
122
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
123
     * @param parent a parent element
124
     * @return the nested text, or null if none was found
125
     */
126
    public static String findText(Element parent) {
127
        NodeList l = parent.getChildNodes();
128
        for (int i = 0; i < l.getLength(); i++) {
129
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
130
                Text text = (Text)l.item(i);
131
                return text.getNodeValue();
132
            }
133
        }
134
        return null;
135
    }
136
    
137
    /**
138
     * Find all direct child elements of an element.
139
     * More useful than {@link Element#getElementsByTagNameNS} because it does
140
     * not recurse into recursive child elements.
141
     * Children which are all-whitespace text nodes are ignored; others cause
142
     * an exception to be thrown.
143
     * @param parent a parent element in a DOM tree
144
     * @return a list of direct child elements (may be empty)
145
     * @throws IllegalArgumentException if there are non-element children besides whitespace
146
     */
147
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
148
        NodeList l = parent.getChildNodes();
149
        List<Element> elements = new ArrayList<Element>(l.getLength());
150
        for (int i = 0; i < l.getLength(); i++) {
151
            Node n = l.item(i);
152
            if (n.getNodeType() == Node.ELEMENT_NODE) {
153
                elements.add((Element)n);
154
            } else if (n.getNodeType() == Node.TEXT_NODE) {
155
                String text = ((Text)n).getNodeValue();
156
                if (text.trim().length() > 0) {
157
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
158
                }
159
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
160
                // skip
161
            } else {
162
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
163
            }
164
        }
165
        return elements;
166
    }
167
168
    /**
82
    /**
169
     * Finds AuxiliaryConfiguration for the given project helper. The method
83
     * Finds AuxiliaryConfiguration for the given project helper. The method
170
     * finds project associated with the helper and searches 
84
     * finds project associated with the helper and searches 
Lines 241-271 Link Here
241
        }
155
        }
242
    }
156
    }
243
157
244
    /**
245
     * Append child element to the correct position according to given
246
     * order.
247
     * @param parent parent to which the child will be added
248
     * @param el element to be added
249
     * @param order order of the elements which must be followed
250
     */
251
    public static void appendChildElement(Element parent, Element el, String[] order) {
252
        Element insertBefore = null;
253
        List l = Arrays.asList(order);
254
        int index = l.indexOf(el.getLocalName());
255
        assert index != -1 : el.getLocalName()+" was not found in "+l; // NOI18N
256
        Iterator it = Util.findSubElements(parent).iterator();
257
        while (it.hasNext()) {
258
            Element e = (Element)it.next();
259
            int index2 = l.indexOf(e.getLocalName());
260
            assert index2 != -1 : e.getLocalName()+" was not found in "+l; // NOI18N
261
            if (index2 > index) {
262
                insertBefore = e;
263
                break;
264
            }
265
        }
266
        parent.insertBefore(el, insertBefore);
267
    }
268
    
269
    /**Get the "default" (user-specified) ant script for the given freeform project.
158
    /**Get the "default" (user-specified) ant script for the given freeform project.
270
     * Please note that this method may return <code>null</code> if there is no such script.
159
     * Please note that this method may return <code>null</code> if there is no such script.
271
     *
160
     *
Lines 287-317 Link Here
287
    }
176
    }
288
    
177
    
289
    /**
178
    /**
290
     * Convert an XML fragment from one namespace to another.
291
     */
292
    private static Element translateXML(Element from, String namespace) {
293
        Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
294
        NodeList nl = from.getChildNodes();
295
        int length = nl.getLength();
296
        for (int i = 0; i < length; i++) {
297
            Node node = nl.item(i);
298
            Node newNode;
299
            if (node.getNodeType() == Node.ELEMENT_NODE) {
300
                newNode = translateXML((Element) node, namespace);
301
            } else {
302
                newNode = node.cloneNode(true);
303
            }
304
            to.appendChild(newNode);
305
        }
306
        NamedNodeMap m = from.getAttributes();
307
        for (int i = 0; i < m.getLength(); i++) {
308
            Node attr = m.item(i);
309
            to.setAttribute(attr.getNodeName(), attr.getNodeValue());
310
        }
311
        return to;
312
    }
313
314
    /**
315
     * Namespace of data used in {@link #getPrimaryConfigurationData} and {@link #putPrimaryConfigurationData}.
179
     * Namespace of data used in {@link #getPrimaryConfigurationData} and {@link #putPrimaryConfigurationData}.
316
     * @since org.netbeans.modules.ant.freeform/1 1.15
180
     * @since org.netbeans.modules.ant.freeform/1 1.15
317
     */
181
     */
Lines 332-338 Link Here
332
                if (data != null) {
196
                if (data != null) {
333
                    return data;
197
                    return data;
334
                } else {
198
                } else {
335
                    return translateXML(helper.getPrimaryConfigurationData(true), NAMESPACE);
199
                    return XMLUtil.translateXML(helper.getPrimaryConfigurationData(true), NAMESPACE);
336
                }
200
                }
337
            }
201
            }
338
        });
202
        });
Lines 353-359 Link Here
353
        }
217
        }
354
        ProjectManager.mutex().writeAccess(new Mutex.Action<Void>() {
218
        ProjectManager.mutex().writeAccess(new Mutex.Action<Void>() {
355
            public Void run() {
219
            public Void run() {
356
                Element dataAs1 = translateXML(data, FreeformProjectType.NS_GENERAL_1);
220
                Element dataAs1 = XMLUtil.translateXML(data, FreeformProjectType.NS_GENERAL_1);
357
                if (SCHEMA_1 == null) {
221
                if (SCHEMA_1 == null) {
358
                    try {
222
                    try {
359
                        SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
223
                        SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Lines 390-396 Link Here
390
        Element dummy1 = doc.createElementNS(FreeformProjectType.NS_GENERAL_1, FreeformProjectType.NAME_SHARED);
254
        Element dummy1 = doc.createElementNS(FreeformProjectType.NS_GENERAL_1, FreeformProjectType.NAME_SHARED);
391
        // Make sure it is not invalid.
255
        // Make sure it is not invalid.
392
        dummy1.appendChild(doc.createElementNS(FreeformProjectType.NS_GENERAL_1, "name")). // NOI18N
256
        dummy1.appendChild(doc.createElementNS(FreeformProjectType.NS_GENERAL_1, "name")). // NOI18N
393
                appendChild(doc.createTextNode(findText(findElement(data, "name", NAMESPACE)))); // NOI18N
257
                appendChild(doc.createTextNode(XMLUtil.findText(XMLUtil.findElement(data, "name", NAMESPACE)))); // NOI18N
394
        helper.putPrimaryConfigurationData(dummy1, true);
258
        helper.putPrimaryConfigurationData(dummy1, true);
395
        helper.createAuxiliaryConfiguration().putConfigurationFragment(data, true);
259
        helper.createAuxiliaryConfiguration().putConfigurationFragment(data, true);
396
    }
260
    }
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java (-12 / +12 lines)
Lines 64-70 Link Here
64
import org.netbeans.api.queries.VisibilityQuery;
64
import org.netbeans.api.queries.VisibilityQuery;
65
import org.netbeans.modules.ant.freeform.FreeformProject;
65
import org.netbeans.modules.ant.freeform.FreeformProject;
66
import org.netbeans.modules.ant.freeform.FreeformProjectType;
66
import org.netbeans.modules.ant.freeform.FreeformProjectType;
67
import org.netbeans.modules.ant.freeform.spi.support.Util;
68
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
67
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
69
import org.netbeans.spi.project.support.ant.AntProjectEvent;
68
import org.netbeans.spi.project.support.ant.AntProjectEvent;
70
import org.netbeans.spi.project.support.ant.AntProjectListener;
69
import org.netbeans.spi.project.support.ant.AntProjectListener;
Lines 91-96 Link Here
91
import org.openide.util.RequestProcessor;
90
import org.openide.util.RequestProcessor;
92
import org.openide.util.actions.SystemAction;
91
import org.openide.util.actions.SystemAction;
93
import org.openide.util.lookup.Lookups;
92
import org.openide.util.lookup.Lookups;
93
import org.openide.xml.XMLUtil;
94
import org.w3c.dom.Element;
94
import org.w3c.dom.Element;
95
95
96
/**
96
/**
Lines 136-145 Link Here
136
        
136
        
137
        private void updateKeys(boolean fromListener) {
137
        private void updateKeys(boolean fromListener) {
138
            Element genldata = p.getPrimaryConfigurationData();
138
            Element genldata = p.getPrimaryConfigurationData();
139
            Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
139
            Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
140
            if (viewEl != null) {
140
            if (viewEl != null) {
141
                Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
141
                Element itemsEl = XMLUtil.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
142
                keys = Util.findSubElements(itemsEl);
142
                keys = XMLUtil.findSubElements(itemsEl);
143
            } else {
143
            } else {
144
                keys = Collections.<Element>emptyList();
144
                keys = Collections.<Element>emptyList();
145
            }
145
            }
Lines 182-189 Link Here
182
        
182
        
183
        public Node node(Element itemEl) {
183
        public Node node(Element itemEl) {
184
            
184
            
185
            Element locationEl = Util.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N
185
            Element locationEl = XMLUtil.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N
186
            String location = Util.findText(locationEl);
186
            String location = XMLUtil.findText(locationEl);
187
            String locationEval = p.evaluator().evaluate(location);
187
            String locationEval = p.evaluator().evaluate(location);
188
            if (locationEval == null) {
188
            if (locationEval == null) {
189
                return null;
189
                return null;
Lines 194-202 Link Here
194
                return null;
194
                return null;
195
            }
195
            }
196
            String label;
196
            String label;
197
            Element labelEl = Util.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
197
            Element labelEl = XMLUtil.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
198
            if (labelEl != null) {
198
            if (labelEl != null) {
199
                label = Util.findText(labelEl);
199
                label = XMLUtil.findText(labelEl);
200
            } else {
200
            } else {
201
                label = null;
201
                label = null;
202
            }
202
            }
Lines 206-223 Link Here
206
                    return null;
206
                    return null;
207
                }
207
                }
208
                String includes = null;
208
                String includes = null;
209
                Element includesEl = Util.findElement(itemEl, "includes", FreeformProjectType.NS_GENERAL); // NOI18N
209
                Element includesEl = XMLUtil.findElement(itemEl, "includes", FreeformProjectType.NS_GENERAL); // NOI18N
210
                if (includesEl != null) {
210
                if (includesEl != null) {
211
                    includes = p.evaluator().evaluate(Util.findText(includesEl));
211
                    includes = p.evaluator().evaluate(XMLUtil.findText(includesEl));
212
                    if (includes.matches("\\$\\{[^}]+\\}")) { // NOI18N
212
                    if (includes.matches("\\$\\{[^}]+\\}")) { // NOI18N
213
                        // Clearly intended to mean "include everything".
213
                        // Clearly intended to mean "include everything".
214
                        includes = null;
214
                        includes = null;
215
                    }
215
                    }
216
                }
216
                }
217
                String excludes = null;
217
                String excludes = null;
218
                Element excludesEl = Util.findElement(itemEl, "excludes", FreeformProjectType.NS_GENERAL); // NOI18N
218
                Element excludesEl = XMLUtil.findElement(itemEl, "excludes", FreeformProjectType.NS_GENERAL); // NOI18N
219
                if (excludesEl != null) {
219
                if (excludesEl != null) {
220
                    excludes = p.evaluator().evaluate(Util.findText(excludesEl));
220
                    excludes = p.evaluator().evaluate(XMLUtil.findText(excludesEl));
221
                }
221
                }
222
                String style = itemEl.getAttribute("style"); // NOI18N
222
                String style = itemEl.getAttribute("style"); // NOI18N
223
                for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) {
223
                for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) {
(-)a/ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/ArtifactProviderTest.java (-3 / +4 lines)
Lines 49-54 Link Here
49
import org.netbeans.api.project.ant.AntArtifactQuery;
49
import org.netbeans.api.project.ant.AntArtifactQuery;
50
import org.netbeans.modules.ant.freeform.spi.support.Util;
50
import org.netbeans.modules.ant.freeform.spi.support.Util;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
52
import org.openide.xml.XMLUtil;
52
import org.w3c.dom.Document;
53
import org.w3c.dom.Document;
53
import org.w3c.dom.Element;
54
import org.w3c.dom.Element;
54
55
Lines 137-143 Link Here
137
        //assert ProjectManager.mutex().isWriteAccess();
138
        //assert ProjectManager.mutex().isWriteAccess();
138
        Element data = Util.getPrimaryConfigurationData(helper);
139
        Element data = Util.getPrimaryConfigurationData(helper);
139
        Document doc = data.getOwnerDocument();
140
        Document doc = data.getOwnerDocument();
140
        for (Element exportEl : Util.findSubElements(data)) {
141
        for (Element exportEl : XMLUtil.findSubElements(data)) {
141
            if (!exportEl.getLocalName().equals("export")) { // NOI18N
142
            if (!exportEl.getLocalName().equals("export")) { // NOI18N
142
                continue;
143
                continue;
143
            }
144
            }
Lines 165-173 Link Here
165
                el.appendChild(doc.createTextNode(export.cleanTarget)); // NOI18N
166
                el.appendChild(doc.createTextNode(export.cleanTarget)); // NOI18N
166
                exportEl.appendChild(el);
167
                exportEl.appendChild(el);
167
            }
168
            }
168
            Element later = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL);
169
            Element later = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL);
169
            if (later == null) {
170
            if (later == null) {
170
                later = Util.findElement(data, "subprojects", FreeformProjectType.NS_GENERAL);
171
                later = XMLUtil.findElement(data, "subprojects", FreeformProjectType.NS_GENERAL);
171
            }
172
            }
172
            data.insertBefore(exportEl, later);
173
            data.insertBefore(exportEl, later);
173
        }
174
        }
(-)a/ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/FreeformProjectGeneratorTest.java (-33 / +34 lines)
Lines 62-67 Link Here
62
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileObject;
63
import org.openide.modules.ModuleInfo;
63
import org.openide.modules.ModuleInfo;
64
import org.openide.util.Lookup;
64
import org.openide.util.Lookup;
65
import org.openide.xml.XMLUtil;
65
import org.w3c.dom.Element;
66
import org.w3c.dom.Element;
66
67
67
/**
68
/**
Lines 227-240 Link Here
227
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
228
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
228
//        ProjectManager.getDefault().saveAllProjects();
229
//        ProjectManager.getDefault().saveAllProjects();
229
        Element el = Util.getPrimaryConfigurationData(helper);
230
        Element el = Util.getPrimaryConfigurationData(helper);
230
        el = Util.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
231
        el = XMLUtil.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
231
        assertNotNull("Target mapping were not saved correctly",  el);
232
        assertNotNull("Target mapping were not saved correctly",  el);
232
        List<Element> subElements = Util.findSubElements(el);
233
        List<Element> subElements = XMLUtil.findSubElements(el);
233
        assertEquals(2, subElements.size());
234
        assertEquals(2, subElements.size());
234
        // compare first target mapping
235
        // compare first target mapping
235
        Element el2 = subElements.get(0);
236
        Element el2 = subElements.get(0);
236
        assertElement(el2, "action", null, "name", "first-targetName");
237
        assertElement(el2, "action", null, "name", "first-targetName");
237
        List<Element> l1 = Util.findSubElements(el2);
238
        List<Element> l1 = XMLUtil.findSubElements(el2);
238
        assertEquals(7, l1.size());
239
        assertEquals(7, l1.size());
239
        assertElementArray(l1, 
240
        assertElementArray(l1, 
240
            new String[]{"script", "target", "target", "target", "property", "property", "context"}, 
241
            new String[]{"script", "target", "target", "target", "property", "property", "context"}, 
Lines 244-259 Link Here
244
        el2 = l1.get(5);
245
        el2 = l1.get(5);
245
        assertElement(el2, "property", "v2", "name", "k2");
246
        assertElement(el2, "property", "v2", "name", "k2");
246
        el2 = l1.get(6);
247
        el2 = l1.get(6);
247
        List<Element> l2 = Util.findSubElements(el2);
248
        List<Element> l2 = XMLUtil.findSubElements(el2);
248
        assertEquals(5, l2.size());
249
        assertEquals(5, l2.size());
249
        assertElementArray(l2, 
250
        assertElementArray(l2, 
250
            new String[]{"property", "folder", "pattern", "format", "arity"}, 
251
            new String[]{"property", "folder", "pattern", "format", "arity"}, 
251
            new String[]{"someProperty1", "someFolder1", "somePattern1", "relative-path", null});
252
            new String[]{"someProperty1", "someFolder1", "somePattern1", "relative-path", null});
252
        assertNotNull("have <one-file-only>", Util.findElement(l2.get(4), "one-file-only", FreeformProjectType.NS_GENERAL));
253
        assertNotNull("have <one-file-only>", XMLUtil.findElement(l2.get(4), "one-file-only", FreeformProjectType.NS_GENERAL));
253
        // compare second target mapping
254
        // compare second target mapping
254
        el2 = subElements.get(1);
255
        el2 = subElements.get(1);
255
        assertElement(el2, "action", null, "name", "second-targetName");
256
        assertElement(el2, "action", null, "name", "second-targetName");
256
        l1 = Util.findSubElements(el2);
257
        l1 = XMLUtil.findSubElements(el2);
257
        assertEquals(7, l1.size());
258
        assertEquals(7, l1.size());
258
        assertElementArray(l1, 
259
        assertElementArray(l1, 
259
            new String[]{"script", "target", "target", "target", "property", "property", "context"},
260
            new String[]{"script", "target", "target", "target", "property", "property", "context"},
Lines 263-276 Link Here
263
        el2 = l1.get(5);
264
        el2 = l1.get(5);
264
        assertElement(el2, "property", "second-v2", "name", "second-k2");
265
        assertElement(el2, "property", "second-v2", "name", "second-k2");
265
        el2 = l1.get(6);
266
        el2 = l1.get(6);
266
        l2 = Util.findSubElements(el2);
267
        l2 = XMLUtil.findSubElements(el2);
267
        assertEquals(4, l2.size());
268
        assertEquals(4, l2.size());
268
        assertElementArray(l2, 
269
        assertElementArray(l2, 
269
            new String[]{"property", "folder", "format", "arity"}, 
270
            new String[]{"property", "folder", "format", "arity"}, 
270
            new String[]{"second-someProperty1", "second-someFolder1", "java-name", null});
271
            new String[]{"second-someProperty1", "second-someFolder1", "java-name", null});
271
        Element sepFilesEl = Util.findElement(l2.get(3), "separated-files", FreeformProjectType.NS_GENERAL);
272
        Element sepFilesEl = XMLUtil.findElement(l2.get(3), "separated-files", FreeformProjectType.NS_GENERAL);
272
        assertNotNull("have <separated-files>", sepFilesEl);
273
        assertNotNull("have <separated-files>", sepFilesEl);
273
        assertEquals("right separator", "someSeparator1", Util.findText(sepFilesEl));
274
        assertEquals("right separator", "someSeparator1", XMLUtil.findText(sepFilesEl));
274
        ProjectManager.getDefault().saveAllProjects();
275
        ProjectManager.getDefault().saveAllProjects();
275
            
276
            
276
        // test updating
277
        // test updating
Lines 289-302 Link Here
289
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
290
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
290
//        ProjectManager.getDefault().saveAllProjects();
291
//        ProjectManager.getDefault().saveAllProjects();
291
        el = Util.getPrimaryConfigurationData(helper);
292
        el = Util.getPrimaryConfigurationData(helper);
292
        el = Util.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
293
        el = XMLUtil.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
293
        assertNotNull("Target mapping were not saved correctly",  el);
294
        assertNotNull("Target mapping were not saved correctly",  el);
294
        subElements = Util.findSubElements(el);
295
        subElements = XMLUtil.findSubElements(el);
295
        assertEquals(1, subElements.size());
296
        assertEquals(1, subElements.size());
296
        // compare first target mapping
297
        // compare first target mapping
297
        el2 = subElements.get(0);
298
        el2 = subElements.get(0);
298
        assertElement(el2, "action", null, "name", "foo");
299
        assertElement(el2, "action", null, "name", "foo");
299
        l1 = Util.findSubElements(el2);
300
        l1 = XMLUtil.findSubElements(el2);
300
        assertEquals(5, l1.size());
301
        assertEquals(5, l1.size());
301
        assertElementArray(l1, 
302
        assertElementArray(l1, 
302
            new String[]{"script", "target", "target", "property", "property"}, 
303
            new String[]{"script", "target", "target", "property", "property"}, 
Lines 319-332 Link Here
319
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
320
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
320
//        ProjectManager.getDefault().saveAllProjects();
321
//        ProjectManager.getDefault().saveAllProjects();
321
        el = Util.getPrimaryConfigurationData(helper);
322
        el = Util.getPrimaryConfigurationData(helper);
322
        el = Util.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
323
        el = XMLUtil.findElement(el, "ide-actions", FreeformProjectType.NS_GENERAL);
323
        assertNotNull("Target mapping were not saved correctly",  el);
324
        assertNotNull("Target mapping were not saved correctly",  el);
324
        subElements = Util.findSubElements(el);
325
        subElements = XMLUtil.findSubElements(el);
325
        assertEquals(1, subElements.size());
326
        assertEquals(1, subElements.size());
326
        // compare first target mapping
327
        // compare first target mapping
327
        el2 = subElements.get(0);
328
        el2 = subElements.get(0);
328
        assertElement(el2, "action", null, "name", "foo");
329
        assertElement(el2, "action", null, "name", "foo");
329
        l1 = Util.findSubElements(el2);
330
        l1 = XMLUtil.findSubElements(el2);
330
        assertEquals(5, l1.size());
331
        assertEquals(5, l1.size());
331
        assertElementArray(l1, 
332
        assertElementArray(l1, 
332
            new String[]{"script", "target", "target", "property", "property"}, 
333
            new String[]{"script", "target", "target", "property", "property"}, 
Lines 361-371 Link Here
361
        FreeformProjectGenerator.putContextMenuAction(helper, mappings);
362
        FreeformProjectGenerator.putContextMenuAction(helper, mappings);
362
//        ProjectManager.getDefault().saveAllProjects();
363
//        ProjectManager.getDefault().saveAllProjects();
363
        Element el = Util.getPrimaryConfigurationData(helper);
364
        Element el = Util.getPrimaryConfigurationData(helper);
364
        el = Util.findElement(el, "view", FreeformProjectType.NS_GENERAL);
365
        el = XMLUtil.findElement(el, "view", FreeformProjectType.NS_GENERAL);
365
        assertNotNull("Target mapping were not saved correctly",  el);
366
        assertNotNull("Target mapping were not saved correctly",  el);
366
        el = Util.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
367
        el = XMLUtil.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
367
        assertNotNull("Target mapping were not saved correctly",  el);
368
        assertNotNull("Target mapping were not saved correctly",  el);
368
        List<Element> subElements = Util.findSubElements(el);
369
        List<Element> subElements = XMLUtil.findSubElements(el);
369
        assertEquals(2, subElements.size());
370
        assertEquals(2, subElements.size());
370
        assertElementArray(subElements, 
371
        assertElementArray(subElements, 
371
            new String[]{"ide-action", "ide-action"}, 
372
            new String[]{"ide-action", "ide-action"}, 
Lines 386-396 Link Here
386
        FreeformProjectGenerator.putContextMenuAction(helper, mappings);
387
        FreeformProjectGenerator.putContextMenuAction(helper, mappings);
387
//        ProjectManager.getDefault().saveAllProjects();
388
//        ProjectManager.getDefault().saveAllProjects();
388
        el = Util.getPrimaryConfigurationData(helper);
389
        el = Util.getPrimaryConfigurationData(helper);
389
        el = Util.findElement(el, "view", FreeformProjectType.NS_GENERAL);
390
        el = XMLUtil.findElement(el, "view", FreeformProjectType.NS_GENERAL);
390
        assertNotNull("Target mapping were not saved correctly",  el);
391
        assertNotNull("Target mapping were not saved correctly",  el);
391
        el = Util.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
392
        el = XMLUtil.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
392
        assertNotNull("Target mapping were not saved correctly",  el);
393
        assertNotNull("Target mapping were not saved correctly",  el);
393
        subElements = Util.findSubElements(el);
394
        subElements = XMLUtil.findSubElements(el);
394
        assertEquals(4, subElements.size());
395
        assertEquals(4, subElements.size());
395
        assertElementArray(subElements, 
396
        assertElementArray(subElements, 
396
            new String[]{"ide-action", "ide-action", "ide-action", "ide-action"},
397
            new String[]{"ide-action", "ide-action", "ide-action", "ide-action"},
Lines 437-454 Link Here
437
        FreeformProjectGenerator.putCustomContextMenuActions(helper, customActions);
438
        FreeformProjectGenerator.putCustomContextMenuActions(helper, customActions);
438
//        ProjectManager.getDefault().saveAllProjects();
439
//        ProjectManager.getDefault().saveAllProjects();
439
        Element el = Util.getPrimaryConfigurationData(helper);
440
        Element el = Util.getPrimaryConfigurationData(helper);
440
        el = Util.findElement(el, "view", FreeformProjectType.NS_GENERAL);
441
        el = XMLUtil.findElement(el, "view", FreeformProjectType.NS_GENERAL);
441
        assertNotNull("Target mapping were not saved correctly",  el);
442
        assertNotNull("Target mapping were not saved correctly",  el);
442
        el = Util.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
443
        el = XMLUtil.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
443
        assertNotNull("Target mapping were not saved correctly",  el);
444
        assertNotNull("Target mapping were not saved correctly",  el);
444
        List<Element> subElements = Util.findSubElements(el);
445
        List<Element> subElements = XMLUtil.findSubElements(el);
445
        assertEquals(2, subElements.size());
446
        assertEquals(2, subElements.size());
446
        assertElementArray(subElements, 
447
        assertElementArray(subElements, 
447
            new String[]{"action", "action"}, 
448
            new String[]{"action", "action"}, 
448
            new String[]{null, null});
449
            new String[]{null, null});
449
        // compare first custom action
450
        // compare first custom action
450
        Element el2 = subElements.get(0);
451
        Element el2 = subElements.get(0);
451
        List<Element> l1 = Util.findSubElements(el2);
452
        List<Element> l1 = XMLUtil.findSubElements(el2);
452
        assertEquals(6, l1.size());
453
        assertEquals(6, l1.size());
453
        assertElementArray(l1, 
454
        assertElementArray(l1, 
454
            new String[]{"script", "label", "target", "target", "property", "property"}, 
455
            new String[]{"script", "label", "target", "target", "property", "property"}, 
Lines 459-465 Link Here
459
        assertElement(el2, "property", "v2", "name", "k2");
460
        assertElement(el2, "property", "v2", "name", "k2");
460
        // compare second custom action
461
        // compare second custom action
461
        el2 = subElements.get(1);
462
        el2 = subElements.get(1);
462
        l1 = Util.findSubElements(el2);
463
        l1 = XMLUtil.findSubElements(el2);
463
        assertEquals(6, l1.size());
464
        assertEquals(6, l1.size());
464
        assertElementArray(l1, 
465
        assertElementArray(l1, 
465
            new String[]{"script", "label", "target", "target", "property", "property"}, 
466
            new String[]{"script", "label", "target", "target", "property", "property"}, 
Lines 482-506 Link Here
482
        FreeformProjectGenerator.putCustomContextMenuActions(helper, customActions);
483
        FreeformProjectGenerator.putCustomContextMenuActions(helper, customActions);
483
//        ProjectManager.getDefault().saveAllProjects();
484
//        ProjectManager.getDefault().saveAllProjects();
484
        el = Util.getPrimaryConfigurationData(helper);
485
        el = Util.getPrimaryConfigurationData(helper);
485
        el = Util.findElement(el, "view", FreeformProjectType.NS_GENERAL);
486
        el = XMLUtil.findElement(el, "view", FreeformProjectType.NS_GENERAL);
486
        assertNotNull("Target mapping were not saved correctly",  el);
487
        assertNotNull("Target mapping were not saved correctly",  el);
487
        el = Util.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
488
        el = XMLUtil.findElement(el, "context-menu", FreeformProjectType.NS_GENERAL);
488
        assertNotNull("Target mapping were not saved correctly",  el);
489
        assertNotNull("Target mapping were not saved correctly",  el);
489
        subElements = Util.findSubElements(el);
490
        subElements = XMLUtil.findSubElements(el);
490
        assertEquals(2, subElements.size());
491
        assertEquals(2, subElements.size());
491
        assertElementArray(subElements, 
492
        assertElementArray(subElements, 
492
            new String[]{"action", "action"}, 
493
            new String[]{"action", "action"}, 
493
            new String[]{null, null});
494
            new String[]{null, null});
494
        // compare first custom action
495
        // compare first custom action
495
        el2 = subElements.get(0);
496
        el2 = subElements.get(0);
496
        l1 = Util.findSubElements(el2);
497
        l1 = XMLUtil.findSubElements(el2);
497
        assertEquals(1, l1.size());
498
        assertEquals(1, l1.size());
498
        assertElementArray(l1, 
499
        assertElementArray(l1, 
499
            new String[]{"label"}, 
500
            new String[]{"label"}, 
500
            new String[]{"fooLabel"});
501
            new String[]{"fooLabel"});
501
        // compare second custom action
502
        // compare second custom action
502
        el2 = subElements.get(1);
503
        el2 = subElements.get(1);
503
        l1 = Util.findSubElements(el2);
504
        l1 = XMLUtil.findSubElements(el2);
504
        assertEquals(1, l1.size());
505
        assertEquals(1, l1.size());
505
        assertElementArray(l1, 
506
        assertElementArray(l1, 
506
            new String[]{"label"}, 
507
            new String[]{"label"}, 
Lines 518-524 Link Here
518
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
519
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
519
        assertEquals(message, expectedName, element.getLocalName());
520
        assertEquals(message, expectedName, element.getLocalName());
520
        if (expectedValue != null) {
521
        if (expectedValue != null) {
521
            assertEquals(message, expectedValue, Util.findText(element));
522
            assertEquals(message, expectedValue, XMLUtil.findText(element));
522
        }
523
        }
523
    }
524
    }
524
525
Lines 546-552 Link Here
546
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
547
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
547
        assertEquals(message, expectedName, element.getLocalName());
548
        assertEquals(message, expectedName, element.getLocalName());
548
        if (expectedValue != null) {
549
        if (expectedValue != null) {
549
            assertEquals(message, expectedValue, Util.findText(element));
550
            assertEquals(message, expectedValue, XMLUtil.findText(element));
550
        }
551
        }
551
        String val = element.getAttribute(expectedAttrName);
552
        String val = element.getAttribute(expectedAttrName);
552
        assertEquals(expectedAttrValue, val);
553
        assertEquals(expectedAttrValue, val);
(-)a/ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/FreeformSourcesTest.java (-4 / +5 lines)
Lines 58-63 Link Here
58
import org.netbeans.spi.project.support.ant.EditableProperties;
58
import org.netbeans.spi.project.support.ant.EditableProperties;
59
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.xml.XMLUtil;
61
import org.w3c.dom.Document;
62
import org.w3c.dom.Document;
62
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
63
import org.w3c.dom.NodeList;
64
import org.w3c.dom.NodeList;
Lines 110-121 Link Here
110
        TestCL l = new TestCL();
111
        TestCL l = new TestCL();
111
        s.addChangeListener(l);
112
        s.addChangeListener(l);
112
        Element data = extsrcroot.getPrimaryConfigurationData();
113
        Element data = extsrcroot.getPrimaryConfigurationData();
113
        Element folders = Util.findElement(data, "folders", FreeformProjectType.NS_GENERAL);
114
        Element folders = XMLUtil.findElement(data, "folders", FreeformProjectType.NS_GENERAL);
114
        assertNotNull("have <folders>", folders);
115
        assertNotNull("have <folders>", folders);
115
        List/*<Element>*/ sourceFolders = Util.findSubElements(folders);
116
        List<Element> sourceFolders = XMLUtil.findSubElements(folders);
116
        assertEquals("have 2 <source-folder>s", 2, sourceFolders.size());
117
        assertEquals("have 2 <source-folder>s", 2, sourceFolders.size());
117
        Element sourceFolder = (Element) sourceFolders.get(1);
118
        Element sourceFolder = (Element) sourceFolders.get(1);
118
        Element location = Util.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
119
        Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
119
        assertNotNull("have <location>", location);
120
        assertNotNull("have <location>", location);
120
        NodeList nl = location.getChildNodes();
121
        NodeList nl = location.getChildNodes();
121
        assertEquals("one child (text)", 1, nl.getLength());
122
        assertEquals("one child (text)", 1, nl.getLength());
Lines 146-152 Link Here
146
        FileUtil.createData(new File(d, "s/ignored/file"));
147
        FileUtil.createData(new File(d, "s/ignored/file"));
147
        Element data = Util.getPrimaryConfigurationData(helper);
148
        Element data = Util.getPrimaryConfigurationData(helper);
148
        Document doc = data.getOwnerDocument();
149
        Document doc = data.getOwnerDocument();
149
        Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), Util.findElement(data, "view", Util.NAMESPACE)).
150
        Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), XMLUtil.findElement(data, "view", Util.NAMESPACE)).
150
                appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
151
                appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
151
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
152
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
152
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode("stuff"));
153
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode("stuff"));
(-)a/ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/UnboundTargetAlertTest.java (-3 / +4 lines)
Lines 52-57 Link Here
52
import org.netbeans.modules.ant.freeform.FreeformProjectType;
52
import org.netbeans.modules.ant.freeform.FreeformProjectType;
53
import org.netbeans.modules.ant.freeform.TestBase;
53
import org.netbeans.modules.ant.freeform.TestBase;
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
55
import org.openide.xml.XMLUtil;
55
import org.w3c.dom.Element;
56
import org.w3c.dom.Element;
56
57
57
/**
58
/**
Lines 98-109 Link Here
98
        assertEquals(null, lastMapping.context);
99
        assertEquals(null, lastMapping.context);
99
        // Also check the context menu.
100
        // Also check the context menu.
100
        Element data = prj.getPrimaryConfigurationData();
101
        Element data = prj.getPrimaryConfigurationData();
101
        Element view = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL);
102
        Element view = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL);
102
        assertNotNull(view);
103
        assertNotNull(view);
103
        Element contextMenu = Util.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL);
104
        Element contextMenu = XMLUtil.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL);
104
        assertNotNull(contextMenu);
105
        assertNotNull(contextMenu);
105
        Set<String> actionNames = new TreeSet<String>();
106
        Set<String> actionNames = new TreeSet<String>();
106
        for (Element action : Util.findSubElements(contextMenu)) {
107
        for (Element action : XMLUtil.findSubElements(contextMenu)) {
107
            if (action.getLocalName().equals("ide-action")) {
108
            if (action.getLocalName().equals("ide-action")) {
108
                actionNames.add(action.getAttribute("name"));
109
                actionNames.add(action.getAttribute("name"));
109
            }
110
            }
(-)a/ant.freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java (-5 / +6 lines)
Lines 70-75 Link Here
70
import org.openide.nodes.NodeReorderEvent;
70
import org.openide.nodes.NodeReorderEvent;
71
import org.w3c.dom.Document;
71
import org.w3c.dom.Document;
72
import org.openide.util.Lookup;
72
import org.openide.util.Lookup;
73
import org.openide.xml.XMLUtil;
73
import org.w3c.dom.Element;
74
import org.w3c.dom.Element;
74
import org.w3c.dom.NodeList;
75
import org.w3c.dom.NodeList;
75
76
Lines 120-138 Link Here
120
        TestNL l = new TestNL();
121
        TestNL l = new TestNL();
121
        root.addNodeListener(l);
122
        root.addNodeListener(l);
122
        Element data = extsrcroot.getPrimaryConfigurationData();
123
        Element data = extsrcroot.getPrimaryConfigurationData();
123
        Element view = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL);
124
        Element view = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL);
124
        assertNotNull("have <view>", view);
125
        assertNotNull("have <view>", view);
125
        Element items = Util.findElement(view, "items", FreeformProjectType.NS_GENERAL);
126
        Element items = XMLUtil.findElement(view, "items", FreeformProjectType.NS_GENERAL);
126
        assertNotNull("have <items>", items);
127
        assertNotNull("have <items>", items);
127
        Element sourceFolder = Util.findElement(items, "source-folder", FreeformProjectType.NS_GENERAL);
128
        Element sourceFolder = XMLUtil.findElement(items, "source-folder", FreeformProjectType.NS_GENERAL);
128
        assertNotNull("have <source-folder>", sourceFolder);
129
        assertNotNull("have <source-folder>", sourceFolder);
129
        Element location = Util.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
130
        Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
130
        assertNotNull("have <location>", location);
131
        assertNotNull("have <location>", location);
131
        NodeList nl = location.getChildNodes();
132
        NodeList nl = location.getChildNodes();
132
        assertEquals("one child", 1, nl.getLength());
133
        assertEquals("one child", 1, nl.getLength());
133
        location.removeChild(nl.item(0));
134
        location.removeChild(nl.item(0));
134
        location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
135
        location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
135
        Element sourceFile =  Util.findElement(items, "source-file", FreeformProjectType.NS_GENERAL);
136
        Element sourceFile =  XMLUtil.findElement(items, "source-file", FreeformProjectType.NS_GENERAL);
136
        assertNotNull("have <source-file>", sourceFile);
137
        assertNotNull("have <source-file>", sourceFile);
137
        items.removeChild(sourceFile);
138
        items.removeChild(sourceFile);
138
        extsrcroot.putPrimaryConfigurationData(data);
139
        extsrcroot.putPrimaryConfigurationData(data);
(-)a/apisupport.project/nbproject/project.xml (-1 / +1 lines)
Lines 370-376 Link Here
370
                    <build-prerequisite/>
370
                    <build-prerequisite/>
371
                    <compile-dependency/>
371
                    <compile-dependency/>
372
                    <run-dependency>
372
                    <run-dependency>
373
                        <specification-version>8.0</specification-version>
373
                        <specification-version>8.4</specification-version>
374
                    </run-dependency>
374
                    </run-dependency>
375
                </dependency>
375
                </dependency>
376
                <dependency>
376
                <dependency>
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java (-5 / +6 lines)
Lines 87-92 Link Here
87
import org.openide.util.RequestProcessor;
87
import org.openide.util.RequestProcessor;
88
import org.openide.util.Utilities;
88
import org.openide.util.Utilities;
89
import org.openide.util.WeakListeners;
89
import org.openide.util.WeakListeners;
90
import org.openide.xml.XMLUtil;
90
import org.w3c.dom.Element;
91
import org.w3c.dom.Element;
91
92
92
/**
93
/**
Lines 603-620 Link Here
603
     */
604
     */
604
    private String computeModuleClasspath(ModuleList ml) {
605
    private String computeModuleClasspath(ModuleList ml) {
605
        Element data = project.getPrimaryConfigurationData();
606
        Element data = project.getPrimaryConfigurationData();
606
        Element moduleDependencies = Util.findElement(data,
607
        Element moduleDependencies = XMLUtil.findElement(data,
607
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
608
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
608
        assert moduleDependencies != null : "Malformed metadata in " + project;
609
        assert moduleDependencies != null : "Malformed metadata in " + project;
609
        StringBuffer cp = new StringBuffer();
610
        StringBuffer cp = new StringBuffer();
610
        for (Element dep : Util.findSubElements(moduleDependencies)) {
611
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
611
            if (Util.findElement(dep, "compile-dependency", // NOI18N
612
            if (XMLUtil.findElement(dep, "compile-dependency", // NOI18N
612
                    NbModuleProject.NAMESPACE_SHARED) == null) {
613
                    NbModuleProject.NAMESPACE_SHARED) == null) {
613
                continue;
614
                continue;
614
            }
615
            }
615
            Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N
616
            Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N
616
                NbModuleProject.NAMESPACE_SHARED);
617
                NbModuleProject.NAMESPACE_SHARED);
617
            String cnb = Util.findText(cnbEl);
618
            String cnb = XMLUtil.findText(cnbEl);
618
            ModuleEntry module = ml.getEntry(cnb);
619
            ModuleEntry module = ml.getEntry(cnb);
619
            if (module == null) {
620
            if (module == null) {
620
                Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory()));
621
                Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + FileUtil.getFileDisplayName(project.getProjectDirectory()));
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/NbModuleProject.java (-14 / +15 lines)
Lines 131-136 Link Here
131
import org.openide.util.Exceptions;
131
import org.openide.util.Exceptions;
132
import org.openide.util.lookup.AbstractLookup;
132
import org.openide.util.lookup.AbstractLookup;
133
import org.openide.util.lookup.InstanceContent;
133
import org.openide.util.lookup.InstanceContent;
134
import org.openide.xml.XMLUtil;
134
135
135
/**
136
/**
136
 * A NetBeans module project.
137
 * A NetBeans module project.
Lines 221-228 Link Here
221
                    .displayName(NbBundle.getMessage(NbModuleProject.class, "LBL_javahelp_packages")).add();
222
                    .displayName(NbBundle.getMessage(NbModuleProject.class, "LBL_javahelp_packages")).add();
222
        }
223
        }
223
        for (Map.Entry<FileObject,Element> entry : getExtraCompilationUnits().entrySet()) {
224
        for (Map.Entry<FileObject,Element> entry : getExtraCompilationUnits().entrySet()) {
224
            Element pkgrootEl = Util.findElement(entry.getValue(), "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N
225
            Element pkgrootEl = XMLUtil.findElement(entry.getValue(), "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N
225
            String pkgrootS = Util.findText(pkgrootEl);
226
            String pkgrootS = XMLUtil.findText(pkgrootEl);
226
            sourcesHelper.sourceRoot(pkgrootS).type(JavaProjectConstants.SOURCES_TYPE_JAVA)
227
            sourcesHelper.sourceRoot(pkgrootS).type(JavaProjectConstants.SOURCES_TYPE_JAVA)
227
                    .displayName(/* XXX should schema incl. display name? */entry.getKey().getNameExt()).add();
228
                    .displayName(/* XXX should schema incl. display name? */entry.getKey().getNameExt()).add();
228
        }
229
        }
Lines 340-346 Link Here
340
                AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration();
341
                AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration();
341
                Element data = ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true);
342
                Element data = ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true);
342
                if (data != null) {
343
                if (data != null) {
343
                    return Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED);
344
                    return XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED);
344
                } else {
345
                } else {
345
                    return helper.getPrimaryConfigurationData(true);
346
                    return helper.getPrimaryConfigurationData(true);
346
                }
347
                }
Lines 357-363 Link Here
357
            public Void run() {
358
            public Void run() {
358
                AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration();
359
                AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration();
359
                if (ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true) != null) {
360
                if (ac.getConfigurationFragment(NbModuleProject.NAME_SHARED, NbModuleProject.NAMESPACE_SHARED_2, true) != null) {
360
                    ac.putConfigurationFragment(Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED_2), true);
361
                    ac.putConfigurationFragment(XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED_2), true);
361
                } else {
362
                } else {
362
                    helper.putPrimaryConfigurationData(data, true);
363
                    helper.putPrimaryConfigurationData(data, true);
363
                }
364
                }
Lines 373-381 Link Here
373
374
374
    private NbModuleProvider.NbModuleType getModuleType() {
375
    private NbModuleProvider.NbModuleType getModuleType() {
375
        Element data = getPrimaryConfigurationData();
376
        Element data = getPrimaryConfigurationData();
376
        if (Util.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N
377
        if (XMLUtil.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N
377
            return NbModuleProvider.SUITE_COMPONENT;
378
            return NbModuleProvider.SUITE_COMPONENT;
378
        } else if (Util.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N
379
        } else if (XMLUtil.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null) { // NOI18N
379
            return NbModuleProvider.STANDALONE;
380
            return NbModuleProvider.STANDALONE;
380
        } else {
381
        } else {
381
            return NbModuleProvider.NETBEANS_ORG;
382
            return NbModuleProvider.NETBEANS_ORG;
Lines 471-479 Link Here
471
472
472
    public String getCodeNameBase() {
473
    public String getCodeNameBase() {
473
        Element config = getPrimaryConfigurationData();
474
        Element config = getPrimaryConfigurationData();
474
        Element cnb = Util.findElement(config, "code-name-base", NbModuleProject.NAMESPACE_SHARED); // NOI18N
475
        Element cnb = XMLUtil.findElement(config, "code-name-base", NbModuleProject.NAMESPACE_SHARED); // NOI18N
475
        if (cnb != null) {
476
        if (cnb != null) {
476
            return Util.findText(cnb);
477
            return XMLUtil.findText(cnb);
477
        } else {
478
        } else {
478
            return null;
479
            return null;
479
        }
480
        }
Lines 623-634 Link Here
623
            return true;
624
            return true;
624
        }
625
        }
625
        Element config = getPrimaryConfigurationData();
626
        Element config = getPrimaryConfigurationData();
626
        Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
627
        Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
627
        if (pubPkgs == null) {
628
        if (pubPkgs == null) {
628
            // Try <friend-packages> too.
629
            // Try <friend-packages> too.
629
            pubPkgs = Util.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
630
            pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
630
        }
631
        }
631
        return pubPkgs != null && !Util.findSubElements(pubPkgs).isEmpty();
632
        return pubPkgs != null && !XMLUtil.findSubElements(pubPkgs).isEmpty();
632
    }
633
    }
633
    
634
    
634
    public List<String> supportedTestTypes() {
635
    public List<String> supportedTestTypes() {
Lines 655-664 Link Here
655
    public Map<FileObject,Element> getExtraCompilationUnits() {
656
    public Map<FileObject,Element> getExtraCompilationUnits() {
656
        if (extraCompilationUnits == null) {
657
        if (extraCompilationUnits == null) {
657
            extraCompilationUnits = new HashMap<FileObject,Element>();
658
            extraCompilationUnits = new HashMap<FileObject,Element>();
658
            for (Element ecu : Util.findSubElements(getPrimaryConfigurationData())) {
659
            for (Element ecu : XMLUtil.findSubElements(getPrimaryConfigurationData())) {
659
                if (ecu.getLocalName().equals("extra-compilation-unit")) { // NOI18N
660
                if (ecu.getLocalName().equals("extra-compilation-unit")) { // NOI18N
660
                    Element pkgrootEl = Util.findElement(ecu, "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N
661
                    Element pkgrootEl = XMLUtil.findElement(ecu, "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N
661
                    String pkgrootS = Util.findText(pkgrootEl);
662
                    String pkgrootS = XMLUtil.findText(pkgrootEl);
662
                    String pkgrootEval = evaluator().evaluate(pkgrootS);
663
                    String pkgrootEval = evaluator().evaluate(pkgrootS);
663
                    FileObject pkgroot = getHelper().resolveFileObject(pkgrootEval);
664
                    FileObject pkgroot = getHelper().resolveFileObject(pkgrootEval);
664
                    if (pkgroot == null) {
665
                    if (pkgroot == null) {
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java (-30 / +30 lines)
Lines 218-226 Link Here
218
        } else {
218
        } else {
219
            ml = ModuleList.getModuleList(prjDirF);
219
            ml = ModuleList.getModuleList(prjDirF);
220
        }
220
        }
221
        for (Element depEl : Util.findSubElements(moduleDependencies)) {
221
        for (Element depEl : XMLUtil.findSubElements(moduleDependencies)) {
222
            Element cnbEl = findElement(depEl, ProjectXMLManager.CODE_NAME_BASE);
222
            Element cnbEl = findElement(depEl, ProjectXMLManager.CODE_NAME_BASE);
223
            String _cnb = Util.findText(cnbEl);
223
            String _cnb = XMLUtil.findText(cnbEl);
224
            ModuleDependency depToAdd = getModuleDependency(_cnb, ml, depEl);
224
            ModuleDependency depToAdd = getModuleDependency(_cnb, ml, depEl);
225
            if (depToAdd == null) {
225
            if (depToAdd == null) {
226
                continue;
226
                continue;
Lines 255-267 Link Here
255
        Element relVerEl = findElement(runDepEl, ProjectXMLManager.RELEASE_VERSION);
255
        Element relVerEl = findElement(runDepEl, ProjectXMLManager.RELEASE_VERSION);
256
        String relVer = null;
256
        String relVer = null;
257
        if (relVerEl != null) {
257
        if (relVerEl != null) {
258
            relVer = Util.findText(relVerEl);
258
            relVer = XMLUtil.findText(relVerEl);
259
        }
259
        }
260
260
261
        Element specVerEl = findElement(runDepEl, ProjectXMLManager.SPECIFICATION_VERSION);
261
        Element specVerEl = findElement(runDepEl, ProjectXMLManager.SPECIFICATION_VERSION);
262
        String specVer = null;
262
        String specVer = null;
263
        if (specVerEl != null) {
263
        if (specVerEl != null) {
264
            specVer = Util.findText(specVerEl);
264
            specVer = XMLUtil.findText(specVerEl);
265
        }
265
        }
266
266
267
        Element compDepEl = findElement(depEl, ProjectXMLManager.COMPILE_DEPENDENCY);
267
        Element compDepEl = findElement(depEl, ProjectXMLManager.COMPILE_DEPENDENCY);
Lines 287-295 Link Here
287
        } else {
287
        } else {
288
            ml = ModuleList.getModuleList(prjDirF);
288
            ml = ModuleList.getModuleList(prjDirF);
289
        }
289
        }
290
        for (Element dep : Util.findSubElements(moduleDependencies)) {
290
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
291
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
291
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
292
            String depCnb = Util.findText(cnbEl);
292
            String depCnb = XMLUtil.findText(cnbEl);
293
            if (depCnb.equals(cnb)) {
293
            if (depCnb.equals(cnb)) {
294
                return getModuleDependency(cnb, ml, dep);
294
                return getModuleDependency(cnb, ml, dep);
295
            }
295
            }
Lines 301-309 Link Here
301
    public void removeDependency(String cnbToRemove) {
301
    public void removeDependency(String cnbToRemove) {
302
        Element _confData = getConfData();
302
        Element _confData = getConfData();
303
        Element moduleDependencies = findModuleDependencies(_confData);
303
        Element moduleDependencies = findModuleDependencies(_confData);
304
        for (Element dep : Util.findSubElements(moduleDependencies)) {
304
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
305
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
305
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
306
            String _cnb = Util.findText(cnbEl);
306
            String _cnb = XMLUtil.findText(cnbEl);
307
            if (cnbToRemove.equals(_cnb)) {
307
            if (cnbToRemove.equals(_cnb)) {
308
                moduleDependencies.removeChild(dep);
308
                moduleDependencies.removeChild(dep);
309
            }
309
            }
Lines 330-338 Link Here
330
    public void removeDependenciesByCNB(Collection<String> cnbsToDelete) {
330
    public void removeDependenciesByCNB(Collection<String> cnbsToDelete) {
331
        Element _confData = getConfData();
331
        Element _confData = getConfData();
332
        Element moduleDependencies = findModuleDependencies(_confData);
332
        Element moduleDependencies = findModuleDependencies(_confData);
333
        for (Element dep : Util.findSubElements(moduleDependencies)) {
333
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
334
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
334
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
335
            String _cnb = Util.findText(cnbEl);
335
            String _cnb = XMLUtil.findText(cnbEl);
336
            if (cnbsToDelete.remove(_cnb)) {
336
            if (cnbsToDelete.remove(_cnb)) {
337
                moduleDependencies.removeChild(dep);
337
                moduleDependencies.removeChild(dep);
338
            }
338
            }
Lines 350-360 Link Here
350
    public void editDependency(ModuleDependency origDep, ModuleDependency newDep) {
350
    public void editDependency(ModuleDependency origDep, ModuleDependency newDep) {
351
        Element _confData = getConfData();
351
        Element _confData = getConfData();
352
        Element moduleDependencies = findModuleDependencies(_confData);
352
        Element moduleDependencies = findModuleDependencies(_confData);
353
        List<Element> currentDeps = Util.findSubElements(moduleDependencies);
353
        List<Element> currentDeps = XMLUtil.findSubElements(moduleDependencies);
354
        for (Iterator<Element> it = currentDeps.iterator(); it.hasNext();) {
354
        for (Iterator<Element> it = currentDeps.iterator(); it.hasNext();) {
355
            Element dep = it.next();
355
            Element dep = it.next();
356
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
356
            Element cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
357
            String _cnb = Util.findText(cnbEl);
357
            String _cnb = XMLUtil.findText(cnbEl);
358
            if (_cnb.equals(origDep.getModuleEntry().getCodeNameBase())) {
358
            if (_cnb.equals(origDep.getModuleEntry().getCodeNameBase())) {
359
                moduleDependencies.removeChild(dep);
359
                moduleDependencies.removeChild(dep);
360
                Element nextDep = it.hasNext() ? it.next() : null;
360
                Element nextDep = it.hasNext() ? it.next() : null;
Lines 474-494 Link Here
474
        Element _confData = getConfData();
474
        Element _confData = getConfData();
475
        Element testModuleDependenciesEl = findTestDependenciesElement(_confData);
475
        Element testModuleDependenciesEl = findTestDependenciesElement(_confData);
476
        Element testTypeRemoveEl = null;
476
        Element testTypeRemoveEl = null;
477
        for (Element type : Util.findSubElements(testModuleDependenciesEl)) {
477
        for (Element type : XMLUtil.findSubElements(testModuleDependenciesEl)) {
478
            Element nameEl = findElement(type, TEST_TYPE_NAME);
478
            Element nameEl = findElement(type, TEST_TYPE_NAME);
479
            String nameOfType = Util.findText(nameEl);
479
            String nameOfType = XMLUtil.findText(nameEl);
480
            if (testType.equals(nameOfType)) {
480
            if (testType.equals(nameOfType)) {
481
                testTypeRemoveEl = type;
481
                testTypeRemoveEl = type;
482
            }
482
            }
483
        }
483
        }
484
        //found such a test type
484
        //found such a test type
485
        if (testTypeRemoveEl != null) {
485
        if (testTypeRemoveEl != null) {
486
            for (Element el : Util.findSubElements(testTypeRemoveEl)) {
486
            for (Element el : XMLUtil.findSubElements(testTypeRemoveEl)) {
487
                Element cnbEl = findElement(el, TEST_DEPENDENCY_CNB);
487
                Element cnbEl = findElement(el, TEST_DEPENDENCY_CNB);
488
                if (cnbEl == null) {
488
                if (cnbEl == null) {
489
                    continue;   //name node, continue
489
                    continue;   //name node, continue
490
                }
490
                }
491
                String _cnb = Util.findText(cnbEl);
491
                String _cnb = XMLUtil.findText(cnbEl);
492
                if (cnbToRemove.equals(_cnb)) {
492
                if (cnbToRemove.equals(_cnb)) {
493
                    // found test dependency with desired CNB
493
                    // found test dependency with desired CNB
494
                    testTypeRemoveEl.removeChild(el);
494
                    testTypeRemoveEl.removeChild(el);
Lines 542-548 Link Here
542
                }
542
                }
543
                Element testTypeEl = null;
543
                Element testTypeEl = null;
544
                //iterate through test types to determine if testType exist
544
                //iterate through test types to determine if testType exist
545
                for (Element tt : Util.findSubElements(testModuleDependenciesEl)) {
545
                for (Element tt : XMLUtil.findSubElements(testModuleDependenciesEl)) {
546
                    Node nameNode = findElement(tt, "name"); // NOI18N
546
                    Node nameNode = findElement(tt, "name"); // NOI18N
547
                    assert nameNode != null : "should be some child with name";
547
                    assert nameNode != null : "should be some child with name";
548
                    //Node nameNode = tt.getFirstChild();
548
                    //Node nameNode = tt.getFirstChild();
Lines 638-661 Link Here
638
        Map<String, Set<TestModuleDependency>> testDeps = new HashMap<String, Set<TestModuleDependency>>();
638
        Map<String, Set<TestModuleDependency>> testDeps = new HashMap<String, Set<TestModuleDependency>>();
639
639
640
        if (testDepsEl != null) {
640
        if (testDepsEl != null) {
641
            for (Element typeEl : Util.findSubElements(testDepsEl)) {
641
            for (Element typeEl : XMLUtil.findSubElements(testDepsEl)) {
642
                Element testTypeEl = findElement(typeEl, TEST_TYPE_NAME);
642
                Element testTypeEl = findElement(typeEl, TEST_TYPE_NAME);
643
                String testType = null;
643
                String testType = null;
644
                if (testTypeEl != null) {
644
                if (testTypeEl != null) {
645
                    testType = Util.findText(testTypeEl);
645
                    testType = XMLUtil.findText(testTypeEl);
646
                }
646
                }
647
                if (testType == null) {
647
                if (testType == null) {
648
                    testType = TestModuleDependency.UNIT; // default variant
648
                    testType = TestModuleDependency.UNIT; // default variant
649
                }
649
                }
650
                Set<TestModuleDependency> directTestDeps = new TreeSet<TestModuleDependency>();
650
                Set<TestModuleDependency> directTestDeps = new TreeSet<TestModuleDependency>();
651
                for (Element depEl : Util.findSubElements(typeEl)) {
651
                for (Element depEl : XMLUtil.findSubElements(typeEl)) {
652
                    if (depEl.getTagName().equals(TEST_DEPENDENCY)) {
652
                    if (depEl.getTagName().equals(TEST_DEPENDENCY)) {
653
                        // parse test dep
653
                        // parse test dep
654
                        Element cnbEl = findElement(depEl, TEST_DEPENDENCY_CNB);
654
                        Element cnbEl = findElement(depEl, TEST_DEPENDENCY_CNB);
655
                        boolean test = findElement(depEl, TEST_DEPENDENCY_TEST) != null;
655
                        boolean test = findElement(depEl, TEST_DEPENDENCY_TEST) != null;
656
                        String _cnb = null;
656
                        String _cnb = null;
657
                        if (cnbEl != null) {
657
                        if (cnbEl != null) {
658
                            _cnb = Util.findText(cnbEl);
658
                            _cnb = XMLUtil.findText(cnbEl);
659
                        }
659
                        }
660
                        boolean recursive = findElement(depEl, TEST_DEPENDENCY_RECURSIVE) != null;
660
                        boolean recursive = findElement(depEl, TEST_DEPENDENCY_RECURSIVE) != null;
661
                        boolean compile = findElement(depEl, TEST_DEPENDENCY_COMPILE) != null;
661
                        boolean compile = findElement(depEl, TEST_DEPENDENCY_COMPILE) != null;
Lines 806-817 Link Here
806
            return Collections.unmodifiableMap(cpExtensions);
806
            return Collections.unmodifiableMap(cpExtensions);
807
        }
807
        }
808
        Map<String, String> cps = new HashMap<String, String>();
808
        Map<String, String> cps = new HashMap<String, String>();
809
        for (Element cpExtEl : Util.findSubElements(getConfData())) {
809
        for (Element cpExtEl : XMLUtil.findSubElements(getConfData())) {
810
            if (CLASS_PATH_EXTENSION.equals(cpExtEl.getTagName())) {
810
            if (CLASS_PATH_EXTENSION.equals(cpExtEl.getTagName())) {
811
                Element binOrigEl = findElement(cpExtEl, BINARY_ORIGIN);
811
                Element binOrigEl = findElement(cpExtEl, BINARY_ORIGIN);
812
                Element runtimePathEl = findElement(cpExtEl, CLASS_PATH_RUNTIME_PATH);
812
                Element runtimePathEl = findElement(cpExtEl, CLASS_PATH_RUNTIME_PATH);
813
                if (binOrigEl != null && runtimePathEl != null) {
813
                if (binOrigEl != null && runtimePathEl != null) {
814
                    cps.put(Util.findText(runtimePathEl), Util.findText(binOrigEl));
814
                    cps.put(XMLUtil.findText(runtimePathEl), XMLUtil.findText(binOrigEl));
815
                }
815
                }
816
            }
816
            }
817
        }
817
        }
Lines 822-828 Link Here
822
    public String getCodeNameBase() {
822
    public String getCodeNameBase() {
823
        if (cnb == null) {
823
        if (cnb == null) {
824
            Element cnbEl = findElement(getConfData(), ProjectXMLManager.CODE_NAME_BASE);
824
            Element cnbEl = findElement(getConfData(), ProjectXMLManager.CODE_NAME_BASE);
825
            cnb = Util.findText(cnbEl);
825
            cnb = XMLUtil.findText(cnbEl);
826
        }
826
        }
827
        return cnb;
827
        return cnb;
828
    }
828
    }
Lines 875-881 Link Here
875
    }
875
    }
876
876
877
    private static Element findElement(Element parentEl, String elementName) {
877
    private static Element findElement(Element parentEl, String elementName) {
878
        return Util.findElement(parentEl, elementName, NbModuleProject.NAMESPACE_SHARED);
878
        return XMLUtil.findElement(parentEl, elementName, NbModuleProject.NAMESPACE_SHARED);
879
    }
879
    }
880
880
881
    /** Package-private for unit tests only. */
881
    /** Package-private for unit tests only. */
Lines 922-932 Link Here
922
     */
922
     */
923
    private static Set<ManifestManager.PackageExport> findAllPackages(Element parent) {
923
    private static Set<ManifestManager.PackageExport> findAllPackages(Element parent) {
924
        Set<ManifestManager.PackageExport> packages = new HashSet<ManifestManager.PackageExport>();
924
        Set<ManifestManager.PackageExport> packages = new HashSet<ManifestManager.PackageExport>();
925
        for (Element pkgEl : Util.findSubElements(parent)) {
925
        for (Element pkgEl : XMLUtil.findSubElements(parent)) {
926
            if (PACKAGE.equals(pkgEl.getTagName())) {
926
            if (PACKAGE.equals(pkgEl.getTagName())) {
927
                packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), false));
927
                packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), false));
928
            } else if (SUBPACKAGES.equals(pkgEl.getTagName())) {
928
            } else if (SUBPACKAGES.equals(pkgEl.getTagName())) {
929
                packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), true));
929
                packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), true));
930
            }
930
            }
931
        }
931
        }
932
        return packages;
932
        return packages;
Lines 958-966 Link Here
958
        Element friendsEl = findFriendsElement(confData);
958
        Element friendsEl = findFriendsElement(confData);
959
        if (friendsEl != null) {
959
        if (friendsEl != null) {
960
            Set<String> friends = new TreeSet<String>();
960
            Set<String> friends = new TreeSet<String>();
961
            for (Element friendEl : Util.findSubElements(friendsEl)) {
961
            for (Element friendEl : XMLUtil.findSubElements(friendsEl)) {
962
                if (FRIEND.equals(friendEl.getTagName())) {
962
                if (FRIEND.equals(friendEl.getTagName())) {
963
                    friends.add(Util.findText(friendEl));
963
                    friends.add(XMLUtil.findText(friendEl));
964
                }
964
                }
965
            }
965
            }
966
            return friends.toArray(new String[friends.size()]);
966
            return friends.toArray(new String[friends.size()]);
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java (-98 / +1 lines)
Lines 125-230 Link Here
125
    private static final String SFS_VALID_PATH_RE = "(\\p{Alnum}|\\/|_)+"; // NOI18N
125
    private static final String SFS_VALID_PATH_RE = "(\\p{Alnum}|\\/|_)+"; // NOI18N
126
    
126
    
127
    // COPIED FROM org.netbeans.modules.project.ant:
127
    // COPIED FROM org.netbeans.modules.project.ant:
128
    // (except for namespace == null support in findElement)
128
    // (**EXCEPT** except for namespace == null support in findElement)
129
    // (and support for comments in findSubElements)
129
    // (and support for comments in findSubElements)
130
    
130
    
131
    /**
132
     * Search for an XML element in the direct children of a parent.
133
     * DOM provides a similar method but it does a recursive search
134
     * which we do not want. It also gives a node list and we want
135
     * only one result.
136
     * @param parent a parent element
137
     * @param name the intended local name
138
     * @param namespace the intended namespace (or null)
139
     * @return the first child element with that name, or null if none
140
     */
141
    public static Element findElement(Element parent, String name, String namespace) {
142
        NodeList l = parent.getChildNodes();
143
        for (int i = 0; i < l.getLength(); i++) {
144
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
145
                Element el = (Element)l.item(i);
146
                if ((namespace == null && name.equals(el.getTagName())) ||
147
                        (namespace != null && name.equals(el.getLocalName()) &&
148
                        namespace.equals(el.getNamespaceURI()))) {
149
                    return el;
150
                }
151
            }
152
        }
153
        return null;
154
    }
155
    
156
    /**
157
     * Extract nested text from an element.
158
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
159
     * @param parent a parent element
160
     * @return the nested text, or null if none was found
161
     */
162
    public static String findText(Element parent) {
163
        NodeList l = parent.getChildNodes();
164
        for (int i = 0; i < l.getLength(); i++) {
165
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
166
                Text text = (Text)l.item(i);
167
                return text.getNodeValue();
168
            }
169
        }
170
        return null;
171
    }
172
    
173
    /**
174
     * Find all direct child elements of an element.
175
     * More useful than {@link Element#getElementsByTagNameNS} because it does
176
     * not recurse into recursive child elements.
177
     * Children which are all-whitespace text nodes or comments are ignored; others cause
178
     * an exception to be thrown.
179
     * @param parent a parent element in a DOM tree
180
     * @return a list of direct child elements (may be empty)
181
     * @throws IllegalArgumentException if there are non-element children besides whitespace
182
     */
183
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
184
        NodeList l = parent.getChildNodes();
185
        List<Element> elements = new ArrayList<Element>(l.getLength());
186
        for (int i = 0; i < l.getLength(); i++) {
187
            Node n = l.item(i);
188
            if (n.getNodeType() == Node.ELEMENT_NODE) {
189
                elements.add((Element)n);
190
            } else if (n.getNodeType() == Node.TEXT_NODE) {
191
                String text = ((Text)n).getNodeValue();
192
                if (text.trim().length() > 0) {
193
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
194
                }
195
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
196
                // OK, ignore
197
            } else {
198
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
199
            }
200
        }
201
        return elements;
202
    }
203
204
    /**
205
     * Convert an XML fragment from one namespace to another.
206
     */
207
    public static Element translateXML(Element from, String namespace) {
208
        Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
209
        NodeList nl = from.getChildNodes();
210
        int length = nl.getLength();
211
        for (int i = 0; i < length; i++) {
212
            Node node = nl.item(i);
213
            Node newNode;
214
            if (node.getNodeType() == Node.ELEMENT_NODE) {
215
                newNode = translateXML((Element) node, namespace);
216
            } else {
217
                newNode = node.cloneNode(true);
218
            }
219
            to.appendChild(newNode);
220
        }
221
        NamedNodeMap m = from.getAttributes();
222
        for (int i = 0; i < m.getLength(); i++) {
223
            Node attr = m.item(i);
224
            to.setAttribute(attr.getNodeName(), attr.getNodeValue());
225
        }
226
        return to;
227
    }
228
131
229
    /**
132
    /**
230
     * Pass to {@link XPath#setNamespaceContext} to bind {@code nbm:} to the /3 namespace.
133
     * Pass to {@link XPath#setNamespaceContext} to bind {@code nbm:} to the /3 namespace.
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/AccessibilityQueryImpl.java (-4 / +5 lines)
Lines 48-53 Link Here
48
import org.openide.ErrorManager;
48
import org.openide.ErrorManager;
49
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileUtil;
50
import org.openide.filesystems.FileUtil;
51
import org.openide.xml.XMLUtil;
51
import org.w3c.dom.Element;
52
import org.w3c.dom.Element;
52
53
53
/**
54
/**
Lines 69-85 Link Here
69
            if (path != null) {
70
            if (path != null) {
70
                String name = path.replace('/', '.');
71
                String name = path.replace('/', '.');
71
                Element config = project.getPrimaryConfigurationData();
72
                Element config = project.getPrimaryConfigurationData();
72
                Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
73
                Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
73
                if (pubPkgs == null) {
74
                if (pubPkgs == null) {
74
                    // Try <friend-packages> too.
75
                    // Try <friend-packages> too.
75
                    pubPkgs = Util.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
76
                    pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
76
                }
77
                }
77
                if (pubPkgs != null) {
78
                if (pubPkgs != null) {
78
                    Iterator it = Util.findSubElements(pubPkgs).iterator();
79
                    Iterator it = XMLUtil.findSubElements(pubPkgs).iterator();
79
                    while (it.hasNext()) {
80
                    while (it.hasNext()) {
80
                        Element pubPkg = (Element) it.next();
81
                        Element pubPkg = (Element) it.next();
81
                        boolean sub = "subpackages".equals(pubPkg.getLocalName()); // NOI18N
82
                        boolean sub = "subpackages".equals(pubPkg.getLocalName()); // NOI18N
82
                        String pubPkgS = Util.findText(pubPkg);
83
                        String pubPkgS = XMLUtil.findText(pubPkg);
83
                        if (name.equals(pubPkgS) || (sub && name.startsWith(pubPkgS + '.'))) {
84
                        if (name.equals(pubPkgS) || (sub && name.startsWith(pubPkgS + '.'))) {
84
                            return true;
85
                            return true;
85
                        }
86
                        }
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/ClassPathProviderImpl.java (-7 / +7 lines)
Lines 63-69 Link Here
63
import org.netbeans.spi.java.classpath.ClassPathProvider;
63
import org.netbeans.spi.java.classpath.ClassPathProvider;
64
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
64
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
65
import org.netbeans.modules.apisupport.project.NbModuleProject;
65
import org.netbeans.modules.apisupport.project.NbModuleProject;
66
import org.netbeans.modules.apisupport.project.Util;
67
import org.netbeans.spi.java.classpath.PathResourceImplementation;
66
import org.netbeans.spi.java.classpath.PathResourceImplementation;
68
import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
67
import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
69
import org.netbeans.spi.project.support.ant.AntProjectEvent;
68
import org.netbeans.spi.project.support.ant.AntProjectEvent;
Lines 74-79 Link Here
74
import org.openide.filesystems.FileStateInvalidException;
73
import org.openide.filesystems.FileStateInvalidException;
75
import org.openide.filesystems.FileUtil;
74
import org.openide.filesystems.FileUtil;
76
import org.openide.util.WeakListeners;
75
import org.openide.util.WeakListeners;
76
import org.openide.xml.XMLUtil;
77
import org.w3c.dom.Element;
77
import org.w3c.dom.Element;
78
78
79
public final class ClassPathProviderImpl implements ClassPathProvider {
79
public final class ClassPathProviderImpl implements ClassPathProvider {
Lines 296-304 Link Here
296
        for (Map.Entry<FileObject,Element> entry : project.getExtraCompilationUnits().entrySet()) {
296
        for (Map.Entry<FileObject,Element> entry : project.getExtraCompilationUnits().entrySet()) {
297
            final FileObject pkgroot = entry.getKey();
297
            final FileObject pkgroot = entry.getKey();
298
            Element pkgrootEl = entry.getValue();
298
            Element pkgrootEl = entry.getValue();
299
            Element classpathEl = Util.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N
299
            Element classpathEl = XMLUtil.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N
300
            assert classpathEl != null : "no <classpath> in " + pkgrootEl;
300
            assert classpathEl != null : "no <classpath> in " + pkgrootEl;
301
            final String classpathS = Util.findText(classpathEl);
301
            final String classpathS = XMLUtil.findText(classpathEl);
302
            if (classpathS == null) {
302
            if (classpathS == null) {
303
                extraCompilationUnitsCompile.put(pkgroot, ClassPathSupport.createClassPath(new URL[0]));
303
                extraCompilationUnitsCompile.put(pkgroot, ClassPathSupport.createClassPath(new URL[0]));
304
                extraCompilationUnitsExecute.put(pkgroot, ClassPathSupport.createClassPath(new URL[0]));
304
                extraCompilationUnitsExecute.put(pkgroot, ClassPathSupport.createClassPath(new URL[0]));
Lines 333-341 Link Here
333
                    }
333
                    }
334
                    public void configurationXmlChanged(AntProjectEvent ev) {
334
                    public void configurationXmlChanged(AntProjectEvent ev) {
335
                        Element pkgrootEl = project.getExtraCompilationUnits().get(pkgroot);
335
                        Element pkgrootEl = project.getExtraCompilationUnits().get(pkgroot);
336
                        Element classpathEl = Util.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N
336
                        Element classpathEl = XMLUtil.findElement(pkgrootEl, "classpath", NbModuleProject.NAMESPACE_SHARED); // NOI18N
337
                        assert classpathEl != null : "no <classpath> in " + pkgrootEl;
337
                        assert classpathEl != null : "no <classpath> in " + pkgrootEl;
338
                        cpS = Util.findText(classpathEl);
338
                        cpS = XMLUtil.findText(classpathEl);
339
                        pcs.firePropertyChange(PROP_RESOURCES, null, null);
339
                        pcs.firePropertyChange(PROP_RESOURCES, null, null);
340
                    }
340
                    }
341
                    public void propertiesChanged(AntProjectEvent ev) {}
341
                    public void propertiesChanged(AntProjectEvent ev) {}
Lines 344-354 Link Here
344
                extraCompilationUnitsCompile.put(pkgroot, ClassPathFactory.createClassPath(ecuCompile));
344
                extraCompilationUnitsCompile.put(pkgroot, ClassPathFactory.createClassPath(ecuCompile));
345
                // Add <built-to> dirs and JARs for ClassPath.EXECUTE.
345
                // Add <built-to> dirs and JARs for ClassPath.EXECUTE.
346
                List<PathResourceImplementation> extraEntries = new ArrayList<PathResourceImplementation>();
346
                List<PathResourceImplementation> extraEntries = new ArrayList<PathResourceImplementation>();
347
                for (Element kid : Util.findSubElements(pkgrootEl)) {
347
                for (Element kid : XMLUtil.findSubElements(pkgrootEl)) {
348
                    if (!kid.getLocalName().equals("built-to")) { // NOI18N
348
                    if (!kid.getLocalName().equals("built-to")) { // NOI18N
349
                        continue;
349
                        continue;
350
                    }
350
                    }
351
                    String rawtext = Util.findText(kid);
351
                    String rawtext = XMLUtil.findText(kid);
352
                    assert rawtext != null : "Null content for <built-to> in " + project;
352
                    assert rawtext != null : "Null content for <built-to> in " + project;
353
                    String text = project.evaluator().evaluate(rawtext);
353
                    String text = project.evaluator().evaluate(rawtext);
354
                    if (text == null) {
354
                    if (text == null) {
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/GlobalSourceForBinaryImpl.java (-5 / +5 lines)
Lines 409-421 Link Here
409
                is.close();
409
                is.close();
410
            }
410
            }
411
            Element docel = doc.getDocumentElement();
411
            Element docel = doc.getDocumentElement();
412
            Element type = Util.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
412
            Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
413
            String cnb = null;
413
            String cnb = null;
414
            if (Util.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
414
            if (XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
415
                Element cfg = Util.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
415
                Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
416
                Element data = Util.findElement(cfg, "data", null); // NOI18N
416
                Element data = XMLUtil.findElement(cfg, "data", null); // NOI18N
417
                if (data != null) {
417
                if (data != null) {
418
                    cnb = Util.findText(Util.findElement(data, "code-name-base", null)); // NOI18N
418
                    cnb = XMLUtil.findText(XMLUtil.findElement(data, "code-name-base", null)); // NOI18N
419
                }
419
                }
420
            }
420
            }
421
            return cnb;
421
            return cnb;
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SourceForBinaryImpl.java (-3 / +3 lines)
Lines 50-60 Link Here
50
import javax.swing.event.ChangeListener;
50
import javax.swing.event.ChangeListener;
51
import org.netbeans.api.java.queries.SourceForBinaryQuery;
51
import org.netbeans.api.java.queries.SourceForBinaryQuery;
52
import org.netbeans.modules.apisupport.project.NbModuleProject;
52
import org.netbeans.modules.apisupport.project.NbModuleProject;
53
import org.netbeans.modules.apisupport.project.Util;
54
import org.netbeans.modules.apisupport.project.universe.TestEntry;
53
import org.netbeans.modules.apisupport.project.universe.TestEntry;
55
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
54
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
56
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.xml.XMLUtil;
58
import org.w3c.dom.Element;
58
import org.w3c.dom.Element;
59
59
60
/**
60
/**
Lines 136-146 Link Here
136
                if (res == null) {
136
                if (res == null) {
137
                // Check extra compilation units.
137
                // Check extra compilation units.
138
                ECUS: for (Map.Entry<FileObject,Element> entry : project.getExtraCompilationUnits().entrySet()) {
138
                ECUS: for (Map.Entry<FileObject,Element> entry : project.getExtraCompilationUnits().entrySet()) {
139
                    for (Element kid : Util.findSubElements(entry.getValue())) {
139
                    for (Element kid : XMLUtil.findSubElements(entry.getValue())) {
140
                        if (!kid.getLocalName().equals("built-to")) { // NOI18N
140
                        if (!kid.getLocalName().equals("built-to")) { // NOI18N
141
                            continue;
141
                            continue;
142
                        }
142
                        }
143
                        String rawtext = Util.findText(kid);
143
                        String rawtext = XMLUtil.findText(kid);
144
                        assert rawtext != null : "Null content for <built-to> in " + project;
144
                        assert rawtext != null : "Null content for <built-to> in " + project;
145
                        String text = project.evaluator().evaluate(rawtext);
145
                        String text = project.evaluator().evaluate(rawtext);
146
                        if (text == null) {
146
                        if (text == null) {
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/queries/SubprojectProviderImpl.java (-8 / +9 lines)
Lines 63-68 Link Here
63
import org.openide.ErrorManager;
63
import org.openide.ErrorManager;
64
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileObject;
65
import org.openide.filesystems.FileUtil;
65
import org.openide.filesystems.FileUtil;
66
import org.openide.xml.XMLUtil;
66
import org.w3c.dom.Element;
67
import org.w3c.dom.Element;
67
68
68
/**
69
/**
Lines 89-107 Link Here
89
            return Collections.emptySet();
90
            return Collections.emptySet();
90
        }
91
        }
91
        Element data = project.getPrimaryConfigurationData();
92
        Element data = project.getPrimaryConfigurationData();
92
        Element moduleDependencies = Util.findElement(data,
93
        Element moduleDependencies = XMLUtil.findElement(data,
93
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
94
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
94
        assert moduleDependencies != null : "Malformed metadata in " + project;
95
        assert moduleDependencies != null : "Malformed metadata in " + project;
95
        for (Element dep : Util.findSubElements(moduleDependencies)) {
96
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
96
            /* Probably better to open runtime deps too. TBD.
97
            /* Probably better to open runtime deps too. TBD.
97
            if (Util.findElement(dep, "build-prerequisite", // NOI18N
98
            if (XMLUtil.findElement(dep, "build-prerequisite", // NOI18N
98
                    NbModuleProject.NAMESPACE_SHARED) == null) {
99
                    NbModuleProject.NAMESPACE_SHARED) == null) {
99
                continue;
100
                continue;
100
            }
101
            }
101
             */
102
             */
102
            Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N
103
            Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N
103
                NbModuleProject.NAMESPACE_SHARED);
104
                NbModuleProject.NAMESPACE_SHARED);
104
            String cnb = Util.findText(cnbEl);
105
            String cnb = XMLUtil.findText(cnbEl);
105
            ModuleEntry module = ml.getEntry(cnb);
106
            ModuleEntry module = ml.getEntry(cnb);
106
            if (module == null) {
107
            if (module == null) {
107
                Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + project);
108
                Util.err.log(ErrorManager.WARNING, "Warning - could not find dependent module " + cnb + " for " + project);
Lines 129-143 Link Here
129
            }
130
            }
130
        }
131
        }
131
        // #63824: consider also artifacts found in ${cp.extra} and/or <class-path-extension>s
132
        // #63824: consider also artifacts found in ${cp.extra} and/or <class-path-extension>s
132
        for (Element cpext : Util.findSubElements(data)) {
133
        for (Element cpext : XMLUtil.findSubElements(data)) {
133
            if (!cpext.getTagName().equals("class-path-extension")) { // NOI18N
134
            if (!cpext.getTagName().equals("class-path-extension")) { // NOI18N
134
                continue;
135
                continue;
135
            }
136
            }
136
            Element binorig = Util.findElement(cpext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N
137
            Element binorig = XMLUtil.findElement(cpext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N
137
            if (binorig == null) {
138
            if (binorig == null) {
138
                continue;
139
                continue;
139
            }
140
            }
140
            String text = Util.findText(binorig);
141
            String text = XMLUtil.findText(binorig);
141
            String eval = project.evaluator().evaluate(text);
142
            String eval = project.evaluator().evaluate(text);
142
            if (eval == null) {
143
            if (eval == null) {
143
                continue;
144
                continue;
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/suite/SuiteProject.java (-2 / +3 lines)
Lines 89-94 Link Here
89
import org.openide.util.Lookup;
89
import org.openide.util.Lookup;
90
import org.openide.util.Mutex;
90
import org.openide.util.Mutex;
91
import org.openide.util.lookup.Lookups;
91
import org.openide.util.lookup.Lookups;
92
import org.openide.xml.XMLUtil;
92
import org.w3c.dom.Element;
93
import org.w3c.dom.Element;
93
94
94
/**
95
/**
Lines 242-249 Link Here
242
        }
243
        }
243
        
244
        
244
        private String getSimpleName() {
245
        private String getSimpleName() {
245
            Element nameEl = Util.findElement(helper.getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N
246
            Element nameEl = XMLUtil.findElement(helper.getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N
246
            String text = (nameEl != null) ? Util.findText(nameEl) : null;
247
            String text = (nameEl != null) ? XMLUtil.findText(nameEl) : null;
247
            return (text != null) ? text : "???"; // NOI18N
248
            return (text != null) ? text : "???"; // NOI18N
248
        }
249
        }
249
        
250
        
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/BasicBrandingModel.java (-3 / +3 lines)
Lines 56-62 Link Here
56
import org.netbeans.api.annotations.common.CheckForNull;
56
import org.netbeans.api.annotations.common.CheckForNull;
57
import org.netbeans.api.annotations.common.NullAllowed;
57
import org.netbeans.api.annotations.common.NullAllowed;
58
import org.netbeans.api.project.Project;
58
import org.netbeans.api.project.Project;
59
import org.netbeans.modules.apisupport.project.Util;
60
import org.netbeans.modules.apisupport.project.suite.BrandingSupport;
59
import org.netbeans.modules.apisupport.project.suite.BrandingSupport;
61
import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BrandedFile;
60
import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BrandedFile;
62
import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BundleKey;
61
import org.netbeans.modules.apisupport.project.suite.BrandingSupport.BundleKey;
Lines 67-72 Link Here
67
import org.openide.filesystems.FileUtil;
66
import org.openide.filesystems.FileUtil;
68
import org.openide.util.ChangeSupport;
67
import org.openide.util.ChangeSupport;
69
import org.openide.util.NbBundle;
68
import org.openide.util.NbBundle;
69
import org.openide.xml.XMLUtil;
70
import org.w3c.dom.Element;
70
import org.w3c.dom.Element;
71
71
72
/**
72
/**
Lines 406-413 Link Here
406
                res = getProjectDirectoryFile().getName();
406
                res = getProjectDirectoryFile().getName();
407
            return res;
407
            return res;
408
        }
408
        }
409
        Element nameEl = Util.findElement(suiteProps.getProject().getHelper().getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N
409
        Element nameEl = XMLUtil.findElement(suiteProps.getProject().getHelper().getPrimaryConfigurationData(true), "name", SuiteProjectType.NAMESPACE_SHARED); // NOI18N
410
        String text = (nameEl != null) ? Util.findText(nameEl) : null;
410
        String text = (nameEl != null) ? XMLUtil.findText(nameEl) : null;
411
        return (text != null) ? text : "???"; // NOI18N
411
        return (text != null) ? text : "???"; // NOI18N
412
    }
412
    }
413
413
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/customizer/SuiteCustomizerLibraries.java (-9 / +9 lines)
Lines 1467-1489 Link Here
1467
            dependencies = new HashSet<Dependency>();
1467
            dependencies = new HashSet<Dependency>();
1468
            // Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules.
1468
            // Cannot use ProjectXMLManager since we need to report also deps on nonexistent modules.
1469
            Element dataE = project.getPrimaryConfigurationData();
1469
            Element dataE = project.getPrimaryConfigurationData();
1470
            Element depsE = Util.findElement(dataE, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1470
            Element depsE = XMLUtil.findElement(dataE, "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1471
            assert depsE != null : "Malformed metadata in " + project;
1471
            assert depsE != null : "Malformed metadata in " + project;
1472
            for (Element dep : Util.findSubElements(depsE)) {
1472
            for (Element dep : XMLUtil.findSubElements(depsE)) {
1473
                Element run = Util.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1473
                Element run = XMLUtil.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1474
                if (run == null) {
1474
                if (run == null) {
1475
                    continue;
1475
                    continue;
1476
                }
1476
                }
1477
                String text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N
1477
                String text = XMLUtil.findText(XMLUtil.findElement(dep, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N
1478
                Element relverE = Util.findElement(run, "release-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1478
                Element relverE = XMLUtil.findElement(run, "release-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1479
                if (relverE != null) {
1479
                if (relverE != null) {
1480
                    text += '/' + Util.findText(relverE);
1480
                    text += '/' + XMLUtil.findText(relverE);
1481
                }
1481
                }
1482
                Element specverE = Util.findElement(run, "specification-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1482
                Element specverE = XMLUtil.findElement(run, "specification-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1483
                if (specverE != null) {
1483
                if (specverE != null) {
1484
                    text += " > " + Util.findText(specverE);
1484
                    text += " > " + XMLUtil.findText(specverE);
1485
                } else {
1485
                } else {
1486
                    Element implver = Util.findElement(run, "implementation-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1486
                    Element implver = XMLUtil.findElement(run, "implementation-version", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1487
                    if (implver != null) {
1487
                    if (implver != null) {
1488
                        // Will special-case '*' as an impl version to mean "match anything".
1488
                        // Will special-case '*' as an impl version to mean "match anything".
1489
                        text += " = *"; // NOI18N
1489
                        text += " = *"; // NOI18N
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/AbstractEntryWithSources.java (-5 / +6 lines)
Lines 54-59 Link Here
54
import org.openide.ErrorManager;
54
import org.openide.ErrorManager;
55
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.xml.XMLUtil;
57
import org.w3c.dom.Element;
58
import org.w3c.dom.Element;
58
59
59
abstract class AbstractEntryWithSources extends AbstractEntry {
60
abstract class AbstractEntryWithSources extends AbstractEntry {
Lines 136-152 Link Here
136
            return new String[0];
137
            return new String[0];
137
        }
138
        }
138
        Element data = project.getPrimaryConfigurationData();
139
        Element data = project.getPrimaryConfigurationData();
139
        Element moduleDependencies = Util.findElement(data,
140
        Element moduleDependencies = XMLUtil.findElement(data,
140
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
141
            "module-dependencies", NbModuleProject.NAMESPACE_SHARED); // NOI18N
141
        assert moduleDependencies != null : "Malformed metadata in " + project;
142
        assert moduleDependencies != null : "Malformed metadata in " + project;
142
        for (Element dep : Util.findSubElements(moduleDependencies)) {
143
        for (Element dep : XMLUtil.findSubElements(moduleDependencies)) {
143
            if (Util.findElement(dep, "run-dependency", // NOI18N
144
            if (XMLUtil.findElement(dep, "run-dependency", // NOI18N
144
                    NbModuleProject.NAMESPACE_SHARED) == null) {
145
                    NbModuleProject.NAMESPACE_SHARED) == null) {
145
                continue;
146
                continue;
146
            }
147
            }
147
            Element cnbEl = Util.findElement(dep, "code-name-base", // NOI18N
148
            Element cnbEl = XMLUtil.findElement(dep, "code-name-base", // NOI18N
148
                NbModuleProject.NAMESPACE_SHARED);
149
                NbModuleProject.NAMESPACE_SHARED);
149
            String cnb = Util.findText(cnbEl);
150
            String cnb = XMLUtil.findText(cnbEl);
150
            deps.add(cnb);
151
            deps.add(cnb);
151
        }
152
        }
152
        return deps.toArray(new String[deps.size()]);
153
        return deps.toArray(new String[deps.size()]);
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java (-16 / +16 lines)
Lines 201-208 Link Here
201
        if (data == null) {
201
        if (data == null) {
202
            throw new IOException("Not an NBM project in " + basedir); // NOI18N
202
            throw new IOException("Not an NBM project in " + basedir); // NOI18N
203
        }
203
        }
204
        boolean suiteComponent = Util.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N
204
        boolean suiteComponent = XMLUtil.findElement(data, "suite-component", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N
205
        boolean standalone = Util.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N
205
        boolean standalone = XMLUtil.findElement(data, "standalone", NbModuleProject.NAMESPACE_SHARED) != null; // NOI18N
206
        assert !(suiteComponent && standalone) : basedir;
206
        assert !(suiteComponent && standalone) : basedir;
207
        if (suiteComponent) {
207
        if (suiteComponent) {
208
            PropertyEvaluator eval = parseProperties(basedir, null, NbModuleType.SUITE_COMPONENT, "irrelevant"); // NOI18N
208
            PropertyEvaluator eval = parseProperties(basedir, null, NbModuleType.SUITE_COMPONENT, "irrelevant"); // NOI18N
Lines 528-550 Link Here
528
        }
528
        }
529
        assert root != null ^ type != NbModuleType.NETBEANS_ORG;
529
        assert root != null ^ type != NbModuleType.NETBEANS_ORG;
530
        assert path != null ^ type != NbModuleType.NETBEANS_ORG;
530
        assert path != null ^ type != NbModuleType.NETBEANS_ORG;
531
        String cnb = Util.findText(Util.findElement(data, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N
531
        String cnb = XMLUtil.findText(XMLUtil.findElement(data, "code-name-base", NbModuleProject.NAMESPACE_SHARED)); // NOI18N
532
        PropertyEvaluator eval = parseProperties(basedir, root, type, cnb);
532
        PropertyEvaluator eval = parseProperties(basedir, root, type, cnb);
533
        String module = eval.getProperty("module.jar"); // NOI18N
533
        String module = eval.getProperty("module.jar"); // NOI18N
534
        // Cf. ParseProjectXml.computeClasspath:
534
        // Cf. ParseProjectXml.computeClasspath:
535
        StringBuffer cpextra = new StringBuffer();
535
        StringBuffer cpextra = new StringBuffer();
536
        for (Element ext : Util.findSubElements(data)) {
536
        for (Element ext : XMLUtil.findSubElements(data)) {
537
            if (!ext.getLocalName().equals("class-path-extension")) { // NOI18N
537
            if (!ext.getLocalName().equals("class-path-extension")) { // NOI18N
538
                continue;
538
                continue;
539
            }
539
            }
540
            Element binaryOrigin = Util.findElement(ext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N
540
            Element binaryOrigin = XMLUtil.findElement(ext, "binary-origin", NbModuleProject.NAMESPACE_SHARED); // NOI18N
541
            String text;
541
            String text;
542
            if (binaryOrigin != null) {
542
            if (binaryOrigin != null) {
543
                text = Util.findText(binaryOrigin);
543
                text = XMLUtil.findText(binaryOrigin);
544
            } else {
544
            } else {
545
                Element runtimeRelativePath = Util.findElement(ext, "runtime-relative-path", NbModuleProject.NAMESPACE_SHARED); // NOI18N
545
                Element runtimeRelativePath = XMLUtil.findElement(ext, "runtime-relative-path", NbModuleProject.NAMESPACE_SHARED); // NOI18N
546
                assert runtimeRelativePath != null : "Malformed <class-path-extension> in " + basedir;
546
                assert runtimeRelativePath != null : "Malformed <class-path-extension> in " + basedir;
547
                String reltext = Util.findText(runtimeRelativePath);
547
                String reltext = XMLUtil.findText(runtimeRelativePath);
548
                // XXX assumes that module.jar is not overridden independently of module.jar.dir:
548
                // XXX assumes that module.jar is not overridden independently of module.jar.dir:
549
                text = "${cluster}/${module.jar.dir}/" + reltext; // NOI18N
549
                text = "${cluster}/${module.jar.dir}/" + reltext; // NOI18N
550
            }
550
            }
Lines 967-975 Link Here
967
            } catch (SAXException e) {
967
            } catch (SAXException e) {
968
                throw (IOException) new IOException(e.toString()).initCause(e);
968
                throw (IOException) new IOException(e.toString()).initCause(e);
969
            }
969
            }
970
            for (Element moduleVersion : Util.findSubElements(doc.getDocumentElement())) {
970
            for (Element moduleVersion : XMLUtil.findSubElements(doc.getDocumentElement())) {
971
                if (moduleVersion.getTagName().equals("module_version") && moduleVersion.getAttribute("last").equals("true")) { // NOI18N
971
                if (moduleVersion.getTagName().equals("module_version") && moduleVersion.getAttribute("last").equals("true")) { // NOI18N
972
                    for (Element fileEl : Util.findSubElements(moduleVersion)) {
972
                    for (Element fileEl : XMLUtil.findSubElements(moduleVersion)) {
973
                        if (fileEl.getTagName().equals("file")) { // NOI18N
973
                        if (fileEl.getTagName().equals("file")) { // NOI18N
974
                            String name = fileEl.getAttribute("name"); // NOI18N
974
                            String name = fileEl.getAttribute("name"); // NOI18N
975
                            File f = new File(cluster, name.replace('/', File.separatorChar));
975
                            File f = new File(cluster, name.replace('/', File.separatorChar));
Lines 1007-1024 Link Here
1007
            throw (IOException) new IOException(projectXml + ": " + e.toString()).initCause(e); // NOI18N
1007
            throw (IOException) new IOException(projectXml + ": " + e.toString()).initCause(e); // NOI18N
1008
        }
1008
        }
1009
        Element docel = doc.getDocumentElement();
1009
        Element docel = doc.getDocumentElement();
1010
        Element type = Util.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
1010
        Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
1011
        if (!Util.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
1011
        if (!XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
1012
            return null;
1012
            return null;
1013
        }
1013
        }
1014
        Element cfg = Util.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
1014
        Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
1015
        Element data = Util.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1015
        Element data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED); // NOI18N
1016
        if (data != null) {
1016
        if (data != null) {
1017
            return data;
1017
            return data;
1018
        } else {
1018
        } else {
1019
            data = Util.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED_2); // NOI18N
1019
            data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED_2); // NOI18N
1020
            if (data != null) {
1020
            if (data != null) {
1021
                return Util.translateXML(data, NbModuleProject.NAMESPACE_SHARED);
1021
                return XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED);
1022
            } else {
1022
            } else {
1023
                return null;
1023
                return null;
1024
            }
1024
            }
(-)a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java (-2 / +2 lines)
Lines 303-310 Link Here
303
                    Document doc = XMLUtil.parse(new InputSource(projectXML.toURI().toString()),
303
                    Document doc = XMLUtil.parse(new InputSource(projectXML.toURI().toString()),
304
                            false, true, null, null);
304
                            false, true, null, null);
305
                    Element project = doc.getDocumentElement();
305
                    Element project = doc.getDocumentElement();
306
                    Element config = Util.findElement(project, "configuration", null); // NOI18N
306
                    Element config = XMLUtil.findElement(project, "configuration", null); // NOI18N
307
                    data = Util.findElement(config, "data", NbModuleProject.NAMESPACE_SHARED);
307
                    data = XMLUtil.findElement(config, "data", NbModuleProject.NAMESPACE_SHARED);
308
                } catch (IOException e) {
308
                } catch (IOException e) {
309
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
309
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
310
                } catch (SAXException e) {
310
                } catch (SAXException e) {
(-)a/j2ee.archive/nbproject/project.xml (-1 / +1 lines)
Lines 294-300 Link Here
294
                    <build-prerequisite/>
294
                    <build-prerequisite/>
295
                    <compile-dependency/>
295
                    <compile-dependency/>
296
                    <run-dependency>
296
                    <run-dependency>
297
                        <specification-version>8.0</specification-version>
297
                        <specification-version>8.4</specification-version>
298
                    </run-dependency>
298
                    </run-dependency>
299
                </dependency>
299
                </dependency>
300
                <dependency>
300
                <dependency>
(-)a/j2ee.archive/src/org/netbeans/modules/j2ee/archive/project/UpdateHelper.java (-34 / +3 lines)
Lines 61-66 Link Here
61
import org.netbeans.spi.project.AuxiliaryConfiguration;
61
import org.netbeans.spi.project.AuxiliaryConfiguration;
62
import org.netbeans.spi.project.support.ant.AntProjectHelper;
62
import org.netbeans.spi.project.support.ant.AntProjectHelper;
63
import org.netbeans.spi.project.support.ant.EditableProperties;
63
import org.netbeans.spi.project.support.ant.EditableProperties;
64
import org.openide.xml.XMLUtil;
64
65
65
66
66
/**
67
/**
Lines 277-283 Link Here
277
            if (oldRoot != null) {
278
            if (oldRoot != null) {
278
                Document doc = oldRoot.getOwnerDocument();
279
                Document doc = oldRoot.getOwnerDocument();
279
                Element newRoot = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,DATA); //NOI18N
280
                Element newRoot = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,DATA); //NOI18N
280
                copyDocument (doc, oldRoot, newRoot);
281
                XMLUtil.copyDocument (oldRoot, newRoot, ArchiveProjectType.PROJECT_CONFIGURATION_NS);
281
                Element sourceRoots = doc.createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS,"source-roots");  //NOI18N
282
                Element sourceRoots = doc.createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS,"source-roots");  //NOI18N
282
                Element root = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,"root");   //NOI18N
283
                Element root = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,"root");   //NOI18N
283
                root.setAttribute ("id","src.dir");   //NOI18N
284
                root.setAttribute ("id","src.dir");   //NOI18N
Lines 294-300 Link Here
294
                if (oldRoot != null) {
295
                if (oldRoot != null) {
295
                    Document doc = oldRoot.getOwnerDocument();
296
                    Document doc = oldRoot.getOwnerDocument();
296
                    Element newRoot = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,DATA); //NOI18N
297
                    Element newRoot = doc.createElementNS (ArchiveProjectType.PROJECT_CONFIGURATION_NS,DATA); //NOI18N
297
                    copyDocument (doc, oldRoot, newRoot);
298
                    XMLUtil.copyDocument (oldRoot, newRoot, ArchiveProjectType.PROJECT_CONFIGURATION_NS);
298
                    cachedElement = updateMinAntVersion (newRoot, doc);
299
                    cachedElement = updateMinAntVersion (newRoot, doc);
299
                }
300
                }
300
            }
301
            }
Lines 317-354 Link Here
317
        return cachedProperties;
318
        return cachedProperties;
318
    }
319
    }
319
320
320
    private static void copyDocument (Document doc, Element from, Element to) {
321
        NodeList nl = from.getChildNodes();
322
        int length = nl.getLength();
323
        for (int i=0; i< length; i++) {
324
            Node node = nl.item (i);
325
            Node newNode = null;
326
            switch (node.getNodeType()) {
327
                case Node.ELEMENT_NODE:
328
                    Element oldElement = (Element) node;
329
                    newNode = doc.createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS,oldElement.getTagName());
330
                    NamedNodeMap m = oldElement.getAttributes();
331
                    Element newElement = (Element) newNode;
332
                    for (int index = 0; index < m.getLength(); index++) {
333
                        Node attr = m.item(index);
334
                          newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
335
                    }
336
                    copyDocument(doc,oldElement,newElement);
337
                    break;
338
                case Node.TEXT_NODE:
339
                    Text oldText = (Text) node;
340
                    newNode = doc.createTextNode(oldText.getData());
341
                    break;
342
                case Node.COMMENT_NODE:
343
                    Comment oldComment = (Comment) node;
344
                    newNode = doc.createComment(oldComment.getData());
345
                    break;
346
            }
347
            if (newNode != null) {
348
                to.appendChild (newNode);
349
            }
350
        }
351
    }
352
    public static final String MINIMUM_ANT_VERSION = "1.6.5"; // NOI18N
321
    public static final String MINIMUM_ANT_VERSION = "1.6.5"; // NOI18N
353
    
322
    
354
    private static Element updateMinAntVersion (final Element root, final Document doc) {
323
    private static Element updateMinAntVersion (final Element root, final Document doc) {
(-)a/j2ee.clientproject/nbproject/project.xml (-25 / +34 lines)
Lines 375-381 Link Here
375
                    <build-prerequisite/>
375
                    <build-prerequisite/>
376
                    <compile-dependency/>
376
                    <compile-dependency/>
377
                    <run-dependency>
377
                    <run-dependency>
378
                        <specification-version>8.0</specification-version>
378
                        <specification-version>8.4</specification-version>
379
                    </run-dependency>
379
                    </run-dependency>
380
                </dependency>
380
                </dependency>
381
                <dependency>
381
                <dependency>
Lines 399-409 Link Here
399
                <test-type>
399
                <test-type>
400
                    <name>unit</name>
400
                    <name>unit</name>
401
                    <test-dependency>
401
                    <test-dependency>
402
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
403
                        <compile-dependency/>
404
                    </test-dependency>
405
                    <test-dependency>
402
                        <code-name-base>org.netbeans.modules.j2ee.clientproject</code-name-base>
406
                        <code-name-base>org.netbeans.modules.j2ee.clientproject</code-name-base>
403
                        <recursive/>
407
                        <recursive/>
404
                        <compile-dependency/>
408
                        <compile-dependency/>
405
                    </test-dependency>
409
                    </test-dependency>
406
                    <test-dependency>
410
                    <test-dependency>
411
                        <code-name-base>org.netbeans.modules.j2ee.sun.ddui</code-name-base>
412
                    </test-dependency>
413
                    <test-dependency>
414
                        <code-name-base>org.netbeans.modules.j2eeserver</code-name-base>
415
                        <test/>
416
                    </test-dependency>
417
                    <test-dependency>
418
                        <code-name-base>org.netbeans.modules.java.project</code-name-base>
419
                    </test-dependency>
420
                    <test-dependency>
421
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
422
                    </test-dependency>
423
                    <test-dependency>
424
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
425
                        <recursive/>
426
                        <compile-dependency/>
427
                    </test-dependency>
428
                    <test-dependency>
429
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
430
                        <compile-dependency/>
431
                        <test/>
432
                    </test-dependency>
433
                    <test-dependency>
434
                        <code-name-base>org.netbeans.modules.websvc.core</code-name-base>
435
                    </test-dependency>
436
                    <test-dependency>
437
                        <code-name-base>org.netbeans.modules.websvc.projectapi</code-name-base>
438
                    </test-dependency>
439
                    <test-dependency>
407
                        <code-name-base>org.openide.util</code-name-base>
440
                        <code-name-base>org.openide.util</code-name-base>
408
                        <compile-dependency/>
441
                        <compile-dependency/>
409
                        <test/>
442
                        <test/>
Lines 413-442 Link Here
413
                        <compile-dependency/>
446
                        <compile-dependency/>
414
                        <test/>
447
                        <test/>
415
                    </test-dependency>
448
                    </test-dependency>
416
                    <test-dependency>
417
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
418
                        <compile-dependency/>
419
                        <test/>
420
                    </test-dependency>
421
                    <test-dependency>
422
                        <code-name-base>org.netbeans.modules.j2eeserver</code-name-base>
423
                        <test/>
424
                    </test-dependency>
425
                    <test-dependency>
426
                        <code-name-base>org.netbeans.modules.j2ee.sun.ddui</code-name-base>
427
                    </test-dependency>
428
                    <test-dependency>
429
                        <code-name-base>org.netbeans.modules.java.project</code-name-base>
430
                    </test-dependency>
431
                    <test-dependency>
432
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
433
                    </test-dependency>
434
                    <test-dependency>
435
                        <code-name-base>org.netbeans.modules.websvc.core</code-name-base>
436
                    </test-dependency>
437
                    <test-dependency>
438
                        <code-name-base>org.netbeans.modules.websvc.projectapi</code-name-base>
439
                    </test-dependency>
440
                </test-type>
449
                </test-type>
441
            </test-dependencies>
450
            </test-dependencies>
442
            <friend-packages>
451
            <friend-packages>
(-)a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/UpdateProjectImpl.java (-35 / +3 lines)
Lines 53-58 Link Here
53
import org.openide.DialogDisplayer;
53
import org.openide.DialogDisplayer;
54
import org.openide.NotifyDescriptor;
54
import org.openide.NotifyDescriptor;
55
import org.openide.util.NbBundle;
55
import org.openide.util.NbBundle;
56
import org.openide.xml.XMLUtil;
56
import org.w3c.dom.Comment;
57
import org.w3c.dom.Comment;
57
import org.w3c.dom.Document;
58
import org.w3c.dom.Document;
58
import org.w3c.dom.Element;
59
import org.w3c.dom.Element;
Lines 147-153 Link Here
147
            if (oldRoot != null) {
148
            if (oldRoot != null) {
148
                Document doc = oldRoot.getOwnerDocument();
149
                Document doc = oldRoot.getOwnerDocument();
149
                Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
150
                Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
150
                copyDocument (doc, oldRoot, newRoot);
151
                XMLUtil.copyDocument (oldRoot, newRoot, AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE);
151
                Element sourceRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
152
                Element sourceRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
152
                Element root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
153
                Element root = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
153
                root.setAttribute ("id","src.dir");   //NOI18N
154
                root.setAttribute ("id","src.dir");   //NOI18N
Lines 164-170 Link Here
164
                if (oldRoot != null) {
165
                if (oldRoot != null) {
165
                    Document doc = oldRoot.getOwnerDocument();
166
                    Document doc = oldRoot.getOwnerDocument();
166
                    Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
167
                    Element newRoot = doc.createElementNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
167
                    copyDocument (doc, oldRoot, newRoot);
168
                    XMLUtil.copyDocument (oldRoot, newRoot, AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE);
168
                    cachedElement = updateMinAntVersion (newRoot, doc);
169
                    cachedElement = updateMinAntVersion (newRoot, doc);
169
                }
170
                }
170
            }
171
            }
Lines 187-225 Link Here
187
        return cachedProperties;
188
        return cachedProperties;
188
    }
189
    }
189
190
190
    private static void copyDocument (Document doc, Element from, Element to) {
191
        NodeList nl = from.getChildNodes();
192
        int length = nl.getLength();
193
        for (int i=0; i< length; i++) {
194
            Node node = nl.item (i);
195
            Node newNode = null;
196
            switch (node.getNodeType()) {
197
                case Node.ELEMENT_NODE:
198
                    Element oldElement = (Element) node;
199
                    newNode = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
200
                    NamedNodeMap m = oldElement.getAttributes();
201
                    Element newElement = (Element) newNode;
202
                    for (int index = 0; index < m.getLength(); index++) {
203
                        Node attr = m.item(index);
204
                          newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
205
                    }
206
                    copyDocument(doc,oldElement,newElement);
207
                    break;
208
                case Node.TEXT_NODE:
209
                    Text oldText = (Text) node;
210
                    newNode = doc.createTextNode(oldText.getData());
211
                    break;
212
                case Node.COMMENT_NODE:
213
                    Comment oldComment = (Comment) node;
214
                    newNode = doc.createComment(oldComment.getData());
215
                    break;
216
            }
217
            if (newNode != null) {
218
                to.appendChild (newNode);
219
            }
220
        }
221
    }
222
    
223
    private static Element updateMinAntVersion (final Element root, final Document doc) {
191
    private static Element updateMinAntVersion (final Element root, final Document doc) {
224
        NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
192
        NodeList list = root.getElementsByTagNameNS (AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
225
        if (list.getLength() == 1) {
193
        if (list.getLength() == 1) {
(-)a/j2ee.clientproject/src/org/netbeans/modules/j2ee/clientproject/classpath/ClassPathSupportCallbackImpl.java (-19 / +2 lines)
Lines 51-61 Link Here
51
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
51
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
52
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
52
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
54
import org.openide.xml.XMLUtil;
54
import org.w3c.dom.Document;
55
import org.w3c.dom.Document;
55
import org.w3c.dom.Element;
56
import org.w3c.dom.Element;
56
import org.w3c.dom.Node;
57
import org.w3c.dom.Node;
57
import org.w3c.dom.NodeList;
58
import org.w3c.dom.NodeList;
58
import org.w3c.dom.Text;
59
59
60
/**
60
/**
61
 *
61
 *
Lines 91-97 Link Here
91
        for ( int i = 0; i < libs.getLength(); i++ ) {
91
        for ( int i = 0; i < libs.getLength(); i++ ) {
92
            Element item = (Element)libs.item( i );
92
            Element item = (Element)libs.item( i );
93
            // appclient is different from other j2ee projects - it stores reference without ${ and }
93
            // appclient is different from other j2ee projects - it stores reference without ${ and }
94
            String ref = "${"+findText( item )+"}";
94
            String ref = "${"+XMLUtil.findText( item )+"}";
95
            libraries.add(ref); // NOI18N
95
            libraries.add(ref); // NOI18N
96
            String dirs = item.getAttribute(ATTR_DIRS);
96
            String dirs = item.getAttribute(ATTR_DIRS);
97
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
97
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
Lines 140-162 Link Here
140
        return libraryElement;
140
        return libraryElement;
141
    }
141
    }
142
       
142
       
143
    /**
144
     * Extracts <b>the first</b> nested text from an element.
145
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
146
     * @param parent a parent element
147
     * @return the nested text, or null if none was found
148
     */
149
    private static String findText( Element parent ) {
150
        NodeList l = parent.getChildNodes();
151
        for ( int i = 0; i < l.getLength(); i++ ) {
152
            if ( l.item(i).getNodeType() == Node.TEXT_NODE ) {
153
                Text text = (Text)l.item( i );
154
                return text.getNodeValue();
155
            }
156
        }
157
        return null;
158
    }
159
160
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
143
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
161
        Map<String, String> destination = new HashMap<String, String>();
144
        Map<String, String> destination = new HashMap<String, String>();
162
        List<String> l = getIncludedLibraries(antProjectHelper, projectXMLElement, destination);
145
        List<String> l = getIncludedLibraries(antProjectHelper, projectXMLElement, destination);
(-)a/j2ee.earproject/nbproject/project.xml (-29 / +38 lines)
Lines 347-353 Link Here
347
                    <build-prerequisite/>
347
                    <build-prerequisite/>
348
                    <compile-dependency/>
348
                    <compile-dependency/>
349
                    <run-dependency>
349
                    <run-dependency>
350
                        <specification-version>8.0</specification-version>
350
                        <specification-version>8.4</specification-version>
351
                    </run-dependency>
351
                    </run-dependency>
352
                </dependency>
352
                </dependency>
353
                <dependency>
353
                <dependency>
Lines 363-373 Link Here
363
                <test-type>
363
                <test-type>
364
                    <name>unit</name>
364
                    <name>unit</name>
365
                    <test-dependency>
365
                    <test-dependency>
366
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
367
                        <compile-dependency/>
368
                    </test-dependency>
369
                    <test-dependency>
366
                        <code-name-base>org.netbeans.modules.j2ee.earproject</code-name-base>
370
                        <code-name-base>org.netbeans.modules.j2ee.earproject</code-name-base>
367
                        <recursive/>
371
                        <recursive/>
368
                        <compile-dependency/>
372
                        <compile-dependency/>
369
                    </test-dependency>
373
                    </test-dependency>
370
                    <test-dependency>
374
                    <test-dependency>
375
                        <code-name-base>org.netbeans.modules.j2ee.sun.dd</code-name-base>
376
                    </test-dependency>
377
                    <test-dependency>
378
                        <code-name-base>org.netbeans.modules.j2ee.sun.ddui</code-name-base>
379
                    </test-dependency>
380
                    <test-dependency>
381
                        <code-name-base>org.netbeans.modules.j2eeserver</code-name-base>
382
                        <test/>
383
                    </test-dependency>
384
                    <test-dependency>
385
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
386
                    </test-dependency>
387
                    <test-dependency>
388
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
389
                        <recursive/>
390
                        <compile-dependency/>
391
                    </test-dependency>
392
                    <test-dependency>
393
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
394
                        <compile-dependency/>
395
                        <test/>
396
                    </test-dependency>
397
                    <test-dependency>
398
                        <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
399
                        <compile-dependency/>
400
                    </test-dependency>
401
                    <test-dependency>
402
                        <code-name-base>org.netbeans.modules.web.core</code-name-base>
403
                    </test-dependency>
404
                    <test-dependency>
405
                        <code-name-base>org.netbeans.modules.web.core.syntax</code-name-base>
406
                    </test-dependency>
407
                    <test-dependency>
371
                        <code-name-base>org.openide.util</code-name-base>
408
                        <code-name-base>org.openide.util</code-name-base>
372
                        <compile-dependency/>
409
                        <compile-dependency/>
373
                        <test/>
410
                        <test/>
Lines 377-410 Link Here
377
                        <compile-dependency/>
414
                        <compile-dependency/>
378
                        <test/>
415
                        <test/>
379
                    </test-dependency>
416
                    </test-dependency>
380
                    <test-dependency>
381
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
382
                        <compile-dependency/>
383
                        <test/>
384
                    </test-dependency>
385
                    <test-dependency>
386
                        <code-name-base>org.netbeans.modules.j2eeserver</code-name-base>
387
                        <test/>
388
                    </test-dependency>
389
                    <test-dependency>
390
                        <code-name-base>org.netbeans.modules.j2ee.sun.dd</code-name-base>
391
                    </test-dependency>
392
                    <test-dependency>
393
                        <code-name-base>org.netbeans.modules.j2ee.sun.ddui</code-name-base>
394
                    </test-dependency>
395
                    <test-dependency>
396
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
397
                    </test-dependency>
398
                    <test-dependency>
399
                        <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
400
                        <compile-dependency/>
401
                    </test-dependency>
402
                    <test-dependency>
403
                        <code-name-base>org.netbeans.modules.web.core</code-name-base>
404
                    </test-dependency>
405
                    <test-dependency>
406
                        <code-name-base>org.netbeans.modules.web.core.syntax</code-name-base>
407
                    </test-dependency>
408
                </test-type>
417
                </test-type>
409
            </test-dependencies>
418
            </test-dependencies>
410
            <public-packages/>
419
            <public-packages/>
(-)a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/UpdateProjectImpl.java (-56 / +3 lines)
Lines 60-71 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.w3c.dom.Comment;
63
import org.openide.xml.XMLUtil;
64
import org.w3c.dom.Document;
64
import org.w3c.dom.Document;
65
import org.w3c.dom.NamedNodeMap;
66
import org.w3c.dom.Node;
65
import org.w3c.dom.Node;
67
import org.w3c.dom.NodeList;
66
import org.w3c.dom.NodeList;
68
import org.w3c.dom.Text;
69
67
70
68
71
/**
69
/**
Lines 159-165 Link Here
159
            if(oldRoot != null) {
157
            if(oldRoot != null) {
160
                Document doc = oldRoot.getOwnerDocument();
158
                Document doc = oldRoot.getOwnerDocument();
161
                Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
159
                Element newRoot = doc.createElementNS(EarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
162
                copyDocument(doc, oldRoot, newRoot);
160
                XMLUtil.copyDocument(oldRoot, newRoot, EarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
163
                
161
                
164
                //update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/>
162
                //update <web-module-/additional/-libraries/> to <j2ee-module-/additional/-libraries/>
165
//                NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries");
163
//                NodeList contList = newRoot.getElementsByTagNameNS(ns, "web-module-libraries");
Lines 173-179 Link Here
173
                        Element library = (Element) libList.item(i);
171
                        Element library = (Element) libList.item(i);
174
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
172
                        Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
175
                        //remove ${ and } from the beginning and end
173
                        //remove ${ and } from the beginning and end
176
                        String webFileText = findText(webFile);
174
                        String webFileText = XMLUtil.findText(webFile);
177
                        webFileText = webFileText.substring(2, webFileText.length() - 1);
175
                        webFileText = webFileText.substring(2, webFileText.length() - 1);
178
                        if (webFileText.startsWith("libs.")) {
176
                        if (webFileText.startsWith("libs.")) {
179
                            String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N
177
                            String libName = webFileText.substring(5, webFileText.indexOf(".classpath")); //NOI18N
Lines 209-265 Link Here
209
        return cachedElement;
207
        return cachedElement;
210
    }
208
    }
211
209
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() {
210
    public EditableProperties getUpdatedProjectProperties() {
264
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
211
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
265
    }
212
    }
(-)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
(-)a/j2ee.ejbjarproject/nbproject/project.xml (-1 / +10 lines)
Lines 450-456 Link Here
450
                    <build-prerequisite/>
450
                    <build-prerequisite/>
451
                    <compile-dependency/>
451
                    <compile-dependency/>
452
                    <run-dependency>
452
                    <run-dependency>
453
                        <specification-version>8.0</specification-version>
453
                        <specification-version>8.4</specification-version>
454
                    </run-dependency>
454
                    </run-dependency>
455
                </dependency>
455
                </dependency>
456
                <dependency>
456
                <dependency>
Lines 474-479 Link Here
474
                <test-type>
474
                <test-type>
475
                    <name>unit</name>
475
                    <name>unit</name>
476
                    <test-dependency>
476
                    <test-dependency>
477
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
478
                        <compile-dependency/>
479
                    </test-dependency>
480
                    <test-dependency>
477
                        <code-name-base>org.netbeans.modules.j2ee.ejbjarproject</code-name-base>
481
                        <code-name-base>org.netbeans.modules.j2ee.ejbjarproject</code-name-base>
478
                        <recursive/>
482
                        <recursive/>
479
                        <compile-dependency/>
483
                        <compile-dependency/>
Lines 482-487 Link Here
482
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
486
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
483
                    </test-dependency>
487
                    </test-dependency>
484
                    <test-dependency>
488
                    <test-dependency>
489
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
490
                        <recursive/>
491
                        <compile-dependency/>
492
                    </test-dependency>
493
                    <test-dependency>
485
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
494
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
486
                    </test-dependency>
495
                    </test-dependency>
487
                    <test-dependency>
496
                    <test-dependency>
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java (-28 / +2 lines)
Lines 172-177 Link Here
172
import org.openide.filesystems.FileStateInvalidException;
172
import org.openide.filesystems.FileStateInvalidException;
173
import org.openide.filesystems.FileSystem.AtomicAction;
173
import org.openide.filesystems.FileSystem.AtomicAction;
174
import org.openide.util.Exceptions;
174
import org.openide.util.Exceptions;
175
import org.openide.xml.XMLUtil;
175
176
176
/**
177
/**
177
 * Represents one ejb module project
178
 * Represents one ejb module project
Lines 627-633 Link Here
627
        if (element != null) {
628
        if (element != null) {
628
            Document doc = element.getOwnerDocument();
629
            Document doc = element.getOwnerDocument();
629
            Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
630
            Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
630
            copyDocument (doc, element, newRoot);
631
            XMLUtil.copyDocument (element, newRoot, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
631
            Element srcRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots");  //NOI18N
632
            Element srcRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots");  //NOI18N
632
            Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
633
            Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
633
            root.setAttribute ("id","src.dir");   //NOI18N
634
            root.setAttribute ("id","src.dir");   //NOI18N
Lines 643-675 Link Here
643
        }
644
        }
644
    }
645
    }
645
646
646
    private static void copyDocument (Document doc, Element from, Element to) {
647
        NodeList nl = from.getChildNodes();
648
        int length = nl.getLength();
649
        for (int i=0; i< length; i++) {
650
            Node node = nl.item (i);
651
            Node newNode = null;
652
            switch (node.getNodeType()) {
653
                case Node.ELEMENT_NODE:
654
                    Element oldElement = (Element) node;
655
                    newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
656
                    copyDocument(doc,oldElement,(Element)newNode);
657
                    break;
658
                case Node.TEXT_NODE:
659
                    Text oldText = (Text) node;
660
                    newNode = doc.createTextNode(oldText.getData());
661
                    break;
662
                case Node.COMMENT_NODE:
663
                    Comment oldComment = (Comment) node;
664
                    newNode = doc.createComment(oldComment.getData());
665
                    break;
666
            }
667
            if (newNode != null) {
668
                to.appendChild (newNode);
669
            }
670
        }
671
    }
672
673
    public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) {
647
    public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) {
674
    }    
648
    }    
675
    
649
    
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateProjectImpl.java (-56 / +3 lines)
Lines 59-71 Link Here
59
import org.openide.filesystems.FileUtil;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.util.Mutex;
60
import org.openide.util.Mutex;
61
import org.openide.util.NbBundle;
61
import org.openide.util.NbBundle;
62
import org.w3c.dom.Comment;
62
import org.openide.xml.XMLUtil;
63
import org.w3c.dom.Document;
63
import org.w3c.dom.Document;
64
import org.w3c.dom.Element;
64
import org.w3c.dom.Element;
65
import org.w3c.dom.NamedNodeMap;
66
import org.w3c.dom.Node;
65
import org.w3c.dom.Node;
67
import org.w3c.dom.NodeList;
66
import org.w3c.dom.NodeList;
68
import org.w3c.dom.Text;
69
67
70
/**
68
/**
71
 *
69
 *
Lines 191-197 Link Here
191
            if (oldRoot != null) {
189
            if (oldRoot != null) {
192
                Document doc = oldRoot.getOwnerDocument();
190
                Document doc = oldRoot.getOwnerDocument();
193
                Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
191
                Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
194
                copyDocument (doc, oldRoot, newRoot);
192
                XMLUtil.copyDocument (oldRoot, newRoot, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
195
                if(version == 1) {
193
                if(version == 1) {
196
                    //1=>2 upgrade
194
                    //1=>2 upgrade
197
                    Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
195
                    Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
Lines 211-217 Link Here
211
                    for (int i = 0; i < libList.getLength(); i++) {
209
                    for (int i = 0; i < libList.getLength(); i++) {
212
                        if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) {
210
                        if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) {
213
                            Element library = (Element) libList.item(i);
211
                            Element library = (Element) libList.item(i);
214
                            String fileText = findText(library);
212
                            String fileText = XMLUtil.findText(library);
215
                            if (fileText.startsWith ("libs.")) {
213
                            if (fileText.startsWith ("libs.")) {
216
                                String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N
214
                                String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N
217
                                List/*<URL>*/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N
215
                                List/*<URL>*/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N
Lines 253-292 Link Here
253
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
251
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
254
    }
252
    }
255
253
256
    private static void copyDocument (Document doc, Element from, Element to) {
257
        NodeList nl = from.getChildNodes();
258
        int length = nl.getLength();
259
        for (int i=0; i< length; i++) {
260
            Node node = nl.item (i);
261
            Node newNode = null;
262
            switch (node.getNodeType()) {
263
                case Node.ELEMENT_NODE:
264
                    Element oldElement = (Element) node;
265
                    newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
266
                    //copy attributes
267
                    NamedNodeMap m = oldElement.getAttributes();
268
                    Element newElement = (Element) newNode;
269
                    for (int index = 0; index < m.getLength(); index++) {
270
                        Node attr = m.item(index);
271
                        newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
272
                    }
273
                    copyDocument(doc,oldElement,(Element)newNode);
274
                    break;
275
                case Node.TEXT_NODE:
276
                    Text oldText = (Text) node;
277
                    newNode = doc.createTextNode(oldText.getData());
278
                    break;
279
                case Node.COMMENT_NODE:
280
                    Comment oldComment = (Comment) node;
281
                    newNode = doc.createComment(oldComment.getData());
282
                    break;
283
            }
284
            if (newNode != null) {
285
                to.appendChild (newNode);
286
            }
287
        }
288
    }
289
    
290
    private static Element updateMinAntVersion (final Element root, final Document doc) {
254
    private static Element updateMinAntVersion (final Element root, final Document doc) {
291
        NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
255
        NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
292
        if (list.getLength() == 1) {
256
        if (list.getLength() == 1) {
Lines 301-323 Link Here
301
        return root;
265
        return root;
302
    }
266
    }
303
    
267
    
304
    /**
305
     * Extract nested text from a node.
306
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
307
     * @param parent a parent node
308
     * @return the nested text, or null if none was found
309
     */
310
    private static String findText(Node parent) {
311
        NodeList l = parent.getChildNodes();
312
        for (int i = 0; i < l.getLength(); i++) {
313
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
314
                Text text = (Text)l.item(i);
315
                return text.getNodeValue();
316
            }
317
        }
318
        return null;
319
    }
320
    
321
    private boolean showUpdateDialog() {
268
    private boolean showUpdateDialog() {
322
        return DialogDisplayer.getDefault().notify(
269
        return DialogDisplayer.getDefault().notify(
323
            new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate",BUILD_NUMBER),
270
            new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate",BUILD_NUMBER),
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathSupportCallbackImpl.java (-79 / +3 lines)
Lines 42-50 Link Here
42
package org.netbeans.modules.j2ee.ejbjarproject.classpath;
42
package org.netbeans.modules.j2ee.ejbjarproject.classpath;
43
43
44
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.Arrays;
46
import java.util.HashMap;
45
import java.util.HashMap;
47
import java.util.Iterator;
48
import java.util.List;
46
import java.util.List;
49
import java.util.Map;
47
import java.util.Map;
50
import org.netbeans.modules.j2ee.common.Util;
48
import org.netbeans.modules.j2ee.common.Util;
Lines 55-63 Link Here
55
import org.w3c.dom.Element;
53
import org.w3c.dom.Element;
56
import org.w3c.dom.Node;
54
import org.w3c.dom.Node;
57
import org.w3c.dom.NodeList;
55
import org.w3c.dom.NodeList;
58
import org.w3c.dom.Text;
59
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
56
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
60
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
57
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
58
import org.openide.xml.XMLUtil;
61
59
62
/**
60
/**
63
 *
61
 *
Lines 95-101 Link Here
95
        for ( int i = 0; i < libs.getLength(); i++ ) {
93
        for ( int i = 0; i < libs.getLength(); i++ ) {
96
            Element item = (Element)libs.item( i );
94
            Element item = (Element)libs.item( i );
97
            // ejbjar is different from other j2ee projects - it stores reference without ${ and }
95
            // ejbjar is different from other j2ee projects - it stores reference without ${ and }
98
            String ref = "${"+findText( item )+"}";
96
            String ref = "${"+XMLUtil.findText( item )+"}";
99
            libraries.add(ref); // NOI18N
97
            libraries.add(ref); // NOI18N
100
            String dirs = item.getAttribute(ATTR_DIRS);
98
            String dirs = item.getAttribute(ATTR_DIRS);
101
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
99
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
Lines 125-131 Link Here
125
        Document doc = data.getOwnerDocument();
123
        Document doc = data.getOwnerDocument();
126
        for (ClassPathSupport.Item item : classpath) {
124
        for (ClassPathSupport.Item item : classpath) {
127
            if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N
125
            if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N
128
                appendChildElement(data, 
126
                XMLUtil.appendChildElement(data,
129
                    createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), 
127
                    createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), 
130
                    ejbjarElemOrder);
128
                    ejbjarElemOrder);
131
            }
129
            }
Lines 134-195 Link Here
134
        antProjectHelper.putPrimaryConfigurationData( data, true );
132
        antProjectHelper.putPrimaryConfigurationData( data, true );
135
    }
133
    }
136
    
134
    
137
    /**
138
     * Find all direct child elements of an element.
139
     * More useful than {@link Element#getElementsByTagNameNS} because it does
140
     * not recurse into recursive child elements.
141
     * Children which are all-whitespace text nodes are ignored; others cause
142
     * an exception to be thrown.
143
     * @param parent a parent element in a DOM tree
144
     * @return a list of direct child elements (may be empty)
145
     * @throws IllegalArgumentException if there are non-element children besides whitespace
146
     */
147
    private static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
148
        NodeList l = parent.getChildNodes();
149
        List<Element> elements = new ArrayList<Element>(l.getLength());
150
        for (int i = 0; i < l.getLength(); i++) {
151
            Node n = l.item(i);
152
            if (n.getNodeType() == Node.ELEMENT_NODE) {
153
                elements.add((Element)n);
154
            } else if (n.getNodeType() == Node.TEXT_NODE) {
155
                String text = ((Text)n).getNodeValue();
156
                if (text.trim().length() > 0) {
157
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
158
                }
159
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
160
                // skip
161
            } else {
162
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
163
            }
164
        }
165
        return elements;
166
    }
167
    
168
    /**
169
     * Append child element to the correct position according to given
170
     * order.
171
     * @param parent parent to which the child will be added
172
     * @param el element to be added
173
     * @param order order of the elements which must be followed
174
     */
175
    private static void appendChildElement(Element parent, Element el, String[] order) {
176
        Element insertBefore = null;
177
        List l = Arrays.asList(order);
178
        int index = l.indexOf(el.getLocalName());
179
        assert index != -1 : el.getLocalName()+" was not found in "+l; // NOI18N
180
        Iterator it = findSubElements(parent).iterator();
181
        while (it.hasNext()) {
182
            Element e = (Element)it.next();
183
            int index2 = l.indexOf(e.getLocalName());
184
            assert index2 != -1 : e.getLocalName()+" was not found in "+l; // NOI18N
185
            if (index2 > index) {
186
                insertBefore = e;
187
                break;
188
            }
189
        }
190
        parent.insertBefore(el, insertBefore);
191
    }
192
        
193
    private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) {
135
    private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) {
194
        Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
136
        Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
195
        // ejbjar is different from other j2ee projects - it stores reference without ${ and }
137
        // ejbjar is different from other j2ee projects - it stores reference without ${ and }
Lines 198-221 Link Here
198
        return libraryElement;
140
        return libraryElement;
199
    }
141
    }
200
       
142
       
201
    /**
202
     * Extracts <b>the first</b> nested text from an element.
203
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
204
     * @param parent a parent element
205
     * @return the nested text, or null if none was found
206
     */
207
    private static String findText( Element parent ) {
208
        NodeList l = parent.getChildNodes();
209
        for ( int i = 0; i < l.getLength(); i++ ) {
210
            if ( l.item(i).getNodeType() == Node.TEXT_NODE ) {
211
                Text text = (Text)l.item( i );
212
                return text.getNodeValue();
213
            }
214
        }
215
        return null;
216
    }
217
        
218
219
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
143
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
220
        Map<String, String> destination = new HashMap<String, String>();
144
        Map<String, String> destination = new HashMap<String, String>();
221
        List<String> l = getIncludedLibraries(helper, projectXMLElement, destination);
145
        List<String> l = getIncludedLibraries(helper, projectXMLElement, destination);
(-)a/java.freeform/nbproject/project.xml (-1 / +1 lines)
Lines 200-206 Link Here
200
                    <build-prerequisite/>
200
                    <build-prerequisite/>
201
                    <compile-dependency/>
201
                    <compile-dependency/>
202
                    <run-dependency>
202
                    <run-dependency>
203
                        <specification-version>8.0</specification-version>
203
                        <specification-version>8.4</specification-version>
204
                    </run-dependency>
204
                    </run-dependency>
205
                </dependency>
205
                </dependency>
206
                <dependency>
206
                <dependency>
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java (-22 / +23 lines)
Lines 89-94 Link Here
89
import org.openide.util.Mutex;
89
import org.openide.util.Mutex;
90
import org.openide.util.Utilities;
90
import org.openide.util.Utilities;
91
import org.openide.util.WeakListeners;
91
import org.openide.util.WeakListeners;
92
import org.openide.xml.XMLUtil;
92
import org.w3c.dom.Element;
93
import org.w3c.dom.Element;
93
94
94
/**
95
/**
Lines 193-199 Link Here
193
        if (java == null) {
194
        if (java == null) {
194
            return null;
195
            return null;
195
        }
196
        }
196
        List<Element> compilationUnits = Util.findSubElements(java);
197
        List<Element> compilationUnits = XMLUtil.findSubElements(java);
197
        it = compilationUnits.iterator();
198
        it = compilationUnits.iterator();
198
        while (it.hasNext()) {
199
        while (it.hasNext()) {
199
            Element compilationUnitEl = (Element)it.next();
200
            Element compilationUnitEl = (Element)it.next();
Lines 258-264 Link Here
258
            if (java == null) {
259
            if (java == null) {
259
                return;
260
                return;
260
            }
261
            }
261
            for (Element compilationUnitEl : Util.findSubElements(java)) {
262
            for (Element compilationUnitEl : XMLUtil.findSubElements(java)) {
262
                assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
263
                assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
263
                // For each compilation unit, find the package roots first.
264
                // For each compilation unit, find the package roots first.
264
                List<FileObject> packageRoots = findPackageRoots(helper, evaluator, compilationUnitEl);
265
                List<FileObject> packageRoots = findPackageRoots(helper, evaluator, compilationUnitEl);
Lines 337-349 Link Here
337
    
338
    
338
    static List<String> findPackageRootNames(Element compilationUnitEl) {
339
    static List<String> findPackageRootNames(Element compilationUnitEl) {
339
        List<String> names = new ArrayList<String>();
340
        List<String> names = new ArrayList<String>();
340
        Iterator it = Util.findSubElements(compilationUnitEl).iterator();
341
        Iterator it = XMLUtil.findSubElements(compilationUnitEl).iterator();
341
        while (it.hasNext()) {
342
        while (it.hasNext()) {
342
            Element e = (Element) it.next();
343
            Element e = (Element) it.next();
343
            if (!e.getLocalName().equals("package-root")) { // NOI18N
344
            if (!e.getLocalName().equals("package-root")) { // NOI18N
344
                continue;
345
                continue;
345
            }
346
            }
346
            String location = Util.findText(e);
347
            String location = XMLUtil.findText(e);
347
            names.add(location);
348
            names.add(location);
348
        }
349
        }
349
        return names;
350
        return names;
Lines 421-427 Link Here
421
    }
422
    }
422
    
423
    
423
    private List<URL> createCompileClasspath(Element compilationUnitEl) {
424
    private List<URL> createCompileClasspath(Element compilationUnitEl) {
424
        for (Element e : Util.findSubElements(compilationUnitEl)) {
425
        for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
425
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("compile")) { // NOI18N
426
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("compile")) { // NOI18N
426
                return createClasspath(e);
427
                return createClasspath(e);
427
            }
428
            }
Lines 434-440 Link Here
434
     * Create a classpath from a &lt;classpath&gt; element.
435
     * Create a classpath from a &lt;classpath&gt; element.
435
     */
436
     */
436
    private List<URL> createClasspath(Element classpathEl) {
437
    private List<URL> createClasspath(Element classpathEl) {
437
        String cp = Util.findText(classpathEl);
438
        String cp = XMLUtil.findText(classpathEl);
438
        if (cp == null) {
439
        if (cp == null) {
439
            cp = "";
440
            cp = "";
440
        }
441
        }
Lines 456-462 Link Here
456
    }
457
    }
457
    
458
    
458
    private List<URL> createExecuteClasspath(List<String> packageRoots, Element compilationUnitEl) {
459
    private List<URL> createExecuteClasspath(List<String> packageRoots, Element compilationUnitEl) {
459
        for (Element e : Util.findSubElements(compilationUnitEl)) {
460
        for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
460
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("execute")) { // NOI18N
461
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("execute")) { // NOI18N
461
                return createClasspath(e);
462
                return createClasspath(e);
462
            }
463
            }
Lines 466-477 Link Here
466
        List<URL> urls = new ArrayList<URL>();
467
        List<URL> urls = new ArrayList<URL>();
467
        urls.addAll(createCompileClasspath(compilationUnitEl));
468
        urls.addAll(createCompileClasspath(compilationUnitEl));
468
        boolean foundBuiltTos = false;
469
        boolean foundBuiltTos = false;
469
        for (Element builtTo : Util.findSubElements(compilationUnitEl)) {
470
        for (Element builtTo : XMLUtil.findSubElements(compilationUnitEl)) {
470
            if (!builtTo.getLocalName().equals("built-to")) { // NOI18N
471
            if (!builtTo.getLocalName().equals("built-to")) { // NOI18N
471
                continue;
472
                continue;
472
            }
473
            }
473
            foundBuiltTos = true;
474
            foundBuiltTos = true;
474
            String rawtext = Util.findText(builtTo);
475
            String rawtext = XMLUtil.findText(builtTo);
475
            assert rawtext != null : "Must have nonempty text inside <built-to>";
476
            assert rawtext != null : "Must have nonempty text inside <built-to>";
476
            String text = evaluator.evaluate(rawtext);
477
            String text = evaluator.evaluate(rawtext);
477
            if (text == null) {
478
            if (text == null) {
Lines 486-492 Link Here
486
    }
487
    }
487
    
488
    
488
    private List<URL> createProcessorClasspath(Element compilationUnitEl) {
489
    private List<URL> createProcessorClasspath(Element compilationUnitEl) {
489
        for (Element e : Util.findSubElements(compilationUnitEl)) {
490
        for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
490
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("processor")) { // NOI18N
491
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("processor")) { // NOI18N
491
                return createClasspath(e);
492
                return createClasspath(e);
492
            }
493
            }
Lines 496-502 Link Here
496
    }
497
    }
497
498
498
    private List<URL> createBootClasspath(Element compilationUnitEl) {
499
    private List<URL> createBootClasspath(Element compilationUnitEl) {
499
        for (Element e : Util.findSubElements(compilationUnitEl)) {
500
        for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
500
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("boot")) { // NOI18N
501
            if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("boot")) { // NOI18N
501
                return createClasspath(e);
502
                return createClasspath(e);
502
            }
503
            }
Lines 571-577 Link Here
571
            if (java == null) {
572
            if (java == null) {
572
                return null;
573
                return null;
573
            }
574
            }
574
            List<Element> compilationUnits = Util.findSubElements(java);
575
            List<Element> compilationUnits = XMLUtil.findSubElements(java);
575
            Iterator it = compilationUnits.iterator();
576
            Iterator it = compilationUnits.iterator();
576
            while (it.hasNext()) {
577
            while (it.hasNext()) {
577
                Element compilationUnitEl = (Element)it.next();
578
                Element compilationUnitEl = (Element)it.next();
Lines 680-707 Link Here
680
                rootFolder = null;
681
                rootFolder = null;
681
            }
682
            }
682
            Element genldata = Util.getPrimaryConfigurationData(helper);
683
            Element genldata = Util.getPrimaryConfigurationData(helper);
683
            Element foldersE = Util.findElement(genldata, "folders", Util.NAMESPACE); // NOI18N
684
            Element foldersE = XMLUtil.findElement(genldata, "folders", Util.NAMESPACE); // NOI18N
684
            if (foldersE != null) {
685
            if (foldersE != null) {
685
                for (Element folderE : Util.findSubElements(foldersE)) {
686
                for (Element folderE : XMLUtil.findSubElements(foldersE)) {
686
                    if (folderE.getLocalName().equals("source-folder")) {
687
                    if (folderE.getLocalName().equals("source-folder")) {
687
                        Element typeE = Util.findElement(folderE, "type", Util.NAMESPACE); // NOI18N
688
                        Element typeE = XMLUtil.findElement(folderE, "type", Util.NAMESPACE); // NOI18N
688
                        if (typeE != null) {
689
                        if (typeE != null) {
689
                            String type = Util.findText(typeE);
690
                            String type = XMLUtil.findText(typeE);
690
                            if (type.equals(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
691
                            if (type.equals(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
691
                                Element locationE = Util.findElement(folderE, "location", Util.NAMESPACE); // NOI18N
692
                                Element locationE = XMLUtil.findElement(folderE, "location", Util.NAMESPACE); // NOI18N
692
                                String location = evaluator.evaluate(Util.findText(locationE));
693
                                String location = evaluator.evaluate(XMLUtil.findText(locationE));
693
                                if (location != null && helper.resolveFile(location).equals(rootFolder)) {
694
                                if (location != null && helper.resolveFile(location).equals(rootFolder)) {
694
                                    Element includesE = Util.findElement(folderE, "includes", Util.NAMESPACE); // NOI18N
695
                                    Element includesE = XMLUtil.findElement(folderE, "includes", Util.NAMESPACE); // NOI18N
695
                                    if (includesE != null) {
696
                                    if (includesE != null) {
696
                                        incl = evaluator.evaluate(Util.findText(includesE));
697
                                        incl = evaluator.evaluate(XMLUtil.findText(includesE));
697
                                        if (incl != null && incl.matches("\\$\\{[^}]+\\}")) { // NOI18N
698
                                        if (incl != null && incl.matches("\\$\\{[^}]+\\}")) { // NOI18N
698
                                            // Clearly intended to mean "include everything".
699
                                            // Clearly intended to mean "include everything".
699
                                            incl = null;
700
                                            incl = null;
700
                                        }
701
                                        }
701
                                    }
702
                                    }
702
                                    Element excludesE = Util.findElement(folderE, "excludes", Util.NAMESPACE); // NOI18N
703
                                    Element excludesE = XMLUtil.findElement(folderE, "excludes", Util.NAMESPACE); // NOI18N
703
                                    if (excludesE != null) {
704
                                    if (excludesE != null) {
704
                                        excl = evaluator.evaluate(Util.findText(excludesE));
705
                                        excl = evaluator.evaluate(XMLUtil.findText(excludesE));
705
                                    }
706
                                    }
706
                                }
707
                                }
707
                            }
708
                            }
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java (-25 / +25 lines)
Lines 506-524 Link Here
506
        antProject.setAttribute("basedir", /* ".." times count('/', FILE_SCRIPT_PATH) */".."); // NOI18N
506
        antProject.setAttribute("basedir", /* ".." times count('/', FILE_SCRIPT_PATH) */".."); // NOI18N
507
        // Look for <properties> in project.xml and make corresponding definitions in the Ant script.
507
        // Look for <properties> in project.xml and make corresponding definitions in the Ant script.
508
        Element data = Util.getPrimaryConfigurationData(helper);
508
        Element data = Util.getPrimaryConfigurationData(helper);
509
        Element properties = Util.findElement(data, "properties", Util.NAMESPACE);
509
        Element properties = XMLUtil.findElement(data, "properties", Util.NAMESPACE);
510
        if (properties != null) {
510
        if (properties != null) {
511
            for (Element el : Util.findSubElements(properties)) {
511
            for (Element el : XMLUtil.findSubElements(properties)) {
512
                Element nue = antProject.getOwnerDocument().createElement("property"); // NOI18N
512
                Element nue = antProject.getOwnerDocument().createElement("property"); // NOI18N
513
                if (el.getLocalName().equals("property")) { // NOI18N
513
                if (el.getLocalName().equals("property")) { // NOI18N
514
                    String name = el.getAttribute("name"); // NOI18N
514
                    String name = el.getAttribute("name"); // NOI18N
515
                    assert name != null;
515
                    assert name != null;
516
                    String text = Util.findText(el);
516
                    String text = XMLUtil.findText(el);
517
                    assert text != null;
517
                    assert text != null;
518
                    nue.setAttribute("name", name);
518
                    nue.setAttribute("name", name);
519
                    nue.setAttribute("value", text);
519
                    nue.setAttribute("value", text);
520
                } else if (el.getLocalName().equals("property-file")) { // NOI18N
520
                } else if (el.getLocalName().equals("property-file")) { // NOI18N
521
                    String text = Util.findText(el);
521
                    String text = XMLUtil.findText(el);
522
                    assert text != null;
522
                    assert text != null;
523
                    nue.setAttribute("file", text);
523
                    nue.setAttribute("file", text);
524
                } else {
524
                } else {
Lines 615-621 Link Here
615
        if (java == null) {
615
        if (java == null) {
616
            return Collections.emptyList();
616
            return Collections.emptyList();
617
        }
617
        }
618
        return Util.findSubElements(java);
618
        return XMLUtil.findSubElements(java);
619
    }
619
    }
620
    
620
    
621
    /**
621
    /**
Lines 684-692 Link Here
684
     */
684
     */
685
    private Element findCompilationUnit(String sources) {
685
    private Element findCompilationUnit(String sources) {
686
        for (Element compilationUnitEl : compilationUnits()) {
686
        for (Element compilationUnitEl : compilationUnits()) {
687
            for (Element packageRoot : Util.findSubElements(compilationUnitEl)) {
687
            for (Element packageRoot : XMLUtil.findSubElements(compilationUnitEl)) {
688
                if (packageRoot.getLocalName().equals("package-root")) { // NOI18N
688
                if (packageRoot.getLocalName().equals("package-root")) { // NOI18N
689
                    if (Util.findText(packageRoot).equals(sources)) {
689
                    if (XMLUtil.findText(packageRoot).equals(sources)) {
690
                        return compilationUnitEl;
690
                        return compilationUnitEl;
691
                    }
691
                    }
692
                }
692
                }
Lines 714-722 Link Here
714
     */
714
     */
715
    private String findClassesOutputDir(Element compilationUnitEl) {
715
    private String findClassesOutputDir(Element compilationUnitEl) {
716
        // Look for an appropriate <built-to>.
716
        // Look for an appropriate <built-to>.
717
        for (Element builtTo : Util.findSubElements(compilationUnitEl)) {
717
        for (Element builtTo : XMLUtil.findSubElements(compilationUnitEl)) {
718
            if (builtTo.getLocalName().equals("built-to")) { // NOI18N
718
            if (builtTo.getLocalName().equals("built-to")) { // NOI18N
719
                String rawtext = Util.findText(builtTo);
719
                String rawtext = XMLUtil.findText(builtTo);
720
                // Check that it is not an archive.
720
                // Check that it is not an archive.
721
                String evaltext = evaluator.evaluate(rawtext);
721
                String evaltext = evaluator.evaluate(rawtext);
722
                if (evaltext != null) {
722
                if (evaltext != null) {
Lines 745-753 Link Here
745
    String findSourceLevel(String sources) {
745
    String findSourceLevel(String sources) {
746
        Element compilationUnitEl = findCompilationUnit(sources);
746
        Element compilationUnitEl = findCompilationUnit(sources);
747
        if (compilationUnitEl != null) {
747
        if (compilationUnitEl != null) {
748
            Element sourceLevel = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3);
748
            Element sourceLevel = XMLUtil.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3);
749
            if (sourceLevel != null) {
749
            if (sourceLevel != null) {
750
                return Util.findText(sourceLevel);
750
                return XMLUtil.findText(sourceLevel);
751
            }
751
            }
752
        }
752
        }
753
        return null;
753
        return null;
Lines 761-771 Link Here
761
    String findCUClasspath(String sources, String moud) {
761
    String findCUClasspath(String sources, String moud) {
762
        Element compilationUnitEl = findCompilationUnit(sources);
762
        Element compilationUnitEl = findCompilationUnit(sources);
763
        if (compilationUnitEl != null) {
763
        if (compilationUnitEl != null) {
764
            for (Element classpath : Util.findSubElements(compilationUnitEl)) {
764
            for (Element classpath : XMLUtil.findSubElements(compilationUnitEl)) {
765
                if (classpath.getLocalName().equals("classpath")) { // NOI18N
765
                if (classpath.getLocalName().equals("classpath")) { // NOI18N
766
                    String mode = classpath.getAttribute("mode"); // NOI18N
766
                    String mode = classpath.getAttribute("mode"); // NOI18N
767
                    if (mode.equals(moud)) {
767
                    if (mode.equals(moud)) {
768
                        return Util.findText(classpath);
768
                        return XMLUtil.findText(classpath);
769
                    }
769
                    }
770
                }
770
                }
771
            }
771
            }
Lines 810-820 Link Here
810
        // XXX cannot use FreeformProjectGenerator since that is currently not a public support SPI from ant/freeform
810
        // XXX cannot use FreeformProjectGenerator since that is currently not a public support SPI from ant/freeform
811
        // XXX should this try to find an existing binding? probably not, since it is assumed that if there was one, we would never get here to begin with
811
        // XXX should this try to find an existing binding? probably not, since it is assumed that if there was one, we would never get here to begin with
812
        Element data = Util.getPrimaryConfigurationData(helper);
812
        Element data = Util.getPrimaryConfigurationData(helper);
813
        Element ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
813
        Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
814
        if (ideActions == null) {
814
        if (ideActions == null) {
815
            //fix for #58442:
815
            //fix for #58442:
816
            ideActions = data.getOwnerDocument().createElementNS(Util.NAMESPACE, "ide-actions"); // NOI18N
816
            ideActions = data.getOwnerDocument().createElementNS(Util.NAMESPACE, "ide-actions"); // NOI18N
817
            Util.appendChildElement(data, ideActions, rootElementsOrder);
817
            XMLUtil.appendChildElement(data, ideActions, rootElementsOrder);
818
        }
818
        }
819
        Document doc = data.getOwnerDocument();
819
        Document doc = data.getOwnerDocument();
820
        Element action = doc.createElementNS(Util.NAMESPACE, "action"); // NOI18N
820
        Element action = doc.createElementNS(Util.NAMESPACE, "action"); // NOI18N
Lines 854-862 Link Here
854
        } else {
854
        } else {
855
            // Add a context menu item, since it applies to the project as a whole.
855
            // Add a context menu item, since it applies to the project as a whole.
856
            // Assume there is already a <context-menu> defined, which is quite likely.
856
            // Assume there is already a <context-menu> defined, which is quite likely.
857
            Element view = Util.findElement(data, "view", Util.NAMESPACE); // NOI18N
857
            Element view = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
858
            if (view != null) {
858
            if (view != null) {
859
                Element contextMenu = Util.findElement(view, "context-menu", Util.NAMESPACE); // NOI18N
859
                Element contextMenu = XMLUtil.findElement(view, "context-menu", Util.NAMESPACE); // NOI18N
860
                if (contextMenu != null) {
860
                if (contextMenu != null) {
861
                    Element ideAction = doc.createElementNS(Util.NAMESPACE, "ide-action"); // NOI18N
861
                    Element ideAction = doc.createElementNS(Util.NAMESPACE, "ide-action"); // NOI18N
862
                    ideAction.setAttribute("name", command); // NOI18N
862
                    ideAction.setAttribute("name", command); // NOI18N
Lines 994-1000 Link Here
994
                return null;
994
                return null;
995
            }
995
            }
996
        }
996
        }
997
        for (Element target : Util.findSubElements(doc.getDocumentElement())) {
997
        for (Element target : XMLUtil.findSubElements(doc.getDocumentElement())) {
998
            if (target.getLocalName().equals("target") && targetName.equals(target.getAttribute("name"))) { // NOI18N
998
            if (target.getLocalName().equals("target") && targetName.equals(target.getAttribute("name"))) { // NOI18N
999
                return target;
999
                return target;
1000
            }
1000
            }
Lines 1010-1032 Link Here
1010
     */
1010
     */
1011
    String[] findCommandBinding(String command) {
1011
    String[] findCommandBinding(String command) {
1012
        Element data = Util.getPrimaryConfigurationData(helper);
1012
        Element data = Util.getPrimaryConfigurationData(helper);
1013
        Element ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
1013
        Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
1014
        if (ideActions == null) {
1014
        if (ideActions == null) {
1015
            return null;
1015
            return null;
1016
        }
1016
        }
1017
        String scriptName = "build.xml"; // NOI18N
1017
        String scriptName = "build.xml"; // NOI18N
1018
        for (Element action : Util.findSubElements(ideActions)) {
1018
        for (Element action : XMLUtil.findSubElements(ideActions)) {
1019
            assert action.getLocalName().equals("action");
1019
            assert action.getLocalName().equals("action");
1020
            if (action.getAttribute("name").equals(command)) {
1020
            if (action.getAttribute("name").equals(command)) {
1021
                Element script = Util.findElement(action, "script", Util.NAMESPACE); // NOI18N
1021
                Element script = XMLUtil.findElement(action, "script", Util.NAMESPACE); // NOI18N
1022
                if (script != null) {
1022
                if (script != null) {
1023
                    scriptName = Util.findText(script);
1023
                    scriptName = XMLUtil.findText(script);
1024
                }
1024
                }
1025
                List<String> scriptPlusTargetNames = new ArrayList<String>();
1025
                List<String> scriptPlusTargetNames = new ArrayList<String>();
1026
                scriptPlusTargetNames.add(scriptName);
1026
                scriptPlusTargetNames.add(scriptName);
1027
                for (Element target : Util.findSubElements(action)) {
1027
                for (Element target : XMLUtil.findSubElements(action)) {
1028
                    if (target.getLocalName().equals("target")) { // NOI18N
1028
                    if (target.getLocalName().equals("target")) { // NOI18N
1029
                        scriptPlusTargetNames.add(Util.findText(target));
1029
                        scriptPlusTargetNames.add(XMLUtil.findText(target));
1030
                    }
1030
                    }
1031
                }
1031
                }
1032
                if (scriptName.equals(JdkConfiguration.NBJDK_XML) && scriptPlusTargetNames.size() > 1) {
1032
                if (scriptName.equals(JdkConfiguration.NBJDK_XML) && scriptPlusTargetNames.size() > 1) {
Lines 1069-1075 Link Here
1069
    Element targetUsesTaskExactlyOnce(Element target, String taskName) {
1069
    Element targetUsesTaskExactlyOnce(Element target, String taskName) {
1070
        // XXX should maybe also look for any other usage of the task in the same script in case there is none in the mentioned target
1070
        // XXX should maybe also look for any other usage of the task in the same script in case there is none in the mentioned target
1071
        Element foundTask = null;
1071
        Element foundTask = null;
1072
        for (Element task : Util.findSubElements(target)) {
1072
        for (Element task : XMLUtil.findSubElements(target)) {
1073
            if (task.getLocalName().equals(taskName)) {
1073
            if (task.getLocalName().equals(taskName)) {
1074
                if (foundTask != null) {
1074
                if (foundTask != null) {
1075
                    // Duplicate.
1075
                    // Duplicate.
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/JavaFreeformFileBuiltQuery.java (-4 / +4 lines)
Lines 47-53 Link Here
47
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.api.project.ProjectManager;
49
import org.netbeans.api.queries.FileBuiltQuery.Status;
49
import org.netbeans.api.queries.FileBuiltQuery.Status;
50
import org.netbeans.modules.ant.freeform.spi.support.Util;
51
import org.netbeans.spi.project.AuxiliaryConfiguration;
50
import org.netbeans.spi.project.AuxiliaryConfiguration;
52
import org.netbeans.spi.project.support.ant.AntProjectEvent;
51
import org.netbeans.spi.project.support.ant.AntProjectEvent;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
Lines 58-63 Link Here
58
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileUtil;
58
import org.openide.filesystems.FileUtil;
60
import org.openide.util.Mutex;
59
import org.openide.util.Mutex;
60
import org.openide.xml.XMLUtil;
61
import org.w3c.dom.Element;
61
import org.w3c.dom.Element;
62
62
63
/**
63
/**
Lines 99-105 Link Here
99
        List<String> to   = new ArrayList<String>();
99
        List<String> to   = new ArrayList<String>();
100
        
100
        
101
        if (java != null) {
101
        if (java != null) {
102
            List<Element> compilationUnits = Util.findSubElements(java);
102
            List<Element> compilationUnits = XMLUtil.findSubElements(java);
103
            Iterator it = compilationUnits.iterator();
103
            Iterator it = compilationUnits.iterator();
104
            while (it.hasNext()) {
104
            while (it.hasNext()) {
105
                Element compilationUnitEl = (Element)it.next();
105
                Element compilationUnitEl = (Element)it.next();
Lines 188-198 Link Here
188
    
188
    
189
    static List<String> findBuiltToNames(Element compilationUnitEl) {
189
    static List<String> findBuiltToNames(Element compilationUnitEl) {
190
        List<String> names = new ArrayList<String>();
190
        List<String> names = new ArrayList<String>();
191
        for (Element e : Util.findSubElements(compilationUnitEl)) {
191
        for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
192
            if (!e.getLocalName().equals("built-to")) { // NOI18N
192
            if (!e.getLocalName().equals("built-to")) { // NOI18N
193
                continue;
193
                continue;
194
            }
194
            }
195
            String location = Util.findText(e);
195
            String location = XMLUtil.findText(e);
196
            names.add(location);
196
            names.add(location);
197
        }
197
        }
198
        return names;
198
        return names;
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java (-66 / +67 lines)
Lines 60-65 Link Here
60
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.modules.SpecificationVersion;
61
import org.openide.modules.SpecificationVersion;
62
import org.openide.util.Exceptions;
62
import org.openide.util.Exceptions;
63
import org.openide.xml.XMLUtil;
63
import org.w3c.dom.Document;
64
import org.w3c.dom.Document;
64
import org.w3c.dom.Element;
65
import org.w3c.dom.Element;
65
66
Lines 113-150 Link Here
113
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
114
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
114
        List<SourceFolder> list = new ArrayList<SourceFolder>();
115
        List<SourceFolder> list = new ArrayList<SourceFolder>();
115
        Element data = Util.getPrimaryConfigurationData(helper);
116
        Element data = Util.getPrimaryConfigurationData(helper);
116
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
117
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
117
        if (foldersEl == null) {
118
        if (foldersEl == null) {
118
            return list;
119
            return list;
119
        }
120
        }
120
        for (Element sourceFolderEl : Util.findSubElements(foldersEl)) {
121
        for (Element sourceFolderEl : XMLUtil.findSubElements(foldersEl)) {
121
            if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
122
            if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
122
                continue;
123
                continue;
123
            }
124
            }
124
            SourceFolder sf = new SourceFolder();
125
            SourceFolder sf = new SourceFolder();
125
            Element el = Util.findElement(sourceFolderEl, "label", Util.NAMESPACE); // NOI18N
126
            Element el = XMLUtil.findElement(sourceFolderEl, "label", Util.NAMESPACE); // NOI18N
126
            if (el != null) {
127
            if (el != null) {
127
                sf.label = Util.findText(el);
128
                sf.label = XMLUtil.findText(el);
128
            }
129
            }
129
            el = Util.findElement(sourceFolderEl, "type", Util.NAMESPACE); // NOI18N
130
            el = XMLUtil.findElement(sourceFolderEl, "type", Util.NAMESPACE); // NOI18N
130
            if (el != null) {
131
            if (el != null) {
131
                sf.type = Util.findText(el);
132
                sf.type = XMLUtil.findText(el);
132
            }
133
            }
133
            el = Util.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
134
            el = XMLUtil.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
134
            if (el != null) {
135
            if (el != null) {
135
                sf.location = Util.findText(el);
136
                sf.location = XMLUtil.findText(el);
136
            }
137
            }
137
            el = Util.findElement(sourceFolderEl, "includes", Util.NAMESPACE); // NOI18N
138
            el = XMLUtil.findElement(sourceFolderEl, "includes", Util.NAMESPACE); // NOI18N
138
            if (el != null) {
139
            if (el != null) {
139
                sf.includes = Util.findText(el);
140
                sf.includes = XMLUtil.findText(el);
140
            }
141
            }
141
            el = Util.findElement(sourceFolderEl, "excludes", Util.NAMESPACE); // NOI18N
142
            el = XMLUtil.findElement(sourceFolderEl, "excludes", Util.NAMESPACE); // NOI18N
142
            if (el != null) {
143
            if (el != null) {
143
                sf.excludes = Util.findText(el);
144
                sf.excludes = XMLUtil.findText(el);
144
            }
145
            }
145
            el = Util.findElement(sourceFolderEl, "encoding", Util.NAMESPACE); // NOI18N
146
            el = XMLUtil.findElement(sourceFolderEl, "encoding", Util.NAMESPACE); // NOI18N
146
            if (el != null) {
147
            if (el != null) {
147
                sf.encoding = Util.findText(el);
148
                sf.encoding = XMLUtil.findText(el);
148
            }
149
            }
149
            if (type == null || type.equals(sf.type)) {
150
            if (type == null || type.equals(sf.type)) {
150
                if (sf.label == null || sf.label.length() == 0) {
151
                if (sf.label == null || sf.label.length() == 0) {
Lines 173-193 Link Here
173
        //assert ProjectManager.mutex().isWriteAccess();
174
        //assert ProjectManager.mutex().isWriteAccess();
174
        Element data = Util.getPrimaryConfigurationData(helper);
175
        Element data = Util.getPrimaryConfigurationData(helper);
175
        Document doc = data.getOwnerDocument();
176
        Document doc = data.getOwnerDocument();
176
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
177
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
177
        if (foldersEl == null) {
178
        if (foldersEl == null) {
178
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
179
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
179
            Util.appendChildElement(data, foldersEl, rootElementsOrder);
180
            XMLUtil.appendChildElement(data, foldersEl, rootElementsOrder);
180
        } else {
181
        } else {
181
            for (Element sourceFolderEl : Util.findSubElements(foldersEl)) {
182
            for (Element sourceFolderEl : XMLUtil.findSubElements(foldersEl)) {
182
                if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
183
                if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
183
                    continue;
184
                    continue;
184
                }
185
                }
185
                if (type == null) {
186
                if (type == null) {
186
                    foldersEl.removeChild(sourceFolderEl);
187
                    foldersEl.removeChild(sourceFolderEl);
187
                } else {
188
                } else {
188
                    Element typeEl = Util.findElement(sourceFolderEl, "type", Util.NAMESPACE); // NOI18N
189
                    Element typeEl = XMLUtil.findElement(sourceFolderEl, "type", Util.NAMESPACE); // NOI18N
189
                    if (typeEl != null) {
190
                    if (typeEl != null) {
190
                        String typeElValue = Util.findText(typeEl);
191
                        String typeElValue = XMLUtil.findText(typeEl);
191
                        if (type.equals(typeElValue)) {
192
                        if (type.equals(typeElValue)) {
192
                            foldersEl.removeChild(sourceFolderEl);
193
                            foldersEl.removeChild(sourceFolderEl);
193
                        }
194
                        }
Lines 232-238 Link Here
232
                el.appendChild(doc.createTextNode(sf.encoding)); // NOI18N
233
                el.appendChild(doc.createTextNode(sf.encoding)); // NOI18N
233
                sourceFolderEl.appendChild(el);
234
                sourceFolderEl.appendChild(el);
234
            }
235
            }
235
            Util.appendChildElement(foldersEl, sourceFolderEl, folderElementsOrder);
236
            XMLUtil.appendChildElement(foldersEl, sourceFolderEl, folderElementsOrder);
236
        }
237
        }
237
        Util.putPrimaryConfigurationData(helper, data);
238
        Util.putPrimaryConfigurationData(helper, data);
238
    }
239
    }
Lines 249-284 Link Here
249
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
250
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
250
        List<SourceFolder> list = new ArrayList<SourceFolder>();
251
        List<SourceFolder> list = new ArrayList<SourceFolder>();
251
        Element data = Util.getPrimaryConfigurationData(helper);
252
        Element data = Util.getPrimaryConfigurationData(helper);
252
        Element viewEl = Util.findElement(data, "view", Util.NAMESPACE); // NOI18N
253
        Element viewEl = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
253
        if (viewEl == null) {
254
        if (viewEl == null) {
254
            return list;
255
            return list;
255
        }
256
        }
256
        Element itemsEl = Util.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
257
        Element itemsEl = XMLUtil.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
257
        if (itemsEl == null) {
258
        if (itemsEl == null) {
258
            return list;
259
            return list;
259
        }
260
        }
260
        for (Element sourceFolderEl : Util.findSubElements(itemsEl)) {
261
        for (Element sourceFolderEl : XMLUtil.findSubElements(itemsEl)) {
261
            if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
262
            if (!sourceFolderEl.getLocalName().equals("source-folder")) { // NOI18N
262
                continue;
263
                continue;
263
            }
264
            }
264
            SourceFolder sf = new SourceFolder();
265
            SourceFolder sf = new SourceFolder();
265
            sf.style = sourceFolderEl.getAttribute("style"); // NOI18N
266
            sf.style = sourceFolderEl.getAttribute("style"); // NOI18N
266
            assert sf.style != null && sf.style.length() > 0 : "Bad style attr on <source-folder> in " + helper; // NOI18N
267
            assert sf.style != null && sf.style.length() > 0 : "Bad style attr on <source-folder> in " + helper; // NOI18N
267
            Element el = Util.findElement(sourceFolderEl, "label", Util.NAMESPACE); // NOI18N
268
            Element el = XMLUtil.findElement(sourceFolderEl, "label", Util.NAMESPACE); // NOI18N
268
            if (el != null) {
269
            if (el != null) {
269
                sf.label = Util.findText(el);
270
                sf.label = XMLUtil.findText(el);
270
            }
271
            }
271
            el = Util.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
272
            el = XMLUtil.findElement(sourceFolderEl, "location", Util.NAMESPACE); // NOI18N
272
            if (el != null) {
273
            if (el != null) {
273
                sf.location = Util.findText(el);
274
                sf.location = XMLUtil.findText(el);
274
            }
275
            }
275
            el = Util.findElement(sourceFolderEl, "includes", Util.NAMESPACE); // NOI18N
276
            el = XMLUtil.findElement(sourceFolderEl, "includes", Util.NAMESPACE); // NOI18N
276
            if (el != null) {
277
            if (el != null) {
277
                sf.includes = Util.findText(el);
278
                sf.includes = XMLUtil.findText(el);
278
            }
279
            }
279
            el = Util.findElement(sourceFolderEl, "excludes", Util.NAMESPACE); // NOI18N
280
            el = XMLUtil.findElement(sourceFolderEl, "excludes", Util.NAMESPACE); // NOI18N
280
            if (el != null) {
281
            if (el != null) {
281
                sf.excludes = Util.findText(el);
282
                sf.excludes = XMLUtil.findText(el);
282
            }
283
            }
283
            if (style == null || style.equals(sf.style)) {
284
            if (style == null || style.equals(sf.style)) {
284
                list.add(sf);
285
                list.add(sf);
Lines 303-319 Link Here
303
        ArrayList list = new ArrayList();
304
        ArrayList list = new ArrayList();
304
        Element data = Util.getPrimaryConfigurationData(helper);
305
        Element data = Util.getPrimaryConfigurationData(helper);
305
        Document doc = data.getOwnerDocument();
306
        Document doc = data.getOwnerDocument();
306
        Element viewEl = Util.findElement(data, "view", Util.NAMESPACE); // NOI18N
307
        Element viewEl = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
307
        if (viewEl == null) {
308
        if (viewEl == null) {
308
            viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N
309
            viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N
309
            Util.appendChildElement(data, viewEl, rootElementsOrder);
310
            XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
310
        }
311
        }
311
        Element itemsEl = Util.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
312
        Element itemsEl = XMLUtil.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
312
        if (itemsEl == null) {
313
        if (itemsEl == null) {
313
            itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N
314
            itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N
314
            Util.appendChildElement(viewEl, itemsEl, viewElementsOrder);
315
            XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder);
315
        }
316
        }
316
        List<Element> sourceViews = Util.findSubElements(itemsEl);
317
        List<Element> sourceViews = XMLUtil.findSubElements(itemsEl);
317
        Iterator it = sourceViews.iterator();
318
        Iterator it = sourceViews.iterator();
318
        while (it.hasNext()) {
319
        while (it.hasNext()) {
319
            Element sourceViewEl = (Element)it.next();
320
            Element sourceViewEl = (Element)it.next();
Lines 355-361 Link Here
355
                el.appendChild(doc.createTextNode(sf.excludes)); // NOI18N
356
                el.appendChild(doc.createTextNode(sf.excludes)); // NOI18N
356
                sourceFolderEl.appendChild(el);
357
                sourceFolderEl.appendChild(el);
357
            }
358
            }
358
            Util.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
359
            XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
359
        }
360
        }
360
        Util.putPrimaryConfigurationData(helper, data);
361
        Util.putPrimaryConfigurationData(helper, data);
361
    }
362
    }
Lines 390-409 Link Here
390
        if (data == null) {
391
        if (data == null) {
391
            return list;
392
            return list;
392
        }
393
        }
393
        for (Element cuEl : Util.findSubElements(data)) {
394
        for (Element cuEl : XMLUtil.findSubElements(data)) {
394
            JavaCompilationUnit cu = new JavaCompilationUnit();
395
            JavaCompilationUnit cu = new JavaCompilationUnit();
395
            List<String> outputs = new ArrayList<String>();
396
            List<String> outputs = new ArrayList<String>();
396
            List<String> javadoc = new ArrayList<String>();
397
            List<String> javadoc = new ArrayList<String>();
397
            List<JavaCompilationUnit.CP> cps = new ArrayList<JavaCompilationUnit.CP>();
398
            List<JavaCompilationUnit.CP> cps = new ArrayList<JavaCompilationUnit.CP>();
398
            List<String> packageRoots = new ArrayList<String>();
399
            List<String> packageRoots = new ArrayList<String>();
399
            for (Element el : Util.findSubElements(cuEl)) {
400
            for (Element el : XMLUtil.findSubElements(cuEl)) {
400
                if (el.getLocalName().equals("package-root")) { // NOI18N
401
                if (el.getLocalName().equals("package-root")) { // NOI18N
401
                    packageRoots.add(Util.findText(el));
402
                    packageRoots.add(XMLUtil.findText(el));
402
                    continue;
403
                    continue;
403
                }
404
                }
404
                if (el.getLocalName().equals("classpath")) { // NOI18N
405
                if (el.getLocalName().equals("classpath")) { // NOI18N
405
                    JavaCompilationUnit.CP cp = new JavaCompilationUnit.CP();
406
                    JavaCompilationUnit.CP cp = new JavaCompilationUnit.CP();
406
                    cp.classpath = Util.findText(el);
407
                    cp.classpath = XMLUtil.findText(el);
407
                    cp.mode = el.getAttribute("mode"); // NOI18N
408
                    cp.mode = el.getAttribute("mode"); // NOI18N
408
                    if (cp.mode != null && cp.classpath != null) {
409
                    if (cp.mode != null && cp.classpath != null) {
409
                        cps.add(cp);
410
                        cps.add(cp);
Lines 411-425 Link Here
411
                    continue;
412
                    continue;
412
                }
413
                }
413
                if (el.getLocalName().equals("built-to")) { // NOI18N
414
                if (el.getLocalName().equals("built-to")) { // NOI18N
414
                    outputs.add(Util.findText(el));
415
                    outputs.add(XMLUtil.findText(el));
415
                    continue;
416
                    continue;
416
                }
417
                }
417
                if (el.getLocalName().equals("javadoc-built-to")) { // NOI18N
418
                if (el.getLocalName().equals("javadoc-built-to")) { // NOI18N
418
                    javadoc.add(Util.findText(el));
419
                    javadoc.add(XMLUtil.findText(el));
419
                    continue;
420
                    continue;
420
                }
421
                }
421
                if (el.getLocalName().equals("source-level")) { // NOI18N
422
                if (el.getLocalName().equals("source-level")) { // NOI18N
422
                    cu.sourceLevel = Util.findText(el);
423
                    cu.sourceLevel = XMLUtil.findText(el);
423
                }
424
                }
424
                if (el.getLocalName().equals("unit-tests")) { // NOI18N
425
                if (el.getLocalName().equals("unit-tests")) { // NOI18N
425
                    cu.isTests = true;
426
                    cu.isTests = true;
Lines 503-509 Link Here
503
            }
504
            }
504
        }
505
        }
505
        Document doc = data.getOwnerDocument();
506
        Document doc = data.getOwnerDocument();
506
        for (Element cuEl : Util.findSubElements(data)) {
507
        for (Element cuEl : XMLUtil.findSubElements(data)) {
507
            data.removeChild(cuEl);
508
            data.removeChild(cuEl);
508
        }
509
        }
509
        for (JavaCompilationUnit cu : compUnits) {
510
        for (JavaCompilationUnit cu : compUnits) {
Lines 656-662 Link Here
656
        ArrayList list = new ArrayList();
657
        ArrayList list = new ArrayList();
657
        Element data = Util.getPrimaryConfigurationData(helper);
658
        Element data = Util.getPrimaryConfigurationData(helper);
658
        Document doc = data.getOwnerDocument();
659
        Document doc = data.getOwnerDocument();
659
        Iterator it = Util.findSubElements(data).iterator();
660
        Iterator it = XMLUtil.findSubElements(data).iterator();
660
        while (it.hasNext()) {
661
        while (it.hasNext()) {
661
            Element exportEl = (Element)it.next();
662
            Element exportEl = (Element)it.next();
662
            if (!exportEl.getLocalName().equals("export")) { // NOI18N
663
            if (!exportEl.getLocalName().equals("export")) { // NOI18N
Lines 688-694 Link Here
688
                el.appendChild(doc.createTextNode(export.cleanTarget)); // NOI18N
689
                el.appendChild(doc.createTextNode(export.cleanTarget)); // NOI18N
689
                exportEl.appendChild(el);
690
                exportEl.appendChild(el);
690
            }
691
            }
691
            Util.appendChildElement(data, exportEl, rootElementsOrder);
692
            XMLUtil.appendChildElement(data, exportEl, rootElementsOrder);
692
        }
693
        }
693
        Util.putPrimaryConfigurationData(helper, data);
694
        Util.putPrimaryConfigurationData(helper, data);
694
    }
695
    }
Lines 736-747 Link Here
736
        ArrayList list = new ArrayList();
737
        ArrayList list = new ArrayList();
737
        Element data = Util.getPrimaryConfigurationData(helper);
738
        Element data = Util.getPrimaryConfigurationData(helper);
738
        Document doc = data.getOwnerDocument();
739
        Document doc = data.getOwnerDocument();
739
        Element subproject = Util.findElement(data, "subprojects", Util.NAMESPACE); // NOI18N
740
        Element subproject = XMLUtil.findElement(data, "subprojects", Util.NAMESPACE); // NOI18N
740
        if (subproject != null) {
741
        if (subproject != null) {
741
            data.removeChild(subproject);
742
            data.removeChild(subproject);
742
        }
743
        }
743
        subproject = doc.createElementNS(Util.NAMESPACE, "subprojects"); // NOI18N
744
        subproject = doc.createElementNS(Util.NAMESPACE, "subprojects"); // NOI18N
744
        Util.appendChildElement(data, subproject, rootElementsOrder);
745
        XMLUtil.appendChildElement(data, subproject, rootElementsOrder);
745
        
746
        
746
        Iterator it = subprojects.iterator();
747
        Iterator it = subprojects.iterator();
747
        while (it.hasNext()) {
748
        while (it.hasNext()) {
Lines 819-830 Link Here
819
    private static void putBuildElement(AntProjectHelper helper, List<String> buildFolders, String elemName) {
820
    private static void putBuildElement(AntProjectHelper helper, List<String> buildFolders, String elemName) {
820
        Element data = Util.getPrimaryConfigurationData(helper);
821
        Element data = Util.getPrimaryConfigurationData(helper);
821
        Document doc = data.getOwnerDocument();
822
        Document doc = data.getOwnerDocument();
822
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
823
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
823
        if (foldersEl == null) {
824
        if (foldersEl == null) {
824
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
825
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
825
            Util.appendChildElement(data, foldersEl, rootElementsOrder);
826
            XMLUtil.appendChildElement(data, foldersEl, rootElementsOrder);
826
        } else {
827
        } else {
827
            List<Element> folders = Util.findSubElements(foldersEl);
828
            List<Element> folders = XMLUtil.findSubElements(foldersEl);
828
            Iterator it = folders.iterator();
829
            Iterator it = folders.iterator();
829
            while (it.hasNext()) {
830
            while (it.hasNext()) {
830
                Element buildFolderEl = (Element)it.next();
831
                Element buildFolderEl = (Element)it.next();
Lines 841-847 Link Here
841
            Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
842
            Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
842
            locationEl.appendChild(doc.createTextNode(location));
843
            locationEl.appendChild(doc.createTextNode(location));
843
            buildFolderEl.appendChild(locationEl);
844
            buildFolderEl.appendChild(locationEl);
844
            Util.appendChildElement(foldersEl, buildFolderEl, folderElementsOrder);
845
            XMLUtil.appendChildElement(foldersEl, buildFolderEl, folderElementsOrder);
845
        }
846
        }
846
        Util.putPrimaryConfigurationData(helper, data);
847
        Util.putPrimaryConfigurationData(helper, data);
847
    }
848
    }
Lines 900-946 Link Here
900
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
901
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
901
        List<TargetMapping> list = new ArrayList<TargetMapping>();
902
        List<TargetMapping> list = new ArrayList<TargetMapping>();
902
        Element genldata = Util.getPrimaryConfigurationData(helper);
903
        Element genldata = Util.getPrimaryConfigurationData(helper);
903
        Element actionsEl = Util.findElement(genldata, "ide-actions", Util.NAMESPACE); // NOI18N
904
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", Util.NAMESPACE); // NOI18N
904
        if (actionsEl == null) {
905
        if (actionsEl == null) {
905
            return list;
906
            return list;
906
        }
907
        }
907
        for (Element actionEl : Util.findSubElements(actionsEl)) {
908
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
908
            TargetMapping tm = new TargetMapping();
909
            TargetMapping tm = new TargetMapping();
909
            tm.name = actionEl.getAttribute("name"); // NOI18N
910
            tm.name = actionEl.getAttribute("name"); // NOI18N
910
            List<String> targetNames = new ArrayList<String>();
911
            List<String> targetNames = new ArrayList<String>();
911
            EditableProperties props = new EditableProperties(false);
912
            EditableProperties props = new EditableProperties(false);
912
            for (Element subEl : Util.findSubElements(actionEl)) {
913
            for (Element subEl : XMLUtil.findSubElements(actionEl)) {
913
                if (subEl.getLocalName().equals("target")) { // NOI18N
914
                if (subEl.getLocalName().equals("target")) { // NOI18N
914
                    targetNames.add(Util.findText(subEl));
915
                    targetNames.add(XMLUtil.findText(subEl));
915
                    continue;
916
                    continue;
916
                }
917
                }
917
                if (subEl.getLocalName().equals("script")) { // NOI18N
918
                if (subEl.getLocalName().equals("script")) { // NOI18N
918
                    tm.script = Util.findText(subEl);
919
                    tm.script = XMLUtil.findText(subEl);
919
                    continue;
920
                    continue;
920
                }
921
                }
921
                if (subEl.getLocalName().equals("context")) { // NOI18N
922
                if (subEl.getLocalName().equals("context")) { // NOI18N
922
                    TargetMapping.Context ctx = new TargetMapping.Context();
923
                    TargetMapping.Context ctx = new TargetMapping.Context();
923
                    for (Element contextSubEl : Util.findSubElements(subEl)) {
924
                    for (Element contextSubEl : XMLUtil.findSubElements(subEl)) {
924
                        if (contextSubEl.getLocalName().equals("property")) { // NOI18N
925
                        if (contextSubEl.getLocalName().equals("property")) { // NOI18N
925
                            ctx.property = Util.findText(contextSubEl);
926
                            ctx.property = XMLUtil.findText(contextSubEl);
926
                            continue;
927
                            continue;
927
                        }
928
                        }
928
                        if (contextSubEl.getLocalName().equals("format")) { // NOI18N
929
                        if (contextSubEl.getLocalName().equals("format")) { // NOI18N
929
                            ctx.format = Util.findText(contextSubEl);
930
                            ctx.format = XMLUtil.findText(contextSubEl);
930
                            continue;
931
                            continue;
931
                        }
932
                        }
932
                        if (contextSubEl.getLocalName().equals("folder")) { // NOI18N
933
                        if (contextSubEl.getLocalName().equals("folder")) { // NOI18N
933
                            ctx.folder = Util.findText(contextSubEl);
934
                            ctx.folder = XMLUtil.findText(contextSubEl);
934
                            continue;
935
                            continue;
935
                        }
936
                        }
936
                        if (contextSubEl.getLocalName().equals("pattern")) { // NOI18N
937
                        if (contextSubEl.getLocalName().equals("pattern")) { // NOI18N
937
                            ctx.pattern = Util.findText(contextSubEl);
938
                            ctx.pattern = XMLUtil.findText(contextSubEl);
938
                            continue;
939
                            continue;
939
                        }
940
                        }
940
                        if (contextSubEl.getLocalName().equals("arity")) { // NOI18N
941
                        if (contextSubEl.getLocalName().equals("arity")) { // NOI18N
941
                            Element sepFilesEl = Util.findElement(contextSubEl, "separated-files", Util.NAMESPACE); // NOI18N
942
                            Element sepFilesEl = XMLUtil.findElement(contextSubEl, "separated-files", Util.NAMESPACE); // NOI18N
942
                            if (sepFilesEl != null) {
943
                            if (sepFilesEl != null) {
943
                                ctx.separator = Util.findText(sepFilesEl);
944
                                ctx.separator = XMLUtil.findText(sepFilesEl);
944
                            }
945
                            }
945
                            continue;
946
                            continue;
946
                        }
947
                        }
Lines 994-1000 Link Here
994
    
995
    
995
    private static void readProperty(Element propertyElement, EditableProperties props) {
996
    private static void readProperty(Element propertyElement, EditableProperties props) {
996
        String key = propertyElement.getAttribute("name"); // NOI18N
997
        String key = propertyElement.getAttribute("name"); // NOI18N
997
        String value = Util.findText(propertyElement);
998
        String value = XMLUtil.findText(propertyElement);
998
        props.setProperty(key, value);
999
        props.setProperty(key, value);
999
    }
1000
    }
1000
1001
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/JavadocQuery.java (-6 / +6 lines)
Lines 47-58 Link Here
47
import java.util.List;
47
import java.util.List;
48
import javax.swing.event.ChangeListener;
48
import javax.swing.event.ChangeListener;
49
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
49
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
50
import org.netbeans.modules.ant.freeform.spi.support.Util;
51
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
50
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
52
import org.netbeans.spi.project.AuxiliaryConfiguration;
51
import org.netbeans.spi.project.AuxiliaryConfiguration;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
54
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
53
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
55
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.xml.XMLUtil;
56
import org.w3c.dom.Element;
56
import org.w3c.dom.Element;
57
57
58
/**
58
/**
Lines 74-85 Link Here
74
    public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
74
    public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
75
        Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true);
75
        Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true);
76
        if (data != null) {
76
        if (data != null) {
77
            for (Element cu : Util.findSubElements(data)) {
77
            for (Element cu : XMLUtil.findSubElements(data)) {
78
                assert cu.getLocalName().equals("compilation-unit") : cu;
78
                assert cu.getLocalName().equals("compilation-unit") : cu;
79
                boolean rightCU = false;
79
                boolean rightCU = false;
80
                for (Element builtTo : Util.findSubElements(cu)) {
80
                for (Element builtTo : XMLUtil.findSubElements(cu)) {
81
                    if (builtTo.getLocalName().equals("built-to")) { // NOI18N
81
                    if (builtTo.getLocalName().equals("built-to")) { // NOI18N
82
                        String rawtext = Util.findText(builtTo);
82
                        String rawtext = XMLUtil.findText(builtTo);
83
                        assert rawtext != null;
83
                        assert rawtext != null;
84
                        String evaltext = eval.evaluate(rawtext);
84
                        String evaltext = eval.evaluate(rawtext);
85
                        if (evaltext != null) {
85
                        if (evaltext != null) {
Lines 95-103 Link Here
95
                }
95
                }
96
                if (rightCU) {
96
                if (rightCU) {
97
                    List<URL> resultURLs = new ArrayList<URL>();
97
                    List<URL> resultURLs = new ArrayList<URL>();
98
                    for (Element javadocTo : Util.findSubElements(cu)) {
98
                    for (Element javadocTo : XMLUtil.findSubElements(cu)) {
99
                        if (javadocTo.getLocalName().equals("javadoc-built-to")) { // NOI18N
99
                        if (javadocTo.getLocalName().equals("javadoc-built-to")) { // NOI18N
100
                            String rawtext = Util.findText(javadocTo);
100
                            String rawtext = XMLUtil.findText(javadocTo);
101
                            assert rawtext != null;
101
                            assert rawtext != null;
102
                            String evaltext = eval.evaluate(rawtext);
102
                            String evaltext = eval.evaluate(rawtext);
103
                            if (evaltext != null) {
103
                            if (evaltext != null) {
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/SourceForBinaryQueryImpl.java (-4 / +4 lines)
Lines 50-56 Link Here
50
import javax.swing.event.ChangeListener;
50
import javax.swing.event.ChangeListener;
51
import org.netbeans.api.java.queries.SourceForBinaryQuery;
51
import org.netbeans.api.java.queries.SourceForBinaryQuery;
52
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.api.project.ProjectManager;
53
import org.netbeans.modules.ant.freeform.spi.support.Util;
54
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
53
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
54
import org.netbeans.spi.project.AuxiliaryConfiguration;
56
import org.netbeans.spi.project.support.ant.AntProjectEvent;
55
import org.netbeans.spi.project.support.ant.AntProjectEvent;
Lines 60-65 Link Here
60
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
61
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.FileUtil;
62
import org.openide.util.Mutex;
61
import org.openide.util.Mutex;
62
import org.openide.xml.XMLUtil;
63
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
64
64
65
/**
65
/**
Lines 100-106 Link Here
100
            if (java == null) {
100
            if (java == null) {
101
                return null;
101
                return null;
102
            }
102
            }
103
            for (Element compilationUnit : Util.findSubElements(java)) {
103
            for (Element compilationUnit : XMLUtil.findSubElements(java)) {
104
                assert compilationUnit.getLocalName().equals("compilation-unit") : compilationUnit;
104
                assert compilationUnit.getLocalName().equals("compilation-unit") : compilationUnit;
105
                List<URL> binaries = findBinaries(compilationUnit);
105
                List<URL> binaries = findBinaries(compilationUnit);
106
                if (!binaries.isEmpty()) {
106
                if (!binaries.isEmpty()) {
Lines 137-147 Link Here
137
     */
137
     */
138
    private List<URL> findBinaries(Element compilationUnitEl) {
138
    private List<URL> findBinaries(Element compilationUnitEl) {
139
        List<URL> binaries = new ArrayList<URL>();
139
        List<URL> binaries = new ArrayList<URL>();
140
        for (Element builtToEl : Util.findSubElements(compilationUnitEl)) {
140
        for (Element builtToEl : XMLUtil.findSubElements(compilationUnitEl)) {
141
            if (!builtToEl.getLocalName().equals("built-to")) { // NOI18N
141
            if (!builtToEl.getLocalName().equals("built-to")) { // NOI18N
142
                continue;
142
                continue;
143
            }
143
            }
144
            String text = Util.findText(builtToEl);
144
            String text = XMLUtil.findText(builtToEl);
145
            String textEval = evaluator.evaluate(text);
145
            String textEval = evaluator.evaluate(text);
146
            if (textEval == null) {
146
            if (textEval == null) {
147
                continue;
147
                continue;
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java (-4 / +4 lines)
Lines 45-51 Link Here
45
import java.util.Map;
45
import java.util.Map;
46
import java.util.WeakHashMap;
46
import java.util.WeakHashMap;
47
import org.netbeans.api.project.ProjectManager;
47
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.modules.ant.freeform.spi.support.Util;
49
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
48
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation;
50
import org.netbeans.spi.project.AuxiliaryConfiguration;
49
import org.netbeans.spi.project.AuxiliaryConfiguration;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
Lines 54-59 Link Here
54
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
56
import org.openide.util.Mutex;
55
import org.openide.util.Mutex;
56
import org.openide.xml.XMLUtil;
57
import org.w3c.dom.Element;
57
import org.w3c.dom.Element;
58
58
59
/**
59
/**
Lines 102-108 Link Here
102
        if (java == null) {
102
        if (java == null) {
103
            return null;
103
            return null;
104
        }
104
        }
105
        for (Element compilationUnitEl : Util.findSubElements(java)) {
105
        for (Element compilationUnitEl : XMLUtil.findSubElements(java)) {
106
            assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
106
            assert compilationUnitEl.getLocalName().equals("compilation-unit") : compilationUnitEl;
107
            List<FileObject> packageRoots = Classpaths.findPackageRoots(helper, evaluator, compilationUnitEl);
107
            List<FileObject> packageRoots = Classpaths.findPackageRoots(helper, evaluator, compilationUnitEl);
108
            for (FileObject root : packageRoots) {
108
            for (FileObject root : packageRoots) {
Lines 133-141 Link Here
133
     * Get the source level indicated in a compilation unit (or null if none is indicated).
133
     * Get the source level indicated in a compilation unit (or null if none is indicated).
134
     */
134
     */
135
    private String getLevel(Element compilationUnitEl) {
135
    private String getLevel(Element compilationUnitEl) {
136
        Element sourceLevelEl = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3);
136
        Element sourceLevelEl = XMLUtil.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3);
137
        if (sourceLevelEl != null) {
137
        if (sourceLevelEl != null) {
138
            return Util.findText(sourceLevelEl);
138
            return XMLUtil.findText(sourceLevelEl);
139
        } else {
139
        } else {
140
            return null;
140
            return null;
141
        }
141
        }
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/TestQuery.java (-5 / +5 lines)
Lines 46-52 Link Here
46
import java.util.ArrayList;
46
import java.util.ArrayList;
47
import java.util.Arrays;
47
import java.util.Arrays;
48
import java.util.List;
48
import java.util.List;
49
import org.netbeans.modules.ant.freeform.spi.support.Util;
50
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
49
import org.netbeans.spi.java.queries.MultipleRootsUnitTestForSourceQueryImplementation;
51
import org.netbeans.spi.project.AuxiliaryConfiguration;
50
import org.netbeans.spi.project.AuxiliaryConfiguration;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
Lines 54-59 Link Here
54
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileStateInvalidException;
54
import org.openide.filesystems.FileStateInvalidException;
56
import org.openide.filesystems.FileUtil;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.xml.XMLUtil;
57
import org.w3c.dom.Element;
57
import org.w3c.dom.Element;
58
58
59
/**
59
/**
Lines 117-128 Link Here
117
        List<URL> tests = new ArrayList<URL>();
117
        List<URL> tests = new ArrayList<URL>();
118
        Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true);
118
        Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true);
119
        if (data != null) {
119
        if (data != null) {
120
            for (Element cu : Util.findSubElements(data)) {
120
            for (Element cu : XMLUtil.findSubElements(data)) {
121
                assert cu.getLocalName().equals("compilation-unit") : cu;
121
                assert cu.getLocalName().equals("compilation-unit") : cu;
122
                boolean isTests = Util.findElement(cu, "unit-tests", JavaProjectNature.NS_JAVA_3) != null; // NOI18N
122
                boolean isTests = XMLUtil.findElement(cu, "unit-tests", JavaProjectNature.NS_JAVA_3) != null; // NOI18N
123
                for (Element pr : Util.findSubElements(cu)) {
123
                for (Element pr : XMLUtil.findSubElements(cu)) {
124
                    if (pr.getLocalName().equals("package-root")) { // NOI18N
124
                    if (pr.getLocalName().equals("package-root")) { // NOI18N
125
                        String rawtext = Util.findText(pr);
125
                        String rawtext = XMLUtil.findText(pr);
126
                        assert rawtext != null;
126
                        assert rawtext != null;
127
                        String evaltext = eval.evaluate(rawtext);
127
                        String evaltext = eval.evaluate(rawtext);
128
                        if (evaltext != null) {
128
                        if (evaltext != null) {
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/UsageLogger.java (-4 / +4 lines)
Lines 51-57 Link Here
51
import org.netbeans.api.project.ProjectUtils;
51
import org.netbeans.api.project.ProjectUtils;
52
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
52
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
53
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
53
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
54
import org.netbeans.spi.project.AuxiliaryConfiguration;
56
import org.netbeans.spi.project.support.ant.AntProjectHelper;
55
import org.netbeans.spi.project.support.ant.AntProjectHelper;
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
56
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
Lines 61-66 Link Here
61
import org.openide.util.Exceptions;
60
import org.openide.util.Exceptions;
62
import org.openide.util.NbBundle;
61
import org.openide.util.NbBundle;
63
import org.openide.util.RequestProcessor;
62
import org.openide.util.RequestProcessor;
63
import org.openide.xml.XMLUtil;
64
import org.w3c.dom.Element;
64
import org.w3c.dom.Element;
65
65
66
/**
66
/**
Lines 109-126 Link Here
109
        Set<String> classpathEntries = new HashSet<String>();
109
        Set<String> classpathEntries = new HashSet<String>();
110
        Element java = JavaProjectGenerator.getJavaCompilationUnits(aux);
110
        Element java = JavaProjectGenerator.getJavaCompilationUnits(aux);
111
        if (java != null) {
111
        if (java != null) {
112
            for (Element compilationUnitEl : Util.findSubElements(java)) {
112
            for (Element compilationUnitEl : XMLUtil.findSubElements(java)) {
113
                compilationUnits++;
113
                compilationUnits++;
114
                int builtTos = 0;
114
                int builtTos = 0;
115
                int roots = 0;
115
                int roots = 0;
116
                for (Element other : Util.findSubElements(compilationUnitEl)) {
116
                for (Element other : XMLUtil.findSubElements(compilationUnitEl)) {
117
                    String name = other.getLocalName();
117
                    String name = other.getLocalName();
118
                    if (name.equals("package-root")) { // NOI18N
118
                    if (name.equals("package-root")) { // NOI18N
119
                        roots++;
119
                        roots++;
120
                    } else if (name.equals("built-to")) { // NOI18N
120
                    } else if (name.equals("built-to")) { // NOI18N
121
                        builtTos++;
121
                        builtTos++;
122
                    } else if (name.equals("classpath")) { // NOI18N
122
                    } else if (name.equals("classpath")) { // NOI18N
123
                        String text = Util.findText(other);
123
                        String text = XMLUtil.findText(other);
124
                        if (text != null) {
124
                        if (text != null) {
125
                            String textEval = eval.evaluate(text);
125
                            String textEval = eval.evaluate(text);
126
                            if (textEval != null) {
126
                            if (textEval != null) {
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/jdkselection/JdkConfiguration.java (-10 / +9 lines)
Lines 53-59 Link Here
53
import org.netbeans.api.project.ProjectManager;
53
import org.netbeans.api.project.ProjectManager;
54
import org.netbeans.api.project.ProjectUtils;
54
import org.netbeans.api.project.ProjectUtils;
55
import org.netbeans.modules.ant.freeform.spi.support.Util;
55
import org.netbeans.modules.ant.freeform.spi.support.Util;
56
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
57
import org.netbeans.spi.project.support.ant.AntProjectHelper;
56
import org.netbeans.spi.project.support.ant.AntProjectHelper;
58
import org.netbeans.spi.project.support.ant.EditableProperties;
57
import org.netbeans.spi.project.support.ant.EditableProperties;
59
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
58
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
Lines 163-179 Link Here
163
        Element projectE = nbjdkDoc.getDocumentElement();
162
        Element projectE = nbjdkDoc.getDocumentElement();
164
        Set<String> targetsCreated = new HashSet<String>();
163
        Set<String> targetsCreated = new HashSet<String>();
165
        // XXX remove any definition of ${ant.script}, which will by now be obsolete
164
        // XXX remove any definition of ${ant.script}, which will by now be obsolete
166
        Element ideActionsE = Util.findElement(generalDataE, "ide-actions", Util.NAMESPACE);
165
        Element ideActionsE = XMLUtil.findElement(generalDataE, "ide-actions", Util.NAMESPACE);
167
        if (ideActionsE != null) {
166
        if (ideActionsE != null) {
168
            for (Element actionE : Util.findSubElements(ideActionsE)) {
167
            for (Element actionE : XMLUtil.findSubElements(ideActionsE)) {
169
                rebindAction(actionE, projectE, targetsCreated);
168
                rebindAction(actionE, projectE, targetsCreated);
170
            }
169
            }
171
        }
170
        }
172
        Element viewE = Util.findElement(generalDataE, "ide-actions", Util.NAMESPACE);
171
        Element viewE = XMLUtil.findElement(generalDataE, "ide-actions", Util.NAMESPACE);
173
        if (viewE != null) {
172
        if (viewE != null) {
174
            Element contextMenuE = Util.findElement(viewE, "context-menu", Util.NAMESPACE);
173
            Element contextMenuE = XMLUtil.findElement(viewE, "context-menu", Util.NAMESPACE);
175
            if (contextMenuE != null) {
174
            if (contextMenuE != null) {
176
                for (Element actionE : Util.findSubElements(contextMenuE)) {
175
                for (Element actionE : XMLUtil.findSubElements(contextMenuE)) {
177
                    if (!actionE.getLocalName().equals("action")) {
176
                    if (!actionE.getLocalName().equals("action")) {
178
                        continue; // ignore <ide-action> here
177
                        continue; // ignore <ide-action> here
179
                    }
178
                    }
Lines 187-196 Link Here
187
    }
186
    }
188
187
189
    private void rebindAction(Element actionE, Element projectE, Set<String> targetsCreated) {
188
    private void rebindAction(Element actionE, Element projectE, Set<String> targetsCreated) {
190
        Element scriptE = Util.findElement(actionE, "script", Util.NAMESPACE); // NOI18N
189
        Element scriptE = XMLUtil.findElement(actionE, "script", Util.NAMESPACE); // NOI18N
191
        String script;
190
        String script;
192
        if (scriptE != null) {
191
        if (scriptE != null) {
193
            script = Util.findText(scriptE);
192
            script = XMLUtil.findText(scriptE);
194
            actionE.removeChild(scriptE);
193
            actionE.removeChild(scriptE);
195
        } else {
194
        } else {
196
            script = "build.xml"; // NOI18N
195
            script = "build.xml"; // NOI18N
Lines 199-209 Link Here
199
        scriptE.appendChild(actionE.getOwnerDocument().createTextNode(NBJDK_XML));
198
        scriptE.appendChild(actionE.getOwnerDocument().createTextNode(NBJDK_XML));
200
        actionE.insertBefore(scriptE, actionE.getFirstChild());
199
        actionE.insertBefore(scriptE, actionE.getFirstChild());
201
        List<String> targetNames = new ArrayList<String>();
200
        List<String> targetNames = new ArrayList<String>();
202
        for (Element targetE : Util.findSubElements(actionE)) {
201
        for (Element targetE : XMLUtil.findSubElements(actionE)) {
203
            if (!targetE.getLocalName().equals("target")) { // NOI18N
202
            if (!targetE.getLocalName().equals("target")) { // NOI18N
204
                continue;
203
                continue;
205
            }
204
            }
206
            targetNames.add(Util.findText(targetE));
205
            targetNames.add(XMLUtil.findText(targetE));
207
        }
206
        }
208
        if (targetNames.isEmpty()) {
207
        if (targetNames.isEmpty()) {
209
            targetNames.add(null);
208
            targetNames.add(null);
(-)a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/ClasspathsTest.java (-2 / +3 lines)
Lines 77-82 Link Here
77
import org.openide.filesystems.FileObject;
77
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileUtil;
78
import org.openide.filesystems.FileUtil;
79
import org.openide.util.Mutex;
79
import org.openide.util.Mutex;
80
import org.openide.xml.XMLUtil;
80
import org.w3c.dom.Document;
81
import org.w3c.dom.Document;
81
import org.w3c.dom.Element;
82
import org.w3c.dom.Element;
82
83
Lines 456-462 Link Here
456
        FileUtil.createData(new File(d, "s/ignored/file"));
457
        FileUtil.createData(new File(d, "s/ignored/file"));
457
        Element data = Util.getPrimaryConfigurationData(helper);
458
        Element data = Util.getPrimaryConfigurationData(helper);
458
        Document doc = data.getOwnerDocument();
459
        Document doc = data.getOwnerDocument();
459
        Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), Util.findElement(data, "view", Util.NAMESPACE)).
460
        Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), XMLUtil.findElement(data, "view", Util.NAMESPACE)).
460
                appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
461
                appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
461
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
462
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
462
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode(JavaProjectConstants.SOURCES_TYPE_JAVA));
463
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode(JavaProjectConstants.SOURCES_TYPE_JAVA));
Lines 547-553 Link Here
547
        data.getElementsByTagName("properties").item(0).
548
        data.getElementsByTagName("properties").item(0).
548
                appendChild(doc.createElementNS(Util.NAMESPACE, "property-file")).
549
                appendChild(doc.createElementNS(Util.NAMESPACE, "property-file")).
549
                appendChild(doc.createTextNode("config.properties"));
550
                appendChild(doc.createTextNode("config.properties"));
550
        Element folders = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), Util.findElement(data, "view", Util.NAMESPACE));
551
        Element folders = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), XMLUtil.findElement(data, "view", Util.NAMESPACE));
551
        Element sf = (Element) folders.appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
552
        Element sf = (Element) folders.appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
552
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources #1"));
553
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources #1"));
553
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode(JavaProjectConstants.SOURCES_TYPE_JAVA));
554
        sf.appendChild(doc.createElementNS(Util.NAMESPACE, "type")).appendChild(doc.createTextNode(JavaProjectConstants.SOURCES_TYPE_JAVA));
(-)a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaActionsTest.java (-17 / +16 lines)
Lines 51-57 Link Here
51
import java.util.Locale;
51
import java.util.Locale;
52
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.api.project.ProjectManager;
53
import org.netbeans.modules.ant.freeform.FreeformProject;
53
import org.netbeans.modules.ant.freeform.FreeformProject;
54
import org.netbeans.modules.ant.freeform.FreeformProjectType;
55
import org.netbeans.modules.ant.freeform.TestBase;
54
import org.netbeans.modules.ant.freeform.TestBase;
56
import org.netbeans.modules.ant.freeform.spi.support.Util;
55
import org.netbeans.modules.ant.freeform.spi.support.Util;
57
import org.netbeans.spi.project.ActionProvider;
56
import org.netbeans.spi.project.ActionProvider;
Lines 88-100 Link Here
88
        prj = copyProject(simple);
87
        prj = copyProject(simple);
89
        // Remove existing context-sensitive bindings to make a clean slate.
88
        // Remove existing context-sensitive bindings to make a clean slate.
90
        Element data = prj.getPrimaryConfigurationData();
89
        Element data = prj.getPrimaryConfigurationData();
91
        Element ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
90
        Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
92
        assertNotNull(ideActions);
91
        assertNotNull(ideActions);
93
        Iterator<Element> actionsIt = Util.findSubElements(ideActions).iterator();
92
        Iterator<Element> actionsIt = XMLUtil.findSubElements(ideActions).iterator();
94
        while (actionsIt.hasNext()) {
93
        while (actionsIt.hasNext()) {
95
            Element action = actionsIt.next();
94
            Element action = actionsIt.next();
96
            assertEquals("action", action.getLocalName());
95
            assertEquals("action", action.getLocalName());
97
            if (Util.findElement(action, "context", Util.NAMESPACE) != null) {
96
            if (XMLUtil.findElement(action, "context", Util.NAMESPACE) != null) {
98
                ideActions.removeChild(action);
97
                ideActions.removeChild(action);
99
            }
98
            }
100
        }
99
        }
Lines 209-217 Link Here
209
        ja.addBinding("some.action", "special.xml", "special-target", "selection", "${some.src.dir}", "\\.java$", "relative-path", ",");
208
        ja.addBinding("some.action", "special.xml", "special-target", "selection", "${some.src.dir}", "\\.java$", "relative-path", ",");
210
        Element data = prj.getPrimaryConfigurationData();
209
        Element data = prj.getPrimaryConfigurationData();
211
        assertNotNull(data);
210
        assertNotNull(data);
212
        Element ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
211
        Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
213
        assertNotNull(ideActions);
212
        assertNotNull(ideActions);
214
        List<Element> actions = Util.findSubElements(ideActions);
213
        List<Element> actions = XMLUtil.findSubElements(ideActions);
215
        Element lastAction = actions.get(actions.size() - 1);
214
        Element lastAction = actions.get(actions.size() - 1);
216
        String expectedXml =
215
        String expectedXml =
217
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
216
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 231-238 Link Here
231
        assertEquals(expectedXml, xmlToString(lastAction));
230
        assertEquals(expectedXml, xmlToString(lastAction));
232
        ja.addBinding("some.other.action", "special.xml", "special-target", "selection", "${some.src.dir}", null, "relative-path", null);
231
        ja.addBinding("some.other.action", "special.xml", "special-target", "selection", "${some.src.dir}", null, "relative-path", null);
233
        data = prj.getPrimaryConfigurationData();
232
        data = prj.getPrimaryConfigurationData();
234
        ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
233
        ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
235
        actions = Util.findSubElements(ideActions);
234
        actions = XMLUtil.findSubElements(ideActions);
236
        lastAction = actions.get(actions.size() - 1);
235
        lastAction = actions.get(actions.size() - 1);
237
        expectedXml =
236
        expectedXml =
238
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
237
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 252-259 Link Here
252
        // Non-context-sensitive bindings have no <context> but need to add a view item.
251
        // Non-context-sensitive bindings have no <context> but need to add a view item.
253
        ja.addBinding("general.action", "special.xml", "special-target", null, null, null, null, null);
252
        ja.addBinding("general.action", "special.xml", "special-target", null, null, null, null, null);
254
        data = prj.getPrimaryConfigurationData();
253
        data = prj.getPrimaryConfigurationData();
255
        ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
254
        ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
256
        actions = Util.findSubElements(ideActions);
255
        actions = XMLUtil.findSubElements(ideActions);
257
        lastAction = actions.get(actions.size() - 1);
256
        lastAction = actions.get(actions.size() - 1);
258
        expectedXml =
257
        expectedXml =
259
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
258
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 262-273 Link Here
262
            "    <target>special-target</target>\n" +
261
            "    <target>special-target</target>\n" +
263
            "</action>\n";
262
            "</action>\n";
264
        assertEquals(expectedXml, xmlToString(lastAction));
263
        assertEquals(expectedXml, xmlToString(lastAction));
265
        Element view = Util.findElement(data, "view", Util.NAMESPACE);
264
        Element view = XMLUtil.findElement(data, "view", Util.NAMESPACE);
266
        assertNotNull(view);
265
        assertNotNull(view);
267
        Element contextMenu = Util.findElement(view, "context-menu", Util.NAMESPACE);
266
        Element contextMenu = XMLUtil.findElement(view, "context-menu", Util.NAMESPACE);
268
        assertNotNull(contextMenu);
267
        assertNotNull(contextMenu);
269
        // Currently (no FPG to help) it is always added as the last item.
268
        // Currently (no FPG to help) it is always added as the last item.
270
        List<Element> contextMenuActions = Util.findSubElements(contextMenu);
269
        List<Element> contextMenuActions = XMLUtil.findSubElements(contextMenu);
271
        Element lastContextMenuAction = contextMenuActions.get(contextMenuActions.size() - 1);
270
        Element lastContextMenuAction = contextMenuActions.get(contextMenuActions.size() - 1);
272
        expectedXml =
271
        expectedXml =
273
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
272
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 276-288 Link Here
276
        
275
        
277
        //test #58442:
276
        //test #58442:
278
        data = prj.getPrimaryConfigurationData();
277
        data = prj.getPrimaryConfigurationData();
279
        ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
278
        ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
280
        data.removeChild(ideActions);
279
        data.removeChild(ideActions);
281
        
280
        
282
        ja.addBinding("some.other.action", "special.xml", "special-target", "selection", "${some.src.dir}", null, "relative-path", null);
281
        ja.addBinding("some.other.action", "special.xml", "special-target", "selection", "${some.src.dir}", null, "relative-path", null);
283
        data = prj.getPrimaryConfigurationData();
282
        data = prj.getPrimaryConfigurationData();
284
        ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE);
283
        ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE);
285
        actions = Util.findSubElements(ideActions);
284
        actions = XMLUtil.findSubElements(ideActions);
286
        lastAction = actions.get(actions.size() - 1);
285
        lastAction = actions.get(actions.size() - 1);
287
        expectedXml =
286
        expectedXml =
288
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
287
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
Lines 460-466 Link Here
460
        assertEquals("Correct code generated for external script", expectedXml, xmlToString(root));
459
        assertEquals("Correct code generated for external script", expectedXml, xmlToString(root));
461
        // And also with locations defined as special properties in various ways...
460
        // And also with locations defined as special properties in various ways...
462
        Element data = prj.getPrimaryConfigurationData();
461
        Element data = prj.getPrimaryConfigurationData();
463
        Element properties = Util.findElement(data, "properties", Util.NAMESPACE);
462
        Element properties = XMLUtil.findElement(data, "properties", Util.NAMESPACE);
464
        assertNotNull(properties);
463
        assertNotNull(properties);
465
        Element property = data.getOwnerDocument().createElementNS(Util.NAMESPACE, "property");
464
        Element property = data.getOwnerDocument().createElementNS(Util.NAMESPACE, "property");
466
        property.setAttribute("name", "external.xml");
465
        property.setAttribute("name", "external.xml");
(-)a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectGeneratorTest.java (-74 / +75 lines)
Lines 77-82 Link Here
77
import org.netbeans.spi.project.support.ant.PropertyUtils;
77
import org.netbeans.spi.project.support.ant.PropertyUtils;
78
import org.openide.modules.ModuleInfo;
78
import org.openide.modules.ModuleInfo;
79
import org.openide.util.Lookup;
79
import org.openide.util.Lookup;
80
import org.openide.xml.XMLUtil;
80
81
81
/**
82
/**
82
 * Tests for JavaProjectGenerator.
83
 * Tests for JavaProjectGenerator.
Lines 212-236 Link Here
212
        // check that all elements are written in expected order
213
        // check that all elements are written in expected order
213
        
214
        
214
        Element el = Util.getPrimaryConfigurationData(helper);
215
        Element el = Util.getPrimaryConfigurationData(helper);
215
        List subElements = Util.findSubElements(el);
216
        List subElements = XMLUtil.findSubElements(el);
216
        assertEquals(7, subElements.size());
217
        assertEquals(7, subElements.size());
217
        assertElementArray(subElements, 
218
        assertElementArray(subElements, 
218
            new String[]{"name", "properties", "folders", "ide-actions", "export", "view", "subprojects"}, 
219
            new String[]{"name", "properties", "folders", "ide-actions", "export", "view", "subprojects"}, 
219
            new String[]{null, null, null, null, null, null, null});
220
            new String[]{null, null, null, null, null, null, null});
220
        Element el2 = (Element)subElements.get(5);
221
        Element el2 = (Element)subElements.get(5);
221
        subElements = Util.findSubElements(el2);
222
        subElements = XMLUtil.findSubElements(el2);
222
        assertEquals(2, subElements.size());
223
        assertEquals(2, subElements.size());
223
        assertElementArray(subElements, 
224
        assertElementArray(subElements, 
224
            new String[]{"items", "context-menu"}, 
225
            new String[]{"items", "context-menu"}, 
225
            new String[]{null, null});
226
            new String[]{null, null});
226
        Element el3 = (Element)subElements.get(0);
227
        Element el3 = (Element)subElements.get(0);
227
        List subEls = Util.findSubElements(el3);
228
        List subEls = XMLUtil.findSubElements(el3);
228
        assertEquals(2, subEls.size());
229
        assertEquals(2, subEls.size());
229
        assertElementArray(subEls, 
230
        assertElementArray(subEls, 
230
            new String[]{"source-folder", "source-file"}, 
231
            new String[]{"source-folder", "source-file"}, 
231
            new String[]{null, null});
232
            new String[]{null, null});
232
        el3 = (Element)subElements.get(1);
233
        el3 = (Element)subElements.get(1);
233
        subEls = Util.findSubElements(el3);
234
        subEls = XMLUtil.findSubElements(el3);
234
        assertEquals(2, subEls.size());
235
        assertEquals(2, subEls.size());
235
        assertElementArray(subEls, 
236
        assertElementArray(subEls, 
236
            new String[]{"ide-action", "action"}, 
237
            new String[]{"ide-action", "action"}, 
Lines 259-283 Link Here
259
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
260
        FreeformProjectGenerator.putTargetMappings(helper, mappings);
260
//        ProjectManager.getDefault().saveAllProjects();
261
//        ProjectManager.getDefault().saveAllProjects();
261
        el = Util.getPrimaryConfigurationData(helper);
262
        el = Util.getPrimaryConfigurationData(helper);
262
        subElements = Util.findSubElements(el);
263
        subElements = XMLUtil.findSubElements(el);
263
        assertEquals(7, subElements.size());
264
        assertEquals(7, subElements.size());
264
        assertElementArray(subElements, 
265
        assertElementArray(subElements, 
265
            new String[]{"name", "properties", "folders", "ide-actions", "export", "view", "subprojects"}, 
266
            new String[]{"name", "properties", "folders", "ide-actions", "export", "view", "subprojects"}, 
266
            new String[]{null, null, null, null, null, null, null});
267
            new String[]{null, null, null, null, null, null, null});
267
        el2 = (Element)subElements.get(5);
268
        el2 = (Element)subElements.get(5);
268
        subElements = Util.findSubElements(el2);
269
        subElements = XMLUtil.findSubElements(el2);
269
        assertEquals(2, subElements.size());
270
        assertEquals(2, subElements.size());
270
        assertElementArray(subElements, 
271
        assertElementArray(subElements, 
271
            new String[]{"items", "context-menu"}, 
272
            new String[]{"items", "context-menu"}, 
272
            new String[]{null, null});
273
            new String[]{null, null});
273
        el3 = (Element)subElements.get(0);
274
        el3 = (Element)subElements.get(0);
274
        subEls = Util.findSubElements(el3);
275
        subEls = XMLUtil.findSubElements(el3);
275
        assertEquals(2, subEls.size());
276
        assertEquals(2, subEls.size());
276
        assertElementArray(subEls, 
277
        assertElementArray(subEls, 
277
            new String[]{"source-folder", "source-file"}, 
278
            new String[]{"source-folder", "source-file"}, 
278
            new String[]{null, null});
279
            new String[]{null, null});
279
        el3 = (Element)subElements.get(1);
280
        el3 = (Element)subElements.get(1);
280
        subEls = Util.findSubElements(el3);
281
        subEls = XMLUtil.findSubElements(el3);
281
        assertEquals(2, subEls.size());
282
        assertEquals(2, subEls.size());
282
        assertElementArray(subEls, 
283
        assertElementArray(subEls, 
283
            new String[]{"ide-action", "action"}, 
284
            new String[]{"ide-action", "action"}, 
Lines 296-302 Link Here
296
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
297
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
297
        assertEquals(message, expectedName, element.getLocalName());
298
        assertEquals(message, expectedName, element.getLocalName());
298
        if (expectedValue != null) {
299
        if (expectedValue != null) {
299
            assertEquals(message, expectedValue, Util.findText(element));
300
            assertEquals(message, expectedValue, XMLUtil.findText(element));
300
        }
301
        }
301
    }
302
    }
302
303
Lines 324-330 Link Here
324
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
325
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
325
        assertEquals(message, expectedName, element.getLocalName());
326
        assertEquals(message, expectedName, element.getLocalName());
326
        if (expectedValue != null) {
327
        if (expectedValue != null) {
327
            assertEquals(message, expectedValue, Util.findText(element));
328
            assertEquals(message, expectedValue, XMLUtil.findText(element));
328
        }
329
        }
329
        String val = element.getAttribute(expectedAttrName);
330
        String val = element.getAttribute(expectedAttrName);
330
        assertEquals(expectedAttrValue, val);
331
        assertEquals(expectedAttrValue, val);
Lines 434-447 Link Here
434
        JavaProjectGenerator.putSourceFolders(helper, folders, null);
435
        JavaProjectGenerator.putSourceFolders(helper, folders, null);
435
//        ProjectManager.getDefault().saveAllProjects();
436
//        ProjectManager.getDefault().saveAllProjects();
436
        Element el = Util.getPrimaryConfigurationData(helper);
437
        Element el = Util.getPrimaryConfigurationData(helper);
437
        el = Util.findElement(el, "folders", Util.NAMESPACE);
438
        el = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
438
        assertNotNull("Source folders were not saved correctly",  el);
439
        assertNotNull("Source folders were not saved correctly",  el);
439
        List subElements = Util.findSubElements(el);
440
        List subElements = XMLUtil.findSubElements(el);
440
        assertEquals(2, subElements.size());
441
        assertEquals(2, subElements.size());
441
        // compare first source folder
442
        // compare first source folder
442
        Element el2 = (Element)subElements.get(0);
443
        Element el2 = (Element)subElements.get(0);
443
        assertElement(el2, "source-folder", null);
444
        assertElement(el2, "source-folder", null);
444
        List l1 = Util.findSubElements(el2);
445
        List l1 = XMLUtil.findSubElements(el2);
445
        assertEquals(3, l1.size());
446
        assertEquals(3, l1.size());
446
        assertElementArray(l1, 
447
        assertElementArray(l1, 
447
            new String[]{"label", "type", "location"}, 
448
            new String[]{"label", "type", "location"}, 
Lines 449-455 Link Here
449
        // compare second source folder
450
        // compare second source folder
450
        el2 = (Element)subElements.get(1);
451
        el2 = (Element)subElements.get(1);
451
        assertElement(el2, "source-folder", null);
452
        assertElement(el2, "source-folder", null);
452
        l1 = Util.findSubElements(el2);
453
        l1 = XMLUtil.findSubElements(el2);
453
        assertEquals(3, l1.size());
454
        assertEquals(3, l1.size());
454
        assertElementArray(l1, 
455
        assertElementArray(l1, 
455
            new String[]{"label", "type", "location"}, 
456
            new String[]{"label", "type", "location"}, 
Lines 467-480 Link Here
467
        JavaProjectGenerator.putSourceFolders(helper, folders, "type2");
468
        JavaProjectGenerator.putSourceFolders(helper, folders, "type2");
468
        ProjectManager.getDefault().saveAllProjects();
469
        ProjectManager.getDefault().saveAllProjects();
469
        el = Util.getPrimaryConfigurationData(helper);
470
        el = Util.getPrimaryConfigurationData(helper);
470
        el = Util.findElement(el, "folders", Util.NAMESPACE);
471
        el = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
471
        assertNotNull("Source folders were not saved correctly",  el);
472
        assertNotNull("Source folders were not saved correctly",  el);
472
        subElements = Util.findSubElements(el);
473
        subElements = XMLUtil.findSubElements(el);
473
        assertEquals(2, subElements.size());
474
        assertEquals(2, subElements.size());
474
        // compare first source folder
475
        // compare first source folder
475
        el2 = (Element)subElements.get(0);
476
        el2 = (Element)subElements.get(0);
476
        assertElement(el2, "source-folder", null);
477
        assertElement(el2, "source-folder", null);
477
        l1 = Util.findSubElements(el2);
478
        l1 = XMLUtil.findSubElements(el2);
478
        assertEquals(3, l1.size());
479
        assertEquals(3, l1.size());
479
        assertElementArray(l1, 
480
        assertElementArray(l1, 
480
            new String[]{"label", "type", "location"}, 
481
            new String[]{"label", "type", "location"}, 
Lines 482-488 Link Here
482
        // compare second source folder
483
        // compare second source folder
483
        el2 = (Element)subElements.get(1);
484
        el2 = (Element)subElements.get(1);
484
        assertElement(el2, "source-folder", null);
485
        assertElement(el2, "source-folder", null);
485
        l1 = Util.findSubElements(el2);
486
        l1 = XMLUtil.findSubElements(el2);
486
        assertEquals(3, l1.size());
487
        assertEquals(3, l1.size());
487
        assertElementArray(l1, 
488
        assertElementArray(l1, 
488
            new String[]{"label", "type", "location"}, 
489
            new String[]{"label", "type", "location"}, 
Lines 582-598 Link Here
582
        JavaProjectGenerator.putSourceViews(helper, folders, null);
583
        JavaProjectGenerator.putSourceViews(helper, folders, null);
583
        ProjectManager.getDefault().saveAllProjects();
584
        ProjectManager.getDefault().saveAllProjects();
584
        Element el = Util.getPrimaryConfigurationData(helper);
585
        Element el = Util.getPrimaryConfigurationData(helper);
585
        el = Util.findElement(el, "view", Util.NAMESPACE);
586
        el = XMLUtil.findElement(el, "view", Util.NAMESPACE);
586
        assertNotNull("View folders were not saved correctly",  el);
587
        assertNotNull("View folders were not saved correctly",  el);
587
        el = Util.findElement(el, "items", Util.NAMESPACE);
588
        el = XMLUtil.findElement(el, "items", Util.NAMESPACE);
588
        assertNotNull("View folders were not saved correctly",  el);
589
        assertNotNull("View folders were not saved correctly",  el);
589
        List subElements = Util.findSubElements(el);
590
        List subElements = XMLUtil.findSubElements(el);
590
        // there will be three sublements: <source-file> is added for build.xml during project.creation
591
        // there will be three sublements: <source-file> is added for build.xml during project.creation
591
        assertEquals(3, subElements.size());
592
        assertEquals(3, subElements.size());
592
        // compare first source view
593
        // compare first source view
593
        Element el2 = (Element)subElements.get(0);
594
        Element el2 = (Element)subElements.get(0);
594
        assertElement(el2, "source-folder", null, "style", "tree");
595
        assertElement(el2, "source-folder", null, "style", "tree");
595
        List l1 = Util.findSubElements(el2);
596
        List l1 = XMLUtil.findSubElements(el2);
596
        assertEquals(2, l1.size());
597
        assertEquals(2, l1.size());
597
        assertElementArray(l1, 
598
        assertElementArray(l1, 
598
            new String[]{"label", "location"}, 
599
            new String[]{"label", "location"}, 
Lines 600-606 Link Here
600
        // compare second source view
601
        // compare second source view
601
        el2 = (Element)subElements.get(1);
602
        el2 = (Element)subElements.get(1);
602
        assertElement(el2, "source-folder", null, "style", "packages");
603
        assertElement(el2, "source-folder", null, "style", "packages");
603
        l1 = Util.findSubElements(el2);
604
        l1 = XMLUtil.findSubElements(el2);
604
        assertEquals(2, l1.size());
605
        assertEquals(2, l1.size());
605
        assertElementArray(l1, 
606
        assertElementArray(l1, 
606
            new String[]{"label", "location"}, 
607
            new String[]{"label", "location"}, 
Lines 618-634 Link Here
618
        JavaProjectGenerator.putSourceViews(helper, folders, "packages");
619
        JavaProjectGenerator.putSourceViews(helper, folders, "packages");
619
        ProjectManager.getDefault().saveAllProjects();
620
        ProjectManager.getDefault().saveAllProjects();
620
        el = Util.getPrimaryConfigurationData(helper);
621
        el = Util.getPrimaryConfigurationData(helper);
621
        el = Util.findElement(el, "view", Util.NAMESPACE);
622
        el = XMLUtil.findElement(el, "view", Util.NAMESPACE);
622
        assertNotNull("Source views were not saved correctly",  el);
623
        assertNotNull("Source views were not saved correctly",  el);
623
        el = Util.findElement(el, "items", Util.NAMESPACE);
624
        el = XMLUtil.findElement(el, "items", Util.NAMESPACE);
624
        assertNotNull("View folders were not saved correctly",  el);
625
        assertNotNull("View folders were not saved correctly",  el);
625
        subElements = Util.findSubElements(el);
626
        subElements = XMLUtil.findSubElements(el);
626
        // there will be three sublements: <source-file> is added for build.xml during project.creation
627
        // there will be three sublements: <source-file> is added for build.xml during project.creation
627
        assertEquals("3 elements in " + subElements, 3, subElements.size());
628
        assertEquals("3 elements in " + subElements, 3, subElements.size());
628
        // compare first source view
629
        // compare first source view
629
        el2 = (Element)subElements.get(0);
630
        el2 = (Element)subElements.get(0);
630
        assertElement(el2, "source-folder", null, "style", "tree");
631
        assertElement(el2, "source-folder", null, "style", "tree");
631
        l1 = Util.findSubElements(el2);
632
        l1 = XMLUtil.findSubElements(el2);
632
        assertEquals(2, l1.size());
633
        assertEquals(2, l1.size());
633
        assertElementArray(l1, 
634
        assertElementArray(l1, 
634
            new String[]{"label", "location"}, 
635
            new String[]{"label", "location"}, 
Lines 636-642 Link Here
636
        // compare second source view
637
        // compare second source view
637
        el2 = (Element)subElements.get(1);
638
        el2 = (Element)subElements.get(1);
638
        assertElement(el2, "source-folder", null, "style", "packages");
639
        assertElement(el2, "source-folder", null, "style", "packages");
639
        l1 = Util.findSubElements(el2);
640
        l1 = XMLUtil.findSubElements(el2);
640
        assertEquals(2, l1.size());
641
        assertEquals(2, l1.size());
641
        assertElementArray(l1, 
642
        assertElementArray(l1, 
642
            new String[]{"label", "location"}, 
643
            new String[]{"label", "location"}, 
Lines 758-769 Link Here
758
//        ProjectManager.getDefault().saveAllProjects();
759
//        ProjectManager.getDefault().saveAllProjects();
759
        Element el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
760
        Element el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
760
        assertNotNull("Java compilation units were not saved correctly",  el);
761
        assertNotNull("Java compilation units were not saved correctly",  el);
761
        List subElements = Util.findSubElements(el);
762
        List subElements = XMLUtil.findSubElements(el);
762
        assertEquals(2, subElements.size());
763
        assertEquals(2, subElements.size());
763
        // compare first compilation unit
764
        // compare first compilation unit
764
        Element el2 = (Element)subElements.get(0);
765
        Element el2 = (Element)subElements.get(0);
765
        assertElement(el2, "compilation-unit", null);
766
        assertElement(el2, "compilation-unit", null);
766
        List l1 = Util.findSubElements(el2);
767
        List l1 = XMLUtil.findSubElements(el2);
767
        assertEquals(7, l1.size());
768
        assertEquals(7, l1.size());
768
        assertElementArray(l1, 
769
        assertElementArray(l1, 
769
            new String[]{"package-root", "package-root", "classpath", "classpath", "built-to", "built-to", "source-level"}, 
770
            new String[]{"package-root", "package-root", "classpath", "classpath", "built-to", "built-to", "source-level"}, 
Lines 775-781 Link Here
775
        // compare second compilation unit
776
        // compare second compilation unit
776
        el2 = (Element)subElements.get(1);
777
        el2 = (Element)subElements.get(1);
777
        assertElement(el2, "compilation-unit", null);
778
        assertElement(el2, "compilation-unit", null);
778
        l1 = Util.findSubElements(el2);
779
        l1 = XMLUtil.findSubElements(el2);
779
        assertEquals(7, l1.size());
780
        assertEquals(7, l1.size());
780
        assertElementArray(l1, 
781
        assertElementArray(l1, 
781
            new String[]{"package-root", "package-root", "classpath", "classpath", "built-to", "built-to", "source-level"}, 
782
            new String[]{"package-root", "package-root", "classpath", "classpath", "built-to", "built-to", "source-level"}, 
Lines 797-808 Link Here
797
//        ProjectManager.getDefault().saveAllProjects();
798
//        ProjectManager.getDefault().saveAllProjects();
798
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
799
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
799
        assertNotNull("Java compilation units were not saved correctly",  el);
800
        assertNotNull("Java compilation units were not saved correctly",  el);
800
        subElements = Util.findSubElements(el);
801
        subElements = XMLUtil.findSubElements(el);
801
        assertEquals(1, subElements.size());
802
        assertEquals(1, subElements.size());
802
        // compare first compilation unit
803
        // compare first compilation unit
803
        el2 = (Element)subElements.get(0);
804
        el2 = (Element)subElements.get(0);
804
        assertElement(el2, "compilation-unit", null);
805
        assertElement(el2, "compilation-unit", null);
805
        l1 = Util.findSubElements(el2);
806
        l1 = XMLUtil.findSubElements(el2);
806
        assertEquals(1, l1.size());
807
        assertEquals(1, l1.size());
807
        assertElementArray(l1, 
808
        assertElementArray(l1, 
808
            new String[]{"package-root"}, 
809
            new String[]{"package-root"}, 
Lines 827-838 Link Here
827
        // Check that the correct /1 data was saved.
828
        // Check that the correct /1 data was saved.
828
        Element el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
829
        Element el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
829
        assertNotNull("Java compilation units were saved in /1",  el);
830
        assertNotNull("Java compilation units were saved in /1",  el);
830
        List<Element> subElements = Util.findSubElements(el);
831
        List<Element> subElements = XMLUtil.findSubElements(el);
831
        assertEquals(1, subElements.size());
832
        assertEquals(1, subElements.size());
832
        // compare the compilation unit
833
        // compare the compilation unit
833
        Element el2 = (Element) subElements.get(0);
834
        Element el2 = (Element) subElements.get(0);
834
        assertElement(el2, "compilation-unit", null);
835
        assertElement(el2, "compilation-unit", null);
835
        assertElementArray(Util.findSubElements(el2),
836
        assertElementArray(XMLUtil.findSubElements(el2),
836
            new String[] {"package-root"},
837
            new String[] {"package-root"},
837
            new String[] {"pkgroot1"});
838
            new String[] {"pkgroot1"});
838
        ProjectManager.getDefault().saveAllProjects();
839
        ProjectManager.getDefault().saveAllProjects();
Lines 849-860 Link Here
849
        assertNull("No /1 data", el);
850
        assertNull("No /1 data", el);
850
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true);
851
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true);
851
        assertNotNull("Have /2 data", el);
852
        assertNotNull("Have /2 data", el);
852
        subElements = Util.findSubElements(el);
853
        subElements = XMLUtil.findSubElements(el);
853
        assertEquals(1, subElements.size());
854
        assertEquals(1, subElements.size());
854
        // compare the compilation unit
855
        // compare the compilation unit
855
        el2 = (Element) subElements.get(0);
856
        el2 = (Element) subElements.get(0);
856
        assertElement(el2, "compilation-unit", null);
857
        assertElement(el2, "compilation-unit", null);
857
        assertElementArray(Util.findSubElements(el2),
858
        assertElementArray(XMLUtil.findSubElements(el2),
858
            new String[] {"package-root", "unit-tests"},
859
            new String[] {"package-root", "unit-tests"},
859
            new String[] {"pkgroot1", null});
860
            new String[] {"pkgroot1", null});
860
        ProjectManager.getDefault().saveAllProjects();
861
        ProjectManager.getDefault().saveAllProjects();
Lines 874-885 Link Here
874
        assertNull("No /1 data", el);
875
        assertNull("No /1 data", el);
875
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true);
876
        el = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true);
876
        assertNotNull("Have /2 data", el);
877
        assertNotNull("Have /2 data", el);
877
        subElements = Util.findSubElements(el);
878
        subElements = XMLUtil.findSubElements(el);
878
        assertEquals(1, subElements.size());
879
        assertEquals(1, subElements.size());
879
        // compare the compilation unit
880
        // compare the compilation unit
880
        el2 = (Element) subElements.get(0);
881
        el2 = (Element) subElements.get(0);
881
        assertElement(el2, "compilation-unit", null);
882
        assertElement(el2, "compilation-unit", null);
882
        assertElementArray(Util.findSubElements(el2),
883
        assertElementArray(XMLUtil.findSubElements(el2),
883
            new String[] {"package-root", "javadoc-built-to", "javadoc-built-to"},
884
            new String[] {"package-root", "javadoc-built-to", "javadoc-built-to"},
884
            new String[] {"pkgroot1", "javadoc1", "javadoc2"});
885
            new String[] {"pkgroot1", "javadoc1", "javadoc2"});
885
        ProjectManager.getDefault().saveAllProjects();
886
        ProjectManager.getDefault().saveAllProjects();
Lines 1000-1006 Link Here
1000
        
1001
        
1001
        JavaProjectGenerator.putExports(helper, exports);
1002
        JavaProjectGenerator.putExports(helper, exports);
1002
        Element el = Util.getPrimaryConfigurationData(helper);
1003
        Element el = Util.getPrimaryConfigurationData(helper);
1003
        List subElements = Util.findSubElements(el);
1004
        List subElements = XMLUtil.findSubElements(el);
1004
        // 4, i.e. name, two exports and one view of build.xml file
1005
        // 4, i.e. name, two exports and one view of build.xml file
1005
        assertEquals(5, subElements.size());
1006
        assertEquals(5, subElements.size());
1006
        // compare first compilation unit
1007
        // compare first compilation unit
Lines 1010-1016 Link Here
1010
        assertElement(el2, "properties", null);
1011
        assertElement(el2, "properties", null);
1011
        el2 = (Element)subElements.get(2);
1012
        el2 = (Element)subElements.get(2);
1012
        assertElement(el2, "export", null);
1013
        assertElement(el2, "export", null);
1013
        List l1 = Util.findSubElements(el2);
1014
        List l1 = XMLUtil.findSubElements(el2);
1014
        assertEquals(5, l1.size());
1015
        assertEquals(5, l1.size());
1015
        assertElementArray(l1, 
1016
        assertElementArray(l1, 
1016
            new String[]{"type", "location", "script", "build-target", "clean-target"}, 
1017
            new String[]{"type", "location", "script", "build-target", "clean-target"}, 
Lines 1018-1024 Link Here
1018
        // compare second compilation unit
1019
        // compare second compilation unit
1019
        el2 = (Element)subElements.get(3);
1020
        el2 = (Element)subElements.get(3);
1020
        assertElement(el2, "export", null);
1021
        assertElement(el2, "export", null);
1021
        l1 = Util.findSubElements(el2);
1022
        l1 = XMLUtil.findSubElements(el2);
1022
        assertEquals(3, l1.size());
1023
        assertEquals(3, l1.size());
1023
        assertElementArray(l1, 
1024
        assertElementArray(l1, 
1024
            new String[]{"type", "location", "build-target"}, 
1025
            new String[]{"type", "location", "build-target"}, 
Lines 1038-1044 Link Here
1038
        
1039
        
1039
        JavaProjectGenerator.putExports(helper, exports);
1040
        JavaProjectGenerator.putExports(helper, exports);
1040
        el = Util.getPrimaryConfigurationData(helper);
1041
        el = Util.getPrimaryConfigurationData(helper);
1041
        subElements = Util.findSubElements(el);
1042
        subElements = XMLUtil.findSubElements(el);
1042
        // 3, i.e. name, export and one view of build.xml file
1043
        // 3, i.e. name, export and one view of build.xml file
1043
        assertEquals(4, subElements.size());
1044
        assertEquals(4, subElements.size());
1044
        // compare first compilation unit
1045
        // compare first compilation unit
Lines 1048-1054 Link Here
1048
        assertElement(el2, "properties", null);
1049
        assertElement(el2, "properties", null);
1049
        el2 = (Element)subElements.get(2);
1050
        el2 = (Element)subElements.get(2);
1050
        assertElement(el2, "export", null);
1051
        assertElement(el2, "export", null);
1051
        l1 = Util.findSubElements(el2);
1052
        l1 = XMLUtil.findSubElements(el2);
1052
        assertEquals(3, l1.size());
1053
        assertEquals(3, l1.size());
1053
        assertElementArray(l1, 
1054
        assertElementArray(l1, 
1054
            new String[]{"type", "location", "build-target"}, 
1055
            new String[]{"type", "location", "build-target"}, 
Lines 1123-1131 Link Here
1123
        
1124
        
1124
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1125
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1125
        Element el = Util.getPrimaryConfigurationData(helper);
1126
        Element el = Util.getPrimaryConfigurationData(helper);
1126
        Element subprojectsEl = Util.findElement(el, "subprojects", Util.NAMESPACE);
1127
        Element subprojectsEl = XMLUtil.findElement(el, "subprojects", Util.NAMESPACE);
1127
        assertNotNull("<subprojects> element exists", subprojectsEl);
1128
        assertNotNull("<subprojects> element exists", subprojectsEl);
1128
        List subElements = Util.findSubElements(subprojectsEl);
1129
        List subElements = XMLUtil.findSubElements(subprojectsEl);
1129
        assertEquals("project depends on two subprojects", 2, subElements.size());
1130
        assertEquals("project depends on two subprojects", 2, subElements.size());
1130
        Element el2 = (Element)subElements.get(0);
1131
        Element el2 = (Element)subElements.get(0);
1131
        assertElement(el2, "project", "/some/path/projA");
1132
        assertElement(el2, "project", "/some/path/projA");
Lines 1140-1155 Link Here
1140
        subprojects.add("/projC");
1141
        subprojects.add("/projC");
1141
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1142
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1142
        el = Util.getPrimaryConfigurationData(helper);
1143
        el = Util.getPrimaryConfigurationData(helper);
1143
        subprojectsEl = Util.findElement(el, "subprojects", Util.NAMESPACE);
1144
        subprojectsEl = XMLUtil.findElement(el, "subprojects", Util.NAMESPACE);
1144
        subElements = Util.findSubElements(subprojectsEl);
1145
        subElements = XMLUtil.findSubElements(subprojectsEl);
1145
        assertEquals("project depends on one subproject", 1, subElements.size());
1146
        assertEquals("project depends on one subproject", 1, subElements.size());
1146
        el2 = (Element)subElements.get(0);
1147
        el2 = (Element)subElements.get(0);
1147
        assertElement(el2, "project", "/projC");
1148
        assertElement(el2, "project", "/projC");
1148
        subprojects = new ArrayList();
1149
        subprojects = new ArrayList();
1149
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1150
        JavaProjectGenerator.putSubprojects(helper, subprojects);
1150
        el = Util.getPrimaryConfigurationData(helper);
1151
        el = Util.getPrimaryConfigurationData(helper);
1151
        subprojectsEl = Util.findElement(el, "subprojects", Util.NAMESPACE);
1152
        subprojectsEl = XMLUtil.findElement(el, "subprojects", Util.NAMESPACE);
1152
        subElements = Util.findSubElements(subprojectsEl);
1153
        subElements = XMLUtil.findSubElements(subprojectsEl);
1153
        assertEquals("project depends on one subproject", 0, subElements.size());
1154
        assertEquals("project depends on one subproject", 0, subElements.size());
1154
        
1155
        
1155
        ProjectManager.getDefault().saveAllProjects();
1156
        ProjectManager.getDefault().saveAllProjects();
Lines 1212-1229 Link Here
1212
        
1213
        
1213
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1214
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1214
        Element el = Util.getPrimaryConfigurationData(helper);
1215
        Element el = Util.getPrimaryConfigurationData(helper);
1215
        Element foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1216
        Element foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1216
        assertNotNull("<folders> element exists", foldersEl);
1217
        assertNotNull("<folders> element exists", foldersEl);
1217
        List subElements = Util.findSubElements(foldersEl);
1218
        List subElements = XMLUtil.findSubElements(foldersEl);
1218
        assertEquals("project has two build-folders", 2, subElements.size());
1219
        assertEquals("project has two build-folders", 2, subElements.size());
1219
        Element el2 = (Element)subElements.get(0);
1220
        Element el2 = (Element)subElements.get(0);
1220
        assertElement(el2, "build-folder", null);
1221
        assertElement(el2, "build-folder", null);
1221
        assertEquals("build-folder has one subelement", 1, Util.findSubElements(el2).size());
1222
        assertEquals("build-folder has one subelement", 1, XMLUtil.findSubElements(el2).size());
1222
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/some/path/projA");
1223
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "/some/path/projA");
1223
        el2 = (Element)subElements.get(1);
1224
        el2 = (Element)subElements.get(1);
1224
        assertElement(el2, "build-folder", null);
1225
        assertElement(el2, "build-folder", null);
1225
        assertEquals("build-folder has one subelement", 1, Util.findSubElements(el2).size());
1226
        assertEquals("build-folder has one subelement", 1, XMLUtil.findSubElements(el2).size());
1226
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "C:\\dev\\projB");
1227
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "C:\\dev\\projB");
1227
        
1228
        
1228
        ProjectManager.getDefault().saveAllProjects();
1229
        ProjectManager.getDefault().saveAllProjects();
1229
        
1230
        
Lines 1233-1250 Link Here
1233
        buildFolders.add("/projC");
1234
        buildFolders.add("/projC");
1234
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1235
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1235
        el = Util.getPrimaryConfigurationData(helper);
1236
        el = Util.getPrimaryConfigurationData(helper);
1236
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1237
        foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1237
        subElements = Util.findSubElements(foldersEl);
1238
        subElements = XMLUtil.findSubElements(foldersEl);
1238
        assertEquals("project has one build-folder", 1, subElements.size());
1239
        assertEquals("project has one build-folder", 1, subElements.size());
1239
        el2 = (Element)subElements.get(0);
1240
        el2 = (Element)subElements.get(0);
1240
        assertElement(el2, "build-folder", null);
1241
        assertElement(el2, "build-folder", null);
1241
        assertEquals("build-folder has one subelement", 1, Util.findSubElements(el2).size());
1242
        assertEquals("build-folder has one subelement", 1, XMLUtil.findSubElements(el2).size());
1242
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/projC");
1243
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "/projC");
1243
        buildFolders = new ArrayList();
1244
        buildFolders = new ArrayList();
1244
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1245
        JavaProjectGenerator.putBuildFolders(helper, buildFolders);
1245
        el = Util.getPrimaryConfigurationData(helper);
1246
        el = Util.getPrimaryConfigurationData(helper);
1246
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1247
        foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1247
        subElements = Util.findSubElements(foldersEl);
1248
        subElements = XMLUtil.findSubElements(foldersEl);
1248
        assertEquals("project has no build-folder", 0, subElements.size());
1249
        assertEquals("project has no build-folder", 0, subElements.size());
1249
        
1250
        
1250
        ProjectManager.getDefault().saveAllProjects();
1251
        ProjectManager.getDefault().saveAllProjects();
Lines 1264-1281 Link Here
1264
        
1265
        
1265
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1266
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1266
        Element el = Util.getPrimaryConfigurationData(helper);
1267
        Element el = Util.getPrimaryConfigurationData(helper);
1267
        Element foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1268
        Element foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1268
        assertNotNull("<folders> element exists", foldersEl);
1269
        assertNotNull("<folders> element exists", foldersEl);
1269
        List subElements = Util.findSubElements(foldersEl);
1270
        List subElements = XMLUtil.findSubElements(foldersEl);
1270
        assertEquals("project has two build-files", 2, subElements.size());
1271
        assertEquals("project has two build-files", 2, subElements.size());
1271
        Element el2 = (Element)subElements.get(0);
1272
        Element el2 = (Element)subElements.get(0);
1272
        assertElement(el2, "build-file", null);
1273
        assertElement(el2, "build-file", null);
1273
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1274
        assertEquals("build-file has one subelement", 1, XMLUtil.findSubElements(el2).size());
1274
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/some/path/projA/archive.jar");
1275
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "/some/path/projA/archive.jar");
1275
        el2 = (Element)subElements.get(1);
1276
        el2 = (Element)subElements.get(1);
1276
        assertElement(el2, "build-file", null);
1277
        assertElement(el2, "build-file", null);
1277
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1278
        assertEquals("build-file has one subelement", 1, XMLUtil.findSubElements(el2).size());
1278
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "C:\\dev\\projB\\library.jar");
1279
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "C:\\dev\\projB\\library.jar");
1279
        
1280
        
1280
        ProjectManager.getDefault().saveAllProjects();
1281
        ProjectManager.getDefault().saveAllProjects();
1281
        
1282
        
Lines 1284-1302 Link Here
1284
        buildFiles.add("/projC/dist/projC.jar");
1285
        buildFiles.add("/projC/dist/projC.jar");
1285
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1286
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1286
        el = Util.getPrimaryConfigurationData(helper);
1287
        el = Util.getPrimaryConfigurationData(helper);
1287
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1288
        foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1288
        subElements = Util.findSubElements(foldersEl);
1289
        subElements = XMLUtil.findSubElements(foldersEl);
1289
        assertEquals("project has one build-file", 1, subElements.size());
1290
        assertEquals("project has one build-file", 1, subElements.size());
1290
        el2 = (Element)subElements.get(0);
1291
        el2 = (Element)subElements.get(0);
1291
        assertElement(el2, "build-file", null);
1292
        assertElement(el2, "build-file", null);
1292
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1293
        assertEquals("build-file has one subelement", 1, XMLUtil.findSubElements(el2).size());
1293
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/projC/dist/projC.jar");
1294
        assertElement((Element)XMLUtil.findSubElements(el2).get(0), "location", "/projC/dist/projC.jar");
1294
        
1295
        
1295
        buildFiles = new ArrayList();
1296
        buildFiles = new ArrayList();
1296
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1297
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1297
        el = Util.getPrimaryConfigurationData(helper);
1298
        el = Util.getPrimaryConfigurationData(helper);
1298
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1299
        foldersEl = XMLUtil.findElement(el, "folders", Util.NAMESPACE);
1299
        subElements = Util.findSubElements(foldersEl);
1300
        subElements = XMLUtil.findSubElements(foldersEl);
1300
        assertEquals("project has no build-file", 0, subElements.size());
1301
        assertEquals("project has no build-file", 0, subElements.size());
1301
        
1302
        
1302
        ProjectManager.getDefault().saveAllProjects();
1303
        ProjectManager.getDefault().saveAllProjects();
(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 280-286 Link Here
280
                    <build-prerequisite/>
280
                    <build-prerequisite/>
281
                    <compile-dependency/>
281
                    <compile-dependency/>
282
                    <run-dependency>
282
                    <run-dependency>
283
                        <specification-version>8.0</specification-version>
283
                        <specification-version>8.4</specification-version>
284
                    </run-dependency>
284
                    </run-dependency>
285
                </dependency>
285
                </dependency>
286
                <dependency>
286
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/UpdateProjectImpl.java (-38 / +3 lines)
Lines 53-65 Link Here
53
import org.openide.NotifyDescriptor;
53
import org.openide.NotifyDescriptor;
54
import org.openide.util.Mutex;
54
import org.openide.util.Mutex;
55
import org.openide.util.NbBundle;
55
import org.openide.util.NbBundle;
56
import org.w3c.dom.Comment;
56
import org.openide.xml.XMLUtil;
57
import org.w3c.dom.Document;
57
import org.w3c.dom.Document;
58
import org.w3c.dom.Element;
58
import org.w3c.dom.Element;
59
import org.w3c.dom.NamedNodeMap;
60
import org.w3c.dom.Node;
59
import org.w3c.dom.Node;
61
import org.w3c.dom.NodeList;
60
import org.w3c.dom.NodeList;
62
import org.w3c.dom.Text;
63
61
64
/**
62
/**
65
 *
63
 *
Lines 153-159 Link Here
153
            if (oldRoot != null) {
151
            if (oldRoot != null) {
154
                Document doc = oldRoot.getOwnerDocument();
152
                Document doc = oldRoot.getOwnerDocument();
155
                Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
153
                Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
156
                copyDocument (doc, oldRoot, newRoot);
154
                XMLUtil.copyDocument (oldRoot, newRoot, J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE);
157
                Element sourceRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
155
                Element sourceRoots = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
158
                Element root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
156
                Element root = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
159
                root.setAttribute ("id","src.dir");   //NOI18N
157
                root.setAttribute ("id","src.dir");   //NOI18N
Lines 170-176 Link Here
170
                if (oldRoot != null) {
168
                if (oldRoot != null) {
171
                    Document doc = oldRoot.getOwnerDocument();
169
                    Document doc = oldRoot.getOwnerDocument();
172
                    Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
170
                    Element newRoot = doc.createElementNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
173
                    copyDocument (doc, oldRoot, newRoot);
171
                    XMLUtil.copyDocument (oldRoot, newRoot, J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE);
174
                    cachedElement = newRoot;
172
                    cachedElement = newRoot;
175
                }
173
                }
176
            }
174
            }
Lines 204-242 Link Here
204
        }
202
        }
205
    }
203
    }
206
204
207
    private static void copyDocument (Document doc, Element from, Element to) {
208
        NodeList nl = from.getChildNodes();
209
        int length = nl.getLength();
210
        for (int i=0; i< length; i++) {
211
            Node node = nl.item (i);
212
            Node newNode = null;
213
            switch (node.getNodeType()) {
214
                case Node.ELEMENT_NODE:
215
                    Element oldElement = (Element) node;
216
                    newNode = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
217
                    NamedNodeMap m = oldElement.getAttributes();
218
                    Element newElement = (Element) newNode;
219
                    for (int index = 0; index < m.getLength(); index++) {
220
                        Node attr = m.item(index);
221
                          newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
222
                    }
223
                    copyDocument(doc,oldElement,newElement);
224
                    break;
225
                case Node.TEXT_NODE:
226
                    Text oldText = (Text) node;
227
                    newNode = doc.createTextNode(oldText.getData());
228
                    break;
229
                case Node.COMMENT_NODE:
230
                    Comment oldComment = (Comment) node;
231
                    newNode = doc.createComment(oldComment.getData());
232
                    break;
233
            }
234
            if (newNode != null) {
235
                to.appendChild (newNode);
236
            }
237
        }
238
    }
239
240
    private static void deleteMinAntVersion(final Element root) {
205
    private static void deleteMinAntVersion(final Element root) {
241
        NodeList list = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
206
        NodeList list = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
242
        if (list.getLength() == 1) {
207
        if (list.getLength() == 1) {
(-)a/java.source/nbproject/project.xml (-1 / +1 lines)
Lines 352-358 Link Here
352
                    <build-prerequisite/>
352
                    <build-prerequisite/>
353
                    <compile-dependency/>
353
                    <compile-dependency/>
354
                    <run-dependency>
354
                    <run-dependency>
355
                        <specification-version>8.0</specification-version>
355
                        <specification-version>8.4</specification-version>
356
                    </run-dependency>
356
                    </run-dependency>
357
                </dependency>
357
                </dependency>
358
                <dependency>
358
                <dependency>
(-)a/java.source/test/unit/src/org/netbeans/modules/java/source/usages/TestSupport.java (-23 / +3 lines)
Lines 190-196 Link Here
190
                assert false : "Shared not implemented";
190
                assert false : "Shared not implemented";
191
            }
191
            }
192
            Element root = xml.getDocumentElement ();
192
            Element root = xml.getDocumentElement ();
193
            Element data = findElement (root, elementName, namespace);
193
            Element data = XMLUtil.findElement (root, elementName, namespace);
194
            if (data != null) {
194
            if (data != null) {
195
                return  (Element) data.cloneNode (true);
195
                return  (Element) data.cloneNode (true);
196
            } else {
196
            } else {
Lines 205-211 Link Here
205
            }
205
            }
206
            
206
            
207
            Element root = xml.getDocumentElement ();
207
            Element root = xml.getDocumentElement ();
208
            Element existing = findElement (root, fragment.getLocalName (), fragment.getNamespaceURI ());
208
            Element existing = XMLUtil.findElement (root, fragment.getLocalName (), fragment.getNamespaceURI ());
209
            // XXX first compare to existing and return if the same
209
            // XXX first compare to existing and return if the same
210
            if (existing != null) {
210
            if (existing != null) {
211
                root.removeChild (existing);
211
                root.removeChild (existing);
Lines 236-242 Link Here
236
            }
236
            }
237
237
238
            Element root = xml.getDocumentElement ();
238
            Element root = xml.getDocumentElement ();
239
            Element data = findElement (root, elementName, namespace);
239
            Element data = XMLUtil.findElement (root, elementName, namespace);
240
            if (data != null) {
240
            if (data != null) {
241
                root.removeChild (data);
241
                root.removeChild (data);
242
                return true;
242
                return true;
Lines 245-268 Link Here
245
            }
245
            }
246
        }
246
        }
247
    }
247
    }
248
    
249
    // copied from org.netbeans.modules.project.ant.Util
250
    private static Element findElement(Element parent, String name, String namespace) {
251
        Element result = null;
252
        NodeList l = parent.getChildNodes();
253
        int len = l.getLength();
254
        for (int i = 0; i < len; i++) {
255
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
256
                Element el = (Element)l.item(i);
257
                if (name.equals(el.getLocalName()) && namespace.equals(el.getNamespaceURI())) {
258
                    if (result == null) {
259
                        result = el;
260
                    } else {
261
                        return null;
262
                    }
263
                }
264
            }
265
        }
266
        return result;
267
    }
268
}
248
}
(-)a/maven/nbproject/project.xml (-1 / +1 lines)
Lines 362-368 Link Here
362
                    <build-prerequisite/>
362
                    <build-prerequisite/>
363
                    <compile-dependency/>
363
                    <compile-dependency/>
364
                    <run-dependency>
364
                    <run-dependency>
365
                        <specification-version>8.0</specification-version>
365
                        <specification-version>8.4</specification-version>
366
                    </run-dependency>
366
                    </run-dependency>
367
                </dependency>
367
                </dependency>
368
                <dependency>
368
                <dependency>
(-)a/maven/src/org/netbeans/modules/maven/M2AuxilaryConfigImpl.java (-27 / +6 lines)
Lines 65-72 Link Here
65
import org.w3c.dom.DOMException;
65
import org.w3c.dom.DOMException;
66
import org.w3c.dom.Document;
66
import org.w3c.dom.Document;
67
import org.w3c.dom.Element;
67
import org.w3c.dom.Element;
68
import org.w3c.dom.Node;
69
import org.w3c.dom.NodeList;
70
import org.xml.sax.InputSource;
68
import org.xml.sax.InputSource;
71
import org.xml.sax.SAXException;
69
import org.xml.sax.SAXException;
72
70
Lines 142-148 Link Here
142
        if (shared) {
140
        if (shared) {
143
            //first check the document schedule for persistence
141
            //first check the document schedule for persistence
144
            if (scheduledDocument != null) {
142
            if (scheduledDocument != null) {
145
                Element el = findElement(scheduledDocument.getDocumentElement(), elementName, namespace);
143
                Element el = XMLUtil.findElement(scheduledDocument.getDocumentElement(), elementName, namespace);
146
                if (el != null) {
144
                if (el != null) {
147
                    el = (Element) el.cloneNode(true);
145
                    el = (Element) el.cloneNode(true);
148
                }
146
                }
Lines 159-165 Link Here
159
                        //TODO shall be have some kind of caching here to prevent frequent IO?
157
                        //TODO shall be have some kind of caching here to prevent frequent IO?
160
                        doc = XMLUtil.parse(new InputSource(in), false, true, null, null);
158
                        doc = XMLUtil.parse(new InputSource(in), false, true, null, null);
161
                        cachedDoc = doc;
159
                        cachedDoc = doc;
162
                        return findElement(doc.getDocumentElement(), elementName, namespace);
160
                        return XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
163
                    } catch (SAXException ex) {
161
                    } catch (SAXException ex) {
164
                        ProblemReporterImpl impl = project.getProblemReporter();
162
                        ProblemReporterImpl impl = project.getProblemReporter();
165
                        if (!impl.hasReportWithId(BROKEN_NBCONFIG)) {
163
                        if (!impl.hasReportWithId(BROKEN_NBCONFIG)) {
Lines 189-195 Link Here
189
                } else {
187
                } else {
190
                    //reuse cached value if available;
188
                    //reuse cached value if available;
191
                    if (cachedDoc != null) {
189
                    if (cachedDoc != null) {
192
                        return findElement(cachedDoc.getDocumentElement(), elementName, namespace);
190
                        return XMLUtil.findElement(cachedDoc.getDocumentElement(), elementName, namespace);
193
                    }
191
                    }
194
                }
192
                }
195
            } else {
193
            } else {
Lines 203-209 Link Here
203
                Document doc;
201
                Document doc;
204
                try {
202
                try {
205
                    doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
203
                    doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
206
                    return findElement(doc.getDocumentElement(), elementName, namespace);
204
                    return XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
207
                } catch (SAXException ex) {
205
                } catch (SAXException ex) {
208
                    ex.printStackTrace();
206
                    ex.printStackTrace();
209
                } catch (IOException ex) {
207
                } catch (IOException ex) {
Lines 254-260 Link Here
254
            }
252
            }
255
        }
253
        }
256
        if (doc != null) {
254
        if (doc != null) {
257
            Element el = findElement(doc.getDocumentElement(), fragment.getNodeName(), fragment.getNamespaceURI());
255
            Element el = XMLUtil.findElement(doc.getDocumentElement(), fragment.getNodeName(), fragment.getNamespaceURI());
258
            if (el != null) {
256
            if (el != null) {
259
                doc.getDocumentElement().removeChild(el);
257
                doc.getDocumentElement().removeChild(el);
260
            }
258
            }
Lines 319-325 Link Here
319
            }
317
            }
320
        }
318
        }
321
        if (doc != null) {
319
        if (doc != null) {
322
            Element el = findElement(doc.getDocumentElement(), elementName, namespace);
320
            Element el = XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
323
            if (el != null) {
321
            if (el != null) {
324
                doc.getDocumentElement().removeChild(el);
322
                doc.getDocumentElement().removeChild(el);
325
            }
323
            }
Lines 341-365 Link Here
341
        return true;
339
        return true;
342
    }
340
    }
343
341
344
    private static Element findElement(Element parent, String name, String namespace) {
345
        Element result = null;
346
        NodeList l = parent.getChildNodes();
347
        int len = l.getLength();
348
        for (int i = 0; i < len; i++) {
349
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
350
                Element el = (Element) l.item(i);
351
                if (name.equals(el.getLocalName()) && ((namespace == el.getNamespaceURI()) /*check both namespaces are null*/ || (namespace != null && namespace.equals(el.getNamespaceURI())))) {
352
                    if (result == null) {
353
                        result = el;
354
                    } else {
355
                        return null;
356
                    }
357
                }
358
            }
359
        }
360
        return result;
361
    }
362
363
    static class OpenConfigAction extends AbstractAction {
342
    static class OpenConfigAction extends AbstractAction {
364
343
365
        private FileObject fo;
344
        private FileObject fo;
(-)a/o.n.bluej/nbproject/project.xml (-1 / +1 lines)
Lines 213-219 Link Here
213
                    <build-prerequisite/>
213
                    <build-prerequisite/>
214
                    <compile-dependency/>
214
                    <compile-dependency/>
215
                    <run-dependency>
215
                    <run-dependency>
216
                        <specification-version>8.0</specification-version>
216
                        <specification-version>8.4</specification-version>
217
                    </run-dependency>
217
                    </run-dependency>
218
                </dependency>
218
                </dependency>
219
                <dependency>
219
                <dependency>
(-)a/o.n.bluej/src/org/netbeans/bluej/UpdateHelper.java (-35 / +3 lines)
Lines 61-66 Link Here
61
import org.netbeans.spi.project.support.ant.AntProjectHelper;
61
import org.netbeans.spi.project.support.ant.AntProjectHelper;
62
import org.netbeans.spi.project.support.ant.EditableProperties;
62
import org.netbeans.spi.project.support.ant.EditableProperties;
63
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
63
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
64
import org.openide.xml.XMLUtil;
64
65
65
66
66
/**
67
/**
Lines 267-273 Link Here
267
            if (oldRoot != null) {
268
            if (oldRoot != null) {
268
                Document doc = oldRoot.getOwnerDocument();
269
                Document doc = oldRoot.getOwnerDocument();
269
                Element newRoot = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); // NOI18N
270
                Element newRoot = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); // NOI18N
270
                copyDocument (doc, oldRoot, newRoot);
271
                XMLUtil.copyDocument (oldRoot, newRoot, BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE);
271
                Element sourceRoots = doc.createElementNS(BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  // NOI18N
272
                Element sourceRoots = doc.createElementNS(BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  // NOI18N
272
                Element root = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   // NOI18N
273
                Element root = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   // NOI18N
273
                root.setAttribute ("id","src.dir");   // NOI18N
274
                root.setAttribute ("id","src.dir");   // NOI18N
Lines 284-290 Link Here
284
                if (oldRoot != null) {
285
                if (oldRoot != null) {
285
                    Document doc = oldRoot.getOwnerDocument();
286
                    Document doc = oldRoot.getOwnerDocument();
286
                    Element newRoot = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); // NOI18N
287
                    Element newRoot = doc.createElementNS (BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); // NOI18N
287
                    copyDocument (doc, oldRoot, newRoot);
288
                    XMLUtil.copyDocument (oldRoot, newRoot, BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE);
288
                    cachedElement = updateMinAntVersion (newRoot, doc);
289
                    cachedElement = updateMinAntVersion (newRoot, doc);
289
                }
290
                }
290
            }
291
            }
Lines 307-345 Link Here
307
        return cachedProperties;
308
        return cachedProperties;
308
    }
309
    }
309
310
310
    private static void copyDocument (Document doc, Element from, Element to) {
311
        NodeList nl = from.getChildNodes();
312
        int length = nl.getLength();
313
        for (int i=0; i< length; i++) {
314
            Node node = nl.item (i);
315
            Node newNode = null;
316
            switch (node.getNodeType()) {
317
                case Node.ELEMENT_NODE:
318
                    Element oldElement = (Element) node;
319
                    newNode = doc.createElementNS(BluejProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
320
                    NamedNodeMap m = oldElement.getAttributes();
321
                    Element newElement = (Element) newNode;
322
                    for (int index = 0; index < m.getLength(); index++) {
323
                        Node attr = m.item(index);
324
                          newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
325
                    }
326
                    copyDocument(doc,oldElement,newElement);
327
                    break;
328
                case Node.TEXT_NODE:
329
                    Text oldText = (Text) node;
330
                    newNode = doc.createTextNode(oldText.getData());
331
                    break;
332
                case Node.COMMENT_NODE:
333
                    Comment oldComment = (Comment) node;
334
                    newNode = doc.createComment(oldComment.getData());
335
                    break;
336
            }
337
            if (newNode != null) {
338
                to.appendChild (newNode);
339
            }
340
        }
341
    }
342
343
    static final String MINIMUM_ANT_VERSION = "1.6.5";  // NOI18N
311
    static final String MINIMUM_ANT_VERSION = "1.6.5";  // NOI18N
344
    
312
    
345
    private static Element updateMinAntVersion (final Element root, final Document doc) {
313
    private static Element updateMinAntVersion (final Element root, final Document doc) {
(-)a/openide.loaders/nbproject/project.xml (-1 / +1 lines)
Lines 142-148 Link Here
142
                    <build-prerequisite/>
142
                    <build-prerequisite/>
143
                    <compile-dependency/>
143
                    <compile-dependency/>
144
                    <run-dependency>
144
                    <run-dependency>
145
                        <specification-version>8.0</specification-version>
145
                        <specification-version>8.4</specification-version>
146
                    </run-dependency>
146
                    </run-dependency>
147
                </dependency>
147
                </dependency>
148
                <dependency>
148
                <dependency>
(-)a/openide.loaders/src/org/openide/loaders/XMLDataObject.java (-6 / +1 lines)
Lines 609-620 Link Here
609
    @Deprecated
609
    @Deprecated
610
    public static Document parse (URL url, ErrorHandler eh, boolean validate) throws IOException, SAXException {
610
    public static Document parse (URL url, ErrorHandler eh, boolean validate) throws IOException, SAXException {
611
        
611
        
612
        DocumentBuilder builder = XMLDataObjectImpl.makeBuilder(validate);
612
        return XMLUtil.parse (new InputSource(url.toExternalForm()),validate, false, eh, getChainingEntityResolver());
613
        builder.setErrorHandler(eh);
614
        builder.setEntityResolver(getChainingEntityResolver());
615
        
616
        return builder.parse (new InputSource(url.toExternalForm()));
617
618
    }
613
    }
619
614
620
    /** Creates SAX parse that can be used to parse XML files.
615
    /** Creates SAX parse that can be used to parse XML files.
(-)a/openide.util/apichanges.xml (+16 lines)
Lines 1457-1462 Link Here
1457
      <class package="org.openide.xml" name="XMLUtil"/>
1457
      <class package="org.openide.xml" name="XMLUtil"/>
1458
      <issue number="16629"/>
1458
      <issue number="16629"/>
1459
    </change>
1459
    </change>
1460
    <change id="refactored-methods-into-XMLUtil">
1461
        <api name="xml"/>
1462
        <summary>Refactored XML methods from various modules to be added
1463
        to <code>XMLUtil</code>.  Seven new methods added.</summary>
1464
        <version major="8" minor="4"/>
1465
        <date day="7" month="4" year="2010"/>
1466
        <author login="mvfranz"/>
1467
        <compatibility addition="yes"/>
1468
        <description>
1469
            <p>
1470
                Refactored XML related methods into XMLUtil.
1471
            </p>
1472
        </description>
1473
        <class package="org.openide.xml" name="XMLUtil"/>
1474
        <issue number="136595"/>
1475
    </change>
1460
</changes>
1476
</changes>
1461
<htmlcontents>
1477
<htmlcontents>
1462
<head>
1478
<head>
(-)a/openide.util/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.util
2
OpenIDE-Module: org.openide.util
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/util/Bundle.properties
4
OpenIDE-Module-Specification-Version: 8.2
4
OpenIDE-Module-Specification-Version: 8.4
5
5
(-)a/openide.util/src/org/openide/xml/XMLUtil.java (+246 lines)
Lines 45-52 Link Here
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.io.OutputStream;
46
import java.io.OutputStream;
47
import java.io.StringReader;
47
import java.io.StringReader;
48
import java.util.ArrayList;
49
import java.util.Arrays;
48
import java.util.HashMap;
50
import java.util.HashMap;
49
import java.util.HashSet;
51
import java.util.HashSet;
52
import java.util.List;
53
import java.util.logging.Level;
54
import java.util.logging.Logger;
50
import java.util.Map;
55
import java.util.Map;
51
import java.util.Set;
56
import java.util.Set;
52
import javax.xml.parsers.DocumentBuilder;
57
import javax.xml.parsers.DocumentBuilder;
Lines 64-69 Link Here
64
import javax.xml.transform.stream.StreamSource;
69
import javax.xml.transform.stream.StreamSource;
65
import javax.xml.validation.Schema;
70
import javax.xml.validation.Schema;
66
import javax.xml.validation.Validator;
71
import javax.xml.validation.Validator;
72
import org.openide.util.Exceptions;
67
import org.w3c.dom.Attr;
73
import org.w3c.dom.Attr;
68
import org.w3c.dom.CDATASection;
74
import org.w3c.dom.CDATASection;
69
import org.w3c.dom.DOMException;
75
import org.w3c.dom.DOMException;
Lines 842-845 Link Here
842
        }
848
        }
843
        return doc;
849
        return doc;
844
    }
850
    }
851
852
    /**
853
     * Append a child element to the parent at the specified location.
854
     *
855
     * Starting with a valid document, append an element according to the schema
856
     * sequence represented by the <code>order</code>.  All existing child elements must be
857
     * include as well as the new element.  The existing child element following
858
     * the new child is important, as the element will be 'inserted before', not
859
     * 'inserted after'.
860
     *
861
     * @param parent parent to which the child will be appended
862
     * @param el element to be added
863
     * @param order order of the elements which must be followed
864
     * @throws IllegalArgumentException if the order cannot be followed, either
865
     * a missing existing or new child element is not specifed in order
866
     *
867
     * @since 8.4
868
     */
869
    public static void appendChildElement(Element parent, Element el, String[] order) throws IllegalArgumentException {
870
        List l = Arrays.asList(order);
871
        int index = l.indexOf(el.getLocalName());
872
873
        // ensure the new new element is contained in the 'order'
874
        if (index == -1) {
875
            throw new IllegalArgumentException("new child element '"+ el.getLocalName() + "' not specified in order " + l); // NOI18N
876
        }
877
878
        List<Element> elements = findSubElements(parent);
879
        Element insertBefore = null;
880
881
        for (Element e : elements) {
882
            int index2 = l.indexOf(e.getLocalName());
883
            // ensure that all existing elements are in 'order'
884
            if (index2 == -1) {
885
                throw new IllegalArgumentException("Existing child element '" + e.getLocalName() + "' not specified in order " + l);  // NOI18N
886
            }
887
            if (index2 > index) {
888
                insertBefore = e;
889
                break;
890
            }
891
        }
892
893
        parent.insertBefore(el, insertBefore);
894
    }
895
896
    /**
897
     * Find all direct child elements of an element.
898
     * Children which are all-whitespace text nodes or comments are ignored; others cause
899
     * an exception to be thrown.
900
     * @param parent a parent element in a DOM tree
901
     * @return a list of direct child elements (may be empty)
902
     * @throws IllegalArgumentException if there are non-element children besides whitespace
903
     * 
904
     * @since 8.4
905
     */
906
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
907
        NodeList l = parent.getChildNodes();
908
        List<Element> elements = new ArrayList<Element>(l.getLength());
909
        for (int i = 0; i < l.getLength(); i++) {
910
            Node n = l.item(i);
911
            if (n.getNodeType() == Node.ELEMENT_NODE) {
912
                elements.add((Element) n);
913
            } else if (n.getNodeType() == Node.TEXT_NODE) {
914
                String text = ((Text) n).getNodeValue();
915
                if (text.trim().length() > 0) {
916
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
917
                }
918
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
919
                // OK, ignore
920
            } else {
921
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
922
            }
923
        }
924
        return elements;
925
    }
926
927
    /**
928
     * Search for an XML element in the direct children of parent only.
929
     *
930
     * This compares localName (nodeName if localName is null) to name,
931
     * and checks the tags namespace with the provided namespace.
932
     * A <code>null</code> namespace will match any namespace.
933
     *
934
     * <ul>This is differs from the DOM version by:
935
     * <li>not searching recursively</li>
936
     * <li>returns a single result</li>
937
     * </ul>
938
     *
939
     * @param parent a parent element
940
     * @param name the intended local name
941
     * @param namespace the intended namespace (or null)
942
     * @return the one child element with that name, or null if none
943
     * @throws IllegalArgumentException if there is multiple elements of the same name
944
     * 
945
     * @since 8.4
946
     */
947
    public static Element findElement(Element parent, String name, String namespace) throws IllegalArgumentException {
948
        Element result = null;
949
        NodeList l = parent.getChildNodes();
950
        int nodeCount = l.getLength();
951
        for (int i = 0; i < nodeCount; i++) {
952
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
953
                Node node = l.item(i);
954
                String localName = node.getLocalName();
955
                localName = localName == null ? node.getNodeName() : localName;
956
                
957
                if (name.equals(localName)
958
			&& (namespace == null || namespace.equals(node.getNamespaceURI()))) {
959
                    if (result == null) {
960
                        result = (Element)node;
961
                    } else {
962
                        throw new IllegalArgumentException("more than one element with same name found");
963
                    }
964
                }
965
            }
966
        }
967
        return result;
968
    }
969
970
    /**
971
     * Extract nested text from a node.
972
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
973
     * @param parent a parent element
974
     * @return the nested text, or null if none was found
975
     * 
976
     * @since 8.4
977
     */
978
    public static String findText(Node parent) {
979
        NodeList l = parent.getChildNodes();
980
        for (int i = 0; i < l.getLength(); i++) {
981
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
982
                Text text = (Text) l.item(i);
983
                return text.getNodeValue();
984
            }
985
        }
986
        return null;
987
    }
988
989
    /**
990
     * Convert an XML fragment from one namespace to another.
991
     * 
992
     * @param from element to translate
993
     * @param namespace namespace to be translated to
994
     * @return
995
     * 
996
     * @since 8.4
997
     */
998
    public static Element translateXML(Element from, String namespace) {
999
        Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
1000
        NodeList nl = from.getChildNodes();
1001
        int length = nl.getLength();
1002
        for (int i = 0; i < length; i++) {
1003
            Node node = nl.item(i);
1004
            Node newNode;
1005
            if (node.getNodeType() == Node.ELEMENT_NODE) {
1006
                newNode = translateXML((Element) node, namespace);
1007
            } else {
1008
                newNode = node.cloneNode(true);
1009
            }
1010
            to.appendChild(newNode);
1011
        }
1012
        NamedNodeMap m = from.getAttributes();
1013
        for (int i = 0; i < m.getLength(); i++) {
1014
            Node attr = m.item(i);
1015
            to.setAttribute(attr.getNodeName(), attr.getNodeValue());
1016
        }
1017
        return to;
1018
    }
1019
1020
    /**
1021
     * Copy elements from one document to another attaching at the specified element
1022
     * and translating the namespace.
1023
     *
1024
     * @param from copy the children of this element (exclusive)
1025
     * @param to where to attach the copied elements
1026
     * @param newNamespace destination namespace
1027
     * 
1028
     * @since 8.4
1029
     */
1030
    public static void copyDocument(Element from, Element to, String newNamespace) {
1031
        Document doc = to.getOwnerDocument();
1032
        NodeList nl = from.getChildNodes();
1033
        int length = nl.getLength();
1034
        for (int i = 0; i < length; i++) {
1035
            Node node = nl.item(i);
1036
            Node newNode = null;
1037
            if (Node.ELEMENT_NODE == node.getNodeType()) {
1038
                Element oldElement = (Element) node;
1039
                newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
1040
                NamedNodeMap m = oldElement.getAttributes();
1041
                Element newElement = (Element) newNode;
1042
                for (int index = 0; index < m.getLength(); index++) {
1043
                    Node attr = m.item(index);
1044
                    newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
1045
                }
1046
                copyDocument(oldElement, newElement, newNamespace);
1047
            } else {
1048
                newNode = node.cloneNode(true);
1049
                newNode = to.getOwnerDocument().importNode(newNode, true);
1050
            }
1051
            if (newNode != null) {
1052
                to.appendChild(newNode);
1053
            }
1054
        }
1055
    }
1056
1057
    /**
1058
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
1059
     * @return a standard error handler
1060
     *
1061
     * @since 8.4
1062
     */
1063
    public static ErrorHandler defaultErrorHandler() {
1064
        return new ErrHandler();
1065
    }
1066
1067
    private static final class ErrHandler implements ErrorHandler {
1068
1069
        public ErrHandler() {}
1070
1071
        private void annotate(SAXParseException exception) throws SAXException {
1072
            Exceptions.attachMessage(exception, "Occurred at: " + exception.getSystemId() + ":" + exception.getLineNumber()); // NOI18N
1073
        }
1074
1075
        public void fatalError(SAXParseException exception) throws SAXException {
1076
            annotate(exception);
1077
            throw exception;
1078
        }
1079
1080
        public void error(SAXParseException exception) throws SAXException {
1081
            annotate(exception);
1082
            throw exception;
1083
        }
1084
1085
        public void warning(SAXParseException exception) throws SAXException {
1086
            annotate(exception);
1087
            Logger.getLogger(XMLUtil.class.getName()).log(Level.INFO, null, exception);
1088
        }
1089
1090
    }
845
}
1091
}
(-)a/openide.util/test/unit/src/org/openide/xml/XMLUtilTest.java (+207 lines)
Lines 49-54 Link Here
49
import java.io.StringReader;
49
import java.io.StringReader;
50
import java.lang.ref.Reference;
50
import java.lang.ref.Reference;
51
import java.lang.ref.WeakReference;
51
import java.lang.ref.WeakReference;
52
import java.util.List;
52
import javax.xml.XMLConstants;
53
import javax.xml.XMLConstants;
53
import javax.xml.parsers.DocumentBuilderFactory;
54
import javax.xml.parsers.DocumentBuilderFactory;
54
import javax.xml.transform.stream.StreamSource;
55
import javax.xml.transform.stream.StreamSource;
Lines 497-500 Link Here
497
        assertGC("can collect resolver", resolverRef);
498
        assertGC("can collect resolver", resolverRef);
498
    }
499
    }
499
500
501
    public void testAppendChildElement() throws Exception {
502
        Document doc = XMLUtil.parse(new InputSource(new StringReader("<root></root>")), false, true, null, null);
503
        Element parent = doc.createElementNS("unittest", "parent");
504
        Element newElement1 = doc.createElementNS("unittest", "new_element1");
505
        Element newElement2 = doc.createElementNS("unittest", "new_element2");
506
        Element newElement3 = doc.createElementNS("unittest", "new_element3");
507
508
        // append to the default root node (no match in order)
509
        XMLUtil.appendChildElement(parent, newElement1, new String[] { "new_element2", "new_element1" });
510
        NodeList children = parent.getChildNodes();
511
        assertEquals(1, children.getLength());
512
513
        // append after the child we just appended
514
        XMLUtil.appendChildElement(parent, newElement2, new String[] { "new_element2", "new_element1" });
515
516
        children = parent.getChildNodes();
517
        assertEquals(2, children.getLength());
518
        Node firstChild = parent.getChildNodes().item(0);
519
        Node secondChild = parent.getChildNodes().item(1);
520
        assertEquals("new_element2", firstChild.getNodeName());
521
        assertEquals("new_element1", secondChild.getNodeName());
522
523
        // failures
524
525
        try {
526
            // new child is not in the order list
527
            XMLUtil.appendChildElement(parent, newElement3, new String[] { "new_element2", "new_element1"});
528
            fail("Expecting IAE");
529
        } catch (IllegalArgumentException e) {
530
            assertEquals("new child element 'new_element3' not specified in order [new_element2, new_element1]", e.getMessage());
531
        }
532
        try {
533
            // existing child not in the order list
534
            XMLUtil.appendChildElement(parent, newElement3, new String[] { "new_element3"});
535
            fail("Expecting IAE");
536
        } catch (IllegalArgumentException e) {
537
            assertEquals("Existing child element 'new_element2' not specified in order [new_element3]", e.getMessage());
538
        }
539
    }
540
541
    public void testFindSubElements() throws Exception {
542
        Document doc = XMLUtil.parse(new InputSource(new StringReader("<root> <child1></child1><child2/><!-- comment --><child3/></root>")),
543
                false, true, null, null);
544
545
        Element parent = doc.getDocumentElement();
546
        assertEquals(5, parent.getChildNodes().getLength());
547
        List<Element> subElements = XMLUtil.findSubElements(parent);
548
        assertEquals(3, subElements.size());
549
        Element firstChild = subElements.get(0);
550
        Element secondChild = subElements.get(1);
551
        Element thirdChild = subElements.get(2);
552
553
        assertEquals("child1", firstChild.getNodeName());
554
        assertEquals("child2", secondChild.getNodeName());
555
        assertEquals("child3", thirdChild.getNodeName());
556
557
        Document failureDoc = XMLUtil.parse(new InputSource(new StringReader("<root>Non whitespace<!-- comment --></root>")),
558
            false, true, null, null);
559
        Element failedParent = failureDoc.getDocumentElement();
560
        try {
561
            XMLUtil.findSubElements(failedParent);
562
            fail("expected IAE");
563
        } catch (IllegalArgumentException e) { }
564
    }
565
566
    public void testFindElement() throws Exception {
567
        String xmlDoc = "<root> " +
568
                        " <h:table xmlns:h=\"http://www.w3.org/TR/html4/\">" +
569
                        " </h:table>" +
570
                        " <f:table xmlns:f=\"http://www.w3schools.com/furniture\">" +
571
                        " </f:table>" +
572
                        " <dup/><dup/>" +
573
                        " <h:form xmlns:h=\"http://www.w3.org/TR/html4/\">" +
574
                        " </h:form>" +
575
                        "</root>";
576
        
577
        Document doc = XMLUtil.parse(new InputSource(new StringReader(xmlDoc)), false, true, null, null);
578
        Element parent = doc.getDocumentElement();
579
580
        Element doesNotExist1 = XMLUtil.findElement(parent, "doesNotExist", "h");
581
        assertNull(doesNotExist1);
582
583
        Element doesNotExist2 = XMLUtil.findElement(parent, "doesNotExist", null);
584
        assertNull(doesNotExist2);
585
586
        Element noTable2 = XMLUtil.findElement(parent, "table", "h");
587
        assertNull(noTable2);
588
589
        Element noTable3 = XMLUtil.findElement(parent, "table", "f");
590
        assertNull(noTable3);
591
592
        Element table1 = XMLUtil.findElement(parent, "table", "http://www.w3.org/TR/html4/");
593
        assertNotNull(table1);
594
595
        Element table2 = XMLUtil.findElement(parent, "table", "http://www.w3schools.com/furniture");
596
        assertNotNull(table2);
597
598
        Element form1 = XMLUtil.findElement(parent, "form", "http://www.w3.org/TR/html4/");
599
        assertNotNull(form1);
600
601
        Element form2 = XMLUtil.findElement(parent, "form", null);
602
        assertNotNull(form2);
603
604
        assertEquals(form1, form2);
605
606
        try {
607
            XMLUtil.findElement(parent, "dup", null);
608
            fail("Expected IAE");
609
        } catch (IllegalArgumentException e) { }
610
611
        try {
612
            XMLUtil.findElement(parent, "table", null);
613
            fail("Expected IAE");
614
        } catch (IllegalArgumentException e) { }
615
    }
616
617
    public void testFindText() throws Exception {
618
        Document doc = XMLUtil.parse(new InputSource(new StringReader("<root>Text To Find<child></child></root>")),
619
                false, true, null, null);
620
621
        Element parent = doc.getDocumentElement();
622
        String foundText = XMLUtil.findText(parent);
623
624
        assertEquals("Text To Find", foundText);
625
626
        String notFoundText = XMLUtil.findText(parent.getFirstChild());
627
628
        assertNull(notFoundText);
629
    }
630
631
    public void testTranslateXML() throws Exception {
632
        // don't add any whitespace to the first 3 nodes
633
        String xmlDoc = "<root><table bgcolor='red'><tr>" +
634
                        "   <td>Apples</td>" +
635
                        "   <td>Bananas</td>" +
636
                        "  </tr>" +
637
                        " </table>" +
638
                        " <!-- comment -->" +
639
                        "<![CDATA[free form data]]>" +
640
                        "</root>";
641
642
        Document doc = XMLUtil.parse(new InputSource(new StringReader(xmlDoc)), false, true, null, null);
643
        Element parent = doc.getDocumentElement();
644
645
        Element translated = XMLUtil.translateXML((Element) parent.getFirstChild(), "http://www.w3.org/TR/html4/");
646
647
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
648
        XMLUtil.write(doc, baos, "UTF-8");
649
650
        Document destDoc = XMLUtil.parse(new InputSource(new StringReader("<root/>")), false, true, null, null);
651
652
        destDoc.importNode(translated, true);
653
        baos = new ByteArrayOutputStream();
654
        XMLUtil.write(destDoc, baos, "UTF-8");
655
656
        assertEquals("http://www.w3.org/TR/html4/", translated.getNamespaceURI());
657
        assertEquals(1, translated.getAttributes().getLength());
658
659
        assertEquals("http://www.w3.org/TR/html4/", translated.getFirstChild().getNamespaceURI());
660
        assertEquals(0, translated.getFirstChild().getAttributes().getLength());
661
    }
662
663
    public void testCopyDocument() throws Exception {
664
        String srcXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
665
                        "<root>" +
666
                        "   <table bgcolor='red'>" +
667
                        "    <tr>" +
668
                        "           <td>Apples</td>" +
669
                        "           <td>Bananas</td>" +
670
                        "       </tr>" +
671
                        "   </table>" +
672
                        " <!-- comment -->" +
673
                        "</root>";
674
675
        String resultXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
676
                        "<root>\n" +
677
                        "    <table xmlns=\"http://www.w3.org/TR/html4/\" bgcolor=\"red\">\n" +
678
                        "        <tr>\n" +
679
                        "            <td>Apples</td>\n" +
680
                        "            <td>Bananas</td>\n" +
681
                        "        </tr>\n" +
682
                        "    </table>\n" +
683
                        "    <!-- comment -->\n" +
684
                        "</root>\n";
685
686
        Document srcDoc = XMLUtil.parse(new InputSource(new StringReader(srcXml)), false, true, null, null);
687
        Element srcRoot = srcDoc.getDocumentElement();
688
689
        Document dstDoc = XMLUtil.parse(new InputSource(new StringReader("<root/>")), false, true, null, null);
690
691
        Element dstRoot = dstDoc.getDocumentElement();
692
        XMLUtil.copyDocument(srcRoot, dstRoot, "http://www.w3.org/TR/html4/");
693
694
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
695
        XMLUtil.write(dstDoc, baos, "UTF-8");
696
        assertEquals(resultXml, baos.toString());
697
698
        assertEquals(1, dstDoc.getChildNodes().getLength());
699
        Element root = dstDoc.getDocumentElement();
700
        Element tableNode = (Element) root.getFirstChild().getNextSibling();
701
702
        assertEquals("table", tableNode.getNodeName());
703
        assertEquals("http://www.w3.org/TR/html4/", tableNode.getNamespaceURI());
704
        assertEquals(1, tableNode.getAttributes().getLength());
705
    }
706
500
}
707
}
(-)a/profiler.nbmodule/nbproject/project.xml (-1 / +1 lines)
Lines 146-152 Link Here
146
                    <build-prerequisite/>
146
                    <build-prerequisite/>
147
                    <compile-dependency/>
147
                    <compile-dependency/>
148
                    <run-dependency>
148
                    <run-dependency>
149
                        <specification-version>8.0</specification-version>
149
                        <specification-version>8.4</specification-version>
150
                    </run-dependency>
150
                    </run-dependency>
151
                </dependency>
151
                </dependency>
152
                <dependency>
152
                <dependency>
(-)a/profiler.nbmodule/src/org/netbeans/modules/profiler/nbmodule/NbModuleProjectTypeProfiler.java (-33 / +3 lines)
Lines 60-67 Link Here
60
import org.netbeans.lib.profiler.common.Profiler;
60
import org.netbeans.lib.profiler.common.Profiler;
61
import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
61
import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
62
import org.netbeans.modules.profiler.projectsupport.utilities.SourceUtils;
62
import org.netbeans.modules.profiler.projectsupport.utilities.SourceUtils;
63
import org.w3c.dom.Node;
63
import org.openide.xml.XMLUtil;
64
import org.w3c.dom.NodeList;
65
64
66
65
67
/**
66
/**
Lines 258-298 Link Here
258
        }
257
        }
259
        
258
        
260
        // Module is a NB module suite component, not a NB source module
259
        // Module is a NB module suite component, not a NB source module
261
        if (findElement(e, "suite-component", namespace) != null) return false; // NOI18N
260
        if (XMLUtil.findElement(e, "suite-component", namespace) != null) return false; // NOI18N
262
        
261
        
263
        // Module is a NB module suite component, not a NB source module
262
        // Module is a NB module suite component, not a NB source module
264
        if (findElement(e, "standalone", namespace) != null) return false; // NOI18N
263
        if (XMLUtil.findElement(e, "standalone", namespace) != null) return false; // NOI18N
265
        
264
        
266
        // Module is a NB source module (neither suite component nor standalone)
265
        // Module is a NB source module (neither suite component nor standalone)
267
        return true;
266
        return true;
268
    }
267
    }
269
    
270
    // COPIED FROM org.netbeans.modules.project.ant:
271
    // (except for namespace == null support in findElement)
272
    // (and support for comments in findSubElements)
273
    
274
    /**
275
     * Search for an XML element in the direct children of a parent.
276
     * DOM provides a similar method but it does a recursive search
277
     * which we do not want. It also gives a node list and we want
278
     * only one result.
279
     * @param parent a parent element
280
     * @param name the intended local name
281
     * @param namespace the intended namespace (or null)
282
     * @return the first child element with that name, or null if none
283
     */
284
    private static Element findElement(Element parent, String name, String namespace) {
285
        NodeList l = parent.getChildNodes();
286
        for (int i = 0; i < l.getLength(); i++) {
287
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
288
                Element el = (Element)l.item(i);
289
                if ((namespace == null && name.equals(el.getTagName())) ||
290
                        (namespace != null && name.equals(el.getLocalName()) &&
291
                        namespace.equals(el.getNamespaceURI()))) {
292
                    return el;
293
                }
294
            }
295
        }
296
        return null;
297
    }
298
}
268
}
(-)a/project.ant/nbproject/project.xml (-1 / +1 lines)
Lines 166-172 Link Here
166
                    <build-prerequisite/>
166
                    <build-prerequisite/>
167
                    <compile-dependency/>
167
                    <compile-dependency/>
168
                    <run-dependency>
168
                    <run-dependency>
169
                        <specification-version>8.0</specification-version>
169
                        <specification-version>8.4</specification-version>
170
                    </run-dependency>
170
                    </run-dependency>
171
                </dependency>
171
                </dependency>
172
                <dependency>
172
                <dependency>
(-)a/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java (-5 / +5 lines)
Lines 190-198 Link Here
190
        try {
190
        try {
191
            Document projectXml = loadProjectXml(projectDiskFile);
191
            Document projectXml = loadProjectXml(projectDiskFile);
192
            if (projectXml != null) {
192
            if (projectXml != null) {
193
                Element typeEl = Util.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
193
                Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
194
                if (typeEl != null) {
194
                if (typeEl != null) {
195
                    String type = Util.findText(typeEl);
195
                    String type = XMLUtil.findText(typeEl);
196
                    if (type != null) {
196
                    if (type != null) {
197
                        AntBasedProjectType provider = findAntBasedProjectType(type);
197
                        AntBasedProjectType provider = findAntBasedProjectType(type);
198
                        if (provider != null) {
198
                        if (provider != null) {
Lines 236-247 Link Here
236
            LOG.log(Level.FINE, "could not load {0}", projectDiskFile);
236
            LOG.log(Level.FINE, "could not load {0}", projectDiskFile);
237
            return null;
237
            return null;
238
        }
238
        }
239
        Element typeEl = Util.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
239
        Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
240
        if (typeEl == null) {
240
        if (typeEl == null) {
241
            LOG.log(Level.FINE, "no <type> in {0}", projectDiskFile);
241
            LOG.log(Level.FINE, "no <type> in {0}", projectDiskFile);
242
            return null;
242
            return null;
243
        }
243
        }
244
        String type = Util.findText(typeEl);
244
        String type = XMLUtil.findText(typeEl);
245
        if (type == null) {
245
        if (type == null) {
246
            LOG.log(Level.FINE, "no <type> text in {0}", projectDiskFile);
246
            LOG.log(Level.FINE, "no <type> text in {0}", projectDiskFile);
247
            return null;
247
            return null;
Lines 338-344 Link Here
338
            } catch (ParserConfigurationException x) {
338
            } catch (ParserConfigurationException x) {
339
                throw new SAXException(x);
339
                throw new SAXException(x);
340
            }
340
            }
341
            builder.setErrorHandler(Util.defaultErrorHandler());
341
            builder.setErrorHandler(XMLUtil.defaultErrorHandler());
342
            Document projectXml = builder.parse(src);
342
            Document projectXml = builder.parse(src);
343
            LOG.fine("parsed document");
343
            LOG.fine("parsed document");
344
//            dumpFields(projectXml);
344
//            dumpFields(projectXml);
(-)a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java (-3 / +3 lines)
Lines 436-444 Link Here
436
    public static String getLibrariesLocationText(AuxiliaryConfiguration aux) {
436
    public static String getLibrariesLocationText(AuxiliaryConfiguration aux) {
437
        Element libraries = aux.getConfigurationFragment(EL_LIBRARIES, NAMESPACE, true);
437
        Element libraries = aux.getConfigurationFragment(EL_LIBRARIES, NAMESPACE, true);
438
        if (libraries != null) {
438
        if (libraries != null) {
439
            for (Element definitions : Util.findSubElements(libraries)) {
439
            for (Element definitions : XMLUtil.findSubElements(libraries)) {
440
                assert definitions.getLocalName().equals(EL_DEFINITIONS) : definitions;
440
                assert definitions.getLocalName().equals(EL_DEFINITIONS) : definitions;
441
                String text = Util.findText(definitions);
441
                String text = XMLUtil.findText(definitions);
442
                assert text != null : aux;
442
                assert text != null : aux;
443
                return text;
443
                return text;
444
            }
444
            }
Lines 1012-1018 Link Here
1012
        if (libraries == null) {
1012
        if (libraries == null) {
1013
            libraries = XMLUtil.createDocument("dummy", null, null, null).createElementNS(NAMESPACE, EL_LIBRARIES); // NOI18N
1013
            libraries = XMLUtil.createDocument("dummy", null, null, null).createElementNS(NAMESPACE, EL_LIBRARIES); // NOI18N
1014
        } else {
1014
        } else {
1015
            List<Element> elements = Util.findSubElements(libraries);
1015
            List<Element> elements = XMLUtil.findSubElements(libraries);
1016
            if (elements.size() == 1) {
1016
            if (elements.size() == 1) {
1017
                libraries.removeChild(elements.get(0));
1017
                libraries.removeChild(elements.get(0));
1018
            }
1018
            }
(-)a/project.ant/src/org/netbeans/modules/project/ant/ProjectXMLCatalogReader.java (-24 / +1 lines)
Lines 68-74 Link Here
68
import org.openide.util.NbCollections;
68
import org.openide.util.NbCollections;
69
import org.openide.xml.XMLUtil;
69
import org.openide.xml.XMLUtil;
70
import org.w3c.dom.Element;
70
import org.w3c.dom.Element;
71
import org.w3c.dom.NamedNodeMap;
72
import org.w3c.dom.Node;
71
import org.w3c.dom.Node;
73
import org.w3c.dom.NodeList;
72
import org.w3c.dom.NodeList;
74
import org.xml.sax.SAXException;
73
import org.xml.sax.SAXException;
Lines 251-257 Link Here
251
                        try {
250
                        try {
252
                            String ns2 = ns.substring(0, slash + 1) + Integer.toString(Integer.parseInt(ns.substring(slash + 1)) + 1);
251
                            String ns2 = ns.substring(0, slash + 1) + Integer.toString(Integer.parseInt(ns.substring(slash + 1)) + 1);
253
                            if (_resolveURI(ns2) != null) {
252
                            if (_resolveURI(ns2) != null) {
254
                                Element data2 = translateXML(data, ns2);
253
                                Element data2 = XMLUtil.translateXML(data, ns2);
255
                                data.getParentNode().replaceChild(data2, data);
254
                                data.getParentNode().replaceChild(data2, data);
256
                                try {
255
                                try {
257
                                    validate(attempt);
256
                                    validate(attempt);
Lines 315-340 Link Here
315
        return null;
314
        return null;
316
    }
315
    }
317
316
318
    private static Element translateXML(Element from, String namespace) { // XXX use #136595
319
        Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
320
        NodeList nl = from.getChildNodes();
321
        int length = nl.getLength();
322
        for (int i = 0; i < length; i++) {
323
            Node node = nl.item(i);
324
            Node newNode;
325
            if (node.getNodeType() == Node.ELEMENT_NODE) {
326
                newNode = translateXML((Element) node, namespace);
327
            } else {
328
                newNode = node.cloneNode(true);
329
            }
330
            to.appendChild(newNode);
331
        }
332
        NamedNodeMap m = from.getAttributes();
333
        for (int i = 0; i < m.getLength(); i++) {
334
            Node attr = m.item(i);
335
            to.setAttribute(attr.getNodeName(), attr.getNodeValue());
336
        }
337
        return to;
338
    }
339
340
}
317
}
(-)a/project.ant/src/org/netbeans/modules/project/ant/Util.java (-175 lines)
Lines 1-175 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.project.ant;
43
44
import java.util.ArrayList;
45
import java.util.List;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import org.openide.util.Exceptions;
49
import org.w3c.dom.Element;
50
import org.w3c.dom.Node;
51
import org.w3c.dom.NodeList;
52
import org.w3c.dom.Text;
53
import org.xml.sax.ErrorHandler;
54
import org.xml.sax.SAXException;
55
import org.xml.sax.SAXParseException;
56
57
/**
58
 * Utilities relating to Ant projects.
59
 * @author Jesse Glick
60
 */
61
public class Util {
62
63
    private Util() {}
64
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 (namespace.equals(el.getNamespaceURI()) && name.equals(el.getLocalName())) {
83
                    if (result == null) {
84
                        result = el;
85
                    } else {
86
                        return null;
87
                    }
88
                }
89
            }
90
        }
91
        return result;
92
    }
93
    
94
    /**
95
     * Extract nested text from an element.
96
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
97
     * @param parent a parent element
98
     * @return the nested text, or null if none was found
99
     */
100
    public static String findText(Element parent) {
101
        NodeList l = parent.getChildNodes();
102
        for (int i = 0; i < l.getLength(); i++) {
103
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
104
                Text text = (Text)l.item(i);
105
                return text.getNodeValue();
106
            }
107
        }
108
        return null;
109
    }
110
    
111
    /**
112
     * Find all direct child elements of an element.
113
     * More useful than {@link Element#getElementsByTagNameNS} because it does
114
     * not recurse into recursive child elements.
115
     * Children which are all-whitespace text nodes are ignored; others cause
116
     * an exception to be thrown.
117
     * @param parent a parent element in a DOM tree
118
     * @return a list of direct child elements (may be empty)
119
     * @throws IllegalArgumentException if there are non-element children besides whitespace
120
     */
121
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
122
        NodeList l = parent.getChildNodes();
123
        List<Element> elements = new ArrayList<Element>(l.getLength());
124
        for (int i = 0; i < l.getLength(); i++) {
125
            Node n = l.item(i);
126
            if (n.getNodeType() == Node.ELEMENT_NODE) {
127
                elements.add((Element)n);
128
            } else if (n.getNodeType() == Node.TEXT_NODE) {
129
                String text = ((Text)n).getNodeValue();
130
                if (text.trim().length() > 0) {
131
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
132
                }
133
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
134
                // skip
135
            } else {
136
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
137
            }
138
        }
139
        return elements;
140
    }
141
    
142
    /**
143
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
144
     * @return a standard error handler
145
     */
146
    public static ErrorHandler defaultErrorHandler() {
147
        return new ErrHandler();
148
    }
149
    
150
    private static final class ErrHandler implements ErrorHandler {
151
        
152
        public ErrHandler() {}
153
        
154
        private void annotate(SAXParseException exception) throws SAXException {
155
            Exceptions.attachMessage(exception, "Occurred at: " + exception.getSystemId() + ":" + exception.getLineNumber()); // NOI18N
156
        }
157
        
158
        public void fatalError(SAXParseException exception) throws SAXException {
159
            annotate(exception);
160
            throw exception;
161
        }
162
        
163
        public void error(SAXParseException exception) throws SAXException {
164
            annotate(exception);
165
            throw exception;
166
        }
167
        
168
        public void warning(SAXParseException exception) throws SAXException {
169
            annotate(exception);
170
            Logger.getLogger(Util.class.getName()).log(Level.INFO, null, exception);
171
        }
172
        
173
    }
174
    
175
}
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java (-6 / +5 lines)
Lines 63-69 Link Here
63
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
63
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
64
import org.netbeans.modules.project.ant.ProjectXMLCatalogReader;
64
import org.netbeans.modules.project.ant.ProjectXMLCatalogReader;
65
import org.netbeans.modules.project.ant.UserQuestionHandler;
65
import org.netbeans.modules.project.ant.UserQuestionHandler;
66
import org.netbeans.modules.project.ant.Util;
67
import org.netbeans.spi.project.AuxiliaryConfiguration;
66
import org.netbeans.spi.project.AuxiliaryConfiguration;
68
import org.netbeans.spi.project.AuxiliaryProperties;
67
import org.netbeans.spi.project.AuxiliaryProperties;
69
import org.netbeans.spi.project.CacheDirectoryProvider;
68
import org.netbeans.spi.project.CacheDirectoryProvider;
Lines 301-307 Link Here
301
        File f = FileUtil.toFile(xml);
300
        File f = FileUtil.toFile(xml);
302
        assert f != null;
301
        assert f != null;
303
        try {
302
        try {
304
            Document doc = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
303
            Document doc = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
305
            ProjectXMLCatalogReader.validate(doc.getDocumentElement());
304
            ProjectXMLCatalogReader.validate(doc.getDocumentElement());
306
            return doc;
305
            return doc;
307
        } catch (IOException e) {
306
        } catch (IOException e) {
Lines 416-422 Link Here
416
        Document doc = getConfigurationXml(shared);
415
        Document doc = getConfigurationXml(shared);
417
        if (shared) {
416
        if (shared) {
418
            Element project = doc.getDocumentElement();
417
            Element project = doc.getDocumentElement();
419
            Element config = Util.findElement(project, "configuration", PROJECT_NS); // NOI18N
418
            Element config = XMLUtil.findElement(project, "configuration", PROJECT_NS); // NOI18N
420
            assert config != null;
419
            assert config != null;
421
            return config;
420
            return config;
422
        } else {
421
        } else {
Lines 892-898 Link Here
892
            public Element run() {
891
            public Element run() {
893
                synchronized (modifiedMetadataPaths) {
892
                synchronized (modifiedMetadataPaths) {
894
                    Element root = getConfigurationDataRoot(shared);
893
                    Element root = getConfigurationDataRoot(shared);
895
                    Element data = Util.findElement(root, elementName, namespace);
894
                    Element data = XMLUtil.findElement(root, elementName, namespace);
896
                    if (data != null) {
895
                    if (data != null) {
897
                        return cloneSafely(data);
896
                        return cloneSafely(data);
898
                    } else {
897
                    } else {
Lines 930-936 Link Here
930
            public Void run() {
929
            public Void run() {
931
                synchronized (modifiedMetadataPaths) {
930
                synchronized (modifiedMetadataPaths) {
932
                    Element root = getConfigurationDataRoot(shared);
931
                    Element root = getConfigurationDataRoot(shared);
933
                    Element existing = Util.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
932
                    Element existing = XMLUtil.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
934
                    // XXX first compare to existing and return if the same
933
                    // XXX first compare to existing and return if the same
935
                    if (existing != null) {
934
                    if (existing != null) {
936
                        root.removeChild(existing);
935
                        root.removeChild(existing);
Lines 972-978 Link Here
972
            public Boolean run() {
971
            public Boolean run() {
973
                synchronized (modifiedMetadataPaths) {
972
                synchronized (modifiedMetadataPaths) {
974
                    Element root = getConfigurationDataRoot(shared);
973
                    Element root = getConfigurationDataRoot(shared);
975
                    Element data = Util.findElement(root, elementName, namespace);
974
                    Element data = XMLUtil.findElement(root, elementName, namespace);
976
                    if (data != null) {
975
                    if (data != null) {
977
                        root.removeChild(data);
976
                        root.removeChild(data);
978
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
977
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java (-10 / +9 lines)
Lines 70-76 Link Here
70
import org.netbeans.api.queries.CollocationQuery;
70
import org.netbeans.api.queries.CollocationQuery;
71
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
71
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
72
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
72
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
73
import org.netbeans.modules.project.ant.Util;
74
import org.netbeans.spi.project.AuxiliaryConfiguration;
73
import org.netbeans.spi.project.AuxiliaryConfiguration;
75
import org.netbeans.spi.project.SubprojectProvider;
74
import org.netbeans.spi.project.SubprojectProvider;
76
import org.openide.ErrorManager;
75
import org.openide.ErrorManager;
Lines 569-575 Link Here
569
        // Linear search; always keeping references sorted first by foreign project
568
        // Linear search; always keeping references sorted first by foreign project
570
        // name, then by target name.
569
        // name, then by target name.
571
        Element nextRefEl = null;
570
        Element nextRefEl = null;
572
        Iterator<Element> it = Util.findSubElements(references).iterator();
571
        Iterator<Element> it = XMLUtil.findSubElements(references).iterator();
573
        while (it.hasNext()) {
572
        while (it.hasNext()) {
574
            Element testRefEl = it.next();
573
            Element testRefEl = it.next();
575
            RawReference testRef = RawReference.create(testRefEl);
574
            RawReference testRef = RawReference.create(testRefEl);
Lines 816-822 Link Here
816
    
815
    
817
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
816
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
818
        // As with addRawReference, do a linear search through.
817
        // As with addRawReference, do a linear search through.
819
        for (Element testRefEl : Util.findSubElements(references)) {
818
        for (Element testRefEl : XMLUtil.findSubElements(references)) {
820
            RawReference testRef = RawReference.create(testRefEl);
819
            RawReference testRef = RawReference.create(testRefEl);
821
            String refID = testRef.getID();
820
            String refID = testRef.getID();
822
            String refName = testRef.getForeignProjectName();
821
            String refName = testRef.getForeignProjectName();
Lines 869-875 Link Here
869
    }
868
    }
870
    
869
    
871
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
870
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
872
        List<Element> subEls = Util.findSubElements(references);
871
        List<Element> subEls = XMLUtil.findSubElements(references);
873
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
872
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
874
        for (Element subEl : subEls) {
873
        for (Element subEl : subEls) {
875
            refs.add(RawReference.create(subEl));
874
            refs.add(RawReference.create(subEl));
Lines 911-917 Link Here
911
    }
910
    }
912
    
911
    
913
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
912
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
914
        for (Element subEl : Util.findSubElements(references)) {
913
        for (Element subEl : XMLUtil.findSubElements(references)) {
915
            RawReference ref = RawReference.create(subEl);
914
            RawReference ref = RawReference.create(subEl);
916
            String refID = ref.getID();
915
            String refID = ref.getID();
917
            String refName = ref.getForeignProjectName();
916
            String refName = ref.getForeignProjectName();
Lines 1693-1699 Link Here
1693
                if (idx == -1) {
1692
                if (idx == -1) {
1694
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1693
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1695
                }
1694
                }
1696
                String val = Util.findText(el);
1695
                String val = XMLUtil.findText(el);
1697
                if (val == null) {
1696
                if (val == null) {
1698
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1697
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1699
                }
1698
                }
Lines 1711-1717 Link Here
1711
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1710
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1712
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1711
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1713
            }
1712
            }
1714
            List nl = Util.findSubElements(xml);
1713
            List nl = XMLUtil.findSubElements(xml);
1715
            if (nl.size() < 6) {
1714
            if (nl.size() < 6) {
1716
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1715
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1717
            }
1716
            }
Lines 1726-1732 Link Here
1726
                if (idx == -1) {
1725
                if (idx == -1) {
1727
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1726
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1728
                }
1727
                }
1729
                String val = Util.findText(el);
1728
                String val = XMLUtil.findText(el);
1730
                if (val == null) {
1729
                if (val == null) {
1731
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1730
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1732
                }
1731
                }
Lines 1744-1752 Link Here
1744
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1743
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1745
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1744
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1746
                }
1745
                }
1747
                for (Element el2 : Util.findSubElements(el)) {
1746
                for (Element el2 : XMLUtil.findSubElements(el)) {
1748
                    String key = el2.getAttribute("name");
1747
                    String key = el2.getAttribute("name");
1749
                    String value = Util.findText(el2);
1748
                    String value = XMLUtil.findText(el2);
1750
                    // #53553: NPE
1749
                    // #53553: NPE
1751
                    if (value == null) {
1750
                    if (value == null) {
1752
                        value = ""; // NOI18N
1751
                        value = ""; // NOI18N
(-)a/project.ant/test/unit/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingletonTest.java (-1 / +2 lines)
Lines 58-63 Link Here
58
import org.openide.util.Lookup;
58
import org.openide.util.Lookup;
59
import org.openide.util.lookup.Lookups;
59
import org.openide.util.lookup.Lookups;
60
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
61
import org.openide.xml.XMLUtil;
61
import org.w3c.dom.Element;
62
import org.w3c.dom.Element;
62
63
63
public class AntBasedProjectFactorySingletonTest extends NbTestCase {
64
public class AntBasedProjectFactorySingletonTest extends NbTestCase {
Lines 238-244 Link Here
238
    }
239
    }
239
    private static String namesOfChildren(Element e) {
240
    private static String namesOfChildren(Element e) {
240
        StringBuilder b = new StringBuilder();
241
        StringBuilder b = new StringBuilder();
241
        for (Element kid : Util.findSubElements(e)) {
242
        for (Element kid : XMLUtil.findSubElements(e)) {
242
            if (b.length() > 0) {
243
            if (b.length() > 0) {
243
                b.append(' ');
244
                b.append(' ');
244
            }
245
            }
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java (-4 / +3 lines)
Lines 70-76 Link Here
70
import org.netbeans.api.project.Project;
70
import org.netbeans.api.project.Project;
71
import org.netbeans.api.project.ant.AntArtifact;
71
import org.netbeans.api.project.ant.AntArtifact;
72
import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider;
72
import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider;
73
import org.netbeans.modules.project.ant.Util;
74
import org.netbeans.spi.diff.DiffProvider;
73
import org.netbeans.spi.diff.DiffProvider;
75
import org.netbeans.spi.project.AuxiliaryConfiguration;
74
import org.netbeans.spi.project.AuxiliaryConfiguration;
76
import org.netbeans.api.project.ProjectInformation;
75
import org.netbeans.api.project.ProjectInformation;
Lines 225-233 Link Here
225
            
224
            
226
            private String getText(String elementName) {
225
            private String getText(String elementName) {
227
                Element data = helper.getPrimaryConfigurationData(true);
226
                Element data = helper.getPrimaryConfigurationData(true);
228
                Element el = Util.findElement(data, elementName, "urn:test:shared");
227
                Element el = XMLUtil.findElement(data, elementName, "urn:test:shared");
229
                if (el != null) {
228
                if (el != null) {
230
                    String text = Util.findText(el);
229
                    String text = XMLUtil.findText(el);
231
                    if (text != null) {
230
                    if (text != null) {
232
                        return text;
231
                        return text;
233
                    }
232
                    }
Lines 324-330 Link Here
324
        if (!f.isFile()) {
323
        if (!f.isFile()) {
325
            return null;
324
            return null;
326
        }
325
        }
327
        return XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
326
        return XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
328
    }
327
    }
329
    
328
    
330
    /**
329
    /**
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java (-38 / +37 lines)
Lines 54-60 Link Here
54
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.junit.NbTestCase;
55
import org.netbeans.junit.RandomlyFails;
55
import org.netbeans.junit.RandomlyFails;
56
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
56
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
57
import org.netbeans.modules.project.ant.Util;
58
import org.netbeans.spi.project.AuxiliaryConfiguration;
57
import org.netbeans.spi.project.AuxiliaryConfiguration;
59
import org.netbeans.spi.project.CacheDirectoryProvider;
58
import org.netbeans.spi.project.CacheDirectoryProvider;
60
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
Lines 156-167 Link Here
156
        Element data = h.getPrimaryConfigurationData(true);
155
        Element data = h.getPrimaryConfigurationData(true);
157
        assertEquals("correct element name", "data", data.getLocalName());
156
        assertEquals("correct element name", "data", data.getLocalName());
158
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
157
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
159
        Element stuff = Util.findElement(data, "shared-stuff", "urn:test:shared");
158
        Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
160
        assertNotNull("had nested stuff in it", stuff);
159
        assertNotNull("had nested stuff in it", stuff);
161
        data = h.getPrimaryConfigurationData(false);
160
        data = h.getPrimaryConfigurationData(false);
162
        assertEquals("correct element name", "data", data.getLocalName());
161
        assertEquals("correct element name", "data", data.getLocalName());
163
        assertEquals("correct element namespace", "urn:test:private", data.getNamespaceURI());
162
        assertEquals("correct element namespace", "urn:test:private", data.getNamespaceURI());
164
        stuff = Util.findElement(data, "private-stuff", "urn:test:private");
163
        stuff = XMLUtil.findElement(data, "private-stuff", "urn:test:private");
165
        assertNotNull("had nested stuff in it", stuff);
164
        assertNotNull("had nested stuff in it", stuff);
166
    }
165
    }
167
    
166
    
Lines 181-187 Link Here
181
        }
180
        }
182
        assertEquals("correct element name", "data", data.getLocalName());
181
        assertEquals("correct element name", "data", data.getLocalName());
183
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
182
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
184
        Element stuff = Util.findElement(data, "shared-stuff", "urn:test:shared");
183
        Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
185
        /* This now retains the former contents:
184
        /* This now retains the former contents:
186
        assertNull("had no stuff in it", stuff);
185
        assertNull("had no stuff in it", stuff);
187
         */
186
         */
Lines 192-204 Link Here
192
        pm.saveProject(p);
191
        pm.saveProject(p);
193
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
192
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
194
        Element root = doc.getDocumentElement();
193
        Element root = doc.getDocumentElement();
195
        Element type = Util.findElement(root, "type", AntProjectHelper.PROJECT_NS);
194
        Element type = XMLUtil.findElement(root, "type", AntProjectHelper.PROJECT_NS);
196
        assertEquals("correct restored type", "test", Util.findText(type));
195
        assertEquals("correct restored type", "test", XMLUtil.findText(type));
197
        Element config = Util.findElement(root, "configuration", AntProjectHelper.PROJECT_NS);
196
        Element config = XMLUtil.findElement(root, "configuration", AntProjectHelper.PROJECT_NS);
198
        assertNotNull("have <configuration>", config);
197
        assertNotNull("have <configuration>", config);
199
        data = Util.findElement(config, "data", "urn:test:shared");
198
        data = XMLUtil.findElement(config, "data", "urn:test:shared");
200
        assertNotNull("have <data>", data);
199
        assertNotNull("have <data>", data);
201
        Element details = Util.findElement(data, "details", "urn:test:shared");
200
        Element details = XMLUtil.findElement(data, "details", "urn:test:shared");
202
        assertNotNull("have <details>", details);
201
        assertNotNull("have <details>", details);
203
    }
202
    }
204
    
203
    
Lines 463-469 Link Here
463
    public void testPutPrimaryConfigurationData() throws Exception {
462
    public void testPutPrimaryConfigurationData() throws Exception {
464
        h.addAntProjectListener(l);
463
        h.addAntProjectListener(l);
465
        Element data = h.getPrimaryConfigurationData(true);
464
        Element data = h.getPrimaryConfigurationData(true);
466
        assertNotNull("<shared-stuff/> is there to start", Util.findElement(data, "shared-stuff", "urn:test:shared"));
465
        assertNotNull("<shared-stuff/> is there to start", XMLUtil.findElement(data, "shared-stuff", "urn:test:shared"));
467
        assertTrue("project is not initially modified", !pm.isModified(p));
466
        assertTrue("project is not initially modified", !pm.isModified(p));
468
        assertEquals("gPCD fires no events", 0, l.events().length);
467
        assertEquals("gPCD fires no events", 0, l.events().length);
469
        assertNotNull("config data has an owner document", data.getOwnerDocument());
468
        assertNotNull("config data has an owner document", data.getOwnerDocument());
Lines 471-477 Link Here
471
        data.appendChild(nue);
470
        data.appendChild(nue);
472
        assertTrue("project is not modified after uncommitted change", !pm.isModified(p));
471
        assertTrue("project is not modified after uncommitted change", !pm.isModified(p));
473
        assertEquals("no events fired after uncommitted change", 0, l.events().length);
472
        assertEquals("no events fired after uncommitted change", 0, l.events().length);
474
        assertEquals("after uncommitted change gPCD does not yet have new <misc/>", null, Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared"));
473
        assertEquals("after uncommitted change gPCD does not yet have new <misc/>", null, XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared"));
475
        h.putPrimaryConfigurationData(data, true);
474
        h.putPrimaryConfigurationData(data, true);
476
        assertTrue("project is modified after committed change", pm.isModified(p));
475
        assertTrue("project is modified after committed change", pm.isModified(p));
477
        AntProjectEvent[] evs = l.events();
476
        AntProjectEvent[] evs = l.events();
Lines 479-506 Link Here
479
        assertEquals("correct helper", h, evs[0].getHelper());
478
        assertEquals("correct helper", h, evs[0].getHelper());
480
        assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
479
        assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
481
        assertTrue("expected change", evs[0].isExpected());
480
        assertTrue("expected change", evs[0].isExpected());
482
        nue = Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
481
        nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
483
        assertNotNull("after committed change gPCD has new <misc/>", nue);
482
        assertNotNull("after committed change gPCD has new <misc/>", nue);
484
        assertEquals("new element name is correct", "misc", nue.getLocalName());
483
        assertEquals("new element name is correct", "misc", nue.getLocalName());
485
        assertEquals("new element namespace is correct", "urn:test:shared", nue.getNamespaceURI());
484
        assertEquals("new element namespace is correct", "urn:test:shared", nue.getNamespaceURI());
486
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
485
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
487
        Element configuration = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
486
        Element configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
488
        assertNotNull("still has <configuration> on disk", configuration);
487
        assertNotNull("still has <configuration> on disk", configuration);
489
        data = Util.findElement(configuration, "data", "urn:test:shared");
488
        data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
490
        assertNotNull("still has <data> on disk", data);
489
        assertNotNull("still has <data> on disk", data);
491
        nue = Util.findElement(data, "misc", "urn:test:shared");
490
        nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
492
        assertEquals("<misc/> not yet on disk", null, nue);
491
        assertEquals("<misc/> not yet on disk", null, nue);
493
        pm.saveProject(p);
492
        pm.saveProject(p);
494
        assertTrue("project is not modified after save", !pm.isModified(p));
493
        assertTrue("project is not modified after save", !pm.isModified(p));
495
        assertEquals("saving changes fires no new events", 0, l.events().length);
494
        assertEquals("saving changes fires no new events", 0, l.events().length);
496
        nue = Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
495
        nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
497
        assertNotNull("after save gPCD still has new <misc/>", nue);
496
        assertNotNull("after save gPCD still has new <misc/>", nue);
498
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
497
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
499
        configuration = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
498
        configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
500
        assertNotNull("still has <configuration> on disk", configuration);
499
        assertNotNull("still has <configuration> on disk", configuration);
501
        data = Util.findElement(configuration, "data", "urn:test:shared");
500
        data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
502
        assertNotNull("still has <data> on disk", data);
501
        assertNotNull("still has <data> on disk", data);
503
        nue = Util.findElement(data, "misc", "urn:test:shared");
502
        nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
504
        assertNotNull("<misc/> now on disk", nue);
503
        assertNotNull("<misc/> now on disk", nue);
505
        // #42147: changes made on disk should result in firing of an AntProjectEvent
504
        // #42147: changes made on disk should result in firing of an AntProjectEvent
506
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
505
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
Lines 516-527 Link Here
516
        assertFalse("unexpected change", evs[0].isExpected());
515
        assertFalse("unexpected change", evs[0].isExpected());
517
        assertEquals("correct new display name", "Some New Name", ProjectUtils.getInformation(p).getDisplayName());
516
        assertEquals("correct new display name", "Some New Name", ProjectUtils.getInformation(p).getDisplayName());
518
        data = h.getPrimaryConfigurationData(true);
517
        data = h.getPrimaryConfigurationData(true);
519
        Element stuff = Util.findElement(data, "other-shared-stuff", "urn:test:shared");
518
        Element stuff = XMLUtil.findElement(data, "other-shared-stuff", "urn:test:shared");
520
        assertNotNull("have <other-shared-stuff/> now", stuff);
519
        assertNotNull("have <other-shared-stuff/> now", stuff);
521
        AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
520
        AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
522
        data = aux.getConfigurationFragment("data", "urn:test:shared-aux", true);
521
        data = aux.getConfigurationFragment("data", "urn:test:shared-aux", true);
523
        assertNotNull("have aux <data>", data);
522
        assertNotNull("have aux <data>", data);
524
        stuff = Util.findElement(data, "other-aux-shared-stuff", "urn:test:shared-aux");
523
        stuff = XMLUtil.findElement(data, "other-aux-shared-stuff", "urn:test:shared-aux");
525
        assertNotNull("have <other-aux-shared-stuff/> now", stuff);
524
        assertNotNull("have <other-aux-shared-stuff/> now", stuff);
526
        // XXX try private.xml too
525
        // XXX try private.xml too
527
        // XXX try modifying both XML files, or different parts of the same, and saving in a batch
526
        // XXX try modifying both XML files, or different parts of the same, and saving in a batch
Lines 551-557 Link Here
551
        assertNotNull("found shared <data>", data);
550
        assertNotNull("found shared <data>", data);
552
        assertEquals("correct name", "data", data.getLocalName());
551
        assertEquals("correct name", "data", data.getLocalName());
553
        assertEquals("correct namespace", "urn:test:shared-aux", data.getNamespaceURI());
552
        assertEquals("correct namespace", "urn:test:shared-aux", data.getNamespaceURI());
554
        Element stuff = Util.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
553
        Element stuff = XMLUtil.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
555
        assertNotNull("found <aux-shared-stuff/>", stuff);
554
        assertNotNull("found <aux-shared-stuff/>", stuff);
556
        assertEquals("gCF fires no changes", 0, l.events().length);
555
        assertEquals("gCF fires no changes", 0, l.events().length);
557
        // Check write of shared data.
556
        // Check write of shared data.
Lines 567-577 Link Here
567
        pm.saveProject(p);
566
        pm.saveProject(p);
568
        assertEquals("saving project fires no new changes", 0, l.events().length);
567
        assertEquals("saving project fires no new changes", 0, l.events().length);
569
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
568
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
570
        Element config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
569
        Element config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
571
        assertNotNull("<configuration> still exists", config);
570
        assertNotNull("<configuration> still exists", config);
572
        data = Util.findElement(config, "data", "urn:test:shared-aux");
571
        data = XMLUtil.findElement(config, "data", "urn:test:shared-aux");
573
        assertNotNull("<data> still exists", data);
572
        assertNotNull("<data> still exists", data);
574
        stuff = Util.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
573
        stuff = XMLUtil.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
575
        assertNotNull("still have <aux-shared-stuff/>", stuff);
574
        assertNotNull("still have <aux-shared-stuff/>", stuff);
576
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
575
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
577
        // Check read of private data.
576
        // Check read of private data.
Lines 579-585 Link Here
579
        assertNotNull("found shared <data>", data);
578
        assertNotNull("found shared <data>", data);
580
        assertEquals("correct name", "data", data.getLocalName());
579
        assertEquals("correct name", "data", data.getLocalName());
581
        assertEquals("correct namespace", "urn:test:private-aux", data.getNamespaceURI());
580
        assertEquals("correct namespace", "urn:test:private-aux", data.getNamespaceURI());
582
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
581
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
583
        assertNotNull("found <aux-private-stuff/>", stuff);
582
        assertNotNull("found <aux-private-stuff/>", stuff);
584
        assertEquals("gCF fires no changes", 0, l.events().length);
583
        assertEquals("gCF fires no changes", 0, l.events().length);
585
        // Check write of private data.
584
        // Check write of private data.
Lines 596-604 Link Here
596
        assertEquals("saving project fires no new changes", 0, l.events().length);
595
        assertEquals("saving project fires no new changes", 0, l.events().length);
597
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
596
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
598
        config = doc.getDocumentElement();
597
        config = doc.getDocumentElement();
599
        data = Util.findElement(config, "data", "urn:test:private-aux");
598
        data = XMLUtil.findElement(config, "data", "urn:test:private-aux");
600
        assertNotNull("<data> still exists", data);
599
        assertNotNull("<data> still exists", data);
601
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
600
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
602
        assertNotNull("still have <aux-private-stuff/>", stuff);
601
        assertNotNull("still have <aux-private-stuff/>", stuff);
603
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
602
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
604
        // Check that missing fragments are not returned.
603
        // Check that missing fragments are not returned.
Lines 625-635 Link Here
625
        data = aux.getConfigurationFragment("hello", "urn:test:whatever", true);
624
        data = aux.getConfigurationFragment("hello", "urn:test:whatever", true);
626
        assertNotNull("can retrieve new frag", data);
625
        assertNotNull("can retrieve new frag", data);
627
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
626
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
628
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
627
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
629
        assertNotNull("<configuration> still exists", config);
628
        assertNotNull("<configuration> still exists", config);
630
        data = Util.findElement(config, "hello", "urn:test:whatever");
629
        data = XMLUtil.findElement(config, "hello", "urn:test:whatever");
631
        assertNotNull("<hello> still exists", data);
630
        assertNotNull("<hello> still exists", data);
632
        assertEquals("correct nested contents too", "stuff", Util.findText(data));
631
        assertEquals("correct nested contents too", "stuff", XMLUtil.findText(data));
633
        // Try removing a fragment.
632
        // Try removing a fragment.
634
        assertFalse("project is unmodified", pm.isModified(p));
633
        assertFalse("project is unmodified", pm.isModified(p));
635
        assertTrue("can remove new frag", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
634
        assertTrue("can remove new frag", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
Lines 637-645 Link Here
637
        assertNull("now frag is gone", aux.getConfigurationFragment("hello", "urn:test:whatever", true));
636
        assertNull("now frag is gone", aux.getConfigurationFragment("hello", "urn:test:whatever", true));
638
        pm.saveProject(p);
637
        pm.saveProject(p);
639
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
638
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
640
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
639
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
641
        assertNotNull("<configuration> still exists", config);
640
        assertNotNull("<configuration> still exists", config);
642
        data = Util.findElement(config, "hello", "urn:test:whatever");
641
        data = XMLUtil.findElement(config, "hello", "urn:test:whatever");
643
        assertNull("now <hello> is gone", data);
642
        assertNull("now <hello> is gone", data);
644
        assertFalse("cannot remove a frag that is not there", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
643
        assertFalse("cannot remove a frag that is not there", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
645
        assertFalse("trying to remove a nonexistent frag does not modify project", pm.isModified(p));
644
        assertFalse("trying to remove a nonexistent frag does not modify project", pm.isModified(p));
Lines 659-665 Link Here
659
        aux.putConfigurationFragment(data, true);
658
        aux.putConfigurationFragment(data, true);
660
        pm.saveProject(p);
659
        pm.saveProject(p);
661
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
660
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
662
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
661
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
663
        String[] names = new String[]{"aaa-namespace", "aaaa-namespace", "bbb-name-sp", "bbb-namespace", "bbb-namespace-1", "ccc-namespace", "data-urn:test:shared", "data-urn:test:shared-aux"};
662
        String[] names = new String[]{"aaa-namespace", "aaaa-namespace", "bbb-name-sp", "bbb-namespace", "bbb-namespace-1", "ccc-namespace", "data-urn:test:shared", "data-urn:test:shared-aux"};
664
        int count = 0;
663
        int count = 0;
665
        NodeList list = config.getChildNodes();
664
        NodeList list = config.getChildNodes();
Lines 684-690 Link Here
684
        assertNotNull("AuxiliaryConfiguration present", aux);
683
        assertNotNull("AuxiliaryConfiguration present", aux);
685
684
686
        Element data = aux.getConfigurationFragment("data", "urn:test:private-aux", false);
685
        Element data = aux.getConfigurationFragment("data", "urn:test:private-aux", false);
687
        Element stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
686
        Element stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
688
        assertNotNull("found <aux-private-stuff/>", stuff);
687
        assertNotNull("found <aux-private-stuff/>", stuff);
689
        // Check write of private data.
688
        // Check write of private data.
690
        stuff.setAttribute("attr", "val");
689
        stuff.setAttribute("attr", "val");
Lines 710-718 Link Here
710
        //check the data are written:
709
        //check the data are written:
711
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
710
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
712
        Element config = doc.getDocumentElement();
711
        Element config = doc.getDocumentElement();
713
        data = Util.findElement(config, "data", "urn:test:private-aux");
712
        data = XMLUtil.findElement(config, "data", "urn:test:private-aux");
714
        assertNotNull("<data> still exists", data);
713
        assertNotNull("<data> still exists", data);
715
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
714
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
716
        assertNotNull("still have <aux-private-stuff/>", stuff);
715
        assertNotNull("still have <aux-private-stuff/>", stuff);
717
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
716
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
718
        
717
        
Lines 788-794 Link Here
788
                System.out.println("starting #" + x);
787
                System.out.println("starting #" + x);
789
                for (int i = 0; i < 1000; i++) {
788
                for (int i = 0; i < 1000; i++) {
790
                    Element data = h.getPrimaryConfigurationData(true);
789
                    Element data = h.getPrimaryConfigurationData(true);
791
                    Util.findSubElements(data);
790
                    XMLUtil.findSubElements(data);
792
                    if (i % 100 == 0) {
791
                    if (i % 100 == 0) {
793
                        System.out.println("in the middle of #" + x);
792
                        System.out.println("in the middle of #" + x);
794
                        try {
793
                        try {
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelperTest.java (-3 / +3 lines)
Lines 52-64 Link Here
52
import org.netbeans.api.project.TestUtil;
52
import org.netbeans.api.project.TestUtil;
53
import org.netbeans.junit.NbTestCase;
53
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.modules.project.ant.AntBuildExtenderAccessor;
54
import org.netbeans.modules.project.ant.AntBuildExtenderAccessor;
55
import org.netbeans.modules.project.ant.Util;
56
import org.netbeans.spi.project.AuxiliaryConfiguration;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
57
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
59
import org.openide.modules.SpecificationVersion;
58
import org.openide.modules.SpecificationVersion;
60
import org.openide.util.Utilities;
59
import org.openide.util.Utilities;
61
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
61
import org.openide.xml.XMLUtil;
62
import org.w3c.dom.Document;
62
import org.w3c.dom.Document;
63
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
64
import org.w3c.dom.NodeList;
64
import org.w3c.dom.NodeList;
Lines 111-117 Link Here
111
        assertNull("No build-impl.xml yet", bi);
111
        assertNull("No build-impl.xml yet", bi);
112
        // Modify shared data in a project.
112
        // Modify shared data in a project.
113
        Element primdata = h.getPrimaryConfigurationData(true);
113
        Element primdata = h.getPrimaryConfigurationData(true);
114
        Element oldDisplayName = Util.findElement(primdata, "display-name", "urn:test:shared");
114
        Element oldDisplayName = XMLUtil.findElement(primdata, "display-name", "urn:test:shared");
115
        assertNotNull("had a <display-name> before", oldDisplayName);
115
        assertNotNull("had a <display-name> before", oldDisplayName);
116
        Element displayName = primdata.getOwnerDocument().createElementNS("urn:test:shared", "display-name");
116
        Element displayName = primdata.getOwnerDocument().createElementNS("urn:test:shared", "display-name");
117
        displayName.appendChild(primdata.getOwnerDocument().createTextNode("New Name"));
117
        displayName.appendChild(primdata.getOwnerDocument().createTextNode("New Name"));
Lines 132-138 Link Here
132
        NodeList l = doc.getElementsByTagName("description");
132
        NodeList l = doc.getElementsByTagName("description");
133
        assertEquals("one <description> in build-impl.xml", 1, l.getLength());
133
        assertEquals("one <description> in build-impl.xml", 1, l.getLength());
134
        el = (Element)l.item(0);
134
        el = (Element)l.item(0);
135
        assertEquals("correct description", "New Name", Util.findText(el));
135
        assertEquals("correct description", "New Name", XMLUtil.findText(el));
136
        // Clear build-impl.xml to test if it is rewritten.
136
        // Clear build-impl.xml to test if it is rewritten.
137
        bi.delete();
137
        bi.delete();
138
        // Now make some irrelevant change - e.g. to private.xml - and check that there is no modification.
138
        // Now make some irrelevant change - e.g. to private.xml - and check that there is no modification.
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ProjectGeneratorTest.java (-2 / +2 lines)
Lines 49-61 Link Here
49
import org.netbeans.api.project.TestUtil;
49
import org.netbeans.api.project.TestUtil;
50
import org.netbeans.junit.NbTestCase;
50
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
51
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
52
import org.netbeans.modules.project.ant.Util;
53
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectInformation;
54
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
56
import org.openide.util.Mutex;
55
import org.openide.util.Mutex;
57
import org.openide.util.MutexException;
56
import org.openide.util.MutexException;
58
import org.openide.util.test.MockLookup;
57
import org.openide.util.test.MockLookup;
58
import org.openide.xml.XMLUtil;
59
import org.w3c.dom.Document;
59
import org.w3c.dom.Document;
60
import org.w3c.dom.Element;
60
import org.w3c.dom.Element;
61
import org.w3c.dom.NodeList;
61
import org.w3c.dom.NodeList;
Lines 142-148 Link Here
142
                    NodeList l = doc.getElementsByTagNameNS(AntProjectHelper.PROJECT_NS, "type");
142
                    NodeList l = doc.getElementsByTagNameNS(AntProjectHelper.PROJECT_NS, "type");
143
                    assertEquals("one <type>", 1, l.getLength());
143
                    assertEquals("one <type>", 1, l.getLength());
144
                    Element el = (Element)l.item(0);
144
                    Element el = (Element)l.item(0);
145
                    assertEquals("correct saved type", "test", Util.findText(el));
145
                    assertEquals("correct saved type", "test", XMLUtil.findText(el));
146
                    l = doc.getElementsByTagNameNS("urn:test:shared", "shared-stuff");
146
                    l = doc.getElementsByTagNameNS("urn:test:shared", "shared-stuff");
147
                    assertEquals("one <shared-stuff>", 1, l.getLength());
147
                    assertEquals("one <shared-stuff>", 1, l.getLength());
148
                    doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
148
                    doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java (-8 / +8 lines)
Lines 63-69 Link Here
63
import org.netbeans.api.queries.CollocationQuery;
63
import org.netbeans.api.queries.CollocationQuery;
64
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.junit.NbTestCase;
65
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
65
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
66
import org.netbeans.modules.project.ant.Util;
67
import org.netbeans.spi.project.AuxiliaryConfiguration;
66
import org.netbeans.spi.project.AuxiliaryConfiguration;
68
import org.netbeans.spi.project.SubprojectProvider;
67
import org.netbeans.spi.project.SubprojectProvider;
69
import org.netbeans.spi.queries.CollocationQueryImplementation;
68
import org.netbeans.spi.queries.CollocationQueryImplementation;
Lines 71-76 Link Here
71
import org.openide.filesystems.FileUtil;
70
import org.openide.filesystems.FileUtil;
72
import org.openide.util.lookup.Lookups;
71
import org.openide.util.lookup.Lookups;
73
import org.openide.util.test.MockLookup;
72
import org.openide.util.test.MockLookup;
73
import org.openide.xml.XMLUtil;
74
import org.w3c.dom.Document;
74
import org.w3c.dom.Document;
75
import org.w3c.dom.Element;
75
import org.w3c.dom.Element;
76
import org.w3c.dom.NodeList;
76
import org.w3c.dom.NodeList;
Lines 342-350 Link Here
342
        assertTrue("Project is still modified", pm.isModified(p));
342
        assertTrue("Project is still modified", pm.isModified(p));
343
        pm.saveProject(p);
343
        pm.saveProject(p);
344
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
344
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
345
        Element config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
345
        Element config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
346
        assertNotNull("have <configuration>", config);
346
        assertNotNull("have <configuration>", config);
347
        Element references = Util.findElement(config, ReferenceHelper.REFS_NAME, ReferenceHelper.REFS_NS);
347
        Element references = XMLUtil.findElement(config, ReferenceHelper.REFS_NAME, ReferenceHelper.REFS_NS);
348
        assertNotNull("have <references>", references);
348
        assertNotNull("have <references>", references);
349
        NodeList nl = references.getElementsByTagNameNS(ReferenceHelper.REFS_NS, "reference");
349
        NodeList nl = references.getElementsByTagNameNS(ReferenceHelper.REFS_NS, "reference");
350
        assertEquals("have three <reference>s", 3, nl.getLength());
350
        assertEquals("have three <reference>s", 3, nl.getLength());
Lines 386-394 Link Here
386
            Element reference = (Element)nl.item(i);
386
            Element reference = (Element)nl.item(i);
387
            for (int j = 0; j < 6; j++) {
387
            for (int j = 0; j < 6; j++) {
388
                String elementName = elementNames[j];
388
                String elementName = elementNames[j];
389
                Element element = Util.findElement(reference, elementName, ReferenceHelper.REFS_NS);
389
                Element element = XMLUtil.findElement(reference, elementName, ReferenceHelper.REFS_NS);
390
                assertNotNull("had element " + elementName + " in ref #" + i, element);
390
                assertNotNull("had element " + elementName + " in ref #" + i, element);
391
                assertEquals("correct text in " + elementName + " in ref #" + i, values[i][j], Util.findText(element));
391
                assertEquals("correct text in " + elementName + " in ref #" + i, values[i][j], XMLUtil.findText(element));
392
            }
392
            }
393
        }
393
        }
394
    }
394
    }
Lines 1080-1088 Link Here
1080
        Element refs = p.getLookup().lookup(AuxiliaryConfiguration.class).getConfigurationFragment(ReferenceHelper.REFS_NAME, namespace, true);
1080
        Element refs = p.getLookup().lookup(AuxiliaryConfiguration.class).getConfigurationFragment(ReferenceHelper.REFS_NAME, namespace, true);
1081
        assertNotNull(refs);
1081
        assertNotNull(refs);
1082
        List<String> actualScriptLocations = new ArrayList<String>();
1082
        List<String> actualScriptLocations = new ArrayList<String>();
1083
        for (Element ref : Util.findSubElements(refs)) {
1083
        for (Element ref : XMLUtil.findSubElements(refs)) {
1084
            Element script = Util.findElement(ref, "script", namespace);
1084
            Element script = XMLUtil.findElement(ref, "script", namespace);
1085
            actualScriptLocations.add(Util.findText(script));
1085
            actualScriptLocations.add(XMLUtil.findText(script));
1086
        }
1086
        }
1087
        assertEquals(Arrays.asList(scriptLocations), actualScriptLocations);
1087
        assertEquals(Arrays.asList(scriptLocations), actualScriptLocations);
1088
    }
1088
    }
(-)a/projectapi/nbproject/project.xml (-1 / +1 lines)
Lines 92-98 Link Here
92
                    <build-prerequisite/>
92
                    <build-prerequisite/>
93
                    <compile-dependency/>
93
                    <compile-dependency/>
94
                    <run-dependency>
94
                    <run-dependency>
95
                        <specification-version>8.0</specification-version>
95
                        <specification-version>8.4</specification-version>
96
                    </run-dependency>
96
                    </run-dependency>
97
                </dependency>
97
                </dependency>
98
                <dependency>
98
                <dependency>
(-)a/projectapi/src/org/netbeans/modules/projectapi/AuxiliaryConfigImpl.java (-22 / +3 lines)
Lines 98-104 Link Here
98
                                InputSource input = new InputSource(is);
98
                                InputSource input = new InputSource(is);
99
                                input.setSystemId(config.getURL().toString());
99
                                input.setSystemId(config.getURL().toString());
100
                                Element root = XMLUtil.parse(input, false, true, /*XXX*/null, null).getDocumentElement();
100
                                Element root = XMLUtil.parse(input, false, true, /*XXX*/null, null).getDocumentElement();
101
                                return findElement(root, elementName, namespace);
101
                                return XMLUtil.findElement(root, elementName, namespace);
102
                            } finally {
102
                            } finally {
103
                                is.close();
103
                                is.close();
104
                            }
104
                            }
Lines 163-169 Link Here
163
                            doc = XMLUtil.createDocument("auxiliary-configuration", "http://www.netbeans.org/ns/auxiliary-configuration/1", null, null);
163
                            doc = XMLUtil.createDocument("auxiliary-configuration", "http://www.netbeans.org/ns/auxiliary-configuration/1", null, null);
164
                        }
164
                        }
165
                        Element root = doc.getDocumentElement();
165
                        Element root = doc.getDocumentElement();
166
                        Element oldFragment = findElement(root, elementName, namespace);
166
                        Element oldFragment = XMLUtil.findElement(root, elementName, namespace);
167
                        if (oldFragment != null) {
167
                        if (oldFragment != null) {
168
                            root.removeChild(oldFragment);
168
                            root.removeChild(oldFragment);
169
                        }
169
                        }
Lines 230-236 Link Here
230
                            is.close();
230
                            is.close();
231
                        }
231
                        }
232
                        Element root = doc.getDocumentElement();
232
                        Element root = doc.getDocumentElement();
233
                        Element toRemove = findElement(root, elementName, namespace);
233
                        Element toRemove = XMLUtil.findElement(root, elementName, namespace);
234
                        if (toRemove != null) {
234
                        if (toRemove != null) {
235
                            root.removeChild(toRemove);
235
                            root.removeChild(toRemove);
236
                            if (root.getElementsByTagName("*").getLength() > 0) {
236
                            if (root.getElementsByTagName("*").getLength() > 0) {
Lines 276-298 Link Here
276
        });
276
        });
277
    }
277
    }
278
278
279
    private static Element findElement(Element parent, String name, String namespace) {
280
        Element result = null;
281
        NodeList l = parent.getChildNodes();
282
        int len = l.getLength();
283
        for (int i = 0; i < len; i++) {
284
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
285
                Element el = (Element) l.item(i);
286
                if (name.equals(el.getLocalName()) && namespace.equals(el.getNamespaceURI())) {
287
                    if (result == null) {
288
                        result = el;
289
                    } else {
290
                        return null;
291
                    }
292
                }
293
            }
294
        }
295
        return result;
296
    }
297
298
}
279
}
(-)a/projectimport.eclipse.core/nbproject/project.xml (-1 / +1 lines)
Lines 192-198 Link Here
192
                    <build-prerequisite/>
192
                    <build-prerequisite/>
193
                    <compile-dependency/>
193
                    <compile-dependency/>
194
                    <run-dependency>
194
                    <run-dependency>
195
                        <specification-version>8.0</specification-version>
195
                        <specification-version>8.4</specification-version>
196
                    </run-dependency>
196
                    </run-dependency>
197
                </dependency>
197
                </dependency>
198
                <dependency>
198
                <dependency>
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/DotClassPathParser.java (-4 / +4 lines)
Lines 68-74 Link Here
68
    public static DotClassPath parse(File dotClasspath, List<Link> links) throws IOException {
68
    public static DotClassPath parse(File dotClasspath, List<Link> links) throws IOException {
69
        Document dotClasspathXml;
69
        Document dotClasspathXml;
70
        try {
70
        try {
71
            dotClasspathXml = XMLUtil.parse(new InputSource(dotClasspath.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
71
            dotClasspathXml = XMLUtil.parse(new InputSource(dotClasspath.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
72
        } catch (SAXException e) {
72
        } catch (SAXException e) {
73
            IOException ioe = (IOException) new IOException(dotClasspath + ": " + e.toString()).initCause(e); //NOI18N
73
            IOException ioe = (IOException) new IOException(dotClasspath + ": " + e.toString()).initCause(e); //NOI18N
74
            throw ioe;
74
            throw ioe;
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 (-13 / +13 lines)
Lines 65-71 Link Here
65
    public static String parse(File dotProject, Set<String> natures, List<Link> links, Set<Variable> variables) throws IOException {
65
    public static String parse(File dotProject, Set<String> natures, List<Link> links, Set<Variable> variables) throws IOException {
66
        Document dotProjectXml;
66
        Document dotProjectXml;
67
        try {
67
        try {
68
            dotProjectXml = XMLUtil.parse(new InputSource(dotProject.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
68
            dotProjectXml = XMLUtil.parse(new InputSource(dotProject.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
69
        } catch (SAXException e) {
69
        } catch (SAXException e) {
70
            IOException ioe = (IOException) new IOException(dotProject + ": " + e.toString()).initCause(e); // NOI18N
70
            IOException ioe = (IOException) new IOException(dotProject + ": " + e.toString()).initCause(e); // NOI18N
71
            throw ioe;
71
            throw ioe;
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 121-127 Link Here
121
        }
121
        }
122
        Document doc;
122
        Document doc;
123
        try {
123
        try {
124
            doc = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
124
            doc = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
125
        } catch (SAXException e) {
125
        } catch (SAXException e) {
126
            IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); // NOI18N
126
            IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); // NOI18N
127
            throw ioe;
127
            throw ioe;
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 (-4 / +4 lines)
Lines 63-69 Link Here
63
        UserLibraryParser parser = new UserLibraryParser();
63
        UserLibraryParser parser = new UserLibraryParser();
64
        Document xml;
64
        Document xml;
65
        try {
65
        try {
66
            xml = XMLUtil.parse(new InputSource(new StringReader(xmlDoc)), false, true, Util.defaultErrorHandler(), null);
66
            xml = XMLUtil.parse(new InputSource(new StringReader(xmlDoc)), false, true, XMLUtil.defaultErrorHandler(), null);
67
        } catch (SAXException e) {
67
        } catch (SAXException e) {
68
            IOException ioe = (IOException) new IOException("Library '"+libName+"' cannot be parsed: " + e.toString()).initCause(e); // NOI18N
68
            IOException ioe = (IOException) new IOException("Library '"+libName+"' cannot be parsed: " + e.toString()).initCause(e); // NOI18N
69
            throw ioe;
69
            throw ioe;
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 (-121 lines)
Lines 41-61 Link Here
41
41
42
package org.netbeans.modules.projectimport.eclipse.core;
42
package org.netbeans.modules.projectimport.eclipse.core;
43
43
44
import java.util.ArrayList;
45
import java.util.List;
46
import java.util.logging.Level;
44
import java.util.logging.Level;
47
import java.util.logging.LogRecord;
45
import java.util.logging.LogRecord;
48
import java.util.logging.Logger;
46
import java.util.logging.Logger;
49
import org.openide.util.Exceptions;
50
import org.openide.util.NbBundle;
47
import org.openide.util.NbBundle;
51
import org.openide.util.Parameters;
48
import org.openide.util.Parameters;
52
import org.w3c.dom.Element;
53
import org.w3c.dom.Node;
54
import org.w3c.dom.NodeList;
55
import org.w3c.dom.Text;
56
import org.xml.sax.ErrorHandler;
57
import org.xml.sax.SAXException;
58
import org.xml.sax.SAXParseException;
59
49
60
/**
50
/**
61
 * Utilities relating to Ant projects.
51
 * Utilities relating to Ant projects.
Lines 67-183 Link Here
67
57
68
    private Util() {}
58
    private Util() {}
69
59
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.
150
     * @return a standard error handler
151
     */
152
    public static ErrorHandler defaultErrorHandler() {
153
        return new ErrHandler();
154
    }
155
    
156
    private static final class ErrHandler implements ErrorHandler {
157
        
158
        public ErrHandler() {}
159
        
160
        private void annotate(SAXParseException exception) throws SAXException {
161
            Exceptions.attachMessage(exception, "Occurred at: " + exception.getSystemId() + ":" + exception.getLineNumber()); // NOI18N
162
        }
163
        
164
        public void fatalError(SAXParseException exception) throws SAXException {
165
            annotate(exception);
166
            throw exception;
167
        }
168
        
169
        public void error(SAXParseException exception) throws SAXException {
170
            annotate(exception);
171
            throw exception;
172
        }
173
        
174
        public void warning(SAXParseException exception) throws SAXException {
175
            annotate(exception);
176
            Logger.getLogger(Util.class.getName()).log(Level.INFO, null, exception);
177
        }
178
        
179
    }
180
181
    public static void logUsage(Class srcClass, String message, Object ...params) {
60
    public static void logUsage(Class srcClass, String message, Object ...params) {
182
        Parameters.notNull("message", message); // NOI18N
61
        Parameters.notNull("message", message); // NOI18N
183
62
(-)a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/WorkspaceParser.java (-3 / +3 lines)
Lines 145-151 Link Here
145
        }
145
        }
146
        Document xml;
146
        Document xml;
147
        try {
147
        try {
148
            xml = XMLUtil.parse(new InputSource(workspace.getUserJSFLibraries().toURI().toString()), false, true, Util.defaultErrorHandler(), null);
148
            xml = XMLUtil.parse(new InputSource(workspace.getUserJSFLibraries().toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
149
        } catch (SAXException e) {
149
        } catch (SAXException e) {
150
            IOException ioe = (IOException) new IOException(workspace.getUserJSFLibraries() + ": " + e.toString()).initCause(e); // NOI18N
150
            IOException ioe = (IOException) new IOException(workspace.getUserJSFLibraries() + ": " + e.toString()).initCause(e); // NOI18N
151
            throw ioe;
151
            throw ioe;
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();
(-)a/projectimport.eclipse.web/nbproject/project.xml (-1 / +1 lines)
Lines 96-102 Link Here
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <specification-version>8.0</specification-version>
99
                        <specification-version>8.4</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
(-)a/projectimport.eclipse.web/src/org/netbeans/modules/projectimport/eclipse/web/Util.java (-176 lines)
Lines 1-176 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.projectimport.eclipse.web;
43
44
import java.util.ArrayList;
45
import java.util.List;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import org.openide.util.Exceptions;
49
import org.w3c.dom.Element;
50
import org.w3c.dom.Node;
51
import org.w3c.dom.NodeList;
52
import org.w3c.dom.Text;
53
import org.xml.sax.ErrorHandler;
54
import org.xml.sax.SAXException;
55
import org.xml.sax.SAXParseException;
56
57
/**
58
 * Utilities relating to Ant projects.
59
 * @author Jesse Glick
60
 */
61
public class Util {
62
63
    private Util() {}
64
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.
145
     * @return a standard error handler
146
     */
147
    public static ErrorHandler defaultErrorHandler() {
148
        return new ErrHandler();
149
    }
150
    
151
    private static final class ErrHandler implements ErrorHandler {
152
        
153
        public ErrHandler() {}
154
        
155
        private void annotate(SAXParseException exception) throws SAXException {
156
            Exceptions.attachMessage(exception, "Occurred at: " + exception.getSystemId() + ":" + exception.getLineNumber()); // NOI18N
157
        }
158
        
159
        public void fatalError(SAXParseException exception) throws SAXException {
160
            annotate(exception);
161
            throw exception;
162
        }
163
        
164
        public void error(SAXParseException exception) throws SAXException {
165
            annotate(exception);
166
            throw exception;
167
        }
168
        
169
        public void warning(SAXParseException exception) throws SAXException {
170
            annotate(exception);
171
            Logger.getLogger(Util.class.getName()).log(Level.INFO, null, exception);
172
        }
173
        
174
    }
175
    
176
}
(-)a/projectimport.eclipse.web/src/org/netbeans/modules/projectimport/eclipse/web/WebProjectFactory.java (-6 / +6 lines)
Lines 235-241 Link Here
235
        if (f.exists()) {
235
        if (f.exists()) {
236
            Document webContent;
236
            Document webContent;
237
            try {
237
            try {
238
                webContent = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
238
                webContent = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
239
            } catch (SAXException e) {
239
            } catch (SAXException e) {
240
                IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); //NOI18N
240
                IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); //NOI18N
241
                throw ioe;
241
                throw ioe;
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 266-272 Link Here
266
        if (f.exists()) {
266
        if (f.exists()) {
267
            Document webContent;
267
            Document webContent;
268
            try {
268
            try {
269
                webContent = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
269
                webContent = XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
270
            } catch (SAXException e) {
270
            } catch (SAXException e) {
271
                IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); //NOI18N
271
                IOException ioe = (IOException) new IOException(f + ": " + e.toString()).initCause(e); //NOI18N
272
                throw ioe;
272
                throw ioe;
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
(-)a/projectimport.jbuilder/nbproject/project.xml (-1 / +1 lines)
Lines 198-204 Link Here
198
                    <build-prerequisite/>
198
                    <build-prerequisite/>
199
                    <compile-dependency/>
199
                    <compile-dependency/>
200
                    <run-dependency>
200
                    <run-dependency>
201
                        <specification-version>8.0</specification-version>
201
                        <specification-version>8.4</specification-version>
202
                    </run-dependency>
202
                    </run-dependency>
203
                </dependency>
203
                </dependency>
204
                <dependency>
204
                <dependency>
(-)a/projectimport.jbuilder/src/org/netbeans/modules/projectimport/jbuilder/parsing/UserLibrarySupport.java (-5 / +6 lines)
Lines 195-201 Link Here
195
                return null;
195
                return null;
196
            }
196
            }
197
197
198
            List/*<Element>*/ reqElems = Util.findSubElements(docEl);
198
            List<Element> reqElems = XMLUtil.findSubElements(docEl);
199
            for (int i = 0; i < reqElems.size(); i++) {
199
            for (int i = 0; i < reqElems.size(); i++) {
200
                Element elem = (Element)reqElems.get(i);
200
                Element elem = (Element)reqElems.get(i);
201
                String classElem = getClassElement(elem);
201
                String classElem = getClassElement(elem);
Lines 235-241 Link Here
235
    }
235
    }
236
236
237
    private void resolvePath(final File[] folders, final AbstractProject.UserLibrary retval, final Element classElem) throws IllegalArgumentException {
237
    private void resolvePath(final File[] folders, final AbstractProject.UserLibrary retval, final Element classElem) throws IllegalArgumentException {
238
        List/*<Element>*/ pathElems = (classElem != null) ? Util.findSubElements(classElem) : Collections.EMPTY_LIST;
238
        List<Element> pathElems = (classElem != null) ? XMLUtil.findSubElements(classElem) : Collections.EMPTY_LIST;
239
        for (int i = 0; i < pathElems.size(); i++) {
239
        for (int i = 0; i < pathElems.size(); i++) {
240
            String path = getPath((Element)pathElems.get(i));
240
            String path = getPath((Element)pathElems.get(i));
241
            if (path != null) {
241
            if (path != null) {
Lines 277-284 Link Here
277
        String fullName = null;
277
        String fullName = null;
278
        
278
        
279
        if (docEl != null) {
279
        if (docEl != null) {
280
            Element fullNameElement = Util.findElement(docEl, FULLNAME_ELEMENT,null);
280
            try {XMLUtil.write(docEl.getOwnerDocument(), System.out, "UTC-8"); } catch (Exception e) {}
281
            fullName = (fullNameElement != null) ? Util.findText(fullNameElement) : null;
281
            Element fullNameElement = XMLUtil.findElement(docEl, FULLNAME_ELEMENT,null);
282
            fullName = (fullNameElement != null) ? XMLUtil.findText(fullNameElement) : null;
282
        }
283
        }
283
        
284
        
284
        return fullName;
285
        return fullName;
Lines 302-308 Link Here
302
        String path = null;
303
        String path = null;
303
        
304
        
304
        if (pathElem != null && pathElem.getNodeName().equals(name)) {
305
        if (pathElem != null && pathElem.getNodeName().equals(name)) {
305
            path = Util.findText(pathElem);
306
            path = XMLUtil.findText(pathElem);
306
            
307
            
307
        }
308
        }
308
        
309
        
(-)a/projectui/nbproject/project.xml (-1 / +1 lines)
Lines 185-191 Link Here
185
                    <build-prerequisite/>
185
                    <build-prerequisite/>
186
                    <compile-dependency/>
186
                    <compile-dependency/>
187
                    <run-dependency>
187
                    <run-dependency>
188
                        <specification-version>8.0</specification-version>
188
                        <specification-version>8.4</specification-version>
189
                    </run-dependency>
189
                    </run-dependency>
190
                </dependency>
190
                </dependency>
191
                <dependency>
191
                <dependency>
(-)a/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/TestSupport.java (-23 / +3 lines)
Lines 190-196 Link Here
190
                assert false : "Shared not implemented";
190
                assert false : "Shared not implemented";
191
            }
191
            }
192
            Element root = xml.getDocumentElement ();
192
            Element root = xml.getDocumentElement ();
193
            Element data = findElement (root, elementName, namespace);
193
            Element data = XMLUtil.findElement (root, elementName, namespace);
194
            if (data != null) {
194
            if (data != null) {
195
                return  (Element) data.cloneNode (true);
195
                return  (Element) data.cloneNode (true);
196
            } else {
196
            } else {
Lines 205-211 Link Here
205
            }
205
            }
206
            
206
            
207
            Element root = xml.getDocumentElement ();
207
            Element root = xml.getDocumentElement ();
208
            Element existing = findElement (root, fragment.getLocalName (), fragment.getNamespaceURI ());
208
            Element existing = XMLUtil.findElement (root, fragment.getLocalName (), fragment.getNamespaceURI ());
209
            // XXX first compare to existing and return if the same
209
            // XXX first compare to existing and return if the same
210
            if (existing != null) {
210
            if (existing != null) {
211
                root.removeChild (existing);
211
                root.removeChild (existing);
Lines 236-242 Link Here
236
            }
236
            }
237
237
238
            Element root = xml.getDocumentElement ();
238
            Element root = xml.getDocumentElement ();
239
            Element data = findElement (root, elementName, namespace);
239
            Element data = XMLUtil.findElement (root, elementName, namespace);
240
            if (data != null) {
240
            if (data != null) {
241
                root.removeChild (data);
241
                root.removeChild (data);
242
                return true;
242
                return true;
Lines 245-268 Link Here
245
            }
245
            }
246
        }
246
        }
247
    }
247
    }
248
    
249
    // copied from org.netbeans.modules.project.ant.Util
250
    private static Element findElement(Element parent, String name, String namespace) {
251
        Element result = null;
252
        NodeList l = parent.getChildNodes();
253
        int len = l.getLength();
254
        for (int i = 0; i < len; i++) {
255
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
256
                Element el = (Element)l.item(i);
257
                if (name.equals(el.getLocalName()) && namespace.equals(el.getNamespaceURI())) {
258
                    if (result == null) {
259
                        result = el;
260
                    } else {
261
                        return null;
262
                    }
263
                }
264
            }
265
        }
266
        return result;
267
    }
268
}
248
}
(-)a/ruby.project/nbproject/project.xml (-1 / +1 lines)
Lines 265-271 Link Here
265
                    <build-prerequisite/>
265
                    <build-prerequisite/>
266
                    <compile-dependency/>
266
                    <compile-dependency/>
267
                    <run-dependency>
267
                    <run-dependency>
268
                        <specification-version>8.0</specification-version>
268
                        <specification-version>8.4</specification-version>
269
                    </run-dependency>
269
                    </run-dependency>
270
                </dependency>
270
                </dependency>
271
                <dependency>
271
                <dependency>
(-)a/ruby.project/src/org/netbeans/modules/ruby/rubyproject/UpdateHelper.java (-39 lines)
Lines 43-55 Link Here
43
43
44
import java.io.IOException;
44
import java.io.IOException;
45
import javax.swing.JButton;
45
import javax.swing.JButton;
46
import org.w3c.dom.Comment;
47
import org.w3c.dom.Document;
48
import org.w3c.dom.Element;
46
import org.w3c.dom.Element;
49
import org.w3c.dom.NamedNodeMap;
50
import org.w3c.dom.Node;
51
import org.w3c.dom.NodeList;
52
import org.w3c.dom.Text;
53
import org.openide.DialogDisplayer;
47
import org.openide.DialogDisplayer;
54
import org.openide.ErrorManager;
48
import org.openide.ErrorManager;
55
import org.openide.NotifyDescriptor;
49
import org.openide.NotifyDescriptor;
Lines 307-345 Link Here
307
        EditableProperties cachedProperties = this.helper.getProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH);
301
        EditableProperties cachedProperties = this.helper.getProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH);
308
        return cachedProperties;
302
        return cachedProperties;
309
    }
303
    }
310
311
    private static void copyDocument(Document doc, Element from, Element to, String projectConfigurationNamespace) {
312
        NodeList nl = from.getChildNodes();
313
        int length = nl.getLength();
314
        for (int i=0; i< length; i++) {
315
            Node node = nl.item (i);
316
            Node newNode = null;
317
            switch (node.getNodeType()) {
318
                case Node.ELEMENT_NODE:
319
                    Element oldElement = (Element) node;
320
                    newNode = doc.createElementNS(projectConfigurationNamespace, oldElement.getTagName());
321
                    NamedNodeMap m = oldElement.getAttributes();
322
                    Element newElement = (Element) newNode;
323
                    for (int index = 0; index < m.getLength(); index++) {
324
                        Node attr = m.item(index);
325
                          newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
326
                    }
327
                    copyDocument(doc, oldElement, newElement, projectConfigurationNamespace);
328
                    break;
329
                case Node.TEXT_NODE:
330
                    Text oldText = (Text) node;
331
                    newNode = doc.createTextNode(oldText.getData());
332
                    break;
333
                case Node.COMMENT_NODE:
334
                    Comment oldComment = (Comment) node;
335
                    newNode = doc.createComment(oldComment.getData());
336
                    break;
337
            }
338
            if (newNode != null) {
339
                to.appendChild (newNode);
340
            }
341
        }
342
    }
343
    
304
    
344
//    private static Element updateMinAntVersion (final Element root, final Document doc) {
305
//    private static Element updateMinAntVersion (final Element root, final Document doc) {
345
//        NodeList list = root.getElementsByTagNameNS (RubyProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
306
//        NodeList list = root.getElementsByTagNameNS (RubyProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
(-)a/ruby.rakeproject/nbproject/project.xml (-1 / +1 lines)
Lines 98-104 Link Here
98
                    <build-prerequisite/>
98
                    <build-prerequisite/>
99
                    <compile-dependency/>
99
                    <compile-dependency/>
100
                    <run-dependency>
100
                    <run-dependency>
101
                        <specification-version>8.0</specification-version>
101
                        <specification-version>8.4</specification-version>
102
                    </run-dependency>
102
                    </run-dependency>
103
                </dependency>
103
                </dependency>
104
                <dependency>
104
                <dependency>
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/modules/project/rake/RakeBasedProjectFactorySingleton.java (-3 / +3 lines)
Lines 166-172 Link Here
166
        }
166
        }
167
        Document projectXml;
167
        Document projectXml;
168
        try {
168
        try {
169
            projectXml = XMLUtil.parse(new InputSource(projectDiskFile.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
169
            projectXml = XMLUtil.parse(new InputSource(projectDiskFile.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
170
        } catch (SAXException e) {
170
        } catch (SAXException e) {
171
            IOException ioe = (IOException) new IOException(projectDiskFile + ": " + e.toString()).initCause(e);
171
            IOException ioe = (IOException) new IOException(projectDiskFile + ": " + e.toString()).initCause(e);
172
            Exceptions.attachLocalizedMessage(ioe, NbBundle.getMessage(RakeBasedProjectFactorySingleton.class,
172
            Exceptions.attachLocalizedMessage(ioe, NbBundle.getMessage(RakeBasedProjectFactorySingleton.class,
Lines 178-188 Link Here
178
        if (!"project".equals(projectEl.getLocalName()) || !PROJECT_NS.equals(projectEl.getNamespaceURI())) { // NOI18N
178
        if (!"project".equals(projectEl.getLocalName()) || !PROJECT_NS.equals(projectEl.getNamespaceURI())) { // NOI18N
179
            return null;
179
            return null;
180
        }
180
        }
181
        Element typeEl = Util.findElement(projectEl, "type", PROJECT_NS); // NOI18N
181
        Element typeEl = XMLUtil.findElement(projectEl, "type", PROJECT_NS); // NOI18N
182
        if (typeEl == null) {
182
        if (typeEl == null) {
183
            return null;
183
            return null;
184
        }
184
        }
185
        String type = Util.findText(typeEl);
185
        String type = XMLUtil.findText(typeEl);
186
        if (type == null) {
186
        if (type == null) {
187
            return null;
187
            return null;
188
        }
188
        }
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/modules/project/rake/Util.java (-175 lines)
Lines 1-175 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.ruby.modules.project.rake;
43
44
import java.util.ArrayList;
45
import java.util.List;
46
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;
52
import org.xml.sax.SAXException;
53
import org.xml.sax.SAXParseException;
54
55
/**
56
 * Utilities relating to Ant projects.
57
 * @author Jesse Glick
58
 */
59
public class Util {
60
61
    private Util() {}
62
63
    /**
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.
142
     * @return a standard error handler
143
     */
144
    public static ErrorHandler defaultErrorHandler() {
145
        return new ErrHandler();
146
    }
147
    
148
    private static final class ErrHandler implements ErrorHandler {
149
        
150
        public ErrHandler() {}
151
        
152
        private void annotate(SAXParseException exception) throws SAXException {
153
            ErrorManager.getDefault().annotate(exception, ErrorManager.UNKNOWN,
154
                "Occurred at: " + exception.getSystemId() + ":" + exception.getLineNumber(), // NOI18N
155
                null, null, null);
156
        }
157
        
158
        public void fatalError(SAXParseException exception) throws SAXException {
159
            annotate(exception);
160
            throw exception;
161
        }
162
        
163
        public void error(SAXParseException exception) throws SAXException {
164
            annotate(exception);
165
            throw exception;
166
        }
167
        
168
        public void warning(SAXParseException exception) throws SAXException {
169
            annotate(exception);
170
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception);
171
        }
172
        
173
    }
174
    
175
}
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/spi/project/support/rake/ProjectGenerator.java (-8 lines)
Lines 41-60 Link Here
41
41
42
package org.netbeans.modules.ruby.spi.project.support.rake;
42
package org.netbeans.modules.ruby.spi.project.support.rake;
43
43
44
import java.io.File;
45
import java.io.IOException;
44
import java.io.IOException;
46
import java.io.OutputStream;
45
import java.io.OutputStream;
47
import java.net.URL;
48
import java.util.Iterator;
46
import java.util.Iterator;
49
import javax.xml.transform.Transformer;
50
import javax.xml.transform.TransformerException;
51
import javax.xml.transform.TransformerFactory;
52
import javax.xml.transform.stream.StreamResult;
53
import javax.xml.transform.stream.StreamSource;
54
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.api.project.ProjectManager;
56
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
49
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
57
import org.netbeans.modules.ruby.modules.project.rake.Util;
58
import org.openide.filesystems.FileLock;
50
import org.openide.filesystems.FileLock;
59
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
52
import org.openide.filesystems.FileUtil;
(-)a/ruby.rakeproject/src/org/netbeans/modules/ruby/spi/project/support/rake/RakeProjectHelper.java (-6 / +5 lines)
Lines 58-64 Link Here
58
import org.netbeans.modules.ruby.api.project.rake.RakeArtifact;
58
import org.netbeans.modules.ruby.api.project.rake.RakeArtifact;
59
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
59
import org.netbeans.modules.ruby.modules.project.rake.RakeBasedProjectFactorySingleton;
60
import org.netbeans.modules.ruby.modules.project.rake.UserQuestionHandler;
60
import org.netbeans.modules.ruby.modules.project.rake.UserQuestionHandler;
61
import org.netbeans.modules.ruby.modules.project.rake.Util;
62
import org.netbeans.spi.project.AuxiliaryConfiguration;
61
import org.netbeans.spi.project.AuxiliaryConfiguration;
63
import org.netbeans.spi.project.AuxiliaryProperties;
62
import org.netbeans.spi.project.AuxiliaryProperties;
64
import org.netbeans.spi.project.CacheDirectoryProvider;
63
import org.netbeans.spi.project.CacheDirectoryProvider;
Lines 277-283 Link Here
277
        File f = FileUtil.toFile(xml);
276
        File f = FileUtil.toFile(xml);
278
        assert f != null;
277
        assert f != null;
279
        try {
278
        try {
280
            return XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, Util.defaultErrorHandler(), null);
279
            return XMLUtil.parse(new InputSource(f.toURI().toString()), false, true, XMLUtil.defaultErrorHandler(), null);
281
        } catch (IOException e) {
280
        } catch (IOException e) {
282
            if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
281
            if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
283
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
282
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
Lines 389-395 Link Here
389
        Document doc = getConfigurationXml(shared);
388
        Document doc = getConfigurationXml(shared);
390
        if (shared) {
389
        if (shared) {
391
            Element project = doc.getDocumentElement();
390
            Element project = doc.getDocumentElement();
392
            Element config = Util.findElement(project, "configuration", PROJECT_NS); // NOI18N
391
            Element config = XMLUtil.findElement(project, "configuration", PROJECT_NS); // NOI18N
393
            assert config != null;
392
            assert config != null;
394
            return config;
393
            return config;
395
        } else {
394
        } else {
Lines 828-834 Link Here
828
            public Element run() {
827
            public Element run() {
829
                synchronized (modifiedMetadataPaths) {
828
                synchronized (modifiedMetadataPaths) {
830
                    Element root = getConfigurationDataRoot(shared);
829
                    Element root = getConfigurationDataRoot(shared);
831
                    Element data = Util.findElement(root, elementName, namespace);
830
                    Element data = XMLUtil.findElement(root, elementName, namespace);
832
                    if (data != null) {
831
                    if (data != null) {
833
                        return cloneSafely(data);
832
                        return cloneSafely(data);
834
                    } else {
833
                    } else {
Lines 866-872 Link Here
866
            public Void run() {
865
            public Void run() {
867
                synchronized (modifiedMetadataPaths) {
866
                synchronized (modifiedMetadataPaths) {
868
                    Element root = getConfigurationDataRoot(shared);
867
                    Element root = getConfigurationDataRoot(shared);
869
                    Element existing = Util.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
868
                    Element existing = XMLUtil.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
870
                    // XXX first compare to existing and return if the same
869
                    // XXX first compare to existing and return if the same
871
                    if (existing != null) {
870
                    if (existing != null) {
872
                        root.removeChild(existing);
871
                        root.removeChild(existing);
Lines 908-914 Link Here
908
            public Boolean run() {
907
            public Boolean run() {
909
                synchronized (modifiedMetadataPaths) {
908
                synchronized (modifiedMetadataPaths) {
910
                    Element root = getConfigurationDataRoot(shared);
909
                    Element root = getConfigurationDataRoot(shared);
911
                    Element data = Util.findElement(root, elementName, namespace);
910
                    Element data = XMLUtil.findElement(root, elementName, namespace);
912
                    if (data != null) {
911
                    if (data != null) {
913
                        root.removeChild(data);
912
                        root.removeChild(data);
914
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
913
                        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
(-)a/web.freeform/nbproject/project.xml (-6 / +15 lines)
Lines 223-229 Link Here
223
                    <build-prerequisite/>
223
                    <build-prerequisite/>
224
                    <compile-dependency/>
224
                    <compile-dependency/>
225
                    <run-dependency>
225
                    <run-dependency>
226
                        <specification-version>8.0</specification-version>
226
                        <specification-version>8.4</specification-version>
227
                    </run-dependency>
227
                    </run-dependency>
228
                </dependency>
228
                </dependency>
229
                <dependency>
229
                <dependency>
Lines 239-250 Link Here
239
                <test-type>
239
                <test-type>
240
                    <name>unit</name>
240
                    <name>unit</name>
241
                    <test-dependency>
241
                    <test-dependency>
242
                        <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
242
                        <code-name-base>org.netbeans.libs.freemarker</code-name-base>
243
                        <recursive/>
244
                        <compile-dependency/>
245
                    </test-dependency>
243
                    </test-dependency>
246
                    <test-dependency>
244
                    <test-dependency>
247
                        <code-name-base>org.netbeans.modules.javahelp</code-name-base>
245
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
246
                        <compile-dependency/>
248
                    </test-dependency>
247
                    </test-dependency>
249
                    <test-dependency>
248
                    <test-dependency>
250
                        <code-name-base>org.netbeans.modules.editor.mimelookup.impl</code-name-base>
249
                        <code-name-base>org.netbeans.modules.editor.mimelookup.impl</code-name-base>
Lines 253-263 Link Here
253
                        <code-name-base>org.netbeans.modules.editor.settings.storage</code-name-base>
252
                        <code-name-base>org.netbeans.modules.editor.settings.storage</code-name-base>
254
                    </test-dependency>
253
                    </test-dependency>
255
                    <test-dependency>
254
                    <test-dependency>
255
                        <code-name-base>org.netbeans.modules.javahelp</code-name-base>
256
                    </test-dependency>
257
                    <test-dependency>
258
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
259
                        <recursive/>
260
                        <compile-dependency/>
261
                    </test-dependency>
262
                    <test-dependency>
256
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
263
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
257
                        <recursive/>
264
                        <recursive/>
258
                    </test-dependency>
265
                    </test-dependency>
259
                    <test-dependency>
266
                    <test-dependency>
260
                        <code-name-base>org.netbeans.libs.freemarker</code-name-base>
267
                        <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
268
                        <recursive/>
269
                        <compile-dependency/>
261
                    </test-dependency>
270
                    </test-dependency>
262
                </test-type>
271
                </test-type>
263
            </test-dependencies>
272
            </test-dependencies>
(-)a/web.freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java (-3 / +4 lines)
Lines 71-76 Link Here
71
import org.openide.util.Lookup;
71
import org.openide.util.Lookup;
72
import org.openide.util.lookup.Lookups;
72
import org.openide.util.lookup.Lookups;
73
import org.openide.util.lookup.ProxyLookup;
73
import org.openide.util.lookup.ProxyLookup;
74
import org.openide.xml.XMLUtil;
74
import org.w3c.dom.Comment;
75
import org.w3c.dom.Comment;
75
import org.w3c.dom.Document;
76
import org.w3c.dom.Document;
76
import org.w3c.dom.Element;
77
import org.w3c.dom.Element;
Lines 288-294 Link Here
288
            if (web == null) {
289
            if (web == null) {
289
                return null;
290
                return null;
290
            }
291
            }
291
            List<Element> webModules = Util.findSubElements(web);
292
            List<Element> webModules = XMLUtil.findSubElements(web);
292
            List<FileObject> roots = new ArrayList<FileObject>();
293
            List<FileObject> roots = new ArrayList<FileObject>();
293
            for (Element webModulesEl : webModules) {
294
            for (Element webModulesEl : webModules) {
294
                assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N
295
                assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N
Lines 298-305 Link Here
298
        }
299
        }
299
        
300
        
300
        private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) {
301
        private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) {
301
            Element el = Util.findElement(parent, fileElName, WebProjectNature.NS_WEB_2);
302
            Element el = XMLUtil.findElement(parent, fileElName, WebProjectNature.NS_WEB_2);
302
            return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), Util.findText(el));
303
            return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), XMLUtil.findText(el));
303
        }
304
        }
304
        
305
        
305
    }
306
    }
(-)a/web.freeform/src/org/netbeans/modules/web/freeform/WebFreeFormActionProvider.java (-16 / +16 lines)
Lines 266-286 Link Here
266
        // See corresponding schema.
266
        // See corresponding schema.
267
        
267
        
268
        Element data = Util.getPrimaryConfigurationData(helper);
268
        Element data = Util.getPrimaryConfigurationData(helper);
269
        Element properties = Util.findElement(data, "properties", Util.NAMESPACE); // NOI18N
269
        Element properties = XMLUtil.findElement(data, "properties", Util.NAMESPACE); // NOI18N
270
        if (properties != null) {
270
        if (properties != null) {
271
            Iterator/*<Element>*/ propertiesIt = Util.findSubElements(properties).iterator();
271
            Iterator<Element> propertiesIt = XMLUtil.findSubElements(properties).iterator();
272
            while (propertiesIt.hasNext()) {
272
            while (propertiesIt.hasNext()) {
273
                Element el = (Element) propertiesIt.next();
273
                Element el = (Element) propertiesIt.next();
274
                Element nue = script.getOwnerDocument().createElement("property"); // NOI18N
274
                Element nue = script.getOwnerDocument().createElement("property"); // NOI18N
275
                if (el.getLocalName().equals("property")) { // NOI18N
275
                if (el.getLocalName().equals("property")) { // NOI18N
276
                    String name = el.getAttribute("name"); // NOI18N
276
                    String name = el.getAttribute("name"); // NOI18N
277
                    assert name != null;
277
                    assert name != null;
278
                    String text = Util.findText(el);
278
                    String text = XMLUtil.findText(el);
279
                    assert text != null;
279
                    assert text != null;
280
                    nue.setAttribute("name", name); // NOI18N
280
                    nue.setAttribute("name", name); // NOI18N
281
                    nue.setAttribute("value", text); // NOI18N
281
                    nue.setAttribute("value", text); // NOI18N
282
                } else if (el.getLocalName().equals("property-file")) { // NOI18N
282
                } else if (el.getLocalName().equals("property-file")) { // NOI18N
283
                    String text = Util.findText(el);
283
                    String text = XMLUtil.findText(el);
284
                    assert text != null;
284
                    assert text != null;
285
                    nue.setAttribute("file", text); // NOI18N
285
                    nue.setAttribute("file", text); // NOI18N
286
                } else {
286
                } else {
Lines 460-466 Link Here
460
        // XXX cannot use FreeformProjectGenerator since that is currently not a public support SPI from ant/freeform
460
        // XXX cannot use FreeformProjectGenerator since that is currently not a public support SPI from ant/freeform
461
        // XXX should this try to find an existing binding? probably not, since it is assumed that if there was one, we would never get here to begin with
461
        // XXX should this try to find an existing binding? probably not, since it is assumed that if there was one, we would never get here to begin with
462
        Element data = Util.getPrimaryConfigurationData(helper);
462
        Element data = Util.getPrimaryConfigurationData(helper);
463
        Element ideActions = Util.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
463
        Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N
464
        if (ideActions == null) {
464
        if (ideActions == null) {
465
            // Probably won't happen, since generator produces it always.
465
            // Probably won't happen, since generator produces it always.
466
            // Not trivial to just add it now, since order is significant in the schema. (FPG deals with these things.)
466
            // Not trivial to just add it now, since order is significant in the schema. (FPG deals with these things.)
Lines 506-514 Link Here
506
        } else {
506
        } else {
507
            // Add a context menu item, since it applies to the project as a whole.
507
            // Add a context menu item, since it applies to the project as a whole.
508
            // Assume there is already a <context-menu> defined, which is quite likely.
508
            // Assume there is already a <context-menu> defined, which is quite likely.
509
            Element view = Util.findElement(data, "view", Util.NAMESPACE); // NOI18N
509
            Element view = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
510
            if (view != null) {
510
            if (view != null) {
511
                Element contextMenu = Util.findElement(view, "context-menu", Util.NAMESPACE); // NOI18N
511
                Element contextMenu = XMLUtil.findElement(view, "context-menu", Util.NAMESPACE); // NOI18N
512
                if (contextMenu != null) {
512
                if (contextMenu != null) {
513
                    Element ideAction = doc.createElementNS(Util.NAMESPACE, "ide-action"); // NOI18N
513
                    Element ideAction = doc.createElementNS(Util.NAMESPACE, "ide-action"); // NOI18N
514
                    ideAction.setAttribute("name", command); // NOI18N
514
                    ideAction.setAttribute("name", command); // NOI18N
Lines 684-700 Link Here
684
    private String findSourceFolders(String type) {
684
    private String findSourceFolders(String type) {
685
        StringBuffer result = new StringBuffer();
685
        StringBuffer result = new StringBuffer();
686
        Element data = Util.getPrimaryConfigurationData(helper);
686
        Element data = Util.getPrimaryConfigurationData(helper);
687
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
687
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
688
        if (foldersEl != null) {
688
        if (foldersEl != null) {
689
            for (Iterator i = Util.findSubElements(foldersEl).iterator(); i.hasNext();) {
689
            for (Iterator i = XMLUtil.findSubElements(foldersEl).iterator(); i.hasNext();) {
690
                Element sourceFolderEl = (Element)i.next();
690
                Element sourceFolderEl = (Element)i.next();
691
                Element typeEl = Util.findElement(sourceFolderEl , "type", Util.NAMESPACE); // NOI18N
691
                Element typeEl = XMLUtil.findElement(sourceFolderEl , "type", Util.NAMESPACE); // NOI18N
692
                if (typeEl == null || !Util.findText(typeEl).equals(type))
692
                if (typeEl == null || !XMLUtil.findText(typeEl).equals(type))
693
                    continue;
693
                    continue;
694
                Element locationEl = Util.findElement(sourceFolderEl , "location", Util.NAMESPACE); // NOI18N
694
                Element locationEl = XMLUtil.findElement(sourceFolderEl , "location", Util.NAMESPACE); // NOI18N
695
                if (locationEl == null)
695
                if (locationEl == null)
696
                    continue;
696
                    continue;
697
                String location = Util.findText(locationEl);
697
                String location = XMLUtil.findText(locationEl);
698
                if (result.length() > 0)
698
                if (result.length() > 0)
699
                    result.append(":"); // NOI18N
699
                    result.append(":"); // NOI18N
700
                result.append(location);
700
                result.append(location);
Lines 705-717 Link Here
705
    
705
    
706
    private String findContextPath() {
706
    private String findContextPath() {
707
        Element data = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true); // NOI18N
707
        Element data = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true); // NOI18N
708
        Element webModulEl = Util.findElement(data, "web-module", WebProjectNature.NS_WEB_2); // NOI18N
708
        Element webModulEl = XMLUtil.findElement(data, "web-module", WebProjectNature.NS_WEB_2); // NOI18N
709
        if (webModulEl == null)
709
        if (webModulEl == null)
710
            return null;
710
            return null;
711
        Element contextPathEl = Util.findElement(webModulEl, "context-path", WebProjectNature.NS_WEB_2); // NOI18N
711
        Element contextPathEl = XMLUtil.findElement(webModulEl, "context-path", WebProjectNature.NS_WEB_2); // NOI18N
712
        if (contextPathEl == null)
712
        if (contextPathEl == null)
713
            return null;
713
            return null;
714
        return Util.findText(contextPathEl);
714
        return XMLUtil.findText(contextPathEl);
715
    }
715
    }
716
    
716
    
717
}
717
}
(-)a/web.freeform/src/org/netbeans/modules/web/freeform/WebModules.java (-11 / +11 lines)
Lines 70-76 Link Here
70
import org.netbeans.api.project.ProjectManager;
70
import org.netbeans.api.project.ProjectManager;
71
import org.netbeans.api.project.ProjectUtils;
71
import org.netbeans.api.project.ProjectUtils;
72
import org.netbeans.api.project.SourceGroup;
72
import org.netbeans.api.project.SourceGroup;
73
import org.netbeans.modules.ant.freeform.spi.support.Util;
74
import org.netbeans.modules.j2ee.dd.spi.MetadataUnit;
73
import org.netbeans.modules.j2ee.dd.spi.MetadataUnit;
75
import org.netbeans.modules.j2ee.dd.spi.web.WebAppMetadataModelFactory;
74
import org.netbeans.modules.j2ee.dd.spi.web.WebAppMetadataModelFactory;
76
import org.netbeans.modules.web.api.webmodule.WebModule;
75
import org.netbeans.modules.web.api.webmodule.WebModule;
Lines 85-90 Link Here
85
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
84
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
86
import org.netbeans.spi.project.support.ant.PropertyUtils;
85
import org.netbeans.spi.project.support.ant.PropertyUtils;
87
import org.openide.util.Mutex;
86
import org.openide.util.Mutex;
87
import org.openide.xml.XMLUtil;
88
88
89
/**
89
/**
90
 * Web module implementation on top of freeform project.
90
 * Web module implementation on top of freeform project.
Lines 171-191 Link Here
171
        if (web == null) {
171
        if (web == null) {
172
            return mods;
172
            return mods;
173
        }
173
        }
174
        List/*<Element>*/ webModules = Util.findSubElements(web);
174
        List<Element> webModules = XMLUtil.findSubElements(web);
175
        Iterator it = webModules.iterator();
175
        Iterator it = webModules.iterator();
176
        while (it.hasNext()) {
176
        while (it.hasNext()) {
177
            Element webModulesEl = (Element)it.next();
177
            Element webModulesEl = (Element)it.next();
178
            assert webModulesEl.getLocalName().equals("web-module") : webModulesEl;
178
            assert webModulesEl.getLocalName().equals("web-module") : webModulesEl;
179
            FileObject docRootFO = getFile (webModulesEl, "doc-root"); //NOI18N
179
            FileObject docRootFO = getFile (webModulesEl, "doc-root"); //NOI18N
180
            Element j2eeSpecEl = Util.findElement (webModulesEl, "j2ee-spec-level", WebProjectNature.NS_WEB_2);
180
            Element j2eeSpecEl = XMLUtil.findElement (webModulesEl, "j2ee-spec-level", WebProjectNature.NS_WEB_2);
181
            String j2eeSpec = j2eeSpecEl == null ? null : evaluator.evaluate (Util.findText (j2eeSpecEl));
181
            String j2eeSpec = j2eeSpecEl == null ? null : evaluator.evaluate (XMLUtil.findText (j2eeSpecEl));
182
            Element contextPathEl = Util.findElement (webModulesEl, "context-path", WebProjectNature.NS_WEB_2);
182
            Element contextPathEl = XMLUtil.findElement (webModulesEl, "context-path", WebProjectNature.NS_WEB_2);
183
            String contextPathText = contextPathEl == null ? null : Util.findText (contextPathEl);
183
            String contextPathText = contextPathEl == null ? null : XMLUtil.findText (contextPathEl);
184
            String contextPath = contextPathText == null ? null : evaluator.evaluate (contextPathText);
184
            String contextPath = contextPathText == null ? null : evaluator.evaluate (contextPathText);
185
            Element classpathEl = Util.findElement (webModulesEl, "classpath", WebProjectNature.NS_WEB_2);
185
            Element classpathEl = XMLUtil.findElement (webModulesEl, "classpath", WebProjectNature.NS_WEB_2);
186
            FileObject [] sources = getSources ();
186
            FileObject [] sources = getSources ();
187
            ClassPath cp = classpathEl == null ? null : createClasspath (classpathEl, sources);
187
            ClassPath cp = classpathEl == null ? null : createClasspath (classpathEl, sources);
188
            Element webInfEl = Util.findElement (webModulesEl, "web-inf", WebProjectNature.NS_WEB_2);
188
            Element webInfEl = XMLUtil.findElement (webModulesEl, "web-inf", WebProjectNature.NS_WEB_2);
189
            FileObject webInf = null;
189
            FileObject webInf = null;
190
            if (webInfEl != null) {
190
            if (webInfEl != null) {
191
                webInf = getFile (webModulesEl, "web-inf"); //NOI18N
191
                webInf = getFile (webModulesEl, "web-inf"); //NOI18N
Lines 196-203 Link Here
196
    }
196
    }
197
    
197
    
198
    private FileObject getFile (Element parent, String fileElName) {
198
    private FileObject getFile (Element parent, String fileElName) {
199
        Element el = Util.findElement (parent, fileElName, WebProjectNature.NS_WEB_2);
199
        Element el = XMLUtil.findElement (parent, fileElName, WebProjectNature.NS_WEB_2);
200
        String fname = Util.findText (el);
200
        String fname = XMLUtil.findText (el);
201
        if (fname == null) {
201
        if (fname == null) {
202
            // empty element => cannot find fileobject
202
            // empty element => cannot find fileobject
203
            return null;
203
            return null;
Lines 240-246 Link Here
240
     */
240
     */
241
    private ClassPath createClasspath(Element classpathEl, FileObject[] sources) {
241
    private ClassPath createClasspath(Element classpathEl, FileObject[] sources) {
242
//        System.out.println("creating classpath for " + classpathEl);
242
//        System.out.println("creating classpath for " + classpathEl);
243
        String cp = Util.findText(classpathEl);
243
        String cp = XMLUtil.findText(classpathEl);
244
        if (cp == null) {
244
        if (cp == null) {
245
            cp = "";
245
            cp = "";
246
        }
246
        }
(-)a/web.freeform/src/org/netbeans/modules/web/freeform/WebProjectGenerator.java (-24 / +24 lines)
Lines 48-55 Link Here
48
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
48
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
49
import org.netbeans.spi.project.AuxiliaryConfiguration;
49
import org.netbeans.spi.project.AuxiliaryConfiguration;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.openide.filesystems.FileObject;
52
import org.openide.util.NbBundle;
51
import org.openide.util.NbBundle;
52
import org.openide.xml.XMLUtil;
53
import org.w3c.dom.Document;
53
import org.w3c.dom.Document;
54
import org.w3c.dom.Element;
54
import org.w3c.dom.Element;
55
import org.w3c.dom.Node;
55
import org.w3c.dom.Node;
Lines 102-141 Link Here
102
102
103
        Element data = Util.getPrimaryConfigurationData(helper);
103
        Element data = Util.getPrimaryConfigurationData(helper);
104
        Document doc = data.getOwnerDocument();
104
        Document doc = data.getOwnerDocument();
105
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
105
        Element foldersEl = XMLUtil.findElement(data, "folders", Util.NAMESPACE); // NOI18N
106
        if (foldersEl == null) {
106
        if (foldersEl == null) {
107
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
107
            foldersEl = doc.createElementNS(Util.NAMESPACE, "folders"); // NOI18N
108
            Util.appendChildElement(data, foldersEl, rootElementsOrder);
108
            XMLUtil.appendChildElement(data, foldersEl, rootElementsOrder);
109
        } else {
109
        } else {
110
            List l = Util.findSubElements(foldersEl);
110
            List l = XMLUtil.findSubElements(foldersEl);
111
            for (int i = 0; i < l.size(); i++) {
111
            for (int i = 0; i < l.size(); i++) {
112
                Element e = (Element) l.get(i);
112
                Element e = (Element) l.get(i);
113
                Element te = Util.findElement(e, "type", Util.NAMESPACE);
113
                Element te = XMLUtil.findElement(e, "type", Util.NAMESPACE);
114
                if (te != null && Util.findText(te).equals(folderType)) {
114
                if (te != null && XMLUtil.findText(te).equals(folderType)) {
115
                    foldersEl.removeChild(e);
115
                    foldersEl.removeChild(e);
116
                    break;
116
                    break;
117
                }
117
                }
118
            }
118
            }
119
        }
119
        }
120
        
120
        
121
        Element viewEl = Util.findElement(data, "view", Util.NAMESPACE); // NOI18N
121
        Element viewEl = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
122
        if (viewEl == null) {
122
        if (viewEl == null) {
123
            viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N
123
            viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N
124
            Util.appendChildElement(data, viewEl, rootElementsOrder);
124
            XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
125
        }
125
        }
126
        Element itemsEl = Util.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
126
        Element itemsEl = XMLUtil.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
127
        if (itemsEl == null) {
127
        if (itemsEl == null) {
128
            itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N
128
            itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N
129
            Util.appendChildElement(viewEl, itemsEl, viewElementsOrder);
129
            XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder);
130
        } else {
130
        } else {
131
            List l = Util.findSubElements(itemsEl);
131
            List l = XMLUtil.findSubElements(itemsEl);
132
            for (int i = 0; i < l.size(); i++) {
132
            for (int i = 0; i < l.size(); i++) {
133
                Element e = (Element) l.get(i);
133
                Element e = (Element) l.get(i);
134
                if (e.hasAttribute("style")) {
134
                if (e.hasAttribute("style")) {
135
                    if (e.getAttribute("style").equals("tree")) {
135
                    if (e.getAttribute("style").equals("tree")) {
136
                        // #110173
136
                        // #110173
137
                        Element labelElement = Util.findElement(e, "label", Util.NAMESPACE);
137
                        Element labelElement = XMLUtil.findElement(e, "label", Util.NAMESPACE);
138
                        if (labelElement != null && label.equals(Util.findText(labelElement))) {
138
                        if (labelElement != null && label.equals(XMLUtil.findText(labelElement))) {
139
                            itemsEl.removeChild(e);
139
                            itemsEl.removeChild(e);
140
                            break;
140
                            break;
141
                        }
141
                        }
Lines 159-165 Link Here
159
            el = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
159
            el = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
160
            el.appendChild(doc.createTextNode(path));
160
            el.appendChild(doc.createTextNode(path));
161
            sourceFolderEl.appendChild(el);
161
            sourceFolderEl.appendChild(el);
162
            Util.appendChildElement(foldersEl, sourceFolderEl, folderElementsOrder);
162
            XMLUtil.appendChildElement(foldersEl, sourceFolderEl, folderElementsOrder);
163
            
163
            
164
            sourceFolderEl = doc.createElementNS(Util.NAMESPACE, "source-folder"); // NOI18N
164
            sourceFolderEl = doc.createElementNS(Util.NAMESPACE, "source-folder"); // NOI18N
165
            sourceFolderEl.setAttribute("style", "tree"); // NOI18N
165
            sourceFolderEl.setAttribute("style", "tree"); // NOI18N
Lines 177-183 Link Here
177
                    insertWebInfElement(itemsEl, firstNode, sourceFolderEl);
177
                    insertWebInfElement(itemsEl, firstNode, sourceFolderEl);
178
                }
178
                }
179
            } else {
179
            } else {
180
                Util.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
180
                XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
181
            }
181
            }
182
        }
182
        }
183
        Util.putPrimaryConfigurationData(helper, data);
183
        Util.putPrimaryConfigurationData(helper, data);
Lines 192-198 Link Here
192
        if (secondNode != null) {
192
        if (secondNode != null) {
193
            itemsEl.insertBefore(sourceFolderEl, secondNode);
193
            itemsEl.insertBefore(sourceFolderEl, secondNode);
194
        } else {
194
        } else {
195
            Util.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
195
            XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
196
        }
196
        }
197
    }
197
    }
198
    
198
    
Lines 213-244 Link Here
213
                return list;
213
                return list;
214
            }
214
            }
215
        }
215
        }
216
        List<Element> wms = Util.findSubElements(data);
216
        List<Element> wms = XMLUtil.findSubElements(data);
217
        Iterator<Element> it = wms.iterator();
217
        Iterator<Element> it = wms.iterator();
218
        while (it.hasNext()) {
218
        while (it.hasNext()) {
219
            Element wmEl = it.next();
219
            Element wmEl = it.next();
220
            WebModule wm = new WebModule();
220
            WebModule wm = new WebModule();
221
            Iterator it2 = Util.findSubElements(wmEl).iterator();
221
            Iterator it2 = XMLUtil.findSubElements(wmEl).iterator();
222
            while (it2.hasNext()) {
222
            while (it2.hasNext()) {
223
                Element el = (Element)it2.next();
223
                Element el = (Element)it2.next();
224
                if (el.getLocalName().equals("doc-root")) { // NOI18N
224
                if (el.getLocalName().equals("doc-root")) { // NOI18N
225
                    wm.docRoot = Util.findText(el);
225
                    wm.docRoot = XMLUtil.findText(el);
226
                    continue;
226
                    continue;
227
                }
227
                }
228
                if (el.getLocalName().equals("classpath")) { // NOI18N
228
                if (el.getLocalName().equals("classpath")) { // NOI18N
229
                    wm.classpath = Util.findText(el);
229
                    wm.classpath = XMLUtil.findText(el);
230
                    continue;
230
                    continue;
231
                }
231
                }
232
                if (el.getLocalName().equals("context-path")) { // NOI18N
232
                if (el.getLocalName().equals("context-path")) { // NOI18N
233
                    wm.contextPath = Util.findText(el);
233
                    wm.contextPath = XMLUtil.findText(el);
234
                    continue;
234
                    continue;
235
                }
235
                }
236
                if (el.getLocalName().equals("j2ee-spec-level")) { // NOI18N
236
                if (el.getLocalName().equals("j2ee-spec-level")) { // NOI18N
237
                    wm.j2eeSpecLevel = Util.findText(el);
237
                    wm.j2eeSpecLevel = XMLUtil.findText(el);
238
                    continue;
238
                    continue;
239
                }
239
                }
240
                if (el.getLocalName().equals("web-inf")) { // NOI18N
240
                if (el.getLocalName().equals("web-inf")) { // NOI18N
241
                    wm.webInf = Util.findText(el);
241
                    wm.webInf = XMLUtil.findText(el);
242
                }
242
                }
243
            }
243
            }
244
            list.add(wm);
244
            list.add(wm);
Lines 295-301 Link Here
295
        }
295
        }
296
        
296
        
297
        Document doc = data.getOwnerDocument();
297
        Document doc = data.getOwnerDocument();
298
        List<Element> wms = Util.findSubElements(data);
298
        List<Element> wms = XMLUtil.findSubElements(data);
299
        Iterator<Element> it = wms.iterator();
299
        Iterator<Element> it = wms.iterator();
300
        while (it.hasNext()) {
300
        while (it.hasNext()) {
301
            Element wmEl = it.next();
301
            Element wmEl = it.next();
(-)a/web.freeform/test/unit/src/org/netbeans/modules/web/freeform/WebProjectGeneratorTest.java (-8 / +9 lines)
Lines 64-69 Link Here
64
import org.openide.filesystems.FileUtil;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.modules.ModuleInfo;
65
import org.openide.modules.ModuleInfo;
66
import org.openide.util.Lookup;
66
import org.openide.util.Lookup;
67
import org.openide.xml.XMLUtil;
67
import org.w3c.dom.Element;
68
import org.w3c.dom.Element;
68
import org.xml.sax.SAXException;
69
import org.xml.sax.SAXException;
69
import org.xml.sax.SAXParseException;
70
import org.xml.sax.SAXParseException;
Lines 196-208 Link Here
196
        // check that the correct /1 data was saved
197
        // check that the correct /1 data was saved
197
        Element el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_1, true);
198
        Element el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_1, true);
198
        assertNotNull("Web modules should be saved in /1",  el);
199
        assertNotNull("Web modules should be saved in /1",  el);
199
        List<Element> subElements = Util.findSubElements(el);
200
        List<Element> subElements = XMLUtil.findSubElements(el);
200
        assertEquals(1, subElements.size());
201
        assertEquals(1, subElements.size());
201
        
202
        
202
        // compare the web module
203
        // compare the web module
203
        Element el2 = subElements.get(0);
204
        Element el2 = subElements.get(0);
204
        assertElement(el2, "web-module", null);
205
        assertElement(el2, "web-module", null);
205
        assertElementArray(Util.findSubElements(el2),
206
        assertElementArray(XMLUtil.findSubElements(el2),
206
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
207
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
207
            new String[] {"web",      "mymodule",     "1.5",             "web/WEB-INF"});
208
            new String[] {"web",      "mymodule",     "1.5",             "web/WEB-INF"});
208
        // validate against schema:
209
        // validate against schema:
Lines 224-235 Link Here
224
        assertNull("No /1 data should exist.", el);
225
        assertNull("No /1 data should exist.", el);
225
        el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true);
226
        el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true);
226
        assertNotNull("Should have /2 data.", el);
227
        assertNotNull("Should have /2 data.", el);
227
        subElements = Util.findSubElements(el);
228
        subElements = XMLUtil.findSubElements(el);
228
        assertEquals(1, subElements.size());
229
        assertEquals(1, subElements.size());
229
        // compare the web module
230
        // compare the web module
230
        el2 = subElements.get(0);
231
        el2 = subElements.get(0);
231
        assertElement(el2, "web-module", null);
232
        assertElement(el2, "web-module", null);
232
        assertElementArray(Util.findSubElements(el2),
233
        assertElementArray(XMLUtil.findSubElements(el2),
233
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
234
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
234
            new String[] {"web",      "mymodule",     "1.5",             "somewhereelse/WEB-INF"});
235
            new String[] {"web",      "mymodule",     "1.5",             "somewhereelse/WEB-INF"});
235
        // validate against schema:
236
        // validate against schema:
Lines 252-263 Link Here
252
        assertNull("No /1 data should exist.", el);
253
        assertNull("No /1 data should exist.", el);
253
        el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true);
254
        el = aux.getConfigurationFragment(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, true);
254
        assertNotNull("Should have /2 data.", el);
255
        assertNotNull("Should have /2 data.", el);
255
        subElements = Util.findSubElements(el);
256
        subElements = XMLUtil.findSubElements(el);
256
        assertEquals(1, subElements.size());
257
        assertEquals(1, subElements.size());
257
        // compare the web module
258
        // compare the web module
258
        el2 = subElements.get(0);
259
        el2 = subElements.get(0);
259
        assertElement(el2, "web-module", null);
260
        assertElement(el2, "web-module", null);
260
        assertElementArray(Util.findSubElements(el2),
261
        assertElementArray(XMLUtil.findSubElements(el2),
261
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
262
            new String[] {"doc-root", "context-path", "j2ee-spec-level", "web-inf"},
262
            new String[] {"web",      "mymodule",     "1.5",             "somewhereelse/WEB-INF"});
263
            new String[] {"web",      "mymodule",     "1.5",             "somewhereelse/WEB-INF"});
263
        // validate against schema:
264
        // validate against schema:
Lines 304-310 Link Here
304
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
305
        String message = "Element "+element+" does not match [name="+expectedName+",value="+expectedValue+"]"; // NOI18N
305
        assertEquals(message, expectedName, element.getLocalName());
306
        assertEquals(message, expectedName, element.getLocalName());
306
        if (expectedValue != null) {
307
        if (expectedValue != null) {
307
            assertEquals(message, expectedValue, Util.findText(element));
308
            assertEquals(message, expectedValue, XMLUtil.findText(element));
308
        }
309
        }
309
    }
310
    }
310
311
Lines 332-338 Link Here
332
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
333
            expectedValue+", attr="+expectedAttrName+", attrvalue="+expectedAttrValue+"]"; // NOI18N
333
        assertEquals(message, expectedName, element.getLocalName());
334
        assertEquals(message, expectedName, element.getLocalName());
334
        if (expectedValue != null) {
335
        if (expectedValue != null) {
335
            assertEquals(message, expectedValue, Util.findText(element));
336
            assertEquals(message, expectedValue, XMLUtil.findText(element));
336
        }
337
        }
337
        String val = element.getAttribute(expectedAttrName);
338
        String val = element.getAttribute(expectedAttrName);
338
        assertEquals(expectedAttrValue, val);
339
        assertEquals(expectedAttrValue, val);
(-)a/web.project/nbproject/project.xml (-6 / +15 lines)
Lines 489-495 Link Here
489
                    <build-prerequisite/>
489
                    <build-prerequisite/>
490
                    <compile-dependency/>
490
                    <compile-dependency/>
491
                    <run-dependency>
491
                    <run-dependency>
492
                        <specification-version>8.0</specification-version>
492
                        <specification-version>8.4</specification-version>
493
                    </run-dependency>
493
                    </run-dependency>
494
                </dependency>
494
                </dependency>
495
                <dependency>
495
                <dependency>
Lines 522-528 Link Here
522
                <test-type>
522
                <test-type>
523
                    <name>unit</name>
523
                    <name>unit</name>
524
                    <test-dependency>
524
                    <test-dependency>
525
                        <code-name-base>org.netbeans.modules.web.project</code-name-base>
525
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
526
                        <compile-dependency/>
527
                    </test-dependency>
528
                    <test-dependency>
529
                        <code-name-base>org.netbeans.modules.j2eeapis</code-name-base>
530
                    </test-dependency>
531
                    <test-dependency>
532
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
533
                    </test-dependency>
534
                    <test-dependency>
535
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
526
                        <recursive/>
536
                        <recursive/>
527
                        <compile-dependency/>
537
                        <compile-dependency/>
528
                    </test-dependency>
538
                    </test-dependency>
Lines 532-541 Link Here
532
                        <test/>
542
                        <test/>
533
                    </test-dependency>
543
                    </test-dependency>
534
                    <test-dependency>
544
                    <test-dependency>
535
                        <code-name-base>org.netbeans.modules.j2eeapis</code-name-base>
545
                        <code-name-base>org.netbeans.modules.web.project</code-name-base>
536
                    </test-dependency>
546
                        <recursive/>
537
                    <test-dependency>
547
                        <compile-dependency/>
538
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
539
                    </test-dependency>
548
                    </test-dependency>
540
                    <test-dependency>
549
                    <test-dependency>
541
                        <code-name-base>org.openide.util</code-name-base>
550
                        <code-name-base>org.openide.util</code-name-base>
(-)a/web.project/src/org/netbeans/modules/web/project/UpdateProjectImpl.java (-52 / +3 lines)
Lines 69-74 Link Here
69
import org.openide.filesystems.URLMapper;
69
import org.openide.filesystems.URLMapper;
70
import org.openide.util.Mutex;
70
import org.openide.util.Mutex;
71
import org.openide.util.NbBundle;
71
import org.openide.util.NbBundle;
72
import org.openide.xml.XMLUtil;
72
import org.w3c.dom.Comment;
73
import org.w3c.dom.Comment;
73
import org.w3c.dom.Document;
74
import org.w3c.dom.Document;
74
import org.w3c.dom.Element;
75
import org.w3c.dom.Element;
Lines 295-301 Link Here
295
            if (oldRoot != null) {
296
            if (oldRoot != null) {
296
                Document doc = oldRoot.getOwnerDocument();
297
                Document doc = oldRoot.getOwnerDocument();
297
                Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
298
                Element newRoot = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
298
                copyDocument (doc, oldRoot, newRoot);
299
                XMLUtil.copyDocument (oldRoot, newRoot, WebProjectType.PROJECT_CONFIGURATION_NAMESPACE);
299
                if (version == 1) {
300
                if (version == 1) {
300
                    //1->2 upgrade
301
                    //1->2 upgrade
301
                    Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
302
                    Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
Lines 317-323 Link Here
317
                            Element library = (Element) libList.item(i);
318
                            Element library = (Element) libList.item(i);
318
                            Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
319
                            Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
319
                            //remove ${ and } from the beginning and end
320
                            //remove ${ and } from the beginning and end
320
                            String webFileText = findText(webFile);
321
                            String webFileText = XMLUtil.findText(webFile);
321
                            webFileText = webFileText.substring(2, webFileText.length() - 1);
322
                            webFileText = webFileText.substring(2, webFileText.length() - 1);
322
//                            warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE);
323
//                            warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : Item.PATH_IN_WAR_NONE);
323
                            if (webFileText.startsWith ("lib.")) {
324
                            if (webFileText.startsWith ("lib.")) {
Lines 375-430 Link Here
375
        }
376
        }
376
    }
377
    }
377
378
378
    /**
379
     * Extract nested text from a node.
380
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
381
     * @param parent a parent node
382
     * @return the nested text, or null if none was found
383
     */
384
    private static String findText(Node parent) {
385
        NodeList l = parent.getChildNodes();
386
        for (int i = 0; i < l.getLength(); i++) {
387
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
388
                Text text = (Text)l.item(i);
389
                return text.getNodeValue();
390
            }
391
        }
392
        return null;
393
    }
394
    
395
    private static void copyDocument (Document doc, Element from, Element to) {
396
        NodeList nl = from.getChildNodes();
397
        int length = nl.getLength();
398
        for (int i=0; i< length; i++) {
399
            Node node = nl.item (i);
400
            Node newNode = null;
401
            switch (node.getNodeType()) {
402
                case Node.ELEMENT_NODE:
403
                    Element oldElement = (Element) node;
404
                    newNode = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
405
                    NamedNodeMap m = oldElement.getAttributes();
406
                    Element newElement = (Element) newNode;
407
                    for (int index = 0; index < m.getLength(); index++) {
408
                        Node attr = m.item(index);
409
                        newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
410
                    }
411
                    copyDocument(doc,oldElement,(Element)newNode);
412
                    break;
413
                case Node.TEXT_NODE:
414
                    Text oldText = (Text) node;
415
                    newNode = doc.createTextNode(oldText.getData());
416
                    break;
417
                case Node.COMMENT_NODE:
418
                    Comment oldComment = (Comment) node;
419
                    newNode = doc.createComment(oldComment.getData());
420
                    break;
421
            }
422
            if (newNode != null) {
423
                to.appendChild (newNode);
424
            }
425
        }
426
    }
427
428
    private static Element updateMinAntVersion (final Element root, final Document doc) {
379
    private static Element updateMinAntVersion (final Element root, final Document doc) {
429
        NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION);
380
        NodeList list = root.getElementsByTagNameNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,TAG_MINIMUM_ANT_VERSION);
430
        if (list.getLength() == 1) {
381
        if (list.getLength() == 1) {
(-)a/web.project/src/org/netbeans/modules/web/project/classpath/ClassPathSupportCallbackImpl.java (-39 / +4 lines)
Lines 45-60 Link Here
45
import java.util.List;
45
import java.util.List;
46
import java.util.Map;
46
import java.util.Map;
47
import org.netbeans.modules.j2ee.common.Util;
47
import org.netbeans.modules.j2ee.common.Util;
48
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
49
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
48
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
50
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
49
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
51
import org.netbeans.modules.web.project.WebProjectType;
50
import org.netbeans.modules.web.project.WebProjectType;
52
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.netbeans.spi.project.support.ant.AntProjectHelper;
52
import org.openide.xml.XMLUtil;
53
import org.w3c.dom.Document;
53
import org.w3c.dom.Document;
54
import org.w3c.dom.Element;
54
import org.w3c.dom.Element;
55
import org.w3c.dom.Node;
55
import org.w3c.dom.Node;
56
import org.w3c.dom.NodeList;
56
import org.w3c.dom.NodeList;
57
import org.w3c.dom.Text;
58
57
59
/**
58
/**
60
 * Defines the various class paths for a web project.
59
 * Defines the various class paths for a web project.
Lines 120-139 Link Here
120
                            Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
119
                            Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
121
                            NodeList pathInWarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_WAR);
120
                            NodeList pathInWarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_WAR);
122
                            //remove ${ and } from the beginning and end
121
                            //remove ${ and } from the beginning and end
123
                            String webFileText = findText(webFile);
122
                            String webFileText = XMLUtil.findText(webFile);
124
                            webFileText = webFileText.substring(2, webFileText.length() - 1);
123
                            webFileText = webFileText.substring(2, webFileText.length() - 1);
125
                            
124
                            
126
                            //#86522
125
                            //#86522
127
                            if (webModuleLibraries.equals(TAG_WEB_MODULE__ADDITIONAL_LIBRARIES)) {
126
                            if (webModuleLibraries.equals(TAG_WEB_MODULE__ADDITIONAL_LIBRARIES)) {
128
                                String pathInWar = PATH_IN_WAR_NONE;
127
                                String pathInWar = PATH_IN_WAR_NONE;
129
                                if (pathInWarElements.getLength() > 0) {
128
                                if (pathInWarElements.getLength() > 0) {
130
                                    pathInWar = findText((Element) pathInWarElements.item(0));
129
                                    pathInWar = XMLUtil.findText((Element) pathInWarElements.item(0));
131
                                    if (pathInWar == null)
130
                                    if (pathInWar == null)
132
                                        pathInWar = "";
131
                                        pathInWar = "";
133
                                }
132
                                }
134
                                warIncludesMap.put(webFileText, pathInWar);
133
                                warIncludesMap.put(webFileText, pathInWar);
135
                            } else {
134
                            } else {
136
                                warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? findText((Element) pathInWarElements.item(0)) : PATH_IN_WAR_NONE);
135
                                warIncludesMap.put(webFileText, pathInWarElements.getLength() > 0 ? XMLUtil.findText((Element) pathInWarElements.item(0)) : PATH_IN_WAR_NONE);
137
                            }
136
                            }
138
                            if (dirs != null) {
137
                            if (dirs != null) {
139
                                warIncludesMap.put(webFileText+"."+Util.DESTINATION_DIRECTORY, dirs);
138
                                warIncludesMap.put(webFileText+"."+Util.DESTINATION_DIRECTORY, dirs);
Lines 148-187 Link Here
148
    }
147
    }
149
148
150
    /**
149
    /**
151
     * Extracts <b>the first</b> nested text from an element.
152
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
153
     * @param parent a parent element
154
     * @return the nested text, or null if none was found
155
     */
156
    private static String findText( Element parent ) {
157
        NodeList l = parent.getChildNodes();
158
        for ( int i = 0; i < l.getLength(); i++ ) {
159
            if ( l.item(i).getNodeType() == Node.TEXT_NODE ) {
160
                Text text = (Text)l.item( i );
161
                return text.getNodeValue();
162
            }
163
        }
164
        return null;
165
    }
166
    
167
    /**
168
     * Extract nested text from a node.
169
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
170
     * @param parent a parent node
171
     * @return the nested text, or null if none was found
172
     */
173
    private static String findText(Node parent) {
174
        NodeList l = parent.getChildNodes();
175
        for (int i = 0; i < l.getLength(); i++) {
176
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
177
                Text text = (Text)l.item(i);
178
                return text.getNodeValue();
179
            }
180
        }
181
        return null;
182
    }
183
184
    /**
185
     * Updates the project helper with the list of classpath items which are to be
150
     * Updates the project helper with the list of classpath items which are to be
186
     * included in deployment.
151
     * included in deployment.
187
     */
152
     */

Return to bug 136595