Skip to content

Commit e92b823

Browse files
author
mgeipel
committed
added stream module to remove record boundaries.
1 parent 42bb838 commit e92b823

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2013 Deutsche Nationalbibliothek
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.culturegraph.mf.stream.pipe;
17+
18+
import org.culturegraph.mf.framework.DefaultStreamPipe;
19+
import org.culturegraph.mf.framework.StreamReceiver;
20+
import org.culturegraph.mf.framework.annotations.Description;
21+
import org.culturegraph.mf.framework.annotations.In;
22+
import org.culturegraph.mf.framework.annotations.Out;
23+
import org.culturegraph.mf.util.StreamConstants;
24+
25+
26+
/**
27+
* Removes record boundaries
28+
*
29+
* @author Markus Michael Geipel
30+
*
31+
*/
32+
@Description("Removes record boundaries")
33+
@In(StreamReceiver.class)
34+
@Out(StreamReceiver.class)
35+
public final class RecordBounderyRemover
36+
extends DefaultStreamPipe<StreamReceiver> {
37+
38+
private final String entityName;
39+
40+
public RecordBounderyRemover(final String entityName) {
41+
super();
42+
this.entityName = entityName;
43+
}
44+
45+
public RecordBounderyRemover(){
46+
super();
47+
this.entityName = null;
48+
49+
}
50+
51+
@Override
52+
public void startRecord(final String identifier) {
53+
assert !isClosed();
54+
55+
if (null != entityName) {
56+
getReceiver().startEntity(entityName);
57+
getReceiver().literal(StreamConstants.ID, identifier);
58+
}
59+
}
60+
61+
@Override
62+
public void endRecord() {
63+
assert !isClosed();
64+
65+
if (null != entityName) {
66+
getReceiver().endEntity();
67+
}
68+
}
69+
70+
@Override
71+
public void startEntity(final String name) {
72+
assert !isClosed();
73+
getReceiver().startEntity(name);
74+
}
75+
76+
@Override
77+
public void endEntity() {
78+
assert !isClosed();
79+
getReceiver().endEntity();
80+
}
81+
82+
@Override
83+
public void literal(final String name, final String value) {
84+
assert !isClosed();
85+
getReceiver().literal(name, value);
86+
}
87+
}

0 commit comments

Comments
 (0)