Package org.docx4j.openpackaging.parts

Examples of org.docx4j.openpackaging.parts.PartName


    super(partName);
    setJAXBContext(Context.jc);           
  }

  public JaxbDmlPart() throws InvalidFormatException {
    super(new PartName("/xl/blagh.xml"));
    setJAXBContext(Context.jc);           
  }
View Full Code Here


  public static Part newPartForContentType(String contentType, String partName)
  throws InvalidFormatException, PartUnrecognisedException {
   
    if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_COLORS)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramColorsPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_DATA)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramDataPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_LAYOUT)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramLayoutPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_STYLE)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramStylePart(new PartName(partName));
//    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_DRAWING)) {
//      return new org.docx4j.openpackaging.parts.DrawingML.DiagramDrawingPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_DRAWING)) {
      return new Drawing(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_CHART)) {
      return new Chart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_LAYOUT_HEADER)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramLayoutHeaderPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.DRAWINGML_CHART_SHAPES)) {
      return new ChartShapePart(new PartName(partName));
    }
    else {
      throw new PartUnrecognisedException("No subclass found for "
          + partName + " (content type '" + contentType + "')");
    }
View Full Code Here

    super(partName);
    init();
  }

  public Drawing() throws InvalidFormatException {
    super(new PartName("/xl/drawings/drawing1.xml"));
    init();
  }
View Full Code Here

    init();
   
  }

  public DiagramDrawingPart() throws InvalidFormatException {
    super(new PartName("/word/diagrams/drawing1.xml"));
    init();   
  }   
