1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.List ; 50 51 import org.apache.turbine.RunData; 52 import org.apache.turbine.TemplateContext; 53 import org.apache.turbine.tool.IntakeTool; 54 import org.apache.fulcrum.intake.model.Group; 55 56 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 57 import org.tigris.scarab.om.Attribute; 58 import org.tigris.scarab.om.AttributeManager; 59 import org.tigris.scarab.om.AttributePeer; 60 import org.tigris.scarab.om.ScarabUser; 61 import org.tigris.scarab.util.ScarabConstants; 62 import org.tigris.scarab.services.cache.ScarabCache; 63 import org.tigris.scarab.tools.ScarabRequestTool; 64 import org.tigris.scarab.tools.ScarabLocalizationTool; 65 66 72 public class GlobalAttributes extends RequireLoginFirstAction 73 { 74 75 78 public void doCreatenew(RunData data, TemplateContext context) 79 throws Exception 80 { 81 String nextTemplate = data.getParameters().getString( 82 ScarabConstants.OTHER_TEMPLATE, "admin, GlobalAttributeEdit.vm"); 83 setTarget(data, nextTemplate); 84 85 ScarabRequestTool scarabR = getScarabRequestTool(context); 86 scarabR.setAttribute(AttributeManager.getInstance()); 87 } 88 89 public void doSave(RunData data, TemplateContext context) 90 throws Exception 91 { 92 IntakeTool intake = getIntakeTool(context); 93 List userAttrs = AttributePeer.getAttributes("user"); 94 for (int i=0; i<userAttrs.size(); i++) 95 { 96 Attribute attr = (Attribute)userAttrs.get(i); 97 Group attrGroup = intake.get("Attribute", attr.getQueryKey()); 98 if (attrGroup != null) 99 { 100 attrGroup.setProperties(attr); 101 attr.save(); 102 } 103 } 104 ScarabCache.clear(); 105 getScarabRequestTool(context).setConfirmMessage(getLocalizationTool(context).get(DEFAULT_MSG)); 106 } 107 108 public synchronized void doCopy(RunData data, TemplateContext context) 109 throws Exception 110 { 111 Object [] keys = data.getParameters().getKeys(); 112 String key = null; 113 String id = null; 114 Attribute attribute = null; 115 boolean didCopy = false; 116 for (int i =0; i<keys.length; i++) 117 { 118 key = keys[i].toString(); 119 if (key.startsWith("action_")) 120 { 121 id = key.substring(7); 122 attribute = AttributeManager.getInstance(new Integer (id)); 123 Attribute newAttribute = attribute 124 .copyAttribute((ScarabUser)data.getUser()); 125 newAttribute.save(); 126 didCopy = true; 127 } 128 } 129 ScarabLocalizationTool l10n = getLocalizationTool(context); 130 ScarabRequestTool scarabR = getScarabRequestTool(context); 131 if (didCopy) 132 { 133 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 134 } 135 else 136 { 137 scarabR.setInfoMessage(l10n.get(NO_CHANGES_MADE)); 138 } 139 } 140 } 141 | Popular Tags |