From version < 4.1 >
edited by Caleb James DeLisle
on 2012/02/13
To version < 5.1 >
edited by Caleb James DeLisle
on 2012/02/13
< >
Change comment: better input checking

Summary

Details

Page properties
Content
... ... @@ -37,13 +37,19 @@
37 37  {{groovy}}
38 38  classDocumentName = "Mailing.MailingMemberClass";
39 39  classDoc = xwiki.getDocument(classDocumentName).getDocument();
40 -classDoc.getxWikiClass().setCustomMapping("internal");
41 -xcontext.getContext().getWiki().saveDocument(classDoc, xcontext.getContext());
42 -classDoc = xwiki.getDocument(classDocumentName).getDocument();
43 -if ("internal".equals(classDoc.getxWikiClass().getCustomMapping())) {
44 - println("Success.");
40 +xml = classDoc.getxWikiClassXML();
41 +if (xml == null || "".equals(xml)) {
42 + println("The document [" + classDocumentName + "] doesn't seem to "
43 + + ((classDoc.isNew()) ? "exist." : "contain a class."));
45 45  } else {
46 - println("Failed to alter the custom mapping field.");
45 + classDoc.getxWikiClass().setCustomMapping("internal");
46 + xcontext.getContext().getWiki().saveDocument(classDoc, xcontext.getContext());
47 + classDoc = xwiki.getDocument(classDocumentName).getDocument();
48 + if ("internal".equals(classDoc.getxWikiClass().getCustomMapping())) {
49 + println("Success.");
50 + } else {
51 + println("Failed to alter the custom mapping field.");
52 + }
47 47  }
48 48  {{/groovy}}
49 49  {{/code}}

Get Connected