Skip to content

Commit 07088cf

Browse files
[FIX] Serialization: minor fixes
1 parent 5d9c1b8 commit 07088cf

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

basex-core/src/main/java/org/basex/io/serial/BuilderSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected final void text(final byte[] value, final FTPos ftp) throws IOExceptio
3737

3838
@Override
3939
protected final void pi(final byte[] name, final byte[] value) throws IOException {
40-
builder.pi(concat(name, cpToken(' '), value));
40+
builder.pi(value.length > 0 ? concat(name, cpToken(' '), value) : name);
4141
}
4242

4343
@Override

basex-core/src/main/java/org/basex/io/serial/HTMLSerializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected void pi(final byte[] name, final byte[] value) throws IOException {
140140

141141
@Override
142142
protected void print(final int cp) throws IOException {
143-
if(script) out.print(cp);
143+
if(script > 0) out.print(cp);
144144
else if(cp > 0x7F && cp < 0xA0 && !html5) throw SERILL_X.getIO(Integer.toHexString(cp));
145145
else if(cp == 0xA0) out.print(E_NBSP);
146146
else super.print(cp);
@@ -154,14 +154,14 @@ protected void startOpen(final QNm name) throws IOException {
154154
out.print(name.string());
155155
indAttrLength = out.lineLength();
156156
sep = indent;
157-
script = SCRIPTS.contains(lc(name.local()));
158157
if(content && eq(lc(elem.local()), HEAD)) skip++;
159158
}
160159

161160
@Override
162161
protected void finishOpen() throws IOException {
163162
super.finishOpen();
164163
printCT(false, true);
164+
if(SCRIPTS.contains(lc(elem.local()))) script++;
165165
}
166166

167167
@Override
@@ -186,7 +186,7 @@ protected void finishEmpty() throws IOException {
186186
@Override
187187
protected void finishClose() throws IOException {
188188
super.finishClose();
189-
script = script && !SCRIPTS.contains(lc(elem.local()));
189+
if(SCRIPTS.contains(lc(elem.local()))) script--;
190190
}
191191

192192
@Override

basex-core/src/main/java/org/basex/io/serial/MarkupSerializer.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import static org.basex.io.serial.SerializerOptions.*;
55
import static org.basex.query.QueryError.*;
66
import static org.basex.util.Token.*;
7-
import static org.basex.util.Token.normalize;
87

98
import java.io.*;
9+
import java.util.*;
1010

1111
import org.basex.io.out.PrintOutput.*;
1212
import org.basex.query.*;
@@ -39,7 +39,7 @@ abstract class MarkupSerializer extends StandardSerializer {
3939
/** Indicates if root element has been serialized. */
4040
boolean root;
4141
/** Script flag. */
42-
boolean script;
42+
int script;
4343

4444
/** HTML5 flag. */
4545
final boolean html5;
@@ -233,9 +233,7 @@ protected void comment(final byte[] value) throws IOException {
233233
protected void pi(final byte[] name, final byte[] value) throws IOException {
234234
if(sep) indent();
235235
out.print(PI_O);
236-
out.print(name);
237-
out.print(' ');
238-
out.print(value);
236+
out.print(value.length > 0 ? concat(name, cpToken(' '), value) : name);
239237
out.print(PI_C);
240238
sep = true;
241239
}
@@ -378,10 +376,14 @@ protected final boolean printCT(final boolean empty, final boolean html) throws
378376
skip++;
379377
if(empty) finishOpen();
380378
level++;
381-
startOpen(new QNm(META));
382-
attribute(HTTP_EQUIV, CONTENT_TYPE, false);
383-
attribute(CONTENT, concat(media.isEmpty() ? MediaType.TEXT_HTML : media, "; ",
384-
CHARSET, "=", encoding), false);
379+
startOpen(new QNm(elem.hasPrefix() ? concat(elem.prefix(), ":", META) : META));
380+
if(html5) {
381+
attribute(CHARSET, token(encoding), false);
382+
} else {
383+
attribute(HTTP_EQUIV, CONTENT_TYPE, false);
384+
attribute(CONTENT, concat(media.isEmpty() ? MediaType.TEXT_HTML : media, "; ",
385+
CHARSET, "=", encoding), false);
386+
}
385387
out.print(html ? ELEM_C : ELEM_SC);
386388
level--;
387389
if(empty) finishClose();
@@ -442,21 +444,30 @@ boolean inline() {
442444
* @throws QueryIOException query I/O exception
443445
*/
444446
boolean suppressIndentation(final QNm qname) throws QueryIOException {
445-
if(suppress == null) suppress = qnames(SUPPRESS_INDENTATION);
446-
return suppress.contains(qname);
447+
if(suppress == null) {
448+
suppress = new QNmSet();
449+
for(final QNm name : qnames(SUPPRESS_INDENTATION)) {
450+
suppress.add(new QNm(lc(name.string()), name.uri()));
451+
}
452+
}
453+
return !suppress.isEmpty() && suppress.contains(new QNm(lc(qname.string()), qname.uri()));
447454
}
448455

449456
/**
450-
* Returns the values of an option as QNames.
457+
* Returns the value of an option as a list of QNames.
451458
* @param option option to be found
452-
* @return set of QNames
459+
* @return QNames
453460
* @throws QueryIOException query I/O exception
454461
*/
455-
private QNmSet qnames(final StringOption option) throws QueryIOException {
456-
try {
457-
return QNm.set(sopts.get(option), sc);
458-
} catch(final QueryException ex) {
459-
throw new QueryIOException(ex);
462+
private ArrayList<QNm> qnames(final StringOption option) throws QueryIOException {
463+
final ArrayList<QNm> list = new ArrayList<>();
464+
for(final byte[] name : distinctTokens(token(sopts.get(option)))) {
465+
try {
466+
list.add(QNm.parse(name, sc != null ? sc.elemNS : null, sc, null));
467+
} catch(final QueryException ex) {
468+
throw new QueryIOException(ex);
469+
}
460470
}
471+
return list;
461472
}
462473
}

basex-core/src/main/java/org/basex/query/util/DeepEqualOptions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.basex.query.util;
22

3+
import static org.basex.util.Token.*;
4+
35
import java.text.*;
46

57
import org.basex.query.*;
@@ -105,7 +107,12 @@ public String toString() {
105107
* @throws QueryException query exception
106108
*/
107109
public boolean unordered(final QNm qname) throws QueryException {
108-
if(unordered == null) unordered = QNm.set(get(UNORDERED_ELEMENTS), null);
110+
if(unordered == null) {
111+
unordered = new QNmSet();
112+
for(final byte[] name : distinctTokens(token(get(UNORDERED_ELEMENTS)))) {
113+
unordered.add(QNm.parse(name, null, null, null));
114+
}
115+
}
109116
return unordered.contains(qname);
110117
}
111118
}

basex-core/src/main/java/org/basex/query/value/item/QNm.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.basex.query.*;
1414
import org.basex.query.util.*;
1515
import org.basex.query.util.collation.*;
16-
import org.basex.query.util.hash.*;
1716
import org.basex.query.value.type.*;
1817
import org.basex.util.*;
1918
import org.basex.util.list.*;
@@ -318,21 +317,6 @@ public void toString(final QueryString qs) {
318317

319318
// STATIC METHODS ===============================================================================
320319

321-
/**
322-
* Returns the requested value as set of QNames.
323-
* @param value value to be parsed
324-
* @param sc static context (can be {@code null})
325-
* @return set with QNames
326-
* @throws QueryException query exception
327-
*/
328-
public static QNmSet set(final String value, final StaticContext sc) throws QueryException {
329-
final QNmSet set = new QNmSet();
330-
for(final byte[] name : distinctTokens(token(value))) {
331-
if(name.length != 0) set.add(parse(name, sc == null ? null : sc.elemNS, sc, null));
332-
}
333-
return set;
334-
}
335-
336320
/**
337321
* Converts a value to a QName.
338322
* @param value value to parse

0 commit comments

Comments
 (0)