Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.xml;
 
 
 import static org.kuali.rice.core.api.impex.xml.XmlConstants.*;


Parsing routines for XML structures shared across parsers.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class CommonXmlParser {
     private static final Logger LOG = Logger.getLogger(CommonXmlParser.class);

    
Parses, but does not save, a RuleResponsibility from responsibility identifier elements nested in the specified element

Parameters:
element parent element of responsibility identifier elements
Returns:
a parsed RuleResponsibility
Throws:
org.kuali.rice.core.api.util.xml.XmlException
 
     public static RuleResponsibilityBo parseResponsibilityNameAndType(Element elementthrows XmlException {
         RuleResponsibilityBo responsibility = new RuleResponsibilityBo();
 
         String principalId = element.getChildText(element.getNamespace());
         String principalName = element.getChildText(element.getNamespace());
         String groupId = element.getChildText(element.getNamespace());
         Element groupNameElement = element.getChild(element.getNamespace());
         String role = element.getChildText(element.getNamespace());
         Element roleNameElement = element.getChild(element.getNamespace());
 
         String user = element.getChildText(element.getNamespace());
         String workgroup = element.getChildText(element.getNamespace());
 
         if (!StringUtils.isEmpty(user)) {
             principalName = user;
             .warn("Rule XML is using deprecated element 'user', please use 'principalName' instead.");
         }
 
         // in code below, we allow core config parameter replacement in responsibilities
         if (!StringUtils.isBlank(principalId)) {
             principalId = Utilities.substituteConfigParameters(principalId);
             Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
             if (principal == null) {
                 throw new XmlException("Could not locate principal with the given id: " + principalId);
             }
             responsibility.setRuleResponsibilityName(principalId);
         } else if (!StringUtils.isBlank(principalName)) {
             principalName = Utilities.substituteConfigParameters(principalName);
             Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName);
             if (principal == null) {
                 throw new XmlException("Could not locate principal with the given name: " + principalName);
             }
             responsibility.setRuleResponsibilityName(principal.getPrincipalId());
         } else if (!StringUtils.isBlank(groupId)) {
             groupId = Utilities.substituteConfigParameters(groupId);
             Group group = KimApiServiceLocator.getGroupService().getGroup(groupId);
             if (group == null) {
                 throw new XmlException("Could not locate group with the given id: " + groupId);
             }
             responsibility.setRuleResponsibilityName(groupId);
         } else if (groupNameElement != null) {
             String groupName = groupNameElement.getText();
             String groupNamespace = groupNameElement.getAttributeValue();
             if (StringUtils.isBlank(groupName)) {
                 throw new XmlException("Group name element has no value");
             }
             if (StringUtils.isBlank(groupNamespace)) {
                 throw new XmlException("namespace attribute must be specified");
             }
            groupName = Utilities.substituteConfigParameters(groupName);
            groupNamespace = Utilities.substituteConfigParameters(groupNamespace);
            Group group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(groupNamespace,
                    groupName);
            if (group == null) {
                throw new XmlException("Could not locate group with the given namespace: " + groupNamespace + " and name: " + groupName);
            }
            responsibility.setRuleResponsibilityName(group.getId());
        } else if (!StringUtils.isBlank(role)) {
            role = Utilities.substituteConfigParameters(role);
            responsibility.setRuleResponsibilityName(role);
        } else if (roleNameElement != null) {
            String roleName = roleNameElement.getText();
            String attributeClassName = roleNameElement.getAttributeValue();
            if (StringUtils.isBlank(roleName)) {
                throw new XmlException("Role name element has no value");
            }
            if (StringUtils.isBlank(attributeClassName)) {
                throw new XmlException("attributeClassName attribute must be specified");
            }
            roleName = Utilities.substituteConfigParameters(roleName);
            attributeClassName = Utilities.substituteConfigParameters(attributeClassName);
            responsibility.setRuleResponsibilityName(RoleName.constructRoleValue(attributeClassNameroleName));
        } else if (!StringUtils.isBlank(workgroup)) {
            .warn("Rule XML is using deprecated element 'workgroup', please use 'groupName' instead.");
            workgroup = Utilities.substituteConfigParameters(workgroup);
            String workgroupNamespace = Utilities.parseGroupNamespaceCode(workgroup);
            String workgroupName = Utilities.parseGroupName(workgroup);
            Group workgroupObject = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(
                    workgroupNamespaceworkgroupName);
            if (workgroupObject == null) {
                throw new XmlException("Could not locate workgroup: " + workgroup);
            }
            responsibility.setRuleResponsibilityName(workgroupObject.getId());
        } else {
            return null;
        }
        return responsibility;
    }
New to GrepCode? Check out our FAQ X