Coverage Report - org.kuali.rice.core.impl.style.StyleServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StyleServiceImpl
0%
0/30
0%
0/10
2.4
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.core.impl.style;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.kuali.rice.core.api.style.Style;
 20  
 import org.kuali.rice.core.api.style.StyleRepositoryService;
 21  
 import org.kuali.rice.core.api.style.StyleService;
 22  
 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
 23  
 import org.kuali.rice.kew.api.KewApiConstants;
 24  
 import org.kuali.rice.krad.util.KRADConstants;
 25  
 
 26  
 import javax.xml.transform.Templates;
 27  
 import javax.xml.transform.TransformerConfigurationException;
 28  
 import javax.xml.transform.TransformerFactory;
 29  
 import javax.xml.transform.stream.StreamSource;
 30  
 import java.io.StringReader;
 31  
 import java.util.List;
 32  
 import java.util.Properties;
 33  
 
 34  
 
 35  
 /**
 36  
  * Implements generic StyleService via existing EDL style table
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class StyleServiceImpl implements StyleService {
 40  
         
 41  0
     private static final Logger LOG = Logger.getLogger(StyleServiceImpl.class);
 42  
 
 43  
     private StyleRepositoryService styleRepositoryService;
 44  
 
 45  
     public void setStyleRepositoryService(StyleRepositoryService styleRepositoryService) {
 46  0
             this.styleRepositoryService = styleRepositoryService;
 47  0
     }
 48  
 
 49  
     /**
 50  
      * Loads the named style from the database, or (if configured) imports it from a file
 51  
      * specified via a configuration parameter with a name of the format edl.style.<styleName>
 52  
      * {@inheritDoc}
 53  
      */
 54  
     @Override
 55  
     public Style getStyle(String styleName) {
 56  0
             return styleRepositoryService.getStyle(styleName);
 57  
     }
 58  
 
 59  
     @Override
 60  
     public Templates getStyleAsTranslet(String name) throws TransformerConfigurationException {
 61  0
         if (name == null) {
 62  0
             return null;
 63  
         }
 64  
 
 65  0
         Style style = getStyle(name);
 66  0
         if (style == null) {
 67  0
             return null;
 68  
         }
 69  
 
 70  0
         boolean useXSLTC = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_USE_XSLTC_IND);
 71  0
         if (useXSLTC) {
 72  0
             LOG.info("using xsltc to compile stylesheet");
 73  0
             String key = "javax.xml.transform.TransformerFactory";
 74  0
             String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
 75  0
             Properties props = System.getProperties();
 76  0
             props.put(key, value);
 77  0
             System.setProperties(props);
 78  
         }
 79  
 
 80  0
         TransformerFactory factory = TransformerFactory.newInstance();
 81  0
         factory.setURIResolver(new StyleUriResolver(this));
 82  
 
 83  0
         if (useXSLTC) {
 84  0
             factory.setAttribute("translet-name",name);
 85  0
             factory.setAttribute("generate-translet",Boolean.TRUE);
 86  0
             String debugTransform = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_DEBUG_TRANSFORM_IND);
 87  0
             if (debugTransform.trim().equals("Y")) {
 88  0
                 factory.setAttribute("debug", Boolean.TRUE);
 89  
             }
 90  
         }
 91  
 
 92  0
         return factory.newTemplates(new StreamSource(new StringReader(style.getXmlContent())));
 93  
     }
 94  
 
 95  
     @Override
 96  
     public void saveStyle(Style style) {
 97  0
             styleRepositoryService.saveStyle(style);
 98  0
     }
 99  
     
 100  
     @Override
 101  
     public List<String> getAllStyleNames() {
 102  0
         return styleRepositoryService.getAllStyleNames();
 103  
     }
 104  
 }