Examples of OdfElement


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 = "./";
          if (refObjPath.startsWith(prefix)) {
            refObjPath = refObjPath.substring(2);
            hasPrefix = true;
          }
          // 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 + "/");
          }
          String 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);
          }
          InputStream is = srcDoc.getPackage().getInputStream(refObjPath);
          if (is != null) {
            String mediaType = srcDoc.getPackage().getFileEntry(refObjPath).getMediaTypeString();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

          XPathConstants.NODESET);
      IdentityHashMap<OdfElement, List<OdfElement>> srcDrawStyleCloneEleList = new IdentityHashMap<OdfElement, List<OdfElement>>();
      IdentityHashMap<OdfElement, OdfElement> appendDrawStyleList = new IdentityHashMap<OdfElement, OdfElement>();
      Iterator<OdfElement> iter = appendContentStyleList.keySet().iterator();
      while (iter.hasNext()) {
        OdfElement styleElement = iter.next();
        OdfElement cloneStyleElement = appendContentStyleList.get(styleElement);
        getCopyStyleList(styleElement, cloneStyleElement, styleQName, srcStyleDefNodeList,
            srcDrawStyleCloneEleList, appendDrawStyleList, tempList, false);
      }
      iter = appendStylesStyleList.keySet().iterator();
      while (iter.hasNext()) {
        OdfElement styleElement = iter.next();
        OdfElement cloneStyleElement = appendStylesStyleList.get(styleElement);
        getCopyStyleList(styleElement, cloneStyleElement, styleQName, srcStyleDefNodeList,
            srcDrawStyleCloneEleList, appendDrawStyleList, tempList, false);
      }
      // 2.2 rename, copy the referred style element to the corresponding
      // position in the dom tree
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

            XPathConstants.NODESET);
      else
        destStyleNodeList = (NodeList) xpath.evaluate(".//*[@" + styleQName + "]", dom, XPathConstants.NODESET);
      Iterator<OdfElement> iter = srcStyleCloneEleList.keySet().iterator();
      while (iter.hasNext()) {
        OdfElement styleElement = iter.next();
        OdfElement cloneStyleElement = appendStyleList.get(styleElement);
        if (cloneStyleElement == null) {
          cloneStyleElement = (OdfElement) styleElement.cloneNode(true);
          appendStyleList.put(styleElement, cloneStyleElement);
        }
        String styleName = styleElement.getAttributeNS(styleURI, styleLocalName);
        List<String> newStyleNameList = styleRenameMap.get(styleName);
        // if the newStyleNameList != null, means that styleName exists
        // in dest document
        // and it has already been renamed
        if ((newStyleNameList != null) || (isStyleNameExist(destStyleNodeList, styleName) != null)) {
          String newStyleName = null;
          if (newStyleNameList == null) {
            newStyleNameList = new ArrayList<String>();
            newStyleName = styleName + "-" + makeUniqueName();
            newStyleNameList.add(newStyleName);
            styleRenameMap.put(styleName, newStyleNameList);
          } else {
            for (int i = 0; i < newStyleNameList.size(); i++) {
              String styleNameIter = newStyleNameList.get(i);
              OdfElement destStyleElementWithNewName = isStyleNameExist(destStyleNodeList, styleNameIter);
              // check if the two style elements have the same
              // content
              // if not, the cloneStyleElement should rename,
              // rather than reuse the new style name
              cloneStyleElement.setAttributeNS(styleURI, styleQName, styleNameIter);
              if ((destStyleElementWithNewName != null)
                  && destStyleElementWithNewName.equals(cloneStyleElement)) {
                newStyleName = styleNameIter;
                break;
              }
            }
            if (newStyleName == null) {
              newStyleName = styleName + "-" + makeUniqueName();
              newStyleNameList.add(newStyleName);
            }
          }
          // System.out.println("renaming:"+styleName+"-"+newStyleName);
          // if newStyleName has been set in the element as the new
          // name
          // which means that the newStyleName is conform to the odf
          // spec
          // then change element style reference name
          if (changeStyleRefName(srcStyleCloneEleList.get(styleElement), styleName, newStyleName)) {
            cloneStyleElement.setAttributeNS(styleURI, styleQName, newStyleName);
            // if display name should also be renamed
            String displayName = cloneStyleElement.getAttributeNS(styleURI, "display-name");
            if ((displayName != null) && (displayName.length() > 0)) {
              cloneStyleElement.setAttributeNS(styleURI, stylePrefix + ":display-name", displayName
                  + newStyleName.substring(newStyleName.length() - 8));
            }
          }
        }
      }

      iter = appendStyleList.keySet().iterator();
      while (iter.hasNext()) {
        OdfElement styleElement = iter.next();
        OdfElement cloneStyleElement = appendStyleList.get(styleElement);
        String newStyleName = cloneStyleElement.getAttributeNS(styleURI, styleLocalName);
        Boolean isAppended = styleAppendMap.get(newStyleName);
        // if styleAppendMap contain the newStyleName,
        // means that cloneStyleElement has already been appended
        if ((isAppended != null) && isAppended.booleanValue() == true) {
          continue;
        } else {
          styleAppendMap.put(newStyleName, true);
        }
        OdfElement cloneForeignStyleElement = (OdfElement) cloneForeignElement(cloneStyleElement, dom, true);
        String styleElePath = getElementPath(styleElement);
        appendForeignStyleElement(cloneForeignStyleElement, dom, styleElePath);
        copyLinkedRef(cloneStyleElement);
      }
    } catch (Exception e) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

  /*
   * Find next <code>TextSelection</code> which match specified style.
   */
  private TextSelection findNext(TextSelection selected) {
    OdfElement element = null;
    try {
      Node rootNode = mTextDocument.getContentRoot();
      if (selected == null) {
        mNode = getNextMatchElementInTree(rootNode, rootNode);
      } else {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

      if (stylePrefix.equals("draw"))
        styleURI = OdfDocumentNamespace.DRAW.getUri();
      // OdfElement override the "toString" method
      String cloneEleStr = cloneEle.toString();
      for (int i = 0; i < srcStyleNodeList.getLength(); i++) {
        OdfElement styleElement = (OdfElement) srcStyleNodeList.item(i);
        String styleName = styleElement.getAttributeNS(styleURI, styleLocalName);
        if (styleName != null) {
          int index = 0;
          index = cloneEleStr.indexOf("=\"" + styleName + "\"", index);
          while (index >= 0) {
            String subStr = cloneEleStr.substring(0, index);
            int lastSpaceIndex = subStr.lastIndexOf(' ');
            String attrStr = subStr.substring(lastSpaceIndex + 1, index);
            if (attrStr.equals(styleQName) || attrStrList.contains(attrStr + "=" + "\"" + styleName + "\"")) {
              index = cloneEleStr.indexOf("=\"" + styleName + "\"", index + styleName.length());
              continue;
            }
            attrStrList.add(attrStr + "=" + "\"" + styleName + "\"");
            XPath xpath = ((OdfFileDom) cloneEle.getOwnerDocument()).getXPath();
            NodeList styleRefNodes = (NodeList) xpath.evaluate(
                ".//*[@" + attrStr + "='" + styleName + "']", cloneEle, XPathConstants.NODESET);
            boolean isExist = false;
            for (int j = 0; j <= styleRefNodes.getLength(); j++) {
              OdfElement styleRefElement = null;
              if (j == styleRefNodes.getLength()) {
                isExist = isStyleNameRefExist(cloneEle, styleName, false);
                if (isExist) {
                  styleRefElement = cloneEle;
                } else {
                  continue;
                }
              } else {
                OdfElement tmpElement = (OdfElement) styleRefNodes.item(j);
                if (isStyleNameRefExist(tmpElement, styleName, false)) {
                  styleRefElement = tmpElement;
                } else {
                  continue;
                }
              }
              boolean hasLoopStyleDef = true;
              if (copyStyleEleList.get(styleElement) == null) {
                List<OdfElement> styleRefEleList = new ArrayList<OdfElement>();
                copyStyleEleList.put(styleElement, styleRefEleList);
                hasLoopStyleDef = false;
              }
              copyStyleEleList.get(styleElement).add(styleRefElement);

              OdfElement cloneStyleElement = appendStyleList.get(styleElement);
              if (cloneStyleElement == null) {
                cloneStyleElement = (OdfElement) styleElement.cloneNode(true);
                appendStyleList.put(styleElement, cloneStyleElement);
              }
              if (loop && !hasLoopStyleDef) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

        // should new the element since the current path node
        if (isExist) {
          isExist = false;
        }
        StringTokenizer token2 = new StringTokenizer(onePath, "@");
        OdfElement newElement = dom.createElementNS(OdfName.newName(token2.nextToken(), token2.nextToken()));
        parentNode.appendChild(newElement);
        parentNode = newElement;
      }
    }
    parentNode.appendChild(cloneStyleEle);
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

  // if false means that the newStyleName value is not conform to the ODF
  // spec, so do not modify the oldStyleName
  private boolean changeStyleRefName(List<OdfElement> list, String oldStyleName, String newStyleName) {
    boolean rtn = false;
    for (int index = 0; index < list.size(); index++) {
      OdfElement element = list.get(index);
      NamedNodeMap attributes = element.getAttributes();

      if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
          Node item = attributes.item(i);
          String value = item.getNodeValue();
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

  // check if nodeList contains the node that "style:name" attribute has the
  // same value with styleName
  // Note: nodeList here is all the style definition list
  private OdfElement isStyleNameExist(NodeList nodeList, String styleName) {
    for (int i = 0; i < nodeList.getLength(); i++) {
      OdfElement element = (OdfElement) nodeList.item(i);
      String name = element.getAttributeNS(OdfDocumentNamespace.STYLE.getUri(), "name");
      if (name.equals(styleName)) {
        // return true;
        return element;
      }
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

    try {
      OdfFileDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();
      NodeList linkNodes = (NodeList) xpath.evaluate("//*[@xlink:href]", contentDom, XPathConstants.NODESET);
      for (int i = 0; i < linkNodes.getLength(); i++) {
        OdfElement object = (OdfElement) linkNodes.item(i);
        String refObjPath = object.getAttributeNS(OdfDocumentNamespace.XLINK.getUri(), "href");
        int relation = odfEle.compareDocumentPosition(object);
        // if slide element contains the returned element which has the
        // xlink:href reference
        if ((relation & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0 && refObjPath != null
            && refObjPath.length() > 0) {
View Full Code Here

Examples of org.odftoolkit.odfdom.pkg.OdfElement

      // 2.2. get the reference of each style which occurred in the
      // current page
      for (int i = 0; i < stylesList.getLength(); i++) {
        Node item = stylesList.item(i);
        if (item instanceof OdfElement) {
          OdfElement node = (OdfElement) item;
          String styleName = node.getAttributeNS(OdfDocumentNamespace.STYLE.getUri(), "name");
          if (styleName != null) {
            // search the styleName contained at the current page
            // element
            NodeList styleNodes = (NodeList) xpath.evaluate("//*[@*='" + styleName + "']", contentDom,
                XPathConstants.NODESET);
            int styleCnt = styleNodes.getLength();
            if (styleCnt > 1) {
              // the first styleName is occurred in the style
              // definition
              // so check if the second styleName and last
              // styleName is occurred in the current page element
              // if yes, then remove it
              OdfElement elementFirst = (OdfElement) styleNodes.item(1);
              OdfElement elementLast = (OdfElement) styleNodes.item(styleCnt - 1);
              boolean isSamePage = false;
              if (elementFirst instanceof DrawPageElement) {
                DrawPageElement tempPage = (DrawPageElement) elementFirst;
                if (tempPage.equals(odfEle)) {
                  isSamePage = true;
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.