1   /*
2    * Copyright 2003 - 2013 The eFaps Team
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  package org.efaps.update.schema.program;
22  import java.net.URL;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import org.efaps.update.schema.program.jasperreport.JasperReportImporter;
27  import org.efaps.update.util.InstallationException;
28  
29  
30  /**
31   * TODO comment!
32   *
33   * @author The eFaps Team
34   * @version $Id$
35   */
36  public class JasperReportUpdate extends AbstractSourceUpdate
37  {
38  
39      /**
40       * Link from JavaScript extending JavaScript.
41       */
42      private static final Link LINK2SUPER = new Link("Admin_Program_JasperReport2JasperReport", "From",
43                                                      "Admin_Program_JasperReport", "To");
44  
45      /**
46       * Set off all links for this JasperReportUpdate.
47       */
48      private static final Set<Link> ALLLINKS = new HashSet<Link>();
49      static {
50          JasperReportUpdate.ALLLINKS.add(JasperReportUpdate.LINK2SUPER);
51      }
52  
53      /**
54       * @param _url URL of the file
55       *
56       */
57      public JasperReportUpdate(final URL _url)
58      {
59          super(_url, "Admin_Program_JasperReport", JasperReportUpdate.ALLLINKS);
60      }
61  
62      /**
63       * Read the file.
64       *
65       * @param _url URL to the file
66       * @return JavaScriptUpdate
67       */
68      public static JasperReportUpdate readFile(final URL _url)
69      {
70          final JasperReportUpdate ret = new JasperReportUpdate(_url);
71          final JasperReportDefinition definition = ret.new JasperReportDefinition(_url);
72          ret.addDefinition(definition);
73          return ret;
74      }
75  
76      /**
77       * Definition for the JasperReport.
78       *
79       */
80      public class JasperReportDefinition extends AbstractSourceDefinition
81      {
82  
83          /**
84           * Importer for the JasperReport.
85           */
86          private JasperReportImporter jrxml = null;
87  
88          /**
89           * Construtor.
90           *
91           * @param _url URL to the JasperReport file
92           *
93           */
94          public JasperReportDefinition(final URL _url)
95          {
96              super(_url);
97          }
98  
99          /**
100          * Search the instance.
101          *
102          * @throws InstallationException if the source code for the Jasper
103          *                               Report could not be read or file could
104          *                               not be accessed because of the wrong
105          *                               URL
106          */
107         @Override
108         protected void searchInstance()
109             throws InstallationException
110         {
111             if (this.jrxml == null) {
112                 this.jrxml = new JasperReportImporter(getUrl());
113             }
114             setName(this.jrxml.getProgramName());
115 
116             if (this.jrxml.getEFapsUUID() != null) {
117                 addValue("UUID", this.jrxml.getEFapsUUID().toString());
118             }
119 
120 //            if (this.jrxml.getExtendSource() != null) {
121 //                addLink(JasperReportUpdate.LINK2SUPER, new LinkInstance(this.jrxml.getExtendSource()));
122 //            }
123 
124             if (getInstance() == null) {
125                 setInstance(this.jrxml.searchInstance());
126             }
127         }
128 
129         /**
130          * {@inheritDoc}
131          */
132         @Override
133         protected String getRevision()
134             throws InstallationException
135         {
136             if (this.jrxml == null) {
137                 this.jrxml = new JasperReportImporter(getUrl());
138             }
139             return this.jrxml.getRevision();
140         }
141     }
142 
143 }