View Full Code Here

          try {
            Unmarshaller u = Context.jc.createUnmarshaller();
            Object o = u.unmarshal( el );           
            log.debug(o.getClass().getName());
           
            PartName name = part.getPartName();
           
            if (o instanceof CoverPageProperties) {
             
              part = new DocPropsCoverPagePart(name);             
              ((DocPropsCoverPagePart)part).setJaxbElement(
                  (CoverPageProperties)o);
             
            } else if (o instanceof org.opendope.conditions.Conditions) {
             
              part = new ConditionsPart(name);
              ((ConditionsPart)part).setJaxbElement(
                  (org.opendope.conditions.Conditions)o);
             
             
            } else if (o instanceof org.opendope.xpaths.Xpaths) {
             
              part = new XPathsPart(name);
              ((XPathsPart)part).setJaxbElement(
                  (org.opendope.xpaths.Xpaths)o);

            } else if (o instanceof org.opendope.questions.Questionnaire) {
             
              part = new QuestionsPart(name);
              ((QuestionsPart)part).setJaxbElement(
                  (org.opendope.questions.Questionnaire)o);

            } else if (o instanceof org.opendope.answers.Answers) {
             
              part = new StandardisedAnswersPart(name);
              ((StandardisedAnswersPart)part).setJaxbElement(
                  (org.opendope.answers.Answers)o);
             
            } else if (o instanceof org.opendope.components.Components) {
             
              part = new ComponentsPart(name);
              ((ComponentsPart)part).setJaxbElement(
                  (org.opendope.components.Components)o);

            } else if (o instanceof JAXBElement<?>
                && XmlUtils.unwrap(o) instanceof org.docx4j.bibliography.CTSources) {
              part = new BibliographyPart(name);
              ((BibliographyPart)part).setJaxbElement(
                  (JAXBElement<org.docx4j.bibliography.CTSources>)o);
                           
            } else {
             
              log.warn("No known part after all for CustomXmlPart " + o.getClass().getName());

              CustomXmlDataStorage data = Load.getCustomXmlDataStorageClass().factory();

              // Copy el into a new document
              org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument();
              //XmlUtils.treeCopy(el, doc);
              org.w3c.dom.Node copy = doc.importNode(el, true);
              // Word doesn't like the xml namespace to be bound. At some point in a process
              // from docx -> package-> flatopc -> package -> docx, it is added to the custom xml root element.
              try {
                copy.getAttributes().removeNamedItemNS("http://www.w3.org/2000/xmlns/","xml");
              } catch (DOMException e) {}
              doc.appendChild(copy);             
              data.setDocument(doc);
             
              ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart) part)
                  .setData(data);
             
            }
           
          } catch (javax.xml.bind.UnmarshalException ue) {
           
            // No ...
            CustomXmlDataStorage data = Load.getCustomXmlDataStorageClass().factory();

            // Copy el into a new document
            org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument();
            //XmlUtils.treeCopy(el, doc);
            org.w3c.dom.Node copy = doc.importNode(el, true);
            try {
              copy.getAttributes().removeNamedItemNS("http://www.w3.org/2000/xmlns/","xml");
            } catch (DOMException e) {}
            doc.appendChild(copy);             
            data.setDocument(doc);
           
            ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart) part)
                .setData(data);
          }         
         
         
        } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) {
         
          // Copy el into a new document
          org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument();
          //XmlUtils.treeCopy(el, doc);
          org.w3c.dom.Node copy = doc.importNode(el, true);
          try {
            copy.getAttributes().removeNamedItemNS("http://www.w3.org/2000/xmlns/","xml");
            // May not be required here. Not tested.
          } catch (DOMException e) {}
          doc.appendChild(copy);             
         
          ((XmlPart)part).setDocument(doc);

        } else {
          // Shouldn't happen, since ContentTypeManagerImpl should
          // return an instance of one of the above, or throw an
          // Exception.
         
          log.error("No suitable part found for: " + pkgPart.getName());
          part = null;         
        }
      } catch (java.lang.IllegalArgumentException e) {

        if (el!=null) {
          log.error(e.getMessage());
          log.error(XmlUtils.w3CDomNodeToString(el));
        }
        throw e;       
       
      } catch (PartUnrecognisedException e) {

        // Try to get it as a binary part
        log.error("Part unrecognised: " + pkgPart.getName());
        part = new BinaryPart( new PartName(pkgPart.getName())); // /?
        ((BinaryPart)part).setBinaryData( pkgPart.getBinaryData() );
      }
    } catch (Exception ex) {
      // IOException, URISyntaxException
      ex.printStackTrace();
View Full Code Here

   */
  public PartName getPartName() {
    if (partName==null) {
      log.error("PartName was null!");
      try {
        return new PartName("/null");
      } catch (Exception e) {
        log.error(e.getMessage());
        // TODO: handle exception
      }
    }
View Full Code Here

      // Could have just passed String relType
      // Null where used from BPAI, and a FlatOpcXmlImporter case.
      // Cases where rel is not available can prepare a suitable dummy
     
      AlternativeFormatInputPart afip =
        new AlternativeFormatInputPart(new PartName(partName) );
      afip.setContentType(new ContentType(contentType));
      return afip;
     
    } else if (rel!=null && rel.getType().equals(Namespaces.EMBEDDED_PKG) ) {
     
      EmbeddedPackagePart epp = new EmbeddedPackagePart(new PartName(partName) );
      epp.setContentType(new ContentType(contentType));
      return epp;

    } else if (rel!=null && rel.getType().equals(Namespaces.OLE_OBJECT) ) {
     
      OleObjectBinaryPart olePart = new OleObjectBinaryPart(new PartName(partName));
      olePart.setContentType(new ContentType(contentType));
      return olePart;
     
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT)) {
      return CreateMainDocumentPartObject(partName);
      // how is the main document distinguished from the glossary document?
      // Answer:- Main Document is a Package level relationship target,
      // whereas the Glossary Document is a Part-level target (from the
      // Main Document part)           
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED)) {
      return CreateMainDocumentPartObject(partName);
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_TEMPLATE)) {
      return CreateMainDocumentPartObject(partName);
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_TEMPLATE_MACROENABLED)) {
      return CreateMainDocumentPartObject(partName);
    } else if (contentType.equals(ContentTypes.PACKAGE_COREPROPERTIES)) {
      return CreateDocPropsCorePartObject(partName );
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMPROPERTIES)) {
      return CreateDocPropsCustomPartObject(partName );
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_EXTENDEDPROPERTIES)) {
      return CreateDocPropsExtendedPartObject(partName );
     
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE)) {
     
      // NB, since this is just "application/xml", it
      return new org.docx4j.openpackaging.parts.CustomXmlDataStoragePart(new PartName(partName));
     
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGEPROPERTIES)) {
      return CreateCustomXmlDataStoragePropertiesPartObject(partName );     
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_FONT)) {
      return CreateObfuscatedFontPartObject(partName );
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_OLE_OBJECT)
        || contentType.equals(ContentTypes.OFFICEDOCUMENT_ACTIVEX_OBJECT)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_ACTIVEX_XML_OBJECT)) {
      return new org.docx4j.openpackaging.parts.ActiveXControlXmlPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_THEME)) {
      return CreateThemePartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_COMMENTS)) {
      return CreateCommentsPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_ENDNOTES)) {
      return CreateEndnotesPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FONTTABLE)) {
      return CreateFontTablePartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FOOTER)) {
      return CreateFooterPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_FOOTNOTES)) {
      return CreateFootnotesPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_GLOSSARYDOCUMENT)) {
      return CreateGlossaryDocumentPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_HEADER)) {
      return CreateHeaderPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_NUMBERING)) {
      return CreateNumberingPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_SETTINGS)) {
      return CreateDocumentSettingsPartObject(partName );
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_STYLES)) {
      return CreateStyleDefinitionsPartObject( partName);
    } else if (contentType.equals(ContentTypes.WORDPROCESSINGML_WEBSETTINGS)) {
      return CreateWebSettingsPartObject(partName );
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_DATA)) {
      return new VbaDataPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_PROJECT)) {
      return new VbaProjectBinaryPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_VBA_PROJECT_SIGNATURE)) {
      return new VbaProjectSignatureBin(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_JPEG)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.ImageJpegPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_PNG)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.ImagePngPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_GIF)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.ImageGifPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_TIFF)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.ImageTiffPart(new PartName(partName));
