Skip to content

Commit ae6afe5

Browse files
EXM-47281: Also check the name of the creator when adding a contributor.
1 parent 0521ee6 commit ae6afe5

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ private void updateAuthorElements(AuthorElement prolog, boolean isNewDocument) t
415415
fragment = prologCreator.getCreatorFragment(documentType);
416416
}
417417
} else {
418-
if ( ! AuthorPageDocumentUtil.hasCreator(
419-
existentAuthorsElements, prologCreator.getCreatorTypeValue())
418+
if ( ! AuthorPageDocumentUtil.hasAuthorWithTypeAndName(
419+
existentAuthorsElements, prologCreator.getCreatorTypeValue(), prologCreator.getAuthor())
420420
&&
421-
! AuthorPageDocumentUtil.hasContributor(
421+
! AuthorPageDocumentUtil.hasAuthorWithTypeAndName(
422422
existentAuthorsElements, prologCreator.getContributorTypeValue(), prologCreator.getAuthor())) {
423423
// if wasn't found this contributor
424424
fragment = prologCreator.getContributorFragment(documentType);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,23 @@ private void addAuthor(boolean isNewDocument) throws TextOperationException {
371371
private void editAuthor(boolean isNewDocument) throws XPathException, TextOperationException {
372372
// prolog contains author elements
373373
String fragment = null;
374-
Object[] creatorElement = wsTextEditorPage.evaluateXPath(
375-
ElementXPathUtils.getAuthorCreatorXpath(documentType));
376374
if (isNewDocument) {
375+
Object[] creatorElement = wsTextEditorPage.evaluateXPath(
376+
ElementXPathUtils.getAuthorXpathByTypeAndName(
377+
documentType, prologCreator.getCreatorTypeValue(), null));
377378
// The document isn't new. We should work with creators
378379
if (creatorElement.length == 0) {
379380
fragment = prologCreator.getCreatorFragment(documentType);
380381
}
381382
} else {
382383
// The document isn't new. We should work with contributors
384+
Object[] creatorElement = wsTextEditorPage.evaluateXPath(
385+
ElementXPathUtils.getAuthorXpathByTypeAndName(
386+
documentType, prologCreator.getCreatorTypeValue(), prologCreator.getAuthor()));
383387
if (creatorElement.length == 0) {
384388
Object[] contributorElement = wsTextEditorPage.evaluateXPath(
385-
ElementXPathUtils.getAuthorContributorXpath(documentType, prologCreator.getAuthor()));
389+
ElementXPathUtils.getAuthorXpathByTypeAndName(
390+
documentType, prologCreator.getContributorTypeValue(), prologCreator.getAuthor()));
386391
if(contributorElement.length == 0) {
387392
fragment = prologCreator.getContributorFragment(documentType);
388393
}

src/main/java/com/oxygenxml/prolog/updater/utils/AuthorPageDocumentUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,22 @@ public static boolean hasCreator(List<AuthorElement> authors, String creatorType
120120

121121

122122
/**
123-
* Search for contributor author with the given name
123+
* Search for author with the type attribute and the given name
124124
*
125125
* @param authors The list with authors.
126-
* @param contributorTypeValue The value of type attribute for a contributor.
126+
* @param attributeType The value of type attribute.
127127
* @param authorName The name of the author.
128128
*
129129
* @return <code>true</code> if was found an author with given type.
130130
*/
131-
public static boolean hasContributor(List<AuthorElement> authors, String contributorTypeValue, String authorName) {
131+
public static boolean hasAuthorWithTypeAndName(List<AuthorElement> authors, String attributeType, String authorName) {
132132
boolean foundContributor = false;
133133

134134
// Iterate over authors.
135135
for (AuthorElement el : authors) {
136136
// Get the type's value,
137137
AttrValue typeAttr = el.getAttribute("type");
138-
if (typeAttr != null && contributorTypeValue.equals(typeAttr.getValue())) {
138+
if (typeAttr != null && attributeType.equals(typeAttr.getValue())) {
139139
try {
140140
// Check the content of contributor element.
141141
String textContent = el.getTextContent();

src/main/java/com/oxygenxml/prolog/updater/utils/ElementXPathUtils.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -132,50 +132,46 @@ private static String getAuthorCreatorXPathInternal(String prologTypeXpath) {
132132
}
133133

134134
/**
135-
* Get the XPath of the contributor element with the given author name.
135+
* Get the XPath of the author element with the given type attribute and the given author name.
136136
*
137137
* @param documentType
138138
* The document type( {@link DocumentType#TOPIC},
139139
* {@link DocumentType#MAP}, {@link DocumentType#BOOKMAP}
140140
* or {@link DocumentType#SUBJECT_SCHEME} ).
141+
* @param authorType The type attribute of the author.
141142
* @param authorName The name of the author.
142143
*
143-
* @return The XPath of last the creator element.
144+
* @return The XPath of the author element with the given type attribute and the given author name.
144145
*/
145-
public static String getAuthorContributorXpath(DocumentType documentType, String authorName) {
146+
public static String getAuthorXpathByTypeAndName(DocumentType documentType, String authorType, String authorName) {
146147
return documentType.equals(DocumentType.TOPIC)
147-
? getAuthorContributorXPathInternal(ElementXPathConstants.PROLOG_XPATH, authorName)
148-
: getAuthorContributorXPathInternal(ElementXPathConstants.TOPICMETA_XPATH, authorName);
148+
? getAuthorXpathByTypeAndNameInternal(ElementXPathConstants.PROLOG_XPATH, authorType, authorName)
149+
: getAuthorXpathByTypeAndNameInternal(ElementXPathConstants.TOPICMETA_XPATH, authorType, authorName);
149150
}
150151

151152
/**
152-
* Get the xpath for retrieving the contributor elements with the given author name.
153+
* Get the XPath of the author element with the given type attribute and the given author name.
153154
*
154155
* @param prologTypeXpath The xpath to prolog/topicmeta element.
155-
* @param authorName The name of the author.
156-
*
157-
* @return The xpath for retrieving all contributor elements with the given author name.
156+
* @param authorType The type attribute of the author.
157+
* @param authorName The name of the author.
158+
*
159+
* @return The XPath of the author element with the given type attribute and the given author name.
158160
*/
159-
private static String getAuthorContributorXPathInternal(String prologTypeXpath, String authorName) {
161+
private static String getAuthorXpathByTypeAndNameInternal(String prologTypeXpath, String authorType, String authorName) {
160162
StringBuilder xpath = new StringBuilder();
161163
xpath.append(prologTypeXpath);
162-
xpath.append("/author[@type='");
163-
164-
String creatorTypeValue = XmlElementsConstants.CONTRIBUTOR_TYPE;
165-
PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
166-
if (pluginWorkspace != null) {
167-
WSOptionsStorage optionsStorage = pluginWorkspace.getOptionsStorage();
168-
String valueFromOptions = optionsStorage.getOption(OptionKeys.CUSTOM_CONTRIBUTOR_TYPE_VALUE, "");
169-
if (!valueFromOptions.isEmpty()) {
170-
creatorTypeValue = valueFromOptions;
171-
}
164+
xpath.append("/author");
165+
if(authorType != null) {
166+
xpath.append("[@type='");
167+
xpath.append(authorType).append("']");
168+
}
169+
if(authorName != null) {
170+
xpath.append("[text()= '").append(authorName).append("']");
172171
}
173-
xpath.append(creatorTypeValue);
174-
xpath.append("' and text()= '").append(authorName).append("']");
175-
176172
return xpath.toString();
177173
}
178-
174+
179175
/**
180176
* Get the XPath of the critdates element.
181177
*

0 commit comments

Comments
 (0)