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; |