InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SDKFileHelper Class Reference

#include <SDKFileHelper.h>

Inheritance diagram for SDKFileHelper:
SDKFileDocumentChooserSDKFileOpenChooserSDKFilePlaceChooserSDKFileSaveChooserSDKFolderChooserSDKFileOpenMultipleFileChooser

Public Member Functions

 SDKFileHelper (const PMString &path)
 
 SDKFileHelper (const IDFile &file)
 
virtual ~SDKFileHelper ()
 
bool16 IsExisting () const
 
bool16 IsChosen () const
 
PMString GetPath () const
 
IDFile GetIDFile () const
 
IDFile GetAbsoluteFromRelative (const PMString &relativePath) const
 
PMString GetParentFolderAsString () const
 

Static Public Member Functions

static bool16 isMacPosixPathEnabled ()
 

Protected Member Functions

 SDKFileHelper ()
 
void initFromString ()
 
void initFromSysFile ()
 
void traceInitializeDiagnostics (int32 e) const
 
PMString calcDefaultFileName () const
 
void setChosen (bool16 chsen)
 
void setIDFile (const IDFile &file)
 
void setPath (const PMString &path)
 
PMString absoluteFromRelative (const PMString &folder, const PMString &path) const
 
bool16 isAbsolutePath (const PMString &path) const
 
bool16 isUnixPath (const PMString &path) const
 
bool16 isMacPath (const PMString &path) const
 
bool16 isWinPath (const PMString &path) const
 
PMString getMinusLastElement (const PMString &path) const
 
PMString getMinusFirstElement (const PMString &path) const
 
PMString getAsMacPath (const PMString &path) const
 
PMString getAsWinPath (const PMString &path) const
 

Friends

class SDKFileHelperUnitTest
 

Detailed Description

Cross-platform abstraction of file that eases working with files. Intended to obviate need for many of the methods in SDKUtilities. Becomes particularly powerful when the mechanism to choose a file is considered, eliminating the need for difficult to write boilerplate to parameterise the file selection dialogs.

Constructor & Destructor Documentation

SDKFileHelper::SDKFileHelper (const PMStringpath)

Constructor to use when the path is already known as a string.

Parameters
pathpath to file of interest
Precondition
path should exist and should not be an empty string
Postcondition
GetIDFile will return a IDFile giving file's location
GetPath will return the path used in constructor argument
SDKFileHelper::SDKFileHelper (const IDFilefile)

Constructor if a IDFile is available

Parameters
filespecifies the file of interest
Precondition
file should be valid
Postcondition
GetIDFile will return a IDFile used in constructor argument
GetPath will return the path of the file
SDKFileHelper::~SDKFileHelper ()
virtual

Destructor

SDKFileHelper::SDKFileHelper ()
protected

Default constructor: invoked only from subclasses

Member Function Documentation

PMString SDKFileHelper::absoluteFromRelative (const PMStringfolder,
const PMStringpath 
) const
protected

Make an absolute path given a folder and a relative path

Parameters
folderfolder relative to which we're going to navigate
pathspecifies path of interest
Returns
absolute path representation of supplied path if we could do it, empty if not
PMString SDKFileHelper::calcDefaultFileName () const
protected

Helper to provide a default file name (Untitled, translated per locale, for instance).

Returns
a string that can be used as a default file name e.g. for save operation
IDFile SDKFileHelper::GetAbsoluteFromRelative (const PMStringrelativePath) const

Return a IDFile that represents a file relative to this file. Replaces the old SDKUtilities::GetAbsolutePath which was potentially confusing to use.

Parameters
relativePathfor instance, ../images/something.gif
Returns
IDFile representing relative location
PMString SDKFileHelper::getAsMacPath (const PMStringpath) const
protected

Return the path as a Macintosh format path (pre OS X)

Parameters
pathspecifies the path of interest
Returns
representation in Mac format
PMString SDKFileHelper::getAsWinPath (const PMStringpath) const
protected

Return the path as a WIndows format path (not UNC)

Parameters
pathspecifies the path of interest
Returns
representation in Windows format
IDFile SDKFileHelper::GetIDFile () const

Return a IDFile that represents the file location. Note that IDFile is a PMString on Windows, but on Macintosh encapsulates the 'old' Mac file system specifics.

