1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.web.data;
24 
25 import com.sun.star.wizards.ui.UIConsts;
26 import java.util.Hashtable;
27 import java.util.Map;
28 
29 import javax.xml.transform.*;
30 import javax.xml.transform.stream.StreamSource;
31 
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.wizards.common.FileAccess;
34 
35 public class CGLayout extends ConfigSetItem
36 {
37 
38     public String cp_Name;
39     public String cp_FSName;
40     private Map templates;
41 
createTemplates(XMultiServiceFactory xmsf)42     private void createTemplates(XMultiServiceFactory xmsf) throws Exception
43     {
44 
45         templates = new Hashtable(3);
46 
47         TransformerFactory tf = TransformerFactory.newInstance();
48 
49         String workPath = getSettings().workPath;
50         FileAccess fa = new FileAccess(xmsf);
51         String stylesheetPath = fa.getURL(getSettings().workPath, "layouts/" + cp_FSName);
52 
53         String[] files = fa.listFiles(stylesheetPath, false);
54 
55         for (int i = 0; i < files.length; i++)
56         {
57             if (FileAccess.getExtension(files[i]).equals("xsl"))
58             {
59                 templates.put(FileAccess.getFilename(files[i]), tf.newTemplates(new StreamSource(files[i])));
60             }
61         }
62     }
63 
getImageUrls()64     public Object[] getImageUrls()
65     {
66         Object[] sRetUrls = new Object[1];
67         int ResId = UIConsts.RID_IMG_WEB + (cp_Index * 2);
68         return new Integer[]
69                 {
70                     new Integer(ResId), new Integer(ResId + 1)
71                 };
72     }
73 
getTemplates(XMultiServiceFactory xmsf)74     public Map getTemplates(XMultiServiceFactory xmsf) throws Exception
75     {
76 
77         // TODO uncomment...
78         // if (templates==null)
79         createTemplates(xmsf);
80 
81         return templates;
82     }
83 }
84