Skip to content

Commit 0fc0346

Browse files
committed
metafacture-xml/ (main): Fix Checkstyle violations.
1 parent dfbeb84 commit 0fc0346

13 files changed

+269
-181
lines changed

metafacture-xml/src/main/java/org/metafacture/xml/CGXmlHandler.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.xml;
1718

1819
import org.metafacture.framework.FluxCommand;
@@ -23,6 +24,7 @@
2324
import org.metafacture.framework.annotations.In;
2425
import org.metafacture.framework.annotations.Out;
2526
import org.metafacture.framework.helpers.DefaultXmlPipe;
27+
2628
import org.xml.sax.Attributes;
2729

2830
/**
@@ -60,8 +62,7 @@
6062
@FluxCommand("handle-cg-xml")
6163
public final class CGXmlHandler extends DefaultXmlPipe<StreamReceiver> {
6264

63-
public static final String CGXML_NAMESPACE =
64-
"http://www.culturegraph.org/cgxml";
65+
public static final String CGXML_NAMESPACE = "http://www.culturegraph.org/cgxml";
6566

6667
private static final String ROOT_TAG = "cgxml";
6768
private static final String RECORDS_TAG = "records";
@@ -76,6 +77,9 @@ public final class CGXmlHandler extends DefaultXmlPipe<StreamReceiver> {
7677

7778
private static final String VERSION = "1.0";
7879

80+
public CGXmlHandler() {
81+
}
82+
7983
@Override
8084
public void startElement(final String uri, final String localName,
8185
final String qName, final Attributes attributes) {
@@ -114,7 +118,8 @@ private void emitStartRecord(final Attributes attributes) {
114118
final String recordId = attributes.getValue("", ID_ATTR);
115119
if (recordId == null) {
116120
getReceiver().startRecord("");
117-
} else {
121+
}
122+
else {
118123
getReceiver().startRecord(recordId);
119124
}
120125
}
@@ -144,7 +149,8 @@ public void endElement(final String uri, final String localName,
144149
}
145150
if (RECORD_TAG.equals(localName)) {
146151
getReceiver().endRecord();
147-
} else if (ENTITY_TAG.equals(localName)) {
152+
}
153+
else if (ENTITY_TAG.equals(localName)) {
148154
getReceiver().endEntity();
149155
}
150156
}

metafacture-xml/src/main/java/org/metafacture/xml/FilenameExtractor.java

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.xml;
1718

1819
import java.io.File;
@@ -25,34 +26,6 @@
2526
*/
2627
public interface FilenameExtractor extends RecordIdentifier {
2728

28-
/**
29-
* Provides functions and fields that all {@link FilenameExtractor}
30-
* implementing classes may found useful.
31-
*
32-
* @author Pascal Christoph (dr0i)
33-
*
34-
*/
35-
class FilenameUtil {
36-
public String target = "tmp";
37-
public String encoding = "UTF-8";
38-
public String property = null;
39-
public String fileSuffix = null;
40-
public int startIndex = 0;
41-
public int endIndex = 0;
42-
public String filename = "test";
43-
44-
/**
45-
* Ensures that path exists. If not, make it.
46-
*
47-
* @param path
48-
* the path of the to be stored file.
49-
*/
50-
public void ensurePathExists(final File path) {
51-
final File parent = path.getAbsoluteFile().getParentFile();
52-
parent.mkdirs();
53-
}
54-
}
55-
5629
/**
5730
* Returns the encoding used to open the resource.
5831
*
@@ -66,7 +39,7 @@ public void ensurePathExists(final File path) {
6639
* @param encoding
6740
* new encoding
6841
*/
69-
void setEncoding(final String encoding);
42+
void setEncoding(String encoding);
7043

7144
/**
7245
* Sets the end of the index in the filename to extract the name of the
@@ -75,15 +48,15 @@ public void ensurePathExists(final File path) {
7548
* @param endIndex
7649
* This marks the index' end.
7750
*/
78-
void setEndIndex(final int endIndex);
51+
void setEndIndex(int endIndex);
7952

8053
/**
8154
* Sets the file's suffix.
8255
*
8356
* @param fileSuffix
8457
* the suffix used for the to be generated files
8558
*/
86-
void setFileSuffix(final String fileSuffix);
59+
void setFileSuffix(String fileSuffix);
8760

8861
/**
8962
* Sets the beginning of the index in the filename to extract the name of
@@ -92,14 +65,103 @@ public void ensurePathExists(final File path) {
9265
* @param startIndex
9366
* This marks the index' beginning.
9467
*/
95-
void setStartIndex(final int startIndex);
68+
void setStartIndex(int startIndex);
9669

9770
/**
9871
* Sets the target path.
9972
*
10073
* @param target
10174
* the basis directory in which the files are stored
10275
*/
103-
void setTarget(final String target);
76+
void setTarget(String target);
77+
78+
/**
79+
* Provides functions and fields that all {@link FilenameExtractor}
80+
* implementing classes may found useful.
81+
*
82+
* @author Pascal Christoph (dr0i)
83+
*
84+
*/
85+
class FilenameUtil {
86+
87+
private String encoding = "UTF-8";
88+
private String fileSuffix;
89+
private String filename = "test";
90+
private String property;
91+
private String target = "tmp";
92+
private int endIndex;
93+
private int startIndex;
94+
95+
FilenameUtil() {
96+
}
97+
98+
/**
99+
* Ensures that path exists. If not, make it.
100+
*
101+
* @param path
102+
* the path of the to be stored file.
103+
*/
104+
public void ensurePathExists(final File path) {
105+
final File parent = path.getAbsoluteFile().getParentFile();
106+
parent.mkdirs();
107+
}
108+
109+
public void setEncoding(final String encoding) {
110+
this.encoding = encoding;
111+
}
112+
113+
public String getEncoding() {
114+
return encoding;
115+
}
116+
117+
public void setFileSuffix(final String fileSuffix) {
118+
this.fileSuffix = fileSuffix;
119+
}
120+
121+
public String getFileSuffix() {
122+
return fileSuffix;
123+
}
124+
125+
public void setFilename(final String filename) {
126+
this.filename = filename;
127+
}
128+
129+
public String getFilename() {
130+
return filename;
131+
}
132+
133+
public void setProperty(final String property) {
134+
this.property = property;
135+
}
136+
137+
public String getProperty() {
138+
return property;
139+
}
140+
141+
public void setTarget(final String target) {
142+
this.target = target;
143+
}
144+
145+
public String getTarget() {
146+
return target;
147+
}
148+
149+
public void setEndIndex(final int endIndex) {
150+
this.endIndex = endIndex;
151+
}
152+
153+
public int getEndIndex() {
154+
return endIndex;
155+
}
156+
157+
public void setStartIndex(final int startIndex) {
158+
this.startIndex = startIndex;
159+
}
160+
161+
public int getStartIndex() {
162+
return startIndex;
163+
}
164+
165+
}
104166

105167
}

metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.xml;
1716

18-
import java.util.regex.Pattern;
17+
package org.metafacture.xml;
1918

2019
import org.metafacture.framework.FluxCommand;
2120
import org.metafacture.framework.StreamReceiver;
@@ -24,8 +23,10 @@
2423
import org.metafacture.framework.annotations.In;
2524
import org.metafacture.framework.annotations.Out;
2625
import org.metafacture.framework.helpers.DefaultXmlPipe;
26+
2727
import org.xml.sax.Attributes;
2828

29+
import java.util.regex.Pattern;
2930

3031
/**
3132
* A generic xml reader.
@@ -41,22 +42,21 @@ public final class GenericXmlHandler extends DefaultXmlPipe<StreamReceiver> {
4142

4243
public static final String DEFAULT_RECORD_TAG = "record";
4344

45+
public static final boolean EMIT_NAMESPACE = false;
46+
4447
private static final Pattern TABS = Pattern.compile("\t+");
4548

4649
private String recordTagName = DEFAULT_RECORD_TAG;
4750

4851
private boolean inRecord;
4952
private StringBuilder valueBuffer = new StringBuilder();
5053

51-
public static final boolean EMIT_NAMESPACE = false;
5254
private boolean emitNamespace = EMIT_NAMESPACE;
5355

5456
public GenericXmlHandler() {
55-
super();
56-
final String recordTagNameProperty = System.getProperty(
57-
"org.culturegraph.metamorph.xml.recordtag");
57+
final String recordTagNameProperty = System.getProperty("org.culturegraph.metamorph.xml.recordtag");
5858
if (recordTagNameProperty != null) {
59-
recordTagName = recordTagNameProperty;
59+
recordTagName = recordTagNameProperty;
6060
}
6161
}
6262

@@ -71,7 +71,6 @@ public GenericXmlHandler() {
7171
*/
7272
@Deprecated
7373
public GenericXmlHandler(final String recordTagName) {
74-
super();
7574
this.recordTagName = recordTagName;
7675
}
7776

