Skip to content

Make language and refrence marker configurable #657 #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author Markus Michael Geipel
*
*/
@Description("Expands some macros for RDF/XML")
@Description("Expands some macros for RDF/XML. When using Fix, configure `referenceMarker` to any char but the default `*`")
@In(StreamReceiver.class)
@Out(StreamReceiver.class)
@FluxCommand("rdf-macros")
Expand All @@ -41,6 +41,8 @@ public final class RdfMacroPipe extends DefaultStreamPipe<StreamReceiver> {
public static final String RDF_ABOUT = "~rdf:about";
public static final String XML_LANG = "~xml:lang";
private String autoAddedSubject = "";
private char referenceMarker = REFERENCE_MARKER;
private char languageMarker = LANGUAGE_MARKER;

/**
* Creates an instance of {@link RdfMacroPipe}.
Expand All @@ -57,6 +59,42 @@ public void setAutoAddedSubject(final String autoAddedSubject) {
this.autoAddedSubject = autoAddedSubject;
}

/**
* Sets the single char reference marker.
*
* @param referenceMarker the reference marker
*/
public void setReferenceMarker(final String referenceMarker) {
this.referenceMarker = referenceMarker.charAt(0);
}

/**
* Gets the reference marker.
*
* @return the reference marker
*/
public char getReferenceMarker() {
return referenceMarker;
}

/**
* Sets the single char language marker.
*
* @param languageMarker the language marker
*/
public void setLanguageMarker(final String languageMarker) {
this.languageMarker = languageMarker.charAt(0);
}

/**
* Gets the language marker.
*
* @return the language marker
*/
public char getLanguageMarker() {
return languageMarker;
}

@Override
public void startRecord(final String identifier) {
getReceiver().startRecord(identifier);
Expand Down Expand Up @@ -87,8 +125,8 @@ public void endEntity() {

@Override
public void literal(final String name, final String value) {
final int index = name.indexOf(LANGUAGE_MARKER);
if (!name.isEmpty() && name.charAt(0) == REFERENCE_MARKER) {
final int index = name.indexOf(languageMarker);
if (!name.isEmpty() && name.charAt(0) == referenceMarker) {
getReceiver().startEntity(name.substring(1));
getReceiver().literal(RDF_REFERENCE, value);
getReceiver().endEntity();
Expand Down