Skip to content

Commit

Permalink
Merge pull request 'feature/pdf-form' (#2) from feature/pdf-form into…
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Oct 2, 2024
2 parents 30cb6f4 + 05186e5 commit 80040ac
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 100 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

##
## Added
- creating pdf form
- button go to edit in editor
- pdf favicon

## 5.0.2
## Changed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.onlyoffice</groupId>
<artifactId>docs-integration-sdk</artifactId>
<version>1.1.2</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/onlyoffice/OnlyOfficeConvertServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.onlyoffice.model.common.Format;
import com.onlyoffice.model.convertservice.ConvertRequest;
import com.onlyoffice.model.convertservice.ConvertResponse;
import com.onlyoffice.model.convertservice.convertrequest.PDF;
import com.onlyoffice.service.convert.ConvertService;
import onlyoffice.managers.auth.AuthContext;
import onlyoffice.sdk.manager.document.DocumentManager;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
}
String pageIdString = request.getParameter("pageId");
String newTitle = request.getParameter("newTitle");
Boolean createForm = Boolean.valueOf(request.getParameter("createForm"));

String attachmentIdString = request.getParameter("attachmentId");
Long attachmentId = Long.parseLong(attachmentIdString);
Expand All @@ -106,8 +108,8 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
if (docx != null
&& extension.equals(docx.getName())
&& docx.getConvert() != null
&& docx.getConvert().contains("docxf")) {
newFileExtension = "docxf";
&& docx.getConvert().contains("pdf")) {
newFileExtension = "pdf";
}

String title = fileName.substring(0, fileName.lastIndexOf("."));
Expand All @@ -127,6 +129,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
contextMap.put("attachmentId", attachmentIdString);
contextMap.put("oldName", fileName);
contextMap.put("newName", newName);
contextMap.put("createForm", createForm);
writer.write(getTemplate(contextMap));
}

Expand All @@ -142,11 +145,11 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
}

String attachmentIdString = request.getParameter("attachmentId");
Boolean createForm = Boolean.valueOf(request.getParameter("createForm"));

ConfluenceUser user = null;
String errorMessage = null;
JSONObject json = null;


Long attachmentId = Long.parseLong(attachmentIdString);
log.info("attachmentId " + attachmentId);

Expand Down Expand Up @@ -183,8 +186,8 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
if (docx != null
&& extension.equals(docx.getName())
&& docx.getConvert() != null
&& docx.getConvert().contains("docxf")) {
convertToExt = "docxf";
&& docx.getConvert().contains("pdf")) {
convertToExt = "pdf";
}