@@ -85,7 +84,7 @@ public GenericXmlHandler(final String recordTagName) {
8584
*
8685
* @param recordTagName the tag name which marks the start of a record.
8786
*/
88-
public void setRecordTagName(String recordTagName) {
87+
public void setRecordTagName(final String recordTagName) {
8988
this.recordTagName = recordTagName;
9089
}
9190

@@ -103,7 +102,7 @@ public String getRecordTagName() {
103102
* @param emitNamespace set to "true" if namespace should be emitted. Defaults
104103
* to "false".
105104
*/
106-
public void setEmitNamespace(boolean emitNamespace) {
105+
public void setEmitNamespace(final boolean emitNamespace) {
107106
this.emitNamespace = emitNamespace;
108107
}
109108

@@ -112,22 +111,23 @@ public boolean getEmitNamespace() {
112111
}
113112

114113
@Override
115-
public void startElement(final String uri, final String localName,
116-
final String qName, final Attributes attributes) {
117-
114+
public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) {
118115
if (inRecord) {
119116
writeValue();
120117
if (emitNamespace) {
121118
getReceiver().startEntity(qName);
122-
} else {
119+
}
120+
else {
123121
getReceiver().startEntity(localName);
124122
}
125123
writeAttributes(attributes);
126-
} else if (localName.equals(recordTagName)) {
124+
}
125+
else if (localName.equals(recordTagName)) {
127126
final String identifier = attributes.getValue("id");
128127
if (identifier == null) {
129128
getReceiver().startRecord("");
130-
} else {
129+
}
130+
else {
131131
getReceiver().startRecord(identifier);
132132
}
133133
writeAttributes(attributes);
@@ -136,14 +136,14 @@ public void startElement(final String uri, final String localName,
136136
}
137137

138138
@Override
139-
public void endElement(final String uri, final String localName,
140-
final String qName) {
139+
public void endElement(final String uri, final String localName, final String qName) {
141140
if (inRecord) {
142141
writeValue();
143142
if (localName.equals(recordTagName)) {
144143
inRecord = false;
145144
getReceiver().endRecord();
146-
} else {
145+
}
146+
else {
147147
getReceiver().endEntity();
148148
}
149149
}
@@ -152,8 +152,7 @@ public void endElement(final String uri, final String localName,
152152
@Override
153153
public void characters(final char[] chars, final int start, final int length) {
154154
if (inRecord) {
155-
valueBuffer.append(TABS.matcher(new String(chars, start, length))
156-
.replaceAll(""));
155+
valueBuffer.append(TABS.matcher(new String(chars, start, length)).replaceAll(""));
157156
}
158157
}
159158

@@ -169,11 +168,7 @@ private void writeAttributes(final Attributes attributes) {
169168
final int length = attributes.getLength();
170169

171170
for (int i = 0; i < length; ++i) {
172-
String name;
173-
if (emitNamespace) {
174-
name = attributes.getQName(i);
175-
} else
176-
name = attributes.getLocalName(i);
171+
final String name = emitNamespace ? attributes.getQName(i) : attributes.getLocalName(i);
177172
final String value = attributes.getValue(i);
178173
getReceiver().literal(name, value);
179174
}

metafacture-xml/src/main/java/org/metafacture/xml/RecordIdentifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.xml;
1718

1819
/**
@@ -32,6 +33,6 @@ public interface RecordIdentifier {
3233
* @param property
3334
* the property which will be used to extract a record name.
3435
*/
35-
public void setProperty(final String property);
36+
void setProperty(String property);
3637

3738
}

0 commit comments

Comments
 (0)