Package org.docx4j.model

Examples of org.docx4j.model.PropertyResolver


    if (lvl.getPStyle()!=null) {
     
      // Get the style
//      StyleDefinitionsPart stylesPart = ((WordprocessingMLPackage)this.getPackage()).
//        getMainDocumentPart().getStyleDefinitionsPart();
      PropertyResolver propertyResolver
        = ((WordprocessingMLPackage)this.getPackage()).getMainDocumentPart().getPropertyResolver();
     
      log.debug("override level has linked style: " + lvl.getPStyle().getVal() );
     
      org.docx4j.wml.Style style = propertyResolver.getStyle( lvl.getPStyle().getVal() );
     
      if (style==null) {
        log.error("Couldn't find style " + lvl.getPStyle().getVal());
        return null;
      }
View Full Code Here


 
    private PropertyResolver propertyResolver;
  public PropertyResolver getPropertyResolver() {
    if (propertyResolver==null) {
      try {
        propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack);
      } catch (Docx4JException e) {
        e.printStackTrace();
      }     
    }
    return propertyResolver;
View Full Code Here

      ResultTriple triple = em.new ResultTriple();     
     
      org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart stylesPart =
        wmlPackage.getMainDocumentPart().getStyleDefinitionsPart();
     
      PropertyResolver propertyResolver = wmlPackage.getMainDocumentPart().getPropertyResolver();
           
      // If numId is not provided explicitly,
      // is it provided by the style?
      // (ie does this style have a list associated with it?)
      if (numId == null
          || numId.equals("")) {
       
        org.docx4j.wml.Style style = null;
        if (pStyleVal==null || pStyleVal.equals("") ) {
            log.debug("no explicit numId; no style either");
          return null;
        }
       
        log.debug("no explicit numId; looking in styles");
      PPr ppr = propertyResolver.getEffectivePPr(pStyleVal);
     
        if (ppr == null) {
            log.debug("Style '" + pStyleVal + "' has no pPr");
//            System.out.println("Style '" + pStyleVal + "' has no pPr");
//              System.out.println(
View Full Code Here

      }

      org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart stylesPart =
        wmlPackage.getMainDocumentPart().getStyleDefinitionsPart();
     
      PropertyResolver propertyResolver = wmlPackage.getMainDocumentPart().getPropertyResolver();
           
      // If numId is not provided explicitly,
      // is it provided by the style?
      // (ie does this style have a list associated with it?)
      if (numId == null
          || numId.equals("")) {
       
        org.docx4j.wml.Style style = null;
        if (pStyleVal==null || pStyleVal.equals("") ) {
            log.debug("no explicit numId; no style either");
          return null;
        }
       
        log.debug("no explicit numId; looking in styles");
      style = propertyResolver.getStyle(pStyleVal);
     
        if (style == null) {
          log.debug("Couldn't find style '" + pStyleVal + "'");
          return null;
        }
       
        if (style.getPPr() == null) {
            log.debug("Style '" + pStyleVal + "' has no pPr");
//            System.out.println("Style '" + pStyleVal + "' has no pPr");
//              System.out.println(
//                  org.docx4j.XmlUtils.marshaltoString(style, true, true)
//                  );
             
            return null;
        }

       
        NumPr numPr = style.getPPr().getNumPr();
       
        if (numPr==null) {
            log.debug("Couldn't get NumPr from " +  pStyleVal);
//            log.debug(
//                org.docx4j.XmlUtils.marshaltoString(style, true, true)
//                );
            // So there is no numbering set on the style either
            // That's ok ..
            return null;
        }
       
       
        if (numPr.getNumId()==null) {
          log.debug("NumPr element has no numId");
          if (pStyleVal==null) {
            return null;
          } else {
                // use propertyResolver to follow <w:basedOn w:val="blagh"/>
              log.debug(pStyleVal + ".. use propertyResolver to follow basedOn");
            PPr ppr = propertyResolver.getEffectivePPr(pStyleVal);
           
            numPr = ppr.getNumPr();
              if (numPr==null) { 
                  log.debug(pStyleVal + "NumPr element still has no numId (basedOn didn't help)");
                return null; // Is this the right thing to do? Check!
View Full Code Here

      String inputfilepath = System.getProperty("user.dir") + "/src/test/java/org/docx4j/model/listnumbering/NumberingIndents";

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath + ".docx"));

    PropertyResolver propertyResolver =
            wordMLPackage.getMainDocumentPart().getPropertyResolver();

    final int EXPECT_START_LENGTH = EXPECT_START.length();

    // Iterate through the paragraphs
    int assertionCount=0;
    for (Object o : wordMLPackage.getMainDocumentPart().getContent() ) {

      if (o instanceof P) {

        P p = (P)o;

        if (p.getPPr()!=null) {

            PPr pPr = propertyResolver.getEffectivePPr(p.getPPr());

            if (pPr.getInd()!=null) {

              String actual = removeNamespaces(XmlUtils.marshaltoString(pPr.getInd(), true));
View Full Code Here

        FOConversionContext context,
        NodeIterator pPrNodeIt,
        String pStyleVal, NodeIterator childResults,
        boolean sdt) {

      PropertyResolver propertyResolver = context.getPropertyResolver();
     
      // 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;
    }
    if (log.isDebugEnabled()) {
      log.debug("style '" + pStyleVal );
    }

      //      log.info("pPrNode:" + pPrNodeIt.getClass().getName() ); // org.apache.xml.dtm.ref.DTMNodeIterator     
//      log.info("childResults:" + childResults.getClass().getName() );
     
     
        try {
         
          PPr pPrDirect = null;
         
          // 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;
          RPr rPr = null;
          RPr rPrParagraphMark = null// required for list item label
          if (pPrNodeIt==null) {  // Never happens?           
          if (log.isDebugEnabled()) {
            log.debug("Here after all!!");
          }
            pPr = propertyResolver.getEffectivePPr(defaultParagraphStyleId);
            rPr = propertyResolver.getEffectiveRPr(defaultParagraphStyleId);
            rPrParagraphMark = rPr;
          } else {
            Node n = pPrNodeIt.nextNode();
            if (n==null) {
              if (log.isDebugEnabled()) {
                log.debug("pPrNodeIt.nextNode() was null (ie there is no pPr in this p)");
              }
                pPr = propertyResolver.getEffectivePPr(defaultParagraphStyleId);
                rPr = propertyResolver.getEffectiveRPr(defaultParagraphStyleId);
                // TODO - in this case, we should be able to compute once,
                // and on subsequent calls, just return pre computed value
            } else {
              if (log.isDebugEnabled()) {
                log.debug( "P actual pPr: "+ XmlUtils.w3CDomNodeToString(n) );
              }
              Unmarshaller u = Context.jc.createUnmarshaller();     
              u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
              Object jaxb = u.unmarshal(n);
            pPrDirect =  (PPr)jaxb;
            pPr = propertyResolver.getEffectivePPr(pPrDirect)
            if ((pPr==null) && (log.isDebugEnabled())) {
              log.debug("pPr null; obtained from: " + XmlUtils.w3CDomNodeToString(n) );
            }
           
            // On the block representing the w:p, we want to put both
              // pPr and rPr attributes.
           
            if (log.isDebugEnabled()) {
              log.debug("getting rPr for paragraph style");
            }
            rPr = propertyResolver.getEffectiveRPr(null, pPrDirect);
              // rPr in pPr direct formatting only applies to paragraph mark,
              // and by virtue of that, to list item label,
              // so pass null here
            // Now, work out the value for list item label
                rPrParagraphMark = XmlUtils.deepCopy(rPr);
View Full Code Here

        FOConversionContext context,
        NodeIterator pPrNodeIt,
        NodeIterator rPrNodeIt,
        NodeIterator childResults ) {

      PropertyResolver propertyResolver = context.getPropertyResolver();
     
      // 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

     
//      log.info("rPrNode:" + rPrNodeIt.getClass().getName() ); // org.apache.xml.dtm.ref.DTMNodeIterator     
//      log.info("childResults:" + childResults.getClass().getName() );
     
     
        try {
         
      Unmarshaller u = Context.jc.createUnmarshaller();     
      u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());

      // If there is w:pPr/w:pStyle,     
      // we need to honour any rPr in the pStyle
      PPr pPrDirect = null;
          if (pPrNodeIt!=null) {
            Node n = pPrNodeIt.nextNode();
            if (n!=null) {
              Object jaxb = u.unmarshal(n);
              try {
                pPrDirect =  (PPr)jaxb;
              } catch (ClassCastException e) {
                  log.error("Couldn't cast to PPr " + jaxb.getClass().getName() + " to PPr!");
              }                       
            }
          }
         
      Object jaxbR = u.unmarshal(rPrNodeIt.nextNode());     
      //RPr rPrDirect = null;
      RPr rPr = null;
      if (jaxbR instanceof RPr) {
        //rPrDirect =  (RPr)jaxbR;
        rPr = propertyResolver.getEffectiveRPr((RPr)jaxbR, pPrDirect);
      } else if (jaxbR instanceof ParaRPr) {
//        if (log.isDebugEnabled()) {
//          Throwable t = new Throwable();
//          log.debug("passed ParaRPr", t);
//        }
       
        rPr = propertyResolver.getEffectiveRPr(null, pPrDirect);
//          System.out.println("p rpr-->" + XmlUtils.marshaltoString(pPrDirect.getRPr()));
           
            StyleUtil.apply((ParaRPr)jaxbR, rPr);        
       
      } else {
View Full Code Here

   
    this.tblGrid = tbl.getTblGrid();
   
    this.tblPr = tbl.getTblPr();
   
    PropertyResolver pr = conversionContext.getPropertyResolver();
     
    effectiveTableStyle = pr.getEffectiveTableStyle(tbl.getTblPr() );
//      if (tblPr!=null
//          && tblPr.getTblW()!=null) {
//        if (tblPr.getTblW().getType()!=null
//            && (tblPr.getTblW().getType().equals("auto")
//                || tblPr.getTblW().getType().equals("nil") )) {
View Full Code Here

   
    private static String getCssForTableCells(HTMLConversionContext context,
        Tbl tbl, int idx) {
     
      StringBuffer result = new StringBuffer();   
    PropertyResolver pr = context.getPropertyResolver();
    Style s = pr.getEffectiveTableStyle(tbl.getTblPr() );
   
    result.append("#" + TableWriter.getId(idx) + " td { ");
      List<Property> properties =  new ArrayList<Property>();
      if (s.getTblPr()!=null
          && s.getTblPr().getTblBorders()!=null ) {
View Full Code Here

    @Override
  protected Element handlePPr(FOConversionContext conversionContext, PPr pPrDirect, boolean sdt,
      Element currentParent) {
      Element ret = currentParent;

      PropertyResolver propertyResolver = conversionContext.getPropertyResolver();
     

      String defaultParagraphStyleId = "Normal";
      if (conversionContext.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null) {
          Style defaultParagraphStyle =
              conversionContext.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle();
          if (defaultParagraphStyle != null) {
            defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
          }
      }
     
      String pStyleVal = null;
      if (pPrDirect!=null && pPrDirect.getPStyle()!=null) {
        pStyleVal = pPrDirect.getPStyle().getVal();
      } else {
      pStyleVal = defaultParagraphStyleId;
    }
      getLog().debug("style '" + pStyleVal );        

        try {
         
//          PPr pPr = null;
//          RPr rPr = null;
      pPr = propertyResolver.getEffectivePPr(pPrDirect)

      getLog().debug("getting rPr for paragraph style");           
      rPr = propertyResolver.getEffectiveRPr(null, pPrDirect);
      // rPr in pPr direct formatting only applies to paragraph mark,
      // and by virtue of that, to list item label,
      // so pass null here
     
      // Now, work out the value for list item label
View Full Code Here

TOP

Related Classes of org.docx4j.model.PropertyResolver

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.