Home | History | Annotate | Download | only in objects
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one
      3  * or more contributor license agreements. See the NOTICE file
      4  * distributed with this work for additional information
      5  * regarding copyright ownership. The ASF licenses this file
      6  * to you under the Apache License, Version 2.0 (the  "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *     http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 /*
     19  * $Id: XMLStringFactoryImpl.java 468655 2006-10-28 07:12:06Z minchau $
     20  */
     21 package org.apache.xpath.objects;
     22 
     23 import org.apache.xml.utils.FastStringBuffer;
     24 import org.apache.xml.utils.XMLString;
     25 import org.apache.xml.utils.XMLStringFactory;
     26 
     27 /**
     28  * Class XMLStringFactoryImpl creates XString versions of XMLStrings.
     29  * @xsl.usage internal
     30  */
     31 public class XMLStringFactoryImpl extends XMLStringFactory
     32 {
     33   /** The XMLStringFactory to pass to DTM construction.   */
     34   private static XMLStringFactory m_xstringfactory =
     35     new XMLStringFactoryImpl();
     36 
     37   /**
     38    * Get the XMLStringFactory to pass to DTM construction.
     39    *
     40    *
     41    * @return A never-null static reference to a String factory.
     42    */
     43   public static XMLStringFactory getFactory()
     44   {
     45     return m_xstringfactory;
     46   }
     47 
     48   /**
     49    * Create a new XMLString from a Java string.
     50    *
     51    *
     52    * @param string Java String reference, which must be non-null.
     53    *
     54    * @return An XMLString object that wraps the String reference.
     55    */
     56   public XMLString newstr(String string)
     57   {
     58     return new XString(string);
     59   }
     60 
     61   /**
     62    * Create a XMLString from a FastStringBuffer.
     63    *
     64    *
     65    * @param fsb FastStringBuffer reference, which must be non-null.
     66    * @param start The start position in the array.
     67    * @param length The number of characters to read from the array.
     68    *
     69    * @return An XMLString object that wraps the FastStringBuffer reference.
     70    */
     71   public XMLString newstr(FastStringBuffer fsb, int start, int length)
     72   {
     73     return new XStringForFSB(fsb, start, length);
     74   }
     75 
     76   /**
     77    * Create a XMLString from a FastStringBuffer.
     78    *
     79    *
     80    * @param string FastStringBuffer reference, which must be non-null.
     81    * @param start The start position in the array.
     82    * @param length The number of characters to read from the array.
     83    *
     84    * @return An XMLString object that wraps the FastStringBuffer reference.
     85    */
     86   public XMLString newstr(char[] string, int start, int length)
     87   {
     88     return new XStringForChars(string, start, length);
     89   }
     90 
     91   /**
     92    * Get a cheap representation of an empty string.
     93    *
     94    * @return An non-null reference to an XMLString that represents "".
     95    */
     96   public XMLString emptystr()
     97   {
     98     return XString.EMPTYSTRING;
     99   }
    100 
    101 }
    102