1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include <stdio.h> 25 #include <resourcemodel/XPathLogger.hxx> 26 27 namespace writerfilter 28 { XPathLogger()29XPathLogger::XPathLogger() 30 : mp_tokenMap(new TokenMap_t) 31 { 32 } 33 ~XPathLogger()34XPathLogger::~XPathLogger() 35 { 36 } 37 getXPath() const38string XPathLogger::getXPath() const 39 { 40 return m_currentPath; 41 } 42 updateCurrentPath()43void XPathLogger::updateCurrentPath() 44 { 45 m_currentPath = ""; 46 47 for (vector<string>::const_iterator aIt = m_path.begin(); 48 aIt != m_path.end(); 49 aIt++) 50 { 51 if (m_currentPath.size() > 0) 52 m_currentPath += "/"; 53 54 m_currentPath += *aIt; 55 } 56 } 57 startElement(string _token)58void XPathLogger::startElement(string _token) 59 { 60 TokenMap_t::const_iterator aIt = mp_tokenMap->find(_token); 61 62 if (aIt == mp_tokenMap->end()) 63 (*mp_tokenMap)[_token] = 1; 64 else 65 (*mp_tokenMap)[_token]++; 66 67 static char sBuffer[256]; 68 snprintf(sBuffer, sizeof(sBuffer), "[%d]", (*mp_tokenMap)[_token]); 69 m_path.push_back(_token + sBuffer); 70 71 m_tokenMapStack.push(mp_tokenMap); 72 mp_tokenMap.reset(new TokenMap_t); 73 74 updateCurrentPath(); 75 } 76 endElement()77void XPathLogger::endElement() 78 { 79 mp_tokenMap = m_tokenMapStack.top(); 80 m_tokenMapStack.pop(); 81 m_path.pop_back(); 82 83 updateCurrentPath(); 84 } 85 86 } 87