Skip to content

Commit 5227f19

Browse files
committed
Deprecated CGEntity format
CGEntity has been replaced by the formeta format
1 parent aa24f65 commit 5227f19

File tree

7 files changed

+167
-418
lines changed

7 files changed

+167
-418
lines changed

src/main/java/org/culturegraph/mf/stream/converter/CGEntityDecoder.java

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,78 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.culturegraph.mf.stream.converter;
17-
18-
import java.util.regex.Pattern;
19-
20-
import org.culturegraph.mf.exceptions.FormatException;
21-
import org.culturegraph.mf.framework.DefaultObjectPipe;
22-
import org.culturegraph.mf.framework.StreamReceiver;
23-
import org.culturegraph.mf.framework.annotations.Description;
24-
import org.culturegraph.mf.framework.annotations.In;
25-
import org.culturegraph.mf.framework.annotations.Out;
26-
import org.culturegraph.mf.types.CGEntity;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
30-
31-
/**
32-
* Reads Strings CGEntity format.
33-
*
34-
* @see CGEntityEncoder
35-
*
36-
* @author Markus Michael Geipel, Christoph Böhme
37-
*
38-
*/
39-
@Description("Reads Strings CGEntity format.")
40-
@In(String.class)
41-
@Out(StreamReceiver.class)
42-
public final class CGEntityDecoder
43-
extends DefaultObjectPipe<String, StreamReceiver> {
44-
45-
private static final Pattern FIELD_PATTERN = Pattern.compile(
46-
String.valueOf(CGEntity.FIELD_DELIMITER), Pattern.LITERAL);
47-
private static final Pattern SUBFIELD_PATTERN = Pattern.compile(
48-
String.valueOf(CGEntity.SUB_DELIMITER), Pattern.LITERAL);
49-
50-
private static final Logger LOG = LoggerFactory
51-
.getLogger(CGEntityDecoder.class);
52-
53-
@Override
54-
public void process(final String record) {
55-
process(record, getReceiver());
56-
}
57-
58-
public static void process(final String record, final StreamReceiver receiver) {
59-
try {
60-
final String[] fields = FIELD_PATTERN.split(record);
61-
receiver.startRecord(fields[0]);
62-
for (int i = 1; i < fields.length; ++i) {
63-
final char firstChar = fields[i].charAt(0);
64-
if (firstChar == CGEntity.LITERAL_MARKER) {
65-
final String[] parts = SUBFIELD_PATTERN
66-
.split(fields[i], -1);
67-
receiver.literal(
68-
parts[0].substring(1),
69-
parts[1].replace(CGEntity.NEWLINE_ESC,
70-
CGEntity.NEWLINE));
71-
} else if (firstChar == CGEntity.ENTITY_START_MARKER) {
72-
receiver.startEntity(fields[i].substring(1));
73-
} else if (firstChar == CGEntity.ENTITY_END_MARKER) {
74-
receiver.endEntity();
75-
} else if (firstChar == CGEntity.NEWLINE) {
76-
LOG.debug("unexpected newline");
77-
} else {
78-
throw new FormatException(record);
79-
}
80-
}
81-
receiver.endRecord();
82-
} catch (IndexOutOfBoundsException exception) {
83-
throw new FormatException(record, exception);
84-
}
85-
}
86-
16+
package org.culturegraph.mf.stream.converter;
17+
18+
import java.util.regex.Pattern;
19+
20+
import org.culturegraph.mf.exceptions.FormatException;
21+
import org.culturegraph.mf.framework.DefaultObjectPipe;
22+
import org.culturegraph.mf.framework.StreamReceiver;
23+
import org.culturegraph.mf.framework.annotations.Description;
24+
import org.culturegraph.mf.framework.annotations.In;
25+
import org.culturegraph.mf.framework.annotations.Out;
26+
import org.culturegraph.mf.types.CGEntity;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
31+
/**
32+
* Reads Strings CGEntity format.
33+
*
34+
* @see CGEntityEncoder
35+
*
36+
* @author Markus Michael Geipel, Christoph Böhme
37+
*
38+
* @deprecated Use FormetaDecoder instead
39+
*
40+
*/
41+
@Description("Reads Strings CGEntity format.")
42+
@In(String.class)
43+
@Out(StreamReceiver.class)
44+
@Deprecated
45+
public final class CGEntityDecoder
46+
extends DefaultObjectPipe<String, StreamReceiver> {
47+
48+
private static final Pattern FIELD_PATTERN = Pattern.compile(
49+
String.valueOf(CGEntity.FIELD_DELIMITER), Pattern.LITERAL);
50+
private static final Pattern SUBFIELD_PATTERN = Pattern.compile(
51+
String.valueOf(CGEntity.SUB_DELIMITER), Pattern.LITERAL);
52+
53+
private static final Logger LOG = LoggerFactory
54+
.getLogger(CGEntityDecoder.class);
55+
56+
@Override
57+
public void process(final String record) {
58+
process(record, getReceiver());
59+
}
60+
61+
public static void process(final String record, final StreamReceiver receiver) {
62+
try {
63+
final String[] fields = FIELD_PATTERN.split(record);
64+
receiver.startRecord(fields[0]);
65+
for (int i = 1; i < fields.length; ++i) {
66+
final char firstChar = fields[i].charAt(0);
67+
if (firstChar == CGEntity.LITERAL_MARKER) {
68+
final String[] parts = SUBFIELD_PATTERN
69+
.split(fields[i], -1);
70+
receiver.literal(
71+
parts[0].substring(1),
72+
parts[1].replace(CGEntity.NEWLINE_ESC,
73+
CGEntity.NEWLINE));
74+
} else if (firstChar == CGEntity.ENTITY_START_MARKER) {
75+
receiver.startEntity(fields[i].substring(1));
76+
} else if (firstChar == CGEntity.ENTITY_END_MARKER) {
77+
receiver.endEntity();
78+
} else if (firstChar == CGEntity.NEWLINE) {
79+
LOG.debug("unexpected newline");
80+
} else {
81+
throw new FormatException(record);
82+
}
83+
}
84+
receiver.endRecord();
85+
} catch (IndexOutOfBoundsException exception) {
86+
throw new FormatException(record, exception);
87+
}
88+
}
89+
8790
}

src/main/java/org/culturegraph/mf/stream/converter/CGEntityEncoder.java

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,75 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.culturegraph.mf.stream.converter;
17-
18-
import org.culturegraph.mf.framework.DefaultStreamPipe;
19-
import org.culturegraph.mf.framework.ObjectReceiver;
20-
import org.culturegraph.mf.framework.StreamReceiver;
21-
import org.culturegraph.mf.framework.annotations.Description;
22-
import org.culturegraph.mf.framework.annotations.In;
23-
import org.culturegraph.mf.framework.annotations.Out;
24-
import org.culturegraph.mf.types.CGEntity;
25-
26-
/**
27-
* Encodes an event stream in CGEntity format.
28-
*
29-
* @see CGEntityDecoder
30-
*
31-
* @author Markus Michael Geipel, Christoph Böhme
32-
*
33-
*/
34-
35-
@Description("Encodes a stream in CGE Format")
36-
@In(StreamReceiver.class)
37-
@Out(String.class)
38-
public final class CGEntityEncoder
39-
extends DefaultStreamPipe<ObjectReceiver<String>> {
40-
41-
private StringBuilder builder = new StringBuilder();
42-
43-
@Override
44-
public void startRecord(final String identifier) {
45-
builder = new StringBuilder();
46-
builder.append(identifier);
47-
builder.append(CGEntity.FIELD_DELIMITER);
48-
}
49-
50-
@Override
51-
public void endRecord() {
52-
getReceiver().process(builder.toString());
53-
}
54-
55-
@Override
56-
public void startEntity(final String name) {
57-
builder.append(CGEntity.ENTITY_START_MARKER);
58-
builder.append(name);
59-
builder.append(CGEntity.FIELD_DELIMITER);
60-
}
61-
62-
@Override
63-
public void endEntity() {
64-
builder.append(CGEntity.ENTITY_END_MARKER);
65-
builder.append(CGEntity.FIELD_DELIMITER);
66-
}
67-
68-
@Override
69-
public void literal(final String name, final String value) {
70-
builder.append(CGEntity.LITERAL_MARKER);
71-
builder.append(name);
72-
builder.append(CGEntity.SUB_DELIMITER);
73-
builder.append(value.replace(CGEntity.NEWLINE, CGEntity.NEWLINE_ESC));
74-
builder.append(CGEntity.FIELD_DELIMITER);
75-
}
76-
77-
@Override
78-
protected void onResetStream() {
79-
builder = new StringBuilder();
80-
}
81-
82-
public String getCurrentSerialization(){
83-
return builder.toString();
84-
}
85-
16+
package org.culturegraph.mf.stream.converter;
17+
18+
import org.culturegraph.mf.framework.DefaultStreamPipe;
19+
import org.culturegraph.mf.framework.ObjectReceiver;
20+
import org.culturegraph.mf.framework.StreamReceiver;
21+
import org.culturegraph.mf.framework.annotations.Description;
22+
import org.culturegraph.mf.framework.annotations.In;
23+
import org.culturegraph.mf.framework.annotations.Out;
24+
import org.culturegraph.mf.types.CGEntity;
25+
26+
/**
27+
* Encodes an event stream in CGEntity format.
28+
*
29+
* @see CGEntityDecoder
30+
*
31+
* @author Markus Michael Geipel, Christoph Böhme
32+
*
33+
* @deprecated Use FormetaEncoder instead
34+
*/
35+
@Description("Encodes a stream in CGE Format")
36+
@In(StreamReceiver.class)
37+
@Out(String.class)
38+
@Deprecated
39+
public final class CGEntityEncoder
40+
extends DefaultStreamPipe<ObjectReceiver<String>> {
41+
42+
private StringBuilder builder = new StringBuilder();
43+
44+
@Override
45+
public void startRecord(final String identifier) {
46+
builder = new StringBuilder();
47+
builder.append(identifier);
48+
builder.append(CGEntity.FIELD_DELIMITER);
49+
}
50+
51+
@Override
52+
public void endRecord() {
53+
getReceiver().process(builder.toString());
54+
}
55+
56+
@Override
57+
public void startEntity(final String name) {
58+
builder.append(CGEntity.ENTITY_START_MARKER);
59+
builder.append(name);
60+
builder.append(CGEntity.FIELD_DELIMITER);
61+
}
62+
63+
@Override
64+
public void endEntity() {
65+
builder.append(CGEntity.ENTITY_END_MARKER);
66+
builder.append(CGEntity.FIELD_DELIMITER);
67+
}
68+
69+
@Override
70+
public void literal(final String name, final String value) {
71+
builder.append(CGEntity.LITERAL_MARKER);
72+
builder.append(name);
73+
builder.append(CGEntity.SUB_DELIMITER);
74+
builder.append(value.replace(CGEntity.NEWLINE, CGEntity.NEWLINE_ESC));
75+
builder.append(CGEntity.FIELD_DELIMITER);
76+
}
77+
78+
@Override
79+
protected void onResetStream() {
80+
builder = new StringBuilder();
81+
}
82+
83+
public String getCurrentSerialization(){
84+
return builder.toString();
85+
}
86+
8687
}

src/main/java/org/culturegraph/mf/stream/pipe/StreamSerializer.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)