forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve entity parsing, supporting multi-line entity definitions
- Loading branch information
1 parent
6a8edb1
commit 85e8b47
Showing
6 changed files
with
237 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
is.autoload=true | ||
cp.extra=\ | ||
${ant.core.lib} | ||
javac.source=1.6 | ||
javac.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!-- The following DTD is a simple view of a book: | ||
book | ||
index | ||
+ | ||
word | ||
#PCDATA | ||
page | ||
#PCDATA | ||
chapter+ | ||
comment? | ||
#PCDATA | ||
paragraph* | ||
#PCDATA | ||
summary? | ||
#PCDATA | ||
|
||
good | ||
EMPTY | ||
--> | ||
|
||
<!ENTITY % yesno | ||
"(yes, no)" | ||
> | ||
|
||
<!ELEMENT summary (#PCDATA)> | ||
|
||
<!ELEMENT book (summary?, chapter+, index+, available)> | ||
|
||
<!ELEMENT available EMPTY> | ||
|
||
<!ELEMENT index (word, ref+)> | ||
|
||
<!ELEMENT ref (page, line)> | ||
|
||
<!ELEMENT word (#PCDATA)> | ||
|
||
<!ELEMENT line (#PCDATA)> | ||
|
||
<!ELEMENT page (#PCDATA)> | ||
|
||
<!ELEMENT chapter (comment?, paragraph*)> | ||
|
||
<!ELEMENT paragraph (#PCDATA)> | ||
|
||
<!ELEMENT comment (#PCDATA)> | ||
|
||
<!ATTLIST book good %yesno; 'yes'> | ||
<!ATTLIST summary length CDATA #REQUIRED> | ||
<!ATTLIST summary lang CDATA #IMPLIED> | ||
<!ATTLIST summary size CDATA #FIXED '12'> | ||
<!ATTLIST chapter title CDATA #IMPLIED> | ||
<!ATTLIST index color CDATA #IMPLIED> | ||
<!ATTLIST index cross-ref %yesno; "no"> | ||
<!ATTLIST index glossary CDATA #FIXED "nope"> | ||
<!ATTLIST word freq CDATA #IMPLIED> | ||
|
||
|
55 changes: 55 additions & 0 deletions
55
ide/schema2beans/test/unit/data/goldenfiles/tests/SecondaryTest/testEntityParser.pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!-- The following DTD is a simple view of a book: | ||
book | ||
index | ||
+ | ||
word | ||
#PCDATA | ||
page | ||
#PCDATA | ||
chapter+ | ||
comment? | ||
#PCDATA | ||
paragraph* | ||
#PCDATA | ||
summary? | ||
#PCDATA | ||
|
||
good | ||
EMPTY | ||
--> | ||
|
||
|
||
|
||
<!ELEMENT summary (#PCDATA)> | ||
|
||
<!ELEMENT book (summary?, chapter+, index+, available)> | ||
|
||
<!ELEMENT available EMPTY> | ||
|
||
<!ELEMENT index (word, ref+)> | ||
|
||
<!ELEMENT ref (page, line)> | ||
|
||
<!ELEMENT word (#PCDATA)> | ||
|
||
<!ELEMENT line (#PCDATA)> | ||
|
||
<!ELEMENT page (#PCDATA)> | ||
|
||
<!ELEMENT chapter (comment?, paragraph*)> | ||
|
||
<!ELEMENT paragraph (#PCDATA)> | ||
|
||
<!ELEMENT comment (#PCDATA)> | ||
|
||
<!ATTLIST book good (yes, no) 'yes'> | ||
<!ATTLIST summary length CDATA #REQUIRED> | ||
<!ATTLIST summary lang CDATA #IMPLIED> | ||
<!ATTLIST summary size CDATA #FIXED '12'> | ||
<!ATTLIST chapter title CDATA #IMPLIED> | ||
<!ATTLIST index color CDATA #IMPLIED> | ||
<!ATTLIST index cross-ref (yes, no) "no"> | ||
<!ATTLIST index glossary CDATA #FIXED "nope"> | ||
<!ATTLIST word freq CDATA #IMPLIED> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package tests; | ||
|
||
import java.io.*; | ||
import java.lang.reflect.Field; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
import org.netbeans.junit.*; | ||
|
||
import org.netbeans.modules.schema2beansdev.*; | ||
|
||
public class SecondaryTest extends NbTestCase { | ||
|
||
public SecondaryTest(java.lang.String testName) { | ||
super(testName); | ||
} | ||
|
||
public void testEntityParser() throws Exception { | ||
File schemaFile = new File(getDataDir(), "TestEntity.dtd"); | ||
try (InputStream dtdIn = new FileInputStream(schemaFile); | ||
Reader reader = new InputStreamReader(dtdIn, StandardCharsets.ISO_8859_1); | ||
InputStream goldenStream = new FileInputStream(getGoldenFile()); | ||
Reader goldenReader = new InputStreamReader(goldenStream, StandardCharsets.ISO_8859_1)) { | ||
EntityParser ep = new EntityParser(); | ||
|
||
ep.parse(reader); | ||
|
||
Field entityMapField = EntityParser.class.getDeclaredField("entityMap"); | ||
entityMapField.setAccessible(true); | ||
|
||
Map entityMap = (Map) entityMapField.get(ep); | ||
|
||
assertEquals(1, entityMap.size()); | ||
|
||
StringBuilder testOutput = new StringBuilder(); | ||
|
||
try (Reader r = ep.getReader()) { | ||
int read = 0; | ||
char[] buffer = new char[4096]; | ||
while ( (read = r.read(buffer)) >= 0) { | ||
testOutput.append(buffer, 0, read); | ||
} | ||
} | ||
|
||
StringBuilder reference = new StringBuilder(); | ||
{ | ||
int read = 0; | ||
char[] buffer = new char[4096]; | ||
while ( (read = goldenReader.read(buffer)) >= 0) { | ||
reference.append(buffer, 0, read); | ||
} | ||
} | ||
|
||
assertEquals(reference.toString(), testOutput.toString()); | ||
} | ||
} | ||
} |