예제 #1
0
  public static void main(String[] args) throws Exception {

    /* You should do this ONLY ONCE in the whole application life-cycle: */

    /* Create and adjust the configuration singleton */
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setDirectoryForTemplateLoading(new File("/Users/ian.goldsmith/projects/freemarker"));
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    /*
     * You usually do these for MULTIPLE TIMES in the application
     * life-cycle:
     */

    /* Create a data-model */
    Map message = new HashMap();
    message.put(
        "contentAsXml",
        freemarker.ext.dom.NodeModel.parse(
            new File("/Users/ian.goldsmith/projects/freemarker/test.xml")));

    Map root = new HashMap();
    root.put("message", message);

    /* Get the template (uses cache internally) */
    Template temp = cfg.getTemplate("testxml.ftl");

    /* Merge data-model with template */
    Writer out = new OutputStreamWriter(System.out);
    temp.process(root, out);
    // Note: Depending on what `out` is, you may need to call `out.close()`.
    // This is usually the case for file output, but not for servlet output.
  }
예제 #2
0
  public NodeModel getXmlNodeModel() {
    NodeModel nodeModel = null;

    try {
      nodeModel = NodeModel.parse(new InputSource(new StringReader(getXml())));
    } catch (Throwable err) {
      logger.error(err);
    }

    return nodeModel;
  }
예제 #3
0
  /**
   * Método público que permite generar fichero de metadatos en carpeta separada. Comprueba si el
   * fichero manifest tiene un lomes integrado o un metadato externo. si el ODE no tiene metadatos..
   * no genera nada
   *
   * @param pathOde path del ODE que se desea exportar
   * @param dirDestino directorio donde se va a copiar la catalogacion lomes
   * @param subdirDestino target subdirectory
   * @throws Exception
   */
  public void obtenerLOMES(
      String pathOde, String dirDestino, String subdirDestino, String lomFileName)
      throws Exception {
    this.pathOde = pathOde;
    this.dirDestino = dirDestino;

    crearCarpeta(dirDestino + File.separator + subdirDestino);

    modelo = NodeModel.parse(new File(pathOde + MANIFEST));
    root.put("doc", modelo);

    pathLomesExterno = chequearLomes();
    obtenerLOMES(subdirDestino + File.separator + lomFileName);
  }
예제 #4
0
  /**
   * metodo que permite verificar si un fichero lomes externo es un fichero lomes
   *
   * @param lomesExterno path al fichero xml con los metadatos
   * @return
   *     <ul>
   *       <li>true .- si es un lomes
   *       <li>false.- si no es un lomes
   *     </ul>
   */
  private boolean chequearTipoLomesExterno(String lomesExterno) throws Exception {
    boolean resultado = false;

    NodeModel modeloExterno = null;
    try {
      modeloExterno = NodeModel.parse(new File(pathOde + "/" + lomesExterno));
      Node nodo = modeloExterno.getNode().getChildNodes().item(0);
      if (nodo != null
          && nodo.getNamespaceURI() != null
          && nodo.getNamespaceURI().equals("http://ltsc.ieee.org/xsd/LOM")) {
        resultado = true;
      }

    } catch (Exception e) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Error en GeneradorHTML:chequearTipoLomesExterno .. problemas al leer fichero lomes externo: "
                + e.getMessage());
      }
      throw e;
    }
    return resultado;
  }
예제 #5
0
  /**
   * metodo que permite generar los ficheros html necesarios para visualizar el ODE como html
   *
   * @param pathOde path donde se encuentra el ODE que se desea exportar
   * @param dirDestino directorio donde se van a generar los ficheros html
   * @throws Exception
   */
  public void generarFrames(String pathOde, String dirDestino) throws Exception {
    this.pathOde = pathOde;
    this.dirDestino = dirDestino;
    crearCarpeta(dirDestino + "/contenido");

    try {

      modelo = NodeModel.parse(new File(pathOde + MANIFEST));
      pathLomesExterno = chequearLomes();

      generarBlanco();
      generarContenidoFrame();
      generarContenidoIndex();
      generarMenu();
      generarCabecera();
      generarIndex();

    } catch (Exception e) {
      if (logger.isDebugEnabled()) {
        logger.debug("Error en GeneradorHTML:generarFrames .. " + e.getMessage());
      }
      throw new Exception(e);
    }
  }
