Java tutorial
/* * Kuali Coeus, a comprehensive research administration system for higher education. * * Copyright 2005-2015 Kuali, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kuali.coeus.common.framework.krms; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.kuali.coeus.sys.framework.service.KcServiceLocator; import org.kuali.rice.core.api.exception.RiceRuntimeException; import org.kuali.rice.core.api.util.xml.XmlHelper; import org.kuali.rice.kew.engine.RouteContext; import org.kuali.rice.kew.framework.support.krms.RulesEngineExecutor; import org.kuali.rice.kew.rule.xmlrouting.XPathHelper; import org.kuali.rice.krms.api.engine.Engine; import org.kuali.rice.krms.api.engine.EngineResults; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import java.io.ByteArrayInputStream; public abstract class KcRulesEngineExecuter implements RulesEngineExecutor { protected final Log LOG = LogFactory.getLog(KcRulesEngineExecuter.class); @Override public EngineResults execute(RouteContext routeContext, Engine engine) { KcServiceLocator.getService(KcKrmsCacheManager.class).clearCache(); return performExecute(routeContext, engine); } protected String getElementValue(String docContent, String xpathExpression) { try { Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes())); XPath xpath = XPathHelper.newXPath(); String value = (String) xpath.evaluate(xpathExpression, document, XPathConstants.STRING); return value; } catch (Exception e) { throw new RiceRuntimeException(e.getMessage(), e); } } protected NodeList getElementValueAsNodeList(String docContent, String xpathExpression) { try { Document document = XmlHelper.trimXml(new ByteArrayInputStream(docContent.getBytes())); XPath xpath = XPathHelper.newXPath(); NodeList value = (NodeList) xpath.evaluate(xpathExpression, document, XPathConstants.NODESET); return value; } catch (Exception e) { throw new RiceRuntimeException(e.getMessage(), e); } } protected abstract EngineResults performExecute(RouteContext routeContext, Engine engine); }