/**
   * Factory method that creates a concrete instance of the <code>PCVResource</code> interface for
   * the given <code>nameIn</code>, the DOM <code>Document</code> and the <code>VirtualCollection
   * </code>.
   *
   * @param collIn The context <code>VirtualCollection</code> instance for the <code>PCVResource
   *     </code> that will be created
   * @param nameIn The name of this new <code>PCVResource</code>.
   * @param pcvDocIn The raw XML data for this new <code>PCVResource</code>
   * @return A concrete implementation of <code>PCVResource</code> that is associated with the given
   *     <code>collIn</code>.
   * @throws XMLDBException If anything goes wrong during the instantiation or a database specific
   *     error occures.
   * @see _de.xplib.nexd.api.pcvr.AbstractPCVRFactory#newPCVResource(
   *     _de.xplib.nexd.api.VirtualCollection, java.lang.String, org.w3c.dom.Document)
   */
  public PCVResource newPCVResource(
      final VirtualCollection collIn, final String nameIn, final Document pcvDocIn)
      throws XMLDBException {

    pcvDocIn.getDocumentElement().setAttribute(PCVResource.ATTR_SCHEMA_RESNAME, nameIn);

    Document doc = (Document) pcvDocIn.cloneNode(true);

    return new PCVResourceImpl(collIn, doc, nameIn);
  }
 /**
  * Construct a new document by cloning an existing document, copying only the master spreads. Note
  * that this is different from a generic loadObject(InDesignObject) operation (as for
  * InDesignObject), which is a full copy.
  *
  * @param inddDoc
  * @throws Exception
  */
 public InDesignDocument(InDesignDocument inddDoc, boolean removeSpreads) throws Exception {
   Document cloneSourceDoc = inddDoc.getDataSource();
   if (cloneSourceDoc == null)
     throw new Exception("Got null data source from input InDesign document.");
   this.dataSource = (Document) cloneSourceDoc.cloneNode(true);
   logger.debug("InDesignDocument(inddDoc): setting dataSource to " + dataSource);
   Element clonedDataSource = this.dataSource.getDocumentElement();
   if (removeSpreads) {
     // Now delete the components that hold actual content, namely spreads and stories:
     for (Element spread : DataUtil.getElementChildren(clonedDataSource, null, SPRD_TAGNAME)) {
       clonedDataSource.removeChild(spread);
     }
     // FIXME: For stories, we only want to delete stories that are associated with frames on
     // normal spreads, not master spreads. So for now just leaving them in.
     //			for (Element story : DataUtil.getElementChildren(clonedDataSource, null, CFLO_TAGNAME)) {
     //				clonedDataSource.removeChild(story);
     //			}
   }
   this.load(clonedDataSource);
   this.spreads.clear(); // Just to make sure
   // Now make sure there is a spread as a document must have at least one spread.
   Spread spread = this.newSpread(this.getMasterSpreads().get(0).getName());
   spread.addPage(1);
 }
 private void enviarFicheroUnidadEnPorciones(EnvioErroneo envio, Document doc, Element unidad)
     throws TransformerException {
   // Creamos un nuevo nodo de unidad
   Element nuevaUnidad = doc.createElement("UNIDAD");
   doc.getElementsByTagName("UNIDADES").item(0).appendChild(nuevaUnidad);
   // Le añadimos los parámetros
   Node xUnidad = unidad.getElementsByTagName("X_UNIDAD").item(0).cloneNode(true);
   doc.adoptNode(xUnidad);
   String codUnidad = xUnidad.getTextContent();
   Node xNombre = unidad.getElementsByTagName("T_NOMBRE").item(0).cloneNode(true);
   doc.adoptNode(xNombre);
   nuevaUnidad.appendChild(xUnidad);
   nuevaUnidad.appendChild(xNombre);
   // Ahora añadimos los alumnos
   Element alumnos = doc.createElement("ALUMNOS");
   nuevaUnidad.appendChild(alumnos);
   // Y vamos creando un fichero por cada alumno
   NodeList nl = unidad.getElementsByTagName("ALUMNOS").item(0).getChildNodes();
   for (int i = 0; i < nl.getLength(); i++) {
     Object obj = nl.item(i);
     if (!(obj instanceof Element)) {
       continue;
     }
     Element al = (Element) obj;
     al = (Element) al.cloneNode(true);
     // Clonamos el documento
     Document docAlumno = (Document) doc.cloneNode(true);
     docAlumno.adoptNode(al);
     // Y le añadimos el
     docAlumno.getElementsByTagName("ALUMNOS").item(0).appendChild(al);
     // Guardamos el archivo y lo enviamos
     String contenido = docToString(docAlumno);
     File tmp = new File(getCarpetaFallidos(), "tmp_unidad_" + codUnidad + "_" + i + ".xml");
     Archivo.setContenido(contenido, "latin1", tmp, false);
     String codigoOperacion = Cripto.md5(tmp.getName() + "" + Math.random());
     int ret = enviarFichero(tmp, codigoOperacion);
     if (ret == GestorEnvioFaltas.RET_ERROR_PROCESANDO) {
       envio.getErroneos().add(tmp);
       // Cogemos el dato X_MATRICULA
       String datoMatricula = al.getElementsByTagName("X_MATRICULA").item(0).getTextContent();
       Alumno a = Alumno.getAlumnoDesdeCodFaltas(datoMatricula);
       if (a != null) {
         AlumnoEnvioErroneo aee = new AlumnoEnvioErroneo(a);
         envio.getAlumnosFallidos().add(aee);
         // Ahora tenemos que localizar las fechas distintas donde falla
         NodeList nlf = al.getElementsByTagName("F_FALASI");
         ArrayList<String> fechas = new ArrayList<String>();
         for (int x = 0; x < nlf.getLength(); x++) {
           String sFecha = nlf.item(x).getTextContent();
           if (!fechas.contains(sFecha)) {
             fechas.add(sFecha);
           }
         }
         aee.setInfo(Str.implode(fechas, "; "));
       }
     } else if (ret == GestorEnvioFaltas.RET_ERROR_ENVIANDO) {
       envio.getFallidos().add(tmp);
     } else {
       tmp.delete();
     }
   }
 }
  public void enviarFicheroGeneralEnPorciones(EnvioErroneo envio) {
    try {

      // Tenemos que dividir el archivo por cursos y unidades
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      documentBuilderFactory.setNamespaceAware(false);
      documentBuilderFactory.setValidating(false);
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      File tmpX = new File(getCarpetaFallidos(), envio.getFicheroEnvio().getName() + ".tmp");
      Archivo.setContenido(
          Archivo.getContenido(envio.getFicheroEnvio(), "latin1"), "UTF-8", tmpX, false);
      Document doc = documentBuilder.parse(tmpX);
      tmpX.delete();
      // Ahore recorremos el documento generando un archivo nuevo por cada version
      Node nCursos = doc.getElementsByTagName("CURSOS").item(0);
      Node datosGenerales = doc.getElementsByTagName("DATOS_GENERALES").item(0);
      NodeList cursos = nCursos.getChildNodes();
      for (int i = 0; i < cursos.getLength(); i++) {
        Object obj = cursos.item(i);
        if (!(obj instanceof Element)) {
          continue;
        }
        Element cursoActual = (Element) obj;
        // Creamos un nuevo documento
        Document nuevoDoc = documentBuilder.newDocument();
        // Le añadimos un nodo de servicio
        Node servicio = nuevoDoc.createElement("SERVICIO");
        nuevoDoc.appendChild(servicio);
        // A este le añadimos los datos generales (clonados)
        Node nuevoDatosGenerales = datosGenerales.cloneNode(true);
        nuevoDoc.adoptNode(nuevoDatosGenerales);
        servicio.appendChild(nuevoDatosGenerales);
        // Creamos un nodo de cursos y se lo añadimos
        Node nuevoCursos = nuevoDoc.createElement("CURSOS");
        servicio.appendChild(nuevoCursos);
        // Creamos un nodo de curso y se lo añadimos
        Node nuevoCurso = nuevoDoc.createElement("CURSO");
        nuevoCursos.appendChild(nuevoCurso);
        // Le añadimos los datos al curso
        Node el1 = cursoActual.getElementsByTagName("X_OFERTAMATRIG").item(0).cloneNode(true);
        nuevoDoc.adoptNode(el1);
        String nombreCurso = el1.getTextContent();
        Node el2 = cursoActual.getElementsByTagName("D_OFERTAMATRIG").item(0).cloneNode(true);
        nuevoDoc.adoptNode(el2);
        nuevoCurso.appendChild(el1);
        nuevoCurso.appendChild(el2);
        // Creamos un nodo de unidades y se lo añadimos
        Node nuevoUnidades = nuevoDoc.createElement("UNIDADES");
        nuevoCurso.appendChild(nuevoUnidades);
        // Ahora recorremos las unidades creando un documento nuevo por cada una
        Element nodoUnidadesActual = (Element) cursoActual.getElementsByTagName("UNIDADES").item(0);
        NodeList unidades = nodoUnidadesActual.getChildNodes();
        for (int x = 0; x < unidades.getLength(); x++) {
          Node nObj = unidades.item(x);
          if (!(nObj instanceof Element)) {
            continue;
          }
          // Clonamos la unidad
          Node unidad = nObj.cloneNode(true);
          // Clonamos el documento completo
          Document docActual = (Document) nuevoDoc.cloneNode(true);
          // Adoptamos el nodo creado
          docActual.adoptNode(unidad);
          // Y se lo añadimos a las unidades
          docActual.getElementsByTagName("UNIDADES").item(0).appendChild(unidad);
          // Guardamos el documento y lo enviamos
          String contenido = docToString(docActual);
          File tmp = new File(getCarpetaFallidos(), "tmp_curso_" + nombreCurso + "_" + x + ".xml");
          Archivo.setContenido(contenido, "latin1", tmp, false);
          String codigoOperacion = Cripto.md5(tmp.getName() + "" + Math.random());
          int ret = enviarFichero(tmp, codigoOperacion);
          if (ret == GestorEnvioFaltas.RET_ERROR_PROCESANDO) {
            tmp.delete();
            // Sobre ese archivo tenemos que hacer envíos alumno por alumno
            // Clonamos el documento
            docActual = (Document) nuevoDoc.cloneNode(true);
            // Y procesamos el envío
            enviarFicheroUnidadEnPorciones(envio, docActual, (Element) unidad);
          } else if (ret == GestorEnvioFaltas.RET_ERROR_ENVIANDO) {
            envio.getFallidos().add(tmp);
          } else {
            tmp.delete();
          }
        }
      }
    } catch (Exception ex) {
      Logger.getLogger(GeneradorFicherosSeneca.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Пример #5
0
 @Override
 public Node cloneNode(boolean deep) {
   return new XMLDocumentStruct((Document) doc.cloneNode(deep), caseSensitive);
 }
Пример #6
0
 @Override
 public Collection duplicate(boolean deepCopy) {
   return new XMLDocumentStruct((Document) doc.cloneNode(deepCopy), caseSensitive);
 }