当前位置: 首页>>代码示例>>Java>>正文


Java IMicroNode类代码示例

本文整理汇总了Java中com.helger.xml.microdom.IMicroNode的典型用法代码示例。如果您正苦于以下问题:Java IMicroNode类的具体用法?Java IMicroNode怎么用?Java IMicroNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IMicroNode类属于com.helger.xml.microdom包,在下文中一共展示了IMicroNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeToFile

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Write a Micro Node to a file.
 *
 * @param aNode
 *        The node to be serialized. May be any kind of node (incl.
 *        documents). May not be <code>null</code>.
 * @param aFile
 *        The file to write to. May not be <code>null</code>.
 * @param aSettings
 *        The settings to be used for the creation. May not be
 *        <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
public static ESuccess writeToFile (@Nonnull final IMicroNode aNode,
                                    @Nonnull final File aFile,
                                    @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aFile, "File");

  final OutputStream aOS = FileHelper.getOutputStream (aFile);
  if (aOS == null)
    return ESuccess.FAILURE;

  // No need to wrap the OS in a BufferedOutputStream as inside, it is later
  // on wrapped in a BufferedWriter
  return writeToStream (aNode, aOS, aSettings);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:29,代码来源:MicroWriter.java

示例2: writeToStream

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Write a Micro Node to an {@link OutputStream}.
 *
 * @param aNode
 *        The node to be serialized. May be any kind of node (incl.
 *        documents). May not be <code>null</code>.
 * @param aOS
 *        The output stream to write to. May not be <code>null</code>. The
 *        output stream is closed anyway directly after the operation finishes
 *        (on success and on error).
 * @param aSettings
 *        The settings to be used for the creation. May not be
 *        <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