예제 #6
0
  /**
   * Método para generar fichero menu.html
   *
   * @throws Exception
   */
  private void generarMenu() throws Exception {
    FileOutputStream fo = null;
    Writer out = null;
    File index = null;
    Template temp;
    try {
      modelo = NodeModel.parse(new File(pathOde + MANIFEST));
      root.put("doc", modelo);

      temp = cfg.getTemplate("menuXML.ftl");
      index = new File(dirDestino + "/contenido/menu.html");
      boolean creado = index.createNewFile();
      if (creado) {
        fo = new FileOutputStream(index);
        out = new OutputStreamWriter(fo);
        temp.process(root, out);
        out.flush();
      }

    } catch (Exception e) {

      if (logger.isDebugEnabled()) {
        logger.debug("Error en GeneradorHTML:generarMenu .. " + e.getMessage());
      }
      throw e;
    } finally {
      index = null;
      if (fo != null) {
        try {
          fo.close();
          out.close();
        } catch (IOException e) {
        }
      }
    }
  }
예제 #7
0
  /**
   * Método que devuelve el título de ode en caso que existiera.. busca el título en el lomes
   * integrado en el manifest o en algun lomes externo si lo tuviera.
   *
   * @return String con el título del ode
   */
  private String obtenerTitulo() throws Exception {
    String resultado = "";
    if (pathLomesExterno == null) return resultado;
    boolean terminado = false;

    if (pathLomesExterno.equals("")) {
      Node nodo = modelo.getNode().getChildNodes().item(0);
      NodeModel.simplify(nodo);

      NodeList hijos = nodo.getChildNodes();
      for (int i = 0; i < hijos.getLength() && !terminado; i++) {
        Node child = hijos.item(i);
        if (child.getLocalName() != null && child.getLocalName().equals("metadata")) {

          NodeList hijos2 = child.getChildNodes();
          for (int j = 0; j < hijos2.getLength() && !terminado; j++) {
            Node child2 = hijos2.item(j);
            if (child2.getLocalName() != null && child2.getLocalName().equals("lom")) {

              NodeList hijos3 = child2.getChildNodes();
              for (int k = 0; k < hijos3.getLength() && !terminado; k++) {
                Node child3 = hijos3.item(k);
                if (child3.getLocalName() != null && child3.getLocalName().equals("general")) {

                  NodeList hijos4 = child3.getChildNodes();
                  for (int l = 0; l < hijos4.getLength() && !terminado; l++) {
                    Node child4 = hijos4.item(l);
                    if (child4.getLocalName() != null && child4.getLocalName().equals("title")) {

                      NodeList hijos5 = child4.getChildNodes();
                      for (int ll = 0; ll < hijos5.getLength() && !terminado; ll++) {
                        Node child5 = hijos5.item(ll);
                        if (child5.getLocalName() != null
                            && child5.getLocalName().equals("string")) {
                          resultado = child5.getFirstChild().getNodeValue();

                          terminado = true;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        } // metadata
      }
    } else {
      NodeModel modeloExterno = null;
      try {
        modeloExterno = NodeModel.parse(new File(pathOde + "/" + pathLomesExterno));

        Node nodo = modeloExterno.getNode().getChildNodes().item(0);
        NodeModel.simplify(nodo);

        NodeList hijos = nodo.getChildNodes();
        for (int i = 0; i < hijos.getLength() && !terminado; i++) {
          Node child = hijos.item(i);
          if (child.getLocalName() != null && child.getLocalName().equals("general")) {

            NodeList hijos2 = child.getChildNodes();
            for (int j = 0; j < hijos2.getLength() && !terminado; j++) {
              Node child2 = hijos2.item(j);
              if (child2.getLocalName() != null && child2.getLocalName().equals("title")) {

                NodeList hijos3 = child2.getChildNodes();
                for (int k = 0; k < hijos3.getLength() && !terminado; k++) {
                  Node child3 = hijos3.item(k);
                  if (child3.getLocalName() != null && child3.getLocalName().equals("string")) {
                    resultado = child3.getFirstChild().getNodeValue();
                    terminado = true;
                  }
                }
              }
            }
          } // metadata
        }

      } catch (Exception e) {
        if (logger.isDebugEnabled()) {
          logger.debug("Error en GeneradorHTML:obtenerTitulo .. " + e.getMessage());
        }
        throw e;
      }
    }

    return resultado;
  }