Coverage Report - org.kuali.rice.kew.docsearch.xml.DocumentSearchXMLResultProcessorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentSearchXMLResultProcessorImpl
0%
0/60
0%
0/22
5.4
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.docsearch.xml;
 18  
 
 19  
 import org.kuali.rice.kew.docsearch.StandardDocumentSearchResultProcessor;
 20  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 21  
 import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
 22  
 import org.kuali.rice.kns.web.ui.Column;
 23  
 import org.w3c.dom.Element;
 24  
 import org.w3c.dom.NamedNodeMap;
 25  
 import org.w3c.dom.Node;
 26  
 import org.w3c.dom.NodeList;
 27  
 import org.xml.sax.InputSource;
 28  
 
 29  
 import javax.xml.parsers.DocumentBuilderFactory;
 30  
 import javax.xml.xpath.XPath;
 31  
 import javax.xml.xpath.XPathConstants;
 32  
 import javax.xml.xpath.XPathExpressionException;
 33  
 import java.io.BufferedReader;
 34  
 import java.io.StringReader;
 35  
 import java.util.ArrayList;
 36  
 import java.util.List;
 37  
 
 38  
 
 39  
 /**
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  */
 43  0
 public class DocumentSearchXMLResultProcessorImpl extends StandardDocumentSearchResultProcessor implements DocumentSearchXMLResultProcessor {
 44  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentSearchXMLResultProcessorImpl.class);
 45  
 
 46  
         private RuleAttribute ruleAttribute;
 47  0
         private List<Column> customDisplayColumns = new ArrayList<Column>();
 48  
 
 49  
         public void setRuleAttribute(RuleAttribute ruleAttribute) {
 50  0
                 this.ruleAttribute = ruleAttribute;
 51  0
         }
 52  
 
 53  
         @Override
 54  
         public List<Column> getCustomDisplayColumns() {
 55  0
                 List<Column> displayColumns = new ArrayList<Column>();
 56  0
                 if (customDisplayColumns.isEmpty()) {
 57  0
                         XPath xpath = XPathHelper.newXPath();
 58  0
                         String xPathExpression = "//searchResultConfig/column";
 59  
                         try {
 60  0
                                 NodeList nodes = (NodeList) xpath.evaluate(xPathExpression, getConfigXML(), XPathConstants.NODESET);
 61  0
                     if (nodes == null) {
 62  0
                         LOG.error("Could not find searching configuration columns (<searchResultConfig><column>) for this DocumentSearchXMLResultProcessor");
 63  
                     } else {
 64  0
                                     for (int i = 0; i < nodes.getLength(); i++) {
 65  0
                                             Node field = nodes.item(i);
 66  0
                                             NamedNodeMap fieldAttributes = field.getAttributes();
 67  0
                                             String key = (fieldAttributes.getNamedItem("name") != null) ? fieldAttributes.getNamedItem("name").getNodeValue().trim() : null;
 68  0
                                             String title = (fieldAttributes.getNamedItem("title") != null) ? fieldAttributes.getNamedItem("title").getNodeValue().trim() : null;
 69  0
                                             String sortable = (fieldAttributes.getNamedItem("sortable") != null) ? fieldAttributes.getNamedItem("sortable").getNodeValue().trim() : null;
 70  0
                                             Column currentColumn = new Column(title,sortable,key);
 71  0
                                             displayColumns.add(currentColumn);
 72  
                                     }
 73  0
                                     customDisplayColumns = displayColumns;
 74  
                     }
 75  0
                         } catch (XPathExpressionException e) {
 76  0
                                 LOG.error("error in getCustomDisplayColumns ", e);
 77  0
                                 throw new RuntimeException("Error trying to find xml content with xpath expression: " + xPathExpression, e);
 78  0
                         } catch (Exception e) {
 79  0
                                 LOG.error("error in getCustomDisplayColumns attempting to find xml custon columns", e);
 80  0
                                 throw new RuntimeException("Error trying to get xml custom columns.", e);
 81  0
                         }
 82  
                 }
 83  0
                 return customDisplayColumns;
 84  
         }
 85  
 
 86  
         @Override
 87  
         public boolean getShowAllStandardFields() {
 88  0
                 boolean returnValue = DEFAULT_SHOW_ALL_STANDARD_FIELDS_VALUE;
 89  0
                 XPath xpath = XPathHelper.newXPath();
 90  0
                 String findXpathExpressionPrefix = "//searchResultConfig";
 91  
                 Node searchResultConfig;
 92  
                 try {
 93  0
                         searchResultConfig = (Node) xpath.evaluate(findXpathExpressionPrefix, getConfigXML(), XPathConstants.NODE);
 94  0
                         if (searchResultConfig != null) {
 95  0
                                 NamedNodeMap fieldAttributes = searchResultConfig.getAttributes();
 96  0
                                 if (fieldAttributes.getNamedItem("showStandardSearchFields") != null) {
 97  0
                                         returnValue = Boolean.valueOf(fieldAttributes.getNamedItem("showStandardSearchFields").getNodeValue());
 98  
                                 }
 99  
                         }
 100  0
                 } catch (XPathExpressionException e) {
 101  0
                         LOG.error("error in getSearchContent ", e);
 102  0
                         throw new RuntimeException("Error trying to find xml content with xpath expression", e);
 103  0
                 }
 104  0
                 return returnValue;
 105  
         }
 106  
 
 107  
         @Override
 108  
         public boolean getOverrideSearchableAttributes() {
 109  0
                 boolean returnValue = DEFAULT_OVERRIDE_SEARCHABLE_ATTRIBUTES_VALUE;
 110  0
                 XPath xpath = XPathHelper.newXPath();
 111  0
                 String findXpathExpressionPrefix = "//searchResultConfig";
 112  
                 Node searchResultConfig;
 113  
                 try {
 114  0
                         searchResultConfig = (Node) xpath.evaluate(findXpathExpressionPrefix, getConfigXML(), XPathConstants.NODE);
 115  0
                         if (searchResultConfig != null) {
 116  0
                                 NamedNodeMap fieldAttributes = searchResultConfig.getAttributes();
 117  0
                                 if (fieldAttributes.getNamedItem("overrideSearchableAttributes") != null) {
 118  0
                                         returnValue = Boolean.valueOf(fieldAttributes.getNamedItem("overrideSearchableAttributes").getNodeValue());
 119  
                                 }
 120  
                         }
 121  0
                 } catch (XPathExpressionException e) {
 122  0
                         LOG.error("error in getSearchContent ", e);
 123  0
                         throw new RuntimeException("Error trying to find xml content with xpath expression", e);
 124  0
                 }
 125  0
                 return returnValue;
 126  
         }
 127  
 
 128  
         public Element getConfigXML() {
 129  
                 try {
 130  0
                         return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new BufferedReader(new StringReader(ruleAttribute.getXmlConfigData())))).getDocumentElement();
 131  0
                 } catch (Exception e) {
 132  0
                         String ruleAttrStr = (ruleAttribute == null ? null : ruleAttribute.getName());
 133  0
                         LOG.error("error parsing xml data from search processor attribute: " + ruleAttrStr, e);
 134  0
                         throw new RuntimeException("error parsing xml data from search processor attribute: " + ruleAttrStr, e);
 135  
                 }
 136  
         }
 137  
 }