index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk/models/OnlineQueryParams.java
package ai.chalk.models; import ai.chalk.features.Feature; import ai.chalk.features.StructFeaturesClass; import ai.chalk.features.WindowedFeaturesClass; import ai.chalk.internal.Utils; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import java.util.*; import java.time.Duration; /** * OnlineQueryParams holds the parameters for an online query. * It is the starting point for constructing an instance of * OnlineQueryParamsComplete. Both `withInput` and `withOutput` * must be called at least once. * * <p> * Example usage: * <pre> * {@code * OnlineQueryParamsComplete params = OnlineQueryParams.builder() * .withInput("user.id", new int[] {1, 2, 3}) * .withOutputs("user.email", "user.transactions") * .build(); * * try (OnlineQueryResult result = client.onlineQuery(params)) { * // do something with the result * } * } * </pre> * </p> */ @AllArgsConstructor @Getter public class OnlineQueryParams { // The features for which there are known values, mapped // to those values. Set by `OnlineQueryParams.builder().withInput`. /** * The features for which there are known values, mapped * to those values. Set by * `OnlineQueryParams.builder().withInput`. **/ private Map<String, Object> inputs; /** * The features that you'd like to compute from the inputs. * Set by `OnlineQueryParams.builder().withOutputs`. */ private List<String> outputs; /** * Maximum staleness overrides for any output features or intermediate features. * Set by `OnlineQueryParams.builder().withStaleness`. */ private Map<String, Duration> staleness; /** * Metadata to attach to the query. Set by `OnlineQueryParams.builder().withMeta`. */ private Map<String, String> meta; // tags is a list of tags to apply to the query. private List<String> tags; private boolean includeMeta; private boolean includeMetrics; private String environmentId; private String previewDeploymentId; private String queryName; private String correlationId; private String branch; @AllArgsConstructor @NoArgsConstructor public static class Builder { protected Map<String, Object> inputs; protected List<String> outputs; protected Map<String, Duration> staleness; protected Map<String, String> meta; protected List<String> tags; protected boolean includeMeta; protected boolean includeMetrics; protected String environmentId; protected String previewDeploymentId; protected String queryName; protected String correlationId; protected String branch; protected <T extends Builder> T _withInput(String fqn, Object... values) { if (this.inputs == null) { this.inputs = new HashMap<>(); } if (values.length == 1 && values[0].getClass().isArray()) { // Cast and use the inner array as the actual argument values = Utils.convertToArrayOfObjects(values[0]); } this.inputs.put(fqn, values); return (T) this; } public <T extends Builder, K> T _withInput(Feature<K> feature, K... value) { return this._withInput(feature.getFqn(), value); } protected <T extends Builder> T _withOutputs(String... outputs) { if (this.outputs == null) { this.outputs = new ArrayList<>(); } this.outputs.addAll(Arrays.asList(outputs)); return (T) this; } public <T extends Builder> T _withOutputs(Feature<?>... outputs) { var outputFqns = new String[outputs.length]; for (int i = 0; i < outputs.length; i++) { outputFqns[i] = outputs[i].getFqn(); } return (T) this._withOutputs(outputFqns); } public <T extends Builder> T _withOutputs(WindowedFeaturesClass... outputs) { var outputFqns = new String[outputs.length]; for (int i = 0; i < outputs.length; i++) { outputFqns[i] = outputs[i].getFqn(); } return (T) this._withOutputs(outputFqns); } public <T extends Builder> T _withOutputs(StructFeaturesClass... outputs) { var outputFqns = new String[outputs.length]; for (int i = 0; i < outputs.length; i++) { outputFqns[i] = outputs[i].getFqn(); } return (T) this._withOutputs(outputFqns); } // withStaleness takes alternating key, value pairs and adds them to the staleness map public Builder withStaleness(Object... staleness) { if (this.staleness == null) { this.staleness = new HashMap<>(); } if (staleness.length % 2 != 0) { throw new IllegalArgumentException("staleness must be an even number of alternating keys and values"); } for (int i = 0; i < staleness.length; i += 2) { if (!(staleness[i] instanceof String)) { throw new IllegalArgumentException("staleness must be an even number of alternating keys and values"); } this.staleness.put((String) staleness[i], (Duration) staleness[i + 1]); } return this; } // withMeta adds a single key, value pair to the meta map public Builder withMeta(String key, String value) { if (this.meta == null) { this.meta = new HashMap<>(); } this.meta.put(key, value); return this; } // withTags takes either multiple arguments or a single list of tags and adds them to the tags list public Builder withTags(Object... tags) { if (this.tags == null) { this.tags = new ArrayList<>(); } if (tags.length == 1 && tags[0] instanceof List) { this.tags.addAll((List<String>) tags[0]); } else { for (Object tag : tags) { this.tags.add((String) tag); } } return this; } // withTag adds a single tag to the tags list public Builder withTag(String tag) { return this.withTags(tag); } // withIncludeMeta sets the includeMeta flag public Builder withIncludeMeta(boolean includeMeta) { this.includeMeta = includeMeta; return this; } // withIncludeMetrics sets the includeMetrics flag public Builder withIncludeMetrics(boolean includeMetrics) { this.includeMetrics = includeMetrics; return this; } // withEnvironmentId sets the environmentId public Builder withEnvironmentId(String environmentId) { this.environmentId = environmentId; return this; } // withPreviewDeploymentId sets the previewDeploymentId public Builder withPreviewDeploymentId(String previewDeploymentId) { this.previewDeploymentId = previewDeploymentId; return this; } // withQueryName sets the queryName public Builder withQueryName(String queryName) { this.queryName = queryName; return this; } // withCorrelationId sets the correlationId public Builder withCorrelationId(String correlationId) { this.correlationId = correlationId; return this; } // withBranch sets the branch public Builder withBranch(String branch) { this.branch = branch; return this; } public OnlineQueryParams build() { return new OnlineQueryParams(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } } public static class BuilderComplete extends Builder { public BuilderComplete( Map<String, Object> inputs, List<String> outputs, Map<String, Duration> staleness, Map<String, String> meta, List<String> tags, boolean includeMeta, boolean includeMetrics, String environmentId, String previewDeploymentId, String queryName, String correlationId, String branch ) { super(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderComplete withInput(String fqn, Object... values) { return this._withInput(fqn, values); } @SafeVarargs public final <T> BuilderComplete withInput(Feature<T> feature, T... values) { return this._withInput(feature.getFqn(), values); } public BuilderComplete withOutputs(String... outputs) { return this._withOutputs(outputs); } public BuilderComplete withOutputs(Feature<?>... outputs) { return this._withOutputs(outputs); } public BuilderComplete withOutputs(WindowedFeaturesClass... outputs) { return this._withOutputs(outputs); } public BuilderComplete withOutputs(StructFeaturesClass... outputs) { return this._withOutputs(outputs); } public OnlineQueryParamsComplete build() { return new OnlineQueryParamsComplete(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } } public static class BuilderWithInputs extends Builder { public BuilderWithInputs( Map<String, Object> inputs, List<String> outputs, Map<String, Duration> staleness, Map<String, String> meta, List<String> tags, boolean includeMeta, boolean includeMetrics, String environmentId, String previewDeploymentId, String queryName, String correlationId, String branch ) { super(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } private BuilderComplete newBuilderComplete() { return new BuilderComplete(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderWithInputs withInput(String fqn, Object... values) { return this._withInput(fqn, values); } @SafeVarargs public final <T> BuilderWithInputs withInput(Feature<T> feature, T... values) { return this._withInput(feature.getFqn(), values); } public BuilderComplete withOutputs(String... outputs) { return this.newBuilderComplete()._withOutputs(outputs); } public BuilderComplete withOutputs(Feature<?>... outputs) { return this.newBuilderComplete()._withOutputs(outputs); } public BuilderComplete withOutputs(WindowedFeaturesClass... outputs) { return this.newBuilderComplete()._withOutputs(outputs); } public BuilderComplete withOutputs(StructFeaturesClass... outputs) { return this.newBuilderComplete()._withOutputs(outputs); } } public static class BuilderWithOutputs extends Builder { public BuilderWithOutputs( Map<String, Object> inputs, List<String> outputs, Map<String, Duration> staleness, Map<String, String> meta, List<String> tags, boolean includeMeta, boolean includeMetrics, String environmentId, String previewDeploymentId, String queryName, String correlationId, String branch ) { super(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderComplete newBuilderComplete() { return new BuilderComplete(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderComplete withInput(String fqn, Object... values) { return newBuilderComplete()._withInput(fqn, values); } @SafeVarargs public final <T> BuilderComplete withInput(Feature<T> feature, T... values) { return newBuilderComplete()._withInput(feature.getFqn(), values); } public BuilderWithOutputs withOutputs(String... outputs) { return this._withOutputs(outputs); } public BuilderWithOutputs withOutputs(Feature<?>... outputs) { return this._withOutputs(outputs); } public BuilderWithOutputs withOutputs(WindowedFeaturesClass... outputs) { return this._withOutputs(outputs); } public BuilderWithOutputs withOutputs(StructFeaturesClass... outputs) { return this._withOutputs(outputs); } } @NoArgsConstructor public static class BuilderSeed extends Builder { public BuilderSeed( Map<String, Object> inputs, List<String> outputs, Map<String, Duration> staleness, Map<String, String> meta, List<String> tags, boolean includeMeta, boolean includeMetrics, String environmentId, String previewDeploymentId, String queryName, String correlationId, String branch ) { super(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderWithInputs newBuilderWithInputs() { return new BuilderWithInputs(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } public BuilderWithOutputs newBuilderWithOutputs() { return new BuilderWithOutputs(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } // withInput adds a single feature FQN, value pair to the inputs map public BuilderWithInputs withInput(String fqn, Object... values) { return newBuilderWithInputs().withInput(fqn, values); } @SafeVarargs public final <T> BuilderWithInputs withInput(Feature<T> feature, T... value) { return newBuilderWithInputs().withInput(feature, value); } // withOutputs takes either one output or a list of outputs and adds them to the outputs list public BuilderWithOutputs withOutputs(String... outputs) { return newBuilderWithOutputs().withOutputs(outputs); } public BuilderWithOutputs withOutputs(Feature<?>... outputs) { return newBuilderWithOutputs().withOutputs(outputs); } public BuilderWithOutputs withOutputs(WindowedFeaturesClass... outputs) { return newBuilderWithOutputs().withOutputs(outputs); } public BuilderWithOutputs withOutputs(StructFeaturesClass... outputs) { return newBuilderWithOutputs().withOutputs(outputs); } } public static BuilderSeed builder() { return new BuilderSeed(); } }
0
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk/models/OnlineQueryParamsComplete.java
package ai.chalk.models; import java.time.Duration; import java.util.List; import java.util.Map; public class OnlineQueryParamsComplete extends OnlineQueryParams { /** * Thin subclass of OnlineQueryParams. Used to statically * indicate that all required online query params have been * provided. * * <p> Constructed by calling `withInput` and `withOutput` * at least once in {@link OnlineQueryParams.Builder}. * * <p> * Example usage: * <pre> * {@code * OnlineQueryParamsComplete params = OnlineQueryParams.builder() * .withInput("user.id", new int[] {1, 2, 3}) * .withOutputs("user.email", "user.transactions") * .build(); * * try (OnlineQueryResult result = client.onlineQuery(params)) { * // do something with the result * } * } * </pre> * </p> */ public OnlineQueryParamsComplete( Map<String, Object> inputs, List<String> outputs, Map<String, Duration> staleness, Map<String, String> meta, List<String> tags, boolean includeMeta, boolean includeMetrics, String environmentId, String previewDeploymentId, String queryName, String correlationId, String branch ) { super(inputs, outputs, staleness, meta, tags, includeMeta, includeMetrics, environmentId, previewDeploymentId, queryName, correlationId, branch); } }
0
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk/models/OnlineQueryResult.java
package ai.chalk.models; import ai.chalk.exceptions.ClientException; import ai.chalk.exceptions.ServerError; import ai.chalk.features.FeaturesClass; import ai.chalk.internal.arrow.Unmarshaller; import lombok.Data; import lombok.AllArgsConstructor; import org.apache.arrow.vector.table.Table; import java.util.Map; /** * OnlineQueryResult holds the result of an online query. */ @Data @AllArgsConstructor public class OnlineQueryResult implements AutoCloseable { /** * scalarsTable is an Arrow Table containing scalar * features of the target feature class. For example, if * the target feature class "User" has the attributes * "email" and "name", then the scalarsTable will contain * these two columns. Each row in the table corresponds to * a single User in the query. */ private final Table scalarsTable; /** * groupsTables is a map from a has-many feature to its * corresponding Arrow Table. For example, if the target * feature class "User" has an attribute "transactions" * which is a has-many feature, then all transactions * associated with any of the Users in the query will be * returned in the groupsTables map, under the key * "user.transactions". */ private final Map<String, Table> groupsTables; /** * errors is a list of errors that occurred in the server * during the query. */ private final ServerError[] errors; /** * meta contains execution metadata for the query. See QueryMeta for * details. */ private final QueryMeta meta; /** * close releases resources associated with the result. */ public void close() { scalarsTable.close(); for (Table table : groupsTables.values()) { table.close(); } } public <T extends FeaturesClass> T[] unmarshal(Class<T> clazz) throws ClientException { return Unmarshaller.unmarshalOnlineQueryResult(this, clazz); } }
0
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk/models/QueryMeta.java
package ai.chalk.models; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; import java.time.ZonedDateTime; /** * QueryMeta represents metadata about a Chalk query. */ @Data @NoArgsConstructor public class QueryMeta { /** * Execution duration in seconds. */ private double executionDurationS; /** * The id of the deployment that served this query. */ private String deploymentId; /** * The id of the environment that served this query. Not * intended to be human-readable,but helpful for support. */ private String environmentId; /** * The short name of the environment that served this query. * For example: "dev" or "prod". */ private String environmentName; /** * A unique ID generated and persisted by Chalk for this * query. All computed features, metrics, and logs are * associated with this ID. Your system can store this ID * for audit and debugging workflows. */ private String queryId; /** * At the start of query execution, Chalk computes * 'datetime.now()'. This value is used to timestamp * computed features. */ private ZonedDateTime queryTimestamp; /** * Deterministic hash of the 'structure' of the query. * Queries that have the same input/output features will * typically have the same hash; changes may be observed * over time as we adjust implementation details. */ private String queryHash; }
0
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk
java-sources/ai/chalk/chalk-java-jdk17/0.3.4/ai/chalk/models/ResolverException.java
package ai.chalk.models; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class ResolverException { // The name of the class of the exception. private String kind; // The message taken from the exception. private String message; // The stacktrace produced by the code. private String stacktrace; @Override public String toString() { return "ResolverException{" + "kind='" + kind + '\'' + ", message='" + message + '\'' + ", stacktrace='" + stacktrace + '\'' + '}'; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus/0.0.1/plus
java-sources/ai/chat2db/excel/easyexcel-plus/0.0.1/plus/easyexcel/Empty.java
package plus.easyexcel; /** * empty * * @author Jiaju Zhuang */ public class Empty { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/EasyExcel.java
package ai.chat2db.excel; /** * This is actually {@link EasyExcelFactory}, and short names look better. * * @author jipengfei */ public class EasyExcel extends EasyExcelFactory {}
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/EasyExcelFactory.java
package ai.chat2db.excel; import java.io.File; import java.io.InputStream; import java.io.OutputStream; import ai.chat2db.excel.read.builder.ExcelReaderBuilder; import ai.chat2db.excel.read.builder.ExcelReaderSheetBuilder; import ai.chat2db.excel.read.listener.ReadListener; import ai.chat2db.excel.write.builder.ExcelWriterBuilder; import ai.chat2db.excel.write.builder.ExcelWriterSheetBuilder; import ai.chat2db.excel.write.builder.ExcelWriterTableBuilder; /** * Reader and writer factory class * * @author jipengfei */ public class EasyExcelFactory { /** * Build excel the write * * @return */ public static ExcelWriterBuilder write() { return new ExcelWriterBuilder(); } /** * Build excel the write * * @param file File to write * @return Excel writer builder */ public static ExcelWriterBuilder write(File file) { return write(file, null); } /** * Build excel the write * * @param file File to write * @param head Annotate the class for configuration information * @return Excel writer builder */ public static ExcelWriterBuilder write(File file, Class head) { ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); excelWriterBuilder.file(file); if (head != null) { excelWriterBuilder.head(head); } return excelWriterBuilder; } /** * Build excel the write * * @param pathName File path to write * @return Excel writer builder */ public static ExcelWriterBuilder write(String pathName) { return write(pathName, null); } /** * Build excel the write * * @param pathName File path to write * @param head Annotate the class for configuration information * @return Excel writer builder */ public static ExcelWriterBuilder write(String pathName, Class head) { ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); excelWriterBuilder.file(pathName); if (head != null) { excelWriterBuilder.head(head); } return excelWriterBuilder; } /** * Build excel the write * * @param outputStream Output stream to write * @return Excel writer builder */ public static ExcelWriterBuilder write(OutputStream outputStream) { return write(outputStream, null); } /** * Build excel the write * * @param outputStream Output stream to write * @param head Annotate the class for configuration information. * @return Excel writer builder */ public static ExcelWriterBuilder write(OutputStream outputStream, Class head) { ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); excelWriterBuilder.file(outputStream); if (head != null) { excelWriterBuilder.head(head); } return excelWriterBuilder; } /** * Build excel the <code>writerSheet</code> * * @return Excel sheet writer builder */ public static ExcelWriterSheetBuilder writerSheet() { return writerSheet(null, null); } /** * Build excel the <code>writerSheet</code> * * @param sheetNo Index of sheet,0 base. * @return Excel sheet writer builder. */ public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo) { return writerSheet(sheetNo, null); } /** * Build excel the 'writerSheet' * * @param sheetName The name of sheet. * @return Excel sheet writer builder. */ public static ExcelWriterSheetBuilder writerSheet(String sheetName) { return writerSheet(null, sheetName); } /** * Build excel the 'writerSheet' * * @param sheetNo Index of sheet,0 base. * @param sheetName The name of sheet. * @return Excel sheet writer builder. */ public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo, String sheetName) { ExcelWriterSheetBuilder excelWriterSheetBuilder = new ExcelWriterSheetBuilder(); if (sheetNo != null) { excelWriterSheetBuilder.sheetNo(sheetNo); } if (sheetName != null) { excelWriterSheetBuilder.sheetName(sheetName); } return excelWriterSheetBuilder; } /** * Build excel the <code>writerTable</code> * * @return Excel table writer builder. */ public static ExcelWriterTableBuilder writerTable() { return writerTable(null); } /** * Build excel the 'writerTable' * * @param tableNo Index of table,0 base. * @return Excel table writer builder. */ public static ExcelWriterTableBuilder writerTable(Integer tableNo) { ExcelWriterTableBuilder excelWriterTableBuilder = new ExcelWriterTableBuilder(); if (tableNo != null) { excelWriterTableBuilder.tableNo(tableNo); } return excelWriterTableBuilder; } /** * Build excel the read * * @return Excel reader builder. */ public static ExcelReaderBuilder read() { return new ExcelReaderBuilder(); } /** * Build excel the read * * @param file File to read. * @return Excel reader builder. */ public static ExcelReaderBuilder read(File file) { return read(file, null, null); } /** * Build excel the read * * @param file File to read. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(File file, ReadListener readListener) { return read(file, null, readListener); } /** * Build excel the read * * @param file File to read. * @param head Annotate the class for configuration information. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) { ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); excelReaderBuilder.file(file); if (head != null) { excelReaderBuilder.head(head); } if (readListener != null) { excelReaderBuilder.registerReadListener(readListener); } return excelReaderBuilder; } /** * Build excel the read * * @param pathName File path to read. * @return Excel reader builder. */ public static ExcelReaderBuilder read(String pathName) { return read(pathName, null, null); } /** * Build excel the read * * @param pathName File path to read. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(String pathName, ReadListener readListener) { return read(pathName, null, readListener); } /** * Build excel the read * * @param pathName File path to read. * @param head Annotate the class for configuration information. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) { ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); excelReaderBuilder.file(pathName); if (head != null) { excelReaderBuilder.head(head); } if (readListener != null) { excelReaderBuilder.registerReadListener(readListener); } return excelReaderBuilder; } /** * Build excel the read * * @param inputStream Input stream to read. * @return Excel reader builder. */ public static ExcelReaderBuilder read(InputStream inputStream) { return read(inputStream, null, null); } /** * Build excel the read * * @param inputStream Input stream to read. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) { return read(inputStream, null, readListener); } /** * Build excel the read * * @param inputStream Input stream to read. * @param head Annotate the class for configuration information. * @param readListener Read listener. * @return Excel reader builder. */ public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) { ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); excelReaderBuilder.file(inputStream); if (head != null) { excelReaderBuilder.head(head); } if (readListener != null) { excelReaderBuilder.registerReadListener(readListener); } return excelReaderBuilder; } /** * Build excel the 'readSheet' * * @return Excel sheet reader builder. */ public static ExcelReaderSheetBuilder readSheet() { return readSheet(null, null); } /** * Build excel the 'readSheet' * * @param sheetNo Index of sheet,0 base. * @return Excel sheet reader builder. */ public static ExcelReaderSheetBuilder readSheet(Integer sheetNo) { return readSheet(sheetNo, null); } /** * Build excel the 'readSheet' * * @param sheetName The name of sheet. * @return Excel sheet reader builder. */ public static ExcelReaderSheetBuilder readSheet(String sheetName) { return readSheet(null, sheetName); } /** * Build excel the 'readSheet' * * @param sheetNo Index of sheet,0 base. * @param sheetName The name of sheet. * @return Excel sheet reader builder. */ public static ExcelReaderSheetBuilder readSheet(Integer sheetNo, String sheetName) { ExcelReaderSheetBuilder excelReaderSheetBuilder = new ExcelReaderSheetBuilder(); if (sheetNo != null) { excelReaderSheetBuilder.sheetNo(sheetNo); } if (sheetName != null) { excelReaderSheetBuilder.sheetName(sheetName); } return excelReaderSheetBuilder; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/ExcelReader.java
package ai.chat2db.excel; import java.io.Closeable; import java.util.Arrays; import java.util.List; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.analysis.ExcelAnalyser; import ai.chat2db.excel.analysis.ExcelAnalyserImpl; import ai.chat2db.excel.analysis.ExcelReadExecutor; import ai.chat2db.excel.context.AnalysisContext; import lombok.extern.slf4j.Slf4j; /** * Excel readers are all read in event mode. * * @author jipengfei */ @Slf4j public class ExcelReader implements Closeable { /** * Analyser */ private final ExcelAnalyser excelAnalyser; public ExcelReader(ReadWorkbook readWorkbook) { excelAnalyser = new ExcelAnalyserImpl(readWorkbook); } /** * Parse all sheet content by default * * @deprecated lease use {@link #readAll()} */ @Deprecated public void read() { readAll(); } /*** * Parse all sheet content by default */ public void readAll() { excelAnalyser.analysis(null, Boolean.TRUE); } /** * Parse the specified sheet,SheetNo start from 0 * * @param readSheet Read sheet */ public ExcelReader read(ReadSheet... readSheet) { return read(Arrays.asList(readSheet)); } /** * Read multiple sheets. * * @param readSheetList * @return */ public ExcelReader read(List<ReadSheet> readSheetList) { excelAnalyser.analysis(readSheetList, Boolean.FALSE); return this; } /** * Context for the entire execution process * * @return */ public AnalysisContext analysisContext() { return excelAnalyser.analysisContext(); } /** * Current executor * * @return */ public ExcelReadExecutor excelExecutor() { return excelAnalyser.excelExecutor(); } /** * @return * @deprecated please use {@link #analysisContext()} */ @Deprecated public AnalysisContext getAnalysisContext() { return analysisContext(); } /** * Complete the entire read file.Release the cache and close stream. */ public void finish() { if (excelAnalyser != null) { excelAnalyser.finish(); } } @Override public void close() { finish(); } /** * Prevents calls to {@link #finish} from freeing the cache * */ @Override protected void finalize() { try { finish(); } catch (Throwable e) { log.warn("Destroy object failed", e); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/ExcelWriter.java
package ai.chat2db.excel; import java.io.Closeable; import java.util.Collection; import java.util.function.Supplier; import ai.chat2db.excel.context.WriteContext; import ai.chat2db.excel.write.ExcelBuilder; import ai.chat2db.excel.write.ExcelBuilderImpl; import ai.chat2db.excel.write.metadata.WriteSheet; import ai.chat2db.excel.write.metadata.WriteTable; import ai.chat2db.excel.write.metadata.WriteWorkbook; import ai.chat2db.excel.write.metadata.fill.FillConfig; import lombok.extern.slf4j.Slf4j; /** * Excel Writer This tool is used to write value out to Excel via POI. This object can perform the following two * functions. * * <pre> * 1. Create a new empty Excel workbook, write the value to the stream after the value is filled. * 2. Edit existing Excel, write the original Excel file, or write it to other places.} * </pre> * * @author jipengfei */ @Slf4j public class ExcelWriter implements Closeable { private final ExcelBuilder excelBuilder; /** * Create new writer * * @param writeWorkbook */ public ExcelWriter(WriteWorkbook writeWorkbook) { excelBuilder = new ExcelBuilderImpl(writeWorkbook); } /** * Write data to a sheet * * @param data Data to be written * @param writeSheet Write to this sheet * @return this current writer */ public ExcelWriter write(Collection<?> data, WriteSheet writeSheet) { return write(data, writeSheet, null); } /** * Write data to a sheet * * @param supplier Data to be written * @param writeSheet Write to this sheet * @return this current writer */ public ExcelWriter write(Supplier<Collection<?>> supplier, WriteSheet writeSheet) { return write(supplier.get(), writeSheet, null); } /** * Write value to a sheet * * @param data Data to be written * @param writeSheet Write to this sheet * @param writeTable Write to this table * @return this */ public ExcelWriter write(Collection<?> data, WriteSheet writeSheet, WriteTable writeTable) { excelBuilder.addContent(data, writeSheet, writeTable); return this; } /** * Write value to a sheet * * @param supplier Data to be written * @param writeSheet Write to this sheet * @param writeTable Write to this table * @return this */ public ExcelWriter write(Supplier<Collection<?>> supplier, WriteSheet writeSheet, WriteTable writeTable) { excelBuilder.addContent(supplier.get(), writeSheet, writeTable); return this; } /** * Fill value to a sheet * * @param data * @param writeSheet * @return */ public ExcelWriter fill(Object data, WriteSheet writeSheet) { return fill(data, null, writeSheet); } /** * Fill value to a sheet * * @param data * @param fillConfig * @param writeSheet * @return */ public ExcelWriter fill(Object data, FillConfig fillConfig, WriteSheet writeSheet) { excelBuilder.fill(data, fillConfig, writeSheet); return this; } /** * Fill value to a sheet * * @param supplier * @param writeSheet * @return */ public ExcelWriter fill(Supplier<Object> supplier, WriteSheet writeSheet) { return fill(supplier.get(), null, writeSheet); } /** * Fill value to a sheet * * @param supplier * @param fillConfig * @param writeSheet * @return */ public ExcelWriter fill(Supplier<Object> supplier, FillConfig fillConfig, WriteSheet writeSheet) { excelBuilder.fill(supplier.get(), fillConfig, writeSheet); return this; } /** * Close IO */ public void finish() { if (excelBuilder != null) { excelBuilder.finish(false); } } /** * The context of the entire writing process * * @return */ public WriteContext writeContext() { return excelBuilder.writeContext(); } @Override public void close() { finish(); } /** * Prevents calls to {@link #finish} from freeing the cache */ @Override protected void finalize() { try { finish(); } catch (Throwable e) { log.warn("Destroy object failed", e); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/ExcelAnalyser.java
package ai.chat2db.excel.analysis; import java.util.List; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.context.AnalysisContext; /** * Excel file analyser * * @author jipengfei */ public interface ExcelAnalyser { /** * parse the sheet * * @param readSheetList * Which sheets you need to read. * @param readAll * The <code>readSheetList</code> parameter is ignored, and all sheets are read. */ void analysis(List<ReadSheet> readSheetList, Boolean readAll); /** * Complete the entire read file.Release the cache and close stream */ void finish(); /** * Acquisition excel executor * * @return Excel file Executor */ ExcelReadExecutor excelExecutor(); /** * get the analysis context. * * @return analysis context */ AnalysisContext analysisContext(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/ExcelAnalyserImpl.java
package ai.chat2db.excel.analysis; import ai.chat2db.excel.analysis.v07.XlsxSaxAnalyser; import ai.chat2db.excel.exception.ExcelAnalysisException; import ai.chat2db.excel.exception.ExcelAnalysisStopException; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.read.metadata.holder.ReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder; import ai.chat2db.excel.analysis.csv.CsvExcelReadExecutor; import ai.chat2db.excel.analysis.v03.XlsSaxAnalyser; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.context.csv.CsvReadContext; import ai.chat2db.excel.context.csv.DefaultCsvReadContext; import ai.chat2db.excel.context.xls.DefaultXlsReadContext; import ai.chat2db.excel.context.xls.XlsReadContext; import ai.chat2db.excel.context.xlsx.DefaultXlsxReadContext; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import ai.chat2db.excel.support.ExcelTypeEnum; import ai.chat2db.excel.util.ClassUtils; import ai.chat2db.excel.util.DateUtils; import ai.chat2db.excel.util.FileUtils; import ai.chat2db.excel.util.NumberDataFormatterUtils; import ai.chat2db.excel.util.StringUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.filesystem.DocumentFactoryHelper; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.InputStream; import java.util.List; /** * @author jipengfei */ public class ExcelAnalyserImpl implements ExcelAnalyser { private static final Logger LOGGER = LoggerFactory.getLogger(ExcelAnalyserImpl.class); private AnalysisContext analysisContext; private ExcelReadExecutor excelReadExecutor; /** * Prevent multiple shutdowns */ private boolean finished = false; public ExcelAnalyserImpl(ReadWorkbook readWorkbook) { try { choiceExcelExecutor(readWorkbook); } catch (RuntimeException e) { finish(); throw e; } catch (Throwable e) { finish(); throw new ExcelAnalysisException(e); } } private void choiceExcelExecutor(ReadWorkbook readWorkbook) throws Exception { ExcelTypeEnum excelType = ExcelTypeEnum.valueOf(readWorkbook); switch (excelType) { case XLS: POIFSFileSystem poifsFileSystem; if (readWorkbook.getFile() != null) { poifsFileSystem = new POIFSFileSystem(readWorkbook.getFile()); } else { poifsFileSystem = new POIFSFileSystem(readWorkbook.getInputStream()); } // So in encrypted excel, it looks like XLS but it's actually XLSX if (poifsFileSystem.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) { InputStream decryptedStream = null; try { decryptedStream = DocumentFactoryHelper .getDecryptedStream(poifsFileSystem.getRoot().getFileSystem(), readWorkbook.getPassword()); XlsxReadContext xlsxReadContext = new DefaultXlsxReadContext(readWorkbook, ExcelTypeEnum.XLSX); analysisContext = xlsxReadContext; excelReadExecutor = new XlsxSaxAnalyser(xlsxReadContext, decryptedStream); return; } finally { IOUtils.closeQuietly(decryptedStream); // as we processed the full stream already, we can close the filesystem here // otherwise file handles are leaked poifsFileSystem.close(); } } if (readWorkbook.getPassword() != null) { Biff8EncryptionKey.setCurrentUserPassword(readWorkbook.getPassword()); } XlsReadContext xlsReadContext = new DefaultXlsReadContext(readWorkbook, ExcelTypeEnum.XLS); xlsReadContext.xlsReadWorkbookHolder().setPoifsFileSystem(poifsFileSystem); analysisContext = xlsReadContext; excelReadExecutor = new XlsSaxAnalyser(xlsReadContext); break; case XLSX: XlsxReadContext xlsxReadContext = new DefaultXlsxReadContext(readWorkbook, ExcelTypeEnum.XLSX); analysisContext = xlsxReadContext; excelReadExecutor = new XlsxSaxAnalyser(xlsxReadContext, null); break; case CSV: CsvReadContext csvReadContext = new DefaultCsvReadContext(readWorkbook, ExcelTypeEnum.CSV); analysisContext = csvReadContext; excelReadExecutor = new CsvExcelReadExecutor(csvReadContext); break; default: break; } } @Override public void analysis(List<ReadSheet> readSheetList, Boolean readAll) { try { if (!readAll && CollectionUtils.isEmpty(readSheetList)) { throw new IllegalArgumentException("Specify at least one read sheet."); } analysisContext.readWorkbookHolder().setParameterSheetDataList(readSheetList); analysisContext.readWorkbookHolder().setReadAll(readAll); try { excelReadExecutor.execute(); } catch (ExcelAnalysisStopException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Custom stop!"); } } } catch (RuntimeException e) { finish(); throw e; } catch (Throwable e) { finish(); throw new ExcelAnalysisException(e); } } @Override public void finish() { if (finished) { return; } finished = true; if (analysisContext == null || analysisContext.readWorkbookHolder() == null) { return; } ReadWorkbookHolder readWorkbookHolder = analysisContext.readWorkbookHolder(); Throwable throwable = null; try { if (readWorkbookHolder.getReadCache() != null) { readWorkbookHolder.getReadCache().destroy(); } } catch (Throwable t) { throwable = t; } try { if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder) && ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage() != null) { ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage().revert(); } } catch (Throwable t) { throwable = t; } try { if ((readWorkbookHolder instanceof XlsReadWorkbookHolder) && ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem() != null) { ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem().close(); } } catch (Throwable t) { throwable = t; } // close csv. // https://github.com/CodePhiliaX/easyexcel-plus/issues/2309 try { if ((readWorkbookHolder instanceof CsvReadWorkbookHolder) && ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser() != null && analysisContext.readWorkbookHolder().getAutoCloseStream()) { ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser().close(); } } catch (Throwable t) { throwable = t; } try { if (analysisContext.readWorkbookHolder().getAutoCloseStream() && readWorkbookHolder.getInputStream() != null) { readWorkbookHolder.getInputStream().close(); } } catch (Throwable t) { throwable = t; } try { if (readWorkbookHolder.getTempFile() != null) { FileUtils.delete(readWorkbookHolder.getTempFile()); } } catch (Throwable t) { throwable = t; } clearEncrypt03(); removeThreadLocalCache(); if (throwable != null) { throw new ExcelAnalysisException("Can not close IO.", throwable); } } private void removeThreadLocalCache() { NumberDataFormatterUtils.removeThreadLocalCache(); DateUtils.removeThreadLocalCache(); ClassUtils.removeThreadLocalCache(); } private void clearEncrypt03() { if (StringUtils.isEmpty(analysisContext.readWorkbookHolder().getPassword()) || !ExcelTypeEnum.XLS.equals(analysisContext.readWorkbookHolder().getExcelType())) { return; } Biff8EncryptionKey.setCurrentUserPassword(null); } @Override public ExcelReadExecutor excelExecutor() { return excelReadExecutor; } @Override public AnalysisContext analysisContext() { return analysisContext; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/ExcelReadExecutor.java
package ai.chat2db.excel.analysis; import java.util.List; import ai.chat2db.excel.read.metadata.ReadSheet; /** * Excel file Executor * * @author Jiaju Zhuang */ public interface ExcelReadExecutor { /** * Returns the actual sheet in excel * * @return Actual sheet in excel */ List<ReadSheet> sheetList(); /** * Read the sheet. */ void execute(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/csv/CsvExcelReadExecutor.java
package ai.chat2db.excel.analysis.csv; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Files; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import ai.chat2db.excel.analysis.ExcelReadExecutor; import ai.chat2db.excel.enums.ByteOrderMarkEnum; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.exception.ExcelAnalysisException; import ai.chat2db.excel.exception.ExcelAnalysisStopSheetException; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; import ai.chat2db.excel.util.SheetUtils; import ai.chat2db.excel.util.StringUtils; import ai.chat2db.excel.context.csv.CsvReadContext; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; import org.apache.commons.io.input.BOMInputStream; /** * read executor * * @author zhuangjiaju */ @Slf4j public class CsvExcelReadExecutor implements ExcelReadExecutor { private final List<ReadSheet> sheetList; private final CsvReadContext csvReadContext; public CsvExcelReadExecutor(CsvReadContext csvReadContext) { this.csvReadContext = csvReadContext; sheetList = new ArrayList<>(); ReadSheet readSheet = new ReadSheet(); sheetList.add(readSheet); readSheet.setSheetNo(0); } @Override public List<ReadSheet> sheetList() { return sheetList; } @Override public void execute() { CSVParser csvParser; try { csvParser = csvParser(); csvReadContext.csvReadWorkbookHolder().setCsvParser(csvParser); } catch (IOException e) { throw new ExcelAnalysisException(e); } for (ReadSheet readSheet : sheetList) { readSheet = SheetUtils.match(readSheet, csvReadContext); if (readSheet == null) { continue; } try { csvReadContext.currentSheet(readSheet); int rowIndex = 0; for (CSVRecord record : csvParser) { dealRecord(record, rowIndex++); } } catch (ExcelAnalysisStopSheetException e) { if (log.isDebugEnabled()) { log.debug("Custom stop!", e); } } // The last sheet is read csvReadContext.analysisEventProcessor().endSheet(csvReadContext); } } private CSVParser csvParser() throws IOException { CsvReadWorkbookHolder csvReadWorkbookHolder = csvReadContext.csvReadWorkbookHolder(); CSVFormat csvFormat = csvReadWorkbookHolder.getCsvFormat(); ByteOrderMarkEnum byteOrderMark = ByteOrderMarkEnum.valueOfByCharsetName( csvReadContext.csvReadWorkbookHolder().getCharset().name()); if (csvReadWorkbookHolder.getMandatoryUseInputStream()) { return buildCsvParser(csvFormat, csvReadWorkbookHolder.getInputStream(), byteOrderMark); } if (csvReadWorkbookHolder.getFile() != null) { return buildCsvParser(csvFormat, Files.newInputStream(csvReadWorkbookHolder.getFile().toPath()), byteOrderMark); } return buildCsvParser(csvFormat, csvReadWorkbookHolder.getInputStream(), byteOrderMark); } private CSVParser buildCsvParser(CSVFormat csvFormat, InputStream inputStream, ByteOrderMarkEnum byteOrderMark) throws IOException { if (byteOrderMark == null) { return csvFormat.parse( new InputStreamReader(inputStream, csvReadContext.csvReadWorkbookHolder().getCharset())); } return csvFormat.parse(new InputStreamReader(new BOMInputStream(inputStream, byteOrderMark.getByteOrderMark()), csvReadContext.csvReadWorkbookHolder().getCharset())); } private void dealRecord(CSVRecord record, int rowIndex) { Map<Integer, Cell> cellMap = new LinkedHashMap<>(); Iterator<String> cellIterator = record.iterator(); int columnIndex = 0; Boolean autoTrim = csvReadContext.currentReadHolder().globalConfiguration().getAutoTrim(); while (cellIterator.hasNext()) { String cellString = cellIterator.next(); ReadCellData<String> readCellData = new ReadCellData<>(); readCellData.setRowIndex(rowIndex); readCellData.setColumnIndex(columnIndex); // csv is an empty string of whether <code>,,</code> is read or <code>,"",</code> if (StringUtils.isNotBlank(cellString)) { readCellData.setType(CellDataTypeEnum.STRING); readCellData.setStringValue(autoTrim ? cellString.trim() : cellString); } else { readCellData.setType(CellDataTypeEnum.EMPTY); } cellMap.put(columnIndex++, readCellData); } RowTypeEnum rowType = MapUtils.isEmpty(cellMap) ? RowTypeEnum.EMPTY : RowTypeEnum.DATA; ReadRowHolder readRowHolder = new ReadRowHolder(rowIndex, rowType, csvReadContext.readWorkbookHolder().getGlobalConfiguration(), cellMap); csvReadContext.readRowHolder(readRowHolder); csvReadContext.csvReadSheetHolder().setCellMap(cellMap); csvReadContext.csvReadSheetHolder().setRowIndex(rowIndex); csvReadContext.analysisEventProcessor().endRow(csvReadContext); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/IgnorableXlsRecordHandler.java
package ai.chat2db.excel.analysis.v03; /** * Need to ignore the current handler without reading the current sheet. * * @author Jiaju Zhuang */ public interface IgnorableXlsRecordHandler extends XlsRecordHandler {}
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/XlsListSheetListener.java
package ai.chat2db.excel.analysis.v03; import java.io.IOException; import java.util.HashMap; import java.util.Map; import ai.chat2db.excel.exception.ExcelAnalysisException; import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder; import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; import org.apache.poi.hssf.eventusermodel.HSSFListener; import org.apache.poi.hssf.eventusermodel.HSSFRequest; import org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener; import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BoundSheetRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.analysis.v03.handlers.BofRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.BoundSheetRecordHandler; import ai.chat2db.excel.context.xls.XlsReadContext; /** * In some cases, you need to know the number of sheets in advance and only read the file once in advance. * * @author Jiaju Zhuang */ public class XlsListSheetListener implements HSSFListener { private final XlsReadContext xlsReadContext; private static final Map<Short, XlsRecordHandler> XLS_RECORD_HANDLER_MAP = new HashMap<Short, XlsRecordHandler>(); static { XLS_RECORD_HANDLER_MAP.put(BOFRecord.sid, new BofRecordHandler()); XLS_RECORD_HANDLER_MAP.put(BoundSheetRecord.sid, new BoundSheetRecordHandler()); } public XlsListSheetListener(XlsReadContext xlsReadContext) { this.xlsReadContext = xlsReadContext; xlsReadContext.xlsReadWorkbookHolder().setNeedReadSheet(Boolean.FALSE); } @Override public void processRecord(Record record) { XlsRecordHandler handler = XLS_RECORD_HANDLER_MAP.get(record.getSid()); if (handler == null) { return; } handler.processRecord(xlsReadContext, record); } public void execute() { MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this); HSSFListener formatListener = new FormatTrackingHSSFListener(listener); HSSFEventFactory factory = new HSSFEventFactory(); HSSFRequest request = new HSSFRequest(); EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener(formatListener); request.addListenerForAllRecords(workbookBuildingListener); try { factory.processWorkbookEvents(request, xlsReadContext.xlsReadWorkbookHolder().getPoifsFileSystem()); } catch (IOException e) { throw new ExcelAnalysisException(e); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/XlsRecordHandler.java
package ai.chat2db.excel.analysis.v03; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Intercepts handle xls reads. * * @author Dan Zheng */ public interface XlsRecordHandler { /** * Whether to support * * @param xlsReadContext * @param record * @return */ boolean support(XlsReadContext xlsReadContext, Record record); /** * Processing record * * @param xlsReadContext * @param record */ void processRecord(XlsReadContext xlsReadContext, Record record); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/XlsSaxAnalyser.java
package ai.chat2db.excel.analysis.v03; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import ai.chat2db.excel.analysis.ExcelReadExecutor; import ai.chat2db.excel.exception.ExcelAnalysisException; import ai.chat2db.excel.exception.ExcelAnalysisStopException; import ai.chat2db.excel.exception.ExcelAnalysisStopSheetException; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder; import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; import org.apache.poi.hssf.eventusermodel.HSSFListener; import org.apache.poi.hssf.eventusermodel.HSSFRequest; import org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener; import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BlankRecord; import org.apache.poi.hssf.record.BoolErrRecord; import org.apache.poi.hssf.record.BoundSheetRecord; import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.HyperlinkRecord; import org.apache.poi.hssf.record.IndexRecord; import org.apache.poi.hssf.record.LabelRecord; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.MergeCellsRecord; import org.apache.poi.hssf.record.NoteRecord; import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.hssf.record.RKRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.SSTRecord; import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.TextObjectRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ai.chat2db.excel.analysis.v03.handlers.BlankRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.BofRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.BoolErrRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.BoundSheetRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.DummyRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.EofRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.FormulaRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.HyperlinkRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.IndexRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.LabelRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.LabelSstRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.MergeCellsRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.NoteRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.NumberRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.ObjRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.RkRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.SstRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.StringRecordHandler; import ai.chat2db.excel.analysis.v03.handlers.TextObjectRecordHandler; import ai.chat2db.excel.context.xls.XlsReadContext; /** * A text extractor for Excel files. * <p> * Returns the textual content of the file, suitable for indexing by something like Lucene, but not really intended for * display to the user. * </p> * * <p> * To turn an excel file into a CSV or similar, then see the XLS2CSVmra example * </p> * * * @author jipengfei * @see <a href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/eventusermodel/examples/XLS2CSVmra.java">XLS2CSVmra</a> */ @Slf4j public class XlsSaxAnalyser implements HSSFListener, ExcelReadExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(XlsSaxAnalyser.class); private static final short DUMMY_RECORD_SID = -1; private final XlsReadContext xlsReadContext; private static final Map<Short, XlsRecordHandler> XLS_RECORD_HANDLER_MAP = new HashMap<Short, XlsRecordHandler>(32); static { XLS_RECORD_HANDLER_MAP.put(BlankRecord.sid, new BlankRecordHandler()); XLS_RECORD_HANDLER_MAP.put(BOFRecord.sid, new BofRecordHandler()); XLS_RECORD_HANDLER_MAP.put(BoolErrRecord.sid, new BoolErrRecordHandler()); XLS_RECORD_HANDLER_MAP.put(BoundSheetRecord.sid, new BoundSheetRecordHandler()); XLS_RECORD_HANDLER_MAP.put(DUMMY_RECORD_SID, new DummyRecordHandler()); XLS_RECORD_HANDLER_MAP.put(EOFRecord.sid, new EofRecordHandler()); XLS_RECORD_HANDLER_MAP.put(FormulaRecord.sid, new FormulaRecordHandler()); XLS_RECORD_HANDLER_MAP.put(HyperlinkRecord.sid, new HyperlinkRecordHandler()); XLS_RECORD_HANDLER_MAP.put(IndexRecord.sid, new IndexRecordHandler()); XLS_RECORD_HANDLER_MAP.put(LabelRecord.sid, new LabelRecordHandler()); XLS_RECORD_HANDLER_MAP.put(LabelSSTRecord.sid, new LabelSstRecordHandler()); XLS_RECORD_HANDLER_MAP.put(MergeCellsRecord.sid, new MergeCellsRecordHandler()); XLS_RECORD_HANDLER_MAP.put(NoteRecord.sid, new NoteRecordHandler()); XLS_RECORD_HANDLER_MAP.put(NumberRecord.sid, new NumberRecordHandler()); XLS_RECORD_HANDLER_MAP.put(ObjRecord.sid, new ObjRecordHandler()); XLS_RECORD_HANDLER_MAP.put(RKRecord.sid, new RkRecordHandler()); XLS_RECORD_HANDLER_MAP.put(SSTRecord.sid, new SstRecordHandler()); XLS_RECORD_HANDLER_MAP.put(StringRecord.sid, new StringRecordHandler()); XLS_RECORD_HANDLER_MAP.put(TextObjectRecord.sid, new TextObjectRecordHandler()); } public XlsSaxAnalyser(XlsReadContext xlsReadContext) { this.xlsReadContext = xlsReadContext; } @Override public List<ReadSheet> sheetList() { try { if (xlsReadContext.readWorkbookHolder().getActualSheetDataList() == null) { new XlsListSheetListener(xlsReadContext).execute(); } } catch (ExcelAnalysisStopException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Custom stop!"); } } return xlsReadContext.readWorkbookHolder().getActualSheetDataList(); } @Override public void execute() { XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder(); MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this); xlsReadWorkbookHolder.setFormatTrackingHSSFListener(new FormatTrackingHSSFListener(listener)); EventWorkbookBuilder.SheetRecordCollectingListener workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener( xlsReadWorkbookHolder.getFormatTrackingHSSFListener()); xlsReadWorkbookHolder.setHssfWorkbook(workbookBuildingListener.getStubHSSFWorkbook()); HSSFEventFactory factory = new HSSFEventFactory(); HSSFRequest request = new HSSFRequest(); request.addListenerForAllRecords(xlsReadWorkbookHolder.getFormatTrackingHSSFListener()); try { factory.processWorkbookEvents(request, xlsReadWorkbookHolder.getPoifsFileSystem()); } catch (IOException e) { throw new ExcelAnalysisException(e); } // There are some special xls that do not have the terminator "[EOF]", so an additional xlsReadContext.analysisEventProcessor().endSheet(xlsReadContext); } @Override public void processRecord(Record record) { XlsRecordHandler handler = XLS_RECORD_HANDLER_MAP.get(record.getSid()); if (handler == null) { return; } boolean ignoreRecord = (handler instanceof IgnorableXlsRecordHandler) && xlsReadContext.xlsReadWorkbookHolder().getIgnoreRecord(); if (ignoreRecord) { // No need to read the current sheet return; } if (!handler.support(xlsReadContext, record)) { return; } try { handler.processRecord(xlsReadContext, record); } catch (ExcelAnalysisStopSheetException e) { if (log.isDebugEnabled()) { log.debug("Custom stop!", e); } xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.TRUE); xlsReadContext.xlsReadWorkbookHolder().setCurrentSheetStopped(Boolean.TRUE); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/AbstractXlsRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.XlsRecordHandler; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Abstract xls record handler * * @author Jiaju Zhuang **/ public abstract class AbstractXlsRecordHandler implements XlsRecordHandler { @Override public boolean support(XlsReadContext xlsReadContext, Record record) { return true; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/BlankRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.BlankRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class BlankRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { BlankRecord br = (BlankRecord)record; xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)br.getColumn(), ReadCellData.newEmptyInstance(br.getRow(), (int)br.getColumn())); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/BofRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.util.ArrayList; import java.util.List; import ai.chat2db.excel.exception.ExcelAnalysisStopException; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; import ai.chat2db.excel.util.SheetUtils; import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BoundSheetRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class BofRecordHandler extends AbstractXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { BOFRecord br = (BOFRecord) record; XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder(); if (br.getType() == BOFRecord.TYPE_WORKBOOK) { xlsReadWorkbookHolder.setReadSheetIndex(null); xlsReadWorkbookHolder.setIgnoreRecord(Boolean.FALSE); return; } if (br.getType() != BOFRecord.TYPE_WORKSHEET) { return; } // Init read sheet Data initReadSheetDataList(xlsReadWorkbookHolder); Integer readSheetIndex = xlsReadWorkbookHolder.getReadSheetIndex(); if (readSheetIndex == null) { readSheetIndex = 0; xlsReadWorkbookHolder.setReadSheetIndex(readSheetIndex); } ReadSheet actualReadSheet = xlsReadWorkbookHolder.getActualSheetDataList().get(readSheetIndex); assert actualReadSheet != null : "Can't find the sheet."; // Copy the parameter to the current sheet ReadSheet readSheet = SheetUtils.match(actualReadSheet, xlsReadContext); if (readSheet != null) { xlsReadContext.currentSheet(readSheet); xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.FALSE); } else { xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.TRUE); } xlsReadContext.xlsReadWorkbookHolder().setCurrentSheetStopped(Boolean.FALSE); // Go read the next one xlsReadWorkbookHolder.setReadSheetIndex(xlsReadWorkbookHolder.getReadSheetIndex() + 1); } private void initReadSheetDataList(XlsReadWorkbookHolder xlsReadWorkbookHolder) { if (xlsReadWorkbookHolder.getActualSheetDataList() != null) { return; } BoundSheetRecord[] boundSheetRecords = BoundSheetRecord.orderByBofPosition(xlsReadWorkbookHolder.getBoundSheetRecordList()); List<ReadSheet> readSheetDataList = new ArrayList<ReadSheet>(); for (int i = 0; i < boundSheetRecords.length; i++) { BoundSheetRecord boundSheetRecord = boundSheetRecords[i]; ReadSheet readSheet = new ReadSheet(i, boundSheetRecord.getSheetname()); readSheetDataList.add(readSheet); } xlsReadWorkbookHolder.setActualSheetDataList(readSheetDataList); // Just need to get the list of sheets if (!xlsReadWorkbookHolder.getNeedReadSheet()) { throw new ExcelAnalysisStopException("Just need to get the list of sheets."); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/BoolErrRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.BoolErrRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class BoolErrRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { BoolErrRecord ber = (BoolErrRecord)record; xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)ber.getColumn(), ReadCellData.newInstance(ber.getBooleanValue(), ber.getRow(), (int)ber.getColumn())); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/BoundSheetRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import org.apache.poi.hssf.record.BoundSheetRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class BoundSheetRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { BoundSheetRecord bsr = (BoundSheetRecord)record; xlsReadContext.xlsReadWorkbookHolder().getBoundSheetRecordList().add(bsr); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/DummyRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.util.LinkedHashMap; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord; import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class DummyRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder(); if (record instanceof LastCellOfRowDummyRecord) { // End of this row LastCellOfRowDummyRecord lcrdr = (LastCellOfRowDummyRecord)record; xlsReadSheetHolder.setRowIndex(lcrdr.getRow()); xlsReadContext.readRowHolder(new ReadRowHolder(lcrdr.getRow(), xlsReadSheetHolder.getTempRowType(), xlsReadContext.readSheetHolder().getGlobalConfiguration(), xlsReadSheetHolder.getCellMap())); xlsReadContext.analysisEventProcessor().endRow(xlsReadContext); xlsReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>()); xlsReadSheetHolder.setTempRowType(RowTypeEnum.EMPTY); } else if (record instanceof MissingCellDummyRecord) { MissingCellDummyRecord mcdr = (MissingCellDummyRecord)record; // https://github.com/CodePhiliaX/easyexcel-plus/issues/2236 // Some abnormal XLS, in the case of data already exist, or there will be a "MissingCellDummyRecord" // records, so if the existing data, empty data is ignored xlsReadSheetHolder.getCellMap().putIfAbsent(mcdr.getColumn(), ReadCellData.newEmptyInstance(mcdr.getRow(), mcdr.getColumn())); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/EofRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.util.LinkedHashMap; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import ai.chat2db.excel.util.BooleanUtils; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class EofRecordHandler extends AbstractXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { if (xlsReadContext.readSheetHolder() == null) { return; } //Represents the current sheet does not need to be read or the user manually stopped reading the sheet. if (BooleanUtils.isTrue(xlsReadContext.xlsReadWorkbookHolder().getIgnoreRecord())) { // When the user manually stops reading the sheet, the method to end the sheet needs to be called. if (BooleanUtils.isTrue(xlsReadContext.xlsReadWorkbookHolder().getCurrentSheetStopped())) { xlsReadContext.analysisEventProcessor().endSheet(xlsReadContext); } return; } // Sometimes tables lack the end record of the last column if (!xlsReadContext.xlsReadSheetHolder().getCellMap().isEmpty()) { XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder(); // Forge a termination data xlsReadContext.readRowHolder(new ReadRowHolder(xlsReadContext.xlsReadSheetHolder().getRowIndex() + 1, xlsReadSheetHolder.getTempRowType(), xlsReadContext.readSheetHolder().getGlobalConfiguration(), xlsReadSheetHolder.getCellMap())); xlsReadContext.analysisEventProcessor().endRow(xlsReadContext); xlsReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>()); xlsReadSheetHolder.setTempRowType(RowTypeEnum.EMPTY); } xlsReadContext.analysisEventProcessor().endSheet(xlsReadContext); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/FormulaRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.math.BigDecimal; import java.util.Map; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.constant.BuiltinFormats; import ai.chat2db.excel.constant.EasyExcelConstants; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.metadata.data.DataFormatData; import ai.chat2db.excel.metadata.data.FormulaData; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import lombok.extern.slf4j.Slf4j; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.record.FormulaRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.ss.usermodel.CellType; /** * Record handler * * @author Dan Zheng */ @Slf4j public class FormulaRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { private static final String ERROR = "#VALUE!"; @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { FormulaRecord frec = (FormulaRecord)record; Map<Integer, Cell> cellMap = xlsReadContext.xlsReadSheetHolder().getCellMap(); ReadCellData<?> tempCellData = new ReadCellData<>(); tempCellData.setRowIndex(frec.getRow()); tempCellData.setColumnIndex((int)frec.getColumn()); CellType cellType = CellType.forInt(frec.getCachedResultType()); String formulaValue = null; try { formulaValue = HSSFFormulaParser.toFormulaString(xlsReadContext.xlsReadWorkbookHolder().getHssfWorkbook(), frec.getParsedExpression()); } catch (Exception e) { log.debug("Get formula value error.", e); } FormulaData formulaData = new FormulaData(); formulaData.setFormulaValue(formulaValue); tempCellData.setFormulaData(formulaData); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); switch (cellType) { case STRING: // Formula result is a string // This is stored in the next record tempCellData.setType(CellDataTypeEnum.STRING); xlsReadContext.xlsReadSheetHolder().setTempCellData(tempCellData); break; case NUMERIC: tempCellData.setType(CellDataTypeEnum.NUMBER); tempCellData.setOriginalNumberValue(BigDecimal.valueOf(frec.getValue())); tempCellData.setNumberValue( tempCellData.getOriginalNumberValue().round(EasyExcelConstants.EXCEL_MATH_CONTEXT)); int dataFormat = xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex(frec); DataFormatData dataFormatData = new DataFormatData(); dataFormatData.setIndex((short)dataFormat); dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormatData.getIndex(), xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(frec), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale())); tempCellData.setDataFormatData(dataFormatData); cellMap.put((int)frec.getColumn(), tempCellData); break; case ERROR: tempCellData.setType(CellDataTypeEnum.ERROR); tempCellData.setStringValue(ERROR); cellMap.put((int)frec.getColumn(), tempCellData); break; case BOOLEAN: tempCellData.setType(CellDataTypeEnum.BOOLEAN); tempCellData.setBooleanValue(frec.getCachedBooleanValue()); cellMap.put((int)frec.getColumn(), tempCellData); break; default: tempCellData.setType(CellDataTypeEnum.EMPTY); cellMap.put((int)frec.getColumn(), tempCellData); break; } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/HyperlinkRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.metadata.CellExtra; import org.apache.poi.hssf.record.HyperlinkRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class HyperlinkRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public boolean support(XlsReadContext xlsReadContext, Record record) { return xlsReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK); } @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { HyperlinkRecord hr = (HyperlinkRecord)record; CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.HYPERLINK, hr.getAddress(), hr.getFirstRow(), hr.getLastRow(), hr.getFirstColumn(), hr.getLastColumn()); xlsReadContext.xlsReadSheetHolder().setCellExtra(cellExtra); xlsReadContext.analysisEventProcessor().extra(xlsReadContext); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/IndexRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import org.apache.poi.hssf.record.IndexRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Jiaju Zhuang */ public class IndexRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { if (xlsReadContext.readSheetHolder() == null) { return; } xlsReadContext.readSheetHolder().setApproximateTotalRowNumber(((IndexRecord)record).getLastRowAdd1()); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/LabelRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.LabelRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class LabelRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { LabelRecord lrec = (LabelRecord)record; String data = lrec.getValue(); if (data != null && xlsReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) { data = data.trim(); } xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)lrec.getColumn(), ReadCellData.newInstance(data, lrec.getRow(), (int)lrec.getColumn())); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/LabelSstRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.util.Map; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.cache.ReadCache; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class LabelSstRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { LabelSSTRecord lsrec = (LabelSSTRecord)record; ReadCache readCache = xlsReadContext.readWorkbookHolder().getReadCache(); Map<Integer, Cell> cellMap = xlsReadContext.xlsReadSheetHolder().getCellMap(); if (readCache == null) { cellMap.put((int)lsrec.getColumn(), ReadCellData.newEmptyInstance(lsrec.getRow(), (int)lsrec.getColumn())); return; } String data = readCache.get(lsrec.getSSTIndex()); if (data == null) { cellMap.put((int)lsrec.getColumn(), ReadCellData.newEmptyInstance(lsrec.getRow(), (int)lsrec.getColumn())); return; } if (xlsReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) { data = data.trim(); } cellMap.put((int)lsrec.getColumn(), ReadCellData.newInstance(data, lsrec.getRow(), (int)lsrec.getColumn())); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/MergeCellsRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.metadata.CellExtra; import org.apache.poi.hssf.record.MergeCellsRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.ss.util.CellRangeAddress; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class MergeCellsRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public boolean support(XlsReadContext xlsReadContext, Record record) { return xlsReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.MERGE); } @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { MergeCellsRecord mcr = (MergeCellsRecord)record; for (int i = 0; i < mcr.getNumAreas(); i++) { CellRangeAddress cellRangeAddress = mcr.getAreaAt(i); CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.MERGE, null, cellRangeAddress.getFirstRow(), cellRangeAddress.getLastRow(), cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn()); xlsReadContext.xlsReadSheetHolder().setCellExtra(cellExtra); xlsReadContext.analysisEventProcessor().extra(xlsReadContext); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/NoteRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.metadata.CellExtra; import org.apache.poi.hssf.record.NoteRecord; import org.apache.poi.hssf.record.Record; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class NoteRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public boolean support(XlsReadContext xlsReadContext, Record record) { return xlsReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT); } @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { NoteRecord nr = (NoteRecord)record; String text = xlsReadContext.xlsReadSheetHolder().getObjectCacheMap().get(nr.getShapeId()); CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, text, nr.getRow(), nr.getColumn()); xlsReadContext.xlsReadSheetHolder().setCellExtra(cellExtra); xlsReadContext.analysisEventProcessor().extra(xlsReadContext); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/NumberRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import java.math.BigDecimal; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.constant.BuiltinFormats; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.data.DataFormatData; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class NumberRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { NumberRecord nr = (NumberRecord)record; ReadCellData<?> cellData = ReadCellData.newInstanceOriginal(BigDecimal.valueOf(nr.getValue()), nr.getRow(), (int)nr.getColumn()); short dataFormat = (short)xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatIndex( nr); DataFormatData dataFormatData = new DataFormatData(); dataFormatData.setIndex(dataFormat); dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormat, xlsReadContext.xlsReadWorkbookHolder().getFormatTrackingHSSFListener().getFormatString(nr), xlsReadContext.readSheetHolder().getGlobalConfiguration().getLocale())); cellData.setDataFormatData(dataFormatData); xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)nr.getColumn(), cellData); xlsReadContext.xlsReadSheetHolder().setTempRowType(RowTypeEnum.DATA); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/ObjRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import org.apache.poi.hssf.record.CommonObjectDataSubRecord; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.SubRecord; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Jiaju Zhuang */ public class ObjRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { ObjRecord or = (ObjRecord)record; for (SubRecord subRecord : or.getSubRecords()) { if (subRecord instanceof CommonObjectDataSubRecord) { CommonObjectDataSubRecord codsr = (CommonObjectDataSubRecord)subRecord; if (CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT == codsr.getObjectType()) { xlsReadContext.xlsReadSheetHolder().setTempObjectIndex(codsr.getObjectId()); } break; } } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/RkRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.context.xls.XlsReadContext; import org.apache.poi.hssf.record.RKRecord; import org.apache.poi.hssf.record.Record; /** * Record handler * * @author Dan Zheng */ public class RkRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { RKRecord re = (RKRecord)record; xlsReadContext.xlsReadSheetHolder().getCellMap().put((int)re.getColumn(), ReadCellData.newEmptyInstance(re.getRow(), (int)re.getColumn())); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/SstRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.cache.XlsCache; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.SSTRecord; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class SstRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { xlsReadContext.readWorkbookHolder().setReadCache(new XlsCache((SSTRecord)record)); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/StringRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.metadata.data.CellData; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.StringRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Dan Zheng */ public class StringRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { private static final Logger LOGGER = LoggerFactory.getLogger(StringRecordHandler.class); @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { // String for formula StringRecord srec = (StringRecord)record; XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder(); CellData<?> tempCellData = xlsReadSheetHolder.getTempCellData(); if (tempCellData == null) { LOGGER.warn("String type formula but no value found."); return; } tempCellData.setStringValue(srec.getString()); xlsReadSheetHolder.getCellMap().put(tempCellData.getColumnIndex(), tempCellData); xlsReadSheetHolder.setTempCellData(null); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v03/handlers/TextObjectRecordHandler.java
package ai.chat2db.excel.analysis.v03.handlers; import ai.chat2db.excel.analysis.v03.IgnorableXlsRecordHandler; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.TextObjectRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ai.chat2db.excel.context.xls.XlsReadContext; /** * Record handler * * @author Jiaju Zhuang */ public class TextObjectRecordHandler extends AbstractXlsRecordHandler implements IgnorableXlsRecordHandler { private static final Logger LOGGER = LoggerFactory.getLogger(TextObjectRecordHandler.class); @Override public boolean support(XlsReadContext xlsReadContext, Record record) { return xlsReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT); } @Override public void processRecord(XlsReadContext xlsReadContext, Record record) { TextObjectRecord tor = (TextObjectRecord)record; XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder(); Integer tempObjectIndex = xlsReadSheetHolder.getTempObjectIndex(); if (tempObjectIndex == null) { LOGGER.debug("tempObjectIndex is null."); return; } xlsReadSheetHolder.getObjectCacheMap().put(tempObjectIndex, tor.getStr().getString()); xlsReadSheetHolder.setTempObjectIndex(null); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/XlsxSaxAnalyser.java
package ai.chat2db.excel.analysis.v07; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import ai.chat2db.excel.cache.ReadCache; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.exception.ExcelAnalysisException; import ai.chat2db.excel.exception.ExcelAnalysisStopSheetException; import ai.chat2db.excel.metadata.CellExtra; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder; import ai.chat2db.excel.util.FileUtils; import ai.chat2db.excel.util.MapUtils; import ai.chat2db.excel.util.SheetUtils; import ai.chat2db.excel.util.StringUtils; import ai.chat2db.excel.analysis.ExcelReadExecutor; import ai.chat2db.excel.analysis.v07.handlers.sax.SharedStringsTableHandler; import ai.chat2db.excel.analysis.v07.handlers.sax.XlsxRowHandler; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import lombok.extern.slf4j.Slf4j; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.xssf.eventusermodel.XSSFReader; import org.apache.poi.xssf.model.Comments; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.usermodel.XSSFComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; /** * @author jipengfei */ @Slf4j public class XlsxSaxAnalyser implements ExcelReadExecutor { /** * Storage sheet SharedStrings */ public static final PackagePartName SHARED_STRINGS_PART_NAME; static { try { SHARED_STRINGS_PART_NAME = PackagingURIHelper.createPartName("/xl/sharedStrings.xml"); } catch (InvalidFormatException e) { log.error("Initialize the XlsxSaxAnalyser failure", e); throw new ExcelAnalysisException("Initialize the XlsxSaxAnalyser failure", e); } } private final XlsxReadContext xlsxReadContext; private final List<ReadSheet> sheetList; private final Map<Integer, InputStream> sheetMap; /** * excel comments key: sheetNo value: CommentsTable */ private final Map<Integer, CommentsTable> commentsTableMap; public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception { this.xlsxReadContext = xlsxReadContext; // Initialize cache XlsxReadWorkbookHolder xlsxReadWorkbookHolder = xlsxReadContext.xlsxReadWorkbookHolder(); OPCPackage pkg = readOpcPackage(xlsxReadWorkbookHolder, decryptedStream); xlsxReadWorkbookHolder.setOpcPackage(pkg); // Read the Shared information Strings PackagePart sharedStringsTablePackagePart = pkg.getPart(SHARED_STRINGS_PART_NAME); if (sharedStringsTablePackagePart != null) { // Specify default cache defaultReadCache(xlsxReadWorkbookHolder, sharedStringsTablePackagePart); // Analysis sharedStringsTable.xml analysisSharedStringsTable(sharedStringsTablePackagePart.getInputStream(), xlsxReadWorkbookHolder); } XSSFReader xssfReader = new XSSFReader(pkg); analysisUse1904WindowDate(xssfReader, xlsxReadWorkbookHolder); // set style table setStylesTable(xlsxReadWorkbookHolder, xssfReader); sheetList = new ArrayList<>(); sheetMap = new HashMap<>(); commentsTableMap = new HashMap<>(); Map<Integer, PackageRelationshipCollection> packageRelationshipCollectionMap = MapUtils.newHashMap(); xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap); XSSFReader.SheetIterator ite = (XSSFReader.SheetIterator)xssfReader.getSheetsData(); int index = 0; if (!ite.hasNext()) { throw new ExcelAnalysisException("Can not find any sheet!"); } while (ite.hasNext()) { InputStream inputStream = ite.next(); sheetList.add(new ReadSheet(index, ite.getSheetName())); sheetMap.put(index, inputStream); if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { Comments comments = ite.getSheetComments(); if (comments instanceof CommentsTable) { commentsTableMap.put(index, (CommentsTable) comments); } } if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) { PackageRelationshipCollection packageRelationshipCollection = Optional.ofNullable(ite.getSheetPart()) .map(packagePart -> { try { return packagePart.getRelationships(); } catch (InvalidFormatException e) { log.warn("Reading the Relationship failed", e); return null; } }).orElse(null); if (packageRelationshipCollection != null) { packageRelationshipCollectionMap.put(index, packageRelationshipCollection); } } index++; } } private void setStylesTable(XlsxReadWorkbookHolder xlsxReadWorkbookHolder, XSSFReader xssfReader) { try { xlsxReadWorkbookHolder.setStylesTable(xssfReader.getStylesTable()); } catch (Exception e) { log.warn( "Currently excel cannot get style information, but it doesn't affect the data analysis.You can try to" + " save the file with office again or ignore the current error.", e); } } private void defaultReadCache(XlsxReadWorkbookHolder xlsxReadWorkbookHolder, PackagePart sharedStringsTablePackagePart) { ReadCache readCache = xlsxReadWorkbookHolder.getReadCacheSelector().readCache(sharedStringsTablePackagePart); xlsxReadWorkbookHolder.setReadCache(readCache); readCache.init(xlsxReadContext); } private void analysisUse1904WindowDate(XSSFReader xssfReader, XlsxReadWorkbookHolder xlsxReadWorkbookHolder) throws Exception { if (xlsxReadWorkbookHolder.globalConfiguration().getUse1904windowing() != null) { return; } InputStream workbookXml = xssfReader.getWorkbookData(); WorkbookDocument ctWorkbook = WorkbookDocument.Factory.parse(workbookXml); CTWorkbook wb = ctWorkbook.getWorkbook(); CTWorkbookPr prefix = wb.getWorkbookPr(); if (prefix != null && prefix.getDate1904()) { xlsxReadWorkbookHolder.getGlobalConfiguration().setUse1904windowing(Boolean.TRUE); } else { xlsxReadWorkbookHolder.getGlobalConfiguration().setUse1904windowing(Boolean.FALSE); } } private void analysisSharedStringsTable(InputStream sharedStringsTableInputStream, XlsxReadWorkbookHolder xlsxReadWorkbookHolder) { ContentHandler handler = new SharedStringsTableHandler(xlsxReadWorkbookHolder.getReadCache()); parseXmlSource(sharedStringsTableInputStream, handler); xlsxReadWorkbookHolder.getReadCache().putFinished(); } private OPCPackage readOpcPackage(XlsxReadWorkbookHolder xlsxReadWorkbookHolder, InputStream decryptedStream) throws Exception { if (decryptedStream == null && xlsxReadWorkbookHolder.getFile() != null) { return OPCPackage.open(xlsxReadWorkbookHolder.getFile()); } if (xlsxReadWorkbookHolder.getMandatoryUseInputStream()) { if (decryptedStream != null) { return OPCPackage.open(decryptedStream); } else { return OPCPackage.open(xlsxReadWorkbookHolder.getInputStream()); } } File readTempFile = FileUtils.createCacheTmpFile(); xlsxReadWorkbookHolder.setTempFile(readTempFile); File tempFile = new File(readTempFile.getPath(), UUID.randomUUID() + ".xlsx"); if (decryptedStream != null) { FileUtils.writeToFile(tempFile, decryptedStream, false); } else { FileUtils.writeToFile(tempFile, xlsxReadWorkbookHolder.getInputStream(), xlsxReadWorkbookHolder.getAutoCloseStream()); } return OPCPackage.open(tempFile, PackageAccess.READ); } @Override public List<ReadSheet> sheetList() { return sheetList; } private void parseXmlSource(InputStream inputStream, ContentHandler handler) { InputSource inputSource = new InputSource(inputStream); try { SAXParserFactory saxFactory; String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName(); if (StringUtils.isEmpty(xlsxSAXParserFactoryName)) { saxFactory = SAXParserFactory.newInstance(); } else { saxFactory = SAXParserFactory.newInstance(xlsxSAXParserFactoryName, null); } try { saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (Throwable ignore) {} try { saxFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); } catch (Throwable ignore) {} try { saxFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); } catch (Throwable ignore) {} SAXParser saxParser = saxFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setContentHandler(handler); xmlReader.parse(inputSource); inputStream.close(); } catch (IOException | ParserConfigurationException | SAXException e) { throw new ExcelAnalysisException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { throw new ExcelAnalysisException("Can not close 'inputStream'!"); } } } } @Override public void execute() { for (ReadSheet readSheet : sheetList) { readSheet = SheetUtils.match(readSheet, xlsxReadContext); if (readSheet != null) { try { xlsxReadContext.currentSheet(readSheet); parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext)); // Read comments readComments(readSheet); } catch (ExcelAnalysisStopSheetException e) { if (log.isDebugEnabled()) { log.debug("Custom stop!", e); } } // The last sheet is read xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext); } } } private void readComments(ReadSheet readSheet) { if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) { return; } CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo()); if (commentsTable == null) { return; } Iterator<CellAddress> cellAddresses = commentsTable.getCellAddresses(); while (cellAddresses.hasNext()) { CellAddress cellAddress = cellAddresses.next(); XSSFComment cellComment = commentsTable.findCellComment(cellAddress); CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(), cellAddress.getRow(), cellAddress.getColumn()); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra); xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import ai.chat2db.excel.context.xlsx.XlsxReadContext; /** * Cell Value Handler * * @author jipengfei */ public abstract class AbstractCellValueTagHandler extends AbstractXlsxTagHandler { @Override public void characters(XlsxReadContext xlsxReadContext, char[] ch, int start, int length) { xlsxReadContext.xlsxReadSheetHolder().getTempData().append(ch, start, length); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/AbstractXlsxTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import org.xml.sax.Attributes; import ai.chat2db.excel.context.xlsx.XlsxReadContext; /** * Abstract tag handler * * @author Jiaju Zhuang */ public abstract class AbstractXlsxTagHandler implements XlsxTagHandler { @Override public boolean support(XlsxReadContext xlsxReadContext) { return true; } @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { } @Override public void endElement(XlsxReadContext xlsxReadContext, String name) { } @Override public void characters(XlsxReadContext xlsxReadContext, char[] ch, int start, int length) { } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/CellFormulaTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import ai.chat2db.excel.metadata.data.FormulaData; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import org.xml.sax.Attributes; /** * Cell Handler * * @author jipengfei */ public class CellFormulaTagHandler extends AbstractXlsxTagHandler { @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); xlsxReadSheetHolder.setTempFormula(new StringBuilder()); } @Override public void endElement(XlsxReadContext xlsxReadContext, String name) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); FormulaData formulaData = new FormulaData(); formulaData.setFormulaValue(xlsxReadSheetHolder.getTempFormula().toString()); xlsxReadSheetHolder.getTempCellData().setFormulaData(formulaData); } @Override public void characters(XlsxReadContext xlsxReadContext, char[] ch, int start, int length) { xlsxReadContext.xlsxReadSheetHolder().getTempFormula().append(ch, start, length); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/CellInlineStringValueTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; /** * Cell inline string value handler * * @author jipengfei */ public class CellInlineStringValueTagHandler extends AbstractCellValueTagHandler { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/CellTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import java.math.BigDecimal; import ai.chat2db.excel.constant.EasyExcelConstants; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.util.BooleanUtils; import ai.chat2db.excel.util.PositionUtils; import ai.chat2db.excel.util.StringUtils; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import org.xml.sax.Attributes; /** * Cell Handler * * @author jipengfei */ public class CellTagHandler extends AbstractXlsxTagHandler { private static final int DEFAULT_FORMAT_INDEX = 0; @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); xlsxReadSheetHolder.setColumnIndex(PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_R), xlsxReadSheetHolder.getColumnIndex())); // t="s" ,it means String // t="str" ,it means String,but does not need to be read in the 'sharedStrings.xml' // t="inlineStr" ,it means String,but does not need to be read in the 'sharedStrings.xml' // t="b" ,it means Boolean // t="e" ,it means Error // t="n" ,it means Number // t is null ,it means Empty or Number CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_T)); xlsxReadSheetHolder.setTempCellData(new ReadCellData<>(type)); xlsxReadSheetHolder.setTempData(new StringBuilder()); // Put in data transformation information String dateFormatIndex = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_S); int dateFormatIndexInteger; if (StringUtils.isEmpty(dateFormatIndex)) { dateFormatIndexInteger = DEFAULT_FORMAT_INDEX; } else { dateFormatIndexInteger = Integer.parseInt(dateFormatIndex); } xlsxReadSheetHolder.getTempCellData().setDataFormatData( xlsxReadContext.xlsxReadWorkbookHolder().dataFormatData(dateFormatIndexInteger)); } @Override public void endElement(XlsxReadContext xlsxReadContext, String name) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); ReadCellData<?> tempCellData = xlsxReadSheetHolder.getTempCellData(); StringBuilder tempData = xlsxReadSheetHolder.getTempData(); String tempDataString = tempData.toString(); CellDataTypeEnum oldType = tempCellData.getType(); switch (oldType) { case STRING: // In some cases, although cell type is a string, it may be an empty tag if (StringUtils.isEmpty(tempDataString)) { break; } String stringValue = xlsxReadContext.readWorkbookHolder().getReadCache().get( Integer.valueOf(tempDataString)); tempCellData.setStringValue(stringValue); break; case DIRECT_STRING: case ERROR: tempCellData.setStringValue(tempDataString); tempCellData.setType(CellDataTypeEnum.STRING); break; case BOOLEAN: if (StringUtils.isEmpty(tempDataString)) { tempCellData.setType(CellDataTypeEnum.EMPTY); break; } tempCellData.setBooleanValue(BooleanUtils.valueOf(tempData.toString())); break; case NUMBER: case EMPTY: if (StringUtils.isEmpty(tempDataString)) { tempCellData.setType(CellDataTypeEnum.EMPTY); break; } tempCellData.setType(CellDataTypeEnum.NUMBER); tempCellData.setOriginalNumberValue(new BigDecimal(tempDataString)); tempCellData.setNumberValue( tempCellData.getOriginalNumberValue().round(EasyExcelConstants.EXCEL_MATH_CONTEXT)); break; default: throw new IllegalStateException("Cannot set values now"); } if (tempCellData.getStringValue() != null && xlsxReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) { tempCellData.setStringValue(tempCellData.getStringValue().trim()); } tempCellData.checkEmpty(); tempCellData.setRowIndex(xlsxReadSheetHolder.getRowIndex()); tempCellData.setColumnIndex(xlsxReadSheetHolder.getColumnIndex()); xlsxReadSheetHolder.getCellMap().put(xlsxReadSheetHolder.getColumnIndex(), tempCellData); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/CellValueTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; /** * Cell Value Handler * * @author jipengfei */ public class CellValueTagHandler extends AbstractCellValueTagHandler { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/CountTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.util.PositionUtils; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import org.xml.sax.Attributes; /** * Cell Handler * * @author jipengfei */ public class CountTagHandler extends AbstractXlsxTagHandler { @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { String d = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_REF); String totalStr = d.substring(d.indexOf(":") + 1); xlsxReadContext.readSheetHolder().setApproximateTotalRowNumber(PositionUtils.getRow(totalStr) + 1); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/HyperlinkTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import java.util.Optional; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.metadata.CellExtra; import ai.chat2db.excel.util.StringUtils; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.xml.sax.Attributes; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.context.xlsx.XlsxReadContext; /** * Cell Handler * * @author Jiaju Zhuang */ public class HyperlinkTagHandler extends AbstractXlsxTagHandler { @Override public boolean support(XlsxReadContext xlsxReadContext) { return xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK); } @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { String ref = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_REF); if (StringUtils.isEmpty(ref)) { return; } // Hyperlink has 2 case: // case 1,In the 'location' tag String location = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_LOCATION); if (location != null) { CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.HYPERLINK, location, ref); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra); xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext); return; } // case 2, In the 'r:id' tag, Then go to 'PackageRelationshipCollection' to get inside String rId = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_RID); PackageRelationshipCollection packageRelationshipCollection = xlsxReadContext.xlsxReadSheetHolder() .getPackageRelationshipCollection(); if (rId == null || packageRelationshipCollection == null) { return; } Optional.ofNullable(packageRelationshipCollection.getRelationshipByID(rId)) .map(PackageRelationship::getTargetURI) .ifPresent(uri -> { CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.HYPERLINK, uri.toString(), ref); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra); xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext); }); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/MergeCellTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import ai.chat2db.excel.enums.CellExtraTypeEnum; import ai.chat2db.excel.metadata.CellExtra; import ai.chat2db.excel.util.StringUtils; import org.xml.sax.Attributes; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.context.xlsx.XlsxReadContext; /** * Cell Handler * * @author Jiaju Zhuang */ public class MergeCellTagHandler extends AbstractXlsxTagHandler { @Override public boolean support(XlsxReadContext xlsxReadContext) { return xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.MERGE); } @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { String ref = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_REF); if (StringUtils.isEmpty(ref)) { return; } CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.MERGE, null, ref); xlsxReadContext.readSheetHolder().setCellExtra(cellExtra); xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/RowTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import java.util.LinkedHashMap; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.enums.RowTypeEnum; import ai.chat2db.excel.metadata.Cell; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.util.PositionUtils; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import org.apache.commons.collections4.MapUtils; import org.xml.sax.Attributes; /** * Cell Handler * * @author jipengfei */ public class RowTagHandler extends AbstractXlsxTagHandler { @Override public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); int rowIndex = PositionUtils.getRowByRowTagt(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_R), xlsxReadSheetHolder.getRowIndex()); Integer lastRowIndex = xlsxReadContext.readSheetHolder().getRowIndex(); while (lastRowIndex + 1 < rowIndex) { xlsxReadContext.readRowHolder(new ReadRowHolder(lastRowIndex + 1, RowTypeEnum.EMPTY, xlsxReadSheetHolder.getGlobalConfiguration(), new LinkedHashMap<Integer, Cell>())); xlsxReadContext.analysisEventProcessor().endRow(xlsxReadContext); xlsxReadSheetHolder.setColumnIndex(null); xlsxReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>()); lastRowIndex++; } xlsxReadSheetHolder.setRowIndex(rowIndex); } @Override public void endElement(XlsxReadContext xlsxReadContext, String name) { XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); RowTypeEnum rowType = MapUtils.isEmpty(xlsxReadSheetHolder.getCellMap()) ? RowTypeEnum.EMPTY : RowTypeEnum.DATA; // It's possible that all of the cells in the row are empty if (rowType == RowTypeEnum.DATA) { boolean hasData = false; for (Cell cell : xlsxReadSheetHolder.getCellMap().values()) { if (!(cell instanceof ReadCellData)) { hasData = true; break; } ReadCellData<?> readCellData = (ReadCellData<?>)cell; if (readCellData.getType() != CellDataTypeEnum.EMPTY) { hasData = true; break; } } if (!hasData) { rowType = RowTypeEnum.EMPTY; } } xlsxReadContext.readRowHolder(new ReadRowHolder(xlsxReadSheetHolder.getRowIndex(), rowType, xlsxReadSheetHolder.getGlobalConfiguration(), xlsxReadSheetHolder.getCellMap())); xlsxReadContext.analysisEventProcessor().endRow(xlsxReadContext); xlsxReadSheetHolder.setColumnIndex(null); xlsxReadSheetHolder.setCellMap(new LinkedHashMap<>()); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/XlsxTagHandler.java
package ai.chat2db.excel.analysis.v07.handlers; import org.xml.sax.Attributes; import ai.chat2db.excel.context.xlsx.XlsxReadContext; /** * Tag handler * * @author Dan Zheng */ public interface XlsxTagHandler { /** * Whether to support * * @param xlsxReadContext * @return */ boolean support(XlsxReadContext xlsxReadContext); /** * Start handle * * @param xlsxReadContext * xlsxReadContext * @param name * Tag name * @param attributes * Tag attributes */ void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes); /** * End handle * * @param xlsxReadContext * xlsxReadContext * @param name * Tag name */ void endElement(XlsxReadContext xlsxReadContext, String name); /** * Read data * * @param xlsxReadContext * @param ch * @param start * @param length */ void characters(XlsxReadContext xlsxReadContext, char[] ch, int start, int length); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/sax/SharedStringsTableHandler.java
/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package ai.chat2db.excel.analysis.v07.handlers.sax; import java.util.regex.Matcher; import java.util.regex.Pattern; import ai.chat2db.excel.cache.ReadCache; import ai.chat2db.excel.constant.ExcelXmlConstants; import org.xml.sax.Attributes; import org.xml.sax.helpers.DefaultHandler; /** * Sax read sharedStringsTable.xml * * @author Jiaju Zhuang */ public class SharedStringsTableHandler extends DefaultHandler { private static final Pattern UTF_PATTTERN = Pattern.compile("_x([0-9A-Fa-f]{4})_"); /** * The final piece of data */ private StringBuilder currentData; /** * Current element data */ private StringBuilder currentElementData; private final ReadCache readCache; /** * Some fields in the T tag need to be ignored */ private boolean ignoreTagt = false; /** * The only time you need to read the characters in the T tag is when it is used */ private boolean isTagt = false; public SharedStringsTableHandler(ReadCache readCache) { this.readCache = readCache; } @Override public void startElement(String uri, String localName, String name, Attributes attributes) { if (name == null) { return; } switch (name) { case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_T_TAG: currentElementData = null; isTagt = true; break; case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_SI_TAG: currentData = null; break; case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_RPH_TAG: ignoreTagt = true; break; default: // ignore } } @Override public void endElement(String uri, String localName, String name) { if (name == null) { return; } switch (name) { case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_T_TAG: if (currentElementData != null) { if (currentData == null) { currentData = new StringBuilder(); } currentData.append(currentElementData); } isTagt = false; break; case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_SI_TAG: if (currentData == null) { readCache.put(null); } else { readCache.put(utfDecode(currentData.toString())); } break; case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: case ExcelXmlConstants.SHAREDSTRINGS_NS2_RPH_TAG: ignoreTagt = false; break; default: // ignore } } @Override public void characters(char[] ch, int start, int length) { if (!isTagt || ignoreTagt) { return; } if (currentElementData == null) { currentElementData = new StringBuilder(); } currentElementData.append(ch, start, length); } /** * from poi XSSFRichTextString * * @param value the string to decode * @return the decoded string or null if the input string is null * <p> * For all characters which cannot be represented in XML as defined by the XML 1.0 specification, * the characters are escaped using the Unicode numerical character representation escape character * format _xHHHH_, where H represents a hexadecimal character in the character's value. * <p> * Example: The Unicode character 0D is invalid in an XML 1.0 document, * so it shall be escaped as <code>_x000D_</code>. * </p> * See section 3.18.9 in the OOXML spec. * @see org.apache.poi.xssf.usermodel.XSSFRichTextString#utfDecode(String) */ static String utfDecode(String value) { if (value == null || !value.contains("_x")) { return value; } StringBuilder buf = new StringBuilder(); Matcher m = UTF_PATTTERN.matcher(value); int idx = 0; while (m.find()) { int pos = m.start(); if (pos > idx) { buf.append(value, idx, pos); } String code = m.group(1); int icode = Integer.decode("0x" + code); buf.append((char)icode); idx = m.end(); } // small optimization: don't go via StringBuilder if not necessary, // the encodings are very rare, so we should almost always go via this shortcut. if (idx == 0) { return value; } buf.append(value.substring(idx)); return buf.toString(); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/analysis/v07/handlers/sax/XlsxRowHandler.java
package ai.chat2db.excel.analysis.v07.handlers.sax; import java.util.HashMap; import java.util.Map; import ai.chat2db.excel.constant.ExcelXmlConstants; import ai.chat2db.excel.analysis.v07.handlers.CellFormulaTagHandler; import ai.chat2db.excel.analysis.v07.handlers.CellInlineStringValueTagHandler; import ai.chat2db.excel.analysis.v07.handlers.CellTagHandler; import ai.chat2db.excel.analysis.v07.handlers.CellValueTagHandler; import ai.chat2db.excel.analysis.v07.handlers.CountTagHandler; import ai.chat2db.excel.analysis.v07.handlers.HyperlinkTagHandler; import ai.chat2db.excel.analysis.v07.handlers.MergeCellTagHandler; import ai.chat2db.excel.analysis.v07.handlers.RowTagHandler; import ai.chat2db.excel.analysis.v07.handlers.XlsxTagHandler; import ai.chat2db.excel.context.xlsx.XlsxReadContext; import lombok.extern.slf4j.Slf4j; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * @author jipengfei */ @Slf4j public class XlsxRowHandler extends DefaultHandler { private final XlsxReadContext xlsxReadContext; private static final Map<String, XlsxTagHandler> XLSX_CELL_HANDLER_MAP = new HashMap<>(64); static { CellFormulaTagHandler cellFormulaTagHandler = new CellFormulaTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.CELL_FORMULA_TAG, cellFormulaTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_CELL_FORMULA_TAG, cellFormulaTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_CELL_FORMULA_TAG, cellFormulaTagHandler); CellInlineStringValueTagHandler cellInlineStringValueTagHandler = new CellInlineStringValueTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.CELL_INLINE_STRING_VALUE_TAG, cellInlineStringValueTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_CELL_INLINE_STRING_VALUE_TAG, cellInlineStringValueTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_CELL_INLINE_STRING_VALUE_TAG, cellInlineStringValueTagHandler); CellTagHandler cellTagHandler = new CellTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.CELL_TAG, cellTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_CELL_TAG, cellTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_CELL_TAG, cellTagHandler); CellValueTagHandler cellValueTagHandler = new CellValueTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.CELL_VALUE_TAG, cellValueTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_CELL_VALUE_TAG, cellValueTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_CELL_VALUE_TAG, cellValueTagHandler); CountTagHandler countTagHandler = new CountTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.DIMENSION_TAG, countTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_DIMENSION_TAG, countTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_DIMENSION_TAG, countTagHandler); HyperlinkTagHandler hyperlinkTagHandler = new HyperlinkTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.HYPERLINK_TAG, hyperlinkTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_HYPERLINK_TAG, hyperlinkTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_HYPERLINK_TAG, hyperlinkTagHandler); MergeCellTagHandler mergeCellTagHandler = new MergeCellTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.MERGE_CELL_TAG, mergeCellTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_MERGE_CELL_TAG, mergeCellTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_MERGE_CELL_TAG, mergeCellTagHandler); RowTagHandler rowTagHandler = new RowTagHandler(); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.ROW_TAG, rowTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.X_ROW_TAG, rowTagHandler); XLSX_CELL_HANDLER_MAP.put(ExcelXmlConstants.NS2_ROW_TAG, rowTagHandler); } public XlsxRowHandler(XlsxReadContext xlsxReadContext) { this.xlsxReadContext = xlsxReadContext; } @Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { XlsxTagHandler handler = XLSX_CELL_HANDLER_MAP.get(name); if (handler == null || !handler.support(xlsxReadContext)) { return; } xlsxReadContext.xlsxReadSheetHolder().getTagDeque().push(name); handler.startElement(xlsxReadContext, name, attributes); } @Override public void characters(char[] ch, int start, int length) throws SAXException { String currentTag = xlsxReadContext.xlsxReadSheetHolder().getTagDeque().peek(); if (currentTag == null) { return; } XlsxTagHandler handler = XLSX_CELL_HANDLER_MAP.get(currentTag); if (handler == null || !handler.support(xlsxReadContext)) { return; } handler.characters(xlsxReadContext, ch, start, length); } @Override public void endElement(String uri, String localName, String name) throws SAXException { XlsxTagHandler handler = XLSX_CELL_HANDLER_MAP.get(name); if (handler == null || !handler.support(xlsxReadContext)) { return; } handler.endElement(xlsxReadContext, name); xlsxReadContext.xlsxReadSheetHolder().getTagDeque().pop(); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/ExcelIgnore.java
package ai.chat2db.excel.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Ignore convert excel * * @author Jiaju Zhuang */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ExcelIgnore {}
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/ExcelIgnoreUnannotated.java
package ai.chat2db.excel.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Ignore all unannotated fields. * * @author Jiaju Zhuang */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ExcelIgnoreUnannotated { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/ExcelProperty.java
package ai.chat2db.excel.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.converters.AutoConverter; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.annotation.format.DateTimeFormat; /** * @author jipengfei */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ExcelProperty { /** * The name of the sheet header. * * <p> * write: It automatically merges when you have more than one head * <p> * read: When you have multiple heads, take the last one * * @return The name of the sheet header */ String[] value() default {""}; /** * Index of column * * Read or write it on the index of column, If it's equal to -1, it's sorted by Java class. * * priority: index &gt; order &gt; default sort * * @return Index of column */ int index() default -1; /** * Defines the sort order for an column. * * priority: index &gt; order &gt; default sort * * @return Order of column */ int order() default Integer.MAX_VALUE; /** * Force the current field to use this converter. * * @return Converter */ Class<? extends Converter<?>> converter() default AutoConverter.class; /** * * default @see ai.chat2db.excel.util.TypeUtil if default is not meet you can set format * * @return Format string * @deprecated please use {@link DateTimeFormat} */ @Deprecated String format() default ""; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/format/DateTimeFormat.java
package ai.chat2db.excel.annotation.format; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.enums.BooleanEnum; /** * Convert date format. * * <p> * write: It can be used on classes {@link java.util.Date} * <p> * read: It can be used on classes {@link String} * * @author Jiaju Zhuang */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface DateTimeFormat { /** * * Specific format reference {@link java.text.SimpleDateFormat} * * @return Format pattern */ String value() default ""; /** * True if date uses 1904 windowing, or false if using 1900 date windowing. * * @return True if date uses 1904 windowing, or false if using 1900 date windowing. */ BooleanEnum use1904windowing() default BooleanEnum.DEFAULT; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/format/NumberFormat.java
package ai.chat2db.excel.annotation.format; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.math.RoundingMode; /** * Convert number format. * * <p> * write: It can be used on classes that inherit {@link Number} * <p> * read: It can be used on classes {@link String} * * @author Jiaju Zhuang */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface NumberFormat { /** * * Specific format reference {@link java.text.DecimalFormat} * * @return Format pattern */ String value() default ""; /** * Rounded by default * * @return RoundingMode */ RoundingMode roundingMode() default RoundingMode.HALF_UP; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/ColumnWidth.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Set the width of the table * * @author Jiaju Zhuang */ @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ColumnWidth { /** * Column width * <p> * -1 means the default column width is used * * @return Column width */ int value() default -1; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/ContentFontStyle.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.enums.BooleanEnum; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.hssf.usermodel.HSSFPalette; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.IndexedColors; /** * Custom content styles. * * @author Jiaju Zhuang */ @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ContentFontStyle { /** * The name for the font (i.e. Arial) */ String fontName() default ""; /** * Height in the familiar unit of measure - points */ short fontHeightInPoints() default -1; /** * Whether to use italics or not */ BooleanEnum italic() default BooleanEnum.DEFAULT; /** * Whether to use a strikeout horizontal line through the text or not */ BooleanEnum strikeout() default BooleanEnum.DEFAULT; /** * The color for the font * * @see Font#COLOR_NORMAL * @see Font#COLOR_RED * @see HSSFPalette#getColor(short) * @see IndexedColors */ short color() default -1; /** * Set normal, super or subscript. * * @see Font#SS_NONE * @see Font#SS_SUPER * @see Font#SS_SUB */ short typeOffset() default -1; /** * set type of text underlining to use * * @see Font#U_NONE * @see Font#U_SINGLE * @see Font#U_DOUBLE * @see Font#U_SINGLE_ACCOUNTING * @see Font#U_DOUBLE_ACCOUNTING */ byte underline() default -1; /** * Set character-set to use. * * @see FontCharset * @see Font#ANSI_CHARSET * @see Font#DEFAULT_CHARSET * @see Font#SYMBOL_CHARSET */ int charset() default -1; /** * Bold */ BooleanEnum bold() default BooleanEnum.DEFAULT; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/ContentLoopMerge.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * The regions of the loop merge * * @author Jiaju Zhuang */ @Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ContentLoopMerge { /** * Each row * * @return */ int eachRow() default 1; /** * Extend column * * @return */ int columnExtend() default 1; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/ContentRowHeight.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Set the height of each table * * @author Jiaju Zhuang */ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ContentRowHeight { /** * Set the content height * <p> * -1 mean the auto set height * * @return Content height */ short value() default -1; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/ContentStyle.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.enums.BooleanEnum; import ai.chat2db.excel.enums.poi.BorderStyleEnum; import ai.chat2db.excel.enums.poi.FillPatternTypeEnum; import ai.chat2db.excel.enums.poi.HorizontalAlignmentEnum; import ai.chat2db.excel.enums.poi.VerticalAlignmentEnum; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.usermodel.IndexedColors; /** * Custom content styles * * @author Jiaju Zhuang */ @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface ContentStyle { /** * Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. */ short dataFormat() default -1; /** * Set the cell's using this style to be hidden */ BooleanEnum hidden() default BooleanEnum.DEFAULT; /** * Set the cell's using this style to be locked */ BooleanEnum locked() default BooleanEnum.DEFAULT; /** * Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which * looks like a number or a formula shouldn't be treated as on. Turning this on is somewhat (but not completely, see * {@link IgnoredErrorType}) like prefixing the cell value with a ' in Excel */ BooleanEnum quotePrefix() default BooleanEnum.DEFAULT; /** * Set the type of horizontal alignment for the cell */ HorizontalAlignmentEnum horizontalAlignment() default HorizontalAlignmentEnum.DEFAULT; /** * Set whether the text should be wrapped. Setting this flag to <code>true</code> make all content visible within a * cell by displaying it on multiple lines * */ BooleanEnum wrapped() default BooleanEnum.DEFAULT; /** * Set the type of vertical alignment for the cell */ VerticalAlignmentEnum verticalAlignment() default VerticalAlignmentEnum.DEFAULT; /** * Set the degree of rotation for the text in the cell. * * Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The * implementations of this method will map between these two value-ranges accordingly, however the corresponding * getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is * applied to. */ short rotation() default -1; /** * Set the number of spaces to indent the text in the cell */ short indent() default -1; /** * Set the type of border to use for the left border of the cell */ BorderStyleEnum borderLeft() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the right border of the cell */ BorderStyleEnum borderRight() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the top border of the cell */ BorderStyleEnum borderTop() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the bottom border of the cell */ BorderStyleEnum borderBottom() default BorderStyleEnum.DEFAULT; /** * Set the color to use for the left border * * @see IndexedColors */ short leftBorderColor() default -1; /** * Set the color to use for the right border * * @see IndexedColors * */ short rightBorderColor() default -1; /** * Set the color to use for the top border * * @see IndexedColors * */ short topBorderColor() default -1; /** * Set the color to use for the bottom border * * @see IndexedColors * */ short bottomBorderColor() default -1; /** * Setting to one fills the cell with the foreground color... No idea about other values * * @see FillPatternType#SOLID_FOREGROUND */ FillPatternTypeEnum fillPatternType() default FillPatternTypeEnum.DEFAULT; /** * Set the background fill color. * * @see IndexedColors * */ short fillBackgroundColor() default -1; /** * Set the foreground fill color <i>Note: Ensure Foreground color is set prior to background color.</i> * * @see IndexedColors * */ short fillForegroundColor() default -1; /** * Controls if the Cell should be auto-sized to shrink to fit if the text is too long */ BooleanEnum shrinkToFit() default BooleanEnum.DEFAULT; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/HeadFontStyle.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.enums.BooleanEnum; import org.apache.poi.common.usermodel.fonts.FontCharset; import org.apache.poi.hssf.usermodel.HSSFPalette; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.IndexedColors; /** * Custom header styles. * * @author Jiaju Zhuang */ @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface HeadFontStyle { /** * The name for the font (i.e. Arial) */ String fontName() default ""; /** * Height in the familiar unit of measure - points */ short fontHeightInPoints() default -1; /** * Whether to use italics or not */ BooleanEnum italic() default BooleanEnum.DEFAULT; /** * Whether to use a strikeout horizontal line through the text or not */ BooleanEnum strikeout() default BooleanEnum.DEFAULT; /** * The color for the font * * @see Font#COLOR_NORMAL * @see Font#COLOR_RED * @see HSSFPalette#getColor(short) * @see IndexedColors */ short color() default -1; /** * Set normal, super or subscript. * * @see Font#SS_NONE * @see Font#SS_SUPER * @see Font#SS_SUB */ short typeOffset() default -1; /** * set type of text underlining to use * * @see Font#U_NONE * @see Font#U_SINGLE * @see Font#U_DOUBLE * @see Font#U_SINGLE_ACCOUNTING * @see Font#U_DOUBLE_ACCOUNTING */ byte underline() default -1; /** * Set character-set to use. * * @see FontCharset * @see Font#ANSI_CHARSET * @see Font#DEFAULT_CHARSET * @see Font#SYMBOL_CHARSET */ int charset() default -1; /** * Bold */ BooleanEnum bold() default BooleanEnum.DEFAULT; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/HeadRowHeight.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Set the height of each table * * @author Jiaju Zhuang */ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface HeadRowHeight { /** * Set the header height * <p> * -1 mean the auto set height * * @return Header height */ short value() default -1; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/HeadStyle.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import ai.chat2db.excel.enums.BooleanEnum; import ai.chat2db.excel.enums.poi.BorderStyleEnum; import ai.chat2db.excel.enums.poi.FillPatternTypeEnum; import ai.chat2db.excel.enums.poi.HorizontalAlignmentEnum; import ai.chat2db.excel.enums.poi.VerticalAlignmentEnum; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IgnoredErrorType; import org.apache.poi.ss.usermodel.IndexedColors; /** * Custom header styles * * @author Jiaju Zhuang */ @Target({ElementType.FIELD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface HeadStyle { /** * Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. */ short dataFormat() default -1; /** * Set the cell's using this style to be hidden */ BooleanEnum hidden() default BooleanEnum.DEFAULT; /** * Set the cell's using this style to be locked */ BooleanEnum locked() default BooleanEnum.DEFAULT; /** * Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which * looks like a number or a formula shouldn't be treated as on. Turning this on is somewhat (but not completely, see * {@link IgnoredErrorType}) like prefixing the cell value with a ' in Excel */ BooleanEnum quotePrefix() default BooleanEnum.DEFAULT; /** * Set the type of horizontal alignment for the cell */ HorizontalAlignmentEnum horizontalAlignment() default HorizontalAlignmentEnum.DEFAULT; /** * Set whether the text should be wrapped. Setting this flag to <code>true</code> make all content visible within a * cell by displaying it on multiple lines */ BooleanEnum wrapped() default BooleanEnum.DEFAULT; /** * Set the type of vertical alignment for the cell */ VerticalAlignmentEnum verticalAlignment() default VerticalAlignmentEnum.DEFAULT; /** * Set the degree of rotation for the text in the cell. * * Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The * implementations of this method will map between these two value-ranges accordingly, however the corresponding * getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is * applied to. */ short rotation() default -1; /** * Set the number of spaces to indent the text in the cell */ short indent() default -1; /** * Set the type of border to use for the left border of the cell */ BorderStyleEnum borderLeft() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the right border of the cell */ BorderStyleEnum borderRight() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the top border of the cell */ BorderStyleEnum borderTop() default BorderStyleEnum.DEFAULT; /** * Set the type of border to use for the bottom border of the cell */ BorderStyleEnum borderBottom() default BorderStyleEnum.DEFAULT; /** * Set the color to use for the left border * * @see IndexedColors */ short leftBorderColor() default -1; /** * Set the color to use for the right border * * @see IndexedColors */ short rightBorderColor() default -1; /** * Set the color to use for the top border * * @see IndexedColors */ short topBorderColor() default -1; /** * Set the color to use for the bottom border * * @see IndexedColors */ short bottomBorderColor() default -1; /** * Setting to one fills the cell with the foreground color... No idea about other values * * @see FillPatternType#SOLID_FOREGROUND */ FillPatternTypeEnum fillPatternType() default FillPatternTypeEnum.DEFAULT; /** * Set the background fill color. * * @see IndexedColors */ short fillBackgroundColor() default -1; /** * Set the foreground fill color <i>Note: Ensure Foreground color is set prior to background color.</i> * * @see IndexedColors */ short fillForegroundColor() default -1; /** * Controls if the Cell should be auto-sized to shrink to fit if the text is too long */ BooleanEnum shrinkToFit() default BooleanEnum.DEFAULT; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/annotation/write/style/OnceAbsoluteMerge.java
package ai.chat2db.excel.annotation.write.style; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Merge the cells once * * @author Jiaju Zhuang */ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface OnceAbsoluteMerge { /** * First row * * @return */ int firstRowIndex() default -1; /** * Last row * * @return */ int lastRowIndex() default -1; /** * First column * * @return */ int firstColumnIndex() default -1; /** * Last row * * @return */ int lastColumnIndex() default -1; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/Ehcache.java
package ai.chat2db.excel.cache; import java.io.File; import java.util.ArrayList; import java.util.UUID; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.util.FileUtils; import ai.chat2db.excel.util.ListUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.ehcache.CacheManager; import org.ehcache.config.CacheConfiguration; import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.CacheManagerBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder; import org.ehcache.config.units.EntryUnit; import org.ehcache.config.units.MemoryUnit; /** * Default cache * * @author Jiaju Zhuang */ @Slf4j public class Ehcache implements ReadCache { public static final int BATCH_COUNT = 100; /** * Key index */ private int activeIndex = 0; public static final int DEBUG_CACHE_MISS_SIZE = 1000; public static final int DEBUG_WRITE_SIZE = 100 * 10000; private ArrayList<String> dataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); private static final CacheManager FILE_CACHE_MANAGER; private static final CacheConfiguration<Integer, ArrayList> FILE_CACHE_CONFIGURATION; private static final CacheManager ACTIVE_CACHE_MANAGER; private static final File CACHE_PATH_FILE; private final CacheConfiguration<Integer, ArrayList> activeCacheConfiguration; /** * Bulk storage data */ private org.ehcache.Cache<Integer, ArrayList> fileCache; /** * Currently active cache */ private org.ehcache.Cache<Integer, ArrayList> activeCache; private String cacheAlias; /** * Count the number of cache misses */ private int cacheMiss = 0; @Deprecated public Ehcache(Integer maxCacheActivateSize) { this(maxCacheActivateSize, null); } public Ehcache(Integer maxCacheActivateSize, Integer maxCacheActivateBatchCount) { // In order to be compatible with the code // If the user set up `maxCacheActivateSize`, then continue using it if (maxCacheActivateSize != null) { this.activeCacheConfiguration = CacheConfigurationBuilder .newCacheConfigurationBuilder(Integer.class, ArrayList.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(maxCacheActivateSize, MemoryUnit.MB)) .build(); } else { this.activeCacheConfiguration = CacheConfigurationBuilder .newCacheConfigurationBuilder(Integer.class, ArrayList.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(maxCacheActivateBatchCount, EntryUnit.ENTRIES)) .build(); } } static { CACHE_PATH_FILE = FileUtils.createCacheTmpFile(); FILE_CACHE_MANAGER = CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(CACHE_PATH_FILE)).build( true); ACTIVE_CACHE_MANAGER = CacheManagerBuilder.newCacheManagerBuilder().build(true); FILE_CACHE_CONFIGURATION = CacheConfigurationBuilder .newCacheConfigurationBuilder(Integer.class, ArrayList.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .disk(20, MemoryUnit.GB)).build(); } @Override public void init(AnalysisContext analysisContext) { cacheAlias = UUID.randomUUID().toString(); try { fileCache = FILE_CACHE_MANAGER.createCache(cacheAlias, FILE_CACHE_CONFIGURATION); } catch (IllegalStateException e) { //fix Issue #2693,Temporary files may be deleted if there is no operation for a long time, so they need // to be recreated. if (CACHE_PATH_FILE.exists()) { throw e; } synchronized (Ehcache.class) { if (!CACHE_PATH_FILE.exists()) { if (log.isDebugEnabled()) { log.debug("cache file dir is not exist retry create"); } FileUtils.createDirectory(CACHE_PATH_FILE); } } fileCache = FILE_CACHE_MANAGER.createCache(cacheAlias, FILE_CACHE_CONFIGURATION); } activeCache = ACTIVE_CACHE_MANAGER.createCache(cacheAlias, activeCacheConfiguration); } @Override public void put(String value) { dataList.add(value); if (dataList.size() >= BATCH_COUNT) { fileCache.put(activeIndex, dataList); activeIndex++; dataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); } if (log.isDebugEnabled()) { int alreadyPut = activeIndex * BATCH_COUNT + dataList.size(); if (alreadyPut % DEBUG_WRITE_SIZE == 0) { log.debug("Already put :{}", alreadyPut); } } } @Override public String get(Integer key) { if (key == null || key < 0) { return null; } int route = key / BATCH_COUNT; ArrayList<String> dataList = activeCache.get(route); if (dataList == null) { dataList = fileCache.get(route); activeCache.put(route, dataList); if (log.isDebugEnabled()) { if (cacheMiss++ % DEBUG_CACHE_MISS_SIZE == 0) { log.debug("Cache misses count:{}", cacheMiss); } } } return dataList.get(key % BATCH_COUNT); } @Override public void putFinished() { if (CollectionUtils.isEmpty(dataList)) { return; } fileCache.put(activeIndex, dataList); } @Override public void destroy() { FILE_CACHE_MANAGER.removeCache(cacheAlias); ACTIVE_CACHE_MANAGER.removeCache(cacheAlias); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/MapCache.java
package ai.chat2db.excel.cache; import java.util.ArrayList; import java.util.List; import ai.chat2db.excel.context.AnalysisContext; /** * Putting temporary data directly into a map is a little more efficient but very memory intensive * * @author Jiaju Zhuang */ public class MapCache implements ReadCache { private final List<String> cache = new ArrayList<>(); @Override public void init(AnalysisContext analysisContext) {} @Override public void put(String value) { cache.add(value); } @Override public String get(Integer key) { if (key == null || key < 0) { return null; } return cache.get(key); } @Override public void putFinished() {} @Override public void destroy() {} }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/ReadCache.java
package ai.chat2db.excel.cache; import ai.chat2db.excel.context.AnalysisContext; /** * Read cache * * @author Jiaju Zhuang */ public interface ReadCache { /** * Initialize cache * * @param analysisContext * A context is the main anchorage point of a excel reader. */ void init(AnalysisContext analysisContext); /** * Automatically generate the key and put it in the cache.Key start from 0 * * @param value * Cache value */ void put(String value); /** * Get value * * @param key * Index * @return Value */ String get(Integer key); /** * It's called when all the values are put in */ void putFinished(); /** * Called when the excel read is complete */ void destroy(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/XlsCache.java
package ai.chat2db.excel.cache; import org.apache.poi.hssf.record.SSTRecord; import ai.chat2db.excel.context.AnalysisContext; /** * * Use SSTRecord. * * @author Jiaju Zhuang */ public class XlsCache implements ReadCache { private final SSTRecord sstRecord; public XlsCache(SSTRecord sstRecord) { this.sstRecord = sstRecord; } @Override public void init(AnalysisContext analysisContext) {} @Override public void put(String value) {} @Override public String get(Integer key) { return sstRecord.getString(key).toString(); } @Override public void putFinished() {} @Override public void destroy() {} }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/selector/EternalReadCacheSelector.java
package ai.chat2db.excel.cache.selector; import ai.chat2db.excel.cache.ReadCache; import org.apache.poi.openxml4j.opc.PackagePart; /** * Choose a eternal cache * * @author Jiaju Zhuang **/ public class EternalReadCacheSelector implements ReadCacheSelector { private ReadCache readCache; public EternalReadCacheSelector(ReadCache readCache) { this.readCache = readCache; } @Override public ReadCache readCache(PackagePart sharedStringsTablePackagePart) { return readCache; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/selector/ReadCacheSelector.java
package ai.chat2db.excel.cache.selector; import ai.chat2db.excel.cache.ReadCache; import org.apache.poi.openxml4j.opc.PackagePart; /** * Select the cache * * @author Jiaju Zhuang **/ public interface ReadCacheSelector { /** * Select a cache * * @param sharedStringsTablePackagePart * @return */ ReadCache readCache(PackagePart sharedStringsTablePackagePart); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/cache/selector/SimpleReadCacheSelector.java
package ai.chat2db.excel.cache.selector; import java.io.IOException; import ai.chat2db.excel.cache.Ehcache; import ai.chat2db.excel.cache.MapCache; import ai.chat2db.excel.cache.ReadCache; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import org.apache.poi.openxml4j.opc.PackagePart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Simple cache selector * * @author Jiaju Zhuang **/ @Getter @Setter @EqualsAndHashCode public class SimpleReadCacheSelector implements ReadCacheSelector { private static final Logger LOGGER = LoggerFactory.getLogger(SimpleReadCacheSelector.class); /** * Convert bytes to megabytes */ private static final long B2M = 1000 * 1000L; /** * If it's less than 5M, use map cache, or use ehcache.unit MB. */ private static final long DEFAULT_MAX_USE_MAP_CACHE_SIZE = 5; /** * Maximum batch of `SharedStrings` stored in memory. * The batch size is 100.{@link Ehcache#BATCH_COUNT} */ private static final int DEFAULT_MAX_EHCACHE_ACTIVATE_BATCH_COUNT = 20; /** * Shared strings exceeding this value will use {@link Ehcache},or use {@link MapCache}.unit MB. */ private Long maxUseMapCacheSize; /** * Maximum size of cache activation.unit MB. * * @deprecated Please use maxCacheActivateBatchCount to control the size of the occupied memory */ @Deprecated private Integer maxCacheActivateSize; /** * Maximum batch of `SharedStrings` stored in memory. * The batch size is 100.{@link Ehcache#BATCH_COUNT} */ private Integer maxCacheActivateBatchCount; public SimpleReadCacheSelector() { } /** * Parameter maxCacheActivateSize has already been abandoned * * @param maxUseMapCacheSize * @param maxCacheActivateSize */ @Deprecated public SimpleReadCacheSelector(Long maxUseMapCacheSize, Integer maxCacheActivateSize) { this.maxUseMapCacheSize = maxUseMapCacheSize; this.maxCacheActivateSize = maxCacheActivateSize; } @Override public ReadCache readCache(PackagePart sharedStringsTablePackagePart) { long size = sharedStringsTablePackagePart.getSize(); if (size < 0) { try { size = sharedStringsTablePackagePart.getInputStream().available(); } catch (IOException e) { LOGGER.warn("Unable to get file size, default used MapCache"); return new MapCache(); } } if (maxUseMapCacheSize == null) { maxUseMapCacheSize = DEFAULT_MAX_USE_MAP_CACHE_SIZE; } if (size < maxUseMapCacheSize * B2M) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Use map cache.size:{}", size); } return new MapCache(); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Use ehcache.size:{}", size); } // In order to be compatible with the code // If the user set up `maxCacheActivateSize`, then continue using it if (maxCacheActivateSize != null) { return new Ehcache(maxCacheActivateSize, maxCacheActivateBatchCount); } else { if (maxCacheActivateBatchCount == null) { maxCacheActivateBatchCount = DEFAULT_MAX_EHCACHE_ACTIVATE_BATCH_COUNT; } return new Ehcache(maxCacheActivateSize, maxCacheActivateBatchCount); } } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/constant/BuiltinFormats.java
package ai.chat2db.excel.constant; import java.util.Locale; import java.util.Map; import ai.chat2db.excel.util.MapUtils; import ai.chat2db.excel.util.StringUtils; /** * Excel's built-in format conversion.Currently only supports Chinese. * * <p> * If it is not Chinese, it is recommended to directly modify the builtinFormats, which will better support * internationalization in the future. * * <p> * Specific correspondence please see: * https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-2.8.1 * * @author Jiaju Zhuang **/ public class BuiltinFormats { private static final String RESERVED = "reserved-"; public static short GENERAL = 0; public static final String[] BUILTIN_FORMATS_ALL_LANGUAGES = { // 0 "General", // 1 "0", // 2 "0.00", // 3 "#,##0", // 4 "#,##0.00", // 5 "\"¥\"#,##0_);(\"¥\"#,##0)", // 6 "\"¥\"#,##0_);[Red](\"¥\"#,##0)", // 7 "\"¥\"#,##0.00_);(\"¥\"#,##0.00)", // 8 "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)", // 9 "0%", // 10 "0.00%", // 11 "0.00E+00", // 12 "# ?/?", // 13 "# ??/??", // 14 // The official documentation shows "m/d/yy", but the actual test is "yyyy/m/d". "yyyy/m/d", // 15 "d-mmm-yy", // 16 "d-mmm", // 17 "mmm-yy", // 18 "h:mm AM/PM", // 19 "h:mm:ss AM/PM", // 20 "h:mm", // 21 "h:mm:ss", // 22 // The official documentation shows "m/d/yy h:mm", but the actual test is "yyyy-m-d h:mm". "yyyy-m-d h:mm", // 23-36 No specific correspondence found in the official documentation. // 23 null, // 24 null, // 25 null, // 26 null, // 27 null, // 28 null, // 29 null, // 30 null, // 31 null, // 32 null, // 33 null, // 34 null, // 35 null, // 36 null, // 37 "#,##0_);(#,##0)", // 38 "#,##0_);[Red](#,##0)", // 39 "#,##0.00_);(#,##0.00)", // 40 "#,##0.00_);[Red](#,##0.00)", // 41 "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", // 42 "_(\"¥\"* #,##0_);_(\"¥\"* (#,##0);_(\"¥\"* \"-\"_);_(@_)", // 43 "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", // 44 "_(\"¥\"* #,##0.00_);_(\"¥\"* (#,##0.00);_(\"¥\"* \"-\"??_);_(@_)", // 45 "mm:ss", // 46 "[h]:mm:ss", // 47 "mm:ss.0", // 48 "##0.0E+0", // 49 "@", }; public static final String[] BUILTIN_FORMATS_CN = { // 0 "General", // 1 "0", // 2 "0.00", // 3 "#,##0", // 4 "#,##0.00", // 5 "\"¥\"#,##0_);(\"¥\"#,##0)", // 6 "\"¥\"#,##0_);[Red](\"¥\"#,##0)", // 7 "\"¥\"#,##0.00_);(\"¥\"#,##0.00)", // 8 "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)", // 9 "0%", // 10 "0.00%", // 11 "0.00E+00", // 12 "# ?/?", // 13 "# ??/??", // 14 // The official documentation shows "m/d/yy", but the actual test is "yyyy/m/d". "yyyy/m/d", // 15 "d-mmm-yy", // 16 "d-mmm", // 17 "mmm-yy", // 18 "h:mm AM/PM", // 19 "h:mm:ss AM/PM", // 20 "h:mm", // 21 "h:mm:ss", // 22 // The official documentation shows "m/d/yy h:mm", but the actual test is "yyyy-m-d h:mm". "yyyy-m-d h:mm", // 23-26 No specific correspondence found in the official documentation. // 23 null, // 24 null, // 25 null, // 26 null, // 27 "yyyy\"年\"m\"月\"", // 28 "m\"月\"d\"日\"", // 29 "m\"月\"d\"日\"", // 30 "m-d-yy", // 31 "yyyy\"年\"m\"月\"d\"日\"", // 32 "h\"时\"mm\"分\"", // 33 "h\"时\"mm\"分\"ss\"秒\"", // 34 "上午/下午h\"时\"mm\"分\"", // 35 "上午/下午h\"时\"mm\"分\"ss\"秒\"", // 36 "yyyy\"年\"m\"月\"", // 37 "#,##0_);(#,##0)", // 38 "#,##0_);[Red](#,##0)", // 39 "#,##0.00_);(#,##0.00)", // 40 "#,##0.00_);[Red](#,##0.00)", // 41 "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", // 42 "_(\"¥\"* #,##0_);_(\"¥\"* (#,##0);_(\"¥\"* \"-\"_);_(@_)", // 43 "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", // 44 "_(\"¥\"* #,##0.00_);_(\"¥\"* (#,##0.00);_(\"¥\"* \"-\"??_);_(@_)", // 45 "mm:ss", // 46 "[h]:mm:ss", // 47 "mm:ss.0", // 48 "##0.0E+0", // 49 "@", // 50 "yyyy\"年\"m\"月\"", // 51 "m\"月\"d\"日\"", // 52 "yyyy\"年\"m\"月\"", // 53 "m\"月\"d\"日\"", // 54 "m\"月\"d\"日\"", // 55 "上午/下午h\"时\"mm\"分\"", // 56 "上午/下午h\"时\"mm\"分\"ss\"秒\"", // 57 "yyyy\"年\"m\"月\"", // 58 "m\"月\"d\"日\"", // 59 "t0", // 60 "t0.00", // 61 "t#,##0", // 62 "t#,##0.00", // 63-66 No specific correspondence found in the official documentation. // 63 null, // 64 null, // 65 null, // 66 null, // 67 "t0%", // 68 "t0.00%", // 69 "t# ?/?", // 70 "t# ??/??", // 71 "ว/ด/ปปปป", // 72 "ว-ดดด-ปป", // 73 "ว-ดดด", // 74 "ดดด-ปป", // 75 "ช:นน", // 76 "ช:นน:ทท", // 77 "ว/ด/ปปปป ช:นน", // 78 "นน:ทท", // 79 "[ช]:นน:ทท", // 80 "นน:ทท.0", // 81 "d/m/bb", // end }; public static final String[] BUILTIN_FORMATS_US = { // 0 "General", // 1 "0", // 2 "0.00", // 3 "#,##0", // 4 "#,##0.00", // 5 "\"$\"#,##0_);(\"$\"#,##0)", // 6 "\"$\"#,##0_);[Red](\"$\"#,##0)", // 7 "\"$\"#,##0.00_);(\"$\"#,##0.00)", // 8 "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)", // 9 "0%", // 10 "0.00%", // 11 "0.00E+00", // 12 "# ?/?", // 13 "# ??/??", // 14 // The official documentation shows "m/d/yy", but the actual test is "yyyy/m/d". "yyyy/m/d", // 15 "d-mmm-yy", // 16 "d-mmm", // 17 "mmm-yy", // 18 "h:mm AM/PM", // 19 "h:mm:ss AM/PM", // 20 "h:mm", // 21 "h:mm:ss", // 22 // The official documentation shows "m/d/yy h:mm", but the actual test is "yyyy-m-d h:mm". "yyyy-m-d h:mm", // 23-26 No specific correspondence found in the official documentation. // 23 null, // 24 null, // 25 null, // 26 null, // 27 "yyyy\"年\"m\"月\"", // 28 "m\"月\"d\"日\"", // 29 "m\"月\"d\"日\"", // 30 "m-d-yy", // 31 "yyyy\"年\"m\"月\"d\"日\"", // 32 "h\"时\"mm\"分\"", // 33 "h\"时\"mm\"分\"ss\"秒\"", // 34 "上午/下午h\"时\"mm\"分\"", // 35 "上午/下午h\"时\"mm\"分\"ss\"秒\"", // 36 "yyyy\"年\"m\"月\"", // 37 "#,##0_);(#,##0)", // 38 "#,##0_);[Red](#,##0)", // 39 "#,##0.00_);(#,##0.00)", // 40 "#,##0.00_);[Red](#,##0.00)", // 41 "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", // 42 "_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)", // 43 "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", // 44 "_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)", // 45 "mm:ss", // 46 "[h]:mm:ss", // 47 "mm:ss.0", // 48 "##0.0E+0", // 49 "@", // 50 "yyyy\"年\"m\"月\"", // 51 "m\"月\"d\"日\"", // 52 "yyyy\"年\"m\"月\"", // 53 "m\"月\"d\"日\"", // 54 "m\"月\"d\"日\"", // 55 "上午/下午h\"时\"mm\"分\"", // 56 "上午/下午h\"时\"mm\"分\"ss\"秒\"", // 57 "yyyy\"年\"m\"月\"", // 58 "m\"月\"d\"日\"", // 59 "t0", // 60 "t0.00", // 61 "t#,##0", // 62 "t#,##0.00", // 63-66 No specific correspondence found in the official documentation. // 63 null, // 64 null, // 65 null, // 66 null, // 67 "t0%", // 68 "t0.00%", // 69 "t# ?/?", // 70 "t# ??/??", // 71 "ว/ด/ปปปป", // 72 "ว-ดดด-ปป", // 73 "ว-ดดด", // 74 "ดดด-ปป", // 75 "ช:นน", // 76 "ช:นน:ทท", // 77 "ว/ด/ปปปป ช:นน", // 78 "นน:ทท", // 79 "[ช]:นน:ทท", // 80 "นน:ทท.0", // 81 "d/m/bb", // end }; public static final Map<String, Short> BUILTIN_FORMATS_MAP_CN = buildMap(BUILTIN_FORMATS_CN); public static final Map<String, Short> BUILTIN_FORMATS_MAP_US = buildMap(BUILTIN_FORMATS_US); public static final short MIN_CUSTOM_DATA_FORMAT_INDEX = 82; public static String getBuiltinFormat(Short index, String defaultFormat, Locale locale) { if (index == null || index <= 0) { return defaultFormat; } // Give priority to checking if it is the default value for all languages if (index < BUILTIN_FORMATS_ALL_LANGUAGES.length) { String format = BUILTIN_FORMATS_ALL_LANGUAGES[index]; if (format != null) { return format; } } // In other cases, give priority to using the externally provided format if (!StringUtils.isEmpty(defaultFormat) && !defaultFormat.startsWith(RESERVED)) { return defaultFormat; } // Finally, try using the built-in format String[] builtinFormat = switchBuiltinFormats(locale); if (index >= builtinFormat.length) { return defaultFormat; } return builtinFormat[index]; } public static String[] switchBuiltinFormats(Locale locale) { if (locale != null && Locale.US.getCountry().equals(locale.getCountry())) { return BUILTIN_FORMATS_US; } return BUILTIN_FORMATS_CN; } public static Map<String, Short> switchBuiltinFormatsMap(Locale locale) { if (locale != null && Locale.US.getCountry().equals(locale.getCountry())) { return BUILTIN_FORMATS_MAP_US; } return BUILTIN_FORMATS_MAP_CN; } private static Map<String, Short> buildMap(String[] builtinFormats) { Map<String, Short> map = MapUtils.newHashMapWithExpectedSize(builtinFormats.length); for (int i = 0; i < builtinFormats.length; i++) { map.put(builtinFormats[i], (short)i); } return map; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/constant/EasyExcelConstants.java
package ai.chat2db.excel.constant; import java.math.MathContext; import java.math.RoundingMode; /** * Used to store constant * * @author Jiaju Zhuang */ public class EasyExcelConstants { /** * Excel by default with 15 to store Numbers, and the double in Java can use to store number 17, led to the accuracy * will be a problem. So you need to set up 15 to deal with precision */ public static final MathContext EXCEL_MATH_CONTEXT = new MathContext(15, RoundingMode.HALF_UP); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/constant/ExcelXmlConstants.java
package ai.chat2db.excel.constant; /** * @author jipengfei */ public class ExcelXmlConstants { public static final String DIMENSION_TAG = "dimension"; public static final String ROW_TAG = "row"; public static final String CELL_FORMULA_TAG = "f"; public static final String CELL_VALUE_TAG = "v"; /** * When the data is "inlineStr" his tag is "t" */ public static final String CELL_INLINE_STRING_VALUE_TAG = "t"; public static final String CELL_TAG = "c"; public static final String MERGE_CELL_TAG = "mergeCell"; public static final String HYPERLINK_TAG = "hyperlink"; public static final String X_DIMENSION_TAG = "x:dimension"; public static final String NS2_DIMENSION_TAG = "ns2:dimension"; public static final String X_ROW_TAG = "x:row"; public static final String NS2_ROW_TAG = "ns2:row"; public static final String X_CELL_FORMULA_TAG = "x:f"; public static final String NS2_CELL_FORMULA_TAG = "ns2:f"; public static final String X_CELL_VALUE_TAG = "x:v"; public static final String NS2_CELL_VALUE_TAG = "ns2:v"; /** * When the data is "inlineStr" his tag is "t" */ public static final String X_CELL_INLINE_STRING_VALUE_TAG = "x:t"; public static final String NS2_CELL_INLINE_STRING_VALUE_TAG = "ns2:t"; public static final String X_CELL_TAG = "x:c"; public static final String NS2_CELL_TAG = "ns2:c"; public static final String X_MERGE_CELL_TAG = "x:mergeCell"; public static final String NS2_MERGE_CELL_TAG = "ns2:mergeCell"; public static final String X_HYPERLINK_TAG = "x:hyperlink"; public static final String NS2_HYPERLINK_TAG = "ns2:hyperlink"; /** * s attribute */ public static final String ATTRIBUTE_S = "s"; /** * ref attribute */ public static final String ATTRIBUTE_REF = "ref"; /** * r attribute */ public static final String ATTRIBUTE_R = "r"; /** * t attribute */ public static final String ATTRIBUTE_T = "t"; /** * location attribute */ public static final String ATTRIBUTE_LOCATION = "location"; /** * rId attribute */ public static final String ATTRIBUTE_RID = "r:id"; /** * Cell range split */ public static final String CELL_RANGE_SPLIT = ":"; // The following is a constant read the `SharedStrings.xml` /** * text */ public static final String SHAREDSTRINGS_T_TAG = "t"; public static final String SHAREDSTRINGS_X_T_TAG = "x:t"; public static final String SHAREDSTRINGS_NS2_T_TAG = "ns2:t"; /** * SharedStringItem */ public static final String SHAREDSTRINGS_SI_TAG = "si"; public static final String SHAREDSTRINGS_X_SI_TAG = "x:si"; public static final String SHAREDSTRINGS_NS2_SI_TAG = "ns2:si"; /** * Mac 2016 2017 will have this extra field to ignore */ public static final String SHAREDSTRINGS_RPH_TAG = "rPh"; public static final String SHAREDSTRINGS_X_RPH_TAG = "x:rPh"; public static final String SHAREDSTRINGS_NS2_RPH_TAG = "ns2:rPh"; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/constant/OrderConstant.java
package ai.chat2db.excel.constant; /** * Order constant. * * @author Jiaju Zhuang */ public class OrderConstant { /** * The system's own style */ public static int DEFAULT_DEFINE_STYLE = -70000; /** * Annotation style definition */ public static int ANNOTATION_DEFINE_STYLE = -60000; /** * Define style. */ public static final int DEFINE_STYLE = -50000; /** * default order. */ public static int DEFAULT_ORDER = 0; /** * Sorting of styles written to cells. */ public static int FILL_STYLE = 50000; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/AnalysisContext.java
package ai.chat2db.excel.context; import java.io.InputStream; import java.util.List; import ai.chat2db.excel.event.AnalysisEventListener; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.holder.ReadHolder; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.ReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.ReadWorkbookHolder; import ai.chat2db.excel.read.processor.AnalysisEventProcessor; import ai.chat2db.excel.support.ExcelTypeEnum; /** * * A context is the main anchorage point of a excel reader. * * @author jipengfei */ public interface AnalysisContext { /** * Select the current table * * @param readSheet * sheet to read */ void currentSheet(ReadSheet readSheet); /** * All information about the workbook you are currently working on * * @return Current workbook holder */ ReadWorkbookHolder readWorkbookHolder(); /** * All information about the sheet you are currently working on * * @return Current sheet holder */ ReadSheetHolder readSheetHolder(); /** * Set row of currently operated cell * * @param readRowHolder * Current row holder */ void readRowHolder(ReadRowHolder readRowHolder); /** * Row of currently operated cell * * @return Current row holder */ ReadRowHolder readRowHolder(); /** * The current read operation corresponds to the <code>readSheetHolder</code> or <code>readWorkbookHolder</code> * * @return Current holder */ ReadHolder currentReadHolder(); /** * Custom attribute * * @return */ Object getCustom(); /** * Event processor * * @return */ AnalysisEventProcessor analysisEventProcessor(); /** * Data that the customer needs to read * * @return */ List<ReadSheet> readSheetList(); /** * Data that the customer needs to read * * @param readSheetList */ void readSheetList(List<ReadSheet> readSheetList); /** * * get excel type * * @return excel type * @deprecated please use {@link #readWorkbookHolder()} */ @Deprecated ExcelTypeEnum getExcelType(); /** * get in io * * @return file io * @deprecated please use {@link #readWorkbookHolder()} */ @Deprecated InputStream getInputStream(); /** * get current row * * @return * @deprecated please use {@link #readRowHolder()} */ @Deprecated Integer getCurrentRowNum(); /** * get total row ,Data may be inaccurate * * @return * @deprecated please use {@link #readRowHolder()} */ @Deprecated Integer getTotalCount(); /** * get current result * * @return get current result * @deprecated please use {@link #readRowHolder()} */ @Deprecated Object getCurrentRowAnalysisResult(); /** * Interrupt execution * * @deprecated please use {@link AnalysisEventListener#hasNext(AnalysisContext)} */ @Deprecated void interrupt(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/AnalysisContextImpl.java
package ai.chat2db.excel.context; import java.io.InputStream; import java.util.List; import ai.chat2db.excel.exception.ExcelAnalysisException; import ai.chat2db.excel.read.metadata.ReadSheet; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.read.metadata.holder.ReadHolder; import ai.chat2db.excel.read.metadata.holder.ReadRowHolder; import ai.chat2db.excel.read.metadata.holder.ReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.ReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder; import ai.chat2db.excel.read.processor.AnalysisEventProcessor; import ai.chat2db.excel.read.processor.DefaultAnalysisEventProcessor; import ai.chat2db.excel.support.ExcelTypeEnum; import lombok.extern.slf4j.Slf4j; /** * @author jipengfei */ @Slf4j public class AnalysisContextImpl implements AnalysisContext { /** * The Workbook currently written */ private ReadWorkbookHolder readWorkbookHolder; /** * Current sheet holder */ private ReadSheetHolder readSheetHolder; /** * Current row holder */ private ReadRowHolder readRowHolder; /** * Configuration of currently operated cell */ private ReadHolder currentReadHolder; /** * Event processor */ private final AnalysisEventProcessor analysisEventProcessor; public AnalysisContextImpl(ReadWorkbook readWorkbook, ExcelTypeEnum actualExcelType) { if (readWorkbook == null) { throw new IllegalArgumentException("Workbook argument cannot be null"); } switch (actualExcelType) { case XLS: readWorkbookHolder = new XlsReadWorkbookHolder(readWorkbook); break; case XLSX: readWorkbookHolder = new XlsxReadWorkbookHolder(readWorkbook); break; case CSV: readWorkbookHolder = new CsvReadWorkbookHolder(readWorkbook); break; default: break; } currentReadHolder = readWorkbookHolder; analysisEventProcessor = new DefaultAnalysisEventProcessor(); if (log.isDebugEnabled()) { log.debug("Initialization 'AnalysisContextImpl' complete"); } } @Override public void currentSheet(ReadSheet readSheet) { switch (readWorkbookHolder.getExcelType()) { case XLS: readSheetHolder = new XlsReadSheetHolder(readSheet, readWorkbookHolder); break; case XLSX: readSheetHolder = new XlsxReadSheetHolder(readSheet, readWorkbookHolder); break; case CSV: readSheetHolder = new CsvReadSheetHolder(readSheet, readWorkbookHolder); break; default: break; } currentReadHolder = readSheetHolder; if (readWorkbookHolder.getHasReadSheet().contains(readSheetHolder.getSheetNo())) { throw new ExcelAnalysisException("Cannot read sheet repeatedly."); } readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo()); if (log.isDebugEnabled()) { log.debug("Began to read:{}", readSheetHolder); } } @Override public ReadWorkbookHolder readWorkbookHolder() { return readWorkbookHolder; } @Override public ReadSheetHolder readSheetHolder() { return readSheetHolder; } @Override public ReadRowHolder readRowHolder() { return readRowHolder; } @Override public void readRowHolder(ReadRowHolder readRowHolder) { this.readRowHolder = readRowHolder; } @Override public ReadHolder currentReadHolder() { return currentReadHolder; } @Override public Object getCustom() { return readWorkbookHolder.getCustomObject(); } @Override public AnalysisEventProcessor analysisEventProcessor() { return analysisEventProcessor; } @Override public List<ReadSheet> readSheetList() { return null; } @Override public void readSheetList(List<ReadSheet> readSheetList) { } @Override public ExcelTypeEnum getExcelType() { return readWorkbookHolder.getExcelType(); } @Override public InputStream getInputStream() { return readWorkbookHolder.getInputStream(); } @Override public Integer getCurrentRowNum() { return readRowHolder.getRowIndex(); } @Override public Integer getTotalCount() { return readSheetHolder.getTotal(); } @Override public Object getCurrentRowAnalysisResult() { return readRowHolder.getCurrentRowAnalysisResult(); } @Override public void interrupt() { throw new ExcelAnalysisException("interrupt error"); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/WriteContext.java
package ai.chat2db.excel.context; import java.io.OutputStream; import ai.chat2db.excel.enums.WriteTypeEnum; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import ai.chat2db.excel.write.metadata.WriteSheet; import ai.chat2db.excel.write.metadata.WriteTable; import ai.chat2db.excel.write.metadata.holder.WriteHolder; import ai.chat2db.excel.write.metadata.holder.WriteSheetHolder; import ai.chat2db.excel.write.metadata.holder.WriteTableHolder; import ai.chat2db.excel.write.metadata.holder.WriteWorkbookHolder; /** * Write context * * @author jipengfei */ public interface WriteContext { /** * If the current sheet already exists, select it; if not, create it * * @param writeSheet * Current sheet * @param writeType */ void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType); /** * If the current table already exists, select it; if not, create it * * @param writeTable */ void currentTable(WriteTable writeTable); /** * All information about the workbook you are currently working on * * @return */ WriteWorkbookHolder writeWorkbookHolder(); /** * All information about the sheet you are currently working on * * @return */ WriteSheetHolder writeSheetHolder(); /** * All information about the table you are currently working on * * @return */ WriteTableHolder writeTableHolder(); /** * Configuration of currently operated cell. May be 'writeSheetHolder' or 'writeTableHolder' or * 'writeWorkbookHolder' * * @return */ WriteHolder currentWriteHolder(); /** * close * * @param onException */ void finish(boolean onException); /** * Current sheet * * @return * @deprecated please us e{@link #writeSheetHolder()} */ @Deprecated Sheet getCurrentSheet(); /** * Need head * * @return * @deprecated please us e{@link #writeSheetHolder()} */ @Deprecated boolean needHead(); /** * Get outputStream * * @return * @deprecated please us e{@link #writeWorkbookHolder()} ()} */ @Deprecated OutputStream getOutputStream(); /** * Get workbook * * @return * @deprecated please us e{@link #writeWorkbookHolder()} ()} */ @Deprecated Workbook getWorkbook(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/WriteContextImpl.java
package ai.chat2db.excel.context; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Map; import java.util.UUID; import ai.chat2db.excel.enums.WriteTypeEnum; import ai.chat2db.excel.exception.ExcelGenerateException; import ai.chat2db.excel.metadata.CellRange; import ai.chat2db.excel.metadata.Head; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; import ai.chat2db.excel.write.handler.context.CellWriteHandlerContext; import ai.chat2db.excel.write.handler.context.RowWriteHandlerContext; import ai.chat2db.excel.write.handler.context.SheetWriteHandlerContext; import ai.chat2db.excel.write.handler.context.WorkbookWriteHandlerContext; import ai.chat2db.excel.support.ExcelTypeEnum; import ai.chat2db.excel.util.ClassUtils; import ai.chat2db.excel.util.DateUtils; import ai.chat2db.excel.util.FileUtils; import ai.chat2db.excel.util.ListUtils; import ai.chat2db.excel.util.NumberDataFormatterUtils; import ai.chat2db.excel.util.StringUtils; import ai.chat2db.excel.util.WorkBookUtil; import ai.chat2db.excel.util.WriteHandlerUtils; import ai.chat2db.excel.write.metadata.WriteSheet; import ai.chat2db.excel.write.metadata.WriteTable; import ai.chat2db.excel.write.metadata.WriteWorkbook; import ai.chat2db.excel.write.metadata.holder.WriteHolder; import ai.chat2db.excel.write.metadata.holder.WriteSheetHolder; import ai.chat2db.excel.write.metadata.holder.WriteTableHolder; import ai.chat2db.excel.write.metadata.holder.WriteWorkbookHolder; import ai.chat2db.excel.write.property.ExcelWriteHeadProperty; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.crypt.EncryptionMode; import org.apache.poi.poifs.crypt.Encryptor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A context is the main anchorage point of a excel writer. * * @author jipengfei */ public class WriteContextImpl implements WriteContext { private static final Logger LOGGER = LoggerFactory.getLogger(WriteContextImpl.class); private static final String NO_SHEETS = "no sheets"; /** * The Workbook currently written */ private WriteWorkbookHolder writeWorkbookHolder; /** * Current sheet holder */ private WriteSheetHolder writeSheetHolder; /** * The table currently written */ private WriteTableHolder writeTableHolder; /** * Configuration of currently operated cell */ private WriteHolder currentWriteHolder; /** * Prevent multiple shutdowns */ private boolean finished = false; public WriteContextImpl(WriteWorkbook writeWorkbook) { if (writeWorkbook == null) { throw new IllegalArgumentException("Workbook argument cannot be null"); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Begin to Initialization 'WriteContextImpl'"); } initCurrentWorkbookHolder(writeWorkbook); WorkbookWriteHandlerContext workbookWriteHandlerContext = WriteHandlerUtils.createWorkbookWriteHandlerContext( this); WriteHandlerUtils.beforeWorkbookCreate(workbookWriteHandlerContext); try { WorkBookUtil.createWorkBook(writeWorkbookHolder); } catch (Exception e) { throw new ExcelGenerateException("Create workbook failure", e); } WriteHandlerUtils.afterWorkbookCreate(workbookWriteHandlerContext); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Initialization 'WriteContextImpl' complete"); } } private void initCurrentWorkbookHolder(WriteWorkbook writeWorkbook) { writeWorkbookHolder = new WriteWorkbookHolder(writeWorkbook); currentWriteHolder = writeWorkbookHolder; if (LOGGER.isDebugEnabled()) { LOGGER.debug("CurrentConfiguration is writeWorkbookHolder"); } } /** * @param writeSheet */ @Override public void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType) { if (writeSheet == null) { throw new IllegalArgumentException("Sheet argument cannot be null"); } if (selectSheetFromCache(writeSheet)) { return; } initCurrentSheetHolder(writeSheet); // Workbook handler need to supplementary execution WorkbookWriteHandlerContext workbookWriteHandlerContext = WriteHandlerUtils.createWorkbookWriteHandlerContext( this); WriteHandlerUtils.beforeWorkbookCreate(workbookWriteHandlerContext, true); WriteHandlerUtils.afterWorkbookCreate(workbookWriteHandlerContext, true); // Initialization current sheet initSheet(writeType); } private boolean selectSheetFromCache(WriteSheet writeSheet) { writeSheetHolder = null; Integer sheetNo = writeSheet.getSheetNo(); if (sheetNo == null && StringUtils.isEmpty(writeSheet.getSheetName())) { sheetNo = 0; } if (sheetNo != null) { writeSheetHolder = writeWorkbookHolder.getHasBeenInitializedSheetIndexMap().get(sheetNo); } if (writeSheetHolder == null && !StringUtils.isEmpty(writeSheet.getSheetName())) { writeSheetHolder = writeWorkbookHolder.getHasBeenInitializedSheetNameMap().get(writeSheet.getSheetName()); } if (writeSheetHolder == null) { return false; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Sheet:{},{} is already existed", writeSheet.getSheetNo(), writeSheet.getSheetName()); } writeSheetHolder.setNewInitialization(Boolean.FALSE); writeTableHolder = null; currentWriteHolder = writeSheetHolder; if (LOGGER.isDebugEnabled()) { LOGGER.debug("CurrentConfiguration is writeSheetHolder"); } return true; } private void initCurrentSheetHolder(WriteSheet writeSheet) { writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder); writeTableHolder = null; currentWriteHolder = writeSheetHolder; if (LOGGER.isDebugEnabled()) { LOGGER.debug("CurrentConfiguration is writeSheetHolder"); } } private void initSheet(WriteTypeEnum writeType) { SheetWriteHandlerContext sheetWriteHandlerContext = WriteHandlerUtils.createSheetWriteHandlerContext(this); WriteHandlerUtils.beforeSheetCreate(sheetWriteHandlerContext); Sheet currentSheet; try { if (writeSheetHolder.getSheetNo() != null) { // When the add default sort order of appearance if (WriteTypeEnum.ADD.equals(writeType) && writeWorkbookHolder.getTempTemplateInputStream() == null) { currentSheet = createSheet(); } else { currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo()); writeSheetHolder .setCachedSheet( writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo())); } } else { // sheet name must not null currentSheet = writeWorkbookHolder.getWorkbook().getSheet(writeSheetHolder.getSheetName()); writeSheetHolder .setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheet(writeSheetHolder.getSheetName())); } } catch (IllegalArgumentException e) { if (e.getMessage() != null && e.getMessage().contains(NO_SHEETS)) { currentSheet = createSheet(); } else { throw e; } } if (currentSheet == null) { currentSheet = createSheet(); } writeSheetHolder.setSheet(currentSheet); WriteHandlerUtils.afterSheetCreate(sheetWriteHandlerContext); if (WriteTypeEnum.ADD.equals(writeType)) { // Initialization head initHead(writeSheetHolder.excelWriteHeadProperty()); } writeWorkbookHolder.getHasBeenInitializedSheetIndexMap().put(writeSheetHolder.getSheetNo(), writeSheetHolder); writeWorkbookHolder.getHasBeenInitializedSheetNameMap().put(writeSheetHolder.getSheetName(), writeSheetHolder); } private Sheet createSheet() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Can not find sheet:{} ,now create it", writeSheetHolder.getSheetNo()); } if (StringUtils.isEmpty(writeSheetHolder.getSheetName())) { writeSheetHolder.setSheetName(writeSheetHolder.getSheetNo().toString()); } Sheet currentSheet = WorkBookUtil.createSheet(writeWorkbookHolder.getWorkbook(), writeSheetHolder.getSheetName()); writeSheetHolder.setCachedSheet(currentSheet); return currentSheet; } public void initHead(ExcelWriteHeadProperty excelWriteHeadProperty) { if (!currentWriteHolder.needHead() || !currentWriteHolder.excelWriteHeadProperty().hasHead()) { return; } int newRowIndex = writeSheetHolder.getNewRowIndexAndStartDoWrite(); newRowIndex += currentWriteHolder.relativeHeadRowIndex(); // Combined head if (currentWriteHolder.automaticMergeHead()) { addMergedRegionToCurrentSheet(excelWriteHeadProperty, newRowIndex); } for (int relativeRowIndex = 0, i = newRowIndex; i < excelWriteHeadProperty.getHeadRowNumber() + newRowIndex; i++, relativeRowIndex++) { RowWriteHandlerContext rowWriteHandlerContext = WriteHandlerUtils.createRowWriteHandlerContext(this, newRowIndex, relativeRowIndex, Boolean.TRUE); WriteHandlerUtils.beforeRowCreate(rowWriteHandlerContext); Row row = WorkBookUtil.createRow(writeSheetHolder.getSheet(), i); rowWriteHandlerContext.setRow(row); WriteHandlerUtils.afterRowCreate(rowWriteHandlerContext); addOneRowOfHeadDataToExcel(row, i, excelWriteHeadProperty.getHeadMap(), relativeRowIndex); WriteHandlerUtils.afterRowDispose(rowWriteHandlerContext); } } private void addMergedRegionToCurrentSheet(ExcelWriteHeadProperty excelWriteHeadProperty, int rowIndex) { for (CellRange cellRangeModel : excelWriteHeadProperty.headCellRangeList()) { writeSheetHolder.getSheet() .addMergedRegionUnsafe(new CellRangeAddress(cellRangeModel.getFirstRow() + rowIndex, cellRangeModel.getLastRow() + rowIndex, cellRangeModel.getFirstCol(), cellRangeModel.getLastCol())); } } private void addOneRowOfHeadDataToExcel(Row row, Integer rowIndex, Map<Integer, Head> headMap, int relativeRowIndex) { for (Map.Entry<Integer, Head> entry : headMap.entrySet()) { Head head = entry.getValue(); int columnIndex = entry.getKey(); ExcelContentProperty excelContentProperty = ClassUtils.declaredExcelContentProperty(null, currentWriteHolder.excelWriteHeadProperty().getHeadClazz(), head.getFieldName(), currentWriteHolder); CellWriteHandlerContext cellWriteHandlerContext = WriteHandlerUtils.createCellWriteHandlerContext(this, row, rowIndex, head, columnIndex, relativeRowIndex, Boolean.TRUE, excelContentProperty); WriteHandlerUtils.beforeCellCreate(cellWriteHandlerContext); Cell cell = row.createCell(columnIndex); cellWriteHandlerContext.setCell(cell); WriteHandlerUtils.afterCellCreate(cellWriteHandlerContext); WriteCellData<String> writeCellData = new WriteCellData<>(head.getHeadNameList().get(relativeRowIndex)); cell.setCellValue(writeCellData.getStringValue()); cellWriteHandlerContext.setCellDataList(ListUtils.newArrayList(writeCellData)); cellWriteHandlerContext.setFirstCellData(writeCellData); WriteHandlerUtils.afterCellDispose(cellWriteHandlerContext); } } @Override public void currentTable(WriteTable writeTable) { if (writeTable == null) { return; } if (writeTable.getTableNo() == null || writeTable.getTableNo() <= 0) { writeTable.setTableNo(0); } if (writeSheetHolder.getHasBeenInitializedTable().containsKey(writeTable.getTableNo())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Table:{} is already existed", writeTable.getTableNo()); } writeTableHolder = writeSheetHolder.getHasBeenInitializedTable().get(writeTable.getTableNo()); writeTableHolder.setNewInitialization(Boolean.FALSE); currentWriteHolder = writeTableHolder; if (LOGGER.isDebugEnabled()) { LOGGER.debug("CurrentConfiguration is writeTableHolder"); } return; } initCurrentTableHolder(writeTable); // Workbook and sheet handler need to supplementary execution WorkbookWriteHandlerContext workbookWriteHandlerContext = WriteHandlerUtils.createWorkbookWriteHandlerContext( this); WriteHandlerUtils.beforeWorkbookCreate(workbookWriteHandlerContext, true); WriteHandlerUtils.afterWorkbookCreate(workbookWriteHandlerContext, true); SheetWriteHandlerContext sheetWriteHandlerContext = WriteHandlerUtils.createSheetWriteHandlerContext(this); WriteHandlerUtils.beforeSheetCreate(sheetWriteHandlerContext, true); WriteHandlerUtils.afterSheetCreate(sheetWriteHandlerContext, true); initHead(writeTableHolder.excelWriteHeadProperty()); } private void initCurrentTableHolder(WriteTable writeTable) { writeTableHolder = new WriteTableHolder(writeTable, writeSheetHolder); writeSheetHolder.getHasBeenInitializedTable().put(writeTable.getTableNo(), writeTableHolder); currentWriteHolder = writeTableHolder; if (LOGGER.isDebugEnabled()) { LOGGER.debug("CurrentConfiguration is writeTableHolder"); } } @Override public WriteWorkbookHolder writeWorkbookHolder() { return writeWorkbookHolder; } @Override public WriteSheetHolder writeSheetHolder() { return writeSheetHolder; } @Override public WriteTableHolder writeTableHolder() { return writeTableHolder; } @Override public WriteHolder currentWriteHolder() { return currentWriteHolder; } @Override public void finish(boolean onException) { if (finished) { return; } finished = true; WriteHandlerUtils.afterWorkbookDispose(writeWorkbookHolder.getWorkbookWriteHandlerContext()); if (writeWorkbookHolder == null) { return; } Throwable throwable = null; boolean isOutputStreamEncrypt = false; // Determine if you need to write excel boolean writeExcel = !onException; if (writeWorkbookHolder.getWriteExcelOnException()) { writeExcel = Boolean.TRUE; } // No data is written if an exception is thrown if (writeExcel) { try { isOutputStreamEncrypt = doOutputStreamEncrypt07(); } catch (Throwable t) { throwable = t; } } if (!isOutputStreamEncrypt) { try { if (writeExcel) { writeWorkbookHolder.getWorkbook().write(writeWorkbookHolder.getOutputStream()); } writeWorkbookHolder.getWorkbook().close(); } catch (Throwable t) { throwable = t; } } try { Workbook workbook = writeWorkbookHolder.getWorkbook(); if (workbook instanceof SXSSFWorkbook) { ((SXSSFWorkbook)workbook).dispose(); } } catch (Throwable t) { throwable = t; } try { if (writeWorkbookHolder.getAutoCloseStream() && writeWorkbookHolder.getOutputStream() != null) { writeWorkbookHolder.getOutputStream().close(); } } catch (Throwable t) { throwable = t; } if (writeExcel && !isOutputStreamEncrypt) { try { doFileEncrypt07(); } catch (Throwable t) { throwable = t; } } try { if (writeWorkbookHolder.getTempTemplateInputStream() != null) { writeWorkbookHolder.getTempTemplateInputStream().close(); } } catch (Throwable t) { throwable = t; } clearEncrypt03(); removeThreadLocalCache(); if (throwable != null) { throw new ExcelGenerateException("Can not close IO.", throwable); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Finished write."); } } private void removeThreadLocalCache() { NumberDataFormatterUtils.removeThreadLocalCache(); DateUtils.removeThreadLocalCache(); ClassUtils.removeThreadLocalCache(); } @Override public Sheet getCurrentSheet() { return writeSheetHolder.getSheet(); } @Override public boolean needHead() { return writeSheetHolder.needHead(); } @Override public OutputStream getOutputStream() { return writeWorkbookHolder.getOutputStream(); } @Override public Workbook getWorkbook() { return writeWorkbookHolder.getWorkbook(); } private void clearEncrypt03() { if (StringUtils.isEmpty(writeWorkbookHolder.getPassword()) || !ExcelTypeEnum.XLS.equals(writeWorkbookHolder.getExcelType())) { return; } Biff8EncryptionKey.setCurrentUserPassword(null); } /** * To encrypt */ private boolean doOutputStreamEncrypt07() throws Exception { if (StringUtils.isEmpty(writeWorkbookHolder.getPassword()) || !ExcelTypeEnum.XLSX.equals(writeWorkbookHolder.getExcelType())) { return false; } if (writeWorkbookHolder.getFile() != null) { return false; } File tempXlsx = FileUtils.createTmpFile(UUID.randomUUID() + ".xlsx"); FileOutputStream tempFileOutputStream = new FileOutputStream(tempXlsx); try { writeWorkbookHolder.getWorkbook().write(tempFileOutputStream); } finally { try { writeWorkbookHolder.getWorkbook().close(); tempFileOutputStream.close(); } catch (Exception e) { if (!tempXlsx.delete()) { throw new ExcelGenerateException("Can not delete temp File!"); } throw e; } } try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(tempXlsx)) { fileSystem.writeFilesystem(writeWorkbookHolder.getOutputStream()); } finally { if (!tempXlsx.delete()) { throw new ExcelGenerateException("Can not delete temp File!"); } } return true; } /** * To encrypt */ private void doFileEncrypt07() throws Exception { if (StringUtils.isEmpty(writeWorkbookHolder.getPassword()) || !ExcelTypeEnum.XLSX.equals(writeWorkbookHolder.getExcelType())) { return; } if (writeWorkbookHolder.getFile() == null) { return; } try (POIFSFileSystem fileSystem = openFileSystemAndEncrypt(writeWorkbookHolder.getFile()); FileOutputStream fileOutputStream = new FileOutputStream(writeWorkbookHolder.getFile())) { fileSystem.writeFilesystem(fileOutputStream); } } private POIFSFileSystem openFileSystemAndEncrypt(File file) throws Exception { POIFSFileSystem fileSystem = new POIFSFileSystem(); Encryptor encryptor = new EncryptionInfo(EncryptionMode.standard).getEncryptor(); encryptor.confirmPassword(writeWorkbookHolder.getPassword()); try (OPCPackage opcPackage = OPCPackage.open(file, PackageAccess.READ_WRITE); OutputStream outputStream = encryptor.getDataStream(fileSystem)) { opcPackage.save(outputStream); } return fileSystem; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/csv/CsvReadContext.java
package ai.chat2db.excel.context.csv; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; /** * A context is the main anchorage point of a ls xls reader. * * @author Jiaju Zhuang **/ public interface CsvReadContext extends AnalysisContext { /** * All information about the workbook you are currently working on. * * @return Current workbook holder */ CsvReadWorkbookHolder csvReadWorkbookHolder(); /** * All information about the sheet you are currently working on. * * @return Current sheet holder */ CsvReadSheetHolder csvReadSheetHolder(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/csv/DefaultCsvReadContext.java
package ai.chat2db.excel.context.csv; import ai.chat2db.excel.context.AnalysisContextImpl; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; import ai.chat2db.excel.support.ExcelTypeEnum; /** * A context is the main anchorage point of a ls xls reader. * * @author Jiaju Zhuang */ public class DefaultCsvReadContext extends AnalysisContextImpl implements CsvReadContext { public DefaultCsvReadContext(ReadWorkbook readWorkbook, ExcelTypeEnum actualExcelType) { super(readWorkbook, actualExcelType); } @Override public CsvReadWorkbookHolder csvReadWorkbookHolder() { return (CsvReadWorkbookHolder)readWorkbookHolder(); } @Override public CsvReadSheetHolder csvReadSheetHolder() { return (CsvReadSheetHolder)readSheetHolder(); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/xls/DefaultXlsReadContext.java
package ai.chat2db.excel.context.xls; import ai.chat2db.excel.context.AnalysisContextImpl; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; import ai.chat2db.excel.support.ExcelTypeEnum; /** * * A context is the main anchorage point of a ls xls reader. * * @author Jiaju Zhuang */ public class DefaultXlsReadContext extends AnalysisContextImpl implements XlsReadContext { public DefaultXlsReadContext(ReadWorkbook readWorkbook, ExcelTypeEnum actualExcelType) { super(readWorkbook, actualExcelType); } @Override public XlsReadWorkbookHolder xlsReadWorkbookHolder() { return (XlsReadWorkbookHolder)readWorkbookHolder(); } @Override public XlsReadSheetHolder xlsReadSheetHolder() { return (XlsReadSheetHolder)readSheetHolder(); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/xls/XlsReadContext.java
package ai.chat2db.excel.context.xls; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xls.XlsReadWorkbookHolder; /** * A context is the main anchorage point of a ls xls reader. * * @author Jiaju Zhuang **/ public interface XlsReadContext extends AnalysisContext { /** * All information about the workbook you are currently working on. * * @return Current workbook holder */ XlsReadWorkbookHolder xlsReadWorkbookHolder(); /** * All information about the sheet you are currently working on. * * @return Current sheet holder */ XlsReadSheetHolder xlsReadSheetHolder(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/xlsx/DefaultXlsxReadContext.java
package ai.chat2db.excel.context.xlsx; import ai.chat2db.excel.context.AnalysisContextImpl; import ai.chat2db.excel.read.metadata.ReadWorkbook; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder; import ai.chat2db.excel.support.ExcelTypeEnum; /** * * A context is the main anchorage point of a ls xls reader. * * @author Jiaju Zhuang */ public class DefaultXlsxReadContext extends AnalysisContextImpl implements XlsxReadContext { public DefaultXlsxReadContext(ReadWorkbook readWorkbook, ExcelTypeEnum actualExcelType) { super(readWorkbook, actualExcelType); } @Override public XlsxReadWorkbookHolder xlsxReadWorkbookHolder() { return (XlsxReadWorkbookHolder)readWorkbookHolder(); } @Override public XlsxReadSheetHolder xlsxReadSheetHolder() { return (XlsxReadSheetHolder)readSheetHolder(); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/context/xlsx/XlsxReadContext.java
package ai.chat2db.excel.context.xlsx; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; import ai.chat2db.excel.read.metadata.holder.xlsx.XlsxReadWorkbookHolder; /** * A context is the main anchorage point of a ls xlsx reader. * * @author Jiaju Zhuang **/ public interface XlsxReadContext extends AnalysisContext { /** * All information about the workbook you are currently working on. * * @return Current workbook holder */ XlsxReadWorkbookHolder xlsxReadWorkbookHolder(); /** * All information about the sheet you are currently working on. * * @return Current sheet holder */ XlsxReadSheetHolder xlsxReadSheetHolder(); }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/AutoConverter.java
package ai.chat2db.excel.converters; /** * An empty converter.It's automatically converted by type. * * @author Jiaju Zhuang */ public class AutoConverter implements Converter<Object> { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/Converter.java
package ai.chat2db.excel.converters; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * Convert between Java objects and excel objects * * @param <T> * @author Dan Zheng */ public interface Converter<T> { /** * Back to object types in Java * * @return Support for Java class */ default Class<?> supportJavaTypeKey() { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } /** * Back to object enum in excel * * @return Support for {@link CellDataTypeEnum} */ default CellDataTypeEnum supportExcelTypeKey() { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } /** * Convert excel objects to Java objects * * @param cellData Excel cell data.NotNull. * @param contentProperty Content property.Nullable. * @param globalConfiguration Global configuration.NotNull. * @return Data to put into a Java object * @throws Exception Exception. */ default T convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } /** * Convert excel objects to Java objects * * @param context read converter context * @return Data to put into a Java object * @throws Exception Exception. */ default T convertToJavaData(ReadConverterContext<?> context) throws Exception { return convertToJavaData(context.getReadCellData(), context.getContentProperty(), context.getAnalysisContext().currentReadHolder().globalConfiguration()); } /** * Convert Java objects to excel objects * * @param value Java Data.NotNull. * @param contentProperty Content property.Nullable. * @param globalConfiguration Global configuration.NotNull. * @return Data to put into a Excel * @throws Exception Exception. */ default WriteCellData<?> convertToExcelData(T value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { throw new UnsupportedOperationException("The current operation is not supported by the current converter."); } /** * Convert Java objects to excel objects * * @param context write context * @return Data to put into a Excel * @throws Exception Exception. */ default WriteCellData<?> convertToExcelData(WriteConverterContext<T> context) throws Exception { return convertToExcelData(context.getValue(), context.getContentProperty(), context.getWriteContext().currentWriteHolder().globalConfiguration()); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/ConverterKeyBuild.java
package ai.chat2db.excel.converters; import java.util.Map; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.util.MapUtils; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; /** * Converter unique key.Consider that you can just use class as the key. * * @author Jiaju Zhuang */ public class ConverterKeyBuild { private static final Map<Class<?>, Class<?>> BOXING_MAP = MapUtils.newHashMap(); static { BOXING_MAP.put(int.class, Integer.class); BOXING_MAP.put(byte.class, Byte.class); BOXING_MAP.put(long.class, Long.class); BOXING_MAP.put(double.class, Double.class); BOXING_MAP.put(float.class, Float.class); BOXING_MAP.put(char.class, Character.class); BOXING_MAP.put(short.class, Short.class); BOXING_MAP.put(boolean.class, Boolean.class); } public static ConverterKey buildKey(Class<?> clazz) { return buildKey(clazz, null); } public static ConverterKey buildKey(Class<?> clazz, CellDataTypeEnum cellDataTypeEnum) { Class<?> boxingClass = BOXING_MAP.get(clazz); if (boxingClass != null) { return new ConverterKey(boxingClass, cellDataTypeEnum); } return new ConverterKey(clazz, cellDataTypeEnum); } @Getter @Setter @EqualsAndHashCode @AllArgsConstructor public static class ConverterKey { private Class<?> clazz; private CellDataTypeEnum cellDataTypeEnum; } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/DefaultConverterLoader.java
package ai.chat2db.excel.converters; import java.util.Map; import ai.chat2db.excel.util.MapUtils; import ai.chat2db.excel.converters.ConverterKeyBuild.ConverterKey; import ai.chat2db.excel.converters.bigdecimal.BigDecimalBooleanConverter; import ai.chat2db.excel.converters.bigdecimal.BigDecimalNumberConverter; import ai.chat2db.excel.converters.bigdecimal.BigDecimalStringConverter; import ai.chat2db.excel.converters.biginteger.BigIntegerBooleanConverter; import ai.chat2db.excel.converters.biginteger.BigIntegerNumberConverter; import ai.chat2db.excel.converters.biginteger.BigIntegerStringConverter; import ai.chat2db.excel.converters.booleanconverter.BooleanBooleanConverter; import ai.chat2db.excel.converters.booleanconverter.BooleanNumberConverter; import ai.chat2db.excel.converters.booleanconverter.BooleanStringConverter; import ai.chat2db.excel.converters.bytearray.BoxingByteArrayImageConverter; import ai.chat2db.excel.converters.bytearray.ByteArrayImageConverter; import ai.chat2db.excel.converters.byteconverter.ByteBooleanConverter; import ai.chat2db.excel.converters.byteconverter.ByteNumberConverter; import ai.chat2db.excel.converters.byteconverter.ByteStringConverter; import ai.chat2db.excel.converters.date.DateDateConverter; import ai.chat2db.excel.converters.date.DateNumberConverter; import ai.chat2db.excel.converters.date.DateStringConverter; import ai.chat2db.excel.converters.doubleconverter.DoubleBooleanConverter; import ai.chat2db.excel.converters.doubleconverter.DoubleNumberConverter; import ai.chat2db.excel.converters.doubleconverter.DoubleStringConverter; import ai.chat2db.excel.converters.file.FileImageConverter; import ai.chat2db.excel.converters.floatconverter.FloatBooleanConverter; import ai.chat2db.excel.converters.floatconverter.FloatNumberConverter; import ai.chat2db.excel.converters.floatconverter.FloatStringConverter; import ai.chat2db.excel.converters.inputstream.InputStreamImageConverter; import ai.chat2db.excel.converters.integer.IntegerBooleanConverter; import ai.chat2db.excel.converters.integer.IntegerNumberConverter; import ai.chat2db.excel.converters.integer.IntegerStringConverter; import ai.chat2db.excel.converters.localdate.LocalDateDateConverter; import ai.chat2db.excel.converters.localdate.LocalDateNumberConverter; import ai.chat2db.excel.converters.localdate.LocalDateStringConverter; import ai.chat2db.excel.converters.localdatetime.LocalDateTimeNumberConverter; import ai.chat2db.excel.converters.localdatetime.LocalDateTimeDateConverter; import ai.chat2db.excel.converters.localdatetime.LocalDateTimeStringConverter; import ai.chat2db.excel.converters.longconverter.LongBooleanConverter; import ai.chat2db.excel.converters.longconverter.LongNumberConverter; import ai.chat2db.excel.converters.longconverter.LongStringConverter; import ai.chat2db.excel.converters.shortconverter.ShortBooleanConverter; import ai.chat2db.excel.converters.shortconverter.ShortNumberConverter; import ai.chat2db.excel.converters.shortconverter.ShortStringConverter; import ai.chat2db.excel.converters.string.StringBooleanConverter; import ai.chat2db.excel.converters.string.StringErrorConverter; import ai.chat2db.excel.converters.string.StringNumberConverter; import ai.chat2db.excel.converters.string.StringStringConverter; import ai.chat2db.excel.converters.url.UrlImageConverter; /** * Load default handler * * @author Jiaju Zhuang */ public class DefaultConverterLoader { private static Map<ConverterKey, Converter<?>> defaultWriteConverter; private static Map<ConverterKey, Converter<?>> allConverter; static { initDefaultWriteConverter(); initAllConverter(); } private static void initAllConverter() { allConverter = MapUtils.newHashMapWithExpectedSize(40); putAllConverter(new BigDecimalBooleanConverter()); putAllConverter(new BigDecimalNumberConverter()); putAllConverter(new BigDecimalStringConverter()); putAllConverter(new BigIntegerBooleanConverter()); putAllConverter(new BigIntegerNumberConverter()); putAllConverter(new BigIntegerStringConverter()); putAllConverter(new BooleanBooleanConverter()); putAllConverter(new BooleanNumberConverter()); putAllConverter(new BooleanStringConverter()); putAllConverter(new ByteBooleanConverter()); putAllConverter(new ByteNumberConverter()); putAllConverter(new ByteStringConverter()); putAllConverter(new DateNumberConverter()); putAllConverter(new DateStringConverter()); putAllConverter(new LocalDateNumberConverter()); putAllConverter(new LocalDateStringConverter()); putAllConverter(new LocalDateTimeNumberConverter()); putAllConverter(new LocalDateTimeStringConverter()); putAllConverter(new DoubleBooleanConverter()); putAllConverter(new DoubleNumberConverter()); putAllConverter(new DoubleStringConverter()); putAllConverter(new FloatBooleanConverter()); putAllConverter(new FloatNumberConverter()); putAllConverter(new FloatStringConverter()); putAllConverter(new IntegerBooleanConverter()); putAllConverter(new IntegerNumberConverter()); putAllConverter(new IntegerStringConverter()); putAllConverter(new LongBooleanConverter()); putAllConverter(new LongNumberConverter()); putAllConverter(new LongStringConverter()); putAllConverter(new ShortBooleanConverter()); putAllConverter(new ShortNumberConverter()); putAllConverter(new ShortStringConverter()); putAllConverter(new StringBooleanConverter()); putAllConverter(new StringNumberConverter()); putAllConverter(new StringStringConverter()); putAllConverter(new StringErrorConverter()); } private static void initDefaultWriteConverter() { defaultWriteConverter = MapUtils.newHashMapWithExpectedSize(40); putWriteConverter(new BigDecimalNumberConverter()); putWriteConverter(new BigIntegerNumberConverter()); putWriteConverter(new BooleanBooleanConverter()); putWriteConverter(new ByteNumberConverter()); putWriteConverter(new DateDateConverter()); putWriteConverter(new LocalDateTimeDateConverter()); putWriteConverter(new LocalDateDateConverter()); putWriteConverter(new DoubleNumberConverter()); putWriteConverter(new FloatNumberConverter()); putWriteConverter(new IntegerNumberConverter()); putWriteConverter(new LongNumberConverter()); putWriteConverter(new ShortNumberConverter()); putWriteConverter(new StringStringConverter()); putWriteConverter(new FileImageConverter()); putWriteConverter(new InputStreamImageConverter()); putWriteConverter(new ByteArrayImageConverter()); putWriteConverter(new BoxingByteArrayImageConverter()); putWriteConverter(new UrlImageConverter()); // In some cases, it must be converted to string putWriteStringConverter(new BigDecimalStringConverter()); putWriteStringConverter(new BigIntegerStringConverter()); putWriteStringConverter(new BooleanStringConverter()); putWriteStringConverter(new ByteStringConverter()); putWriteStringConverter(new DateStringConverter()); putWriteStringConverter(new LocalDateStringConverter()); putWriteStringConverter(new LocalDateTimeStringConverter()); putWriteStringConverter(new DoubleStringConverter()); putWriteStringConverter(new FloatStringConverter()); putWriteStringConverter(new IntegerStringConverter()); putWriteStringConverter(new LongStringConverter()); putWriteStringConverter(new ShortStringConverter()); putWriteStringConverter(new StringStringConverter()); } /** * Load default write converter * * @return */ public static Map<ConverterKey, Converter<?>> loadDefaultWriteConverter() { return defaultWriteConverter; } private static void putWriteConverter(Converter<?> converter) { defaultWriteConverter.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey()), converter); } private static void putWriteStringConverter(Converter<?> converter) { defaultWriteConverter.put( ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()), converter); } /** * Load default read converter * * @return */ public static Map<ConverterKey, Converter<?>> loadDefaultReadConverter() { return loadAllConverter(); } /** * Load all converter * * @return */ public static Map<ConverterKey, Converter<?>> loadAllConverter() { return allConverter; } private static void putAllConverter(Converter<?> converter) { allConverter.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()), converter); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/NullableObjectConverter.java
package ai.chat2db.excel.converters; /** * When implementing <code>convertToExcelData</code> method, pay attention to the reference <code>value</code> may be * null * * @author JiaJu Zhuang **/ public interface NullableObjectConverter<T> extends Converter<T> { }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/ReadConverterContext.java
package ai.chat2db.excel.converters; import ai.chat2db.excel.context.AnalysisContext; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; /** * read converter context * * @author Jiaju Zhuang */ @Getter @Setter @EqualsAndHashCode @AllArgsConstructor public class ReadConverterContext<T> { /** * Excel cell data.NotNull. */ private ReadCellData<T> readCellData; /** * Content property.Nullable. */ private ExcelContentProperty contentProperty; /** * context.NotNull. */ private AnalysisContext analysisContext; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/WriteConverterContext.java
package ai.chat2db.excel.converters; import ai.chat2db.excel.context.WriteContext; import ai.chat2db.excel.metadata.property.ExcelContentProperty; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * write converter context * * @author Jiaju Zhuang */ @Getter @Setter @EqualsAndHashCode @NoArgsConstructor @AllArgsConstructor public class WriteConverterContext<T> { /** * Java Data.NotNull. */ private T value; /** * Content property.Nullable. */ private ExcelContentProperty contentProperty; /** * write context */ private WriteContext writeContext; }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/bigdecimal/BigDecimalBooleanConverter.java
package ai.chat2db.excel.converters.bigdecimal; import java.math.BigDecimal; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigDecimal and boolean converter * * @author Jiaju Zhuang */ public class BigDecimalBooleanConverter implements Converter<BigDecimal> { @Override public Class<BigDecimal> supportJavaTypeKey() { return BigDecimal.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.BOOLEAN; } @Override public BigDecimal convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return BigDecimal.ONE; } return BigDecimal.ZERO; } @Override public WriteCellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (BigDecimal.ONE.equals(value)) { return new WriteCellData<>(Boolean.TRUE); } return new WriteCellData<>(Boolean.FALSE); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/bigdecimal/BigDecimalNumberConverter.java
package ai.chat2db.excel.converters.bigdecimal; import java.math.BigDecimal; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.util.NumberUtils; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigDecimal and number converter * * @author Jiaju Zhuang */ public class BigDecimalNumberConverter implements Converter<BigDecimal> { @Override public Class<BigDecimal> supportJavaTypeKey() { return BigDecimal.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.NUMBER; } @Override public BigDecimal convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue(); } @Override public WriteCellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellData(value, contentProperty); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/bigdecimal/BigDecimalStringConverter.java
package ai.chat2db.excel.converters.bigdecimal; import java.math.BigDecimal; import java.text.ParseException; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.util.NumberUtils; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigDecimal and string converter * * @author Jiaju Zhuang */ public class BigDecimalStringConverter implements Converter<BigDecimal> { @Override public Class<BigDecimal> supportJavaTypeKey() { return BigDecimal.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.STRING; } @Override public BigDecimal convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty); } @Override public WriteCellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/biginteger/BigIntegerBooleanConverter.java
package ai.chat2db.excel.converters.biginteger; import java.math.BigInteger; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigInteger and boolean converter * * @author Jiaju Zhuang */ public class BigIntegerBooleanConverter implements Converter<BigInteger> { @Override public Class<BigInteger> supportJavaTypeKey() { return BigInteger.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.BOOLEAN; } @Override public BigInteger convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return BigInteger.ONE; } return BigInteger.ZERO; } @Override public WriteCellData<?> convertToExcelData(BigInteger value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (BigInteger.ONE.equals(value)) { return new WriteCellData<>(Boolean.TRUE); } return new WriteCellData<>(Boolean.FALSE); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/biginteger/BigIntegerNumberConverter.java
package ai.chat2db.excel.converters.biginteger; import java.math.BigInteger; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.util.NumberUtils; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigInteger and number converter * * @author Jiaju Zhuang */ public class BigIntegerNumberConverter implements Converter<BigInteger> { @Override public Class<BigInteger> supportJavaTypeKey() { return BigInteger.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.NUMBER; } @Override public BigInteger convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getNumberValue().toBigInteger(); } @Override public WriteCellData<?> convertToExcelData(BigInteger value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellData(value, contentProperty); } }
0
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters
java-sources/ai/chat2db/excel/easyexcel-plus-core/0.0.1/ai/chat2db/excel/converters/biginteger/BigIntegerStringConverter.java
package ai.chat2db.excel.converters.biginteger; import java.math.BigInteger; import java.text.ParseException; import ai.chat2db.excel.converters.Converter; import ai.chat2db.excel.enums.CellDataTypeEnum; import ai.chat2db.excel.util.NumberUtils; import ai.chat2db.excel.metadata.GlobalConfiguration; import ai.chat2db.excel.metadata.data.ReadCellData; import ai.chat2db.excel.metadata.data.WriteCellData; import ai.chat2db.excel.metadata.property.ExcelContentProperty; /** * BigDecimal and string converter * * @author Jiaju Zhuang */ public class BigIntegerStringConverter implements Converter<BigInteger> { @Override public Class<BigInteger> supportJavaTypeKey() { return BigInteger.class; } @Override public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.STRING; } @Override public BigInteger convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException { return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty).toBigInteger(); } @Override public WriteCellData<?> convertToExcelData(BigInteger value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return NumberUtils.formatToCellDataString(value, contentProperty); } }