Package net.sourceforge.syncyoursecrets.xmlmapping

Examples of net.sourceforge.syncyoursecrets.xmlmapping.StringElement


   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object obj) {
    // TODO: stupid example impl.
    if (obj instanceof StringElement) {
      StringElement stringElement = (StringElement) obj;
      return stringElement.getElementName();
    }
    if (obj instanceof MappingElement) {
      MappingElement element = (MappingElement) obj;
      return element.getName();
    }
View Full Code Here


   *
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object obj) {
    if (obj instanceof StringElement) {
      StringElement stringElement = (StringElement) obj;
      return stringElement.getElementName();
    } else if (obj instanceof MappingElement) {
      MappingElement element = (MappingElement) obj;
      return element.getName();
    } else {
      logger.warn("Cannot provide label for unknown type " + obj);
View Full Code Here

      Map<Long, DateTime> times) throws Exception {

    ListElement list = new ListElement("list", null);

    for (Long key : names.keySet()) {
      StringElement entry = new StringElement(CHILD_NODE);
      entry.setContent(names.get(key));
      entry.setLastModified(times.get(key));
      entry.setId(key);
      list.add(entry);
    }
    return list;

  }
View Full Code Here

    assertEquals("List expected to contain all elements", 7L, list
        .getElements().keySet().size());

    for (Long key : names.keySet()) {
      assertTrue(list.getElements().containsKey(key));
      StringElement entry = (StringElement) list.getElements().get(key);

      assertEquals("Checking content of element " + key, expectedNames
          .get(key), entry.getContent());
      assertEquals("Checking last modification time on element " + key,
          expectedTimes.get(key), entry.getLastModified());

    }

  }
View Full Code Here

   *             the parser configuration exception
   */
  @Test
  public void testMerge() throws ParserConfigurationException {
    // create a newer StringElement
    StringElement newEntry = new StringElement(ENTRY_NAME);
    newEntry.setContent(UPDATED_CONTENT);
    newEntry.setId(TEST_ID);
    newEntry
        .setLastModified(DateTimeUtil.parseDateTime(UPDATED_TIME_STAMP));
    newEntry.setLastAction(MappingElement.ACTIONS.UPDATE);

    // create an "old" StringElement
    StringElement oldEntry = new StringElement(ENTRY_NAME);
    oldEntry.setContent(OLD_CONTENT);
    oldEntry.setId(TEST_ID);
    oldEntry.setLastModified(DateTimeUtil.parseDateTime(OLD_TIME_STAMP));
    oldEntry.setLastAction(MappingElement.ACTIONS.CREATE);

    // compare the merged Entry with the newest StringElement.
    StringElement mergedEntry = (StringElement) oldEntry.merge(newEntry);
    assertEquals("Comparing element name", ENTRY_NAME, mergedEntry
        .getElementName());
    assertEquals("Comparing content", UPDATED_CONTENT, mergedEntry
        .getContent());
    assertEquals("Comparing last modified timestamp", UPDATED_TIME_STAMP,
        DateTimeUtil.dateTime2String(mergedEntry.getLastModified()));
    assertEquals("Comparing last modification action",
        MappingElement.ACTIONS.UPDATE, mergedEntry.getLastAction());

  }
View Full Code Here

   */
  public void fillFromXml(File input) throws Exception {
    Document doc = XmlSerializeTool.readFile(input);

    Element root = doc.getDocumentElement();
    StringElement stringElement = new StringElement(root);
    assertEquals("Element name check", ENTRY_NAME, stringElement
        .getElementName());

    assertEquals("Check content", TEST_CONTENT, stringElement.getContent());

  }
View Full Code Here

   */
  public void toXml(File output) throws Exception {
    // create new document
    Document doc = XmlSerializeTool.createDocument();

    StringElement stringElement = new StringElement(ENTRY_NAME);
    stringElement.setContent(TEST_CONTENT);

    Element node = stringElement.toXml(doc);

    doc.appendChild(node);

    XmlSerializeTool.writeFile(doc, output);
  }
View Full Code Here

  public Document toXml() throws Exception {
    Document doc = XmlSerializeTool.createDocument();

    ListElement list = new ListElement(LIST_ELEMENT_NAME, null);

    StringElement stringElement = new StringElement(FIRST_ELEMENT_NAME);
    stringElement.setContent(FIRST_CONTENT);
    list.add(stringElement);

    StringElement otherElement = new StringElement(SECOND_ELEMENT_NAME);
    otherElement.setContent(SECOND_CONTENT);
    list.add(otherElement);

    Element root = list.toXml(doc);

    doc.appendChild(root);
View Full Code Here

    Iterator<MappingElement> it = list.iterator();

    int foundcount = 0;
    while (it.hasNext()) {
      StringElement current = (StringElement) it.next();
      if (current.getElementName().equals(FIRST_ELEMENT_NAME)) {
        assertEquals("Check content", FIRST_CONTENT, current
            .getContent());
        foundcount++;
      }
      if (current.getElementName().equals(SECOND_ELEMENT_NAME)) {
        assertEquals("Check content", SECOND_CONTENT, current
            .getContent());
        foundcount++;
      }

    }
View Full Code Here

TOP

Related Classes of net.sourceforge.syncyoursecrets.xmlmapping.StringElement

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.