@@ -56,7 +56,6 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
56
56
private static final String FIELD_DELIMITER = "\u001e " ;
57
57
private static final String SUB_DELIMITER = "\u001f " ;
58
58
private boolean idnControlSubField ;
59
- private boolean recordOpen ;
60
59
private boolean entityOpen ;
61
60
private StringBuilder builder = new StringBuilder ();
62
61
private String id ="" ;
@@ -65,25 +64,14 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
65
64
private static final Pattern FIELD_NAME_PATTERN = Pattern .compile (FIELD_NAME_PATTERN_STRING );
66
65
private boolean ignoreRecordId ;
67
66
68
- /**
69
- * For each field in the stream the method calls:
70
- * <ol>
71
- * <li>receiver.startEntity</li>
72
- * <li>receiver.literal for each subfield of the field</li>
73
- * <li>receiver.endEntity</li>
74
- * </ol>
75
- * Fields without any subfield will be skipped.<br>
76
- *
77
- * @param record
78
- */
67
+
79
68
@ Override
80
69
public void startRecord (final String recordId ) {
81
70
// the name is a idn, which should be found in the encoded data under 003@.
82
71
//any rest of the previous record is cleared before the new begins.
83
72
builder .setLength (0 );
84
73
this .id = recordId ;
85
74
//Now an entity can be opened. But no literal is allowed.
86
- this .recordOpen = true ;
87
75
this .entityOpen = false ;
88
76
}
89
77
@@ -95,50 +83,37 @@ public boolean getIgnoreRecordId() {
95
83
return this .ignoreRecordId ;
96
84
}
97
85
98
- protected void compareIdFromRecord (final String recordId ) {
99
- if (this .id .equals (recordId )) {
100
- idnControlSubField = false ; //only test this context.
101
- return ;
102
- }
103
- throw new MissingIdException (recordId );
104
- }
105
-
106
-
107
86
@ Override
108
87
public void startEntity (final String name ) {
109
88
// Here begins a field (i.e. "028A ", which is given in the name.
110
89
// It is unknown, whether there are any subfields in the field.
111
90
final Matcher fieldNameMatcher = FIELD_NAME_PATTERN .matcher (name );
112
- if (fieldNameMatcher .find ()) {
113
- builder .append (name .trim ()+ " " );
114
- }
115
- else {
91
+ if (!fieldNameMatcher .matches ()) {
116
92
throw new FormatException (name );
117
93
}
118
- if (name .trim ().equals ("003@" ) && !getIgnoreRecordId ()) {
119
- //Time to check record Id in the following subfield.
120
- idnControlSubField = true ;
121
- }else {
122
- //No check is necessary.
123
- idnControlSubField = false ;
124
- }
125
- //Now literals can be opened. But no entities are allowed.
126
- if (recordOpen )
127
- this .entityOpen = true ;
94
+ builder .append (name .trim ()+ " " );
95
+
96
+ idnControlSubField = !ignoreRecordId && name .trim ().equals ("003@" );
97
+ //Now literals can be opened.
98
+ this .entityOpen = true ;
128
99
}
129
100
130
101
@ Override
131
102
public void literal (final String name , final String value ) {
132
103
//A Subfield has one character or digit exactly.
133
104
if (name .length ()!=1 ){
134
105
throw new FormatException (name );
135
- } else if (!entityOpen ){
136
- throw new FormatException (name ); //new exceptions define!!!! tODo
106
+ }
107
+ if (!entityOpen ){
108
+ throw new FormatException (name ); //new exceptions definition for literal out of entity
137
109
}
138
110
final String valueNew = Normalizer .normalize (value , Form .NFD );
139
111
if (idnControlSubField ){
140
112
// it is a 003@ field, the same record id delivered with record should follow
141
- compareIdFromRecord (value );
113
+ if (!this .id .equals (value )) {
114
+ throw new MissingIdException (value );
115
+ }
116
+ idnControlSubField = false ; //only one record Id will be checked.
142
117
}
143
118
builder .append (SUB_DELIMITER );
144
119
builder .append (name );
@@ -155,9 +130,7 @@ public void endEntity() {
155
130
@ Override
156
131
public void endRecord () {
157
132
getReceiver ().process (builder .toString ());
158
- builder .setLength (0 );
159
- //Now a record can be opened. But no literal and entity are allowed.
160
- this .recordOpen = false ;
133
+ //No literal is allowed.
161
134
this .entityOpen = false ;
162
135
}
163
136
@ Override
0 commit comments