xref: /aoo42x/main/autodoc/source/cosv/storage/ploc.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <cosv/ploc.hxx>
30 
31 // NOT FULLY DECLARED SERVICES
32 #include <cosv/bstream.hxx>
33 
34 
35 
36 
37 namespace csv
38 {
39 namespace ploc
40 {
41 
42 
43 Path::Path( const char *        i_sPath,
44             bool                i_bPathIsAlwaysDir,
45             const char *        i_sDelimiter        )
46     :   pRoot(0)
47         // aPath,
48         // sFile
49 {
50     Set(i_sPath, i_bPathIsAlwaysDir, i_sDelimiter );
51 }
52 
53 Path::Path( const Path & i_rPath )
54     :   pRoot(i_rPath.pRoot->CreateCopy()),
55         aPath(i_rPath.aPath),
56         sFile(i_rPath.sFile)
57 {
58 }
59 
60 Path::~Path()
61 {
62 }
63 
64 Path &
65 Path::operator=( const Path & i_rPath )
66 {
67     pRoot = i_rPath.pRoot->CreateCopy();
68     aPath = i_rPath.aPath;
69     sFile = i_rPath.sFile;
70     return *this;
71 }
72 
73 
74 void
75 Path::Set( const char *        i_sPath,
76            bool                i_bPathIsAlwaysDir,
77            const char *        i_sDelimiter        )
78 {
79     if ( *i_sDelimiter != '\\' AND *i_sDelimiter != '/' )
80         return;
81 
82     const char *
83         restPath = 0;
84     pRoot = Root::Create_( restPath, i_sPath, i_sDelimiter );
85     if (restPath == 0)
86         return;
87 
88     aPath.Set(restPath, i_bPathIsAlwaysDir, i_sDelimiter);
89 
90     if (NOT i_bPathIsAlwaysDir)
91     {
92 		const char *
93 		    file = strrchr( restPath, *i_sDelimiter );
94         if (file == 0)
95 			file = restPath;
96 		else
97 			file++;
98         sFile = file;
99     }
100 }
101 
102 void
103 Path::SetFile( const String & i_sName )
104 {
105     sFile = i_sName;
106 }
107 
108 const char *
109 Path::FileExtension() const
110 {
111     const char *
112         ext = strrchr(sFile, '.');
113     if (ext != 0)
114         ++ext;
115     else
116         ext = "";
117     return ext;
118 }
119 
120 bool
121 Path::IsValid() const
122 {
123     return RootDir().OwnDelimiter() != 0;
124 }
125 
126 void
127 Path::Get( ostream & o_rPath ) const
128 {
129     if (NOT IsValid())
130         return;
131 
132     pRoot->Get( o_rPath );
133     aPath.Get( o_rPath, pRoot->OwnDelimiter() );
134 
135     if ( sFile.length() > 0 )
136         o_rPath << sFile;
137 
138 }
139 
140 void
141 Path::Get( bostream & o_rPath ) const
142 {
143     if (NOT IsValid())
144         return;
145 
146     pRoot->Get( o_rPath );
147     aPath.Get( o_rPath, pRoot->OwnDelimiter() );
148 
149     if ( sFile.length() > 0 )
150         o_rPath.write( sFile );
151 }
152 
153 
154 
155 
156 } // namespace ploc
157 } // namespace csv
158