All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docx4j.model.styles.BrokenStyleRemediator Maven / Gradle / Ivy

Go to download

docx4j is a library which helps you to work with the Office Open XML file format as used in docx documents, pptx presentations, and xlsx spreadsheets.

There is a newer version: 11.4.11
Show newest version
package org.docx4j.model.styles;

import org.docx4j.XmlUtils;
import org.docx4j.wml.Style;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author jharrop
 * @since 3.2.0
 */
public class BrokenStyleRemediator {

	/* Microsoft's SSRS creates styles such as:
	 * 
		  
		    
		    
		    
		      
		    
		  
		  
		  missing type and id!
		  
  	 */
	
	protected static Logger log = LoggerFactory.getLogger(BrokenStyleRemediator.class);
	
    public static void remediate(Style s) {
    	
    	if (s.getStyleId()==null) {

            if(log.isWarnEnabled()) {
                log.warn("Style is missing ID(!)");
                log.warn(XmlUtils.marshaltoString(s));
            }
    		
    		// Set the ID to the name
    		if (s.getName()!=null
    				&& s.getName().getVal()!=null) {
      	  		log.warn("remediating");
    			s.setStyleId(s.getName().getVal());
    		} else {
      	  		log.warn(".. ignoring");    			
    			return;
    		}
    	}
    	
      if (s.getType()==null) {

  		log.warn("Style is missing type");
  		
  		if (s.getBasedOn()!=null
  				&& s.getBasedOn().getVal()!=null
  				&& s.getBasedOn().getVal().equals("Normal")) {
  			
  	  		log.warn("remediating");
  	  		s.setType("paragraph");
  		
		} else {
			// Does type have a default value?
  	  		log.warn(".. ignoring");    			
			return;
		}  		
      }	
      
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy