com.sun.org.apache.xml.internal.utils.XMLStringFactory Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.utils.XMLStringFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the given block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, int blocksize,
               boolean buildIdIndex,
               boolean newNameTable)
{
    super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, blocksize, false, buildIdIndex, newNameTable);

    _dtmManager = mgr;
    _size = blocksize;

    // Use a smaller size for the space stack if the blocksize is small
    _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64];

    /* From DOMBuilder */
    _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE;

    // If the input source is DOMSource, set the _document field and
    // create the node2Ids table.
    if (source instanceof DOMSource) {
        _hasDOMSource = true;
        DOMSource domsrc = (DOMSource)source;
        Node node = domsrc.getNode();
        if (node instanceof Document) {
            _document = (Document)node;
        }
        else {
            _document = node.getOwnerDocument();
        }
        _node2Ids = new HashMap<>();
    }
}
 
Example #2
Source File: SAX2RTFDTM.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SAX2RTFDTM(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // NEVER track source locators for RTFs; they aren't meaningful. I think.
  // (If we did track them, we'd need to tail-prune these too.)
  //com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.m_source_location;
  m_useSourceLocationProperty=false;
  m_sourceSystemId = (m_useSourceLocationProperty) ? new StringVector()
                                                   : null;
  m_sourceLine = (m_useSourceLocationProperty) ? new IntVector() : null;
  m_sourceColumn = (m_useSourceLocationProperty) ? new IntVector() : null;

  // Record initial sizes of fields that are pushed and restored
  // for RTF tail-pruning.  More entries can be popped than pushed, so
  // we need this to mark the primordial state of the DTM.
  m_emptyNodeCount = m_size;
  m_emptyNSDeclSetCount = (m_namespaceDeclSets == null)
                               ? 0 : m_namespaceDeclSets.size();
  m_emptyNSDeclSetElemsCount = (m_namespaceDeclSetElements == null)
                                    ? 0 : m_namespaceDeclSetElements.size();
  m_emptyDataCount = m_data.size();
  m_emptyCharsCount = m_chars.size();
  m_emptyDataQNCount = m_dataOrQName.size();
}
 
Example #3
Source File: SAX2RTFDTM.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public SAX2RTFDTM(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // NEVER track source locators for RTFs; they aren't meaningful. I think.
  // (If we did track them, we'd need to tail-prune these too.)
  //com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.m_source_location;
  m_useSourceLocationProperty=false;
  m_sourceSystemId = (m_useSourceLocationProperty) ? new StringVector()
                                                   : null;
  m_sourceLine = (m_useSourceLocationProperty) ? new IntVector() : null;
  m_sourceColumn = (m_useSourceLocationProperty) ? new IntVector() : null;

  // Record initial sizes of fields that are pushed and restored
  // for RTF tail-pruning.  More entries can be popped than pushed, so
  // we need this to mark the primordial state of the DTM.
  m_emptyNodeCount = m_size;
  m_emptyNSDeclSetCount = (m_namespaceDeclSets == null)
                               ? 0 : m_namespaceDeclSets.size();
  m_emptyNSDeclSetElemsCount = (m_namespaceDeclSetElements == null)
                                    ? 0 : m_namespaceDeclSetElements.size();
  m_emptyDataCount = m_data.size();
  m_emptyCharsCount = m_chars.size();
  m_emptyDataQNCount = m_dataOrQName.size();
}
 
Example #4
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the given block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, int blocksize,
               boolean buildIdIndex,
               boolean newNameTable)
{
    super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, blocksize, false, buildIdIndex, newNameTable);

    _dtmManager = mgr;
    _size = blocksize;

    // Use a smaller size for the space stack if the blocksize is small
    _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64];

    /* From DOMBuilder */
    _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE;

    // If the input source is DOMSource, set the _document field and
    // create the node2Ids table.
    if (source instanceof DOMSource) {
        _hasDOMSource = true;
        DOMSource domsrc = (DOMSource)source;
        Node node = domsrc.getNode();
        if (node instanceof Document) {
            _document = (Document)node;
        }
        else {
            _document = node.getOwnerDocument();
        }
        _node2Ids = new Hashtable();
    }
}
 
Example #5
Source File: SAXImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the given block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, int blocksize,
               boolean buildIdIndex,
               boolean newNameTable)
{
    super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, blocksize, false, buildIdIndex, newNameTable);

    _dtmManager = mgr;
    _size = blocksize;

    // Use a smaller size for the space stack if the blocksize is small
    _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64];

    /* From DOMBuilder */
    _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE;

    // If the input source is DOMSource, set the _document field and
    // create the node2Ids table.
    if (source instanceof DOMSource) {
        _hasDOMSource = true;
        DOMSource domsrc = (DOMSource)source;
        Node node = domsrc.getNode();
        if (node instanceof Document) {
            _document = (Document)node;
        }
        else {
            _document = node.getOwnerDocument();
        }
        _node2Ids = new HashMap<>();
    }
}
 
