Examples of OdfElement


Examples of org.odftoolkit.odfdom.pkg.OdfElement

  public void addComment(String content, String creator) throws InvalidNavigationException {
    if (validate() == false) {
      throw new InvalidNavigationException("No matched string at this position");
    }
    // create annotation element
    OdfElement parentElement = getContainerElement();
    OdfFileDom dom = (OdfFileDom) parentElement.getOwnerDocument();
    OfficeAnnotationElement annotationElement = dom.newOdfElement(OfficeAnnotationElement.class);
    // set creator
    DcCreatorElement dcCreatorElement = annotationElement.newDcCreatorElement();
    if (creator == null) {
      creator = System.getProperty("user.name");
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

   * Return a new span that cover this selection and keep the original style
   * of this <code>Selection</code>.
   */
  private OdfTextSpan getSpan(OdfFileDom ownerDoc) {

    OdfElement parentElement = getContainerElement();
    if (parentElement != null) {
      OdfElement copyParentNode = (OdfElement) parentElement.cloneNode(true);
      if (ownerDoc != parentElement.getOwnerDocument()) {
        copyParentNode = (OdfElement) ownerDoc.adoptNode(copyParentNode);
      }
      OdfTextSpan textSpan = new OdfTextSpan(ownerDoc);
      int sIndex = mIndexInContainer;
      int eIndex = sIndex + mMatchedText.length();
      // delete the content except the selection string
      // delete from the end to start, so that the postion will not be
      // impact by delete action
      delete(eIndex, TextExtractor.getText(copyParentNode).length() - eIndex, copyParentNode);
      delete(0, sIndex, copyParentNode);
      optimize(copyParentNode);
      Node childNode = copyParentNode.getFirstChild();
      while (childNode != null) {
        textSpan.appendChild(childNode.cloneNode(true));
        childNode = childNode.getNextSibling();
      }
      // apply text style for the textSpan
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

   */
  private boolean validate() {
    if (getContainerElement() == null) {
      return false;
    }
    OdfElement container = getContainerElement();
    if (container == null) {
      return false;
    }
    String content = TextExtractor.getText(container);
    if (content.indexOf(mMatchedText, mIndexInContainer) == mIndexInContainer) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

   * @throws Exception
   *             if the file DOM could not be created.
   */
  @SuppressWarnings("unchecked")
  protected <T extends OdfElement> T getContentRoot(Class<T> clazz) throws Exception {
    OdfElement contentRoot = getContentDom().getRootElement();
    OfficeBodyElement contentBody = OdfElement.findFirstChildNode(OfficeBodyElement.class, contentRoot);
    NodeList childs = contentBody.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
      Node cur = childs.item(i);
      if ((cur != null) && clazz.isInstance(cur)) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

  public Iterator<Section> getSectionIterator() {
    TextSectionElement element;
    ArrayList<Section> list = new ArrayList<Section>();
    try {
      // search in content.xml
      OdfElement root = getContentDom().getRootElement();
      OfficeBodyElement officeBody = OdfElement.findFirstChildNode(OfficeBodyElement.class, root);
      NodeList sectionList = officeBody.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "section");
      for (int i = 0; i < sectionList.getLength(); i++) {
        element = (TextSectionElement) sectionList.item(i);
        list.add(Section.getInstance(element));
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

   * @return a section object with a specific name
   */
  public Section getSectionByName(String name) {
    TextSectionElement element;
    try {
      OdfElement root = getContentDom().getRootElement();
      OfficeBodyElement officeBody = OdfElement.findFirstChildNode(OfficeBodyElement.class, root);
      XPath xpath = getContentDom().getXPath();
      String xpathValue = ".//text:section[@text:name=\"" + name + "\"]";
      element = (TextSectionElement) xpath.evaluate(xpathValue, officeBody, XPathConstants.NODE);
      if (element != null) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

   * @return Returns a duplicated element which is not in the DOM tree with
   *         the specified element
   */
  Node cloneForeignElement(Node element, OdfFileDom dom, boolean deep) {
    if (element instanceof OdfElement) {
      OdfElement cloneElement = dom.createElementNS(((OdfElement) element).getOdfName());

      NamedNodeMap attributes = element.getAttributes();
      if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
          Node item = attributes.item(i);
          String qname = null;
          String prefix = item.getPrefix();
          if (prefix == null) {
            qname = item.getLocalName();
          } else {
            qname = prefix + ":" + item.getLocalName();
          }

          cloneElement.setAttributeNS(item.getNamespaceURI(), qname, item.getNodeValue());
        }
      }

      if (deep) {
        Node childNode = element.getFirstChild();
        while (childNode != null) {
          cloneElement.appendChild(cloneForeignElement(childNode, dom, true));
          childNode = childNode.getNextSibling();
        }
      }

      return cloneElement;
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

      NodeList childList = (NodeList) xpath.evaluate(xpathValue, element, XPathConstants.NODESET);
      if (childList == null)
        return;

      for (int i = 0; i < childList.getLength(); i++) {
        OdfElement ele = (OdfElement) childList.item(i);
        Attr attri = ele.getAttributeNodeNS(OdfDocumentNamespace.XML.getUri(), "id");
        updateAttribute(attri);
      }
    } catch (Exception e) {
      Logger.getLogger(Document.class.getName()).log(Level.SEVERE, "Failed in updateXMLIds", e);
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

      String xpathValue = "descendant-or-self::node()[@text:name|@table:name|@draw:name|@chart:name]";
      NodeList childList = (NodeList) xpath.evaluate(xpathValue, element, XPathConstants.NODESET);
      if (childList == null)
        return;
      for (int i = 0; i < childList.getLength(); i++) {
        OdfElement ele = (OdfElement) childList.item(i);
        Attr attri = ele.getAttributeNodeNS(OdfDocumentNamespace.TEXT.getUri(), "name");
        if (attri != null)
          updateAttribute(attri);
        attri = ele.getAttributeNodeNS(OdfDocumentNamespace.TABLE.getUri(), "name");
        if (attri != null)
          updateAttribute(attri);
        if (ele instanceof DrawFrameElement)// only update draw:frame
        {
          attri = ele.getAttributeNodeNS(OdfDocumentNamespace.DRAW.getUri(), "name");
          if (attri != null)
            updateAttribute(attri);
        }
      }
    } catch (Exception e) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

      // new a map to put the original name and the rename string, in case
      // that the same name might be referred by the slide several times.
      HashMap<String, String> objectRenameMap = new HashMap<String, String>();
      NodeList linkNodes = (NodeList) xpath.evaluate(".//*[@xlink:href]", sourceCloneEle, XPathConstants.NODESET);
      for (int i = 0; i <= linkNodes.getLength(); i++) {
        OdfElement object = null;
        if (linkNodes.getLength() == i) {
          if (sourceCloneEle.hasAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href")) {
            object = sourceCloneEle;
          } else {
            break;
          }
        } else {
          object = (OdfElement) linkNodes.item(i);
        }
        String refObjPath = object.getAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href");
        if (refObjPath != null && refObjPath.length() > 0) {
          // the path of the object is start with "./"
          boolean hasPrefix = false;
          String prefix = "./";
          String newObjPath;
          if (refObjPath.startsWith(prefix)) {
            refObjPath = refObjPath.substring(2);
            hasPrefix = true;
          }
          // check if this linked resource has been copied
          if (objectRenameMap.containsKey(refObjPath)) {
            // this object has been copied already
            newObjPath = objectRenameMap.get(refObjPath);
            object.setAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "xlink:href",
                hasPrefix ? (prefix + newObjPath) : newObjPath);
            continue;
          }
          // check if the current document contains the same path
          OdfFileEntry fileEntry = getPackage().getFileEntry(refObjPath);
          // note: if refObjPath is a directory, it must end with '/'
          if (fileEntry == null) {
            fileEntry = getPackage().getFileEntry(refObjPath + "/");
          }
          newObjPath = refObjPath;
          if (fileEntry != null) {
            // rename the object path
            newObjPath = objectRenameMap.get(refObjPath);
            if (newObjPath == null) {
              // if refObjPath still contains ".", it means that
              // it has the suffix
              // then change the name before the suffix string
              int dotIndex = refObjPath.indexOf(".");
              if (dotIndex != -1) {
                newObjPath = refObjPath.substring(0, dotIndex) + "-" + makeUniqueName()
                    + refObjPath.substring(dotIndex);
              } else {
                newObjPath = refObjPath + "-" + makeUniqueName();
              }
              objectRenameMap.put(refObjPath, newObjPath);
            }
            object.setAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "xlink:href",
                hasPrefix ? (prefix + newObjPath) : newObjPath);
          } else
            objectRenameMap.put(refObjPath, refObjPath);
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.