use of jodd.madvoc.ActionConfigSet in project jodd by oblac.
the class ActionsManager method registerAction.
/**
* Registers manually created {@link ActionConfig action configurations}.
* Optionally, if action path with the same name already exist,
* exception will be thrown.
*/
public ActionConfig registerAction(ActionConfig actionConfig) {
String actionPath = actionConfig.actionPath;
if (log.isDebugEnabled()) {
log.debug("Registering Madvoc action: " + actionConfig.actionPath + " to: " + actionConfig.getActionString());
}
ActionConfigSet set = createActionConfigSet(actionConfig.actionPath);
if (set.actionPathMacros != null) {
// new action patch contain macros
int ndx = -1;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).actionPath.equals(actionPath)) {
ndx = i;
break;
}
}
if (ndx < 0) {
list.add(set);
} else {
set = list.get(ndx);
}
} else {
// action path is without macros
if (!map.containsKey(actionConfig.actionPath)) {
map.put(actionConfig.actionPath, set);
} else {
set = map.get(actionConfig.actionPath);
}
}
boolean isDuplicate = set.add(actionConfig);
if (madvocConfig.isDetectDuplicatePathsEnabled()) {
if (isDuplicate) {
throw new MadvocException("Duplicate action path for " + actionConfig);
}
}
// finally
configs.put(actionConfig.getActionString(), actionConfig);
if (!isDuplicate) {
actionsCount++;
}
// async check
if (actionConfig.isAsync()) {
asyncMode = true;
}
return actionConfig;
}
use of jodd.madvoc.ActionConfigSet in project jodd by oblac.
the class ActionsManager method lookup.
// ---------------------------------------------------------------- look-up
/**
* Returns action configurations for provided action path.
* First it lookups for exact <code>actionPath</code>.
* If action path is not registered, it is split into chunks
* and match against macros.
* Returns <code>null</code> if action path is not registered.
* <code>method</code> must be in uppercase.
*/
public ActionConfig lookup(String actionPath, String method) {
// 1st try: the map
ActionConfigSet actionConfigSet = map.get(actionPath);
if (actionConfigSet != null) {
ActionConfig actionConfig = actionConfigSet.lookup(method);
if (actionConfig != null) {
return actionConfig;
}
}
// 2nd try: the list
int actionPathDeep = StringUtil.count(actionPath, '/');
int len = list.size();
int lastMatched = -1;
int maxMatchedChars = -1;
for (int i = 0; i < len; i++) {
actionConfigSet = list.get(i);
int deep = actionConfigSet.deep;
if (deep < actionPathDeep) {
continue;
}
if (deep > actionPathDeep) {
break;
}
// same deep level, try the fully match
int matchedChars = actionConfigSet.actionPathMacros.match(actionPath);
if (matchedChars == -1) {
continue;
}
if (matchedChars > maxMatchedChars) {
maxMatchedChars = matchedChars;
lastMatched = i;
}
}
if (lastMatched < 0) {
return null;
}
ActionConfigSet set = list.get(lastMatched);
return set.lookup(method);
}
use of jodd.madvoc.ActionConfigSet in project jodd by oblac.
the class ActionPathMacroInjector method inject.
public void inject(ActionRequest actionRequest) {
ActionConfig config = actionRequest.getActionConfig();
ActionConfigSet set = config.getActionConfigSet();
if (set.actionPathMacros == null) {
// no action path macros at all, just exit
return;
}
ScopeData[] injectData = lookupScopeData(actionRequest);
if (injectData == null) {
return;
}
// inject
Target[] targets = actionRequest.getTargets();
String[] names = set.actionPathMacros.getNames();
String[] values = set.actionPathMacros.extract(actionRequest.getActionPath());
for (int ndx = 0; ndx < values.length; ndx++) {
String value = values[ndx];
if (StringUtil.isEmpty(value)) {
continue;
}
String macroName = names[ndx];
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, macroName);
if (name != null) {
setTargetProperty(target, name, value);
}
}
}
}
}
Aggregations