Skip to content

Commit 5ca0753

Browse files
#21, EXM-47281: Don't allow adding original author as additional one.
1 parent a628b52 commit 5ca0753

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

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

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

1010
import com.oxygenxml.prolog.updater.prolog.content.PrologContentCreator;
11+
import com.oxygenxml.prolog.updater.tags.OptionKeys;
1112
import com.oxygenxml.prolog.updater.utils.AuthorPageDocumentUtil;
1213
import com.oxygenxml.prolog.updater.utils.ElementXPathUtils;
1314
import com.oxygenxml.prolog.updater.utils.XMLFragmentUtils;
@@ -20,9 +21,12 @@
2021
import ro.sync.ecss.extensions.api.node.AttrValue;
2122
import ro.sync.ecss.extensions.api.node.AuthorElement;
2223
import ro.sync.ecss.extensions.api.node.AuthorNode;
24+
import ro.sync.exml.workspace.api.PluginWorkspace;
25+
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
2326
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
2427
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
2528
import ro.sync.exml.workspace.api.editor.page.ditamap.WSDITAMapEditorPage;
29+
import ro.sync.exml.workspace.api.options.WSOptionsStorage;
2630

2731
/**
2832
* Edit DITA topic in author mode.
@@ -415,10 +419,11 @@ private void updateAuthorElements(AuthorElement prolog, boolean isNewDocument) t
415419
fragment = prologCreator.getCreatorFragment(documentType);
416420
}
417421
} else {
418-
if (!AuthorPageDocumentUtil.hasContributor(
419-
existentAuthorsElements,
420-
prologCreator.getContributorTypeValue(),
421-
prologCreator.getAuthor())) {
422+
if ( ! AuthorPageDocumentUtil.hasCreator(
423+
existentAuthorsElements, prologCreator.getCreatorTypeValue())
424+
&&
425+
! AuthorPageDocumentUtil.hasContributor(
426+
existentAuthorsElements, prologCreator.getContributorTypeValue(), prologCreator.getAuthor())) {
422427
// if wasn't found this contributor
423428
fragment = prologCreator.getContributorFragment(documentType);
424429
int nuOfAuthors = existentAuthorsElements.size();

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,20 +370,26 @@ private void addAuthor(boolean isNewDocument) throws TextOperationException {
370370
*/
371371
private void editAuthor(boolean isNewDocument) throws XPathException, TextOperationException {
372372
// prolog contains author elements
373-
String xpath;
374-
String fragment;
373+
String fragment = null;
374+
Object[] creatorElement = wsTextEditorPage.evaluateXPath(
375+
ElementXPathUtils.getAuthorCreatorXpath(documentType));
375376
if (isNewDocument) {
376377
// The document isn't new. We should work with creators
377-
xpath = ElementXPathUtils.getAuthorCreatorXpath(documentType);
378-
fragment = prologCreator.getCreatorFragment(documentType);
378+
if (creatorElement.length == 0) {
379+
fragment = prologCreator.getCreatorFragment(documentType);
380+
}
379381
} else {
380382
// The document isn't new. We should work with contributors
381-
xpath = ElementXPathUtils.getAuthorContributorXpath(documentType, prologCreator.getAuthor());
382-
fragment = prologCreator.getContributorFragment(documentType);
383+
if (creatorElement.length == 0) {
384+
Object[] contributorElement = wsTextEditorPage.evaluateXPath(
385+
ElementXPathUtils.getAuthorContributorXpath(documentType, prologCreator.getAuthor()));
386+
if(contributorElement.length == 0) {
387+
fragment = prologCreator.getContributorFragment(documentType);
388+
}
389+
}
383390
}
384391

385-
Object[] authorElements = wsTextEditorPage.evaluateXPath(xpath);
386-
if (authorElements.length == 0) {
392+
if (fragment != null) {
387393
// there aren't creator/contributor author elements in prolog
388394
TextPageDocumentUtil.insertXmlFragment(wsTextEditorPage, fragment,
389395
ElementXPathUtils.getLastAuthorXpath(documentType), RelativeInsertPosition.INSERT_LOCATION_AFTER);

src/main/java/com/oxygenxml/prolog/updater/tags/OptionKeys.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,4 @@ private OptionKeys() {
9292
* Option to set the revised dates in prolog for maps.
9393
*/
9494
public static final String MAP_UPDATE_REVISED_DATES = "prolog.updater.update.revised.dates.map";
95-
96-
/**
97-
* Option to allow adding of original author as additional one.
98-
*/
99-
public static final String ALLOW_ADDING_ORIGINAL_AUTHOR_AS_ADDITIONAL = "allow.adding.original.author.as.additional";
10095
}

src/test/java/com/oxygenxml/prolog/updater/DitaMapUpdaterAuthorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public void testUpdateAuthorInProlog() throws IOException, SAXException, BadLoca
6060
String expectedOldXmlWithCreator = "<?xml version=\"1.0\" encoding=\"utf-8\"?><map>" +
6161
" <topicmeta >" +
6262
" <author type=\"creator\" >"+AuthorTestCase.AUTHOR_NAME+"</author>" +
63-
" <author type=\"contributor\" >"+AuthorTestCase.AUTHOR_NAME+"</author>" +
6463
" <critdates>" +
6564
" <!--"+AuthorTestCase.AUTHOR_NAME+"-->" +
6665
" <revised modified=\""+localDate+"\" />" +

src/test/java/com/oxygenxml/prolog/updater/DitaTopicUpdaterAuthorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public void testUpdateAuthorInProlog() throws IOException, SAXException, BadLoca
6666
" <title > </title>" +
6767
" <prolog >" +
6868
" <author type=\"creator\" >"+AuthorTestCase.AUTHOR_NAME+"</author>" +
69-
" <author type=\"contributor\" >"+AuthorTestCase.AUTHOR_NAME+"</author>" +
7069
" <critdates>" +
7170
" <!--"+AuthorTestCase.AUTHOR_NAME+"-->" +
7271
" <revised modified=\""+localDate+"\" />" +

0 commit comments

Comments
 (0)