gpt4 book ai didi

org.apache.poi.xwpf.usermodel.XWPFRelation类的使用及代码示例

转载 作者:知者 更新时间:2024-03-25 09:15:05 29 4
gpt4 key购买 nike

本文整理了Java中org.apache.poi.xwpf.usermodel.XWPFRelation类的一些代码示例,展示了XWPFRelation类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XWPFRelation类的具体详情如下:
包路径:org.apache.poi.xwpf.usermodel.XWPFRelation
类名称:XWPFRelation

XWPFRelation介绍

暂无

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

private int getRelationIndex(XWPFRelation relation) {
  int i = 1;
  for (RelationPart rp : doc.getRelationParts()) {
    if (rp.getRelationship().getRelationshipType().equals(relation.getRelation())) {
      i++;
    }
  }
  return i;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

PackagePart pp = getPackagePart();
if (pp.getContentType().equals(XWPFRelation.GLOSSARY_DOCUMENT.getContentType())) {
  logger.log(POILogger.WARN,
      "POI does not currently support template.main+xml (glossary) parts.  " +

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Create a new WordProcessingML package and setup the default minimal content
 */
protected static OPCPackage newPackage() {
  try {
    OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());    // NOSONAR - we do not want to close this here
    // Main part
    PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
    // Create main part relationship
    pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
    // Create main document part
    pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
    pkg.getPackageProperties().setCreatorProperty(DOCUMENT_CREATOR);
    return pkg;
  } catch (Exception e) {
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * @since POI 3.14-Beta1
 */
@Override
protected POIXMLRelation getDescriptor(String relationshipType) {
  return XWPFRelation.getInstance(relationshipType);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * @since POI 3.14-Beta1
 */
@Override
protected POIXMLRelation getDescriptor(String relationshipType) {
  return XWPFRelation.getInstance(relationshipType);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Gets the index of the relation we're trying to create
 *
 * @param relation
 * @return i
 */
private int getRelationIndex(XWPFRelation relation) {
  int i = 1;
  for (RelationPart rp : getRelationParts()) {
    if (rp.getRelationship().getRelationshipType().equals(relation.getRelation())) {
      i++;
    }
  }
  return i;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

if ( rel.getContentType().equals( contentType ) ) {
  return new XWPFWordExtractor(pkg);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Create a new WordProcessingML package and setup the default minimal content
 */
protected static OPCPackage newPackage() {
  try {
    OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());    // NOSONAR - we do not want to close this here
    // Main part
    PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
    // Create main part relationship
    pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
    // Create main document part
    pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
    pkg.getPackageProperties().setCreatorProperty(DOCUMENT_CREATOR);
    return pkg;
  } catch (Exception e) {
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

@Override
public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackageRelationship rel, PackagePart part){
  POIXMLRelation descriptor = XWPFRelation.getInstance(rel.getRelationshipType());
  if(descriptor == null || descriptor.getRelationClass() == null){
    logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
    return new POIXMLDocumentPart(part, rel);
  }
  try {
    Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
    try {
      Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(POIXMLDocumentPart.class, PackagePart.class, PackageRelationship.class);
      return constructor.newInstance(parent, part, rel);
    } catch (NoSuchMethodException e) {
      Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
      return constructor.newInstance(part, rel);
    }
  } catch (Exception e){
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private void initFootnotes() throws XmlException, IOException {
  for (RelationPart rp : getRelationParts()) {
    POIXMLDocumentPart p = rp.getDocumentPart();
    String relation = rp.getRelationship().getRelationshipType();
    if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
      this.footnotes = (XWPFFootnotes) p;
      this.footnotes.onDocumentRead();
      this.footnotes.setIdManager(footnoteIdManager);
    } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())) {
      this.endnotes = (XWPFEndnotes) p;
      this.endnotes.onDocumentRead();
      this.endnotes.setIdManager(footnoteIdManager);
    }
  }
}

代码示例来源:origin: apache/tika

/**
 * This returns all items that might contain embedded objects:
 * main document, headers, footers, comments, etc.
 */
@Override
protected List<PackagePart> getMainDocumentParts() {
  List<PackagePart> mainStoryDocs = getStoryDocumentParts();
  List<PackagePart> relatedParts = new ArrayList<>();
  mainStoryDocs.addAll(
      opcPackage.getPartsByContentType(
          XWPFRelation.GLOSSARY_DOCUMENT.getContentType()));
  for (PackagePart pp : mainStoryDocs) {
    addRelatedParts(pp, relatedParts);
  }
  relatedParts.addAll(mainStoryDocs);
  return relatedParts;
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Create a new WordProcessingML package and setup the default minimal content
 */
protected static OPCPackage newPackage() {
   try {
    OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
    // Main part
    PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
    // Create main part relationship
    pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
    // Create main document part
    pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
    pkg.getPackageProperties().setCreatorProperty(DOCUMENT_CREATOR);
    return pkg;
  } catch (Exception e){
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private void initHyperlinks() {
  // Get the hyperlinks
  // TODO: make me optional/separated in private function
  try {
    for (PackageRelationship rel : getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation())) {
      hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
    }
  } catch (InvalidFormatException e) {
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: apache/tika

StringBuilder sb = new StringBuilder();
List<PackagePart> pps = container.getPartsByContentType(XWPFRelation.DOCUMENT.getContentType());
if (pps != null) {
  for (PackagePart pp : pps) {
pps = container.getPartsByContentType(XWPFRelation.GLOSSARY_DOCUMENT.getContentType());

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Returns the styles object used
 */
@Internal
public CTStyles getStyle() throws XmlException, IOException {
  PackagePart[] parts;
  try {
    parts = getRelatedByType(XWPFRelation.STYLES.getRelation());
  } catch (InvalidFormatException e) {
    throw new IllegalStateException(e);
  }
  if (parts.length != 1) {
    throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
  }
  StylesDocument sd = StylesDocument.Factory.parse(parts[0].getInputStream(), DEFAULT_XML_OPTIONS);
  return sd.getStyles();
}

代码示例来源:origin: apache/tika

@Override
protected void buildXHTML(XHTMLContentHandler xhtml)
    throws SAXException, XmlException, IOException {
  //handle main document
  List<PackagePart> pps = getStoryDocumentParts();
  if (pps != null) {
    for (PackagePart pp : pps) {
      //likely only one, but why not...
      handleDocumentPart(pp, xhtml);
    }
  }
  //handle glossary document
  pps = opcPackage.getPartsByContentType(XWPFRelation.GLOSSARY_DOCUMENT.getContentType());
  if (pps != null) {
    if (pps.size() > 0) {
      xhtml.startElement("div", "class", "glossary");
      for (PackagePart pp : pps) {
        //likely only one, but why not...
        handleDocumentPart(pp, xhtml);
      }
      xhtml.endElement("div");
    }
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

POIXMLDocumentPart p = rp.getDocumentPart();
String relation = rp.getRelationship().getRelationshipType();
if (relation.equals(XWPFRelation.STYLES.getRelation())) {
  this.styles = (XWPFStyles) p;
  this.styles.onDocumentRead();
} else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) {
  this.numbering = (XWPFNumbering) p;
  this.numbering.onDocumentRead();
} else if (relation.equals(XWPFRelation.FOOTER.getRelation())) {
  XWPFFooter footer = (XWPFFooter) p;
  footers.add(footer);
  footer.onDocumentRead();
} else if (relation.equals(XWPFRelation.HEADER.getRelation())) {
  XWPFHeader header = (XWPFHeader) p;
  headers.add(header);
  header.onDocumentRead();
} else if (relation.equals(XWPFRelation.COMMENT.getRelation())) {
} else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) {
  settings = (XWPFSettings) p;
  settings.onDocumentRead();
} else if (relation.equals(XWPFRelation.IMAGES.getRelation())) {
  XWPFPictureData picData = (XWPFPictureData) p;
  picData.onDocumentRead();
  registerPackagePictureData(picData);
  pictures.add(picData);
} else if (relation.equals(XWPFRelation.CHART.getRelation())) {
} else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) {

代码示例来源:origin: apache/tika

private static POIXMLTextExtractor trySXWPF(OPCPackage pkg) throws XmlException, OpenXML4JException, IOException {
  PackageRelationshipCollection packageRelationshipCollection = pkg.getRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
  if (packageRelationshipCollection.size() == 0) {
    packageRelationshipCollection = pkg.getRelationshipsByType("http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument");
  }
  if (packageRelationshipCollection.size() == 0) {
    return null;
  }
  PackagePart corePart = pkg.getPart(packageRelationshipCollection.getRelationship(0));
  String targetContentType = corePart.getContentType();
  for (XWPFRelation relation : XWPFWordExtractor.SUPPORTED_TYPES) {
    if (targetContentType.equals(relation.getContentType())) {
      return new XWPFEventBasedWordExtractor(pkg);
    }
  }
  return null;
}

代码示例来源:origin: apache/tika

private Map<String, String> loadHyperlinkRelationships(PackagePart bodyPart) {
  Map<String, String> hyperlinks = new HashMap<>();
  try {
    PackageRelationshipCollection prc = bodyPart.getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation());
    for (int i = 0; i < prc.size(); i++) {
      PackageRelationship pr = prc.getRelationship(i);
      if (pr == null) {
        continue;
      }
      String id = pr.getId();
      String url = (pr.getTargetURI() == null) ? null : pr.getTargetURI().toString();
      if (id != null && url != null) {
        hyperlinks.put(id, url);
      }
    }
  } catch (InvalidFormatException e) {
    LOG.warn("Invalid format", e);
  }
  return hyperlinks;
}

代码示例来源:origin: apache/tika

XWPFRelation.DOCUMENT.getContentType(),
xhtml, relationshipsManager, officeParserConfig));
XWPFRelation.FOOTNOTE.getContentType(),
xhtml, relationshipsManager, officeParserConfig));
XWPFRelation.HEADER.getContentType(),
xhtml, relationshipsManager, officeParserConfig));
XWPFRelation.FOOTER.getContentType(),
xhtml, relationshipsManager, officeParserConfig));

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com