Skip to content

Commit 8895a23

Browse files
lili
authored andcommitted
Nested entities will be checked now.
The javadoc about the S (control) subfield is still there, but the newest core does not support its processing.
1 parent 3445e5e commit 8895a23

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/main/java/org/culturegraph/mf/stream/converter/bib/PicaEncoder.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.culturegraph.mf.exceptions.FormatException;
2424
import org.culturegraph.mf.framework.DefaultStreamPipe;
2525

26-
import org.culturegraph.mf.framework.DefaultStreamPipe;
2726
import org.culturegraph.mf.framework.ObjectReceiver;
2827
import org.culturegraph.mf.framework.StreamReceiver;
2928
import org.culturegraph.mf.framework.annotations.Description;
@@ -55,14 +54,18 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
5554

5655
private static final String FIELD_DELIMITER = "\u001e";
5756
private static final String SUB_DELIMITER = "\u001f";
58-
private boolean idnControlSubField;
59-
private boolean entityOpen;
60-
private StringBuilder builder = new StringBuilder();
61-
private String id="";
62-
57+
private static final String FIELD_IDN_INTERN = "003@";
6358
private static final String FIELD_NAME_PATTERN_STRING = "\\d{3}.(/..)?";
6459
private static final Pattern FIELD_NAME_PATTERN = Pattern.compile(FIELD_NAME_PATTERN_STRING);
65-
private boolean ignoreRecordId;
60+
61+
private static StringBuilder builder = new StringBuilder(); //Result of the encoding process
62+
63+
private boolean entityOpen; //Flag to inform whether an entity is opened.
64+
private boolean idnControlSubField; //Flag to inform whether it is the 003@ field.
65+
private boolean ignoreRecordId; //Flag to decide whether the record Id is checked.
66+
67+
private String id;
68+
6669

6770

6871
@Override
@@ -91,10 +94,13 @@ public void startEntity(final String name) {
9194
if (!fieldNameMatcher.matches()) {
9295
throw new FormatException(name);
9396
}
97+
if (entityOpen) { //No nested entities are allowed in pica+.
98+
throw new FormatException(name);
99+
}
94100
builder.append(name.trim()+ " ");
95101

96-
idnControlSubField = !ignoreRecordId && name.trim().equals("003@");
97-
//Now literals can be opened.
102+
idnControlSubField = !ignoreRecordId && FIELD_IDN_INTERN.equals(name.trim());
103+
//Now literals can be opened but no more entities.
98104
this.entityOpen = true;
99105
}
100106

0 commit comments

Comments
 (0)