001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: XMLStringFactoryDefault.java 468655 2006-10-28 07:12:06Z minchau $
020     */
021    package org.apache.xml.utils;
022    
023    /**
024     * The default implementation of XMLStringFactory.
025     * This implementation creates XMLStringDefault objects.
026     */
027    public class XMLStringFactoryDefault extends XMLStringFactory
028    {
029      // A constant representing the empty String
030      private static final XMLStringDefault EMPTY_STR = new XMLStringDefault("");
031      
032      /**
033       * Create a new XMLString from a Java string.
034       *
035       *
036       * @param string Java String reference, which must be non-null.
037       *
038       * @return An XMLString object that wraps the String reference.
039       */
040      public XMLString newstr(String string)
041      {
042        return new XMLStringDefault(string);
043      }
044    
045      /**
046       * Create a XMLString from a FastStringBuffer.
047       *
048       *
049       * @param fsb FastStringBuffer reference, which must be non-null.
050       * @param start The start position in the array.
051       * @param length The number of characters to read from the array.
052       *
053       * @return An XMLString object that wraps the FastStringBuffer reference.
054       */
055      public XMLString newstr(FastStringBuffer fsb, int start, int length)
056      {
057        return new XMLStringDefault(fsb.getString(start, length));
058      }
059    
060      /**
061       * Create a XMLString from a FastStringBuffer.
062       *
063       *
064       * @param string FastStringBuffer reference, which must be non-null.
065       * @param start The start position in the array.
066       * @param length The number of characters to read from the array.
067       *
068       * @return An XMLString object that wraps the FastStringBuffer reference.
069       */
070      public XMLString newstr(char[] string, int start, int length)
071      {
072        return new XMLStringDefault(new String(string, start, length));
073      }
074                                       
075      /**
076       * Get a cheap representation of an empty string.
077       * 
078       * @return An non-null reference to an XMLString that represents "".
079       */
080      public XMLString emptystr()
081      {
082        return EMPTY_STR;
083      }
084    }