Skip to content

Commit 0aa96e7

Browse files
#15, EXM-47487: Check if update is allowed before to start the process.
1 parent 5ca0753 commit 0aa96e7

File tree

6 files changed

+69
-37
lines changed

6 files changed

+69
-37
lines changed

src/main/java/com/oxygenxml/prolog/updater/DitaPrologUpdater.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ public void updateProlog(final WSEditor wsEditor, final boolean isNewDocument) {
7474
AWTUtil.invokeSynchronously(new Runnable() {
7575
public void run() {
7676
if (ditaEditor[0] != null) {
77-
boolean wasUpdated = ditaEditor[0].updateProlog(isNewDocument);
78-
if (!wasUpdated) {
79-
showWarnMessage(wsEditor);
80-
}
77+
if(prologContentCreater.isAllowedUpdate(ditaEditor[0].getDocumentType())) {
78+
boolean wasUpdated = ditaEditor[0].updateProlog(isNewDocument);
79+
if (!wasUpdated) {
80+
showWarnMessage(wsEditor);
81+
}
82+
}
8183
}
8284
}
8385
});

src/main/java/com/oxygenxml/prolog/updater/dita/editor/DitaEditor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ public interface DitaEditor {
1515
*/
1616
boolean updateProlog( boolean isNewDocument);
1717

18+
/**
19+
* Get the type of the current document.
20+
* @return The type of the current document
21+
* ( {@link DocumentType#TOPIC}, {@link DocumentType#MAP},
22+
* {@link DocumentType#BOOKMAP} or {@link DocumentType#SUBJECT_SCHEME} ).
23+
*/
24+
public DocumentType getDocumentType();
1825
}

src/main/java/com/oxygenxml/prolog/updater/dita/editor/DitaTopicAuthorEditor.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.apache.log4j.Logger;
99

1010
import com.oxygenxml.prolog.updater.prolog.content.PrologContentCreator;
11-
import com.oxygenxml.prolog.updater.tags.OptionKeys;
1211
import com.oxygenxml.prolog.updater.utils.AuthorPageDocumentUtil;
1312
import com.oxygenxml.prolog.updater.utils.ElementXPathUtils;
1413
import com.oxygenxml.prolog.updater.utils.XMLFragmentUtils;
@@ -21,12 +20,9 @@
2120
import ro.sync.ecss.extensions.api.node.AttrValue;
2221
import ro.sync.ecss.extensions.api.node.AuthorElement;
2322
import ro.sync.ecss.extensions.api.node.AuthorNode;
24-
import ro.sync.exml.workspace.api.PluginWorkspace;
25-
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
2623
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
2724
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
2825
import ro.sync.exml.workspace.api.editor.page.ditamap.WSDITAMapEditorPage;
29-
import ro.sync.exml.workspace.api.options.WSOptionsStorage;
3026

3127
/**
3228
* Edit DITA topic in author mode.
@@ -452,12 +448,13 @@ private void updateAuthorElements(AuthorElement prolog, boolean isNewDocument) t
452448
}
453449

454450
/**
455-
* Get the document type of the current document.
456-
* @return The document type of the current document
451+
* Get the type of the current document.
452+
* @return The type of the current document
457453
* ( {@link DocumentType#TOPIC}, {@link DocumentType#MAP},
458454
* {@link DocumentType#BOOKMAP} or {@link DocumentType#SUBJECT_SCHEME} ).
459455
*/
460-
private DocumentType getDocumentType() {
456+
@Override
457+
public DocumentType getDocumentType() {
461458
DocumentType docType = DocumentType.TOPIC;
462459
AuthorElement rootElement = documentController.getAuthorDocumentNode().getRootElement();
463460
AttrValue classValue = rootElement.getAttribute(XmlElementsConstants.CLASS);

src/main/java/com/oxygenxml/prolog/updater/dita/editor/DitaTopicTextEditor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ private void editAuthor(boolean isNewDocument) throws XPathException, TextOperat
402402
* ( {@link DocumentType#TOPIC}, {@link DocumentType#MAP},
403403
* {@link DocumentType#BOOKMAP} or {@link DocumentType#SUBJECT_SCHEME} ).
404404
*/
405-
private DocumentType getDocumentType() {
405+
@Override
406+
public DocumentType getDocumentType() {
406407
DocumentType docType = DocumentType.TOPIC;
407408

408409
try {

src/main/java/com/oxygenxml/prolog/updater/prolog/content/PrologContentCreator.java

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ public class PrologContentCreator {
5353
/**
5454
* <code>true</code> if the creator must be set in DITA Topic.
5555
*/
56-
private boolean setTopicCreator = true;
56+
private boolean isAllowedTopicCreatorUpdate = true;
5757

5858
/**
5959
* <code>true</code> if the creator must be set in DITA Map.
6060
*/
61-
private boolean setMapCreator = true;
61+
private boolean isAllowedMapCreatorUpdate = true;
6262

6363
/**
6464
* <code>true</code> if the contributor must be update in DITA Topic.
6565
*/
66-
private boolean updateTopicContributor = true;
66+
private boolean isAllowedTopicContributorUpdate = true;
6767

6868
/**
6969
* <code>true</code> if the contributor must be update in DITA Map.
7070
*/
71-
private boolean updateMapContributor = true;
71+
private boolean isAllowedMapContributorUpdate = true;
7272

7373
/**
7474
* <code>true</code> if the prolog update is allowed in DITA Topic.
@@ -83,22 +83,22 @@ public class PrologContentCreator {
8383
/**
8484
* <code>true</code> if the created date must be set in DITA Topic.
8585
*/
86-
private boolean setTopicCreatedDate = true;
86+
private boolean isAllowedTopicCreatedDateUpdate = true;
8787

8888
/**
8989
* <code>true</code> if the created date must be set in DITA Map.
9090
*/
91-
private boolean setMapCreatedDate = true;
91+
private boolean isAllowedMapCreatedDateUpdate = true;
9292

9393
/**
9494
* <code>true</code> if the revised date must be update in DITA Topic.
9595
*/
96-
private boolean updateTopicRevisedDate = true;
96+
private boolean isAllowedTopicRevisedDateUpdate = true;
9797

9898
/**
9999
* <code>true</code> if the revised date must be update in DITA Map.
100100
*/
101-
private boolean updateMapRevisedDate = true;
101+
private boolean isAllowedMapRevisedDateUpdate = true;
102102

103103
/**
104104
* The maximum number of revised elements
@@ -212,8 +212,8 @@ public String getPrologFragment(boolean isNewDocument, DocumentType documentType
212212
*/
213213
public String getCreatorFragment(DocumentType documentType) {
214214
String fragment = null;
215-
if ((setTopicCreator && documentType.equals(DocumentType.TOPIC))
216-
|| (setMapCreator && !documentType.equals(DocumentType.TOPIC))) {
215+
if ((isAllowedTopicCreatorUpdate && documentType.equals(DocumentType.TOPIC))
216+
|| (isAllowedMapCreatorUpdate && !documentType.equals(DocumentType.TOPIC))) {
217217
fragment = creatorFragment.toString();
218218
}
219219
return fragment;
@@ -228,8 +228,8 @@ public String getCreatorFragment(DocumentType documentType) {
228228
*/
229229
public String getContributorFragment(DocumentType documentType) {
230230
String fragment = null;
231-
if ((updateTopicContributor && documentType.equals(DocumentType.TOPIC))
232-
|| (updateMapContributor && !documentType.equals(DocumentType.TOPIC))) {
231+
if ((isAllowedTopicContributorUpdate && documentType.equals(DocumentType.TOPIC))
232+
|| (isAllowedMapContributorUpdate && !documentType.equals(DocumentType.TOPIC))) {
233233
fragment = contributorXML.toString();
234234
}
235235
return fragment;
@@ -244,8 +244,8 @@ public String getContributorFragment(DocumentType documentType) {
244244
*/
245245
public String getCreatedDateFragment(DocumentType documentType) {
246246
String fragment = null;
247-
if ((setTopicCreatedDate && documentType.equals(DocumentType.TOPIC))
248-
|| (setMapCreatedDate && !documentType.equals(DocumentType.TOPIC))) {
247+
if ((isAllowedTopicCreatedDateUpdate && documentType.equals(DocumentType.TOPIC))
248+
|| (isAllowedMapCreatedDateUpdate && !documentType.equals(DocumentType.TOPIC))) {
249249
fragment = createdDateXML.toString();
250250
}
251251
return fragment;
@@ -260,8 +260,8 @@ public String getCreatedDateFragment(DocumentType documentType) {
260260
*/
261261
public String getRevisedDateFragment(DocumentType documentType) {
262262
String fragment = null;
263-
if ((updateTopicRevisedDate && documentType.equals(DocumentType.TOPIC))
264-
|| (updateMapRevisedDate && !documentType.equals(DocumentType.TOPIC))) {
263+
if ((isAllowedTopicRevisedDateUpdate && documentType.equals(DocumentType.TOPIC))
264+
|| (isAllowedMapRevisedDateUpdate && !documentType.equals(DocumentType.TOPIC))) {
265265
fragment = revisedDateFragment.toString();
266266
}
267267
return fragment;
@@ -352,22 +352,22 @@ private void loadOptions() {
352352
isAllowedMapUpdate = Boolean.parseBoolean(value);
353353

354354
value = optionsStorage.getOption(OptionKeys.TOPIC_SET_CREATOR, String.valueOf(true));
355-
setTopicCreator = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
355+
isAllowedTopicCreatorUpdate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
356356
value = optionsStorage.getOption(OptionKeys.MAP_SET_CREATOR, String.valueOf(true));
357-
setMapCreator = Boolean.parseBoolean(value) && isAllowedMapUpdate;
357+
isAllowedMapCreatorUpdate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
358358
value = optionsStorage.getOption(OptionKeys.TOPIC_UPDATE_CONTRIBUTOR, String.valueOf(true));
359-
updateTopicContributor = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
359+
isAllowedTopicContributorUpdate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
360360
value = optionsStorage.getOption(OptionKeys.MAP_UPDATE_CONTRIBUTOR, String.valueOf(true));
361-
updateMapContributor = Boolean.parseBoolean(value) && isAllowedMapUpdate;
361+
isAllowedMapContributorUpdate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
362362

363363
value = optionsStorage.getOption(OptionKeys.TOPIC_SET_CREATED_DATE, String.valueOf(true));
364-
setTopicCreatedDate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
364+
isAllowedTopicCreatedDateUpdate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
365365
value = optionsStorage.getOption(OptionKeys.MAP_SET_CREATED_DATE, String.valueOf(true));
366-
setMapCreatedDate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
366+
isAllowedMapCreatedDateUpdate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
367367
value = optionsStorage.getOption(OptionKeys.TOPIC_UPDATE_REVISED_DATES, String.valueOf(true));
368-
updateTopicRevisedDate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
368+
isAllowedTopicRevisedDateUpdate = Boolean.parseBoolean(value) && isAllowedTopicUpdate;
369369
value = optionsStorage.getOption(OptionKeys.MAP_UPDATE_REVISED_DATES, String.valueOf(true));
370-
updateMapRevisedDate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
370+
isAllowedMapRevisedDateUpdate = Boolean.parseBoolean(value) && isAllowedMapUpdate;
371371

372372
value = optionsStorage.getOption(OptionKeys.CUSTOM_CREATOR_TYPE_VALUE, "");
373373
if (value != null && !value.isEmpty()) {
@@ -380,11 +380,37 @@ private void loadOptions() {
380380
}
381381
}
382382

383+
/**
384+
* Check if it's allowed the update for the given document type.
385+
*
386+
* @param documentType The document type: {@link DocumentType#TOPIC},
387+
* {@link DocumentType#MAP} or {@link DocumentType#BOOKMAP}
388+
* @return
389+
*/
390+
public boolean isAllowedUpdate(DocumentType documentType) {
391+
boolean isAllowed = false;
392+
if (documentType.equals(DocumentType.TOPIC)) {
393+
isAllowed = isAllowedTopicCreatorUpdate || isAllowedTopicContributorUpdate
394+
|| isAllowedTopicCreatedDateUpdate || isAllowedTopicRevisedDateUpdate;
395+
} else {
396+
isAllowed = isAllowedMapCreatorUpdate || isAllowedMapContributorUpdate
397+
|| isAllowedMapCreatedDateUpdate || isAllowedMapRevisedDateUpdate;
398+
}
399+
return isAllowed;
400+
}
383401

402+
/**
403+
* Get the value of type attribute for creator.
404+
* @return The value of type attribute for creator.
405+
*/
384406
public String getCreatorTypeValue() {
385407
return creatorTypeValue;
386408
}
387409

410+
/**
411+
* Get the value of type attribute for contributor.
412+
* @return The value of type attribute for contributor.
413+
*/
388414
public String getContributorTypeValue() {
389415
return contributorTypeValue;
390416
}

src/main/java/com/oxygenxml/prolog/updater/view/PrologOptionPage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.oxygenxml.prolog.updater.prolog.content.DateFormats;
1515
import com.oxygenxml.prolog.updater.tags.OptionKeys;
1616
import com.oxygenxml.prolog.updater.tags.Tags;
17-
import com.oxygenxml.prolog.updater.utils.XmlElementsConstants;
1817

1918
import ro.sync.exml.workspace.api.PluginResourceBundle;
2019
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;

0 commit comments

Comments
 (0)