|
23 | 23 | import org.culturegraph.mf.exceptions.FormatException;
|
24 | 24 | import org.culturegraph.mf.framework.DefaultStreamPipe;
|
25 | 25 |
|
26 |
| -import org.culturegraph.mf.framework.DefaultStreamPipe; |
27 | 26 | import org.culturegraph.mf.framework.ObjectReceiver;
|
28 | 27 | import org.culturegraph.mf.framework.StreamReceiver;
|
29 | 28 | import org.culturegraph.mf.framework.annotations.Description;
|
@@ -55,14 +54,18 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
|
55 | 54 |
|
56 | 55 | private static final String FIELD_DELIMITER = "\u001e";
|
57 | 56 | 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@"; |
63 | 58 | private static final String FIELD_NAME_PATTERN_STRING = "\\d{3}.(/..)?";
|
64 | 59 | 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 | + |
66 | 69 |
|
67 | 70 |
|
68 | 71 | @Override
|
@@ -91,10 +94,13 @@ public void startEntity(final String name) {
|
91 | 94 | if (!fieldNameMatcher.matches()) {
|
92 | 95 | throw new FormatException(name);
|
93 | 96 | }
|
| 97 | + if (entityOpen) { //No nested entities are allowed in pica+. |
| 98 | + throw new FormatException(name); |
| 99 | + } |
94 | 100 | builder.append(name.trim()+ " ");
|
95 | 101 |
|
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. |
98 | 104 | this.entityOpen = true;
|
99 | 105 | }
|
100 | 106 |
|
|
0 commit comments