1 4 package info.magnolia.module.admininterface; 5 6 import javax.jcr.PathNotFoundException; 7 import javax.jcr.RepositoryException; 8 9 import org.apache.commons.lang.StringUtils; 10 11 import info.magnolia.cms.beans.config.ContentRepository; 12 import info.magnolia.cms.core.Content; 13 import info.magnolia.cms.gui.dialog.Dialog; 14 import info.magnolia.cms.gui.dialog.DialogControlImpl; 15 import info.magnolia.cms.gui.dialog.UUIDDialogControl; 16 import info.magnolia.cms.security.AccessDeniedException; 17 import info.magnolia.cms.util.ContentUtil; 18 19 20 26 public class UUIDSaveHandler extends SaveHandlerImpl implements DialogAwareSaveHandler { 27 28 31 private Dialog dialog; 32 33 public Dialog getDialog() { 34 return dialog; 35 } 36 37 public void setDialog(Dialog dialog) { 38 this.dialog = dialog; 39 } 40 41 44 protected void processString(Content node, String name, int type, int encoding, String [] values, String valueStr) 45 throws PathNotFoundException, RepositoryException, AccessDeniedException { 46 DialogControlImpl control = getControl(name); 47 if (control instanceof UUIDDialogControl) { 48 if (StringUtils.isNotEmpty(valueStr)) { 50 valueStr = getUUID(name, valueStr); 51 } 52 } 53 54 super.processString(node, name, type, encoding, values, valueStr); 55 } 56 57 60 protected void processMultiple(Content node, String name, int type, String [] values) throws RepositoryException, 61 PathNotFoundException, AccessDeniedException { 62 DialogControlImpl control = getControl(name); 63 64 if (control instanceof UUIDDialogControl) { 65 if (values != null && values.length != 0) { 66 String [] uuidValues = new String [values.length]; 67 for (int i = 0; i < values.length; i++) { 68 uuidValues[i] = getUUID(name, values[i]); 69 } 70 values = uuidValues; 71 } 72 } 73 super.processMultiple(node, name, type, values); 74 } 75 76 81 protected DialogControlImpl getControl(String name) { 82 Object control = this.getDialog().getSub(name); 83 if (control instanceof DialogControlImpl) { 84 return (DialogControlImpl) control; 85 } 86 return null; 87 } 88 89 95 private String getUUID(String name, String path) { 96 String repository = ((UUIDDialogControl)getControl(name)).getRepository(); 97 Content node = ContentUtil.getContent(repository, path); 98 if (node == null) { 99 return path; 100 } 101 return node.getUUID(); 102 } 103 104 } 105 | Popular Tags |