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: ProcessorPreserveSpace.java 468640 2006-10-28 06:53:53Z minchau $
020     */
021    package org.apache.xalan.processor;
022    
023    import java.util.Vector;
024    
025    import org.apache.xalan.templates.Stylesheet;
026    import org.apache.xalan.templates.WhiteSpaceInfo;
027    import org.apache.xpath.XPath;
028    
029    import org.xml.sax.Attributes;
030    
031    /**
032     * TransformerFactory for xsl:preserve-space markup.
033     * <pre>
034     * <!ELEMENT xsl:preserve-space EMPTY>
035     * <!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>
036     * </pre>
037     */
038    class ProcessorPreserveSpace extends XSLTElementProcessor
039    {
040        static final long serialVersionUID = -5552836470051177302L;
041    
042      /**
043       * Receive notification of the start of an preserve-space element.
044       *
045       * @param handler The calling StylesheetHandler/TemplatesBuilder.
046       * @param uri The Namespace URI, or the empty string if the
047       *        element has no Namespace URI or if Namespace
048       *        processing is not being performed.
049       * @param localName The local name (without prefix), or the
050       *        empty string if Namespace processing is not being
051       *        performed.
052       * @param rawName The raw XML 1.0 name (with prefix), or the
053       *        empty string if raw names are not available.
054       * @param attributes The attributes attached to the element.  If
055       *        there are no attributes, it shall be an empty
056       *        Attributes object.
057       */
058      public void startElement(
059              StylesheetHandler handler, String uri, String localName, String rawName, 
060              Attributes attributes)
061                throws org.xml.sax.SAXException
062      {
063        Stylesheet thisSheet = handler.getStylesheet();
064            WhitespaceInfoPaths paths = new WhitespaceInfoPaths(thisSheet);
065        setPropertiesFromAttributes(handler, rawName, attributes, paths);
066    
067        Vector xpaths = paths.getElements();
068    
069        for (int i = 0; i < xpaths.size(); i++)
070        {
071          WhiteSpaceInfo wsi = new WhiteSpaceInfo((XPath) xpaths.elementAt(i), false, thisSheet);
072          wsi.setUid(handler.nextUid());
073    
074          thisSheet.setPreserveSpaces(wsi);
075        }
076        paths.clearElements();
077      }
078    }