Skip to content

Commit 4b0a9f9

Browse files
committed
v1.0.1: All MOUtils methods are now instance methods, instead of static methods. This was done to make it easier to write unit tests for methods that use MOUtils.
1 parent 57557d5 commit 4b0a9f9

File tree

3 files changed

+48
-50
lines changed

3 files changed

+48
-50
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
projectVersion=1.0.0
2+
projectVersion=1.0.1

src/main/java/com/rsicms/rsuite/utils/mo/MOUtils.java

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
import com.rsicms.rsuite.utils.xml.TransformUtils;
5050

5151
/**
52-
* A collection of static MO utility methods.
52+
* A collection of MO utility methods.
5353
*/
5454
public class MOUtils {
5555

5656
/**
5757
* @deprecated Instead, please use
5858
* {@link #getInputStream(Transformer, ManagedObject, boolean, boolean, String)}.
5959
*/
60-
public static InputStream getInputStream(ExecutionContext context, ManagedObject mo,
60+
public InputStream getInputStream(ExecutionContext context, ManagedObject mo,
6161
boolean includeXMLDeclaration, boolean includeDoctypeDeclaration, String encoding)
6262
throws RSuiteException, UnsupportedEncodingException, TransformerException {
6363
return getInputStream(context.getXmlApiManager().getTransformer((File) null), mo,
@@ -77,7 +77,7 @@ public static InputStream getInputStream(ExecutionContext context, ManagedObject
7777
* @throws UnsupportedEncodingException
7878
* @throws TransformerException
7979
*/
80-
public static InputStream getInputStream(Transformer transformer, ManagedObject mo,
80+
public InputStream getInputStream(Transformer transformer, ManagedObject mo,
8181
boolean includeXMLDeclaration, boolean includeDoctypeDeclaration, String encoding)
8282
throws RSuiteException, UnsupportedEncodingException, TransformerException {
8383
Element elem = mo.getElement();
@@ -101,7 +101,7 @@ public static InputStream getInputStream(Transformer transformer, ManagedObject
101101
* @throws RSuiteException
102102
* @throws TransformerException
103103
*/
104-
public static Element getElement(ManagedObjectService moService, User user, String id,
104+
public Element getElement(ManagedObjectService moService, User user, String id,
105105
Transformer transformer, boolean includeXMLDeclaration, boolean includeDoctypeDeclaration,
106106
String encoding) throws RSuiteException, TransformerException {
107107
return getElement(moService.getManagedObject(user, id).getElement(), transformer,
@@ -121,7 +121,7 @@ public static Element getElement(ManagedObjectService moService, User user, Stri
121121
* @throws RSuiteException
122122
* @throws TransformerException
123123
*/
124-
public static Element getElement(ManagedObject mo, Transformer transformer,
124+
public Element getElement(ManagedObject mo, Transformer transformer,
125125
boolean includeXMLDeclaration, boolean includeDoctypeDeclaration, String encoding)
126126
throws RSuiteException, TransformerException {
127127
return getElement(mo.getElement(), transformer, includeXMLDeclaration,
@@ -140,8 +140,8 @@ public static Element getElement(ManagedObject mo, Transformer transformer,
140140
* @throws RSuiteException
141141
* @throws TransformerException
142142
*/
143-
public static Element getElement(Element elem, Transformer transformer,
144-
boolean includeXMLDeclaration, boolean includeDoctypeDeclaration, String encoding)
143+
public Element getElement(Element elem, Transformer transformer, boolean includeXMLDeclaration,
144+
boolean includeDoctypeDeclaration, String encoding)
145145
throws RSuiteException, TransformerException {
146146
return DomUtils.getElement(transformer, elem, includeXMLDeclaration, includeDoctypeDeclaration,
147147
encoding);
@@ -154,7 +154,7 @@ public static Element getElement(Element elem, Transformer transformer,
154154
* @return a display name for the MO.
155155
* @throws RSuiteException
156156
*/
157-
public static String getDisplayName(ManagedObject mo) throws RSuiteException {
157+
public String getDisplayName(ManagedObject mo) throws RSuiteException {
158158
return StringUtils.isBlank(mo.getDisplayName()) ? mo.getLocalName() : mo.getDisplayName();
159159
}
160160

@@ -165,7 +165,7 @@ public static String getDisplayName(ManagedObject mo) throws RSuiteException {
165165
* @return the qualified element name.
166166
* @throws RSuiteException Thrown if unable to determine the given MO's qualified element name.
167167
*/
168-
public static String getQualifiedElementName(ManagedObject mo) throws RSuiteException {
168+
public String getQualifiedElementName(ManagedObject mo) throws RSuiteException {
169169
StringBuilder sb = new StringBuilder();
170170
if (StringUtils.isNotBlank(mo.getNamespaceURI())) {
171171
sb.append(mo.getNamespaceURI()).append(":");
@@ -179,7 +179,7 @@ public static String getQualifiedElementName(ManagedObject mo) throws RSuiteExce
179179
* @param mo
180180
* @return a display name for the MO, or an empty string if an exception is encountered.
181181
*/
182-
public static String getDisplayNameQuietly(ManagedObject mo) {
182+
public String getDisplayNameQuietly(ManagedObject mo) {
183183
try {
184184
return getDisplayName(mo);
185185
} catch (Exception e) {
@@ -197,7 +197,7 @@ public static String getDisplayNameQuietly(ManagedObject mo) {
197197
* assembly reference, or CANode.
198198
* @throws RSuiteException
199199
*/
200-
public static ManagedObject getManagedObject(ExecutionContext context, User user,
200+
public ManagedObject getManagedObject(ExecutionContext context, User user,
201201
ContentAssemblyItem caItem) throws RSuiteException {
202202
ManagedObject mo = null;
203203
if (caItem instanceof ManagedObject) {
@@ -219,8 +219,8 @@ public static ManagedObject getManagedObject(ExecutionContext context, User user
219219
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
220220
* @throws IOException Thrown if unable to get bytes from given file.
221221
*/
222-
public static ObjectSource getObjectSource(ExecutionContext context, String filename,
223-
File content, String encoding) throws IOException {
222+
public ObjectSource getObjectSource(ExecutionContext context, String filename, File content,
223+
String encoding) throws IOException {
224224
FileInputStream fis = new FileInputStream(content);
225225
try {
226226
return getObjectSource(context, filename, fis, encoding);
@@ -239,7 +239,7 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
239239
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
240240
* @throws IOException Thrown if unable to get bytes from input stream.
241241
*/
242-
public static ObjectSource getObjectSource(ExecutionContext context, String filename,
242+
public ObjectSource getObjectSource(ExecutionContext context, String filename,
243243
InputStream content, String encoding) throws IOException {
244244
return getObjectSource(context, filename, IOUtils.toByteArray(content), encoding);
245245
}
@@ -254,8 +254,8 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
254254
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
255255
* @throws IOException Thrown if unable to get bytes from given file.
256256
*/
257-
public static ObjectSource getObjectSource(ExecutionContext context, String filename,
258-
String content, String encoding) throws IOException {
257+
public ObjectSource getObjectSource(ExecutionContext context, String filename, String content,
258+
String encoding) throws IOException {
259259
return getObjectSource(context, filename,
260260
IOUtils.toByteArray(new StringReader(content), encoding), encoding);
261261
}
@@ -270,8 +270,8 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
270270
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
271271
* @throws IOException Thrown if unable to get bytes from given file.
272272
*/
273-
public static ObjectSource getObjectSource(ExecutionContext context, String filename,
274-
byte[] content, String encoding) throws IOException {
273+
public ObjectSource getObjectSource(ExecutionContext context, String filename, byte[] content,
274+
String encoding) throws IOException {
275275
if (context.getRSuiteServerConfiguration()
276276
.isTreatAsXmlFileExtension(FilenameUtils.getExtension(filename))) {
277277
return new XmlObjectSource(content, encoding);
@@ -289,7 +289,7 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
289289
* @param advisor A local MO advisor to use. May be null.
290290
* @return The insert options for either a new XML MO or non-XML MO.
291291
*/
292-
public static ObjectInsertOptions getObjectInsertOptions(ExecutionContext context,
292+
public ObjectInsertOptions getObjectInsertOptions(ExecutionContext context,
293293
ObjectSource objectSource, String objectName, ManagedObjectAdvisor advisor) {
294294

295295
// In 4.1.12 an additional constructor was added to ObjectInsertOptions
@@ -329,8 +329,8 @@ public static ObjectInsertOptions getObjectInsertOptions(ExecutionContext contex
329329
* @param advisor
330330
* @return The update options for either an existing XML MO or non-XML MO.
331331
*/
332-
public static ObjectUpdateOptions getObjectUpdateOptions(ObjectSource objectSource,
333-
String objectName, ManagedObjectAdvisor advisor) {
332+
public ObjectUpdateOptions getObjectUpdateOptions(ObjectSource objectSource, String objectName,
333+
ManagedObjectAdvisor advisor) {
334334
ObjectUpdateOptions options = new ObjectUpdateOptions();
335335
options.setExternalFileName(objectName);
336336
options.setDisplayName(objectName);
@@ -350,7 +350,7 @@ public static ObjectUpdateOptions getObjectUpdateOptions(ObjectSource objectSour
350350
* sub MO is checked out.
351351
* @throws RSuiteException
352352
*/
353-
public static boolean isCheckedOut(ManagedObjectService moService, User user, String id,
353+
public boolean isCheckedOut(ManagedObjectService moService, User user, String id,
354354
boolean includeSubMos) throws RSuiteException {
355355
if (moService.isCheckedOut(user, id)) {
356356
return true;
@@ -378,8 +378,7 @@ public static boolean isCheckedOut(ManagedObjectService moService, User user, St
378378
* specified user.
379379
* @throws RSuiteException
380380
*/
381-
public static boolean checkout(ExecutionContext context, User user, String id)
382-
throws RSuiteException {
381+
public boolean checkout(ExecutionContext context, User user, String id) throws RSuiteException {
383382
ManagedObjectService moService = context.getManagedObjectService();
384383
if (!moService.isCheckedOut(user, id)) {
385384
moService.checkOut(user, id);
@@ -405,7 +404,7 @@ public static boolean checkout(ExecutionContext context, User user, String id)
405404
* or null if there is only one version of the MO.
406405
* @throws RSuiteException
407406
*/
408-
public static VersionSpecifier getPreviousVersionSpecifier(ExecutionContext context, User user,
407+
public VersionSpecifier getPreviousVersionSpecifier(ExecutionContext context, User user,
409408
String id) throws RSuiteException {
410409

411410
VersionHistory vh = context.getManagedObjectService().getVersionHistory(user, id);
@@ -432,7 +431,7 @@ public static VersionSpecifier getPreviousVersionSpecifier(ExecutionContext cont
432431
* @param metaDataItems
433432
* @throws RSuiteException
434433
*/
435-
public static void setMetadataEntries(User user, ManagedObjectService moService, String moid,
434+
public void setMetadataEntries(User user, ManagedObjectService moService, String moid,
436435
List<MetaDataItem> metaDataItems) throws RSuiteException {
437436
moService.setMetaDataEntries(user, moid, metaDataItems);
438437
}
@@ -450,7 +449,7 @@ public static void setMetadataEntries(User user, ManagedObjectService moService,
450449
* @param lmdName
451450
* @throws RSuiteException
452451
*/
453-
public static void deleteMetadataEntries(User user, ManagedObjectService moService, String moid,
452+
public void deleteMetadataEntries(User user, ManagedObjectService moService, String moid,
454453
String lmdName) throws RSuiteException {
455454
if (StringUtils.isNotBlank(moid) && StringUtils.isNotBlank(lmdName)) {
456455
ManagedObject mo = moService.getManagedObject(user, moid);
@@ -477,9 +476,8 @@ public static void deleteMetadataEntries(User user, ManagedObjectService moServi
477476
* @throws IOException
478477
* @throws RSuiteException
479478
*/
480-
public static ManagedObject load(ExecutionContext context, User user, String filename,
481-
InputStream is, String encoding, ManagedObjectAdvisor moAdvisor)
482-
throws IOException, RSuiteException {
479+
public ManagedObject load(ExecutionContext context, User user, String filename, InputStream is,
480+
String encoding, ManagedObjectAdvisor moAdvisor) throws IOException, RSuiteException {
483481
return load(context, user, filename, getObjectSource(context, filename, is, encoding),
484482
moAdvisor);
485483
}
@@ -495,7 +493,7 @@ public static ManagedObject load(ExecutionContext context, User user, String fil
495493
* @return The <code>ManagedObject</code> loaded in RSuite.
496494
* @throws RSuiteException
497495
*/
498-
public static ManagedObject load(ExecutionContext context, User user, String filename,
496+
public ManagedObject load(ExecutionContext context, User user, String filename,
499497
ObjectSource objectSource, ManagedObjectAdvisor moAdvisor) throws RSuiteException {
500498
return context.getManagedObjectService().load(user, objectSource,
501499
getObjectInsertOptions(context, objectSource, filename, moAdvisor));
@@ -509,7 +507,7 @@ public static ManagedObject load(ExecutionContext context, User user, String fil
509507
* @return True if the MO is an XML MO with the specified QName.
510508
* @throws RSuiteException
511509
*/
512-
public static boolean hasMatchingQName(ManagedObject mo, QName qname) throws RSuiteException {
510+
public boolean hasMatchingQName(ManagedObject mo, QName qname) throws RSuiteException {
513511
return (mo != null && !mo.isNonXml() && mo.getLocalName().equals(qname.getLocalPart()) && (
514512
// If both are blank, they're both in the default namespace
515513
(StringUtils.isBlank(mo.getNamespaceURI()) && StringUtils.isBlank(qname.getNamespaceURI()))
@@ -542,10 +540,9 @@ public static boolean hasMatchingQName(ManagedObject mo, QName qname) throws RSu
542540
* @throws SAXException
543541
* @throws IOException
544542
*/
545-
public static void applyTransformAndUpdate(ExecutionContext context, Session session,
546-
ManagedObject mo, URI xslUri, Map<String, Object> xslParams,
547-
boolean includeStandardRSuiteXslParams, String baseRSuiteUrl, String resultEncoding,
548-
String versionNote)
543+
public void applyTransformAndUpdate(ExecutionContext context, Session session, ManagedObject mo,
544+
URI xslUri, Map<String, Object> xslParams, boolean includeStandardRSuiteXslParams,
545+
String baseRSuiteUrl, String resultEncoding, String versionNote)
549546
throws RSuiteException, URISyntaxException, TransformerException, SAXException, IOException {
550547
User user = session.getUser();
551548
ManagedObjectService moService = context.getManagedObjectService();
@@ -592,7 +589,7 @@ public static void applyTransformAndUpdate(ExecutionContext context, Session ses
592589
* including non-XML MOs. Not sure about references.
593590
* @throws RSuiteException
594591
*/
595-
public static boolean isSubMo(ManagedObjectService moService, User user, ManagedObject mo)
592+
public boolean isSubMo(ManagedObjectService moService, User user, ManagedObject mo)
596593
throws RSuiteException {
597594
return !mo.getId().equals(moService.getRootManagedObjectId(user, mo.getId()));
598595
}
@@ -606,7 +603,7 @@ public static boolean isSubMo(ManagedObjectService moService, User user, Managed
606603
* @return True if not a sub-MO; else false.
607604
* @throws RSuiteException
608605
*/
609-
public static boolean isNotSubMo(ManagedObjectService moService, User user, ManagedObject mo)
606+
public boolean isNotSubMo(ManagedObjectService moService, User user, ManagedObject mo)
610607
throws RSuiteException {
611608
return !isSubMo(moService, user, mo);
612609
}
@@ -619,7 +616,7 @@ public static boolean isNotSubMo(ManagedObjectService moService, User user, Mana
619616
* @param mo
620617
* @throws RSuiteException
621618
*/
622-
public static void throwIfSubMo(ManagedObjectService moService, User user, ManagedObject mo)
619+
public void throwIfSubMo(ManagedObjectService moService, User user, ManagedObject mo)
623620
throws RSuiteException {
624621
if (isSubMo(moService, user, mo)) {
625622
throw new RSuiteException(RSuiteException.ERROR_PARAM_INVALID,
@@ -636,7 +633,7 @@ public static void throwIfSubMo(ManagedObjectService moService, User user, Manag
636633
* @param mo
637634
* @throws RSuiteException
638635
*/
639-
public static void throwIfNotSubMo(ManagedObjectService moService, User user, ManagedObject mo)
636+
public void throwIfNotSubMo(ManagedObjectService moService, User user, ManagedObject mo)
640637
throws RSuiteException {
641638
if (isNotSubMo(moService, user, mo)) {
642639
throw new RSuiteException(RSuiteException.ERROR_PARAM_INVALID,
@@ -656,8 +653,8 @@ public static void throwIfNotSubMo(ManagedObjectService moService, User user, Ma
656653
* @return A sibling sub-MO or, when one doesn't exist, null.
657654
* @throws RSuiteException Thrown if the given MO is not a sub-MO.
658655
*/
659-
public static ManagedObject getSiblingSubMo(ManagedObjectService moService, User user,
660-
ManagedObject mo, boolean preceding) throws RSuiteException {
656+
public ManagedObject getSiblingSubMo(ManagedObjectService moService, User user, ManagedObject mo,
657+
boolean preceding) throws RSuiteException {
661658
throwIfNotSubMo(moService, user, mo);
662659
int increment = 20;
663660
int start = 0;
@@ -701,7 +698,7 @@ public static ManagedObject getSiblingSubMo(ManagedObjectService moService, User
701698
* @return The sub-MO preceding the given one, or null when there isn't one.
702699
* @throws RSuiteException Thrown when not given a sub-MO.
703700
*/
704-
public static ManagedObject getPrecedingSubMo(ManagedObjectService moService, User user,
701+
public ManagedObject getPrecedingSubMo(ManagedObjectService moService, User user,
705702
ManagedObject mo) throws RSuiteException {
706703
return getSiblingSubMo(moService, user, mo, true);
707704
}
@@ -715,7 +712,7 @@ public static ManagedObject getPrecedingSubMo(ManagedObjectService moService, Us
715712
* @return The sub-MO following the given one, or null when there isn't one.
716713
* @throws RSuiteException Thrown when not given a sub-MO.
717714
*/
718-
public static ManagedObject getFollowingSubMo(ManagedObjectService moService, User user,
715+
public ManagedObject getFollowingSubMo(ManagedObjectService moService, User user,
719716
ManagedObject mo) throws RSuiteException {
720717
return getSiblingSubMo(moService, user, mo, false);
721718
}
@@ -740,10 +737,9 @@ public static ManagedObject getFollowingSubMo(ManagedObjectService moService, Us
740737
* @throws RSuiteException
741738
* @throws TransformerException
742739
*/
743-
public static void addNodesIntoExistingMo(ManagedObjectService moService, User user,
744-
String ancestorMoId, String adjacentNodeXPath, boolean insertBefore, XPathEvaluator eval,
745-
List<Node> newNodes, boolean stripDoctype, Transformer trans)
746-
throws RSuiteException, TransformerException {
740+
public void addNodesIntoExistingMo(ManagedObjectService moService, User user, String ancestorMoId,
741+
String adjacentNodeXPath, boolean insertBefore, XPathEvaluator eval, List<Node> newNodes,
742+
boolean stripDoctype, Transformer trans) throws RSuiteException, TransformerException {
747743

748744
if (newNodes != null && newNodes.size() > 0) {
749745
// Require the ancestor MO be checked out by the requesting user.

src/main/java/com/rsicms/rsuite/utils/mo/qualifiers/QNameManagedObjectQualifier.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
public class QNameManagedObjectQualifier implements ManagedObjectQualifier {
1313

1414
private QName qname;
15+
private MOUtils moUtils;
1516

1617
public QNameManagedObjectQualifier(QName qname) {
1718
this.qname = qname;
19+
this.moUtils = new MOUtils();
1820
}
1921

2022
@Override
2123
public boolean accept(ManagedObject mo) throws RSuiteException {
22-
return MOUtils.hasMatchingQName(mo, qname);
24+
return moUtils.hasMatchingQName(mo, qname);
2325
}
2426

2527
}

0 commit comments

Comments
 (0)