xref: /aoo41x/main/autodoc/source/ary/loc/loca_le.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include "loca_le.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <ary/loc/loc_dir.hxx>
34*cdf0e10cSrcweir #include <ary/loc/loc_file.hxx>
35*cdf0e10cSrcweir #include <ary/loc/loc_root.hxx>
36*cdf0e10cSrcweir #include <loc_internalgate.hxx>
37*cdf0e10cSrcweir #include "locs_le.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace ary
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir namespace loc
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir DYN LocationPilot &
48*cdf0e10cSrcweir InternalGate::Create_Locations_()
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     return *new LocationAdmin;
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir inline Le_Storage &
57*cdf0e10cSrcweir LocationAdmin::Storage() const
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     csv_assert(pStorage);
60*cdf0e10cSrcweir     return *pStorage.MutablePtr();
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir LocationAdmin::LocationAdmin()
65*cdf0e10cSrcweir     :   pStorage(new Le_Storage)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir LocationAdmin::~LocationAdmin()
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir Root &
74*cdf0e10cSrcweir LocationAdmin::CheckIn_Root(const csv::ploc::Path & i_path)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     Dyn<Root>
77*cdf0e10cSrcweir         p_new( new Root(i_path) );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     Le_id
80*cdf0e10cSrcweir         id = Storage().RootIndex().Search(p_new->LocalName());
81*cdf0e10cSrcweir     if ( id.IsValid() )
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         return ary_cast<Root>(Storage()[id]);
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     Root *
87*cdf0e10cSrcweir         ret = p_new.Ptr();
88*cdf0e10cSrcweir     Storage().Store_Entity(*p_new.Release());
89*cdf0e10cSrcweir     Storage().RootIndex().Add(ret->LeId());
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     Directory *
92*cdf0e10cSrcweir         p_rootdir = new Directory(ret->LeId());
93*cdf0e10cSrcweir     Storage().Store_Entity(*p_rootdir);
94*cdf0e10cSrcweir     ret->Assign_Directory(p_rootdir->LeId());
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     return *ret;
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir File &
100*cdf0e10cSrcweir LocationAdmin::CheckIn_File( const String  &                   i_name,
101*cdf0e10cSrcweir                                   const csv::ploc::DirectoryChain & i_subPath,
102*cdf0e10cSrcweir                                   Le_id                             i_root )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     Root &
105*cdf0e10cSrcweir         root = Find_Root(i_root);
106*cdf0e10cSrcweir     Directory &
107*cdf0e10cSrcweir         parent_dir = CheckIn_Directories(
108*cdf0e10cSrcweir                         Find_Directory(root.MyDir()),
109*cdf0e10cSrcweir                         i_subPath.Begin(),
110*cdf0e10cSrcweir                         i_subPath.End() );
111*cdf0e10cSrcweir     Le_id
112*cdf0e10cSrcweir         fid = parent_dir.Search_File(i_name);
113*cdf0e10cSrcweir     if (NOT fid.IsValid())
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         File *
116*cdf0e10cSrcweir             ret = new File(i_name, parent_dir.LeId());
117*cdf0e10cSrcweir         Storage().Store_Entity(*ret);
118*cdf0e10cSrcweir         parent_dir.Add_File(*ret);
119*cdf0e10cSrcweir         return *ret;
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir     else
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         return Find_File(fid);
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir Root &
128*cdf0e10cSrcweir LocationAdmin::Find_Root(Le_id  i_id) const
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     return ary_cast<Root>(Storage()[i_id]);
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir Directory &
134*cdf0e10cSrcweir LocationAdmin::Find_Directory(Le_id i_id) const
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     return ary_cast<Directory>(Storage()[i_id]);
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir File &
140*cdf0e10cSrcweir LocationAdmin::Find_File(Le_id i_id) const
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     return ary_cast<File>(Storage()[i_id]);
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir Directory &
146*cdf0e10cSrcweir LocationAdmin::CheckIn_Directory( Directory &         io_parent,
147*cdf0e10cSrcweir                                        const String &      i_name )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     Le_id
150*cdf0e10cSrcweir         did = io_parent.Search_Dir(i_name);
151*cdf0e10cSrcweir     if (NOT did.IsValid())
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         Directory *
154*cdf0e10cSrcweir             ret = new Directory(i_name, io_parent.LeId());
155*cdf0e10cSrcweir         Storage().Store_Entity(*ret);
156*cdf0e10cSrcweir         io_parent.Add_Dir(*ret);
157*cdf0e10cSrcweir         return *ret;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir     else
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         return Find_Directory(did);
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir Directory &
166*cdf0e10cSrcweir LocationAdmin::CheckIn_Directories(
167*cdf0e10cSrcweir                             Directory &                     io_root,
168*cdf0e10cSrcweir                             StringVector::const_iterator    i_beginSubPath,
169*cdf0e10cSrcweir                             StringVector::const_iterator    i_endSubPath )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     if (i_beginSubPath == i_endSubPath)
172*cdf0e10cSrcweir         return io_root;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     Directory &
175*cdf0e10cSrcweir         next = CheckIn_Directory(io_root, *i_beginSubPath);
176*cdf0e10cSrcweir     return CheckIn_Directories(next, i_beginSubPath+1, i_endSubPath);
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir }   // namespace loc
181*cdf0e10cSrcweir }   // namespace ary
182