Skip to content

Commit bb498f1

Browse files
committed
Updated for release 2.3.0
1 parent 56f773a commit bb498f1

17 files changed

+344
-242
lines changed

i18n/XMLJava_es.tmx

Lines changed: 119 additions & 111 deletions
Large diffs are not rendered by default.

i18n/XMLJava_es.xlf

Lines changed: 100 additions & 89 deletions
Large diffs are not rendered by default.

lib/xmljava.jar

1.29 KB
Binary file not shown.

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sonar.projectKey=XMLJava
33
# this is the name displayed in the SonarQube UI
44
sonar.projectName=XMLJava
5-
sonar.projectVersion=2.0.0
5+
sonar.projectVersion=2.3.0
66

77
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
88
# Since SonarQube 4.2, this property is optional if sonar.modules is set.

src/com/maxprograms/xml/AttlistDecl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.io.OutputStream;
1616
import java.nio.charset.Charset;
17+
import java.text.MessageFormat;
1718
import java.util.List;
1819
import java.util.Vector;
1920

@@ -24,24 +25,24 @@ public class AttlistDecl implements XMLNode {
2425

2526
public AttlistDecl(String declaration) {
2627
attributes = new Vector<>();
27-
int i = "<!ATTLIST".length();
2828
declaration = declaration.trim();
29+
int i = "<!ATTLIST".length();
2930
char c = declaration.charAt(i);
3031
while (XMLUtils.isXmlSpace(c)) {
3132
i++;
3233
c = declaration.charAt(i);
3334
}
3435
StringBuilder sb = new StringBuilder();
35-
while (!XMLUtils.isXmlSpace(c)) {
36+
while (!XMLUtils.isXmlSpace(c) && c != '>') {
3637
sb.append(c);
3738
i++;
3839
c = declaration.charAt(i);
3940
}
4041
listName = sb.toString();
41-
parseAttributes(declaration.substring(i, declaration.lastIndexOf(">")).trim());
42+
parseAttributes(declaration.substring(i, declaration.lastIndexOf('>')).trim());
4243
}
4344

44-
private void parseAttributes(String declaration) {
45+
private void parseAttributes(String declaration) throws IllegalArgumentException {
4546
int i = 0;
4647
while (i < declaration.length()) {
4748
char c = declaration.charAt(i);
@@ -164,7 +165,8 @@ private void parseAttributes(String declaration) {
164165
i++;
165166
}
166167
} else {
167-
throw new IllegalArgumentException("Expected quoted default value after #FIXED.");
168+
MessageFormat mf = new MessageFormat(Messages.getString("AttlistDecl.0"));
169+
throw new IllegalArgumentException(mf.format(new String[] {declaration}));
168170
}
169171
attributes.add(new AttributeDecl(name, type, defaultValueBuilder.toString(), true));
170172
} else {

src/com/maxprograms/xml/Catalog.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
352352
return null;
353353
}
354354

355-
private InputSource resolveHttp(URI uri) throws MalformedURLException, IOException {
355+
private InputSource resolveHttp(URI uri) throws IOException {
356356
MessageFormat mf = new MessageFormat(Messages.getString("Catalog.3"));
357357
logger.log(Level.WARNING, mf.format(new String[] { uri.toURL().toString() }));
358358
URL url = uri.toURL();
@@ -457,28 +457,21 @@ public void currentDocumentBase(String parentFile) {
457457
}
458458

459459
public String getDTD(String name) {
460-
if (name != null) {
461-
return dtdCatalog.get(name);
462-
}
463-
return null;
460+
return name != null ? dtdCatalog.get(name) : null;
464461
}
465462

466463
public void addDtdPublicEntity(String publicId, String path) {
467464
if (dtdPublicEntities == null) {
468465
dtdPublicEntities = new Hashtable<>();
469466
}
470-
if (!dtdPublicEntities.containsKey(publicId)) {
471-
dtdPublicEntities.put(publicId, path);
472-
}
467+
dtdPublicEntities.computeIfAbsent(publicId, k -> path);
473468
}
474469

475470
public void addDtdSystemEntity(String systemId, String path) {
476471
if (dtdSystemEntities == null) {
477472
dtdSystemEntities = new Hashtable<>();
478473
}
479-
if (!dtdSystemEntities.containsKey(systemId)) {
480-
dtdSystemEntities.put(systemId, path);
481-
}
474+
dtdSystemEntities.computeIfAbsent(systemId, k -> path);
482475
}
483476

484477
public void parseDTD(String publicId) {

src/com/maxprograms/xml/CatalogBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
public class CatalogBuilder {
2525

26-
private static Map<String,Catalog> map = new Hashtable<>();
26+
private static Map<String, Catalog> map = new Hashtable<>();
2727

2828
private CatalogBuilder() {
2929
// Do not instantiate
3030
}
3131

32-
public static Catalog getCatalog(String file) throws SAXException, IOException, ParserConfigurationException, URISyntaxException{
32+
public static Catalog getCatalog(String file)
33+
throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
3334
if (!map.containsKey(file)) {
3435
map.put(file, new Catalog(file));
3536
}

src/com/maxprograms/xml/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
public class Constants {
1616

17-
public static final String VERSION = "2.2.0";
18-
public static final String BUILD = "20250523_1301";
17+
public static final String VERSION = "2.3.0";
18+
public static final String BUILD = "20250525_0726";
1919

2020
private Constants() {
2121
// private for security

src/com/maxprograms/xml/ContentModel.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
*******************************************************************************/
1212
package com.maxprograms.xml;
1313

14-
import java.io.Serializable;
1514
import java.text.MessageFormat;
1615
import java.util.List;
16+
import java.util.Set;
1717
import java.util.Stack;
1818
import java.util.StringTokenizer;
19+
import java.util.TreeSet;
1920
import java.util.Vector;
2021

21-
public class ContentModel implements Serializable {
22+
public class ContentModel {
2223

2324
public static final String EMPTY = "EMPTY";
2425
public static final String ANY = "ANY";
@@ -78,7 +79,6 @@ public static ContentModel parse(String modelString) {
7879

7980
while (st.hasMoreTokens()) {
8081
String token = st.nextToken().trim();
81-
validateToken(token);
8282

8383
if (token.equals("(")) {
8484
stack.push(current);
@@ -125,16 +125,15 @@ private static ContentParticle processGroup(List<Object> group) {
125125
}
126126
if (group.size() == 1) {
127127
Object obj = group.get(0);
128-
if (obj instanceof ContentParticle) {
129-
return (ContentParticle) obj;
130-
} else if (obj instanceof String) {
131-
return new DTDName((String) obj);
128+
if (obj instanceof ContentParticle particle) {
129+
return particle;
130+
} else if (obj instanceof String name) {
131+
return new DTDName(name);
132132
}
133133
}
134134
String sep = null;
135135
for (Object obj : group) {
136-
if (obj instanceof String) {
137-
String token = (String) obj;
136+
if (obj instanceof String token) {
138137
if ("|".equals(token) || ",".equals(token)) {
139138
sep = token;
140139
break;
@@ -149,10 +148,10 @@ private static ContentParticle processGroup(List<Object> group) {
149148
if ("|".equals(obj) || ",".equals(obj)) {
150149
continue;
151150
}
152-
if (obj instanceof ContentParticle) {
153-
result.addParticle((ContentParticle) obj);
154-
} else if (obj instanceof String) {
155-
result.addParticle(new DTDName((String) obj));
151+
if (obj instanceof ContentParticle particle) {
152+
result.addParticle(particle);
153+
} else if (obj instanceof String name) {
154+
result.addParticle(new DTDName(name));
156155
}
157156
}
158157
return result;
@@ -176,13 +175,6 @@ else if (c == ')')
176175
}
177176
}
178177

179-
private static void validateToken(String token) {
180-
if (!token.matches("[a-zA-Z0-9#|,?*+()]+")) {
181-
MessageFormat mf = new MessageFormat(Messages.getString("ContentModel.6"));
182-
throw new IllegalArgumentException(mf.format(new String[] { token }));
183-
}
184-
}
185-
186178
@Override
187179
public String toString() {
188180
StringBuilder sb = new StringBuilder();
@@ -204,4 +196,23 @@ public List<ContentParticle> getContent() {
204196
public String getType() {
205197
return type;
206198
}
199+
200+
public Set<String> getChildren() {
201+
if (type.equals(EMPTY)) {
202+
return new TreeSet<>();
203+
}
204+
Set<String> children = new TreeSet<>();
205+
for (ContentParticle particle : content) {
206+
if (particle instanceof DTDName name) {
207+
children.add(name.getName());
208+
}
209+
if (particle instanceof DTDChoice choice) {
210+
children.addAll(choice.getChildren());
211+
}
212+
if (particle instanceof DTDSecuence sequence) {
213+
children.addAll(sequence.getChildren());
214+
}
215+
}
216+
return children;
217+
}
207218
}

src/com/maxprograms/xml/DTDChoice.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
package com.maxprograms.xml;
1313

1414
import java.util.List;
15+
import java.util.Set;
16+
import java.util.TreeSet;
1517
import java.util.Vector;
1618

1719
public class DTDChoice implements ContentParticle {
@@ -72,4 +74,20 @@ public String toString() {
7274
public List<ContentParticle> getParticles() {
7375
return content;
7476
}
77+
78+
public Set<String> getChildren() {
79+
Set<String> children = new TreeSet<>();
80+
for (ContentParticle particle : content) {
81+
if (particle instanceof DTDName name) {
82+
children.add(name.getName());
83+
}
84+
if (particle instanceof DTDChoice choice) {
85+
children.addAll(choice.getChildren());
86+
}
87+
if (particle instanceof DTDSecuence sequence) {
88+
children.addAll(sequence.getChildren());
89+
}
90+
}
91+
return children;
92+
}
7593
}

0 commit comments

Comments
 (0)