Skip to content

Commit

Permalink
#124 - OCR Tessaract Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Friesen authored and mfriesen committed May 15, 2023
1 parent 7739e28 commit 9afb416
Show file tree
Hide file tree
Showing 85 changed files with 5,449 additions and 63 deletions.
3 changes: 3 additions & 0 deletions aws-dynamodb/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<allow pkg="software.amazon.awssdk.services.dynamodb" />
<allow pkg="com.amazonaws.xray.interceptors" />

<subpackage name="objects">
<allow pkg="java.time" />
</subpackage>
</subpackage>

</import-control>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.dynamodb;
package com.formkiq.aws.dynamodb.objects;

import java.text.SimpleDateFormat;
import java.time.DateTimeException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.common.formats;
package com.formkiq.aws.dynamodb.objects;

import static com.formkiq.stacks.common.formats.MimeType.MIME_DOCX;
import static com.formkiq.stacks.common.formats.MimeType.MIME_HTML;
import static com.formkiq.stacks.common.formats.MimeType.MIME_JPEG;
import static com.formkiq.stacks.common.formats.MimeType.MIME_JSON;
import static com.formkiq.stacks.common.formats.MimeType.MIME_PDF;
import static com.formkiq.stacks.common.formats.MimeType.MIME_PNG;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_DOCX;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_HTML;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_JPEG;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_JSON;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_PDF;
import static com.formkiq.aws.dynamodb.objects.MimeType.MIME_PNG;
import java.util.Set;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,52 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.common.formats;
package com.formkiq.aws.dynamodb.objects;

/**
* Supported Conversion Formats.
*
*/
public enum MimeType {

/** text/html. */
MIME_HTML("text/html"),
/** image/bmp. */
MIME_BMP("image/bmp"),
/** application/vnd.openxmlformats-officedocument.wordprocessingml.document. */
MIME_DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
/** application/pdf. */
MIME_PDF("application/pdf"),
/** image/png. */
MIME_PNG("image/png"),
/** image/gif. */
MIME_GIF("image/gif"),
/** text/html. */
MIME_HTML("text/html"),
/** image/jpeg. */
MIME_JPEG("image/jpeg"),
/** image/jpg. */
MIME_JPG("image/jpg"),
/** application/json. */
MIME_JSON("application/json"),
/** application/pdf. */
MIME_PDF("application/pdf"),
/** image/png. */
MIME_PNG("image/png"),
/** image/tif. */
MIME_TIF("image/tif"),
/** image/tiff. */
MIME_TIFF("image/tiff"),
/** Unknown Mime. */
MIME_UNKNOWN("UNKNOWN");
MIME_UNKNOWN("UNKNOWN"),
/** image/webp. */
MIME_WEBP("image/webp");

/**
* Is Content Type plain text.
*
* @param contentType {@link String}
* @return boolean
*/
public static boolean isPlainText(final String contentType) {
return contentType != null
&& (contentType.startsWith("text/") || "application/json".equals(contentType)
|| "application/x-www-form-urlencoded".equals(contentType));
}

/** Content Type. */
private String contentType;
Expand All @@ -66,14 +90,34 @@ public String getContentType() {
}

/**
* Is Content Type plain text.
* Get File Extension.
*
* @param contentType {@link String}
* @return boolean
* @return {@link String}
*/
public static boolean isPlainText(final String contentType) {
return contentType != null
&& (contentType.startsWith("text/") || "application/json".equals(contentType)
|| "application/x-www-form-urlencoded".equals(contentType));
public String getExtension() {
int pos = this.contentType.lastIndexOf("/");
return pos > -1 ? this.contentType.substring(pos + 1).toLowerCase() : null;
}

/**
* Find {@link MimeType} from Content-Type.
*
* @param ct {@link String}
* @return {@link MimeType}
*/
public static MimeType fromContentType(final String ct) {

MimeType type = MimeType.MIME_UNKNOWN;

if (ct != null) {
for (MimeType mt : MimeType.values()) {
if (ct.equals(mt.getContentType())) {
type = mt;
break;
}
}
}

return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.aws.dynamodb.objects;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
*
* Unit Test for {@link MimeType}.
*
*/
class MimeTypeTest {

/**
* Test fromContentType.
*/
@Test
void testFromContentType() {
assertEquals(MimeType.MIME_PNG, MimeType.fromContentType("image/png"));
assertEquals(MimeType.MIME_UNKNOWN, MimeType.fromContentType(null));
}

}
9 changes: 8 additions & 1 deletion aws-sqs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
description = "AWS SQS"

dependencies {

annotationProcessor group: 'com.formkiq', name: 'graalvm-annotations-processor', version: '1.4.0-SNAPSHOT'

implementation group: 'com.formkiq', name: 'graalvm-annotations', version: '1.2.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'

api 'software.amazon.awssdk:sqs:2.20.33'
implementation group: 'software.amazon.awssdk', name: 'url-connection-client', version: '2.20.33'
implementation project(':aws-xray')
Expand All @@ -12,7 +18,8 @@ dependencies {
exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
}

testImplementation group: 'junit', name: 'junit', version:'4.+'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.9.1'
//testImplementation group: 'junit', name: 'junit', version:'4.+'
}

test {
Expand Down
2 changes: 2 additions & 0 deletions aws-sqs/config/checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<allow pkg="com.amazonaws.xray.interceptors" />
<allow pkg="software.amazon.awssdk.core.client.config" />

<allow pkg="com.formkiq.graalvm.annotations" />
<allow pkg="com.google.gson.annotations" />
<allow pkg="com.formkiq.module.lambdaservices" />
</subpackage>

Expand Down
Loading

0 comments on commit 9afb416

Please sign in to comment.