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/src/org/netbeans/modules/ant/freeform/Actions.java (-34 / +34 lines)
Lines 64-70 Link Here
64
import javax.swing.AbstractAction;
64
import javax.swing.AbstractAction;
65
import javax.swing.Action;
65
import javax.swing.Action;
66
import org.apache.tools.ant.module.api.support.ActionUtils;
66
import org.apache.tools.ant.module.api.support.ActionUtils;
67
import org.netbeans.modules.ant.freeform.spi.support.Util;
68
import org.netbeans.modules.ant.freeform.ui.TargetMappingPanel;
67
import org.netbeans.modules.ant.freeform.ui.TargetMappingPanel;
69
import org.netbeans.modules.ant.freeform.ui.UnboundTargetAlert;
68
import org.netbeans.modules.ant.freeform.ui.UnboundTargetAlert;
70
import org.netbeans.spi.project.ActionProvider;
69
import org.netbeans.spi.project.ActionProvider;
Lines 83-88 Link Here
83
import org.openide.util.NbBundle;
82
import org.openide.util.NbBundle;
84
import org.openide.util.Utilities;
83
import org.openide.util.Utilities;
85
import org.openide.util.actions.SystemAction;
84
import org.openide.util.actions.SystemAction;
85
import org.openide.xml.XMLUtil;
86
import org.w3c.dom.Element;
86
import org.w3c.dom.Element;
87
87
88
/**
88
/**
Lines 135-147 Link Here
135
    
135
    
136
    public String[] getSupportedActions() {
136
    public String[] getSupportedActions() {
137
        Element genldata = project.getPrimaryConfigurationData();
137
        Element genldata = project.getPrimaryConfigurationData();
138
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
138
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
139
        if (actionsEl == null) {
139
        if (actionsEl == null) {
140
            return new String[0];
140
            return new String[0];
141
        }
141
        }
142
        // Use a set, not a list, since when using context you can define one action several times:
142
        // Use a set, not a list, since when using context you can define one action several times:
143
        Set<String> names = new LinkedHashSet<String>();
143
        Set<String> names = new LinkedHashSet<String>();
144
        for (Element actionEl : Util.findSubElements(actionsEl)) {
144
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
145
            names.add(actionEl.getAttribute("name")); // NOI18N
145
            names.add(actionEl.getAttribute("name")); // NOI18N
146
        }
146
        }
147
        // #46886: also always enable all common global actions, in case they should be selected:
147
        // #46886: also always enable all common global actions, in case they should be selected:
Lines 168-183 Link Here
168
        }
168
        }
169
        
169
        
170
        Element genldata = project.getPrimaryConfigurationData();
170
        Element genldata = project.getPrimaryConfigurationData();
171
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
171
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
172
        if (actionsEl == null) {
172
        if (actionsEl == null) {
173
            throw new IllegalArgumentException("No commands supported"); // NOI18N
173
            throw new IllegalArgumentException("No commands supported"); // NOI18N
174
        }
174
        }
175
        boolean foundAction = false;
175
        boolean foundAction = false;
176
        for (Element actionEl : Util.findSubElements(actionsEl)) {
176
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
177
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
177
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
178
                foundAction = true;
178
                foundAction = true;
179
                // XXX perhaps check also existence of script
179
                // XXX perhaps check also existence of script
180
                Element contextEl = Util.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
180
                Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
181
                if (contextEl != null) {
181
                if (contextEl != null) {
182
                    // Check whether the context contains files all in this folder,
182
                    // Check whether the context contains files all in this folder,
183
                    // matching the pattern if any, and matching the arity (single/multiple).
183
                    // matching the pattern if any, and matching the arity (single/multiple).
Lines 188-196 Link Here
188
                        return true;
188
                        return true;
189
                    } else if (!selection.isEmpty()) {
189
                    } else if (!selection.isEmpty()) {
190
                        // Multiple selection; check arity.
190
                        // Multiple selection; check arity.
191
                        Element arityEl = Util.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
191
                        Element arityEl = XMLUtil.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
192
                        assert arityEl != null : "No <arity> in <context> for " + command;
192
                        assert arityEl != null : "No <arity> in <context> for " + command;
193
                        if (Util.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL) != null) { // NOI18N
193
                        if (XMLUtil.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL) != null) { // NOI18N
194
                            // Supports multiple selection, take it.
194
                            // Supports multiple selection, take it.
195
                            return true;
195
                            return true;
196
                        }
196
                        }
Lines 232-243 Link Here
232
        }
232
        }
233
        
233
        
234
        Element genldata = project.getPrimaryConfigurationData();
234
        Element genldata = project.getPrimaryConfigurationData();
235
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
235
        Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
236
        if (actionsEl == null) {
236
        if (actionsEl == null) {
237
            throw new IllegalArgumentException("No commands supported"); // NOI18N
237
            throw new IllegalArgumentException("No commands supported"); // NOI18N
238
        }
238
        }
239
        boolean foundAction = false;
239
        boolean foundAction = false;
240
        for (Element actionEl : Util.findSubElements(actionsEl)) {
240
        for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
241
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
241
            if (actionEl.getAttribute("name").equals(command)) { // NOI18N
242
                foundAction = true;
242
                foundAction = true;
243
                runConfiguredAction(project, actionEl, context);
243
                runConfiguredAction(project, actionEl, context);
Lines 272-280 Link Here
272
            _files.add(d.getPrimaryFile());
272
            _files.add(d.getPrimaryFile());
273
        }
273
        }
274
        Collection<? extends FileObject> files = _files;
274
        Collection<? extends FileObject> files = _files;
275
        Element folderEl = Util.findElement(contextEl, "folder", FreeformProjectType.NS_GENERAL); // NOI18N
275
        Element folderEl = XMLUtil.findElement(contextEl, "folder", FreeformProjectType.NS_GENERAL); // NOI18N
276
        assert folderEl != null : "Must have <folder> in <context>";
276
        assert folderEl != null : "Must have <folder> in <context>";
277
        String rawtext = Util.findText(folderEl);
277
        String rawtext = XMLUtil.findText(folderEl);
278
        assert rawtext != null : "Must have text contents in <folder>";
278
        assert rawtext != null : "Must have text contents in <folder>";
279
        String evaltext = project.evaluator().evaluate(rawtext);
279
        String evaltext = project.evaluator().evaluate(rawtext);
280
        if (evaltext == null) {
280
        if (evaltext == null) {
Lines 285-293 Link Here
285
            return Collections.emptyMap();
285
            return Collections.emptyMap();
286
        }
286
        }
287
        Pattern pattern = null;
287
        Pattern pattern = null;
288
        Element patternEl = Util.findElement(contextEl, "pattern", FreeformProjectType.NS_GENERAL); // NOI18N
288
        Element patternEl = XMLUtil.findElement(contextEl, "pattern", FreeformProjectType.NS_GENERAL); // NOI18N
289
        if (patternEl != null) {
289
        if (patternEl != null) {
290
            String text = Util.findText(patternEl);
290
            String text = XMLUtil.findText(patternEl);
291
            assert text != null : "Must have text contents in <pattern>";
291
            assert text != null : "Must have text contents in <pattern>";
292
            try {
292
            try {
293
                pattern = Pattern.compile(text);
293
                pattern = Pattern.compile(text);
Lines 316-324 Link Here
316
     */
