Skip to content

Commit ec50c14

Browse files
committed
Milestone 1.0.0
Features: - disable hyper-link in generator; - reorder by sheet column name; - custom HyperSchema for both read/write;
1 parent c4f0a99 commit ec50c14

File tree

25 files changed

+656
-126
lines changed

25 files changed

+656
-126
lines changed

README.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,25 @@ The project is forked from [scndry/jackson-dataformat-spreadsheet](https://githu
77
### Maven
88
```xml
99
<project>
10-
<repositories>
11-
<repository>
12-
<id>sonatype-snapshots</id>
13-
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
14-
<snapshots>
15-
<enabled>true</enabled>
16-
</snapshots>
17-
</repository>
18-
</repositories>
19-
2010
<dependency>
2111
<groupId>io.github.honhimw</groupId>
2212
<artifactId>jackson-dataformat-excel-hyperlink</artifactId>
23-
<version>0.0.3-SNAPSHOT</version>
13+
<version>1.0.0</version>
2414
</dependency>
2515
</project>
2616
```
2717

2818
### Gradle
2919
```groovy
3020
// Groovy
31-
repositories {
32-
maven {
33-
name 'sonatype-snapshots'
34-
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
35-
}
36-
}
37-
3821
dependencies {
39-
implementation 'io.github.honhimw:jackson-dataformat-excel-hyperlink:0.0.3-SNAPSHOT'
22+
implementation 'io.github.honhimw:jackson-dataformat-excel-hyperlink:1.0.0'
4023
}
4124
```
4225
```kotlin
4326
// Kotlin
44-
repositories {
45-
maven {
46-
name = "sonatype-snapshots"
47-
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
48-
}
49-
}
50-
5127
dependencies {
52-
implementation("io.github.honhimw:jackson-dataformat-excel-hyperlink:0.0.3-SNAPSHOT")
28+
implementation("io.github.honhimw:jackson-dataformat-excel-hyperlink:1.0.0")
5329
}
5430
```
5531

@@ -94,6 +70,22 @@ The commonly used (.xlsx) format document for office suite spreadsheets, which c
9470

9571
---
9672

73+
## Feature
74+
75+
### io.github.honhimw.jackson.dataformat.hyper.deser.BookParser.Feature
76+
77+
| Features | Default | Description |
78+
|------------------------|---------|------------------------------------------------|
79+
| BLANK_ROW_AS_NULL | true | Blank row read as an null object in collection |
80+
| BREAK_ON_BLANK_ROW | false | Blank row as symbol for ending |
81+
| REORDER_BY_COLUMN_NAME | false | Reorder schema by sheet title column |
82+
83+
### io.github.honhimw.jackson.dataformat.hyper.HyperGenerator.Feature
84+
85+
| Features | Default | Description |
86+
|------------|---------|------------------------------------------------------------------------------------------------------------------------|
87+
| HYPERLINKE | true | Using hyperlinks to describe object relationships<br/>**Note.** Number of hyperlinks is usually limited to 65536.<br/> |
88+
9789
## Usage
9890

9991
```java

build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ plugins {
2020
}
2121

2222
group = "io.github.honhimw"
23-
version = "0.0.3-SNAPSHOT"
23+
version = "1.0.0"
2424
description = "Support for reading and writing Excel-Hyperlink via Jackson abstractions."
2525

2626
val title = "Jackson dataformat: HyperLink"
27-
val jacksonVersion = "2.14.2"
27+
val jacksonVersion = "2.16.2"
2828
val poiVersion = "5.2.3"
2929
val snapshots = version.toString().endsWith("SNAPSHOT")
3030

@@ -35,7 +35,7 @@ repositories {
3535
dependencies {
3636
api("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
3737
api("org.apache.poi:poi-ooxml:$poiVersion")
38-
implementation("org.slf4j:slf4j-api:2.0.6")
38+
implementation("org.slf4j:slf4j-api:2.0.12")
3939
}
4040

4141
dependencies {
@@ -97,10 +97,10 @@ publishing {
9797
repositories {
9898
maven {
9999
name = "sonatype"
100-
if (snapshots) {
101-
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
100+
url = if (snapshots) {
101+
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
102102
} else {
103-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
103+
uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
104104
}
105105
credentials {
106106
username = findProperty("SONATYPE_USERNAME") as String

example/multiSheet.xlsx

11 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
distributionBase=GRADLE_USER_HOME
1616
distributionPath=wrapper/dists
17-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
17+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
1818
zipStoreBase=GRADLE_USER_HOME
1919
zipStorePath=wrapper/dists

src/main/java/io/github/honhimw/jackson/dataformat/hyper/HyperFactory.java

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
package io.github.honhimw.jackson.dataformat.hyper;
1616

17-
import com.fasterxml.jackson.core.FormatSchema;
18-
import com.fasterxml.jackson.core.JsonEncoding;
19-
import com.fasterxml.jackson.core.JsonFactory;
20-
import com.fasterxml.jackson.core.StreamReadFeature;
21-
import com.fasterxml.jackson.core.Version;
17+
import com.fasterxml.jackson.core.*;
2218
import com.fasterxml.jackson.core.io.IOContext;
2319
import io.github.honhimw.jackson.dataformat.hyper.deser.BookInput;
2420
import io.github.honhimw.jackson.dataformat.hyper.deser.BookParser;
@@ -31,39 +27,41 @@
3127
import io.github.honhimw.jackson.dataformat.hyper.schema.HyperSchema;
3228
import io.github.honhimw.jackson.dataformat.hyper.ser.BookOutput;
3329
import io.github.honhimw.jackson.dataformat.hyper.ser.BookWriter;
30+
import org.apache.poi.openxml4j.opc.PackagePart;
31+
import org.apache.poi.ss.usermodel.Workbook;
32+
import org.apache.poi.ss.usermodel.WorkbookFactory;
33+
import org.apache.poi.util.TempFile;
34+
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
35+
3436
import java.io.File;
3537
import java.io.IOException;
3638
import java.io.InputStream;
3739
import java.io.OutputStream;
3840
import java.nio.file.Files;
3941
import java.nio.file.StandardCopyOption;
40-
import org.apache.poi.openxml4j.opc.PackagePart;
41-
import org.apache.poi.ss.usermodel.Workbook;
42-
import org.apache.poi.ss.usermodel.WorkbookFactory;
43-
import org.apache.poi.util.TempFile;
44-
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
4542

4643
@SuppressWarnings("java:S2177")
4744
public final class HyperFactory extends JsonFactory {
4845

4946
public static final String FORMAT_NAME = "hyper";
50-
public static final int DEFAULT_SHEET_PARSER_FEATURE_FLAGS = BookParser.Feature.collectDefaults();
47+
public static final int DEFAULT_BOOK_PARSER_FEATURE_FLAGS = BookParser.Feature.collectDefaults();
48+
public static final int DEFAULT_BOOK_GENERATOR_FEATURE_FLAGS = HyperGenerator.Feature.collectDefaults();
5149

5250
private final transient WorkbookProvider _workbookProvider;
53-
private int _sheetParserFeatures;
51+
private int _bookParserFeatures = DEFAULT_BOOK_PARSER_FEATURE_FLAGS;
52+
private int _bookGeneratorFeatures = DEFAULT_BOOK_GENERATOR_FEATURE_FLAGS;
5453

5554
public HyperFactory() {
56-
this(SXSSFWorkbook::new, DEFAULT_SHEET_PARSER_FEATURE_FLAGS);
55+
this(SXSSFWorkbook::new);
5756
}
5857

59-
public HyperFactory(final WorkbookProvider workbookProvider, final int sheetParserFeatures) {
60-
_workbookProvider = workbookProvider;
61-
_sheetParserFeatures = sheetParserFeatures;
58+
public HyperFactory(final WorkbookProvider workbookProvider) {
59+
this._workbookProvider = workbookProvider;
6260
}
6361

6462
public HyperFactory(final HyperFactory base) {
6563
_workbookProvider = base._workbookProvider;
66-
_sheetParserFeatures = base._sheetParserFeatures;
64+
_bookParserFeatures = base._bookParserFeatures;
6765
}
6866

6967
@Override
@@ -101,7 +99,7 @@ public Version version() {
10199

102100
/*
103101
/**********************************************************
104-
/* Configuration, sheet parser configuration
102+
/* Configuration, book parser configuration
105103
/**********************************************************
106104
*/
107105

@@ -110,12 +108,32 @@ public HyperFactory configure(final BookParser.Feature f, final boolean state) {
110108
}
111109

112110
public HyperFactory enable(final BookParser.Feature f) {
113-
_sheetParserFeatures |= f.getMask();
111+
_bookParserFeatures |= f.getMask();
114112
return this;
115113
}
116114

117115
public HyperFactory disable(final BookParser.Feature f) {
118-
_sheetParserFeatures &= ~f.getMask();
116+
_bookParserFeatures &= ~f.getMask();
117+
return this;
118+
}
119+
120+
/*
121+
/**********************************************************
122+
/* Configuration, book generator configuration
123+
/**********************************************************
124+
*/
125+
126+
public HyperFactory configure(final HyperGenerator.Feature f, final boolean state) {
127+
return state ? enable(f) : disable(f);
128+
}
129+
130+
public HyperFactory enable(final HyperGenerator.Feature f) {
131+
_bookGeneratorFeatures |= f.getMask();
132+
return this;
133+
}
134+
135+
public HyperFactory disable(final HyperGenerator.Feature f) {
136+
_bookGeneratorFeatures &= ~f.getMask();
119137
return this;
120138
}
121139

@@ -179,7 +197,7 @@ public HyperGenerator createGenerator(final OutputStream out) throws IOException
179197
*/
180198

181199
private BookParser _createParser(final BookReader reader, final IOContext ctxt) {
182-
return new BookParser(ctxt, _parserFeatures, _objectCodec, _sheetParserFeatures, reader);
200+
return new BookParser(ctxt, _parserFeatures, _objectCodec, _bookParserFeatures, reader);
183201
}
184202

185203
private BookReader _createFileSheetReader(final File src) throws IOException {
@@ -227,7 +245,7 @@ private BookInput<?> _preferRawAsFile(final BookInput<?> src) throws IOException
227245
*/
228246

229247
private HyperGenerator _createGenerator(final BookWriter writer, final IOContext ctxt) {
230-
return new HyperGenerator(ctxt, _generatorFeatures, _objectCodec, writer);
248+
return new HyperGenerator(ctxt, _generatorFeatures, _objectCodec, writer, _bookGeneratorFeatures);
231249
}
232250

233251
@SuppressWarnings("resource")

src/main/java/io/github/honhimw/jackson/dataformat/hyper/HyperGenerator.java

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
package io.github.honhimw.jackson.dataformat.hyper;
1616

17-
import com.fasterxml.jackson.core.Base64Variant;
18-
import com.fasterxml.jackson.core.FormatSchema;
19-
import com.fasterxml.jackson.core.ObjectCodec;
20-
import com.fasterxml.jackson.core.StreamWriteFeature;
21-
import com.fasterxml.jackson.core.Version;
17+
import com.fasterxml.jackson.core.*;
2218
import com.fasterxml.jackson.core.base.GeneratorBase;
2319
import com.fasterxml.jackson.core.io.IOContext;
2420
import io.github.honhimw.jackson.dataformat.hyper.exception.BookStreamWriteException;
@@ -48,11 +44,13 @@ public final class HyperGenerator extends GeneratorBase {
4844
private final BookWriter _writer;
4945
private HyperSchema _schema;
5046
private BookStreamContext _outputContext;
47+
private final int _formatFeatures;
5148

52-
public HyperGenerator(final IOContext ctxt, final int features, final ObjectCodec codec, final BookWriter writer) {
53-
super(features, codec);
49+
public HyperGenerator(final IOContext ctxt, final int features, final ObjectCodec codec, final BookWriter writer, final int formatFeatures) {
50+
super(features, codec, ctxt);
5451
_ioContext = ctxt;
5552
_writer = writer;
53+
this._formatFeatures = formatFeatures;
5654
}
5755

5856
@Override
@@ -84,6 +82,13 @@ public void setSchema(final FormatSchema schema) {
8482
_writer.setSchema(_schema);
8583
_writer.writeHeaders();
8684
_outputContext = BookStreamContext.createRootContext(_schema);
85+
if (!isEnabled(Feature.HYPERLINKE)) {
86+
_writer.disableHyperlink();
87+
}
88+
}
89+
90+
public boolean isEnabled(final Feature f) {
91+
return (_formatFeatures & f.getMask()) != 0;
8792
}
8893

8994
public boolean isDate1904() {
@@ -312,4 +317,42 @@ private void _checkSchemaSet() throws IOException {
312317
"No schema of type '" + HyperSchema.SCHEMA_TYPE + "' set, can not generate", this);
313318
}
314319
}
320+
321+
public enum Feature implements FormatFeature {
322+
HYPERLINKE(true),
323+
;
324+
final boolean _defaultState;
325+
final int _mask;
326+
327+
Feature(final boolean defaultState) {
328+
_defaultState = defaultState;
329+
_mask = 1 << ordinal();
330+
}
331+
332+
public static int collectDefaults() {
333+
int flags = 0;
334+
for (Feature f : values()) {
335+
if (f.enabledByDefault()) {
336+
flags |= f.getMask();
337+
}
338+
}
339+
return flags;
340+
}
341+
342+
@Override
343+
public boolean enabledByDefault() {
344+
return _defaultState;
345+
}
346+
347+
@Override
348+
public int getMask() {
349+
return _mask;
350+
}
351+
352+
@Override
353+
public boolean enabledIn(final int flags) {
354+
return (flags & getMask()) != 0;
355+
}
356+
}
357+
315358
}

src/main/java/io/github/honhimw/jackson/dataformat/hyper/HyperMapper.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public BookParser createParser(final InputStream in) throws IOException {
201201

202202
/*
203203
/**********************************************************
204-
/* Configuration, simple features: SheetParser.Feature
204+
/* Configuration, simple features: BookParser.Feature
205205
/**********************************************************
206206
*/
207207

@@ -224,6 +224,31 @@ public HyperMapper disable(final BookParser.Feature... features) {
224224
return this;
225225
}
226226

227+
/*
228+
/**********************************************************
229+
/* Configuration, simple features: BookParser.Feature
230+
/**********************************************************
231+
*/
232+
233+
public HyperMapper configure(final HyperGenerator.Feature f, final boolean state) {
234+
tokenStreamFactory().configure(f, state);
235+
return this;
236+
}
237+
238+
public HyperMapper enable(final HyperGenerator.Feature... features) {
239+
for (HyperGenerator.Feature f : features) {
240+
tokenStreamFactory().enable(f);
241+
}
242+
return this;
243+
}
244+
245+
public HyperMapper disable(final HyperGenerator.Feature... features) {
246+
for (HyperGenerator.Feature f : features) {
247+
tokenStreamFactory().disable(f);
248+
}
249+
return this;
250+
}
251+
227252
/*
228253
/**********************************************************
229254
/* Configuration, schema generation

0 commit comments

Comments
 (0)