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 62176
Collapse All | Expand All

(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties (-1 / +4 lines)
Lines 49-55 Link Here
49
LBL_ByExtension=by &Filename Extension
49
LBL_ByExtension=by &Filename Extension
50
LBL_Extension=&Extension(s)\:
50
LBL_Extension=&Extension(s)\:
51
LBL_ByElement=by &XML Root Element
51
LBL_ByElement=by &XML Root Element
52
LBL_Element=&Namespace\:
52
LBL_Namespace=&Namespace\:
53
LBL_ElementName=&Element Name\:
53
54
54
ACS_FileRecognitionPanel=File Recognition Panel
55
ACS_FileRecognitionPanel=File Recognition Panel
55
ACS_CTL_ByElement=Recognize by xml namespace
56
ACS_CTL_ByElement=Recognize by xml namespace
Lines 93-96 Link Here
93
MSG_NoExtension=Please specify at least one file extension.
94
MSG_NoExtension=Please specify at least one file extension.
94
MSG_BadExtensionPattern=Invalid extension pattern. Please enter a list of extensions separated by spaces or commas.
95
MSG_BadExtensionPattern=Invalid extension pattern. Please enter a list of extensions separated by spaces or commas.
95
MSG_BadMimeTypeForXML=Inappropriate MIME type. Must be one of "text/myformat+xml" or "application/myformat+xml".
96
MSG_BadMimeTypeForXML=Inappropriate MIME type. Must be one of "text/myformat+xml" or "application/myformat+xml".
97
MSG_BadElementName=Invalid element name.
96
MSG_EmptyMIMEType=Please specify MIME type
98
MSG_EmptyMIMEType=Please specify MIME type
99
MSG_EmptyElementOrNamespace=Please specify an element name and/or a namespace.
(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/FileRecognitionPanel.form (-4 / +26 lines)
Lines 1-4 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
1
<?xml version="1.1" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
4
  <AuxValues>
Lines 99-117 Link Here
99
          <ComponentRef name="txtNamespace"/>
99
          <ComponentRef name="txtNamespace"/>
100
        </Property>
100
        </Property>
101
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
101
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
102
          <ResourceString bundle="org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties" key="LBL_Element" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
102
          <ResourceString bundle="org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties" key="LBL_Namespace" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
103
        </Property>
103
        </Property>
104
      </Properties>
104
      </Properties>
105
      <Constraints>
105
      <Constraints>
106
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
106
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
107
          <GridBagConstraints gridX="0" gridY="6" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="12" weightX="0.0" weightY="0.0"/>
107
          <GridBagConstraints gridX="0" gridY="7" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="12" weightX="0.0" weightY="0.0"/>
108
        </Constraint>
108
        </Constraint>
109
      </Constraints>
109
      </Constraints>
110
    </Component>
110
    </Component>
111
    <Component class="javax.swing.JTextField" name="txtNamespace">
111
    <Component class="javax.swing.JTextField" name="txtNamespace">
112
      <Constraints>
112
      <Constraints>
113
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
113
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
114
          <GridBagConstraints gridX="2" gridY="6" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.1"/>
114
          <GridBagConstraints gridX="2" gridY="7" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.1"/>
115
        </Constraint>
115
        </Constraint>
116
      </Constraints>
116
      </Constraints>
117
    </Component>
117
    </Component>
Lines 129-133 Link Here
129
        </Constraint>
129
        </Constraint>
130
      </Constraints>
130
      </Constraints>
131
    </Component>
131
    </Component>
132
    <Component class="javax.swing.JLabel" name="lblElementName">
133
      <Properties>
134
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
135
          <ComponentRef name="txtElementName"/>
136
        </Property>
137
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
138
          <ResourceString bundle="org/netbeans/modules/apisupport/project/ui/wizard/loader/Bundle.properties" key="LBL_ElementName" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
139
        </Property>
140
      </Properties>
141
      <Constraints>
142
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
143
          <GridBagConstraints gridX="0" gridY="6" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="20" insetsBottom="0" insetsRight="0" anchor="12" weightX="0.0" weightY="0.0"/>
144
        </Constraint>
145
      </Constraints>
146
    </Component>
147
    <Component class="javax.swing.JTextField" name="txtElementName">
148
      <Constraints>
149
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
150
          <GridBagConstraints gridX="2" gridY="6" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="6" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
151
        </Constraint>
152
      </Constraints>
153
    </Component>
132
  </SubComponents>
154
  </SubComponents>
133
</Form>
155
</Form>
(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/FileRecognitionPanel.java (-12 / +48 lines)
Lines 67-72 Link Here
67
    private static final Pattern EXTENSION_PATTERN = Pattern.compile("([.]?[a-zA-Z0-9_]+){1}([ ,]+[.]?[a-zA-Z0-9_]+)*[ ]*"); // NOI18N
67
    private static final Pattern EXTENSION_PATTERN = Pattern.compile("([.]?[a-zA-Z0-9_]+){1}([ ,]+[.]?[a-zA-Z0-9_]+)*[ ]*"); // NOI18N
68
    private static final Pattern ELEMENT_PATTERN = Pattern.compile("(application/([a-zA-Z0-9_.-])*\\+xml|text/([a-zA-Z0-9_.-])*\\+xml)"); // NOI18N
68
    private static final Pattern ELEMENT_PATTERN = Pattern.compile("(application/([a-zA-Z0-9_.-])*\\+xml|text/([a-zA-Z0-9_.-])*\\+xml)"); // NOI18N
69
    private static final Pattern MIME_TYPE_PATTERN = Pattern.compile("[\\w.]+(?:[+-][\\w.]+)?/[\\w.]+(?:[+-][\\w.]+)*"); // NOI18N
69
    private static final Pattern MIME_TYPE_PATTERN = Pattern.compile("[\\w.]+(?:[+-][\\w.]+)?/[\\w.]+(?:[+-][\\w.]+)*"); // NOI18N
70
    private static final Pattern ROOT_ELEMENT_PATTERN = Pattern.compile("^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02ff\\u0370-\\u037d"
71
                                                                  + "\\u037f-\\u1fff\\u200c-\\u200d\\u2070-\\u218f\\u2c00-\\u2fef\\u3001-\\ud7ff"
72
                                                                  + "\\uf900-\\ufdcf\\ufdf0-\\ufffd]"
73
                                                                  + "[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02ff\\u0370-\\u037d"
74
                                                                  + "\\u037f-\\u1fff\\u200c-\\u200d\\u2070-\\u218f\\u2c00-\\u2fef\\u3001-\\ud7ff"
75
                                                                  + "\\uf900-\\ufdcf\\ufdf0-\\ufffd\\-\\.0-9"
76
                                                                  + "\\u00b7\\u0300-\\u036f\\u203f-\\u2040]*\\Z"); // NOI18N
70
    
77
    
71
    private NewLoaderIterator.DataModel data;
78
    private NewLoaderIterator.DataModel data;
72
    private ButtonGroup group;
79
    private ButtonGroup group;
Lines 88-93 Link Here
88
            public void actionPerformed(ActionEvent event) {
95
            public void actionPerformed(ActionEvent event) {
89
                txtExtension.setEnabled(rbByExtension.isSelected());
96
                txtExtension.setEnabled(rbByExtension.isSelected());
90
                txtNamespace.setEnabled(rbByElement.isSelected());
97
                txtNamespace.setEnabled(rbByElement.isSelected());
98
                txtElementName.setEnabled(rbByElement.isSelected());
91
                checkValidity();
99
                checkValidity();
92
            }
100
            }
93
        };
101
        };
Lines 103-109 Link Here
103
        putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle"));
111
        putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle"));
104
    }