316
     */
317
    private static void runConfiguredAction(FreeformProject project, Element actionEl, Lookup context) {
317
    private static void runConfiguredAction(FreeformProject project, Element actionEl, Lookup context) {
318
        String script;
318
        String script;
319
        Element scriptEl = Util.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
319
        Element scriptEl = XMLUtil.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
320
        if (scriptEl != null) {
320
        if (scriptEl != null) {
321
            script = Util.findText(scriptEl);
321
            script = XMLUtil.findText(scriptEl);
322
        } else {
322
        } else {
323
            script = "build.xml"; // NOI18N
323
            script = "build.xml"; // NOI18N
324
        }
324
        }
Lines 334-346 Link Here
334
            DialogDisplayer.getDefault().notify(nd);
334
            DialogDisplayer.getDefault().notify(nd);
335
            return;
335
            return;
336
        }
336
        }
337
        List<Element> targets = Util.findSubElements(actionEl);
337
        List<Element> targets = XMLUtil.findSubElements(actionEl);
338
        List<String> targetNames = new ArrayList<String>(targets.size());
338
        List<String> targetNames = new ArrayList<String>(targets.size());
339
        for (Element targetEl : targets) {
339
        for (Element targetEl : targets) {
340
            if (!targetEl.getLocalName().equals("target")) { // NOI18N
340
            if (!targetEl.getLocalName().equals("target")) { // NOI18N
341
                continue;
341
                continue;
342
            }
342
            }
343
            targetNames.add(Util.findText(targetEl));
343
            targetNames.add(XMLUtil.findText(targetEl));
344
        }
344
        }
