Skip to content

Commit 89412d1

Browse files
Enable multiview for XJB (JAXB customization files)
Closes: #9008
1 parent b5d2a9b commit 89412d1

4 files changed

Lines changed: 71 additions & 39 deletions

File tree

java/xml.jaxb/nbproject/project.xml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
<specification-version>1.40</specification-version>
6262
</run-dependency>
6363
</dependency>
64+
<dependency>
65+
<code-name-base>org.netbeans.core.multiview</code-name-base>
66+
<build-prerequisite/>
67+
<compile-dependency/>
68+
<run-dependency>
69+
<release-version>1</release-version>
70+
<specification-version>1.75</specification-version>
71+
</run-dependency>
72+
</dependency>
6473
<dependency>
6574
<code-name-base>org.netbeans.libs.javacapi</code-name-base>
6675
<build-prerequisite/>
@@ -231,36 +240,41 @@
231240
</run-dependency>
232241
</dependency>
233242
<dependency>
234-
<code-name-base>org.openide.util.ui</code-name-base>
243+
<code-name-base>org.openide.util</code-name-base>
235244
<build-prerequisite/>
236245
<compile-dependency/>
237246
<run-dependency>
238247
<specification-version>9.3</specification-version>
239248
</run-dependency>
240249
</dependency>
241250
<dependency>
242-
<code-name-base>org.openide.util</code-name-base>
251+
<code-name-base>org.openide.util.lookup</code-name-base>
252+
<build-prerequisite/>
253+
<compile-dependency/>
254+
<run-dependency>
255+
<specification-version>8.0</specification-version>
256+
</run-dependency>
257+
</dependency>
258+
<dependency>
259+
<code-name-base>org.openide.util.ui</code-name-base>
243260
<build-prerequisite/>
244261
<compile-dependency/>
245262
<run-dependency>
246263
<specification-version>9.3</specification-version>
247264
</run-dependency>
248265
</dependency>
249266
<dependency>
250-
<code-name-base>org.openide.util.lookup</code-name-base>
267+
<code-name-base>org.openide.windows</code-name-base>
251268
<build-prerequisite/>
252269
<compile-dependency/>
253270
<run-dependency>
254-
<specification-version>8.0</specification-version>
271+
<specification-version>6.108</specification-version>
255272
</run-dependency>
256273
</dependency>
257274
</module-dependencies>
258275
<test-dependencies>
259276
<test-type>
260277
<name>unit</name>
261-
<test-dependency>
262-
<code-name-base>org.netbeans.api.progress</code-name-base>
263-
</test-dependency>
264278
<test-dependency>
265279
<code-name-base>org.netbeans.bootstrap</code-name-base>
266280
</test-dependency>

java/xml.jaxb/src/org/netbeans/modules/xml/jaxb/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Templates/XML=XML
3535
Templates/XML/JavaXMLBinding=JAXB Binding
3636
JAXBResolver=JAXB Binding
3737
JAXB-ENDORSED=JAXB-ENDORSED
38+
CTL_SourceTabCaption=&Source

java/xml.jaxb/src/org/netbeans/modules/xml/jaxb/JAXBWizard.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
package org.netbeans.modules.xml.jaxb;
2121

22+
import org.netbeans.core.spi.multiview.MultiViewElement;
23+
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
2224
import org.openide.filesystems.MIMEResolver;
25+
import org.openide.util.Lookup;
26+
import org.openide.windows.TopComponent;
2327

2428
/**
2529
* A place holder class
@@ -33,6 +37,18 @@
3337
)
3438
public class JAXBWizard {
3539

40+
@MultiViewElement.Registration(
41+
displayName="org.netbeans.modules.xml.jaxb.Bundle#CTL_SourceTabCaption",
42+
iconBase="org/netbeans/modules/xml/jaxb/resources/XML_file.png",
43+
persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED,
44+
preferredID="xml.text",
45+
mimeType="text/x-jaxb-binding+xml",
46+
position=1
47+
)
48+
public static MultiViewEditorElement createMultiViewEditor(Lookup context) {
49+
return new MultiViewEditorElement(context);
50+
}
51+
3652
/** Creates a new instance of JAXBWizard */
3753
public JAXBWizard() {
3854
}