Example #6
Source File: SAXImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the default block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, boolean buildIdIndex)
{
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
}
 
Example #7
Source File: SAX2DTM2.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the given block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing,
               int blocksize,
               boolean usePrevsib,
               boolean buildIdIndex,
               boolean newNameTable)
{

  super(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, blocksize, usePrevsib, newNameTable);

  // Initialize the values of m_SHIFT and m_MASK.
  int shift;
  for(shift=0; (blocksize>>>=1) != 0; ++shift);

  m_blocksize = 1<<shift;
  m_SHIFT = shift;
  m_MASK = m_blocksize - 1;

  m_buildIdIndex = buildIdIndex;

  // Some documents do not have attribute nodes. That is why
  // we set the initial size of this Vector to be small and set
  // the increment to a bigger number.
  m_values = new Vector(32, 512);

  m_maxNodeIndex = 1 << DTMManager.IDENT_DTM_NODE_BITS;

  // Set the map0 values in the constructor.
  m_exptype_map0 = m_exptype.getMap0();
  m_nextsib_map0 = m_nextsib.getMap0();
  m_firstch_map0 = m_firstch.getMap0();
  m_parent_map0  = m_parent.getMap0();
}
 
Example #8
Source File: SAX2DTM2.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the default block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{

  this(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
}
 
Example #9
Source File: SAXImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the default block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, boolean buildIdIndex)
{
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
}
 
Example #10
Source File: SAX2DTM2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the default block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{

  this(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
}
 
Example #11
Source File: SAX2DTM2.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the default block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{

  this(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
}
 
Example #12
Source File: SAX2DTM2.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the default block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{

  this(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
}
 
Example #13
Source File: SAXImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the default block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, boolean buildIdIndex)
{
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
}
 
Example #14
Source File: SAX2DTM2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the given block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing,
               int blocksize,
               boolean usePrevsib,
               boolean buildIdIndex,
               boolean newNameTable)
{

  super(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, blocksize, usePrevsib, newNameTable);

  // Initialize the values of m_SHIFT and m_MASK.
  int shift;
  for(shift=0; (blocksize>>>=1) != 0; ++shift);

  m_blocksize = 1<<shift;
  m_SHIFT = shift;
  m_MASK = m_blocksize - 1;

  m_buildIdIndex = buildIdIndex;

  // Some documents do not have attribute nodes. That is why
  // we set the initial size of this Vector to be small and set
  // the increment to a bigger number.
  m_values = new Vector(32, 512);

  m_maxNodeIndex = 1 << DTMManager.IDENT_DTM_NODE_BITS;

  // Set the map0 values in the constructor.
  m_exptype_map0 = m_exptype.getMap0();
  m_nextsib_map0 = m_nextsib.getMap0();
  m_firstch_map0 = m_firstch.getMap0();
  m_parent_map0  = m_parent.getMap0();
}
 
Example #15
Source File: SAX2DTM2.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the default block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{

  this(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, true, true, false);
}
 
Example #16
Source File: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the default block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, boolean buildIdIndex)
{
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
}
 
Example #17
Source File: SAX2DTM2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAX2DTM2 object using the given block size.
 */
public SAX2DTM2(DTMManager mgr, Source source, int dtmIdentity,
               DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing,
               int blocksize,
               boolean usePrevsib,
               boolean buildIdIndex,
               boolean newNameTable)
{

  super(mgr, source, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing, blocksize, usePrevsib, newNameTable);

  // Initialize the values of m_SHIFT and m_MASK.
  int shift;
  for(shift=0; (blocksize>>>=1) != 0; ++shift);

  m_blocksize = 1<<shift;
  m_SHIFT = shift;
  m_MASK = m_blocksize - 1;

  m_buildIdIndex = buildIdIndex;

  // Some documents do not have attribute nodes. That is why
  // we set the initial size of this ArrayList to be small.
  m_values = new ArrayList<>(32);

  m_maxNodeIndex = 1 << DTMManager.IDENT_DTM_NODE_BITS;

  // Set the map0 values in the constructor.
  m_exptype_map0 = m_exptype.getMap0();
  m_nextsib_map0 = m_nextsib.getMap0();
  m_firstch_map0 = m_firstch.getMap0();
  m_parent_map0  = m_parent.getMap0();
}
 
Example #18
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a SAXImpl object using the default block size.
 */