Returns
IDFile corresponding to the file
PMString SDKFileHelper::getMinusFirstElement (const PMStringpath) const
protected
Return string minus the first element from the pathname.

So "\\this\\that\\file" becomes "\\that\\file" and "../../file" becomes "../file"

Parameters
path
Returns
shortened form
PMString SDKFileHelper::getMinusLastElement (const PMStringpath) const
protected
return string minus the last element from the pathname.

So "\\this\\that\\file" becomes "\\this\\that"

Parameters
path
Returns
shortened from
PMString SDKFileHelper::GetParentFolderAsString () const
Returns
path to folder containing this file.
PMString SDKFileHelper::GetPath () const

Return a string-based representation of the path to this file.

Returns
path associated with this file
void SDKFileHelper::initFromString ()
protected

May be invoked from this or derived class when we have the path as a PMString and want to find a corresponding IDFile

Precondition
this->fPath is not empty
Postcondition
this->fSysFile should refer to a valid file
void SDKFileHelper::initFromSysFile ()
protected

May be invoked from this or derived class when we have file specified as IDFile and want PMString equivalent

Precondition
this->fSysFile refers to valid file
Postcondition
this->fPath is not empty
bool16 SDKFileHelper::isAbsolutePath (const PMStringpath) const
protected

Determine if the passed in string represents an absolute pathname. A win absolute pathname looks like "\\this\\that\\file" A mac absolute pathname looks like "this:that:file" a unix absolute pathname looks like "/this/that/file"

Parameters
paththe path passed in.
Returns
kTrue if the string represents an absolute pathname
bool16 SDKFileHelper::IsChosen () const

Determine if a IDFile has been acquired as a result of a 'Choice' by the user. Convenience method for the SDKxxxChooser methods to represent whether a choice occurred and expose this.

Returns
kTrue if this file has been chosen, kFalse otherwise (e.g. if it has been initialised by a string/IDFile in the constructor
bool16 SDKFileHelper::IsExisting () const

Tests whether the file exists. If the file has not yet been created or an invalid path or IDFile has been specified then this should be false.

Returns
kTrue if file exists, kFalse otherwise
bool16 SDKFileHelper::isMacPath (const PMStringpath) const
protected
Determines whether the path passed in can be a mac path. 

This is not a firm test of what constitutes a mac path, more just a heuristic that answers, "given a path, is it plausible it is a mac path?".

Parameters
paththe path used for the test.
Returns
true if this string could be a mac path.
bool16 SDKFileHelper::isMacPosixPathEnabled ()
static

Returns the Mac Path-Style

Returns
Mac Path-style in type PathStyle
bool16 SDKFileHelper::isUnixPath (const PMStringpath) const
protected
Determines if the passed in string represents a UNIX path.

This is not a firm test of what constitutes a UNIX path, more just a heuristic that answers, "given a path, is it plausible it is a UNIX path?".

Parameters
paththe path used for the test.
Returns
true if the path could be a unix path.
bool16 SDKFileHelper::isWinPath (const PMStringpath) const
protected
Determines whether the path passed in could be a win path.

This is not a firm test of what constitutes a win path, more just a heuristic that answers, "given a path, is it plausible it is a win path?".

Parameters
paththe path used for the test.
Returns
true if this string could be a win path.
void SDKFileHelper::setChosen (bool16 chsen)
protected

Mutator for the 'chosen' attribute; this is protected because client code should not be able to indicate that an end-user has made a choice.

Parameters
chsenIN specifies the new state for this attribute
void SDKFileHelper::setIDFile (const IDFilefile)
protected

Mutator for the IDFile stored in the instance; deliberately not exposed to client code. We need this method to let the derived classes that return a IDFile from a choice set the state of the instance.

Parameters
fileIN path in file system to file.
Precondition
IDFile valid
Postcondition
the fPath won't be initialised, only fSysFile changed
void SDKFileHelper::setPath (const PMStringpath)
protected

Mutator for the PMString path stored in the instance; deliberately not exposed to client code. We need

Parameters
pathIN path to file
Precondition
should be valid path in filesystem
Postcondition
the fSysFile won't be initialised, only fPath changed
void SDKFileHelper::traceInitializeDiagnostics (int32 e) const
protected

Report problems in creating a IDFile from a PMString

Parameters
eIN error number for core filename initialisation (see ICoreFilename)