public static ESuccess writeToStream (@Nonnull final IMicroNode aNode,
                                      @Nonnull @WillClose final OutputStream aOS,
                                      @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aOS, "OutputStream");
  ValueEnforcer.notNull (aSettings, "Settings");

  try
  {
    final MicroSerializer aSerializer = new MicroSerializer (aSettings);
    aSerializer.write (aNode, aOS);
    return ESuccess.SUCCESS;
  }
  finally
  {
    StreamHelper.close (aOS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:36,代码来源:MicroWriter.java

示例3: writeToWriter

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Write a Micro Node to a {@link Writer}.
 *
 * @param aNode
 *        The node to be serialized. May be any kind of node (incl.
 *        documents). May not be <code>null</code>.
 * @param aWriter
 *        The writer to write to. May not be <code>null</code>. The writer is
 *        closed anyway directly after the operation finishes (on success and
 *        on error).
 * @param aSettings
 *        The settings to be used for the creation. May not be
 *        <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
public static ESuccess writeToWriter (@Nonnull final IMicroNode aNode,
                                      @Nonnull @WillClose final Writer aWriter,
                                      @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aWriter, "Writer");
  ValueEnforcer.notNull (aSettings, "Settings");

  try
  {
    final MicroSerializer aSerializer = new MicroSerializer (aSettings);
    aSerializer.write (aNode, aWriter);
    return ESuccess.SUCCESS;
  }
  finally
  {
    StreamHelper.close (aWriter);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:36,代码来源:MicroWriter.java

示例4: getNodeAsString

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Convert the passed micro node to an XML string using the provided settings.
 *
 * @param aNode
 *        The node to be converted to a string. May not be <code>null</code> .
 * @param aSettings
 *        The XML writer settings to use. May not be <code>null</code>.
 * @return The string representation of the passed node.
 */
@Nullable
public static String getNodeAsString (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aSettings, "Settings");

  try (final NonBlockingStringWriter aWriter = new NonBlockingStringWriter (50 * CGlobal.BYTES_PER_KILOBYTE))
  {
    // start serializing
    if (writeToWriter (aNode, aWriter, aSettings).isSuccess ())
      return aWriter.getAsString ();
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:MicroWriter.java

示例5: getNodeAsBytes

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Convert the passed micro node to an XML byte array using the provided
 * settings.
 *
 * @param aNode
 *        The node to be converted to a byte array. May not be
 *        <code>null</code> .
 * @param aSettings
 *        The XML writer settings to use. May not be <code>null</code>.
 * @return The byte array representation of the passed node.
 * @since 8.6.3
 */
@Nullable
public static byte [] getNodeAsBytes (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aSettings, "Settings");

  try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 *
                                                                                            CGlobal.BYTES_PER_KILOBYTE))
  {
    // start serializing
    if (writeToStream (aNode, aBAOS, aSettings).isSuccess ())
      return aBAOS.toByteArray ();
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:32,代码来源:MicroWriter.java

示例6: ignorableWhitespace

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
public void ignorableWhitespace (@Nonnull final char [] aChars,
                                 @Nonnegative final int nStart,
                                 @Nonnegative final int nLength)
{
  _updatePosition ("ignorableWhitespace");
  if (m_bSaveIgnorableWhitespaces)
  {
    final IMicroNode aLastChild = m_aParent.getLastChild ();
    if (aLastChild != null && aLastChild.getType ().isText ())
    {
      final IMicroText aLastText = (IMicroText) aLastChild;
      if (aLastText.isElementContentWhitespace ())
      {
        // Merge directly following text nodes to one node!
        // This may happen when compiling with JDK 1.6.0_04
        aLastText.appendData (aChars, nStart, nLength);
      }
      else
        m_aParent.appendIgnorableWhitespaceText (aChars, nStart, nLength);
    }
    else
      m_aParent.appendIgnorableWhitespaceText (aChars, nStart, nLength);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:25,代码来源:MicroSAXHandler.java

示例7: getPath

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
/**
 * Get the path of the given node, up to the root element.
 *
 * @param aNode
 *        The node to get the path from. May be <code>null</code>.
 * @param sSep
 *        The separator to be put between each level. For XPath e.g. use "/"
 * @return A non-<code>null</code> string. If the passed node is
 *         <code>null</code>, the return value is an empty string.
 */
@Nonnull
@SuppressFBWarnings ("IL_INFINITE_LOOP")
public static String getPath (@Nullable final IMicroNode aNode, @Nonnull final String sSep)
{
  ValueEnforcer.notNull (sSep, "Separator");

  final StringBuilder aSB = new StringBuilder ();
  IMicroNode aCurrentNode = aNode;
  while (aCurrentNode != null)
  {
    if (aSB.length () > 0)
      aSB.insert (0, sSep);
    aSB.insert (0, aCurrentNode.getNodeName ());
    aCurrentNode = aCurrentNode.getParent ();
  }
  return aSB.toString ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:MicroHelper.java

示例8: _testGetNodeAsXHTMLString

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
private static void _testGetNodeAsXHTMLString (final IMicroNode aNode)
{
  // try all permutations
  final XMLWriterSettings aSettings = XMLWriterSettings.createForXHTML ();
  for (int nCharSet = 0; nCharSet < 2; ++nCharSet)
  {
    aSettings.setCharset (nCharSet == 1 ? StandardCharsets.ISO_8859_1 : StandardCharsets.UTF_8);
    for (final EXMLSerializeIndent eIndent : EXMLSerializeIndent.values ())
    {
      aSettings.setIndent (eIndent);
      for (final EXMLSerializeDocType eDocType : EXMLSerializeDocType.values ())
      {
        aSettings.setSerializeDocType (eDocType);
        assertNotNull (MicroWriter.getNodeAsString (aNode, aSettings));
      }
    }
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:19,代码来源:MicroWriterTest.java

示例9: _testGetNodeAsXMLString

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
private static void _testGetNodeAsXMLString (final IMicroNode aNode)
{
  // try all permutations
  final XMLWriterSettings aSettings = new XMLWriterSettings ();
  for (int nCharSet = 0; nCharSet < 2; ++nCharSet)
  {
    aSettings.setCharset (nCharSet == 1 ? StandardCharsets.ISO_8859_1 : StandardCharsets.UTF_8);
    for (final EXMLSerializeIndent eIndent : EXMLSerializeIndent.values ())
    {
      aSettings.setIndent (eIndent);
      for (final EXMLSerializeDocType eDocType : EXMLSerializeDocType.values ())
      {
        aSettings.setSerializeDocType (eDocType);
        assertNotNull (MicroWriter.getNodeAsString (aNode, aSettings));
      }
    }
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:19,代码来源:MicroWriterTest.java

示例10: _writeContainer

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
private void _writeContainer (@Nonnull final XMLEmitter aXMLWriter,
                              @Nonnull final IMicroNode aParentNode,
                              @Nonnull final IMicroContainer aContainer)
{
  // A container has no own properties!
  if (aContainer.hasChildren ())
    _writeNodeList (aXMLWriter, aParentNode, aContainer.getAllChildren ());
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:9,代码来源:MicroSerializer.java

示例11: next

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
public IMicroNode next ()
{
  if (m_aOpen.isEmpty ())
    throw new NoSuchElementException ();

  final IMicroNode ret = m_aOpen.remove (0);
  if (ret.hasChildren ())
    m_aOpen.addAll (0, ret.getAllChildren ());
  return ret;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:11,代码来源:MicroRecursiveIterator.java

示例12: testConvertToMicroNode

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
@Test
public void testConvertToMicroNode () throws SAXException, IOException, ParserConfigurationException
{
  final String sXML = "<?xml version='1.0'?>" +
                      "<!DOCTYPE root [ <!ENTITY sc \"sc.exe\"> <!ELEMENT root (child, child2)> <!ELEMENT child (#PCDATA)> <!ELEMENT child2 (#PCDATA)> ]>" +
                      "<root attr='value'>" +
                      "<![CDATA[hihi]]>" +
                      "text" +
                      "&sc;" +
                      "<child xmlns='http://myns' a='b' />" +
                      "<child2 />" +
                      "<!-- comment -->" +
                      "<?stylesheet x y z?>" +
                      "</root>";
  final DocumentBuilderFactory aDBF = XMLFactory.createDefaultDocumentBuilderFactory ();
  aDBF.setCoalescing (false);
  aDBF.setIgnoringComments (false);
  final Document doc = aDBF.newDocumentBuilder ()
                           .parse (new StringInputStream (sXML, StandardCharsets.ISO_8859_1));
  assertNotNull (doc);
  final IMicroNode aNode = MicroHelper.convertToMicroNode (doc);
  assertNotNull (aNode);
  try
  {
    MicroHelper.convertToMicroNode (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:31,代码来源:MicroHelperTest.java

示例13: getAsDocument

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
@Nonnull
@OverrideOnDemand
protected IMicroNode getAsDocument (@Nonnull final IMicroElement aElement)
{
  final IMicroDocument aDoc = new MicroDocument ();
  aDoc.appendChild (aElement);
  return aDoc;
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:9,代码来源:PSWriter.java

示例14: emitNode

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
@Override
protected void emitNode (@Nonnull final XMLEmitter aXMLWriter,
                         @Nullable final IMicroNode aParentNode,
                         @Nullable final IMicroNode aPrevSibling,
                         @Nonnull final IMicroNode aNode,
                         @Nullable final IMicroNode aNextSibling)
{
  ValueEnforcer.notNull (aNode, "Node");

  switch (aNode.getType ())
  {
    case ELEMENT:
      _writeElement (aXMLWriter, aParentNode, aPrevSibling, (IMicroElement) aNode, aNextSibling);
      break;
    case TEXT:
      _writeText (aXMLWriter, (IMicroText) aNode);
      break;
    case CDATA:
      _writeCDATA (aXMLWriter, (IMicroCDATA) aNode);
      break;
    case COMMENT:
      _writeComment (aXMLWriter, (IMicroComment) aNode);
      break;
    case ENTITY_REFERENCE:
      _writeEntityReference (aXMLWriter, (IMicroEntityReference) aNode);
      break;
    case DOCUMENT:
      _writeDocument (aXMLWriter, (IMicroDocument) aNode);
      break;
    case DOCUMENT_TYPE:
      _writeDocumentType (aXMLWriter, (IMicroDocumentType) aNode);
      break;
    case PROCESSING_INSTRUCTION:
      _writeProcessingInstruction (aXMLWriter, (IMicroProcessingInstruction) aNode);
      break;
    case CONTAINER:
      _writeContainer (aXMLWriter, aParentNode, (IMicroContainer) aNode);
      break;
    default:
      throw new IllegalArgumentException ("Passed node type " +
                                          aNode.getClass ().getName () +
                                          " is not yet supported");
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:45,代码来源:MicroSerializer.java

示例15: _isInlineNode

import com.helger.xml.microdom.IMicroNode; //导入依赖的package包/类
private static boolean _isInlineNode (@Nonnull final IMicroNode aNode)
{
  return aNode.isText () || aNode.isCDATA () || aNode.isEntityReference ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:5,代码来源:MicroSerializer.java


注:本文中的com.helger.xml.microdom.IMicroNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。