1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: XMLStringFactoryDefault.java,v 1.3 2004/02/17 04:21:14 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.utils;
  20. /**
  21. * The default implementation of XMLStringFactory.
  22. * This implementation creates XMLStringDefault objects.
  23. */
  24. public class XMLStringFactoryDefault extends XMLStringFactory
  25. {
  26. // A constant representing the empty String
  27. private static final XMLStringDefault EMPTY_STR = new XMLStringDefault("");
  28. /**
  29. * Create a new XMLString from a Java string.
  30. *
  31. *
  32. * @param string Java String reference, which must be non-null.
  33. *
  34. * @return An XMLString object that wraps the String reference.
  35. */
  36. public XMLString newstr(String string)
  37. {
  38. return new XMLStringDefault(string);
  39. }
  40. /**
  41. * Create a XMLString from a FastStringBuffer.
  42. *
  43. *
  44. * @param fsb FastStringBuffer reference, which must be non-null.
  45. * @param start The start position in the array.
  46. * @param length The number of characters to read from the array.
  47. *
  48. * @return An XMLString object that wraps the FastStringBuffer reference.
  49. */
  50. public XMLString newstr(FastStringBuffer fsb, int start, int length)
  51. {
  52. return new XMLStringDefault(fsb.getString(start, length));
  53. }
  54. /**
  55. * Create a XMLString from a FastStringBuffer.
  56. *
  57. *
  58. * @param string FastStringBuffer reference, which must be non-null.
  59. * @param start The start position in the array.
  60. * @param length The number of characters to read from the array.
  61. *
  62. * @return An XMLString object that wraps the FastStringBuffer reference.
  63. */
  64. public XMLString newstr(char[] string, int start, int length)
  65. {
  66. return new XMLStringDefault(new String(string, start, length));
  67. }
  68. /**
  69. * Get a cheap representation of an empty string.
  70. *
  71. * @return An non-null reference to an XMLString that represents "".
  72. */
  73. public XMLString emptystr()
  74. {
  75. return EMPTY_STR;
  76. }
  77. }