@Test
  public void testGetRecursiveChildIter() {
    final Document doc = XMLFactory.newDocument();

    // No children present
    assertFalse(new ChildElementIterator(doc).hasNext());

    // 1 child
    final Element eRoot = (Element) doc.appendChild(doc.createElement("root"));
    assertEquals(1, ContainerHelper.newList(new ChildElementIterator(doc)).size());

    // 2 children
    eRoot.appendChild(doc.createElement("Hallo"));
    eRoot.appendChild(doc.createTextNode(" - "));
    eRoot.appendChild(doc.createElement("Welt"));
    assertEquals(2, ContainerHelper.newList(new ChildElementIterator(eRoot)).size());
    assertEquals(
        1,
        ContainerHelper.newList(
                new ChildElementIterator(eRoot, new FilterElementWithTagName("Hallo")))
            .size());

    try {
      new ChildElementIterator(doc).remove();
      fail();
    } catch (final UnsupportedOperationException ex) {
    }
    try {
      new ChildElementIterator(null);
      fail();
    } catch (final NullPointerException ex) {
    }
  }
Пример #2
0
 @Test
 public void testBasicExport() {
   final ExportRecord aRecordWithAllTypes =
       new ExportRecord()
           .addField("Hallo")
           .addField(PDTFactory.getCurrentLocalTime())
           .addField(PDTFactory.getCurrentLocalDate())
           .addField(PDTFactory.getCurrentLocalDateTime())
           .addField(PDTFactory.getCurrentDateTime())
           .addField(true)
           .addField(4711)
           .addField(-123456789012345L)
           .addField(new BigInteger("1234512345123451234512345123451234512345123451234512345"))
           .addField(3.1415)
           .addField(new BigDecimal("12345123451234512345123451234512345123451234512345.12345"));
   final ExportRecord aEmptyRecord = new ExportRecord();
   final ExporterCSV aExporter = new ExporterCSV(CCharset.CHARSET_ISO_8859_1_OBJ);
   // Fails because no record is present
   assertTrue(
       aExporter
           .exportRecords(new EmptyExportRecordProvider(), new NonBlockingByteArrayOutputStream())
           .isFailure());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(ContainerHelper.newList(aRecordWithAllTypes)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   ContainerHelper.newList(
                       aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord)),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   null,
                   ContainerHelper.newList(aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
   assertTrue(
       aExporter
           .exportRecords(
               new ConstantExportRecordProvider(
                   aRecordWithAllTypes,
                   ContainerHelper.newList(aRecordWithAllTypes, aRecordWithAllTypes, aEmptyRecord),
                   aRecordWithAllTypes),
               new NonBlockingByteArrayOutputStream())
           .isSuccess());
 }
Пример #3
0
 @Nonnull
 @ReturnsMutableCopy
 public List<IDirectedGraphRelation> getAllIncomingRelations() {
   return m_aIncoming == null
       ? new ArrayList<IDirectedGraphRelation>()
       : ContainerHelper.newList(m_aIncoming.values());
 }
 @Override
 @Nullable
 public List<String> getAttributeValues(
     @Nullable final String sName, @Nullable final List<String> aDefault) {
   final Object aValue = getAttributeObject(sName);
   if (aValue instanceof String[]) {
     // multiple values passed in the request
     return ContainerHelper.newList((String[]) aValue);
   }
   if (aValue instanceof String) {
     // single value passed in the request
     return ContainerHelper.newList((String) aValue);
   }
   // E.g. for file items
   return aDefault;
 }
Пример #5
0
 @Test
 public void testCreate() {
   assertFalse(new HCSmall().hasChildren());
   assertEquals(0, HCSmall.create((IPredefinedLocaleTextProvider) null).getChildCount());
   assertEquals(
       0,
       HCSmall.create((IPredefinedLocaleTextProvider) null, (IPredefinedLocaleTextProvider) null)
           .getChildCount());
   assertEquals(0, HCSmall.create((IHCNodeBuilder) null).getChildCount());
   assertEquals(0, HCSmall.create((IHCNodeBuilder) null, (IHCNodeBuilder) null).getChildCount());
   assertEquals(1, HCSmall.create("Text").getChildCount());
   assertEquals(0, HCSmall.create((String) null).getChildCount());
   assertEquals(1, HCSmall.create(HCB.create("Bold")).getChildCount());
   assertEquals(0, HCSmall.create((IHCNode) null).getChildCount());
   assertEquals(3, HCSmall.create("Hallo", "Welt", "!!!").getChildCount());
   assertEquals(0, HCSmall.create(new String[0]).getChildCount());
   assertEquals(0, HCSmall.create((String[]) null).getChildCount());
   assertEquals(2, HCSmall.create(HCB.create("Bold"), HCI.create("Italic")).getChildCount());
   assertEquals(0, HCSmall.create(new IHCNode[0]).getChildCount());
   assertEquals(0, HCSmall.create((IHCNode[]) null).getChildCount());
   assertEquals(
       2,
       HCSmall.create(ContainerHelper.newList(HCB.create("Bold"), HCI.create("Italic")))
           .getChildCount());
   assertEquals(0, HCSmall.create(new ArrayList<IHCNode>()).getChildCount());
 }
Пример #6
0
 @Nonnull
 @ReturnsMutableCopy
 public List<CSSItem> getAllItems() {
   m_aRWLock.readLock().lock();
   try {
     return ContainerHelper.newList(m_aItems);
   } finally {
     m_aRWLock.readLock().unlock();
   }
 }
Пример #7
0
 /**
  * Interpret the passed XHTML fragment as HTML and retrieve a result container with all body
  * elements.
  *
  * @param sXHTML The XHTML text fragment. This fragment is parsed as an HTML body and may
  *     therefore not contain the &lt;body&gt; tag.
  * @return <code>null</code> if the passed text could not be interpreted as XHTML or if no body
  *     element was found, an {@link IMicroContainer} with all body children otherwise.
  */
 @Nullable
 public IMicroContainer unescapeXHTMLFragment(@Nullable final String sXHTML) {
   // Ensure that the content is surrounded by a single tag
   final IMicroDocument aDoc = parseXHTMLFragment(sXHTML);
   if (aDoc != null && aDoc.getDocumentElement() != null) {
     // Find "body" case insensitive
     final IMicroElement eBody =
         HCUtils.getFirstChildElement(aDoc.getDocumentElement(), EHTMLElement.BODY);
     if (eBody != null) {
       final IMicroContainer ret = new MicroContainer();
       if (eBody.hasChildren()) {
         // Make a copy of the list, because it is modified in
         // detachFromParent!
         for (final IMicroNode aChildNode : ContainerHelper.newList(eBody.getChildren()))
           ret.appendChild(aChildNode.detachFromParent());
       }
       return ret;
     }
   }
   return null;
 }
Пример #8
0
 /**
  * Returns all arguments of the invocation.
  *
  * @return If there's no arguments, an empty array will be returned.
  */
 @Nonnull
 @ReturnsMutableCopy
 public List<IJSExpression> args() {
   return ContainerHelper.newList(this.m_aArgs);
 }
 /** @return A list of all XSD resources used for validation. Never <code>null</code>. */
 @Nonnull
 @Nonempty
 @ReturnsMutableCopy
 public final List<IReadableResource> getOriginalXSDs() {
   return ContainerHelper.newList(m_aXSDs);
 }
Пример #10
0
 @Override
 @Nonnull
 @ReturnsMutableCopy
 public List<DATATYPE> getValues() {
   return ContainerHelper.newList(getData());
 }
Пример #11
0
 /**
  * Ctor
  *
  * @param aList List to use as the basis
  */
 public JSONPropertyValueList(@Nullable final Iterable<? extends DATATYPE> aList) {
   super(ContainerHelper.newList(aList));
 }
Пример #12
0
 @Nonnull
 @ReturnsMutableCopy
 public List<FeedEntry> getAllEntries() {
   return ContainerHelper.newList(m_aEntries);
 }