Skip to content

Commit e1dade8

Browse files
alexandrevryghembram-maegerman
authored andcommitted
134319: Renamed injectedAsHTML to escapeHTML
1 parent ab3118f commit e1dade8

File tree

6 files changed

+70
-70
lines changed

6 files changed

+70
-70
lines changed

src/app/core/breadcrumbs/dso-name.service.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class DSONameService {
2727
* With only two exceptions those solutions seem overkill for now.
2828
*/
2929
private readonly factories = {
30-
EPerson: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
31-
const firstName = dso.firstMetadataValue('eperson.firstname', undefined, injectedAsHTML);
32-
const lastName = dso.firstMetadataValue('eperson.lastname', undefined, injectedAsHTML);
30+
EPerson: (dso: DSpaceObject, escapeHTML?: boolean): string => {
31+
const firstName = dso.firstMetadataValue('eperson.firstname', undefined, escapeHTML);
32+
const lastName = dso.firstMetadataValue('eperson.lastname', undefined, escapeHTML);
3333
if (isEmpty(firstName) && isEmpty(lastName)) {
3434
return this.translateService.instant('dso.name.unnamed');
3535
} else if (isEmpty(firstName) || isEmpty(lastName)) {
@@ -38,33 +38,33 @@ export class DSONameService {
3838
return `${firstName} ${lastName}`;
3939
}
4040
},
41-
Person: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
42-
const familyName = dso.firstMetadataValue('person.familyName', undefined, injectedAsHTML);
43-
const givenName = dso.firstMetadataValue('person.givenName', undefined, injectedAsHTML);
41+
Person: (dso: DSpaceObject, escapeHTML?: boolean): string => {
42+
const familyName = dso.firstMetadataValue('person.familyName', undefined, escapeHTML);
43+
const givenName = dso.firstMetadataValue('person.givenName', undefined, escapeHTML);
4444
if (isEmpty(familyName) && isEmpty(givenName)) {
45-
return dso.firstMetadataValue('dc.title', undefined, injectedAsHTML) || this.translateService.instant('dso.name.unnamed');
45+
return dso.firstMetadataValue('dc.title', undefined, escapeHTML) || this.translateService.instant('dso.name.unnamed');
4646
} else if (isEmpty(familyName) || isEmpty(givenName)) {
4747
return familyName || givenName;
4848
} else {
4949
return `${familyName}, ${givenName}`;
5050
}
5151
},
52-
OrgUnit: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
53-
return dso.firstMetadataValue('organization.legalName', undefined, injectedAsHTML) || this.translateService.instant('dso.name.untitled');
52+
OrgUnit: (dso: DSpaceObject, escapeHTML?: boolean): string => {
53+
return dso.firstMetadataValue('organization.legalName', undefined, escapeHTML);
5454
},
55-
Default: (dso: DSpaceObject, injectedAsHTML?: boolean): string => {
55+
Default: (dso: DSpaceObject, escapeHTML?: boolean): string => {
5656
// If object doesn't have dc.title metadata use name property
57-
return dso.firstMetadataValue('dc.title', undefined, injectedAsHTML) || dso.name || this.translateService.instant('dso.name.untitled');
58-
}
57+
return dso.firstMetadataValue('dc.title', undefined, escapeHTML) || dso.name || this.translateService.instant('dso.name.untitled');
58+
},
5959
};
6060

6161
/**
6262
* Get the name for the given {@link DSpaceObject}
6363
*
6464
* @param dso The {@link DSpaceObject} you want a name for
65-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
65+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
6666
*/
67-
getName(dso: DSpaceObject | undefined, injectedAsHTML?: boolean): string {
67+
getName(dso: DSpaceObject | undefined, escapeHTML?: boolean): string {
6868
if (dso) {
6969
const types = dso.getRenderTypes();
7070
const match = types
@@ -73,10 +73,10 @@ export class DSONameService {
7373

7474
let name;
7575
if (hasValue(match)) {
76-
name = this.factories[match](dso, injectedAsHTML);
76+
name = this.factories[match](dso, escapeHTML);
7777
}
7878
if (isEmpty(name)) {
79-
name = this.factories.Default(dso, injectedAsHTML);
79+
name = this.factories.Default(dso, escapeHTML);
8080
}
8181
return name;
8282
} else {
@@ -89,28 +89,28 @@ export class DSONameService {
8989
*
9090
* @param object
9191
* @param dso
92-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
92+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
9393
*
9494
* @returns {string} html embedded hit highlight.
9595
*/
96-
getHitHighlights(object: any, dso: DSpaceObject, injectedAsHTML?: boolean): string {
96+
getHitHighlights(object: any, dso: DSpaceObject, escapeHTML?: boolean): string {
9797
const types = dso.getRenderTypes();
9898
const entityType = types
9999
.filter((type) => typeof type === 'string')
100100
.find((type: string) => (['Person', 'OrgUnit']).includes(type)) as string;
101101
if (entityType === 'Person') {
102-
const familyName = this.firstMetadataValue(object, dso, 'person.familyName', injectedAsHTML);
103-
const givenName = this.firstMetadataValue(object, dso, 'person.givenName', injectedAsHTML);
102+
const familyName = this.firstMetadataValue(object, dso, 'person.familyName', escapeHTML);
103+
const givenName = this.firstMetadataValue(object, dso, 'person.givenName', escapeHTML);
104104
if (isEmpty(familyName) && isEmpty(givenName)) {
105-
return this.firstMetadataValue(object, dso, 'dc.title', injectedAsHTML) || dso.name;
105+
return this.firstMetadataValue(object, dso, 'dc.title', escapeHTML) || dso.name;
106106
} else if (isEmpty(familyName) || isEmpty(givenName)) {
107107
return familyName || givenName;
108108
}
109109
return `${familyName}, ${givenName}`;
110110
} else if (entityType === 'OrgUnit') {
111-
return this.firstMetadataValue(object, dso, 'organization.legalName', injectedAsHTML) || this.translateService.instant('dso.name.untitled');
111+
return this.firstMetadataValue(object, dso, 'organization.legalName', escapeHTML);
112112
}
113-
return this.firstMetadataValue(object, dso, 'dc.title', injectedAsHTML) || dso.name || this.translateService.instant('dso.name.untitled');
113+
return this.firstMetadataValue(object, dso, 'dc.title', escapeHTML) || dso.name || this.translateService.instant('dso.name.untitled');
114114
}
115115

116116
/**
@@ -119,12 +119,12 @@ export class DSONameService {
119119
* @param object
120120
* @param dso
121121
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
122-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
122+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
123123
*
124124
* @returns {string} the first matching string value, or `undefined`.
125125
*/
126-
firstMetadataValue(object: any, dso: DSpaceObject, keyOrKeys: string | string[], injectedAsHTML?: boolean): string {
127-
return Metadata.firstValue(dso.metadata, keyOrKeys, object.hitHighlights, undefined, injectedAsHTML);
126+
firstMetadataValue(object: any, dso: DSpaceObject, keyOrKeys: string | string[], escapeHTML?: boolean): string {
127+
return Metadata.firstValue(dso.metadata, keyOrKeys, object.hitHighlights, undefined, escapeHTML);
128128
}
129129

130130
}

src/app/core/shared/dspace-object.model.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,47 +109,47 @@ export class DSpaceObject extends ListableObject implements CacheableObject {
109109
*
110110
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
111111
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
112-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
112+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
113113
* @returns {MetadataValue[]} the matching values or an empty array.
114114
*/
115-
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue[] {
116-
return Metadata.all(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
115+
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue[] {
116+
return Metadata.all(this.metadata, keyOrKeys, undefined, valueFilter, escapeHTML);
117117
}
118118

119119
/**
120120
* Like [[allMetadata]], but only returns string values.
121121
*
122122
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
123123
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
124-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
124+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
125125
* @returns {string[]} the matching string values or an empty array.
126126
*/
127-
allMetadataValues(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): string[] {
128-
return Metadata.allValues(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
127+
allMetadataValues(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, escapeHTML?: boolean): string[] {
128+
return Metadata.allValues(this.metadata, keyOrKeys, undefined, valueFilter, escapeHTML);
129129
}
130130

131131
/**
132132
* Gets the first matching MetadataValue object in this DSpaceObject, or `undefined`.
133133
*
134134
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
135135
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
136-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
136+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
137137
* @returns {MetadataValue} the first matching value, or `undefined`.
138138
*/
139-
firstMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue {
140-
return Metadata.first(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
139+
firstMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue {
140+
return Metadata.first(this.metadata, keyOrKeys, undefined, valueFilter, escapeHTML);
141141
}
142142

143143
/**
144144
* Like [[firstMetadata]], but only returns a string value, or `undefined`.
145145
*
146146
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
147147
* @param {MetadataValueFilter} valueFilter The value filter to use. If unspecified, no filtering will be done.
148-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
148+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
149149
* @returns {string} the first matching string value, or `undefined`.
150150
*/
151-
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, injectedAsHTML?: boolean): string {
152-
return Metadata.firstValue(this.metadata, keyOrKeys, undefined, valueFilter, injectedAsHTML);
151+
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter, escapeHTML?: boolean): string {
152+
return Metadata.firstValue(this.metadata, keyOrKeys, undefined, valueFilter, escapeHTML);
153153
}
154154

155155
/**

src/app/core/shared/metadata.utils.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export class Metadata {
3232
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see above.
3333
* @param hitHighlights The search hit highlights.
3434
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
35-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
35+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
3636
* @returns {MetadataValue[]} the matching values or an empty array.
3737
*/
38-
public static all(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue[] {
38+
public static all(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue[] {
3939
const matches: MetadataValue[] = [];
4040
if (isNotEmpty(hitHighlights)) {
4141
for (const mdKey of Metadata.resolveKeys(hitHighlights, keyOrKeys)) {
@@ -55,7 +55,7 @@ export class Metadata {
5555
if (metadata[mdKey]) {
5656
for (const candidate of metadata[mdKey]) {
5757
if (Metadata.valueMatches(candidate as MetadataValue, filter)) {
58-
if (injectedAsHTML) {
58+
if (escapeHTML) {
5959
matches.push(Object.assign(new MetadataValue(), candidate, {
6060
value: escape(candidate.value),
6161
}));
@@ -76,11 +76,11 @@ export class Metadata {
7676
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see above.
7777
* @param hitHighlights The search hit highlights.
7878
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
79-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
79+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
8080
* @returns {string[]} the matching string values or an empty array.
8181
*/
82-
public static allValues(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, injectedAsHTML?: boolean): string[] {
83-
return Metadata.all(metadata, keyOrKeys, hitHighlights, filter, injectedAsHTML).map((mdValue) => mdValue.value);
82+
public static allValues(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): string[] {
83+
return Metadata.all(metadata, keyOrKeys, hitHighlights, filter, escapeHTML).map((mdValue) => mdValue.value);
8484
}
8585

8686
/**
@@ -90,10 +90,10 @@ export class Metadata {
9090
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see above.
9191
* @param hitHighlights The search hit highlights.
9292
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
93-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
93+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
9494
* @returns {MetadataValue} the first matching value, or `undefined`.
9595
*/
96-
public static first(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, injectedAsHTML?: boolean): MetadataValue {
96+
public static first(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): MetadataValue {
9797
if (isNotEmpty(hitHighlights)) {
9898
for (const key of Metadata.resolveKeys(hitHighlights, keyOrKeys)) {
9999
const values: MetadataValue[] = hitHighlights[key] as MetadataValue[];
@@ -106,7 +106,7 @@ export class Metadata {
106106
const values: MetadataValue[] = metadata[key] as MetadataValue[];
107107
if (values) {
108108
const result: MetadataValue = values.find((value: MetadataValue) => Metadata.valueMatches(value, filter));
109-
if (injectedAsHTML) {
109+
if (escapeHTML) {
110110
return Object.assign(new MetadataValue(), result, {
111111
value: escape(result.value),
112112
});
@@ -123,11 +123,11 @@ export class Metadata {
123123
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see above.
124124
* @param hitHighlights The search hit highlights.
125125
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
126-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
126+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
127127
* @returns {string} the first matching string value, or `undefined`.
128128
*/
129-
public static firstValue(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, injectedAsHTML?: boolean): string {
130-
const value = Metadata.first(metadata, keyOrKeys, hitHighlights, filter, injectedAsHTML);
129+
public static firstValue(metadata: MetadataMapInterface, keyOrKeys: string | string[], hitHighlights?: MetadataMapInterface, filter?: MetadataValueFilter, escapeHTML?: boolean): string {
130+
const value = Metadata.first(metadata, keyOrKeys, hitHighlights, filter, escapeHTML);
131131
return isUndefined(value) ? undefined : value.value;
132132
}
133133

src/app/shared/object-detail/my-dspace-result-detail-element/search-result-detail-element.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ export class SearchResultDetailElementComponent<T extends SearchResult<K>, K ext
3333
* Gets all matching metadata string values from hitHighlights or dso metadata, preferring hitHighlights.
3434
*
3535
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
36-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
36+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
3737
* @returns {string[]} the matching string values or an empty array.
3838
*/
39-
allMetadataValues(keyOrKeys: string | string[], injectedAsHTML = true): string[] {
40-
return Metadata.allValues(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, injectedAsHTML);
39+
allMetadataValues(keyOrKeys: string | string[], escapeHTML = true): string[] {
40+
return Metadata.allValues(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, escapeHTML);
4141
}
4242

4343
/**
4444
* Gets the first matching metadata string value from hitHighlights or dso metadata, preferring hitHighlights.
4545
*
4646
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
47-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
47+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
4848
* @returns {string} the first matching string value, or `undefined`.
4949
*/
50-
firstMetadataValue(keyOrKeys: string | string[], injectedAsHTML = true): string {
51-
return Metadata.firstValue(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, injectedAsHTML);
50+
firstMetadataValue(keyOrKeys: string | string[], escapeHTML = true): string {
51+
return Metadata.firstValue(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, escapeHTML);
5252
}
5353
}

src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ export class SearchResultGridElementComponent<T extends SearchResult<K>, K exten
4747
* Gets all matching metadata string values from hitHighlights or dso metadata, preferring hitHighlights.
4848
*
4949
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
50-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
50+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
5151
* @returns {string[]} the matching string values or an empty array.
5252
*/
53-
allMetadataValues(keyOrKeys: string | string[], injectedAsHTML = true): string[] {
54-
return Metadata.allValues(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, injectedAsHTML);
53+
allMetadataValues(keyOrKeys: string | string[], escapeHTML = true): string[] {
54+
return Metadata.allValues(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, escapeHTML);
5555
}
5656

5757
/**
5858
* Gets the first matching metadata string value from hitHighlights or dso metadata, preferring hitHighlights.
5959
*
6060
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
61-
* @param injectedAsHTML Whether the HTML is used inside a `[innerHTML]` attribute
61+
* @param escapeHTML Whether the HTML is used inside a `[innerHTML]` attribute
6262
* @returns {string} the first matching string value, or `undefined`.
6363
*/
64-
firstMetadataValue(keyOrKeys: string | string[], injectedAsHTML = true): string {
65-
return Metadata.firstValue(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, injectedAsHTML);
64+
firstMetadataValue(keyOrKeys: string | string[], escapeHTML = true): string {
65+
return Metadata.firstValue(this.dso.metadata, keyOrKeys, this.object.hitHighlights, undefined, escapeHTML);
6666
}
6767

6868
private isCollapsed(): Observable<boolean> {

0 commit comments

Comments
 (0)