//    } else if (contentType.equals(ContentTypes.IMAGE_EPS)) {
//      return new org.docx4j.openpackaging.parts.WordprocessingML.ImageEpsPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_BMP)) {
      return new org.docx4j.openpackaging.parts.WordprocessingML.ImageBmpPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_EMF) || contentType.equals(ContentTypes.IMAGE_EMF2)) {
      return new MetafileEmfPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.IMAGE_WMF)) {
      return new MetafileWmfPart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.VML_DRAWING)) {
      return new VMLPart(new PartName(partName));
//      return new VMLBinaryPart(new PartName(partName));       
    } else if (contentType.equals(ContentTypes.DRAWINGML_DIAGRAM_DRAWING)) {
      return new org.docx4j.openpackaging.parts.DrawingML.DiagramDrawingPart(new PartName(partName));
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.drawing")) {
      try {
        return JaxbDmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.presentation")
        || contentType.equals(ContentTypes.PRESENTATIONML_MACROENABLED)
        || contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE)
        || contentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED)
            ) {
      try {
        return JaxbPmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK)
        || contentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED)
        || contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE)
        || contentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE_MACROENABLED)) {
      try {
        return new WorkbookPart(new PartName(partName));
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
     
    } else if (contentType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml")) {
      try {
        return JaxbSmlPart.newPartForContentType(contentType, partName);
      } catch (Exception e) {
        return new BinaryPart( new PartName(partName));       
      }
    } else if (contentType.equals(ContentTypes.OFFICEDOCUMENT_THEME_OVERRIDE)) {
      return new org.docx4j.openpackaging.parts.DrawingML.ThemeOverridePart(new PartName(partName));   
    } else if (contentType.equals(ContentTypes.DIGITAL_SIGNATURE_XML_SIGNATURE_PART)) {
      return new org.docx4j.openpackaging.parts.digitalsignature.XmlSignaturePart(new PartName(partName));
    } else if (contentType.equals(ContentTypes.APPLICATION_XML)
        || partName.endsWith(".xml")) {
     
      // Rarely (but sometimes) used, owing to OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE above.
     
      // Simple minded detection of XML content.
      // If it turns out not to be XML, the zip loader
      // will catch the error and load it as a binary part instead.
      log.warn("DefaultPart used for part '" + partName
          + "' of content type '" + contentType + "'");
      return CreateDefaultXmlPartObject(partName );
     
    } else if (contentType.equals(ContentTypes.PRESENTATIONML_FONT_DATA)) {
     
      return new FontDataPart(new PartName(partName));
     
    } else {
     
      log.error("No subclass found for " + partName + "; defaulting to binary");
      //throw new PartUnrecognisedException("No subclass found for " + partName + " (content type '" + contentType + "')");   
      return new BinaryPart( new PartName(partName));
    }

  }
View Full Code Here

    super(partName);
    init();   
  }

  public XmlSignaturePart() throws InvalidFormatException {
    super(new PartName("/_xmlsignatures/sig1.xml"));
    init();   
  }
View Full Code Here

    super(partName);
    init();
  }

  public SlideLayoutPart() throws InvalidFormatException {
    super(new PartName("/ppt/slideLayouts/slideLayout1.xml"));
    init();
  }
View Full Code Here

   * Constructor.  Also creates a new content type manager
   *
   */
  public OpcPackage() {
    try {
      this.setPartName(new PartName("/", false));
     
      contentTypeManager = new ContentTypeManager();
    } catch (Exception e) {
      log.error(e.getMessage());
      // TODO: handle exception
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.PartName

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.