private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) {
    String docloc =
        this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
    URL docurl = ClassLoader.getSystemResource(docloc);

    if (docurl == null) {
      throw new IllegalStateException("Unable to get resource " + docloc);
    }

    SAXBuilder builder = new SAXBuilder(validating);
    // builder.setValidation(validating);
    builder.setExpandEntities(expand);
    Document doc = null;
    try {
      doc = builder.build(docurl);
    } catch (JDOMException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (doc == null) {
      fail("Unable to parse document, see output.");
    }

    Format fmt = Format.getCompactFormat();
    if (encoding != null) {
      fmt.setEncoding(encoding);
    }
    XMLOutputter xout = new XMLOutputter(fmt);

    String actual = xout.outputString(doc.getRootElement());
    assertEquals(expect, actual);
  }
  /*
   * 初始化signlist
   */
  private static void initSignList() {
    SAXBuilder builder = new SAXBuilder();
    Document read_doc = null;
    try {
      read_doc = builder.build("./bin/com/fc/config/operator.xml");
    } catch (JDOMException | IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    SignInfo si = null;
    Element stu = read_doc.getRootElement(); // 读取根节点
    List<Element> list = stu.getChildren("binaryOperator"); // 获取根元素的所有子节点
    List<Element> unarylist = stu.getChildren("unaryOperator");
    for (int i = 0; i < list.size(); i++) { // 遍历子节点,并取出其属性、子节点的文本。
      Element e = list.get(i);
      String classURL = e.getChildText("class");
      String name = e.getAttribute("name").getValue();
      String pri = e.getAttribute("priority").getValue();
      si = new SignInfo(name, classURL, Integer.parseInt(pri));
      signlist.put(name, si);
    }
    for (int i = 0; i < unarylist.size(); i++) { // 遍历子节点,并取出其属性、子节点的文本。
      Element e = unarylist.get(i);
      String classURL = e.getChildText("class");
      String name = e.getAttribute("name").getValue();
      String pri = e.getAttribute("priority").getValue();
      si = new SignInfo(name, classURL, Integer.parseInt(pri));
      signlist.put(name, si);
    }
  }
 public LocaleExtractor(
     MavenProjectInfo mavenProjectInfo, String manifestFileName, String phrescoTargetDir)
     throws Exception {
   try {
     System.setProperty(
         "javax.xml.parsers.SAXParserFactory",
         "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
     builder = new SAXBuilder();
     // disabling xml validation
     builder.setValidation(false);
     builder.setIgnoringElementContentWhitespace(true);
     loc = mavenProjectInfo.getBaseDir() + File.separator + phrescoTargetDir;
     loopDoc =
         builder.build(
             new File(
                 mavenProjectInfo.getBaseDir()
                     + mavenProjectInfo
                         .getProject()
                         .getProperties()
                         .getProperty("phresco.theme.target.dir")
                     + File.separator
                     + mavenProjectInfo
                         .getProject()
                         .getProperties()
                         .getProperty("phresco.theme.config.name")));
   } catch (JDOMException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  public List<Character> getCharacters(File input) throws JDOMException, IOException {
    List<Character> result = new LinkedList<Character>();
    SAXBuilder saxBuilder = new SAXBuilder();
    for (File file : input.listFiles()) {
      Document document = null;
      try {
        document = saxBuilder.build(file);
      } catch (JDOMParseException parseException) {
        // file not a valid xml file (e.g. config.txt)
        continue;
      }

      XPathFactory xpf = XPathFactory.instance();
      XPathExpression<Element> xpath =
          xpf.compile("/treatment/description/statement/structure/character", Filters.element());
      List<Element> elements = xpath.evaluate(document);
      for (Element element : elements) {
        String charType = element.getAttributeValue("char_type");
        if (charType != null && charType.equals("range_value")) {
          String toValue = element.getAttributeValue("to");
          String fromValue = element.getAttributeValue("from");
          String category = element.getAttributeValue("name");
          result.add(new Character(toValue, category));
          result.add(new Character(fromValue, category));
        } else {
          String value = element.getAttributeValue("value");
          String category = element.getAttributeValue("name");
          result.add(new Character(value, category));
        }
      }
    }
    return result;
  }
Exemple #5
0
  private String chooserQuery() {
    Random r = new Random();
    File experimentFile = new File(queryFile);
    SAXBuilder sb = new SAXBuilder();
    Document d = null;
    try {
      d = sb.build(experimentFile);
    } catch (JDOMException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    List<String> queries = new ArrayList<String>();

    Element jpameterTag = d.getRootElement();
    Element queriesTag = jpameterTag.getChild("queries");

    List<Element> query = queriesTag.getChildren();

    for (Element e : query) {
      Element type = e.getChild("type");
      if (Integer.parseInt(type.getValue()) == typeQuery + 1) {
        Element sql = e.getChild("sql");
        queries.add(sql.getValue());
      }
    }
    if (queries.size() > 0) return queries.get(r.nextInt(queries.size()));
    else return null;
  }
  public List<String> getStructures(File input) throws JDOMException, IOException {
    List<String> result = new LinkedList<String>();
    SAXBuilder saxBuilder = new SAXBuilder();
    for (File file : input.listFiles()) {
      Document document = null;
      try {
        document = saxBuilder.build(file);
      } catch (JDOMParseException parseException) {
        // file not a valid xml file (e.g. config.txt)
        continue;
      }

      XPathFactory xpf = XPathFactory.instance();
      XPathExpression<Element> xpath =
          xpf.compile("/treatment/description/statement/structure", Filters.element());
      List<Element> elements = xpath.evaluate(document);
      for (Element element : elements) {
        String name = element.getAttributeValue("name");
        String constraint = element.getAttributeValue("constraint");
        if (constraint != null) name = constraint + " " + name;
        result.add(name);
      }
    }
    return result;
  }
Exemple #7
0
  void metaVersusData(File p_file) throws Exception {
    SAXBuilder leftBuilder = new SAXBuilder();

    Document doc = leftBuilder.build(p_file);

    metaVersusData(doc.getRootElement());
  }
  private String mapItemParamsToAdviceCaseParams(
      String adviceName, List<YParameter> inAspectParams, String data) {
    org.jdom2.Element result = new org.jdom2.Element(adviceName);

    SAXBuilder builder = new SAXBuilder();
    org.jdom2.Element root = null;
    try {
      org.jdom2.Document document = builder.build(new StringReader(data));
      root = document.getRootElement();
    } catch (Exception e) {
      System.out.println(e);
    }
    for (YParameter param : inAspectParams) {
      String paramName = param.getName();
      org.jdom2.Element advElem = root.getChild(paramName);
      try {
        if (advElem != null) {
          org.jdom2.Element copy = (org.jdom2.Element) advElem.clone();
          result.addContent(copy);
        } else {
          result.addContent(new org.jdom2.Element(paramName));
        }
      } catch (IllegalAddException iae) {
        System.out.println("+++++++++++++++++ error:" + iae.getMessage());
      }
    }
    return JDOMUtil.elementToString(result);
  }
 public PodaPresu4() {
   JFileChooser chooser = new JFileChooser();
   chooser.setFileFilter(new FileNameExtensionFilter("Trabajos XML", "xml"));
   if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
     try {
       SAXBuilder builder = new SAXBuilder();
       Document d = builder.build(chooser.getSelectedFile());
       tx = new TrabajoXml(d);
       jt = new JfTrabajo();
       jt.addWindowListener(
           new WindowAdapter() {
             @Override
             public void windowClosing(WindowEvent e) {
               checkSave();
               super.windowClosing(
                   e); // To change body of generated methods, choose Tools | Templates.
             }
           });
       jt.setTrabajo(tx.readTrabajo());
       jt.setVisible(true);
     } catch (JDOMException | IOException ex) {
       Logger.getLogger(PodaPresu4.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
  public static void removeEventinXml(String eventNameString) {
    SAXBuilder sxbuilder = new SAXBuilder();
    try {
      Document document = sxbuilder.build(new File(xmlDefaultPath));
      Element racine = document.getRootElement();

      //			List listEvents = racine.getChildren("evenement");
      //			Iterator i = listEvents.iterator();
      //			while(i.hasNext()){
      //				Element elementEvent = (Element)i.next();
      //				if(elementEvent.getAttribute("nomEvent").getValue().equalsIgnoreCase(eventNameString)){
      //					racine.removeChild("evenement");
      //				}
      //			}

      //
      //	if(racine.getChild("evenement").getAttribute("nomEvent").getValue().equalsIgnoreCase(eventNameString)){
      //
      //			}

      //			List<Element> children = racine.getChildren();
      //			for(Element child : children) {
      //
      //				if(child.getAttribute("nomEvent").getValue().equalsIgnoreCase(eventNameString)){
      //					System.out.println("poins");
      ////					child.getParentElement().removeChild("evenement");
      //					System.out.println(child.getAttributeValue("nomEvent"));
      //				}
      //			}

      //			enregistre(document, xmlDefaultPath);
    } catch (Exception e) {
      e.getMessage();
    }
  }
  public static List<String> getEventsNameByXml() {
    SAXBuilder sxb = new SAXBuilder();
    Document document;
    List<String> listEvenementsString = null;
    //		Object obj=null;
    try {
      document = sxb.build(new File(xmlDefaultPath));

      //			listevents=getEventsNameByDoc(document);

      Element racine = document.getRootElement();

      //			System.out.println("racine="+racine.getText()+"finracine");
      List<Element> listEvenementsElement = racine.getChildren("evenement");
      listEvenementsString = new ArrayList<String>();

      for (Element evenementElement : listEvenementsElement) {
        listEvenementsString.add(evenementElement.getAttributeValue("nomEvent"));
      }

      //			System.out.println("listofEventsJdomtaille ="+listEvenementsString.size());

      // il faut valider le fichier xml avec la dtd
      //			JDomOperations.validateJDOM(document);
      //			afficheXml(document);
    } catch (Exception e) {
      // afficher un popup qui dit que le format du fichier xml entré n'est pas valide
      System.out.println("format xml non respecté");
      System.out.println(e.getMessage());
    }
    return listEvenementsString;
  }
  private org.jdom2.Element getDataforCase(String specName, String caseID, String data) {
    String caseData = "";
    try {
      caseData = _ibClient.getCaseData(caseID, _handle);
    } catch (IOException e) {
      e.printStackTrace();
    }
    org.jdom2.Element result = new org.jdom2.Element(specName);

    SAXBuilder builder = new SAXBuilder();
    org.jdom2.Element root = null;
    List<org.jdom2.Element> ls = null;
    try {
      org.jdom2.Document document = builder.build(new StringReader(data));
      root = document.getRootElement();

      ls = document.getRootElement().getChildren();
    } catch (Exception e) {
      System.out.println(e);
    }
    for (org.jdom2.Element l : ls) {
      String paramName = l.getName();
      org.jdom2.Element advElem = root.getChild(paramName);
      try {
        if (advElem != null) {
          org.jdom2.Element copy = (org.jdom2.Element) advElem.clone();
          result.addContent(copy);
        } else {
          result.addContent(new org.jdom2.Element(paramName));
        }
      } catch (IllegalAddException iae) {
      }
    }
    return result;
  }
  /*
  <fnmocTable>
    <entry>
      <grib1Id>0004</grib1Id>
      <fnmocId>0004</fnmocId>
      <name>MISC_GRIDS</name>
      <fullName>Miscellaneous Grids</fullName>
      <description>atmospheric model</description>
      <status>current</status>
    </entry>
    <entry>
      <grib1Id>0008</grib1Id>
      <fnmocId>0008</fnmocId>
      <name>STRATO</name>
      <fullName>NOGAPS Stratosphere Functions</fullName>
      <description>atmospheric stratosphere model</description>
      <status>current</status>
    </entry>
   */
  private Map<Integer, String> readGenProcess(String path) {
    try (InputStream is = GribResourceReader.getInputStream(path)) {
      if (is == null) {
        logger.error("Cant find FNMOC gen process table = " + path);
        return null;
      }

      SAXBuilder builder = new SAXBuilder();
      org.jdom2.Document doc = builder.build(is);
      Element root = doc.getRootElement();

      Map<Integer, String> result = new HashMap<>(200);
      Element fnmocTable = root.getChild("fnmocTable");
      List<Element> params = fnmocTable.getChildren("entry");
      for (Element elem1 : params) {
        int code = Integer.parseInt(elem1.getChildText("grib1Id"));
        String desc = elem1.getChildText("fullName");
        result.put(code, desc);
      }

      return Collections.unmodifiableMap(result); // all at once - thread safe

    } catch (IOException ioe) {
      logger.error("Cant read FNMOC Table 1 = " + path, ioe);

    } catch (JDOMException e) {
      logger.error("Cant parse FNMOC Table 1 = " + path, e);
    }

    return null;
  }
  public static Document GetTasksByQuery(InputStream stream, String query)
      throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();

    // String query = "//task[contains(attendant/@ids,'" + userId + "')]";

    Document doc = null;
    try {

      doc = builder.build(stream);
    } catch (IOException ex) {
      Logger.getLogger(TasksJDOMParser.class.getName()).log(Level.SEVERE, null, ex);

      throw ex;
    }

    XPathFactory xpfac = XPathFactory.instance();

    XPathExpression xp = xpfac.compile(query);

    List<Element> tasks = (List<Element>) xp.evaluate(doc);

    Document xmlDoc = new Document();

    Element root = new Element("tasks");

    for (int index = 0; index < tasks.size(); index++) {
      root.addContent(tasks.get(index).clone());
    }

    xmlDoc.addContent(root);
    return xmlDoc;
  }
  @SuppressWarnings("deprecation")
  public void setItemDescription(String itemDescription)
      throws JDOMException, IOException, URISyntaxException {
    StringReader is = new StringReader(itemDescription);

    SAXBuilder sb = new SAXBuilder();
    sb.setValidation(true);

    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = loader.getResource("../../xml/cloud.xsd");

    File file = new File(url.toURI());

    if (file != null) {
      sb.setProperty(
          "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
          "http://www.w3.org/2001/XMLSchema");
      sb.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", file);
    }

    Document dDoc = sb.build(is);

    Element dDocElm = dDoc.getRootElement().clone();

    this.descElm.removeContent();
    this.descElm.addContent(dDocElm);
  }
  public TableConfig readConfigXML(
      String fileLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog)
      throws IOException {

    org.jdom2.Document doc;
    try {
      SAXBuilder builder = new SAXBuilder(false);
      if (debugURL) System.out.println(" PointConfig URL = <" + fileLocation + ">");
      doc = builder.build(fileLocation);
    } catch (JDOMException e) {
      throw new IOException(e.getMessage());
    }
    if (debugXML) System.out.println(" SAXBuilder done");

    if (showParsedXML) {
      XMLOutputter xmlOut = new XMLOutputter();
      System.out.println(
          "*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******");
    }

    Element configElem = doc.getRootElement();
    String featureType = configElem.getAttributeValue("featureType");
    Element tableElem = configElem.getChild("table");
    TableConfig tc = parseTableConfig(ds, tableElem, null);
    tc.featureType = FeatureType.valueOf(featureType);

    return tc;
  }
 private ArchivoXmlUsuario(String rutaArchivo) throws JDOMException, IOException {
   SAXBuilder saxB = new SAXBuilder();
   saxB.setIgnoringElementContentWhitespace(true);
   this.documento = saxB.build(rutaArchivo);
   this.raiz = this.documento.getRootElement();
   this.ruta = rutaArchivo;
 }
  public static Question[] getQuestions(File xmlFile) {
    SAXBuilder builder = new SAXBuilder();
    Question[] res = {};

    try {

      Document document = (Document) builder.build(xmlFile);

      Element rootNode = document.getRootElement();

      List topics = rootNode.getChildren("t");

      String id, group, text, text_en, answer, q_type, q_ans, support, number; // , snippet;

      for (int i = 0; i < topics.size(); i++) {

        Element t = (Element) topics.get(i);
        List questions = t.getChildren("q");
        for (int j = 0; j < questions.size(); j++) {

          Element q = (Element) questions.get(j);
          id = q.getAttributeValue("q_id").toString();
          q_type = q.getAttributeValue("q_type").toString();
          q_ans = q.getAttributeValue("q_exp_ans_type").toString();
          support = q.getChild("answer").getAttributeValue("a_support");
          // snippet = q.getChild("answer").getAttributeValue("a_support");
          group = t.getAttributeValue("t_string").toString();
          text = q.getChild("question").getText();
          number = q.getChild("question").getAttributeValue("question_id");
          answer = q.getChild("answer").getChildText("a_string");
          text_en = q.getChild("q_translation").getText();
          res =
              ArrayUtils.add(
                  res,
                  new Question(
                      id,
                      group,
                      text,
                      answer,
                      text_en,
                      new String[0],
                      q_type,
                      q_ans,
                      support,
                      number));
        }
      }

    } catch (IOException io) {
      System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
      System.out.println(jdomex.getMessage());
    }

    return res;
  }
 /**
  * recupere le Document via un url xml
  *
  * @param xmltemppathlistvoitures2 chemin du fichier xml
  * @return le document
  */
 private static Document getXmlList(String xmltemppathlistvoitures2) {
   SAXBuilder sxb = new SAXBuilder();
   Document document = null;
   try {
     document = sxb.build(new File(xmltemppathlistvoitures2));
   } catch (Exception e) {
     e.getMessage();
   }
   return document;
 }
 /** ************************************************************************* */
 public static synchronized Document stringToDocument(String s) {
   try {
     _builder.setIgnoringBoundaryWhitespace(true);
     return (s != null) ? _builder.build(new StringReader(s)) : null;
   } catch (JDOMException jde) {
     _log.error("JDOMException converting to Document, String = " + s, jde);
   } catch (IOException ioe) {
     _log.error("IOException converting to Document, String = " + s, ioe);
   }
   return null;
 }
 protected void loadSettings(final String xmlFilename) throws IOException, JDOMException {
   final SAXBuilder sax = new SAXBuilder();
   final Document doc = sax.build(xmlFilename);
   final Element root = doc.getRootElement();
   viewer.stateFromXml(root);
   setupAssignments.restoreFromXml(root);
   manualTransformation.restoreFromXml(root);
   bookmarks.restoreFromXml(root);
   activeSourcesDialog.update();
   viewer.requestRepaint();
 }
 //	/**
 //	 * permet de creer un nouvel element Evenement
 //	 * @param xmldefaultpath2 est le path principal par défaut
 //	 */
 //	private static Document createElementEvenement(String xmldefaultpath2) {
 //		SAXBuilder sxb = new SAXBuilder();
 //		Document document=null;
 //		try{
 //			document = sxb.build(new File(xmldefaultpath2));
 //
 //			Element racine = document.getRootElement();
 //
 //			Element newVoitureElement=new Element("evenement");
 //			newVoitureElement.setAttribute("nomEvenement","");
 //			newVoitureElement.setAttribute("nomCircuit","");
 //			newVoitureElement.setAttribute("longueurCircuit","");
 //
 //			enregistre(document, xmlTempPathListVoitures);
 //		}
 //		catch(Exception e){
 //			e.getMessage();
 //
 //		}
 //		return document;
 //	}
 private static void cleanTemp(String path, String childrenName) {
   SAXBuilder sxb = new SAXBuilder();
   Document document;
   try {
     document = sxb.build(new File(path));
     Element racine = document.getRootElement();
     racine.removeChildren(childrenName);
     JDomOperations.enregistre(document, path);
   } catch (Exception e) {
     e.getMessage();
   }
 }
Exemple #23
0
 private static Channel loadChannel(InputStream in) throws Exception {
   SAXBuilder builder = new SAXBuilder(false);
   Document doc = builder.build(in);
   Element root = doc.getRootElement();
   String version = root.getAttributeValue("version");
   if (!"1.0".equals(version)) throw new Exception("Invalid file version");
   String type = root.getAttributeValue("type");
   Class clazz = Class.forName(type);
   if (!Channel.class.isAssignableFrom(clazz)) throw new Exception("Invalid channel type");
   Element elSettings = root.getChild("settings");
   return SimpleBeanToXML.xmlToObject(elSettings, clazz, false);
 }
  public static void read(InputStream is, StringBuilder errlog) throws IOException {

    Document doc;
    SAXBuilder saxBuilder = new SAXBuilder();
    try {
      doc = saxBuilder.build(is);
    } catch (JDOMException e) {
      throw new IOException(e.getMessage());
    }

    read(doc.getRootElement(), errlog);
  }
Exemple #25
0
 public static Document openXmlDocument(String path) {
   SAXBuilder builder = new SAXBuilder();
   try {
     Document doc = builder.build(new File(path));
     return doc;
   } catch (JDOMException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return null;
 }
  public Element getFileRoot(String filename) {

    // find file & load file
    Element root = null;

    boolean verify = false;

    try {
      SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", verify);

      builder.setFeature("http://apache.org/xml/features/xinclude", true);
      builder.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
      builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
      builder.setFeature("http://apache.org/xml/features/validation/schema", verify);
      builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", verify);
      builder.setFeature("http://xml.org/sax/features/namespaces", true);

      Document doc =
          builder.build(new BufferedInputStream(new FileInputStream(new File(filename))));
      root = doc.getRootElement();
    } catch (Exception e) {
      System.out.println("While reading file: " + e);
    }
    return root;
  }
Exemple #27
0
  private static void ouvrirDoc() {
    SAXBuilder sxb = new SAXBuilder();
    try {
      // On crée un nouveau document JDOM avec en argument le fichier XML
      // Le parsing est terminé ;)
      document = sxb.build(new File("rdf.xml"));
      System.out.println("Fichier ouvert");
    } catch (Exception e) {
      e.printStackTrace();
    }

    // On initialise un nouvel élément racine avec l'élément racine du
    // document.
    racine = document.getRootElement();
  }
  /*
   * (non-Javadoc)
   *
   * @see com.mydomain.maizsoft.cargaarchivos.ArchivoXML#read()
   */
  @Override
  public void read() {

    @SuppressWarnings("deprecation")
    SAXBuilder leer = new SAXBuilder(false);
    try {
      Document document = leer.build(getPath() + getNombre());

      Element raiz = document.getRootElement();
      raiz.getAttributeValue(ConstantesArchivosXML.SUPERPADRE);

      Element padre = raiz.getChild(ConstantesArchivosXML.PADRE);

      List usuarios = raiz.getChildren(ConstantesArchivosXML.PADRE);

      Iterator padres = usuarios.iterator();

      while (padres.hasNext()) {
        Element elePadre = (Element) padres.next();
        Element idPadre = elePadre.getChild(ConstantesArchivosXML.PADREID);
        List cursos = elePadre.getChildren(ConstantesArchivosXML.HIJO);
        Iterator hijos = cursos.iterator();
        long var2 = Long.parseLong(idPadre.getText());
        HistorialNotas nueva = new HistorialNotas();
        nueva.setUserAccount(entityManager.find(Usuario.class, var2));

        while (hijos.hasNext()) {
          Element eleHijo = (Element) hijos.next();
          Element idHijo = eleHijo.getChild(ConstantesArchivosXML.HIJOID);
          Element semestre = eleHijo.getChild(ConstantesArchivosXML.HIJOSEMESTRE);
          Element nota = eleHijo.getChild(ConstantesArchivosXML.HIJONOTA);
          long var = Long.parseLong(idHijo.getText());
          nueva.setGrupoCurso(entityManager.find(GrupoCurso.class, var));
          double notad = Double.parseDouble(nota.getText());
          nueva.setSemestre(semestre.getText());
          nueva.setNota(notad);
          entityManager.persist(nueva);
        }
      }

    } catch (Exception e) {
      FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
      mensaje.add("Se produjo un error técnico :(");
    }

    FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
    mensaje.add("Proceso exitoso :-)");
  }
Exemple #29
0
  private void setData() {
    try {
      Document doc = builder.build(prefFile);

      Element rootNode = doc.getRootElement();
      Element RWDir = new Element("RWDir");

      rootNode.getChild("firstLoad").setText("no");
      RWDir.setText(RWDIRECTORY.getAbsolutePath());

      rootNode.addContent(RWDir);

      XMLOutputter xmlOutput = new XMLOutputter();
      FileWriter fw = new FileWriter(prefFile);

      xmlOutput.setFormat(Format.getPrettyFormat());
      xmlOutput.output(doc, fw);

      fw.close();
    } catch (IOException io) {
      io.printStackTrace();
    } catch (JDOMException e) {
      e.printStackTrace();
    }
  }
  public void parseDoc(File file) throws Exception {
    adjustFile(file);
    start = -1;
    end = -1;
    prevValue = -1;
    ocrAl = new ArrayList<>(1000);
    outFileName =
        file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4) + "ngt.xml";
    builder = new SAXBuilder();
    doc = builder.build(file);
    root = doc.getRootElement();
    xmlns = root.getNamespace();
    xpath =
        XPathFactory.instance()
            .compile(
                "//ns:span[@class='ocr_word']",
                Filters.element(),
                null,
                Namespace.getNamespace("ns", "http://www.w3.org/1999/xhtml"));
    List<Element> elements = xpath.evaluate(root);
    for (Element element : elements) {
      parseOcrWord(element);
    }

    ocrAl.add("%%%");
    ocrAl.add("%%%");
    findAnchors();
    writeFragment(start, end);
  }