112
    }
105
113
106
    static String checkValidity(AtomicBoolean error, String mimeType, String namespace, String extension, boolean byElement) {
114
    static String checkValidity(AtomicBoolean error, String mimeType, String namespace, String elementName, String extension, boolean byElement) {
107
        if (mimeType.isEmpty()) {
115
        if (mimeType.isEmpty()) {
108
            return getMessage("MSG_EmptyMIMEType");
116
            return getMessage("MSG_EmptyMIMEType");
109
        } else if (!MIME_TYPE_PATTERN.matcher(mimeType).matches()) {
117
        } else if (!MIME_TYPE_PATTERN.matcher(mimeType).matches()) {
Lines 111-123 Link Here
111
            return getMessage("MSG_NotValidMimeType");
119
            return getMessage("MSG_NotValidMimeType");
112
        } else {
120
        } else {
113
            if (byElement) {
121
            if (byElement) {
114
                if (namespace.isEmpty()) {
122
                if(!ELEMENT_PATTERN.matcher(mimeType).matches()) {
115
                    return getMessage("MSG_NoNamespace");
123
                    error.set(true);
116
                } else {
124
                    return getMessage("MSG_BadMimeTypeForXML");
117
                    if (!ELEMENT_PATTERN.matcher(mimeType).matches()) {
125
                } else if (elementName.isEmpty() && namespace.isEmpty()) {
118
                        error.set(true);
126
                    return getMessage("MSG_EmptyElementOrNamespace");
119
                        return getMessage("MSG_BadMimeTypeForXML");
127
                } else if (!elementName.isEmpty() && !ROOT_ELEMENT_PATTERN.matcher(elementName).matches()) {
120
                    }
128
                    error.set(true);
129
                    return getMessage("MSG_BadElementName");
121
                }
130
                }
122
            } else {
131
            } else {
123
                if (extension.isEmpty()) {
132
                if (extension.isEmpty()) {
Lines 136-142 Link Here
136
    private void checkValidity() {
145
    private void checkValidity() {
137
        AtomicBoolean error = new AtomicBoolean();
146
        AtomicBoolean error = new AtomicBoolean();
138
        String msg = checkValidity(error, txtMimeType.getText().trim(), txtNamespace.getText().trim(),
147
        String msg = checkValidity(error, txtMimeType.getText().trim(), txtNamespace.getText().trim(),
139
                txtExtension.getText().trim(), rbByElement.isSelected());
148
                txtElementName.getText().trim(), txtExtension.getText().trim(), rbByElement.isSelected());
140
        if (msg == null) {
149
        if (msg == null) {
141
            markValid();
150
            markValid();
142
        } else if (error.get()) {
151
        } else if (error.get()) {
Lines 161-166 Link Here
161
    private void attachDocumentListeners() {
170
    private void attachDocumentListeners() {
162
        if (!listenersAttached) {
171
        if (!listenersAttached) {
163
            txtNamespace.getDocument().addDocumentListener(docList);
172
            txtNamespace.getDocument().addDocumentListener(docList);
173
            txtElementName.getDocument().addDocumentListener(docList);
164
            txtExtension.getDocument().addDocumentListener(docList);
174
            txtExtension.getDocument().addDocumentListener(docList);
165
            txtMimeType.getDocument().addDocumentListener(docList);
175
            txtMimeType.getDocument().addDocumentListener(docList);
166
            listenersAttached = true;
176
            listenersAttached = true;
Lines 170-175 Link Here
170
    private void removeDocumentListeners() {
180
    private void removeDocumentListeners() {
171
        if (listenersAttached) {
181
        if (listenersAttached) {
172
            txtNamespace.getDocument().removeDocumentListener(docList);
182
            txtNamespace.getDocument().removeDocumentListener(docList);
183
            txtElementName.getDocument().removeDocumentListener(docList);
173
            txtExtension.getDocument().removeDocumentListener(docList);
184
            txtExtension.getDocument().removeDocumentListener(docList);
174
            txtMimeType.getDocument().removeDocumentListener(docList);
185
            txtMimeType.getDocument().removeDocumentListener(docList);
175
            listenersAttached = false;
186
            listenersAttached = false;
Lines 183-191 Link Here
183
        if (data.isExtensionBased()) {
194
        if (data.isExtensionBased()) {
184
            data.setExtension(txtExtension.getText().trim());
195
            data.setExtension(txtExtension.getText().trim());
185
            data.setNamespace(null);
196
            data.setNamespace(null);
197
            data.setElementName(null);
186
        } else {
198
        } else {
187
            data.setExtension(null);
199
            data.setExtension(null);
188
            data.setNamespace(txtNamespace.getText().trim());
200
            data.setNamespace(txtNamespace.getText().trim());
201
            data.setElementName(txtElementName.getText().trim());
189
        }
202
        }
190
    }
203
    }
191
    
204
    
Lines 202-209 Link Here
202
        }
215
        }
203
        txtExtension.setEnabled(rbByExtension.isSelected());
216
        txtExtension.setEnabled(rbByExtension.isSelected());
204
        txtNamespace.setEnabled(rbByElement.isSelected());
217
        txtNamespace.setEnabled(rbByElement.isSelected());
218
        txtElementName.setEnabled(rbByElement.isSelected());
205
        txtExtension.setText(data.getExtension());
219
        txtExtension.setText(data.getExtension());
206
        txtNamespace.setText(data.getNamespace());
220
        txtNamespace.setText(data.getNamespace());
221
        txtElementName.setText(data.getElementName());
207
        
222
        
208
        checkValidity();
223
        checkValidity();
209
    }
224
    }
Lines 238-243 Link Here
238
        lblNamespace = new javax.swing.JLabel();
253
        lblNamespace = new javax.swing.JLabel();
239
        txtNamespace = new javax.swing.JTextField();
254
        txtNamespace = new javax.swing.JTextField();
240
        mimeTypeHint = new javax.swing.JLabel();
255
        mimeTypeHint = new javax.swing.JLabel();
256
        lblElementName = new javax.swing.JLabel();
257
        txtElementName = new javax.swing.JTextField();
241
258
242
        setLayout(new java.awt.GridBagLayout());
259
        setLayout(new java.awt.GridBagLayout());
243
260
Lines 292-308 Link Here
292
        add(rbByElement, gridBagConstraints);
309
        add(rbByElement, gridBagConstraints);
293
310
294
        lblNamespace.setLabelFor(txtNamespace);
311
        lblNamespace.setLabelFor(txtNamespace);
295
        org.openide.awt.Mnemonics.setLocalizedText(lblNamespace, org.openide.util.NbBundle.getMessage(FileRecognitionPanel.class, "LBL_Element")); // NOI18N
312
        org.openide.awt.Mnemonics.setLocalizedText(lblNamespace, org.openide.util.NbBundle.getMessage(FileRecognitionPanel.class, "LBL_Namespace")); // NOI18N
296
        gridBagConstraints = new java.awt.GridBagConstraints();
313
        gridBagConstraints = new java.awt.GridBagConstraints();
297
        gridBagConstraints.gridx = 0;
314
        gridBagConstraints.gridx = 0;
298
        gridBagConstraints.gridy = 6;
315
        gridBagConstraints.gridy = 7;
299
        gridBagConstraints.gridwidth = 2;
316
        gridBagConstraints.gridwidth = 2;
300
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
317
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
301
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
318
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
302
        add(lblNamespace, gridBagConstraints);
319
        add(lblNamespace, gridBagConstraints);
303
        gridBagConstraints = new java.awt.GridBagConstraints();
320
        gridBagConstraints = new java.awt.GridBagConstraints();
304
        gridBagConstraints.gridx = 2;
321
        gridBagConstraints.gridx = 2;
305
        gridBagConstraints.gridy = 6;
322
        gridBagConstraints.gridy = 7;
306
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
323
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
307
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
324
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
308
        gridBagConstraints.weighty = 0.1;
325
        gridBagConstraints.weighty = 0.1;
Lines 319-333 Link Here
319
        add(mimeTypeHint, gridBagConstraints);
336
        add(mimeTypeHint, gridBagConstraints);
320
        mimeTypeHint.getAccessibleContext().setAccessibleName("MIME Type Hint");
337
        mimeTypeHint.getAccessibleContext().setAccessibleName("MIME Type Hint");
321
        mimeTypeHint.getAccessibleContext().setAccessibleDescription("MIME Type Hint");
338
        mimeTypeHint.getAccessibleContext().setAccessibleDescription("MIME Type Hint");
339
340
        lblElementName.setLabelFor(txtElementName);
341
        org.openide.awt.Mnemonics.setLocalizedText(lblElementName, org.openide.util.NbBundle.getMessage(FileRecognitionPanel.class, "LBL_ElementName")); // NOI18N
342
        gridBagConstraints = new java.awt.GridBagConstraints();
343
        gridBagConstraints.gridx = 0;
344
        gridBagConstraints.gridy = 6;
345
        gridBagConstraints.gridwidth = 2;
346
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
347
        gridBagConstraints.insets = new java.awt.Insets(6, 20, 0, 0);
348
        add(lblElementName, gridBagConstraints);
349
        gridBagConstraints = new java.awt.GridBagConstraints();
350
        gridBagConstraints.gridx = 2;
351
        gridBagConstraints.gridy = 6;
352
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
353
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
354
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
355
        add(txtElementName, gridBagConstraints);
322
    }// </editor-fold>//GEN-END:initComponents
356
    }// </editor-fold>//GEN-END:initComponents
323
    
357
    
324
    // Variables declaration - do not modify//GEN-BEGIN:variables
358
    // Variables declaration - do not modify//GEN-BEGIN:variables
359
    private javax.swing.JLabel lblElementName;
325
    private javax.swing.JLabel lblExtension;
360
    private javax.swing.JLabel lblExtension;
326
    private javax.swing.JLabel lblMimeType;
361
    private javax.swing.JLabel lblMimeType;
327
    private javax.swing.JLabel lblNamespace;
362
    private javax.swing.JLabel lblNamespace;
328
    private javax.swing.JLabel mimeTypeHint;
363
    private javax.swing.JLabel mimeTypeHint;
329
    private javax.swing.JRadioButton rbByElement;
364
    private javax.swing.JRadioButton rbByElement;
330
    private javax.swing.JRadioButton rbByExtension;
365
    private javax.swing.JRadioButton rbByExtension;
366
    private javax.swing.JTextField txtElementName;
331
    private javax.swing.JTextField txtExtension;
367
    private javax.swing.JTextField txtExtension;
332
    private javax.swing.JTextField txtMimeType;
368
    private javax.swing.JTextField txtMimeType;
333
    private javax.swing.JTextField txtNamespace;
369
    private javax.swing.JTextField txtNamespace;
(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/NewLoaderIterator.java (-3 / +16 lines)
Lines 122-127 Link Here
122
        private boolean extensionBased = true;
122
        private boolean extensionBased = true;
123
        private String extension;
123
        private String extension;
124
        private String namespace;
124
        private String namespace;
125
        private String elementName;
125
        private boolean useMultiview;
126
        private boolean useMultiview;
126
        
127
        
127
        private CreatedModifiedFiles files;
128
        private CreatedModifiedFiles files;
Lines 209-214 Link Here
209
        public void setNamespace(String namespace) {
210
        public void setNamespace(String namespace) {
210
            this.namespace = namespace;
211
            this.namespace = namespace;
211
        }
212
        }
213
214
        public String getElementName() {
215
            return elementName;
216
        }
217
218
        public void setElementName(String elementName) {
219
            this.elementName = elementName;
220
        }
212
        
221
        
213
    }
222
    }
214
    
223
    
Lines 235-241 Link Here
235
        replaceTokens.put("PACKAGENAME", packageName);//NOI18N
244
        replaceTokens.put("PACKAGENAME", packageName);//NOI18N
236
        replaceTokens.put("MIMETYPE", mime);//NOI18N
245
        replaceTokens.put("MIMETYPE", mime);//NOI18N
237
        replaceTokens.put("EXTENSIONS", formatExtensions(model.isExtensionBased(), model.getExtension(), mime));//NOI18N
246
        replaceTokens.put("EXTENSIONS", formatExtensions(model.isExtensionBased(), model.getExtension(), mime));//NOI18N
238
        replaceTokens.put("NAMESPACES", formatNameSpace(model.isExtensionBased(), model.getNamespace(), mime));//NOI18N
247
        replaceTokens.put("NAMESPACES", formatNameSpace(model.isExtensionBased(), model.getNamespace(), model.getElementName(), mime));//NOI18N
239
        
248
        
240
        // Copy action icon
249
        // Copy action icon
241
        File origIconPath = model.getIconPath();
250
        File origIconPath = model.getIconPath();
Lines 428-433 Link Here
428
            suffix = "Template.xml"; // NOI18N
437
            suffix = "Template.xml"; // NOI18N
429
            try {
438
            try {
430
                replaceTokens.put("NAMESPACE", XMLUtil.toElementContent(model.getNamespace())); // NOI18N
439
                replaceTokens.put("NAMESPACE", XMLUtil.toElementContent(model.getNamespace())); // NOI18N
440
                replaceTokens.put("ELEMENT", model.getElementName().isEmpty()? "root": XMLUtil.toElementContent(model.getElementName())); // NOI18N
431
            } catch (CharConversionException ex) {
441
            } catch (CharConversionException ex) {
432
                assert false: ex;
442
                assert false: ex;
433
            }
443
            }
Lines 489-495 Link Here
489
        return element;
499
        return element;
490
    }
500
    }
491
    
501
    
492
    private static String formatNameSpace(boolean isExtensionBased, String namespace, String mime) {
502
    private static String formatNameSpace(boolean isExtensionBased, String namespace, java.lang.String elementName, String mime) {
493
        if (isExtensionBased) {
503
        if (isExtensionBased) {
494
            return "";
504
            return "";
495
        }
505
        }
Lines 498-504 Link Here
498
        buff.append("        <resolver mime=\"").append(mime).append("\">\n"); //NOI18N
508
        buff.append("        <resolver mime=\"").append(mime).append("\">\n"); //NOI18N
499
        buff.append("            <xml-rule>\n"); // NOI18N
509
        buff.append("            <xml-rule>\n"); // NOI18N
500
        try {
510
        try {
501
            buff.append("                <element ns=\"").append(XMLUtil.toElementContent(namespace)).append("\"/>\n"); //NOI18N
511
            StringBuffer attrStringBuff = new StringBuffer();
512
            if(!elementName.isEmpty()) attrStringBuff.append(" name=\"").append(XMLUtil.toElementContent(elementName)).append("\""); //NOI18N
513
            if(!namespace.isEmpty()) attrStringBuff.append(" ns=\"").append(XMLUtil.toElementContent(namespace)).append("\""); //NOI18N
514
            buff.append("                <element").append(attrStringBuff).append("/>\n"); //NOI18N
502
        } catch (CharConversionException ex) {
515
        } catch (CharConversionException ex) {
503
            assert false : ex;
516
            assert false : ex;
504
        }
517
        }
(-)a/apisupport.wizards/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/templateNew2 (-2 / +2 lines)
Lines 1-2 Link Here
1
<root xmlns="${NAMESPACE}">
1
<${ELEMENT} xmlns="${NAMESPACE}">
2
</root>
2
</${ELEMENT}>
(-)a/apisupport.wizards/test/unit/src/org/netbeans/modules/apisupport/project/ui/wizard/loader/FileRecognitionPanelTest.java (-11 / +19 lines)
Lines 52-71 Link Here
52
    }
52
    }
53
53
54
    public void testCheckValidity() throws Exception {
54
    public void testCheckValidity() throws Exception {
55
        assertValidity(Result.VALID, "text/x-foo", "", "foo", false);
55
        assertValidity(Result.VALID, "text/x-foo", "", "", "foo", false);
56
        assertValidity(Result.INFO, "", "", "foo", false);
56
        assertValidity(Result.INFO, "", "", "", "foo", false);
57
        assertValidity(Result.ERROR, "some-type", "", "foo", false);
57
        assertValidity(Result.ERROR, "some-type", "", "", "foo", false);
58
        assertValidity(Result.INFO, "text/x-foo", "", "", false);
58
        assertValidity(Result.INFO, "text/x-foo", "", "", "", false);
59
        assertValidity(Result.ERROR, "text/x-foo", "", "bad/ext", false);
59
        assertValidity(Result.ERROR, "text/x-foo", "", "", "bad/ext", false);
60
        assertValidity(Result.INFO, "text/x-foo", "", "", true);
60
        assertValidity(Result.ERROR, "text/x-foo", "", "", "", true);
61
        assertValidity(Result.ERROR, "text/docbook", "whatever", "", true);
61
        assertValidity(Result.ERROR, "text/docbook", "whatever", "", "", true);
62
        assertValidity(Result.VALID, "text/docbook+xml", "whatever", "", true);
62
        assertValidity(Result.ERROR, "text/docbook", "", "whatever", "", true);
63
        assertValidity(Result.VALID, "text/x-docbook+xml", "whatever", "", true);
63
        assertValidity(Result.VALID, "text/docbook+xml", "", "whatever", "", true);
64
        assertValidity(Result.VALID, "text/x-docbook+xml", "", "whatever", "", true);
65
        assertValidity(Result.VALID, "text/x-docbook+xml", "whatever", "", "", true);
66
        assertValidity(Result.ERROR, "text/x-docbook+xml", "7whatever", "", "", true);
67
        assertValidity(Result.ERROR, "text/x-docbook+xml", "what ever", "", "", true);
68
        assertValidity(Result.ERROR, "text/x-docbook+xml", "what&ever", "", "", true);
69
        assertValidity(Result.VALID, "text/x-docbook+xml", "äøñ", "", "", true);
70
        assertValidity(Result.VALID, "text/x-docbook+xml", "whatever", "whatever", "", true);
71
        assertValidity(Result.ERROR, "text/x-docbook+xml", "7whatever", "whatever", "", true);
64
    }
72
    }
65
    enum Result {VALID, INFO, ERROR}
73
    enum Result {VALID, INFO, ERROR}
66
    private static void assertValidity(Result expected, String mimeType, String namespace, String extension, boolean byElement) {
74
    private static void assertValidity(Result expected, String mimeType, java.lang.String elementName, String namespace, String extension, boolean byElement) {
67
        AtomicBoolean error = new AtomicBoolean();
75
        AtomicBoolean error = new AtomicBoolean();
68
        String msg = FileRecognitionPanel.checkValidity(error, mimeType, namespace, extension, byElement);
76
        String msg = FileRecognitionPanel.checkValidity(error, mimeType, namespace, elementName, extension, byElement);
69
        assertEquals(msg, expected, msg != null ? (error.get() ? Result.ERROR : Result.INFO) : Result.VALID);
77
        assertEquals(msg, expected, msg != null ? (error.get() ? Result.ERROR : Result.INFO) : Result.VALID);
70
    }
78
    }
71
79

Return to bug 62176