if (!attachmentUtil.checkAccess(attachmentId, user, false)
Expand All @@ -210,6 +213,10 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
.region(region)
.build();

if (convertToExt.equals("pdf") && createForm) {
convertRequest.setPdf(new PDF(true));
}

ConvertResponse convertResponse = convertService.processConvert(convertRequest,
String.valueOf(attachmentId));

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/onlyoffice/OnlyOfficeEditorServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import onlyoffice.managers.auth.AuthContext;
import com.atlassian.confluence.pages.Attachment;
import onlyoffice.sdk.manager.document.DocumentManager;
import onlyoffice.sdk.manager.security.JwtManager;
import onlyoffice.sdk.manager.url.UrlManager;
import onlyoffice.utils.attachment.AttachmentUtil;
import org.apache.log4j.LogManager;
Expand Down Expand Up @@ -68,20 +69,22 @@ public class OnlyOfficeEditorServlet extends HttpServlet {
private final AttachmentUtil attachmentUtil;
private final ConfigService configService;
private final SettingsManager settingsManager;
private final JwtManager jwtManager;

private final LocaleManager localeManager;

public OnlyOfficeEditorServlet(final I18nResolver i18n, final UrlManager urlManager, final AuthContext authContext,
final DocumentManager documentManager, final AttachmentUtil attachmentUtil,
final ConfigService configService, final SettingsManager settingsManager,
final LocaleManager localeManager) {
final JwtManager jwtManager, final LocaleManager localeManager) {
this.i18n = i18n;
this.urlManager = urlManager;
this.authContext = authContext;
this.documentManager = documentManager;
this.attachmentUtil = attachmentUtil;
this.configService = configService;
this.settingsManager = settingsManager;
this.jwtManager = jwtManager;
this.localeManager = localeManager;
}

Expand Down Expand Up @@ -111,7 +114,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
String extension = fileExt == null
|| !fileExt.equals("xlsx")
&& !fileExt.equals("pptx")
&& !fileExt.equals("docxf")
&& !fileExt.equals("pdf")
? "docx" : fileExt.trim();

String name = fileName == null || fileName.equals("")
Expand Down Expand Up @@ -182,9 +185,20 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
request.getHeader("USER-AGENT")
);

if (modeString != null
&& modeString.equals("fillForms")
&& config.getDocument().getPermissions().getFillForms()
) {
config.getDocument().getPermissions().setEdit(false);
}

config.getEditorConfig().setLang(localeManager.getLocale(user).toLanguageTag());
config.getEditorConfig().setActionLink(actionData);

if (settingsManager.isSecurityEnabled()) {
config.setToken(jwtManager.createToken(config));
}

ObjectMapper mapper = createObjectMapper();

context.put("request", request);
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/onlyoffice/conditions/IsOfficeFileAttachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

public class IsOfficeFileAttachment implements Condition {
private boolean forEdit;
private boolean form;
private DocumentManager documentManager;
private AttachmentUtil attachmentUtil;

Expand All @@ -41,13 +40,9 @@ public IsOfficeFileAttachment(final DocumentManager documentManager, final Attac

public void init(final Map<String, String> params) throws PluginParseException {
forEdit = false;
form = false;
if (params != null && !params.isEmpty() && params.get("forEdit") != null) {
forEdit = !params.get("forEdit").isEmpty();
}
if (params != null && !params.isEmpty() && params.get("form") != null) {
form = !params.get("form").isEmpty();
}
}

public boolean shouldDisplay(final Map<String, Object> context) {
Expand All @@ -65,19 +60,12 @@ public boolean shouldDisplay(final Map<String, Object> context) {
String fileName = attachment.getFileName();

if (forEdit) {
if (form) {
if (accessEdit && documentManager.isFillable(fileName)) {
return true;
}
} else {
if (accessEdit && documentManager.isEditable(fileName)) {
return true;
}
if (accessEdit && documentManager.isEditable(fileName)) {
return true;
}
} else {
if (accessView
&& documentManager.isViewable(fileName)
&& !(accessEdit && documentManager.isEditable(fileName))
&& documentManager.isViewable(fileName) && !(accessEdit && documentManager.isEditable(fileName))
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean shouldDisplay(final Map<String, Object> context) {
return false;
}

if ((form && !ext.equals("docxf")) || (!form && ext.equals("docxf"))) {
if (form && !ext.equals("docxf")) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
String fileName = attachment.getFileName();
String access = null;

if (accessEdit && documentManager.isEditable(fileName)) {
if (accessEdit && documentManager.isFillable(fileName)) {
access = "fillForms";
} else if (accessEdit && documentManager.isEditable(fileName)) {
access = "edit";
} else if (accessEdit && documentManager.isFillable(fileName)) {
access = "fillform";
} else if (accessView && documentManager.isViewable(fileName)
&& !(accessEdit
&& (documentManager.isEditable(fileName) || documentManager.isFillable(fileName)))) {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/onlyoffice/macro/OnlyOfficePreviewMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public String execute(final Map<String, String> args, final String s, final Conv

if (attachmentUtil.checkAccess(attachment.getId(), user, true)
&& !isPreview) {
if (documentManager.isEditable(fileName)) {
action = "edit";
} else if (documentManager.isFillable(fileName)) {
if (documentManager.isFillable(fileName)) {
action = "fill";
} else if (documentManager.isEditable(fileName)) {
action = "edit";
}
}

Expand Down Expand Up @@ -183,9 +183,6 @@ public ImagePlaceholder getImagePlaceholder(final Map<String, String> args,
String fileExt = name.substring(dotIdx + 1).toLowerCase();
if (documentManager.getDocumentType(name) != null) {
documentType = documentManager.getDocumentType(name).name().toLowerCase();
if (fileExt.equals("oform")) {
documentType = "form";
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/onlyoffice/sdk/manager/url/UrlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public String getCreateUrl(final String fileId) {
if (attachmentUtil.checkAccessCreate(user, pageId)) {
String fileName = documentManager.getDocumentName(fileId);
String extension = documentManager.getExtension(fileName);
DocumentType documentType = documentManager.getDocumentType(fileName);

if (!extension.equals("docxf")) {
extension = documentManager.getDefaultExtension(documentType);
}

return getConfluenceBaseUrl(false) + DOC_EDITOR_SERVLET + "?pageId=" + pageId + "&fileExt=" + extension;
} else {
Expand Down
21 changes: 6 additions & 15 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<resource type="download" name="images/preview-placeholder-word.svg" key="images" location="images/preview-placeholder-word.svg"/>
<resource type="download" name="images/preview-placeholder-cell.svg" key="images" location="images/preview-placeholder-cell.svg"/>
<resource type="download" name="images/preview-placeholder-slide.svg" key="images" location="images/preview-placeholder-slide.svg"/>
<resource type="download" name="images/preview-placeholder-form.svg" key="images" location="images/preview-placeholder-form.svg"/>
<resource type="download" name="images/preview-placeholder-pdf.svg" key="images" location="images/preview-placeholder-pdf.svg"/>

<web-resource key="onlyoffice-confluence-plugin-resources" name="Web Resources container for the main page">
<resource type="download" name="onlyoffice-main.js" location="js/onlyoffice-main.js"/>
Expand Down Expand Up @@ -70,7 +70,7 @@
<resource type="download" name="new-docx.svg" location="images/new-docx.svg"/>
<resource type="download" name="new-xlsx.svg" location="images/new-xlsx.svg"/>
<resource type="download" name="new-pptx.svg" location="images/new-pptx.svg"/>
<resource type="download" name="new-docxf.svg" location="images/new-docxf.svg"/>
<resource type="download" name="new-pdf.svg" location="images/new-pdf.svg"/>
<resource type="download" name="confirm.svg" location="images/confirm.svg"/>
<resource type="download" name="16.svg" location="images/16.svg"/>
<condition class="onlyoffice.conditions.IsOfficePageAttachments"/>
Expand Down Expand Up @@ -103,6 +103,7 @@
<resource type="download" name="word.ico" location="images/word.ico"/>
<resource type="download" name="cell.ico" location="images/cell.ico"/>
<resource type="download" name="slide.ico" location="images/slide.ico"/>
<resource type="download" name="pdf.ico" location="images/pdf.ico"/>
</web-resource>

<web-resource key="macro-browser-smart-fields" name="Macro Browser Smart Fields">
Expand Down Expand Up @@ -146,21 +147,11 @@
<link><![CDATA[/plugins/servlet/onlyoffice/doceditor?attachmentId=$attachment.id]]></link>
<styleClass>onlyoffice-doceditor</styleClass>
</web-item>
<web-item key="onlyoffice-docform" name="Link for the attachment fill form" section="system.attachment" weight="9">
<condition class="onlyoffice.conditions.IsOfficeFileAttachment">
<param name="forEdit">true</param>
<param name="form">true</param>
</condition>
<description>The link and the text for it which is used to open the .oform document to fill in the fields in the form.</description>
<label key="onlyoffice.editor.fillFormlink"/>
<link><![CDATA[/plugins/servlet/onlyoffice/doceditor?attachmentId=$attachment.id]]></link>
<styleClass>onlyoffice-doceditor</styleClass>
</web-item>
<web-item key="onlyoffice-docviewer" name="Link for viewing the attachment" section="system.attachment" weight="10">
<condition class="onlyoffice.conditions.IsOfficeFileAttachment"/>
<description>Link and text for this link used to open the document which is available for preview only.</description>
<label key="onlyoffice.editor.viewlink"/>
<link><![CDATA[/plugins/servlet/onlyoffice/doceditor?attachmentId=$attachment.id&mode=view]]></link>
<link><![CDATA[/plugins/servlet/onlyoffice/doceditor?attachmentId=$attachment.id]]></link>
<styleClass>onlyoffice-doceditor</styleClass>
</web-item>
<web-item key="onlyoffice-docconvert" name="Link for converting the attachment" section="system.attachment" weight="11">
Expand All @@ -170,13 +161,13 @@
<link><![CDATA[/plugins/servlet/onlyoffice/convert?attachmentId=$attachment.id]]></link>
<styleClass>onlyoffice-doceditor</styleClass>
</web-item>
<web-item key="onlyoffice-doc-create-form" name="Link for create oform from docxf" section="system.attachment" weight="11">
<web-item key="onlyoffice-doc-create-form" name="Link for create pdf from docxf" section="system.attachment" weight="11">
<condition class="onlyoffice.conditions.IsOfficeFileConvertAttachment">
<param name="form">true</param>
</condition>
<description>The link and the text for it which is used to convert the docx to oform</description>
<label key="onlyoffice.form.create.link"/>
<link><![CDATA[/plugins/servlet/onlyoffice/convert?attachmentId=$attachment.id]]></link>
<link><![CDATA[/plugins/servlet/onlyoffice/convert?attachmentId=$attachment.id&createFrom=true]]></link>
<styleClass>onlyoffice-doceditor</styleClass>
</web-item>
<web-item key="onlyoffice-download-as" name="Link to download as attachment" section="system.attachment" weight="35">
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/css/dialog-filecreate.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
background-image: url(new-pptx.svg);
}

#inline-dialog-filecreate .icon-onlyoffice-new-docxf{
background-image: url(new-docxf.svg);
#inline-dialog-filecreate .icon-onlyoffice-new-pdf{
background-image: url(new-pdf.svg);
}

#inline-dialog-filecreate .filename{
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/images/new-docxf.svg

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/resources/images/new-pdf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/pdf.ico
Binary file not shown.
Loading

0 comments on commit 80040ac

Please sign in to comment.