Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/standardmodel/StdSimpleString.java


1   /*
2   ================================================================================
3   
4     FILE:  StdSimpleString.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      Standard implementation of SimpleString
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.standardmodel;
43  
44  
45  import java.io.IOException;
46  import org.xml.sax.Attributes;
47  import org.xml.sax.SAXException;
48  import org.xml.sax.ErrorHandler;
49  import org.xml.sax.Locator;
50  
51  import com.virtuosotechnologies.lib.xml.XMLUnparser;
52  
53  
54  /**
55   * Standard implementation of SimpleString.
56   */
57  /*package*/ class StdSimpleString
58  extends BaseString
59  {
60    /*package*/ StdSimpleString(
61      BaseSongMember parent,
62      String value)
63    {
64      super(parent, value);
65    }
66    
67    
68    /*package*/ void unparse(
69      XMLUnparser unparser,
70      String element)
71    throws
72      IOException
73    {
74      unparser.startSingleLineElement(element);
75      unparser.addString(getString());
76      unparser.endElement(element);
77    }
78    
79    
80    /*package*/ void unparseMultiLine(
81      XMLUnparser unparser,
82      String element)
83    throws
84      IOException
85    {
86      unparser.startMultiLineElement(element);
87      char[] chars = getString().toCharArray();
88      for (int start = 0; start < chars.length; )
89      {
90        int count = 0;
91        int next = start;
92        while (next < chars.length)
93        {
94          char ch = chars[next];
95          if (ch == '\r' || ch == '\n')
96          {
97            ++next;
98            if (ch == '\r' && next < chars.length && chars[next] == '\n')
99            {
100             ++next;
101           }
102           break;
103         }
104         else
105         {
106           ++next;
107           ++count;
108         }
109       }
110       unparser.startSingleLineElement(XMLConstants.STRINGLISTMEMBER_ELEMENT);
111       unparser.addString(new String(chars, start, count));
112       unparser.endElement(XMLConstants.STRINGLISTMEMBER_ELEMENT);
113       start = next;
114     }
115     unparser.endElement(element);
116   }
117   
118   
119   /*package*/ class ParseHandler
120   extends ParseHandlerBase
121   {
122     /*package*/ ParseHandler(
123       ErrorHandler errorHandler,
124       Locator locator,
125       String localElement)
126     {
127       super(errorHandler, locator, localElement);
128     }
129     
130     /*package*/ void localCharacters(
131       char[] chs,
132       int start,
133       int length)
134     throws
135       SAXException
136     {
137       setString(getString()+new String(chs, start, length), null);
138     }
139   }
140   
141   
142   /*package*/ class MultiLineParseHandler
143   extends ParseHandlerBase
144   {
145     /*package*/ MultiLineParseHandler(
146       ErrorHandler errorHandler,
147       Locator locator,
148       String localElement)
149     {
150       super(errorHandler, locator, localElement);
151     }
152     
153     /*package*/ ParseHandlerBase localStartElement(
154       String uri,
155       String localName,
156       String qName,
157       Attributes attributes)
158     throws
159       SAXException
160     {
161       if (localName.equals(XMLConstants.STRINGLISTMEMBER_ELEMENT))
162       {
163         return new ParseHandler(getErrorHandler(), getDocumentLocator(),
164           XMLConstants.STRINGLISTMEMBER_ELEMENT);
165       }
166       else
167       {
168         return super.localStartElement(uri, localName, qName, attributes);
169       }
170     }
171     
172     /*package*/ void childFinished(
173       String uri,
174       String localName,
175       String qName)
176     throws
177       SAXException
178     {
179       setString(getString()+"\n", null);
180     }
181   }
182 }