Package org.docx4j.model.styles

Examples of org.docx4j.model.styles.StyleTree$AugmentedStyle


      Styles styles = getStyleDefinitionsPart().getJaxbElement();   
      for ( org.docx4j.wml.Style s : styles.getStyle() ) {       
        allStyles.put(s.getStyleId(), s)
        //log.debug("live style: " + s.getStyleId() );
      }
      styleTree = new StyleTree(getStylesInUse(), allStyles);
       
    }
    return styleTree;
   
  }
View Full Code Here


          if (defaultRunStyle.getStyleId()==null) // possible, for non MS source docx
            defaultCharacterStyleId = "DefaultParagraphFont";
          else defaultCharacterStyleId = defaultRunStyle.getStyleId();
         
         
          StyleTree styleTree = pkg.getMainDocumentPart().getStyleTree();
       
        // Set @class 
        String classVal =null;
        String rStyleVal = defaultCharacterStyleId;
        if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
          rStyleVal = rPrSDT.getRStyle().getVal();
        }
        Tree<AugmentedStyle> cTree = styleTree.getCharacterStylesTree();   
        org.docx4j.model.styles.Node<AugmentedStyle> asn = cTree.get(rStyleVal);
        if (asn==null) {
          log.warn("No style node for: " + rStyleVal);
        } else {
          classVal = StyleTree.getHtmlClassAttributeValue(cTree, asn);   
        }
         
       
        String css = null;
        if ( rPrSDT!=null) {
          StringBuilder result = new StringBuilder();
          HtmlCssHelper.createCss(pkg, rPrSDT, result);
          css = result.toString();
          if (css.equals("")) {
            css =null;
          }
        }
       
        if (css==null && classVal==null) {
          // Do nothing
        } else if (classVal==null) {
          // just @style
          r = "<span style=\"" + css + "\">" + r + "</span>";
        } else if (css==null) {
          // just @class
          r = "<span class=\"" + classVal + "\">" + r + "</span>";
        } else {
          r = "<span style=\"" + css + "\" class=\"" + classVal + "\">" + r + "</span>";          
        }
        log.debug("\nenhanced with css: \n" + r);
       
      } else if (Docx4jProperties.getProperty("docx4j.model.datastorage.BindingTraverser.XHTML.Block.rStyle.Adopt", false)) {
       
        log.debug("Block.rStyle.Adopt..");
       
        // its block level, and we're instructed to apply the paragraph style
        // linked to w:sdtPr/w:rPr/w:rStyle (if any)
        String rStyleVal=null;
        if ( rPrSDT!=null && rPrSDT.getRStyle()!=null) {
          rStyleVal = rPrSDT.getRStyle().getVal();
          log.debug(".." + rStyleVal);
        }
       
        if (rStyleVal==null) {

          log.debug("No rStyle specified ");
         
        } else {
         
          Style pStyle = pkg.getMainDocumentPart().getStyleDefinitionsPart(false).getLinkedStyle(rStyleVal);
         
          if (pStyle==null) {
           
            log.warn("No linked style for " + rStyleVal);
           
          } else {
           
            // Got the pStyle .. now apply it in the XHTML
              StyleTree styleTree = pkg.getMainDocumentPart().getStyleTree();
             
              String pStyleVal = pStyle.getStyleId();
            log.debug(".." + pStyleVal);
                             
            // Set @class 
            String classVal =null;
            Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();   
            org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal);
            if (asn==null) {
              log.warn("No style node for: " + pStyleVal);
            } else {
              classVal = StyleTree.getHtmlClassAttributeValue(pTree, asn);   
View Full Code Here

 
    // Set @class
      if (table.getStyleId()==null) {
        log.debug("table has no w:tblStyle?");
      } else {
      StyleTree styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree()
      Tree<AugmentedStyle> tTree = styleTree.getTableStylesTree();   
      org.docx4j.model.styles.Node<AugmentedStyle> asn = tTree.get(table.getStyleId());
      tableRoot.setAttribute("class",
          StyleTree.getHtmlClassAttributeValue(tTree, asn)     
      );
      }
View Full Code Here

   
   
    public static String getCssForStyles(HTMLConversionContext context) {
      StringBuilder result = new StringBuilder();
     
      StyleTree styleTree = null;
    try {
      styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
    } catch (Exception e) {
      context.getLog().error("Couldn't getStyleTree", e);
        return result.toString();     
View Full Code Here

        NodeIterator pPrNodeIt,
        String pStyleVal, NodeIterator childResults,
        String htmlElementName ) {
     

    StyleTree styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
     
      // Note that this is invoked for every paragraph with a pPr node.
     
      // incoming objects are org.apache.xml.dtm.ref.DTMNodeIterator
      // which implements org.w3c.dom.traversal.NodeIterator

    Style defaultParagraphStyle =
        (context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
        context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle() :
        null);
   
      String defaultParagraphStyleId;
      if (defaultParagraphStyle==null) // possible, for non MS source docx
        defaultParagraphStyleId = "Normal";
      else defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
     
    if ( pStyleVal ==null || pStyleVal.equals("") ) {
//      pStyleVal = "Normal";
      pStyleVal = defaultParagraphStyleId;
    }
      context.getLog().debug("style '" + pStyleVal );        
     
//      log.info("pPrNode:" + pPrNodeIt.getClass().getName() ); // org.apache.xml.dtm.ref.DTMNodeIterator     
//      log.info("childResults:" + childResults.getClass().getName() );

     
        try {
         
          // Get the pPr node as a JAXB object,
          // so we can read it using our standard
          // methods.  Its a bit sad that we
          // can't just adorn our DOM tree with the
          // original JAXB objects?
          PPr pPr = null;
          if (pPrNodeIt!=null) { //It is never null
            Node n = pPrNodeIt.nextNode();
            if (n!=null) {
              Unmarshaller u = Context.jc.createUnmarshaller();     
              u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
              Object jaxb = u.unmarshal(n);
              try {
                pPr =  (PPr)jaxb;
              } catch (ClassCastException e) {
                context.getLog().error("Couldn't cast " + jaxb.getClass().getName() + " to PPr!");
              }                       
            }
          }
         
            // Create a DOM document to take the results     
      Document document = XmlUtils.getNewDocumentBuilder().newDocument();     
        //log.info("Document: " + document.getClass().getName() );
      Element xhtmlBlock = document.createElement(htmlElementName);     
      document.appendChild(xhtmlBlock);
             
      if (context.getLog().isDebugEnabled() && pPr!=null) {         
        context.getLog().debug(XmlUtils.marshaltoString(pPr, true, true));         
      }       
       
      // Set @class
      context.getLog().debug(pStyleVal);
      Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();   
      org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal);
      String classVal = StyleTree.getHtmlClassAttributeValue(pTree, asn);     
      xhtmlBlock.setAttribute("class", classVal);
   
     
View Full Code Here

      if (defaultRunStyle.getStyleId()==null) // possible, for non MS source docx
        defaultCharacterStyleId = "DefaultParagraphFont";
      else defaultCharacterStyleId = defaultRunStyle.getStyleId();
     
     
      StyleTree styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
           
      // Note that this is invoked for every paragraph with a pPr node.
     
      // incoming objects are org.apache.xml.dtm.ref.DTMNodeIterator
      // which implements org.w3c.dom.traversal.NodeIterator
View Full Code Here

        String lvl,
        String cNvPrName,
        String phType, NodeIterator childResults, NodeIterator lvlNpPr ) {
           
     
    StyleTree styleTree = null;
    try {
      styleTree = context.getPmlPackage().getStyleTree();
    } catch (InvalidFormatException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
     
    log.debug("lvl:" +lvl);
    int level;
    if (lvl.equals("NaN")) {
      level = 1;
    } else {
      level = Integer.parseInt(lvl);
    }
    String pStyleVal;
     
    System.out.println("cNvPrName: " + cNvPrName + "; " + "phType: " + phType );
   
    if (cNvPrName.toLowerCase().indexOf("subtitle")>-1
        || phType.toLowerCase().indexOf("subtitle")>-1) {
      // Subtitle on first page in default layout is styled as a Body.
        pStyleVal = "Lvl" + level + "Master" + context.getResolvedLayout().getMasterNumber() + "Body";
    } else if (cNvPrName.toLowerCase().indexOf("title")>-1
      || phType.toLowerCase().indexOf("title")>-1) {
      pStyleVal = "Lvl" + level + "Master" + context.getResolvedLayout().getMasterNumber() + "Title";
    } else {
      // eg cNvPrName: TextBox 2; phType:
      pStyleVal = "Lvl" + level + "Master" + context.getResolvedLayout().getMasterNumber() + "Other";     
    }
    System.out.println("--> " + pStyleVal );
   
        try {
         
         
            // Create a DOM builder and parse the fragment     
      Document document = XmlUtils.getNewDocumentBuilder().newDocument();
     
      //log.info("Document: " + document.getClass().getName() );

      Node xhtmlP = document.createElement("p");     
      document.appendChild(xhtmlP);
                     
      // Set @class
      log.debug(pStyleVal);
      Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();   
      org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal);
      ((Element)xhtmlP).setAttribute("class",
          StyleTree.getHtmlClassAttributeValue(pTree, asn)     
      );
     
View Full Code Here

 
    public static String getCssForStyles(SvgConversionContext context) {
     
      StringBuilder result = new StringBuilder();
     
    StyleTree styleTree=null;
    try {
      styleTree = context.getPmlPackage().getStyleTree();
    } catch (InvalidFormatException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
    // Second iteration - paragraph level pPr *and rPr*
    result.append("\n /* PARAGRAPH STYLES */ \n");     
    Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();   
      for (org.docx4j.model.styles.Node<AugmentedStyle> n : pTree.toList() ) {
        Style s = n.getData().getStyle();

        result.append( "."+ s.getStyleId()  + " {display:block;" );
          if (s.getPPr()==null) {
View Full Code Here

      Map<String, Style> map = new HashMap<String, Style>();
      for (Style s : styles) {
        map.put(s.getStyleId(), s);
        list.add(s.getStyleId());
      }
      styleTree = new StyleTree(list, map);
        // TODO: We don't have defaultParagraphStyleId, defaultCharacterStyleId
        // so use DocDefaults for now.
    }
    return styleTree;
   
View Full Code Here

TOP

Related Classes of org.docx4j.model.styles.StyleTree$AugmentedStyle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.