This commit is contained in:
34
docs/snippets/java/plugins/min_length_validator.md
Normal file
34
docs/snippets/java/plugins/min_length_validator.md
Normal file
@@ -0,0 +1,34 @@
|
||||
```java title="Java"
|
||||
import dev.kreuzberg.Kreuzberg;
|
||||
import dev.kreuzberg.ExtractionResult;
|
||||
import dev.kreuzberg.Validator;
|
||||
import dev.kreuzberg.ValidationException;
|
||||
import dev.kreuzberg.KreuzbergException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MinLengthValidatorExample {
|
||||
public static void main(String[] args) {
|
||||
int minLength = 100;
|
||||
|
||||
Validator minLengthValidator = result -> {
|
||||
if (result.getContent().length() < minLength) {
|
||||
throw new ValidationException(
|
||||
"Content too short: " + result.getContent().length() +
|
||||
" < " + minLength
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
Kreuzberg.registerValidator("min-length", minLengthValidator, 100);
|
||||
|
||||
ExtractionResult result = Kreuzberg.extractFile("document.pdf");
|
||||
System.out.println("Validation passed!");
|
||||
} catch (ValidationException e) {
|
||||
System.err.println("Validation failed: " + e.getMessage());
|
||||
} catch (IOException | KreuzbergException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user