xref: /AOO41X/main/wizards/com/sun/star/wizards/web/data/CGLayout.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 package com.sun.star.wizards.web.data;
28 
29 import com.sun.star.wizards.ui.UIConsts;
30 import java.util.Hashtable;
31 import java.util.Map;
32 
33 import javax.xml.transform.*;
34 import javax.xml.transform.stream.StreamSource;
35 
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.wizards.common.FileAccess;
38 
39 public class CGLayout extends ConfigSetItem
40 {
41 
42     public String cp_Name;
43     public String cp_FSName;
44     private Map templates;
45 
46     private void createTemplates(XMultiServiceFactory xmsf) throws Exception
47     {
48 
49         templates = new Hashtable(3);
50 
51         TransformerFactory tf = TransformerFactory.newInstance();
52 
53         String workPath = getSettings().workPath;
54         FileAccess fa = new FileAccess(xmsf);
55         String stylesheetPath = fa.getURL(getSettings().workPath, "layouts/" + cp_FSName);
56 
57         String[] files = fa.listFiles(stylesheetPath, false);
58 
59         for (int i = 0; i < files.length; i++)
60         {
61             if (FileAccess.getExtension(files[i]).equals("xsl"))
62             {
63                 templates.put(FileAccess.getFilename(files[i]), tf.newTemplates(new StreamSource(files[i])));
64             }
65         }
66     }
67 
68     public Object[] getImageUrls()
69     {
70         Object[] sRetUrls = new Object[1];
71         int ResId = UIConsts.RID_IMG_WEB + (cp_Index * 2);
72         return new Integer[]
73                 {
74                     new Integer(ResId), new Integer(ResId + 1)
75                 };
76     }
77 
78     public Map getTemplates(XMultiServiceFactory xmsf) throws Exception
79     {
80 
81         // TODO uncomment...
82         // if (templates==null)
83         createTemplates(xmsf);
84 
85         return templates;
86     }
87 }
88