From 91c7de5ca892c0c504e98a8611964bd11ebcba39 Mon Sep 17 00:00:00 2001 From: Alexander Tyutyunnyk Date: Tue, 20 Jul 2021 10:57:55 +0300 Subject: [PATCH] Update annotation to 21.7 --- pom.xml | 2 +- .../annotator/AbstractBoxAnnotator.java | 46 -- .../annotator/AbstractSvgAnnotator.java | 76 -- .../annotator/AbstractTextAnnotator.java | 38 +- .../ui/annotation/annotator/Annotator.java | 188 ----- .../annotator/AnnotatorFactory.java | 68 +- .../annotation/annotator/AreaAnnotator.java | 59 +- .../annotation/annotator/ArrowAnnotator.java | 90 +-- .../annotation/annotator/BaseAnnotator.java | 225 ++++++ .../annotator/DistanceAnnotator.java | 96 +-- .../annotation/annotator/PointAnnotator.java | 61 +- .../annotator/PolylineAnnotator.java | 87 +-- .../annotator/ResourceRedactionAnnotator.java | 63 +- .../annotator/TexStrikeoutAnnotator.java | 68 -- .../annotator/TexUnderlineAnnotator.java | 71 -- .../annotation/annotator/TextAnnotator.java | 78 -- .../annotator/TextFieldAnnotator.java | 69 +- .../annotator/TextHighlightAnnotator.java | 57 ++ .../annotator/TextRedactionAnnotator.java | 50 +- .../annotator/TextReplacementAnnotator.java | 78 +- .../annotator/TextStrikeoutAnnotator.java | 58 ++ .../annotator/TextUnderlineAnnotator.java | 60 ++ .../annotator/WatermarkAnnotator.java | 64 +- .../config/AnnotationConfiguration.java | 54 +- .../controller/AnnotationController.java | 24 +- .../ui/annotation/entity/Annotations.java | 75 ++ .../request/AnnotateDocumentRequest.java | 48 -- .../entity/request/PostedDataEntity.java | 180 +++++ .../request/TextCoordinatesRequest.java | 31 + .../entity/web/AnnotatedDocumentEntity.java | 16 +- .../entity/web/AnnotationDataEntity.java | 176 ++--- .../web/AnnotationPageDescriptionEntity.java | 20 - .../web/AnnotationPostedDataEntity.java | 39 + .../annotation/entity/web/CommentsEntity.java | 40 +- .../entity/web/PageDataDescriptionEntity.java | 19 + .../annotation/entity/web/TextRowEntity.java | 33 + .../ui/annotation/importer/Importer.java | 38 - .../annotation/service/AnnotationService.java | 11 +- .../service/AnnotationServiceImpl.java | 696 ++++++++++++------ .../service/IPageStreamFactory.java | 20 + .../service/StreamFactoryClass.java | 70 ++ .../ui/annotation/util/AnnotationMapper.java | 162 ++-- .../ui/annotation/util/AnnotationTypes.java | 57 -- .../util/DocumentTypesConverter.java | 22 +- .../ui/annotation/util/PathConstants.java | 10 - .../annotation/util/SupportedAnnotations.java | 93 +-- .../util/directory/DirectoryUtils.java | 19 + .../util/directory/FilesDirectoryUtils.java | 30 + .../model/response/FileDescriptionEntity.java | 2 +- 49 files changed, 2048 insertions(+), 1689 deletions(-) delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/AbstractBoxAnnotator.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/AbstractSvgAnnotator.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/Annotator.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/BaseAnnotator.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TexStrikeoutAnnotator.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TexUnderlineAnnotator.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TextAnnotator.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TextHighlightAnnotator.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TextStrikeoutAnnotator.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/annotator/TextUnderlineAnnotator.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/Annotations.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/request/AnnotateDocumentRequest.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/request/PostedDataEntity.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/request/TextCoordinatesRequest.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPageDescriptionEntity.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPostedDataEntity.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/web/PageDataDescriptionEntity.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/entity/web/TextRowEntity.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/importer/Importer.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/service/IPageStreamFactory.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/service/StreamFactoryClass.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/util/AnnotationTypes.java delete mode 100644 src/main/java/com/groupdocs/ui/annotation/util/PathConstants.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/util/directory/DirectoryUtils.java create mode 100644 src/main/java/com/groupdocs/ui/annotation/util/directory/FilesDirectoryUtils.java diff --git a/pom.xml b/pom.xml index 4c993ba..4d88113 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ com.groupdocs groupdocs-annotation - 19.7 + 21.7 jar diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractBoxAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractBoxAnnotator.java deleted file mode 100644 index 37a6ccc..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractBoxAnnotator.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Point; -import com.groupdocs.annotation.domain.Rectangle; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; - -import java.text.ParseException; - -public abstract class AbstractBoxAnnotator extends Annotator { - - public AbstractBoxAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo annotationInfo = super.initAnnotationInfo(); - // set draw annotation properties - Rectangle box = annotationInfo.getBox(); - StringBuilder builder = new StringBuilder(). - append("M").append(box.getX()). - append(",").append(box.getY()). - append("L").append(box.getWidth()). - append(",").append(box.getHeight()); - annotationInfo.setSvgPath(builder.toString()); - // set annotation position - annotationInfo.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - return annotationInfo; - } - - @Override - protected Rectangle getBox() { - String svgPath = annotationData.getSvgPath(); - String startPoint = svgPath.replaceAll("[a-zA-Z]+", "").split(" ")[0]; - String endPoint = svgPath.replaceAll("[a-zA-Z]+", "").split(" ")[1]; - String[] start = startPoint.split(","); - double startX = Double.parseDouble(start.length > 0 ? start[0] : "0"); - double startY = Double.parseDouble(start.length > 1 ? start[1] : "0"); - String[] end = endPoint.split(","); - double endX = Double.parseDouble(end.length > 0 ? end[0] : "0") - startX; - double endY = Double.parseDouble(end.length > 1 ? end[1] : "0") - startY; - return new Rectangle(startX, startY, endX, endY); - } -} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractSvgAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractSvgAnnotator.java deleted file mode 100644 index 4dfcbaa..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractSvgAnnotator.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; - -import java.text.ParseException; - -public abstract class AbstractSvgAnnotator extends Annotator { - - public AbstractSvgAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo annotationInfo = super.initAnnotationInfo(); - // set draw annotation properties - annotationInfo.setSvgPath(buildSvgPath()); - return annotationInfo; - } - - /** - * Use this method for fixing box coordinates if needed - * - * @param annotationInfo - */ - protected void fixBox(AnnotationInfo annotationInfo) { - double topPosition = pageData.getHeight() - annotationData.getTop(); - annotationInfo.getBox().setY((float) topPosition); - } - - /** - * Calculate svg position - * - * @return - */ - protected String buildSvgPath() { - // we use such calculation since the GroupDocs.Annotation library takes text line position from the bottom of the page - double topPosition = pageData.getHeight() - annotationData.getTop(); - // calculation of the X-shift - double topRightX = annotationData.getLeft() + annotationData.getWidth(); - // calculation of the Y-shift - double bottomRightY = topPosition - annotationData.getHeight(); - return getSvgString(topPosition, annotationData.getLeft(), topRightX, bottomRightY); - } - - /** - * Build svg string - * - * @param top top position - * @param left left position - * @param right right position - * @param bottom bottom position - * @return - */ - protected String getSvgString(double top, double left, double right, double bottom) { - return new StringBuilder(). - append("[{\"x\":").append(left). - append(",\"y\":").append(top). - append("},{\"x\":").append(right). - append(",\"y\":").append(top). - append("},{\"x\":").append(left). - append(",\"y\":").append(bottom). - append("},{\"x\":").append(right). - append(",\"y\":").append(bottom). - append("}]").toString(); - } - - @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); - } - -} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractTextAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractTextAnnotator.java index 16eee40..879e4fd 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractTextAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/AbstractTextAnnotator.java @@ -1,31 +1,23 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.Point; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import org.springframework.util.StringUtils; +import java.util.ArrayList; +import java.util.List; -import java.text.ParseException; +public abstract class AbstractTextAnnotator extends BaseAnnotator { -public abstract class AbstractTextAnnotator extends Annotator { - - public AbstractTextAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo annotationInfo = super.initAnnotationInfo(); - annotationInfo.setFieldText(annotationData.getText()); - annotationInfo.setFontFamily(StringUtils.capitalize(annotationData.getFont())); - annotationInfo.setFontSize(annotationData.getFontSize()); - annotationInfo.setFontColor(annotationData.getFontColor()); - return annotationInfo; + protected AbstractTextAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); } - @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + protected static java.util.List getPoints(AnnotationDataEntity annotationData, PageInfo pageInfo) { + List tmp0 = new ArrayList<>(); + tmp0.add(new Point(annotationData.getLeft(), pageInfo.getHeight() - annotationData.getTop())); + tmp0.add(new Point(annotationData.getLeft()+ annotationData.getWidth(), pageInfo.getHeight() - annotationData.getTop())); + tmp0.add(new Point(annotationData.getLeft(), pageInfo.getHeight() - annotationData.getTop()- annotationData.getHeight())); + tmp0.add(new Point(annotationData.getLeft()+ annotationData.getWidth(), pageInfo.getHeight() - annotationData.getTop()- annotationData.getHeight())); + return tmp0; } -} +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/Annotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/Annotator.java deleted file mode 100644 index 5f4b09f..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/Annotator.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationReplyInfo; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import com.groupdocs.ui.annotation.entity.web.CommentsEntity; -import com.groupdocs.ui.exception.TotalGroupDocsException; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -/** - * Annotator - * Abstract class contains general description for the annotating functionality - * - * @author Aspose Pty Ltd - */ -public abstract class Annotator { - - public static final String MESSAGE = "Annotation of type %s for this file type is not supported"; - - protected AnnotationDataEntity annotationData; - protected PageData pageData; - - /** - * Constructor - * - * @param annotationData - * @param pageData - */ - public Annotator(AnnotationDataEntity annotationData, PageData pageData) { - this.annotationData = annotationData; - this.pageData = pageData; - } - - /** - * Add area annotation into the Word document - * - * @return - * @throws UnsupportedOperationException Word document doesn't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotateWord() throws UnsupportedOperationException, ParseException; - - /** - * Add area annotation into the pdf document - * - * @return - * @throws UnsupportedOperationException pdf document doesn't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotatePdf() throws UnsupportedOperationException, ParseException; - - /** - * Add area annotation into the Excel document - * - * @return - * @throws UnsupportedOperationException the Excel document don't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotateCells() throws UnsupportedOperationException, ParseException; - - /** - * Add area annotation into the Power Point document - * - * @return - * @throws UnsupportedOperationException the Power Point document doesn't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotateSlides() throws UnsupportedOperationException, ParseException; - - /** - * Add area annotation into the image document - * - * @return - * @throws UnsupportedOperationException image doesn't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotateImage() throws UnsupportedOperationException, ParseException; - - /** - * Add area annotation into the document - * - * @return - * @throws UnsupportedOperationException diagram document doesn't supported for the current annotation type - * @throws ParseException the date cannot be parsed - */ - public abstract AnnotationInfo annotateDiagram() throws UnsupportedOperationException, ParseException; - - /** - * Initial for annotation info - * - * @return annotation info - * @throws ParseException the date cannot be parsed - */ - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo areaAnnotation = new AnnotationInfo(); - // draw annotation options - areaAnnotation.setBox(getBox()); - // set page number to add annotation - areaAnnotation.setPageNumber(annotationData.getPageNumber() - 1); - // set annotation type - areaAnnotation.setType(getType()); - // add replies - CommentsEntity[] comments = annotationData.getComments(); - if (comments != null && comments.length != 0) { - AnnotationReplyInfo[] replies = new AnnotationReplyInfo[comments.length]; - for (int i = 0; i < comments.length; i++) { - AnnotationReplyInfo reply = getAnnotationReplyInfo(comments[i]); - replies[i] = reply; - } - areaAnnotation.setReplies(replies); - } - return areaAnnotation; - } - - /** - * Initial for reply annotation info - * - * @param comment annotation comment - * @return annotation reply info - * @throws ParseException the date cannot be parsed - */ - protected AnnotationReplyInfo getAnnotationReplyInfo(CommentsEntity comment) throws ParseException { - AnnotationReplyInfo reply = new AnnotationReplyInfo(); - reply.setMessage(comment.getText()); - DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); - format.setTimeZone(TimeZone.getTimeZone("GMT")); - Date date; - try { - date = new Date(Long.parseLong(comment.getTime())); - } catch (Exception e) { - try { - date = format.parse(comment.getTime()); - } catch (Exception exc) { - format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); - date = format.parse(comment.getTime()); - } - } - reply.setRepliedOn(date); - reply.setUserName(comment.getUserName()); - return reply; - } - - /** - * Get rectangle - * - * @return box - */ - protected abstract Rectangle getBox(); - - /** - * Get type of annotation - * - * @return annotation type - */ - protected abstract byte getType(); - - /** - * Get Annotation info depending on document type - * - * @throws ParseException the date cannot be parsed - */ - public AnnotationInfo getAnnotationInfo(String documentType) throws ParseException { - switch (documentType) { - case "Portable Document Format": - return annotatePdf(); - case "Microsoft Word": - return annotateWord(); - case "Microsoft PowerPoint": - return annotateSlides(); - case "image": - return annotateImage(); - case "Microsoft Excel": - return annotateCells(); - case "AutoCAD Drawing File Format": - return annotateDiagram(); - default: - throw new TotalGroupDocsException("Wrong annotation data without document type!"); - } - } -} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/AnnotatorFactory.java b/src/main/java/com/groupdocs/ui/annotation/annotator/AnnotatorFactory.java index bd8e15a..43ed974 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/AnnotatorFactory.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/AnnotatorFactory.java @@ -1,51 +1,59 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.PageData; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.annotation.models.PageInfo; import com.groupdocs.ui.exception.TotalGroupDocsException; -/** - * Creator for annotator instances - */ public class AnnotatorFactory { /** + *

* Create annotator instance depending on type of annotation + *

* - * @param annotationData annotation - * @param pageData document - * @return annotator instance + * @return + * @param annotationData AnnotationDataEntity + * @param pageInfo PageInfo */ - public static Annotator createAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - switch (annotationData.getType()) { - case "text": - return new TextAnnotator(annotationData, pageData); + public static BaseAnnotator createAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + AnnotationDataEntity roundedAnnotationData = roundCoordinates(annotationData); + switch (roundedAnnotationData.getType().toLowerCase()) { // addev .toLowerCase() + case "texthighlight": //textHighlight + return new TextHighlightAnnotator(roundedAnnotationData, pageInfo); case "area": - return new AreaAnnotator(annotationData, pageData); + return new AreaAnnotator(roundedAnnotationData, pageInfo); case "point": - return new PointAnnotator(annotationData, pageData); - case "textStrikeout": - return new TexStrikeoutAnnotator(annotationData, pageData); + return new PointAnnotator(roundedAnnotationData, pageInfo); + case "textstrikeout": //textStrikeout + return new TextStrikeoutAnnotator(roundedAnnotationData, pageInfo); case "polyline": - return new PolylineAnnotator(annotationData, pageData); - case "textField": - return new TextFieldAnnotator(annotationData, pageData); + return new PolylineAnnotator(roundedAnnotationData, pageInfo); + case "textfield": //textField + return new TextFieldAnnotator(roundedAnnotationData, pageInfo); case "watermark": - return new WatermarkAnnotator(annotationData, pageData); - case "textReplacement": - return new TextReplacementAnnotator(annotationData, pageData); + return new WatermarkAnnotator(roundedAnnotationData, pageInfo); + case "textreplacement": //textReplacement + return new TextReplacementAnnotator(roundedAnnotationData, pageInfo); case "arrow": - return new ArrowAnnotator(annotationData, pageData); - case "textRedaction": - return new TextRedactionAnnotator(annotationData, pageData); - case "resourcesRedaction": - return new ResourceRedactionAnnotator(annotationData, pageData); - case "textUnderline": - return new TexUnderlineAnnotator(annotationData, pageData); + return new ArrowAnnotator(roundedAnnotationData, pageInfo); + case "textredaction": //textRedaction + return new TextRedactionAnnotator(roundedAnnotationData, pageInfo); + case "resourcesredaction": //resourcesRedaction + return new ResourceRedactionAnnotator(roundedAnnotationData, pageInfo); + case "textunderline": //textUnderline + return new TextUnderlineAnnotator(roundedAnnotationData, pageInfo); case "distance": - return new DistanceAnnotator(annotationData, pageData); + return new DistanceAnnotator(roundedAnnotationData, pageInfo); default: throw new TotalGroupDocsException("Wrong annotation data without annotation type!"); } } -} + + private static AnnotationDataEntity roundCoordinates(AnnotationDataEntity annotationData) { + annotationData.setHeight((float) Math.round(annotationData.getHeight())); + annotationData.setLeft((float) Math.round(annotationData.getLeft())); + annotationData.setTop((float) Math.round(annotationData.getTop())); + annotationData.setWidth((float) Math.round(annotationData.getWidth())); + return annotationData; + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/AreaAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/AreaAnnotator.java index 63ca156..0e89848 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/AreaAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/AreaAnnotator.java @@ -1,64 +1,55 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.*; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.AreaAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import java.text.ParseException; +public class AreaAnnotator extends BaseAnnotator { -/** - * AreaAnnotator - * Annotates documents with the area annotation - * - * @author Aspose Pty Ltd - */ -public class AreaAnnotator extends Annotator { + private AreaAnnotation areaAnnotation; - public AreaAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } + public AreaAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); - @Override - public AnnotationInfo annotateWord() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + areaAnnotation = new AreaAnnotation(); + areaAnnotation.setBox(getBox()); } @Override - public AnnotationInfo annotatePdf() throws ParseException { - // initiate AnnotationInfo object - AnnotationInfo areaAnnotation = initAnnotationInfo(); - // set annotation X, Y position - areaAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - // add replies + public AnnotationBase annotateWord() { + areaAnnotation = (AreaAnnotation) initAnnotationBase(areaAnnotation); return areaAnnotation; } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - protected byte getType() { - return AnnotationType.Area; + public AnnotationBase annotateDiagram() { + return annotateWord(); } @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + protected int getType() { + return AnnotationType.Area; } -} \ No newline at end of file +} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/ArrowAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/ArrowAnnotator.java index 0b0aa0e..550f9e7 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/ArrowAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/ArrowAnnotator.java @@ -1,86 +1,90 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationReplyInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.Rectangle; +import com.groupdocs.annotation.models.Reply; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.ArrowAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; import com.groupdocs.ui.annotation.entity.web.CommentsEntity; -import java.text.ParseException; - -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class ArrowAnnotator extends AbstractBoxAnnotator { +public class ArrowAnnotator extends BaseAnnotator { private boolean withGuid = false; + private ArrowAnnotation arrowAnnotation; + + public ArrowAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); - public ArrowAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); + this.arrowAnnotation = new ArrowAnnotation(); + this.arrowAnnotation.setBox(getBox()); } @Override - public AnnotationInfo annotateWord() throws ParseException { + public AnnotationBase annotateWord() { withGuid = false; - AnnotationInfo arrowAnnotation = initAnnotationInfo(); + arrowAnnotation = (ArrowAnnotation) initAnnotationBase(arrowAnnotation); return arrowAnnotation; } @Override - public AnnotationInfo annotatePdf() throws ParseException { - withGuid = false; - AnnotationInfo arrowAnnotation = initAnnotationInfo(); - return arrowAnnotation; + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { + public AnnotationBase annotateSlides() { withGuid = true; - // init annotation object - AnnotationInfo arrowAnnotation = initAnnotationInfo(); - arrowAnnotation.setBackgroundColor(15988609); + arrowAnnotation = (ArrowAnnotation) initAnnotationBase(arrowAnnotation); return arrowAnnotation; } @Override - public AnnotationInfo annotateImage() throws ParseException { - withGuid = false; - // init annotation object - AnnotationInfo arrowAnnotation = initAnnotationInfo(); - arrowAnnotation.setBackgroundColor(-15988609); - return arrowAnnotation; + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() throws ParseException { - withGuid = false; - // init annotation object - AnnotationInfo arrowAnnotation = initAnnotationInfo(); - arrowAnnotation.setBackgroundColor(15988609); - return arrowAnnotation; + public AnnotationBase annotateDiagram() { + return annotateWord(); } @Override - protected AnnotationReplyInfo getAnnotationReplyInfo(CommentsEntity comment) throws ParseException { - AnnotationReplyInfo annotationReplyInfo = super.getAnnotationReplyInfo(comment); + protected Reply getAnnotationReplyInfo(CommentsEntity comment) { + Reply annotationReplyInfo = super.getAnnotationReplyInfo(comment); if (withGuid) { - annotationReplyInfo.setParentReplyGuid(String.valueOf(annotationData.getId())); + annotationReplyInfo.setParentReply(new Reply()); + annotationReplyInfo.getParentReply().setId(annotationData.getId()); } return annotationReplyInfo; } @Override - protected byte getType() { + protected int getType() { return AnnotationType.Arrow; } + @Override + protected Rectangle getBox() { + String svgPath = annotationData.getSvgPath(); + + String startPoint = svgPath.replace("[a-zA-Z]+", "").split(" ")[0]; + String endPoint = svgPath.replace("[a-zA-Z]+", "").split(" ")[1]; + + String[] start = startPoint.split(","); + float startX = Float.parseFloat(start.length > 0 ? start[0].replace("M", "").replace(",", ".") : "0"); + float startY = Float.parseFloat(start.length > 0 ? start[1].replace("M", "").replace(",", ".") : "0"); + + String[] end = endPoint.split(","); + float endX = Float.parseFloat(end.length > 0 ? end[0].replace("L", "").replace(",", ".") : "0") - startX; + float endY = Float.parseFloat(end.length > 1 ? end[1].replace("L", "").replace(",", ".") : "0") - startY; + + return new Rectangle(startX, startY, endX, endY); + } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/BaseAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/BaseAnnotator.java new file mode 100644 index 0000000..9f70db9 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/BaseAnnotator.java @@ -0,0 +1,225 @@ +package com.groupdocs.ui.annotation.annotator; + + +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.Rectangle; +import com.groupdocs.annotation.models.Reply; +import com.groupdocs.annotation.models.User; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.annotation.entity.web.CommentsEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Locale; +import java.util.TimeZone; + +/** + *

+ * BaseSigner + *

+ */ +public abstract class BaseAnnotator { + + public String Message = "Annotation of type {0} for this file type is not supported"; + protected AnnotationDataEntity annotationData; + protected PageInfo pageInfo; + + /** + *

+ * Constructor + *

+ * + * @param annotationData + * @param pageInfo + */ + protected BaseAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + this.annotationData = annotationData; + this.pageInfo = pageInfo; + } + + /** + *

+ * Add area annotation into the Word document + *

+ * + * @return AnnotationBase + */ + public abstract AnnotationBase annotateWord(); + + /** + *

+ * Add area annotation into the pdf document + *

+ * + * @return AnnotationBase + */ + public abstract AnnotationBase annotatePdf(); + + ///// + ///// Add area annotation into the Excel document + ///// + ///// AnnotationBase + public abstract AnnotationBase annotateCells(); + + /** + *

+ * Add area annotation into the Power Point document + *

+ * + * @return AnnotationBase + */ + public abstract AnnotationBase annotateSlides(); + + /** + *

+ * Add area annotation into the image document + *

+ * + * @return AnnotationBase + */ + public abstract AnnotationBase annotateImage(); + + /** + *

+ * Add area annotation into the document + *

+ * + * @return AnnotationBase + */ + public abstract AnnotationBase annotateDiagram(); + + /** + *

+ * Initial for annotation info + *

+ * + * @param annotationBase + * @return AnnotationBase + */ + protected final AnnotationBase initAnnotationBase(AnnotationBase annotationBase) { + // set page number to add annotation + annotationBase.setPageNumber(annotationData.getPageNumber() - 1); + // set annotation type + annotationBase.setType(getType()); + annotationBase.setCreatedOn(Date.from(Instant.now())); + annotationBase.setId(annotationData.getId()); + // add replies + CommentsEntity[] comments = annotationData.getComments(); + if (comments != null && comments.length != 0) { + java.util.List replies = new ArrayList<>(); + for (int i = 0; i < comments.length; i++) { + Reply reply = getAnnotationReplyInfo(comments[i]); + replies.add(reply); + } + annotationBase.setReplies(replies); + } + return annotationBase; + } + + /** + *

+ * Initial for reply annotation info + *

+ * + * @return AnnotationReplyInfo + * @param comment CommentsEntity + */ + protected Reply getAnnotationReplyInfo(CommentsEntity comment) { + Reply reply = new Reply(); + reply.setComment(comment.getText()); + DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); + format.setTimeZone(TimeZone.getTimeZone("GMT")); + Date date; + try { + date = new Date(Long.parseLong(comment.getTime())); + } catch (Exception e) { + try { + date = format.parse(comment.getTime()); + } catch (Exception exc) { + format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); + try { + date = format.parse(comment.getTime()); + } catch (ParseException ex) { + throw new TotalGroupDocsException(ex); + } + } + } + reply.setRepliedOn(date); + reply.setUser(new User()); + reply.getUser().setName(comment.getUserName()); + return reply; + } + + /** + *

+ * Get rectangle + *

+ * + * @return Rectangle + */ + protected Rectangle getBox() { + return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + } + + /** + *

+ * Get type of annotation + *

+ * + * @return byte + */ + protected abstract int getType(); + + /** + *

+ * Get Annotation info depending on document type + *

+ * + * @return AnnotationBase + * @param documentType string + */ + public final AnnotationBase getAnnotationBase(String documentType) { + switch (documentType) { + case "Portable Document Format": + return annotatePdf(); + case "Microsoft Word": + case "Open Document Text": + return annotateWord(); + case "Rich Text Format": + return annotateWord(); + case "Microsoft PowerPoint": + return annotateSlides(); + case "image": + return annotateImage(); + case "Microsoft Excel": + return annotateCells(); + case "AutoCAD Drawing File Format": + return annotateDiagram(); + default: + throw new TotalGroupDocsException("Wrong annotation data without document type!"); + } + } + + /** + *

+ * Check if the current annotatin is supported + *

+ * + * @return + * @param documentType string + */ + public final boolean isSupported(String documentType) { + try { + AnnotatorFactory.createAnnotator(annotationData, pageInfo).getAnnotationBase(documentType); + return true; + } catch (java.lang.UnsupportedOperationException e) { + Message += annotationData.getType(); + return false; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/DistanceAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/DistanceAnnotator.java index 0c4b843..a51cfee 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/DistanceAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/DistanceAnnotator.java @@ -1,84 +1,92 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationReplyInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.Rectangle; +import com.groupdocs.annotation.models.Reply; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.DistanceAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; import com.groupdocs.ui.annotation.entity.web.CommentsEntity; -import java.text.ParseException; +public class DistanceAnnotator extends BaseAnnotator { -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class DistanceAnnotator extends AbstractBoxAnnotator { + private DistanceAnnotation distanceAnnotation; - public DistanceAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); + public DistanceAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + distanceAnnotation = new DistanceAnnotation(); + distanceAnnotation.setBox(getBox()); } @Override - public AnnotationInfo annotateWord() throws ParseException { - AnnotationInfo distanceAnnotation = initAnnotationInfo(); + public AnnotationBase annotateWord() { + distanceAnnotation = (DistanceAnnotation) initAnnotationBaseDistanceAnnotator(distanceAnnotation); return distanceAnnotation; } @Override - public AnnotationInfo annotatePdf() throws ParseException { - AnnotationInfo distanceAnnotation = initAnnotationInfo(); - return distanceAnnotation; + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() throws ParseException { - // init annotation object - AnnotationInfo distanceAnnotation = initAnnotationInfo(); - distanceAnnotation.setBackgroundColor(15988609); - return distanceAnnotation; + public AnnotationBase annotateImage() { + return annotateWord(); } - @Override - public AnnotationInfo annotateDiagram() throws ParseException { - // init annotation object - AnnotationInfo distanceAnnotation = initAnnotationInfo(); - distanceAnnotation.setBackgroundColor(15988609); - return distanceAnnotation; + public AnnotationBase annotateDiagram() { + return annotateWord(); } - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo distanceAnnotation = super.initAnnotationInfo(); + protected final AnnotationBase initAnnotationBaseDistanceAnnotator(AnnotationBase annotationBase) { + distanceAnnotation = (DistanceAnnotation) super.initAnnotationBase(annotationBase); + String tmp0 = annotationData.getText(); + if (tmp0 == null) { + tmp0 = ""; + } // add replies - String text = (annotationData.getText() == null) ? "" : annotationData.getText(); + String text = tmp0; CommentsEntity[] comments = annotationData.getComments(); if (comments != null && comments.length != 0) { - AnnotationReplyInfo reply = distanceAnnotation.getReplies()[0]; + Reply reply = distanceAnnotation.getReplies().get(0); if (reply != null) { - reply.setMessage(String.format("%s %s", annotationData.getText(), reply.getMessage())); + reply.setComment(String.format("{0} {1}", text, reply.getComment())); } - } else { - distanceAnnotation.setFieldText(text); } + return distanceAnnotation; } @Override - protected byte getType() { + protected int getType() { return AnnotationType.Distance; } -} \ No newline at end of file + + @Override + protected Rectangle getBox() { + String svgPath = annotationData.getSvgPath(); + + String startPoint = svgPath.replaceAll("[a-zA-Z]+", "").split(" ")[0]; + String endPoint = svgPath.replaceAll("[a-zA-Z]+", "").split(" ")[1]; + String[] start = startPoint.split(","); + float startX = Float.parseFloat(start.length > 0 ? start[0] : "0"); + float startY = Float.parseFloat(start.length > 1 ? start[1] : "0"); + String[] end = endPoint.split(","); + float endX = Float.parseFloat(end.length > 0 ? end[0] : "0") - startX; + float endY = Float.parseFloat(end.length > 1 ? end[1] : "0") - startY; + return new Rectangle(startX, startY, endX, endY); + } +} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/PointAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/PointAnnotator.java index f1cbbe2..2a4efe5 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/PointAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/PointAnnotator.java @@ -1,69 +1,56 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.*; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.PointAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import java.text.ParseException; -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class PointAnnotator extends Annotator { +public class PointAnnotator extends BaseAnnotator { - public PointAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } + private PointAnnotation pointAnnotation; - @Override - public AnnotationInfo annotateWord() throws ParseException { - return initAnnotationInfo(); - } + public PointAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); - @Override - public AnnotationInfo annotatePdf() throws ParseException { - return initAnnotationInfo(); + pointAnnotation = new PointAnnotation(); + pointAnnotation.setBox(getBox()); } @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - // init annotation object - AnnotationInfo pointAnnotation = super.initAnnotationInfo(); - // set annotation position - pointAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); + public AnnotationBase annotateWord() { + pointAnnotation = (PointAnnotation) super.initAnnotationBase(pointAnnotation); return pointAnnotation; } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateSlides() { + return annotateWord(); } - @Override - public AnnotationInfo annotateDiagram() throws ParseException { - return initAnnotationInfo(); + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + public AnnotationBase annotateDiagram() { + return annotateWord(); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.Point; } -} \ No newline at end of file +} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/PolylineAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/PolylineAnnotator.java index c984c1a..96a5df6 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/PolylineAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/PolylineAnnotator.java @@ -1,92 +1,79 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.User; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.PolylineAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; import com.groupdocs.ui.annotation.entity.web.CommentsEntity; -import java.text.ParseException; -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class PolylineAnnotator extends Annotator { +public class PolylineAnnotator extends BaseAnnotator { - public PolylineAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } + private PolylineAnnotation polylineAnnotation; - @Override - public AnnotationInfo annotateWord() throws ParseException { - return initAnnotationInfo(); - } + public PolylineAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + this.polylineAnnotation = new PolylineAnnotation(); + this.polylineAnnotation.setBox(getBox()); + this.polylineAnnotation.setPenColor(1201033); + this.polylineAnnotation.setPenWidth((byte) 2); + this.polylineAnnotation.setSvgPath(annotationData.getSvgPath()); + } @Override - public AnnotationInfo annotatePdf() throws ParseException { - AnnotationInfo polylineAnnotation = initAnnotationInfo(); + public AnnotationBase annotateWord() { + polylineAnnotation = (PolylineAnnotation) initAnnotationBase(polylineAnnotation); return polylineAnnotation; } @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo polylineAnnotation = super.initAnnotationInfo(); - polylineAnnotation.setPenColor(1201033); - polylineAnnotation.setPenWidth((byte) 2); - polylineAnnotation.setSvgPath(annotationData.getSvgPath()); - return polylineAnnotation; + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - AnnotationInfo polylineAnnotation = initAnnotationInfo(); - fillCreatorName(polylineAnnotation); + public AnnotationBase annotateSlides() { + polylineAnnotation = (PolylineAnnotation) initAnnotationBase(polylineAnnotation); + fillCreatorName(polylineAnnotation, annotationData); return polylineAnnotation; } /** + *

* Fill creator name field in annotation info + *

* - * @param polylineAnnotation annotation info + * @param polylineAnnotation AnnotationBase + * @param annotationData */ - protected void fillCreatorName(AnnotationInfo polylineAnnotation) { + protected static void fillCreatorName(AnnotationBase polylineAnnotation, AnnotationDataEntity annotationData) { CommentsEntity[] comments = annotationData.getComments(); if (comments != null && comments.length > 0 && comments[0] != null) { - polylineAnnotation.setCreatorName(comments[0].getUserName()); + polylineAnnotation.setUser(new User()); + polylineAnnotation.getUser().setName(comments[0].getUserName()); } } @Override - public AnnotationInfo annotateImage() throws ParseException { - AnnotationInfo polylineAnnotation = initAnnotationInfo(); - fillCreatorName(polylineAnnotation); - return polylineAnnotation; - } - - @Override - public AnnotationInfo annotateDiagram() throws ParseException { - AnnotationInfo polylineAnnotation = initAnnotationInfo(); - fillCreatorName(polylineAnnotation); - return polylineAnnotation; + public AnnotationBase annotateImage() { + return annotateSlides(); } @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + public AnnotationBase annotateDiagram() { + return annotateSlides(); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.Polyline; } -} \ No newline at end of file +} diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/ResourceRedactionAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/ResourceRedactionAnnotator.java index 6ba6625..1933748 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/ResourceRedactionAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/ResourceRedactionAnnotator.java @@ -1,68 +1,57 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.*; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.ResourcesRedactionAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; -import java.text.ParseException; -/** - * AreaAnnotator - * Annotates documents with the area annotation - * - * @author Aspose Pty Ltd - */ -public class ResourceRedactionAnnotator extends Annotator { +public class ResourceRedactionAnnotator extends BaseAnnotator { - public ResourceRedactionAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } + private ResourcesRedactionAnnotation resourcesRedactionAnnotation; - @Override - public AnnotationInfo annotateWord() throws ParseException { - AnnotationInfo resourceRedactionAnnotation = initAnnotationInfo(); - return resourceRedactionAnnotation; + public ResourceRedactionAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + this.resourcesRedactionAnnotation = new ResourcesRedactionAnnotation(); + this.resourcesRedactionAnnotation.setBox(getBox()); } @Override - public AnnotationInfo annotatePdf() throws ParseException { - // initiate AnnotationInfo object - AnnotationInfo resourceRedactionAnnotation = initAnnotationInfo(); - // set annotation X, Y position - resourceRedactionAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - return resourceRedactionAnnotation; + public AnnotationBase annotateWord() { + resourcesRedactionAnnotation = (ResourcesRedactionAnnotation) initAnnotationBase(resourcesRedactionAnnotation); + return resourcesRedactionAnnotation; } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - AnnotationInfo resourceRedactionAnnotation = initAnnotationInfo(); - return resourceRedactionAnnotation; + public AnnotationBase annotateCells() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - public AnnotationInfo annotateImage() throws ParseException { - AnnotationInfo resourceRedactionAnnotation = initAnnotationInfo(); - return resourceRedactionAnnotation; + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() throws ParseException { - // init annotation object - AnnotationInfo resourceRedactionAnnotation = initAnnotationInfo(); - return resourceRedactionAnnotation; + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); + public AnnotationBase annotateDiagram() { + return annotateWord(); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.ResourcesRedaction; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TexStrikeoutAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TexStrikeoutAnnotator.java deleted file mode 100644 index f90e6b3..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TexStrikeoutAnnotator.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Point; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; - -import java.text.ParseException; - -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TexStrikeoutAnnotator extends AbstractSvgAnnotator { - - public TexStrikeoutAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - public AnnotationInfo annotateWord() throws ParseException { - // init possible types of annotations - AnnotationInfo strikeoutAnnotation = initAnnotationInfo(); - fixBox(strikeoutAnnotation); - return strikeoutAnnotation; - } - - @Override - public AnnotationInfo annotatePdf() throws ParseException { - AnnotationInfo strikeoutAnnotation = initAnnotationInfo(); - strikeoutAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - strikeoutAnnotation.setPenColor(0); - strikeoutAnnotation.setGuid(String.valueOf(annotationData.getId())); - return strikeoutAnnotation; - } - - @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); - } - - @Override - public AnnotationInfo annotateSlides() throws ParseException { - AnnotationInfo strikeoutAnnotation = initAnnotationInfo(); - fixBox(strikeoutAnnotation); - strikeoutAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - strikeoutAnnotation.setPenColor(0); - return strikeoutAnnotation; - } - - @Override - public AnnotationInfo annotateImage() throws ParseException { - return initAnnotationInfo(); - } - - @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); - } - - @Override - protected byte getType() { - return AnnotationType.TextStrikeout; - } -} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TexUnderlineAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TexUnderlineAnnotator.java deleted file mode 100644 index 727476c..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TexUnderlineAnnotator.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Point; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; - -import java.text.ParseException; - -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TexUnderlineAnnotator extends AbstractSvgAnnotator { - - public TexUnderlineAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - public AnnotationInfo annotateWord() throws ParseException { - // init possible types of annotations - AnnotationInfo underlineAnnotation = initAnnotationInfo(); - // set line color - underlineAnnotation.setPenColor(1201033); - fixBox(underlineAnnotation); - return underlineAnnotation; - } - - @Override - public AnnotationInfo annotatePdf() throws ParseException { - AnnotationInfo underlineAnnotation = initAnnotationInfo(); - underlineAnnotation.setGuid(String.valueOf(annotationData.getId())); - underlineAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - underlineAnnotation.setPenColor(1201033); - return underlineAnnotation; - } - - @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); - } - - @Override - public AnnotationInfo annotateSlides() throws ParseException { - AnnotationInfo underlineAnnotation = initAnnotationInfo(); - fixBox(underlineAnnotation); - underlineAnnotation.setPenColor(0); - underlineAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - return underlineAnnotation; - } - - @Override - public AnnotationInfo annotateImage() throws ParseException { - AnnotationInfo annotationInfo = initAnnotationInfo(); - return annotationInfo; - } - - @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); - } - - @Override - protected byte getType() { - return AnnotationType.TextUnderline; - } -} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextAnnotator.java deleted file mode 100644 index 9dfc392..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TextAnnotator.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.groupdocs.ui.annotation.annotator; - -import com.groupdocs.annotation.domain.*; -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; - -import java.text.ParseException; - -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TextAnnotator extends AbstractSvgAnnotator { - - public TextAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } - - @Override - public AnnotationInfo annotateWord() throws ParseException { - // init possible types of annotations - AnnotationInfo textAnnotation = initAnnotationInfo(); - return textAnnotation; - } - - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo textAnnotation = super.initAnnotationInfo(); - textAnnotation.setGuid(String.valueOf(annotationData.getId())); - return textAnnotation; - } - - @Override - public AnnotationInfo annotatePdf() throws ParseException { - // init possible types of annotations - AnnotationInfo textAnnotation = initAnnotationInfo(); - return textAnnotation; - } - - @Override - public AnnotationInfo annotateCells() throws ParseException { - // init possible types of annotations - AnnotationInfo textAnnotation = super.initAnnotationInfo(); - textAnnotation.setPageNumber(annotationData.getPageNumber()); - textAnnotation.setAnnotationPosition(new Point(1, 1)); - textAnnotation.setBox(new Rectangle(0, 0, 0, 0)); - return textAnnotation; - } - - @Override - public AnnotationInfo annotateSlides() throws ParseException { - // init possible types of annotations - AnnotationInfo textAnnotation = initAnnotationInfo(); - textAnnotation.getBox().setX((float) (annotationData.getLeft() / 4)); - return textAnnotation; - } - - @Override - public AnnotationInfo annotateImage() throws ParseException { - return initAnnotationInfo(); - } - - @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); - } - - @Override - protected Rectangle getBox() { - return new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight()); - } - - @Override - protected byte getType() { - return AnnotationType.Text; - } -} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextFieldAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextFieldAnnotator.java index d924cb6..2e62d73 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TextFieldAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextFieldAnnotator.java @@ -1,70 +1,61 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Point; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.TextFieldAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import java.text.ParseException; -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TextFieldAnnotator extends AbstractTextAnnotator { +public class TextFieldAnnotator extends BaseAnnotator { - public TextFieldAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); + private TextFieldAnnotation textFieldAnnotation; + + public TextFieldAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + textFieldAnnotation = new TextFieldAnnotation(); + textFieldAnnotation.setBox(getBox()); + + textFieldAnnotation.setFontFamily(annotationData.getFont() != null || !"".equals(annotationData.getFont()) ? annotationData.getFont() : "Arial"); + textFieldAnnotation.setFontColor(annotationData.getFontColor()); + textFieldAnnotation.setFontSize(annotationData.getFontSize() == 0 ? 12 : annotationData.getFontSize()); + textFieldAnnotation.setText(annotationData.getText()); } @Override - public AnnotationInfo annotateWord() throws ParseException { - // init possible types of annotations - AnnotationInfo textFieldAnnotation = initAnnotationInfo(); + public AnnotationBase annotateWord() { + textFieldAnnotation = (TextFieldAnnotation) initAnnotationBase(textFieldAnnotation); return textFieldAnnotation; } @Override - public AnnotationInfo annotatePdf() throws ParseException { - // init possible types of annotations - // Text field annotation - AnnotationInfo textFieldAnnotation = initAnnotationInfo(); - textFieldAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - textFieldAnnotation.setBackgroundColor(16777215); - return textFieldAnnotation; + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - // init possible types of annotations - AnnotationInfo textFieldAnnotation = initAnnotationInfo(); - return textFieldAnnotation; + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() throws ParseException { - // init possible types of annotations - AnnotationInfo textFieldAnnotation = initAnnotationInfo(); - return textFieldAnnotation; + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() throws ParseException { - // init possible types of annotations - AnnotationInfo textFieldAnnotation = initAnnotationInfo(); - return textFieldAnnotation; + public AnnotationBase annotateDiagram() { + return annotateWord(); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.TextField; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextHighlightAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextHighlightAnnotator.java new file mode 100644 index 0000000..b701943 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextHighlightAnnotator.java @@ -0,0 +1,57 @@ +package com.groupdocs.ui.annotation.annotator; + +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.HighlightAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; +import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; + + +public class TextHighlightAnnotator extends AbstractTextAnnotator { + + private HighlightAnnotation highlightAnnotation; + + public TextHighlightAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + highlightAnnotation = new HighlightAnnotation(); + highlightAnnotation.setPoints(getPoints(annotationData, pageInfo)); + } + + @Override + public AnnotationBase annotateWord() { + highlightAnnotation = (HighlightAnnotation) initAnnotationBase(highlightAnnotation); + return highlightAnnotation; + } + + @Override + public AnnotationBase annotatePdf() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateCells() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateSlides() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateImage() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); + } + + @Override + protected int getType() { + return AnnotationType.TextHighlight; + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextRedactionAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextRedactionAnnotator.java index bf47edc..ac4e8be 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TextRedactionAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextRedactionAnnotator.java @@ -1,45 +1,51 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.TextRedactionAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TextRedactionAnnotator extends TextAnnotator { +public class TextRedactionAnnotator extends TextHighlightAnnotator { - public TextRedactionAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); + private TextRedactionAnnotation textRedactionAnnotation; + + public TextRedactionAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + textRedactionAnnotation = new TextRedactionAnnotation(); + textRedactionAnnotation.setPoints(getPoints(annotationData, pageInfo)); + } + + @Override + public AnnotationBase annotateCells() { + return annotatePdf(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateSlides() { + return annotatePdf(); } @Override - public AnnotationInfo annotateSlides() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateImage() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - public AnnotationInfo annotateImage() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotatePdf() { + textRedactionAnnotation = (TextRedactionAnnotation) initAnnotationBase(textRedactionAnnotation); + return textRedactionAnnotation; } @Override - protected byte getType() { + protected int getType() { return AnnotationType.TextRedaction; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextReplacementAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextReplacementAnnotator.java index 4a9026e..9291466 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/TextReplacementAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextReplacementAnnotator.java @@ -1,84 +1,58 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Rectangle; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.ReplacementAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; -import java.text.ParseException; -/** - * TextAnnotator - * Annotates documents with the text annotation - * - * @author Aspose Pty Ltd - */ -public class TextReplacementAnnotator extends AbstractSvgAnnotator { +public class TextReplacementAnnotator extends AbstractTextAnnotator { - public TextReplacementAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); - } + private ReplacementAnnotation replacementAnnotation; - @Override - public AnnotationInfo annotateWord() throws ParseException { - // init possible types of annotations - AnnotationInfo textReplacementAnnotation = initAnnotationInfo(); - return textReplacementAnnotation; - } + public TextReplacementAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); - @Override - protected AnnotationInfo initAnnotationInfo() throws ParseException { - AnnotationInfo textReplacementAnnotation = super.initAnnotationInfo(); - textReplacementAnnotation.setGuid(String.valueOf(annotationData.getId())); - textReplacementAnnotation.setFieldText(annotationData.getText()); - return textReplacementAnnotation; - } - - @Override - protected String buildSvgPath() { - double topPosition = pageData.getHeight() - annotationData.getTop(); - double leftPosition = pageData.getWidth() - annotationData.getLeft(); - double topRightX = annotationData.getLeft() + annotationData.getWidth(); - double bottomRightY = topPosition - annotationData.getHeight(); - return super.getSvgString(topPosition, leftPosition, topRightX, bottomRightY); + replacementAnnotation = new ReplacementAnnotation(); + replacementAnnotation.setPoints(getPoints(annotationData, pageInfo)); + replacementAnnotation.setTextToReplace(annotationData.getText()); } @Override - public AnnotationInfo annotatePdf() throws ParseException { - // init possible types of annotations - AnnotationInfo textReplacementAnnotation = initAnnotationInfo(); - textReplacementAnnotation.setBox(new Rectangle(annotationData.getLeft(), annotationData.getTop(), annotationData.getWidth(), annotationData.getHeight())); - return textReplacementAnnotation; + public AnnotationBase annotateWord() { + replacementAnnotation = (ReplacementAnnotation) initAnnotationBase(replacementAnnotation); + return replacementAnnotation; } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateImage() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - protected Rectangle getBox() { - return new Rectangle(0, 0, 0, 0); + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.TextReplacement; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextStrikeoutAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextStrikeoutAnnotator.java new file mode 100644 index 0000000..f5a6a5c --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextStrikeoutAnnotator.java @@ -0,0 +1,58 @@ +package com.groupdocs.ui.annotation.annotator; + +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.StrikeoutAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; +import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; + +public class TextStrikeoutAnnotator extends AbstractTextAnnotator { + + private StrikeoutAnnotation strikeoutAnnotation; + + public TextStrikeoutAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + strikeoutAnnotation = new StrikeoutAnnotation(); + strikeoutAnnotation.setPoints(getPoints(annotationData, pageInfo)); + } + + @Override + public AnnotationBase annotateWord() { + strikeoutAnnotation = (StrikeoutAnnotation) initAnnotationBase(strikeoutAnnotation); + return strikeoutAnnotation; + } + + @Override + public AnnotationBase annotatePdf() { + strikeoutAnnotation = (StrikeoutAnnotation) initAnnotationBase(strikeoutAnnotation); + this.strikeoutAnnotation.setFontColor(0); + return strikeoutAnnotation; + } + + @Override + public AnnotationBase annotateCells() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateSlides() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateImage() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); + } + + @Override + protected int getType() { + return AnnotationType.TextStrikeout; + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/TextUnderlineAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/TextUnderlineAnnotator.java new file mode 100644 index 0000000..53956be --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/TextUnderlineAnnotator.java @@ -0,0 +1,60 @@ +package com.groupdocs.ui.annotation.annotator; + +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.UnderlineAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; +import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; + + +public class TextUnderlineAnnotator extends AbstractTextAnnotator { + + private UnderlineAnnotation underlineAnnotation; + + public TextUnderlineAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + underlineAnnotation = new UnderlineAnnotation(); + underlineAnnotation.setPoints(getPoints(annotationData, pageInfo)); + } + + @Override + public AnnotationBase annotateWord() { + underlineAnnotation = (UnderlineAnnotation) initAnnotationBase(underlineAnnotation); + underlineAnnotation.setFontColor(1201033); + return underlineAnnotation; + } + + @Override + public AnnotationBase annotatePdf() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateCells() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateSlides() { + underlineAnnotation = (UnderlineAnnotation) initAnnotationBase(underlineAnnotation); + underlineAnnotation.setFontColor(0); + return underlineAnnotation; + } + + @Override + public AnnotationBase annotateImage() { + return annotateWord(); + } + + @Override + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); + } + + @Override + protected int getType() { + return AnnotationType.TextUnderline; + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/annotator/WatermarkAnnotator.java b/src/main/java/com/groupdocs/ui/annotation/annotator/WatermarkAnnotator.java index 3e9cc11..3e8c06a 100644 --- a/src/main/java/com/groupdocs/ui/annotation/annotator/WatermarkAnnotator.java +++ b/src/main/java/com/groupdocs/ui/annotation/annotator/WatermarkAnnotator.java @@ -1,66 +1,60 @@ package com.groupdocs.ui.annotation.annotator; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationType; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.Point; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.WatermarkAnnotation; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; -import java.text.ParseException; +public class WatermarkAnnotator extends BaseAnnotator { -/** - * WatermarkAnnotator - * Annotates documents with the watermark annotation - * - * @author Aspose Pty Ltd - */ -public class WatermarkAnnotator extends AbstractTextAnnotator { + private WatermarkAnnotation watermarkAnnotation; - public WatermarkAnnotator(AnnotationDataEntity annotationData, PageData pageData) { - super(annotationData, pageData); + public WatermarkAnnotator(AnnotationDataEntity annotationData, PageInfo pageInfo) { + super(annotationData, pageInfo); + + watermarkAnnotation = new WatermarkAnnotation(); + watermarkAnnotation.setBox(getBox()); + watermarkAnnotation.setFontFamily(annotationData.getFont() != null || !"".equals(annotationData.getFont()) ? annotationData.getFont() : "Arial"); + watermarkAnnotation.setFontColor(annotationData.getFontColor()); + watermarkAnnotation.setFontSize(annotationData.getFontSize() == 0 ? 12 : annotationData.getFontSize()); + watermarkAnnotation.setText(annotationData.getText()); } @Override - public AnnotationInfo annotateWord() throws ParseException { - AnnotationInfo watermarkAnnotation = initAnnotationInfo(); - watermarkAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); + public AnnotationBase annotateWord() { + watermarkAnnotation = (WatermarkAnnotation) initAnnotationBase(watermarkAnnotation); return watermarkAnnotation; } @Override - public AnnotationInfo annotatePdf() throws ParseException { - // init possible types of annotations - AnnotationInfo watermarkAnnotation = initAnnotationInfo(); - watermarkAnnotation.setAnnotationPosition(new Point(annotationData.getLeft(), annotationData.getTop())); - return watermarkAnnotation; + public AnnotationBase annotatePdf() { + return annotateWord(); } @Override - public AnnotationInfo annotateCells() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateCells() { + return annotateWord(); } @Override - public AnnotationInfo annotateSlides() throws ParseException { - // init possible types of annotations - AnnotationInfo watermarkAnnotation = initAnnotationInfo(); - return watermarkAnnotation; + public AnnotationBase annotateSlides() { + return annotateWord(); } @Override - public AnnotationInfo annotateImage() throws ParseException { - // init possible types of annotations - AnnotationInfo watermarkAnnotation = initAnnotationInfo(); - return watermarkAnnotation; + public AnnotationBase annotateImage() { + return annotateWord(); } @Override - public AnnotationInfo annotateDiagram() { - throw new UnsupportedOperationException(String.format(MESSAGE, annotationData.getType())); + public AnnotationBase annotateDiagram() { + throw new TotalGroupDocsException(Message + annotationData.getType()); } @Override - protected byte getType() { + protected int getType() { return AnnotationType.Watermark; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/config/AnnotationConfiguration.java b/src/main/java/com/groupdocs/ui/annotation/config/AnnotationConfiguration.java index 00eb1ef..73612cd 100644 --- a/src/main/java/com/groupdocs/ui/annotation/config/AnnotationConfiguration.java +++ b/src/main/java/com/groupdocs/ui/annotation/config/AnnotationConfiguration.java @@ -4,16 +4,14 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; - import javax.annotation.PostConstruct; - import static com.groupdocs.ui.config.DefaultDirectories.defaultAnnotationDirectory; import static com.groupdocs.ui.config.DefaultDirectories.relativePathToAbsolute; /** + *

* AnnotationConfiguration - * - * @author Aspose Pty Ltd + *

*/ @Component public class AnnotationConfiguration extends CommonConfiguration { @@ -256,29 +254,29 @@ public void setFitWidth(boolean fitWidth) { @Override public String toString() { - return super.toString() + - "AnnotationConfiguration{" + - "filesDirectory='" + filesDirectory + '\'' + - ", defaultDocument='" + defaultDocument + '\'' + - ", preloadPageCount=" + preloadPageCount + - ", fontsDirectory='" + fontsDirectory + '\'' + - ", textAnnotation=" + textAnnotation + - ", areaAnnotation=" + areaAnnotation + - ", pointAnnotation=" + pointAnnotation + - ", textStrikeoutAnnotation=" + textStrikeoutAnnotation + - ", polylineAnnotation=" + polylineAnnotation + - ", textFieldAnnotation=" + textFieldAnnotation + - ", watermarkAnnotation=" + watermarkAnnotation + - ", textReplacementAnnotation=" + textReplacementAnnotation + - ", arrowAnnotation=" + arrowAnnotation + - ", textRedactionAnnotation=" + textRedactionAnnotation + - ", resourcesRedactionAnnotation=" + resourcesRedactionAnnotation + - ", textUnderlineAnnotation=" + textUnderlineAnnotation + - ", distanceAnnotation=" + distanceAnnotation + - ", downloadOriginal=" + downloadOriginal + - ", downloadAnnotated=" + downloadAnnotated + - ", zoom=" + zoom + - ", fitWidth=" + fitWidth + - '}'; + return super.toString() + + "AnnotationConfiguration{" + + "filesDirectory='" + filesDirectory + '\'' + + ", defaultDocument='" + defaultDocument + '\'' + + ", preloadPageCount=" + preloadPageCount + + ", fontsDirectory='" + fontsDirectory + '\'' + + ", textAnnotation=" + textAnnotation + + ", areaAnnotation=" + areaAnnotation + + ", pointAnnotation=" + pointAnnotation + + ", textStrikeoutAnnotation=" + textStrikeoutAnnotation + + ", polylineAnnotation=" + polylineAnnotation + + ", textFieldAnnotation=" + textFieldAnnotation + + ", watermarkAnnotation=" + watermarkAnnotation + + ", textReplacementAnnotation=" + textReplacementAnnotation + + ", arrowAnnotation=" + arrowAnnotation + + ", textRedactionAnnotation=" + textRedactionAnnotation + + ", resourcesRedactionAnnotation=" + resourcesRedactionAnnotation + + ", textUnderlineAnnotation=" + textUnderlineAnnotation + + ", distanceAnnotation=" + distanceAnnotation + + ", downloadOriginal=" + downloadOriginal + + ", downloadAnnotated=" + downloadAnnotated + + ", zoom=" + zoom + + ", fitWidth=" + fitWidth + + '}'; } } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/controller/AnnotationController.java b/src/main/java/com/groupdocs/ui/annotation/controller/AnnotationController.java index 0adc707..b997491 100644 --- a/src/main/java/com/groupdocs/ui/annotation/controller/AnnotationController.java +++ b/src/main/java/com/groupdocs/ui/annotation/controller/AnnotationController.java @@ -1,10 +1,10 @@ package com.groupdocs.ui.annotation.controller; import com.groupdocs.ui.annotation.config.AnnotationConfiguration; -import com.groupdocs.ui.annotation.entity.request.AnnotateDocumentRequest; import com.groupdocs.ui.annotation.entity.web.AnnotatedDocumentEntity; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import com.groupdocs.ui.annotation.entity.web.AnnotationPageDescriptionEntity; +import com.groupdocs.ui.annotation.entity.web.AnnotationPostedDataEntity; +import com.groupdocs.ui.annotation.entity.web.PageDataDescriptionEntity; import com.groupdocs.ui.annotation.service.AnnotationService; import com.groupdocs.ui.config.GlobalConfiguration; import com.groupdocs.ui.exception.TotalGroupDocsException; @@ -22,7 +22,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; - import javax.annotation.Nullable; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -32,7 +31,6 @@ import java.io.InputStream; import java.util.List; import java.util.Map; - import static com.groupdocs.ui.util.Utils.setLocalPort; import static com.groupdocs.ui.util.Utils.uploadFile; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @@ -46,6 +44,7 @@ @Controller @RequestMapping(value = "/annotation") public class AnnotationController { + private static final Logger logger = LoggerFactory.getLogger(AnnotationController.class); @Autowired @@ -93,6 +92,7 @@ public List loadFileTree(@RequestBody FileTreeRequest fil /** * Get document description * + * @param loadDocumentRequest * @return document description */ @RequestMapping(value = "/loadDocumentDescription", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @@ -104,11 +104,12 @@ public AnnotatedDocumentEntity loadDocumentDescription(@RequestBody LoadDocument /** * Get document page * + * @param loadDocumentPageRequest * @return document page */ @RequestMapping(value = "/loadDocumentPage", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @ResponseBody - public AnnotationPageDescriptionEntity loadDocumentPage(@RequestBody LoadDocumentPageRequest loadDocumentPageRequest) { + public PageDataDescriptionEntity loadDocumentPage(@RequestBody LoadDocumentPageRequest loadDocumentPageRequest) { return annotationService.getDocumentPage(loadDocumentPageRequest); } @@ -119,8 +120,7 @@ public AnnotationPageDescriptionEntity loadDocumentPage(@RequestBody LoadDocumen * @param response http response */ @RequestMapping(value = "/downloadDocument", method = RequestMethod.GET) - public void downloadDocument(@RequestParam("path") String documentGuid, - HttpServletResponse response) { + public void downloadDocument(@RequestParam("path") String documentGuid, HttpServletResponse response) { // get document path String fileName = FilenameUtils.getName(documentGuid); @@ -165,10 +165,13 @@ public UploadedDocumentEntity uploadDocument(@Nullable @RequestParam("file") Mul /** * Annotate document with annotations and download result without saving * - * @return annotated document info + * @param annotateDocumentRequest + * @param response */ @RequestMapping(method = RequestMethod.POST, value = "/downloadAnnotated", consumes = APPLICATION_JSON_VALUE) - public void downloadAnnotated(@RequestBody AnnotateDocumentRequest annotateDocumentRequest, HttpServletResponse response) { + public void downloadAnnotated(@RequestBody AnnotationPostedDataEntity annotateDocumentRequest, HttpServletResponse response) { +// @Route("annotation/downloadAnnotated") +// public final HttpResponseMessage downloadAnnotated(String path) { AnnotationDataEntity[] annotationsData = annotateDocumentRequest.getAnnotationsData(); if (annotationsData == null || annotationsData.length == 0) { throw new IllegalArgumentException("Annotations data is empty"); @@ -199,8 +202,7 @@ public void downloadAnnotated(@RequestBody AnnotateDocumentRequest annotateDocum */ @RequestMapping(value = "/annotate", method = RequestMethod.POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) @ResponseBody - public AnnotatedDocumentEntity annotate(@RequestBody AnnotateDocumentRequest annotateDocumentRequest) { + public AnnotatedDocumentEntity annotate(@RequestBody AnnotationPostedDataEntity annotateDocumentRequest) { return annotationService.annotate(annotateDocumentRequest); } - } \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/Annotations.java b/src/main/java/com/groupdocs/ui/annotation/entity/Annotations.java new file mode 100644 index 0000000..db2c999 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/Annotations.java @@ -0,0 +1,75 @@ +package com.groupdocs.annotation.entity; + +public class Annotations { + + public String[] Cells = { + "textHighlight" + }; + public String[] Diagram = { + "area", + "point", + "polyline", + "textField", + "arrow", + "textRedaction", + "resourcesRedaction", + "distance" + }; + public String[] Word = { + "area", + "point", + "textStrikeout", + "polyline", + "textField", + "watermark", + "textReplacement", + "arrow", + "textRedaction", + "resourcesRedaction", + "textUnderline", + "distance", + "textHighlight" + }; + public String[] Pdf = { + "area", + "point", + "textStrikeout", + "polyline", + "textField", + "watermark", + "textReplacement", + "arrow", + "textRedaction", + "resourcesRedaction", + "textUnderline", + "distance", + "textHighlight" + }; + public String[] Image = { + "area", + "point", + "textStrikeout", + "polyline", + "textField", + "watermark", + "arrow", + "textRedaction", + "resourcesRedaction", + "textUnderline", + "distance", + "textHighlight" + }; + public String[] Slides = { + "area", + "point", + "textStrikeout", + "polyline", + "textField", + "watermark", + "arrow", + "textRedaction", + "resourcesRedaction", + "textUnderline", + "textHighlight" + }; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/request/AnnotateDocumentRequest.java b/src/main/java/com/groupdocs/ui/annotation/entity/request/AnnotateDocumentRequest.java deleted file mode 100644 index 9a89e07..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/entity/request/AnnotateDocumentRequest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.groupdocs.ui.annotation.entity.request; - -import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import com.groupdocs.ui.model.request.LoadDocumentRequest; - -/** - * AnnotateDocumentRequest - * - * @author Aspose Pty Ltd - */ -public class AnnotateDocumentRequest extends LoadDocumentRequest { - /** - * List of annotation data - */ - private AnnotationDataEntity[] annotationsData; - /** - * Document type - */ - private String documentType; - /** - * For print annotated file - */ - private Boolean print; - - public AnnotationDataEntity[] getAnnotationsData() { - return annotationsData; - } - - public void setAnnotationsData(AnnotationDataEntity[] annotationsData) { - this.annotationsData = annotationsData; - } - - public String getDocumentType() { - return documentType; - } - - public void setDocumentType(String documentType) { - this.documentType = documentType; - } - - public Boolean getPrint() { - return print; - } - - public void setPrint(Boolean print) { - this.print = print; - } -} diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/request/PostedDataEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/request/PostedDataEntity.java new file mode 100644 index 0000000..fc5703c --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/request/PostedDataEntity.java @@ -0,0 +1,180 @@ +package com.groupdocs.ui.annotation.entity.request; + +import java.util.List; + +/** + *

+ * DTO-class, representes document with its pages posted from the front-end. + *

+ */ +public class PostedDataEntity { + + /** + *

+ * Absolute path to the posted document. + *

+ * @return + */ + public String getPath() { + return path; + } + + /** + *

+ * Absolute path to the posted document. + *

+ * @param value + */ + public void setPath(String value) { + path = value; + } + private String path; + + /** + *

+ * Absolute path to the document. + *

+ * @return + */ + public String getGuid() { + return guid; + } + + /** + *

+ * Absolute path to the document. + *

+ * @param value + */ + public void setGuid(String value) { + guid = value; + } + private String guid; + + /** + *

+ * Document password. + *

+ * @return + */ + public String getPassword() { + return password; + } + + /** + *

+ * Document password. + *

+ * @param value + */ + public void setPassword(String value) { + password = value; + } + private String password; + + /** + *

+ * Url of the posted file. + *

+ * @return + */ + public String getUrl() { + return url; + } + + /** + *

+ * Url of the posted file. + *

+ * @param value + */ + public void setUrl(String value) { + url = value; + } + private String url; + + /** + *

+ * Page number. + *

+ * @return + */ + public int getPage() { + return page; + } + + /** + *

+ * Page number. + *

+ * @param value + */ + public void setPage(int value) { + page = value; + } + private int page; + + /** + *

+ * Page rotation angle. + *

+ * @return + */ + public int getAngle() { + return angle; + } + + /** + *

+ * Page rotation angle. + *

+ * @param value + */ + public void setAngle(int value) { + angle = value; + } + private int angle; + + /** + *

+ * Collection of the document pages with their data. + *

+ * @return + */ + public List getPages() { + return pages; + } + + /** + *

+ * Collection of the document pages with their data. + *

+ * @param value + */ + public void setPages(List value) { + pages = value; + } + + private List pages; + + /** + *

+ * Flag indicating whether the file should be overwritten. + *

+ * @return + */ + public boolean getRewrite() { + return rewrite; + } + + /** + *

+ * Flag indicating whether the file should be overwritten. + *

+ * @param value + */ + public void setRewrite(boolean value) { + rewrite = value; + } + private boolean rewrite; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/request/TextCoordinatesRequest.java b/src/main/java/com/groupdocs/ui/annotation/entity/request/TextCoordinatesRequest.java new file mode 100644 index 0000000..47122b0 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/request/TextCoordinatesRequest.java @@ -0,0 +1,31 @@ +package com.groupdocs.ui.annotation.entity.request; + +public class TextCoordinatesRequest extends PostedDataEntity { + + public final String getGuid_Rename_Namesake() { + return guid; + } + + public final void setQuid_Rename_Namesake(String value) { + guid = value; + } + private String guid; + + public final String getPassword_Rename_Namesake() { + return password; + } + + public final void setPassword_Rename_Namesake(String value) { + password = value; + } + private String password; + + public final int getPageNumber() { + return pageNumber; + } + + public final void setPageNumber(int value) { + pageNumber = value; + } + private int pageNumber; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotatedDocumentEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotatedDocumentEntity.java index f3cd1ba..8877196 100644 --- a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotatedDocumentEntity.java +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotatedDocumentEntity.java @@ -1,13 +1,11 @@ package com.groupdocs.ui.annotation.entity.web; +import com.groupdocs.ui.model.response.PageDescriptionEntity; +import java.util.ArrayList; import java.util.List; -/** - * AnnotatedDocumentEntity - * - * @author Aspose Pty Ltd - */ -public class AnnotatedDocumentEntity { +public class AnnotatedDocumentEntity extends PageDescriptionEntity { + /** * Document Guid */ @@ -19,7 +17,7 @@ public class AnnotatedDocumentEntity { /** * list of pages */ - private List pages; + private List pages = new ArrayList<>(); public String getGuid() { return guid; @@ -37,11 +35,11 @@ public void setSupportedAnnotations(String[] supportedAnnotations) { this.supportedAnnotations = supportedAnnotations; } - public List getPages() { + public List getPages() { return pages; } - public void setPages(List pages) { + public void setPages(List pages) { this.pages = pages; } } diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationDataEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationDataEntity.java index 0d8203c..8a51dd4 100644 --- a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationDataEntity.java +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationDataEntity.java @@ -1,177 +1,139 @@ package com.groupdocs.ui.annotation.entity.web; -/** - * AnnotationDataEntity - * - * @author Aspose Pty Ltd - */ public class AnnotationDataEntity { - /** - * Annotation Id - */ - private Integer id; - /** - * The number of page in document - */ - private Integer pageNumber; - /** - * The size of font of annotation - */ - private Double fontSize; - /** - * Annotation position. Left position. - */ - private double left; - /** - * Annotation position. Top position. - */ - private double top; - /** - * Annotation position. Width of annotation. - */ - private double width; - /** - * Annotation position. Height of annotation. - */ - private double height; - /** - * SVG path - */ - private String svgPath; - /** - * The type of annotation (text, watermark, ect) - */ - private String type; - /** - * Annotation text - */ - private String text; - /** - * The annotation font - */ - private String font; - /** - * List of comments in annotation - */ - private CommentsEntity[] comments; - /** - * Imported annotations - */ - private boolean imported; - /** - * font color - */ - private Integer fontColor; - public Integer getId() { + public final int getId() { return id; } - public void setId(Integer id) { - this.id = id; + public final void setId(int value) { + id = value; } + private int id; - public Integer getPageNumber() { + public final int getPageNumber() { return pageNumber; } - public void setPageNumber(Integer pageNumber) { - this.pageNumber = pageNumber; + public final void setPageNumber(int value) { + pageNumber = value; } + private int pageNumber; - public Double getFontSize() { + public final int getFontColor() { + return fontColor; + } + + public final void setFontColor(int value) { + fontColor = value; + } + private int fontColor; + + public final Double getFontSize() { return fontSize; } - public void setFontSize(Double fontSize) { - this.fontSize = fontSize; + public final void setFontSize(Double value) { + fontSize = value; } + private Double fontSize; - public double getLeft() { + public final float getLeft() { return left; } - public void setLeft(double left) { - this.left = left; + public final void setLeft(float value) { + left = value; } + private float left; - public double getTop() { + public final float getTop() { return top; } - public void setTop(double top) { - this.top = top; + public final void setTop(float value) { + top = value; } + private float top; - public double getWidth() { + public final float getWidth() { return width; } - public void setWidth(double width) { - this.width = width; + public final void setWidth(float value) { + width = value; } + private float width; - public double getHeight() { + public final float getHeight() { return height; } - public void setHeight(double height) { - this.height = height; + public final void setHeight(float value) { + height = value; } + private float height; - public String getSvgPath() { + public final String getSvgPath() { return svgPath; } - public void setSvgPath(String svgPath) { - this.svgPath = svgPath; + public final void setSvgPath(String value) { + svgPath = value; } + private String svgPath; - public String getType() { + public final String getType() { return type; } - public void setType(String type) { - this.type = type; + public final void setType(String value) { + type = value; } + private String type; - public String getText() { - return text; + public final String getDocumentType() { + return documentType; } - public void setText(String text) { - this.text = text; + public final void setDocumentType(String value) { + documentType = value; } + private String documentType; - public String getFont() { - return font; + public final String getText() { + return text; } - public void setFont(String font) { - this.font = font; + public final void setText(String value) { + text = value; } + private String text; - public CommentsEntity[] getComments() { - return comments; + public final String getFont() { + return font; } - public void setComments(CommentsEntity[] comments) { - this.comments = comments; + public final void setFont(String value) { + font = value; } + private String font; - public boolean isImported() { + public final boolean getImported() { return imported; } - public void setImported(boolean imported) { - this.imported = imported; + public final void setImported(boolean value) { + imported = value; } + private boolean imported; - public Integer getFontColor() { - return fontColor; + public final CommentsEntity[] getComments() { + return comments; } - public void setFontColor(Integer fontColor) { - this.fontColor = fontColor; + public final void setComments(CommentsEntity[] value) { + comments = value; } + private CommentsEntity[] comments; } diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPageDescriptionEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPageDescriptionEntity.java deleted file mode 100644 index 7ae2b87..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPageDescriptionEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.groupdocs.ui.annotation.entity.web; - -import com.groupdocs.ui.model.response.PageDescriptionEntity; - -public class AnnotationPageDescriptionEntity extends PageDescriptionEntity { - - /** - * List of annotation data - */ - private AnnotationDataEntity[] annotations; - - public AnnotationDataEntity[] getAnnotations() { - return annotations; - } - - public void setAnnotations(AnnotationDataEntity[] annotations) { - this.annotations = annotations; - } - -} diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPostedDataEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPostedDataEntity.java new file mode 100644 index 0000000..cb53d67 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/AnnotationPostedDataEntity.java @@ -0,0 +1,39 @@ +package com.groupdocs.ui.annotation.entity.web; + +import com.groupdocs.ui.annotation.entity.request.PostedDataEntity; + + +/** + *

+ * SignaturePostedDataEntity + *

+ */ +public class AnnotationPostedDataEntity extends PostedDataEntity { + + public final String getDocumentType() { + return documentType; + } + + public final void setDocumentType(String value) { + documentType = value; + } + private String documentType; + + public final AnnotationDataEntity[] getAnnotationsData() { + return annotationsData; + } + + public final void setAnnotationsData(AnnotationDataEntity[] value) { + annotationsData = value; + } + private AnnotationDataEntity[] annotationsData; + + public final boolean getPrint() { + return print; + } + + public final void setPrint(boolean value) { + print = value; + } + private boolean print; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/CommentsEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/CommentsEntity.java index 30fd005..68d39b2 100644 --- a/src/main/java/com/groupdocs/ui/annotation/entity/web/CommentsEntity.java +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/CommentsEntity.java @@ -1,45 +1,31 @@ package com.groupdocs.ui.annotation.entity.web; -/** - * CommentsEntity - * - * @author Aspose Pty Ltd - */ public class CommentsEntity { - private Integer id; - private String time; - private String text; - private String userName; - - public Integer getId() { - return id; - } - public void setId(Integer id) { - this.id = id; - } - - public String getTime() { + public final String getTime() { return time; } - public void setTime(String time) { - this.time = time; + public final void setTime(String value) { + time = value; } + private String time; - public String getText() { + public final String getText() { return text; } - public void setText(String text) { - this.text = text; + public final void setText(String value) { + text = value; } + private String text; - public String getUserName() { + public final String getUserName() { return userName; } - public void setUserName(String userName) { - this.userName = userName; + public final void setUserName(String value) { + userName = value; } -} + private String userName; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/PageDataDescriptionEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/PageDataDescriptionEntity.java new file mode 100644 index 0000000..a975af8 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/PageDataDescriptionEntity.java @@ -0,0 +1,19 @@ +package com.groupdocs.ui.annotation.entity.web; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.groupdocs.ui.model.response.PageDescriptionEntity; +import java.util.List; + +public class PageDataDescriptionEntity extends PageDescriptionEntity { + + @JsonProperty + private List annotations; // AnnotationDataEntity[] => List + + public final void setAnnotations(List annotations) { + this.annotations = annotations; + } + + public final List getAnnotations() { + return annotations; + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/entity/web/TextRowEntity.java b/src/main/java/com/groupdocs/ui/annotation/entity/web/TextRowEntity.java new file mode 100644 index 0000000..746dff7 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/entity/web/TextRowEntity.java @@ -0,0 +1,33 @@ +package com.groupdocs.ui.annotation.entity.web; + +import java.util.List; + +public class TextRowEntity { + + public final List getTextCoordinates() { + return textCoordinates; + } + + public final void setTextCoordinates(List value) { + textCoordinates = value; + } + private List textCoordinates; + + public final double getLineTop() { + return lineTop; + } + + public final void setLineTop(double value) { + lineTop = value; + } + private double lineTop; + + public final double getLineHeight() { + return lineHeight; + } + + public final void setLineHeight(double value) { + lineHeight = value; + } + private double lineHeight; +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/importer/Importer.java b/src/main/java/com/groupdocs/ui/annotation/importer/Importer.java deleted file mode 100644 index 2667c1a..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/importer/Importer.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.groupdocs.ui.annotation.importer; - -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.handler.AnnotationImageHandler; - -import java.io.InputStream; - -/** - * Importer - * - * @author Aspose Pty Ltd - */ -public class Importer { - protected InputStream documentStream; - protected AnnotationImageHandler annotator; - - /** - * Constructor - * - * @param documentStream - */ - public Importer(InputStream documentStream, AnnotationImageHandler annotator) { - this.documentStream = documentStream; - this.annotator = annotator; - } - - /** - * Import the annotations from document - * - * @param docType the type of document - * @return AnnotationInfo[] list of annotations - */ - public AnnotationInfo[] importAnnotations(int docType) { - AnnotationInfo[] annotations = annotator.importAnnotations(documentStream, docType); - return annotations; - } - -} diff --git a/src/main/java/com/groupdocs/ui/annotation/service/AnnotationService.java b/src/main/java/com/groupdocs/ui/annotation/service/AnnotationService.java index 46337bd..7c7e5cf 100644 --- a/src/main/java/com/groupdocs/ui/annotation/service/AnnotationService.java +++ b/src/main/java/com/groupdocs/ui/annotation/service/AnnotationService.java @@ -1,15 +1,14 @@ package com.groupdocs.ui.annotation.service; import com.groupdocs.ui.annotation.config.AnnotationConfiguration; -import com.groupdocs.ui.annotation.entity.request.AnnotateDocumentRequest; import com.groupdocs.ui.annotation.entity.web.AnnotatedDocumentEntity; -import com.groupdocs.ui.annotation.entity.web.AnnotationPageDescriptionEntity; +import com.groupdocs.ui.annotation.entity.web.AnnotationPostedDataEntity; +import com.groupdocs.ui.annotation.entity.web.PageDataDescriptionEntity; import com.groupdocs.ui.config.GlobalConfiguration; import com.groupdocs.ui.model.request.FileTreeRequest; import com.groupdocs.ui.model.request.LoadDocumentPageRequest; import com.groupdocs.ui.model.request.LoadDocumentRequest; import com.groupdocs.ui.model.response.FileDescriptionEntity; - import java.io.InputStream; import java.util.List; @@ -53,7 +52,7 @@ public interface AnnotationService { * @param loadDocumentPageRequest request object with document guid and page number * @return document page data */ - AnnotationPageDescriptionEntity getDocumentPage(LoadDocumentPageRequest loadDocumentPageRequest); + PageDataDescriptionEntity getDocumentPage(LoadDocumentPageRequest loadDocumentPageRequest); /** * Annotate document @@ -61,7 +60,7 @@ public interface AnnotationService { * @param annotateDocumentRequest request object with document guid and annotations data * @return annotated document */ - AnnotatedDocumentEntity annotate(AnnotateDocumentRequest annotateDocumentRequest); + AnnotatedDocumentEntity annotate(AnnotationPostedDataEntity annotateDocumentRequest); /** * Annotate document by streams @@ -69,5 +68,5 @@ public interface AnnotationService { * @param annotateDocumentRequest request object with document guid and annotations data * @return stream of annotated document */ - InputStream annotateByStream(AnnotateDocumentRequest annotateDocumentRequest); + InputStream annotateByStream(AnnotationPostedDataEntity annotateDocumentRequest); } diff --git a/src/main/java/com/groupdocs/ui/annotation/service/AnnotationServiceImpl.java b/src/main/java/com/groupdocs/ui/annotation/service/AnnotationServiceImpl.java index 4b4ad44..4149c76 100644 --- a/src/main/java/com/groupdocs/ui/annotation/service/AnnotationServiceImpl.java +++ b/src/main/java/com/groupdocs/ui/annotation/service/AnnotationServiceImpl.java @@ -1,25 +1,26 @@ package com.groupdocs.ui.annotation.service; -import com.groupdocs.annotation.common.exception.AnnotatorException; -import com.groupdocs.annotation.common.license.License; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.FileDescription; -import com.groupdocs.annotation.domain.PageData; -import com.groupdocs.annotation.domain.config.AnnotationConfig; -import com.groupdocs.annotation.domain.containers.DocumentInfoContainer; -import com.groupdocs.annotation.domain.containers.FileTreeContainer; -import com.groupdocs.annotation.domain.image.PageImage; -import com.groupdocs.annotation.domain.options.FileTreeOptions; -import com.groupdocs.annotation.domain.options.ImageOptions; -import com.groupdocs.annotation.handler.AnnotationImageHandler; +import com.groupdocs.annotation.license.License; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.Annotator; +import com.groupdocs.annotation.IDocumentInfo; +import com.groupdocs.annotation.exceptions.AnnotatorException; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.options.LoadOptions; +import com.groupdocs.annotation.options.PreviewFormats; +import com.groupdocs.annotation.options.export.AnnotationType; +import com.groupdocs.annotation.options.export.SaveOptions; +import com.groupdocs.annotation.options.pagepreview.CreatePageStream; +import com.groupdocs.annotation.options.pagepreview.PreviewOptions; import com.groupdocs.ui.annotation.annotator.AnnotatorFactory; +import com.groupdocs.ui.annotation.annotator.BaseAnnotator; import com.groupdocs.ui.annotation.config.AnnotationConfiguration; -import com.groupdocs.ui.annotation.entity.request.AnnotateDocumentRequest; import com.groupdocs.ui.annotation.entity.web.AnnotatedDocumentEntity; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; -import com.groupdocs.ui.annotation.entity.web.AnnotationPageDescriptionEntity; -import com.groupdocs.ui.annotation.importer.Importer; +import com.groupdocs.ui.annotation.entity.web.AnnotationPostedDataEntity; +import com.groupdocs.ui.annotation.entity.web.PageDataDescriptionEntity; import com.groupdocs.ui.annotation.util.AnnotationMapper; +import com.groupdocs.ui.annotation.util.DocumentTypesConverter; import com.groupdocs.ui.annotation.util.SupportedAnnotations; import com.groupdocs.ui.config.GlobalConfiguration; import com.groupdocs.ui.exception.TotalGroupDocsException; @@ -34,19 +35,21 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; - import javax.annotation.PostConstruct; import java.io.*; import java.util.ArrayList; import java.util.List; - -import static com.groupdocs.ui.annotation.util.DocumentTypesConverter.checkedDocumentType; -import static com.groupdocs.ui.annotation.util.DocumentTypesConverter.getDocumentType; -import static com.groupdocs.ui.util.Utils.getStringFromStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Base64; +import java.util.Iterator; @Service public class AnnotationServiceImpl implements AnnotationService { + private static final Logger logger = LoggerFactory.getLogger(AnnotationServiceImpl.class); + private final List SupportedImageFormats = new ArrayList<>(); @Autowired private GlobalConfiguration globalConfiguration; @@ -54,19 +57,21 @@ public class AnnotationServiceImpl implements AnnotationService { @Autowired private AnnotationConfiguration annotationConfiguration; - private AnnotationImageHandler annotationHandler; + private final List annotationPageDescriptionEntityList = new ArrayList<>(); @PostConstruct public void init() { - // create annotation application configuration - AnnotationConfig config = new AnnotationConfig(); - // set storage path - config.setStoragePath(annotationConfiguration.getFilesDirectory()); - config.getFontDirectories().add(annotationConfiguration.getFontsDirectory()); - - annotationHandler = new AnnotationImageHandler(config); - try { + SupportedImageFormats.add(".bmp"); + SupportedImageFormats.add(".jpeg"); + SupportedImageFormats.add(".jpg"); + SupportedImageFormats.add(".tiff"); + SupportedImageFormats.add(".tif"); + SupportedImageFormats.add(".png"); + SupportedImageFormats.add(".dwg"); + SupportedImageFormats.add(".dcm"); + SupportedImageFormats.add(".dxf"); + // set GroupDocs license License license = new License(); license.setLicense(globalConfiguration.getApplication().getLicensePath()); @@ -88,243 +93,520 @@ public AnnotationConfiguration getAnnotationConfiguration() { @Override public List getFileList(FileTreeRequest fileTreeRequest) { String path = fileTreeRequest.getPath(); - // get file list from storage path - FileTreeOptions fileListOptions = new FileTreeOptions(path); - // get temp directory name - String tempDirectoryName = new AnnotationConfig().getTempFolderName(); + if (StringUtils.isEmpty(path)) { + path = annotationConfiguration.getFilesDirectory(); + } try { - FileTreeContainer fileListContainer = annotationHandler.loadFileTree(fileListOptions); + File directory = new File(path); + List filesList = Arrays.asList(directory.listFiles()); - List fileList = new ArrayList<>(); - // parse files/folders list - for (FileDescription fd : fileListContainer.getFileTree()) { - FileDescriptionEntity fileDescription = new FileDescriptionEntity(); - fileDescription.setGuid(fd.getGuid()); - // check if current file/folder is temp directory or is hidden - if (tempDirectoryName.toLowerCase().equals(fd.getName()) || new File(fileDescription.getGuid()).isHidden()) { - // ignore current file and skip to next one - continue; - } else { - // set file/folder name - fileDescription.setName(fd.getName()); - } - // set file type - fileDescription.setDocType(fd.getDocumentType()); - // set is directory true/false - fileDescription.setIsDirectory(fd.isDirectory()); - // set file size - fileDescription.setSize(fd.getSize()); - // add object to array list - fileList.add(fileDescription); - } + List fileList = getFileDescriptionEntities(filesList); return fileList; } catch (Exception ex) { + logger.error("Exception in getting file list", ex); throw new TotalGroupDocsException(ex.getMessage(), ex); } } - @Override - public AnnotatedDocumentEntity getDocumentDescription(LoadDocumentRequest loadDocumentRequest) { - try { - // get/set parameters - String documentGuid = loadDocumentRequest.getGuid(); - String password = loadDocumentRequest.getPassword(); - ImageOptions imageOptions = createImageOptions(password); - // get document info container - String fileName = FilenameUtils.getName(documentGuid); - DocumentInfoContainer documentDescription = annotationHandler.getDocumentInfo(fileName, password); - - String documentType = checkedDocumentType(documentGuid, documentDescription.getDocumentType()); - // check if document contains annotations - AnnotationInfo[] annotations = getAnnotations(documentGuid, documentType); - // get info about each document page - List pageImages = null; - if (annotationConfiguration.getPreloadPageCount() == 0) { - pageImages = annotationHandler.getPages(fileName, imageOptions); - } - String[] supportedAnnotations = SupportedAnnotations.getSupportedAnnotations(documentType); - // initiate custom Document description object - AnnotatedDocumentEntity description = new AnnotatedDocumentEntity(); - description.setGuid(documentGuid); - description.setSupportedAnnotations(supportedAnnotations); - // initiate pages description list - List pages = documentDescription.getPages(); - List pagesDescriptions = new ArrayList<>(pages.size()); - for (int i = 0; i < pages.size(); i++) { - PageData pageData = pages.get(i); - // set current page info for result - PageImage pageImage = pageImages != null ? pageImages.get(i) : null; - AnnotationPageDescriptionEntity page = getAnnotationPageDescriptionEntity(pageData, pageImage); - // set annotations data if document page contains annotations - if (annotations != null && annotations.length > 0) { - page.setAnnotations(AnnotationMapper.instance.mapForPage(annotations, page.getNumber())); - } - pagesDescriptions.add(page); + public List getFileDescriptionEntities(List filesList) { + List fileList = new ArrayList<>(); + for (File file : filesList) { + String guid = file.getAbsolutePath(); + String extension = FilenameUtils.getExtension(guid); + if (file.isDirectory() || (!StringUtils.isEmpty(extension))) { + FileDescriptionEntity fileDescription = new FileDescriptionEntity(); + fileDescription.setGuid(guid); + fileDescription.setName(file.getName()); + fileDescription.setIsDirectory(file.isDirectory()); + fileDescription.setSize(file.length()); + fileList.add(fileDescription); } - description.setPages(pagesDescriptions); - // return document description - return description; - } catch (Exception ex) { - throw new TotalGroupDocsException(ex.getMessage(), ex); } + return fileList; } - /** - * Create initial instance of ImageOptions with documents password - * - * @param password - * @return - */ - public ImageOptions createImageOptions(String password) { - ImageOptions imageOptions = new ImageOptions(); - // set password for protected document - if (!StringUtils.isEmpty(password)) { - imageOptions.setPassword(password); + @Override + public AnnotatedDocumentEntity getDocumentDescription(LoadDocumentRequest loadDocumentRequest) { + try { + return loadDocument( + loadDocumentRequest, + annotationConfiguration.getPreloadPageCount() == 0 + //globalConfiguration.getAnnotationConfiguration().getPreloadPageCount() == 0 + ); + } catch (Throwable ex) { + throw new TotalGroupDocsException(ex); } - return imageOptions; } + + public final AnnotatedDocumentEntity loadDocument(LoadDocumentRequest loadDocumentRequest, boolean loadAllPages) { + Annotator annotator = null; + AnnotatedDocumentEntity description = new AnnotatedDocumentEntity(); + String guid = loadDocumentRequest.getGuid(); + String password = loadDocumentRequest.getPassword(); + LoadOptions loadOptions = new LoadOptions(); + loadOptions.setPassword(password); + + try { + annotator = new Annotator(guid, loadOptions); + + IDocumentInfo info = annotator.getDocument().getDocumentInfo(); + List annotations = annotator.get(); + + description.setGuid(loadDocumentRequest.getGuid()); + + String documentType = ""; + if (info.getFileType() != null) { + documentType = SupportedImageFormats.contains(info.getFileType().getExtension()) ? "image" : info.getFileType().toString(); + } else { + documentType = "Portable Document Format"; + } + + description.supportedAnnotations = SupportedAnnotations.getSupportedAnnotations(documentType); + + List pagesContent = new ArrayList<>(); + + if (loadAllPages) { + pagesContent = getAllPagesContent(password, guid, info); //documentGuid => guid + } - private AnnotationPageDescriptionEntity getAnnotationPageDescriptionEntity(PageData pageData, PageImage pageImage) throws IOException { - AnnotationPageDescriptionEntity page = new AnnotationPageDescriptionEntity(); - page.setHeight(pageData.getHeight()); - page.setWidth(pageData.getWidth()); - page.setNumber(pageData.getNumber()); + for (int i = 0; i < info.getPageCount(); i++) { + PageDataDescriptionEntity page = new PageDataDescriptionEntity(); + page.setNumber(i + 1); + page.setHeight(info.getPagesInfo().get(i).getHeight()); + page.setWidth(info.getPagesInfo().get(i).getWidth()); - if (pageImage != null) { - page.setData(getStringFromStream(pageImage.getStream())); + if (annotations != null && annotations.size() > 0) { + page.setAnnotations(AnnotationMapper.mapForPage(annotations, i + 1, info.getPagesInfo().get(i))); + } + + if (pagesContent.size() > 0) { + page.setData(pagesContent.get(i)); + } + description.getPages().add(page); + } + } finally { + if (annotator != null) { + annotator.dispose(); + } } - return page; + + description.setGuid(guid); //documentGuid => guid + // return document description + return description; + } + + public static String getStringFromStream(InputStream inputStream) throws IOException { +// inputStream.reset(); +// inputStream.skip(0); +// +// byte[] imageRaw = null; +// ByteArrayOutputStream out = new ByteArrayOutputStream(); +// int c; +// while ((c = inputStream.read()) != -1) { +// out.write(c); +// } +// out.flush(); +// imageRaw = out.toByteArray(); +// +// String result = Base64.getEncoder().encodeToString(imageRaw); + + //Base64.encodeToString(imageRaw, Base64.DEFAULT); + + //---- + + inputStream.reset(); + inputStream.skip(0); + + byte[] bytes = IOUtils.toByteArray(inputStream); + // encode ByteArray into String + return Base64.getEncoder().encodeToString(bytes); + +// byte[] buffer = new byte[inputStream.available()]; +// inputStream.read(buffer); +// +// return Base64.getEncoder().encodeToString(buffer); + +// java.io.File targetFile = new java.io.File("C:\\Users\\AlexT\\Desktop\\java-answers\\ConsoleApp1/targetFile.tmp"); +// java.io.OutputStream outStream = new java.io.FileOutputStream(targetFile); +// outStream.write(buffer); + +// return result;//new String(buffer);//, StandardCharsets.UTF_8); + //return new String(IOUtils.toByteArray(inputStream), StandardCharsets.UTF_8); } @Override - public AnnotationPageDescriptionEntity getDocumentPage(LoadDocumentPageRequest loadDocumentPageRequest) { + public PageDataDescriptionEntity getDocumentPage(LoadDocumentPageRequest loadDocumentPageRequest) { + String password = ""; try { // get/set parameters String documentGuid = loadDocumentPageRequest.getGuid(); int pageNumber = loadDocumentPageRequest.getPage(); - String password = loadDocumentPageRequest.getPassword(); - // set options - ImageOptions imageOptions = createImageOptions(password); - imageOptions.setPageNumber(pageNumber); - imageOptions.setCountPagesToConvert(1); - String fileName = FilenameUtils.getName(documentGuid); - List images = annotationHandler.getPages(fileName, imageOptions); + password = loadDocumentPageRequest.getPassword(); + PageDataDescriptionEntity loadedPage = new PageDataDescriptionEntity(); + + // get page image + byte[] bytes; + + final Annotator annotator = new Annotator(documentGuid, getLoadOptions(password)); + try { + final OutputStream renderPage = renderPageToMemoryStream(pageNumber, documentGuid, password); + + ByteArrayOutputStream bufferRenderPage = (ByteArrayOutputStream) renderPage; + byte[] bytesRenderPage = bufferRenderPage.toByteArray(); + InputStream streamRenderPage = new ByteArrayInputStream(bytesRenderPage); + + try { + bytes = IOUtils.toByteArray(streamRenderPage); + } finally { + if (streamRenderPage != null) { + streamRenderPage.close(); + } + } + +// InputStream finput = new FileInputStream(file); +// byte[] imageBytes = new byte[(int)file.length()]; +// finput.read(imageBytes, 0, imageBytes.length); +// finput.close(); +// String imageStr = Base64.encodeBase64String(imageBytes); + + IDocumentInfo info = annotator.getDocument().getDocumentInfo(); + List annotations = annotator.get(); + + if (annotations != null && annotations.size() > 0) { + loadedPage.setAnnotations(AnnotationMapper.mapForPage(annotations, pageNumber, info.getPagesInfo().get(pageNumber - 1))); + } - DocumentInfoContainer documentDescription = annotationHandler.getDocumentInfo(fileName, password); - PageData pageData = documentDescription.getPages().get(pageNumber - 1); + String encodedImage = Base64.getEncoder().encodeToString(bytes); + loadedPage.setData(encodedImage); - AnnotationPageDescriptionEntity page = getAnnotationPageDescriptionEntity(pageData, images.get(0)); + loadedPage.setHeight(info.getPagesInfo().get(pageNumber - 1).getHeight()); + loadedPage.setWidth(info.getPagesInfo().get(pageNumber - 1).getWidth()); + loadedPage.setNumber(pageNumber); + } finally { + if (annotator != null) { + annotator.dispose(); + } + } // return loaded page object - return page; + return loadedPage; } catch (Exception ex) { - throw new TotalGroupDocsException(ex.getMessage(), ex); + throw new TotalGroupDocsException(ex); } } + + private static OutputStream renderPageToMemoryStream(int pageNumberToRender, String documentGuid, String password) { + try { + OutputStream result = new ByteArrayOutputStream(); // MemoryStream => OutputStream + InputStream inputStream = new FileInputStream(documentGuid); //final FileStream outputStream = File.openRead(documentGuid); + try { + final Annotator annotator = new Annotator(inputStream, getLoadOptions(password)); + try { + PreviewOptions previewOptions = new PreviewOptions( //PreviewOptions previewOptions = new PreviewOptions((pageNumber) = > result); + new CreatePageStream() { + @Override + public OutputStream invoke(int pageNumber) { + return result; + } + } + ); + previewOptions.setPreviewFormat(PreviewFormats.PNG); + previewOptions.setPageNumbers(new int[]{pageNumberToRender}); + previewOptions.setRenderComments(false); + + annotator.getDocument().generatePreview(previewOptions); + } finally { + if (annotator != null) { + annotator.dispose(); + } + } + } finally { + if (inputStream != null) { + inputStream.close(); + } + } + return result; + } catch (Exception ex) { + throw new TotalGroupDocsException(ex); + } + } + + private static LoadOptions getLoadOptions(String password) { + LoadOptions loadOptions = new LoadOptions(); + loadOptions.setPassword(password); + return loadOptions; + } + public InputStream annotateDocument(String documentGuid, String documentType, List annotations) throws FileNotFoundException { + Annotator annotator = new Annotator(documentGuid); + + SaveOptions saveOptions = new SaveOptions(); + saveOptions.setAnnotationTypes(AnnotationType.None); + + annotator.save(documentGuid, saveOptions); + + if (annotations.size() > 0) { + annotator.add(annotations); + annotator.save(documentGuid, new SaveOptions()); + } + + return new FileInputStream(documentGuid); + } + @Override - public AnnotatedDocumentEntity annotate(AnnotateDocumentRequest annotateDocumentRequest) { + public AnnotatedDocumentEntity annotate(AnnotationPostedDataEntity annotateDocumentRequest) { AnnotatedDocumentEntity annotatedDocument = new AnnotatedDocumentEntity(); try { + // get/set parameters String documentGuid = annotateDocumentRequest.getGuid(); - String documentType = checkedDocumentType(documentGuid, annotateDocumentRequest.getDocumentType()); - List annotations = getAnnotationInfos(annotateDocumentRequest, documentType); + String password = annotateDocumentRequest.getPassword(); + + //String documentType1 = DocumentTypesConverter.checkedDocumentType(documentGuid, annotateDocumentRequest.getDocumentType()); + String documentType = SupportedImageFormats.contains( + FilenameUtils.getExtension(annotateDocumentRequest.getGuid()) + ) ? "image" : annotateDocumentRequest.getDocumentType(); + + String tempPath = getTempPath(documentGuid); + + AnnotationDataEntity[] annotationsData = annotateDocumentRequest.getAnnotationsData(); + // initiate list of annotations to add + List annotations = new ArrayList<>(); + + final Annotator annotator = new Annotator(documentGuid, getLoadOptions(password)); + try { + IDocumentInfo info = annotator.getDocument().getDocumentInfo(); + + for (int i = 0; i < annotationsData.length; i++) { + AnnotationDataEntity annotationData = annotationsData[i]; + PageInfo pageInfo = info.getPagesInfo().get(annotationsData[i].getPageNumber() - 1); + // add annotation, if current annotation type isn't supported by the current document type it will be ignored + try { + BaseAnnotator baseAnnotator = AnnotatorFactory.createAnnotator(annotationData, pageInfo); + if (baseAnnotator.isSupported(documentType)) { + annotations.add(baseAnnotator.getAnnotationBase(documentType)); + } + } catch (java.lang.RuntimeException ex) { + throw new AnnotatorException(ex.getMessage(), ex); + } + } + } finally { + if (annotator != null) { + annotator.dispose(); + } + } + + // Add annotation to the document + removeAnnotations(documentGuid, password); + // check if annotations array contains at least one annotation to add + if (annotations.size() != 0) { + final Annotator annotator1 = new Annotator(documentGuid, getLoadOptions(password)); + try { + //foreach to while statements conversion + Iterator tmp0 = (annotations).iterator(); + + while (tmp0.hasNext()) { + AnnotationBase annotation = (AnnotationBase) tmp0.next(); + annotator1.add(annotation); + } + + annotator1.save(tempPath); + } finally { + if (annotator1 != null) { + annotator1.dispose(); + } + } - InputStream file = annotateDocument(documentGuid, documentType, annotations); - if (annotateDocumentRequest.getPrint()) { - List annotatedPages = getAnnotatedPages(annotateDocumentRequest.getPassword(), file); - annotatedDocument.setPages(annotatedPages); - } else { try (OutputStream fileStream = new FileOutputStream(documentGuid)) { - IOUtils.copyLarge(file, fileStream); - annotatedDocument.setGuid(documentGuid); + InputStream inputStream1 = new FileInputStream(tempPath); + IOUtils.copyLarge(inputStream1, fileStream); } } + + annotatedDocument = new AnnotatedDocumentEntity(); + annotatedDocument.setGuid(documentGuid); + if (annotateDocumentRequest.getPrint()) { + annotatedDocument.setPages(getAnnotatedPagesForPrint(password, documentGuid)); + Files.move(Paths.get(documentGuid), Paths.get(annotateDocumentRequest.getGuid())); + } } catch (Exception ex) { - throw new TotalGroupDocsException(ex.getMessage(), ex); + // set exception message + throw new TotalGroupDocsException(ex); } + return annotatedDocument; + } + + private List getAnnotatedPagesForPrint(String password, String documentGuid) { + AnnotatedDocumentEntity description = new AnnotatedDocumentEntity(); + try { + InputStream outputStream = new FileInputStream(documentGuid); + try { + final Annotator annotator = new Annotator(outputStream, getLoadOptions(password)); + try { + IDocumentInfo info = annotator.getDocument().getDocumentInfo(); + List pagesContent = getAllPagesContent(password, documentGuid, info); + + for (int i = 0; i < info.getPageCount(); i++) { + PageDataDescriptionEntity page = new PageDataDescriptionEntity(); + + if (pagesContent.size() > 0) { + page.setData(pagesContent.get(i)); + } + + description.getPages().add(page); + } + } finally { + if (annotator != null) { + annotator.dispose(); + } + } + } finally { + if (outputStream != null) { + outputStream.close(); + } + } - public InputStream annotateDocument(String documentGuid, String documentType, List annotations) throws FileNotFoundException { - InputStream file = annotationHandler.removeAnnotationStream(new FileInputStream(documentGuid)); - // check if annotations array contains at least one annotation to add - if (annotations.size() > 0) { - // Add annotation to the document - int type = getDocumentType(documentType); - return annotationHandler.exportAnnotationsToDocument(file, annotations, type); + return description.getPages(); + } catch (Exception ex) { + throw new TotalGroupDocsException(ex.getMessage(), ex); } - return file; } + + private static String getTempPath(String documentGuid) { + File fileName = new File(documentGuid); + return fileName.getParentFile().getPath() + "//tmp_" + fileName.getName(); + } + + public static void removeAnnotations(String documentGuid, String password) { + String tempPath = getTempPath(documentGuid); - public List getAnnotationInfos(AnnotateDocumentRequest annotateDocumentRequest, String documentType) { - AnnotationDataEntity[] annotationsData = annotateDocumentRequest.getAnnotationsData(); - // get document info - required to get document page height and calculate annotation top position - DocumentInfoContainer documentInfo = annotationHandler.getDocumentInfo(new File(annotateDocumentRequest.getGuid()).getName(), annotateDocumentRequest.getPassword()); - List annotations = new ArrayList<>(); - for (AnnotationDataEntity annotationData : annotationsData) { - // create annotator - PageData pageData = documentInfo.getPages().get(annotationData.getPageNumber() - 1); - // add annotation, if current annotation type isn't supported by the current document type it will be ignored + try { + final InputStream inputStream = new FileInputStream(documentGuid); + //final Stream inputStream = File.open(documentGuid, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); try { - annotations.add(AnnotatorFactory.createAnnotator(annotationData, pageData).getAnnotationInfo(documentType)); - } catch (Exception ex) { - throw new TotalGroupDocsException(ex.getMessage(), ex); + final Annotator annotator = new Annotator(inputStream, getLoadOptions(password)); + try { + SaveOptions tmp0 = new SaveOptions(); + tmp0.setAnnotationTypes(AnnotationType.None); + annotator.save(tempPath, tmp0); + } finally { + if (annotator != null) { + annotator.dispose(); + } + } + } finally { + if (inputStream != null) { + inputStream.close(); + } } - } - return annotations; - } + + + try (PrintWriter writer = new PrintWriter(documentGuid)) { + writer.print(""); + } + + try (OutputStream fileStream = new FileOutputStream(documentGuid)) { + InputStream inputStream1 = new FileInputStream(tempPath); + IOUtils.copyLarge(inputStream1, fileStream); + } + +// Files.copy(Paths.get(tempPath), Paths.get(documentGuid)); - @Override - public InputStream annotateByStream(AnnotateDocumentRequest annotateDocumentRequest) { - String documentGuid = annotateDocumentRequest.getGuid(); - String documentType = checkedDocumentType(documentGuid, annotateDocumentRequest.getDocumentType()); - List annotations = getAnnotationInfos(annotateDocumentRequest, documentType); - try { - return annotateDocument(documentGuid, documentType, annotations); - } catch (FileNotFoundException ex) { +// Files.deleteIfExists(Paths.get(documentGuid)); +// Files.move(Paths.get(tempPath), Paths.get(documentGuid)); +// Files.copy(Paths.get(tempPath), Paths.get(documentGuid), StandardCopyOption.REPLACE_EXISTING); + + } catch (Exception ex) { throw new TotalGroupDocsException(ex.getMessage(), ex); } } - - /** - * Get pages images of annotated file - * - * @param password password for the file - * @param inputStream stream of annotated file - * @return list of pages - * @throws IOException - */ - private List getAnnotatedPages(String password, InputStream inputStream) throws IOException { - ImageOptions imageOptions = createImageOptions(password); - List pages = annotationHandler.getPages(inputStream, imageOptions); - List pagesDescriptions = new ArrayList<>(pages.size()); - for (PageImage pageImage : pages) { - AnnotationPageDescriptionEntity page = new AnnotationPageDescriptionEntity(); - page.setData(getStringFromStream(pageImage.getStream())); - - pagesDescriptions.add(page); + + private String getText1(String tempPath) { + String content = ""; + try { + InputStream is = new FileInputStream(tempPath); + BufferedReader buf = new BufferedReader(new InputStreamReader(is)); + String line = buf.readLine(); + StringBuilder sb = new StringBuilder(); + while(line != null){ + sb.append(line).append("\n"); + line = buf.readLine(); + } + content = sb.toString(); + } catch(Throwable ex) { + ex.getMessage(); } - return pagesDescriptions; + return content; } + + private List getAllPagesContent(String password, String documentGuid, IDocumentInfo pages) { + List allPages = new ArrayList<>(); + +// //get page HTML +// renderPageToMemoryStream(pages.getPageCount(), documentGuid, password); +// for (int i = 0; i < pages.getPageCount(); i++) { +// byte[] bytes = annotationPageDescriptionEntityList.get(i).getData().getBytes(); // getData() +// allPages.add(Base64.getEncoder().encodeToString(bytes)); +// +//// allPages.add(annotationPageDescriptionEntityList.get(i).toString()); +//// allPages.add(annotationPageDescriptionEntityList.get(i).getData()); +// } + + for (int i = 0; i < pages.getPageCount(); i++) { + byte[] bytes; + try (OutputStream memoryStream = renderPageToMemoryStream(i + 1, documentGuid, password)) { + ByteArrayOutputStream bos = (ByteArrayOutputStream) memoryStream; + bytes = bos.toByteArray(); //memoryStream.ToArray(); + } catch (IOException ex) { + throw new TotalGroupDocsException(ex.getMessage(), ex); + } - /** - * Get all annotations from the document - * - * @param documentGuid - * @param documentType - * @return array of the annotations - */ - private AnnotationInfo[] getAnnotations(String documentGuid, String documentType) { - try (InputStream documentStream = new FileInputStream(documentGuid)) { - int docType = getDocumentType(documentType); - return new Importer(documentStream, annotationHandler).importAnnotations(docType); - } catch (AnnotatorException annotatorException) { - logger.error("Exception while extract annotations from file {}: {}", FilenameUtils.getName(documentGuid), annotatorException.getCause().getLocalizedMessage()); - return new AnnotationInfo[0]; + String encodedImage = new String(Base64.getEncoder().encode(bytes)); //Convert.ToBase64String(bytes); + allPages.add(encodedImage); + } + + return allPages; + } + +//------------------------------------------ + public List getAnnotationInfos(AnnotationPostedDataEntity annotateDocumentRequest, String documentType) { + try { + AnnotationDataEntity[] annotationsData = annotateDocumentRequest.getAnnotationsData(); + // get document info - required to get document page height and calculate annotation top position + + List annotations = new ArrayList<>(); + for (AnnotationDataEntity annotationData : annotationsData) { + // create annotator + // add annotation, if current annotation type isn't supported by the current document type it will be ignored + PageDataDescriptionEntity pageData = annotationPageDescriptionEntityList.get(annotationData.getPageNumber() - 1); + + PageInfo pageInfo = new PageInfo(); + pageInfo.setHeight((int) pageData.getHeight()); + //pageInfo.setPageNumber(pageData.getNumber()); + pageInfo.setWidth((int) pageData.getWidth()); + + try { + annotations.add(AnnotatorFactory.createAnnotator(annotationData, pageInfo).getAnnotationBase(documentType)); + } catch (Throwable ex) { + throw new TotalGroupDocsException(ex.getMessage(), ex); + } + } + return annotations; } catch (Exception ex) { throw new TotalGroupDocsException(ex.getMessage(), ex); } } -} + @Override + public InputStream annotateByStream(AnnotationPostedDataEntity annotateDocumentRequest) { + String documentGuid = annotateDocumentRequest.getGuid(); + String documentType = DocumentTypesConverter.checkedDocumentType(documentGuid, annotateDocumentRequest.getDocumentType()); + List annotations = getAnnotationInfos(annotateDocumentRequest, documentType); + try { + return annotateDocument(documentGuid, documentType, annotations); + } catch (FileNotFoundException ex) { + throw new TotalGroupDocsException(ex.getMessage(), ex); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/service/IPageStreamFactory.java b/src/main/java/com/groupdocs/ui/annotation/service/IPageStreamFactory.java new file mode 100644 index 0000000..f4a072c --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/service/IPageStreamFactory.java @@ -0,0 +1,20 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.groupdocs.ui.annotation.service; + +import java.io.InputStream; +import java.io.OutputStream; + +/** + * + * @author AlexT + */ +public interface IPageStreamFactory { + + public OutputStream createPageStream(int pageNumber); + + public void closePageStream(int pageNumber, InputStream pageStream); +} diff --git a/src/main/java/com/groupdocs/ui/annotation/service/StreamFactoryClass.java b/src/main/java/com/groupdocs/ui/annotation/service/StreamFactoryClass.java new file mode 100644 index 0000000..4e02618 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/service/StreamFactoryClass.java @@ -0,0 +1,70 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.groupdocs.ui.annotation.service; + +import com.groupdocs.ui.annotation.entity.web.PageDataDescriptionEntity; +import com.groupdocs.ui.exception.TotalGroupDocsException; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import javax.imageio.ImageIO; +import org.apache.commons.io.IOUtils; + +/** + * + * @author AlexT + */ +public class StreamFactoryClass implements IPageStreamFactory { + public List AnnotationPageDescriptionEntityList = new ArrayList<>(); + + @Override + public OutputStream createPageStream(int pageNumber) { + //ByteArrayInputStream; + //ByteArrayOutputStream; + //return new MemoryStream(); + return new ByteArrayOutputStream(); + } + + @Override + public void closePageStream(int pageNumber, InputStream pageStream) { + try { + PageDataDescriptionEntity page = new PageDataDescriptionEntity(); + + BufferedImage imBuff; + try { + imBuff = ImageIO.read(pageStream); + page.setHeight(imBuff.getHeight()); + page.setWidth(imBuff.getWidth()); + page.setNumber(pageNumber); + } catch (IOException ex) { + throw new TotalGroupDocsException(ex); + } + page.setData(getStringFromStream(pageStream)); + AnnotationPageDescriptionEntityList.add(page); + pageStream.close(); + } catch (Exception ex) { + throw new TotalGroupDocsException(ex); + } + } + + public static String getStringFromStream(InputStream inputStream) throws IOException { + return new String(IOUtils.toByteArray(inputStream), StandardCharsets.UTF_8); +// byte[] bytes = null; +// //try (MemoryStream memoryStream = new MemoryStream()) { +// try (ByteArrayOutputStream memoryStream = new ByteArrayOutputStream()) { +// memoryStream = IOUtils.toByteArray(inputStream); +// inputStream.CopyTo(memoryStream); +// bytes = memoryStream.toByteArray(); +// } +// // encode ByteArray into String +// return Convert.ToBase64String(bytes); + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/util/AnnotationMapper.java b/src/main/java/com/groupdocs/ui/annotation/util/AnnotationMapper.java index d107c29..037c871 100644 --- a/src/main/java/com/groupdocs/ui/annotation/util/AnnotationMapper.java +++ b/src/main/java/com/groupdocs/ui/annotation/util/AnnotationMapper.java @@ -1,93 +1,149 @@ package com.groupdocs.ui.annotation.util; -import com.groupdocs.annotation.domain.AnnotationInfo; -import com.groupdocs.annotation.domain.AnnotationReplyInfo; -import com.groupdocs.annotation.domain.Rectangle; +import com.groupdocs.annotation.internal.c.a.ms.System.Convert; +import com.groupdocs.annotation.models.PageInfo; +import com.groupdocs.annotation.models.Point; +import com.groupdocs.annotation.models.Rectangle; +import com.groupdocs.annotation.models.Reply; +import com.groupdocs.annotation.models.annotationmodels.AnnotationBase; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IBox; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IFontColor; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IFontFamily; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IFontSize; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IPoints; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.ISvgPath; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.IText; +import com.groupdocs.annotation.models.annotationmodels.interfaces.properties.ITextToReplace; +import com.groupdocs.annotation.options.export.AnnotationType; import com.groupdocs.ui.annotation.entity.web.AnnotationDataEntity; import com.groupdocs.ui.annotation.entity.web.CommentsEntity; - import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -/** - * Mapper for annotation entities - */ + public class AnnotationMapper { - /** - * Instance of mapper - */ - public static final AnnotationMapper instance = new AnnotationMapper(); private AnnotationMapper() { } /** + *

* Map AnnotationInfo instances into AnnotationDataEntity + *

* - * @param annotations list of AnnotationInfo instances - * @param pageNumber number of page for mapping - * @return list of AnnotationDataEntity instances + * @param pageInfo + * @return + * @param annotations AnnotationInfo[] + * @param pageNumber int */ - public AnnotationDataEntity[] mapForPage(AnnotationInfo[] annotations, int pageNumber) { + // AnnotationDataEntity[] => List + public static List mapForPage(List annotations, int pageNumber, PageInfo pageInfo) { //AnnotationBase[] => List // initiate annotations data array List pageAnnotations = new ArrayList<>(); - // set each annotation data - this functionality used since annotations data returned by the + // each annotation data - this functionality used since annotations data returned by the // GroupDocs.Annotation library are obfuscated - for (int n = 0; n < annotations.length; n++) { - AnnotationInfo annotationInfo = annotations[n]; - if(pageNumber == annotationInfo.getPageNumber() + 1) { - AnnotationDataEntity annotation = mapAnnotationDataEntity(annotationInfo); + for (int n = 0; n < annotations.size(); n++) { + AnnotationBase annotationInfo = annotations.get(n); + if (pageNumber == annotationInfo.getPageNumber() + 1) { + AnnotationDataEntity annotation = mapAnnotationDataEntity(annotationInfo, pageInfo); pageAnnotations.add(annotation); } } - AnnotationDataEntity[] ret = new AnnotationDataEntity[pageAnnotations.size()]; - return pageAnnotations.toArray(ret); + + return pageAnnotations; } /** + *

* Map AnnotationInfo instances into AnnotationDataEntity + *

* - * @param annotationInfo AnnotationInfo instance - * @return AnnotationDataEntity instance + * @param pageInfo + * @return AnnotationDataEntity + * @param annotationInfo AnnotationInfo */ - public AnnotationDataEntity mapAnnotationDataEntity(AnnotationInfo annotationInfo) { + public static AnnotationDataEntity mapAnnotationDataEntity(AnnotationBase annotationInfo, PageInfo pageInfo) { + String annotationTypeName = AnnotationType.getName(annotationInfo.getType()); //getAnnotationType(annotationInfo.getType()); //Enum.GetName(Operators.typeOf(AnnotationType.class), annotationInfo.getType()); + float maxY = 0, minY = 0, maxX = 0, minX = 0; + float boxX = 0, boxY = 0, boxHeight = 0, boxWidth = 0; + String svgPath = ""; + //annotationTypeName (java.lang.String) "Watermark" + if (annotationInfo instanceof IPoints) { + List points = ((IPoints)annotationInfo).getPoints(); + for (Point point : points) { + maxY = point.getY() > maxY ? point.getY(): maxY; + maxX = point.getX() > maxX ? point.getX(): maxX; + minY = point.getY() < minY ? point.getY(): minY; + minX = point.getX() < minX ? point.getX(): minX; + } + } + + if (annotationInfo instanceof IBox) { + Rectangle box = ((IBox)annotationInfo).getBox(); + boxX = box.getX(); + boxY = box.getY(); + boxHeight = box.getHeight(); + boxWidth = box.getWidth(); + + StringBuilder builder = new StringBuilder(). + append("M").append(box.getX()). + append(",").append(box.getY()). + append("L").append(box.getWidth()). + append(",").append(box.getHeight()); + + svgPath = builder.toString(); + } + AnnotationDataEntity annotation = new AnnotationDataEntity(); - annotation.setFont(annotationInfo.getFontFamily()); - annotation.setFontColor(annotationInfo.getFontColor()); - annotation.setFontSize(annotationInfo.getFontSize()); - Rectangle box = annotationInfo.getBox(); - annotation.setHeight(box.getHeight()); - annotation.setLeft(box.getX()); - annotation.setTop(box.getY()); - annotation.setWidth(box.getWidth()); - annotation.setPageNumber(annotationInfo.getPageNumber() + 1); - if (annotationInfo.getSvgPath() != null) { - annotation.setSvgPath(annotationInfo.getSvgPath().replace("l", "L")); + annotation.setFont(annotationInfo instanceof IFontFamily ? ((IFontFamily)annotationInfo).getFontFamily() : ""); + + Double fontSize = annotationInfo instanceof IFontSize ? (((IFontSize)annotationInfo).getFontSize() == null) ? 0.0 : ((IFontSize)annotationInfo).getFontSize() : 0.0; + + annotation.setFontSize(fontSize); + + annotation.setFontColor( + annotationInfo instanceof IFontColor ? + ((((IFontColor) annotationInfo).getFontColor() == null) ? 0 : (int)((IFontColor) annotationInfo).getFontColor()) + : 0 + ); + annotation.setHeight(annotationInfo instanceof IBox ? boxHeight : (annotationInfo instanceof IPoints ? (maxY - minY) : 0)); + annotation.setLeft(annotationInfo instanceof IBox ? boxX : (annotationInfo instanceof IPoints ? minX : 0)); + + annotation.setPageNumber((int)annotationInfo.getPageNumber() + 1); + annotation.setSvgPath(annotationInfo instanceof ISvgPath ? (((ISvgPath)annotationInfo).getSvgPath().replace("l", "L")) : svgPath); + + String text = ""; + if (annotationInfo.getMessage() == null && annotationInfo instanceof ITextToReplace) { + text = ((ITextToReplace) annotationInfo).getTextToReplace(); + } else if (annotationInfo.getMessage() != null) { + text = annotationInfo.getMessage(); } - String text = (annotationInfo.getText() == null) ? annotationInfo.getFieldText() : annotationInfo.getText(); annotation.setText(text); - annotation.setType(AnnotationTypes.instance.getAnnotationType(annotationInfo.getType())); - setReplies(annotationInfo, annotation); - return annotation; - } - - public void setReplies(AnnotationInfo annotationInfo, AnnotationDataEntity annotation) { - // set each reply data - AnnotationReplyInfo[] replies = annotationInfo.getReplies(); - if (replies != null && replies.length > 0) { - CommentsEntity[] comments = new CommentsEntity[replies.length]; - for (int m = 0; m < replies.length; m++) { + + // TODO: remove comment after check all annotations types on main formats + annotation.setTop(annotationInfo instanceof IBox ? boxY : (annotationInfo instanceof IPoints ? pageInfo.getHeight() - maxY : 0)); + //annotation.setType(char.ToLowerInvariant(annotationTypeName[0]) + annotationTypeName.Substring(1)); !!! + annotation.setType(annotationTypeName.toUpperCase()); + annotation.setWidth(annotationInfo instanceof IBox ? boxWidth : (annotationInfo instanceof IPoints ? (maxX - minX) : 0)); + // each reply data + List replies = annotationInfo.getReplies(); + if (replies != null && replies.size() > 0) { + CommentsEntity[] comments = new CommentsEntity[replies.size()]; + for (int m = 0; m < replies.size(); m++) { CommentsEntity comment = new CommentsEntity(); - AnnotationReplyInfo reply = replies[m]; - comment.setText(reply.getMessage()); - DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); + Reply reply = replies.get(m); + comment.setText(reply.getComment()); + DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); //"yyyy-MM-dd HH:mm:ss" comment.setTime(format.format(reply.getRepliedOn())); - comment.setUserName(reply.getUserName()); + + comment.setUserName(reply.getUser().getName()); comments[m] = comment; } annotation.setComments(comments); } + + return annotation; } -} +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/util/AnnotationTypes.java b/src/main/java/com/groupdocs/ui/annotation/util/AnnotationTypes.java deleted file mode 100644 index 6793ba5..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/util/AnnotationTypes.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.groupdocs.ui.annotation.util; - -import java.util.HashMap; -import java.util.Map; - -/** - * AnnotationTypes - * Contains all annotations types - * - * @author Aspose Pty Ltd - */ -public class AnnotationTypes { - - /** - * Map annotation types from byte into string - */ - private static final Map types = new HashMap<>(); - - // init map values - { - types.put((byte) 0, "text"); - types.put((byte) 1, "area"); - types.put((byte) 2, "point"); - types.put((byte) 3, "textStrikeout"); - types.put((byte) 4, "polyline"); - types.put((byte) 5, "textField"); - types.put((byte) 6, "watermark"); - types.put((byte) 7, "textReplacement"); - types.put((byte) 8, "arrow"); - types.put((byte) 9, "textRedaction"); - types.put((byte) 10, "resourcesRedaction"); - types.put((byte) 11, "textUnderline"); - types.put((byte) 12, "distance"); - } - - /** - * Instance of AnnotationTypes - */ - public static final AnnotationTypes instance = new AnnotationTypes(); - - /** - * Private constructor, for using only in this class - */ - private AnnotationTypes() { - } - - /** - * Get string value of annotation type - * - * @param type byte value of annotation type - * @return string value of annotation type - */ - public String getAnnotationType(byte type) { - return types.get(type); - } -} - diff --git a/src/main/java/com/groupdocs/ui/annotation/util/DocumentTypesConverter.java b/src/main/java/com/groupdocs/ui/annotation/util/DocumentTypesConverter.java index 495a971..0402ff7 100644 --- a/src/main/java/com/groupdocs/ui/annotation/util/DocumentTypesConverter.java +++ b/src/main/java/com/groupdocs/ui/annotation/util/DocumentTypesConverter.java @@ -1,33 +1,31 @@ package com.groupdocs.ui.annotation.util; -import com.google.common.collect.Lists; -import com.groupdocs.annotation.domain.DocumentType; - +import com.groupdocs.annotation.models.DocumentType; import java.util.List; - +import com.google.common.collect.Lists; import static com.groupdocs.ui.util.Utils.parseFileExtension; -/** - * Converter for document types - */ public class DocumentTypesConverter { private static final List supportedImageFormats = Lists.newArrayList("bmp", "jpeg", "jpg", "tiff", "tif", "png", "gif", "emf", "wmf", "dwg", "dicom", "djvu"); private static final List supportedDiagramFormats = Lists.newArrayList(".vsd", ".vdx", ".vss", ".vsx", ".vst", ".vtx", ".vsdx", ".vdw", ".vstx", ".vssx"); - + /** + *

* Convert document type from string into int + *

* - * @param documentType string value of document type - * @return int doc type + * @return int + * @param documentType string */ - public static final int getDocumentType(String documentType) { + public static int getDocumentType(String documentType) { switch (documentType) { case "Portable Document Format": case "PDF": return DocumentType.Pdf; case "Microsoft Word": case "WORDS": + case "Microsoft Word Open XML format (.docx)": return DocumentType.Words; case "Microsoft PowerPoint": case "SLIDES": @@ -44,7 +42,7 @@ public static final int getDocumentType(String documentType) { return DocumentType.Undefined; } } - + /** * Check image and diagram document types * diff --git a/src/main/java/com/groupdocs/ui/annotation/util/PathConstants.java b/src/main/java/com/groupdocs/ui/annotation/util/PathConstants.java deleted file mode 100644 index 6f5cbf4..0000000 --- a/src/main/java/com/groupdocs/ui/annotation/util/PathConstants.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.groupdocs.ui.annotation.util; - -import java.io.File; - -public class PathConstants { - /** - * Constant value for specifying output folder - */ - public static final String OUTPUT_FOLDER = File.separator + "Annotated"; -} diff --git a/src/main/java/com/groupdocs/ui/annotation/util/SupportedAnnotations.java b/src/main/java/com/groupdocs/ui/annotation/util/SupportedAnnotations.java index 104ba4c..d0af772 100644 --- a/src/main/java/com/groupdocs/ui/annotation/util/SupportedAnnotations.java +++ b/src/main/java/com/groupdocs/ui/annotation/util/SupportedAnnotations.java @@ -1,100 +1,31 @@ package com.groupdocs.ui.annotation.util; -/** - * The list of supported annotation types for each document type - */ +import com.groupdocs.annotation.entity.Annotations; + public class SupportedAnnotations { - public static String[] CELLS = { - "text" - }; - public static String[] DIAGRAM = { - "area", - "point", - "polyline", - "textField", - "arrow", - "textRedaction", - "resourcesRedaction", - "distance" - }; - public static String[] WORD = { - "point", - "textStrikeout", - "polyline", - "textField", - "watermark", - "textReplacement", - "arrow", - "textRedaction", - "resourcesRedaction", - "textUnderline", - "distance", - "text" - }; - public static String[] PDF = { - "area", - "point", - "textStrikeout", - "polyline", - "textField", - "watermark", - "textReplacement", - "arrow", - "textRedaction", - "resourcesRedaction", - "textUnderline", - "distance", - "text" - }; - public static String[] IMAGE = { - "area", - "point", - "textStrikeout", - "polyline", - "textField", - "watermark", - "arrow", - "textRedaction", - "resourcesRedaction", - "textUnderline", - "distance", - "text" - }; - public static String[] SLIDES = { - "area", - "point", - "textStrikeout", - "polyline", - "textField", - "watermark", - "arrow", - "textRedaction", - "resourcesRedaction", - "textUnderline", - "text" - }; - public static String[] getSupportedAnnotations(String documentType) { + public static final String[] getSupportedAnnotations(String documentType) { + Annotations annotations = new Annotations(); switch (documentType) { case "Portable Document Format": case "PDF": - return PDF; + return annotations.Pdf; case "Microsoft Word": case "WORDS": - return WORD; + return annotations.Word; case "Microsoft PowerPoint": case "SLIDES": - return SLIDES; + return annotations.Slides; case "image": - return IMAGE; + return annotations.Image; case "Microsoft Excel": case "CELLS": - return CELLS; + return annotations.Cells; case "AutoCAD Drawing File Format": case "diagram": - return DIAGRAM; + return annotations.Diagram; default: - return PDF; + return annotations.Pdf; } } -} +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/util/directory/DirectoryUtils.java b/src/main/java/com/groupdocs/ui/annotation/util/directory/DirectoryUtils.java new file mode 100644 index 0000000..9f65c7d --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/util/directory/DirectoryUtils.java @@ -0,0 +1,19 @@ +package com.groupdocs.ui.annotation.util.directory; + +import com.groupdocs.ui.annotation.config.AnnotationConfiguration; + +public class DirectoryUtils { + + public FilesDirectoryUtils FilesDirectory; + + /** + *

+ * Constructor + *

+ * + * @param annotationConfiguration AnnotationConfiguration + */ + public DirectoryUtils(AnnotationConfiguration annotationConfiguration) { + FilesDirectory = new FilesDirectoryUtils(annotationConfiguration); + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/annotation/util/directory/FilesDirectoryUtils.java b/src/main/java/com/groupdocs/ui/annotation/util/directory/FilesDirectoryUtils.java new file mode 100644 index 0000000..970dde1 --- /dev/null +++ b/src/main/java/com/groupdocs/ui/annotation/util/directory/FilesDirectoryUtils.java @@ -0,0 +1,30 @@ +package com.groupdocs.ui.annotation.util.directory; + +import com.groupdocs.ui.annotation.config.AnnotationConfiguration; + +public class FilesDirectoryUtils { /*implements IDirectoryUtils { */ + + private final AnnotationConfiguration AnnotationConfiguration; + + /** + *

+ * Constructor + *

+ * + * @param annotationConfiguration + */ + public FilesDirectoryUtils(AnnotationConfiguration annotationConfiguration) { + AnnotationConfiguration = annotationConfiguration; + } + + /** + *

+ * Get path + *

+ * + * @return string + */ + public final String getPath() { + return AnnotationConfiguration.getFilesDirectory(); + } +} \ No newline at end of file diff --git a/src/main/java/com/groupdocs/ui/model/response/FileDescriptionEntity.java b/src/main/java/com/groupdocs/ui/model/response/FileDescriptionEntity.java index 1ca3d5a..cf53bb0 100644 --- a/src/main/java/com/groupdocs/ui/model/response/FileDescriptionEntity.java +++ b/src/main/java/com/groupdocs/ui/model/response/FileDescriptionEntity.java @@ -18,7 +18,7 @@ public class FileDescriptionEntity { * @return guid */ public String getGuid() { - return guid; + return guid.replace("\\", "//"); } /**