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: FuncNormalizeSpace.java 468655 2006-10-28 07:12:06Z minchau $ 20 */ 21 package org.apache.xpath.functions; 22 23 import org.apache.xml.dtm.DTM; 24 import org.apache.xml.utils.XMLString; 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.objects.XObject; 27 import org.apache.xpath.objects.XString; 28 import org.xml.sax.ContentHandler; 29 30 /** 31 * Execute the normalize-space() function. 32 * @xsl.usage advanced 33 */ 34 public class FuncNormalizeSpace extends FunctionDef1Arg 35 { 36 static final long serialVersionUID = -3377956872032190880L; 37 38 /** 39 * Execute the function. The function must return 40 * a valid object. 41 * @param xctxt The current execution context. 42 * @return A valid XObject. 43 * 44 * @throws javax.xml.transform.TransformerException 45 */ execute(XPathContext xctxt)46 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 47 { 48 XMLString s1 = getArg0AsString(xctxt); 49 50 return (XString)s1.fixWhiteSpace(true, true, false); 51 } 52 53 /** 54 * Execute an expression in the XPath runtime context, and return the 55 * result of the expression. 56 * 57 * 58 * @param xctxt The XPath runtime context. 59 * 60 * @return The result of the expression in the form of a <code>XObject</code>. 61 * 62 * @throws javax.xml.transform.TransformerException if a runtime exception 63 * occurs. 64 */ executeCharsToContentHandler(XPathContext xctxt, ContentHandler handler)65 public void executeCharsToContentHandler(XPathContext xctxt, 66 ContentHandler handler) 67 throws javax.xml.transform.TransformerException, 68 org.xml.sax.SAXException 69 { 70 if(Arg0IsNodesetExpr()) 71 { 72 int node = getArg0AsNode(xctxt); 73 if(DTM.NULL != node) 74 { 75 DTM dtm = xctxt.getDTM(node); 76 dtm.dispatchCharactersEvents(node, handler, true); 77 } 78 } 79 else 80 { 81 XObject obj = execute(xctxt); 82 obj.dispatchCharactersEvents(handler); 83 } 84 } 85 86 } 87