java/xml.jaxb/test/unit/src/org/netbeans/modules/xml/jaxb/util/XSLTest.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,78 +47,79 @@
4747
*/
4848
public class XSLTest extends NbTestCase {
4949
private static final String CONFIG_FILE1 = "ConfigFile1.xml"; //NOI18N
50-
private static final String CONFIG_FILE2 = "ConfigFile2.xml"; //NOI18N
51-
private static final String CONFIG_FILE3 = "ConfigFile3.xml"; //NOI18N
52-
private static final String CONFIG_EMPTY_CAT = "ConfigFileEmptyCatalog.xml"; //NOI18N
50+
private static final String CONFIG_FILE2 = "ConfigFile2.xml"; //NOI18N
51+
private static final String CONFIG_FILE3 = "ConfigFile3.xml"; //NOI18N
52+
private static final String CONFIG_EMPTY_CAT = "ConfigFileEmptyCatalog.xml"; //NOI18N
5353
private static final String BUILD_FILE1 = "BuildFile1.xml"; //NOI18N
54-
private static final String BUILD_FILE2 = "BuildFile2.xml"; //NOI18N
55-
private static final String BUILD_FILE3 = "BuildFile3.xml"; //NOI18N
56-
private static final String BUILD_EMPTY_CAT = "BuildFileEmptyCatalog.xml"; //NOI18N
57-
58-
private static final String XSL_FILE =
54+
private static final String BUILD_FILE2 = "BuildFile2.xml"; //NOI18N
55+
private static final String BUILD_FILE3 = "BuildFile3.xml"; //NOI18N
56+
private static final String BUILD_EMPTY_CAT = "BuildFileEmptyCatalog.xml"; //NOI18N
57+
58+
private static final String XSL_FILE =
5959
"/org/netbeans/modules/xml/jaxb/resources/JAXBBuild.xsl"; //NOI18N
6060
private static final String TEMP_BUILD_FILE = "jaxb_build" ; //NOI18N
61-
61+
6262
public XSLTest(String testName) {
6363
super(testName);
6464
}
65-
65+
66+
@Override
6667
public void setUp() throws Exception {
6768
}
68-
69+
70+
@Override
6971
public void tearDown() throws Exception {
7072
}
71-
73+
7274
private InputStream getFromClasspath(String filePath){
7375
return this.getClass().getResourceAsStream(filePath);
7476
}
75-
77+
7678
private InputStream getDatafile(String filename) throws FileNotFoundException{
7779
String dataFilename = "/org/netbeans/modules/xml/jaxb/util/" + filename;
7880
return new FileInputStream(new File(getDataDir(), dataFilename));
7981
}
80-
82+
8183
private String getString(InputStream stream) throws IOException{
8284
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
83-
StringBuffer sb = new StringBuffer();
85+
StringBuilder sb = new StringBuilder();
8486
String line = "";
8587
while (line != null){
8688
line = br.readLine();
8789
if (line != null){
8890
sb.append(line);
8991
}
9092
}
91-
93+
9294
return sb.toString();
9395
}
94-
96+
9597
private void compareStream(InputStream file1, InputStream file2) throws IOException{
96-
boolean ret = false;
9798
String str1 = getString(file1);
9899
//System.out.println("Str1:" + str1 + ":Str1");
99100
String str2 = getString(file2);
100-
//System.out.println("Str2:" + str2 + ":Str2");
101-
//System.out.println("Length:" + str1.length() + ":" + str2.length());
101+
//System.out.println("Str2:" + str2 + ":Str2");
102+
//System.out.println("Length:" + str1.length() + ":" + str2.length());
102103
assertEquals(str1, str2);
103104
}
104-
105+
105106
private void transformConfig2Build(String configFile, String buildFile){
106107
try {
107108
Source xmlSource = new StreamSource(getDatafile(configFile));
108109
Source xslSource = new StreamSource(getFromClasspath(XSL_FILE));
109110
File tmpFile = java.io.File.createTempFile(TEMP_BUILD_FILE, ".xml");
110111
//System.out.println("tmpFile:" + tmpFile.getAbsolutePath());
111112
tmpFile.deleteOnExit();
112-
FileOutputStream fos = new FileOutputStream(tmpFile);
113-
Result result = new StreamResult(fos);
114-
TransformerFactory fact = TransformerFactory.newInstance();
115-
fact.setAttribute("indent-number", 4); //NOI18N
116-
Transformer xformer = fact.newTransformer(xslSource);
117-
xformer.setOutputProperty(OutputKeys.INDENT, "yes"); //NOI18N
118-
xformer.setOutputProperty(OutputKeys.METHOD, "xml"); //NOI18N
119-
xformer.transform(xmlSource, result);
113+
try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
114+
Result result = new StreamResult(fos);
115+
TransformerFactory fact = TransformerFactory.newInstance();
116+
fact.setAttribute("indent-number", 4); //NOI18N
117+
Transformer xformer = fact.newTransformer(xslSource);
118+
xformer.setOutputProperty(OutputKeys.INDENT, "yes"); //NOI18N
119+
xformer.setOutputProperty(OutputKeys.METHOD, "xml"); //NOI18N
120+
xformer.transform(xmlSource, result);
121+
}
120122
// Compare.
121-
fos.close();
122123
compareStream(getDatafile(buildFile), new FileInputStream(tmpFile));
123124
} catch (TransformerConfigurationException ex) {
124125
Logger.getLogger("global").log(Level.SEVERE, null, ex);
@@ -131,7 +132,7 @@ private void transformConfig2Build(String configFile, String buildFile){
131132
fail("IOException");
132133
}
133134
}
134-
135+
135136
/**
136137
* Test the XSL style sheet.
137138
**/
@@ -163,5 +164,5 @@ public void testXformConfig2BuildEmptyCatalog(){
163164
transformConfig2Build(CONFIG_EMPTY_CAT, BUILD_EMPTY_CAT);
164165
System.out.println("testXformConfig2BuildEmptyCatalog done.");
165166
}
166-
167+
167168
}

0 commit comments

Comments
 (0)