public SAXImpl(XSLTCDTMManager mgr, Source source,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing, boolean buildIdIndex)
{
    this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory,
        doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false);
}
 
Example #19
Source File: XStringForFSB.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #20
Source File: DOM2DTM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}
 
Example #21
Source File: XStringForFSB.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #22
Source File: DOM2DTM.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}
 
Example #23
Source File: DOM2DTM.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}
 
Example #24
Source File: DOM2DTM.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}
 
Example #25
Source File: XStringForFSB.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #26
Source File: XStringForFSB.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #27
Source File: DOM2DTM.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}
 
Example #28
Source File: XStringForFSB.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #29
Source File: XStringForFSB.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Conditionally trim all leading and trailing whitespace in the specified String.
 * All strings of white space are
 * replaced by a single space character (#x20), except spaces after punctuation which
 * receive double spaces if doublePunctuationSpaces is true.
 * This function may be useful to a formatter, but to get first class
 * results, the formatter should probably do it's own white space handling
 * based on the semantics of the formatting object.
 *
 * @param   trimHead    Trim leading whitespace?
 * @param   trimTail    Trim trailing whitespace?
 * @param   doublePunctuationSpaces    Use double spaces for punctuation?
 * @return              The trimmed string.
 */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                               boolean doublePunctuationSpaces)
{

  int end = m_length + m_start;
  char[] buf = new char[m_length];
  FastStringBuffer fsb = fsb();
  boolean edit = false;

  /* replace S to ' '. and ' '+ -> single ' '. */
  int d = 0;
  boolean pres = false;

  for (int s = m_start; s < end; s++)
  {
    char c = fsb.charAt(s);

    if (isSpace(c))
    {
      if (!pres)
      {
        if (' ' != c)
        {
          edit = true;
        }

        buf[d++] = ' ';

        if (doublePunctuationSpaces && (d != 0))
        {
          char prevChar = buf[d - 1];

          if (!((prevChar == '.') || (prevChar == '!')
                || (prevChar == '?')))
          {
            pres = true;
          }
        }
        else
        {
          pres = true;
        }
      }
      else
      {
        edit = true;
        pres = true;
      }
    }
    else
    {
      buf[d++] = c;
      pres = false;
    }
  }

  if (trimTail && 1 <= d && ' ' == buf[d - 1])
  {
    edit = true;

    d--;
  }

  int start = 0;

  if (trimHead && 0 < d && ' ' == buf[0])
  {
    edit = true;

    start++;
  }

  XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();

  return edit ? xsf.newstr(buf, start, d - start) : this;
}
 
Example #30
Source File: DOM2DTM.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a DOM2DTM object from a DOM node.
 *
 * @param mgr The DTMManager who owns this DTM.
 * @param domSource the DOM source that this DTM will wrap.
 * @param dtmIdentity The DTM identity ID for this DTM.
 * @param whiteSpaceFilter The white space filter for this DTM, which may
 *                         be null.
 * @param xstringfactory XMLString factory for creating character content.
 * @param doIndexing true if the caller considers it worth it to use
 *                   indexing schemes.
 */
public DOM2DTM(DTMManager mgr, DOMSource domSource,
               int dtmIdentity, DTMWSFilter whiteSpaceFilter,
               XMLStringFactory xstringfactory,
               boolean doIndexing)
{
  super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
        xstringfactory, doIndexing);

  // Initialize DOM navigation
  m_pos=m_root = domSource.getNode();
  // Initialize DTM navigation
  m_last_parent=m_last_kid=NULL;
  m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);

  // Apparently the domSource root may not actually be the
  // Document node. If it's an Element node, we need to immediately
  // add its attributes. Adapted from nextNode().
  // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  //
  // (If it's an EntityReference node, we're probably scrod. For now
  // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
              //
              // %ISSUE% What about inherited namespaces in this case?
              // Do we need to special-case initialize them into the DTM model?
  if(ELEMENT_NODE == m_root.getNodeType())
  {
    NamedNodeMap attrs=m_root.getAttributes();
    int attrsize=(attrs==null) ? 0 : attrs.getLength();
    if(attrsize>0)
    {
      int attrIndex=NULL; // start with no previous sib
      for(int i=0;i<attrsize;++i)
      {
        // No need to force nodetype in this case;
        // addNode() will take care of switching it from
        // Attr to Namespace if necessary.
        attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
        m_firstch.setElementAt(DTM.NULL,attrIndex);
      }
      // Terminate list of attrs, and make sure they aren't
      // considered children of the element
      m_nextsib.setElementAt(DTM.NULL,attrIndex);

      // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
    } // if attrs exist
  } //if(ELEMENT_NODE)

  // Initialize DTM-completed status
  m_nodesAreProcessed = false;
}