Examples of OdfContentDom


Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  }

  private void copyForeignStyleRef(OdfElement sourceCloneEle,
      OdfPresentationDocument doc) {
    try {
      OdfContentDom contentDom = getContentDom();
      XPath xpath = contentDom.getXPath();
      //1. collect all the referred style element which has "style:name" attribute
      //1.1. style:name of content.xml
      String styleQName = "style:name";
      NodeList srcStyleDefNodeList = (NodeList) xpath.evaluate("//*[@" + styleQName + "]", contentDom, XPathConstants.NODESET);
      HashMap<OdfElement, List<OdfElement>> srcContentStyleCloneEleList = new HashMap<OdfElement, List<OdfElement>>();
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

    // before creating a new dom, make sure that there no DOM opened for this file already
    Document existingDom = packageDocument.getPackage().getCachedDom(packagePath);
    if (existingDom == null) {
      // ToDo: bug 264 - register OdfFileDom to this class
      if (packagePath.equals("content.xml") || packagePath.endsWith("/content.xml")) {
        newFileDom = new OdfContentDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("styles.xml") || packagePath.endsWith("/styles.xml")) {
        newFileDom = new OdfStylesDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("meta.xml") || packagePath.endsWith("/meta.xml")) {
        newFileDom = new OdfMetaDom((OdfSchemaDocument) packageDocument, packagePath);
      } else if (packagePath.equals("settings.xml") || packagePath.endsWith("/settings.xml")) {
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  }

  @Test
  public void testSetDefaultCellStyle() {
    SpreadsheetDocument outputDocument;
    OdfContentDom contentDom; // the document object model for content.xml
    // the office:automatic-styles element in content.xml
    OdfOfficeAutomaticStyles contentAutoStyles;
    OdfStyle style;
    String noaaDateStyleName;
    String noaaTempStyleName;

    try {
      outputDocument = SpreadsheetDocument.newSpreadsheetDocument();
      contentDom = outputDocument.getContentDom();
      contentAutoStyles = contentDom.getOrCreateAutomaticStyles();

      OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom, "yyyy-MM-dd", "numberDateStyle", null);
      OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom, "#0.00", "numberTemperatureStyle");

      contentAutoStyles.appendChild(dateStyle);
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  @Test
  public void testReplaceWithSimpleField() {
    try {
      search = new TextNavigation("ReplaceDateTarget", doc);
      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "ReplaceDateTarget" to FixedDateField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      // declare simple variable
      VariableField simpleVariableField = Fields.createSimpleVariableField(doc, "test_con_variable");
      OdfTextParagraph varParagraph = doc.newParagraph("test_con_variable:");
      simpleVariableField.updateField("true", varParagraph);
      // count the initial date field count.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 2 "ReplaceConditionTarget" to ConditionField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithConditionField("test_con_variable == \"true\"", "trueText", "falseText");
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      VariableField simpleVariableField = Fields.createSimpleVariableField(doc, "test_con_variable");
      OdfTextParagraph varParagraph = doc.newParagraph("test_con_variable:");
      simpleVariableField.updateField("true", varParagraph);

      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 2 "ReplaceHiddenTextTarget" to HiddenTextField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithHiddenTextField("test_con_variable == \"true\"", "hiddenText");
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextConditionalTextElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
    } catch (Exception e) {
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

      search = new TextNavigation("ReplaceReferenceTarget", doc);
      TextSpanElement newTextSpanElement = doc.newParagraph("Selection Reference Content:").newTextSpanElement();
      newTextSpanElement.setTextContent("This is a test selection reference content.");
      ReferenceField referenceField = Fields.createReferenceField(newTextSpanElement, "selection-test-ref");
      // count the initial reference field count.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextReferenceRefElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextReferenceRefElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 2 "ReplaceReferenceTarget" to ReferenceField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithReferenceField(referenceField, DisplayType.TEXT);
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextReferenceRefElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextReferenceRefElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

    try {
      search = new TextNavigation("SelectionUserVariableTarget", doc);
      // declare variable
      VariableField userVariableField = Fields.createUserVariableField(doc, "selection_user_variable", "test");
      // count the initial variable field count.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextUserFieldGetElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextUserFieldGetElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "SelectionUserVariableTarget" to VariableField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        fieldSelection.replaceWithVariableField(userVariableField);
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextUserFieldGetElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextUserFieldGetElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  @Test
  public void testReplaceWithSimpleField2() {
    try {
      search = new TextNavigation("ReplaceDateTarget", doc);
      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "ReplaceDateTarget" to FixedDateField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        //fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
        fieldSelection.replaceWithSimpleField(Field.FieldType.DATE_FIELD)// 1
        //fieldSelection.replaceWithSimpleField(Field.FieldType.TIME_FIELD);  //3
        i++;
      }
     
      nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
     
View Full Code Here

Examples of org.odftoolkit.odfdom.dom.OdfContentDom

  @Test
  public void testReplaceWithSimpleField_time_field() {
    try {
      search = new TextNavigation("ReplaceDateTarget", doc);
      // count the initial date field count. should be 1.
      OdfContentDom contentDom = doc.getContentDom();
      NodeList nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
      int i = nodeList.getLength();
     
      //change all <code>ext:fixed</code> value be false
      for(int k =0;k<nodeList.getLength();k++){
        Node nv = nodeList.item(k);
        if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){
          NamedNodeMap nameMap = nv.getAttributes();
          Node nfix = nameMap.getNamedItem("text:fixed");
          nfix.setNodeValue("false");
        }
      }
     
      OdfStylesDom styleDom = doc.getStylesDom();
      nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
      i += nodeList.getLength();
      // replace all the 3 "ReplaceDateTarget" to FixedDateField.
      while (search.hasNext()) {
        TextSelection item = (TextSelection) search.nextSelection();
        FieldSelection fieldSelection = new FieldSelection(item);
        //fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
        fieldSelection.replaceWithSimpleField(Field.FieldType.TIME_FIELD);
        i++;
      }
      nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
      int j = nodeList.getLength();
      nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
      j += nodeList.getLength();
      Assert.assertEquals(j, i);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
     
      //validate 
      TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE));
      OdfContentDom contentDom1 = doc1.getContentDom();
     
      nodeList = contentDom1.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
      for(int k =0;k<nodeList.getLength();k++){
        //
        Node nv = nodeList.item(k);
        if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){
          NamedNodeMap nameMap = nv.getAttributes();
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.