49
49
import com .rsicms .rsuite .utils .xml .TransformUtils ;
50
50
51
51
/**
52
- * A collection of static MO utility methods.
52
+ * A collection of MO utility methods.
53
53
*/
54
54
public class MOUtils {
55
55
56
56
/**
57
57
* @deprecated Instead, please use
58
58
* {@link #getInputStream(Transformer, ManagedObject, boolean, boolean, String)}.
59
59
*/
60
- public static InputStream getInputStream (ExecutionContext context , ManagedObject mo ,
60
+ public InputStream getInputStream (ExecutionContext context , ManagedObject mo ,
61
61
boolean includeXMLDeclaration , boolean includeDoctypeDeclaration , String encoding )
62
62
throws RSuiteException , UnsupportedEncodingException , TransformerException {
63
63
return getInputStream (context .getXmlApiManager ().getTransformer ((File ) null ), mo ,
@@ -77,7 +77,7 @@ public static InputStream getInputStream(ExecutionContext context, ManagedObject
77
77
* @throws UnsupportedEncodingException
78
78
* @throws TransformerException
79
79
*/
80
- public static InputStream getInputStream (Transformer transformer , ManagedObject mo ,
80
+ public InputStream getInputStream (Transformer transformer , ManagedObject mo ,
81
81
boolean includeXMLDeclaration , boolean includeDoctypeDeclaration , String encoding )
82
82
throws RSuiteException , UnsupportedEncodingException , TransformerException {
83
83
Element elem = mo .getElement ();
@@ -101,7 +101,7 @@ public static InputStream getInputStream(Transformer transformer, ManagedObject
101
101
* @throws RSuiteException
102
102
* @throws TransformerException
103
103
*/
104
- public static Element getElement (ManagedObjectService moService , User user , String id ,
104
+ public Element getElement (ManagedObjectService moService , User user , String id ,
105
105
Transformer transformer , boolean includeXMLDeclaration , boolean includeDoctypeDeclaration ,
106
106
String encoding ) throws RSuiteException , TransformerException {
107
107
return getElement (moService .getManagedObject (user , id ).getElement (), transformer ,
@@ -121,7 +121,7 @@ public static Element getElement(ManagedObjectService moService, User user, Stri
121
121
* @throws RSuiteException
122
122
* @throws TransformerException
123
123
*/
124
- public static Element getElement (ManagedObject mo , Transformer transformer ,
124
+ public Element getElement (ManagedObject mo , Transformer transformer ,
125
125
boolean includeXMLDeclaration , boolean includeDoctypeDeclaration , String encoding )
126
126
throws RSuiteException , TransformerException {
127
127
return getElement (mo .getElement (), transformer , includeXMLDeclaration ,
@@ -140,8 +140,8 @@ public static Element getElement(ManagedObject mo, Transformer transformer,
140
140
* @throws RSuiteException
141
141
* @throws TransformerException
142
142
*/
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 )
145
145
throws RSuiteException , TransformerException {
146
146
return DomUtils .getElement (transformer , elem , includeXMLDeclaration , includeDoctypeDeclaration ,
147
147
encoding );
@@ -154,7 +154,7 @@ public static Element getElement(Element elem, Transformer transformer,
154
154
* @return a display name for the MO.
155
155
* @throws RSuiteException
156
156
*/
157
- public static String getDisplayName (ManagedObject mo ) throws RSuiteException {
157
+ public String getDisplayName (ManagedObject mo ) throws RSuiteException {
158
158
return StringUtils .isBlank (mo .getDisplayName ()) ? mo .getLocalName () : mo .getDisplayName ();
159
159
}
160
160
@@ -165,7 +165,7 @@ public static String getDisplayName(ManagedObject mo) throws RSuiteException {
165
165
* @return the qualified element name.
166
166
* @throws RSuiteException Thrown if unable to determine the given MO's qualified element name.
167
167
*/
168
- public static String getQualifiedElementName (ManagedObject mo ) throws RSuiteException {
168
+ public String getQualifiedElementName (ManagedObject mo ) throws RSuiteException {
169
169
StringBuilder sb = new StringBuilder ();
170
170
if (StringUtils .isNotBlank (mo .getNamespaceURI ())) {
171
171
sb .append (mo .getNamespaceURI ()).append (":" );
@@ -179,7 +179,7 @@ public static String getQualifiedElementName(ManagedObject mo) throws RSuiteExce
179
179
* @param mo
180
180
* @return a display name for the MO, or an empty string if an exception is encountered.
181
181
*/
182
- public static String getDisplayNameQuietly (ManagedObject mo ) {
182
+ public String getDisplayNameQuietly (ManagedObject mo ) {
183
183
try {
184
184
return getDisplayName (mo );
185
185
} catch (Exception e ) {
@@ -197,7 +197,7 @@ public static String getDisplayNameQuietly(ManagedObject mo) {
197
197
* assembly reference, or CANode.
198
198
* @throws RSuiteException
199
199
*/
200
- public static ManagedObject getManagedObject (ExecutionContext context , User user ,
200
+ public ManagedObject getManagedObject (ExecutionContext context , User user ,
201
201
ContentAssemblyItem caItem ) throws RSuiteException {
202
202
ManagedObject mo = null ;
203
203
if (caItem instanceof ManagedObject ) {
@@ -219,8 +219,8 @@ public static ManagedObject getManagedObject(ExecutionContext context, User user
219
219
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
220
220
* @throws IOException Thrown if unable to get bytes from given file.
221
221
*/
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 {
224
224
FileInputStream fis = new FileInputStream (content );
225
225
try {
226
226
return getObjectSource (context , filename , fis , encoding );
@@ -239,7 +239,7 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
239
239
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
240
240
* @throws IOException Thrown if unable to get bytes from input stream.
241
241
*/
242
- public static ObjectSource getObjectSource (ExecutionContext context , String filename ,
242
+ public ObjectSource getObjectSource (ExecutionContext context , String filename ,
243
243
InputStream content , String encoding ) throws IOException {
244
244
return getObjectSource (context , filename , IOUtils .toByteArray (content ), encoding );
245
245
}
@@ -254,8 +254,8 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
254
254
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
255
255
* @throws IOException Thrown if unable to get bytes from given file.
256
256
*/
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 {
259
259
return getObjectSource (context , filename ,
260
260
IOUtils .toByteArray (new StringReader (content ), encoding ), encoding );
261
261
}
@@ -270,8 +270,8 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
270
270
* @return Either an instance of <code>XmlObjectSource</code> or <code>NonXmlObjectSource</code>.
271
271
* @throws IOException Thrown if unable to get bytes from given file.
272
272
*/
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 {
275
275
if (context .getRSuiteServerConfiguration ()
276
276
.isTreatAsXmlFileExtension (FilenameUtils .getExtension (filename ))) {
277
277
return new XmlObjectSource (content , encoding );
@@ -289,7 +289,7 @@ public static ObjectSource getObjectSource(ExecutionContext context, String file
289
289
* @param advisor A local MO advisor to use. May be null.
290
290
* @return The insert options for either a new XML MO or non-XML MO.
291
291
*/
292
- public static ObjectInsertOptions getObjectInsertOptions (ExecutionContext context ,
292
+ public ObjectInsertOptions getObjectInsertOptions (ExecutionContext context ,
293
293
ObjectSource objectSource , String objectName , ManagedObjectAdvisor advisor ) {
294
294
295
295
// In 4.1.12 an additional constructor was added to ObjectInsertOptions
@@ -329,8 +329,8 @@ public static ObjectInsertOptions getObjectInsertOptions(ExecutionContext contex
329
329
* @param advisor
330
330
* @return The update options for either an existing XML MO or non-XML MO.
331
331
*/
332
- public static ObjectUpdateOptions getObjectUpdateOptions (ObjectSource objectSource ,
333
- String objectName , ManagedObjectAdvisor advisor ) {
332
+ public ObjectUpdateOptions getObjectUpdateOptions (ObjectSource objectSource , String objectName ,
333
+ ManagedObjectAdvisor advisor ) {
334
334
ObjectUpdateOptions options = new ObjectUpdateOptions ();
335
335
options .setExternalFileName (objectName );
336
336
options .setDisplayName (objectName );
@@ -350,7 +350,7 @@ public static ObjectUpdateOptions getObjectUpdateOptions(ObjectSource objectSour
350
350
* sub MO is checked out.
351
351
* @throws RSuiteException
352
352
*/
353
- public static boolean isCheckedOut (ManagedObjectService moService , User user , String id ,
353
+ public boolean isCheckedOut (ManagedObjectService moService , User user , String id ,
354
354
boolean includeSubMos ) throws RSuiteException {
355
355
if (moService .isCheckedOut (user , id )) {
356
356
return true ;
@@ -378,8 +378,7 @@ public static boolean isCheckedOut(ManagedObjectService moService, User user, St
378
378
* specified user.
379
379
* @throws RSuiteException
380
380
*/
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 {
383
382
ManagedObjectService moService = context .getManagedObjectService ();
384
383
if (!moService .isCheckedOut (user , id )) {
385
384
moService .checkOut (user , id );
@@ -405,7 +404,7 @@ public static boolean checkout(ExecutionContext context, User user, String id)
405
404
* or null if there is only one version of the MO.
406
405
* @throws RSuiteException
407
406
*/
408
- public static VersionSpecifier getPreviousVersionSpecifier (ExecutionContext context , User user ,
407
+ public VersionSpecifier getPreviousVersionSpecifier (ExecutionContext context , User user ,
409
408
String id ) throws RSuiteException {
410
409
411
410
VersionHistory vh = context .getManagedObjectService ().getVersionHistory (user , id );
@@ -432,7 +431,7 @@ public static VersionSpecifier getPreviousVersionSpecifier(ExecutionContext cont
432
431
* @param metaDataItems
433
432
* @throws RSuiteException
434
433
*/
435
- public static void setMetadataEntries (User user , ManagedObjectService moService , String moid ,
434
+ public void setMetadataEntries (User user , ManagedObjectService moService , String moid ,
436
435
List <MetaDataItem > metaDataItems ) throws RSuiteException {
437
436
moService .setMetaDataEntries (user , moid , metaDataItems );
438
437
}
@@ -450,7 +449,7 @@ public static void setMetadataEntries(User user, ManagedObjectService moService,
450
449
* @param lmdName
451
450
* @throws RSuiteException
452
451
*/
453
- public static void deleteMetadataEntries (User user , ManagedObjectService moService , String moid ,
452
+ public void deleteMetadataEntries (User user , ManagedObjectService moService , String moid ,
454
453
String lmdName ) throws RSuiteException {
455
454
if (StringUtils .isNotBlank (moid ) && StringUtils .isNotBlank (lmdName )) {
456
455
ManagedObject mo = moService .getManagedObject (user , moid );
@@ -477,9 +476,8 @@ public static void deleteMetadataEntries(User user, ManagedObjectService moServi
477
476
* @throws IOException
478
477
* @throws RSuiteException
479
478
*/
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 {
483
481
return load (context , user , filename , getObjectSource (context , filename , is , encoding ),
484
482
moAdvisor );
485
483
}
@@ -495,7 +493,7 @@ public static ManagedObject load(ExecutionContext context, User user, String fil
495
493
* @return The <code>ManagedObject</code> loaded in RSuite.
496
494
* @throws RSuiteException
497
495
*/
498
- public static ManagedObject load (ExecutionContext context , User user , String filename ,
496
+ public ManagedObject load (ExecutionContext context , User user , String filename ,
499
497
ObjectSource objectSource , ManagedObjectAdvisor moAdvisor ) throws RSuiteException {
500
498
return context .getManagedObjectService ().load (user , objectSource ,
501
499
getObjectInsertOptions (context , objectSource , filename , moAdvisor ));
@@ -509,7 +507,7 @@ public static ManagedObject load(ExecutionContext context, User user, String fil
509
507
* @return True if the MO is an XML MO with the specified QName.
510
508
* @throws RSuiteException
511
509
*/
512
- public static boolean hasMatchingQName (ManagedObject mo , QName qname ) throws RSuiteException {
510
+ public boolean hasMatchingQName (ManagedObject mo , QName qname ) throws RSuiteException {
513
511
return (mo != null && !mo .isNonXml () && mo .getLocalName ().equals (qname .getLocalPart ()) && (
514
512
// If both are blank, they're both in the default namespace
515
513
(StringUtils .isBlank (mo .getNamespaceURI ()) && StringUtils .isBlank (qname .getNamespaceURI ()))
@@ -542,10 +540,9 @@ public static boolean hasMatchingQName(ManagedObject mo, QName qname) throws RSu
542
540
* @throws SAXException
543
541
* @throws IOException
544
542
*/
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 )
549
546
throws RSuiteException , URISyntaxException , TransformerException , SAXException , IOException {
550
547
User user = session .getUser ();
551
548
ManagedObjectService moService = context .getManagedObjectService ();
@@ -592,7 +589,7 @@ public static void applyTransformAndUpdate(ExecutionContext context, Session ses
592
589
* including non-XML MOs. Not sure about references.
593
590
* @throws RSuiteException
594
591
*/
595
- public static boolean isSubMo (ManagedObjectService moService , User user , ManagedObject mo )
592
+ public boolean isSubMo (ManagedObjectService moService , User user , ManagedObject mo )
596
593
throws RSuiteException {
597
594
return !mo .getId ().equals (moService .getRootManagedObjectId (user , mo .getId ()));
598
595
}
@@ -606,7 +603,7 @@ public static boolean isSubMo(ManagedObjectService moService, User user, Managed
606
603
* @return True if not a sub-MO; else false.
607
604
* @throws RSuiteException
608
605
*/
609
- public static boolean isNotSubMo (ManagedObjectService moService , User user , ManagedObject mo )
606
+ public boolean isNotSubMo (ManagedObjectService moService , User user , ManagedObject mo )
610
607
throws RSuiteException {
611
608
return !isSubMo (moService , user , mo );
612
609
}
@@ -619,7 +616,7 @@ public static boolean isNotSubMo(ManagedObjectService moService, User user, Mana
619
616
* @param mo
620
617
* @throws RSuiteException
621
618
*/
622
- public static void throwIfSubMo (ManagedObjectService moService , User user , ManagedObject mo )
619
+ public void throwIfSubMo (ManagedObjectService moService , User user , ManagedObject mo )
623
620
throws RSuiteException {
624
621
if (isSubMo (moService , user , mo )) {
625
622
throw new RSuiteException (RSuiteException .ERROR_PARAM_INVALID ,
@@ -636,7 +633,7 @@ public static void throwIfSubMo(ManagedObjectService moService, User user, Manag
636
633
* @param mo
637
634
* @throws RSuiteException
638
635
*/
639
- public static void throwIfNotSubMo (ManagedObjectService moService , User user , ManagedObject mo )
636
+ public void throwIfNotSubMo (ManagedObjectService moService , User user , ManagedObject mo )
640
637
throws RSuiteException {
641
638
if (isNotSubMo (moService , user , mo )) {
642
639
throw new RSuiteException (RSuiteException .ERROR_PARAM_INVALID ,
@@ -656,8 +653,8 @@ public static void throwIfNotSubMo(ManagedObjectService moService, User user, Ma
656
653
* @return A sibling sub-MO or, when one doesn't exist, null.
657
654
* @throws RSuiteException Thrown if the given MO is not a sub-MO.
658
655
*/
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 {
661
658
throwIfNotSubMo (moService , user , mo );
662
659
int increment = 20 ;
663
660
int start = 0 ;
@@ -701,7 +698,7 @@ public static ManagedObject getSiblingSubMo(ManagedObjectService moService, User
701
698
* @return The sub-MO preceding the given one, or null when there isn't one.
702
699
* @throws RSuiteException Thrown when not given a sub-MO.
703
700
*/
704
- public static ManagedObject getPrecedingSubMo (ManagedObjectService moService , User user ,
701
+ public ManagedObject getPrecedingSubMo (ManagedObjectService moService , User user ,
705
702
ManagedObject mo ) throws RSuiteException {
706
703
return getSiblingSubMo (moService , user , mo , true );
707
704
}
@@ -715,7 +712,7 @@ public static ManagedObject getPrecedingSubMo(ManagedObjectService moService, Us
715
712
* @return The sub-MO following the given one, or null when there isn't one.
716
713
* @throws RSuiteException Thrown when not given a sub-MO.
717
714
*/
718
- public static ManagedObject getFollowingSubMo (ManagedObjectService moService , User user ,
715
+ public ManagedObject getFollowingSubMo (ManagedObjectService moService , User user ,
719
716
ManagedObject mo ) throws RSuiteException {
720
717
return getSiblingSubMo (moService , user , mo , false );
721
718
}
@@ -740,10 +737,9 @@ public static ManagedObject getFollowingSubMo(ManagedObjectService moService, Us
740
737
* @throws RSuiteException
741
738
* @throws TransformerException
742
739
*/
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 {
747
743
748
744
if (newNodes != null && newNodes .size () > 0 ) {
749
745
// Require the ancestor MO be checked out by the requesting user.
0 commit comments