blob: 24377e7d79ad8d50f836226c795d8f1c36fca690 [file] [log] [blame]
/*
*
* FileUtility.cpp
*
* Copyright 2000 Lotus Development Corporation. All rights reserved.
* This software is subject to the Lotus Software Agreement, Restricted
* Rights for U.S. government users and applicable export regulations.
*/
#include <stdlib.h>
#include <cstdio>
#include <ctime>
#include <vector>
#if defined(XALAN_OLD_STREAM_HEADERS)
#include <iostream.h>
#else
#include <iostream>
#endif
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif
//#include <Include/PlatformDefinitions.hpp>
#include <framework/URLInputSource.hpp>
#include <util/PlatformUtils.hpp>
#include <XalanDOM/XalanNode.hpp>
#include <XalanDOM/XalanDocument.hpp>
#include <XalanDOM/XalanElement.hpp>
#include <XalanDOM/XalanNodeList.hpp>
#include <PlatformSupport/DoubleSupport.hpp>
#include <PlatformSupport/DirectoryEnumerator.hpp>
#include <PlatformSupport/DOMStringHelper.hpp>
#include <PlatformSupport/XalanUnicode.hpp>
#include <PlatformSupport/XalanOutputStreamPrintWriter.hpp>
#include <PlatformSupport/XalanStdOutputStream.hpp>
#include "FileUtility.hpp"
#if defined(XALAN_NO_NAMESPACES)
typedef vector<XalanDOMString> FileNameVectorType;
#else
typedef std::vector<XalanDOMString> FileNameVectorType;
#endif
/* This routine retrieves test file names from specified directories.
// Inputs: baseDir: typically "conf" or "perf"
// relDir: sub-directory to search.
//
// Notes: It builds the searchSpecification by concatenating all the
// necessary components.
// */
FileNameVectorType FileUtility::getTestFileNames(XalanDOMString baseDir, XalanDOMString relDir)
{
const XalanDOMString pathSep(XALAN_STATIC_UCODE_STRING("\\"));
const XalanDOMString searchSuffix(XALAN_STATIC_UCODE_STRING("*.xml"));
const XalanDOMString searchSpecification(baseDir + relDir + pathSep + relDir + searchSuffix);
DirectoryEnumeratorFunctor<FileNameVectorType, XalanDOMString> theEnumerator;
FileNameVectorType theFiles;
theEnumerator(searchSpecification, theFiles);
return theFiles;
}
/* This routine retrieves all sub-directories from the specified directories.
// Inputs: rootDirectory: typically "conf" or "perf"
//
// Notes: The searchSpecification in this case is just "*".
// */
FileNameVectorType FileUtility::getDirectoryNames(XalanDOMString rootDirectory)
{
const XalanDOMString dirSpec(XALAN_STATIC_UCODE_STRING("*"));
DirectoryEnumeratorFunctor<FileNameVectorType, XalanDOMString, DirectoryFilterPredicate> theEnumerator;
FileNameVectorType theFiles;
theEnumerator(XalanDOMString(rootDirectory), XalanDOMString(dirSpec), theFiles);
return theFiles;
}
/* This routine generates file names based on the provide suffix
// Inputs: theXMLFileName: typically "conf" or "perf"
// suffix: typically "xsl" or "out".
//
// Notes:
// */
XalanDOMString FileUtility::GenerateFileName(const XalanDOMString& theXMLFileName, char* suffix)
{
XalanDOMString theResult;
int thePeriodIndex = -1;
const int theLength = length(theXMLFileName);
for (int i = theLength - 1; i > 0; i--)
{
if (charAt(theXMLFileName, i) == XalanUnicode::charFullStop)
{
thePeriodIndex = i; // charFullStop is the dot (x2E)
break;
}
}
if (thePeriodIndex != -1)
{
theResult = substring(theXMLFileName,
0,
thePeriodIndex + 1);
theResult += XalanDOMString(suffix);
}
return theResult;
}