345
        String[] targetNameArray;
345
        String[] targetNameArray;
346
        if (!targetNames.isEmpty()) {
346
        if (!targetNames.isEmpty()) {
Lines 350-356 Link Here
350
            targetNameArray = null;
350
            targetNameArray = null;
351
        }
351
        }
352
        Properties props = new Properties();
352
        Properties props = new Properties();
353
        Element contextEl = Util.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
353
        Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
354
        if (contextEl != null) {
354
        if (contextEl != null) {
355
            Map<String,FileObject> selection = findSelection(contextEl, context, project);
355
            Map<String,FileObject> selection = findSelection(contextEl, context, project);
356
            if (selection.isEmpty()) {
356
            if (selection.isEmpty()) {
Lines 359-376 Link Here
359
            String separator = null;
359
            String separator = null;
360
            if (selection.size() > 1) {
360
            if (selection.size() > 1) {
361
                // Find the right separator.
361
                // Find the right separator.
362
                Element arityEl = Util.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
362
                Element arityEl = XMLUtil.findElement(contextEl, "arity", FreeformProjectType.NS_GENERAL); // NOI18N
363
                assert arityEl != null : "No <arity> in <context> for " + actionEl.getAttribute("name");
363
                assert arityEl != null : "No <arity> in <context> for " + actionEl.getAttribute("name");
364
                Element sepFilesEl = Util.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
364
                Element sepFilesEl = XMLUtil.findElement(arityEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
365
                if (sepFilesEl == null) {
365
                if (sepFilesEl == null) {
366
                    // Only handles single files -> skip it.
366
                    // Only handles single files -> skip it.
367
                    return;
367
                    return;
368
                }
368
                }
369
                separator = Util.findText(sepFilesEl);
369
                separator = XMLUtil.findText(sepFilesEl);
370
            }
370
            }
371
            Element formatEl = Util.findElement(contextEl, "format", FreeformProjectType.NS_GENERAL); // NOI18N
371
            Element formatEl = XMLUtil.findElement(contextEl, "format", FreeformProjectType.NS_GENERAL); // NOI18N
372
            assert formatEl != null : "No <format> in <context> for " + actionEl.getAttribute("name");
372
            assert formatEl != null : "No <format> in <context> for " + actionEl.getAttribute("name");
373
            String format = Util.findText(formatEl);
373
            String format = XMLUtil.findText(formatEl);
374
            StringBuffer buf = new StringBuffer();
374
            StringBuffer buf = new StringBuffer();
375
            Iterator<Map.Entry<String,FileObject>> it = selection.entrySet().iterator();
375
            Iterator<Map.Entry<String,FileObject>> it = selection.entrySet().iterator();
376
            while (it.hasNext()) {
376
            while (it.hasNext()) {
Lines 421-429 Link Here
421
                    buf.append(separator);
421
                    buf.append(separator);
422
                }
422
                }
423
            }
423
            }
424
            Element propEl = Util.findElement(contextEl, "property", FreeformProjectType.NS_GENERAL); // NOI18N
424
            Element propEl = XMLUtil.findElement(contextEl, "property", FreeformProjectType.NS_GENERAL); // NOI18N
425
            assert propEl != null : "No <property> in <context> for " + actionEl.getAttribute("name");
425
            assert propEl != null : "No <property> in <context> for " + actionEl.getAttribute("name");
426
            String prop = Util.findText(propEl);
426
            String prop = XMLUtil.findText(propEl);
427
            assert prop != null : "Must have text contents in <property>";
427
            assert prop != null : "Must have text contents in <property>";
428
            props.setProperty(prop, buf.toString());
428
            props.setProperty(prop, buf.toString());
429
        }
429
        }
Lines 431-437 Link Here
431
            if (!propEl.getLocalName().equals("property")) { // NOI18N
431
            if (!propEl.getLocalName().equals("property")) { // NOI18N
432
                continue;
432
                continue;
433
            }
433
            }
434
            String rawtext = Util.findText(propEl);
434
            String rawtext = XMLUtil.findText(propEl);
435
            if (rawtext == null) {
435
            if (rawtext == null) {
436
                // Legal to have e.g. <property name="intentionally-left-blank"/>
436
                // Legal to have e.g. <property name="intentionally-left-blank"/>
437
                rawtext = ""; // NOI18N
437
                rawtext = ""; // NOI18N
Lines 454-465 Link Here
454
        actions.add(CommonProjectActions.newFileAction());
454
        actions.add(CommonProjectActions.newFileAction());
455
        // Requested actions.
455
        // Requested actions.
456
        Element genldata = p.getPrimaryConfigurationData();
456
        Element genldata = p.getPrimaryConfigurationData();
457
        Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
457
        Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
458
        if (viewEl != null) {
458
        if (viewEl != null) {
459
            Element contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
459
            Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
460
            if (contextMenuEl != null) {
460
            if (contextMenuEl != null) {
461
                actions.add(null);
461
                actions.add(null);
462
                for (Element actionEl : Util.findSubElements(contextMenuEl)) {
462
                for (Element actionEl : XMLUtil.findSubElements(contextMenuEl)) {
463
                    if (actionEl.getLocalName().equals("ide-action")) { // NOI18N
463
                    if (actionEl.getLocalName().equals("ide-action")) { // NOI18N
464
                        String cmd = actionEl.getAttribute("name");
464
                        String cmd = actionEl.getAttribute("name");
465
                        String displayName;
465
                        String displayName;
Lines 517-525 Link Here
517
        
517
        
518
        public boolean isEnabled() {
518
        public boolean isEnabled() {
519
            String script;
519
            String script;
520
            Element scriptEl = Util.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
520
            Element scriptEl = XMLUtil.findElement(actionEl, "script", FreeformProjectType.NS_GENERAL); // NOI18N
521
            if (scriptEl != null) {
521
            if (scriptEl != null) {
522
                script = Util.findText(scriptEl);
522
                script = XMLUtil.findText(scriptEl);
523
            } else {
523
            } else {
524
                script = "build.xml"; // NOI18N
524
                script = "build.xml"; // NOI18N
525
            }
525
            }
Lines 529-536 Link Here
529
        
529
        
530
        public Object getValue(String key) {
530
        public Object getValue(String key) {
531
            if (key.equals(Action.NAME)) {
531
            if (key.equals(Action.NAME)) {
532
                Element labelEl = Util.findElement(actionEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
532
                Element labelEl = XMLUtil.findElement(actionEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
533
                return Util.findText(labelEl);
533
                return XMLUtil.findText(labelEl);
534
            } else {
534
            } else {
535
                return super.getValue(key);
535
                return super.getValue(key);
536
            }
536
            }
(-)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 (-108 / +2 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 74-80 Link Here
74
import org.w3c.dom.NamedNodeMap;
70
import org.w3c.dom.NamedNodeMap;
75
import org.w3c.dom.Node;
71
import org.w3c.dom.Node;
76
import org.w3c.dom.NodeList;
72
import org.w3c.dom.NodeList;
77
import org.w3c.dom.Text;
78
import org.w3c.dom.ls.DOMImplementationLS;
73
import org.w3c.dom.ls.DOMImplementationLS;
79
import org.w3c.dom.ls.LSSerializer;
74
import org.w3c.dom.ls.LSSerializer;
80
import org.xml.sax.SAXException;
75
import org.xml.sax.SAXException;
Lines 88-170 Link Here
88
    private Util() {}
83
    private Util() {}
89
    
84
    
90
    // XXX XML methods copied from ant/project... make a general API of these instead?
85
    // XXX XML methods copied from ant/project... make a general API of these instead?
91
    
86
          
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
    /**
87
    /**
169
     * Finds AuxiliaryConfiguration for the given project helper. The method
88
     * Finds AuxiliaryConfiguration for the given project helper. The method
170
     * finds project associated with the helper and searches 
89
     * finds project associated with the helper and searches 
Lines 240-270 Link Here
240
            return FileUtil.toFile(helper.getProjectDirectory());
159
            return FileUtil.toFile(helper.getProjectDirectory());
241
        }
160
        }
242
    }
161
    }
243
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
    
162
    
269
    /**Get the "default" (user-specified) ant script for the given freeform project.
163
    /**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.
164
     * Please note that this method may return <code>null</code> if there is no such script.
Lines 390-396 Link Here
390
        Element dummy1 = doc.createElementNS(FreeformProjectType.NS_GENERAL_1, FreeformProjectType.NAME_SHARED);
284
        Element dummy1 = doc.createElementNS(FreeformProjectType.NS_GENERAL_1, FreeformProjectType.NAME_SHARED);
391
        // Make sure it is not invalid.
285
        // Make sure it is not invalid.
392
        dummy1.appendChild(doc.createElementNS(FreeformProjectType.NS_GENERAL_1, "name")). // NOI18N
286
        dummy1.appendChild(doc.createElementNS(FreeformProjectType.NS_GENERAL_1, "name")). // NOI18N
393
                appendChild(doc.createTextNode(findText(findElement(data, "name", NAMESPACE)))); // NOI18N
287
                appendChild(doc.createTextNode(XMLUtil.findText(XMLUtil.findElement(data, "name", NAMESPACE)))); // NOI18N
394
        helper.putPrimaryConfigurationData(dummy1, true);
288
        helper.putPrimaryConfigurationData(dummy1, true);
395
        helper.createAuxiliaryConfiguration().putConfigurationFragment(data, true);
289
        helper.createAuxiliaryConfiguration().putConfigurationFragment(data, true);
396
    }
290
    }
(-)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 (-5 / +4 lines)
Lines 43-49 Link Here
43
43
44
import java.util.Arrays;
44
import java.util.Arrays;
45
import java.util.Collections;
45
import java.util.Collections;
46
import java.util.Iterator;
47
import java.util.List;
46
import java.util.List;
48
import java.util.Set;
47
import java.util.Set;
49
import java.util.TreeSet;
48
import java.util.TreeSet;
Lines 51-57 Link Here
51
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
50
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
52
import org.netbeans.modules.ant.freeform.FreeformProjectType;
51
import org.netbeans.modules.ant.freeform.FreeformProjectType;
53
import org.netbeans.modules.ant.freeform.TestBase;
52
import org.netbeans.modules.ant.freeform.TestBase;
54
import org.netbeans.modules.ant.freeform.spi.support.Util;
53
import org.openide.xml.XMLUtil;
55
import org.w3c.dom.Element;
54
import org.w3c.dom.Element;
56
55
57
/**
56
/**
Lines 98-109 Link Here
98
        assertEquals(null, lastMapping.context);
97
        assertEquals(null, lastMapping.context);
99
        // Also check the context menu.
98
        // Also check the context menu.
100
        Element data = prj.getPrimaryConfigurationData();
99
        Element data = prj.getPrimaryConfigurationData();
101
        Element view = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL);
100
        Element view = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL);
102
        assertNotNull(view);
101
        assertNotNull(view);
103
        Element contextMenu = Util.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL);
102
        Element contextMenu = XMLUtil.findElement(view, "context-menu", FreeformProjectType.NS_GENERAL);
104
        assertNotNull(contextMenu);
103
        assertNotNull(contextMenu);
105
        Set<String> actionNames = new TreeSet<String>();
104
        Set<String> actionNames = new TreeSet<String>();
106
        for (Element action : Util.findSubElements(contextMenu)) {
105
        for (Element action : XMLUtil.findSubElements(contextMenu)) {
107
            if (action.getLocalName().equals("ide-action")) {
106
            if (action.getLocalName().equals("ide-action")) {
108
                actionNames.add(action.getAttribute("name"));
107
                actionNames.add(action.getAttribute("name"));
109
            }
108
            }
(-)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);

Return to bug 136595