View Javadoc

1   package fr.in2p3.jsaga.helpers.xslt;
2   
3   import fr.in2p3.jsaga.Base;
4   import fr.in2p3.jsaga.engine.descriptors.AdaptorDescriptors;
5   
6   import javax.xml.transform.*;
7   import javax.xml.transform.stream.StreamSource;
8   import java.io.*;
9   
10  /* ***************************************************
11  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12  * ***             http://cc.in2p3.fr/             ***
13  * ***************************************************
14  * File:   TransformerURIResolver
15  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16  * Date:   28 juin 2007
17  * ***************************************************
18  * Description:                                      */
19  /**
20   *
21   */
22  public class TransformerURIResolver implements URIResolver {
23      public Source resolve(String href, String base) throws TransformerException {
24          if ("SystemProperties.xml".equals(href)) {
25              ByteArrayOutputStream xml = new ByteArrayOutputStream();
26              try {
27                  System.getProperties().storeToXML(xml, "System properties");
28                  BufferedReader reader = new BufferedReader(new StringReader(xml.toString()));
29                  reader.readLine();
30                  reader.readLine();  // remove DTD (prevent from raising FileNotFoundException)
31                  return new StreamSource(reader);
32              } catch (IOException e) {
33                  throw new TransformerException(e);
34              }
35          } else if ("AdaptorsDescriptor.xml".equals(href)) {
36              try {
37                  byte[] xml = AdaptorDescriptors.getInstance().toByteArray();
38                  return new StreamSource(new ByteArrayInputStream(xml));
39              } catch (Exception e) {
40                  throw new TransformerException(e);
41              }
42          } else if (href.startsWith("var/")) {
43              return new StreamSource(new File(Base.JSAGA_VAR, href.substring(4)));
44          } else {
45              return new StreamSource(new File(Base.JSAGA_HOME, href));
46          }
47      }
48  }